net.charlesames.utility.entity
Class WriteableEntity

java.lang.Object
  extended by net.charlesames.utility.common.Disposable
      extended by net.charlesames.utility.entity.Entity
          extended by net.charlesames.utility.entity.WriteableEntity
All Implemented Interfaces:
EntityContainer
Direct Known Subclasses:
EnsembleEntity, ContourFromRational, RationalSegment, ContourFromReal, RealSegment, ScoreEntity

public abstract class WriteableEntity
extends Entity

A WriteableEntity is an Entity whose contents can be saved to or loaded from a file. 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.

Author:
Charles Ames

Method Summary
 boolean check(HtmlBuilder htmlBuilder)
          Check this component for errors and inconsistencies
static void clearXmlSpecs()
          Clear all XML specification instances.
static XmlSpec createXmlSpec(java.lang.Class<? extends WriteableEntity> entityClass, java.lang.String tag, java.lang.String description)
          Create an XML specification for the indicated entity class.
 EntityContainer getContainer()
          Getter for the Container property.
 java.lang.String getTagName()
          Getter for the TagName property.
 void getXmlData(org.w3c.dom.Element element)
          Read data from an XML Element.
 XmlSpec getXmlSpec()
          Get the XML specification for this subclass of WriteableEntity.
static XmlSpec getXmlSpec(java.lang.Class<? extends WriteableEntity> entityClass)
          Get the XmlSpec for the indicated subclass of WriteableEntity.
static void initializeXsd(org.w3c.dom.Document document)
          Initialize XML schema creation.
 boolean isPersistent()
          Getter for the Persistent flag.
 void logError(org.w3c.dom.Node node, java.lang.Exception exception)
          Handle an exception encountered while loading this document.
 void logError(org.w3c.dom.Node node, java.lang.String message)
          Handle an error encountered while loading this document.
 void makeDirty()
          Signal that the document has experienced a change which should be saved to the associated file.
 void putXmlData(org.w3c.dom.Element element)
          Write data to an XML Element.
 void save(java.io.File file)
          Write the content of this entity to the indicated file in XML format.
 boolean setID(int id)
          Setter for the ID property.
 boolean setName(java.lang.String value)
          Setter for the Name property.
 void setPersistent(boolean persistent)
          Setter for the Persistent flag.
 boolean setStatus(Status status)
          Setter for the Status property.
 org.w3c.dom.Element toXmlNode(org.w3c.dom.Node parent)
          Create an XML Element instance and fill it with data.
 
Methods inherited from class net.charlesames.utility.entity.Entity
decrementReferenceCount, dereferenceHandle, dispose, equals, getHandle, getID, getName, getPath, getReferenceCount, getStatus, getText, hasContainer, incrementReferenceCount, isModifiable, methodHasOverride, predecessor, resequenceEntities, setContainer, setModifiable, shiftEntitiesDown, shiftEntityDown, shiftEntityUp, successor, toString, wipe
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getContainer

public EntityContainer getContainer()
Description copied from class: Entity
Getter for the Container property.

Overrides:
getContainer in class Entity
Returns:
The assigned Container value.

isPersistent

public boolean isPersistent()
Getter for the Persistent flag. The Persistent flag controls whether calls to makeDirty() are transmitted to the repository container. Default is true;

Returns:
The assigned Persistent value.

setPersistent

public void setPersistent(boolean persistent)
Setter for the Persistent flag. The Persistent flag controls whether calls to makeDirty() are transmitted to the repository container. Default is true;

Parameters:
persistent - The intended Persistent value.

makeDirty

public void makeDirty()
Signal that the document has experienced a change which should be saved to the associated file.


setID

public boolean setID(int id)
Description copied from class: Entity
Setter for the ID property.

Overrides:
setID in class Entity
Parameters:
id - The intended ID value.
Returns:
True if an ID change actually happened; false otherwise.

setName

public boolean setName(java.lang.String value)
Description copied from class: Entity
Setter for the Name property.

Overrides:
setName in class Entity
Parameters:
value - The intended Name value.
Returns:
True if a Name change actually happened; false otherwise.

setStatus

public boolean setStatus(Status status)
Description copied from class: Entity
Setter for the Status property.

Overrides:
setStatus in class Entity
Parameters:
status - The intended Status value.
Returns:
True if a Status change actually happened; false otherwise.

getTagName

public final java.lang.String getTagName()
Getter for the TagName property.

Returns:
The TagName value.

toXmlNode

public final org.w3c.dom.Element toXmlNode(org.w3c.dom.Node parent)
Create an XML Element instance and fill it with data.

Parameters:
parent - The parent XML Node to which the new Element will be appended. The class of the parent may be either org.w3c.dom.Element or org.w3c.dom.Document.
Returns:
The newly created Element instance.

getXmlSpec

public XmlSpec getXmlSpec()
Get the XML specification for this subclass of WriteableEntity.

Returns:
The XML specification for this subclass of WriteableEntity.

clearXmlSpecs

public static void clearXmlSpecs()
Clear all XML specification instances.


getXmlSpec

public static XmlSpec getXmlSpec(java.lang.Class<? extends WriteableEntity> entityClass)
Get the XmlSpec for the indicated subclass of WriteableEntity.

Parameters:
entityClass - The indicated entity subclass.
Returns:
The XML specification.
Throws:
NoSuchObjectException - when not found.

initializeXsd

public static void initializeXsd(org.w3c.dom.Document document)
Initialize XML schema creation. Set the Used flag false for all XmlSpec instances.

Parameters:
document - The XML Document which is to receive the schema information.

logError

public void logError(org.w3c.dom.Node node,
                     java.lang.String message)
Handle an error encountered while loading this document.

Parameters:
node - The XML node where this error was detected.
message - A text string describing the error.

logError

public void logError(org.w3c.dom.Node node,
                     java.lang.Exception exception)
Handle an exception encountered while loading this document.

Parameters:
node - The XML node where this error was detected.
exception - The exception describing the error.

putXmlData

public final void putXmlData(org.w3c.dom.Element element)
Write data to an XML Element.

Parameters:
element - The target Element.

getXmlData

public void getXmlData(org.w3c.dom.Element element)
Read data from an XML Element.

Parameters:
element - The source Element.

save

public void save(java.io.File file)
Write the content of this entity to the indicated file in XML format.

Parameters:
file - The indicated file.

check

public boolean check(HtmlBuilder htmlBuilder)
Check this component for errors and inconsistencies

Parameters:
htmlBuilder - Accumulates an HTML formatted record of each error or inconsistency found.
Returns:
False if any errors or inconsistencies are found; true otherwise.

createXmlSpec

public static XmlSpec createXmlSpec(java.lang.Class<? extends WriteableEntity> entityClass,
                                    java.lang.String tag,
                                    java.lang.String description)
Create an XML specification for the indicated entity class.

Parameters:
entityClass - The indicated entity class.
tag - The node name for an XML Element which describes an instance of the entity class.
description - A text description for the XSD element.
Returns:
The newly created XmlSpec instance.
Throws:
java.lang.RuntimeException - when an XmlSpec instance already exists for the indicated entity class.