cox.jmatt.java.MathTools.graphing.xml
Class GraphableXML

java.lang.Object
  extended by cox.jmatt.java.MathTools.graphing.xml.RenderableXML
      extended by cox.jmatt.java.MathTools.graphing.xml.GraphableXML
All Implemented Interfaces:
Graphable, Renderable

public class GraphableXML
extends RenderableXML
implements Graphable

This class generates very simple XML markup. The <Graphable> tag contains the necessary 'id=' attribute along with 'name=' and 'type=' attributes, if they are defined. Its children are <Expression> and <Limit> tags whose 'key=' attribute is the key value used to add them to the Graphable and whose content is the XML-escaped String value of the Object added.


Field Summary
 
Fields inherited from class cox.jmatt.java.MathTools.graphing.xml.RenderableXML
myID, myName, myParams, myType
 
Fields inherited from interface cox.jmatt.java.MathTools.graphing.Graphable
PARAMETRIC_GRAPH, PARAMETRIC_X, PARAMETRIC_Y, POLAR_GRAPH, STANDARD_GRAPH
 
Constructor Summary
GraphableXML()
          Standard constructor for an unnamed Graphable.
GraphableXML(java.lang.String pName)
          Constructor for a named Graphable.
 
Method Summary
 boolean addExpression(java.lang.String pKey, java.lang.Object pValue)
          Add an expression to this Graphable.
 boolean addLimit(java.lang.String pKey, java.lang.Object pValue)
          Add a limit to this Graphable.
 java.lang.Object render(java.lang.Object pContext)
          Rendering a GraphableXML results in a <Graphable> tag containing <Expression> and <Limit> children, followed by any parameter tags.
 boolean testCondition(java.lang.Object pCondition, java.lang.Object pValue)
          Two things can be tested in GraphableXML: whether or not a specific LIMIT or EXPRESSION has been set.
 
Methods inherited from class cox.jmatt.java.MathTools.graphing.xml.RenderableXML
setID, setParameter, setType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface cox.jmatt.java.MathTools.graphing.Renderable
setParameter, setType
 

Constructor Detail

GraphableXML

public GraphableXML()
Standard constructor for an unnamed Graphable.


GraphableXML

public GraphableXML(java.lang.String pName)
Constructor for a named Graphable.

Method Detail

addExpression

public boolean addExpression(java.lang.String pKey,
                             java.lang.Object pValue)
Add an expression to this Graphable. If the key is null or empty the method returns false. If the value is null, it is removed; the return is true if a mapping existed and false if not. If the value is not null it is added and the return is true.

Specified by:
addExpression in interface Graphable
Parameters:
pKey - A String identifying the expression to be added. Usage is optional.
pValue - The Object representing the graph-generating entity.
Returns:
true if the operation succeeds, false otherwise.

addLimit

public boolean addLimit(java.lang.String pKey,
                        java.lang.Object pValue)
Add a limit to this Graphable. If the key is null or empty the method returns false. If the value is null, it is removed; the return is true if a mapping existed and false if not. If the value is not null it is added and the return is true.

Specified by:
addLimit in interface Graphable
Parameters:
pKey - A String used to identify the limit being added. Not required.
pValue - An Object representing the limit to be enforced.
Returns:
true if the limit makes sense and is added successfully, false otherwise.

testCondition

public boolean testCondition(java.lang.Object pCondition,
                             java.lang.Object pValue)
Two things can be tested in GraphableXML: whether or not a specific LIMIT or EXPRESSION has been set. The condition must be either GraphKeysXML.HAS_LIMIT or GraphKeysXML.HAS_EXPRESSION. The value must be the String key used for setting or clearing. If either argument is null the method returns false. If the condition is NOT one of the ones specified, the return value is false.

Specified by:
testCondition in interface Renderable
Overrides:
testCondition in class RenderableXML
Parameters:
pCondition - One of the GraphKeysXML constants listed above.
pValue - The String used to add or clear the expression or limit.
Returns:
true if the value is present, false if not.

render

public java.lang.Object render(java.lang.Object pContext)
Rendering a GraphableXML results in a <Graphable> tag containing <Expression> and <Limit> children, followed by any parameter tags. The Graphable tag contains an 'id=' attribute along with 'name=' and 'type=' attributes if they are defined. Each child tag contains a 'key=' attribute and its content is the expression or limit. No rendering context is required. If any parameters are set they follow the last Limit tag.

Specified by:
render in interface Renderable
Overrides:
render in class RenderableXML
Parameters:
pContext - The Context Object to be used for rendering.
Returns:
The graph-ready Object, requiring no further MathTools interaction.