xml2class
XML data structures

xml2class
Class XML2ClassParser

java.lang.Object
  |
  +--xml2class.XML2ClassParser

public class XML2ClassParser
extends java.lang.Object

The XML2ClassParser extracts data about a present data structure (i.e. it must already be implemented) out of XML code and instantiates a new instance of it with the values available from an XML source. To be precise: it is just a tool which should help to program clear and easy maintainable structures, as it won't do all the work for you.

Simply speaking is all you need a data structure and an XML file describing it. Now you create a new XML2ClassParser and parse the file through a FileReader (or any other Reader . You'll get then the data structure's root element back (as you indicated it), with which you can proceed as usual.

In general, it will be more comfortable to use XMLFile for parsing (and saving). XML2ClassParser just allows you to control the process somewhat better (input not from a file, output not to System.out, using different root elements).

For a more accurate description of its functioning and its limits, please have a look at the xml2class Introduction.

Beware: this parser is no XML validator. Not well-formed or invalid XML may be accepted without error messages. Well-formed and valid XML however may help by omitting future trouble.

Version:
05/08/01
Author:
Simon Bünzli, zeniko@gmx.ch
See Also:
XMLFile, X2cTools, X2cException, GNU General Public License

Constructor Summary
XML2ClassParser()
          Creates a new XML2ClassParser.
XML2ClassParser(java.lang.String classPaths)
          Creates a new XML2ClassParser for the given classpath(s).
XML2ClassParser(java.lang.String[] classPaths)
          Creates a new XML2ClassParser for the given classpath(s).
 
Method Summary
 java.lang.Object parse(java.io.Reader reader)
          Parses a data structure by extracting data from the Reader, beginning with the first instance of the first element, which is found.
 java.lang.Object parse(java.io.Reader reader, java.lang.String elementName)
          Parses a data structure by extracting data from the Reader, beginning with the first instance of the indicated element which is found. The reader should be buffered (it must support mark/reset).
static void printPackageInfo(java.io.PrintWriter out)
          Writes the package's version and copyleft to a PrintWriter.
 void setVerbose(java.io.PrintWriter verbose)
          Sets the parser's verbose output destination (null = not verbose).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XML2ClassParser

public XML2ClassParser()
Creates a new XML2ClassParser. Beware: Any classpath information will have to be included in the element tags!

XML2ClassParser

public XML2ClassParser(java.lang.String classPaths)
Creates a new XML2ClassParser for the given classpath(s).
Parameters:
classPaths - Where any indicated class will be searched (separated by whitespace).

XML2ClassParser

public XML2ClassParser(java.lang.String[] classPaths)
Creates a new XML2ClassParser for the given classpath(s).
Parameters:
classPaths - Where any indicated class will be searched.
Method Detail

parse

public java.lang.Object parse(java.io.Reader reader)
                       throws X2cException

Parses a data structure by extracting data from the Reader, beginning with the first instance of the first element, which is found. The reader should be buffered (it must support mark/reset).

Parameters:
reader - Where the data should come from (usually an XML file).
Returns:
The root element / class of the built up data structure.
Throws:
X2cException - Any exception will be led into a X2cException (or a class extending it).

parse

public java.lang.Object parse(java.io.Reader reader,
                              java.lang.String elementName)
                       throws X2cException

Parses a data structure by extracting data from the Reader, beginning with the first instance of the indicated element which is found.

The reader should be buffered (it must support mark/reset). In order to get several second (or higher) level elements, you'll have to reuse the same reader.

Parameters:
reader - Where the data should come from (usually an XML file).
elementName - The name of the element / class, which you want to start parsing with.
Returns:
The root element / class of the built up data structure.
Throws:
X2cException - Any exception will be led into a X2cException (or a class extending it).

setVerbose

public void setVerbose(java.io.PrintWriter verbose)
Sets the parser's verbose output destination (null = not verbose).
Parameters:
verbose - Where verbose output will be written to, if null, there won't be any.

printPackageInfo

public static void printPackageInfo(java.io.PrintWriter out)
Writes the package's version and copyleft to a PrintWriter.
Parameters:
out - Where the package info should be written to.

xml2class
XML data structures

Copyleft 2001 by Simon Bünzli, zeniko@gmx.ch