Class AbstractMicroNode

java.lang.Object
com.helger.xml.microdom.AbstractMicroNode
All Implemented Interfaces:
com.helger.commons.hierarchy.IHasChildren<IMicroNode>, com.helger.commons.hierarchy.IHasChildrenRecursive<IMicroNode>, com.helger.commons.hierarchy.IHasChildrenSorted<IMicroNode>, com.helger.commons.hierarchy.IHasParent<IMicroNode>, com.helger.commons.lang.ICloneable<IMicroNode>, IMicroNode
Direct Known Subclasses:
AbstractMicroNodeWithChildren, MicroCDATA, MicroComment, MicroDocumentType, MicroEntityReference, MicroProcessingInstruction, MicroText

public abstract class AbstractMicroNode extends Object implements IMicroNode
This is an abstract base class for the micro document object model. It implements a set of common methods required for all object types. Especially for the parent/child handling, the sub class AbstractMicroNodeWithChildren provides some additional features.
Author:
Philip Helger
  • Constructor Details

    • AbstractMicroNode

      public AbstractMicroNode()
  • Method Details

    • onAppendChild

      @OverrideOnDemand protected void onAppendChild(@Nonnull AbstractMicroNode aChildNode)
      Callback that is invoked once a child is to be appended.
      Parameters:
      aChildNode - The appended child node.
    • onInsertBefore

      @OverrideOnDemand protected void onInsertBefore(@Nonnull AbstractMicroNode aChildNode, @Nonnull IMicroNode aSuccessor)
      Callback that is invoked once a child is to be inserted before another child.
      Parameters:
      aChildNode - The new child node to be inserted.
      aSuccessor - The node before which the new node will be inserted.
    • onInsertAfter

      @OverrideOnDemand protected void onInsertAfter(@Nonnull AbstractMicroNode aChildNode, @Nonnull IMicroNode aPredecessor)
      Callback that is invoked once a child is to be inserted after another child.
      Parameters:
      aChildNode - The new child node to be inserted.
      aPredecessor - The node after which the new node will be inserted.
    • onInsertAtIndex

      @OverrideOnDemand protected void onInsertAtIndex(@Nonnegative int nIndex, @Nonnull AbstractMicroNode aChildNode)
      Callback that is invoked once a child is to be inserted at the specified index.
      Parameters:
      nIndex - The index where the node should be inserted.
      aChildNode - The new child node to be inserted.
    • appendChild

      @Nullable public final <NODETYPE extends IMicroNode> NODETYPE appendChild(@Nullable NODETYPE aChildNode)
      Description copied from interface: IMicroNode
      Append any child to the node.
      Specified by:
      appendChild in interface IMicroNode
      Type Parameters:
      NODETYPE - Parameter type == return type
      Parameters:
      aChildNode - The child node to append. May be null.
      Returns:
      The appended node, or null if the parameter was null.
    • insertBefore

      @Nullable public final <NODETYPE extends IMicroNode> NODETYPE insertBefore(@Nullable NODETYPE aChildNode, @Nonnull IMicroNode aSuccessor)
      Description copied from interface: IMicroNode
      Insert an existing node before a certain child node of this.
      Specified by:
      insertBefore in interface IMicroNode
      Type Parameters:
      NODETYPE - Parameter type == return type
      Parameters:
      aChildNode - The new child node to be inserted.
      aSuccessor - The node before which the new node will be inserted.
      Returns:
      The newly inserted node
    • insertAfter

      @Nullable public final <NODETYPE extends IMicroNode> NODETYPE insertAfter(@Nullable NODETYPE aChildNode, @Nonnull IMicroNode aPredecessor)
      Description copied from interface: IMicroNode
      Insert an existing node after a certain child node of this.
      Specified by:
      insertAfter in interface IMicroNode
      Type Parameters:
      NODETYPE - Parameter type == return type
      Parameters:
      aChildNode - The new child node to be inserted.
      aPredecessor - The node after which the new node will be inserted.
      Returns:
      The newly inserted node
    • insertAtIndex

      @Nullable public final <NODETYPE extends IMicroNode> NODETYPE insertAtIndex(@Nonnegative int nIndex, @Nullable NODETYPE aChildNode)
      Description copied from interface: IMicroNode
      Insert an existing node as a child at the specified index.
      Specified by:
      insertAtIndex in interface IMicroNode
      Type Parameters:
      NODETYPE - Parameter type == return type
      Parameters:
      nIndex - The index to insert. Must be ≥ 0.
      aChildNode - The new child node to be inserted.
      Returns:
      The newly inserted node
    • onRemoveChild

      @OverrideOnDemand @Nonnull protected com.helger.commons.state.EChange onRemoveChild(IMicroNode aChild)
      Callback when a child is removed.
      Parameters:
      aChild - The child that is removed.
      Returns:
      EChange.CHANGED if something changed
    • removeChild

      @Nonnull public final com.helger.commons.state.EChange removeChild(@Nonnull IMicroNode aChild)
      Description copied from interface: IMicroNode
      Remove the passed child.
      Specified by:
      removeChild in interface IMicroNode
      Parameters:
      aChild - The child to be removed. May not be null.
      Returns:
      EChange.CHANGED if the child was successfully removed, EChange.UNCHANGED otherwise.
    • onRemoveChildAtIndex

      @OverrideOnDemand @Nonnull protected com.helger.commons.state.EChange onRemoveChildAtIndex(int nIndex)
      Remove the child not at the specified index.
      Parameters:
      nIndex - The 0-based index of the item to be removed.
      Returns:
      EChange.CHANGED if the node was successfully removed, EChange.UNCHANGED otherwise.
    • removeChildAtIndex

      @Nonnull public final com.helger.commons.state.EChange removeChildAtIndex(@Nonnegative int nIndex)
      Description copied from interface: IMicroNode
      Remove the child not at the specified index.
      Specified by:
      removeChildAtIndex in interface IMicroNode
      Parameters:
      nIndex - The 0-based index of the item to be removed.
      Returns:
      EChange.CHANGED if the node was successfully removed, EChange.UNCHANGED otherwise.
    • onRemoveAllChildren

      @OverrideOnDemand @Nonnull protected com.helger.commons.state.EChange onRemoveAllChildren()
      Remove all children from this node.
      Returns:
      EChange.CHANGED if at least one child was present, and was successfully removed, EChange.UNCHANGED otherwise.
    • removeAllChildren

      @Nonnull public final com.helger.commons.state.EChange removeAllChildren()
      Description copied from interface: IMicroNode
      Remove all children from this node.
      Specified by:
      removeAllChildren in interface IMicroNode
      Returns:
      EChange.CHANGED if at least one child was present, and was successfully removed, EChange.UNCHANGED otherwise.
    • hasChildren

      @OverrideOnDemand public boolean hasChildren()
      Specified by:
      hasChildren in interface com.helger.commons.hierarchy.IHasChildren<IMicroNode>
    • getAllChildren

      @OverrideOnDemand @Nullable public com.helger.commons.collection.impl.ICommonsList<IMicroNode> getAllChildren()
      Description copied from interface: IMicroNode
      Get a list of all direct child nodes.
      Specified by:
      getAllChildren in interface com.helger.commons.hierarchy.IHasChildren<IMicroNode>
      Specified by:
      getAllChildren in interface com.helger.commons.hierarchy.IHasChildrenSorted<IMicroNode>
      Specified by:
      getAllChildren in interface IMicroNode
      Returns:
      May be null if the node has no children.
    • getChildren

      @OverrideOnDemand @Nullable public com.helger.commons.collection.impl.ICommonsIterable<IMicroNode> getChildren()
      Specified by:
      getChildren in interface com.helger.commons.hierarchy.IHasChildren<IMicroNode>
    • forAllChildren

      public void forAllChildren(@Nonnull Consumer<? super IMicroNode> aConsumer)
      Specified by:
      forAllChildren in interface com.helger.commons.hierarchy.IHasChildren<IMicroNode>
    • forAllChildrenBreakable

      @Nonnull public com.helger.commons.state.EContinue forAllChildrenBreakable(@Nonnull Function<? super IMicroNode,com.helger.commons.state.EContinue> aConsumer)
      Specified by:
      forAllChildrenBreakable in interface com.helger.commons.hierarchy.IHasChildren<IMicroNode>
    • forAllChildren

      public void forAllChildren(@Nonnull Predicate<? super IMicroNode> aFilter, @Nonnull Consumer<? super IMicroNode> aConsumer)
      Specified by:
      forAllChildren in interface com.helger.commons.hierarchy.IHasChildren<IMicroNode>
    • forAllChildrenMapped

      public <DSTTYPE> void forAllChildrenMapped(@Nonnull Predicate<? super IMicroNode> aFilter, @Nonnull Function<? super IMicroNode,? extends DSTTYPE> aMapper, @Nonnull Consumer<? super DSTTYPE> aConsumer)
      Specified by:
      forAllChildrenMapped in interface com.helger.commons.hierarchy.IHasChildren<IMicroNode>
    • getChildAtIndex

      @OverrideOnDemand @Nullable public IMicroNode getChildAtIndex(@Nonnegative int nIndex)
      Specified by:
      getChildAtIndex in interface com.helger.commons.hierarchy.IHasChildrenSorted<IMicroNode>
    • getChildCount

      @OverrideOnDemand @Nonnegative public int getChildCount()
      Specified by:
      getChildCount in interface com.helger.commons.hierarchy.IHasChildren<IMicroNode>
    • getFirstChild

      @OverrideOnDemand @Nullable public IMicroNode getFirstChild()
      Specified by:
      getFirstChild in interface com.helger.commons.hierarchy.IHasChildrenSorted<IMicroNode>
      Specified by:
      getFirstChild in interface IMicroNode
      Returns:
      The first child node of this node, or null if this node has no children.
    • findFirstChild

      @Nullable public IMicroNode findFirstChild(@Nonnull Predicate<? super IMicroNode> aFilter)
      Specified by:
      findFirstChild in interface com.helger.commons.hierarchy.IHasChildrenSorted<IMicroNode>
    • findFirstChildMapped

      @Nullable public <DSTTYPE> DSTTYPE findFirstChildMapped(@Nonnull Predicate<? super IMicroNode> aFilter, @Nonnull Function<? super IMicroNode,? extends DSTTYPE> aMapper)
      Specified by:
      findFirstChildMapped in interface com.helger.commons.hierarchy.IHasChildrenSorted<IMicroNode>
    • getLastChild

      @OverrideOnDemand @Nullable public IMicroNode getLastChild()
      Specified by:
      getLastChild in interface com.helger.commons.hierarchy.IHasChildrenSorted<IMicroNode>
      Specified by:
      getLastChild in interface IMicroNode
      Returns:
      The last child node of this node, or null if this node has no children.
    • getPreviousSibling

      @Nullable public final IMicroNode getPreviousSibling()
      Specified by:
      getPreviousSibling in interface IMicroNode
      Returns:
      The previous node on the same level as this node, or null if this node has no preceding siblings.
    • getNextSibling

      @Nullable public final IMicroNode getNextSibling()
      Specified by:
      getNextSibling in interface IMicroNode
      Returns:
      The next node on the same level as this node, or null if this node has no succeeding siblings.
    • hasParent

      public final boolean hasParent()
      Specified by:
      hasParent in interface com.helger.commons.hierarchy.IHasParent<IMicroNode>
      Specified by:
      hasParent in interface IMicroNode
      Returns:
      true if this node has a parent node assigned, false otherwise.
    • getParent

      @Nullable public final IMicroNode getParent()
      Specified by:
      getParent in interface com.helger.commons.hierarchy.IHasParent<IMicroNode>
      Specified by:
      getParent in interface IMicroNode
      Returns:
      May be null.
    • internalResetParentNode

      protected final void internalResetParentNode()
    • internalSetParentNode

      protected final void internalSetParentNode(@Nonnull AbstractMicroNodeWithChildren aParentNode)
    • detachFromParent

      @Nonnull public final IMicroNode detachFromParent()
      Description copied from interface: IMicroNode
      Detach this node from the parent node so it can be inserted into another node without problems. Otherwise you would get an IllegalStateException if adding this node again to another parent since each node can only have one parent.
      Specified by:
      detachFromParent in interface IMicroNode
      Returns:
      this
    • findParentElement

      @Nullable public IMicroElement findParentElement(@Nonnull Predicate<? super IMicroElement> aFilter)
      Specified by:
      findParentElement in interface IMicroNode
    • isDocument

      public final boolean isDocument()
      Specified by:
      isDocument in interface IMicroNode
      Returns:
      true if this node can safely be casted to IMicroDocument.
    • isDocumentType

      public final boolean isDocumentType()
      Specified by:
      isDocumentType in interface IMicroNode
      Returns:
      true if this node can safely be casted to IMicroDocumentType.
    • isText

      public final boolean isText()
      Specified by:
      isText in interface IMicroNode
      Returns:
      true if this node can safely be casted to IMicroText.
    • isCDATA

      public final boolean isCDATA()
      Specified by:
      isCDATA in interface IMicroNode
      Returns:
      true if this node can safely be casted to IMicroCDATA.
    • isComment

      public final boolean isComment()
      Specified by:
      isComment in interface IMicroNode
      Returns:
      true if this node can safely be casted to IMicroComment.
    • isEntityReference

      public final boolean isEntityReference()
      Specified by:
      isEntityReference in interface IMicroNode
      Returns:
      true if this node can safely be casted to IMicroEntityReference.
    • isElement

      public final boolean isElement()
      Specified by:
      isElement in interface IMicroNode
      Returns:
      true if this node can safely be casted to IMicroElement.
    • isProcessingInstruction

      public final boolean isProcessingInstruction()
      Specified by:
      isProcessingInstruction in interface IMicroNode
      Returns:
      true if this node can safely be casted to IMicroProcessingInstruction.
    • isContainer

      public final boolean isContainer()
      Specified by:
      isContainer in interface IMicroNode
      Returns:
      true if this node can safely be casted to IMicroContainer.
    • internalTriggerEvent

      protected final void internalTriggerEvent(@Nonnull EMicroEvent eEventType, @Nonnull IMicroEvent aEvent)
    • onEvent

      protected final void onEvent(@Nonnull EMicroEvent eEventType, @Nonnull IMicroNode aSourceNode, @Nonnull IMicroNode aTargetNode)
    • registerEventTarget

      @Nonnull public com.helger.commons.state.EChange registerEventTarget(@Nonnull EMicroEvent eEventType, @Nonnull IMicroEventTarget aTarget)
      Description copied from interface: IMicroNode
      Register a specific MicroDOM event listener. One event listener can only be attached once to an event!
      Specified by:
      registerEventTarget in interface IMicroNode
      Parameters:
      eEventType - The event type. May not be null.
      aTarget - The event target to be added. May not be null.
      Returns:
      EChange.CHANGED if the event listener was registered, EChange.UNCHANGED otherwise.
    • unregisterEventTarget

      @Nonnull public com.helger.commons.state.EChange unregisterEventTarget(@Nonnull EMicroEvent eEventType, @Nonnull IMicroEventTarget aTarget)
      Description copied from interface: IMicroNode
      Unregister a specific MicroDOM event listener.
      Specified by:
      unregisterEventTarget in interface IMicroNode
      Parameters:
      eEventType - The event type. May not be null.
      aTarget - The event target to be added. May not be null.
      Returns:
      EChange.CHANGED if the event listener was unregistered, EChange.UNCHANGED otherwise.
    • getAllEventTargets

      @Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsMap<EMicroEvent,com.helger.commons.callback.CallbackList<IMicroEventTarget>> getAllEventTargets()
      Specified by:
      getAllEventTargets in interface IMicroNode
      Returns:
      A map of all registered event targets. Never null.
    • getAllEventTargets

      @Nonnull @ReturnsMutableCopy public com.helger.commons.callback.CallbackList<IMicroEventTarget> getAllEventTargets(@Nullable EMicroEvent eEvent)
      Description copied from interface: IMicroNode
      Get all event targets for a certain event.
      Specified by:
      getAllEventTargets in interface IMicroNode
      Parameters:
      eEvent - The event to be queried. May be null.
      Returns:
      A map of all registered event targets. Never null.
    • toString

      public String toString()
      Overrides:
      toString in class Object