|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.xml.sax.helpers.DefaultHandler
cox.jmatt.java.MathTools.util.MTXErrorHandler
cox.jmatt.java.MathTools.graphing.GraphHandler
public class GraphHandler
This class is designed specifically to parse graphing.xml.*
package markup and convert it into a GraphPaper
instance containing
the components described in the XML data. It should not be used for any other purpose otherwise the universe will shatter.
GraphHandler
extends MTXErrorHandler
and is used as such. The only methods defined are several from the
org.xml.sax.ContentHandler
and ErrorHandler
interfaces. The latter simply reports parser warns and errors to
CapCom.debug()
and fatals to CapCom.error()
If desired, an alternate ErrorHandler
can be set without affecting
the main operations of this class.
The ContentHandler
methods defined are the fewest necessary to accomplish GraphHandler
's task: converting graphing package XML
into graphing components. MTXProcessor
uses this class in its parseGraph()
method. It simply substitutes an instance of this class
for its handler when parsing the XML markup.
GraphHandler
To use this class from an external application, first create an instance. Next set a GraphEngine
of the desired output type using the
setGraphEngine()
method. Obtain a SAXParser
instance, set GraphHandler
as its ContentHandler (at LEAST), and parse the
XML content. If no external ErrorHandler is necessary, set this class as that and use MathTools' logging tools! When the document finishes, the graph will be
ready. Call getResult()
to retrieve a complete GraphPaper
instance from the GraphEngine sent it. This is exactly what
MTXProcessor
does when it parses a graph!
As with the graphing.xml.*
implementation, all Object data must be String. If not, the GraphPaper
must know how to
convert the Strings returned by the XML parse into whatever Objects it needs. Also, be very, VERY careful if editing the graphing XML or generating it from
an external source. GraphHandler
is NOT TOLERANT of bad XML markup! A complete, albeit short, example of GraphingXML is the file XMLGraph.xml
in the docs/SampleScripts/ folder. This shows the root, Renderable
tags, and content tags exactly as they should be!
When the document is parsed, the three general attributes are set as follows:
GraphPaperInstance.addAxis(id, AxisInstanceFromTag)
RenderableInstance.setType(type)
as soon as the instance is created.GraphableInstance = GraphEngineInstance.getGraph(name)
graphing.xml.*
package DOES assign a simple ID attribute to them. When parsed, this is ignored.
USE CAUTION when parsing XML not generated by the graphing.xml.*
implementation! Some Exceptions are caught and handled gracefully while others
are handled less so. MTXProcessor.parseGraph()
defines an all-encompassing try/catch
block and several methods in this class will
handle some errors, but it is a BAD IDEA to count on that behavior! It is a much better idea to make sure the XML is good before it is parsed!
Constructor Summary | |
---|---|
GraphHandler()
This constructor builds a standard GraphHandler. |
Method Summary | |
---|---|
void |
characters(char[] pChars,
int pStart,
int pLen)
This method is used to accumulate data for tags that have character content: <Expression> <Limit> <Vertices> and <Param>. |
void |
endDocument()
Clean up any mess left behind by the parsing process. |
void |
endElement(java.lang.String uri,
java.lang.String localName,
java.lang.String qName)
If the element is Renderable, add it to the GraphPaper. |
GraphPaper |
getResult()
Return the GraphPaper instance parsed. |
void |
setGraphEngine(GraphEngine pEngine)
This method sets the GraphEngine used to build the graph described in the XML document. |
void |
startDocument()
Prints a debug message. |
void |
startElement(java.lang.String uri,
java.lang.String localName,
java.lang.String qName,
org.xml.sax.Attributes attrs)
Start an element. |
Methods inherited from class cox.jmatt.java.MathTools.util.MTXErrorHandler |
---|
error, error, fatalError, fatalError, warning, warning |
Methods inherited from class org.xml.sax.helpers.DefaultHandler |
---|
endPrefixMapping, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startPrefixMapping, unparsedEntityDecl |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public GraphHandler()
Method Detail |
---|
public void setGraphEngine(GraphEngine pEngine)
GraphEngine
used to build the graph described in the XML document. If set to (or left as) null, the default engine used
is GraphEngineXML
. This GraphEngine must be able to make sense of Strings in Object parameter spots as that is how they are set.
pEngine
- The GraphEngine
to use in constructing the graph.public void startDocument()
GraphEngine
has been set, install a default (XML) one.
startDocument
in interface org.xml.sax.ContentHandler
startDocument
in class MTXErrorHandler
public void startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes attrs)
startElement
in interface org.xml.sax.ContentHandler
startElement
in class org.xml.sax.helpers.DefaultHandler
public void endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName)
endElement
in interface org.xml.sax.ContentHandler
endElement
in class org.xml.sax.helpers.DefaultHandler
public void characters(char[] pChars, int pStart, int pLen)
characters
in interface org.xml.sax.ContentHandler
characters
in class org.xml.sax.helpers.DefaultHandler
public void endDocument()
endDocument
in interface org.xml.sax.ContentHandler
endDocument
in class MTXErrorHandler
public GraphPaper getResult()
GraphPaper
instance parsed. This method is only valid AFTER the parsing process! Beforehand the return value is indeterminate. All
specified components will have been added per their specifications in the XML document. The GraphPaper instance will, of course, belong to the GraphEngine
set before parsing started.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |