net.sourceforge.nite.nom.nomwrite.impl
Class NOMWriteElement

java.lang.Object
  extended by net.sourceforge.nite.nom.nomwrite.impl.NOMWriteElement
All Implemented Interfaces:
NOMElement
Direct Known Subclasses:
NOMReadElement, NOMWriteAnnotation, NOMWriteObject, NOMWriteResourceElement, NOMWriteTypeElement

public abstract class NOMWriteElement
extends java.lang.Object
implements NOMElement

This abstract class is extended by the three different types of element in a NOM Corpus: Annotations, Objects (part of an object set) and TypeElements (part of a type hierarchy).

Author:
jonathan

Nested Class Summary
 class NOMWriteElement.SharedElement
          This inner class provides some utility functions for shared NOM users
 class NOMWriteElement.XMLComment
           
 
Nested classes/interfaces inherited from interface net.sourceforge.nite.nom.nomwrite.NOMElement
NOMElement.SharedEl
 
Field Summary
 
Fields inherited from interface net.sourceforge.nite.nom.nomwrite.NOMElement
FEATURAL_LAYER, IMPLICIT_ORDER, STRUCTURAL_LAYER, TEMPORAL_ORDER, TIME_ALIGNED_LAYER, UNORDERED, UNTIMED
 
Method Summary
 void addAfterSibling(NOMElement sibling)
          add the element as a sibling of the given element.
 void addAttribute(NOMAttribute attribute)
          add an attribute to the element
 void addBeforeSibling(NOMElement sibling)
          add the element as a sibling of the given element.
 void addChild(NOMElement child)
          adds a child to this element.
 void addChildAboveChildren(NOMElement newchild, java.util.List old_children)
          adds the NOMElement newchild in place of the given child list, making the current children chilren of the newly added node.
 void addChildAfter(NOMElement oldchild, NOMElement newchild)
          adds the NOMElement newchild immediately after the given existing child, or reports an exception if the child cannot be found
 void addChildBefore(NOMElement oldchild, NOMElement newchild)
          adds the NOMElement newchild immediately before the given existing child, or reports an exception if the child cannot be found
 void addExternalPointer(java.lang.String role, java.lang.String value)
          Set the href value of the external pointer from this element.
 void addFirstChild(NOMElement child)
          adds the NOMElement as the first child
 void addLastChild(NOMElement child)
          adds the NOMElement as the last child
 void addPointer(NOMPointer pointer)
          add a pointer to the element
 void addToCorpus()
          add an element to the corpus with no information about location.
 void appendText(java.lang.String chars)
          appends to the textual content of an element.
 void deleteChild(NOMElement child)
          Delete an element.
 java.lang.String endElementString()
          Used in serialization - return a string containing the XML for the end of this element.
 NOMElement findAncestorInLayer(NLayer layer)
           
 NOMElement findAncestorNamed(java.lang.String name)
           
 java.util.List findAncestorsInFile()
           
 java.util.Set findAncestorsInLayer(NLayer layer)
           
 java.util.Set findAncestorsNamed(java.lang.String name)
           
 NOMElement findCommonAncestorInFile(NOMElement other)
           
 java.util.List findDescendantsInLayer(NLayer layer)
           
 java.util.List findDescendantsNamed(java.lang.String name)
           
 NAgent getAgent()
          Returns the agent responsible for the element (or null if it's not in an agent coding).
 java.lang.String getAgentName()
          returns the name of the agent responsible for the element.
 NOMAttribute getAttribute(java.lang.String attribute_name)
          returns the named attribute if it exists
 java.lang.Comparable getAttributeComparableValue(java.lang.String name)
          Returns the value of an attribute specified by his name as Comparable.
 java.util.List getAttributes()
          returns a List of NOMAttributes
 int getChildOrder()
          specifies whether the children are temporally ordered, implicitly ordered or unordered by returning one of UNORDERED, IMPLICIT_ORDER or TEMPORAL_ORDER
 java.util.List getChildren()
          returns a List of NOMElements: the children of this element (not including comment elements)
 java.util.List getChildrenWithInterleavedComments()
          This version of getChildren includes any comments that are present in the correct order within the child stream.
 java.lang.String getColour()
          returns the "colour" of the element: we use 'colour' in an NXT-specific way: it's precisely the filename the element will be serailized into, without its the '.xml' extension: thus it comprises observation name; '.'; the agent name followed by '.' (if an agent coding); the coding name.
 java.lang.String getComment()
          returns the contents of the reserved comment String (or null if not set)
 NOMCorpus getCorpus()
          Simply return the Corpus that this element is a part of
 double getEndTime()
          Get the end time of this element.
 java.lang.String getExternalPointerValue()
          returns the value of any external pointer from this element.
 java.lang.String getGVM()
          returns the Graphical Visual Markup string for the element
 java.lang.String getID()
          returns the ID of the element
 java.lang.String getIDLink()
          returns a string containing a Link to this element (without the filename)
 java.lang.String getKeyStroke()
          returns the keystroke associated with this element (as a string)
 NLayer getLayer()
          Returns the metadata layer to which this element belongs.
 java.lang.String getLink()
          returns a string containing a full Link to this element including filename
 NElement getMetadataElement()
          Returns the metadata element for this element.
 java.lang.String getName()
          returns the name of the element
 NOMElement getNextElement()
          returns the element following this one in the corpus if it were to be serialized
 NOMElement getNextSibling()
          returns this element's following sibling of the same colour
 java.util.List getNiteChildren()
          returns a List of nite_children - these should not be of interest once the NOM is fully loaded.
 java.lang.String getObservation()
          returns the name of the observation to which the element belongs
 NOMElement getParentInFile()
          returns the NOMElement belonging to the same colour (i.e.
 java.util.List getParents()
          returns a List of NOMElements
 java.util.List getPointers()
          returns a List of NOMPointers
 java.util.List getPointersTo()
          returns a List of NOMPointers that point to this element
 NOMPointer getPointerWithRole(java.lang.String rolename)
          returns the first NOMPointer which has a matching role
 NOMElement getPreviousSibling()
          returns this element's previous sibling of the same colour
 int getRecursiveDepth()
          get the actual recursive depth of this element in its recursive layer where 0 means no parents in this layer; 1 means one etc.
 int getRecursiveHeight()
          get the actual recursive height of this element in its recursive layer where 0 means no children in this layer; 1 means kids to a depth of 1 etc.
 NOMElement.SharedEl getShared()
          return a shared view of this element which simply provides utility functions for editing the element without thinking about locking and unlocking the corpus.
 double getStartTime()
          Get the start time of this element.
 java.lang.String getText()
          gets the textual content of an element.
 int getTimeType()
          returns the integer TIME_ALIGNED, STRUCTURAL or FEATURAL: the type of the element as far as timing is concerned.
 java.lang.String getXLink()
          Returns the xlink:href to the element this element is stored.
 boolean hasNextElement()
          returns true if there is an element following this one in the corpus if it were to be serialized
 void inheritTimes()
          Inherit start and end times from timed child nodes.
 void insertParent(NOMElement newparent, NOMElement oldparent)
          Insert an new parent node, making me and my siblings children of our the new parent and making our current parent the parent of the new parent
 boolean isComment()
          returns true if this element is a comment
 boolean isLeaf()
          returns true if this element is a leaf (according to the metadata)
 boolean isStreamElement()
          returns true if this is a "stream" element - i.e.
 java.lang.Boolean isStreamElementOld()
          returns true if this is a "stream" element - i.e.
 void removeAttribute(java.lang.String name)
          Remove an attribute completely from an element
 void removeChild(NOMElement child)
          Remove a nite:child from an element without actually deleting the element referred to.
 void removeParentAndAdjust(NOMElement par)
          Remove the parent node, making me and my siblings children of our grandparent.
 void removePointer(NOMPointer pointer)
          remove a pointer from the element
 void setComment(java.lang.String comment)
          sets the comment attribute for this element
 void setDoubleAttribute(java.lang.String name, java.lang.Double value)
          Set the value of a named Double attribute; Create the attribute if it doesn't exist.
 void setEndTime(double et)
          Set the end time of this element.
 void setGVM(java.lang.String name)
          sets the GVM string for this element
 void setKeyStroke(java.lang.String name)
          sets the keystroke string associated with this element
 void setName(java.lang.String name)
          sets the name of the element - not commonly used!
 void setStartTime(double st)
          Set the start time of this element.
 void setStreamElement(boolean stream)
          Set the "stream"ness of the element - a stream element is one which is purely there as a container for other elements for the purposes of serialization.
 void setStringAttribute(java.lang.String name, java.lang.String value)
          Set the value of a named string attribute; create the attribute if it doesn't exist.
 void setText(java.lang.String chars)
          sets the textual content of an element.
 java.lang.String startElementString()
          Used in serialization - return a string containing the XML for the start of this element including attributes.
 void updateTimes()
          Called when a change to the start or end time of a timed unit by the user requires propagation
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

setStringAttribute

public void setStringAttribute(java.lang.String name,
                               java.lang.String value)
                        throws NOMException
Set the value of a named string attribute; create the attribute if it doesn't exist.

Specified by:
setStringAttribute in interface NOMElement
Throws:
NOMException

setDoubleAttribute

public void setDoubleAttribute(java.lang.String name,
                               java.lang.Double value)
                        throws NOMException
Set the value of a named Double attribute; Create the attribute if it doesn't exist.

Specified by:
setDoubleAttribute in interface NOMElement
Throws:
NOMException

removeAttribute

public void removeAttribute(java.lang.String name)
                     throws NOMException
Remove an attribute completely from an element

Specified by:
removeAttribute in interface NOMElement
Throws:
NOMException

getPointers

public java.util.List getPointers()
returns a List of NOMPointers

Specified by:
getPointers in interface NOMElement

getPointersTo

public java.util.List getPointersTo()
returns a List of NOMPointers that point to this element

Specified by:
getPointersTo in interface NOMElement

getPointerWithRole

public NOMPointer getPointerWithRole(java.lang.String rolename)
returns the first NOMPointer which has a matching role

Specified by:
getPointerWithRole in interface NOMElement

getExternalPointerValue

public java.lang.String getExternalPointerValue()
returns the value of any external pointer from this element.

Specified by:
getExternalPointerValue in interface NOMElement

addPointer

public void addPointer(NOMPointer pointer)
                throws NOMException
add a pointer to the element

Specified by:
addPointer in interface NOMElement
Throws:
NOMException

removePointer

public void removePointer(NOMPointer pointer)
                   throws NOMException
remove a pointer from the element

Specified by:
removePointer in interface NOMElement
Throws:
NOMException

addFirstChild

public void addFirstChild(NOMElement child)
                   throws NOMException
adds the NOMElement as the first child

Specified by:
addFirstChild in interface NOMElement
Throws:
NOMException

addLastChild

public void addLastChild(NOMElement child)
                  throws NOMException
adds the NOMElement as the last child

Specified by:
addLastChild in interface NOMElement
Throws:
NOMException

addChildBefore

public void addChildBefore(NOMElement oldchild,
                           NOMElement newchild)
                    throws NOMException
adds the NOMElement newchild immediately before the given existing child, or reports an exception if the child cannot be found

Specified by:
addChildBefore in interface NOMElement
Throws:
NOMException

addChildAfter

public void addChildAfter(NOMElement oldchild,
                          NOMElement newchild)
                   throws NOMException
adds the NOMElement newchild immediately after the given existing child, or reports an exception if the child cannot be found

Specified by:
addChildAfter in interface NOMElement
Throws:
NOMException

addChildAboveChildren

public void addChildAboveChildren(NOMElement newchild,
                                  java.util.List old_children)
                           throws NOMException
adds the NOMElement newchild in place of the given child list, making the current children chilren of the newly added node.

Specified by:
addChildAboveChildren in interface NOMElement
Throws:
NOMException

insertParent

public void insertParent(NOMElement newparent,
                         NOMElement oldparent)
                  throws NOMException
Insert an new parent node, making me and my siblings children of our the new parent and making our current parent the parent of the new parent

Specified by:
insertParent in interface NOMElement
Throws:
NOMException

removeParentAndAdjust

public void removeParentAndAdjust(NOMElement par)
                           throws NOMException
Remove the parent node, making me and my siblings children of our grandparent. Possibly need to check validity...

Specified by:
removeParentAndAdjust in interface NOMElement
Throws:
NOMException

removeChild

public void removeChild(NOMElement child)
                 throws NOMException
Remove a nite:child from an element without actually deleting the element referred to. Throw an error if we're trying to remove the child from its serialized parent.

Specified by:
removeChild in interface NOMElement
Throws:
NOMException

deleteChild

public void deleteChild(NOMElement child)
                 throws NOMException
Delete an element. Remove the child from all its parents.

Specified by:
deleteChild in interface NOMElement
Throws:
NOMException

addChild

public void addChild(NOMElement child)
              throws NOMException
adds a child to this element. Since no order is specified, add the child to the end of the list of children

Specified by:
addChild in interface NOMElement
Throws:
NOMException

addToCorpus

public void addToCorpus()
                 throws NOMException
add an element to the corpus with no information about location. This should only be used with elements that are in the top level of a coding. If the element is in a timed layer and has start and end times, the placement of the addition in the "stream" is derived from those. Otherwise the element is added at the end of the stream.

Specified by:
addToCorpus in interface NOMElement
Throws:
NOMException

addBeforeSibling

public void addBeforeSibling(NOMElement sibling)
                      throws NOMException
add the element as a sibling of the given element. Of course the siblings must be in the same layer and the ordering must not violate any of the precedence constraints

Specified by:
addBeforeSibling in interface NOMElement
Throws:
NOMException

addAfterSibling

public void addAfterSibling(NOMElement sibling)
                     throws NOMException
add the element as a sibling of the given element. Of course the siblings must be in the same layer and the ordering must not violate any of the precedence constraints

Specified by:
addAfterSibling in interface NOMElement
Throws:
NOMException

getCorpus

public NOMCorpus getCorpus()
Simply return the Corpus that this element is a part of

Specified by:
getCorpus in interface NOMElement

getName

public java.lang.String getName()
returns the name of the element

Specified by:
getName in interface NOMElement

getID

public java.lang.String getID()
returns the ID of the element

Specified by:
getID in interface NOMElement

getGVM

public java.lang.String getGVM()
returns the Graphical Visual Markup string for the element

Specified by:
getGVM in interface NOMElement

getKeyStroke

public java.lang.String getKeyStroke()
returns the keystroke associated with this element (as a string)

Specified by:
getKeyStroke in interface NOMElement

getComment

public java.lang.String getComment()
returns the contents of the reserved comment String (or null if not set)

Specified by:
getComment in interface NOMElement

getAgentName

public java.lang.String getAgentName()
returns the name of the agent responsible for the element. Note that this is either the value of the attribute defined under "reserved-attributes" in the metadata, or (more commonly) it's derived from the colour of the element (so you don't need to explicitly name the agent for anything that's in an agent-coding)

Specified by:
getAgentName in interface NOMElement

getAgent

public NAgent getAgent()
Returns the agent responsible for the element (or null if it's not in an agent coding).

Specified by:
getAgent in interface NOMElement

getColour

public java.lang.String getColour()
returns the "colour" of the element: we use 'colour' in an NXT-specific way: it's precisely the filename the element will be serailized into, without its the '.xml' extension: thus it comprises observation name; '.'; the agent name followed by '.' (if an agent coding); the coding name.

Specified by:
getColour in interface NOMElement

getObservation

public java.lang.String getObservation()
returns the name of the observation to which the element belongs

Specified by:
getObservation in interface NOMElement

getChildren

public java.util.List getChildren()
returns a List of NOMElements: the children of this element (not including comment elements)

Specified by:
getChildren in interface NOMElement

getChildrenWithInterleavedComments

public java.util.List getChildrenWithInterleavedComments()
This version of getChildren includes any comments that are present in the correct order within the child stream. NOTE: Order of comments is not always respected with respect to out-of-file links, but will always be maintained for in-file children.

Specified by:
getChildrenWithInterleavedComments in interface NOMElement

isLeaf

public boolean isLeaf()
returns true if this element is a leaf (according to the metadata)


isComment

public boolean isComment()
returns true if this element is a comment

Specified by:
isComment in interface NOMElement

setName

public void setName(java.lang.String name)
sets the name of the element - not commonly used!

Specified by:
setName in interface NOMElement

setGVM

public void setGVM(java.lang.String name)
sets the GVM string for this element

Specified by:
setGVM in interface NOMElement

setKeyStroke

public void setKeyStroke(java.lang.String name)
sets the keystroke string associated with this element

Specified by:
setKeyStroke in interface NOMElement

setComment

public void setComment(java.lang.String comment)
sets the comment attribute for this element

Specified by:
setComment in interface NOMElement

setText

public void setText(java.lang.String chars)
             throws NOMException
sets the textual content of an element.

Specified by:
setText in interface NOMElement
Throws:
NOMException

appendText

public void appendText(java.lang.String chars)
                throws NOMException
appends to the textual content of an element.

Specified by:
appendText in interface NOMElement
Throws:
NOMException

getText

public java.lang.String getText()
gets the textual content of an element.

Specified by:
getText in interface NOMElement

getParents

public java.util.List getParents()
returns a List of NOMElements

Specified by:
getParents in interface NOMElement

findAncestorNamed

public NOMElement findAncestorNamed(java.lang.String name)
Specified by:
findAncestorNamed in interface NOMElement

findAncestorsInFile

public java.util.List findAncestorsInFile()
Specified by:
findAncestorsInFile in interface NOMElement

findAncestorInLayer

public NOMElement findAncestorInLayer(NLayer layer)
Specified by:
findAncestorInLayer in interface NOMElement

findAncestorsNamed

public java.util.Set findAncestorsNamed(java.lang.String name)
Specified by:
findAncestorsNamed in interface NOMElement

findCommonAncestorInFile

public NOMElement findCommonAncestorInFile(NOMElement other)
Specified by:
findCommonAncestorInFile in interface NOMElement

findAncestorsInLayer

public java.util.Set findAncestorsInLayer(NLayer layer)
Specified by:
findAncestorsInLayer in interface NOMElement

findDescendantsInLayer

public java.util.List findDescendantsInLayer(NLayer layer)
Specified by:
findDescendantsInLayer in interface NOMElement

findDescendantsNamed

public java.util.List findDescendantsNamed(java.lang.String name)
Specified by:
findDescendantsNamed in interface NOMElement

getParentInFile

public NOMElement getParentInFile()
returns the NOMElement belonging to the same colour (i.e. that will be serialized into the same file).

Specified by:
getParentInFile in interface NOMElement

getAttributes

public java.util.List getAttributes()
returns a List of NOMAttributes

Specified by:
getAttributes in interface NOMElement

getAttribute

public NOMAttribute getAttribute(java.lang.String attribute_name)
returns the named attribute if it exists

Specified by:
getAttribute in interface NOMElement

addAttribute

public void addAttribute(NOMAttribute attribute)
                  throws NOMException
add an attribute to the element

Specified by:
addAttribute in interface NOMElement
Throws:
NOMException

getNiteChildren

public java.util.List getNiteChildren()
returns a List of nite_children - these should not be of interest once the NOM is fully loaded.


getChildOrder

public int getChildOrder()
specifies whether the children are temporally ordered, implicitly ordered or unordered by returning one of UNORDERED, IMPLICIT_ORDER or TEMPORAL_ORDER

Specified by:
getChildOrder in interface NOMElement

isStreamElementOld

public java.lang.Boolean isStreamElementOld()
returns true if this is a "stream" element - i.e. one which is purely there as a container for other elements for the purposes of serialization.


isStreamElement

public boolean isStreamElement()
returns true if this is a "stream" element - i.e. one which is purely there as a container for other elements for the purposes of serialization.

Specified by:
isStreamElement in interface NOMElement

setStreamElement

public void setStreamElement(boolean stream)
Set the "stream"ness of the element - a stream element is one which is purely there as a container for other elements for the purposes of serialization.

Specified by:
setStreamElement in interface NOMElement

hasNextElement

public boolean hasNextElement()
returns true if there is an element following this one in the corpus if it were to be serialized

Specified by:
hasNextElement in interface NOMElement

getNextElement

public NOMElement getNextElement()
returns the element following this one in the corpus if it were to be serialized

Specified by:
getNextElement in interface NOMElement

getStartTime

public double getStartTime()
Get the start time of this element. No distinction is made here between real and inherited times. If this is not a timed element or has not been assigned a start time, return NOMElement.UNTIMED.

Specified by:
getStartTime in interface NOMElement

getEndTime

public double getEndTime()
Get the end time of this element. No distinction is made here between real and inherited times. If this is not a timed element or has not been assigned an end time, return NOMElement.UNTIMED.

Specified by:
getEndTime in interface NOMElement

setStartTime

public void setStartTime(double st)
                  throws NOMException
Set the start time of this element. Only elements in a timed layer can have their start and end times set directly; all structural times are strictly inherited.

Specified by:
setStartTime in interface NOMElement
Throws:
NOMException

setEndTime

public void setEndTime(double et)
                throws NOMException
Set the end time of this element. Only elements in a timed layer can have their start and end times set directly; all structural times are strictly inherited.

Specified by:
setEndTime in interface NOMElement
Throws:
NOMException

getTimeType

public int getTimeType()
returns the integer TIME_ALIGNED, STRUCTURAL or FEATURAL: the type of the element as far as timing is concerned.

Specified by:
getTimeType in interface NOMElement

inheritTimes

public void inheritTimes()
Inherit start and end times from timed child nodes.


updateTimes

public void updateTimes()
Called when a change to the start or end time of a timed unit by the user requires propagation


getLayer

public NLayer getLayer()
                throws NOMException
Returns the metadata layer to which this element belongs. Note that this is only non-null where the element is an instance of NOMWriteAnnotation (i.e. not in an object set or ontology). Used when adding elements and in serialization

Specified by:
getLayer in interface NOMElement
Throws:
NOMException

getMetadataElement

public NElement getMetadataElement()
Returns the metadata element for this element.

Specified by:
getMetadataElement in interface NOMElement

startElementString

public java.lang.String startElementString()
Used in serialization - return a string containing the XML for the start of this element including attributes.


endElementString

public java.lang.String endElementString()
Used in serialization - return a string containing the XML for the end of this element.


getLink

public java.lang.String getLink()
returns a string containing a full Link to this element including filename

Specified by:
getLink in interface NOMElement

getIDLink

public java.lang.String getIDLink()
returns a string containing a Link to this element (without the filename)


getPreviousSibling

public NOMElement getPreviousSibling()
returns this element's previous sibling of the same colour

Specified by:
getPreviousSibling in interface NOMElement

getNextSibling

public NOMElement getNextSibling()
returns this element's following sibling of the same colour

Specified by:
getNextSibling in interface NOMElement

getRecursiveDepth

public int getRecursiveDepth()
get the actual recursive depth of this element in its recursive layer where 0 means no parents in this layer; 1 means one etc.

Specified by:
getRecursiveDepth in interface NOMElement

addExternalPointer

public void addExternalPointer(java.lang.String role,
                               java.lang.String value)
                        throws NOMException
Set the href value of the external pointer from this element. Only allowed in elements oin layers of type EXTERNAL_POINTER_LAYER

Specified by:
addExternalPointer in interface NOMElement
Throws:
NOMException

getRecursiveHeight

public int getRecursiveHeight()
get the actual recursive height of this element in its recursive layer where 0 means no children in this layer; 1 means kids to a depth of 1 etc.

Specified by:
getRecursiveHeight in interface NOMElement

getAttributeComparableValue

public java.lang.Comparable getAttributeComparableValue(java.lang.String name)
Returns the value of an attribute specified by his name as Comparable. The interface Comparable is usefull to compare values. Notice that in NOM an attribute value is primary a String and if possible interpreted as Double. Because both, String and Double, implement Comparable attribute values could be tried to parse as Double when setting and not when getting it. This will speed up reading, like i.e. needed for searching.

Specified by:
getAttributeComparableValue in interface NOMElement
Parameters:
name - the name of the attribute
Returns:
the value of an attribute as Comparable

getXLink

public java.lang.String getXLink()
Returns the xlink:href to the element this element is stored. The xlink:href could be something like "file.xml#id".

Specified by:
getXLink in interface NOMElement
Returns:
the xlink:href to the element this element is stored

getShared

public NOMElement.SharedEl getShared()
return a shared view of this element which simply provides utility functions for editing the element without thinking about locking and unlocking the corpus.

Specified by:
getShared in interface NOMElement