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   *     http://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.ldap.codec.api;
21  
22  
23  import java.util.Iterator;
24  
25  import org.apache.directory.api.asn1.DecoderException;
26  import org.apache.directory.api.asn1.EncoderException;
27  import org.apache.directory.api.asn1.ber.Asn1Container;
28  import org.apache.directory.api.ldap.model.message.Control;
29  import org.apache.directory.api.ldap.model.message.ExtendedRequest;
30  import org.apache.directory.api.ldap.model.message.ExtendedResponse;
31  import org.apache.mina.filter.codec.ProtocolCodecFactory;
32  
33  
34  /**
35   * The service interface for the LDAP codec.
36   *
37   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
38   * @version $Rev$, $Date$
39   */
40  public interface LdapApiService
41  {
42      String DEFAULT_PROTOCOL_CODEC_FACTORY =
43          "org.apache.directory.api.ldap.codec.protocol.mina.LdapProtocolCodecFactory";
44  
45  
46      // ------------------------------------------------------------------------
47      // Control Methods
48      // ------------------------------------------------------------------------
49  
50      /**
51       * Returns an Iterator over the OID Strings of registered controls.
52       * 
53       * @return The registered control OID Strings
54       */
55      Iterator<String> registeredControls();
56  
57  
58      /**
59       * Checks if a control has been registered.
60       * 
61       * @return The OID of the control to check for registration
62       */
63      boolean isControlRegistered( String oid );
64  
65  
66      /**
67       * Registers an {@link ControlFactory} with this service.
68       * 
69       * @param factory The control factory
70       */
71      ControlFactory<?> registerControl( ControlFactory<?> factory );
72  
73  
74      /**
75       * Unregisters an {@link ControlFactory} with this service.
76       * 
77       * @param oid The oid of the control the factory is associated with.
78       */
79      ControlFactory<?> unregisterControl( String oid );
80  
81  
82      /**
83       * Creates a new codec control decorator of the specified type.
84       *
85       * @param oid The OID of the new control to create.
86       * @return The newly created codec control.
87       */
88      CodecControl<? extends Control> newControl( String oid );
89  
90  
91      /**
92       * Creates a new codec control decorator for the provided control.
93       *
94       * @param control The control the codec control is generated for.
95       * @return The newly created codec control.
96       */
97      CodecControl<? extends Control> newControl( Control control );
98  
99  
100     /**
101      * Creates a JNDI control from the ldap model's control.
102      *
103      * @param modelControl The model's control.
104      * @return The JNDI control.
105      * @throws EncoderException if there are problems encoding the modelControl.
106      */
107     javax.naming.ldap.Control toJndiControl( Control modelControl ) throws EncoderException;
108 
109 
110     /**
111      * Creates a model control from the JNDI control.
112      *
113      * @param jndiControl The JNDI control.
114      * @return The model control.
115      * @throws DecoderException if there are problems decoding the value of the JNDI control.
116      */
117     Control fromJndiControl( javax.naming.ldap.Control jndiControl ) throws DecoderException;
118 
119 
120     // ------------------------------------------------------------------------
121     // Extended Request Methods
122     // ------------------------------------------------------------------------
123 
124     /**
125      * Returns an Iterator over the OID Strings of registered extended 
126      * requests.
127      *
128      * @return The registered extended request OID Strings
129      */
130     Iterator<String> registeredExtendedRequests();
131 
132 
133     /**
134      * Registers an {@link ExtendedOperationFactory} for generating extended request 
135      * response pairs.
136      * 
137      * @param factory The extended request factory
138      * @return The displaced factory if one existed for the oid
139      */
140     ExtendedOperationFactory registerExtendedRequest( ExtendedOperationFactory factory );
141 
142 
143     /**
144      * Unregisters an {@link ExtendedOperationFactory} for generating extended 
145      * request response pairs.
146      * 
147      * @param oid The extended request oid
148      * @return The displaced factory if one existed for the oid
149      */
150     ExtendedOperationFactory unregisterExtendedRequest( String oid );
151 
152 
153     /**
154      * Checks to see if an extended operation, either a standard request 
155      * response, pair or just an unsolicited response is registered.
156      *
157      * @param oid The object identifier for the extended operation
158      * @return true if registered, false if not
159      */
160     boolean isExtendedOperationRegistered( String oid );
161 
162 
163     // ------------------------------------------------------------------------
164     // Extended Response Methods
165     // ------------------------------------------------------------------------
166 
167     /**
168      * Creates a model ExtendedResponse from the JNDI ExtendedResponse.
169      *
170      * @param jndiResponse The JNDI ExtendedResponse 
171      * @return The model ExtendedResponse
172      * @throws DecoderException if the response value cannot be decoded.
173      */
174     ExtendedResponse fromJndi( javax.naming.ldap.ExtendedResponse jndiResponse ) throws DecoderException;
175 
176 
177     /**
178      * Creates a JNDI {@link javax.naming.ldap.ExtendedResponse} from the model 
179      * {@link ExtendedResponse}.
180      * 
181      * @param modelResponse
182      * @return
183      * @throws EncoderException
184      */
185     javax.naming.ldap.ExtendedResponse toJndi( ExtendedResponse modelResponse ) throws EncoderException;
186 
187 
188     /**
189      * Creates a model ExtendedResponse from the JNDI ExtendedResponse.
190      *
191      * @param jndiResponse The JNDI ExtendedResponse 
192      * @return The model ExtendedResponse
193      * @throws DecoderException if the response value cannot be decoded.
194      */
195     ExtendedRequest fromJndi( javax.naming.ldap.ExtendedRequest jndiRequest ) throws DecoderException;
196 
197 
198     /**
199      * Creates a JNDI {@link javax.naming.ldap.ExtendedResponse} from the model 
200      * {@link ExtendedResponse}.
201      * 
202      * @param modelResponse
203      * @return
204      * @throws EncoderException
205      */
206     javax.naming.ldap.ExtendedRequest toJndi( ExtendedRequest modelRequest ) throws EncoderException;
207 
208 
209     // ------------------------------------------------------------------------
210     // Other Methods
211     // ------------------------------------------------------------------------
212 
213     /**
214      * Creates a new LDAP {@link ProtocolCodecFactory}.
215      *
216      * @return the {@link ProtocolCodecFactory}
217      */
218     ProtocolCodecFactory getProtocolCodecFactory();
219 
220 
221     /**
222      * Registers a ProtocolCodecFactory with this LdapCodecService.
223      *
224      * @param factory The factory being registered.
225      * @return The previously set {@link ProtocolCodecFactory}, or null if 
226      * none had been set earlier.
227      */
228     ProtocolCodecFactory registerProtocolCodecFactory( ProtocolCodecFactory factory );
229 
230 
231     /**
232      * Creates a new MessageContainer.
233      *
234      * @TODO akarasulu - Wondering why is this not an LdapMessageContainer?
235      * @return The newly created LDAP MessageContainer instance.
236      */
237     Asn1Container newMessageContainer();
238 
239 
240     /**
241      * Create an instance of a ExtendedResponse, knowing its OID. Inject the payload
242      * into it.
243      * 
244      * @param responseName The extendedRespose OID
245      * @param messageId The original message ID
246      * @param serializedResponse The serialized response payload
247      * @return The extendedResponse instance
248      * 
249      * @throws DecoderException If the payload is incorrect
250      */
251     <E extends ExtendedResponse> E newExtendedResponse( String responseName, int messageId, byte[] serializedResponse )
252         throws DecoderException;
253 
254 
255     /**
256      * Creates a new ExtendedRequest instance.
257      * 
258      * @param oid the extended request's object identifier
259      * @param value the encoded value of the extended request
260      * @return The new extended request
261      */
262     ExtendedRequest newExtendedRequest( String oid, byte[] value );
263 
264 
265     ExtendedRequestDecorator<?> decorate( ExtendedRequest decoratedMessage );
266 
267 
268     ExtendedResponseDecorator<?> decorate( ExtendedResponse decoratedMessage );
269 }