Example usage for javax.naming InitialContext unbind

List of usage examples for javax.naming InitialContext unbind

Introduction

In this page you can find the example usage for javax.naming InitialContext unbind.

Prototype

public void unbind(Name name) throws NamingException 

Source Link

Usage

From source file:org.wso2.carbon.metrics.jdbc.core.BaseReporterTest.java

@AfterSuite
protected static void destroy() throws Exception {
    if (logger.isInfoEnabled()) {
        logger.info("Unbinding jdbc/WSO2MetricsDB");
    }// ww  w .j  a va2  s  . c o m
    InitialContext ic = new InitialContext();
    ic.unbind("jdbc/WSO2MetricsDB");
    ic.unbind("jdbc");

    if (logger.isInfoEnabled()) {
        logger.info("Stopping reporters");
    }
    metrics.deactivate();
}

From source file:com.stratelia.silverpeas.silverStatisticsPeas.control.AbstractSpringDatasourceTest.java

@AfterClass
public static void tearDownClass() throws Exception {
    InitialContext ic = new InitialContext();
    ic.unbind("java:/datasources/silverpeas-jdbc");
    springContext.close();/* w w w .  j ava  2  s  . c  o m*/
    DBUtil.clearTestInstance();
    SimpleMemoryContextFactory.tearDownAsInitialContext();
}

From source file:de.tud.inf.db.sparqlytics.bench.LDBCBenchmark.java

@AfterClass
public static void unbindRepository() throws NamingException {
    InitialContext ctx = new InitialContext();
    Repository repository = (Repository) ctx.lookup("ldbc");
    Slf4jReporter.forRegistry(repository.getStatistics()).withLoggingLevel(Slf4jReporter.LoggingLevel.INFO)
            .prefixedWith("after:").build().report();
    ctx.unbind("ldbc");
}

From source file:org.wso2.carbon.metrics.data.service.MetricsDataServiceTest.java

public static Test suite() {
    return new TestSetup(new TestSuite(MetricsDataServiceTest.class)) {

        protected void setUp() throws Exception {
            DataSource dataSource = JdbcConnectionPool.create("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", "sa", "");
            template = new JdbcTemplate(dataSource);
            ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
            populator.addScript(new ClassPathResource("dbscripts/h2.sql"));
            populator.populate(dataSource.getConnection());

            // Create initial context
            System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory");
            System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming");
            InitialContext ic = new InitialContext();
            ic.createSubcontext("jdbc");
            ic.bind("jdbc/WSO2MetricsDB", dataSource);
        }//  www .  ja v  a  2 s. c  om

        protected void tearDown() throws Exception {
            InitialContext ic = new InitialContext();
            ic.unbind("jdbc/WSO2MetricsDB");
            ic.unbind("jdbc");
        }
    };
}

From source file:org.wso2.carbon.metrics.impl.ReporterTest.java

public static Test suite() {
    return new TestSetup(new TestSuite(ReporterTest.class)) {

        protected void setUp() throws Exception {
            DataSource dataSource = JdbcConnectionPool.create("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", "sa", "");
            template = new JdbcTemplate(dataSource);
            ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
            populator.addScript(new ClassPathResource("dbscripts/h2.sql"));
            populator.populate(dataSource.getConnection());

            // Create initial context
            System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory");
            System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming");
            InitialContext ic = new InitialContext();
            ic.createSubcontext("jdbc");
            ic.bind("jdbc/WSO2MetricsDB", dataSource);

            // Set setup system property to cover database creator logic
            System.setProperty("setup", "");
        }/*  ww w .  ja  v a  2s  . c  o  m*/

        protected void tearDown() throws Exception {
            InitialContext ic = new InitialContext();
            ic.unbind("jdbc/WSO2MetricsDB");
            ic.unbind("jdbc");
        }
    };
}

From source file:net.chrisrichardson.foodToGo.ejb3.facadeWithSpringDI.SpringBeanReferenceInitializer.java

public void destroy() throws Exception {
    logger.debug("Inside ServicePOJOImpl.destroy()");
    InitialContext ctx = new InitialContext();
    for (String jndiName : jndiNames) {
        ctx.unbind(jndiName);
        logger.debug("unbind: " + jndiName);
    }/*from  w  w  w.  j av  a2s  .c o m*/
}

From source file:io.apiman.manager.test.server.ManagerApiTestServer.java

/**
 * Stop the server./* w  w w  .  ja v a  2 s.c om*/
 * @throws Exception
 */
public void stop() throws Exception {
    server.stop();
    ds.close();
    InitialContext ctx = new InitialContext();
    ctx.unbind("java:comp/env/jdbc/ApiManagerDS"); //$NON-NLS-1$
}

From source file:org.jboss.spring.deployers.AbstractSpringMetaDataDeployer.java

/**
 * Unind factory from non-serializable JNDI context.
 *
 * @param name the jndi name/*from w  ww. j ava2 s  .  c om*/
 */
protected void unbind(String name) {
    InitialContext ctx = null;
    try {
        ctx = new InitialContext();
        ctx.unbind(name);
        NonSerializableFactory.unbind(name);
    } catch (NamingException e) {
        log.warn("Unable to unbind BeanFactory from JNDI", e);
    } finally {
        if (ctx != null) {
            try {
                ctx.close();
            } catch (Throwable ignored) {
            }
        }
    }
}

From source file:org.apache.synapse.commons.datasource.JNDIBasedDataSourceRepository.java

public void unRegister(String name) {

    InitialContext context = getCachedInitialContext(name);
    try {/*from w ww . j a v  a 2  s  .c  o m*/
        context.unbind(name);
    } catch (NamingException e) {
        throw new SynapseCommonsException("Error removing a Datasource with name : " + name
                + " from the JNDI context : " + initialContext, e);
    }
    cachedNameList.remove(name);
}

From source file:org.eclipse.edt.ide.deployment.services.internal.testserver.ConfigServlet.java

/**
 * Removes a resource-ref from the web application context.
 * /*from   w  w w .j a  v  a  2s.  co  m*/
 * @return true if the resource-ref was successfully removed.
 */
public boolean removeResourceRef(String name) {
    ClassLoader savedLoader = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(server.getWebApp().getClassLoader());
    try {
        if (!name.startsWith("java:comp/env/")) { //$NON-NLS-1$
            name = "java:comp/env/" + name; //$NON-NLS-1$
        }
        InitialContext ctx = new InitialContext();
        ctx.unbind(name);
        server.log("resource-ref removed: name=" + name, LogLevel.INFO); //$NON-NLS-1$
        return true;
    } catch (Exception e) {
        server.log(e);
        return false;
    } finally {
        Thread.currentThread().setContextClassLoader(savedLoader);
    }
}