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:gov.nih.nci.cagrid.caarray.stubs.cql.CaArrayCQLQueryProcessor.java

private static synchronized CaArraySearchService getSearchService() {
    try {//from w w w.ja  v  a 2  s.  c  o  m
        final Properties jndiProp = new Properties();
        jndiProp.load(CaArraySvcImpl.class.getResourceAsStream("/gov/nih/nci/cagrid/caarray/jndi.properties"));

        if (jndiProp.getProperty("java.naming.factory.initial") == null
                || jndiProp.getProperty("java.naming.factory.url.pkgs") == null
                || jndiProp.getProperty("java.naming.provider.url") == null) {
            throw new IllegalArgumentException(
                    "Unable to find all required properties in jndi.properties file.");
        }

        final Context context = new InitialContext(jndiProp);
        searchService = (CaArraySearchService) context.lookup(CaArraySearchService.JNDI_NAME);
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
    return searchService;
}

From source file:JNDIUtil.java

/**
 * Lookup an object through the JNDI context.
 *
 * @param objectName     The name of the object to be looked up.
 * @param jndiProperties JNDI properties.
 * @return The object./*from www  .ja  v a2  s. c  o m*/
 * @throws NamingException Error getting object.
 */
public static Object lookup(final String objectName, final Properties jndiProperties) throws NamingException {
    Object object = null;
    Context context;

    context = JNDIUtil.getNamingContext(jndiProperties);
    try {
        object = context.lookup(objectName);
    } finally {
        try {
            context.close();
        } catch (NamingException ne) {
            System.out.println("Failed to close Naming Context." + ne);
        }
    }

    return object;
}

From source file:com.wso2telco.ids.datapublisher.util.DBUtil.java

private static void initializeDatasources() throws AuthenticatorException {
    if (mConnectDatasource != null) {
        return;/*from w w  w  .  j  a  v a  2 s  .  c  om*/
    }

    String dataSourceName = null;
    try {
        Context ctx = new InitialContext();
        dataSourceName = DataHolder.getInstance().getMobileConnectConfig().getDataSourceName();
        mConnectDatasource = (DataSource) ctx.lookup(dataSourceName);
    } catch (NamingException e) {
        handleException("Error while looking up the data source: " + dataSourceName, e);
    }
}

From source file:com.dattack.naming.loader.NamingLoader.java

private static void execBind(final Context context, final String key, final Object value)
        throws NamingException {

    Object obj = context.lookup(key);

    if (obj instanceof Context) {
        LOGGER.debug("Destroying context with name '{}'", key);
        context.destroySubcontext(key);//  www  .  j  a v a 2  s.  c  o m
        obj = null;
    }

    if (obj == null) {
        LOGGER.debug("Executing bind method for '{}'", key);
        context.bind(key, value);
    } else {
        LOGGER.debug("Executing rebind method for '{}'", key);
        context.rebind(key, value);
    }
}

From source file:org.dhatim.util.JNDIUtil.java

/**
 * Lookup an object through the JNDI context.
 *
 * @param objectName     The name of the object to be looked up.
 * @param jndiProperties JNDI properties.
 * @return The object./*from w  w w . ja  v a  2  s.co  m*/
 * @throws NamingException Error getting object.
 */
public static Object lookup(final String objectName, final Properties jndiProperties) throws NamingException {
    Object object = null;
    Context context;

    context = JNDIUtil.getNamingContext(jndiProperties);
    try {
        object = context.lookup(objectName);
    } finally {
        try {
            context.close();
        } catch (NamingException ne) {
            logger.debug("Failed to close Naming Context.", ne);
        }
    }

    return object;
}

From source file:org.google.pen.plugin.impl.util.DeviceTypeUtils.java

public static void setupDeviceManagementSchema() throws DeviceMgtPluginException {
    try {/*from   w  w  w. jav  a 2s  . co m*/
        Context ctx = new InitialContext();
        DataSource dataSource = (DataSource) ctx.lookup(DeviceTypeConstants.DATA_SOURCE_NAME);
        DeviceSchemaInitializer initializer = new DeviceSchemaInitializer(dataSource);
        log.info("Initializing device management repository database schema");
        initializer.createRegistryDatabase();
    } catch (NamingException e) {
        log.error("Error while looking up the data source: " + DeviceTypeConstants.DATA_SOURCE_NAME);
    } catch (Exception e) {
        throw new DeviceMgtPluginException(
                "Error occurred while initializing Iot Device " + "Management database schema", e);
    }
}

From source file:edu.umn.msi.tropix.storage.service.impl.UploadTransferServiceContextFactory.java

/**
 * This method is nearly identical to TransferServiceHelper.createTransferContext(DataDescriptor, DataStagedCallback) but makes sure the resource objects do not expire until after the corresponding context has been terminated.
 * /*w  w w .j  a v a  2  s . co  m*/
 * @param dd
 * @param callback
 * @return
 * @throws RemoteException
 */
public static TransferServiceContextReference createTransferContext(final DataDescriptor dd,
        final DataStagedCallback callback) throws RemoteException {
    EndpointReferenceType epr = null; // new org.apache.axis.message.addressing.EndpointReferenceType(); - created object was never used

    final String homeName = "java:comp/env/services/cagrid/TransferServiceContext/home";
    try {
        final Context initialContext = new InitialContext();
        final TransferServiceContextResourceHome home = (TransferServiceContextResourceHome) initialContext
                .lookup(homeName);
        final ResourceKey resourceKey = home.createResource();

        // Grab the newly created resource
        final TransferServiceContextResource thisResource = (TransferServiceContextResource) home
                .find(resourceKey);
        thisResource.setSecurityDescriptor(SecurityUtils.createCreatorOnlyResourceSecurityDescriptor());
        LOG.debug("Calling stage on resource with callback " + callback);
        thisResource.stage(dd, callback);
        String transportURL = (String) MessageContext.getCurrentContext()
                .getProperty(org.apache.axis.MessageContext.TRANS_URL);
        transportURL = transportURL.substring(0, transportURL.lastIndexOf('/') + 1);
        transportURL += "TransferServiceContext";
        epr = AddressingUtils.createEndpointReference(transportURL, resourceKey);
        storeReference(thisResource);
    } catch (final Exception e) {
        throw new RemoteException("Error looking up TransferServiceContext home:" + e.getMessage(), e);
    }

    // return the typed EPR
    final TransferServiceContextReference ref = new TransferServiceContextReference();
    ref.setEndpointReference(epr);
    LOG.debug("Returning ref");
    return ref;
}

From source file:org.homeautomation.firealarm.plugin.impl.util.DeviceTypeUtils.java

/**
 * Creates the device management schema.
 *///from   w  ww.  j  av a 2  s  . c om
public static void setupDeviceManagementSchema() throws DeviceMgtPluginException {
    try {
        Context ctx = new InitialContext();
        DataSource dataSource = (DataSource) ctx.lookup(DeviceTypeConstants.DATA_SOURCE_NAME);
        DeviceSchemaInitializer initializer = new DeviceSchemaInitializer(dataSource);
        log.info("Initializing device management repository database schema");
        initializer.createRegistryDatabase();
    } catch (NamingException e) {
        log.error("Error while looking up the data source: " + DeviceTypeConstants.DATA_SOURCE_NAME);
    } catch (Exception e) {
        throw new DeviceMgtPluginException(
                "Error occurred while initializing Iot Device " + "Management database schema", e);
    }
}

From source file:org.homeautomation.droneanalyzer.plugin.impl.util.DroneAnalyzerUtils.java

/**
 * Creates the device management schema.
 *//*from   ww  w . j a v a2  s  . c  o  m*/
public static void setupDeviceManagementSchema() throws DeviceMgtPluginException {
    try {
        Context ctx = new InitialContext();
        DataSource dataSource = (DataSource) ctx.lookup(DroneAnalyzerConstants.DATA_SOURCE_NAME);
        DeviceSchemaInitializer initializer = new DeviceSchemaInitializer(dataSource);
        log.info("Initializing device management repository database schema");
        initializer.createRegistryDatabase();
    } catch (NamingException e) {
        log.error("Error while looking up the data source: " + DroneAnalyzerConstants.DATA_SOURCE_NAME);
    } catch (Exception e) {
        throw new DeviceMgtPluginException(
                "Error occurred while initializing Iot Device " + "Management database schema", e);
    }
}

From source file:eu.planets_project.tb.impl.persistency.CommentPersistencyImpl.java

/**
 * A Factory method to build a reference to this interface.
 * @return//from w  w w .ja  v  a 2  s . c  o m
 */
public static CommentPersistencyRemote getInstance() {
    Log log = LogFactory.getLog(CommentPersistencyImpl.class);
    try {
        Context jndiContext = new javax.naming.InitialContext();
        CommentPersistencyRemote dao_r = (CommentPersistencyRemote) PortableRemoteObject.narrow(
                jndiContext.lookup("testbed/CommentPersistencyImpl/remote"), CommentPersistencyRemote.class);
        return dao_r;
    } catch (NamingException e) {
        log.error("Failure in getting PortableRemoteObject: " + e.toString());
        return null;
    }
}