ptolemy.backtrack.xmlparser
Class XmlHandler

java.lang.Object
  extended by ptolemy.backtrack.xmlparser.XmlHandler
All Implemented Interfaces:
XmlHandler
Direct Known Subclasses:
ConfigXmlHandler

public class XmlHandler
extends java.lang.Object
implements XmlHandler

The XML element handler that builds the XML tree.

Since:
Ptolemy II 5.1
Version:
$Id: XmlHandler.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Thomas Feng
Accepted Rating:
Red (tfeng)
Proposed Rating:
Red (tfeng)

Field Summary
private  java.util.Hashtable<java.lang.String,java.lang.String> _currentAttributes
          The attributes of the current XML node.
private  ConfigXmlTree _currentTree
          XML tree starting from the current node.
private  java.lang.String _systemId
          The system ID of the XML document.
static java.lang.String MoML_DTD_1
          The standard MoML DTD, represented as a string.
static java.lang.String MoML_PUBLIC_ID_1
          The public ID for version 1 MoML.
 
Constructor Summary
XmlHandler(ConfigXmlTree tree, java.lang.String systemId)
          Construct an XML handler with the given XML tree as the current tree.
 
Method Summary
 void attribute(java.lang.String name, java.lang.String value, boolean isSpecified)
          Handle an attribute.
 void charData(char[] ch, int start, int length)
          Handle a chunk of char data.
 void doctypeDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
          Handle a document type declaration.
 void endDocument()
          Handle the end of the XML document.
 void endElement(java.lang.String elementName)
          Handle the end of an XML element.
 void endExternalEntity(java.lang.String systemId)
          Handle the end of an external entity.
 void error(java.lang.String message, java.lang.String systemId, int line, int column)
          Signal an error message.
 ConfigXmlTree getCurrentTree()
          Return the current XML tree.
 java.lang.String getSystemId()
          Return the system ID of the XML document.
 void ignorableWhitespace(char[] ch, int start, int length)
          Handle consecutive ignorable white spaces.
 void processingInstruction(java.lang.String target, java.lang.String data)
          Handle a processing instruction.
 java.lang.Object resolveEntity(java.lang.String publicId, java.lang.String systemId)
          Resolve an external entity.
 void startDocument()
          Handle the start of the XML document.
 void startElement(java.lang.String elementName)
          Handle the start of an XML element.
 void startExternalEntity(java.lang.String systemId)
          Handle the start of an external entity.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MoML_DTD_1

public static final java.lang.String MoML_DTD_1
The standard MoML DTD, represented as a string. This is used to parse MoML data when a compatible PUBLIC DTD is specified. NOTE: This DTD includes a number of elements that are deprecated. They are included here for backward compatibility. See the MoML chapter of the Ptolemy II design document for a view of the current (nondeprecated) DTD.


MoML_PUBLIC_ID_1

public static final java.lang.String MoML_PUBLIC_ID_1
The public ID for version 1 MoML.


_currentAttributes

private java.util.Hashtable<java.lang.String,java.lang.String> _currentAttributes
The attributes of the current XML node.


_currentTree

private ConfigXmlTree _currentTree
XML tree starting from the current node.


_systemId

private java.lang.String _systemId
The system ID of the XML document.

Constructor Detail

XmlHandler

XmlHandler(ConfigXmlTree tree,
           java.lang.String systemId)
Construct an XML handler with the given XML tree as the current tree.

Parameters:
tree - The initial XML tree.
systemId - The system ID of the document type.
Method Detail

attribute

public void attribute(java.lang.String name,
                      java.lang.String value,
                      boolean isSpecified)
               throws java.lang.Exception
Handle an attribute. Its name and value will be recorded in the hash table of attributes.

Specified by:
attribute in interface XmlHandler
Parameters:
name - The name of the attribute.
value - The value of the attribute.
isSpecified - true if the value was specified, false if it was defaulted from the DTD.
Throws:
java.lang.Exception - Not thrown in this base class.
See Also:
XmlHandler.startElement(java.lang.String), XmlParser.declaredAttributes(java.lang.String), XmlParser.getAttributeType(java.lang.String, java.lang.String), XmlParser.getAttributeDefaultValue(java.lang.String, java.lang.String)

charData

public void charData(char[] ch,
                     int start,
                     int length)
              throws java.lang.Exception
Handle a chunk of char data.

Specified by:
charData in interface XmlHandler
Parameters:
ch - The character data.
start - The starting position in the array.
length - The number of characters available.
Throws:
java.lang.Exception - Not thrown in this base class.

doctypeDecl

