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.entry.Entry; 024import org.apache.directory.api.ldap.model.exception.LdapException; 025import org.apache.directory.api.ldap.model.exception.LdapInvalidSearchFilterException; 026import org.apache.directory.api.ldap.model.filter.ExprNode; 027import org.apache.directory.api.ldap.model.filter.ScopeNode; 028import org.apache.directory.api.ldap.model.name.Dn; 029import org.apache.directory.server.i18n.I18n; 030 031 032/** 033 * Evaluates ScopeNode assertions on candidates. 034 * 035 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 036 */ 037public class ScopeEvaluator implements Evaluator 038{ 039 public ScopeEvaluator() 040 { 041 } 042 043 044 /** 045 * {@inheritDoc} 046 */ 047 public boolean evaluate( ExprNode node, Dn dn, Entry record ) throws LdapException 048 { 049 ScopeNode snode = ( ScopeNode ) node; 050 051 switch ( snode.getScope() ) 052 { 053 case OBJECT: 054 return dn.equals( snode.getBaseDn() ); 055 056 case ONELEVEL: 057 if ( dn.isDescendantOf( snode.getBaseDn() ) ) 058 { 059 return ( snode.getBaseDn().size() + 1 ) == dn.size(); 060 } 061 else 062 { 063 return false; 064 } 065 066 case SUBTREE: 067 return dn.isDescendantOf( snode.getBaseDn() ); 068 069 default: 070 throw new LdapInvalidSearchFilterException( I18n.err( I18n.ERR_247 ) ); 071 } 072 } 073}