de.fu_berlin.ties.xml.io
Class ObjectElement

java.lang.Object
  extended by org.dom4j.tree.AbstractNode
      extended by org.dom4j.tree.AbstractBranch
          extended by org.dom4j.tree.AbstractElement
              extended by org.dom4j.tree.DefaultElement
                  extended by de.fu_berlin.ties.xml.io.ObjectElement
All Implemented Interfaces:
Serializable, Cloneable, Branch, Element, Node

public class ObjectElement
extends DefaultElement

An XML element that is targeted at storing an Java object.

Version:
$Revision: 1.1 $, $Date: 2004/12/06 18:00:41 $, $Author: siefkes $
Author:
Christian Siefkes
See Also:
Serialized Form

Field Summary
static String JAVA_CLASS_ATTRIBUTE
          The name of the attribute used to store the Java class of an object: "java".
 
Fields inherited from class org.dom4j.tree.AbstractElement
EMPTY_ITERATOR, EMPTY_LIST, USE_STRINGVALUE_SEPARATOR, VERBOSE_TOSTRING
 
Fields inherited from class org.dom4j.tree.AbstractBranch
DEFAULT_CONTENT_LIST_SIZE, outputFormat
 
Fields inherited from class org.dom4j.tree.AbstractNode
NODE_TYPE_NAMES
 
Fields inherited from interface org.dom4j.Node
ANY_NODE, ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_NODE, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_REFERENCE_NODE, MAX_NODE_TYPE, NAMESPACE_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE, UNKNOWN_NODE
 
Constructor Summary
ObjectElement(QName qname, Class javaClass)
          Creates a new instance.
ObjectElement(String name, Class javaClass)
          Creates a new instance.
ObjectElement(String name, Namespace namespace, Class javaClass)
          Creates a new instance.
 
Method Summary
 Object createObject()
          Creates (deserializes) an object of a specified type by calling a constructor of the class that accepts an XML element as single argument and passing itself as parameter.
static Object createObject(Element element, Class type)
          Creates (deserializes) an object of a specified type by calling a constructor of the class that accepts an XML element as single argument and passing itself as parameter.
 Class javaClass()
          Returns the Class of the stored object.
 String javaClassName()
          Returns the name of the Class of the stored object.
 boolean unsetJavaClassAttrib()
          Unsets the attribute representing the Class of the stored object.
 
Methods inherited from class org.dom4j.tree.DefaultElement
add, additionalNamespaces, additionalNamespaces, addNewNode, attribute, attribute, attribute, attribute, attributeCount, attributeIterator, attributeList, attributeList, attributes, clearContent, clone, contentList, declaredNamespaces, element, element, element, getDocument, getDocumentFactory, getNamespaceForPrefix, getNamespaceForURI, getParent, getQName, getStringValue, getText, indexOf, node, nodeCount, nodeIterator, processingInstruction, processingInstructions, processingInstructions, remove, removeNode, removeProcessingInstruction, setAttributeList, setAttributes, setContent, setDocument, setParent, setQName, supportsParent
 
Methods inherited from class org.dom4j.tree.AbstractElement
accept, add, add, add, add, add, add, add, add, addAttribute, addAttribute, addCDATA, addComment, addElement, addEntity, addNamespace, addNewNode, addNode, addNode, addProcessingInstruction, addProcessingInstruction, addText, appendAttributes, asXML, attributeValue, attributeValue, attributeValue, attributeValue, childAdded, childRemoved, createAttributeList, createAttributeList, createCopy, createCopy, createCopy, createElement, createElement, createSingleIterator, elementIterator, elementIterator, elementIterator, elementIterator, elements, elements, elements, elements, elementText, elementText, elementTextTrim, elementTextTrim, ensureAttributesCapacity, getData, getName, getNamespace, getNamespacePrefix, getNamespacesForURI, getNamespaceURI, getNodeType, getPath, getQName, getQualifiedName, getUniquePath, getXPathNameStep, getXPathResult, hasMixedContent, isRootElement, isTextOnly, normalize, remove, remove, remove, remove, remove, remove, remove, remove, setAttributes, setAttributeValue, setAttributeValue, setData, setName, setNamespace, setText, toString, write
 
