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.ldap.message; 021 022 import org.apache.directory.shared.ldap.codec.MessageTypeEnum; 023 import org.apache.directory.shared.ldap.message.internal.InternalModifyDnRequest; 024 import org.apache.directory.shared.ldap.message.internal.InternalModifyDnResponse; 025 import org.apache.directory.shared.ldap.message.internal.InternalResultResponse; 026 import org.apache.directory.shared.ldap.name.DN; 027 import org.apache.directory.shared.ldap.name.RDN; 028 029 030 /** 031 * Lockable ModifyDNRequest implementation. 032 * 033 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 034 * @version $Rev: 918756 $ 035 */ 036 public class ModifyDnRequestImpl extends AbstractAbandonableRequest implements InternalModifyDnRequest 037 { 038 static final long serialVersionUID = 1233507339633051696L; 039 040 /** PDU's modify Dn candidate <b>entry</b> distinguished name property */ 041 private DN name; 042 043 /** PDU's <b>newrdn</b> relative distinguished name property */ 044 private RDN newRdn; 045 046 /** PDU's <b>newSuperior</b> distinguished name property */ 047 private DN newSuperior; 048 049 /** PDU's <b>deleteOldRdn</b> flag */ 050 private boolean deleteOldRdn = false; 051 052 private InternalModifyDnResponse response; 053 054 055 // ----------------------------------------------------------------------- 056 // Constructors 057 // ----------------------------------------------------------------------- 058 059 /** 060 * Creates a Lockable ModifyDnRequest implementing object used to perform a 061 * dn change on an entry potentially resulting in an entry move. 062 * 063 * @param id 064 * the seq id of this message 065 */ 066 public ModifyDnRequestImpl(final int id) 067 { 068 super( id, TYPE ); 069 } 070 071 072 // ----------------------------------------------------------------------- 073 // ModifyDnRequest Interface Method Implementations 074 // ----------------------------------------------------------------------- 075 076 /** 077 * Gets the flag which determines if the old Rdn attribute is to be removed 078 * from the entry when the new Rdn is used in its stead. This property 079 * corresponds to the <b>deleteoldrdn 080 * </p> 081 * PDU field. 082 * 083 * @return true if the old rdn is to be deleted, false if it is not 084 */ 085 public boolean getDeleteOldRdn() 086 { 087 return deleteOldRdn; 088 } 089 090 091 /** 092 * Sets the flag which determines if the old Rdn attribute is to be removed 093 * from the entry when the new Rdn is used in its stead. This property 094 * corresponds to the <b>deleteoldrdn 095 * </p> 096 * PDU field. 097 * 098 * @param deleteOldRdn 099 * true if the old rdn is to be deleted, false if it is not 100 */ 101 public void setDeleteOldRdn( boolean deleteOldRdn ) 102 { 103 this.deleteOldRdn = deleteOldRdn; 104 } 105 106 107 /** 108 * Gets whether or not this request is a DN change resulting in a move 109 * operation. Setting the newSuperior property to a non-null name, toggles 110 * this flag. 111 * 112 * @return true if the newSuperior property is <b>NOT</b> null, false 113 * otherwise. 114 */ 115 public boolean isMove() 116 { 117 return newSuperior != null; 118 } 119 120 121 /** 122 * Gets the entry's distinguished name representing the <b>entry</b> PDU 123 * field. 124 * 125 * @return the distinguished name of the entry. 126 */ 127 public DN getName() 128 { 129 return name; 130 } 131 132 133 /** 134 * Sets the entry's distinguished name representing the <b>entry</b> PDU 135 * field. 136 * 137 * @param name 138 * the distinguished name of the entry. 139 */ 140 public void setName( DN name ) 141 { 142 this.name = name; 143 } 144 145 146 /** 147 * Gets the new relative distinguished name for the entry which represents 148 * the PDU's <b>newrdn</b> field. 149 * 150 * @return the relative dn with one component 151 */ 152 public RDN getNewRdn() 153 { 154 return newRdn; 155 } 156 157 158 /** 159 * Sets the new relative distinguished name for the entry which represents 160 * the PDU's <b>newrdn</b> field. 161 * 162 * @param newRdn 163 * the relative dn with one component 164 */ 165 public void setNewRdn( RDN newRdn ) 166 { 167 this.newRdn = newRdn; 168 } 169 170 171 /** 172 * Gets the optional distinguished name of the new superior entry where the 173 * candidate entry is to be moved. This property corresponds to the PDU's 174 * <b>newSuperior</b> field. May be null representing a simple Rdn change 175 * rather than a move operation. 176 * 177 * @return the dn of the superior entry the candidate entry is moved under. 178 */ 179 public DN getNewSuperior() 180 { 181 return newSuperior; 182 } 183 184 185 /** 186 * Sets the optional distinguished name of the new superior entry where the 187 * candidate entry is to be moved. This property corresponds to the PDU's 188 * <b>newSuperior</b> field. May be null representing a simple Rdn change 189 * rather than a move operation. Setting this property to a non-null value 190 * toggles the move flag obtained via the <code>isMove</code> method. 191 * 192 * @param newSuperior 193 * the dn of the superior entry the candidate entry for DN 194 * modification is moved under. 195 */ 196 public void setNewSuperior( DN newSuperior ) 197 { 198 this.newSuperior = newSuperior; 199 } 200 201 202 // ------------------------------------------------------------------------ 203 // SingleReplyRequest Interface Method Implementations 204 // ------------------------------------------------------------------------ 205 206 /** 207 * Gets the protocol response message type for this request which produces 208 * at least one response. 209 * 210 * @return the message type of the response. 211 */ 212 public MessageTypeEnum getResponseType() 213 { 214 return RESP_TYPE; 215 } 216 217 218 /** 219 * The result containing response for this request. 220 * 221 * @return the result containing response for this request 222 */ 223 public InternalResultResponse getResultResponse() 224 { 225 if ( response == null ) 226 { 227 response = new ModifyDnResponseImpl( getMessageId() ); 228 } 229 230 return response; 231 } 232 233 234 /** 235 * Checks to see of an object equals this ModifyDnRequest stub. The equality 236 * presumes all ModifyDnRequest specific properties are the same. 237 * 238 * @param obj 239 * the object to compare with this stub 240 * @return true if the obj is equal to this stub, false otherwise 241 */ 242 public boolean equals( Object obj ) 243 { 244 if ( obj == this ) 245 { 246 return true; 247 } 248 249 if ( !super.equals( obj ) ) 250 { 251 return false; 252 } 253 254 InternalModifyDnRequest req = ( InternalModifyDnRequest ) obj; 255 256 if ( name != null && req.getName() == null ) 257 { 258 return false; 259 } 260 261 if ( name == null && req.getName() != null ) 262 { 263 return false; 264 } 265 266 if ( name != null && req.getName() != null ) 267 { 268 if ( !name.equals( req.getName() ) ) 269 { 270 return false; 271 } 272 } 273 274 if ( deleteOldRdn != req.getDeleteOldRdn() ) 275 { 276 return false; 277 } 278 279 if ( newRdn != null && req.getNewRdn() == null ) 280 { 281 return false; 282 } 283 284 if ( newRdn == null && req.getNewRdn() != null ) 285 { 286 return false; 287 } 288 289 if ( newRdn != null && req.getNewRdn() != null ) 290 { 291 if ( !newRdn.equals( req.getNewRdn() ) ) 292 { 293 return false; 294 } 295 } 296 297 if ( newSuperior != null && req.getNewSuperior() == null ) 298 { 299 return false; 300 } 301 302 if ( newSuperior == null && req.getNewSuperior() != null ) 303 { 304 return false; 305 } 306 307 if ( newSuperior != null && req.getNewSuperior() != null ) 308 { 309 if ( !newSuperior.equals( req.getNewSuperior() ) ) 310 { 311 return false; 312 } 313 } 314 315 return true; 316 } 317 318 319 /** 320 * Get a String representation of a ModifyDNRequest 321 * 322 * @return A ModifyDNRequest String 323 */ 324 public String toString() 325 { 326 327 StringBuffer sb = new StringBuffer(); 328 329 sb.append( " ModifyDN Response\n" ); 330 sb.append( " Entry : '" ).append( name ).append( "'\n" ); 331 if( newRdn != null ) 332 { 333 sb.append( " New RDN : '" ).append( newRdn.toString() ).append( "'\n" ); 334 } 335 sb.append( " Delete old RDN : " ).append( deleteOldRdn ).append( "\n" ); 336 337 if ( newSuperior != null ) 338 { 339 sb.append( " New superior : '" ).append( newSuperior.toString() ).append( "'\n" ); 340 } 341 342 return sb.toString(); 343 } 344 }