Java Graph Transformer
Welcome to the Java Graph Transformer Homepage!

The Java Graph Transformer (JGT) is a Java component that allows you to create or rearrange a graph of Java objects based on the state of a second graph of Java objects and a set of transformation rules.  The transformations are symmetric, so you can map from graph A to graph B and back again.


Data Firewall concept
The driver behind the initial version of JGT was to eliminate the tedious get()/set() coding involved in J2EE applications that employ value objects, but doubtlessly there are other uses.  Value objects are used to shuttle data back and forth between the presentation layer and the persistence (or domain) layer, as shown in the diagram.  This introduces the notion of a data "firewall".  The domain model consists of Person and Address classes, which might realised as Entity Beans.  The application front end is realized as a JSP in the presentation layer.  Communication between the two is realized via a single value object that contains the data from the Person and Address domain objects.  This is a recommended best practise and certainly does offer the advantage of tiering your system, but realizing it involves a lot of tedious code along the lines of :

person.setUserName(valueObject.getUserName());
person.setPassword(valueObject.getPassword());
address.setStreet(valueObject.getStreet());
address.setCity(valueObject.getCity());
address.setPostcode(valueObject.getPostcode());

Additionally, depending on the persistence technology you are using, you can realize a large performance improvement by set()'ing only the fields that need to be set (those that have changed their values usually) and thereby enabling the persistence technology to issue the smallest number of SQL statements required to do the job (although some persistence technologies, like the BEA Weblogic CMP implementation, do this kind of optimization internally).  So, bearing this in mind, the most performant portable J2EE application would rewrite the code above as follows:

if ( ! person.getUserName().equals(valueObject.getUserName())) {
person.setUserName(valueObject.getUserName());
}
if ( ! person.getPassword.equals(valueObject.getPassword())) {
person.setPassword(valueObject.getPassword());
}

Best practise recommends locating this kind of "transformation" code in a Value Object Factory, but nevertheless, writing it is tedious and maintaining it is even more so.  JGT attempts to reduce to a minimum the overhead of this kind of transformation code by providing an XML language tailored to the task of copying data from one object graph to another.  For example, the two clauses above can be stated in JGT as follows:

<graph:set name="name"/> 
<graph:set name="password"/>

JGT in context JGT, therefore can be said to bridge the data firewall, as shown in the second figure.  

JGT provides the following features:

  • Symmetric mapping - define rules that allow a forward mapping from graph A to graph B, and a reverse mapping from graph B to graph A.  This symmetry is required to close the data flow loop that is typical in web applications.
  • Allows the entire suite of mapping rules to be defined once and centrally.  Rules may sectioned into named grouped, which can be independently activated/deactivated at runtime, to match the data requirements of any given use case.
  • Perform the smallest number of set() statement required to realize the mapping.
  • Synchronize collections (including maps) using the smallest number of add() and remove() calls
  • Rules to handle Node Pruning (inserting nulls).
  • Throws PropertyChangeEvents on each graph change to interested listeners.
  • Allow specification by the developer of complex type-conversion rules.
For more information, refer to the tutorial.  Or the code.  Or download the binary.




SourceForge Logo