net.charlesames.utility.entity
Class XmlSpec

java.lang.Object
  extended by net.charlesames.utility.entity.XmlSpec

public class XmlSpec
extends java.lang.Object

Each subclass of WriteableEntity has a static XmlSpec instance that explains how data should be either saved to an XML data element or recovered from an XML data element. The XmlSpec class contains two component collections: A collection of XmlAttribute instances and a separate collection of XmlElement instances. XmlAttributes map object properties to XML attributes. XmlAttributes map object references to XML child elements.

Author:
Charles Ames

Constructor Summary
XmlSpec(java.lang.Class<? extends WriteableEntity> entityClass, java.lang.String tag, java.lang.String description)
          Constructor for XmlSpec instances.
 
Method Summary
 void addAttribute(XmlAttribute attribute)
          Add a new XmlAttribute instance to the specification.
 void addElement(XmlElement element)
          Add a new XmlElement instance to the specification.
 void appendTypeToElement(org.w3c.dom.Element xsdElement)
          Append a type attribute to an XSD element and create the type declaration, if necessary.
 org.w3c.dom.Element createComplexTypeElement(org.w3c.dom.Element parent, java.lang.String description)
          Create complex type element for this specification.
 org.w3c.dom.Document createSchemaDocument()
          Create an XML schema document
 org.w3c.dom.Element createTypeDefinition(org.w3c.dom.Document document)
          Create an explicit complex type definition for this specification.
 XmlAttribute getAttribute(java.lang.String tag)
          Get the XmlAttribute instance with the indicated NodeName.
 java.util.List<XmlAttribute> getAttributes()
          Get all attributes.
 java.util.SortedMap<java.lang.String,XmlAttribute> getAttributesByTag()
          Get all attributes.
 XmlSpec getBaseXmlSpec()
          Get the base XmlSpec instance, if any.
 XmlContent getContent()
          Get the XmlContent instance.
 XmlElement getElement(java.lang.String tag)
          Get the XmlElement instance with the indicated Tag.
 java.util.List<XmlElement> getElements()
          Get all elements.
 java.util.SortedMap<java.lang.String,XmlElement> getElementsByTag()
          Get all elements in Tag order.
 java.lang.Class<? extends WriteableEntity> getEntityClass()
          Get the entity class.
 java.lang.String getNoNamespaceSchemaLocation()
          Get the no-namespace XML schema location.
 java.lang.String getTag()
          Get the XML tag associated with this specification.
 java.lang.String getTargetNamespace()
          Get the target namespace for the XML schema.
 java.lang.String getTypeName()
          Get the type name used for explicit complexType definitions.
 boolean isUsed()
          Check if this XmlSpec has been used in an XML schema.
 void removeAttribute(java.lang.String tag)
          Remove the XmlAttribute instance with the indicated NodeName.
 void removeElement(java.lang.String tag)
          Remove the XmlElement instance with the indicated NodeName.
 void setBaseXmlSpec(XmlSpec baseXmlSpec)
          Set the base XmlSpec instance.
 void setContent(XmlContent content)
          Set the XmlContent instance.
 void setNoNamespaceSchemaLocation(java.lang.String noNamespaceSchemaLocation)
          Set the no-namespace XML schema location.
 void setTargetNamespace(java.lang.String targetNamespace)
          Set the target namespace for the XML schema.
 void setTypeName(java.lang.String typeName)
          Set the type name used for explicit complexType definitions.
 void setUsed(boolean used)
          Indicate if this XmlSpec has been used in an XML schema.
 void validateTag(WriteableEntity entity, org.w3c.dom.Element element)
          Verify that the Tag name of a WriteableEntity is consistent with the node name of an XML Element.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlSpec

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

Parameters:
entityClass - The entity class.
description - Text description for the XSD element.
tag - The XML tag.
Method Detail

getTypeName

public java.lang.String getTypeName()
Get the type name used for explicit complexType definitions.

Returns:
The assigned type name used for explicit complexType definitions. Null if an explicit definition is not required.

setTypeName

public void setTypeName(java.lang.String typeName)
Set the type name used for explicit complexType definitions. This property must be provided if a specification is multiply used.

Parameters:
typeName - The type name intended to be used used for explicit complexType definitions.

getBaseXmlSpec

public XmlSpec getBaseXmlSpec()
Get the base XmlSpec instance, if any.

Returns:
The base XmlSpec instance. Null if no base spec.

setBaseXmlSpec

public void setBaseXmlSpec(XmlSpec baseXmlSpec)
Set the base XmlSpec instance.

Parameters:
baseXmlSpec -

getNoNamespaceSchemaLocation

public java.lang.String getNoNamespaceSchemaLocation()
Get the no-namespace XML schema location.

Returns:
The no-namespace XML schema location.

setNoNamespaceSchemaLocation

