org.xanot
Class XanotSAXHandler

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by org.xanot.XanotSAXHandler
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

public class XanotSAXHandler
extends org.xml.sax.helpers.DefaultHandler

SAX xml handler. This is the actual engine that maps xml data into the model based on rules profided by rule builder.

Author:
Ferdinand Neman (newm4n _at_ gmail.com)

Field Summary
(package private)  org.apache.log4j.Logger log
           
 
Constructor Summary
XanotSAXHandler(RuleBuilder ruleBuilder)
          Creates a new XanotSAXHandler object.
 
Method Summary
 void characters(char[] ch, int start, int length)
          Triggered by SAX parser when encountered character data in the xml.
 void endDocument()
          Triggered by SAX parser when the xml document ends.
 void endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName)
          Triggered by SAX parser when an end tag is encounter.
 void error(org.xml.sax.SAXParseException e)
          Triggered by SAX if it encouter an error when parsing.
 void fatalError(org.xml.sax.SAXParseException e)
          Triggered by SAX if it encouter a fatal error when parsing.
 java.util.Collection<org.xml.sax.SAXParseException> getErrors()
          Get collection of errors, collected when the parsing is running
 java.util.Collection<org.xml.sax.SAXParseException> getFatals()
          Get collection of fatal errors, collected when the parsing is running
 java.lang.reflect.Method getGetterMethod(java.lang.Class klass, java.lang.String property)
          Get a getter method from a specific property name on a class.
 java.lang.Object getRootObject()
          Get the instance of root object.
 RuleBuilder getRuleBuilder()
          Get the rule builder that providing rules.
 java.lang.reflect.Method getSetterMethod(java.lang.Class klass, java.lang.String property)
          Get a setter method from a specific property name on a class.
 java.util.Collection<org.xml.sax.SAXParseException> getWarnings()
          Get collection of warnings, collected when the parsing is running.
 boolean isStopOnError()
           
 boolean isStopOnFatal()
           
 boolean isStopOnWarning()
          Check wether parsing should halt on any warning.
 void setErrors(java.util.Collection<org.xml.sax.SAXParseException> errors)
          Set collection of errors.
 void setFatals(java.util.Collection<org.xml.sax.SAXParseException> fatals)
          Set collection of fatal errors.
 void setRuleBuilder(RuleBuilder ruleBuilder)
          Set the rule builder that providing rules.
 void setStopOnError(boolean stopOnError)
           
 void setStopOnFatal(boolean stopOnFatal)
           
 void setStopOnWarning(boolean stopOnWarning)
          Set to stp
 void setWarnings(java.util.Collection<org.xml.sax.SAXParseException> warnings)
          Set collection of warnings.
 void startDocument()
          Triggered by SAX parser when it start parsing.
 void startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes attributes)
          Triggered by SAX parser when it encounter the starting of xml element.
 void warning(org.xml.sax.SAXParseException e)
          Triggered by SAX parser when it encounters an Error
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endPrefixMapping, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startPrefixMapping, unparsedEntityDecl
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

org.apache.log4j.Logger log
Constructor Detail

XanotSAXHandler

public XanotSAXHandler(RuleBuilder ruleBuilder)
Creates a new XanotSAXHandler object.

Parameters:
ruleBuilder - Rule builder that provides maping rule.
Method Detail

getRootObject

public java.lang.Object getRootObject()
Get the instance of root object. Call this method after the parsing process have fully finished.

Returns:
Returns the rootObject.

getRuleBuilder

public RuleBuilder getRuleBuilder()
Get the rule builder that providing rules.

Returns:
Returns the ruleBuilder.

setRuleBuilder

public void setRuleBuilder(RuleBuilder ruleBuilder)
Set the rule builder that providing rules.

Parameters:
ruleBuilder - The ruleBuilder to set.

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws org.xml.sax.SAXException
Triggered by SAX parser when encountered character data in the xml.

Specified by:
characters in interface org.xml.sax.ContentHandler
Overrides:
characters in class org.xml.sax.helpers.DefaultHandler
Parameters:
ch - Character data
start - Start offset in the array
length - Length of data starting from the offset.
Throws:
org.xml.sax.SAXException - Thrown if anything goes wrong on the parsing.

endDocument

public void endDocument()
                 throws org.xml.sax.SAXException
Triggered by SAX parser when the xml document ends.

Specified by:
endDocument in interface org.xml.sax.ContentHandler
Overrides:
endDocument in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException - Thrown if anything goes wrong on the parsing.

endElement

public void endElement(java.lang.String uri,
                       java.lang.String localName,
                       java.lang.String qName)
                throws org.xml.sax.SAXException
Triggered by SAX parser when an end tag is encounter.

