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    public BindRequestDsml( LdapApiService codec )
046    {
047        super( codec, new BindRequestImpl() );
048    }
049
050
051    /**
052     * Creates a new getDecoratedMessage() of AuthRequestDsml.
053     *
054     * @param ldapMessage the message to decorate
055     */
056    public BindRequestDsml( LdapApiService codec, BindRequest ldapMessage )
057    {
058        super( codec, ldapMessage );
059    }
060
061
062    /**
063     * {@inheritDoc}
064     */
065    public MessageTypeEnum getType()
066    {
067        return getDecorated().getType();
068    }
069
070
071    /**
072     * {@inheritDoc}
073     */
074    public Element toDsml( Element root )
075    {
076        Element element = super.toDsml( root );
077
078        BindRequest request = getDecorated();
079
080        // Principal
081        Dn dn = request.getDn();
082
083        if ( !Dn.isNullOrEmpty( dn ) )
084        {
085            // A DN has been provided
086
087            element.addAttribute( "principal", dn.getName() );
088        }
089        else
090        {
091            // No DN has been provided, let's use the name as a string instead
092
093            String name = request.getName();
094
095            element.addAttribute( "principal", name );
096        }
097
098        return element;
099    }
100
101
102    /**
103     * {@inheritDoc}
104     */
105    public MessageTypeEnum getResponseType()
106    {
107        return getDecorated().getResponseType();
108    }
109
110
111    /**
112     * {@inheritDoc}
113     */
114    public boolean isSimple()
115    {
116        return getDecorated().isSimple();
117    }
118
119
120    /**
121     * {@inheritDoc}
122     */
123    public boolean getSimple()
124    {
125        return getDecorated().getSimple();
126    }
127
128
129    /**
130     * {@inheritDoc}
131     */
132    public BindRequest setSimple( boolean isSimple )
133    {
134        getDecorated().setSimple( isSimple );
135
136        return this;
137    }
138
139
140    /**
141     * {@inheritDoc}
142     */
143    public byte[] getCredentials()
144    {
145        return getDecorated().getCredentials();
146    }
147
148
149    /**
150     * {@inheritDoc}
151     */
152    public BindRequest setCredentials( String credentials )
153    {
154        getDecorated().setCredentials( credentials );
155
156        return this;
157    }
158
159
160    /**
161     * {@inheritDoc}
162     */
163    public BindRequest setCredentials( byte[] credentials )
164    {
165        getDecorated().setCredentials( credentials );
166
167        return this;
168    }
169
170
171    /**
172     * {@inheritDoc}
173     */
174    public String getName()
175    {
176        return getDecorated().getName();
177    }
178
179
180    /**
181     * {@inheritDoc}
182     */
183    public BindRequest setName( String name )
184    {
185        getDecorated().setName( name );
186
187        return this;
188    }
189
190
191    /**
192     * {@inheritDoc}
193     */
194    public Dn getDn()
195    {
196        return getDecorated().getDn();
197    }
198
199
200    /**
201     * {@inheritDoc}
202     */
203    public BindRequest setDn( Dn dn )
204    {
205        getDecorated().setDn( dn );
206
207        return this;
208    }
209
210
211    /**
212     * {@inheritDoc}
213     */
214    public boolean isVersion3()
215    {
216        return getDecorated().isVersion3();
217    }
218
219
220    /**
221     * {@inheritDoc}
222     */
223    public boolean getVersion3()
224    {
225        return getDecorated().getVersion3();
226    }
227
228
229    /**
230     * {@inheritDoc}
231     */
232    public BindRequest setVersion3( boolean isVersion3 )
233    {
234        getDecorated().setVersion3( isVersion3 );
235
236        return this;
237    }
238
239
240    /**
241     * {@inheritDoc}
242     */
243    public String getSaslMechanism()
244    {
245        return getDecorated().getSaslMechanism();
246    }
247
248
249    /**
250     * {@inheritDoc}
251     */
252    public BindRequest setSaslMechanism( String saslMechanism )
253    {
254        getDecorated().setSaslMechanism( saslMechanism );
255
256        return this;
257    }
258
259
260    /**
261     * {@inheritDoc}
262     */
263    public BindRequest setMessageId( int messageId )
264    {
265        super.setMessageId( messageId );
266
267        return this;
268    }
269
270
271    /**
272     * {@inheritDoc}
273     */
274    public BindRequest addControl( Control control )
275    {
276        return ( BindRequest ) super.addControl( control );
277    }
278
279
280    /**
281     * {@inheritDoc}
282     */
283    public BindRequest addAllControls( Control[] controls )
284    {
285        return ( BindRequest ) super.addAllControls( controls );
286    }
287
288
289    /**
290     * {@inheritDoc}
291     */
292    public BindRequest removeControl( Control control )
293    {
294        return ( BindRequest ) super.removeControl( control );
295    }
296}