org.bifrost.xmlio
Class XmlReader

java.lang.Object
  extended by org.bifrost.xmlio.XmlReader

public class XmlReader
extends java.lang.Object

Read data from an XML file into a graph of objects. One or more objects get created as a result of parsing an XML file.

Created: Feb 22, 2003
Copyright: Copyright (c) 2003
Assumptions: none
Requires: ReaderContentHandler, XmlException
Required by: nothing
Revision History:
2003-04-21 Changed to use JAXP instead of Xerces.
2004-04-14 Support for a configuration object

Example:

 XmlReader reader = new XmlReader("filename.xml", "base.pkg.of.classes");
 SalesLot rootObject = (SalesLot)reader.getRootObject();
 
 Could read a structure like this (where SalesLot is the root Java object 
 and the root XML element):
 <SalesLot>
   <Car>
     <make>Saab</make>
     <model>93</model>
     <year>2001</year>
   </Car>
   <Car>
     <make>Saab</make>
     <model>95</model>
     <year>2002</year>
   </Car>
 </SalesLot>
 
 The SalesLot object would implement a method called addCar(Car newCar)
 which would add each of the Car elements to a Collection.
 
 Car would implement setMake(String theMake), setModel(String theModel)
 and setYear(String theYear).
 

Version:
1.0 (revision $Revision: 1.7 $)
Author:
Donald Kittle (last commit: $Author: donald $)

Field Summary
static java.lang.String EX_FILE
          Exception error messages
static java.lang.String EX_NULL_READER
           
static java.lang.String EX_PARSING
           
static java.lang.String EX_URL
           
 
Constructor Summary
XmlReader(java.io.InputStream reader, java.lang.String targetPackage)
          Constructor.
XmlReader(java.lang.String fileName, java.lang.String targetPackage)
          Constructor.
XmlReader(java.net.URL url, java.lang.String targetPackage)
          Constructor.
 
Method Summary
 org.bifrost.xmlio.config.XmlIOConfig getConfig()
          Get the configuration object
 java.lang.Object getRootObject()
          Returns the root object derived from the xml.
 void setConfig(org.bifrost.xmlio.config.XmlIOConfig config)
          Set the configuration object
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EX_FILE

public static final java.lang.String EX_FILE
Exception error messages

See Also:
Constant Field Values

EX_URL

public static final java.lang.String EX_URL
See Also:
Constant Field Values

EX_PARSING

public static final java.lang.String EX_PARSING
See Also:
Constant Field Values

EX_NULL_READER

public static final java.lang.String EX_NULL_READER
See Also:
Constant Field Values
Constructor Detail

XmlReader

public XmlReader(java.lang.String fileName,
                 java.lang.String targetPackage)
          throws XmlException
Constructor. Reads the xml from the file into an object. The target objects that reflect the elements of the xml file exist in the package specified by the targetPackage parameter.

Parameters:
fileName - The path and filename of the xml file
targetPackage - The package where the classes representing the xml are located
Throws:
XmlException - when a file or parsing error occurs

XmlReader

public XmlReader(java.net.URL url,
                 java.lang.String targetPackage)
          throws XmlException
Constructor. Reads the xml from the url into an object. The target objects that reflect the elements of the xml file exist in the package specified by the targetPackage parameter.

Parameters:
url - The url for the xml file
targetPackage - The package where the classes representing the xml are located
Throws:
XmlException - when a file or parsing error occurs

XmlReader

public XmlReader(java.io.InputStream reader,
                 java.lang.String targetPackage)
          throws XmlException
Constructor. Reads the xml input stream into an object. The target objects that reflect the elements of the xml file exist in the package specified by the targetPackage parameter.

Parameters:
reader - The input reader for the xml file
targetPackage - The package where the classes representing the xml are located
Throws:
XmlException - when a file or parsing error occurs
Method Detail

getConfig

public org.bifrost.xmlio.config.XmlIOConfig getConfig()
Get the configuration object

Returns:
the configuration object

setConfig

public void setConfig(org.bifrost.xmlio.config.XmlIOConfig config)
Set the configuration object

Parameters:
config - the configuration object

getRootObject

public java.lang.Object getRootObject()
Returns the root object derived from the xml.

Returns:
Object the the root object derived from the xml or null if the xml could not be parsed