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

java.lang.Object
  extended by cox.jmatt.java.MathTools.graphing.xml.RenderableXML
All Implemented Interfaces:
Renderable
Direct Known Subclasses:
AxisXML, GraphableXML, GraphPaperXML, PolygonXML

public class RenderableXML
extends java.lang.Object
implements Renderable

This is the base class for all XML graphing components. It provides basic parameter-handling machinery along with the foundation required for its subclasses. All XML tags should have an ID. While this class does not ID-tag its parameters, it does provide machinery for the other classes to contain their IDs. It also maintains a 'name' and a 'type' field. The name field is set through the one-argument constructor and the type via the setType() method.

Although this class maintains the parameter table, it is available to subclasses as a protected ArrayList. Likewise the 'myName,' 'myType,' and 'myID' fields. Since these fields are very important to subclasses, their existence can be checked with the testCondition() method. The GraphKeysXML class contains constant condition Objects for verifying that these fields are not null.


Field Summary
protected  java.lang.String myID
          All XML tags should have an 'id=' attribute.
protected  java.lang.String myName
          This String is used to hold the name of the object being manipulated.
protected  java.util.Hashtable<java.lang.String,java.lang.String> myParams
          The parameter table is automatically maintained and handled via the render() method.
protected  java.lang.String myType
          This field holds the String-ed value of the setType() method.
 
Constructor Summary
RenderableXML()
          This constructor provides a simple, blank instance.
RenderableXML(java.lang.String pName)
          This constructor is provided to set the 'myName' field upon creation.
 
Method Summary
 java.lang.Object render(java.lang.Object pContext)
          The base render() method simply produces <Param> tags.
 void setID(java.lang.String pID)
          This is not a mandated Renderable method.
 boolean setParameter(java.lang.String pKey, java.lang.Object pValue)
          Set or clear a parameter.
 boolean setType(java.lang.Object pType)
          Use this method to set or clear the 'myType' field.
 boolean testCondition(java.lang.Object pCondition, java.lang.Object pValue)
          Three conditions can be checked: name, type, and ID.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

myName

protected java.lang.String myName
This String is used to hold the name of the object being manipulated. It is set via the one-argument constructor.


myID

protected java.lang.String myID
All XML tags should have an 'id=' attribute. This is the field set by the setID() method. It is protected to allow subclass access.


myType

protected java.lang.String myType
This field holds the String-ed value of the setType() method. Its default value is null.


myParams

protected java.util.Hashtable<java.lang.String,java.lang.String> myParams
The parameter table is automatically maintained and handled via the render() method. It is protected to allow subclasses access should they need it.

Constructor Detail

RenderableXML

public RenderableXML()
This constructor provides a simple, blank instance. No values are initialized.


RenderableXML

public RenderableXML(java.lang.String pName)
This constructor is provided to set the 'myName' field upon creation. That is all it does.

Method Detail

setID

public void setID(java.lang.String pID)
This is not a mandated Renderable method. It is provided to allow the inclusion of an 'id=' attribute on any generated tag.


setType

public boolean setType(java.lang.Object pType)
Use this method to set or clear the 'myType' field. Setting it to null clears it and setting it to a non-null Object stores its toString(). The return value is always true.

Specified by:
setType in interface Renderable
Parameters:
pType - The 'type' of Renderable being used.
Returns:
true if setting this renderable to pType makes sense, false otherwise.

testCondition

public boolean testCondition(java.lang.Object pCondition,
                             java.lang.Object pValue)
Three conditions can be checked: name, type, and ID. Use the GraphKeysXML constants to check whether or not the specified value is non-null. The value argument is not used. The return value is true if the value is set, false if it is null or blank.

Specified by:
testCondition in interface Renderable
Parameters:
pCondition - The condition to test against the value.
pValue - The value against which the condition is to be checked.
Returns:
true if the test succeeds, false otherwise.

setParameter

public boolean setParameter(java.lang.String pKey,
                            java.lang.Object pValue)

Set or clear a parameter. If the key is null or blank it is ignored and false is returned. If the key is valid and the value is not null, it is added to the parameter table and the return value is true. If the key is valid and the value is null, the value stored under that key is removed from the table. If the Object was successfully removed, the return is true. If the table held no mapping, the return is false.

NOTE: The value Object is converted to String before it is added! Use with care.

Specified by:
setParameter in interface Renderable
Parameters:
pKey - The name of the parameter being set. Must not be null or empty.
pValue - The value of the parameter to set.
Returns:
true if the parameter is set properly, false if it did not make sense or could not be set.

render

public java.lang.Object render(java.lang.Object pContext)
The base render() method simply produces <Param> tags. No individual ID is set. The key value for each parameter appears in a 'key=' attribute and the tag contains the XML-escaped value. No rendering context is required or used.

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