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.extras.controls; 021 022import org.apache.directory.shared.ldap.model.message.controls.AbstractControl; 023 024 025/** 026 * A simple {@link SyncModifyDn} implementation to hold properties. 027 * 028 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 029 * @version $Rev$, $Date$ 030 */ 031public class SyncModifyDnImpl extends AbstractControl implements SyncModifyDn 032{ 033 /** the entry's Dn to be changed */ 034 private String entryDn; 035 036 /** target entry's new parent Dn */ 037 private String newSuperiorDn; 038 039 /** the new Rdn */ 040 private String newRdn; 041 042 /** flag to indicate whether to delete the old Rdn */ 043 private boolean deleteOldRdn = false; 044 045 private SyncModifyDnType modDnType; 046 047 048 /** 049 * Creates a new instance of SyncModifyDnImpl. 050 */ 051 public SyncModifyDnImpl() 052 { 053 super( OID ); 054 } 055 056 057 /** 058 * 059 * Creates a new instance of SyncModifyDnImpl. 060 * 061 * @param isCritical The critical flag 062 */ 063 public SyncModifyDnImpl( boolean isCritical ) 064 { 065 super( OID, isCritical ); 066 } 067 068 069 /** 070 * {@inheritDoc} 071 */ 072 public String getEntryDn() 073 { 074 return entryDn; 075 } 076 077 078 /** 079 * {@inheritDoc} 080 */ 081 public void setEntryDn( String entryDn ) 082 { 083 this.entryDn = entryDn; 084 } 085 086 087 /** 088 * {@inheritDoc} 089 */ 090 public String getNewSuperiorDn() 091 { 092 return newSuperiorDn; 093 } 094 095 096 /** 097 * {@inheritDoc} 098 */ 099 public void setNewSuperiorDn( String newSuperiorDn ) 100 { 101 this.newSuperiorDn = newSuperiorDn; 102 } 103 104 105 /** 106 * {@inheritDoc} 107 */ 108 public String getNewRdn() 109 { 110 return newRdn; 111 } 112 113 114 /** 115 * {@inheritDoc} 116 */ 117 public void setNewRdn( String newRdn ) 118 { 119 this.newRdn = newRdn; 120 } 121 122 123 /** 124 * {@inheritDoc} 125 */ 126 public boolean isDeleteOldRdn() 127 { 128 return deleteOldRdn; 129 } 130 131 132 /** 133 * {@inheritDoc} 134 */ 135 public void setDeleteOldRdn( boolean deleteOldRdn ) 136 { 137 this.deleteOldRdn = deleteOldRdn; 138 } 139 140 141 /** 142 * {@inheritDoc} 143 */ 144 public SyncModifyDnType getModDnType() 145 { 146 return modDnType; 147 } 148 149 150 /** 151 * {@inheritDoc} 152 */ 153 public void setModDnType( SyncModifyDnType modDnType ) 154 { 155 this.modDnType = modDnType; 156 } 157 158 159 160 161 /** 162 * @see Object#hashCode() 163 */ 164 @Override 165 public int hashCode() 166 { 167 int h = 37; 168 169 h = h*17 + super.hashCode(); 170 h = h*17 + modDnType.getValue(); 171 h = h*17 + ( deleteOldRdn ? 1 : 0 ); 172 173 if ( entryDn != null ) 174 { 175 h = h*17 + entryDn.hashCode(); 176 } 177 178 if ( newRdn != null ) 179 { 180 h = h*17 + newRdn.hashCode(); 181 } 182 183 if ( newSuperiorDn != null ) 184 { 185 h = h*17 + newSuperiorDn.hashCode(); 186 } 187 188 return h; 189 } 190 191 192 /** 193 * @see Object#equals(Object) 194 */ 195 @Override 196 public boolean equals( Object o ) 197 { 198 if ( !super.equals( o ) ) 199 { 200 return false; 201 } 202 203 SyncModifyDn otherControl = ( SyncModifyDn ) o; 204 205 if ( newRdn != null ) 206 { 207 if ( newRdn.equals( otherControl.getNewRdn() ) ) 208 { 209 return false; 210 } 211 } 212 else 213 { 214 if ( otherControl.getNewRdn() != null ) 215 { 216 return false; 217 } 218 } 219 220 if ( newSuperiorDn != null ) 221 { 222 if ( newSuperiorDn.equals( otherControl.getNewSuperiorDn() ) ) 223 { 224 return false; 225 } 226 } 227 else 228 { 229 if ( otherControl.getNewSuperiorDn() != null ) 230 { 231 return false; 232 } 233 } 234 235 return ( deleteOldRdn == otherControl.isDeleteOldRdn() ) && 236 ( modDnType == otherControl.getModDnType() ) && 237 ( entryDn.equals( otherControl.getEntryDn() ) && 238 ( isCritical() == otherControl.isCritical() ) ); 239 } 240 241 242 /** 243 * @see Object#toString() 244 */ 245 @Override 246 public String toString() 247 { 248 StringBuilder sb = new StringBuilder(); 249 250 sb.append( " SyncModifyDn control :\n" ); 251 sb.append( " oid : '" ).append( getOid() ).append( '\n' ); 252 sb.append( " critical : '" ).append( isCritical() ).append( '\n' ); 253 sb.append( " entryDn : '" ).append( entryDn ).append( "'\n" ); 254 sb.append( " newSuperior : '" ).append( newSuperiorDn ).append( "'\n" ); 255 sb.append( " newRdn : '" ).append( newRdn ).append( "'\n" ); 256 sb.append( " deleteOldRdn : '" ).append( deleteOldRdn ).append( "'\n" ); 257 258 return sb.toString(); 259 } 260}