Example usage for javax.naming.spi InitialContextFactory getInitialContext

List of usage examples for javax.naming.spi InitialContextFactory getInitialContext

Introduction

In this page you can find the example usage for javax.naming.spi InitialContextFactory getInitialContext.

Prototype

public Context getInitialContext(Hashtable<?, ?> environment) throws NamingException;

Source Link

Document

Creates an Initial Context for beginning name resolution.

Usage

From source file:de.micromata.genome.util.runtime.LocalSettingsEnv.java

private static LocalSettingsEnv createJndiLocalSettingsEnv() {
    Hashtable<String, Object> env = new Hashtable<String, Object>();
    Context initialContext;/*  w w  w  . j  a v  a  2s  . com*/
    try {
        try {
            initialContext = new InitialContext();
            initialContext.lookup("java:");
        } catch (NameNotFoundException | NoInitialContextException ex) {
            log.info("No initialContext. Create own context");
            JndiMockupNamingContextBuilder contextBuilder = new JndiMockupNamingContextBuilder();
            InitialContextFactory initialContextFactory = contextBuilder.createInitialContextFactory(env);
            initialContext = initialContextFactory.getInitialContext(env);
            contextBuilder.activate();

        }
        LocalSettingsEnv localSettingsEnv = localSettingsEnvSupplier.apply(initialContext);
        log.info("Jndi LocalSettingsEnv intialized: " + JndiDumper.getJndiDump());
        return localSettingsEnv;
    } catch (NamingException ex) {
        throw new RuntimeException(ex);
    }

}

From source file:org.apache.activemq.jndi.JNDITestSupport.java

@Override
protected void setUp() throws Exception {
    super.setUp();

    configureEnvironment();/*from   w ww.  j a v  a2  s.co m*/

    InitialContextFactory factory = new ActiveMQInitialContextFactory();
    context = factory.getInitialContext(environment);
    assertTrue("No context created", context != null);
}