org.pentaho.reporting.libraries.xmlns.parser
Class AbstractXmlReadHandler

java.lang.Object
  extended by org.pentaho.reporting.libraries.xmlns.parser.AbstractXmlReadHandler
All Implemented Interfaces:
XmlReadHandler
Direct Known Subclasses:
IgnoreAnyChildReadHandler, PropertiesReadHandler, StringReadHandler

public abstract class AbstractXmlReadHandler
extends java.lang.Object
implements XmlReadHandler

A base class for implementing an XmlReadHandler. This class takes care of all the delegation management.


Constructor Summary
protected AbstractXmlReadHandler()
          Creates a new handler.
 
Method Summary
 void characters(char[] ch, int start, int length)
          This method is called to process the character data between element tags.
protected  java.util.Map deriveParseParameters()
          Creates a working copy of the current parse state.
protected  void doneParsing()
          Done parsing.
 void endElement(java.lang.String uri, java.lang.String tagName)
          This method is called at the end of an element.
protected  XmlReadHandler getHandlerForChild(java.lang.String uri, java.lang.String tagName, org.xml.sax.Attributes atts)
          Returns the handler for a child element.
 org.xml.sax.Locator getLocator()
          Returns the locator as provided by the XML parser.
 RootXmlReadHandler getRootHandler()
          Returns the root handler for the parsing.
 java.lang.String getTagName()
          Returns the tag name.
 java.lang.String getUri()
          Returns the uri of the element.
 void init(RootXmlReadHandler rootHandler, java.lang.String uri, java.lang.String tagName)
          Initialises the handler.
protected  boolean isSameNamespace(java.lang.String namespaceURI)
          Checks whether the given url denotes the same namespace as the element's namespace.
protected  java.lang.Object performExternalParsing(java.lang.String file, java.lang.Class targetClass)
          Parses an external file using LibLoader and returns the parsed result as an object of type targetClass.
protected  java.lang.Object performExternalParsing(java.lang.String file, java.lang.Class targetClass, java.util.Map map)
          Parses an external file using LibLoader and returns the parsed result as an object of type targetClass.
 void startElement(java.lang.String uri, java.lang.String tagName, org.xml.sax.Attributes attrs)
          This method is called at the start of an element.
protected  void startParsing(org.xml.sax.Attributes attrs)
          Starts parsing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler
getObject
 

Constructor Detail

AbstractXmlReadHandler

protected AbstractXmlReadHandler()
Creates a new handler.

Method Detail

init

public void init(RootXmlReadHandler rootHandler,
                 java.lang.String uri,
                 java.lang.String tagName)
Initialises the handler.

Specified by:
init in interface XmlReadHandler
Parameters:
rootHandler - the root handler.
tagName - the tag name.
uri - the namespace uri.

startElement

public final void startElement(java.lang.String uri,
                               java.lang.String tagName,
                               org.xml.sax.Attributes attrs)
                        throws org.xml.sax.SAXException
This method is called at the start of an element.

Specified by:
startElement in interface XmlReadHandler
Parameters:
tagName - the tag name.
attrs - the attributes.
uri - the namespace uri.
Throws:
org.xml.sax.SAXException - if there is a parsing error.

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws org.xml.sax.SAXException
This method is called to process the character data between element tags.

Specified by:
characters in interface XmlReadHandler
Parameters:
ch - the character buffer.
start - the start index.
length - the length.
Throws:
org.xml.sax.SAXException - if there is a parsing error.

endElement

public final void endElement(java.lang.String uri,
                             java.lang.String tagName)
                      throws org.xml.sax.SAXException
This method is called at the end of an element.

Specified by:
endElement in interface XmlReadHandler
Parameters:
tagName - the tag name.
uri - the namespace uri.
Throws:
org.xml.sax.SAXException - if there is a parsing error.

startParsing

protected void startParsing(org.xml.sax.Attributes attrs)
                     throws org.xml.sax.SAXException
Starts parsing.

Parameters:
attrs - the attributes.
Throws:
org.xml.sax.SAXException - if there is a parsing error.

doneParsing

protected void doneParsing()
                    throws org.xml.sax.SAXException
Done parsing.

Throws:
org.xml.sax.SAXException - if there is a parsing error.

isSameNamespace

protected boolean isSameNamespace(java.lang.String namespaceURI)
Checks whether the given url denotes the same namespace as the element's namespace.

Parameters:
namespaceURI - the namespace that should be tested.
Returns:
true, if the namespace matches the element's namespace,false otherwise.

getHandlerForChild

protected XmlReadHandler getHandlerForChild(java.lang.String uri,
                                            java.lang.String tagName,
                                            org.xml.sax.Attributes atts)
                                     throws org.xml.sax.SAXException
Returns the handler for a child element.

Parameters:
uri - the URI of the namespace of the current element.
tagName - the tag name.
atts - the attributes.
Returns:
the handler or null, if the tagname is invalid.
Throws:
org.xml.sax.SAXException - if there is a parsing error.

getTagName

public java.lang.String getTagName()
Returns the tag name.

Returns:
the tag name.

getUri

public java.lang.String getUri()
Returns the uri of the element. The URI identifies the namespace.

Returns:
the element's URI.

getRootHandler

public RootXmlReadHandler getRootHandler()
Returns the root handler for the parsing.

Returns:
the root handler.

getLocator

public org.xml.sax.Locator getLocator()
Returns the locator as provided by the XML parser. This method may return null if the XML parser has no locator support.

Returns:
the locator or null.

performExternalParsing

protected java.lang.Object performExternalParsing(java.lang.String file,
                                                  java.lang.Class targetClass)
                                           throws ParseException,
                                                  org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException
Parses an external file using LibLoader and returns the parsed result as an object of type targetClass. The file is given as relative pathname (relative to the current source file). The current helper-methods are used as parse-parameters for the external parsing.

Parameters:
file - the file to be parsed.
targetClass - the target type of the parse operation.
Returns:
the result, never null.
Throws:
ParseException - if parsing the result failed for some reason.
org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException - if there was an IO error loading the resource.
See Also:
deriveParseParameters(), performExternalParsing(String, Class, Map)

performExternalParsing

protected java.lang.Object performExternalParsing(java.lang.String file,
                                                  java.lang.Class targetClass,
                                                  java.util.Map map)
                                           throws ParseException,
                                                  org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException
Parses an external file using LibLoader and returns the parsed result as an object of type targetClass. The file is given as relative pathname (relative to the current source file). The current helper-methods are used as parse-parameters for the external parsing.

Parameters:
file - the file to be parsed.
targetClass - the target type of the parse operation.
map - the map of parse parameters.
Returns:
the result, never null.
Throws:
ParseException - if parsing the result failed for some reason.
org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException - if there was an IO error loading the resource.
See Also:
deriveParseParameters()

deriveParseParameters

protected java.util.Map deriveParseParameters()
Creates a working copy of the current parse state.

Returns:
the derived parse-parameters.