The handlers
A handler is sued to load a configuration from a file or something else. There are a set of different handlers included. The ConfigurationManager uses the InputStreamHandler as default handler. When the handler has loaded the configuration it will call the specified parser to build the configuration.The handlers described
InputStreamHandler
This handlers tries to find the desired file in the classpath. It uses the ResourceLocator in orderto search for it. It is the default handler.
This is a source example about hwo to use it:
PropertiesFileHandler
This handler will read in a properties file. It uses also the ResourceLocator to find the propertiesfile. The handler can be used to convert old properties files into a Configuration and then
use the XMLFileHandler to store them as an XML file.
ScriptHandler
This handler is more like an experiment. We are currently thinking about if it might makesense introducing a script language for configurations.
URLHandler
If you want to load the configuration from a webserver then you can use this one.Here is a short example:
import org.jconfig.*;
import org.jconfig.handler.*;
public class URLDemo {
public static void main(String[] args) {
try {
URLHandler handler = new URLHandler();
handler.setURL("http://localhost:8181/test.xml");
ConfigurationManager cm = ConfigurationManager.getInstance();
cm.load(handler,"test");
}
catch (Exception e) {
e.printStackTrace();
}
}
}
Note: If you use the ConfigurationManager to load the configuration then it will keep itin and you can now use:
Configuration config = ConfigurationManager.getConfiguration("test");
to access it.XMLFileHandler
The XMLFileHandler will load a XML file and you have to define the full path and filename. Here is an example:
public void testLoadAndSave() {
File file = new File("/home/app/my_config.xml");
try {
XMLFileHandler handler = new XMLFileHandler();
handler.setFile(file);
Configuration config = handler.load("test");
}
catch (Exception e) {
e.printStackTrace();
}
}
This will load the file my_config.xml from the defined directory and parse the content building a new configuration called ?test?.ConfigServerHandler
This one is used to communicate with the ConfigurationServer. This is an example about how to use it:
java.net.URL jcfURL = null;
try {
ConfigServerHandler urlHandler = new ConfigServerHandler();
urlHandler.setURL("jconfig://localhost:8765/config");
Configuration config = urlHandler.load();
}
catch ( Exception e ) {
e.printStackTrace();
}
DatabaseHandler
This implementation provides the basic requirements for a JDBC Handler. The database structure is quite simple. It is a based on a Configuration table:T_CONFIGURATION
a Category table
T_CATEGORY
a Property table
T_PROPERTY
and a Variable table
T_VARIABLE
A Configuration can have 1:many Categories and 1:many Variables and a category can have 1:many Properties.
Implementation does require that the database support some sort of auto-increment for the object identifier (oid), if you want to store the Configurations.
One problem with the implementation is the ability to store the variable information within the properties. This is an inherent problem with all of the ConfigurationHandlers.
Following properties need to set inside of the jconfig.properties file:
org.jconfig.jdbc.driver org.jconfig.jdbc.user org.jconfig.jdbc.pwd org.jconfig.jdbc.url