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      /**
54       * {@inheritDoc}
55       */
56      @Override
57      public ChangeType getChangeType()
58      {
59          return changeType;
60      }
61  
62  
63      /**
64       * {@inheritDoc}
65       */
66      @Override
67      public void setChangeType( ChangeType changeType )
68      {
69          this.changeType = changeType;
70      }
71  
72  
73      /**
74       * {@inheritDoc}
75       */
76      @Override
77      public Dn getPreviousDn()
78      {
79          return previousDn;
80      }
81  
82  
83      /**
84       * {@inheritDoc}
85       */
86      @Override
87      public void setPreviousDn( Dn previousDn )
88      {
89          this.previousDn = previousDn;
90      }
91  
92  
93      /**
94       * {@inheritDoc}
95       */
96      @Override
97      public long getChangeNumber()
98      {
99          return changeNumber;
100     }
101 
102 
103     /**
104      * {@inheritDoc}
105      */
106     @Override
107     public void setChangeNumber( long changeNumber )
108     {
109         this.changeNumber = changeNumber;
110     }
111 
112 
113     /**
114      * @see Object#hashCode()
115      */
116     @Override
117     public int hashCode()
118     {
119         int h = super.hashCode();
120 
121         h = h * 37 + ( int ) changeNumber;
122         h = h * 37 + ( changeType == null ? 0 : changeType.hashCode() );
123         h = h * 37 + ( previousDn == null ? 0 : previousDn.hashCode() );
124 
125         return h;
126     }
127 
128 
129     /**
130      * {@inheritDoc}
131      */
132     @Override
133     public boolean equals( Object o )
134     {
135         if ( !super.equals( o ) )
136         {
137             return false;
138         }
139 
140         EntryChange otherControl = ( EntryChange ) o;
141 
142         return ( changeNumber == otherControl.getChangeNumber() ) && ( changeType == otherControl.getChangeType() )
143             && ( previousDn.equals( otherControl.getPreviousDn() ) );
144     }
145 
146 
147     /**
148      * Return a String representing this EntryChangeControl.
149      */
150     @Override
151     public String toString()
152     {
153         StringBuilder sb = new StringBuilder();
154 
155         sb.append( "    Entry Change Control\n" );
156         sb.append( "        oid : " ).append( getOid() ).append( '\n' );
157         sb.append( "        critical : " ).append( isCritical() ).append( '\n' );
158         sb.append( "        changeType   : '" ).append( changeType ).append( "'\n" );
159         sb.append( "        previousDN   : '" ).append( previousDn ).append( "'\n" );
160 
161         if ( changeNumber == UNDEFINED_CHANGE_NUMBER )
162         {
163             sb.append( "        changeNumber : '" ).append( "UNDEFINED" ).append( "'\n" );
164         }
165         else
166         {
167             sb.append( "        changeNumber : '" ).append( changeNumber ).append( "'\n" );
168         }
169 
170         return sb.toString();
171     }
172 }