Example usage for javax.naming Context lookup

List of usage examples for javax.naming Context lookup

Introduction

In this page you can find the example usage for javax.naming Context lookup.

Prototype

public Object lookup(String name) throws NamingException;

Source Link

Document

Retrieves the named object.

Usage

From source file:$.DeviceTypeDAO.java

public static void initDeviceTypeDAO() {
        try {/*from  ww  w .j a  v a  2 s . c om*/
            Context ctx = new InitialContext();
            dataSource = (DataSource) ctx.lookup(DeviceTypeConstants.DATA_SOURCE_NAME);
        } catch (NamingException e) {
            log.error("Error while looking up the data source: " + DeviceTypeConstants.DATA_SOURCE_NAME);
        }
    }

From source file:org.homeautomation.currentsensor.plugin.impl.dao.CurrentSensorDAO.java

public static void initCurrentSensorDAO() {
    try {//w ww.  java  2  s . c  o m
        Context ctx = new InitialContext();
        dataSource = (DataSource) ctx.lookup(CurrentSensorConstants.DATA_SOURCE_NAME);
    } catch (NamingException e) {
        log.error("Error while looking up the data source: " + CurrentSensorConstants.DATA_SOURCE_NAME);
    }
}

From source file:org.deviceautomation.geolocationTracker.plugin.impl.dao.GeoLocationTrackerDAO.java

public static void initDeviceTypeDAO() {
    DeviceManagementConfiguration deviceManagementConfiguration = GeoLocationTrackerManagementDataHolder
            .getInstance().getDeviceTypeConfigService()
            .getConfiguration(GeoLocationTrackerConstants.DEVICE_TYPE,
                    GeoLocationTrackerConstants.DEVICE_TYPE_PROVIDER_DOMAIN);
    String datasource = deviceManagementConfiguration.getDeviceManagementConfigRepository()
            .getDataSourceConfig().getJndiLookupDefinition().getJndiName();
    try {//from  w  w  w.ja  va  2s .c  o  m
        Context ctx = new InitialContext();
        dataSource = (DataSource) ctx.lookup(datasource);
    } catch (NamingException e) {
        log.error("Error while looking up the data source: " + datasource, e);
    }
}

From source file:org.homeautomation.doormanager.plugin.impl.dao.DoorManagerDAO.java

public static void initDoorManagerDAO() {
    DeviceManagementConfiguration deviceManagementConfiguration = DoorManagerManagementDataHolder.getInstance()
            .getDeviceTypeConfigService().getConfiguration(DoorManagerConstants.DEVICE_TYPE,
                    DoorManagerConstants.DEVICE_TYPE_PROVIDER_DOMAIN);
    String datasource = deviceManagementConfiguration.getDeviceManagementConfigRepository()
            .getDataSourceConfig().getJndiLookupDefinition().getJndiName();
    try {/*w w w  .  jav  a 2s  .c  o m*/
        Context ctx = new InitialContext();
        dataSource = (DataSource) ctx.lookup(datasource);
    } catch (NamingException e) {
        log.error("Error while looking up the data source: " + datasource, e);
    }
}

From source file:org.easybatch.tutorials.advanced.jms.JMSUtil.java

public static void initJMSFactory() throws Exception {

    Properties p = new Properties();
    p.load(JMSUtil.class.getResourceAsStream(("/org/easybatch/tutorials/advanced/jms/jndi.properties")));
    Context jndiContext = new InitialContext(p);

    queueConnectionFactory = (QueueConnectionFactory) jndiContext.lookup("QueueConnectionFactory");
    queue = (Queue) jndiContext.lookup("q");

    QueueConnection queueConnection = queueConnectionFactory.createQueueConnection();
    queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    queueSender = queueSession.createSender(queue);
    queueConnection.start();/*w  ww. j  a  v a  2  s  .  c  o  m*/

}

From source file:eu.planets_project.tb.impl.system.TestbedStatelessAdminBean.java

/**
 * @return A reference to this EJB.//from w  w w  .ja  v  a 2 s.  c o  m
 */
public static TestbedStatelessAdmin getTestbedAdminBean() {
    try {
        Context jndiContext = new javax.naming.InitialContext();
        TestbedStatelessAdmin um = (TestbedStatelessAdmin) jndiContext
                .lookup("planets-project.eu/tb/TestbedAdminBean");
        return um;
    } catch (NamingException e) {
        log.error("Failure during lookup of the local TestbedStatelessAdmin: " + e.toString());
        return null;
    }
}

From source file:com.wso2telco.historylog.DbTracelog.java

/**
 * Initialize datasources.//w  w w.  j  av a  2s. c  o m
 *
 * @throws LogHistoryException the log history exception
 */
public static void initializeDatasources() throws LogHistoryException {
    if (connectDatasource != null) {
        return;
    }

    try {
        Context ctx = new InitialContext();
        connectDatasource = (DataSource) ctx.lookup(CONNECT_DATA_SOURCE);
    } catch (NamingException e) {
        handleException("Error while looking up the data source: " + CONNECT_DATA_SOURCE, e);
    }
}

From source file:org.jbpm.bpel.integration.jms.JmsIntegrationServiceFactory.java

private static Object lookup(String name) throws NamingException {
    Context initialContext = new InitialContext();
    try {/*from w w w  .  ja va 2s . c  o  m*/
        return initialContext.lookup(name);
    } finally {
        initialContext.close();
    }
}

From source file:org.homeautomation.firealarm.plugin.impl.dao.DeviceTypeDAO.java

/**
 * Initialize the device type./*ww w .  j a  v a2  s.c  o  m*/
 */
public static void initDeviceTypeDAO() {
    try {
        Context ctx = new InitialContext();
        dataSource = (DataSource) ctx.lookup(DeviceTypeConstants.DATA_SOURCE_NAME);
    } catch (NamingException e) {
        log.error("Error while looking up the data source: " + DeviceTypeConstants.DATA_SOURCE_NAME);
    }
}

From source file:jp.co.golorp.emarf.sql.DataSources.java

/**
 * ?//from w ww. j  ava  2s  .co  m
 *
 * @return DataSource
 */
public static DataSource get() {

    if (ds != null) {
        return ds;
    }

    /*
     * JNDI??
     */

    String name = BUNDLE.getString(DATA_SOURCE_NAME);
    try {
        Context context = new InitialContext();
        ds = (DataSource) context.lookup(name);
        return ds;
    } catch (NamingException e) {
        LOG.warn(e.getMessage());
    }

    /*
     * DBCP??
     */

    Properties properties = new Properties();
    Enumeration<String> keys = BUNDLE.getKeys();
    while (keys.hasMoreElements()) {
        String key = keys.nextElement();
        String value = BUNDLE.getString(key);
        properties.put(key, value);
        // if (value.contains("mysql")) {
        // DataSources.isMySQL = true;
        // } else if (value.contains("oracle")) {
        // DataSources.isOracle = true;
        // }
    }

    try {
        ds = BasicDataSourceFactory.createDataSource(properties);
        return ds;
    } catch (Exception e) {
        throw new SystemError(e);
    }
}