ptolemy.plot.plotml
Class PlotBoxMLParser

java.lang.Object
  |
  +--com.microstar.xml.HandlerBase
        |
        +--ptolemy.plot.plotml.PlotBoxMLParser
Direct Known Subclasses:
PlotMLParser

public class PlotBoxMLParser
extends HandlerBase

This class constructs a plot from specifications in PlotML (Plot Markup Language), which is an XML language. This class supports only the subset that applies to the PlotBox base class. It ignores all other elements in the DTD. The class contains an instance of the Microstar Ælfred XML parser and implements callback methods to interpret the parsed XML. The way to use this class is to construct it with a reference to a PlotBox object and then call its parse() method.

Version:
$Id: PlotBoxMLParser.java,v 1.9 1999/08/19 01:48:45 cxh Exp $
Author:
Edward A. Lee

Field Summary
protected  java.util.Hashtable _attributes
          Attributes associated with an entity.
protected  java.lang.StringBuffer _currentCharData
          The current character data for the current element.
protected  XmlParser _parser
          The parser.
protected  PlotBox _plot
          The plot object to which to apply commands.
 
Constructor Summary
protected PlotBoxMLParser()
          Protected constructor allows derived classes to set _plot differently.
  PlotBoxMLParser(PlotBox plot)
          Construct an parser to parse commands for the specified plot object.
 
Method Summary
protected  void _checkForNull(java.lang.Object object, java.lang.String message)
          If the argument is null, throw an exception with the given message.
protected  java.lang.String _currentExternalEntity()
          Get the the URI for the current external entity.
 void attribute(java.lang.String name, java.lang.String value, boolean specified)
          Handle an attribute assignment that is part of an XML element.
 void charData(char[] chars, int offset, int length)
          Handle character data.
 void endDocument()
          End the document.
 void endElement(java.lang.String elementName)
          End an element.
 void error(java.lang.String message, java.lang.String sysid, int line, int column)
          Indicate a fatal XML parsing error.
 void parse(java.net.URL base, java.io.InputStream input)
          Parse the given stream as a PlotML file.
 java.lang.Object resolveEntity(java.lang.String publicID, java.lang.String systemID)
          Resolve an external entity.
 void startDocument()
          Start a document.
 void startElement(java.lang.String elementName)
          Start an element.
 void startExternalEntity(java.lang.String systemId)
          Handle the start of an external entity.
 
Methods inherited from class com.microstar.xml.HandlerBase
doctypeDecl, endExternalEntity, ignorableWhitespace, processingInstruction
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_attributes

protected java.util.Hashtable _attributes
Attributes associated with an entity.

_currentCharData

protected java.lang.StringBuffer _currentCharData
The current character data for the current element.

_parser

protected XmlParser _parser
The parser.

_plot

protected PlotBox _plot
The plot object to which to apply commands.
Constructor Detail

PlotBoxMLParser

public PlotBoxMLParser(PlotBox plot)
Construct an parser to parse commands for the specified plot object.
Parameters:
plot - The plot object to which to apply the commands.

PlotBoxMLParser

protected PlotBoxMLParser()
Protected constructor allows derived classes to set _plot differently.
Method Detail

attribute

public void attribute(java.lang.String name,
                      java.lang.String value,
                      boolean specified)
               throws XmlException
Handle an attribute assignment that is part of an XML element. This method is called prior to the corresponding startElement() call, so it simply accumulates attributes in a hashtable for use by startElement().
Overrides:
attribute in class HandlerBase
Parameters:
name - The name of the attribute.
value - The value of the attribute, or null if the attribute is #IMPLIED and not specified.
specified - True if the value is specified, false if the value comes from the default value in the DTD rather than from the XML file.
Throws:
XmlException - If the name or value is null.

charData

public void charData(char[] chars,
                     int offset,
                     int length)
