001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 *
019 */
020 package org.apache.directory.server.core.event;
021
022
023 import org.apache.directory.shared.ldap.constants.SchemaConstants;
024 import org.apache.directory.shared.ldap.filter.ExprNode;
025 import org.apache.directory.shared.ldap.filter.FilterParser;
026 import org.apache.directory.shared.ldap.filter.PresenceNode;
027 import org.apache.directory.shared.ldap.filter.SearchScope;
028 import org.apache.directory.shared.ldap.message.AliasDerefMode;
029 import org.apache.directory.shared.ldap.message.internal.InternalSearchRequest;
030 import org.apache.directory.shared.ldap.name.DN;
031
032
033 /**
034 * Contains the set of notification criteria required for triggering the
035 * delivery of change notifications notifications to {@link DirectoryListener}s.
036 *
037 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
038 * @version $Rev$, $Date$
039 */
040 public class NotificationCriteria
041 {
042 public static final SearchScope DEFAULT_SCOPE = SearchScope.ONELEVEL;
043 public static final AliasDerefMode DEFAULT_ALIAS_DEREF_MODE = AliasDerefMode.DEREF_ALWAYS;
044 public static final DN DEFAULT_BASE = new DN();
045 public static final ExprNode DEFAULT_FILTER = new PresenceNode( SchemaConstants.OBJECT_CLASS_AT_OID );
046
047 private SearchScope scope = DEFAULT_SCOPE;
048 private AliasDerefMode aliasDerefMode = DEFAULT_ALIAS_DEREF_MODE;
049 private DN base = DEFAULT_BASE;
050 private ExprNode filter = DEFAULT_FILTER;
051 private int eventMask = EventType.ALL_EVENT_TYPES_MASK;
052
053
054 public NotificationCriteria()
055 {
056 }
057
058
059 public NotificationCriteria( InternalSearchRequest req )
060 {
061 this.scope = req.getScope();
062 this.aliasDerefMode = req.getDerefAliases();
063 this.base = req.getBase();
064 this.filter = req.getFilter();
065 }
066
067
068 /**
069 * @param scope the scope to set
070 */
071 public void setScope( SearchScope scope )
072 {
073 this.scope = scope;
074 }
075
076
077 /**
078 * @return the scope
079 */
080 public SearchScope getScope()
081 {
082 return scope;
083 }
084
085
086 /**
087 * @param aliasDerefMode the aliasDerefMode to set
088 */
089 public void setAliasDerefMode( AliasDerefMode aliasDerefMode )
090 {
091 this.aliasDerefMode = aliasDerefMode;
092 }
093
094
095 /**
096 * @return the aliasDerefMode
097 */
098 public AliasDerefMode getAliasDerefMode()
099 {
100 return aliasDerefMode;
101 }
102
103
104 /**
105 * @param base the base to set
106 */
107 public void setBase( DN 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 DN( base );
119 }
120
121
122 /**
123 * @return the base
124 */
125 public DN 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 }