1 8 package org.codehaus.spice.jndikit.memory; 9 10 import java.util.Hashtable ; 11 import javax.naming.Context ; 12 import javax.naming.Name ; 13 import javax.naming.NameNotFoundException ; 14 import javax.naming.NamingEnumeration ; 15 import javax.naming.NamingException ; 16 import org.codehaus.spice.jndikit.AbstractLocalContext; 17 import org.codehaus.spice.jndikit.Namespace; 18 19 25 public class MemoryContext 26 extends AbstractLocalContext 27 { 28 private Hashtable m_bindings; 29 30 protected MemoryContext( final Namespace namespace, 31 final Hashtable environment, 32 final Context parent, 33 final Hashtable bindings ) 34 { 35 super( namespace, environment, parent ); 36 m_bindings = bindings; 37 } 38 39 public MemoryContext( final Namespace namespace, 40 final Hashtable environment, 41 final Context parent ) 42 { 43 this( namespace, environment, parent, new Hashtable ( 11 ) ); 44 } 45 46 protected Context newContext() 47 throws NamingException 48 { 49 return new MemoryContext( getNamespace(), getRawEnvironment(), getParent() ); 50 } 51 52 protected Context cloneContext() 53 throws NamingException 54 { 55 return new MemoryContext( getNamespace(), getRawEnvironment(), getParent(), m_bindings ); 56 } 57 58 protected void doLocalBind( final Name name, final Object object ) 59 throws NamingException 60 { 61 m_bindings.put( name.get( 0 ), object ); 62 } 63 64 protected NamingEnumeration doLocalList() 65 throws NamingException 66 { 67 return new MemoryNamingEnumeration( this, getNamespace(), m_bindings, false ); 68 } 69 70 protected NamingEnumeration doLocalListBindings() 71 throws NamingException 72 { 73 return new MemoryNamingEnumeration( this, getNamespace(), m_bindings, true ); 74 } 75 76 84 protected Object doLocalLookup( final Name name ) 85 throws NamingException 86 { 87 final Object object = m_bindings.get( name.get( 0 ) ); 88 if( null == object ) 89 { 90 throw new NameNotFoundException ( name.get( 0 ) ); 91 } 92 return object; 93 } 94 95 101 protected void doLocalUnbind( final Name name ) 102 throws NamingException 103 { 104 m_bindings.remove( name.get( 0 ) ); 105 } 106 } 107 108 | Popular Tags |