Wizard API updated!
Tim Boudreau has released a new version of the Swing Wizard library (version 0.997) that fixes the WizardException bug reported in JavaWorld's recent Open Source Java Project profile. The article's examples have been reworked to test out the new, improved WizardException. Thanks, Tim, for this helpful fix!
Open Source Java Projects: The Wizard API

Newsletter sign-up

Sign up for our technology specific newsletters.

Enterprise Java
View all newsletters

Email Address:

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

Look in-depth at Java-to-XML translation

Jato, a new open source Java/XML translator, provides an effective solution to interfacing Java applications and XML documents. In Part 1 of this series, I provided a quick overview of using Jato to transform from Java-to-XML and XML-to-Java. In Part 1 I also discussed Jato's key features, and its important classes and interfaces.

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



This article, the second in a series of three, moves from the general to the specific by examining Java-to-XML transformations in detail. In that context, we'll see examples illustrating how to:

  • Utilize macros to reduce Jato scripting
  • Use the Jato debugger to understand script execution
  • Perform conditional XML generation
  • Obtain an understanding of script execution using debug statements
  • Recursively transform hierarchically structured object systems
  • Invoke Java methods polymorphically
  • Invoke custom Jato functions


The techniques covered in this article represent ideal generating scripts to persist application-configuration information, serialize Java objects for long-term storage, and dynamically generate XML for viewing in Web browsers. As a vehicle for discussing these topics, we will develop a Jato script that converts a directory structure as represented by the java.io.File class into XML. The completed script will perform the following tasks:

  1. Set a path attribute in the XML document's root node that specifies the path of the base directory.
  2. Write permissions, modification date, and size information about each file and directory contained in the base directory.
  3. Recursively write information about the contents of the base directory. Thus, each directory found in the base directory will be examined; moreover, information about each of its files and directories will be generated.


The following listing provides sample output from the finished script:

<?xml version="1.0" encoding="UTF-8"?>
<root path="E:\ARTICLES\jw-jato-2\examples">
   <dir name="examples" modified="Mon, Jan 15, '01" permissions="rw">
      <dir name="step-1" modified="Tue, Jan 16, '01" permissions="rw">
         <file size="1403" modified="Sat, Mar 17, '01" permissions="rw">
             java-to-xml.xml
         </file>
         <file size="3620" modified="Fri, Feb 09 '01" permissions="rw">
             FileToXML.java
         </file>
      </dir>
   </dir>
</root>


Like many XML documents, our example can generate deeply nested XML elements. With recursive macro calls, we can handily generate and process such documents. One of the difficulties with recursive programs is tracking what the program is currently processing. Jato provides an excellent means for tracking program execution with the <Jato:debug> tag. We'll see macros and debugging next.

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.

1 | 2 | 3 | 4 |  Next >
Resources