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