org.griphyn.vdl.euryale
Class DAXParser

java.lang.Object
  extended byorg.xml.sax.helpers.DefaultHandler
      extended byorg.griphyn.vdl.euryale.DAXParser
All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler

public class DAXParser
extends DefaultHandler

This class uses the xerces SAX2 parser to validate and parse an DAX document. This class extends the xerces DefaultHandler so that we only need to override callbacks of interest.

Version:
$Revision: 1.5 $
Author:
Kavitha Ranganathan, Jens-S. V�ckler, Yong Zhao

Field Summary
private  Callback m_callback
          Maintains the callback class to provide the information to.
private  String m_child
          maintains the currently viewed section 3 child element.
private  int m_depth
          maintain the hierarchy for some debug printing
private  Map m_forward
          A Hashmap to forward resolve namespaces that were encountered during parsing.
private  Job m_job
          collects the information for a section 2 job element.
private  Locator m_location
          Keep the location within the document
private  Logging m_log
          Obtain our logger once for multiple uses.
private  List m_parent
          collects the parents associated with a particular child.
private  XMLReader m_parser
          our own instance of the SAX parser.
private  Profile m_profile
          collects the leaves for a profile that is part of a job.
private  Map m_reverse
          A Hashmap to reverse resolve namespaces that were encountered during parsing.
private  int m_tag
          maintains the indications which parent element to be used whenever a filename tag is being encountered.
(package private) static int TAG_ADAG
           
(package private) static int TAG_ARGUMENT
           
(package private) static int TAG_OTHER
           
(package private) static int TAG_PROFILE
           
private static String vendorParserClass
          class name of the SAX parser.
 
Constructor Summary
DAXParser(String schemaLocation)
          The class constructor initializes the Xerces parser, sets the classes that hold the callback functions, and the features that enable schema validation.
 
Method Summary
 void characters(char[] ch, int start, int length)
          This method is the callback function for characters in an element.
private  void complain(String subject, String name, String value)
          Small helper method to bundle repetitive complaints in a template for reporting progress.
 void createElementObject(String e, List names, List values)
          This method finds out what is the current element, creates the java object that corresponds to the element, and sets the member variables with the values of the attributes of the element.
 void elementCharacters(String elementChars)
          This method sets the content of the java object corresponding to the element "text", which has mixed content.
 void endDocument()
          The parser comes to the end of the document.
 void endElement(String namespaceURI, String localName, String qName)
          The parser is at the end of an element.
 void endPrefixMapping(String prefix)
          Out of the reach of the prefix, remove it from the HashMap.
 Callback getCallback()
          Obtains the current instance to be used for callbacks.
 void ignorableWhitespace(char[] ch, int start, int length)
          Currently, ignorable whitespace will be ignored.
private  void log(String subject, String name, String value)
          Small helper method to bundle repetitive parameters in a template for reporting progress.
private  String map(String uri)
          Helper function to map prefixes correctly onto the elements.
 boolean parse(InputStream stream)
          This function parses a DAX source (could be a document, a stream, etc.), and creates java class instances that correspond to the DAX.
 boolean parse(String daxURI)
          This function parses a DAX source (could be a document, a stream, etc.), and creates java class instances that correspond to the DAX.
 void processingInstruction(String target, String data)
          Receive a processing instruction.
private  boolean set(String uri, boolean flag)
          Sets a feature while capturing failed features right here.
 void setCallback(Callback callback)
          Sets a new callback object to use for future callbacks.
 void setDocumentLocator(Locator locator)
          Obtains the document locator from the parser.
 void setElementRelation(String elementName)
          This method sets the relations between the current java object and its parent object according to the element hierarchy.
 void setSchemaLocations(String list)
          Set the list of external real locations where the XML schema may be found.
 void skippedEntity(String name)
          Receive a notification that an entity was skipped.
 void startDocument()
          This method specifies what to do when the parser is at the beginning of the document.
 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 startPrefixMapping(String prefix, String uri)
          There is a prefix or namespace defined, put the prefix and its URI in the HashMap.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
error, fatalError, notationDecl, resolveEntity, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

vendorParserClass

private static String vendorParserClass
class name of the SAX parser.


m_parser

private XMLReader m_parser
our own instance of the SAX parser.


m_depth

private int m_depth
maintain the hierarchy for some debug printing


m_job

private Job m_job
collects the information for a section 2 job element.


m_profile

private Profile m_profile
collects the leaves for a profile that is part of a job.


m_child

private String m_child
maintains the currently viewed section 3 child element.


m_parent

private List m_parent
collects the parents associated with a particular child.


m_tag

private int m_tag
maintains the indications which parent element to be used whenever a filename tag is being encountered.


