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