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 2

Look in-depth at Java-to-XML translation

  • Print
  • Feedback
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.

  • Print
  • Feedback
What is Tech Briefcase?
TechBriefcase is a new, free service where IT Professionals can Search, Store and Share IT white papers and content like this. Learn more
Bookmark content
Speed up your research efforts with content across the web.
Search and Store
Find the white papers you need. Create folders for any topic.
View Anywhere
Open your briefcase on your iPhone, tablet or desktop. Share with colleagues.
Don't have an account yet?

Resources