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.dsmlv2.request;
21  
22  
23  import org.apache.directory.api.ldap.codec.api.LdapApiService;
24  import org.apache.directory.api.ldap.model.message.BindRequest;
25  import org.apache.directory.api.ldap.model.message.BindRequestImpl;
26  import org.apache.directory.api.ldap.model.message.BindResponse;
27  import org.apache.directory.api.ldap.model.message.Control;
28  import org.apache.directory.api.ldap.model.message.MessageTypeEnum;
29  import org.apache.directory.api.ldap.model.name.Dn;
30  import org.dom4j.Element;
31  
32  
33  /**
34   * DSML Decorator for BindRequest
35   *
36   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
37   */
38  public class BindRequestDsml
39      extends AbstractResultResponseRequestDsml<BindRequest, BindResponse>
40      implements BindRequest
41  {
42      /**
43       * Creates a new getDecoratedMessage() of AuthRequestDsml.
44       * 
45       * @param codec The LDAP Service to use
46       */
47      public BindRequestDsml( LdapApiService codec )
48      {
49          super( codec, new BindRequestImpl() );
50      }
51  
52  
53      /**
54       * Creates a new getDecoratedMessage() of AuthRequestDsml.
55       *
56       * @param codec The LDAP Service to use
57       * @param ldapMessage the message to decorate
58       */
59      public BindRequestDsml( LdapApiService codec, BindRequest ldapMessage )
60      {
61          super( codec, ldapMessage );
62      }
63  
64  
65      /**
66       * {@inheritDoc}
67       */
68      public MessageTypeEnum getType()
69      {
70          return getDecorated().getType();
71      }
72  
73  
74      /**
75       * {@inheritDoc}
76       */
77      public Element toDsml( Element root )
78      {
79          Element element = super.toDsml( root );
80  
81          BindRequest request = getDecorated();
82  
83          // Principal
84          Dn dn = request.getDn();
85  
86          if ( !Dn.isNullOrEmpty( dn ) )
87          {
88              // A DN has been provided
89  
90              element.addAttribute( "principal", dn.getName() );
91          }
92          else
93          {
94              // No DN has been provided, let's use the name as a string instead
95  
96              String name = request.getName();
97  
98              element.addAttribute( "principal", name );
99          }
100 
101         return element;
102     }
103 
104 
105     /**
106      * {@inheritDoc}
107      */
108     public MessageTypeEnum getResponseType()
109     {
110         return getDecorated().getResponseType();
111     }
112 
113 
114     /**
115      * {@inheritDoc}
116      */
117     public boolean isSimple()
118     {
119         return getDecorated().isSimple();
120     }
121 
122 
123     /**
124      * {@inheritDoc}
125      */
126     public boolean getSimple()
127     {
128         return getDecorated().getSimple();
129     }
130 
131 
132     /**
133      * {@inheritDoc}
134      */
135     public BindRequest setSimple( boolean isSimple )
136     {
137         getDecorated().setSimple( isSimple );
138 
139         return this;
140     }
141 
142 
143     /**
144      * {@inheritDoc}
145      */
146     public byte[] getCredentials()
147     {
148         return getDecorated().getCredentials();
149     }
150 
151 
152     /**
153      * {@inheritDoc}
154      */
155     public BindRequest setCredentials( String credentials )
156     {
157         getDecorated().setCredentials( credentials );
158 
159         return this;
160     }
161 
162 
163     /**
164      * {@inheritDoc}
165      */
166     public BindRequest setCredentials( byte[] credentials )
167     {
168         getDecorated().setCredentials( credentials );
169 
170         return this;
171     }
172 
173 
174     /**
175      * {@inheritDoc}
176      */
177     public String getName()
178     {
179         return getDecorated().getName();
180     }
181 
182 
183     /**
184      * {@inheritDoc}
185      */
186     public BindRequest setName( String name )
187     {
188         getDecorated().setName( name );
189 
190         return this;
191     }
192 
193 
194     /**
195      * {@inheritDoc}
196      */
197     public Dn getDn()
198     {
199         return getDecorated().getDn();
200     }
201 
202 
203     /**
204      * {@inheritDoc}
205      */
206     public BindRequest setDn( Dn dn )
207     {
208         getDecorated().setDn( dn );
209 
210         return this;
211     }
212 
213 
214     /**
215      * {@inheritDoc}
216      */
217     public boolean isVersion3()
218     {
219         return getDecorated().isVersion3();
220     }
221 
222 
223     /**
224      * {@inheritDoc}
225      */
226     public boolean getVersion3()
227     {
228         return getDecorated().getVersion3();
229     }
230 
231 
232     /**
233      * {@inheritDoc}
234      */
235     public BindRequest setVersion3( boolean isVersion3 )
236     {
237         getDecorated().setVersion3( isVersion3 );
238 
239         return this;
240     }
241 
242 
243     /**
244      * {@inheritDoc}
245      */
246     public String getSaslMechanism()
247     {
248         return getDecorated().getSaslMechanism();
249     }
250 
251 
252     /**
253      * {@inheritDoc}
254      */
255     public BindRequest setSaslMechanism( String saslMechanism )
256     {
257         getDecorated().setSaslMechanism( saslMechanism );
258 
259         return this;
260     }
261 
262 
263     /**
264      * {@inheritDoc}
265      */
266     public BindRequest setMessageId( int messageId )
267     {
268         super.setMessageId( messageId );
269 
270         return this;
271     }
272 
273 
274     /**
275      * {@inheritDoc}
276      */
277     public BindRequest addControl( Control control )
278     {
279         return ( BindRequest ) super.addControl( control );
280     }
281 
282 
283     /**
284      * {@inheritDoc}
285      */
286     public BindRequest addAllControls( Control[] controls )
287     {
288         return ( BindRequest ) super.addAllControls( controls );
289     }
290 
291 
292     /**
293      * {@inheritDoc}
294      */
295     public BindRequest removeControl( Control control )
296     {
297         return ( BindRequest ) super.removeControl( control );
298     }
299 }