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