2 Replies Latest reply on Aug 14, 2006 6:23 PM by peterj

    How to determine what is in an InitialContext?


      Is it possible to see all the bindings in an InitialContext? I see the list() methods, but I don't really get how the String and Name parameters would work in order to dump out what is in the context, and how can you list sub-contexts?

      Thanks and Regards,


        • 1. Re: How to determine what is in an InitialContext?

          I've written code which dumps out an InitialContext using the list() method. I used an empty String and "java:" as the inputs which seems to give me decent results. Are there any other names which would make sense?

          Also, I found that in some circumstances, as I recurse through the tree of objects within the context, the Enumeration returns by the list() method sometimes returns a String object, rather than a NameClassPair object:

          private static void dumpContextList( Logger lgr, Level lvl, Context ctx, String name, String prefix)
           for( Enumeration e = ctx.list( name ); e.hasMoreElements(); ) {
           Object o = e.nextElement();
           if ( o instanceof NameClassPair ) {
           } else {
           lgr.log( "Found object of Class " + o.getClass().getName() + " = \"" + o.toString() + "\"" );

          Am I missing something here, or is this a bug?

          • 2. Re: How to determine what is in an InitialContext?

            I don't think I have very seen plain Strings coming back from JNDI, but I have had fun dealing with the Proxy classes, some of which don't appear to have a toString method.

            I have noted in my own code that "java:" and "java:comp" tend to return different things. Also try the empty string, that will give you the things in the global namespace. You might also check for subcontexts and dump out the contents of those also.