1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.server.core.subtree;
21
22
23 import org.apache.directory.server.core.entry.ServerAttribute;
24 import org.apache.directory.server.schema.registries.OidRegistry;
25 import org.apache.directory.shared.ldap.constants.SchemaConstants;
26 import org.apache.directory.shared.ldap.entry.EntryAttribute;
27 import org.apache.directory.shared.ldap.entry.client.ClientBinaryValue;
28 import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
29 import org.apache.directory.shared.ldap.filter.EqualityNode;
30 import org.apache.directory.shared.ldap.filter.SimpleNode;
31 import org.apache.directory.shared.ldap.util.StringTools;
32
33 import javax.naming.NamingException;
34 import java.util.Iterator;
35
36
37
38
39
40
41
42
43
44
45 public class RefinementLeafEvaluator
46 {
47
48 private final OidRegistry registry;
49
50
51
52
53
54
55
56 public RefinementLeafEvaluator(OidRegistry registry)
57 {
58 this.registry = registry;
59 }
60
61
62
63
64
65
66
67
68
69
70
71
72 public boolean evaluate( SimpleNode node, EntryAttribute objectClasses ) throws NamingException
73 {
74 if ( node == null )
75 {
76 throw new IllegalArgumentException( "node cannot be null" );
77 }
78
79 if ( !( node instanceof EqualityNode ) )
80 {
81 throw new NamingException( "Unrecognized assertion type for refinement node: " + node );
82 }
83
84 if ( !node.getAttribute().equalsIgnoreCase( SchemaConstants.OBJECT_CLASS_AT ) )
85 {
86 throw new NamingException( "Refinement leaf node attribute was " + node.getAttribute() );
87 }
88
89 if ( null == objectClasses )
90 {
91 throw new IllegalArgumentException( "objectClasses argument cannot be null" );
92 }
93
94 if ( !((ServerAttribute)objectClasses).instanceOf( SchemaConstants.OBJECT_CLASS_AT ) )
95 {
96 throw new IllegalArgumentException( "objectClasses attribute must be for ID 'objectClass'" );
97 }
98
99
100 if ( objectClasses.contains( node.getValue() ) )
101 {
102 return true;
103 }
104
105
106 String value = null;
107 if ( node.getValue() instanceof ClientStringValue )
108 {
109 value = ( String ) node.getValue().get();
110 }
111 else if ( node.getValue() instanceof ClientBinaryValue )
112 {
113 value = "#" + StringTools.toHexString( ( byte[] ) node.getValue().get() );
114 }
115 else
116 {
117 value = node.getValue().toString();
118 }
119
120 if ( Character.isDigit( value.charAt( 0 ) ) )
121 {
122 Iterator<String> list = registry.getNameSet( value ).iterator();
123
124 while ( list.hasNext() )
125 {
126 String objectClass = ( String ) list.next();
127 if ( objectClasses.contains( objectClass ) )
128 {
129 return true;
130 }
131 }
132 }
133
134
135 return false;
136 }
137 }