View Javadoc

1   /*
2    *   Licensed to the Apache Software Foundation (ASF) under one
3    *   or more contributor license agreements.  See the NOTICE file
4    *   distributed with this work for additional information
5    *   regarding copyright ownership.  The ASF licenses this file
6    *   to you under the Apache License, Version 2.0 (the
7    *   "License"); you may not use this file except in compliance
8    *   with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *   Unless required by applicable law or agreed to in writing,
13   *   software distributed under the License is distributed on an
14   *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *   KIND, either express or implied.  See the License for the
16   *   specific language governing permissions and limitations
17   *   under the License.
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   * The default implementation of an OperationManager.
53   *
54   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
55   * @version $Rev$, $Date$
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      /* (non-Javadoc)
69       * @see org.apache.directory.server.core.OperationManager#add(org.apache.directory.server.core.interceptor.context.AddOperationContext)
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      /* (non-Javadoc)
88       * @see org.apache.directory.server.core.OperationManager#bind(org.apache.directory.server.core.interceptor.context.BindOperationContext)
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     /* (non-Javadoc)
107      * @see org.apache.directory.server.core.OperationManager#compare(org.apache.directory.server.core.interceptor.context.CompareOperationContext)
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     /* (non-Javadoc)
126      * @see org.apache.directory.server.core.OperationManager#delete(org.apache.directory.server.core.interceptor.context.DeleteOperationContext)
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     /* (non-Javadoc)
145      * @see org.apache.directory.server.core.OperationManager#getMatchedName(org.apache.directory.server.core.interceptor.context.GetMatchedNameOperationContext)
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     /* (non-Javadoc)
164      * @see org.apache.directory.server.core.OperationManager#getRootDSE(org.apache.directory.server.core.interceptor.context.GetRootDSEOperationContext)
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     /* (non-Javadoc)
184      * @see org.apache.directory.server.core.OperationManager#getSuffix(org.apache.directory.server.core.interceptor.context.GetSuffixOperationContext)
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     /* (non-Javadoc)
203      * @see org.apache.directory.server.core.OperationManager#hasEntry(org.apache.directory.server.core.interceptor.context.EntryOperationContext)
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     /* (non-Javadoc)
222      * @see org.apache.directory.server.core.OperationManager#list(org.apache.directory.server.core.interceptor.context.ListOperationContext)
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     /* (non-Javadoc)
241      * @see org.apache.directory.server.core.OperationManager#listSuffixes(org.apache.directory.server.core.interceptor.context.ListSuffixOperationContext)
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     /* (non-Javadoc)
261      * @see org.apache.directory.server.core.OperationManager#lookup(org.apache.directory.server.core.interceptor.context.LookupOperationContext)
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     /* (non-Javadoc)
280      * @see org.apache.directory.server.core.OperationManager#modify(org.apache.directory.server.core.interceptor.context.ModifyOperationContext)
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     /* (non-Javadoc)
299      * @see org.apache.directory.server.core.OperationManager#move(org.apache.directory.server.core.interceptor.context.MoveOperationContext)
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     /* (non-Javadoc)
318      * @see org.apache.directory.server.core.OperationManager#moveAndRename(org.apache.directory.server.core.interceptor.context.MoveAndRenameOperationContext)
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     /* (non-Javadoc)
337      * @see org.apache.directory.server.core.OperationManager#rename(org.apache.directory.server.core.interceptor.context.RenameOperationContext)
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     /* (non-Javadoc)
356      * @see org.apache.directory.server.core.OperationManager#search(org.apache.directory.server.core.interceptor.context.SearchOperationContext)
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     /* (non-Javadoc)
375      * @see org.apache.directory.server.core.OperationManager#unbind(org.apache.directory.server.core.interceptor.context.UnbindOperationContext)
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         // TODO - need to remove Context caller and PartitionNexusProxy from Invocations
405         InvocationStack stack = InvocationStack.getInstance();
406         stack.pop();
407     }
408 
409 
410     private void push( OperationContext opContext )
411     {
412         // TODO - need to remove Context caller and PartitionNexusProxy from Invocations
413         InvocationStack stack = InvocationStack.getInstance();
414         stack.push( opContext );
415     }
416 }