KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > perseus > jndi > ContextImpl


1 /**
2  * Copyright (C) 2001-2004
3  * - France Telecom R&D
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Authors: P. Dechamboux, S. Chassande-Barrioz
20  *
21  */

22
23 package org.objectweb.perseus.jndi;
24
25 import java.io.Serializable JavaDoc;
26 import java.util.Enumeration JavaDoc;
27 import java.util.Hashtable JavaDoc;
28 import java.util.NoSuchElementException JavaDoc;
29
30 import javax.naming.Binding JavaDoc;
31 import javax.naming.Context JavaDoc;
32 import javax.naming.InitialContext JavaDoc;
33 import javax.naming.InvalidNameException JavaDoc;
34 import javax.naming.LinkRef JavaDoc;
35 import javax.naming.Name JavaDoc;
36 import javax.naming.NameAlreadyBoundException JavaDoc;
37 import javax.naming.NameClassPair JavaDoc;
38 import javax.naming.NameNotFoundException JavaDoc;
39 import javax.naming.NameParser JavaDoc;
40 import javax.naming.NamingEnumeration JavaDoc;
41 import javax.naming.NamingException JavaDoc;
42 import javax.naming.NotContextException JavaDoc;
43 import javax.naming.OperationNotSupportedException JavaDoc;
44 import javax.naming.RefAddr JavaDoc;
45 import javax.naming.Reference JavaDoc;
46
47 /**
48  *
49  */

