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   *    https://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   * A persistence search object
24   * 
25   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
26   */
27  public class PersistentSearchImpl extends AbstractControl implements PersistentSearch
28  {
29  
30      /**
31       * If changesOnly is TRUE, the server MUST NOT return any existing entries
32       * that match the search criteria. Entries are only returned when they are
33       * changed (added, modified, deleted, or subject to a modifyDN operation).
34       */
35      private boolean changesOnly = true;
36  
37      /**
38       * If returnECs is TRUE, the server MUST return an Entry Change Notification
39       * control with each entry returned as the result of changes.
40       */
41      private boolean returnECs = false;
42  
43      /**
44       * As changes are made to the server, the effected entries MUST be returned
45       * to the client if they match the standard search criteria and if the
46       * operation that caused the change is included in the changeTypes field.
47       * The changeTypes field is the logical OR of one or more of these values:
48       * add    (1),
49       * delete (2),
50       * modify (4),
51       * modDN  (8).
52       */
53      private int changeTypes = CHANGE_TYPES_MAX;
54  
55  
56      /**
57       * Default constructor
58       *
59       */
60      public PersistentSearchImpl()
61      {
62          super( OID );
63      }
64  
65  
66      /**
67       * {@inheritDoc}
68       */
69      @Override
70      public void setChangesOnly( boolean changesOnly )
71      {
72          this.changesOnly = changesOnly;
73      }
74  
75  
76      /**
77       * {@inheritDoc}
78       */
79      @Override
80      public boolean isChangesOnly()
81      {
82          return changesOnly;
83      }
84  
85  
86      /**
87       * {@inheritDoc}
88       */
89      @Override
90      public void setReturnECs( boolean returnECs )
91      {
92          this.returnECs = returnECs;
93      }
94  
95  
96      /**
97       * {@inheritDoc}
98       */
99      @Override
100     public boolean isReturnECs()
101     {
102         return returnECs;
103     }
104 
105 
106     /**
107      * {@inheritDoc}
108      */
109     @Override
110     public void setChangeTypes( int changeTypes )
111     {
112         this.changeTypes = changeTypes;
113     }
114 
115 
116     /**
117      * {@inheritDoc}
118      */
119     @Override
120     public int getChangeTypes()
121     {
122         return changeTypes;
123     }
124 
125 
126     /**
127      * {@inheritDoc}
128      */
129     @Override
130     public boolean isNotificationEnabled( ChangeType changeType )
131     {
132         return ( changeType.getValue() & changeTypes ) > 0;
133     }
134 
135 
136     /**
137      * {@inheritDoc}
138      */
139     @Override
140     public void enableNotification( ChangeType changeType )
141     {
142         changeTypes |= changeType.getValue();
143     }
144 
145 
146     /**
147      * {@inheritDoc}
148      */
149     @Override
150     public void disableNotification( ChangeType changeType )
151     {
152         changeTypes &= ~changeType.getValue();
153     }
154 
155 
156     /**
157      * @see Object#hashCode()
158      */
159     @Override
160     public int hashCode()
161     {
162         int h = super.hashCode();
163 
164         h = h * 37 + ( changesOnly ? 1 : 0 );
165         h = h * 37 + ( returnECs ? 1 : 0 );
166         h = h * 37 + changeTypes;
167 
168         return h;
169     }
170 
171 
172     /**
173      * @see Object#equals(Object)
174      */
175     @Override
176     public boolean equals( Object other )
177     {
178         if ( this == other )
179         {
180             return true;
181         }
182 
183         if ( !( other instanceof PersistentSearch ) )
184         {
185             return false;
186         }
187         
188         PersistentSearch otherControl = ( PersistentSearch ) other;
189 
190         return super.equals( other ) 
191             && ( changesOnly == otherControl.isChangesOnly() ) 
192             && ( returnECs == otherControl.isReturnECs() ) 
193             && ( changeTypes == otherControl.getChangeTypes() );
194     }
195 
196 
197     /**
198      * Return a String representing this PSearchControl.
199      */
200     @Override
201     public String toString()
202     {
203         StringBuilder sb = new StringBuilder();
204 
205         sb.append( "    Persistant Search Control\n" );
206         sb.append( "        oid : " ).append( getOid() ).append( '\n' );
207         sb.append( "        critical : " ).append( isCritical() ).append( '\n' );
208         sb.append( "        changeTypes : '" ).append( changeTypes ).append( "'\n" );
209         sb.append( "        changesOnly : '" ).append( changesOnly ).append( "'\n" );
210         sb.append( "        returnECs   : '" ).append( returnECs ).append( "'\n" );
211 
212         return sb.toString();
213     }
214 }