View Javadoc
1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  package org.apache.directory.api.ldap.model.message.controls;
21  
22  
23  import org.apache.directory.api.ldap.model.name.Dn;
24  
25  
26  /**
27   * A simple implementation of the EntryChange response control.
28   *
29   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
30   */
31  public class EntryChangeImpl extends AbstractControl implements EntryChange
32  {
33      /** The changeType */
34      private ChangeType changeType = ChangeType.ADD;
35  
36      private long changeNumber = UNDEFINED_CHANGE_NUMBER;
37  
38      /** The previous Dn */
39      private Dn previousDn = null;
40  
41  
42      /**
43       *
44       * Creates a new instance of EntryChangeControl.
45       *
46       */
47      public EntryChangeImpl()
48      {
49          super( OID );
50      }
51  
52  
53      public ChangeType getChangeType()
54      {
55          return changeType;
56      }
57  
58  
59      public void setChangeType( ChangeType changeType )
60      {
61          this.changeType = changeType;
62      }
63  
64  
65      public Dn getPreviousDn()
66      {
67          return previousDn;
68      }
69  
70  
71      public void setPreviousDn( Dn previousDn )
72      {
73          this.previousDn = previousDn;
74      }
75  
76  
77      public long getChangeNumber()
78      {
79          return changeNumber;
80      }
81  
82  
83      public void setChangeNumber( long changeNumber )
84      {
85          this.changeNumber = changeNumber;
86      }
87  
88  
89      /**
90       * @see Object#hashCode()
91       */
92      public int hashCode()
93      {
94          int h = super.hashCode();
95  
96          h = h * 37 + Long.valueOf( changeNumber ).intValue();
97          h = h * 37 + ( changeType == null ? 0 : changeType.hashCode() );
98          h = h * 37 + ( previousDn == null ? 0 : previousDn.hashCode() );
99  
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 }