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 org.apache.directory.api.ldap.model.entry.Entry;
24 import org.apache.directory.api.ldap.model.exception.LdapException;
25 import org.apache.directory.api.ldap.model.filter.ScopeNode;
26 import org.apache.directory.api.ldap.model.message.SearchScope;
27 import org.apache.directory.server.core.api.partition.PartitionTxn;
28 import org.apache.directory.server.i18n.I18n;
29 import org.apache.directory.server.xdbm.IndexEntry;
30 import org.apache.directory.server.xdbm.ParentIdAndRdn;
31 import org.apache.directory.server.xdbm.Store;
32 import org.apache.directory.server.xdbm.search.Evaluator;
33
34
35
36
37
38
39
40 public class OneLevelScopeEvaluator<E> implements Evaluator<ScopeNode>
41 {
42
43 private final ScopeNode node;
44
45
46 private final String baseId;
47
48
49 private final boolean dereferencing;
50
51
52 private final Store db;
53
54
55
56
57
58
59
60
61 public OneLevelScopeEvaluator( Store db, ScopeNode node )
62 {
63 this.node = node;
64
65 if ( node.getScope() != SearchScope.ONELEVEL )
66 {
67 throw new IllegalStateException( I18n.err( I18n.ERR_720 ) );
68 }
69
70 this.db = db;
71 baseId = node.getBaseId();
72 dereferencing = node.getDerefAliases().isDerefInSearching() || node.getDerefAliases().isDerefAlways();
73 }
74
75
76
77
78
79
80
81
82
83
84
85 public boolean evaluate( Entry candidate ) throws LdapException
86 {
87 throw new UnsupportedOperationException( I18n.err( I18n.ERR_721 ) );
88 }
89
90
91
92
93
94 @Override
95 public boolean evaluate( PartitionTxn partitionTxn, IndexEntry<?, String> indexEntry ) throws LdapException
96 {
97 ParentIdAndRdn parent = db.getRdnIndex().reverseLookup( partitionTxn, indexEntry.getId() );
98 boolean isChild = parent.getParentId().equals( baseId );
99 Entry entry = indexEntry.getEntry();
100
101
102 if ( null == entry )
103 {
104 entry = db.fetch( partitionTxn, indexEntry.getId() );
105
106 if ( null == entry )
107 {
108
109 return false;
110 }
111
112 indexEntry.setEntry( entry );
113 }
114
115
116
117
118
119
120 if ( !dereferencing )
121 {
122 return isChild;
123 }
124
125
126
127
128
129
130 if ( null != db.getAliasIndex().reverseLookup( partitionTxn, indexEntry.getId() ) )
131 {
132 return false;
133 }
134
135
136
137
138
139 if ( isChild )
140 {
141 return true;
142 }
143
144
145
146
147
148
149
150
151
152
153
154 return db.getOneAliasIndex().forward( partitionTxn, baseId, indexEntry.getId() );
155 }
156
157
158 public ScopeNode getExpression()
159 {
160 return node;
161 }
162
163
164
165
166
167
168
169 public String getBaseId()
170 {
171 return baseId;
172 }
173
174
175
176
177
178
179
180 public boolean isDereferencing()
181 {
182 return dereferencing;
183 }
184
185
186
187
188
189 public String toString( String tabs )
190 {
191 StringBuilder sb = new StringBuilder();
192
193 sb.append( tabs ).append( "OneLevelScopEvaluator : " ).append( node ).append( "\n" );
194
195 return sb.toString();
196 }
197
198
199
200
201
202 public String toString()
203 {
204 return toString( "" );
205 }
206 }