Example usage for org.springframework.jndi JndiTemplate bind

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

Introduction

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

Prototype

public void bind(final String name, final Object object) throws NamingException 

Source Link

Document

Bind the given object to the current JNDI context, using the given name.

Usage

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);
                }//  w w  w .  j a v a  2  s .com
                logger.trace("Registered JNDI DataSource java:comp/env/" + res.getName());
            }
        }
    }
}