Example usage for javax.naming NameClassPair isRelative

List of usage examples for javax.naming NameClassPair isRelative

Introduction

In this page you can find the example usage for javax.naming NameClassPair isRelative.

Prototype

public boolean isRelative() 

Source Link

Document

Determines whether the name of this binding is relative to the target context (which is named by the first parameter of the list() method).

Usage

From source file:org.nuxeo.runtime.datasource.DataSourceHelper.java

public static Map<String, DataSource> getDatasources() throws NamingException {
    String prefix = getDataSourceJNDIPrefix();
    Context naming = new InitialContext();
    Context jdbc = (Context) naming.lookup(prefix);
    Enumeration<NameClassPair> namesPair = jdbc.list("");
    Map<String, DataSource> datasourcesByName = new HashMap<String, DataSource>();
    while (namesPair.hasMoreElements()) {
        NameClassPair pair = namesPair.nextElement();
        String name = pair.getName();
        if (pair.isRelative()) {
            name = prefix + "/" + name;
        }/* ww  w.j a  v a 2  s  . co m*/
        Object ds = naming.lookup(name);
        if (ds instanceof DataSource) {
            datasourcesByName.put(name, (DataSource) ds);
        }
    }
    return datasourcesByName;
}