View Javadoc
1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *
10   *    https://www.apache.org/licenses/LICENSE-2.0
11   *
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License.
18   *
19   */
20  package org.apache.directory.api.dsmlv2.request;
21  
22  
23  import java.nio.ByteBuffer;
24  
25  import org.apache.directory.api.asn1.EncoderException;
26  import org.apache.directory.api.dsmlv2.DsmlLiterals;
27  import org.apache.directory.api.dsmlv2.ParserUtils;
28  import org.apache.directory.api.ldap.codec.api.LdapApiService;
29  import org.apache.directory.api.ldap.model.message.AbandonListener;
30  import org.apache.directory.api.ldap.model.message.AbandonableRequest;
31  import org.apache.directory.api.ldap.model.message.ResultResponse;
32  import org.apache.directory.api.ldap.model.message.ResultResponseRequest;
33  import org.dom4j.Element;
34  
35  
36  /**
37   * Abstract class for DSML requests.
38   *
39   * @param <E> The response request result type
40   * @param <F> The response result type
41   *
42   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
43   */
44  public abstract class AbstractResultResponseRequestDsml<E extends ResultResponseRequest, F extends ResultResponse>
45      extends AbstractRequestDsml<E>
46      implements ResultResponseRequest, AbandonableRequest
47  {
48      /**
49       * Creates a new instance of AbstractRequestDsml.
50       *
51       * @param codec The LDAP Service to use
52       * @param ldapMessage the message to decorate
53       */
54      public AbstractResultResponseRequestDsml( LdapApiService codec, E ldapMessage )
55      {
56          super( codec, ldapMessage );
57      }
58  
59  
60      /**
61       * Creates the Request Element and adds RequestID and Controls.
62       *
63       * @param root the root element
64       * @return the Request Element of the given name containing
65       */
66      @Override
67      public Element toDsml( Element root )
68      {
69          Element element = root.addElement( getRequestName() );
70  
71          // Request ID
72          int requestID = getDecorated().getMessageId();
73          if ( requestID > 0 )
74          {
75              element.addAttribute( DsmlLiterals.REQUEST_ID, Integer.toString( requestID ) );
76          }
77  
78          // Controls
79          ParserUtils.addControls( getCodecService(), element, getDecorated().getControls().values(), false );
80  
81          return element;
82      }
83  
84  
85      /**
86       * {@inheritDoc}
87       */
88      @Override
89      public int computeLength()
90      {
91          return 0;
92      }
93  
94  
95      /**
96       * {@inheritDoc}
97       */
98      @Override
99      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 }