Handle character data. In this implementation, the character data is accumulated in a buffer until the end element. Ælfred will call this method once for each chunk of character data found in the contents of elements. Note that the parser may break up a long sequence of characters into smaller chunks and call this method once for each chunk.
Overrides:
charData in class HandlerBase
Parameters:
chars - The character data.
offset - The starting position in the array.
length - The number of characters available.

endDocument

public void endDocument()
                 throws java.lang.Exception
End the document. In this implementation, do nothing. Ælfred will call this method once, when it has finished parsing the XML document. It is guaranteed that this will be the last method called.
Overrides:
endDocument in class HandlerBase
Tags copied from class: HandlerBase
Throws:
java.lang.Exception - Derived methods may throw exceptions.
See Also:
XmlHandler.endDocument()

endElement

public void endElement(java.lang.String elementName)
                throws java.lang.Exception
End an element. For most elements this method calls the appropriate PlotBox method. Ælfred will call this method at the end of each element (including EMPTY elements).
Overrides:
endElement in class HandlerBase
Parameters:
elementName - The element type name.

error

public void error(java.lang.String message,
                  java.lang.String sysid,
                  int line,
                  int column)
           throws XmlException
Indicate a fatal XML parsing error. Ælfred will call this method whenever it encounters a serious error. This method simply throws an XmlException.
Overrides:
error in class HandlerBase
Parameters:
message - The error message.
systemId - The URI of the tntity that caused the error.
line - The approximate line number of the error.
column - The approximate column number of the error.
Throws:
XmlException - If called.

parse

public void parse(java.net.URL base,
                  java.io.InputStream input)
           throws java.lang.Exception
Parse the given stream as a PlotML file. For example, an applet might use this method as follows:
     PlotBoxMLParser parser = new PlotBoxMLParser();
     URL docBase = getDocumentBase();
     URL xmlFile = new URL(docBase, modelURL);
     parser.parse(xmlFile.openStream());
  
A variety of exceptions might be thrown if the parsed data does not represent a valid PlotML file.
Parameters:
input - The stream from which to read XML.
Throws:
java.lang.Exception - If the parser fails.

resolveEntity

public java.lang.Object resolveEntity(java.lang.String publicID,
                                      java.lang.String systemID)
Resolve an external entity. This method returns null, which has the effect of deferring to Ælfred for resolution of the URI. Derived classes may return a a modified URI (a string), an InputStream, or a Reader. In the latter two cases, the input character stream is provided.
Overrides:
resolveEntity in class HandlerBase
Parameters:
publicId - The public identifier, or null if none was supplied.
systemId - The system identifier.
Returns:
Null, indicating to use the default system identifier.

startDocument

public void startDocument()
Start a document. This method is called just before the parser attempts to read the first entity (the root of the document). It is guaranteed that this will be the first method called.
Overrides:
startDocument in class HandlerBase
Tags copied from class: HandlerBase
Throws:
java.lang.Exception - Derived methods may throw exceptions.
See Also:
XmlHandler.startDocument()

startElement

public void startElement(java.lang.String elementName)
                  throws XmlException
Start an element. This is called at the beginning of each XML element. By the time it is called, all of the attributes for the element will already have been reported using the attribute() method. Unrecognized elements are ignored.
Overrides:
startElement in class HandlerBase
Parameters:
elementName - The element type name.
Throws:
XmlException - If the element produces an error in constructing the model.

startExternalEntity

public void startExternalEntity(java.lang.String systemId)
Handle the start of an external entity. This pushes the stack so that error reporting correctly reports the external entity that causes the error.
Overrides:
startExternalEntity in class HandlerBase
Parameters:
systemId - The URI for the external entity.

_checkForNull

protected void _checkForNull(java.lang.Object object,
                             java.lang.String message)
                      throws XmlException
If the argument is null, throw an exception with the given message.
Parameters:
object - The reference to check for null.
message - The message to issue if the reference is null.

_currentExternalEntity

protected java.lang.String _currentExternalEntity()
Get the the URI for the current external entity.
Returns:
A string giving the URI of the external entity being read, or null if none.