Class XMLConfiguration.XMLBuilderVisitor
java.lang.Object
org.apache.commons.configuration2.tree.ConfigurationNodeVisitorAdapter<ImmutableNode>
org.apache.commons.configuration2.BaseHierarchicalConfiguration.BuilderVisitor
org.apache.commons.configuration2.XMLConfiguration.XMLBuilderVisitor
- All Implemented Interfaces:
ConfigurationNodeVisitor<ImmutableNode>
- Enclosing class:
XMLConfiguration
static class XMLConfiguration.XMLBuilderVisitor
extends BaseHierarchicalConfiguration.BuilderVisitor
A concrete
BuilderVisitor
that can construct XML documents.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Document
Stores the document to be constructed.The element mapping.private final ListDelimiterHandler
Stores the list delimiter handler .private final Map
<ImmutableNode, Element> A mapping for the references for new nodes. -
Constructor Summary
ConstructorsConstructorDescriptionXMLBuilderVisitor
(XMLDocumentHelper docHelper, ListDelimiterHandler handler) Creates a new instance ofXMLBuilderVisitor
. -
Method Summary
Modifier and TypeMethodDescriptionprivate static void
clearAttributes
(Element elem) Removes all attributes of the given element.private static Text
findTextNodeForUpdate
(Element elem) Returns the only text node of an element for update.private Element
getElement
(ImmutableNode node, ReferenceNodeHandler refHandler) Helper method for accessing the element of the specified node.void
handleRemovedNodes
(ReferenceNodeHandler refHandler) Updates the current XML document regarding removed nodes.protected void
insert
(ImmutableNode newNode, ImmutableNode parent, ImmutableNode sibling1, ImmutableNode sibling2, ReferenceNodeHandler refHandler) Inserts a new node into the structure constructed by this builder.void
processDocument
(ReferenceNodeHandler refHandler) Processes the specified document, updates element values, and adds new nodes to the hierarchy.private void
removeReference
(Node element) Updates the associated XML elements when a node is removed.protected void
update
(ImmutableNode node, Object reference, ReferenceNodeHandler refHandler) Updates a node that already existed in the original hierarchy.private static void
updateAttributes
(ImmutableNode node, Element elem) Helper method for updating the values of all attributes of the specified node.private void
updateElement
(ImmutableNode node, ReferenceNodeHandler refHandler, Object value) private void
updateElement
(Element element, Object value) Updates the node's value if it represents an element node.Methods inherited from class org.apache.commons.configuration2.BaseHierarchicalConfiguration.BuilderVisitor
visitBeforeChildren
Methods inherited from class org.apache.commons.configuration2.tree.ConfigurationNodeVisitorAdapter
terminate, visitAfterChildren
-
Field Details
-
document
Stores the document to be constructed. -
elementMapping
The element mapping. -
newElements
A mapping for the references for new nodes. -
listDelimiterHandler
Stores the list delimiter handler .
-
-
Constructor Details
-
XMLBuilderVisitor
Creates a new instance ofXMLBuilderVisitor
.- Parameters:
docHelper
- the document helperhandler
- the delimiter handler for properties with multiple values
-
-
Method Details
-
clearAttributes
Removes all attributes of the given element.- Parameters:
elem
- the element
-
findTextNodeForUpdate
Returns the only text node of an element for update. This method is called when the element's text changes. Then all text nodes except for the first are removed. A reference to the first is returned or null if there is no text node at all.- Parameters:
elem
- the element- Returns:
- the first and only text node
-
updateAttributes
Helper method for updating the values of all attributes of the specified node.- Parameters:
node
- the affected nodeelem
- the element that is associated with this node
-
getElement
Helper method for accessing the element of the specified node.- Parameters:
node
- the noderefHandler
- theReferenceNodeHandler
- Returns:
- the element of this node
-
handleRemovedNodes
Updates the current XML document regarding removed nodes. The elements associated with removed nodes are removed from the document.- Parameters:
refHandler
- theReferenceNodeHandler
-
insert
protected void insert(ImmutableNode newNode, ImmutableNode parent, ImmutableNode sibling1, ImmutableNode sibling2, ReferenceNodeHandler refHandler) Inserts a new node into the structure constructed by this builder. This method is called for each node that has been added to the configuration tree after the configuration has been loaded from its source. These new nodes have to be inserted into the original structure. The passed in nodes define the position of the node to be inserted: its parent and the siblings between to insert. This implementation ensures that the correct XML element is created and inserted between the given siblings.- Specified by:
insert
in classBaseHierarchicalConfiguration.BuilderVisitor
- Parameters:
newNode
- the node to be insertedparent
- the parent nodesibling1
- the sibling after which the node is to be inserted; can be null if the new node is going to be the first child nodesibling2
- the sibling before which the node is to be inserted; can be null if the new node is going to be the last child noderefHandler
- theReferenceNodeHandler
-
processDocument
Processes the specified document, updates element values, and adds new nodes to the hierarchy.- Parameters:
refHandler
- theReferenceNodeHandler
-
removeReference
Updates the associated XML elements when a node is removed.- Parameters:
element
- the element to be removed
-
update
Updates a node that already existed in the original hierarchy. This method is called for each node that has an assigned reference object. A concrete implementation should update the reference according to the node's current value. This implementation determines the XML element associated with the given node. Then this element's value and attributes are set accordingly.- Specified by:
update
in classBaseHierarchicalConfiguration.BuilderVisitor
- Parameters:
node
- the current node to be processedreference
- the reference object for this noderefHandler
- theReferenceNodeHandler
-
updateElement
Updates the node's value if it represents an element node.- Parameters:
element
- the elementvalue
- the new value
-
updateElement
-