com.bbn.swede.core.dom
Class TagNode

java.lang.Object
  extended bycom.bbn.swede.core.dom.OASTNode
      extended bycom.bbn.swede.core.dom.TagNode
Direct Known Subclasses:
ClassNode, PropertyNode, Rdf

public abstract class TagNode
extends OASTNode

Common implementation for nodes representing XML tags.

Author:
jlerner

Nested Class Summary
 
Nested classes inherited from class com.bbn.swede.core.dom.OASTNode
OASTNode.NodeCleanupVisitor, OASTNode.NodeInitVisitor
 
Field Summary
 
Fields inherited from class com.bbn.swede.core.dom.OASTNode
_iLength, _iOffset, _nodeParent, _tree, AS_OWL, AS_RDF, AS_RDFS, BASE, COMMENT, DOCTYPE, DOCUMENT, GENERICATTRIBUTE, GENERICPREDICATE, GENERICTHING, LITERAL, NAMESPACE, OWL, OWL_ALLDIFFERENT, OWL_ALLVALUESFROM, OWL_ANNOTATIONPROPERTY, OWL_BACKWARDCOMPATIBLEWITH, OWL_CARDINALITY, OWL_CLASS, OWL_COMPLEMENTOF, OWL_DATARANGE, OWL_DATATYPEPROPERTY, OWL_DEPRECATEDCLASS, OWL_DEPRECATEDPROPERTY, OWL_DIFFERENTFROM, OWL_DISJOINTWITH, OWL_DISTINCTMEMBERS, OWL_EQUIVALENTCLASS, OWL_EQUIVALENTPROPERTY, OWL_FUNCTIONALPROPERTY, OWL_HASVALUE, OWL_IMPORTS, OWL_INCOMPATIBLEWITH, OWL_INTERSECTIONOF, OWL_INVERSEFUNCTIONALPROPERTY, OWL_INVERSEOF, OWL_MAXCARDINALITY, OWL_MINCARDINALITY, OWL_NOTHING, OWL_OBJECTPROPERTY, OWL_ONEOF, OWL_ONPROPERTY, OWL_ONTOLOGY, OWL_ONTOLOGYPROPERTY, OWL_PRIORVERSION, OWL_RESTRICTION, OWL_SAMEAS, OWL_SOMEVALUESFROM, OWL_SYMMETRICPROPERTY, OWL_THING, OWL_TRANSITIVEPROPERTY, OWL_UNIONOF, OWL_VERSIONINFO, PROCESSING_INSTRUCTION, RDF, RDF_ABOUT, RDF_ALT, RDF_BAG, RDF_DATATYPE, RDF_DESCRIPTION, RDF_FIRST, RDF_ID, RDF_LIST, RDF_NODEID, RDF_OBJECT, RDF_PARSETYPE, RDF_PREDICATE, RDF_PROPERTY, RDF_RDF, RDF_RESOURCE, RDF_REST, RDF_SEQ, RDF_STATEMENT, RDF_SUBJECT, RDF_TYPE, RDF_VALUE, RDF_XMLLITERAL, RDFS, RDFS_CLASS, RDFS_COMMENT, RDFS_CONTAINER, RDFS_CONTAINERMEMBERSHIPPROPERTY, RDFS_DATATYPE, RDFS_DOMAIN, RDFS_ISDEFINEDBY, RDFS_LABEL, RDFS_LITERAL, RDFS_MEMBER, RDFS_RANGE, RDFS_RESOURCE, RDFS_SEEALSO, RDFS_SUBCLASSOF, RDFS_SUBPROPERTYOF, S_OWL_URI, S_RDF_URI, S_RDFS_URI, S_XSD_URI, UNPARSEABLE, XML_VERSION
 
Constructor Summary
TagNode()
          Creates a parentless tag node with discrete begin and end tags.
TagNode(boolean bSingleton)
          Creates a parentless tag node.
 
