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.Control;
025import org.apache.directory.api.ldap.model.message.MessageTypeEnum;
026import org.apache.directory.api.ldap.model.message.ModifyDnRequest;
027import org.apache.directory.api.ldap.model.message.ModifyDnRequestImpl;
028import org.apache.directory.api.ldap.model.message.ModifyDnResponse;
029import org.apache.directory.api.ldap.model.name.Dn;
030import org.apache.directory.api.ldap.model.name.Rdn;
031import org.dom4j.Element;
032
033
034/**
035 * DSML Decorator for ModifyDNRequest
036 *
037 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
038 */
039public class ModifyDNRequestDsml
040    extends AbstractResultResponseRequestDsml<ModifyDnRequest, ModifyDnResponse>
041    implements ModifyDnRequest
042{
043    /**
044     * Creates a new getDecoratedMessage() of ModifyDNRequestDsml.
045     */
046    public ModifyDNRequestDsml( LdapApiService codec )
047    {
048        super( codec, new ModifyDnRequestImpl() );
049    }
050
051
052    /**
053     * Creates a new getDecoratedMessage() of ModifyDNRequestDsml.
054     *
055     * @param ldapMessage
056     *      the message to decorate
057     */
058    public ModifyDNRequestDsml( LdapApiService codec, ModifyDnRequest ldapMessage )
059    {
060        super( codec, ldapMessage );
061    }
062
063
064    /**
065     * {@inheritDoc}
066     */
067    public MessageTypeEnum getType()
068    {
069        return getDecorated().getType();
070    }
071
072
073    /**
074     * {@inheritDoc}
075     */
076    public Element toDsml( Element root )
077    {
078        Element element = super.toDsml( root );
079
080        ModifyDnRequest request = getDecorated();
081
082        // Dn
083        if ( request.getName() != null )
084        {
085            element.addAttribute( "dn", request.getName().getName() );
086        }
087
088        // NewRDN
089        if ( request.getNewRdn() != null )
090        {
091            element.addAttribute( "newrdn", request.getNewRdn().getName() );
092        }
093
094        // DeleteOldRDN
095        element.addAttribute( "deleteoldrdn", ( request.getDeleteOldRdn() ? "true" : "false" ) );
096
097        // NewSuperior
098        if ( request.getNewRdn() != null )
099        {
100            element.addAttribute( "newSuperior", request.getNewSuperior().getName() );
101        }
102
103        return element;
104    }
105
106
107    /**
108     * Get the modification's Dn
109     * 
110     * @return Returns the name.
111     */
112    public Dn getName()
113    {
114        return getDecorated().getName();
115    }
116
117
118    /**
119     * Set the modification Dn.
120     * 
121     * @param name The name to set.
122     */
123    public void setEntry( Dn name )
124    {
125        getDecorated().setName( name );
126    }
127
128
129    /**
130     * Tells if the old Rdn is to be deleted
131     * 
132     * @return Returns the deleteOldRDN.
133     */
134    public boolean isDeleteOldRDN()
135    {
136        return getDecorated().getDeleteOldRdn();
137    }
138
139
140    /**
141     * Set the flag to delete the old Rdn
142     * 
143     * @param deleteOldRDN The deleteOldRDN to set.
144     */
145    public void setDeleteOldRDN( boolean deleteOldRDN )
146    {
147        getDecorated().setDeleteOldRdn( deleteOldRDN );
148    }
149
150
151    /**
152     * Get the new Rdn
153     * 
154     * @return Returns the newRDN.
155     */
156    public Rdn getNewRDN()
157    {
158        return getDecorated().getNewRdn();
159    }
160
161
162    /**
163     * Set the new Rdn
164     * 
165     * @param newRdn The newRdn to set.
166     */
167    public void setNewRDN( Rdn newRdn )
168    {
169        getDecorated().setNewRdn( newRdn );
170    }
171
172
173    /**
174     * Get the newSuperior
175     * 
176     * @return Returns the newSuperior.
177     */
178    public Dn getNewSuperior()
179    {
180        return getDecorated().getNewSuperior();
181    }
182
183
184    /**
185     * Set the new superior
186     * 
187     * @param newSuperior The newSuperior to set.
188     */
189    public ModifyDnRequest setNewSuperior( Dn newSuperior )
190    {
191        getDecorated().setNewSuperior( newSuperior );
192
193        return this;
194    }
195
196
197    /**
198     * {@inheritDoc}
199     */
200    public MessageTypeEnum getResponseType()
201    {
202        return getDecorated().getResponseType();
203    }
204
205
206    /**
207     * {@inheritDoc}
208     */
209    public ModifyDnRequest setName( Dn name )
210    {
211        getDecorated().setName( name );
212
213        return this;
214    }
215
216
217    /**
218     * {@inheritDoc}
219     */
220    public Rdn getNewRdn()
221    {
222        return getDecorated().getNewRdn();
223    }
224
225
226    /**
227     * {@inheritDoc}
228     */
229    public ModifyDnRequest setNewRdn( Rdn newRdn )
230    {
231        getDecorated().setNewRdn( newRdn );
232
233        return this;
234    }
235
236
237    /**
238     * {@inheritDoc}
239     */
240    public boolean getDeleteOldRdn()
241    {
242        return getDecorated().getDeleteOldRdn();
243    }
244
245
246    /**
247     * {@inheritDoc}
248     */
249    public ModifyDnRequest setDeleteOldRdn( boolean deleteOldRdn )
250    {
251        getDecorated().setDeleteOldRdn( deleteOldRdn );
252
253        return this;
254    }
255
256
257    /**
258     * {@inheritDoc}
259     */
260    public boolean isMove()
261    {
262        return getDecorated().isMove();
263    }
264
265
266    /**
267     * {@inheritDoc}
268     */
269    public ModifyDnRequest setMessageId( int messageId )
270    {
271        super.setMessageId( messageId );
272
273        return this;
274    }
275
276
277    /**
278     * {@inheritDoc}
279     */
280    public ModifyDnRequest addControl( Control control )
281    {
282        return ( ModifyDnRequest ) super.addControl( control );
283    }
284
285
286    /**
287     * {@inheritDoc}
288     */
289    public ModifyDnRequest addAllControls( Control[] controls )
290    {
291        return ( ModifyDnRequest ) super.addAllControls( controls );
292    }
293
294
295    /**
296     * {@inheritDoc}
297     */
298    public ModifyDnRequest removeControl( Control control )
299    {
300        return ( ModifyDnRequest ) super.removeControl( control );
301    }
302}