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.api.subtree;
21
22
23 import java.util.Iterator;
24
25 import org.apache.directory.api.ldap.model.constants.SchemaConstants;
26 import org.apache.directory.api.ldap.model.entry.Attribute;
27 import org.apache.directory.api.ldap.model.exception.LdapException;
28 import org.apache.directory.api.ldap.model.filter.EqualityNode;
29 import org.apache.directory.api.ldap.model.filter.SimpleNode;
30 import org.apache.directory.api.ldap.model.schema.AttributeType;
31 import org.apache.directory.api.ldap.model.schema.SchemaManager;
32 import org.apache.directory.server.i18n.I18n;
33
34
35
36
37
38
39
40
41
42 public class RefinementLeafEvaluator
43 {
44
45 private final SchemaManager schemaManager;
46
47
48 private AttributeType OBJECT_CLASS_AT;
49
50
51
52
53
54
55
56 public RefinementLeafEvaluator( SchemaManager schemaManager )
57 {
58 this.schemaManager = schemaManager;
59 OBJECT_CLASS_AT = schemaManager.getAttributeType( SchemaConstants.OBJECT_CLASS_AT );
60 }
61
62
63
64
65
66
67
68
69
70
71
72
73 public boolean evaluate( SimpleNode node, Attribute objectClasses ) throws LdapException
74 {
75 if ( node == null )
76 {
77 throw new IllegalArgumentException( I18n.err( I18n.ERR_295 ) );
78 }
79
80 if ( !( node instanceof EqualityNode ) )
81 {
82 throw new LdapException( I18n.err( I18n.ERR_301, node ) );
83 }
84
85 if ( node.isSchemaAware() )
86 {
87 if ( !node.getAttributeType().equals( OBJECT_CLASS_AT ) )
88 {
89 throw new IllegalArgumentException( I18n.err( I18n.ERR_302, node.getAttribute() ) );
90 }
91 }
92 else if ( !node.getAttribute().equalsIgnoreCase( SchemaConstants.OBJECT_CLASS_AT ) &&
93 !node.getAttribute().equalsIgnoreCase( SchemaConstants.OBJECT_CLASS_AT_OID ) )
94 {
95 throw new IllegalArgumentException( I18n.err( I18n.ERR_302, node.getAttribute() ) );
96 }
97
98 if ( null == objectClasses )
99 {
100 throw new IllegalArgumentException( I18n.err( I18n.ERR_303 ) );
101 }
102
103 if ( !( objectClasses.isInstanceOf( OBJECT_CLASS_AT ) ) )
104 {
105 throw new IllegalArgumentException( I18n.err( I18n.ERR_304 ) );
106 }
107
108
109
110 String value = node.getValue().getString();
111
112 if ( objectClasses.contains( value ) )
113 {
114 return true;
115 }
116
117 if ( Character.isDigit( value.charAt( 0 ) ) )
118 {
119 Iterator<String> list = schemaManager.getGlobalOidRegistry().getNameSet( value ).iterator();
120
121 while ( list.hasNext() )
122 {
123 String objectClass = list.next();
124
125 if ( objectClasses.contains( objectClass ) )
126 {
127 return true;
128 }
129 }
130 }
131
132
133 return false;
134 }
135 }