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;
21
22
23 import java.util.Iterator;
24
25 import javax.naming.ServiceUnavailableException;
26
27 import org.apache.directory.server.core.entry.ClonedServerEntry;
28 import org.apache.directory.server.core.filtering.EntryFilteringCursor;
29 import org.apache.directory.server.core.interceptor.context.AddOperationContext;
30 import org.apache.directory.server.core.interceptor.context.BindOperationContext;
31 import org.apache.directory.server.core.interceptor.context.CompareOperationContext;
32 import org.apache.directory.server.core.interceptor.context.DeleteOperationContext;
33 import org.apache.directory.server.core.interceptor.context.EntryOperationContext;
34 import org.apache.directory.server.core.interceptor.context.GetMatchedNameOperationContext;
35 import org.apache.directory.server.core.interceptor.context.GetRootDSEOperationContext;
36 import org.apache.directory.server.core.interceptor.context.GetSuffixOperationContext;
37 import org.apache.directory.server.core.interceptor.context.ListOperationContext;
38 import org.apache.directory.server.core.interceptor.context.ListSuffixOperationContext;
39 import org.apache.directory.server.core.interceptor.context.LookupOperationContext;
40 import org.apache.directory.server.core.interceptor.context.ModifyOperationContext;
41 import org.apache.directory.server.core.interceptor.context.MoveAndRenameOperationContext;
42 import org.apache.directory.server.core.interceptor.context.MoveOperationContext;
43 import org.apache.directory.server.core.interceptor.context.OperationContext;
44 import org.apache.directory.server.core.interceptor.context.RenameOperationContext;
45 import org.apache.directory.server.core.interceptor.context.SearchOperationContext;
46 import org.apache.directory.server.core.interceptor.context.UnbindOperationContext;
47 import org.apache.directory.server.core.invocation.InvocationStack;
48 import org.apache.directory.shared.ldap.name.LdapDN;
49
50
51
52
53
54
55
56
57 public class DefaultOperationManager implements OperationManager
58 {
59 private final DirectoryService directoryService;
60
61
62 public DefaultOperationManager( DirectoryService directoryService )
63 {
64 this.directoryService = directoryService;
65 }
66
67
68
69
70
71 public void add( AddOperationContext opContext ) throws Exception
72 {
73 ensureStarted();
74 push( opContext );
75
76 try
77 {
78 directoryService.getInterceptorChain().add( opContext );
79 }
80 finally
81 {
82 pop();
83 }
84 }
85
86
87
88
89
90 public void bind( BindOperationContext opContext ) throws Exception
91 {
92 ensureStarted();
93 push( opContext );
94
95 try
96 {
97 directoryService.getInterceptorChain().bind( opContext );
98 }
99 finally
100 {
101 pop();
102 }
103 }
104
105
106
107
108
109 public boolean compare( CompareOperationContext opContext ) throws Exception
110 {
111 ensureStarted();
112 push( opContext );
113
114 try
115 {
116 return directoryService.getInterceptorChain().compare( opContext );
117 }
118 finally
119 {
120 pop();
121 }
122 }
123
124
125
126
127
128 public void delete( DeleteOperationContext opContext ) throws Exception
129 {
130 ensureStarted();
131 push( opContext );
132
133 try
134 {
135 directoryService.getInterceptorChain().delete( opContext );
136 }
137 finally
138 {
139 pop();
140 }
141 }
142
143
144
145
146
147 public LdapDN getMatchedName( GetMatchedNameOperationContext opContext ) throws Exception
148 {
149 ensureStarted();
150 push( opContext );
151
152 try
153 {
154 return directoryService.getInterceptorChain().getMatchedName( opContext );
155 }
156 finally
157 {
158 pop();
159 }
160 }
161
162
163
164
165
166 public ClonedServerEntry getRootDSE( GetRootDSEOperationContext opContext )
167 throws Exception
168 {
169 ensureStarted();
170 push( opContext );
171
172 try
173 {
174 return directoryService.getInterceptorChain().getRootDSE( opContext );
175 }
176 finally
177 {
178 pop();
179 }
180 }
181
182
183
184
185
186 public LdapDN getSuffix( GetSuffixOperationContext opContext ) throws Exception
187 {
188 ensureStarted();
189 push( opContext );
190
191 try
192 {
193 return directoryService.getInterceptorChain().getSuffix( opContext );
194 }
195 finally
196 {
197 pop();
198 }
199 }
200
201
202
203
204
205 public boolean hasEntry( EntryOperationContext opContext ) throws Exception
206 {
207 ensureStarted();
208 push( opContext );
209
210 try
211 {
212 return directoryService.getInterceptorChain().hasEntry( opContext );
213 }
214 finally
215 {
216 pop();
217 }
218 }
219
220
221
222
223
224 public EntryFilteringCursor list( ListOperationContext opContext ) throws Exception
225 {
226 ensureStarted();
227 push( opContext );
228
229 try
230 {
231 return directoryService.getInterceptorChain().list( opContext );
232 }
233 finally
234 {
235 pop();
236 }
237 }
238
239
240
241
242
243 public Iterator<String> listSuffixes( ListSuffixOperationContext opContext )
244 throws Exception
245 {
246 ensureStarted();
247 push( opContext );
248
249 try
250 {
251 return directoryService.getInterceptorChain().listSuffixes( opContext );
252 }
253 finally
254 {
255 pop();
256 }
257 }
258
259
260
261
262
263 public ClonedServerEntry lookup( LookupOperationContext opContext ) throws Exception
264 {
265 ensureStarted();
266 push( opContext );
267
268 try
269 {
270 return directoryService.getInterceptorChain().lookup( opContext );
271 }
272 finally
273 {
274 pop();
275 }
276 }
277
278
279
280
281
282 public void modify( ModifyOperationContext opContext ) throws Exception
283 {
284 ensureStarted();
285 push( opContext );
286
287 try
288 {
289 directoryService.getInterceptorChain().modify( opContext );
290 }
291 finally
292 {
293 pop();
294 }
295 }
296
297
298
299
300
301 public void move( MoveOperationContext opContext ) throws Exception
302 {
303 ensureStarted();
304 push( opContext );
305
306 try
307 {
308 directoryService.getInterceptorChain().move( opContext );
309 }
310 finally
311 {
312 pop();
313 }
314 }
315
316
317
318
319
320 public void moveAndRename( MoveAndRenameOperationContext opContext ) throws Exception
321 {
322 ensureStarted();
323 push( opContext );
324
325 try
326 {
327 directoryService.getInterceptorChain().moveAndRename( opContext );
328 }
329 finally
330 {
331 pop();
332 }
333 }
334
335
336
337
338
339 public void rename( RenameOperationContext opContext ) throws Exception
340 {
341 ensureStarted();
342 push( opContext );
343
344 try
345 {
346 directoryService.getInterceptorChain().rename( opContext );
347 }
348 finally
349 {
350 pop();
351 }
352 }
353
354
355
356
357
358 public EntryFilteringCursor search( SearchOperationContext opContext ) throws Exception
359 {
360 ensureStarted();
361 push( opContext );
362
363 try
364 {
365 return directoryService.getInterceptorChain().search( opContext );
366 }
367 finally
368 {
369 pop();
370 }
371 }
372
373
374
375
376
377 public void unbind( UnbindOperationContext opContext ) throws Exception
378 {
379 ensureStarted();
380 push( opContext );
381
382 try
383 {
384 directoryService.getInterceptorChain().unbind( opContext );
385 }
386 finally
387 {
388 pop();
389 }
390 }
391
392
393 private void ensureStarted() throws ServiceUnavailableException
394 {
395 if ( ! directoryService.isStarted() )
396 {
397 throw new ServiceUnavailableException( "Directory service is not started." );
398 }
399 }
400
401
402 private void pop()
403 {
404
405 InvocationStack stack = InvocationStack.getInstance();
406 stack.pop();
407 }
408
409
410 private void push( OperationContext opContext )
411 {
412
413 InvocationStack stack = InvocationStack.getInstance();
414 stack.push( opContext );
415 }
416 }