org.qtitools.qti.node
Class AbstractNode

java.lang.Object
  extended by org.qtitools.qti.node.AbstractNode
All Implemented Interfaces:
java.io.Serializable, XmlNode, Validatable
Direct Known Subclasses:
AbstractObject

public abstract class AbstractNode
extends java.lang.Object
implements XmlNode

Parent of all xml nodes.

Author:
Jiri Kajaba, Jonathon Hare
See Also:
Serialized Form

Field Summary
 
Fields inherited from interface org.qtitools.qti.node.XmlNode
INDENT, NEW_LINE, SIMPLE_NAME_INNER_SEPARATOR, SIMPLE_NAMES_SEPARATOR
 
Constructor Summary
AbstractNode(XmlNode parent)
          Constructs node.
 
Method Summary
protected  java.lang.String attrToXmlString(int depth, boolean printDefaultAttributes)
          Prints attributes of this node into xml string.
protected  java.lang.String bodyToXmlString(int depth, boolean printDefaultAttributes)
          Prints body (children and/or text content) of this node into xml string.
 AttributeList getAttributes()
          Gets list (container) of all attributes.
abstract  java.lang.String getClassTag()
          Gets QTI class name of this node.
 java.lang.String getFullName()
          Gets full name of this node.
static java.lang.String getIndent(int depth)
          Prints indent into xml string.
static org.w3c.dom.Node getNode(java.io.File file)
          Gets node from given source file.
static org.w3c.dom.Node getNode(java.lang.String string)
          Gets node from given source string.
static org.w3c.dom.Node getNode(java.net.URL url)
          Gets node from given source url.
 NodeGroupList getNodeGroups()
          Gets list (container) of all child groups.
 XmlNode getParent()
          Gets parent of this node or null (if node is root; for example AssessmentTest).
 XmlNode getParentRoot()
          Gets root of this node or node itself (if node is root; for example AssessmentTest).
 java.lang.String getSimpleName()
          Gets simple name of this node.
 java.io.File getSourceFile()
          Gets source file of this node.
 org.w3c.dom.Node getSourceNode()
          Gets source node (DOM) of this node.
 java.lang.String getSourceString()
          Gets source string of this node.
 java.net.URL getSourceUrl()
          Gets source url of this node.
 boolean hasChildNodes()
          This is A convenience method to allow easy determination of whether A node has any children.
 void load(java.io.File sourceFile)
          Loads this node from given source file.
 void load(org.w3c.dom.Node sourceNode)
          Loads this node from given source node (DOM).
 void load(java.lang.String sourceString)
          Loads this node from given source string.
 void load(java.net.URL sourceUrl)
          Loads this node from given source url.
protected  void loadAttributes(org.w3c.dom.Node node)
          Loads all attributes from given xml source.
protected  void readChild(org.w3c.dom.Node node)
          Reads one child from given xml source.
protected  void readChildren(org.w3c.dom.Node node)
          Reads all children nodes and/or content from given xml source.
protected  void setParent(XmlNode parent)
          Sets new parent of this node.
 void setSourceFile(java.io.File sourceFile)
          Sets new source file of this node.
 void setSourceNode(org.w3c.dom.Node sourceNode)
          Sets new source node (DOM) of this node.
 void setSourceString(java.lang.String sourceString)
          Sets new source string of this node.
 void setSourceUrl(java.net.URL sourceUrl)
          Sets new source url of this node.
 java.lang.String toXmlString()
          Prints this node and all its children into string.
 java.lang.String toXmlString(int depth, boolean printDefaultAttributes)
          Prints this node and all its children into string.
 ValidationResult validate()
          Validates this object.
protected  ValidationResult validateAttributes()
          Validates attributes of this node.
protected  ValidationResult validateChildren()
          Validates children (body) of this node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractNode

public AbstractNode(XmlNode parent)
Constructs node.

Parameters:
parent - parent of constructed node (can be null for root nodes)
Method Detail

getParent

public XmlNode getParent()
Description copied from interface: XmlNode
Gets parent of this node or null (if node is root; for example AssessmentTest).

While testing some nodes (for example expressions) don't have properly set parent, but it is usable only for testing. (Some nodes cannot exists without parent even for testing).

Specified by:
getParent in interface XmlNode
Returns:
parent of this node or null (if node is root; for example AssessmentTest)

setParent

protected void setParent(XmlNode parent)
Sets new parent of this node.

Parameters:
parent - new parent of this node
See Also:
getParent()

getParentRoot

public XmlNode getParentRoot()
Description copied from interface: XmlNode
Gets root of this node or node itself (if node is root; for example AssessmentTest).

While testing some nodes (for example expressions) don't have properly set parent, but it is usable only for testing. (Some nodes cannot exists without parent even for testing).

Specified by:
getParentRoot in interface XmlNode
Returns:
root of this node or node itself (if node is root; for example AssessmentTest)

getAttributes

public AttributeList getAttributes()
Description copied from interface: XmlNode
Gets list (container) of all attributes.

Specified by:
getAttributes in interface XmlNode
Returns:
list (container) of all attributes of this node

getNodeGroups

public NodeGroupList getNodeGroups()
Description copied from interface: XmlNode
Gets list (container) of all child groups.

For example AssessmentTest contains (one) testPart group. And this (one) group contains all testParts.

Group approach is useful for defining some rules to all testParts (for example required number of testParts in AssessmentTest).

Specified by:
getNodeGroups in interface XmlNode
Returns:
list (container) of all child group

load

public void load(java.net.URL sourceUrl)
Description copied from interface: XmlNode
Loads this node from given source url.

Specified by:
load in interface XmlNode
Parameters:
sourceUrl - source url for this node

getSourceUrl

public java.net.URL getSourceUrl()
Description copied from interface: XmlNode
Gets source url of this node.

Specified by:
getSourceUrl in interface XmlNode
Returns:
source url of this node.
See Also:
XmlNode.setSourceUrl(java.net.URL)

setSourceUrl

public void setSourceUrl(java.net.URL sourceUrl)
Description copied from interface: XmlNode
Sets new source url of this node.

Specified by:
setSourceUrl in interface XmlNode
Parameters:
sourceUrl - new source url of this node
See Also:
XmlNode.getSourceUrl()

load

public void load(java.io.File sourceFile)
Description copied from interface: XmlNode
Loads this node from given source file.

Specified by:
load in interface XmlNode
Parameters:
sourceFile - source file for this node

getSourceFile

public java.io.File getSourceFile()
Description copied from interface: XmlNode
Gets source file of this node.

Specified by:
getSourceFile in interface XmlNode
Returns:
source file of this node.
See Also:
XmlNode.setSourceFile(java.io.File)

setSourceFile

public void setSourceFile(java.io.File sourceFile)
Description copied from interface: XmlNode
Sets new source file of this node.

Specified by:
setSourceFile in interface XmlNode
Parameters:
sourceFile - new source file of this node
See Also:
XmlNode.getSourceFile()

load

public void load(java.lang.String sourceString)
Description copied from interface: XmlNode
Loads this node from given source string.

Specified by:
load in interface XmlNode
Parameters:
sourceString - source string for this node

getSourceString

public java.lang.String getSourceString()
Description copied from interface: XmlNode
Gets source string of this node.

Specified by:
getSourceString in interface XmlNode
Returns:
source string of this node
See Also:
XmlNode.setSourceString(java.lang.String)

setSourceString

public void setSourceString(java.lang.String sourceString)
Description copied from interface: XmlNode
Sets new source string of this node.

Specified by:
setSourceString in interface XmlNode
Parameters:
sourceString - new source string of this node
See Also:
XmlNode.getSourceString()

load

public void load(org.w3c.dom.Node sourceNode)
Description copied from interface: XmlNode
Loads this node from given source node (DOM).

Specified by:
load in interface XmlNode
Parameters:
sourceNode - source node (DOM) for this node

getSourceNode

public org.w3c.dom.Node getSourceNode()
Description copied from interface: XmlNode
Gets source node (DOM) of this node.

Specified by:
getSourceNode in interface XmlNode
Returns:
source node (DOM) of this node
See Also:
XmlNode.setSourceNode(org.w3c.dom.Node)

setSourceNode

public void setSourceNode(org.w3c.dom.Node sourceNode)
Description copied from interface: XmlNode
Sets new source node (DOM) of this node.

Specified by:
setSourceNode in interface XmlNode
Parameters:
sourceNode - new source node (DOM) of this node
See Also:
XmlNode.getSourceNode()

loadAttributes

protected void loadAttributes(org.w3c.dom.Node node)
Loads all attributes from given xml source.

Parameters:
node - xml source

readChildren

