Tuesday, February 12, 2008

Commons Configuration

Useful book : Jakarta Commons Cookbook
For examples in this book is used an older version of jakarta commons configuration
I used this framework for one of my projects iBean Editor eclipse plugin - for reading hints uded for code autocompletion.
Indeed there are many other posibilities to persist object for example : serialize objects in a file using ObjectInputStream/ObjectOutputStream with methods readObject / writeObject , serialization in xml format is also posible using classis for example from dom4j or ever very nice solution with XStream.
But let's concentrate uppon CommonsConfiguration :
the Classes for example that Extend FileConfiguration have methods like save() ...load() to store modified configuration...
if you want to use .property file youread configuration like this with the this code if I want to parse an xml document like this useful code is this

Note: the 1.5 version of common configuration that I used is a little buggy setting the new delimiter will not work if you will provide the file name in the constructor
so you must first set some properties of delimiter and after load the file like this:
XMLConfiguration config = new XMLConfiguration();
config.setDelimiter('|');
config.setDelimiterParsingDisabled(true);
config.load("codecompletion.xml");


**The examples of code were written to be compatible with java 1.4 otherwise can be used more elegant solution using generics

3 comments: