views:

31

answers:

1

Using the com.sun.jndi.fscontext.RefFSContextFactory file based JNDI context factory and it seems to only allow 1 binding file in location you specify. For example

Hashtable properties = new Hashtable(2);
properties.put(Context.PROVIDER_URL,"file:///tmp/jms/mycontext");
properties.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
InitialContext ctx = new InitialContext(properties);

Is there a way to create a directory structure for say comp.env so that each directory has a bindings file ? (Instead of specifying the complete context in the bindings file itself)

+1  A: 

Each directory is a sub-context which is accessed as a path. Directories are branch nodes that each contain a .bindings as their leaf node. Each branch can have exactly one leaf and zero or more additional branches.

How you do this depends on the tool you are using. I can provide examples from WebSphere MQ's JMSAdmin tool but others will have slightly (or wildly) different syntax. Since Sun's FSContext is used in both our examples, the context traversal works the same although our administrative tools may differ in syntax.

Using JMSAdmin you can DEFINE CTX(subcontext_name) and this creates a directory under which will reside a .bindings file. You can then CHANGE CTX(subcontext_name) to make that subcontext the current one. Anything you define will now be in the .bindings file within that subcontext.

In your code you refer to the subcontext as a path. For example, after opening the initial context you can lookup an object as subcontext_name/foo.

There's more on the IBM implementation of this in the WebSphere MQ Using Java manual under Manipulating Subcontexts. Although the syntax may differ from what you are using, the tool is JMS compliant and uses com.sun.jndi.fscontext.RefFSContextFactory so the principles will be the same.

T.Rob
That is not what the question is. I am wondering if we can nicely structure the subcontext in a directory structure so it is more oranized and we don't end up with one huge .bindings file
mrjohn
I guess using the com.sun.jndi.fscontext.RefFSContextFactory you can only have one file that has the complete context.
mrjohn
If you mean per-directory, then yes. A separate .bindings per directory works but not a hierarchy of contexts within a single .bindings file.
T.Rob