Example usage for javax.naming InitialContext doLookup

List of usage examples for javax.naming InitialContext doLookup

Introduction

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

Prototype

@SuppressWarnings("unchecked")
public static <T> T doLookup(String name) throws NamingException 

Source Link

Document

A static method to retrieve the named object.

Usage

From source file:org.wso2.carbon.device.mgt.mobile.android.impl.dao.util.MobileDeviceManagementDAOUtil.java

public static DataSource lookupDataSource(String dataSourceName,
        final Hashtable<Object, Object> jndiProperties) {

    try {/* w ww.j  a  va 2 s . co m*/
        if (jndiProperties == null || jndiProperties.isEmpty()) {
            return (DataSource) InitialContext.doLookup(dataSourceName);
        }
        final InitialContext context = new InitialContext(jndiProperties);
        return (DataSource) context.lookup(dataSourceName);
    } catch (Exception e) {
        String msg = "Error in looking up data source: " + e.getMessage();
        log.error(msg, e);
        throw new RuntimeException(msg + e.getMessage(), e);
    }
}

From source file:org.wso2.carbon.rssmanager.core.dao.util.EntityManager.java

private static UserTransaction getUserTransaction() {
    UserTransaction txObj = null;/*from   w w w  . j ava  2 s. c o  m*/
    try {
        txObj = InitialContext.doLookup(RSSManagerConstants.STANDARD_USER_TRANSACTION_JNDI_NAME);
    } catch (NamingException e) {
        String msg = " Could not obtain UserTransaction ";
        log.error(msg);
    }
    return txObj;
}

From source file:org.wso2.carbon.rssmanager.core.dao.util.EntityManager.java

private static TransactionManager getTransactionManager() {
    TransactionManager txManager = null;
    try {/*from w  w w .  ja  v  a 2  s.  co  m*/
        txManager = InitialContext.doLookup(RSSManagerConstants.STANDARD_TRANSACTION_MANAGER_JNDI_NAME);
    } catch (NamingException e) {
        String msg = " Could not obtain UserTransaction ";
        log.error(msg);
    }
    return txManager;
}

From source file:org.wso2.carbon.rssmanager.core.internal.RSSManagerServiceComponent.java

private TransactionManager lookupTransactionManager() {
    TransactionManager transactionManager = null;
    try {//from   ww w. j  a va 2s . co  m
        Object txObj = InitialContext.doLookup(RSSManagerConstants.STANDARD_USER_TRANSACTION_JNDI_NAME);
        if (txObj instanceof TransactionManager) {
            transactionManager = (TransactionManager) txObj;
        }
    } catch (Exception e) {
        if (log.isDebugEnabled()) {
            log.debug("Cannot find transaction manager at: "
                    + RSSManagerConstants.STANDARD_USER_TRANSACTION_JNDI_NAME, e);
        }
        /* ignore, move onto next step */
    }
    if (transactionManager == null) {
        try {
            transactionManager = InitialContext
                    .doLookup(RSSManagerConstants.STANDARD_TRANSACTION_MANAGER_JNDI_NAME);
        } catch (Exception e) {
            if (log.isDebugEnabled()) {
                log.debug("Cannot find transaction manager at: "
                        + RSSManagerConstants.STANDARD_TRANSACTION_MANAGER_JNDI_NAME, e);
            }
            /* we'll do the lookup later, maybe user provided a custom JNDI name */
        }
    }
    return transactionManager;
}

From source file:org.wso2.carbon.rssmanager.core.util.RSSManagerUtil.java

/**
 * Do jndi look up of data source/* w  w w.j ava  2 s.  c  o  m*/
 *
 * @param dataSourceName data source name
 * @param jndiProperties jndi properties
 * @return DataSource
 */
