Package edu.isi.pegasus.planner.parser
Class InvocationParser
- java.lang.Object
-
- org.xml.sax.helpers.DefaultHandler
-
- edu.isi.pegasus.planner.parser.InvocationParser
-
- All Implemented Interfaces:
org.xml.sax.ContentHandler,org.xml.sax.DTDHandler,org.xml.sax.EntityResolver,org.xml.sax.ErrorHandler
public class InvocationParser extends org.xml.sax.helpers.DefaultHandlerThis class uses the Xerces SAX2 parser to validate and parse an XML document which contains information from kickstart generated invocation record.- Version:
- $Revision$
- Author:
- Jens-S. Vöckler, Yong Zhao
-
-
Field Summary
Fields Modifier and Type Field Description private java.text.SimpleDateFormatm_coarseParsing for ISO dates without millisecondsprivate intm_depthCount the depths of elements in the documentprivate java.text.SimpleDateFormatm_fineParsing for ISO dates with millisecond extension.private java.util.Mapm_forwardA Hashmap to forward resolve namespaces that were encountered during parsing.private org.xml.sax.Locatorm_locationKeep the location within the documentprivate org.griphyn.vdl.util.Loggingm_logObtain our logger once for multiple uses.private org.xml.sax.XMLReaderm_parserHolds the instance of aXMLReaderclass.private InvocationRecordm_resultHolds the result, will be overwritten by each invocation of parse().private java.util.Mapm_reverseA Hashmap to reverse resolve namespaces that were encountered during parsing.private java.util.Stackm_stackA stack of namespaces?protected static java.lang.StringvendorParserClassDefault parser is the Xerces parser.
-
Constructor Summary
Constructors Constructor Description InvocationParser(java.lang.String schemaLocation)The class constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcharacters(char[] ch, int start, int length)This method is the callback function for characters in an element.private voidcomplain(java.lang.String subject, java.lang.String name, java.lang.String value)Small helper method to bundle repetitive complaints in a template for reporting progress.protected InvocationcreateObject(Invocation parent, java.lang.String e, java.util.List names, java.util.List values)This method determines the actively parsed element, creates the Java object that corresponds to the element, and sets the member variables with the values of the attributes of the element.voidendDocument()The parser comes to the end of the document.voidendElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName)The parser is at the end of an element.voidendPrefixMapping(java.lang.String prefix)Out of the reach of the prefix, remove it from the HashMap.private java.lang.Stringfull_where()voidignorableWhitespace(char[] ch, int start, int length)Currently, ignorable whitespace will be ignored.private voidlog(java.lang.String subject, java.lang.String name, java.lang.String value)Small helper method to bundle repetitive parameters in a template for reporting progress.private java.lang.Stringmap(java.lang.String uri)Helper function to map prefixes correctly onto the elements.InvocationRecordparse(java.io.InputStream reader)This function parses a XML source from an InputStream source, and creates java class instances that correspond to different elements in the XML source.InvocationRecordparse(java.io.Reader reader)This function parses a XML source from the new Reader source, and creates java class instances that correspond to different elements in the XML source.private java.util.DateparseDate(java.lang.String date)Small helper to parse the different date varieties and deal with Java obnoxeity.voidprocessingInstruction(java.lang.String target, java.lang.String data)Receive a processing instruction.private booleanset(java.lang.String uri, boolean flag)Sets a feature while capturing failed features right here.voidsetDocumentLocator(org.xml.sax.Locator locator)Obtains the document locator from the parser.protected booleansetElementRelation(char initial, Invocation parent, Invocation child)This method sets the relations between the currently finished XML element and its containing element in terms of Java objects.voidsetSchemaLocations(java.lang.String list)Sets the list of external real locations where the XML schema may be found.private voidsetupJob(Job job, java.util.List names, java.util.List values)Small helper method to set up the attributes for the job elements.voidskippedEntity(java.lang.String name)Receive a notification that an entity was skipped.voidstartDocument()This method specifies what to do when the parser is at the beginning of the document.voidstartElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes atts)This method defines the action to take when the parser begins to parse an element.voidstartPrefixMapping(java.lang.String prefix, java.lang.String uri)There is a prefix or namespace defined, put the prefix and its URI in the HashMap.private java.lang.Stringwhere()
-
-
-
Field Detail
-
vendorParserClass
protected static final java.lang.String vendorParserClass
Default parser is the Xerces parser.- See Also:
- Constant Field Values
-
m_parser
private org.xml.sax.XMLReader m_parser
Holds the instance of aXMLReaderclass.
-
m_result
private InvocationRecord m_result
Holds the result, will be overwritten by each invocation of parse().
-
m_location
private org.xml.sax.Locator m_location
Keep the location within the document
-
m_forward
private java.util.Map m_forward
A Hashmap to forward resolve namespaces that were encountered during parsing.
-
m_reverse
private java.util.Map m_reverse
A Hashmap to reverse resolve namespaces that were encountered during parsing.
-
m_coarse
private java.text.SimpleDateFormat m_coarse
Parsing for ISO dates without milliseconds
-
m_fine
private java.text.SimpleDateFormat m_fine
Parsing for ISO dates with millisecond extension.
-
m_log
private org.griphyn.vdl.util.Logging m_log
Obtain our logger once for multiple uses.
-
m_depth
private int m_depth
Count the depths of elements in the document
-
m_stack
private java.util.Stack m_stack
A stack of namespaces?
-
-
Constructor Detail
-
InvocationParser
public InvocationParser(java.lang.String schemaLocation)
The class constructor. This function initializes the Xerces parser and the features that enable schema validation.- Parameters:
schemaLocation- is the default location of the XML Schema which this parser is capable of parsing. It may be null to use the defaults provided in the document.
-
-
Method Detail
-
set
private boolean set(java.lang.String uri, boolean flag)Sets a feature while capturing failed features right here.- Parameters:
uri- is the feature's URI to modifyflag- is the new value to set.- Returns:
- true, if the feature could be set, false for an exception
-
setSchemaLocations
public void setSchemaLocations(java.lang.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.
-
parse
public InvocationRecord parse(java.io.InputStream reader)
This function parses a XML source from an InputStream source, and creates java class instances that correspond to different elements in the XML source.- Parameters:
reader- is a bytestream opened for reading.- Returns:
- the records with the invocation information, or null on failure.
-
parse
public InvocationRecord parse(java.io.Reader reader)
This function parses a XML source from the new Reader source, and creates java class instances that correspond to different elements in the XML source.- Parameters:
reader- is a character stream opened for reading.- Returns:
- the records with the invocation information, or null on failure.
-
setDocumentLocator
public void setDocumentLocator(org.xml.sax.Locator locator)
Obtains the document locator from the parser. The document location can be used to print debug information, i.e the current location (line, column) in the document.- Specified by:
setDocumentLocatorin interfaceorg.xml.sax.ContentHandler- Overrides:
setDocumentLocatorin classorg.xml.sax.helpers.DefaultHandler- Parameters:
locator- is the externally set current position
-
full_where
private java.lang.String full_where()
-
where
private java.lang.String where()
-
startDocument
public void startDocument()
This method specifies what to do when the parser is at the beginning of the document. In this case, we simply print a message for debugging.- Specified by:
startDocumentin interfaceorg.xml.sax.ContentHandler- Overrides:
startDocumentin classorg.xml.sax.helpers.DefaultHandler
-
endDocument
public void endDocument()
The parser comes to the end of the document.- Specified by:
endDocumentin interfaceorg.xml.sax.ContentHandler- Overrides:
endDocumentin classorg.xml.sax.helpers.DefaultHandler
-
startPrefixMapping
public void startPrefixMapping(java.lang.String prefix, java.lang.String uri) throws org.xml.sax.SAXExceptionThere is a prefix or namespace defined, put the prefix and its URI in the HashMap. We can get the URI when the prefix is used here after.- Specified by:
startPrefixMappingin interfaceorg.xml.sax.ContentHandler- Overrides:
startPrefixMappingin classorg.xml.sax.helpers.DefaultHandler- Parameters:
prefix- the Namespace prefix being declared.uri- the Namespace URI the prefix is mapped to.- Throws:
org.xml.sax.SAXException
-
endPrefixMapping
public void endPrefixMapping(java.lang.String prefix) throws org.xml.sax.SAXExceptionOut of the reach of the prefix, remove it from the HashMap.- Specified by:
endPrefixMappingin interfaceorg.xml.sax.ContentHandler- Overrides:
endPrefixMappingin classorg.xml.sax.helpers.DefaultHandler- Parameters:
prefix- is the prefix that was being mapped previously.- Throws:
org.xml.sax.SAXException
-
map
private java.lang.String map(java.lang.String uri)
Helper function to map prefixes correctly onto the elements.- Parameters:
uri- is the parser-returned URI that needs translation.- Returns:
- the correct prefix for the URI
-
startElement
public void startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes atts) throws org.xml.sax.SAXExceptionThis method defines the action to take when the parser begins to parse an element.- Specified by:
startElementin interfaceorg.xml.sax.ContentHandler- Overrides:
startElementin classorg.xml.sax.helpers.DefaultHandler- Parameters:
namespaceURI- is the URI of the namespace for the elementlocalName- is the element name without namespaceqName- is the element name as it appears in the docmentatts- has the names and values of all the attributes- Throws:
org.xml.sax.SAXException
-
endElement
public void endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName) throws org.xml.sax.SAXExceptionThe parser is at the end of an element. Each successfully and completely parsed Definition will trigger a callback to the registered DefinitionHandler.- Specified by:
endElementin interfaceorg.xml.sax.ContentHandler- Overrides:
endElementin classorg.xml.sax.helpers.DefaultHandler- Parameters:
namespaceURI- is the URI of the namespace for the elementlocalName- is the element name without namespaceqName- is the element name as it appears in the docment- Throws:
org.xml.sax.SAXException
-
characters
public void characters(char[] ch, int start, int length) throws org.xml.sax.SAXExceptionThis method is the callback function for characters in an element. The element is expected to be of mixed content.- Specified by:
charactersin interfaceorg.xml.sax.ContentHandler- Overrides:
charactersin classorg.xml.sax.helpers.DefaultHandler- Parameters:
ch- are the characters from the XML documentstart- is the start position into the arraylength- is the amount of valid data in the array- Throws:
org.xml.sax.SAXException
-
ignorableWhitespace
public void ignorableWhitespace(char[] ch, int start, int length) throws org.xml.sax.SAXExceptionCurrently, ignorable whitespace will be ignored.- Specified by:
ignorableWhitespacein interfaceorg.xml.sax.ContentHandler- Overrides:
ignorableWhitespacein classorg.xml.sax.helpers.DefaultHandler- Parameters:
ch- are the characters from the XML documentstart- is the start position into the arraylength- is the amount of valid data in the array- Throws:
org.xml.sax.SAXException
-
processingInstruction
public void processingInstruction(java.lang.String target, java.lang.String data) throws org.xml.sax.SAXExceptionReceive a processing instruction. Currently, we are just printing a debug message that we received a PI.- Specified by:
processingInstructionin interfaceorg.xml.sax.ContentHandler- Overrides:
processingInstructionin classorg.xml.sax.helpers.DefaultHandler- Parameters:
target- the processing instruction targetdata- the processing instruction data, or null if none was supplied. The data does not include any whitespace separating it from the target.- Throws:
org.xml.sax.SAXException
-
skippedEntity
public void skippedEntity(java.lang.String name) throws org.xml.sax.SAXExceptionReceive a notification that an entity was skipped. Currently, we are just printing a debug message to this fact.- Specified by:
skippedEntityin interfaceorg.xml.sax.ContentHandler- Overrides:
skippedEntityin classorg.xml.sax.helpers.DefaultHandler- Parameters:
name- The name of the skipped entity. If it is a parameter entity, the name will begin with '%', and if it is the external DTD subset, it will be the string "[dtd]".- Throws:
org.xml.sax.SAXException
-
log
private void log(java.lang.String subject, java.lang.String name, java.lang.String value)Small helper method to bundle repetitive parameters in a template for reporting progress.- Parameters:
subject- is the name of the XML element that is being scrutinized.name- is then name of the element we are working with.value- is the attribute value.
-
complain
private void complain(java.lang.String subject, java.lang.String name, java.lang.String value)Small helper method to bundle repetitive complaints in a template for reporting progress.- Parameters:
subject- is the name of the XML element that is being scrutinized.name- is then name of the element we are working with.value- is the attribute value.
-
parseDate
private java.util.Date parseDate(java.lang.String date) throws java.text.ParseExceptionSmall helper to parse the different date varieties and deal with Java obnoxeity.- Parameters:
date- is an ISO 8601 timestamp- Returns:
- a date field
- Throws:
java.text.ParseException- thrown if the date cannot be parsed
-
setupJob
private void setupJob(Job job, java.util.List names, java.util.List values) throws java.lang.NumberFormatException, java.text.ParseException
Small helper method to set up the attributes for the job elements.- Parameters:
job- is the job to set up.names- is the list of attribute namesvalues- is the list of attribute values- Throws:
java.lang.NumberFormatExceptionjava.text.ParseException
-
createObject
protected Invocation createObject(Invocation parent, java.lang.String e, java.util.List names, java.util.List values) throws java.lang.IllegalArgumentException
This method determines the actively parsed element, creates the Java object that corresponds to the element, and sets the member variables with the values of the attributes of the element.- Parameters:
parent- is the parent elemente- is the name of the elementnames- is a list of attribute names, as strings.values- is a list of attribute values, to match the key list.- Returns:
- A new VDL Java object, which may only be partly constructed.
- Throws:
java.lang.IllegalArgumentException- if the element name is too short.
-
setElementRelation
protected boolean setElementRelation(char initial, Invocation parent, Invocation child)This method sets the relations between the currently finished XML element and its containing element in terms of Java objects. Usually it involves adding the object to the parent's child object list.- Parameters:
initial- is the first charactor of the parent element nameparent- is a reference to the parent's Java objectchild- 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.
-
-