Class XMLListReference


  • final class XMLListReference
    extends java.lang.Object

    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 Detail

      • element

        private final org.w3c.dom.Element element
        The wrapped XML element.
    • Constructor Detail

      • XMLListReference

        private XMLListReference​(org.w3c.dom.Element e)
        Private constructor. No instances can be created from other classes.
        Parameters:
        e - the associated element
    • Method Detail

      • assignListReference

        public static void assignListReference​(java.util.Map<ImmutableNode,​java.lang.Object> refs,
                                               ImmutableNode node,
                                               org.w3c.dom.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 references
        node - the affected configuration node
        elem - the current XML element
      • hasListReference

        private static boolean hasListReference​(ImmutableNode node,
                                                ReferenceNodeHandler handler)
        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 checked
        handler - the reference handler
        Returns:
        a flag whether this node has a list reference
      • isFirstListItem

        public static boolean isFirstListItem​(ImmutableNode node,
                                              ReferenceNodeHandler handler)
        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, so isListNode(ImmutableNode, ReferenceNodeHandler) must have returned true for it.
        Parameters:
        node - the configuration node
        handler - the reference node handler
        Returns:
        a flag whether this is the first node of a list
      • isListNode

        public static boolean isListNode​(ImmutableNode node,
                                         ReferenceNodeHandler handler)
        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 node
        handler - the reference node handler
        Returns:
        a flag whether this node is relevant for list handling
      • listValue

        public static java.lang.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 an XMLConfiguration. 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 node
        nodeHandler - the reference node handler
        delimiterHandler - 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

        private static boolean nameEquals​(ImmutableNode n1,
                                          ImmutableNode n2)
        Helper method for comparing the names of two nodes.
        Parameters:
        n1 - node 1
        n2 - node 2
        Returns:
        a flag whether these nodes have equal names
      • getElement

        public org.w3c.dom.Element getElement()
        Gets the associated element.
        Returns:
        the associated XML element