Method Summary
 void addAttribute(String sQName, String sValue)
          Adds an attribute to the tag, after all existing attributes.
 void appendChildAttribute(AttributeNode child)
          Inserts an attribute node as the last attribute child of this node.
 void appendChildTag(TagNode child)
          Inserts a tag node as the last non-attribute child of this node.
 Object clone()
          Creates a deep copy of a node and all nodes below it in the tree.
static TagNode create(String sQName)
          Factory method for creating language tag nodes.
static TagNode create(String sQName, OASTNode parent)
          Factory method for creating tag nodes.
protected  void createRegions()
          Creates regions for the begin and end tags of the node.
protected  void createSingletonRegion()
          Creates a begin region for the node, marking it as a singleton.
 boolean displace(int offset, int length)
          Adjust the node's offset or length to reflect the addition or removal of characters in the file.
protected  OASTNode duplicateType()
          Creates a new OAST node of the same type as this one.
 String generateNodeText()
          Subclasses must implement this method to provide text representing the contents of the node and its children.
 AttributeNode getAttribute(String sQName)
          Retrieves a child attribute with a specified QName.
 AttributeNode[] getAttributes()
          Retrieves all the attributes of this tag.
protected  void initRegions(boolean bSingleton)
          Initializes the simple partitioning of the tag node.
protected  boolean isSingleton()
          Indicates whether this tag node represents a singleton tag.
 void prependChildAttribute(AttributeNode child)
          Inserts an attribute node as the first attribute child of this node.
 void prependChildTag(TagNode child)
          Inserts a tag node as the first non-attribute child of this node.
 void removeAttribute(AttributeNode attribute)
          Removes an attribute from the tag.
 void removeAttribute(String sQName)
          Removes an attribute from the tag.
 void setAttribute(String sQName, String sValue)
          Sets the value of a child attribute of this tag.
protected  void setBeginRegion(int length)
          Sets the begin region of the tag-based node's simple partitioning.
protected  void setEndRegion(int offset)
          Sets the end region of the tag-based node's simple partitioning.
 IRegion[] simplePartitioning()
          Returns a rough partitioning of the node based on the node's tag structure; child nodes are not taken into account.
protected  TagNode splitSingleton()
          Changes the tag from a singleton to discrete begin and end tags.
 
Methods inherited from class com.bbn.swede.core.dom.OASTNode
accept, allowedChildren, appendChild, attach, cleanup, createChild, createChildAttribute, detach, displace, endsBefore, findCommonAncestor, findXmlBase, getChildren, getContainingChild, getDefaultNamespace, getFirstChild, getLastAttribute, getLength, getLevel, getLockObject, getName, getNamespace, getNamespaces, getNextChild, getNodesOfType, getNodesOfType, getNodeType, getOffset, getOWLAbstractSyntaxTree, getOWLDocument, getParent, getPreviousChild, getQName, getQName, getRoot, getUri, getXmlBase, init, insert, match, remove, replace, setLength, setOffset, startsAfter, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TagNode

public TagNode()
Creates a parentless tag node with discrete begin and end tags.


TagNode

public TagNode(boolean bSingleton)
Creates a parentless tag node. The tag will be either a singleton or discrete begin and end tags depending on the parameter passed. A singleton tag node will be split into begin and end tags automatically if a non-attribute child is added to it later.

Parameters:
bSingleton - true to create a singleton tag, false to create discrete begin and end tags.
Method Detail

initRegions

protected void initRegions(boolean bSingleton)
Initializes the simple partitioning of the tag node.

Parameters:
bSingleton - true to partition the tag as a singleton, false to partition it as discrete begin and end tags.

createSingletonRegion

protected void createSingletonRegion()
Creates a begin region for the node, marking it as a singleton. The length of the node will also be set to match the size of the singleton region.


createRegions

protected void createRegions()
Creates regions for the begin and end tags of the node. The length of the node will be set to match the combined size of the regions.


simplePartitioning

public IRegion[] simplePartitioning()
Description copied from class: OASTNode

Returns a rough partitioning of the node based on the node's tag structure; child nodes are not taken into account. Partitioning should be as follows:

