Calitha - Commons (java)

Calitha Commons

Main library dependencies

Additional library dependencies for ANT building

Summary

This Java library has varied classes to provide common functionality for an application. Two examples of such functionality will be discussed here. Documentation of the entire package can be viewed online, and is available for download in the repository.

SimpleDOMParser

Any developer that uses a programmatic XML DOM Parser in a product, realizes that the default settings often are not good enough. DTD's are fetched from remote locations, XSL templates are being parsed over and over, and other problems occur that make the product not perform as good as it should. The solution is to change the configuration of the XML parser. But with all those scattered, yet related, settings it is easy to miss one.

SimpleDOMParser is a wrapper around the Xerces DOMParser, with an easy to use API. The most powerful feature is to pass an implementation of IParserConfiguration to the constructor. The com.calitha.xml package has several implementations of the IParserConfiguration. Two examples:

XML Resource Bundle

Java 1.6 has introduced ResourceBundle.Control which makes it possible to extend the functionality of the ResourceBundle and load resources from different formats. This XML Resource Bundle loads both text and binary resources from special XML files. These XML resource bundle files must be part of the http://namespaces.calitha.com/resourcebundle/1.0 and will be validated against the XML ResourceBundle Schema used for this XML application.

The XML Resource Bundle supports the following resource types:

Synchronization proxy

The idea for this improvement came from the desire to have a new keyword similar to synchronized, but would use a read or write lock. A synchronization proxy allows you to turn an ordinary object into a synchronized object as if each call to the method has the synchronized keyword. This is a nice feature to have, but what's even nicer is that a proxy can also be used to read annotation of methods and determine if a read or write lock is needed. This functionality provides improved concurrency in objects that have rare write operations and frequent read operations. The new annotations feature of Java 1.5 to declare run-time meta-data and the (older) proxy support in Java makes such a custom improvement possible.

Here is some example Java code to demonstrate how to use the RWLock annotation to declare to the synchronization proxy that a read or write lock is needed. @RWLock(RWLock.Type.READ) public long getValue() { return value; } @RWLock(RWLock.Type.WRITE) public void setValue(long value) { this.value = value; }