1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.ldap.server.event;
18
19
20 import javax.naming.NamingException;
21 import javax.naming.Name;
22 import javax.naming.directory.SearchControls;
23 import javax.naming.directory.Attributes;
24
25 import org.apache.ldap.common.filter.ExprNode;
26 import org.apache.ldap.common.filter.ScopeNode;
27 import org.apache.ldap.common.name.DnParser;
28
29
30 /***
31 * Evaluates ScopeNode assertions on candidates using a database.
32 *
33 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
34 * @version $Rev$
35 */
36 public class ScopeEvaluator implements Evaluator
37 {
38 private DnParser parser = null;
39
40
41 public ScopeEvaluator() throws NamingException
42 {
43 parser = new DnParser();
44 }
45
46
47 /***
48 * @see Evaluator#evaluate(ExprNode, String, Attributes)
49 */
50 public boolean evaluate( ExprNode node, String dn, Attributes record )
51 throws NamingException
52 {
53 ScopeNode snode = ( ScopeNode ) node;
54
55 switch( snode.getScope() )
56 {
57 case( SearchControls.OBJECT_SCOPE ):
58 return dn.equals( snode.getBaseDn() );
59 case( SearchControls.ONELEVEL_SCOPE ):
60 if ( dn.endsWith( snode.getBaseDn() ) )
61 {
62 Name candidateDn = parser.parse( dn );
63 Name scopeDn = parser.parse( snode.getBaseDn() );
64 return ( scopeDn.size() + 1 ) == candidateDn.size();
65 }
66 case( SearchControls.SUBTREE_SCOPE ):
67 return dn.endsWith( snode.getBaseDn() );
68 default:
69 throw new NamingException( "Unrecognized search scope!" );
70 }
71 }
72 }