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