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.event;
21  
22  
23  import org.apache.directory.shared.ldap.constants.SchemaConstants;
24  import org.apache.directory.shared.ldap.filter.ExprNode;
25  import org.apache.directory.shared.ldap.filter.FilterParser;
26  import org.apache.directory.shared.ldap.filter.PresenceNode;
27  import org.apache.directory.shared.ldap.filter.SearchScope;
28  import org.apache.directory.shared.ldap.message.AliasDerefMode;
29  import org.apache.directory.shared.ldap.message.SearchRequest;
30  import org.apache.directory.shared.ldap.name.LdapDN;
31  
32  
33  /**
34   * Contains the set of notification criteria required for triggering the 
35   * delivery of change notifications notifications to {@link DirectoryListener}s.
36   * 
37   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
38   * @version $Rev$, $Date$
39   */
40  public class NotificationCriteria
41  {
42      public static final SearchScope DEFAULT_SCOPE = SearchScope.ONELEVEL;
43      public static final AliasDerefMode DEFAULT_ALIAS_DEREF_MODE = AliasDerefMode.DEREF_ALWAYS;
44      public static final LdapDN DEFAULT_BASE = new LdapDN();
45      public static final ExprNode DEFAULT_FILTER = new PresenceNode( SchemaConstants.OBJECT_CLASS_AT_OID );
46      
47      private SearchScope scope = DEFAULT_SCOPE;
48      private AliasDerefMode aliasDerefMode = DEFAULT_ALIAS_DEREF_MODE;
49      private LdapDN base = DEFAULT_BASE;
50      private ExprNode filter = DEFAULT_FILTER;
51      private int eventMask = EventType.ALL_EVENT_TYPES_MASK;
52      
53      
54      public NotificationCriteria()
55      {
56      }
57      
58      
59      public NotificationCriteria( SearchRequest req )
60      {
61          this.scope = req.getScope();
62          this.aliasDerefMode = req.getDerefAliases();
63          this.base = req.getBase();
64          this.filter = req.getFilter();
65      }
66      
67      
68      /**
69       * @param scope the scope to set
70       */
71      public void setScope( SearchScope scope )
72      {
73          this.scope = scope;
74      }
75      
76      
77      /**
78       * @return the scope
79       */
80      public SearchScope getScope()
81      {
82          return scope;
83      }
84  
85  
86      /**
87       * @param aliasDerefMode the aliasDerefMode to set
88       */
89      public void setAliasDerefMode( AliasDerefMode aliasDerefMode )
90      {
91          this.aliasDerefMode = aliasDerefMode;
92      }
93  
94  
95      /**
96       * @return the aliasDerefMode
97       */
98      public AliasDerefMode getAliasDerefMode()
99      {
100         return aliasDerefMode;
101     }
102 
103 
104     /**
105      * @param base the base to set
106      */
107     public void setBase( LdapDN base )
108     {
109         this.base = base;
110     }
111 
112 
113     /**
114      * @param base the base to set
115      */
116     public void setBase( String base ) throws Exception
117     {
118         this.base = new LdapDN( base );
119     }
120 
121 
122     /**
123      * @return the base
124      */
125     public LdapDN getBase()
126     {
127         return base;
128     }
129 
130 
131     /**
132      * @param filter the filter to set
133      */
134     public void setFilter( ExprNode filter )
135     {
136         this.filter = filter;
137     }
138 
139 
140     /**
141      * @param filter the filter to set
142      */
143     public void setFilter( String filter ) throws Exception
144     {
145         this.filter = FilterParser.parse( filter );
146     }
147 
148 
149     /**
150      * @return the filter
151      */
152     public ExprNode getFilter()
153     {
154         return filter;
155     }
156 
157 
158     /**
159      * @param eventMask the eventMask to set
160      */
161     public void setEventMask( int eventMask )
162     {
163         this.eventMask = eventMask;
164     }
165 
166 
167     /**
168      * @param eventMask the eventMask to set
169      */
170     public void setEventMask( EventType ...eventTypes )
171     {
172         this.eventMask = EventType.getMask( eventTypes );
173     }
174 
175 
176     /**
177      * @return the eventMask
178      */
179     public int getEventMask()
180     {
181         return eventMask;
182     }
183 }