com.ricebridge.xmlman.in
Class XmlInputHandler

java.lang.Object
  extended bycom.ricebridge.xmlman.in.XmlInputHandler
All Implemented Interfaces:
Runnable

public class XmlInputHandler
extends Object
implements Runnable

Handles XML loading and parsing operations.

This is a single use object, a new instance must be created for each operation. Used internally by XmlManager.


Constructor Summary
XmlInputHandler()
          Empty constructor.
 
Method Summary
 XmlInputHandler copy(XmlSpec pXmlSpec)
          Create a copy with new XmlSpec.
 RecordListener getAutoRecordListener()
          Retrieve the automatic RecordListener object for the current load operation.
 BadRecordListener getBadRecordListener()
          Get the BadRecordListener object currently in use.
 String[] getFieldNames()
          Get the field names of the primary RecordSpec - may be null.
 RecordListener getRecordListener()
          Get the current RecordListener.
 SAXParserFactory getSAXParserFactory()
          Get the current SAXParserFactory used for creating XML parsers.
 MutableStats getStats()
          Get the current Stats object used when loading XML record data.
 XmlSpec getXmlSpec()
          Get the current XmlSpec object to use when loading XML record data.
 boolean isFinished()
          When true, the loading process has finished.
 void loadSaxFile(File pXmlFile)
          Load XML data from a file, using a SAX parser.
 void loadSaxFromString(String pXmlString)
          Load XML data from a String, using a SAX parser.
 void loadSaxInputSource(InputSource pXmlInputSource)
          Load XML data from an InputSource, using a SAX parser.
 void loadSaxInputStream(InputStream pXmlInputStream)
          Load XML data from an InputStream, using a SAX parser.
 void loadSaxURI(String pURI)
          Load XML data from a Uniform Resource Identifier (URI), using a SAX parser.
static String makeEncoding(XmlSpec pXmlSpec)
          Resolve the current encoding using the current XmlSpec.
static ParseResult parse(String pPathString, XmlSpec pXmlSpec, boolean pMustBeLocationPath, boolean pSplitOnDescend)
          Parse an XPath string into a set of TargetPaths.
 void prepare(RecordSpec pRecordSpec)
          Prepare internal data structures using the specified RecordSpec.
 SaxHandler prepareSaxHandler()
          Create a SaxHandler initialised with the current list of TargetPaths.
 void run()
          Start loading operation in separate Thread.
 void setAutoRecordListener(RecordListener pRecordListener)
          Store the automatic RecordListener object for the current load operation.
 void setBadRecordListener(BadRecordListener pBadRecordListener)
          Set the BadRecordListener object to receive BadRecord description objects as bad data records are encountered.
 void setRecordListener(RecordListener pRecordListener)
          Set the RecordListener for the current parse operation.
 void setSAXParserFactory(SAXParserFactory pSAXParserFactory)
          Set the SAXParserFactory object that creates the SAXParser object for parsing XML.
 void setStats(MutableStats pStats)
          Set the Stats object to use when loading XML record data.
 void setXmlSpec(XmlSpec pXmlSpec)
          Set the XmlSpec object to use when loading XML record data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlInputHandler

public XmlInputHandler()
Empty constructor.

Method Detail

copy

public XmlInputHandler copy(XmlSpec pXmlSpec)
Create a copy with new XmlSpec.


run

public void run()
Start loading operation in separate Thread.

Specified by:
run in interface Runnable
See Also:
XmlSpec.setBackground(boolean)

isFinished

public boolean isFinished()
When true, the loading process has finished.

When false, the loading process is still in progress. Use this method when the loading process is running in the background as a separate thread. See XmlSpec.setBackground(boolean) for details.

See Also:
XmlSpec.setBackground(boolean)

setXmlSpec

public void setXmlSpec(XmlSpec pXmlSpec)
Set the XmlSpec object to use when loading XML record data.

The XmlSpec class lets you set the options to use when loading XML. For full details, see the XmlSpec documentation.

Parameters:
pXmlSpec - the XmlSpec object to use
See Also:
XmlSpec

getXmlSpec

public XmlSpec getXmlSpec()
Get the current XmlSpec object to use when loading XML record data.

If no XmlSpec has been specified, a default one will be created and stored.

See Also:
setXmlSpec(com.ricebridge.xmlman.XmlSpec)