protected void readChildren(org.w3c.dom.Node node)
Reads all children nodes and/or content from given xml source. Every subclass must implement its own children nodes and/or content reading. If there are no children nodes and content do nothing (you don't even need to override this method).

Parameters:
node - xml source

readChild

protected void readChild(org.w3c.dom.Node node)
Reads one child from given xml source. Every subclass must implement its own child reading.

Parameters:
node - xml source

toXmlString

public java.lang.String toXmlString()
Description copied from interface: XmlNode
Prints this node and all its children into string.

Calls toXmlString(0, false).

Specified by:
toXmlString in interface XmlNode
Returns:
xml string of this node and all its children
See Also:
XmlNode.toXmlString(int, boolean)

toXmlString

public java.lang.String toXmlString(int depth,
                                    boolean printDefaultAttributes)
Description copied from interface: XmlNode
Prints this node and all its children into string.

Specified by:
toXmlString in interface XmlNode
Parameters:
depth - indent (0 = no indent)
printDefaultAttributes - whether print attribute's default values
Returns:
xml string of this node and all its children
See Also:
XmlNode.toXmlString()

getClassTag

public abstract java.lang.String getClassTag()
Description copied from interface: XmlNode
Gets QTI class name of this node.

QTI class name has very important role during loading/saving nodes.

For example: Java class name is AssessmentTest; QTI class name is assessmentTest.

Specified by:
getClassTag in interface XmlNode
Returns:
QTI class name of this node

attrToXmlString

protected java.lang.String attrToXmlString(int depth,
                                           boolean printDefaultAttributes)
Prints attributes of this node into xml string.

Parameters:
depth - depth in xml tree (root = 0)
printDefaultAttributes - whether print attributes with default values
Returns:
xml string with printed attributes of this node

bodyToXmlString

protected java.lang.String bodyToXmlString(int depth,
                                           boolean printDefaultAttributes)
Prints body (children and/or text content) of this node into xml string.

Parameters:
depth - depth in xml tree (root = 0)
printDefaultAttributes - whether print attributes with default values
Returns:
xml string with printed body (children and/or text content) of this node

getSimpleName

public java.lang.String getSimpleName()
Description copied from interface: XmlNode
Gets simple name of this node. Simple name contains QTI class name and some additional information to help identify node (if these informations are available).

Simple name is not so important like QTI class name. It servers mostly for displaying informations and in messages.

For example: simple name can be assessmentTest:Test (QTI class name (assessmentTest) + identifier (Test)).

Specified by:
getSimpleName in interface XmlNode
Returns:
simple name of this node
See Also:
XmlNode.getFullName()

getFullName

public java.lang.String getFullName()
Description copied from interface: XmlNode
Gets full name of this node. Full name is chain of simple names from root node to this node.

Full name is not so important like QTI class name. It serves mostly for displaying informations and in messages.

For example: assessmentTest:Test->testPart:Part3->assessmentSection:SectionB->assessmnetItemRef:Item05.

Specified by:
getFullName in interface XmlNode
Returns:
full name of this node
See Also:
XmlNode.getSimpleName()

validate

public ValidationResult validate()
Description copied from interface: Validatable
Validates this object.

Specified by:
validate in interface Validatable
Returns:
validation result

validateAttributes

protected ValidationResult validateAttributes()
Validates attributes of this node.

Returns:
result of validation

validateChildren

protected ValidationResult validateChildren()
Validates children (body) of this node.

Returns:
result of validation

getNode

public static org.w3c.dom.Node getNode(java.net.URL url)
Gets node from given source url.

Parameters:
url - source url
Returns:
node from given source url

getNode

public static org.w3c.dom.Node getNode(java.io.File file)
Gets node from given source file.

Parameters:
file - source file
Returns:
node from given source file

getNode

public static org.w3c.dom.Node getNode(java.lang.String string)
Gets node from given source string.

Parameters:
string - source string
Returns:
node from given source string

getIndent

public static java.lang.String getIndent(int depth)
Prints indent into xml string.

Parameters:
depth - depth in xml tree (root = 0)
Returns:
xml string with printed indent

hasChildNodes

public boolean hasChildNodes()
Description copied from interface: XmlNode
This is A convenience method to allow easy determination of whether A node has any children.

Specified by:
hasChildNodes in interface XmlNode
Returns:
true if the node has any children, false if the node has no children.


Copyright © 2009. All Rights Reserved.