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      public void setChangesOnly( boolean changesOnly )
68      {
69          this.changesOnly = changesOnly;
70      }
71  
72  
73      public boolean isChangesOnly()
74      {
75          return changesOnly;
76      }
77  
78  
79      public void setReturnECs( boolean returnECs )
80      {
81          this.returnECs = returnECs;
82      }
83  
84  
85      public boolean isReturnECs()
86      {
87          return returnECs;
88      }
89  
90  
91      public void setChangeTypes( int changeTypes )
92      {
93          this.changeTypes = changeTypes;
94      }
95  
96  
97      public int getChangeTypes()
98      {
99          return changeTypes;
100     }
101 
102 
103     public boolean isNotificationEnabled( ChangeType changeType )
104     {
105         return ( changeType.getValue() & changeTypes ) > 0;
106     }
107 
108 
109     public void enableNotification( ChangeType changeType )
110     {
111         changeTypes |= changeType.getValue();
112     }
113 
114 
115     /**
116      * Return a String representing this PSearchControl.
117      */
118     public String toString()
119     {
120         StringBuffer sb = new StringBuffer();
121 
122         sb.append( "    Persistant Search Control\n" );
123         sb.append( "        oid : " ).append( getOid() ).append( '\n' );
124         sb.append( "        critical : " ).append( isCritical() ).append( '\n' );
125         sb.append( "        changeTypes : '" ).append( changeTypes ).append( "'\n" );
126         sb.append( "        changesOnly : '" ).append( changesOnly ).append( "'\n" );
127         sb.append( "        returnECs   : '" ).append( returnECs ).append( "'\n" );
128 
129         return sb.toString();
130     }
131 }