TAG_ADAG

static final int TAG_ADAG
See Also:
Constant Field Values

TAG_ARGUMENT

static final int TAG_ARGUMENT
See Also:
Constant Field Values

TAG_PROFILE

static final int TAG_PROFILE
See Also:
Constant Field Values

TAG_OTHER

static final int TAG_OTHER
See Also:
Constant Field Values

m_location

private Locator m_location
Keep the location within the document


m_forward

private Map m_forward
A Hashmap to forward resolve namespaces that were encountered during parsing.


m_reverse

private Map m_reverse
A Hashmap to reverse resolve namespaces that were encountered during parsing.


m_log

private Logging m_log
Obtain our logger once for multiple uses.


m_callback

private Callback m_callback
Maintains the callback class to provide the information to.

Constructor Detail

DAXParser

public DAXParser(String schemaLocation)
The class constructor initializes the Xerces parser, sets the classes that hold the callback functions, and the features that enable schema validation.

Parameters:
schemaLocation - is any URI pointing to the XML schema definition.
Method Detail

set

private boolean set(String uri,
                    boolean flag)
Sets a feature while capturing failed features right here.

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

getCallback

public Callback getCallback()
Obtains the current instance to be used for callbacks.

Returns:
the current callback instance object, or null.
See Also:
setCallback( Callback )

setCallback

public void setCallback(Callback callback)
Sets a new callback object to use for future callbacks.

Parameters:
callback - is the new callback object.
See Also:
getCallback()

setSchemaLocations

public void setSchemaLocations(String list)
Set 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 boolean parse(String daxURI)
This function parses a DAX source (could be a document, a stream, etc.), and creates java class instances that correspond to the DAX. These will provided to the callback functions instead of being collected here in memory.

Parameters:
daxURI - is the URI for the DAX source.
Returns:
true for valid parsing, false if an error occurred.

parse

public boolean parse(InputStream stream)
This function parses a DAX source (could be a document, a stream, etc.), and creates java class instances that correspond to the DAX. These will provided to the callback functions instead of being collected here in memory.

Parameters:
stream - is an input stream for the DAX source.
Returns:
true for valid parsing, false if an error occurred.

setDocumentLocator

public void setDocumentLocator(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.

Parameters:
locator - is the externally set current position

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.


endDocument

public void endDocument()
The parser comes to the end of the document.


startPrefixMapping

public void startPrefixMapping(String prefix,
                               String uri)
                        throws SAXException
There 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.

Parameters:
prefix - the Namespace prefix being declared.
uri - the Namespace URI the prefix is mapped to.
Throws:
SAXException

endPrefixMapping

public void endPrefixMapping(String prefix)
                      throws SAXException
Out of the reach of the prefix, remove it from the HashMap.

Parameters:
prefix - is the prefix that was being mapped previously.
Throws:
SAXException

map

private String map(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(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.

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. Each successfully and completely parsed Definition will trigger a callback to the registered DefinitionHandler.

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

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws SAXException
This method is the callback function for characters in an element. The element should be mixed-content.

Parameters:
ch - are the characters from the XML document
start - is the start position into the array
length - is the amount of valid data in the array
Throws:
SAXException

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
                         throws SAXException
Currently, ignorable whitespace will be ignored.

Parameters:
ch - are the characters from the XML document
start - is the start position into the array
length - is the amount of valid data in the array
Throws:
SAXException

processingInstruction

public void processingInstruction(String target,
                                  String data)
                           throws SAXException
Receive a processing instruction. Currently, we are just printing a debug message that we received a PI.

Parameters:
target - the processing instruction target
data - the processing instruction data, or null if none was supplied. The data does not include any whitespace separating it from the target.
Throws:
SAXException

skippedEntity

public void skippedEntity(String name)
                   throws SAXException
Receive a notification that an entity was skipped. Currently, we are just printing a debug message to this fact.

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:
SAXException

log

private void log(String subject,
                 String name,
                 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(String subject,
                      String name,
                      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.

createElementObject

public void createElementObject(String e,
                                List names,
                                List values)
                         throws IllegalArgumentException
This method finds out what is the current 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:
e - is the name of the element
names - is a list of attribute names, as strings.
values - is a list of attribute values, to match the key list.
Throws:
IllegalArgumentException

setElementRelation

public void setElementRelation(String elementName)
This method sets the relations between the current java object and its parent object according to the element hierarchy. Usually it involves adding the object to the parent's child object list.


elementCharacters

public void elementCharacters(String elementChars)
This method sets the content of the java object corresponding to the element "text", which has mixed content.

See Also:
Text


Copyright © 2003 The University of Chicago and The University of Southern California. All Rights Reserved.