Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

Jato: The new kid on the open source block, Part 3

Translate XML documents into Java objects

  • Print
  • Feedback
Welcome back for Part 3 in this series on Jato, the open source, increasingly capable, XML/Java translator. In Part 1, I introduced Jato and how to perform XML-to-Java and Java-to-XML transformations. Since then Jato has experienced a complete redesign, a number of enhancements, and the addition of an interactive debugger. Part 2 focused on generating XML documents from complex Java object structures through an application that generated an XML document containing file system information. Part 2 further discussed macro writing, XML element and attribute creation, debug statements utilization, Java methods invocation, and Jato function writing.

Read the whole "Jato: The New Kid on the Open Source Block" series:



In Part 3, we turn our attention to XML-to-Java transformations and the conditional tags <Jato:if> and <Jato:else>, as well as Jato expressions, recursive XML traversal, constructors invocation, JavaBeans property settings, conditional parameter lists, and a little Swing.

Note: You may find the Jato Syntax Reference Guide useful for obtaining more detailed information on all the tags presented in this article.

Sounds exciting, so let's get started.

The new assignment

In Part 2 we transformed the hierarchical file-structure information contained in a File object into an XML document called site.xml. A partial listing of site.xml is shown is Listing 1:

Listing 1. Partial listing of site.xml

<?xml version="1.0" encoding="UTF-8"?>
<root path="E:\jato\examples">
   <dir name="examples" modified="1/15/01 10:11 PM" permissions="rw">
      <dir name="simple" modified="1/16/01 9:44 PM" permissions="rw">
         <file size="2745" modified="3/16/01 4:49 PM" permissions="rw">
               SimpleXmlToJava.java
         </file>
         <file size="2745" modified="3/16/01 4:49 PM" permissions="rw">
             SimpleXmlToJava.java
         </file>
      </dir>
   </dir>
   <file size="0" modified="3/17/01 10:38 AM" permissions="rw">
      file
   </file>
</root>


In our new assignment, we must create a Jato script that transforms site.xml into a Swing user interface. The finished application is shown in Figure 1.

Figure 1. JatoTree finished appearance



The user interface makes heavy use of the JTreeTable class source code provided in "Creating TreeTables: Part 2," Scott Violet and Kathy Walrath (java.sun.com).

Before jumping into the Jato script that transforms site.xml, let's lightly explore Jato expressions, a feature required to get an A on our assignment.

Jato expressions

Jato introduced expressions with the release of Beta 2 in March 2001. Expressions provide a compact syntax for obtaining current interpreter state information and evaluating logic that would require a large amount of Jato script. Jato uses expressions to perform conditional checks for <Jato:if> and <Jato:elseif> tags, generate debug statements, set the current object, manipulate the current input and output XML elements, construct variable names, and cause surly programmers to perform random acts of kindness. In this aritcle, I'll quickly introduce expressions, while a future article will deal with this subject in detail.

  • Print
  • Feedback

Resources