001: /**
002: * EasyBeans
003: * Copyright (C) 2006 Bull S.A.S.
004: * Contact: easybeans@ow2.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: BindingsImpl.java 1970 2007-10-16 11:49:25Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.naming.context;
025:
026: import java.util.Enumeration;
027: import java.util.Hashtable;
028: import java.util.NoSuchElementException;
029:
030: import javax.naming.Binding;
031: import javax.naming.NamingEnumeration;
032: import javax.naming.NamingException;
033:
034: /**
035: * Implementation of the NamingEnumeration for Context.listBindings operations.
036: * @author Florent Benoit
037: */
038: public class BindingsImpl implements NamingEnumeration<Binding> {
039:
040: /**
041: * list of names.
042: */
043: private Enumeration names;
044:
045: /**
046: * List of bindings.
047: */
048: private Hashtable bindings;
049:
050: /**
051: * Constructor.
052: * @param bindings list of bindings
053: */
054: public BindingsImpl(final Hashtable bindings) {
055: this .bindings = bindings;
056: this .names = bindings.keys();
057: }
058:
059: /**
060: * It returns a Binding instead of a NameClassPair * Retrieves the next
061: * element in the enumeration.
062: * @return The possibly null element in the enumeration. null is only valid
063: * for enumerations that can return null (e.g. Attribute.getAll()
064: * returns an enumeration of attribute values, and an attribute
065: * value can be null).
066: * @throws NamingException If a naming exception is encountered while
067: * attempting to retrieve the next element. See NamingException and
068: * its subclasses for the possible naming exceptions.
069: */
070: public Binding next() throws NamingException {
071: String name = (String) names.nextElement();
072: return new Binding(name, bindings.get(name));
073: }
074:
075: /**
076: * Returns the next element of this enumeration if this enumeration object
077: * has at least one more element to provide.
078: * @return the next element of this enumeration.
079: */
080: public Binding nextElement() {
081: try {
082: return next();
083: } catch (NamingException e) {
084: throw new NoSuchElementException(e.toString());
085: }
086: }
087:
088: /**
089: * Determines whether there are any more elements in the enumeration.
090: * @return true if there is more in the enumeration ; false otherwise.
091: * @throws NamingException If a naming exception is encountered while
092: * attempting to determine whether there is another element in the
093: * enumeration.
094: */
095: public boolean hasMore() throws NamingException {
096: return names.hasMoreElements();
097: }
098:
099: /**
100: * Closes this enumeration.
101: */
102: public void close() {
103: }
104:
105: /**
106: * Tests if this enumeration contains more elements.
107: * @return <code>true</code> if and only if this enumeration object
108: * contains at least one more element to provide; <code>false</code>
109: * otherwise.
110: */
111: public boolean hasMoreElements() {
112: try {
113: return hasMore();
114: } catch (NamingException e) {
115: return false;
116: }
117: }
118:
119: }
|