class JDBCUtils {

    public static List<SQLDataSourceDef> listDatasourceDefs() {
        List<SQLDataSourceDef> result = new ArrayList<>();
        String[] namespaces = {"java:comp/env/jdbc/", "java:jboss/datasources/"};
        for (String namespace : namespaces) {
            try {
                InitialContext ctx = new InitialContext();
                NamingEnumeration<NameClassPair> list = ctx.list(namespace);
                while (list.hasMoreElements()) {
                    NameClassPair next = list.next();
                    String name = next.getName();
                    String jndiPath = namespace + name;
                    SQLDataSourceDef dsDef = new SQLDataSourceDef(jndiPath, name);
                    result.add(dsDef);
                }
            } catch (NamingException e) {
                log.warn("JNDI namespace {} error: {}", namespace, e.getMessage());
            }
        }
        return result;
    }

}