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 concreteBuilderVisitor
that can construct XML documents.
-
-
Field Summary
Fields Modifier and Type Field Description private org.w3c.dom.Document
document
Stores the document to be constructed.private java.util.Map<org.w3c.dom.Node,org.w3c.dom.Node>
elementMapping
The element mapping.private ListDelimiterHandler
listDelimiterHandler
Stores the list delimiter handler .private java.util.Map<ImmutableNode,org.w3c.dom.Element>
newElements
A mapping for the references for new nodes.
-
Constructor Summary
Constructors Constructor Description XMLBuilderVisitor(XMLDocumentHelper docHelper, ListDelimiterHandler handler)
Creates a new instance ofXMLBuilderVisitor
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static void
clearAttributes(org.w3c.dom.Element elem)
Removes all attributes of the given element.private static org.w3c.dom.Text
findTextNodeForUpdate(org.w3c.dom.Element elem)
Returns the only text node of an element for update.private org.w3c.dom.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(org.w3c.dom.Node element)
Updates the associated XML elements when a node is removed.protected void
update(ImmutableNode node, java.lang.Object reference, ReferenceNodeHandler refHandler)
Updates a node that already existed in the original hierarchy.private static void
updateAttributes(ImmutableNode node, org.w3c.dom.Element elem)
Helper method for updating the values of all attributes of the specified node.private void
updateElement(ImmutableNode node, ReferenceNodeHandler refHandler, java.lang.Object value)
private void
updateElement(org.w3c.dom.Element element, java.lang.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 Detail
-
document
private final org.w3c.dom.Document document
Stores the document to be constructed.
-
elementMapping
private final java.util.Map<org.w3c.dom.Node,org.w3c.dom.Node> elementMapping
The element mapping.
-
newElements
private final java.util.Map<ImmutableNode,org.w3c.dom.Element> newElements
A mapping for the references for new nodes.
-
listDelimiterHandler
private final ListDelimiterHandler listDelimiterHandler
Stores the list delimiter handler .
-
-
Constructor Detail
-
XMLBuilderVisitor
public XMLBuilderVisitor(XMLDocumentHelper docHelper, ListDelimiterHandler handler)
Creates a new instance ofXMLBuilderVisitor
.- Parameters:
docHelper
- the document helperhandler
- the delimiter handler for properties with multiple values
-
-
Method Detail
-
clearAttributes
private static void clearAttributes(org.w3c.dom.Element elem)
Removes all attributes of the given element.- Parameters:
elem
- the element
-
findTextNodeForUpdate
private static org.w3c.dom.Text findTextNodeForUpdate(org.w3c.dom.Element elem)
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
private static void updateAttributes(ImmutableNode node, org.w3c.dom.Element elem)
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
private org.w3c.dom.Element getElement(ImmutableNode node, ReferenceNodeHandler refHandler)
Helper method for accessing the element of the specified node.- Parameters:
node
- the noderefHandler
- theReferenceNodeHandler
- Returns:
- the element of this node
-
handleRemovedNodes
public void handleRemovedNodes(ReferenceNodeHandler refHandler)
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
public void processDocument(ReferenceNodeHandler refHandler)
Processes the specified document, updates element values, and adds new nodes to the hierarchy.- Parameters:
refHandler
- theReferenceNodeHandler
-
removeReference
private void removeReference(org.w3c.dom.Node element)
Updates the associated XML elements when a node is removed.- Parameters:
element
- the element to be removed
-
update
protected void update(ImmutableNode node, java.lang.Object reference, ReferenceNodeHandler refHandler)
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
private void updateElement(org.w3c.dom.Element element, java.lang.Object value)
Updates the node's value if it represents an element node.- Parameters:
element
- the elementvalue
- the new value
-
updateElement
private void updateElement(ImmutableNode node, ReferenceNodeHandler refHandler, java.lang.Object value)
-
-