setStats

public void setStats(MutableStats pStats)
Set the Stats object to use when loading XML record data.

Statistics (such as number of records) are saved to this object.

Parameters:
pStats - Stats object to use
See Also:
Stats

getStats

public MutableStats getStats()
Get the current Stats object used when loading XML record data.

If no Stats object has been specified, a default one will be created and stored.

See Also:
setStats(com.ricebridge.xmlman.in.MutableStats)

setAutoRecordListener

public void setAutoRecordListener(RecordListener pRecordListener)
Store the automatic RecordListener object for the current load operation.

This RecordListener is automatically used by the load operation.

Parameters:
pRecordListener - automatic RecordListener

getAutoRecordListener

public RecordListener getAutoRecordListener()
Retrieve the automatic RecordListener object for the current load operation.

See Also:
setAutoRecordListener(com.ricebridge.xmlman.RecordListener)

setBadRecordListener

public void setBadRecordListener(BadRecordListener pBadRecordListener)
Set the BadRecordListener object to receive BadRecord description objects as bad data records are encountered.

If the ignore bad records option is true then each BadRecord is reported to the BadRecordListener. If it is false, then only the first BadRecord is reported, before processing halts.

Parameters:
pBadRecordListener - BadRecordListener object

getBadRecordListener

public BadRecordListener getBadRecordListener()
Get the BadRecordListener object currently in use.

If a BadRecordListener object has not been specified then a default one will be created and stored.


setSAXParserFactory

public void setSAXParserFactory(SAXParserFactory pSAXParserFactory)
Set the SAXParserFactory object that creates the SAXParser object for parsing XML.

This method can be used to customize XML parsing.

Parameters:
pSAXParserFactory - a SAXParserFactory implementation

getSAXParserFactory

public SAXParserFactory getSAXParserFactory()
Get the current SAXParserFactory used for creating XML parsers.


prepare

public void prepare(RecordSpec pRecordSpec)
Prepare internal data structures using the specified RecordSpec.

This method is called once for each RecordSpec before parsing begins to prepare the XmlInputHandler object for the loading operation.

Parameters:
pRecordSpec - RecordSpec object to add
See Also:
RecordSpec

getFieldNames

public String[] getFieldNames()
Get the field names of the primary RecordSpec - may be null.


setRecordListener

public void setRecordListener(RecordListener pRecordListener)
Set the RecordListener for the current parse operation.


getRecordListener

public RecordListener getRecordListener()
Get the current RecordListener.


loadSaxFile

public void loadSaxFile(File pXmlFile)
Load XML data from a file, using a SAX parser.

Parameters:
pXmlFile - XML file to load

loadSaxInputStream

public void loadSaxInputStream(InputStream pXmlInputStream)
Load XML data from an InputStream, using a SAX parser.

Parameters:
pXmlInputStream - InputStream providing XML data

loadSaxInputSource

public void loadSaxInputSource(InputSource pXmlInputSource)
Load XML data from an InputSource, using a SAX parser.

Parameters:
pXmlInputSource - InputSource providing XML data

loadSaxURI

public void loadSaxURI(String pURI)
Load XML data from a Uniform Resource Identifier (URI), using a SAX parser.

Parameters:
pURI - URI indicating location of XML data

loadSaxFromString

public void loadSaxFromString(String pXmlString)
Load XML data from a String, using a SAX parser.

Parameters:
pXmlString - String containing XML

makeEncoding

public static String makeEncoding(XmlSpec pXmlSpec)
Resolve the current encoding using the current XmlSpec.

Defaults to UTF-8 if no encoding is specified.


prepareSaxHandler

public SaxHandler prepareSaxHandler()
Create a SaxHandler initialised with the current list of TargetPaths.


parse

public static ParseResult parse(String pPathString,
                                XmlSpec pXmlSpec,
                                boolean pMustBeLocationPath,
                                boolean pSplitOnDescend)
Parse an XPath string into a set of TargetPaths.

Normally, pSplitOnDescend should be true when inputing XML and false when outputting XML.

Parameters:
pPathString - String containing XPath expression
pXmlSpec - XmlSpec object defining namespaces, etc.
pMustBeLocationPath - XPath must be a location path, not a literal or function
pSplitOnDescend - split TargetPath at descend points


Copyright © 2004-2005 Ricebridge