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 */ 020package org.apache.directory.server.core.api.event; 021 022 023import org.apache.directory.api.ldap.model.constants.SchemaConstants; 024import org.apache.directory.api.ldap.model.filter.ExprNode; 025import org.apache.directory.api.ldap.model.filter.FilterParser; 026import org.apache.directory.api.ldap.model.filter.PresenceNode; 027import org.apache.directory.api.ldap.model.message.AliasDerefMode; 028import org.apache.directory.api.ldap.model.message.SearchRequest; 029import org.apache.directory.api.ldap.model.message.SearchScope; 030import org.apache.directory.api.ldap.model.name.Dn; 031import org.apache.directory.api.ldap.model.schema.SchemaManager; 032 033 034/** 035 * Contains the set of notification criteria required for triggering the 036 * delivery of change notifications notifications to {@link DirectoryListener}s. 037 * 038 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 039 */ 040public class NotificationCriteria 041{ 042 /** The scope to use (default to ONE_LEVEL) */ 043 private SearchScope scope = SearchScope.ONELEVEL; 044 045 /** The AliasderefMode to use (default to DEREF_ALWAYS) */ 046 private AliasDerefMode aliasDerefMode = AliasDerefMode.DEREF_ALWAYS; 047 048 /** The Base DN to search from (default to null) */ 049 private Dn base = null; 050 051 /** The filter to use (default to '(ObjectClass=*)') */ 052 private ExprNode filter = new PresenceNode( SchemaConstants.OBJECT_CLASS_AT ); 053 054 /** The event mask to use (default to everything) */ 055 private int eventMask = EventType.ALL_EVENT_TYPES_MASK; 056 057 /** The SchemaManager */ 058 private SchemaManager schemaManager; 059 060 /** 061 * Create a new instance of a NotiticationCriteria 062 * 063 * @param schemaManager The SchemaManager instance 064 */ 065 public NotificationCriteria( SchemaManager schemaManager ) 066 { 067 this.schemaManager = schemaManager; 068 } 069 070 071 /** 072 * Create a new instance of a NotiticationCriteria initialized with a search request 073 * 074 * @param schemaManager The SchemaManager instance 075 * @param req The SearchRequest 076 */ 077 public NotificationCriteria( SchemaManager schemaManager, SearchRequest req ) 078 { 079 this.scope = req.getScope(); 080 this.aliasDerefMode = req.getDerefAliases(); 081 this.base = req.getBase(); 082 this.filter = req.getFilter(); 083 this.schemaManager = schemaManager; 084 } 085 086 087 /** 088 * @param scope the scope to set 089 */ 090 public void setScope( SearchScope scope ) 091 { 092 this.scope = scope; 093 } 094 095 096 /** 097 * @return the scope 098 */ 099 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}