edu.isi.pegasus.planner.parser
Class Parser

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

public abstract class Parser
extends DefaultHandler

This is the base class which all the xml parsing classes extend. It initializes the xml parser namely Xerces, sets it's various features like turning on validation against schema etc, plus the namespace resolution.

Version:
$Revision: 2603 $
Author:
Karan Vahi, Gaurang Mehta

Field Summary
protected  String DEFAULT_PARSER_NAME
          Default parser name.
protected  boolean mAdjFName
          Boolean flag to ensure that two adjacent filenames are separated by a whitespace.
protected  Locator mLocator
          Locator object to determine on which line in the xml has the error occured.
protected  LogManager mLogger
          The LogManager object which logs the Pegasus messages.
protected  String mLogMsg
          The String which contains the messages to be logged.
protected  XMLReader mParser
          The object which is used to parse the dax.
protected  PegasusProperties mProps
          The object holding all the properties pertaining to Pegasus.
protected  StringBuffer mTextContent
          Holds the text in an element (text between start and final tags if any).
protected  String mTextString
          A String that holds the contents of data passed as text.
 
Constructor Summary
Parser(PegasusBag bag)
          Intialises the parser.
Parser(PegasusProperties properties)
          Intialises the parser.
 
Method Summary
 void characters(char[] chars, int start, int length)
          This is used to store the character data that is in xml.
private  void createParserInstance()
          Creates an instance of the parser, and sets the various options to it.
abstract  void endDocument()
          This is called automatically when the end of the XML file is reached.
abstract  void endElement(String uri, String localName, String qName)
          An empty implementation is provided by DefaultHandler class.
abstract  String getSchemaLocation()
          Helps the load database to locate the XML schema, if available.
abstract  String getSchemaNamespace()
          Returns the XML schema namespace that a document being parsed conforms to.
 String ignoreWhitespace(String str)
          Our own implementation for ignorable whitespace.
 String ignoreWhitespace(String str, boolean preserveLineBreak)
          Our own implementation for ignorable whitespace.
 void setDocumentLocator(Locator loc)
          Overrides the empty implementation provided by Default Handler and sets the locator variable for the locator.
 boolean setParserFeature(String uri, boolean flag)
          Sets a parser feature, and fails here enabling us to set all the following features.
 void setSchemaLocations(String list)
          Sets the list of external real locations where the XML schema may be found.
abstract  void startElement(String uri, String local, String raw, Attributes attrs)
          An empty implementation is provided by DefaultHandler of ContentHandler.
abstract  void startParser(String file)
          Start the parser.
 void testForFile(String file)
          Tests whether the file exists or not.
 
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

DEFAULT_PARSER_NAME

protected final String DEFAULT_PARSER_NAME
Default parser name. Using Xerces at present.

See Also:
Constant Field Values

mLocator

protected Locator mLocator
Locator object to determine on which line in the xml has the error occured.


mTextContent

protected StringBuffer mTextContent
Holds the text in an element (text between start and final tags if any). Used in case of elements of mixed type.


mLogger

protected LogManager mLogger
The LogManager object which logs the Pegasus messages.


mLogMsg

protected String mLogMsg
The String which contains the messages to be logged.


mParser

protected XMLReader mParser
The object which is used to parse the dax. This reads the XML document and sends it to the event handlers.


mProps

protected PegasusProperties mProps
The object holding all the properties pertaining to Pegasus.


mTextString

protected String mTextString
A String that holds the contents of data passed as text. The string should only be trimmed when the appropriate end tag of the element is invoked. At this point, a whitespace is added if there are whitespaces in at the ends.


mAdjFName

protected boolean mAdjFName
Boolean flag to ensure that two adjacent filenames are separated by a whitespace.

Constructor Detail

Parser

public Parser(PegasusBag bag)
Intialises the parser. Sets the various features. However the parsing is done in the implementing class, by call mParser.parse(filename).

Parameters:
bag - the bag of objects that is useful for initialization.

