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 */
020 package org.apache.directory.shared.dsmlv2.request;
021
022
023 import org.apache.directory.shared.ldap.codec.MessageTypeEnum;
024 import org.apache.directory.shared.ldap.codec.modifyDn.ModifyDNRequestCodec;
025 import org.apache.directory.shared.ldap.name.DN;
026 import org.apache.directory.shared.ldap.name.RDN;
027 import org.dom4j.Element;
028
029
030 /**
031 * DSML Decorator for ModifyDNRequest
032 *
033 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
034 * @version $Rev$, $Date$
035 */
036 public class ModifyDNRequestDsml extends AbstractRequestDsml
037 {
038 /**
039 * Creates a new instance of ModifyDNRequestDsml.
040 */
041 public ModifyDNRequestDsml()
042 {
043 super( new ModifyDNRequestCodec() );
044 }
045
046
047 /**
048 * Creates a new instance of ModifyDNRequestDsml.
049 *
050 * @param ldapMessage
051 * the message to decorate
052 */
053 public ModifyDNRequestDsml( ModifyDNRequestCodec ldapMessage )
054 {
055 super( ldapMessage );
056 }
057
058
059 /**
060 * {@inheritDoc}
061 */
062 public MessageTypeEnum getMessageType()
063 {
064 return instance.getMessageType();
065 }
066
067
068 /**
069 * {@inheritDoc}
070 */
071 public Element toDsml( Element root )
072 {
073 Element element = super.toDsml( root );
074
075 ModifyDNRequestCodec request = ( ModifyDNRequestCodec ) instance;
076
077 // DN
078 if ( request.getEntry() != null )
079 {
080 element.addAttribute( "dn", request.getEntry().getName() );
081 }
082
083 // NewRDN
084 if ( request.getNewRDN() != null )
085 {
086 element.addAttribute( "newrdn", request.getNewRDN().getName() );
087 }
088
089 // DeleteOldRDN
090 element.addAttribute( "deleteoldrdn", ( request.isDeleteOldRDN() ? "true" : "false" ) );
091
092 // NewSuperior
093 if ( request.getNewRDN() != null )
094 {
095 element.addAttribute( "newSuperior", request.getNewSuperior().getName() );
096 }
097
098 return element;
099 }
100
101
102 /**
103 * Get the modification's DN
104 *
105 * @return Returns the entry.
106 */
107 public DN getEntry()
108 {
109 return ( ( ModifyDNRequestCodec ) instance ).getEntry();
110 }
111
112
113 /**
114 * Set the modification DN.
115 *
116 * @param entry The entry to set.
117 */
118 public void setEntry( DN entry )
119 {
120 ( ( ModifyDNRequestCodec ) instance ).setEntry( entry );
121 }
122
123
124 /**
125 * Tells if the old RDN is to be deleted
126 *
127 * @return Returns the deleteOldRDN.
128 */
129 public boolean isDeleteOldRDN()
130 {
131 return ( ( ModifyDNRequestCodec ) instance ).isDeleteOldRDN();
132 }
133
134
135 /**
136 * Set the flag to delete the old RDN
137 *
138 * @param deleteOldRDN The deleteOldRDN to set.
139 */
140 public void setDeleteOldRDN( boolean deleteOldRDN )
141 {
142 ( ( ModifyDNRequestCodec ) instance ).setDeleteOldRDN( deleteOldRDN );
143 }
144
145
146 /**
147 * Get the new RDN
148 *
149 * @return Returns the newRDN.
150 */
151 public RDN getNewRDN()
152 {
153 return ( ( ModifyDNRequestCodec ) instance ).getNewRDN();
154 }
155
156
157 /**
158 * Set the new RDN
159 *
160 * @param newRDN The newRDN to set.
161 */
162 public void setNewRDN( RDN newRDN )
163 {
164 ( ( ModifyDNRequestCodec ) instance ).setNewRDN( newRDN );
165 }
166
167
168 /**
169 * Get the newSuperior
170 *
171 * @return Returns the newSuperior.
172 */
173 public DN getNewSuperior()
174 {
175 return ( ( ModifyDNRequestCodec ) instance ).getNewSuperior();
176 }
177
178
179 /**
180 * Set the new superior
181 *
182 * @param newSuperior The newSuperior to set.
183 */
184 public void setNewSuperior( DN newSuperior )
185 {
186 ( ( ModifyDNRequestCodec ) instance ).setNewSuperior( newSuperior );
187 }
188 }