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.controls; 021 022 023import org.apache.directory.shared.ldap.model.name.Dn; 024 025 026/** 027 * A simple implementation of the EntryChange response control. 028 * 029 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 030 */ 031public class EntryChangeImpl extends AbstractControl implements EntryChange 032{ 033 /** The changeType */ 034 private ChangeType changeType = ChangeType.ADD; 035 036 private long changeNumber = UNDEFINED_CHANGE_NUMBER; 037 038 /** The previous Dn */ 039 private Dn previousDn = null; 040 041 042 /** 043 * 044 * Creates a new instance of EntryChangeControl. 045 * 046 */ 047 public EntryChangeImpl() 048 { 049 super( OID ); 050 } 051 052 053 public ChangeType getChangeType() 054 { 055 return changeType; 056 } 057 058 059 public void setChangeType( ChangeType changeType ) 060 { 061 this.changeType = changeType; 062 } 063 064 065 public Dn getPreviousDn() 066 { 067 return previousDn; 068 } 069 070 071 public void setPreviousDn( Dn previousDn ) 072 { 073 this.previousDn = previousDn; 074 } 075 076 077 public long getChangeNumber() 078 { 079 return changeNumber; 080 } 081 082 083 public void setChangeNumber( long changeNumber ) 084 { 085 this.changeNumber = changeNumber; 086 } 087 088 089 /** 090 * @see Object#hashCode() 091 */ 092 public int hashCode() 093 { 094 int h = super.hashCode(); 095 096 h = h * 37 + Long.valueOf( changeNumber ).intValue(); 097 h = h * 37 + ( changeType == null ? 0 : changeType.hashCode() ); 098 h = h * 37 + ( previousDn == null ? 0 : previousDn.hashCode() ); 099 100 return h; 101 } 102 103 104 /** 105 * {@inheritDoc} 106 */ 107 @Override 108 public boolean equals( Object o ) 109 { 110 if ( !super.equals( o ) ) 111 { 112 return false; 113 } 114 115 EntryChange otherControl = ( EntryChange ) o; 116 117 return ( changeNumber == otherControl.getChangeNumber() ) && 118 ( changeType == otherControl.getChangeType() ) && 119 ( previousDn.equals( otherControl.getPreviousDn() ) ); 120 } 121 122 123 /** 124 * Return a String representing this EntryChangeControl. 125 */ 126 public String toString() 127 { 128 StringBuffer sb = new StringBuffer(); 129 130 sb.append( " Entry Change Control\n" ); 131 sb.append( " oid : " ).append( getOid() ).append( '\n' ); 132 sb.append( " critical : " ).append( isCritical() ).append( '\n' ); 133 sb.append( " changeType : '" ).append( changeType ).append( "'\n" ); 134 sb.append( " previousDN : '" ).append( previousDn ).append( "'\n" ); 135 136 if ( changeNumber == UNDEFINED_CHANGE_NUMBER ) 137 { 138 sb.append( " changeNumber : '" ).append( "UNDEFINED" ).append( "'\n" ); 139 } 140 else 141 { 142 sb.append( " changeNumber : '" ).append( changeNumber ).append( "'\n" ); 143 } 144 145 return sb.toString(); 146 } 147}