Package ucar.unidata.xml
Class XmlEncoder
java.lang.Object
ucar.unidata.xml.XmlUtil
ucar.unidata.xml.XmlEncoder
See the package.html This class is in part responsible for (de)serializing
bundles.
-
Nested Class Summary
Nested classes/interfaces inherited from class ucar.unidata.xml.XmlUtil
XmlUtil.ElementListIterator
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
The name for the class attribute.static final String
The name for the encode attributestatic final String
The name for the id attribute.static final String
The name for the idref attribute.static final String
The name for the length attribute.static final String
The name for the name attribute.static final String
The name for the null attribute.static final String
The name for the stringvalue attribute.static final String
The name for the value attribute.static boolean
Just a debug flag.protected ArrayList
List of classes that we have correspondingXmlDelegate
s for.protected ArrayList
The List ofXmlDelegate
s that know how to handle certain classes.protected Document
The Xml document we create.static final String
Method name for List.addstatic final String
The name of the init method that is called (if it exists) after an object is deserializedstatic final String
Method name for Hashtable.putstatic final String
The name used in the xml for String objects.static final String
The tag name used for arrays.static final String
The xml tag for constructors.static final String
The tag name used for enums.static final String
The xml tag for factory objects.static final String
The xml tag for object fields.static final String
The xml tag when we want to ignore something?static final String
The xml tag for method calls.static final String
The xml tag for the null object.static final String
The xml tag for objects.static final String
The tag name used for primitive arrays.static final String
The xml tag for properties.static final String
The xml tag for serialized objects.static final String
The value for the encode by base64Fields inherited from class ucar.unidata.xml.XmlUtil
NULL_STRING, TAG_WILDCARD, XML_HEADER
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addClassPatternReplacement
(String pattern, String replace) This allows on to change package paths of classes that are in bundles with a new pathprotected void
Define the set of default delegates (e.g., for Rectangle, Font, etc.) for common objects that don't encode very well.void
addDelegateForClass
(Class theClass, XmlDelegate delegate) Add anXmlDelegate
for the given class.void
addHighPriorityDelegateForClass
(Class theClass, XmlDelegate delegate) Add anXmlDelegate
for the given class.void
addSeedObject
(Object seedObject) Add an existing object from the environement that is to be used in place of a newly created object.void
clear()
Clear the internal state this encoder keeps during the encoding/decoding process.createArrayElement
(Object arrayObject) Create an Xml Element that represents the given object (which should be an array).createArrayObject
(Element element) Create an array that contains a set of objects.createConstructorElement
(List arguments) Construct a "constructor" tag that holds the set of argument objects.createConstructorElement
(List arguments, List types) Construct a "constructor" tag that holds the set of argument objects with respective types.createElement
(Object object) This acts as a wrapper around(Object, boolean)
, passing in true for the checkPersistable flag.createElement
(Object object, boolean checkDelegate) This acts as a wrapper aroundcreateElement(Object,Class,boolean,boolean)
, passing in true for the checkPersistable flag.protected Element
createElement
(Object object, Class theClass) This acts as a wrapper aroundcreateElement(Object,Class,boolean,boolean)
, passing in true and true for the checkPersistable and checkDelegate flags.protected Element
createElement
(Object object, Class theClass, boolean checkPersistable, boolean checkDelegate) Create a xml representation of the object.createElementDontCheckDelegate
(Object object) This acts as a wrapper aroundcreateElement(Object,boolean)
, passing in false for the checkDelegate flag.This acts as a wrapper aroundcreateElement(Object,Class,boolean,boolean)
, passing in false for the checkPersistable flag and true for the checkDelegate flag.createElementForObject
(Object object, Class theClass) Construct the Xml representation of the given object.createEnumElement
(E e) Creates the element based on the enum.createEnumObject
(Element element) Creates the enum.createFactoryElement
(Class factoryClass) Create a "factory" tag with the given factoryClass.createMethodElement
(String methodName) Create a "method" xml element, one that represents a method call.createMethodElement
(String methodName, List argumentElements) Create a "method" xml element, one that represents a method call.createMethodElement
(String methodName, Element contents) Create a "method" xml element, one that represents a method call.Create a null element with no class.createNullElement
(Class type) Create a null element with the given class (if non-null).createObject
(Element element) Create an object defined by the given XML.createObjectConstructorElement
(Object object, List arguments) Create an object tag that holds a constructor tag.createObjectConstructorElement
(Object object, List arguments, List types) Create an object tag that holds a constructor tag.createObjectDontCheckDelegate
(Element element) Create an object defined by the given XML.createObjectElement
(Class objectClass) Create a "object" tag with the given objectClass.createObjectInner
(Element element) Create the object defined by the given xml.createObjectInner
(Element element, boolean checkDelegate) This method creates both the Object that the Element element represents and its Class.createPrimitiveArrayElement
(Object primitiveArray) Create an Xml Element that represents the given array of primitives.createPrimitiveArrayObject
(Element element) Create an array that contains a set of primitive objects.createPrimitiveElement
(String primitiveName, Object value) Create the xml element for the given primitive value and name.createPrimitiveObject
(Class primitiveClass, String value) Create the primitive object defined by the given class and value.createPrimitiveObject
(Class primitiveClass, Element element) Create the primitive object defined by the given class and xml element.createPropertyElement
(String propertyName, Element value) Create a "property" xml element, one that represents a bean property on an object.Create an element that represents a reference to an already encoded object.createSerialElement
(Class theClass, String serialRepresentation) Create a "serial" xml element, one that represents a serialized Object.createSerializedObject
(Element parent) Deserialize the serialized object defined by the given parent xml element.createTextNode
(String contents) A utility to create a text nodestatic Object
Decode the XMLvoid
defineObjectId
(Object theObject, String theId) Allow client code to predefine an object to id mapping.static Object
deserialize
(byte[] bytes) A utility to deserialize the given bytesstatic String
encodeObject
(Object object) XML encode the objectstatic List
For the given class find the set of public set/get property methods.static List
findPropertyMethods
(Class c, boolean returnGetters) Find the property methodsFind the Class that corresponds to the given className.getClassName
(Class theClass) Get the String name of the given class.protected XmlDelegate
getDelegate
(Class theClass) Find theXmlDelegate
that handles the given class.Create (if needed) and return the xml Document for this encoder.protected Element
getElementForObject
(Object theObject) Return the DOM element that represents the given object.The the error messagesGet the exceptionsgetFieldElements
(Object object, Hashtable propertyNames) Return a List of Xml Elements that represent the set of public fields in the given object.protected String
Utility method to return a unique (during a particular encoding) String id.protected Object
Returns the object (maybe null) that has the given id.protected String
getObjectId
(Object theObject) Return the encoding id defined for the given object.getPrimitiveClass
(String name) For the given name (e.g., "int", "boolean") return the class (e.g., Integer.TYPE, Boolean.TYPE).getPrimitiveCtor
(Class primitiveClass) Find the Constructor that creates objects of the given primitive class.getPrimitiveName
(Class primitiveClass) Return the name of the class to be used for the given class.getPropertyElements
(Object object, Hashtable propertyNames) Return a List of Xml Elements that represent the set of public properties in the given object.getSpecialCaseElements
(Object object) Handle certain objects in a special way.getTextFromChild
(Element parent) A utility to find the text node child of the given parentprotected void
init()
This resets the state of this encoder.protected void
Initialize the mapping between names for primitives and their classes.protected void
invokeField
(Object object, String fieldName, Element parent) Set the field, identified by the given field name, on the given object, to the value defined by the first xml child of the given parent.protected void
invokeMethod
(Object object, String methodName, Element element) Invoke the the method, identified by the given method name, on the given object.boolean
isPrimitive
(Class theClass) Is the given Class a primitive (e.g., an int, float, Integer, Double, etc.).static void
Runs some tests.boolean
Is the given method name one of the allowable methods to execute.newElement
(String tagName) Create a new Element of the given tag name using the current document.static void
A utility method to print out an error message if we are in debug mode.void
registerClassName
(String theName, Class theClass) Define a mapping from some name (perhaps an old class path) to the new Class that actually is used to create an object.void
registerNewClassName
(String oldName, String newName) Register new class namestatic byte[]
serialize
(Serializable object) A utility to serialize the given objectvoid
setDocument
(Document document) Set the xml Document used by this encoder.protected void
Define a mapping between the given id and the object.protected String
setObjectId
(Object theObject) Create a new id and define mappings between the id, object and DOM element.setObjectId
(Object theObject, Element element) Create a new id and define mappings between the id, object and DOM element.boolean
A simple test method.Create the DOM Element that represents the given object.Create an object from the given xml.XML string to objectCreate an object from the given dom subtree.Convert the given object to xml, formatting the xml (with spaces and newlines).Convert the given object to xml.Methods inherited from class ucar.unidata.xml.XmlUtil
addChildren, appendCdata, appendCdataBytes, attr, attr, attrs, attrs, attrs, attrs, attrs, calculateRFC2104HMAC, closeTag, comment, create, create, create, create, create, create, create, create, create, create, create, create, createCDataNode, decodeBase64, elements, encodeBase64, encodeString, ensureAttributes, eval, expr, findAncestor, findChild, findChildRecurseUp, findChildren, findChildrenRecurseUp, findDescendant, findDescendantFromPath, findDescendants, findDescendantsFromPath, findElement, findElement, findRoot, findUrlRefNode, findUrlRefNode, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttributeFromTree, getAttributeFromTree, getAttributeFromTree, getAttributeFromTree, getAttributesFromTree, getAttributesFromTree, getCdata, getChildText, getDocument, getDocument, getDocument, getElement, getElements, getElements, getElements, getFirstChild, getGrandChildren, getGrandChildText, getGrandChildText, getGrandChildValue, getHeader, getListOfElements, getLocalName, getNodeName, getRoot, getRoot, getRoot, hasAttribute, isFullyQualified, isTag, loadXml, makeCDataNode, makeCDataNode, makeDocument, mergeAttributes, openTag, openTag, quote, removeChildren, setAttribute, setAttributes, tag, tag, toHtml, toString, toString, toString, toString, toString, toStringNoChildren, toStringWithHeader, toStringWithHeader, toStringWithHeader
-
Field Details
-
debug
public static boolean debugJust a debug flag. -
METHOD_INIT
The name of the init method that is called (if it exists) after an object is deserialized- See Also:
-
METHOD_PUT
Method name for Hashtable.put- See Also:
-
METHOD_ADD
Method name for List.add- See Also:
-
NAME_STRING
The name used in the xml for String objects.- See Also:
-
TAG_ARRAY
The tag name used for arrays.- See Also:
-
TAG_ENUM
The tag name used for enums.- See Also:
-
TAG_PARRAY
The tag name used for primitive arrays.- See Also:
-
TAG_CONSTRUCTOR
The xml tag for constructors.- See Also:
-
TAG_FACTORY
The xml tag for factory objects.- See Also:
-
TAG_FIELD
The xml tag for object fields.- See Also:
-
TAG_IGNORE
The xml tag when we want to ignore something?- See Also:
-
TAG_METHOD
The xml tag for method calls.- See Also:
-
TAG_NULL
The xml tag for the null object.- See Also:
-
TAG_OBJECT
The xml tag for objects.- See Also:
-
TAG_PROPERTY
The xml tag for properties.- See Also:
-
TAG_SERIAL
The xml tag for serialized objects.- See Also:
-
ATTR_CLASS
The name for the class attribute.- See Also:
-
ATTR_ENCODING
The name for the encode attribute- See Also:
-
VALUE_BASE64
The value for the encode by base64- See Also:
-
ATTR_ID
The name for the id attribute.- See Also:
-
ATTR_IDREF
The name for the idref attribute.- See Also:
-
ATTR_NAME
The name for the name attribute.- See Also:
-
ATTR_NULL
The name for the null attribute.- See Also:
-
ATTR_STRINGVALUE
The name for the stringvalue attribute.- See Also:
-
ATTR_LENGTH
The name for the length attribute.- See Also:
-
ATTR_VALUE
The name for the value attribute.- See Also:
-
document
The Xml document we create. -
delegateClasses
List of classes that we have correspondingXmlDelegate
s for. -
delegates
The List ofXmlDelegate
s that know how to handle certain classes.
-
-
Constructor Details
-
XmlEncoder
public XmlEncoder()Create a new XmlEncoder.
-
-
Method Details
-
addDefaultDelegates
protected void addDefaultDelegates()Define the set of default delegates (e.g., for Rectangle, Font, etc.) for common objects that don't encode very well. -
toXml
Convert the given object to xml, formatting the xml (with spaces and newlines).- Parameters:
theObject
- The object to convert.- Returns:
- The String xml that represents the object.
-
toXml
Convert the given object to xml.- Parameters:
theObject
- The object to convert.formatXml
- Do we format the result xml with newlines and spaces to make it readable.- Returns:
- The String xml that represents the object.
-
getExceptions
Get the exceptions- Returns:
- the list of exceptions
-
getErrorMessages
The the error messages- Returns:
- the list of error messages
-
toElement
Create the DOM Element that represents the given object.- Parameters:
theObject
- The object to encode.- Returns:
- The dom Element that represents the given Object.
-
decodeXml
Decode the XML- Parameters:
xml
-- Returns:
- the decoded XML
- Throws:
Exception
-
encodeObject
XML encode the object- Parameters:
object
-- Returns:
- encoded object as XML string
- Throws:
Exception
-
toObject
Create an object from the given xml. This will catch any exceptions and print them out in toto, returning null.- Parameters:
xml
- The xml String that defines an object.- Returns:
- The newly created object.
- Throws:
Exception
- When anything bad happens.
-
toObject
XML string to object- Parameters:
xml
-catchAndLogError
-- Returns:
- the object
- Throws:
Exception
-
toObject
Create an object from the given dom subtree.- Parameters:
node
- The xml.- Returns:
- the newly created object.
-
clear
public void clear()Clear the internal state this encoder keeps during the encoding/decoding process. -
init
protected void init()This resets the state of this encoder. -
methodOk
Is the given method name one of the allowable methods to execute.- Parameters:
methodName
- The mehtod name.- Returns:
- Ok to invoke the method.
-
addDelegateForClass
Add anXmlDelegate
for the given class. The delegate is the object responsible for the persistence of all objects of the type of the given class or are a derived class.- Parameters:
theClass
- The class to handle.delegate
- The delegate that handles the class.
-
addHighPriorityDelegateForClass
Add anXmlDelegate
for the given class. The given delegate will get added to the beginning of the list so that it takes priority over ant existing delegates The delegate is the object responsible for the persistence of all objects of the type of the given class or are a derived class.- Parameters:
theClass
- The class to handle.delegate
- The delegate that handles the class.
-
getDelegate
Find theXmlDelegate
that handles the given class.- Parameters:
theClass
- The class.- Returns:
- The delegate that handles the class.
-
getDocument
Create (if needed) and return the xml Document for this encoder.- Returns:
- The xml document to write to.
-
setDocument
Set the xml Document used by this encoder. This allows client code to override which Document is to be used.- Parameters:
document
- The new xml document for this encoder to use.
-
getNextId
Utility method to return a unique (during a particular encoding) String id.- Returns:
- A unique (for this encoder) id.
-
getObjectFromId
Returns the object (maybe null) that has the given id.- Parameters:
id
- The id to lookup.- Returns:
- The object defined by the id or null if not found.
-
addSeedObject
Add an existing object from the environement that is to be used in place of a newly created object. You can "seed" an encoder so that when a newly created object is ".equals" with the seedObject then we actually return and use the seedObject. This way we maintain Object pointer equality.- Parameters:
seedObject
- The object that exists in the environment that we really want to use.
-
setObject
Define a mapping between the given id and the object.- Parameters:
id
- The id of the object.theObject
- The object.
-
getObjectId
Return the encoding id defined for the given object.- Parameters:
theObject
- The object to lookup an id for.- Returns:
- The string id of the object or null.
-
getElementForObject
Return the DOM element that represents the given object.- Parameters:
theObject
- The object.- Returns:
- The dom Element that represented the object or null if not found.
-
defineObjectId
Allow client code to predefine an object to id mapping. This allows client code to predefine that certain objects (say, perhaps a fixed global singleton) are defined with the given id. The object itself won't get written out in the encoding but any other object that has a reference to theObject will write out an <object idref=theId> tag. When the encoded object is read back in it will point to the predefined object. e.g.:encoder.defineObjectId (someSingletonObject, "idOfSingletonObject");
Will result in xml that looks like:<object class="SomeOtherObject"> ... invalid input: '<' property name="referenceToSomeSingleton" idref="idOfSingletonObject"/> ...
Now when we decode the above xml the object defined with "idOfSingletonObject" will be pre-loaded here.- Parameters:
theObject
- The initial object.theId
- The id.
-
setObjectId
Create a new id and define mappings between the id, object and DOM element.- Parameters:
theObject
- The object to define an id for.- Returns:
- The new id.
-
setObjectId
Create a new id and define mappings between the id, object and DOM element.- Parameters:
theObject
- The object to define a new id for.element
- The Xml DOM node that defines theObject.- Returns:
- The new id of the object.
-
initPrimitiveName
protected void initPrimitiveName()Initialize the mapping between names for primitives and their classes. -
isPrimitive
Is the given Class a primitive (e.g., an int, float, Integer, Double, etc.).- Parameters:
theClass
- The class to check.- Returns:
- Is theClass a primitive Class.
-
getPrimitiveName
Return the name of the class to be used for the given class.- Parameters:
primitiveClass
- The class.- Returns:
- The class name to use for the class.
-
getPrimitiveClass
For the given name (e.g., "int", "boolean") return the class (e.g., Integer.TYPE, Boolean.TYPE).- Parameters:
name
- Primitive class name.- Returns:
- The Class.
-
getPrimitiveCtor
Find the Constructor that creates objects of the given primitive class.- Parameters:
primitiveClass
- The class of the primitive (e.g., Integer, int, etc.)- Returns:
- The constructor to use.
-
registerClassName
Define a mapping from some name (perhaps an old class path) to the new Class that actually is used to create an object. For example, say you have encoded and saved as xml some object with class: old.path.SomeObject. Now later you restructured your code (like good programmers do) so now the SomeObject class is really: new.path.SomeObject but you want to be able to read in the old xml. So you do:encoder.registerClassName ("old.path.SomeObject", new.path.SomeObject.class);
- Parameters:
theName
- The old class name.theClass
- The new Class to use.
-
registerNewClassName
Register new class name- Parameters:
oldName
- the old namenewName
- the new name
-
addClassPatternReplacement
This allows on to change package paths of classes that are in bundles with a new path- Parameters:
pattern
- the patternreplace
- the replace pattern
-
getClass
Find the Class that corresponds to the given className. Lookup in the classNameToClass table to see if we have a different Class. If not then just used Class.forName (className);- Parameters:
className
- The name of the Class.- Returns:
- The class found for the className.
- Throws:
ClassNotFoundException
- When we cannot find the class.
-
getClassName
Get the String name of the given class. We lookup to see if the given Class is for one of the primitive types. Else we lookup in the mapping defined with registerClassName. Finally we simply use theClass.getName ().- Parameters:
theClass
- The Class.- Returns:
- The name to use for the given Class.
-
newElement
Create a new Element of the given tag name using the current document.- Parameters:
tagName
- The tag name.- Returns:
- The new Element.
-
createArrayElement
Create an Xml Element that represents the given object (which should be an array). For example, a String array:String[]array ={"foo", "bar"};
would result in: String[]array ={"foo", "bar"};<array class="string" length="2" > <string><![CDATA[foo]]></string> <string><![CDATA[bar]]></string> </array>
Primitive arrays are handled differently (for size reasons):int[]array ={5,4};
Would result in:<parray class="int" length="2" >5,4</parray>
- Parameters:
arrayObject
- The array object.- Returns:
- The new Xml Element that represents the arrayObject.
-
createEnumElement
Creates the element based on the enum.- Type Parameters:
E
- the enum element type- Parameters:
e
- the e- Returns:
- the element
-
createPrimitiveArrayElement
Create an Xml Element that represents the given array of primitives.- Parameters:
primitiveArray
- The array of primitives.- Returns:
- The xml representation of the primitive array.
-
createTextNode
A utility to create a text node- Parameters:
contents
- The text- Returns:
- The text node
-
deserialize
A utility to deserialize the given bytes- Parameters:
bytes
- The bytes- Returns:
- The deserialized object
- Throws:
Exception
- When something bad happens
-
serialize
A utility to serialize the given object- Parameters:
object
- The object- Returns:
- The serialized representation of the object
- Throws:
Exception
- When something bad happens
-
createMethodElement
Create a "method" xml element, one that represents a method call. The argumentElements is a List of Xml Elements that represent the arguments to the method.- Parameters:
methodName
- The name of the method.argumentElements
- List of method arguments.- Returns:
- The method xml Element.
-
createMethodElement
Create a "method" xml element, one that represents a method call.- Parameters:
methodName
- The name of the method.contents
- Xml represention of the method arguments.- Returns:
- The method xml Element.
-
createMethodElement
Create a "method" xml element, one that represents a method call. This method has no arguments.- Parameters:
methodName
- The name of the method.- Returns:
- The method xml Element.
-
createSerialElement
Create a "serial" xml element, one that represents a serialized Object.- Parameters:
theClass
- The class of the original serialized object.serialRepresentation
- Go figure.- Returns:
- The xml element that represents the serialized object.
-
createPropertyElement
Create a "property" xml element, one that represents a bean property on an object.- Parameters:
propertyName
- The bean name.value
- The xml represention of the property value.- Returns:
- The xml element that represents the property.
-
createReferenceElement
Create an element that represents a reference to an already encoded object.- Parameters:
id
- The id of the object.- Returns:
- The xml element that represents holds the object reference.
-
createPrimitiveElement
Create the xml element for the given primitive value and name.- Parameters:
primitiveName
- The name of the primitive (e.g., string, int, etc.)value
- The value.- Returns:
- The xml representation of the primitive.
-
createNullElement
Create a null element with the given class (if non-null).- Parameters:
type
- The class of the null object.- Returns:
- The null element.
-
createNullElement
Create a null element with no class.- Returns:
- The null element.
-
createObjectElement
Create a "object" tag with the given objectClass.- Parameters:
objectClass
- The class of the object.- Returns:
- The xml object tag.
-
createFactoryElement
Create a "factory" tag with the given factoryClass.- Parameters:
factoryClass
- The class of the object that implementsXmlObjectFactory
.- Returns:
- The xml factory tag.
-
createObjectConstructorElement
Create an object tag that holds a constructor tag.- Parameters:
object
- The object to encode.arguments
- The argument values to the constructor.- Returns:
- The xml object tag containing a constructor tag.
-
createObjectConstructorElement
Create an object tag that holds a constructor tag.- Parameters:
object
- The object to encode.arguments
- The argument values to the constructor.types
- The types of the arguments- Returns:
- The xml object tag containing a constructor tag.
-
createConstructorElement
Construct a "constructor" tag that holds the set of argument objects.- Parameters:
arguments
- The argument values.- Returns:
- The xml constructor tag.
-
createConstructorElement
Construct a "constructor" tag that holds the set of argument objects with respective types.- Parameters:
arguments
- The argument values.types
- The types of the arguments.- Returns:
- The xml constructor tag.
-
findPropertyMethods
For the given class find the set of public set/get property methods.- Parameters:
c
- The class to look at.- Returns:
- The list of property Method-s.
-
findPropertyMethods
Find the property methods- Parameters:
c
- the classreturnGetters
- return the getters- Returns:
- list of property methods
-
createObject
Create an object defined by the given XML.- Parameters:
element
- The xml representation of the object.- Returns:
- The object.
-
createObjectDontCheckDelegate
Create an object defined by the given XML. Don't check if the object has a delegate.- Parameters:
element
- The xml representation of the object.- Returns:
- The object.
-
createArrayObject
Create an array that contains a set of objects.- Parameters:
element
- The xml representation of the array.- Returns:
- The array object and its class.
-
createEnumObject
Creates the enum.- Parameters:
element
- the element- Returns:
- the enum
-
getTextFromChild
A utility to find the text node child of the given parent- Parameters:
parent
- The parent node- Returns:
- The contents of the text node
-
createPrimitiveArrayObject
Create an array that contains a set of primitive objects.- Parameters:
element
- The xml representation of the primitive array.- Returns:
- The primitive array object and its class.
-
createPrimitiveObject
Create the primitive object defined by the given class and xml element.- Parameters:
primitiveClass
- The class of the primitive.element
- The xml representation of the primitive.- Returns:
- The primitive object and its class.
-
createPrimitiveObject
Create the primitive object defined by the given class and value.- Parameters:
primitiveClass
- The class of the primitive.value
- The String representation of the value.- Returns:
- The primitive object.
-
createSerializedObject
Deserialize the serialized object defined by the given parent xml element.- Parameters:
parent
- Contains the serialization xml.- Returns:
- The new object and its class.
-
createObjectInner
Create the object defined by the given xml.- Parameters:
element
- Defines the object.- Returns:
- The object with its class.
-
createObjectInner
This method creates both the Object that the Element element represents and its Class. We keep track of the Class separately to handle primitive types (e.g., int, boolean, double).- Parameters:
element
- The xml element that represents the encoded object.checkDelegate
- Should we check if there is anXmlDelegate
for this object.- Returns:
- The pair (object, Class).
-
invokeMethod
Invoke the the method, identified by the given method name, on the given object. Use the children of the given parent xml node as the arguments to the method.- Parameters:
object
- The object to set the field value of.methodName
- The name of the method.element
- The parent xml node that contains the argument object values.
-
invokeField
Set the field, identified by the given field name, on the given object, to the value defined by the first xml child of the given parent.- Parameters:
object
- The object to set the field value of.fieldName
- The name of the field.parent
- The parent xml node that contains the object value.
-
createElement
This acts as a wrapper around(Object, boolean)
, passing in true for the checkPersistable flag.- Parameters:
object
- The object to create the xml element for.- Returns:
- The xml representation of the object.
-
createElementDontCheckPersistable
This acts as a wrapper aroundcreateElement(Object,Class,boolean,boolean)
, passing in false for the checkPersistable flag and true for the checkDelegate flag.- Parameters:
object
- The object to create the xml element for.- Returns:
- The xml representation of the object.
-
createElementDontCheckDelegate
This acts as a wrapper aroundcreateElement(Object,boolean)
, passing in false for the checkDelegate flag.- Parameters:
object
- The object to create the xml element for.- Returns:
- The xml representation of the object.
-
createElement
This acts as a wrapper aroundcreateElement(Object,Class,boolean,boolean)
, passing in true for the checkPersistable flag.- Parameters:
object
- The object to create the xml element for.checkDelegate
- Should we check if the object has anXmlDelegate
that handles it.- Returns:
- The xml representation of the object.
-
createElement
This acts as a wrapper aroundcreateElement(Object,Class,boolean,boolean)
, passing in true and true for the checkPersistable and checkDelegate flags.- Parameters:
object
- The object to create the xml element for.theClass
- Its class.- Returns:
- The xml representation of the object.
-
createElement
protected Element createElement(Object object, Class theClass, boolean checkPersistable, boolean checkDelegate) Create a xml representation of the object. The object may be anything, null, a primitive, an array or a regular object. We pass the class of the object in in case it is null. The flags tell whether to check if the object is a XmlPersistable or has a delegate (the default is to check).- Parameters:
object
- The object to encode.theClass
- The Class of the object.checkPersistable
- Do we defer to the object if is is anXmlPersistable
checkDelegate
- Do we defer to the delegate if the object has anXmlDelegate
- Returns:
- The xml representation of the object.
-
createElementForObject
Construct the Xml representation of the given object. This object is just a regular Object, not a primitive, array, etc.- Parameters:
object
- The regular object.theClass
- The class of the object. We have this here in case the object is null.- Returns:
- The xml representation of the object.
-
getFieldElements
Return a List of Xml Elements that represent the set of public fields in the given object.- Parameters:
object
- The object to look for fields in.propertyNames
- These represent properties that are already being persisted.- Returns:
- A List of xml "field" elements.
-
getPropertyElements
Return a List of Xml Elements that represent the set of public properties in the given object. A property is denoted with public set/get methods of the same type.- Parameters:
object
- The object to look for properties in.propertyNames
- Put the property names in here so we can keep them unique.- Returns:
- A List of xml "property" elements.
-
getSpecialCaseElements
Handle certain objects in a special way. For List-s return a set of "add" method Elements. For a Hashtable return a set of "put" method elements.- Parameters:
object
- The object to check for special case handling.- Returns:
- A list of xml Elements or null if the object is not special.
-
pr
A utility method to print out an error message if we are in debug mode.- Parameters:
msg
- The message.
-
test
A simple test method.- Parameters:
o
- The object to encode.printXml
- Do we println the result xml.- Returns:
- Did we pass the test.
- Throws:
Exception
- When something goes bad.
-
main
Runs some tests.- Parameters:
args
- The command line arguments.
-