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.shared.dsmlv2.request;
021
022
023import org.apache.directory.shared.ldap.codec.api.LdapApiService;
024import org.apache.directory.shared.ldap.model.exception.MessageException;
025import org.apache.directory.shared.ldap.model.message.BindRequest;
026import org.apache.directory.shared.ldap.model.message.BindRequestImpl;
027import org.apache.directory.shared.ldap.model.message.BindResponse;
028import org.apache.directory.shared.ldap.model.message.Control;
029import org.apache.directory.shared.ldap.model.message.MessageTypeEnum;
030import org.apache.directory.shared.ldap.model.name.Dn;
031import org.dom4j.Element;
032
033
034/**
035 * DSML Decorator for BindRequest
036 *
037 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
038 */
039public class BindRequestDsml 
040    extends AbstractResultResponseRequestDsml<BindRequest, BindResponse>
041    implements BindRequest
042{
043    /**
044     * Creates a new getDecoratedMessage() of AuthRequestDsml.
045     */
046    public BindRequestDsml( LdapApiService codec )
047    {
048        super( codec, new BindRequestImpl() );
049    }
050
051
052    /**
053     * Creates a new getDecoratedMessage() of AuthRequestDsml.
054     *
055     * @param ldapMessage the message to decorate
056     */
057    public BindRequestDsml( LdapApiService codec, BindRequest ldapMessage )
058    {
059        super( codec, ldapMessage );
060    }
061
062
063    /**
064     * {@inheritDoc}
065     */
066    public MessageTypeEnum getType()
067    {
068        return getDecorated().getType();
069    }
070
071
072    /**
073     * {@inheritDoc}
074     */
075    public Element toDsml( Element root )
076    {
077        Element element = super.toDsml( root );
078
079        BindRequest request = ( BindRequest ) getDecorated();
080
081        // AbandonID
082        String name = request.getName().getName();
083        if ( ( name != null ) && ( !"".equals( name ) ) )
084        {
085            element.addAttribute( "principal", name );
086        }
087
088        return element;
089    }
090
091
092    /**
093     * {@inheritDoc}
094     */
095    public MessageTypeEnum getResponseType()
096    {
097        return getDecorated().getResponseType();
098    }
099
100
101    /**
102     * {@inheritDoc}
103     */
104    public boolean isSimple()
105    {
106        return getDecorated().isSimple();
107    }
108
109
110    /**
111     * {@inheritDoc}
112     */
113    public boolean getSimple()
114    {
115        return getDecorated().getSimple();
116    }
117
118
119    /**
120     * {@inheritDoc}
121     */
122    public BindRequest setSimple( boolean isSimple )
123    {
124        getDecorated().setSimple( isSimple );
125
126        return this;
127    }
128
129
130    /**
131     * {@inheritDoc}
132     */
133    public byte[] getCredentials()
134    {
135        return getDecorated().getCredentials();
136    }
137
138
139    /**
140     * {@inheritDoc}
141     */
142    public BindRequest setCredentials( String credentials )
143    {
144        getDecorated().setCredentials( credentials );
145
146        return this;
147    }
148
149
150    /**
151     * {@inheritDoc}
152     */
153    public BindRequest setCredentials( byte[] credentials )
154    {
155        getDecorated().setCredentials( credentials );
156
157        return this;
158    }
159
160
161    /**
162     * {@inheritDoc}
163     */
164    public Dn getName()
165    {
166        return getDecorated().getName();
167    }
168
169
170    /**
171     * {@inheritDoc}
172     */
173    public BindRequest setName( Dn name )
174    {
175        getDecorated().setName( name );
176
177        return this;
178    }
179
180
181    /**
182     * {@inheritDoc}
183     */
184    public boolean isVersion3()
185    {
186        return getDecorated().isVersion3();
187    }
188
189
190    /**
191     * {@inheritDoc}
192     */
193    public boolean getVersion3()
194    {
195        return getDecorated().getVersion3();
196    }
197
198
199    /**
200     * {@inheritDoc}
201     */
202    public BindRequest setVersion3( boolean isVersion3 )
203    {
204        getDecorated().setVersion3( isVersion3 );
205
206        return this;
207    }
208
209
210    /**
211     * {@inheritDoc}
212     */
213    public String getSaslMechanism()
214    {
215        return getDecorated().getSaslMechanism();
216    }
217
218
219    /**
220     * {@inheritDoc}
221     */
222    public BindRequest setSaslMechanism( String saslMechanism )
223    {
224        getDecorated().setSaslMechanism( saslMechanism );
225
226        return this;
227    }
228    
229    
230    /**
231     * {@inheritDoc}
232     */
233    public BindRequest setMessageId( int messageId )
234    {
235        super.setMessageId( messageId );
236        
237        return this;
238    }
239
240    
241    /**
242     * {@inheritDoc}
243     */
244    public BindRequest addControl( Control control ) throws MessageException
245    {
246        return (BindRequest)super.addControl( control );
247    }
248    
249    
250    /**
251     * {@inheritDoc}
252     */
253    public BindRequest addAllControls( Control[] controls ) throws MessageException
254    {
255        return (BindRequest)super.addAllControls( controls );
256    }
257    
258    
259    /**
260     * {@inheritDoc}
261     */
262    public BindRequest removeControl( Control control ) throws MessageException
263    {
264        return (BindRequest)super.removeControl( control );
265    }
266}