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