1 8 package org.codehaus.spice.jndikit.memory; 9 10 import java.util.Hashtable ; 11 import java.util.Iterator ; 12 import java.util.NoSuchElementException ; 13 import javax.naming.Binding ; 14 import javax.naming.Context ; 15 import javax.naming.NameClassPair ; 16 import javax.naming.NamingException ; 17 import org.codehaus.spice.jndikit.AbstractNamingEnumeration; 18 import org.codehaus.spice.jndikit.Namespace; 19 20 26 final class MemoryNamingEnumeration 27 extends AbstractNamingEnumeration 28 { 29 protected Hashtable m_bindings; 30 protected Iterator m_names; 31 protected boolean m_returnBindings; 32 33 public MemoryNamingEnumeration( final Context owner, 34 final Namespace namespace, 35 final Hashtable 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 next() 50 throws NamingException 51 { 52 if( !hasMore() ) 53 { 54 throw new NoSuchElementException (); 55 } 56 57 final String name = (String )m_names.next(); 58 Object object = m_bindings.get( name ); 59 60 if( !m_returnBindings ) 61 { 62 return new NameClassPair ( name, object.getClass().getName() ); 63 } 64 else 65 { 66 return new Binding ( name, resolve( name, object ) ); 67 } 68 } 69 70 public void close() 71 { 72 super.close(); 73 m_bindings = null; 74 } 75 } 76 | Popular Tags |