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