Creating your data files
Simple-JNDI stores values in multiple .properties, xml or ini files and are looked up using a specified name convention, such as dot or slash delimited. It is also possible to set the type of object a property represents. As already mentioned, the files are located under a root directory as specified with the org.osjava.sj.root property.
In addition to the delimited lookup key structure, directory names and file names become part of the lookup key. Each delimited tree-node becomes a JNDI Context, while the leaves are implementations. The only exceptions are pseudo sub-values, which you will see with DataSource and other converters.
Examples
The easiest way to understand is to consider a few examples. Imagine a file-structure looking like,
config/
config/debug.properties
config/ProductionDS.properties
config/application1/default.properties
config/application1/ds.properties
config/application1/users.properties
in which the files look like;
- default.properties
-
name=Prototype
url=http://www.generationjava.com/
- debug.properties
-
state=ERROR
- ProductionDS.properties
-
type=javax.sql.DataSource
driver=org.gjt.mm.mysql.Driver
url=jdbc:mysql://localhost/testdb
user=testuser
password=testing
- application1/default.properties
-
name=My Application
version=v3.4
- application1/ds.properties
-
TestDS.type=javax.sql.DataSource
TestDS.driver=org.gjt.mm.mysql.Driver
TestDS.url=jdbc:mysql://localhost/testdb
TestDS.user=testuser
TestDS.password=testing
- application1/users.properties
-
admin=fred
customer=jim
quantity=5
quantity.type=java.lang.Integer
enabled=true
enabled.type=java.lang.Boolean
The following pieces of Java are all legal ways in which to get values from Simple-JNDI. They assume they are preceded with a line of 'InitialContext ctxt = new InitialContext();'.
- Object value = ctxt.lookup("debug.state")
- Object value = ctxt.lookup("name")
- Object value = ctxt.lookup("url")
- Object value = ctxt.lookup("ProductionDS")
- Object value = ctxt.lookup("application1.name")
- Object value = ctxt.lookup("application1.TestDS")
- Object value = ctxt.lookup("application1.users.admin")
- Object value = ctxt.lookup("application1.users.quantity")
- Object value = ctxt.lookup("application1.users.enabled")
Note that the ProductionDS and TestDS return types are objects of type javax.sql.DataSource, while application1.users.quantity is an Integer and application1.users.enabled is the Boolean true value.