Dependencies

The Java Config class is used in very different projects, ranging from quick-and-dirty to long-term big projects. Every project has different demands on its components, and each project has a different toolset. To accommodate this variety of tools, the Java Config class is made to be completely stand-alone. Simply include the javaconfig.jar to your classpath, and you're good to go.

Most notably, Java Config does not do any logging by itself. This has the advantage that it is possible to use any logger you want (although the choice is nowadays is pretty easy), but also that it's possible to initialize your logger using setting retrieved by the Config class.

Note: the examples in Java Config use log4j, this is for demonstration purposes only.

This strictness on dependencies has the disadvantage that Java Config itself cannot use extern validation tools to make sure the configuration is correct. However, projects can easily extends Java Config and use (for example) Apache Commons Validation to implement their own validation.

How does it work?

The core of validation of a Config object is the fact that all methods which are public getters should return a value without throwing an exception. The main validation method in Config simply loops over all existing methods in the current objects, and checks if they behave correctly. If a method throws an exception this implies the method is not satisfied with the content provided to it by the Properties file.

To make the system work, it is important that calls to the getter-method are consistent: they should always return the same result or always throw the same exception. Otherwise callers won't know what to expect, and the whole advantage of a simple point-in-time when a check is done disappears.

Limitations

Known limitations:

  • Whitespaces around values in property-files are ignored. This might cause some slight discomfort for users that need newline characters ("\n") or other whitespace at the beginning or end of their properties.

Feedback

Your feedback is welcome.