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.jndi;
21  
22  
23  import java.util.Hashtable;
24  
25  import javax.naming.Context;
26  import javax.naming.Name;
27  import javax.naming.NameClassPair;
28  import javax.naming.NameParser;
29  import javax.naming.NamingEnumeration;
30  import javax.naming.NamingException;
31  import javax.naming.event.EventDirContext;
32  import javax.naming.event.NamingListener;
33  import javax.naming.directory.Attributes;
34  import javax.naming.directory.DirContext;
35  import javax.naming.directory.ModificationItem;
36  import javax.naming.directory.SearchControls;
37  import javax.naming.directory.SearchResult;
38  import javax.naming.ldap.Control;
39  import javax.naming.ldap.ExtendedRequest;
40  import javax.naming.ldap.ExtendedResponse;
41  import javax.naming.ldap.LdapContext;
42  
43  import org.apache.directory.shared.ldap.exception.LdapServiceUnavailableException;
44  import org.apache.directory.shared.ldap.message.ResultCodeEnum;
45  
46  import javax.naming.Binding;
47  
48  
49  /**
50   * A do nothing placeholder context whose methods throw ServiceUnavailableExceptions.
51   * JNDI provider returns this context when you perform JNDI operations against the
52   * core directory service that has been shutdown or not started.  By returning a
53   * non-null Context we prevent an unnecessary exception being thrown by
54   * {@link javax.naming.InitialContext} and any one of its subclasses.
55   *
56   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
57   * @version $Rev: 691179 $, $Date: 2008-09-02 11:58:45 +0200 (Di, 02 Sep 2008) $
58   */
59  public class DeadContext implements LdapContext, EventDirContext
60  {
61      private final String EXCEPTION_MSG = "Context operation unavailable when "
62          + "invoked after directory service core provider has been shutdown";
63  
64  
65      public Control[] getConnectControls() throws NamingException
66      {
67          throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
68      }
69  
70  
71      public Control[] getRequestControls() throws NamingException
72      {
73          throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
74      }
75  
76  
77      public Control[] getResponseControls() throws NamingException
78      {
79          throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
80      }
81  
82  
83      public void reconnect( Control[] connCtls ) throws NamingException
84      {
85          throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
86      }
87  
88  
89      public void setRequestControls( Control[] requestControls ) throws NamingException
90      {
91          throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
92      }
93  
94  
95      public ExtendedResponse extendedOperation( ExtendedRequest request ) throws NamingException
96      {
97          throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
98      }
99  
100 
101     public LdapContext newInstance( Control[] requestControls ) throws NamingException
102     {
103         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
104     }
105 
106 
107     public Attributes getAttributes( String name ) throws NamingException
108     {
109         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
110     }
111 
112 
113     public void modifyAttributes( String name, int mod_op, Attributes attrs ) throws NamingException
114     {
115         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
116     }
117 
118 
119     public Attributes getAttributes( Name name ) throws NamingException
120     {
121         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
122     }
123 
124 
125     public void modifyAttributes( Name name, int mod_op, Attributes attrs ) throws NamingException
126     {
127         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
128     }
129 
130 
131     public void modifyAttributes( Name name, ModificationItem[] mods ) throws NamingException
132     {
133         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
134     }
135 
136     public DirContext getSchema( String name ) throws NamingException
137     {
138         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
139     }
140 
141 
142     public DirContext getSchemaClassDefinition( String name ) throws NamingException
143     {
144         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
145     }
146 
147 
148     public DirContext getSchema( Name name ) throws NamingException
149     {
150         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
151     }
152 
153 
154     public DirContext getSchemaClassDefinition( Name name ) throws NamingException
155     {
156         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
157     }
158 
159 
160     public void modifyAttributes( String name, ModificationItem[] mods ) throws NamingException
161     {
162         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
163     }
164 
165 
166     public NamingEnumeration<SearchResult> search( String name, Attributes matchingAttributes ) throws NamingException
167     {
168         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
169     }
170 
171 
172     public NamingEnumeration<SearchResult> search( Name name, Attributes matchingAttributes ) throws NamingException
173     {
174         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
175     }
176 
177 
178     public void bind( String name, Object obj, Attributes attrs ) throws NamingException
179     {
180         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
181     }
182 
183 
184     public void rebind( String name, Object obj, Attributes attrs ) throws NamingException
185     {
186         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
187     }
188 
189 
190     public void bind( Name name, Object obj, Attributes attrs ) throws NamingException
191     {
192         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
193     }
194 
195 
196     public void rebind( Name name, Object obj, Attributes attrs ) throws NamingException
197     {
198         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
199     }
200 
201 
202     public Attributes getAttributes( String name, String[] attrIds ) throws NamingException
203     {
204         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
205     }
206 
207 
208     public Attributes getAttributes( Name name, String[] attrIds ) throws NamingException
209     {
210         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
211     }
212 
213 
214     public DirContext createSubcontext( String name, Attributes attrs ) throws NamingException
215     {
216         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
217     }
218 
219 
220     public DirContext createSubcontext( Name name, Attributes attrs ) throws NamingException
221     {
222         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
223     }
224 
225 
226     public NamingEnumeration<SearchResult> search( String name, Attributes matchingAttributes, String[] attributesToReturn )
227         throws NamingException
228     {
229         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
230     }
231 
232 
233     public NamingEnumeration<SearchResult> search( Name name, Attributes matchingAttributes, String[] attributesToReturn )
234         throws NamingException
235     {
236         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
237     }
238 
239 
240     public NamingEnumeration<SearchResult> search( String name, String filter, SearchControls cons ) throws NamingException
241     {
242         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
243     }
244 
245 
246     public NamingEnumeration<SearchResult> search( Name name, String filter, SearchControls cons ) throws NamingException
247     {
248         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
249     }
250 
251 
252     public NamingEnumeration<SearchResult> search( String name, String filterExpr, Object[] filterArgs, SearchControls cons )
253         throws NamingException
254     {
255         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
256     }
257 
258 
259     public NamingEnumeration<SearchResult> search( Name name, String filterExpr, Object[] filterArgs, SearchControls cons )
260         throws NamingException
261     {
262         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
263     }
264 
265 
266     public void close() throws NamingException
267     {
268         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
269     }
270 
271 
272     public String getNameInNamespace() throws NamingException
273     {
274         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
275     }
276 
277 
278     public void destroySubcontext( String name ) throws NamingException
279     {
280         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
281     }
282 
283 
284     public void unbind( String name ) throws NamingException
285     {
286         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
287     }
288 
289 
290     public Hashtable<String,Object>  getEnvironment() throws NamingException
291     {
292         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
293     }
294 
295 
296     public void destroySubcontext( Name name ) throws NamingException
297     {
298         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
299     }
300 
301 
302     public void unbind( Name name ) throws NamingException
303     {
304         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
305     }
306 
307 
308     public Object lookup( String name ) throws NamingException
309     {
310         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
311     }
312 
313 
314     public Object lookupLink( String name ) throws NamingException
315     {
316         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
317     }
318 
319 
320     public Object removeFromEnvironment( String propName ) throws NamingException
321     {
322         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
323     }
324 
325 
326     public void bind( String name, Object obj ) throws NamingException
327     {
328         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
329     }
330 
331 
332     public void rebind( String name, Object obj ) throws NamingException
333     {
334         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
335     }
336 
337 
338     public Object lookup( Name name ) throws NamingException
339     {
340         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
341     }
342 
343 
344     public Object lookupLink( Name name ) throws NamingException
345     {
346         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
347     }
348 
349 
350     public void bind( Name name, Object obj ) throws NamingException
351     {
352         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
353     }
354 
355 
356     public void rebind( Name name, Object obj ) throws NamingException
357     {
358         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
359     }
360 
361 
362     public void rename( String oldName, String newName ) throws NamingException
363     {
364         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
365     }
366 
367 
368     public Context createSubcontext( String name ) throws NamingException
369     {
370         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
371     }
372 
373 
374     public Context createSubcontext( Name name ) throws NamingException
375     {
376         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
377     }
378 
379 
380     public void rename( Name oldName, Name newName ) throws NamingException
381     {
382         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
383     }
384 
385 
386     public NameParser getNameParser( String name ) throws NamingException
387     {
388         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
389     }
390 
391 
392     public NameParser getNameParser( Name name ) throws NamingException
393     {
394         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
395     }
396 
397 
398     public NamingEnumeration<NameClassPair> list( String name ) throws NamingException
399     {
400         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
401     }
402 
403 
404     public NamingEnumeration<Binding> listBindings( String name ) throws NamingException
405     {
406         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
407     }
408 
409 
410     public NamingEnumeration<NameClassPair> list( Name name ) throws NamingException
411     {
412         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
413     }
414 
415 
416     public NamingEnumeration<Binding> listBindings( Name name ) throws NamingException
417     {
418         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
419     }
420 
421 
422     public Object addToEnvironment( String propName, Object propVal ) throws NamingException
423     {
424         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
425     }
426 
427 
428     public String composeName( String name, String prefix ) throws NamingException
429     {
430         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
431     }
432 
433 
434     public Name composeName( Name name, Name prefix ) throws NamingException
435     {
436         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
437     }
438 
439 
440     public void addNamingListener( Name name, String s, SearchControls searchControls, NamingListener namingListener )
441         throws NamingException
442     {
443         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
444     }
445 
446 
447     public void addNamingListener( String s, String s1, SearchControls searchControls, NamingListener namingListener )
448         throws NamingException
449     {
450         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
451     }
452 
453 
454     public void addNamingListener( Name name, String s, Object[] objects, SearchControls searchControls,
455         NamingListener namingListener ) throws NamingException
456     {
457         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
458     }
459 
460 
461     public void addNamingListener( String s, String s1, Object[] objects, SearchControls searchControls,
462         NamingListener namingListener ) throws NamingException
463     {
464         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
465     }
466 
467 
468     public void addNamingListener( Name name, int i, NamingListener namingListener ) throws NamingException
469     {
470         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
471     }
472 
473 
474     public void addNamingListener( String s, int i, NamingListener namingListener ) throws NamingException
475     {
476         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
477     }
478 
479 
480     public void removeNamingListener( NamingListener namingListener ) throws NamingException
481     {
482         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
483     }
484 
485 
486     public boolean targetMustExist() throws NamingException
487     {
488         throw new LdapServiceUnavailableException( EXCEPTION_MSG, ResultCodeEnum.UNAVAILABLE );
489     }
490 }