Example usage for org.springframework.jndi JndiTemplate JndiTemplate

List of usage examples for org.springframework.jndi JndiTemplate JndiTemplate

Introduction

In this page you can find the example usage for org.springframework.jndi JndiTemplate JndiTemplate.

Prototype

public JndiTemplate() 

Source Link

Document

Create a new JndiTemplate instance.

Usage

From source file:org.drugis.addis.config.MainConfig.java

@Bean(name = "dsAddisCore")
public DataSource dataSource() {
    DataSource ds;//  ww  w . j av a 2s  .c o  m
    JndiTemplate jndi = new JndiTemplate();
    try {
        ds = (DataSource) jndi.lookup("java:/comp/env/jdbc/addiscore");
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return ds;
}

From source file:org.drugis.addis.config.MainConfig.java

@Bean(name = "dsPataviTask")
public DataSource dataSourcePataviTask() {
    DataSource ds;/*w  w w. j ava  2 s . c  om*/
    JndiTemplate jndi = new JndiTemplate();
    try {
        ds = (DataSource) jndi.lookup("java:/comp/env/jdbc/patavitask");
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return ds;
}

From source file:com.katsu.dwm.jndi.Loader.java

public void load(File jar, Properties prop) throws ParserConfigurationException, SAXException, IOException {
    String jndi = prop.getProperty(LoaderConst.MODULE_JNDI.getValue());
    if (jndi != null) {
        InputStream is = JarUtils.getResourceAsStream(jar, jndi);
        if (is != null) {
            List<Resource> resources = ResourceParser.parse(is);
            JndiTemplate jndiTemplate = new JndiTemplate();
            for (Resource res : resources) {
                Object ds = DataSourceFactory.getDataSource(res);
                try {
                    jndiTemplate.bind("java:comp/env/" + res.getName(), ds);
                } catch (NamingException e) {
                    logger.warn("DataSource is not registered: " + e);
                }/*from   w  w w .j a  v  a  2 s. c o  m*/
                logger.trace("Registered JNDI DataSource java:comp/env/" + res.getName());
            }
        }
    }
}

From source file:org.alfresco.web.app.ContextLoaderListener.java

public ContextLoaderListener() {
    try {//from   w w w .j av a2  s  .co  m
        this.enableStartup = (Boolean) new JndiTemplate().lookup(ContextLoaderListener.PROPERTY_ENABLE_STARTUP,
                Boolean.class);
    } catch (Exception e) {
        this.enableStartup = true;
    }
}

From source file:org.kuali.rice.core.framework.persistence.jdbc.datasource.PrimaryDataSourceFactoryBean.java

protected DataSource loadPreferredDataSourceFromConfig(Config config) {
    for (String dataSourceParam : getPreferredDataSourceParams()) {
        Object dataSource = config.getObject(dataSourceParam);
        if (dataSource != null) {
            validateDataSource(dataSourceParam, dataSource);
            return (DataSource) dataSource;
        }/*from  w  w w .  jav a2s .co m*/
    }
    if (this.jndiTemplate == null) {
        this.jndiTemplate = new JndiTemplate();
    }
    for (String dataSourceJndiParam : getPreferredDataSourceJndiParams()) {
        DataSource dataSource = getDataSourceFromJndi(config, dataSourceJndiParam);
        if (dataSource != null) {
            return dataSource;
        }
    }
    return null;
}

From source file:org.kuali.rice.core.framework.persistence.jta.JtaConfigurer.java

protected <T> T loadFromConfiguration(Class<T> objectClass, String objectKey, String jndiKey) {
    if (!ConfigContext.isInitialized()) {
        throw new IllegalStateException("Configuration system has not been initialized, so cannot load JTA "
                + "configuration. Please ensure the Configuration system is initalized first.");
    }/*from  w  ww . j  av  a  2 s  .  com*/
    T configured = (T) ConfigContext.getCurrentContextConfig().getObject(objectKey);
    if (configured == null) {
        String jndiName = ConfigContext.getCurrentContextConfig().getProperty(jndiKey);
        if (StringUtils.isNotEmpty(jndiName)) {
            if (this.jndiTemplate == null) {
                this.jndiTemplate = new JndiTemplate();
            }
            try {
                configured = (T) this.jndiTemplate.lookup(jndiName, objectClass);
            } catch (NamingException e) {
                throw new ConfigurationException("Could not locate the " + objectClass.getSimpleName()
                        + " at the given JNDI location: '" + jndiName + "'", e);
            }
        }
    }
    return configured;
}

From source file:org.kuali.rice.core.framework.persistence.jta.TransactionManagerFactoryBean.java

public Object getObject() throws Exception {

    if (ConfigContext.getCurrentContextConfig().getObject(RiceConstants.SPRING_TRANSACTION_MANAGER) != null) {
        return null;
    }/*  w  w w.ja v  a 2s  .co m*/

    TransactionManager transactionManager = (TransactionManager) ConfigContext.getCurrentContextConfig()
            .getObject(RiceConstants.TRANSACTION_MANAGER_OBJ);
    if (transactionManager == null) {
        String transactionManagerJndiName = ConfigContext.getCurrentContextConfig()
                .getProperty(RiceConstants.TRANSACTION_MANAGER_JNDI);
        if (!StringUtils.isEmpty(transactionManagerJndiName)) {
            if (this.jndiTemplate == null) {
                this.jndiTemplate = new JndiTemplate();
            }
            try {
                transactionManager = (TransactionManager) this.jndiTemplate.lookup(transactionManagerJndiName,
                        TransactionManager.class);
            } catch (NamingException e) {
                throw new ConfigurationException(
                        "Could not locate the TransactionManager at the given JNDI location: '"
                                + transactionManagerJndiName + "'",
                        e);
            }
        }

    }
    if (transactionManager != null) {
        return transactionManager;
    }
    return this.defaultTransactionManager;
}

From source file:org.kuali.rice.core.framework.persistence.jta.UserTransactionFactoryBean.java

public Object getObject() throws Exception {

    if (ConfigContext.getCurrentContextConfig().getObject(RiceConstants.SPRING_TRANSACTION_MANAGER) != null) {
        return null;
    }/*w  w  w.  ja  v a  2  s  . com*/

    UserTransaction userTransaction = (UserTransaction) ConfigContext.getCurrentContextConfig()
            .getObject(RiceConstants.USER_TRANSACTION_OBJ);
    if (userTransaction == null) {
        String userTransactionJndiName = ConfigContext.getCurrentContextConfig()
                .getProperty(RiceConstants.USER_TRANSACTION_JNDI);
        if (!StringUtils.isEmpty(userTransactionJndiName)) {
            if (this.jndiTemplate == null) {
                this.jndiTemplate = new JndiTemplate();
            }
            try {
                userTransaction = (UserTransaction) this.jndiTemplate.lookup(userTransactionJndiName,
                        UserTransaction.class);
            } catch (NamingException e) {
                throw new ConfigurationException(
                        "Could not locate the UserTransaction at the given JNDI location: '"
                                + userTransactionJndiName + "'",
                        e);
            }
        }

    }
    if (userTransaction != null) {
        return userTransaction;
    }
    return this.defaultUserTransaction;
}

From source file:org.springframework.beans.factory.access.JndiBeanFactoryLocator.java

/**
 * Load/use a bean factory, as specified by a factoryKey which is a JNDI
 * address, of the form <code>java:comp/env/ejb/BeanFactoryPath</code>. The
 * contents of this JNDI location must be a string containing one or more
 * classpath resource names (separated by any of the delimiters
 * '<code>,; \t\n</code>' if there is more than one. The resulting
 * BeanFactory (or subclass) will be created from the combined resources.
 *//*w  w  w .j a v  a 2  s  .com*/
public BeanFactoryReference useBeanFactory(String factoryKey) throws BeansException {
    String beanFactoryPath = null;
    try {
        beanFactoryPath = (String) (new JndiTemplate()).lookup(factoryKey);
        logger.info("BeanFactoryPath from JNDI is [" + beanFactoryPath + "]");
        String[] paths = StringUtils.tokenizeToStringArray(beanFactoryPath, BEAN_FACTORY_PATH_DELIMITERS, true,
                true);
        return createBeanFactory(paths);
    } catch (NamingException ex) {
        throw new BootstrapException("Define an environment variable 'ejb/BeanFactoryPath' containing "
                + "the class path locations of XML bean definition files", ex);
    }
}

From source file:org.springframework.jndi.JndiAccessor.java

/**
 * Set the JNDI template to use for JNDI lookups.
 * <p>You can also specify JNDI environment settings via "jndiEnvironment".
 * @see #setJndiEnvironment//from w  w  w . j a va 2s  .  co m
 */
public void setJndiTemplate(@Nullable JndiTemplate jndiTemplate) {
    this.jndiTemplate = (jndiTemplate != null ? jndiTemplate : new JndiTemplate());
}