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