1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.ldap.server.subtree;
18
19
20 import org.apache.ldap.common.filter.*;
21 import org.apache.ldap.server.schema.OidRegistry;
22
23 import javax.naming.NamingException;
24 import javax.naming.directory.Attribute;
25 import java.util.Iterator;
26
27
28 /***
29 * A refinement leaf node evaluator. This evaluator checks to see if the
30 * objectClass attribute of a candidate entry is matched by a leaf node in
31 * a refinement filter expression tree.
32 *
33 * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
34 * @version $Rev$
35 */
36 public class RefinementLeafEvaluator
37 {
38 /*** an OID to name and vice versa registry */
39 private final OidRegistry registry;
40
41
42 /***
43 * Creates a refinement filter's leaf node evaluator.
44 *
45 * @param registry the OID registry used to lookup names for objectClass OIDs
46 */
47 public RefinementLeafEvaluator( OidRegistry registry )
48 {
49 this.registry = registry;
50 }
51
52
53 /***
54 * Evaluates whether or not a simple leaf node of a refinement filter selects an
55 * entry based on the entry's objectClass attribute values.
56 *
57 * @param node the leaf node of the refinement filter
58 * @param objectClasses the objectClass attribute's values
59 * @return true if the leaf node selects the entry based on objectClass values, false
60 * if it rejects the entry
61 * @throws NamingException
62 */
63 public boolean evaluate( SimpleNode node, Attribute objectClasses ) throws NamingException
64 {
65 if ( node == null )
66 {
67 throw new IllegalArgumentException( "node cannot be null" );
68 }
69 if ( node.getAssertionType() != LeafNode.EQUALITY )
70 {
71 throw new NamingException( "Unrecognized assertion type for refinement node: "
72 + node.getAssertionType() );
73 }
74 if ( ! node.getAttribute().equalsIgnoreCase( "objectclass" ) )
75 {
76 throw new NamingException( "Refinement leaf node attribute was " + node.getAttribute() );
77 }
78
79 if ( null == objectClasses )
80 {
81 throw new IllegalArgumentException( "objectClasses argument cannot be null" );
82 }
83 if ( ! objectClasses.getID().equalsIgnoreCase( "objectclass" ) )
84 {
85 throw new IllegalArgumentException( "objectClasses attribute must be for ID 'objectClass'" );
86 }
87
88
89 if ( objectClasses.contains( node.getValue() ) )
90 {
91 return true;
92 }
93
94
95 if ( Character.isDigit( node.getValue().charAt( 0 ) ) )
96 {
97 Iterator list = registry.getNameSet( node.getValue() ).iterator();
98 while ( list.hasNext() )
99 {
100 String objectClass = ( String ) list.next();
101 if ( objectClasses.contains( objectClass ) )
102 {
103 return true;
104 }
105 }
106 }
107
108
109 return false;
110 }
111 }