net.charlesames.utility.entity
Class XmlSimpleElement

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

public abstract class XmlSimpleElement
extends XmlElement

An XmlSimpleElement instance is a component of an XmlSpec that maps object properties, object references, and child objects to XML child elements. Each XmlSimpleElement 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
XmlSimpleElement(XmlSpec xmlSpec, java.lang.String tag, XmlType valueType)
          Constructor for XmlSimpleElement instances.
 
Method Summary
 void addRestrictionValue(java.lang.String restrictionValue)
          Add a text string to the set of acceptable values.
 java.util.Set<java.lang.String> getRestrictionValues()
          Get the list of restricted-to values.
 void setEnumValues(java.util.EnumSet<?> enumValues)
          Set the enumeration of restricted-to values.
 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

XmlSimpleElement

public XmlSimpleElement(XmlSpec xmlSpec,
                        java.lang.String tag,
                        XmlType valueType)
Constructor for XmlSimpleElement instances.

Parameters:
xmlSpec - The parent XML specification.
tag - The XML Node name.
valueType - The XSD value type, e.g. "xs:string"
Method Detail

getRestrictionValues

public java.util.Set<java.lang.String> getRestrictionValues()
Get the list of restricted-to values.

Returns:
An unindexed collection of String instances..

addRestrictionValue

public void addRestrictionValue(java.lang.String restrictionValue)
Add a text string to the set of acceptable values.

Parameters:
restrictionValue -

setEnumValues

public void setEnumValues(java.util.EnumSet<?> enumValues)
Set the enumeration of restricted-to values.

Parameters:
enumValues - The intended enumeration of restricted-to values. Null if not restricted.

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.