net.xoetrope.xml
Class XmlParserFactory

java.lang.Object
  extended by net.xoetrope.xml.XmlParserFactory

public class XmlParserFactory
extends java.lang.Object

A basic factory for setting XML parsers and createing new elements

Copyright (c) Xoetrope Ltd., 2002-2003

$Revision: 2.2 $

License: see License.txt


Constructor Summary
XmlParserFactory()
          null constructor for the XmlParserFactory
 
Method Summary
 XmlElement createXmlElement(java.lang.String name)
          Create a new XML element iwth the specified name
static XmlParserFactory getInstance()
          Get an instance of the parser factory
 XmlParser getParser()
          If not already created, create an XmlParser and return it.
 XmlWriter getWriter(java.io.FileOutputStream fos)
          If not already created, create an XmlWriter instance and return it.
 XmlElement parse(java.io.Reader input)
          Read the passed Reader object and parse its contents into an XmlElement structure of the type defined in the XmlParserFactory.
 XmlElement parse(java.io.Reader input, java.lang.String schemaSource)
          Parse the input stream using a schema.
 void registerXmlClass(java.lang.Class clazz)
          Register an xml element class.
 void registerXmlParser(XmlParser parser)
          Register an XML parser
 void registerXmlWriter(XmlWriter writer)
          Register an XML writer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlParserFactory

public XmlParserFactory()
null constructor for the XmlParserFactory

Method Detail

getInstance

public static XmlParserFactory getInstance()
Get an instance of the parser factory

Returns:
The XmlParserFactory Singleton file for the current project

parse

public XmlElement parse(java.io.Reader input)
Read the passed Reader object and parse its contents into an XmlElement structure of the type defined in the XmlParserFactory.

Parameters:
input - The reader from which the content of the XML structure will be read
Returns:
The root XmlElement resulting from the parsing of the XML

parse

public XmlElement parse(java.io.Reader input,
                        java.lang.String schemaSource)
Parse the input stream using a schema. The default NanoXml parser will not validate and so anoth JAXP conformant parser must be setup.

Parameters:
input - the input stream
schemaSource - the schmea against which to validate.
Returns:
The root XmlElement resulting from the parsing of the XML

getParser

public XmlParser getParser()
If not already created, create an XmlParser and return it.

Returns:
The created XmlParser

getWriter

public XmlWriter getWriter(java.io.FileOutputStream fos)
If not already created, create an XmlWriter instance and return it.

Parameters:
fos - the file output stream for the new writer
Returns:
The writer

createXmlElement

public XmlElement createXmlElement(java.lang.String name)
Create a new XML element iwth the specified name

Parameters:
name - the name of the element
Returns:
the new element

registerXmlClass

public void registerXmlClass(java.lang.Class clazz)
Register an xml element class. Any new elements will be instances of this class

Parameters:
clazz - The class representing the Xml class.

registerXmlParser

public void registerXmlParser(XmlParser parser)
Register an XML parser

Parameters:
parser - The XmlParser which is being registered

registerXmlWriter

public void registerXmlWriter(XmlWriter writer)
Register an XML writer

Parameters:
writer - The XmlWriter which is being registered