50 public class ContextImpl implements Context JavaDoc, Serializable JavaDoc {
51     
52     private Hashtable JavaDoc myEnv = null;
53     private Hashtable JavaDoc bindings = new Hashtable JavaDoc();
54     static private NameParser JavaDoc myParser = new NameParserImpl();
55     private String JavaDoc compId;
56     
57     /**
58      * Constructor
59      */

60     public ContextImpl(String JavaDoc id, Hashtable JavaDoc env, Hashtable JavaDoc _bindings) throws NamingException JavaDoc {
61         if (env != null) {
62             // clone env to be able to change it.
63
myEnv = (Hashtable JavaDoc) (env.clone());
64         }
65         if (_bindings != null ) {
66             bindings = (Hashtable JavaDoc) (_bindings.clone());
67         }
68         compId = id;
69     }
70
71     /**
72      * Constructor
73      */

74     public ContextImpl(String JavaDoc id, Hashtable JavaDoc env) throws NamingException JavaDoc {
75         if (env != null) {
76             // clone env to be able to change it.
77
myEnv = (Hashtable JavaDoc) (env.clone());
78         }
79         compId = id;
80     }
81
82     /**
83      * Constructor
84      */

85     public ContextImpl(String JavaDoc id) throws NamingException JavaDoc {
86         myEnv = new Hashtable JavaDoc();
87         compId = id;
88     }
89
90     /**
91      * Constructor
92      */

93     public ContextImpl() throws NamingException JavaDoc {
94         myEnv = new Hashtable JavaDoc();
95         compId = "";
96     }
97
98     public String JavaDoc toString() {
99         String JavaDoc res = "";
100         Enumeration JavaDoc en = bindings.keys();
101         while (en.hasMoreElements()) {
102             String JavaDoc current = (String JavaDoc) en.nextElement() ;
103             res += current+"=>"+bindings.get(current) + "\n";
104         }
105         return res;
106     }
107
108     // ------------------------------------------------------------------
109
// Context implementation
110
// ------------------------------------------------------------------
111

112     /**
113      * Retrieves the named object.
114      * Delegate to the String version.
115      *
116      * @param name the name of the object to look up
117      * @return the object bound to name
118      * @throws javax.naming.NamingException if a naming exception is encountered
119      */

120     public Object JavaDoc lookup(Name JavaDoc name) throws NamingException JavaDoc {
121         // Just use the string version for now.
122
return lookup(name.toString());
123     }
124
125     /**
126      * Retrieves the named object.
127      *
128      * @param name the name of the object to look up
129      * @return the object bound to name
130      * @throws javax.naming.NamingException if a naming exception is encountered
131      */

132     public Object JavaDoc lookup(String JavaDoc name) throws NamingException JavaDoc {
133     
134         Name JavaDoc n = new DottedName(name);
135         if (n.size() < 1) {
136             // Empty name means this context
137
return this;
138         }
139
140         if (n.size() == 1) {
141             // leaf in the env tree
142
Object JavaDoc ret = bindings.get(name);
143             if (ret == null)
144                 throw new NameNotFoundException JavaDoc(name);
145             if (ret instanceof LinkRef JavaDoc) {
146                 // Handle special case of the LinkRef since I think
147
// it's not handled by std NamingManager.getObjectInstance().
148
// The name hidden in linkref is in the initial context.
149
InitialContext JavaDoc ictx = NamingManager.getInstance().getInitialContext();
150                 RefAddr JavaDoc ra = ((Reference JavaDoc) ret).get(0);
151                 ret = ictx.lookup((String JavaDoc)ra.getContent());
152             }
153             return ret;
154         } else {
155             // sub context in the env tree
156
String JavaDoc suffix = n.getSuffix(1).toString();
157             // should throw exception if sub context not found!
158
Context JavaDoc subctx = lookupCtx(n.get(0));
159             return subctx.lookup(suffix);
160         }
161     }
162     
163     /**
164      * Binds a name to an object.
165      * Delegate to the String version.
166      *
167      * @param name the name to bind; may not be empty
168      * @param obj the object to bind; possibly null
169      * @throws javax.naming.NameAlreadyBoundException if name is already bound
170      * @throws javax.naming.directory.InvalidAttributesException
171      * if object did not supply all mandatory attributes
172      * @throws javax.naming.NamingException if a naming exception is encountered
173      */

174     public void bind(Name JavaDoc name, Object JavaDoc obj) throws NamingException JavaDoc {
175         // Just use the string version for now.
176
bind(name.toString(), obj);
177     }
178
179     /**
180      * Binds a name to an object.
181      *
182      * @param name the name to bind; may not be empty
183      * @param obj the object to bind; possibly null
184      * @throws javax.naming.NameAlreadyBoundException if name is already bound
185      * @throws javax.naming.directory.InvalidAttributesException
186      * if object did not supply all mandatory attributes
187      * @throws javax.naming.NamingException if a naming exception is encountered
188      */

189     public void bind(String JavaDoc name, Object JavaDoc obj) throws NamingException JavaDoc {
190
191         Name JavaDoc n = new DottedName(name);
192         if (n.size() < 1) {
193             throw new InvalidNameException JavaDoc("CompNamingContext cannot bind empty name");
194         }
195
196         if (n.size() == 1) {
197             // leaf in the env tree
198
if (bindings.get(name) != null) {
199                 throw new NameAlreadyBoundException JavaDoc("CompNamingContext: Use rebind to bind over a name");
200             }
201             bindings.put(name, obj);
202         } else {
203             // sub context in the env tree
204
String JavaDoc suffix = n.getSuffix(1).toString();
205             // must create the subcontext first if it does not exist yet.
206
Context JavaDoc subctx;
207             try {
208                 subctx = lookupCtx(n.get(0));
209             } catch (NameNotFoundException JavaDoc e) {
210                 subctx = createSubcontext(n.get(0));
211             }
212             subctx.bind(suffix, obj);
213         }
214     }
215
216     /**
217      * Binds a name to an object, overwriting any existing binding.
218      *
219      * @param name
220      * the name to bind; may not be empty
221      * @param obj
222      * the object to bind; possibly null
223      * @throws javax.naming.directory.InvalidAttributesException
224      * if object did not supply all mandatory attributes
225      * @throws javax.naming.NamingException if a naming exception is encountered
226      *
227      */

228     public void rebind(Name JavaDoc name, Object JavaDoc obj) throws NamingException JavaDoc {
229         // Just use the string version for now.
230
rebind(name.toString(), obj);
231     }
232
233     /**
234      * Binds a name to an object, overwriting any existing binding.
235      *
236      * @param name
237      * the name to bind; may not be empty
238      * @param obj
239      * the object to bind; possibly null
240      * @throws javax.naming.directory.InvalidAttributesException
241      * if object did not supply all mandatory attributes
242      * @throws javax.naming.NamingException if a naming exception is encountered
243      */

244     public void rebind(String JavaDoc name, Object JavaDoc obj) throws NamingException JavaDoc {
245
246         Name JavaDoc n = new DottedName(name);
247         if (n.size() < 1) {
248             throw new InvalidNameException JavaDoc("CompNamingContext cannot rebind empty name");
249         }
250
251         if (n.size() == 1) {
252             // leaf in the env tree
253
bindings.put(name, obj);
254         } else {
255             // sub context in the env tree
256
String JavaDoc suffix = n.getSuffix(1).toString();
257             // must create the subcontext first if it does not exist yet.
258
Context JavaDoc subctx;
259             try {
260                 subctx = lookupCtx(n.get(0));
261             } catch (NameNotFoundException JavaDoc e) {
262                 subctx = createSubcontext(n.get(0));
263             }
264             subctx.rebind(suffix, obj);
265         }
266     }
267
268     /**
269      * Unbinds the named object.
270      * @param name
271      * the name to unbind; may not be empty
272      * @throws javax.naming.NameNotFoundException if an intermediate context does not exist
273      * @throws javax.naming.NamingException if a naming exception is encountered
274      */

275     public void unbind(Name JavaDoc name) throws NamingException JavaDoc {
276         // Just use the string version for now.
277
unbind(name.toString());
278     }
279
280     /**
281      * Unbinds the named object.
282      * @param name
283      * the name to unbind; may not be empty
284      * @throws javax.naming.NameNotFoundException if an intermediate context does not exist
285      * @throws javax.naming.NamingException if a naming exception is encountered
286      */

287     public void unbind(String JavaDoc name) throws NamingException JavaDoc {
288
289         Name JavaDoc n = new DottedName(name);
290         if (n.size() < 1) {
291             throw new InvalidNameException JavaDoc("CompNamingContext cannot unbind empty name");
292         }
293
294         if (n.size() == 1) {
295             // leaf in the env tree
296
if (bindings.get(name) == null) {
297                 throw new NameNotFoundException JavaDoc(name);
298             }
299             bindings.remove(name);
300         } else {
301             // sub context in the env tree
302
String JavaDoc suffix = n.getSuffix(1).toString();
303             // should throw exception if sub context not found!
304
Context JavaDoc subctx = lookupCtx(n.get(0));
305             subctx.unbind(suffix);
306         }
307     }
308
309     /**
310      * Binds a new name to the object bound to an old name, and unbinds
311      * the old name.
312      *
313      * @param oldName
314      * the name of the existing binding; may not be empty
315      * @param newName
316      * the name of the new binding; may not be empty
317      * @throws javax.naming.NamingException if a naming exception is encountered
318      */

319     public void rename(Name JavaDoc oldName, Name JavaDoc newName) throws NamingException JavaDoc {
320         // Just use the string version for now.
321
rename(oldName.toString(), newName.toString());
322     }
323
324     /**
325      * Binds a new name to the object bound to an old name, and unbinds
326      * the old name.
327      *
328      * @param oldName the name of the existing binding; may not be empty
329      * @param newName the name of the new binding; may not be empty
330      * @throws javax.naming.NamingException if a naming exception is encountered
331      */

332     public void rename(String JavaDoc oldName, String JavaDoc newName) throws NamingException JavaDoc {
333
334         Object JavaDoc obj = lookup(oldName);
335         rebind(newName, obj);
336         unbind(oldName);
337     }
338
339     /**
340      * Enumerates the names bound in the named context, along with the
341      * class names of objects bound to them.
342      * The contents of any subcontexts are not included.
343      *
344      * @param name the name of the context to list
345      * @return an enumeration of the names and class names of the
346      * bindings in this context. Each element of the
347      * enumeration is of type NameClassPair.
348      * @throws javax.naming.NamingException if a naming exception is encountered
349      */

350     public NamingEnumeration JavaDoc list(Name JavaDoc name) throws NamingException JavaDoc {
351         // Just use the string version for now.
352
return list(name.toString());
353     }
354
355     /**
356      * Enumerates the names bound in the named context, along with the
357      * class names of objects bound to them.
358      *
359      * @param name the name of the context to list
360      * @return an enumeration of the names and class names of the
361      * bindings in this context. Each element of the
362      * enumeration is of type NameClassPair.
363      * @throws javax.naming.NamingException if a naming exception is encountered
364      */

365     public NamingEnumeration JavaDoc list(String JavaDoc name) throws NamingException JavaDoc {
366
367         if (name.length() == 0) {
368             // List this context
369
return new ListOfNames(bindings);
370         }
371         Object JavaDoc obj = lookup(name);
372         if (obj instanceof Context JavaDoc) {
373             return ((Context JavaDoc)obj).list("");
374         } else {
375             throw new NotContextException JavaDoc(name);
376         }
377     }
378
379     /**
380      * Enumerates the names bound in the named context, along with the
381      * objects bound to them.
382      * The contents of any subcontexts are not included.
383      *
384      * If a binding is added to or removed from this context,
385      * its effect on an enumeration previously returned is undefined.
386      *
387      * @param name
388      * the name of the context to list
389      * @return an enumeration of the bindings in this context.
390      * Each element of the enumeration is of type
391      * Binding.
392      * @throws javax.naming.NamingException if a naming exception is encountered
393      *
394      */

395     public NamingEnumeration JavaDoc listBindings(Name JavaDoc name) throws NamingException JavaDoc {
396         // Just use the string version for now.
397
return listBindings(name.toString());
398     }
399
400     /**
401      * Enumerates the names bound in the named context, along with the
402      * objects bound to them.
403      *
404      * @param name the name of the context to list
405      * @return an enumeration of the bindings in this context.
406      * Each element of the enumeration is of type
407      * Binding.
408      * @throws javax.naming.NamingException if a naming exception is encountered
409      */

410     public NamingEnumeration JavaDoc listBindings(String JavaDoc name) throws NamingException JavaDoc {
411
412         if (name.length() == 0) {
413             // List this context
414
return new ListOfBindings(bindings);
415         }
416         Object JavaDoc obj = lookup(name);
417         if (obj instanceof Context JavaDoc) {
418             return ((Context JavaDoc)obj).listBindings("");
419         } else {
420             throw new NotContextException JavaDoc(name);
421         }
422     }
423     
424     /**
425      * Destroys the named context and removes it from the namespace.
426      * Not supported yet.
427      * @param name the name of the context to be destroyed; may not be empty
428      * @throws javax.naming.NamingException if a naming exception is encountered
429      */

430     public void destroySubcontext(Name JavaDoc name) throws NamingException JavaDoc {
431         // Just use the string version for now.
432
destroySubcontext(name.toString());
433     }
434
435     /**
436      * Destroys the named context and removes it from the namespace.
437      * Not supported yet.
438      * @param name the name of the context to be destroyed; may not be empty
439      * @throws javax.naming.NamingException if a naming exception is encountered
440      */

441     public void destroySubcontext(String JavaDoc name) throws NamingException JavaDoc {
442         throw new OperationNotSupportedException JavaDoc("CompNamingContext: destroySubcontext");
443     }
444
445     /**
446      * Creates and binds a new context.
447      * Creates a new context with the given name and binds it in
448      * the target context.
449      *
450      * @param name the name of the context to create; may not be empty
451      * @return the newly created context
452      *
453      * @throws javax.naming.NameAlreadyBoundException if name is already bound
454      * @throws javax.naming.directory.InvalidAttributesException
455      * if creation of the subcontext requires specification of
456      * mandatory attributes
457      * @throws javax.naming.NamingException if a naming exception is encountered
458      */

459     public Context JavaDoc createSubcontext(Name JavaDoc name) throws NamingException JavaDoc {
460         // Just use the string version for now.
461
return createSubcontext(name.toString());
462     }
463
464     /**
465      * Creates and binds a new context.
466      *
467      * @param name the name of the context to create; may not be empty
468      * @return the newly created context
469      *
470      * @throws javax.naming.NameAlreadyBoundException if name is already bound
471      * @throws javax.naming.directory.InvalidAttributesException
472      * if creation of the subcontext requires specification of
473      * mandatory attributes
474      * @throws javax.naming.NamingException if a naming exception is encountered
475      */

476     public Context JavaDoc createSubcontext(String JavaDoc name) throws NamingException JavaDoc {
477
478         Name JavaDoc n = new DottedName(name);
479         if (n.size() < 1) {
480             throw new InvalidNameException JavaDoc("CompNamingContext cannot create empty Subcontext");
481         }
482             
483         Context JavaDoc ctx = null; // returned ctx
484
if (n.size() == 1) {
485             // leaf in the env tree: create ctx and bind it in parent.
486
ctx = new ContextImpl(compId, myEnv);
487             bindings.put(name, ctx);
488         } else {
489             // as for bind, we must create first all the subcontexts
490
// if they don't exist yet.
491
String JavaDoc suffix = n.getSuffix(1).toString();
492             Context JavaDoc subctx;
493             name = n.get(0);
494             try {
495                 subctx = lookupCtx(name);
496             } catch (NameNotFoundException JavaDoc e) {
497                 subctx = createSubcontext(name);
498             }
499             ctx = subctx.createSubcontext(suffix);
500         }
501         return ctx;
502     }
503
504     /**
505      * Retrieves the named object, following links except
506      * for the terminal atomic component of the name.
507      * If the object bound to name is not a link,
508      * returns the object itself.
509      *
510      * @param name the name of the object to look up
511      * @return the object bound to name, not following the
512      * terminal link (if any).
513      * @throws javax.naming.NamingException if a naming exception is encountered
514      */

515     public Object JavaDoc lookupLink(Name JavaDoc name) throws NamingException JavaDoc {
516         // Just use the string version for now.
517
return lookupLink(name.toString());
518     }
519
520     /**
521      * Retrieves the named object, following links except
522      * for the terminal atomic component of the name.
523      * If the object bound to name is not a link,
524      * returns the object itself.
525      *
526      * @param name
527      * the name of the object to look up
528      * @return the object bound to name, not following the
529      * terminal link (if any)
530      * @throws javax.naming.NamingException if a naming exception is encountered
531      */

532     public Object JavaDoc lookupLink(String JavaDoc name) throws NamingException JavaDoc {
533
534         // To be done. For now: just return the object
535
return lookup(name);
536     }
537
538     /**
539      * Retrieves the parser associated with the named context.
540      *
541      * @param name
542      * the name of the context from which to get the parser
543      * @return a name parser that can parse compound names into their atomic
544      * components
545      * @throws javax.naming.NamingException if a naming exception is encountered
546      */

547     public NameParser JavaDoc getNameParser(Name JavaDoc name) throws NamingException JavaDoc {
548         return myParser;
549     }
550
551     /**
552      * Retrieves the parser associated with the named context.
553      *
554      * @param name
555      * the name of the context from which to get the parser
556      * @return a name parser that can parse compound names into their atomic
557      * components
558      * @throws javax.naming.NamingException if a naming exception is encountered
559      */

560     public NameParser JavaDoc getNameParser(String JavaDoc name) throws NamingException JavaDoc {
561         return myParser;
562     }
563
564     /**
565      * Composes the name of this context with a name relative to
566      * this context.
567      *
568      * @param name a name relative to this context
569      * @param prefix the name of this context relative to one of its ancestors
570      * @return the composition of prefix and name
571      * @throws javax.naming.NamingException if a naming exception is encountered
572      */

573     public Name JavaDoc composeName(Name JavaDoc name, Name JavaDoc prefix) throws NamingException JavaDoc {
574         throw new OperationNotSupportedException JavaDoc("CompNamingContext composeName");
575     }
576
577     /**
578      * Composes the name of this context with a name relative to
579      * this context: Not supported.
580      *
581      * @param name a name relative to this context
582      * @param prefix the name of this context relative to one of its ancestors
583      * @return the composition of prefix and name
584      * @throws javax.naming.NamingException if a naming exception is encountered
585      */

586     public String JavaDoc composeName(String JavaDoc name, String JavaDoc prefix) throws NamingException JavaDoc {
587         throw new OperationNotSupportedException JavaDoc("CompNamingContext composeName");
588     }
589
590     /**
591      * Adds a new environment property to the environment of this
592      * context. If the property already exists, its value is overwritten.
593      *
594      * @param propName
595      * the name of the environment property to add; may not be null
596      * @param propVal
597      * the value of the property to add; may not be null
598      * @return the previous value of the property, or null if the property was
599      * not in the environment before
600      * @throws javax.naming.NamingException if a naming exception is encountered
601      */

602     public Object JavaDoc addToEnvironment(String JavaDoc propName, Object JavaDoc propVal) throws NamingException JavaDoc {
603
604         if (myEnv == null) {
605             myEnv = new Hashtable JavaDoc();
606         }
607         return myEnv.put(propName, propVal);
608     }
609
610     /**
611      * Removes an environment property from the environment of this
612      * context.
613      *
614      * @param propName the name of the environment property to remove; may not be null
615      * @return the previous value of the property, or null if the property was
616      * not in the environment
617      * @throws javax.naming.NamingException if a naming exception is encountered
618      */

619     public Object JavaDoc removeFromEnvironment(String JavaDoc propName) throws NamingException JavaDoc {
620
621         if (myEnv == null) {
622             return null;
623         }
624         return myEnv.remove(propName);
625     }
626
627     /**
628      * Retrieves the environment in effect for this context.
629      *
630      * @return the environment of this context; never null
631      * @throws javax.naming.NamingException if a naming exception is encountered
632      */

633     public Hashtable JavaDoc getEnvironment() throws NamingException JavaDoc {
634
635         if (myEnv == null) {
636             myEnv = new Hashtable JavaDoc();
637         }
638         return myEnv;
639     }
640
641     /**
642      * Closes this context.
643      *
644      * @throws javax.naming.NamingException if a naming exception is encountered
645      */

646     public void close() throws NamingException JavaDoc {
647         myEnv = null;
648     }
649
650     /**
651      * Retrieves the full name of this context within its own namespace.
652      *
653      * @return this context's name in its own namespace; never null
654      * @throws javax.naming.OperationNotSupportedException if the naming system does
655      * not have the notion of a full name
656      * @throws javax.naming.NamingException if a naming exception is encountered
657      */

658     public String JavaDoc getNameInNamespace() throws NamingException JavaDoc {
659         // this is used today for debug only.
660
return compId;
661     }
662
663     // ------------------------------------------------------------------
664
// Private Methods
665
// ------------------------------------------------------------------
666

667     /**
668      * Find if this name is a sub context
669      */

670     private Context JavaDoc lookupCtx(String JavaDoc name) throws NamingException JavaDoc {
671         Object JavaDoc obj = bindings.get(name);
672         if (obj == null) {
673             throw new NameNotFoundException JavaDoc();
674         }
675         if (obj instanceof ContextImpl) {
676             return (Context JavaDoc) obj;
677         } else {
678             throw new NameAlreadyBoundException JavaDoc(name);
679         }
680     }
681
682     // ------------------------------------------------------------------
683
// Inner classes for enumerating lists of bindings
684
// ------------------------------------------------------------------
685

686     /**
687      * Implementation of the NamingEnumeration for list operations
688      * Each element is of type NameClassPair.
689      */

690     class ListOfNames implements NamingEnumeration JavaDoc {
691         protected Enumeration JavaDoc names;
692         protected Hashtable JavaDoc bindings;
693     
694         // Constructor. Called by list()
695
// copy bindings locally in this object and build an
696
// enumeration of the keys.
697

698         ListOfNames (Hashtable JavaDoc bindings) {
699             this.bindings = bindings;
700             this.names = bindings.keys();
701         }
702     
703         // Methods implementing NamingEnumeration interface:
704
// - hasMore
705
// - next
706
// - close
707
public boolean hasMore() throws NamingException JavaDoc {
708             return names.hasMoreElements();
709         }
710             
711         public Object JavaDoc next() throws NamingException JavaDoc {
712             String JavaDoc name = (String JavaDoc) names.nextElement();
713             String JavaDoc className = bindings.get(name).getClass().getName();
714             return new NameClassPair JavaDoc(name, className);
715         }
716     
717         public void close() {
718         }
719
720         // Methods inherited from Enumeration:
721
// - nextElement
722
// - hasMoreElements
723

724         public Object JavaDoc nextElement() {
725             try {
726                 return next();
727             } catch (NamingException JavaDoc e) {
728                 throw new NoSuchElementException JavaDoc(e.toString());
729             }
730         }
731     
732         public boolean hasMoreElements() {
733             try {
734                 return hasMore();
735             } catch (NamingException JavaDoc e) {
736                 return false;
737             }
738         }
739     }
740
741
742     /**
743      * Implementation of the NamingEnumeration for listBindings operations
744      */

745     class ListOfBindings extends ListOfNames {
746
747         ListOfBindings (Hashtable JavaDoc bindings) {
748             super(bindings);
749         }
750
751         // next() is the only different method.
752
// It returns a Binding instead of a NameClassPair
753
public Object JavaDoc next() throws NamingException JavaDoc {
754             String JavaDoc name = (String JavaDoc)names.nextElement();
755             return new Binding JavaDoc(name, this.bindings.get(name));
756         }
757     }
758 }
759
Popular Tags