Parser

public Parser(PegasusProperties properties)
Intialises the parser. Sets the various features. However the parsing is done in the implementing class, by call mParser.parse(filename).

Parameters:
properties - the properties passed at runtime.
Method Detail

startElement

public abstract void startElement(String uri,
                                  String local,
                                  String raw,
                                  Attributes attrs)
                           throws SAXException
An empty implementation is provided by DefaultHandler of ContentHandler. This method receives the notification from the sacks parser when start tag of an element comes. Any parser class must implement this method.

Specified by:
startElement in interface ContentHandler
Overrides:
startElement in class DefaultHandler
Throws:
SAXException

endElement

public abstract void endElement(String uri,
                                String localName,
                                String qName)
                         throws SAXException
An empty implementation is provided by DefaultHandler class. This method is called automatically by the Sax parser when the end tag of an element comes in the xml file. Any parser class should implement this method

Specified by:
endElement in interface ContentHandler
Overrides:
endElement in class DefaultHandler
Throws:
SAXException

endDocument

public abstract void endDocument()
This is called automatically when the end of the XML file is reached.

Specified by:
endDocument in interface ContentHandler
Overrides:
endDocument in class DefaultHandler

startParser

public abstract void startParser(String file)
Start the parser. This starts the parsing of the file by the parser.

Parameters:
file - the path to the XML file you want to parse.

getSchemaLocation

public abstract String getSchemaLocation()
Helps the load database to locate the XML schema, if available. Please note that the schema location URL in the instance document is only a hint, and may be overriden by the findings of this method.

Returns:
a location pointing to a definition document of the XML schema that can read VDLx. Result may be null, if such a document is unknown or unspecified.

getSchemaNamespace

public abstract String getSchemaNamespace()
Returns the XML schema namespace that a document being parsed conforms to.

Returns:
the schema namespace

setSchemaLocations

public void setSchemaLocations(String list)
Sets the list of external real locations where the XML schema may be found. Since this list can be determined at run-time through properties etc., we expect this function to be called between instantiating the parser, and using the parser

Parameters:
list - is a list of strings representing schema locations. The content exists in pairs, one of the namespace URI, one of the location URL.

characters

public void characters(char[] chars,
                       int start,
                       int length)
This is used to store the character data that is in xml. An implementation of the interface for the Sacks parser.

Specified by:
characters in interface ContentHandler
Overrides:
characters in class DefaultHandler

ignoreWhitespace

public String ignoreWhitespace(String str)
Our own implementation for ignorable whitespace. A String that holds the contents of data passed as text by the underlying parser. The whitespaces at the end are replaced by one whitespace.

Parameters:
str - The string that contains whitespaces.
Returns:
String corresponding to the trimmed version.

ignoreWhitespace

public String ignoreWhitespace(String str,
                               boolean preserveLineBreak)
Our own implementation for ignorable whitespace. A String that holds the contents of data passed as text by the underlying parser. The whitespaces at the end are replaced by one whitespace.

Parameters:
str - The string that contains whitespaces.
Returns:
String corresponding to the trimmed version.

setDocumentLocator

public void setDocumentLocator(Locator loc)
Overrides the empty implementation provided by Default Handler and sets the locator variable for the locator.

Specified by:
setDocumentLocator in interface ContentHandler
Overrides:
setDocumentLocator in class DefaultHandler
Parameters:
loc - the Locator object which keeps the track as to the line numbers of the line being parsed.

testForFile

public void testForFile(String file)
                 throws FileNotFoundException
Tests whether the file exists or not.

Throws:
FileNotFoundException

createParserInstance

private void createParserInstance()
Creates an instance of the parser, and sets the various options to it.


setParserFeature

public boolean setParserFeature(String uri,
                                boolean flag)
Sets a parser feature, and fails here enabling us to set all the following features.

Parameters:
uri - is the feature's URI to modify
flag - is the new value to set.
Returns:
true if the feature could be set, else false for an exception.


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