Package org.verapdf.xmp.impl
Class XMPNode
java.lang.Object
org.verapdf.xmp.impl.XMPNode
- All Implemented Interfaces:
Comparable
A node in the internally XMP tree, which can be a schema node, a property node, an array node,
an array item, a struct node or a qualifier node (without '?').
Possible improvements:
1. The kind Node of node might be better represented by a class-hierarchy of different nodes.
2. The array type should be an enum
3. isImplicitNode should be removed completely and replaced by return values of fi.
4. hasLanguage, hasType should be automatically maintained by XMPNode
- Since:
- 21.02.2006
-
Constructor Summary
ConstructorDescriptionXMPNode
(String name, String value, PropertyOptions options, String originalPrefix) Creates anXMPNode
with initial values.XMPNode
(String name, PropertyOptions options, String originalPrefix) Constructor for the node without value. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a node as child to this node.void
Adds a node as child to this node.void
addQualifier
(XMPNode qualNode) Appends a qualifier to the qualifier list and sets respective options.protected void
Removes the children list if this node has no children anymore; checks if the provided node is a schema node and doesn't have any children anymore, its deleted.void
clear()
Resets the node.clone()
Performs a deep clone of the node and the complete subtree.void
cloneSubtree
(XMPNode destination) Performs a deep clone of the complete subtree (children and qualifier )into and add it to the destination node.int
dumpNode
(boolean recursive) Renders this node and the tree unter this node in a human readable form.findChildByName
(String expr) findQualifierByName
(String expr) getChild
(int index) int
boolean
boolean
getName()
protected List
getQualifier
(int index) int
getValue()
boolean
boolean
boolean
isAlias()
boolean
boolean
void
removeChild
(int itemIndex) Removes a child at the requested index.void
removeChild
(XMPNode node) Removes a child node.void
Removes all children from the node.void
removeQualifier
(XMPNode qualNode) Removes one qualifier node and fixes the options.void
Removes all qualifiers from the node and sets the options appropriate.void
replaceChild
(int index, XMPNode node) Replaces a node with another one.void
setAlias
(boolean alias) void
setHasAliases
(boolean hasAliases) void
setHasValueChild
(boolean hasValueChild) void
setImplicit
(boolean implicit) void
void
setOptions
(PropertyOptions options) Updates the options of the node.protected void
Sets the parent node, this is solely done byaddChild(...)
andaddQualifier()
.void
void
sort()
Sorts the complete datamodel according to the following rules: Nodes at one level are sorted by name, that is prefix + local name Starting at the root node the children and qualifier are sorted recursively, which the following exceptions.
-
Constructor Details
-
XMPNode
Creates anXMPNode
with initial values.- Parameters:
name
- the name of the nodevalue
- the value of the nodeoptions
- the options of the node
-
XMPNode
Constructor for the node without value.- Parameters:
name
- the name of the nodeoptions
- the options of the node
-
-
Method Details
-
getOriginalPrefix
-
clear
public void clear()Resets the node. -
getParent
- Returns:
- Returns the parent node.
-
getChild
- Parameters:
index
- an index [1..size]- Returns:
- Returns the child with the requested index.
-
addChild
Adds a node as child to this node.- Parameters:
node
- an XMPNode- Throws:
XMPException
-
addChild
Adds a node as child to this node.- Parameters:
index
- the index of the node before which the new one is inserted. Note: The node children are indexed from [1..size]! An index of size + 1 appends a node.node
- an XMPNode- Throws:
XMPException
-
replaceChild
Replaces a node with another one.- Parameters:
index
- the index of the node that will be replaced. Note: The node children are indexed from [1..size]!node
- the replacement XMPNode
-
removeChild
public void removeChild(int itemIndex) Removes a child at the requested index.- Parameters:
itemIndex
- the index to remove [1..size]
-
removeChild
Removes a child node. If its a schema node and doesn't have any children anymore, its deleted.- Parameters:
node
- the child node to delete.
-
cleanupChildren
protected void cleanupChildren()Removes the children list if this node has no children anymore; checks if the provided node is a schema node and doesn't have any children anymore, its deleted. -
removeChildren
public void removeChildren()Removes all children from the node. -
getChildrenLength
public int getChildrenLength()- Returns:
- Returns the number of children without neccessarily creating a list.
-
findChildByName
- Parameters:
expr
- child node name to look for- Returns:
- Returns an
XMPNode
if node has been found,null
otherwise.
-
getQualifier
- Parameters:
index
- an index [1..size]- Returns:
- Returns the qualifier with the requested index.
-
getQualifierLength
public int getQualifierLength()- Returns:
- Returns the number of qualifier without neccessarily creating a list.
-
addQualifier
Appends a qualifier to the qualifier list and sets respective options.- Parameters:
qualNode
- a qualifier node.- Throws:
XMPException
-
removeQualifier
Removes one qualifier node and fixes the options.- Parameters:
qualNode
- qualifier to remove
-
removeQualifiers
public void removeQualifiers()Removes all qualifiers from the node and sets the options appropriate. -
findQualifierByName
- Parameters:
expr
- qualifier node name to look for- Returns:
- Returns a qualifier
XMPNode
if node has been found,null
otherwise.
-
hasChildren
public boolean hasChildren()- Returns:
- Returns whether the node has children.
-
iterateChildren
- Returns:
- Returns an iterator for the children. Note: take care to use it.remove(), as the flag are not adjusted in that case.
-
hasQualifier
public boolean hasQualifier()- Returns:
- Returns whether the node has qualifier attached.
-
iterateQualifier
- Returns:
- Returns an iterator for the qualifier. Note: take care to use it.remove(), as the flag are not adjusted in that case.
-
clone
Performs a deep clone of the node and the complete subtree. -
cloneSubtree
Performs a deep clone of the complete subtree (children and qualifier )into and add it to the destination node.- Parameters:
destination
- the node to add the cloned subtree
-
dumpNode
Renders this node and the tree unter this node in a human readable form.- Parameters:
recursive
- Flag is qualifier and child nodes shall be rendered too- Returns:
- Returns a multiline string containing the dump.
-
compareTo
- Specified by:
compareTo
in interfaceComparable
- See Also:
-
getName
- Returns:
- Returns the name.
-
setName
- Parameters:
name
- The name to set.
-
getValue
- Returns:
- Returns the value.
-
setValue
- Parameters:
value
- The value to set.
-
getOptions
- Returns:
- Returns the options.
-
setOptions
Updates the options of the node.- Parameters:
options
- the options to set.
-
isImplicit
public boolean isImplicit()- Returns:
- Returns the implicit flag
-
setImplicit
public void setImplicit(boolean implicit) - Parameters:
implicit
- Sets the implicit node flag
-
getHasAliases
public boolean getHasAliases()- Returns:
- Returns if the node contains aliases (applies only to schema nodes)
-
setHasAliases
public void setHasAliases(boolean hasAliases) - Parameters:
hasAliases
- sets the flag that the node contains aliases
-
isAlias
public boolean isAlias()- Returns:
- Returns if the node contains aliases (applies only to schema nodes)
-
setAlias
public void setAlias(boolean alias) - Parameters:
alias
- sets the flag that the node is an alias
-
getHasValueChild
public boolean getHasValueChild()- Returns:
- the hasValueChild
-
setHasValueChild
public void setHasValueChild(boolean hasValueChild) - Parameters:
hasValueChild
- the hasValueChild to set
-
sort
public void sort()Sorts the complete datamodel according to the following rules:- Nodes at one level are sorted by name, that is prefix + local name
- Starting at the root node the children and qualifier are sorted recursively, which the following exceptions.
- Sorting will not be used for arrays.
- Within qualifier "xml:lang" and/or "rdf:type" stay at the top in that order, all others are sorted.
-
isLanguageNode
public boolean isLanguageNode()- Returns:
- Returns whether this node is a language qualifier.
-
getUnmodifiableChildren
- Returns:
- Returns a read-only copy of child nodes list.
-
getQualifier
- Returns:
- Returns list of qualifier that is lazy initialized.
-
setParent
Sets the parent node, this is solely done byaddChild(...)
andaddQualifier()
.- Parameters:
parent
- Sets the parent node.
-