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.xdbm.search.evaluator;
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.entry.Entry;
28 import org.apache.directory.api.ldap.model.exception.LdapException;
29 import org.apache.directory.api.ldap.model.filter.PresenceNode;
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.core.api.partition.PartitionTxn;
33 import org.apache.directory.server.xdbm.IndexEntry;
34 import org.apache.directory.server.xdbm.Store;
35 import org.apache.directory.server.xdbm.search.Evaluator;
36
37
38
39
40
41
42
43
44 public class PresenceEvaluator implements Evaluator<PresenceNode>
45 {
46
47 private final PresenceNode node;
48
49
50 private final Store db;
51
52
53 private final AttributeType attributeType;
54
55
56 private final SchemaManager schemaManager;
57
58
59
60
61
62
63
64
65
66 public PresenceEvaluator( PresenceNode node, Store db, SchemaManager schemaManager )
67 {
68 this.db = db;
69 this.node = node;
70 this.schemaManager = schemaManager;
71 this.attributeType = node.getAttributeType();
72 }
73
74
75
76
77
78 @Override
79 public PresenceNode getExpression()
80 {
81 return node;
82 }
83
84
85
86
87
88 public AttributeType getAttributeType()
89 {
90 return attributeType;
91 }
92
93
94
95
96
97 @Override
98
99
100 public boolean evaluate( PartitionTxn partitionTxn, IndexEntry<?, String> indexEntry ) throws LdapException
101 {
102 Entry entry = indexEntry.getEntry();
103
104
105 if ( null == entry )
106 {
107 entry = db.fetch( partitionTxn, indexEntry.getId() );
108
109 if ( null == entry )
110 {
111
112 return false;
113 }
114
115 indexEntry.setEntry( entry );
116 }
117
118 return evaluate( entry );
119 }
120
121
122
123
124
125 @Override
126
127
128 public boolean evaluate( Entry entry ) throws LdapException
129 {
130 String attrOid = attributeType.getOid();
131
132 if ( attrOid.equals( SchemaConstants.OBJECT_CLASS_AT_OID )
133 || attrOid.equals( SchemaConstants.ENTRY_CSN_AT_OID )
134 || attrOid.equals( SchemaConstants.ENTRY_UUID_AT_OID ) )
135 {
136
137
138 return true;
139 }
140
141
142 Attribute attr = entry.get( attributeType );
143
144
145 if ( attr != null )
146 {
147 return true;
148 }
149
150
151
152
153 if ( schemaManager.getAttributeTypeRegistry().hasDescendants( attributeType ) )
154 {
155
156
157
158 Iterator<AttributeType> descendants = schemaManager.getAttributeTypeRegistry().descendants( attributeType );
159
160 do
161 {
162 AttributeType descendant = descendants.next();
163
164 attr = entry.get( descendant );
165
166 if ( attr != null )
167 {
168 return true;
169 }
170 }
171 while ( descendants.hasNext() );
172 }
173
174
175 return false;
176 }
177
178
179
180
181
182 public String toString( String tabs )
183 {
184 StringBuilder sb = new StringBuilder();
185
186 sb.append( tabs ).append( "PresenceEvaluator : " ).append( node ).append( "\n" );
187
188 return sb.toString();
189 }
190
191
192
193
194
195 public String toString()
196 {
197 return toString( "" );
198 }
199 }