1 50 package org.apache.avalon.excalibur.naming.memory; 51 52 import java.util.Hashtable ; 53 54 import javax.naming.Context ; 55 import javax.naming.Name ; 56 import javax.naming.NameNotFoundException ; 57 import javax.naming.NamingEnumeration ; 58 import javax.naming.NamingException ; 59 60 import org.apache.avalon.excalibur.naming.AbstractLocalContext; 61 import org.apache.avalon.excalibur.naming.Namespace; 62 63 70 public class MemoryContext 71 extends AbstractLocalContext 72 { 73 private Hashtable m_bindings; 74 75 protected MemoryContext( final Namespace namespace, 76 final Hashtable environment, 77 final Context parent, 78 final Hashtable bindings ) 79 { 80 super( namespace, environment, parent ); 81 m_bindings = bindings; 82 } 83 84 public MemoryContext( final Namespace namespace, 85 final Hashtable environment, 86 final Context parent ) 87 { 88 this( namespace, environment, parent, new Hashtable ( 11 ) ); 89 } 90 91 protected Context newContext() 92 throws NamingException 93 { 94 return new MemoryContext( getNamespace(), getRawEnvironment(), getParent() ); 95 } 96 97 protected Context cloneContext() 98 throws NamingException 99 { 100 return new MemoryContext( getNamespace(), getRawEnvironment(), getParent(), m_bindings ); 101 } 102 103 protected void doLocalBind( final Name name, final Object object ) 104 throws NamingException 105 { 106 m_bindings.put( name.get( 0 ), object ); 107 } 108 109 protected NamingEnumeration doLocalList() 110 throws NamingException 111 { 112 return new MemoryNamingEnumeration( this, getNamespace(), m_bindings, false ); 113 } 114 115 protected NamingEnumeration doLocalListBindings() 116 throws NamingException 117 { 118 return new MemoryNamingEnumeration( this, getNamespace(), m_bindings, true ); 119 } 120 121 129 protected Object doLocalLookup( final Name name ) 130 throws NamingException 131 { 132 final Object object = m_bindings.get( name.get( 0 ) ); 133 if( null == object ) throw new NameNotFoundException ( name.get( 0 ) ); 134 return object; 135 } 136 137 143 protected void doLocalUnbind( final Name name ) 144 throws NamingException 145 { 146 m_bindings.remove( name.get( 0 ) ); 147 } 148 } 149 150 | Popular Tags |