Package com.helger.xml.microdom
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,Serializable
- 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
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description AbstractMicroNode()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <NODETYPE extends IMicroNode>
NODETYPEappendChild(NODETYPE aChildNode)Append any child to the node.IMicroNodedetachFromParent()Detach this node from the parent node so it can be inserted into another node without problems.IMicroNodefindFirstChild(Predicate<? super IMicroNode> aFilter)<DSTTYPE> DSTTYPEfindFirstChildMapped(Predicate<? super IMicroNode> aFilter, Function<? super IMicroNode,? extends DSTTYPE> aMapper)IMicroElementfindParentElement(Predicate<? super IMicroElement> aFilter)voidforAllChildren(Consumer<? super IMicroNode> aConsumer)voidforAllChildren(Predicate<? super IMicroNode> aFilter, Consumer<? super IMicroNode> aConsumer)com.helger.commons.state.EContinueforAllChildrenBreakable(Function<? super IMicroNode,com.helger.commons.state.EContinue> aConsumer)<DSTTYPE> voidforAllChildrenMapped(Predicate<? super IMicroNode> aFilter, Function<? super IMicroNode,? extends DSTTYPE> aMapper, Consumer<? super DSTTYPE> aConsumer)com.helger.commons.collection.impl.ICommonsList<IMicroNode>getAllChildren()Get a list of all direct child nodes.com.helger.commons.collection.impl.ICommonsMap<EMicroEvent,com.helger.commons.callback.CallbackList<IMicroEventTarget>>getAllEventTargets()com.helger.commons.callback.CallbackList<IMicroEventTarget>getAllEventTargets(EMicroEvent eEvent)Get all event targets for a certain event.IMicroNodegetChildAtIndex(int nIndex)intgetChildCount()com.helger.commons.collection.impl.ICommonsIterable<IMicroNode>getChildren()IMicroNodegetFirstChild()IMicroNodegetLastChild()IMicroNodegetNextSibling()IMicroNodegetParent()IMicroNodegetPreviousSibling()booleanhasChildren()booleanhasParent()<NODETYPE extends IMicroNode>
NODETYPEinsertAfter(NODETYPE aChildNode, IMicroNode aPredecessor)Insert an existing node after a certain child node of this.<NODETYPE extends IMicroNode>
NODETYPEinsertAtIndex(int nIndex, NODETYPE aChildNode)Insert an existing node as a child at the specified index.<NODETYPE extends IMicroNode>
NODETYPEinsertBefore(NODETYPE aChildNode, IMicroNode aSuccessor)Insert an existing node before a certain child node of this.protected voidinternalResetParentNode()protected voidinternalSetParentNode(AbstractMicroNodeWithChildren aParentNode)protected voidinternalTriggerEvent(EMicroEvent eEventType, IMicroEvent aEvent)booleanisCDATA()booleanisComment()booleanisContainer()booleanisDocument()booleanisDocumentType()booleanisElement()booleanisEntityReference()booleanisProcessingInstruction()booleanisText()protected voidonAppendChild(AbstractMicroNode aChildNode)Callback that is invoked once a child is to be appended.protected voidonEvent(EMicroEvent eEventType, IMicroNode aSourceNode, IMicroNode aTargetNode)protected voidonInsertAfter(AbstractMicroNode aChildNode, IMicroNode aPredecessor)Callback that is invoked once a child is to be inserted after another child.protected voidonInsertAtIndex(int nIndex, AbstractMicroNode aChildNode)Callback that is invoked once a child is to be inserted at the specified index.protected voidonInsertBefore(AbstractMicroNode aChildNode, IMicroNode aSuccessor)Callback that is invoked once a child is to be inserted before another child.protected com.helger.commons.state.EChangeonRemoveAllChildren()Remove all children from this node.protected com.helger.commons.state.EChangeonRemoveChild(IMicroNode aChild)Callback when a child is removed.protected com.helger.commons.state.EChangeonRemoveChildAtIndex(int nIndex)Remove the child not at the specified index.com.helger.commons.state.EChangeregisterEventTarget(EMicroEvent eEventType, IMicroEventTarget aTarget)Register a specific MicroDOM event listener.com.helger.commons.state.EChangeremoveAllChildren()Remove all children from this node.com.helger.commons.state.EChangeremoveChild(IMicroNode aChild)Remove the passed child.com.helger.commons.state.EChangeremoveChildAtIndex(int nIndex)Remove the child not at the specified index.StringtoString()com.helger.commons.state.EChangeunregisterEventTarget(EMicroEvent eEventType, IMicroEventTarget aTarget)Unregister a specific MicroDOM event listener.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.helger.commons.hierarchy.IHasChildrenRecursive
forAllChildrenRecursive, forAllChildrenRecursive
-
Methods inherited from interface com.helger.xml.microdom.IMicroNode
appendCDATA, appendCDATA, appendCDATA, appendCDATAWithConversion, appendChildren, appendChildren, appendComment, appendComment, appendComment, appendCommentWithConversion, appendContainer, appendElement, appendElement, appendEntityReference, appendIgnorableWhitespaceText, appendIgnorableWhitespaceText, appendIgnorableWhitespaceText, appendProcessingInstruction, appendText, appendText, appendText, appendTextWithConversion, containsAnyChild, getAllChildrenRecursive, getNodeName, getNodeValue, getParentElementWithName, getParentElementWithName, getType, isEqualContent, replaceChild
-
-
-
-
Method Detail
-
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:IMicroNodeAppend any child to the node.- Specified by:
appendChildin interfaceIMicroNode- Type Parameters:
NODETYPE- Parameter type == return type- Parameters:
aChildNode- The child node to append. May benull.- Returns:
- The appended node, or
nullif the parameter wasnull.
-
insertBefore
@Nullable public final <NODETYPE extends IMicroNode> NODETYPE insertBefore(@Nullable NODETYPE aChildNode, @Nonnull IMicroNode aSuccessor)
Description copied from interface:IMicroNodeInsert an existing node before a certain child node of this.- Specified by:
insertBeforein interfaceIMicroNode- 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:IMicroNodeInsert an existing node after a certain child node of this.- Specified by:
insertAfterin interfaceIMicroNode- 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:IMicroNodeInsert an existing node as a child at the specified index.- Specified by:
insertAtIndexin interfaceIMicroNode- 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.CHANGEDif something changed
-
removeChild
@Nonnull public final com.helger.commons.state.EChange removeChild(@Nonnull IMicroNode aChild)
Description copied from interface:IMicroNodeRemove the passed child.- Specified by:
removeChildin interfaceIMicroNode- Parameters:
aChild- The child to be removed. May not benull.- Returns:
EChange.CHANGEDif the child was successfully removed,EChange.UNCHANGEDotherwise.
-
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.CHANGEDif the node was successfully removed,EChange.UNCHANGEDotherwise.
-
removeChildAtIndex
@Nonnull public final com.helger.commons.state.EChange removeChildAtIndex(@Nonnegative int nIndex)
Description copied from interface:IMicroNodeRemove the child not at the specified index.- Specified by:
removeChildAtIndexin interfaceIMicroNode- Parameters:
nIndex- The 0-based index of the item to be removed.- Returns:
EChange.CHANGEDif the node was successfully removed,EChange.UNCHANGEDotherwise.
-
onRemoveAllChildren
@OverrideOnDemand @Nonnull protected com.helger.commons.state.EChange onRemoveAllChildren()
Remove all children from this node.- Returns:
EChange.CHANGEDif at least one child was present, and was successfully removed,EChange.UNCHANGEDotherwise.
-
removeAllChildren
@Nonnull public final com.helger.commons.state.EChange removeAllChildren()
Description copied from interface:IMicroNodeRemove all children from this node.- Specified by:
removeAllChildrenin interfaceIMicroNode- Returns:
EChange.CHANGEDif at least one child was present, and was successfully removed,EChange.UNCHANGEDotherwise.
-
hasChildren
@OverrideOnDemand public boolean hasChildren()
- Specified by:
hasChildrenin interfacecom.helger.commons.hierarchy.IHasChildren<IMicroNode>
-
getAllChildren
@OverrideOnDemand @Nullable public com.helger.commons.collection.impl.ICommonsList<IMicroNode> getAllChildren()
Description copied from interface:IMicroNodeGet a list of all direct child nodes.- Specified by:
getAllChildrenin interfacecom.helger.commons.hierarchy.IHasChildren<IMicroNode>- Specified by:
getAllChildrenin interfacecom.helger.commons.hierarchy.IHasChildrenSorted<IMicroNode>- Specified by:
getAllChildrenin interfaceIMicroNode- Returns:
- May be
nullif the node has no children.
-
getChildren
@OverrideOnDemand @Nullable public com.helger.commons.collection.impl.ICommonsIterable<IMicroNode> getChildren()
- Specified by:
getChildrenin interfacecom.helger.commons.hierarchy.IHasChildren<IMicroNode>
-
forAllChildren
public void forAllChildren(@Nonnull Consumer<? super IMicroNode> aConsumer)
- Specified by:
forAllChildrenin interfacecom.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:
forAllChildrenBreakablein interfacecom.helger.commons.hierarchy.IHasChildren<IMicroNode>
-
forAllChildren
public void forAllChildren(@Nonnull Predicate<? super IMicroNode> aFilter, @Nonnull Consumer<? super IMicroNode> aConsumer)
- Specified by:
forAllChildrenin interfacecom.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:
forAllChildrenMappedin interfacecom.helger.commons.hierarchy.IHasChildren<IMicroNode>
-
getChildAtIndex
@OverrideOnDemand @Nullable public IMicroNode getChildAtIndex(@Nonnegative int nIndex)
- Specified by:
getChildAtIndexin interfacecom.helger.commons.hierarchy.IHasChildrenSorted<IMicroNode>
-
getChildCount
@OverrideOnDemand @Nonnegative public int getChildCount()
- Specified by:
getChildCountin interfacecom.helger.commons.hierarchy.IHasChildren<IMicroNode>
-
getFirstChild
@OverrideOnDemand @Nullable public IMicroNode getFirstChild()
- Specified by:
getFirstChildin interfacecom.helger.commons.hierarchy.IHasChildrenSorted<IMicroNode>- Specified by:
getFirstChildin interfaceIMicroNode- Returns:
- The first child node of this node, or
nullif this node has no children.
-
findFirstChild
@Nullable public IMicroNode findFirstChild(@Nonnull Predicate<? super IMicroNode> aFilter)
- Specified by:
findFirstChildin interfacecom.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:
findFirstChildMappedin interfacecom.helger.commons.hierarchy.IHasChildrenSorted<IMicroNode>
-
getLastChild
@OverrideOnDemand @Nullable public IMicroNode getLastChild()
- Specified by:
getLastChildin interfacecom.helger.commons.hierarchy.IHasChildrenSorted<IMicroNode>- Specified by:
getLastChildin interfaceIMicroNode- Returns:
- The last child node of this node, or
nullif this node has no children.
-
getPreviousSibling
@Nullable public final IMicroNode getPreviousSibling()
- Specified by:
getPreviousSiblingin interfaceIMicroNode- Returns:
- The previous node on the same level as this node, or
nullif this node has no preceding siblings.
-
getNextSibling
@Nullable public final IMicroNode getNextSibling()
- Specified by:
getNextSiblingin interfaceIMicroNode- Returns:
- The next node on the same level as this node, or
nullif this node has no succeeding siblings.
-
hasParent
public final boolean hasParent()
- Specified by:
hasParentin interfacecom.helger.commons.hierarchy.IHasParent<IMicroNode>- Specified by:
hasParentin interfaceIMicroNode- Returns:
trueif this node has a parent node assigned,falseotherwise.
-
getParent
@Nullable public final IMicroNode getParent()
- Specified by:
getParentin interfacecom.helger.commons.hierarchy.IHasParent<IMicroNode>- Specified by:
getParentin interfaceIMicroNode- 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:IMicroNodeDetach this node from the parent node so it can be inserted into another node without problems. Otherwise you would get anIllegalStateExceptionif adding this node again to another parent since each node can only have one parent.- Specified by:
detachFromParentin interfaceIMicroNode- Returns:
- this
-
findParentElement
@Nullable public IMicroElement findParentElement(@Nonnull Predicate<? super IMicroElement> aFilter)
- Specified by:
findParentElementin interfaceIMicroNode
-
isDocument
public final boolean isDocument()
- Specified by:
isDocumentin interfaceIMicroNode- Returns:
trueif this node can safely be casted toIMicroDocument.
-
isDocumentType
public final boolean isDocumentType()
- Specified by:
isDocumentTypein interfaceIMicroNode- Returns:
trueif this node can safely be casted toIMicroDocumentType.
-
isText
public final boolean isText()
- Specified by:
isTextin interfaceIMicroNode- Returns:
trueif this node can safely be casted toIMicroText.
-
isCDATA
public final boolean isCDATA()
- Specified by:
isCDATAin interfaceIMicroNode- Returns:
trueif this node can safely be casted toIMicroCDATA.
-
isComment
public final boolean isComment()
- Specified by:
isCommentin interfaceIMicroNode- Returns:
trueif this node can safely be casted toIMicroComment.
-
isEntityReference
public final boolean isEntityReference()
- Specified by:
isEntityReferencein interfaceIMicroNode- Returns:
trueif this node can safely be casted toIMicroEntityReference.
-
isElement
public final boolean isElement()
- Specified by:
isElementin interfaceIMicroNode- Returns:
trueif this node can safely be casted toIMicroElement.
-
isProcessingInstruction
public final boolean isProcessingInstruction()
- Specified by:
isProcessingInstructionin interfaceIMicroNode- Returns:
trueif this node can safely be casted toIMicroProcessingInstruction.
-
isContainer
public final boolean isContainer()
- Specified by:
isContainerin interfaceIMicroNode- Returns:
trueif this node can safely be casted toIMicroContainer.
-
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:IMicroNodeRegister a specific MicroDOM event listener. One event listener can only be attached once to an event!- Specified by:
registerEventTargetin interfaceIMicroNode- Parameters:
eEventType- The event type. May not benull.aTarget- The event target to be added. May not benull.- Returns:
EChange.CHANGEDif the event listener was registered,EChange.UNCHANGEDotherwise.
-
unregisterEventTarget
@Nonnull public com.helger.commons.state.EChange unregisterEventTarget(@Nonnull EMicroEvent eEventType, @Nonnull IMicroEventTarget aTarget)
Description copied from interface:IMicroNodeUnregister a specific MicroDOM event listener.- Specified by:
unregisterEventTargetin interfaceIMicroNode- Parameters:
eEventType- The event type. May not benull.aTarget- The event target to be added. May not benull.- Returns:
EChange.CHANGEDif the event listener was unregistered,EChange.UNCHANGEDotherwise.
-
getAllEventTargets
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsMap<EMicroEvent,com.helger.commons.callback.CallbackList<IMicroEventTarget>> getAllEventTargets()
- Specified by:
getAllEventTargetsin interfaceIMicroNode- 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:IMicroNodeGet all event targets for a certain event.- Specified by:
getAllEventTargetsin interfaceIMicroNode- Parameters:
eEvent- The event to be queried. May benull.- Returns:
- A map of all registered event targets. Never
null.
-
-