Specified by:
simplePartitioning in class OASTNode
Returns:
A rough partitioning of the node.

isSingleton

protected boolean isSingleton()
Indicates whether this tag node represents a singleton tag.

Returns:
true if the tag is a singleton, false if it has begin and end tags.

setBeginRegion

protected void setBeginRegion(int length)
Sets the begin region of the tag-based node's simple partitioning. The offset of the region is based on the node's starting offset as returned by getOffset()

Parameters:
length - The length of the beginning region. This is assumed to be less than or equal to the total length of the node, though this method may be called before the node length has been set.

setEndRegion

protected void setEndRegion(int offset)
Sets the end region of the tag-based node's simple partitioning. The length of the end region is calculated automatically based on the values returned by getOffset() and getLength(). A middle region will be created automatically if there is a gap between the beginning and end regions.

Parameters:
offset - Starting offset of the end region. Must be greater than or equal to the offset plus the length of the begin region.

displace

public boolean displace(int offset,
                        int length)
Description copied from class: OASTNode
Adjust the node's offset or length to reflect the addition or removal of characters in the file.

Overrides:
displace in class OASTNode
Parameters:
offset - Position in the document where the change occurred. This node's position will only be changed if some or all of it occurs after this offset.
length - Magnitude of the position adjustment. May be negative.
Returns:
true if the node was displaced, false if not

addAttribute

public void addAttribute(String sQName,
                         String sValue)
                  throws OASTException
Adds an attribute to the tag, after all existing attributes. The tag must not already contain an attribute with the same QName.

Parameters:
sQName - the qualified name of the attribute to add
sValue - the value of the attribute to add. If this is an empty string, the attribute will be added with an empty value. If it is null, the attribute will not be added.
Throws:
OASTException - if this node is attached to a read-only OAST or the attribute is already defined for this object.

setAttribute

public void setAttribute(String sQName,
                         String sValue)
                  throws OASTException
Sets the value of a child attribute of this tag. If the tag does not already have an attribute with the specified qname, one will be added.

Parameters:
sQName - the qualified name of the attribute to set or add
sValue - the new value of the attribute. If this is an empty string, the attribute will be given an empty value. If it is null, the attribute will be removed.
Throws:
OASTException - if this node is attached to a read-only OAST

getAttribute

public AttributeNode getAttribute(String sQName)
Retrieves a child attribute with a specified QName.

Parameters:
sQName - the qualified name of the attribute to retrieve
Returns:
The requested attribute, or null if this tag does not have an attribute with with that qname.

getAttributes

public AttributeNode[] getAttributes()
Retrieves all the attributes of this tag.

Returns:
An array of AttributeNodes that are children of this tag. If the tag has no attributes, an empty array is returned.

removeAttribute

public void removeAttribute(String sQName)
                     throws OASTException

Removes an attribute from the tag. If the tag does not have an attribute with the specified QName, there is no effect.

This is a convenience method, fully equivalent to:

removeAttribute(getAttribute(sQName))

Parameters:
sQName - the qualified name of the attribute to remove
Throws:
OASTException - if this node is attached to a read-only OAST

removeAttribute

public void removeAttribute(AttributeNode attribute)
                     throws OASTException
Removes an attribute from the tag.

Parameters:
attribute - the attribute node to remove
Throws:
OASTException - if this node is attached to a read-only OAST

splitSingleton

protected TagNode splitSingleton()
                          throws OASTException

Changes the tag from a singleton to discrete begin and end tags. If the tag is connected to an OWL Abstract Syntax Tree, this node will be replaced to ensure that the editor updates its text properly. As a result, callers should use the return value of this method for any further changes they need to make to the tag, since this instance may no longer be valid after the split.

Whenever possible, callers should also wrap calls to splitSingleton and their other OAST processing in an OAST runnable so that only one event notification is sent to OAST change listeners.

If this tag is not a singleton, it will simply be returned without making any changes to the OAST.

Returns:
The resulting non-singleton tag
Throws:
OASTException - if this node is attached to a read-only OAST
See Also:
IOASTRunnable, IOWLAbstractSyntaxTree.run(IOASTRunnable)

