KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > spice > jndikit > memory > MemoryNamingEnumeration


1 /*
2  * Copyright (C) The Spice Group. All rights reserved.
3  *
4  * This software is published under the terms of the Spice
5  * Software License version 1.1, a copy of which has been included
6  * with this distribution in the LICENSE.txt file.
7  */

8 package org.codehaus.spice.jndikit.memory;
9
10 import java.util.Hashtable JavaDoc;
11 import java.util.Iterator JavaDoc;
12 import java.util.NoSuchElementException JavaDoc;
13 import javax.naming.Binding JavaDoc;
14 import javax.naming.Context JavaDoc;
15 import javax.naming.NameClassPair JavaDoc;
16 import javax.naming.NamingException JavaDoc;
17 import org.codehaus.spice.jndikit.AbstractNamingEnumeration;
18 import org.codehaus.spice.jndikit.Namespace;
19
20 /**
21  * Class for building NamingEnumerations.
22  *
23  * @author Peter Donald
24  * @version $Revision: 1.1 $
25  */

26 final class MemoryNamingEnumeration
27     extends AbstractNamingEnumeration
28 {
29     protected Hashtable JavaDoc m_bindings;
30     protected Iterator JavaDoc m_names;
31     protected boolean m_returnBindings;
32
33     public MemoryNamingEnumeration( final Context JavaDoc owner,
34                                     final Namespace namespace,
35                                     final Hashtable JavaDoc bindings,
36                                     final boolean returnBindings )
37     {
38         super( owner, namespace );
39         m_returnBindings = returnBindings;
40         m_bindings = bindings;
41         m_names = m_bindings.keySet().iterator();
42     }
43
44     public boolean hasMoreElements()
45     {
46         return m_names.hasNext();
47     }
48
49     public Object JavaDoc next()
50         throws NamingException JavaDoc
51     {
52         if( !hasMore() )
53         {
54             throw new NoSuchElementException JavaDoc();
55         }
56
57         final String JavaDoc name = (String JavaDoc)m_names.next();
58         Object JavaDoc object = m_bindings.get( name );
59
60         if( !m_returnBindings )
61         {
62             return new NameClassPair JavaDoc( name, object.getClass().getName() );
63         }
64         else
65         {
66             return new Binding JavaDoc( name, resolve( name, object ) );
67         }
68     }
69
70     public void close()
71     {
72         super.close();
73         m_bindings = null;
74     }
75 }
76
Popular Tags