1 8 9 package org.apache.commons.configuration; 10 11 import java.util.Hashtable ; 12 13 import javax.naming.Context ; 14 import javax.naming.NamingException ; 15 import javax.naming.spi.InitialContextFactory ; 16 17 import org.codehaus.spice.jndikit.DefaultNameParser; 18 import org.codehaus.spice.jndikit.DefaultNamespace; 19 import org.codehaus.spice.jndikit.memory.MemoryContext; 20 21 30 public class MockStaticMemoryInitialContextFactory 31 implements InitialContextFactory 32 { 33 private static final MemoryContext MEMORY_CONTEXT = createMemoryContext(); 34 35 public Context getInitialContext(final Hashtable environment) 36 throws NamingException 37 { 38 return MEMORY_CONTEXT; 39 } 40 41 46 private static final MemoryContext createMemoryContext() 47 { 48 final DefaultNamespace namespace = 49 new DefaultNamespace(new DefaultNameParser()); 50 MemoryContext me = new MemoryContext(namespace, new Hashtable (), null); 51 52 try 53 { 54 Context testContext = me.createSubcontext("test"); 55 testContext.bind("key", "jndivalue"); 56 testContext.bind("key2","jndivalue2"); 57 testContext.bind("short","1"); 58 testContext.bind("boolean","true"); 59 testContext.bind("byte","10"); 60 testContext.bind("double","10.25"); 61 testContext.bind("float","20.25"); 62 testContext.bind("integer","10"); 63 testContext.bind("long","1000000"); 64 testContext.bind("onlyinjndi","true"); 65 } 66 catch (NamingException ne) 67 { 68 throw new RuntimeException (ne); 69 } 70 return me; 71 } 72 } 73 | Popular Tags |