Skip to content

Declarative creation of contexts and context objects

h-thurow edited this page May 13, 2017 · 6 revisions

In general the directory structure models the context structure. A directory "a/b/c" results in context "a", therein context "b" and "b" containing "c". Calling Context.lookup("a.b.c") will retrieve subcontect "c". The deepest subcontext in this tree becomes created from the properties file name. So "a/b/c/users.properties" leads to the contexts "a.b.c.users". The last subcontext "users" contains the context objects defined as properties within users.properties.

Contexts become also created from delimited property keys. Imagine a file "a.properties" directly in the root directory with a property "b.c.users.admin=...". Simple-JNDI will create the same context structure as in the previous example with the context object "admin" within the last subcontext "users". So you could define the full context structure in only one properties file.

Suppress subcontext creation for file names. Naming a file "default.properties" will hinder Simple-JNDI on creating a subcontext for the filename. So you could rewrite the previous example for creating the context structure through a single properties file. Rename a.properties to default.properties and "b.c.users.admin=..." to "a.b.c.users.admin=...". Again Simple-JNDI will produce the contexts "a.b.c.users" with "admin" as context object in "users".

Delimiter considerations. All previous examples assume the default delimiter ".". When configuring "org.osjava.sj.delimiter=/" you have to replace "." by "/" in property names and lookup calls, e.g. "a/b/c/users/admin=..." and Context.lookup("a/b/c/users/admin"). New in 0.14.0 Use slash separated lookup pathes with dot separated property names.