edu.isi.pegasus.planner.parser
Class StackBasedXMLParser

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by edu.isi.pegasus.planner.parser.Parser
          extended by edu.isi.pegasus.planner.parser.StackBasedXMLParser
All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler
Direct Known Subclasses:
DAXParser3, SiteCatalogParser

public abstract class StackBasedXMLParser
extends Parser

An abstract base class that XML Parsers can use if they use stack internally to store the elements encountered while parsing XML documents using SAX

Version:
$Revision: 2832 $
Author:
Karan Vahi vahi@isi.edu

Field Summary
protected  int mDepth
          Count the depths of elements in the document
protected  boolean mParsingDone
          A boolean indicating that parsing is done.
protected  Stack mStack
          The stack of objects kept around.
 
Fields inherited from class edu.isi.pegasus.planner.parser.Parser
DEFAULT_PARSER_NAME, mAdjFName, mLocator, mLogger, mLogMsg, mParser, mProps, mTextContent, mTextString
 
Constructor Summary
StackBasedXMLParser(PegasusBag bag)
          The overloaded constructor.
 
Method Summary
 void attributeNotSupported(String element, String attribute, String value)
          This is called when an attribute is encountered for an element that is valid in the schema context but not supported right now.
 void complain(String element, String attribute, String value)
          This is called when an attribute is encountered for an element that is invalid from the schema context and is not supported.
abstract  Object createObject(String element, List names, List values)
          Composes the SiteData object corresponding to the element name in the XML document.
 void endDocument()
          This is called automatically when the end of the XML file is reached.
 void endElement(String namespaceURI, String localName, String qName)
          The parser is at the end of an element.
 void log(String element, String attribute, String value)
           
abstract  boolean setElementRelation(String childElement, Object parent, Object child)
          This method sets the relations between the currently finished XML element(child) and its containing element in terms of Java objects.
 void startElement(String namespaceURI, String localName, String qName, Attributes atts)
          This method defines the action to take when the parser begins to parse an element.
 void unSupportedNestingOfElements(String parent, String child)
          Called when certain element nesting is allowed in the XML schema but is not supported in the code as yet.
 
Methods inherited from class edu.isi.pegasus.planner.parser.Parser
characters, getSchemaLocation, getSchemaNamespace, ignoreWhitespace, ignoreWhitespace, setDocumentLocator, setParserFeature, setSchemaLocations, startParser, testForFile
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mDepth

protected int mDepth
Count the depths of elements in the document


mStack

protected Stack mStack
The stack of objects kept around.


mParsingDone

protected boolean mParsingDone
A boolean indicating that parsing is done.

Constructor Detail

StackBasedXMLParser

public StackBasedXMLParser(PegasusBag bag)
The overloaded constructor.

Parameters:
bag - the PegasusBag to be used.
Method Detail

createObject

public abstract Object createObject(String element,
                                    List names,
                                    List values)
Composes the SiteData object corresponding to the element name in the XML document.

Parameters:
element - the element name encountered while parsing.
names - is a list of attribute names, as strings.
values - is a list of attribute values, to match the key list.
Returns:
the relevant SiteData object, else null if unable to construct.
Throws:
IllegalArgumentException - if the element name is too short.

setElementRelation

public abstract boolean setElementRelation(String childElement,
                                           Object parent,
                                           Object child)
This method sets the relations between the currently finished XML element(child) and its containing element in terms of Java objects. Usually it involves adding the object to the parent's child object list.

Parameters:
childElement - name is the the child element name
parent - is a reference to the parent's Java object
child - is the completed child object to connect to the parent
Returns:
true if the element was added successfully, false, if the child does not match into the parent.

endDocument

public void endDocument()
Description copied from class: Parser
This is called automatically when the end of the XML file is reached.

Specified by:
endDocument in interface ContentHandler
Specified by:
endDocument in class Parser

startElement

public void startElement(String namespaceURI,
                         String localName,
                         String qName,
                         Attributes atts)
                  throws SAXException
This method defines the action to take when the parser begins to parse an element.

Specified by:
startElement in interface ContentHandler
Specified by:
startElement in class Parser
Parameters:
namespaceURI - is the URI of the namespace for the element
localName - is the element name without namespace
qName - is the element name as it appears in the docment
atts - has the names and values of all the attributes
Throws:
SAXException

endElement

public void endElement(String namespaceURI,
                       String localName,
                       String qName)
                throws SAXException
The parser is at the end of an element. Triggers the association of the child elements with the appropriate parent elements.

Specified by:
endElement in interface ContentHandler
Specified by:
endElement in class Parser
Parameters:
namespaceURI - is the URI of the namespace for the element
localName - is the element name without namespace
qName - is the element name as it appears in the docment
Throws:
SAXException

log

public void log(String element,
                String attribute,
                String value)
Parameters:
element -
attribute -
value -

complain

public void complain(String element,
                     String attribute,
                     String value)
This is called when an attribute is encountered for an element that is invalid from the schema context and is not supported.

Parameters:
element - the element name
attribute - the attribute name
value - the attribute value

attributeNotSupported

public void attributeNotSupported(String element,
                                  String attribute,
                                  String value)
This is called when an attribute is encountered for an element that is valid in the schema context but not supported right now.

Parameters:
element - the element name
attribute - the attribute name
value - the attribute value

unSupportedNestingOfElements

public void unSupportedNestingOfElements(String parent,
                                         String child)
Called when certain element nesting is allowed in the XML schema but is not supported in the code as yet.

Parameters:
parent - parent element
child - child element


Copyright © 2011 The University of Southern California. All Rights Reserved.