KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > naming > context > BindingsImpl


1 /**
2  * EasyBeans
3  * Copyright (C) 2006 Bull S.A.S.
4  * Contact: easybeans@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: BindingsImpl.java 118 2006-03-05 19:47:51Z benoitf $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.easybeans.naming.context;
27
28 import java.util.Enumeration JavaDoc;
29 import java.util.Hashtable JavaDoc;
30 import java.util.NoSuchElementException JavaDoc;
31
32 import javax.naming.Binding JavaDoc;
33 import javax.naming.NamingEnumeration JavaDoc;
34 import javax.naming.NamingException JavaDoc;
35
36 /**
37  * Implementation of the NamingEnumeration for Context.listBindings operations.
38  * @author Florent Benoit
39  */

40 public class BindingsImpl implements NamingEnumeration JavaDoc<Binding JavaDoc> {
41
42     /**
43      * list of names.
44      */

45     private Enumeration JavaDoc names;
46
47     /**
48      * List of bindings.
49      */

50     private Hashtable JavaDoc bindings;
51
52     /**
53      * Constructor.
54      * @param bindings list of bindings
55      */

56     public BindingsImpl(final Hashtable JavaDoc bindings) {
57         this.bindings = bindings;
58         this.names = bindings.keys();
59     }
60
61     /**
62      * It returns a Binding instead of a NameClassPair * Retrieves the next
63      * element in the enumeration.
64      * @return The possibly null element in the enumeration. null is only valid
65      * for enumerations that can return null (e.g. Attribute.getAll()
66      * returns an enumeration of attribute values, and an attribute
67      * value can be null).
68      * @throws NamingException If a naming exception is encountered while
69      * attempting to retrieve the next element. See NamingException and
70      * its subclasses for the possible naming exceptions.
71      */

72     public Binding JavaDoc next() throws NamingException JavaDoc {
73         String JavaDoc name = (String JavaDoc) names.nextElement();
74         return new Binding JavaDoc(name, bindings.get(name));
75     }
76
77     /**
78      * Returns the next element of this enumeration if this enumeration object
79      * has at least one more element to provide.
80      * @return the next element of this enumeration.
81      */

82     public Binding JavaDoc nextElement() {
83         try {
84             return next();
85         } catch (NamingException JavaDoc e) {
86             throw new NoSuchElementException JavaDoc(e.toString());
87         }
88     }
89
90     /**
91      * Determines whether there are any more elements in the enumeration.
92      * @return true if there is more in the enumeration ; false otherwise.
93      * @throws NamingException If a naming exception is encountered while
94      * attempting to determine whether there is another element in the
95      * enumeration.
96      */

97     public boolean hasMore() throws NamingException JavaDoc {
98         return names.hasMoreElements();
99     }
100
101     /**
102      * Closes this enumeration.
103      */

104     public void close() {
105     }
106
107     /**
108      * Tests if this enumeration contains more elements.
109      * @return <code>true</code> if and only if this enumeration object
110      * contains at least one more element to provide; <code>false</code>
111      * otherwise.
112      */

113     public boolean hasMoreElements() {
114         try {
115             return hasMore();
116         } catch (NamingException JavaDoc e) {
117             return false;
118         }
119     }
120
121 }
122
Popular Tags