1 50 package org.apache.avalon.excalibur.naming.memory; 51 52 import java.util.Hashtable ; 53 import java.util.Iterator ; 54 import java.util.NoSuchElementException ; 55 56 import javax.naming.Binding ; 57 import javax.naming.Context ; 58 import javax.naming.NameClassPair ; 59 import javax.naming.NamingException ; 60 61 import org.apache.avalon.excalibur.naming.AbstractNamingEnumeration; 62 import org.apache.avalon.excalibur.naming.Namespace; 63 64 71 final class MemoryNamingEnumeration 72 extends AbstractNamingEnumeration 73 { 74 protected Hashtable m_bindings; 75 protected Iterator m_names; 76 protected boolean m_returnBindings; 77 78 public MemoryNamingEnumeration( final Context owner, 79 final Namespace namespace, 80 final Hashtable bindings, 81 final boolean returnBindings ) 82 { 83 super( owner, namespace ); 84 m_returnBindings = returnBindings; 85 m_bindings = bindings; 86 m_names = m_bindings.keySet().iterator(); 87 } 88 89 public boolean hasMoreElements() 90 { 91 return m_names.hasNext(); 92 } 93 94 public Object next() 95 throws NamingException 96 { 97 if( !hasMore() ) throw new NoSuchElementException (); 98 99 final String name = (String )m_names.next(); 100 Object object = m_bindings.get( name ); 101 102 if( !m_returnBindings ) 103 { 104 return new NameClassPair ( name, object.getClass().getName() ); 105 } 106 else 107 { 108 return new Binding ( name, resolve( name, object ) ); 109 } 110 } 111 112 public void close() 113 { 114 super.close(); 115 m_bindings = null; 116 } 117 } 118 | Popular Tags |