1 50 package org.apache.avalon.excalibur.naming; 51 52 import java.util.NoSuchElementException ; 53 54 import javax.naming.Context ; 55 import javax.naming.Name ; 56 import javax.naming.NamingEnumeration ; 57 import javax.naming.NamingException ; 58 59 66 public abstract class AbstractNamingEnumeration 67 implements NamingEnumeration 68 { 69 protected Context m_owner; 70 protected Namespace m_namespace; 71 72 public AbstractNamingEnumeration( final Context owner, final Namespace namespace ) 73 { 74 m_owner = owner; 75 m_namespace = namespace; 76 } 77 78 public boolean hasMore() 79 throws NamingException 80 { 81 return hasMoreElements(); 82 } 83 84 public Object nextElement() 85 { 86 try 87 { 88 return next(); 89 } 90 catch( final NamingException ne ) 91 { 92 throw new NoSuchElementException ( ne.toString() ); 93 } 94 } 95 96 protected Object resolve( final String name, final Object object ) 97 throws NamingException 98 { 99 try 101 { 102 final Name atom = m_owner.getNameParser( name ).parse( name ); 103 return m_namespace. 104 getObjectInstance( object, atom, m_owner, m_owner.getEnvironment() ); 105 } 106 catch( final Exception e ) 107 { 108 final NamingException ne = new NamingException ( "getObjectInstance failed" ); 109 ne.setRootCause( e ); 110 throw ne; 111 } 112 } 113 114 public void close() 115 { 116 m_namespace = null; 117 m_owner = null; 118 } 119 } 120 | Popular Tags |