KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > winstone > jndi > WinstoneNameEnumeration


1 /*
2  * Copyright 2003-2006 Rick Knowles <winstone-devel at lists sourceforge net>
3  * Distributed under the terms of either:
4  * - the common development and distribution license (CDDL), v1.0; or
5  * - the GNU Lesser General Public License, v2.1 or later
6  */

7 package winstone.jndi;
8
9 import java.util.Arrays JavaDoc;
10 import java.util.Enumeration JavaDoc;
11 import java.util.Map JavaDoc;
12 import java.util.Vector JavaDoc;
13
14 import javax.naming.NameClassPair JavaDoc;
15 import javax.naming.NamingEnumeration JavaDoc;
16 import javax.naming.NamingException JavaDoc;
17
18 /**
19  * Enumeration across the names/classes of the bindings in a particular context.
20  * Used by the list() method.
21  *
22  * @author <a HREF="mailto:rick_knowles@hotmail.com">Rick Knowles</a>
23  * @version $Id: WinstoneNameEnumeration.java,v 1.3 2006/02/28 07:32:48 rickknowles Exp $
24  */

25 public class WinstoneNameEnumeration implements NamingEnumeration JavaDoc {
26     private Enumeration JavaDoc nameEnumeration;
27     
28     /**
29      * Constructor
30      */

31     public WinstoneNameEnumeration(Map JavaDoc bindings) {
32         Object JavaDoc keys[] = bindings.keySet().toArray();
33         Arrays.sort(keys);
34         Vector JavaDoc nameClassPairs = new Vector JavaDoc();
35         for (int n = 0; n < keys.length; n++)
36             nameClassPairs.add(new NameClassPair JavaDoc((String JavaDoc) keys[n], bindings
37                     .get(keys[n]).getClass().getName()));
38         this.nameEnumeration = nameClassPairs.elements();
39     }
40
41     public void close() throws NamingException JavaDoc {
42         this.nameEnumeration = null;
43     }
44
45     public boolean hasMore() throws NamingException JavaDoc {
46         if (this.nameEnumeration == null)
47             throw new NamingException JavaDoc(ContainerJNDIManager.JNDI_RESOURCES
48                     .getString("WinstoneNameEnumeration.AlreadyClosed"));
49         else
50             return this.nameEnumeration.hasMoreElements();
51     }
52
53     public Object JavaDoc next() throws NamingException JavaDoc {
54         if (hasMore())
55             return this.nameEnumeration.nextElement();
56         else
57             return null;
58     }
59
60     public boolean hasMoreElements() {
61         try {
62             return hasMore();
63         } catch (NamingException JavaDoc err) {
64             return false;
65         }
66     }
67
68     public Object JavaDoc nextElement() {
69         try {
70             return next();
71         } catch (NamingException JavaDoc err) {
72             return null;
73         }
74     }
75
76 }
77
Popular Tags