001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * https://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020package org.apache.directory.api.dsmlv2.request; 021 022 023import java.nio.ByteBuffer; 024 025import org.apache.directory.api.asn1.EncoderException; 026import org.apache.directory.api.dsmlv2.DsmlLiterals; 027import org.apache.directory.api.dsmlv2.ParserUtils; 028import org.apache.directory.api.ldap.codec.api.LdapApiService; 029import org.apache.directory.api.ldap.model.message.AbandonListener; 030import org.apache.directory.api.ldap.model.message.AbandonableRequest; 031import org.apache.directory.api.ldap.model.message.ResultResponse; 032import org.apache.directory.api.ldap.model.message.ResultResponseRequest; 033import org.dom4j.Element; 034 035 036/** 037 * Abstract class for DSML requests. 038 * 039 * @param <E> The response request result type 040 * @param <F> The response result type 041 * 042 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 043 */ 044public abstract class AbstractResultResponseRequestDsml<E extends ResultResponseRequest, F extends ResultResponse> 045 extends AbstractRequestDsml<E> 046 implements ResultResponseRequest, AbandonableRequest 047{ 048 /** 049 * Creates a new instance of AbstractRequestDsml. 050 * 051 * @param codec The LDAP Service to use 052 * @param ldapMessage the message to decorate 053 */ 054 public AbstractResultResponseRequestDsml( LdapApiService codec, E ldapMessage ) 055 { 056 super( codec, ldapMessage ); 057 } 058 059 060 /** 061 * Creates the Request Element and adds RequestID and Controls. 062 * 063 * @param root the root element 064 * @return the Request Element of the given name containing 065 */ 066 @Override 067 public Element toDsml( Element root ) 068 { 069 Element element = root.addElement( getRequestName() ); 070 071 // Request ID 072 int requestID = getDecorated().getMessageId(); 073 if ( requestID > 0 ) 074 { 075 element.addAttribute( DsmlLiterals.REQUEST_ID, Integer.toString( requestID ) ); 076 } 077 078 // Controls 079 ParserUtils.addControls( getCodecService(), element, getDecorated().getControls().values(), false ); 080 081 return element; 082 } 083 084 085 /** 086 * {@inheritDoc} 087 */ 088 @Override 089 public int computeLength() 090 { 091 return 0; 092 } 093 094 095 /** 096 * {@inheritDoc} 097 */ 098 @Override 099 public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException 100 { 101 return null; 102 } 103 104 105 /** 106 * {@inheritDoc} 107 */ 108 @Override 109 public ResultResponse getResultResponse() 110 { 111 return getDecorated().getResultResponse(); 112 } 113 114 115 /** 116 * {@inheritDoc} 117 */ 118 @Override 119 public void abandon() 120 { 121 ( ( AbandonableRequest ) getDecorated() ).abandon(); 122 } 123 124 125 /** 126 * {@inheritDoc} 127 */ 128 @Override 129 public boolean isAbandoned() 130 { 131 return ( ( AbandonableRequest ) getDecorated() ).isAbandoned(); 132 } 133 134 135 /** 136 * {@inheritDoc} 137 */ 138 @Override 139 public AbandonableRequest addAbandonListener( AbandonListener listener ) 140 { 141 ( ( AbandonableRequest ) getDecorated() ).addAbandonListener( listener ); 142 143 return this; 144 } 145}