public static DataSource lookupDataSource(String dataSourceName,
        final Hashtable<Object, Object> jndiProperties) {
    try {
        if (jndiProperties == null || jndiProperties.isEmpty()) {
            return (DataSource) InitialContext.doLookup(dataSourceName);
        }
        final InitialContext context = new InitialContext(jndiProperties);
        return (DataSource) context.doLookup(dataSourceName);
    } catch (Exception e) {
        throw new RuntimeException("Error in looking up data source: " + e.getMessage(), e);
    }
}

From source file:org.wso2.carbon.rssmanager.data.mgt.retriever.internal.UsageManagerDataHolder.java

private TransactionManager lookupTransactionManager() {
    TransactionManager transactionManager = null;
    try {//from   w w  w . ja va  2  s.  c o m
        Object txObj = InitialContext.doLookup(UsageManagerConstants.STANDARD_USER_TRANSACTION_JNDI_NAME);
        if (txObj instanceof TransactionManager) {
            transactionManager = (TransactionManager) txObj;
        }
    } catch (Exception e) {
        if (log.isDebugEnabled()) {
            log.debug("Cannot find transaction manager at: "
                    + UsageManagerConstants.STANDARD_USER_TRANSACTION_JNDI_NAME, e);
        }
        /* ignore, move onto next step */
    }
    if (transactionManager == null) {
        try {
            transactionManager = InitialContext
                    .doLookup(UsageManagerConstants.STANDARD_TRANSACTION_MANAGER_JNDI_NAME);
        } catch (Exception e) {
            if (log.isDebugEnabled()) {
                log.debug("Cannot find transaction manager at: "
                        + UsageManagerConstants.STANDARD_TRANSACTION_MANAGER_JNDI_NAME, e);
            }
            /* we'll do the lookup later, maybe user provided a custom JNDI name */
        }
    }
    return transactionManager;
}

From source file:org.wso2.carbon.tenant.mgt.util.TenantMgtUtil.java

/**
 * Delete tenant data specific to product from database.
 *
 * @param dataSourceName/* www  .  j  ava  2  s. c  om*/
 * @param tableName
 * @param tenantId
 */
public static void deleteProductSpecificTenantData(String dataSourceName, String tableName, int tenantId) {
    try {
        TenantDataDeletionUtil.deleteProductSpecificTenantData(
                ((DataSource) InitialContext.doLookup(dataSourceName)).getConnection(), tableName, tenantId);
    } catch (Exception e) {
        throw new RuntimeException("Error in looking up data source: " + e.getMessage(), e);
    }
}

From source file:org.wso2.carbon.user.core.util.DatabaseUtil.java

private static DataSource lookupDataSource(String dataSourceName) {
    try {/*from  w w  w. j av a2  s .  c o m*/
        return (DataSource) InitialContext.doLookup(dataSourceName);
    } catch (Exception e) {
        throw new RuntimeException("Error in looking up data source: " + e.getMessage(), e);
    }
}

From source file:org.wso2.extension.siddhi.store.rdbms.RDBMSEventTable.java

/**
 * Method for looking up a datasource instance through JNDI.
 *
 * @param resourceName the name of the resource to be looked up.
 * @throws NamingException if the lookup fails.
 *//*from w  ww.  ja va 2  s  . c  om*/
private void lookupDatasource(String resourceName) throws NamingException {
    this.dataSource = InitialContext.doLookup(resourceName);
    this.isLocalDatasource = false;
    if (log.isDebugEnabled()) {
        log.debug("Lookup for resource '" + resourceName + "' completed through " + "JNDI lookup.");
    }
}

From source file:org.wso2.siddhi.extension.table.rdbms.RDBMSEventTable.java

/**
 * Method for looking up a datasource instance through JNDI.
 *
 * @param resourceName the name of the resource to be looked up.
 * @throws NamingException if the lookup fails.
 */// w  ww.  j  a  v a2s. co  m
private void lookupDatasource(String resourceName) throws NamingException {
    this.dataSource = InitialContext.doLookup(resourceName);
}