Package org.simpleframework.xml.stream
Class OutputAttribute
java.lang.Object
org.simpleframework.xml.stream.OutputAttribute
- All Implemented Interfaces:
Node
,OutputNode
The
OutputAttribute
object is used to represent a
node added to the output node map. It represents a simple name
value pair that is used as an attribute by an output element.
This shares its namespaces with the parent element so that any
namespaces added to the attribute are actually added to the
parent element, which ensures correct scoping.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate String
Represents the name of this node object instance.private String
Represents the namespace reference for this node.private NamespaceMap
This contains the namespaces for the parent element.private OutputNode
Represents the output node that this node requires.private String
Represents the value of this node object instance. -
Constructor Summary
ConstructorsConstructorDescriptionOutputAttribute
(OutputNode source, String name, String value) Constructor for theOutputAttribute
object. -
Method Summary
Modifier and TypeMethodDescriptionvoid
commit()
Thecommit
method is used flush and commit any child nodes that have been created by this node.This returns aNodeMap
which can be used to add nodes to the element before that element has been committed.This is used to create a child element within the element that this object represents.This is used to get the text comment for the element.getMode()
TheMode
is used to indicate the output mode of this node.getName()
Returns the name of the node that this represents.This returns theNamespaceMap
for this node.This is used to acquire theNode
that is the parent of this node.This is used to acquire the prefix for this output node.getPrefix
(boolean inherit) This is used to acquire the prefix for this output node.This is used to acquire the namespace URI reference associated with this node.getValue()
Returns the value for the node that this represents.boolean
This is used to determine whether the node has been committed.boolean
isRoot()
This method is used to determine if this node is the root node for the XML document.void
remove()
This is used to remove any uncommitted changes.setAttribute
(String name, String value) This method is used for convinience to add an attribute node to the attributeNodeMap
.void
setComment
(String comment) This is used to set a text comment to the element.void
setData
(boolean data) This is used to set the output mode of this node to either be CDATA or escaped.void
This is used to set the output mode of this node to either be CDATA, escaped, or inherited.void
This is used to change the name of an output node.void
setReference
(String reference) This is used to set the reference for the node.void
This is used to set a text value to the attribute.toString()
This is used to acquire the name and value of the attribute.
-
Field Details
-
scope
This contains the namespaces for the parent element. -
source
Represents the output node that this node requires. -
reference
Represents the namespace reference for this node. -
name
Represents the name of this node object instance. -
value
Represents the value of this node object instance.
-
-
Constructor Details
-
OutputAttribute
Constructor for theOutputAttribute
object. This is used to create a simple name value pair attribute holder.- Parameters:
name
- this is the name that is used for the nodevalue
- this is the value used for the node
-
-
Method Details
-
getValue
Returns the value for the node that this represents. This is a modifiable property for the node and can be changed. When set this forms the value the attribute contains in the parent XML element, which is written in quotations. -
setValue
This is used to set a text value to the attribute. This should be added to the attribute if the attribute is to be written to the parent element. Without a value this is invalid.- Specified by:
setValue
in interfaceOutputNode
- Parameters:
value
- this is the text value to add to this attribute
-
setName
This is used to change the name of an output node. This will only affect the name of the node if the node has not yet been committed. If the node is committed then this will not be reflected in the resulting XML generated.- Specified by:
setName
in interfaceOutputNode
- Parameters:
name
- this is the name to change the node to
-
getName
Returns the name of the node that this represents. This is an immutable property and should not change for any node. If this is null then the attribute will not be added to the node map, all attributes must have a valid key. -
getParent
This is used to acquire theNode
that is the parent of this node. This will return the node that is the direct parent of this node and allows for siblings to make use of nodes with their parents if required.- Specified by:
getParent
in interfaceNode
- Specified by:
getParent
in interfaceOutputNode
- Returns:
- this returns the parent node for this node
-
getAttributes
This returns aNodeMap
which can be used to add nodes to the element before that element has been committed. Nodes can be removed or added to the map and will appear as attributes on the written element when it is committed.- Specified by:
getAttributes
in interfaceOutputNode
- Returns:
- returns the node map used to manipulate attributes
-
getChild
This is used to create a child element within the element that this object represents. When a new child is created with this method then the previous child is committed to the document. The createdOutputNode
object can be used to add attributes to the child element as well as other elements.- Specified by:
getChild
in interfaceOutputNode
- Parameters:
name
- this is the name of the child element to create
-
getComment
This is used to get the text comment for the element. This can be null if no comment has been set. If no comment is set on the node then no comment will be written to the resulting XML.- Specified by:
getComment
in interfaceOutputNode
- Returns:
- this is the comment associated with this element
-
setComment
This is used to set a text comment to the element. This will be written just before the actual element is written. Only a single comment can be set for each output node written.- Specified by:
setComment
in interfaceOutputNode
- Parameters:
comment
- this is the comment to set on the node
-
getMode
TheMode
is used to indicate the output mode of this node. Three modes are possible, each determines how a value, if specified, is written to the resulting XML document. This is determined by thesetData
method which will set the output to be CDATA or escaped, if neither is specified the mode is inherited.- Specified by:
getMode
in interfaceOutputNode
- Returns:
- this returns the mode of this output node object
-
setMode
This is used to set the output mode of this node to either be CDATA, escaped, or inherited. If the mode is set to data then any value specified will be written in a CDATA block, if this is set to escaped values are escaped. If however this method is set to inherited then the mode is inherited from the parent node.- Specified by:
setMode
in interfaceOutputNode
- Parameters:
mode
- this is the output mode to set the node to
-
setData
public void setData(boolean data) This is used to set the output mode of this node to either be CDATA or escaped. If this is set to true the any value specified will be written in a CDATA block, if this is set to false the values is escaped. If however this method is never invoked then the mode is inherited from the parent.- Specified by:
setData
in interfaceOutputNode
- Parameters:
data
- if true the value is written as a CDATA block
-
getPrefix
This is used to acquire the prefix for this output node. If the output node is an element then this will search its parent nodes until the prefix that is currently in scope is found. If however this node is an attribute then the hierarchy of nodes is not searched as attributes to not inherit namespaces.- Specified by:
getPrefix
in interfaceOutputNode
- Returns:
- this returns the prefix associated with this node
-
getPrefix
This is used to acquire the prefix for this output node. If the output node is an element then this will search its parent nodes until the prefix that is currently in scope is found. If however this node is an attribute then the hierarchy of nodes is not searched as attributes to not inherit namespaces.- Specified by:
getPrefix
in interfaceOutputNode
- Parameters:
inherit
- if there is no explicit prefix then inherit- Returns:
- this returns the prefix associated with this node
-
getReference
This is used to acquire the namespace URI reference associated with this node. Although it is recommended that the namespace reference is a URI it does not have to be, it can be any unique identifier that can be used to distinguish the qualified names.- Specified by:
getReference
in interfaceOutputNode
- Returns:
- this returns the namespace URI reference for this
-
setReference
This is used to set the reference for the node. Setting the reference implies that the node is a qualified node within the XML document. Both elements and attributes can be qualified. Depending on the prefix set on this node or, failing that, any parent node for the reference, the element will appear in the XML document with that string prefixed to the node name.- Specified by:
setReference
in interfaceOutputNode
- Parameters:
reference
- this is used to set the reference for the node
-
getNamespaces
This returns theNamespaceMap
for this node. Only an element can have namespaces, so if this node represents an attribute the elements namespaces will be provided when this is requested. By adding a namespace it becomes in scope for the current element all all child elements of that element.- Specified by:
getNamespaces
in interfaceOutputNode
- Returns:
- this returns the namespaces associated with the node
-
setAttribute
This method is used for convinience to add an attribute node to the attributeNodeMap
. The attribute added can be removed from the element by useing the node map.- Specified by:
setAttribute
in interfaceOutputNode
- Parameters:
name
- this is the name of the attribute to be addedvalue
- this is the value of the node to be added- Returns:
- this returns the node that has just been added
-
remove
public void remove()This is used to remove any uncommitted changes. Removal of an output node can only be done if it has no siblings and has not yet been committed. If the node is committed then this will throw an exception to indicate that it cannot be removed.- Specified by:
remove
in interfaceOutputNode
-
commit
public void commit()Thecommit
method is used flush and commit any child nodes that have been created by this node. This allows the output to be completed when building of the XML document has been completed. If output fails an exception is thrown.- Specified by:
commit
in interfaceOutputNode
-
isRoot
public boolean isRoot()This method is used to determine if this node is the root node for the XML document. The root node is the first node in the document and has no sibling nodes. This is false if the node has a parent node or a sibling node.- Specified by:
isRoot
in interfaceOutputNode
- Returns:
- true if this is the root node within the document
-
isCommitted
public boolean isCommitted()This is used to determine whether the node has been committed. If the node has been committed, then this will return true. When committed the node can no longer produce child nodes.- Specified by:
isCommitted
in interfaceOutputNode
- Returns:
- true if this node has already been committed
-
toString
This is used to acquire the name and value of the attribute. Implementing this method ensures that debugging the output node is simplified as it is possible to get the actual value.
-