baddax: Refresh JNDI tree when accessing from outside the container

Hello,

I wrote a tool (a simple main class) which runs a thread to simply check the DataSources stored in an Application Server's JNDI tree (to see, if they can be used by other tools).
The problem is: Once the thread is running, it always gets the same DataSource back, no matter if the DS's properties changed. Let me describe what happens:

1. I defined a DataSource in Orion 2.0.5's data-sources.xml
2. Testing it with an application in the container works fine.
3. I start my external tool, which gets the DataSource and checks it - it works
4. Then I stop the container and change the DataSource props in a way that the connection won't be established (i.e. wrong url)
5. After restarting the container, the aplication in the container throws the expected SQLException
6. But the external tool (which is still running) does its next lookup for the DataSource and gets a valid one and claims that everything is fine.

Well, it seems to me that the external tool outside of the container somehow gets a copy of the JNDI tree (or something) and does no real lookup, but I just don't know. Another hint is, that - unless I do a context.list(""); before looking up the object - the container did not even need to run after the first lookup from the external tool - it just needed one lookup and afterwards I could stop the container without having the external tool recognizing any changes. Well, it at least recognizes that now by the above mentioned context.list(""); ...

I hope I explained it right, let me just add some code of my tool.
Thank you in advance for any hints!
Greetings, Sebastian

//only the important stuff...
public class DataSourceChecker extends Thread {

/** The array with the names of the data sources (command line args)). */
  private String[] _datasourceNames;
  /** Defines in seconds how long the thread sleeps. */
  private int _sleepSeconds;

public void run() {
        boolean success;
        while (true) {
            //check each datasource...
            success = true;
            for (int i = 0; i < _datasourceNames.length; i++) {
                if (!isDataSourceValid(_datasourceNames[i])) {
                    success = false;
                    break;
                }
            }
            writeFile(success);
            try {
                sleep(_sleepSeconds * 1000);
            } catch (InterruptedException ie) {
                _log.error("Error while trying to put thread to sleep.");
            }
        }
    }

private boolean isDataSourceValid(String dataSource) {
        DataSource ds = null;
        Connection con = null;
        boolean success = true;
        try {
            ds = (DataSource)lookup(dataSource);
            con = ds.getConnection();
            //test the connection with something
            con.getCatalog();
        } catch (NamingException ne) {
            _log.error("Did not find datasource " + dataSource + ". " + ne.getMessage());
            success = false;
        } catch (SQLException sqle) {
            _log.error("Error while testing connection of datasource " + dataSource + ". " + sqle.getMessage());
            success = false;
        } finally {
            if (con != null) {
                try {
                    con.close();
                } catch (SQLException sqle) {
                    _log.error("Could not close tested connection of Datasource " + ds + ", exiting tool!");
                    System.exit(1);
                }
            }
        }
        return success;
    }

private Object lookup(String name) throws NamingException {
        //I also tried to set the properties - with the same result
        /*String host = "ormi://127.0.0.1:23791/myConApp";
        Hashtable rmi_env = new Hashtable();
        rmi_env.put(Context.INITIAL_CONTEXT_FACTORY,              "com.evermind.server.rmi.RMIInitialContextFactory");
        rmi_env.put(Context.PROVIDER_URL, host);
        rmi_env.put(Context.SECURITY_PRINCIPAL,"name");
        rmi_env.put(Context.SECURITY_CREDENTIALS,"password");
        */
        InitialContext ctxInitial = new InitialContext();
        ctxInitial.list(""); //need this to check if there actually is a context
        Object o = ctxInitial.lookup(name);
        ctxInitial.close();
        return o;
    }

public static void main(String[] args) {
        DataSourceChecker dsc = new DataSourceChecker(args); //The constructor simply processes the command line args
        dsc.run();
    }

}