KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > uk > org > primrose > pool > standalone > PoolInitialContext


1 /**
2 * Library name : Primrose - A Java Database Connection Pool.
3 * Published by Ben Keeping, http://primrose.org.uk .
4 * Copyright (C) 2004 Ben Keeping, primrose.org.uk
5 * Email: Use "Contact Us Form" on website
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */

21
22 package uk.org.primrose.pool.standalone;
23
24 import javax.naming.*;
25 import java.util.*;
26 public class PoolInitialContext implements Context {
27     Hashtable ht = new Hashtable();
28     public PoolInitialContext() throws NamingException {
29     }
30
31     public PoolInitialContext(Hashtable env) throws NamingException {
32     }
33
34     /**
35      * Retrieves the named object.
36      * If <tt>name</tt> is empty, returns a new instance of this context
37      * (which represents the same naming context as this context, but its
38      * environment may be modified independently and it may be accessed
39      * concurrently).
40      *
41      * @param name
42      * the name of the object to look up
43      * @return the object bound to <tt>name</tt>
44      * @throws NamingException if a naming exception is encountered
45      *
46      * @see #lookup(String)
47      * @see #lookupLink(Name)
48      */

49     public Object JavaDoc lookup(Name name) throws NamingException {
50         return lookup(name.toString());
51     }
52
53     /**
54      * Retrieves the named object.
55      * See {@link #lookup(Name)} for details.
56      * @param name
57      * the name of the object to look up
58      * @return the object bound to <tt>name</tt>
59      * @throws NamingException if a naming exception is encountered
60      */

61     public Object JavaDoc lookup(String JavaDoc name) throws NamingException {
62         Object JavaDoc o = ht.get(name);
63         if (o == null) {
64             String JavaDoc[] parts = name.split("/");
65             o = ht.get(parts[parts.length-1]);
66         }
67
68         if (o == null) {
69             throw new NamingException("Cannot find JNDI resource under name : " +name);
70         }
71
72         return o;
73     }
74
75     /**
76      * Binds a name to an object.
77      * All intermediate contexts and the target context (that named by all
78      * but terminal atomic component of the name) must already exist.
79      *
80      * @param name
81      * the name to bind {
82     } may not be empty
83      * @param obj
84      * the object to bind {
85     } possibly null
86      * @throws NameAlreadyBoundException if name is already bound
87      * @throws javax.naming.directory.InvalidAttributesException
88      * if object did not supply all mandatory attributes
89      * @throws NamingException if a naming exception is encountered
90      *
91      * @see #bind(String, Object)
92      * @see #rebind(Name, Object)
93      * @see javax.naming.directory.DirContext#bind(Name, Object,
94      * javax.naming.directory.Attributes)
95      */

96     public void bind(Name name, Object JavaDoc obj) throws NamingException {
97         //bind(name.getLocalName(), obj);
98
}
99
100     /**
101      * Binds a name to an object.
102      * See {@link #bind(Name, Object)} for details.
103      *
104      * @param name
105      * the name to bind {
106     } may not be empty
107      * @param obj
108      * the object to bind {
109     } possibly null
110      * @throws NameAlreadyBoundException if name is already bound
111      * @throws javax.naming.directory.InvalidAttributesException
112      * if object did not supply all mandatory attributes
113      * @throws NamingException if a naming exception is encountered
114      */

115     public void bind(String JavaDoc name, Object JavaDoc obj) throws NamingException {
116         //System.err.println("Binding " +name +" " +obj);
117
if (ht.get(name) != null) {
118             throw new NameAlreadyBoundException(name +" is already bound under this context");
119         }
120         ht.put(name, obj);
121     }
122
123     /**
124      * Binds a name to an object, overwriting any existing binding.
125      * All intermediate contexts and the target context (that named by all
126      * but terminal atomic component of the name) must already exist.
127      *
128      * <p> If the object is a <tt>DirContext</tt>, any existing attributes
129      * associated with the name are replaced with those of the object.
130      * Otherwise, any existing attributes associated with the name remain
131      * unchanged.
132      *
133      * @param name
134      * the name to bind {
135     } may not be empty
136      * @param obj
137      * the object to bind {
138     } possibly null
139      * @throws javax.naming.directory.InvalidAttributesException
140      * if object did not supply all mandatory attributes
141      * @throws NamingException if a naming exception is encountered
142      *
143      * @see #rebind(String, Object)
144      * @see #bind(Name, Object)
145      * @see javax.naming.directory.DirContext#rebind(Name, Object,
146      * javax.naming.directory.Attributes)
147      * @see javax.naming.directory.DirContext
148      */

149     public void rebind(Name name, Object JavaDoc obj) throws NamingException {
150         //rebind(name, obj);
151
}
152
153     /**
154      * Binds a name to an object, overwriting any existing binding.
155      * See {@link #rebind(Name, Object)} for details.
156      *
157      * @param name
158      * the name to bind {
159     } may not be empty
160      * @param obj
161      * the object to bind {
162     } possibly null
163      * @throws javax.naming.directory.InvalidAttributesException
164      * if object did not supply all mandatory attributes
165      * @throws NamingException if a naming exception is encountered
166      */

167     public void rebind(String JavaDoc name, Object JavaDoc obj) throws NamingException {
168         ht.remove(obj);
169         ht.put(name, obj);
170     }
171
172     /**
173      * Unbinds the named object.
174      * Removes the terminal atomic name in <code>name</code>
175      * from the target context--that named by all but the terminal
176      * atomic part of <code>name</code>.
177      *
178      * <p> This method is idempotent.
179      * It succeeds even if the terminal atomic name
180      * is not bound in the target context, but throws
181      * <tt>NameNotFoundException</tt>
182      * if any of the intermediate contexts do not exist.
183      *
184      * <p> Any attributes associated with the name are removed.
185      * Intermediate contexts are not changed.
186      *
187      * @param name
188      * the name to unbind {
189     } may not be empty
190      * @throws NameNotFoundException if an intermediate context does not exist
191      * @throws NamingException if a naming exception is encountered
192      * @see #unbind(String)
193      */

194     public void unbind(Name name) throws NamingException {
195     }
196
197     /**
198      * Unbinds the named object.
199      * See {@link #unbind(Name)} for details.
200      *
201      * @param name
202      * the name to unbind {
203     } may not be empty
204      * @throws NameNotFoundException if an intermediate context does not exist
205      * @throws NamingException if a naming exception is encountered
206      */

207     public void unbind(String JavaDoc name) throws NamingException {
208         ht.remove(name);
209     }
210
211     /**
212      * Binds a new name to the object bound to an old name, and unbinds
213      * the old name. Both names are relative to this context.
214      * Any attributes associated with the old name become associated
215      * with the new name.
216      * Intermediate contexts of the old name are not changed.
217      *
218      * @param oldName
219      * the name of the existing binding {
220     } may not be empty
221      * @param newName
222      * the name of the new binding {
223     } may not be empty
224      * @throws NameAlreadyBoundException if <tt>newName</tt> is already bound
225      * @throws NamingException if a naming exception is encountered
226      *
227      * @see #rename(String, String)
228      * @see #bind(Name, Object)
229      * @see #rebind(Name, Object)
230      */

231     public void rename(Name oldName, Name newName) throws NamingException {
232     }
233
234     /**
235      * Binds a new name to the object bound to an old name, and unbinds
236      * the old name.
237      * See {@link #rename(Name, Name)} for details.
238      *
239      * @param oldName
240      * the name of the existing binding {
241     } may not be empty
242      * @param newName
243      * the name of the new binding {
244     } may not be empty
245      * @throws NameAlreadyBoundException if <tt>newName</tt> is already bound
246      * @throws NamingException if a naming exception is encountered
247      */

248     public void rename(String JavaDoc oldName, String JavaDoc newName) throws NamingException {
249     }
250
251     /**
252      * Enumerates the names bound in the named context, along with the
253      * class names of objects bound to them.
254      * The contents of any subcontexts are not included.
255      *
256      * <p> If a binding is added to or removed from this context,
257      * its effect on an enumeration previously returned is undefined.
258      *
259      * @param name
260      * the name of the context to list
261      * @return an enumeration of the names and class names of the
262      * bindings in this context. Each element of the
263      * enumeration is of type <tt>NameClassPair</tt>.
264      * @throws NamingException if a naming exception is encountered
265      *
266      * @see #list(String)
267      * @see #listBindings(Name)
268      * @see NameClassPair
269      */

270     public NamingEnumeration list(Name name) throws NamingException {
271         return null;
272     }
273
274     /**
275      * Enumerates the names bound in the named context, along with the
276      * class names of objects bound to them.
277      * See {@link #list(Name)} for details.
278      *
279      * @param name
280      * the name of the context to list
281      * @return an enumeration of the names and class names of the
282      * bindings in this context. Each element of the
283      * enumeration is of type <tt>NameClassPair</tt>.
284      * @throws NamingException if a naming exception is encountered
285      */

286     public NamingEnumeration list(String JavaDoc name) throws NamingException {
287         return null;
288     }
289
290     /**
291      * Enumerates the names bound in the named context, along with the
292      * objects bound to them.
293      * The contents of any subcontexts are not included.
294      *
295      * <p> If a binding is added to or removed from this context,
296      * its effect on an enumeration previously returned is undefined.
297      *
298      * @param name
299      * the name of the context to list
300      * @return an enumeration of the bindings in this context.
301      * Each element of the enumeration is of type
302      * <tt>Binding</tt>.
303      * @throws NamingException if a naming exception is encountered
304      *
305      * @see #listBindings(String)
306      * @see #list(Name)
307      * @see Binding
308       */

309     public NamingEnumeration listBindings(Name name) throws NamingException {
310         return null;
311     }
312
313     /**
314      * Enumerates the names bound in the named context, along with the
315      * objects bound to them.
316      * See {@link #listBindings(Name)} for details.
317      *
318      * @param name
319      * the name of the context to list
320      * @return an enumeration of the bindings in this context.
321      * Each element of the enumeration is of type
322      * <tt>Binding</tt>.
323      * @throws NamingException if a naming exception is encountered
324      */

325     public NamingEnumeration listBindings(String JavaDoc name) throws NamingException {
326         return null;
327     }
328
329     /**
330      * Destroys the named context and removes it from the namespace.
331      * Any attributes associated with the name are also removed.
332      * Intermediate contexts are not destroyed.
333      *
334      * <p> This method is idempotent.
335      * It succeeds even if the terminal atomic name
336      * is not bound in the target context, but throws
337      * <tt>NameNotFoundException</tt>
338      * if any of the intermediate contexts do not exist.
339      *
340      * <p> In a federated naming system, a context from one naming system
341      * may be bound to a name in another. One can subsequently
342      * look up and perform operations on the foreign context using a
343      * composite name. However, an attempt destroy the context using
344      * this composite name will fail with
345      * <tt>NotContextException</tt>, because the foreign context is not
346      * a "subcontext" of the context in which it is bound.
347      * Instead, use <tt>unbind()</tt> to remove the
348      * binding of the foreign context. Destroying the foreign context
349      * requires that the <tt>destroySubcontext()</tt> be performed
350      * on a context from the foreign context's "native" naming system.
351      *
352      * @param name
353      * the name of the context to be destroyed {
354     } may not be empty
355      * @throws NameNotFoundException if an intermediate context does not exist
356      * @throws NotContextException if the name is bound but does not name a
357      * context, or does not name a context of the appropriate type
358      * @throws ContextNotEmptyException if the named context is not empty
359      * @throws NamingException if a naming exception is encountered
360      *
361      * @see #destroySubcontext(String)
362      */

363     public void destroySubcontext(Name name) throws NamingException {
364     }
365
366     /**
367      * Destroys the named context and removes it from the namespace.
368      * See {@link #destroySubcontext(Name)} for details.
369      *
370      * @param name
371      * the name of the context to be destroyed {
372     } may not be empty
373      * @throws NameNotFoundException if an intermediate context does not exist
374      * @throws NotContextException if the name is bound but does not name a
375      * context, or does not name a context of the appropriate type
376      * @throws ContextNotEmptyException if the named context is not empty
377      * @throws NamingException if a naming exception is encountered
378      */

379     public void destroySubcontext(String JavaDoc name) throws NamingException {
380     }
381
382     /**
383      * Creates and binds a new context.
384      * Creates a new context with the given name and binds it in
385      * the target context (that named by all but terminal atomic
386      * component of the name). All intermediate contexts and the
387      * target context must already exist.
388      *
389      * @param name
390      * the name of the context to create {
391     } may not be empty
392      * @return the newly created context
393      *
394      * @throws NameAlreadyBoundException if name is already bound
395      * @throws javax.naming.directory.InvalidAttributesException
396      * if creation of the subcontext requires specification of
397      * mandatory attributes
398      * @throws NamingException if a naming exception is encountered
399      *
400      * @see #createSubcontext(String)
401      * @see javax.naming.directory.DirContext#createSubcontext
402      */

403     public Context createSubcontext(Name name) throws NamingException {
404         return null;
405     }
406
407     /**
408      * Creates and binds a new context.
409      * See {@link #createSubcontext(Name)} for details.
410      *
411      * @param name
412      * the name of the context to create {
413     } may not be empty
414      * @return the newly created context
415      *
416      * @throws NameAlreadyBoundException if name is already bound
417      * @throws javax.naming.directory.InvalidAttributesException
418      * if creation of the subcontext requires specification of
419      * mandatory attributes
420      * @throws NamingException if a naming exception is encountered
421      */

422     public Context createSubcontext(String JavaDoc name) throws NamingException {
423         return null;
424     }
425
426     /**
427      * Retrieves the named object, following links except
428      * for the terminal atomic component of the name.
429      * If the object bound to <tt>name</tt> is not a link,
430      * returns the object itself.
431      *
432      * @param name
433      * the name of the object to look up
434      * @return the object bound to <tt>name</tt>, not following the
435      * terminal link (if any).
436      * @throws NamingException if a naming exception is encountered
437      *
438      * @see #lookupLink(String)
439      */

440     public Object JavaDoc lookupLink(Name name) throws NamingException {
441         return null;
442     }
443
444     /**
445      * Retrieves the named object, following links except
446      * for the terminal atomic component of the name.
447      * See {@link #lookupLink(Name)} for details.
448      *
449      * @param name
450      * the name of the object to look up
451      * @return the object bound to <tt>name</tt>, not following the
452      * terminal link (if any)
453      * @throws NamingException if a naming exception is encountered
454      */

455     public Object JavaDoc lookupLink(String JavaDoc name) throws NamingException {
456         return null;
457     }
458
459     /**
460      * Retrieves the parser associated with the named context.
461      * In a federation of namespaces, different naming systems will
462      * parse names differently. This method allows an application
463      * to get a parser for parsing names into their atomic components
464      * using the naming convention of a particular naming system.
465      * Within any single naming system, <tt>NameParser</tt> objects
466      * returned by this method must be equal (using the <tt>equals()</tt>
467      * test).
468      *
469      * @param name
470      * the name of the context from which to get the parser
471      * @return a name parser that can parse compound names into their atomic
472      * components
473      * @throws NamingException if a naming exception is encountered
474      *
475      * @see #getNameParser(String)
476      * @see CompoundName
477      */

478     public NameParser getNameParser(Name name) throws NamingException {
479         return null;
480     }
481
482     /**
483      * Retrieves the parser associated with the named context.
484      * See {@link #getNameParser(Name)} for details.
485      *
486      * @param name
487      * the name of the context from which to get the parser
488      * @return a name parser that can parse compound names into their atomic
489      * components
490      * @throws NamingException if a naming exception is encountered
491      */

492     public NameParser getNameParser(String JavaDoc name) throws NamingException {
493         return null;
494     }
495
496     /**
497      * Composes the name of this context with a name relative to
498      * this context.
499      * Given a name (<code>name</code>) relative to this context, and
500      * the name (<code>prefix</code>) of this context relative to one
501      * of its ancestors, this method returns the composition of the
502      * two names using the syntax appropriate for the naming
503      * system(s) involved. That is, if <code>name</code> names an
504      * object relative to this context, the result is the name of the
505      * same object, but relative to the ancestor context. None of the
506      * names may be null.
507      * <p>
508      * For example, if this context is named "wiz.com" relative
509      * to the initial context, then
510      * <pre>
511      * composeName("east", "wiz.com") </pre>
512      * might return <code>"east.wiz.com"</code>.
513      * If instead this context is named "org/research", then
514      * <pre>
515      * composeName("user/jane", "org/research") </pre>
516      * might return <code>"org/research/user/jane"</code> while
517      * <pre>
518      * composeName("user/jane", "research") </pre>
519      * returns <code>"research/user/jane"</code>.
520      *
521      * @param name
522      * a name relative to this context
523      * @param prefix
524      * the name of this context relative to one of its ancestors
525      * @return the composition of <code>prefix</code> and <code>name</code>
526      * @throws NamingException if a naming exception is encountered
527      *
528      * @see #composeName(String, String)
529      */

530     public Name composeName(Name name, Name prefix) throws NamingException {
531         return null;
532     }
533
534     /**
535      * Composes the name of this context with a name relative to
536      * this context.
537      * See {@link #composeName(Name, Name)} for details.
538      *
539      * @param name
540      * a name relative to this context
541      * @param prefix
542      * the name of this context relative to one of its ancestors
543      * @return the composition of <code>prefix</code> and <code>name</code>
544      * @throws NamingException if a naming exception is encountered
545      */

546     public String JavaDoc composeName(String JavaDoc name, String JavaDoc prefix) throws NamingException {
547         return null;
548     }
549
550     /**
551      * Adds a new environment property to the environment of this
552      * context. If the property already exists, its value is overwritten.
553      * See class description for more details on environment properties.
554      *
555      * @param propName
556      * the name of the environment property to add {
557     } may not be null
558      * @param propVal
559      * the value of the property to add {
560     } may not be null
561      * @return the previous value of the property, or null if the property was
562      * not in the environment before
563      * @throws NamingException if a naming exception is encountered
564      *
565      * @see #getEnvironment()
566      * @see #removeFromEnvironment(String)
567      */

568     public Object JavaDoc addToEnvironment(String JavaDoc propName, Object JavaDoc propVal) throws NamingException {
569         return null;
570     }
571
572     /**
573      * Removes an environment property from the environment of this
574      * context. See class description for more details on environment
575      * properties.
576      *
577      * @param propName
578      * the name of the environment property to remove {
579     } may not be null
580      * @return the previous value of the property, or null if the property was
581      * not in the environment
582      * @throws NamingException if a naming exception is encountered
583      *
584      * @see #getEnvironment()
585      * @see #addToEnvironment(String, Object)
586      */

587     public Object JavaDoc removeFromEnvironment(String JavaDoc propName) throws NamingException {
588         return null;
589     }
590
591     /**
592      * Retrieves the environment in effect for this context.
593      * See class description for more details on environment properties.
594      *
595      * <p> The caller should not make any changes to the object returned:
596      * their effect on the context is undefined.
597      * The environment of this context may be changed using
598      * <tt>addToEnvironment()</tt> and <tt>removeFromEnvironment()</tt>.
599      *
600      * @return the environment of this context {
601     } never null
602      * @throws NamingException if a naming exception is encountered
603      *
604      * @see #addToEnvironment(String, Object)
605      * @see #removeFromEnvironment(String)
606      */

607     public Hashtable getEnvironment() throws NamingException {
608         return null;
609     }
610
611     /**
612      * Closes this context.
613      * This method releases this context's resources immediately, instead of
614      * waiting for them to be released automatically by the garbage collector.
615      *
616      * <p> This method is idempotent: invoking it on a context that has
617      * already been closed has no effect. Invoking any other method
618      * on a closed context is not allowed, and results in undefined behaviour.
619      *
620      * @throws NamingException if a naming exception is encountered
621      */

622     public void close() throws NamingException {
623     }
624
625     /**
626      * Retrieves the full name of this context within its own namespace.
627      *
628      * <p> Many naming services have a notion of a "full name" for objects
629      * in their respective namespaces. For example, an LDAP entry has
630      * a distinguished name, and a DNS record has a fully qualified name.
631      * This method allows the client application to retrieve this name.
632      * The string returned by this method is not a JNDI composite name
633      * and should not be passed directly to context methods.
634      * In naming systems for which the notion of full name does not
635      * make sense, <tt>OperationNotSupportedException</tt> is thrown.
636      *
637      * @return this context's name in its own namespace {
638     } never null
639      * @throws OperationNotSupportedException if the naming system does
640      * not have the notion of a full name
641      * @throws NamingException if a naming exception is encountered
642      *
643      * @since 1.3
644      */

645     public String JavaDoc getNameInNamespace() throws NamingException {
646         return null;
647     }
648
649 }
650
Popular Tags