Class XMLListReference
java.lang.Object
org.apache.commons.configuration2.XMLListReference
An internal class implementing list handling functionality for XMLConfiguration
.
When an XML document is loaded list properties defined as a string with multiple values separated by the list delimiter are split into multiple configuration nodes. When the configuration is saved the original format should be kept if possible. This class implements functionality to achieve this. Instances are used as references associated with configuration nodes so that the original format can be restored when the configuration is saved.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
assignListReference
(Map<ImmutableNode, Object> refs, ImmutableNode node, Element elem) Assigns an instance of this class as reference to the specified configuration node.Gets the associated element.private static boolean
hasListReference
(ImmutableNode node, ReferenceNodeHandler handler) Checks whether the specified node has an associated list reference.static boolean
isFirstListItem
(ImmutableNode node, ReferenceNodeHandler handler) Checks whether the specified node is the first node of a list.static boolean
isListNode
(ImmutableNode node, ReferenceNodeHandler handler) Checks whether the specified configuration node has to be taken into account for list handling.static String
listValue
(ImmutableNode node, ReferenceNodeHandler nodeHandler, ListDelimiterHandler delimiterHandler) Constructs the concatenated string value of all items comprising the list the specified node belongs to.private static boolean
nameEquals
(ImmutableNode n1, ImmutableNode n2) Helper method for comparing the names of two nodes.
-
Field Details
-
element
The wrapped XML element.
-
-
Constructor Details
-
XMLListReference
Private constructor. No instances can be created from other classes.- Parameters:
e
- the associated element
-
-
Method Details
-
assignListReference
public static void assignListReference(Map<ImmutableNode, Object> refs, ImmutableNode node, Element elem) Assigns an instance of this class as reference to the specified configuration node. This reference acts as a marker indicating that this node is subject to extended list handling.- Parameters:
refs
- the mapping for node referencesnode
- the affected configuration nodeelem
- the current XML element
-
hasListReference
Checks whether the specified node has an associated list reference. This marks the node as part of a list.- Parameters:
node
- the node to be checkedhandler
- the reference handler- Returns:
- a flag whether this node has a list reference
-
isFirstListItem
Checks whether the specified node is the first node of a list. This is needed because all items of the list are collected and stored as value of the first list node. Note: This method requires that the passed in node is a list node, soisListNode(ImmutableNode, ReferenceNodeHandler)
must have returned true for it.- Parameters:
node
- the configuration nodehandler
- the reference node handler- Returns:
- a flag whether this is the first node of a list
-
isListNode
Checks whether the specified configuration node has to be taken into account for list handling. This is the case if the node's parent has at least one child node with the same name which has a special list reference assigned. (Note that the passed in node does not necessarily have such a reference; if it has been added at a later point in time, it also has to become an item of the list.)- Parameters:
node
- the configuration nodehandler
- the reference node handler- Returns:
- a flag whether this node is relevant for list handling
-
listValue
public static String listValue(ImmutableNode node, ReferenceNodeHandler nodeHandler, ListDelimiterHandler delimiterHandler) Constructs the concatenated string value of all items comprising the list the specified node belongs to. This method is called when saving anXMLConfiguration
. Then configuration nodes created for list items have to be collected again and transformed into a string defining all list elements.- Parameters:
node
- the configuration nodenodeHandler
- the reference node handlerdelimiterHandler
- the list delimiter handler of the configuration- Returns:
- a string with all values of the current list
- Throws:
ConfigurationRuntimeException
- if the list delimiter handler does not support the transformation of list items to a string
-
nameEquals
Helper method for comparing the names of two nodes.- Parameters:
n1
- node 1n2
- node 2- Returns:
- a flag whether these nodes have equal names
-
getElement
Gets the associated element.- Returns:
- the associated XML element
-