Class BaseHierarchicalConfiguration.InterpolatedVisitor
- java.lang.Object
-
- org.apache.commons.configuration2.tree.ConfigurationNodeVisitorAdapter<ImmutableNode>
-
- org.apache.commons.configuration2.BaseHierarchicalConfiguration.InterpolatedVisitor
-
- All Implemented Interfaces:
ConfigurationNodeVisitor<ImmutableNode>
- Enclosing class:
- BaseHierarchicalConfiguration
private final class BaseHierarchicalConfiguration.InterpolatedVisitor extends ConfigurationNodeVisitorAdapter<ImmutableNode>
A specialized visitor implementation which constructs the root node of a configuration with all variables replaced by their interpolated values.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<ImmutableNode.Builder>
builderStack
A stack for managing node builder instances.private ImmutableNode
interpolatedRoot
The resulting root node.
-
Constructor Summary
Constructors Constructor Description InterpolatedVisitor()
Creates a new instance ofInterpolatedVisitor
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ImmutableNode
getInterpolatedRoot()
Gets the result of this builder: the root node of the interpolated nodes hierarchy.private void
handleLeafNode(ImmutableNode node, NodeHandler<ImmutableNode> handler)
Handles interpolation for a node with no children.private java.util.Map<java.lang.String,java.lang.Object>
interpolateAttributes(ImmutableNode node, NodeHandler<ImmutableNode> handler)
Returns a map with interpolated attributes of the passed in node.private boolean
interpolateAttributes(ImmutableNode node, NodeHandler<ImmutableNode> handler, java.util.Map<java.lang.String,java.lang.Object> interpolatedAttributes)
Populates a map with interpolated attributes of the passed in node.private boolean
isLeafNode(ImmutableNode node, NodeHandler<ImmutableNode> handler)
Returns a flag whether the given node is a leaf.private ImmutableNode.Builder
peek()
Returns the top-level element from the stack without removing it.private ImmutableNode.Builder
pop()
Pops the top-level element from the stack.private void
push(ImmutableNode.Builder builder)
Pushes a new builder on the stack.private void
storeInterpolatedNode(ImmutableNode node)
Stores a processed node.private boolean
valueChanged(java.lang.Object interpolatedValue, java.lang.Object value)
Tests whether a value is changed because of interpolation.void
visitAfterChildren(ImmutableNode node, NodeHandler<ImmutableNode> handler)
Visits the specified node after after its children - if existing - have been processed.void
visitBeforeChildren(ImmutableNode node, NodeHandler<ImmutableNode> handler)
Visits the specified node before the children of this node - if existing - are processed.-
Methods inherited from class org.apache.commons.configuration2.tree.ConfigurationNodeVisitorAdapter
terminate
-
-
-
-
Field Detail
-
builderStack
private final java.util.List<ImmutableNode.Builder> builderStack
A stack for managing node builder instances.
-
interpolatedRoot
private ImmutableNode interpolatedRoot
The resulting root node.
-
-
Method Detail
-
getInterpolatedRoot
public ImmutableNode getInterpolatedRoot()
Gets the result of this builder: the root node of the interpolated nodes hierarchy.- Returns:
- the resulting root node
-
handleLeafNode
private void handleLeafNode(ImmutableNode node, NodeHandler<ImmutableNode> handler)
Handles interpolation for a node with no children. If interpolation does not change this node, it is copied as is to the resulting structure. Otherwise, a new node is created with the interpolated values.- Parameters:
node
- the current node to be processedhandler
- theNodeHandler
-
interpolateAttributes
private java.util.Map<java.lang.String,java.lang.Object> interpolateAttributes(ImmutableNode node, NodeHandler<ImmutableNode> handler)
Returns a map with interpolated attributes of the passed in node.- Parameters:
node
- the current node to be processedhandler
- theNodeHandler
- Returns:
- the map with interpolated attributes
-
interpolateAttributes
private boolean interpolateAttributes(ImmutableNode node, NodeHandler<ImmutableNode> handler, java.util.Map<java.lang.String,java.lang.Object> interpolatedAttributes)
Populates a map with interpolated attributes of the passed in node.- Parameters:
node
- the current node to be processedhandler
- theNodeHandler
interpolatedAttributes
- a map for storing the results- Returns:
- a flag whether an attribute value was changed by interpolation
-
isLeafNode
private boolean isLeafNode(ImmutableNode node, NodeHandler<ImmutableNode> handler)
Returns a flag whether the given node is a leaf. This is the case if it does not have children.- Parameters:
node
- the node in questionhandler
- theNodeHandler
- Returns:
- a flag whether this is a leaf node
-
peek
private ImmutableNode.Builder peek()
Returns the top-level element from the stack without removing it.- Returns:
- the top-level element from the stack
-
pop
private ImmutableNode.Builder pop()
Pops the top-level element from the stack.- Returns:
- the element popped from the stack
-
push
private void push(ImmutableNode.Builder builder)
Pushes a new builder on the stack.- Parameters:
builder
- the builder
-
storeInterpolatedNode
private void storeInterpolatedNode(ImmutableNode node)
Stores a processed node. Per default, the node is added to the current builder on the stack. If no such builder exists, this is the result node.- Parameters:
node
- the node to be stored
-
valueChanged
private boolean valueChanged(java.lang.Object interpolatedValue, java.lang.Object value)
Tests whether a value is changed because of interpolation.- Parameters:
interpolatedValue
- the interpolated valuevalue
- the original value- Returns:
- a flag whether the value was changed
-
visitAfterChildren
public void visitAfterChildren(ImmutableNode node, NodeHandler<ImmutableNode> handler)
Description copied from class:ConfigurationNodeVisitorAdapter
Visits the specified node after after its children - if existing - have been processed. Empty dummy implementation of this interface method.- Specified by:
visitAfterChildren
in interfaceConfigurationNodeVisitor<ImmutableNode>
- Overrides:
visitAfterChildren
in classConfigurationNodeVisitorAdapter<ImmutableNode>
- Parameters:
node
- the node to be visitedhandler
- theNodeHandler
-
visitBeforeChildren
public void visitBeforeChildren(ImmutableNode node, NodeHandler<ImmutableNode> handler)
Description copied from class:ConfigurationNodeVisitorAdapter
Visits the specified node before the children of this node - if existing - are processed. Empty dummy implementation of this interface method.- Specified by:
visitBeforeChildren
in interfaceConfigurationNodeVisitor<ImmutableNode>
- Overrides:
visitBeforeChildren
in classConfigurationNodeVisitorAdapter<ImmutableNode>
- Parameters:
node
- the node to be visitedhandler
- theNodeHandler
-
-