net.charlesames.utility.entity
Class XmlAttribute

java.lang.Object
  extended by net.charlesames.utility.entity.XmlNode
      extended by net.charlesames.utility.entity.XmlAttribute

public abstract class XmlAttribute
extends XmlNode

An XmlAttribute instance is a component of an XmlSpec that maps object properties to XML attributes. Each XmlAttribute instance is created as an anonymous class which defines two particular methods. getData(WriteableEntity, org.w3c.dom.Node) implements the code which reads data from an XML attribute into a property of a WriteableEntity instance. XmlNode.putData(WriteableEntity, org.w3c.dom.Element) implements the code which writes data from a WriteableEntity property into an XML attribute. Here is an example:

   xmlSpec.addAttribute(new XmlAttribute("version") {
      @Override
      public void putData(WriteableEntity entity, Element element) {
         Form form = (Form) entity;
         String version = form.getVersion();
         element.setAttribute(getName(), version);
      }
      @Override
         public void getData(WriteableEntity entity, Node attribute) {
         Form form = (Form) entity;
         String version = attribute.getNodeValue();
         form.setVersion(version);
         }
      });

Author:
Charles Ames

Constructor Summary
XmlAttribute(XmlSpec xmlSpec, java.lang.String tag, XmlType valueType, java.lang.String valueUse)
          Constructor for XmlAttribute instances.
 
Method Summary
 void addRestrictionValue(java.lang.String restrictionValue)
          Add a text string to the set of acceptable values.
abstract  void getData(WriteableEntity entity, org.w3c.dom.Node attribute)
          Reads data from an XML attribute Node into an WriteableEntity instance.
 java.util.Set<java.lang.String> getRestrictionValues()
          Get the list of restricted-to values.
 XmlType getValueType()
          Get the value for the type attribute.
 java.lang.String getValueUse()
          Get the value for the use attribute.
 java.lang.String getXsdTag()
          Get the tag identifying this node in an XML schema document.
 boolean isIncludedInSchema()
          Check if this node should be visible in the schema.
 void setEnumValues(java.util.EnumSet<?> enumValues)
          Set the enumeration of restricted-to values.
 void setValueUse(java.lang.String valueUse)
          Set the value for the use attribute.
 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.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

XmlAttribute

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

Parameters:
xmlSpec - The XML specification that contains this attribute.
tag - The XML attribute name.
valueType - The XSD value type, e.g. "xs:string"
valueUse - The XSD use attribute, e.g. "optional", "required".
Method Detail

getValueType

public XmlType getValueType()
Get the value for the type attribute.

Returns:
The assigned value for the type attribute.

getValueUse

public java.lang.String getValueUse()
Get the value for the use attribute.

Returns:
The assigned value for the use attribute.

setValueUse

public void setValueUse(java.lang.String valueUse)
Set the value for the use attribute.

Parameters:
valueUse - The intended value for the use attribute.

isIncludedInSchema

public boolean isIncludedInSchema()
Description copied from class: XmlNode
Check if this node should be visible in the schema.

Overrides:
isIncludedInSchema in class XmlNode
Returns:
True if this node should be visible in the schema; false otherwise.

getData

public abstract void getData(WriteableEntity entity,
                             org.w3c.dom.Node attribute)
Reads data from an XML attribute Node into an WriteableEntity instance.

Parameters:
entity - The target WriteableEntity instance.
attribute - The source attribute Node.

getXsdTag

public java.lang.String getXsdTag()
Description copied from class: XmlNode
Get the tag identifying this node in an XML schema document.

Specified by:
getXsdTag in class XmlNode
Returns:
The tag identifying this node in an XML schema document.

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 XmlNode
Parameters:
parent - The parent node.
Returns:
THe newly created node.