Jato: The new kid on the open source block, Part 1
A new library for converting between Java and XML
Kept separate, XML and Java are environmentally friendly, but sound scientific evidence indicates the effort developers exert
to merge them may contribute to global warming. This article, the first of three, introduces the open-source Jato API, a better
way to turn XML documents into Java application objects and vice versa. First, we will examine Jato's key features, architecture,
and important classes. Then we will develop Jato scripts to perform basic Java-to-XML and XML-to-Java transformations. So
get ready to strip out those hundreds of lines of XML parsing code and replace them with a few lines of Jato script!
Read the whole "Jato: The New Kid on the Open Source Block" series:
Note: At the time of this writing, Jato is in Beta 2, with tremendous development work being piled into it. Occasionally, a change
is made that will break backwards compatibility. To ensure the article examples work properly, the distribution will include
all the samples from this series.
What is Jato?
Jato is an open-source Java API and XML language for transforming XML documents into a set of Java objects and back again.
Jato scripts describe the operations to perform and leave the algorithms for implementing the operations to an interpreter.
A Jato script expresses the relationships between XML elements and Java objects, freeing the developer from writing iteration
loops, recursive routines, error-checking code, and many other error-prone, verbose, and monotonous XML parsing chores.
Jato has many advantages over directly employing traditional Java XML APIs such as JDOM, SAX, or DOM. Those advantages include:
- Jato encourages XML and Java designs to be optimized for their specified tasks. Well-designed systems have a low degree of
coupling, allowing one to make independent changes to portions of a system without it breaking. Indeed, it's a good idea for
XML DTD and Java object-oriented design to be developed and deployed independently.
- With Jato, developers simply express the XML elements that map to or from specific Java classes. The Jato interpreter then
implements the necessary parsing and generation algorithms to accomplish the desired actions. As such, you avoid the monotonous,
monolithic, and difficult-to-maintain XML parsing and generation code.
- Using XML to describe transformation to or from XML in Java applications just seems natural. I will never forget the first
time an application called for parsing an XML document to create a set of Java objects. After about 150 lines of code, most
of the remaining 850 lines consisted of cut-and-paste operations followed by altering element, attribute, class, and method
names. Whenever a task involves that much cut-and-paste, it just begs to be automated.
Key Jato features
Jato's design and feature set directly result from implementing real-world projects. Jato is feature-rich, but hopefully not
at the expense of usability or readability. Its key features include: