org.jscience.architecture.traffic.xml
Class XMLArray

java.lang.Object
  extended by org.jscience.architecture.traffic.xml.XMLArray
All Implemented Interfaces:
XMLSerializable

public class XMLArray
extends java.lang.Object
implements XMLSerializable

Class to convert arrays of arbitrary dimensions from/to XML : Accepted componenttypes : - int,float,double,boolean,byte and their respective encapsulator classes, Strings and objects that accept XMLSerializable


Field Summary
protected  java.lang.String alias
          DOCUMENT ME!
protected static int BOOLEAN
          DOCUMENT ME!
protected static int BOOLEAN_CLASS
          DOCUMENT ME!
protected static int BYTE
          DOCUMENT ME!
protected static int BYTE_CLASS
          DOCUMENT ME!
protected static int CONTAINER_ARRAY
          DOCUMENT ME!
protected static int CONTAINER_LINKEDLIST
          DOCUMENT ME!
protected static int CONTAINER_VECTOR
          DOCUMENT ME!
protected  int containerType
          DOCUMENT ME!
protected  java.lang.Object data
          DOCUMENT ME!
protected  java.lang.Class dataClass
          DOCUMENT ME!
protected static int DOUBLE
          DOCUMENT ME!
protected static int DOUBLE_CLASS
          DOCUMENT ME!
protected static int FLOAT
          DOCUMENT ME!
protected static int FLOAT_CLASS
          DOCUMENT ME!
protected static int INT
          DOCUMENT ME!
protected static int INT_CLASS
          DOCUMENT ME!
protected  java.lang.String[] lookUpTable
          DOCUMENT ME!
protected static int OTHER_ARRAY
          DOCUMENT ME!
protected  java.lang.String parentName
          DOCUMENT ME!
protected static int STRING
          DOCUMENT ME!
protected  InstantiationAssistant watson
          DOCUMENT ME!
protected static int XMLSERIALIZABLE
          DOCUMENT ME!
 
Constructor Summary
XMLArray()
          Make a new XMLArray (constructor for loading)
XMLArray(java.lang.Object input, java.lang.String parentName)
          Make a new XMLArray (constructor for saving)
XMLArray(java.lang.Object input, java.lang.String parentName, java.lang.String alias)
          Make a new XMLArray (constructor for saving)
XMLArray(java.lang.String parentName)
          Empty constructor for loading
XMLArray(java.lang.String parentName, InstantiationAssistant assistant)
          Constructor for loading
 
Method Summary
protected  int getComponentType()
          This method tries to guess the component type of the data array.
 InstantiationAssistant getInstantiationAssistant()
          DOCUMENT ME!
 java.lang.Object getResult()
          Return the result array,Vector or LinkedList as an object.
 java.lang.Object getResult(java.lang.Class expectedClass)
          Return the result array,Vector or LinkedList as an object.
protected  java.util.LinkedList getResultLinkedList()
          Gets the result array in LinkedList form.
protected  java.util.Vector getResultVector()
          Gets the result array in Vector form.
 java.lang.String getXMLName()
          DOCUMENT ME!
 void load(XMLElement myElement, XMLLoader loader)
          DOCUMENT ME!
static java.lang.Object loadArray(XMLSerializable parent, XMLLoader loader)
          Load an arbitrary array.
static java.lang.Object loadArray(XMLSerializable parent, XMLLoader loader, java.lang.Class expectedClass)
          Load an arbitrary array.
static java.lang.Object loadArray(XMLSerializable parent, XMLLoader loader, InstantiationAssistant assistant)
          Load an arbitrary array.
static void saveArray(java.lang.Object array, XMLSerializable parent, XMLSaver saver)
          Save an arbitrary array/vector/LinkedList
static void saveArray(java.lang.Object array, XMLSerializable parent, XMLSaver saver, java.lang.String description)
          Save an arbitrary array/vector/LinkedList
 void saveChilds(XMLSaver saver)
          DOCUMENT ME!
 XMLElement saveSelf()
          DOCUMENT ME!
 void setInstantiationAssistant(InstantiationAssistant assistant)
          Sets the InstantiationAssistant of this XMLArray
 void setParentName(java.lang.String parentName)
          DOCUMENT ME!
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INT

protected static final int INT
DOCUMENT ME!

See Also:
Constant Field Values

DOUBLE

protected static final int DOUBLE
DOCUMENT ME!

See Also:
Constant Field Values

FLOAT

protected static final int FLOAT
DOCUMENT ME!

See Also:
Constant Field Values

BOOLEAN

protected static final int BOOLEAN
DOCUMENT ME!

See Also:
Constant Field Values

INT_CLASS

protected static final int INT_CLASS
DOCUMENT ME!

See Also:
Constant Field Values

DOUBLE_CLASS

protected static final int DOUBLE_CLASS
DOCUMENT ME!

See Also:
Constant Field Values

FLOAT_CLASS

protected static final int FLOAT_CLASS
DOCUMENT ME!

See Also:
Constant Field Values

BOOLEAN_CLASS

protected static final int BOOLEAN_CLASS
DOCUMENT ME!

See Also:
Constant Field Values

STRING

protected static final int STRING
DOCUMENT ME!

See Also:
Constant Field Values

XMLSERIALIZABLE

protected static final int XMLSERIALIZABLE
DOCUMENT ME!

See Also:
Constant Field Values

OTHER_ARRAY

protected static final int OTHER_ARRAY
DOCUMENT ME!

See Also:
Constant Field Values

BYTE

protected static final int BYTE
DOCUMENT ME!

See Also:
Constant Field Values

BYTE_CLASS

protected static final int BYTE_CLASS
DOCUMENT ME!

See Also:
Constant Field Values

CONTAINER_ARRAY

protected static final int CONTAINER_ARRAY
DOCUMENT ME!

See Also:
Constant Field Values

CONTAINER_VECTOR

protected static final int CONTAINER_VECTOR
DOCUMENT ME!

See Also:
Constant Field Values

CONTAINER_LINKEDLIST

protected static final int CONTAINER_LINKEDLIST
DOCUMENT ME!

See Also:
Constant Field Values

data

protected java.lang.Object data
DOCUMENT ME!


dataClass

protected java.lang.Class dataClass
DOCUMENT ME!


containerType

protected int containerType
DOCUMENT ME!


parentName

protected java.lang.String parentName
DOCUMENT ME!


alias

protected java.lang.String alias
DOCUMENT ME!


watson

protected InstantiationAssistant watson
DOCUMENT ME!


lookUpTable

protected java.lang.String[] lookUpTable
DOCUMENT ME!

Constructor Detail

XMLArray

public XMLArray()
Make a new XMLArray (constructor for loading)


XMLArray

public XMLArray(java.lang.String parentName)
Empty constructor for loading

Parameters:
parentName - The XML name of the object that is going to load this array.

XMLArray

public XMLArray(java.lang.String parentName,
                InstantiationAssistant assistant)
Constructor for loading

Parameters:
parentName - The XML name of the object that is going to load this array.
assistant - The IntantiationAssistant to use when creating new objects (this parameter is only meaningful for XMLArrays that directly or indirectly contain XMLSerializable objects.)

XMLArray

public XMLArray(java.lang.Object input,
                java.lang.String parentName)
         throws XMLCannotSaveException
Make a new XMLArray (constructor for saving)

Parameters:
input - The array,Vector or LinkedList to save
parentName - The XML name of the object that is going to save this array.
Throws:
XMLCannotSaveException - If there is something wrong with the input array.

XMLArray

public XMLArray(java.lang.Object input,
                java.lang.String parentName,
                java.lang.String alias)
         throws XMLCannotSaveException
Make a new XMLArray (constructor for saving)

Parameters:
input - The array,Vector or LinkedList to save
parentName - The XML name of the object that is going to save this array.
alias - A short description of what this array contains. Mainly useful for debugging.
Throws:
XMLCannotSaveException - If there is something wrong with the input array.
Method Detail

getResult

public java.lang.Object getResult()
                           throws XMLInvalidInputException
Return the result array,Vector or LinkedList as an object. The XMLArray has to be loaded first.

Returns:
The array which has been parsed
Throws:
XMLInvalidInputException - If the XMLArray was not loaded or if there is an internal problem.

getResultVector

protected java.util.Vector getResultVector()
Gets the result array in Vector form. Used by getResult()

Returns:
DOCUMENT ME!

getResultLinkedList

protected java.util.LinkedList getResultLinkedList()
Gets the result array in LinkedList form. Used by getResult()

Returns:
DOCUMENT ME!

getInstantiationAssistant

public InstantiationAssistant getInstantiationAssistant()
DOCUMENT ME!

Returns:
The instantiation assistant of this XMLArray, or null if doesn't have one

setInstantiationAssistant

public void setInstantiationAssistant(InstantiationAssistant assistant)
Sets the InstantiationAssistant of this XMLArray

Parameters:
assistant - new InstantiationAssistant

getResult

public java.lang.Object getResult(java.lang.Class expectedClass)
                           throws XMLInvalidInputException
Return the result array,Vector or LinkedList as an object. The XMLArray has to be loaded first. First checks if the result class equals the parameter class.

Parameters:
expectedClass - The class with which the result has to match
Returns:
The array which has been parsed
Throws:
XMLInvalidInputException - If the XMLArray was not loaded, if there is an internal problem or if the result class doesn't match the parameter class.

getComponentType

protected int getComponentType()
This method tries to guess the component type of the data array. If it cannot determine the component type, then it assumes that all components are XMLSerializable. This assumption may be wrong, but it doesn't hurt since the saver later checks all components individually.

Returns:
The component type of the data (the result is not 100% reliable)

saveArray

public static void saveArray(java.lang.Object array,
                             XMLSerializable parent,
                             XMLSaver saver,
                             java.lang.String description)
                      throws java.io.IOException,
                             XMLCannotSaveException,
                             XMLTreeException
Save an arbitrary array/vector/LinkedList

Parameters:
array - An array to save (Vectors and LinkedLists are also accepted)
parent - The object which is trying to save this array
saver - The XMLSaver to which the array has to be saved
description - A short description of the array
Throws:
java.io.IOException - DOCUMENT ME!
XMLCannotSaveException - DOCUMENT ME!
XMLTreeException - DOCUMENT ME!

saveArray

public static void saveArray(java.lang.Object array,
                             XMLSerializable parent,
                             XMLSaver saver)
                      throws java.io.IOException,
                             XMLCannotSaveException,
                             XMLTreeException
Save an arbitrary array/vector/LinkedList

Parameters:
array - An array to save (Vectors and LinkedLists are also accepted)
parent - The object which is trying to save this array
saver - The XMLSaver to which the array has to be saved
Throws:
java.io.IOException - DOCUMENT ME!
XMLCannotSaveException - DOCUMENT ME!
XMLTreeException - DOCUMENT ME!

loadArray

public static java.lang.Object loadArray(XMLSerializable parent,
                                         XMLLoader loader,
                                         java.lang.Class expectedClass)
                                  throws XMLInvalidInputException,
                                         XMLTreeException,
                                         java.io.IOException
Load an arbitrary array. Check if the result matches the expected class.

Parameters:
parent - The object that is loading this array
loader - The XMLLoader to load this array from
expectedClass - The expected class of the result
Returns:
The resulting array,vector or LinkedList
Throws:
XMLInvalidInputException - DOCUMENT ME!
XMLTreeException - DOCUMENT ME!
java.io.IOException - DOCUMENT ME!

loadArray

public static java.lang.Object loadArray(XMLSerializable parent,
                                         XMLLoader loader)
                                  throws XMLInvalidInputException,
                                         XMLTreeException,
                                         java.io.IOException
Load an arbitrary array. Do not check the result.

Parameters:
parent - The object that is loading this array
loader - The XMLLoader to load this array from
Returns:
The resulting array,vector or LinkedList
Throws:
XMLInvalidInputException - DOCUMENT ME!
XMLTreeException - DOCUMENT ME!
java.io.IOException - DOCUMENT ME!

loadArray

public static java.lang.Object loadArray(XMLSerializable parent,
                                         XMLLoader loader,
                                         InstantiationAssistant assistant)
                                  throws XMLInvalidInputException,
                                         XMLTreeException,
                                         java.io.IOException
Load an arbitrary array. Instantiate child objects via the parameter InstantiationAssistant

Parameters:
parent - The object that is loading this array
loader - The XMLLoader to load this array from
assistant - The InstantiationAssistant to use
Returns:
The resulting array,vector or LinkedList
Throws:
XMLInvalidInputException - DOCUMENT ME!
XMLTreeException - DOCUMENT ME!
java.io.IOException - DOCUMENT ME!

load

public void load(XMLElement myElement,
                 XMLLoader loader)
          throws XMLTreeException,
                 java.io.IOException,
                 XMLInvalidInputException
DOCUMENT ME!

Specified by:
load in interface XMLSerializable
Parameters:
myElement - DOCUMENT ME!
loader - DOCUMENT ME!
Throws:
XMLTreeException - DOCUMENT ME!
java.io.IOException - DOCUMENT ME!
XMLInvalidInputException - DOCUMENT ME!

saveSelf

public XMLElement saveSelf()
                    throws XMLCannotSaveException
DOCUMENT ME!

Specified by:
saveSelf in interface XMLSerializable
Returns:
DOCUMENT ME!
Throws:
XMLCannotSaveException - DOCUMENT ME!

saveChilds

public void saveChilds(XMLSaver saver)
                throws XMLTreeException,
                       java.io.IOException,
                       XMLCannotSaveException
DOCUMENT ME!

Specified by:
saveChilds in interface XMLSerializable
Parameters:
saver - DOCUMENT ME!
Throws:
XMLTreeException - DOCUMENT ME!
java.io.IOException - DOCUMENT ME!
XMLCannotSaveException - DOCUMENT ME!

getXMLName

public java.lang.String getXMLName()
DOCUMENT ME!

Specified by:
getXMLName in interface XMLSerializable
Returns:
DOCUMENT ME!

setParentName

public void setParentName(java.lang.String parentName)
DOCUMENT ME!

Specified by:
setParentName in interface XMLSerializable
Parameters:
parentName - DOCUMENT ME!