prependChildTag

public void prependChildTag(TagNode child)
                     throws OASTException
Inserts a tag node as the first non-attribute child of this node. If the tag is a singleton, it will be split into discrete begin/end tags first. The insertion position will be immediately after the begin tag of this node. The child node will be displaced to the target offset and the tree containing this node will be displaced to make room for the inserted child.

Parameters:
child - The tag node to add as a child
Throws:
OASTException - if this node is attached to a read-only OAST

appendChildTag

public void appendChildTag(TagNode child)
                    throws OASTException
Inserts a tag node as the last non-attribute child of this node. If the tag is a singleton, it will be split into discrete begin/end tags first. The insertion position will be immediately before the end tag of this node. The child node will be displaced to the target offset and the tree containing this node will be displaced to make room for the inserted child.

Parameters:
child - The tag node to add as a child
Throws:
OASTException - if this node is attached to a read-only OAST

prependChildAttribute

public void prependChildAttribute(AttributeNode child)
                           throws OASTException
Inserts an attribute node as the first attribute child of this node. The insertion position will be immediately after the qname in this node's begin tag, plus one character of whitespace. The child node will be displaced to the target offset and the tree containing this node will be displaced to make room for the inserted child.

Parameters:
child - The attribute node to add as a child
Throws:
OASTException - if this node is attached to a read-only OAST

generateNodeText

public String generateNodeText()
Description copied from class: OASTNode
Subclasses must implement this method to provide text representing the contents of the node and its children. This method is only used by the editor for inserting an extrnally-constructed node (i.e., as a result of a New... wizard) into the text. The formatting of the generated text is thus unimportant, as it will likely be modified by the Auto-Indent Strategy and Content Formatter anyway.

Specified by:
generateNodeText in class OASTNode
Returns:
A text approximation of the node and its children

appendChildAttribute

public void appendChildAttribute(AttributeNode child)
                          throws OASTException
Inserts an attribute node as the last attribute child of this node. The insertion position will be immediately before the '>' or '/>' terminating this node's begin tag. The child node will be displaced to the target offset and the tree containing this node will be displaced to make room for the inserted child, plus one character of whitespace to separate the new attribute from the previous one.

Parameters:
child - The attribute node to add as a child
Throws:
OASTException - if this node is attached to a read-only OAST

duplicateType

protected OASTNode duplicateType()
Description copied from class: OASTNode
Creates a new OAST node of the same type as this one.

Specified by:
duplicateType in class OASTNode
Returns:
A new node of the same node type

clone

public Object clone()
Description copied from class: OASTNode
Creates a deep copy of a node and all nodes below it in the tree. The resulting copy is not attached to any OWL abstract syntax tree.

Overrides:
clone in class OASTNode
Returns:
A deep copy of this node, including copies of any node structure below it in the tree.

create

public static TagNode create(String sQName,
                             OASTNode parent)

Factory method for creating tag nodes. If the specified QName is recognized as a tag from the RDF, RDFS, or OWL language, a custom node of the appropriate type will be returned.

Optionally, a parent node may be specified. No parent/child relationships are created, but if an unrecognized QName is specified the parent node will be used to determine which kind of generic tag to create in order to maintain proper thing/predicate striping.

If no parent and a non-language qname are provided, no node will be created.

Parameters:
sQName - The qualified name for the tag node
parent - The intended parent of the new node, or null
Returns:
A tag node of the specified type, a generic predicate or thing, or null if the appropriate generic type cannot be determined.

create

public static TagNode create(String sQName)

Factory method for creating language tag nodes. Returns a node of the specified type with no parent and no children. If a non-language qname or the qname of a non-tag language element is specified, no node will be created.

This is a convenience method, fully equivalent to:

create(sQName, null)

Parameters:
sQName - A string specifying a qualified name for the node
Returns:
A node with the specified qname, or null if an unknown or non-tag node qname is specified.


Copyright © 2004-2005 BBN Technologies. All Rights Reserved.