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 *    http://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 org.apache.directory.api.ldap.codec.api.LdapApiService;
024import org.apache.directory.api.ldap.model.message.BindRequest;
025import org.apache.directory.api.ldap.model.message.BindRequestImpl;
026import org.apache.directory.api.ldap.model.message.BindResponse;
027import org.apache.directory.api.ldap.model.message.Control;
028import org.apache.directory.api.ldap.model.message.MessageTypeEnum;
029import org.apache.directory.api.ldap.model.name.Dn;
030import org.dom4j.Element;
031
032
033/**
034 * DSML Decorator for BindRequest
035 *
036 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
037 */
038public class BindRequestDsml
039    extends AbstractResultResponseRequestDsml<BindRequest, BindResponse>
040    implements BindRequest
041{
042    /**
043     * Creates a new getDecoratedMessage() of AuthRequestDsml.
044     * 
045     * @param codec The LDAP Service to use
046     */
047    public BindRequestDsml( LdapApiService codec )
048    {
049        super( codec, new BindRequestImpl() );
050    }
051
052
053    /**
054     * Creates a new getDecoratedMessage() of AuthRequestDsml.
055     *
056     * @param codec The LDAP Service to use
057     * @param ldapMessage the message to decorate
058     */
059    public BindRequestDsml( LdapApiService codec, BindRequest ldapMessage )
060    {
061        super( codec, ldapMessage );
062    }
063
064
065    /**
066     * {@inheritDoc}
067     */
068    public MessageTypeEnum getType()
069    {
070        return getDecorated().getType();
071    }
072
073
074    /**
075     * {@inheritDoc}
076     */
077    public Element toDsml( Element root )
078    {
079        Element element = super.toDsml( root );
080
081        BindRequest request = getDecorated();
082
083        // Principal
084        Dn dn = request.getDn();
085
086        if ( !Dn.isNullOrEmpty( dn ) )
087        {
088            // A DN has been provided
089
090            element.addAttribute( "principal", dn.getName() );
091        }
092        else
093        {
094            // No DN has been provided, let's use the name as a string instead
095
096            String name = request.getName();
097
098            element.addAttribute( "principal", name );
099        }
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}