1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 package org.osjava.sj.jndi;
40
41 import java.util.Iterator;
42 import java.util.Map;
43
44 import javax.naming.Binding;
45 import javax.naming.NamingEnumeration;
46 import javax.naming.NamingException;
47
48 /***
49 * This class represents a NamingEnumeration of the bindings of a Context.
50 * Originally authored by Henri Yandell and modified to make more flexable with other
51 * Context implementations.
52 *
53 * @author Robert M. Zigweid and Henri Yandell
54 * @version $Rev: 1983 $ $Date: 2005-09-03 07:03:38 -0700 (Sat, 03 Sep 2005) $
55 */
56 public class ContextBindings implements NamingEnumeration {
57
58 /***
59 * A Map of the bindings of a Context.
60 */
61 private Map bindings = null;
62
63 /***
64 * The iterator utilized in the Enumeration
65 */
66 private Iterator iterator = null;
67
68 /***
69 * Creates a ContextBindings object based upon an a Map of names and the objects
70 * the names are bound to. If <code>table</code> is modified after instantiation
71 * of ContextBindings, behavior is undefined and should be considered invalid.
72 *
73 * @param table The table upon which the ContextBindings is based.
74 */
75 public ContextBindings(Map table) {
76 bindings = table;
77 iterator = bindings.keySet().iterator();
78 }
79
80 /***
81 * Returns <code>true</code> if there are more elements available, otherwise
82 * <code>false</code>.
83 *
84 * @return <code>true</code> if there are more elements available, otherwise <code>
85 * false</code>
86 */
87 public boolean hasMoreElements() {
88 return iterator.hasNext();
89 }
90
91 /***
92 * Returns <code>true</code> if there are more elements available, otherwise
93 * <code>false</code>.
94 *
95 * @return <code>true</code> if there are more elements available, otherwise <code>
96 * false</code>
97 * @throws NamingException if a naming exception is encountered
98 */
99 public boolean hasMore() throws NamingException {
100 if(bindings == null) {
101 throw new NamingException();
102 }
103 return hasMoreElements();
104 }
105
106 /***
107 * Returns a {@link Binding Binding} created from the next available name.
108 *
109 * @return a Binding representing the binding of the name and the object bound to the
110 * name
111 */
112 public Object nextElement() {
113 if(bindings == null) {
114 return null;
115 }
116 Object name = iterator.next();
117
118 return new Binding(name.toString(), bindings.get(name));
119 }
120
121 /***
122 * Returns a {@link Binding Binding} created from the next available name.
123 *
124 * @return a Binding representing the binding of the name and the object bound to the
125 * name
126 * @throws NamingException if a naming exception occurs
127 */
128 public Object next() throws NamingException {
129 if(bindings == null) {
130 throw new NamingException();
131 }
132 return nextElement();
133 }
134
135 /***
136 * Close the ContextBindings instance, rendering it inoperable.
137 */
138 public void close() {
139 bindings = null;
140 iterator = null;
141 }
142
143 }
144