public void doctypeDecl(java.lang.String name,
                        java.lang.String publicId,
                        java.lang.String systemId)
                 throws java.lang.Exception
Handle a document type declaration.

Specified by:
doctypeDecl in interface XmlHandler
Parameters:
name - The document type name.
publicId - The public identifier, or null if unspecified.
systemId - The system identifier, or null if unspecified.
Throws:
java.lang.Exception - Not thrown in this base class.

endDocument

public void endDocument()
                 throws java.lang.Exception
Handle the end of the XML document.

Specified by:
endDocument in interface XmlHandler
Throws:
java.lang.Exception - The handler may throw any exception.
See Also:
XmlHandler.startDocument()

endElement

public void endElement(java.lang.String elementName)
                throws java.lang.Exception
Handle the end of an XML element.

Specified by:
endElement in interface XmlHandler
Parameters:
elementName - The name of the element.
Throws:
java.lang.Exception - Not thrown in this base class.
See Also:
XmlHandler.startElement(java.lang.String), XmlParser.declaredElements(), XmlParser.getElementContentType(java.lang.String)

endExternalEntity

public void endExternalEntity(java.lang.String systemId)
                       throws java.lang.Exception
Handle the end of an external entity.

Specified by:
endExternalEntity in interface XmlHandler
Parameters:
systemId - The system ID of the external entity.
Throws:
java.lang.Exception - Not thrown in this base class.
See Also:
XmlHandler.startExternalEntity(java.lang.String), XmlHandler.resolveEntity(java.lang.String, java.lang.String)

error

public void error(java.lang.String message,
                  java.lang.String systemId,
                  int line,
                  int column)
           throws java.lang.Exception
Signal an error message.

Specified by:
error in interface XmlHandler
Parameters:
message - The error message.
systemId - The system ID of the XML document that contains the error.
line - The line number of the error.
column - The column number of the error.
Throws:
java.lang.Exception - Not thrown in this base class.
See Also:
XmlException

getCurrentTree

public ConfigXmlTree getCurrentTree()
Return the current XML tree.

Returns:
The current XML tree.

getSystemId

public java.lang.String getSystemId()
Return the system ID of the XML document.

Returns:
The system ID.

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
                         throws java.lang.Exception
Handle consecutive ignorable white spaces.

Specified by:
ignorableWhitespace in interface XmlHandler
Parameters:
ch - The literal whitespace characters.
start - The starting position in the array.
length - The number of whitespace characters available.
Throws:
java.lang.Exception - Not thrown in this base class.

processingInstruction

public void processingInstruction(java.lang.String target,
                                  java.lang.String data)
                           throws java.lang.Exception
Handle a processing instruction.

Specified by:
processingInstruction in interface XmlHandler
Parameters:
target - The target (the name at the start of the processing instruction).
data - The data, if any (the rest of the processing instruction).
Throws:
java.lang.Exception - Not thrown in this base class.

resolveEntity

public java.lang.Object resolveEntity(java.lang.String publicId,
                                      java.lang.String systemId)
                               throws java.lang.Exception
Resolve an external entity.

Specified by:
resolveEntity in interface XmlHandler
Parameters:
publicId - The public ID, or null if none was supplied.
systemId - The system ID.
Returns:
The replacement system identifier, or null to use the default.
Throws:
java.lang.Exception - Not thrown in this base class.
See Also:
XmlHandler.startExternalEntity(java.lang.String), XmlHandler.endExternalEntity(java.lang.String)

startDocument

public void startDocument()
                   throws java.lang.Exception
Handle the start of the XML document.

Specified by:
startDocument in interface XmlHandler
Throws:
java.lang.Exception - Not thrown in this base class.
See Also:
XmlHandler.endDocument()

startElement

public void startElement(java.lang.String elementName)
                  throws java.lang.Exception
Handle the start of an XML element.

Specified by:
startElement in interface XmlHandler
Parameters:
elementName - The name of the XML element.
Throws:
java.lang.Exception - Not thrown in this base class.
See Also:
XmlHandler.attribute(java.lang.String, java.lang.String, boolean), XmlHandler.endElement(java.lang.String), XmlParser.declaredElements(), XmlParser.getElementContentType(java.lang.String)

startExternalEntity

public void startExternalEntity(java.lang.String systemId)
                         throws java.lang.Exception
Handle the start of an external entity.

Specified by:
startExternalEntity in interface XmlHandler
Parameters:
systemId - The system ID of the external entity.
Throws:
java.lang.Exception - Not thrown in this base class.
See Also:
XmlHandler.endExternalEntity(java.lang.String), XmlHandler.resolveEntity(java.lang.String, java.lang.String)