Methods inherited from class org.dom4j.tree.AbstractBranch
addElement, addElement, addElement, appendContent, content, contentRemoved, createContentList, createContentList, createEmptyList, createResultList, createSingleResultList, elementByID, elementID, getContentAsStringValue, getContentAsText, getTextTrim, hasContent, invalidNodeTypeAddException, isReadOnly, setProcessingInstructions
 
Methods inherited from class org.dom4j.tree.AbstractNode
asXPathResult, createPattern, createXPath, createXPathFilter, createXPathResult, detach, getNodeTypeName, getPath, getUniquePath, matches, numberValueOf, selectNodes, selectNodes, selectNodes, selectObject, selectSingleNode, valueOf
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.dom4j.Element
getTextTrim
 
Methods inherited from interface org.dom4j.Branch
addElement, addElement, appendContent, content, elementByID, setProcessingInstructions
 
Methods inherited from interface org.dom4j.Node
asXPathResult, createXPath, detach, getNodeTypeName, getPath, getUniquePath, hasContent, isReadOnly, matches, numberValueOf, selectNodes, selectNodes, selectNodes, selectObject, selectSingleNode, valueOf
 

Field Detail

JAVA_CLASS_ATTRIBUTE

public static final String JAVA_CLASS_ATTRIBUTE
The name of the attribute used to store the Java class of an object: "java".

See Also:
Constant Field Values
Constructor Detail

ObjectElement

public ObjectElement(String name,
                     Class javaClass)
Creates a new instance.

Parameters:
name - the name of the element
javaClass - the class of the object to store

ObjectElement

public ObjectElement(QName qname,
                     Class javaClass)
Creates a new instance.

Parameters:
qname - the qualified name of the element
javaClass - the class of the object to store

ObjectElement

public ObjectElement(String name,
                     Namespace namespace,
                     Class javaClass)
Creates a new instance.

Parameters:
name - the local name of the element
namespace - the namespace of the element
javaClass - the class of the object to store
Method Detail

createObject

public static final Object createObject(Element element,
                                        Class type)
                                 throws InstantiationException,
                                        SecurityException
Creates (deserializes) an object of a specified type by calling a constructor of the class that accepts an XML element as single argument and passing itself as parameter. Only classes that provide a suitable constructor can be instantiated this way.

Parameters:
type - the class of the object to create; must have a constructor whose only argument is an Element
Returns:
the created object; the returned object will be an instance of the specified class
Throws:
InstantiationException - if instantiation failed
SecurityException - if access to the required reflection information is denied

createObject

public final Object createObject()
                          throws InstantiationException,
                                 SecurityException,
                                 ClassNotFoundException,
                                 IllegalStateException
Creates (deserializes) an object of a specified type by calling a constructor of the class that accepts an XML element as single argument and passing itself as parameter. Only classes that provide a suitable constructor can be instantiated this way.

Returns:
the created object
Throws:
InstantiationException - if instantiation failed
SecurityException - if access to the required reflection information is denied
ClassNotFoundException - if the class specified in the JAVA_CLASS_ATTRIBUTE is not available on this system
IllegalStateException - if the java class attribute has been removed (by calling unsetJavaClassAttrib()

javaClassName

public String javaClassName()
Returns the name of the Class of the stored object.

Returns:
the class name of the stored object; or null if unsetJavaClassAttrib() has been called before

javaClass

public Class javaClass()
                throws ClassNotFoundException,
                       IllegalStateException
Returns the Class of the stored object.

Returns:
the class of the stored object
Throws:
ClassNotFoundException - if the class cannot be located
IllegalStateException - if the java class attribute has been removed (by calling unsetJavaClassAttrib()

unsetJavaClassAttrib

public boolean unsetJavaClassAttrib()
Unsets the attribute representing the Class of the stored object.

Returns:
true if the attribute was successfully removed (first call to this method); false if there was no such attribute (later calls to this method)


Copyright © 2003-2004 Christian Siefkes. All Rights Reserved.