1 8 package org.codehaus.spice.jndikit; 9 10 import java.util.NoSuchElementException ; 11 import javax.naming.Context ; 12 import javax.naming.Name ; 13 import javax.naming.NamingEnumeration ; 14 import javax.naming.NamingException ; 15 16 22 public abstract class AbstractNamingEnumeration 23 implements NamingEnumeration 24 { 25 private Context m_owner; 26 private Namespace m_namespace; 27 28 public AbstractNamingEnumeration( final Context owner, final Namespace namespace ) 29 { 30 m_owner = owner; 31 m_namespace = namespace; 32 } 33 34 public boolean hasMore() 35 throws NamingException 36 { 37 return hasMoreElements(); 38 } 39 40 public Object nextElement() 41 { 42 try 43 { 44 return next(); 45 } 46 catch( final NamingException ne ) 47 { 48 throw new NoSuchElementException ( ne.toString() ); 49 } 50 } 51 52 protected Object resolve( final String name, final Object object ) 53 throws NamingException 54 { 55 try 57 { 58 final Name atom = m_owner.getNameParser( name ).parse( name ); 59 return m_namespace. 60 getObjectInstance( object, atom, m_owner, m_owner.getEnvironment() ); 61 } 62 catch( final Exception e ) 63 { 64 final NamingException ne = new NamingException ( "getObjectInstance failed" ); 65 ne.setRootCause( e ); 66 throw ne; 67 } 68 } 69 70 public void close() 71 { 72 m_namespace = null; 73 m_owner = null; 74 } 75 } 76 | Popular Tags |