Specified by:
endElement in interface org.xml.sax.ContentHandler
Overrides:
endElement in class org.xml.sax.helpers.DefaultHandler
Parameters:
uri - URI element
localName - Local name
qName - Tag name
Throws:
org.xml.sax.SAXException - Thrown if anything goes wrong on the parsing.

getSetterMethod

public java.lang.reflect.Method getSetterMethod(java.lang.Class klass,
                                                java.lang.String property)
Get a setter method from a specific property name on a class.

Parameters:
klass - Class to inspect
property - Property name
Returns:
Setter method or null if there's no such setter method for the specified property

getGetterMethod

public java.lang.reflect.Method getGetterMethod(java.lang.Class klass,
                                                java.lang.String property)
Get a getter method from a specific property name on a class.

Parameters:
klass - Class to inspect
property - Property name
Returns:
Getter method or null if there's no such getter method for the specified property

error

public void error(org.xml.sax.SAXParseException e)
           throws org.xml.sax.SAXException
Triggered by SAX if it encouter an error when parsing.

Specified by:
error in interface org.xml.sax.ErrorHandler
Overrides:
error in class org.xml.sax.helpers.DefaultHandler
Parameters:
e - The cause
Throws:
org.xml.sax.SAXException - Thrown if anything goes wrong on the parsing.

fatalError

public void fatalError(org.xml.sax.SAXParseException e)
                throws org.xml.sax.SAXException
Triggered by SAX if it encouter a fatal error when parsing.

Specified by:
fatalError in interface org.xml.sax.ErrorHandler
Overrides:
fatalError in class org.xml.sax.helpers.DefaultHandler
Parameters:
e - The cause
Throws:
org.xml.sax.SAXException - Thrown if anything goes wrong on the parsing.

startDocument

public void startDocument()
                   throws org.xml.sax.SAXException
Triggered by SAX parser when it start parsing.

Specified by:
startDocument in interface org.xml.sax.ContentHandler
Overrides:
startDocument in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException - Thrown if anything goes wrong on the parsing.

startElement

public void startElement(java.lang.String uri,
                         java.lang.String localName,
                         java.lang.String qName,
                         org.xml.sax.Attributes attributes)
                  throws org.xml.sax.SAXException
Triggered by SAX parser when it encounter the starting of xml element.

Specified by:
startElement in interface org.xml.sax.ContentHandler
Overrides:
startElement in class org.xml.sax.helpers.DefaultHandler
Parameters:
uri - The URI
localName - Local Name
qName - Tag name
attributes - Collection of attributes.
Throws:
org.xml.sax.SAXException - Thrown if anything goes wrong on the parsing.

warning

public void warning(org.xml.sax.SAXParseException e)
             throws org.xml.sax.SAXException
Triggered by SAX parser when it encounters an Error

Specified by:
warning in interface org.xml.sax.ErrorHandler
Overrides:
warning in class org.xml.sax.helpers.DefaultHandler
Parameters:
e - The cause
Throws:
org.xml.sax.SAXException - Thrown if anything goes wrong on the parsing.

getWarnings

public java.util.Collection<org.xml.sax.SAXParseException> getWarnings()
Get collection of warnings, collected when the parsing is running.

Returns:
Collection warning.

setWarnings

public void setWarnings(java.util.Collection<org.xml.sax.SAXParseException> warnings)
Set collection of warnings. It is not to be used manually by user since the collection will be emptied eachtime the parsing starts.

Parameters:
warnings - Collection warning.

getErrors

public java.util.Collection<org.xml.sax.SAXParseException> getErrors()
Get collection of errors, collected when the parsing is running

Returns:
Collection of errors.

setErrors

public void setErrors(java.util.Collection<org.xml.sax.SAXParseException> errors)
Set collection of errors. It is not to be used manually by user since the collection will be emptied eachtime the parsing starts.

Parameters:
errors - Collection of errors

getFatals

public java.util.Collection<org.xml.sax.SAXParseException> getFatals()
Get collection of fatal errors, collected when the parsing is running

Returns:
Collection of fatal errors.

setFatals

public void setFatals(java.util.Collection<org.xml.sax.SAXParseException> fatals)
Set collection of fatal errors. It is not to be used manually by user since the collection will be emptied eachtime the parsing starts.

Parameters:
fatals - Collection of fatal errors.

isStopOnWarning

public boolean isStopOnWarning()
Check wether parsing should halt on any warning.

Returns:
True if halt on warning, false if otherwise.

setStopOnWarning

public void setStopOnWarning(boolean stopOnWarning)
Set to stp

Parameters:
stopOnWarning -

isStopOnError

public boolean isStopOnError()

setStopOnError

public void setStopOnError(boolean stopOnError)

isStopOnFatal

public boolean isStopOnFatal()

setStopOnFatal

public void setStopOnFatal(boolean stopOnFatal)


Copyright 2006 null. All Rights Reserved.