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.server.core.api.event;
21  
22  
23  import org.apache.directory.api.ldap.model.constants.SchemaConstants;
24  import org.apache.directory.api.ldap.model.filter.ExprNode;
25  import org.apache.directory.api.ldap.model.filter.FilterParser;
26  import org.apache.directory.api.ldap.model.filter.PresenceNode;
27  import org.apache.directory.api.ldap.model.message.AliasDerefMode;
28  import org.apache.directory.api.ldap.model.message.SearchRequest;
29  import org.apache.directory.api.ldap.model.message.SearchScope;
30  import org.apache.directory.api.ldap.model.name.Dn;
31  import org.apache.directory.api.ldap.model.schema.SchemaManager;
32  
33  
34  /**
35   * Contains the set of notification criteria required for triggering the 
36   * delivery of change notifications notifications to {@link DirectoryListener}s.
37   * 
38   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
39   */
40  public class NotificationCriteria
41  {
42      /** The scope to use (default to ONE_LEVEL) */
43      private SearchScope scope = SearchScope.ONELEVEL;
44  
45      /** The AliasderefMode to use (default to DEREF_ALWAYS) */
46      private AliasDerefMode aliasDerefMode = AliasDerefMode.DEREF_ALWAYS;
47  
48      /** The Base DN to search from (default to null) */
49      private Dn base = null;
50  
51      /** The filter to use (default to '(ObjectClass=*)') */
52      private ExprNode filter = new PresenceNode( SchemaConstants.OBJECT_CLASS_AT );
53  
54      /** The event mask to use (default to everything) */
55      private int eventMask = EventType.ALL_EVENT_TYPES_MASK;
56  
57      /** The SchemaManager */
58      private SchemaManager schemaManager;
59  
60      /**
61       * Create a new instance of a NotiticationCriteria
62       * 
63       * @param schemaManager The SchemaManager instance
64       */
65      public NotificationCriteria( SchemaManager schemaManager )
66      {
67          this.schemaManager = schemaManager;
68      }
69  
70  
71      /**
72       * Create a new instance of a NotiticationCriteria initialized with a search request
73       * 
74       * @param schemaManager The SchemaManager instance
75       * @param req The SearchRequest
76       */
77      public NotificationCriteria( SchemaManager schemaManager, SearchRequest req )
78      {
79          this.scope = req.getScope();
80          this.aliasDerefMode = req.getDerefAliases();
81          this.base = req.getBase();
82          this.filter = req.getFilter();
83          this.schemaManager = schemaManager;
84      }
85  
86  
87      /**
88       * @param scope the scope to set
89       */
90      public void setScope( SearchScope scope )
91      {
92          this.scope = scope;
93      }
94  
95  
96      /**
97       * @return the scope
98       */
99      public SearchScope getScope()
100     {
101         return scope;
102     }
103 
104 
105     /**
106      * @param aliasDerefMode the aliasDerefMode to set
107      */
108     public void setAliasDerefMode( AliasDerefMode aliasDerefMode )
109     {
110         this.aliasDerefMode = aliasDerefMode;
111     }
112 
113 
114     /**
115      * @return the aliasDerefMode
116      */
117     public AliasDerefMode getAliasDerefMode()
118     {
119         return aliasDerefMode;
120     }
121 
122 
123     /**
124      * @param base the base to set
125      */
126     public void setBase( Dn base )
127     {
128         this.base = base;
129     }
130 
131 
132     /**
133      * @return the base
134      */
135     public Dn getBase()
136     {
137         return base;
138     }
139 
140 
141     /**
142      * @param filter the filter to set
143      */
144     public void setFilter( ExprNode filter )
145     {
146         this.filter = filter;
147     }
148 
149 
150     /**
151      * Set the filter
152      * 
153      * @param filter the filter to set
154      * @throws Exception If the filter is invalid
155      */
156     public void setFilter( String filter ) throws Exception
157     {
158         this.filter = FilterParser.parse( schemaManager, filter );
159     }
160 
161 
162     /**
163      * @return the filter
164      */
165     public ExprNode getFilter()
166     {
167         return filter;
168     }
169 
170 
171     /**
172      * @param eventMask the eventMask to set
173      */
174     public void setEventMask( int eventMask )
175     {
176         this.eventMask = eventMask;
177     }
178 
179 
180     /**
181      * @param eventTypes the eventTypes to set
182      */
183     public void setEventMask( EventType... eventTypes )
184     {
185         this.eventMask = EventType.getMask( eventTypes );
186     }
187 
188 
189     /**
190      * @return the eventMask
191      */
192     public int getEventMask()
193     {
194         return eventMask;
195     }
196 
197 
198     /**
199      * {@inheritDoc}
200      */
201     public String toString()
202     {
203         StringBuilder sb = new StringBuilder();
204 
205         sb.append( "Notification criteria : " );
206         sb.append( '\'' ).append( base ).append( "', " );
207         sb.append( '\'' ).append( filter ).append( "', " );
208         sb.append( '\'' ).append( scope ).append( "', " );
209         sb.append( '\'' ).append( aliasDerefMode ).append( "', " );
210         sb.append( '\'' ).append( EventType.toString( eventMask ) ).append( '\'' );
211 
212         return sb.toString();
213     }
214 }