public void setNoNamespaceSchemaLocation(java.lang.String noNamespaceSchemaLocation)
Set the no-namespace XML schema location.

Parameters:
noNamespaceSchemaLocation - The intended no-namespace XML schema location.

getTargetNamespace

public java.lang.String getTargetNamespace()
Get the target namespace for the XML schema.

Returns:
The assigned target namespace for the XML schema.

setTargetNamespace

public void setTargetNamespace(java.lang.String targetNamespace)
Set the target namespace for the XML schema.

Parameters:
targetNamespace - The intended target namespace for the XML schema.

getEntityClass

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

Returns:
The entity class.

getAttributesByTag

public java.util.SortedMap<java.lang.String,XmlAttribute> getAttributesByTag()
Get all attributes.

Returns:
A collection of XmlAttribute instances, indexed by attribute NodeName.

getTag

public java.lang.String getTag()
Get the XML tag associated with this specification.

Returns:
The XML tag associated with this specification.
Throws:
NoSuchObjectException - when the tag is undefined.

getContent

public XmlContent getContent()
Get the XmlContent instance.

Returns:
The assigned XmlContent instance. Null if undefined.

setContent

public void setContent(XmlContent content)
Set the XmlContent instance.

Parameters:
content - The intended XmlContent instance.
Throws:
ObjectAlreadyExistsException - when this XmlSpec already has a XmlContent.
ObjectAlreadyExistsException - when this XmlSpec already has one or more child XmlElement instances.

getAttributes

public java.util.List<XmlAttribute> getAttributes()
Get all attributes.

Returns:
A collection of XmlAttribute instances, presented in output order.

addAttribute

public void addAttribute(XmlAttribute attribute)
Add a new XmlAttribute instance to the specification.

Parameters:
attribute - The new XmlAttribute.
Throws:
java.lang.IllegalArgumentException - when an attribute with the same NodeName is already present.

getAttribute

public XmlAttribute getAttribute(java.lang.String tag)
Get the XmlAttribute instance with the indicated NodeName.

Parameters:
tag - The indicated NodeName.
Returns:
The XmlAttribute instance with the indicated NodeName.

removeAttribute

public void removeAttribute(java.lang.String tag)
Remove the XmlAttribute instance with the indicated NodeName.

Parameters:
tag - The indicated NodeName.

getElementsByTag

public java.util.SortedMap<java.lang.String,XmlElement> getElementsByTag()
Get all elements in Tag order.

Returns:
A collection of XmlElement instances, indexed by Tag.

getElements

public java.util.List<XmlElement> getElements()
Get all elements.

Returns:
A collection of XmlElement instances, presented in output order.

addElement

public void addElement(XmlElement element)
Add a new XmlElement instance to the specification.

Parameters:
element - The new XmlElement.
Throws:
java.lang.IllegalArgumentException - when an element with the same Tag is already present.

removeElement

public void removeElement(java.lang.String tag)
Remove the XmlElement instance with the indicated NodeName.

Parameters:
tag - The indicated NodeName.

getElement

public XmlElement getElement(java.lang.String tag)
Get the XmlElement instance with the indicated Tag.

Parameters:
tag - The indicated Tag.
Returns:
The XmlElement instance with the indicated Tag.

validateTag

public void validateTag(WriteableEntity entity,
                        org.w3c.dom.Element element)
Verify that the Tag name of a WriteableEntity is consistent with the node name of an XML Element.

Parameters:
entity - A WriteableEntity instance.
element - An XML Element instance.

isUsed

public boolean isUsed()
Check if this XmlSpec has been used in an XML schema.

Returns:
True if this XmlSpec has been used in an XML schema; false otherwise.

setUsed

public void setUsed(boolean used)
Indicate if this XmlSpec has been used in an XML schema.

Parameters:
used - True if this XmlSpec has been used in an XML schema; false otherwise.

appendTypeToElement

public void appendTypeToElement(org.w3c.dom.Element xsdElement)
Append a type attribute to an XSD element and create the type declaration, if necessary.

Parameters:
xsdElement - The XSD element.

createTypeDefinition

public org.w3c.dom.Element createTypeDefinition(org.w3c.dom.Document document)
Create an explicit complex type definition for this specification.

Parameters:
document - A Document instance.
Returns:
The XML element defining the complex type.

createComplexTypeElement

public org.w3c.dom.Element createComplexTypeElement(org.w3c.dom.Element parent,
                                                    java.lang.String description)
Create complex type element for this specification.

Parameters:
parent - The parent element, which should be Xsd.Tags.ELEMENT for inline complex types and Xsd.Tags.SCHEMA for explicit complex type definitions.
description - Text description for the XSD element.
Returns:
The XML element describing the complex type.

createSchemaDocument

public org.w3c.dom.Document createSchemaDocument()
Create an XML schema document

Returns:
An XML document containing the schema generated from this specification