Class 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 Details

    • document

      private final Document document
      Stores the document to be constructed.
    • elementMapping

      private final Map<Node,Node> elementMapping
      The element mapping.
    • newElements

      private final Map<ImmutableNode,Element> newElements
      A mapping for the references for new nodes.
    • listDelimiterHandler

      private final ListDelimiterHandler listDelimiterHandler
      Stores the list delimiter handler .
  • Constructor Details

    • XMLBuilderVisitor

      public XMLBuilderVisitor(XMLDocumentHelper docHelper, ListDelimiterHandler handler)
      Creates a new instance of XMLBuilderVisitor.
      Parameters:
      docHelper - the document helper
      handler - the delimiter handler for properties with multiple values
  • Method Details

    • processDocument

      public void processDocument(ReferenceNodeHandler refHandler)
      Processes the specified document, updates element values, and adds new nodes to the hierarchy.
      Parameters:
      refHandler - the ReferenceNodeHandler
    • 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 - the ReferenceNodeHandler
    • 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 class BaseHierarchicalConfiguration.BuilderVisitor
      Parameters:
      newNode - the node to be inserted
      parent - the parent node
      sibling1 - the sibling after which the node is to be inserted; can be null if the new node is going to be the first child node
      sibling2 - the sibling before which the node is to be inserted; can be null if the new node is going to be the last child node
      refHandler - the ReferenceNodeHandler
    • update

      protected void update(ImmutableNode node, 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 class BaseHierarchicalConfiguration.BuilderVisitor
      Parameters:
      node - the current node to be processed
      reference - the reference object for this node
      refHandler - the ReferenceNodeHandler
    • updateElement

      private void updateElement(ImmutableNode node, ReferenceNodeHandler refHandler, Object value)
    • updateElement

      private void updateElement(Element element, Object value)
      Updates the node's value if it represents an element node.
      Parameters:
      element - the element
      value - the new value
    • removeReference

      private void removeReference(Node element)
      Updates the associated XML elements when a node is removed.
      Parameters:
      element - the element to be removed
    • getElement

      private Element getElement(ImmutableNode node, ReferenceNodeHandler refHandler)
      Helper method for accessing the element of the specified node.
      Parameters:
      node - the node
      refHandler - the ReferenceNodeHandler
      Returns:
      the element of this node
    • updateAttributes

      private static void updateAttributes(ImmutableNode node, Element elem)
      Helper method for updating the values of all attributes of the specified node.
      Parameters:
      node - the affected node
      elem - the element that is associated with this node
    • clearAttributes

      private static void clearAttributes(Element elem)
      Removes all attributes of the given element.
      Parameters:
      elem - the element
    • findTextNodeForUpdate

      private static Text findTextNodeForUpdate(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