Package com.unitesk.aspectrace
Class TraceNode
- java.lang.Object
-
- com.unitesk.aspectrace.TraceNode
-
public final class TraceNode extends java.lang.Object
message
element. The best external representation is an XML-node with corresponding attributes and children.
-
-
Constructor Summary
Constructors Constructor Description TraceNode(java.lang.String name)
TraceNode(java.lang.String name, java.lang.String... attrs)
TraceNode(java.lang.String name, java.lang.String attrName, java.lang.String attrValue)
TraceNode(java.lang.String name, java.util.Map<java.lang.String,java.lang.String> attrs, TraceNode... children)
Main constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addChild(TraceNode child)
Adds a node to the end of child list.void
addTextChild(java.lang.String text)
Adds a text child.static TraceNode
createNodeWithText(java.lang.String name, java.lang.String text)
Creates with a single text child.static TraceNode
createTextNode(java.lang.String text)
Creates a text node.java.lang.String
getAttr(java.lang.String attrName)
Gets attribute value.java.util.Map<java.lang.String,java.lang.String>
getAttrs()
Gets node attributes.TraceNode
getChild(int index)
Gets a child by his index.java.util.List<TraceNode>
getChildren()
Gets a list of children.java.lang.String
getName()
Gets a node name.java.lang.String
getText()
Gets a text.boolean
hasChildren()
Determines whether this node has children or not.boolean
isNode()
Determines whether a node is structured or not.boolean
isText()
Determines whether a node is a text node or not.void
removeAttr(java.lang.String name)
Deletes attribute.void
setAttr(java.lang.String name, java.lang.String value)
Sets attribute value.protected void
setReady()
Prepares a node for the further use after setting all attributes and children.java.lang.String
toString()
-
-
-
Constructor Detail
-
TraceNode
public TraceNode(java.lang.String name)
-
TraceNode
public TraceNode(java.lang.String name, java.lang.String attrName, java.lang.String attrValue)
-
TraceNode
public TraceNode(java.lang.String name, java.lang.String... attrs)
-
TraceNode
public TraceNode(java.lang.String name, java.util.Map<java.lang.String,java.lang.String> attrs, TraceNode... children)
Main constructor.- Parameters:
name
- Node name.attrs
- Attributes (null
is allowed).children
- Child nodes (null
or an empty array are both allowed).
-
-
Method Detail
-
createTextNode
public static TraceNode createTextNode(java.lang.String text)
Creates a text node.
-
createNodeWithText
public static TraceNode createNodeWithText(java.lang.String name, java.lang.String text)
Creates with a single text child.
-
setReady
protected void setReady()
Prepares a node for the further use after setting all attributes and children. Method is called when creatingmessage trace
on the base of this node. Method sets attributes and children to not-null
.It is possible to block node from changes but for the present is turned off because:
- In normal case scenario message is passed only one time (from provider to adapter or from
aspect tracer to main tracer) therefore it is difficult to corrupt data so that it has
consequences. However, this policy may be changed because of the appearance of the
mechanism
MessageStream
. - It realizes the mechanism of
trace filters
which may need to modify messages. For these purposes unblocking attributes and child list is allowed using following methodssetAttr(String, String)
,removeAttr(String)
иaddChild(TraceNode)
.
- In normal case scenario message is passed only one time (from provider to adapter or from
aspect tracer to main tracer) therefore it is difficult to corrupt data so that it has
consequences. However, this policy may be changed because of the appearance of the
mechanism
-
isNode
public boolean isNode()
Determines whether a node is structured or not.- Returns:
true
if the node is structuredfalse
if the node is a text node.
-
getName
public java.lang.String getName()
Gets a node name.- Returns:
null
for a text node and the name for a structured node.
-
isText
public boolean isText()
Determines whether a node is a text node or not.
-
getText
public java.lang.String getText()
Gets a text.- Returns:
null
for a structured node and the text for a text node.
-
getAttrs
public java.util.Map<java.lang.String,java.lang.String> getAttrs()
Gets node attributes.
-
getAttr
public java.lang.String getAttr(java.lang.String attrName)
Gets attribute value.
-
setAttr
public void setAttr(java.lang.String name, java.lang.String value)
Sets attribute value.
-
removeAttr
public void removeAttr(java.lang.String name)
Deletes attribute.
-
hasChildren
public boolean hasChildren()
Determines whether this node has children or not.
-
getChildren
public java.util.List<TraceNode> getChildren()
Gets a list of children.- Returns:
- list of children. Always not-
null
.
-
getChild
public TraceNode getChild(int index) throws java.lang.IndexOutOfBoundsException
Gets a child by his index.- Throws:
java.lang.IndexOutOfBoundsException
-
addChild
public void addChild(TraceNode child)
Adds a node to the end of child list. It is recommended to use this method instead ofgetChildren().add(...)
-
addTextChild
public void addTextChild(java.lang.String text)
Adds a text child.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-