net.charlesames.utility.entity
Class XmlComplexElement

java.lang.Object
  extended by net.charlesames.utility.entity.XmlNode
      extended by net.charlesames.utility.entity.XmlElement
          extended by net.charlesames.utility.entity.XmlComplexElement

public abstract class XmlComplexElement
extends XmlElement

An XmlComplexElement instance is a component of an XmlSpec that maps object properties, object references, and child objects to XML child elements. Each XmlComplexElement instance is created as an anonymous class which defines two particular methods. XmlElement.getData(WriteableEntity, Element) implements the code which reads data from an XML element into a WriteableEntity instance. XmlNode.putData(WriteableEntity, Element) implements the code which writes data from a WriteableEntity property into an XML attribute. Here is an example:

   xmlSpec.addElement(new XmlElement("seed") {
      @Override
      public void putData(WriteableEntity entity, Element element) {
         Stage stage = (Stage) entity;
         Xml.appendContentElement(element, getTag(), Long.toString(stage.seed));
      }
      @Override
      public void getData(WriteableEntity entity, Element element) {
         Stage stage = (Stage) entity;
         try {
            stage.seed = Xml.getLongContent(element);
         }
         catch (IllegalArgumentException e) {
            stage.logLoadError(element, e.getMessage());
         } catch (Exception e) {
            stage.logLoadError(element, e.getMessage());
         }
      }
   });

Author:
Charles Ames

Constructor Summary
XmlComplexElement(XmlSpec xmlSpec, java.lang.Class<? extends WriteableEntity> entityClass, java.lang.String tag)
          Constructor for XmlComplexElement instances.
 
Method Summary
 java.lang.Class<? extends WriteableEntity> getEntityClass()
          Get the entity class.
 org.w3c.dom.Element toXsdElement(org.w3c.dom.Node parent)
          Convert the XML specification node to a node description in an XML schema document
 
Methods inherited from class net.charlesames.utility.entity.XmlElement
getData, getMaxOccurs, getMinOccurs, getXsdTag, isIncludedInSchema, setMaxOccurs, setMinOccurs
 
Methods inherited from class net.charlesames.utility.entity.XmlNode
getDescription, getTag, getXmlSpec, putData, setDescription, setIncludedInSchema
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlComplexElement

public XmlComplexElement(XmlSpec xmlSpec,
                         java.lang.Class<? extends WriteableEntity> entityClass,
                         java.lang.String tag)
Constructor for XmlComplexElement instances.

Parameters:
xmlSpec - The parent XML specification.
entityClass - The entity class.
tag - The XML Element node name.
Method Detail

getEntityClass

public java.lang.Class<? extends WriteableEntity> getEntityClass()
Get the entity class.

Returns:
The entity class.

toXsdElement

public org.w3c.dom.Element toXsdElement(org.w3c.dom.Node parent)
Description copied from class: XmlNode
Convert the XML specification node to a node description in an XML schema document

Overrides:
toXsdElement in class XmlElement
Parameters:
parent - The parent node.
Returns:
THe newly created node.