Class TreeNode

  • Direct Known Subclasses:
    DocumentNode, TextNode

    public abstract class TreeNode
    extends Object
    The abstract class TreeNode representing a node in a document tree.
    Author:
    Martin Scharm
    • Field Detail

      • TEXT_TAG

        public static final String TEXT_TAG
        The node tag name for text nodes, as we will use it in XPath expressions.
        See Also:
        Constant Field Values
      • UNCHANGED

        public static final int UNCHANGED
        UNCHANGED => node hasn't changes.
        See Also:
        Constant Field Values
      • UNMAPPED

        public static final int UNMAPPED
        UNMAPPED => node wasn't mapped.
        See Also:
        Constant Field Values
      • MODIFIED

        public static final int MODIFIED
        MODIFIED => node was modified.
        See Also:
        Constant Field Values
      • SUB_MODIFIED

        public static final int SUB_MODIFIED
        SUB_MODIFIED => the corresponding subtree was modified.
        See Also:
        Constant Field Values
      • KIDSSWAPPED

        public static final int KIDSSWAPPED
        KIDSSWAPPED => the sequence of kids of this node were altered.
        See Also:
        Constant Field Values
      • SWAPPEDKID

        public static final int SWAPPEDKID
        SWAPPEDKID => this is a swapped kid.
        See Also:
        Constant Field Values
      • SUBTREEUNMAPPED

        public static final int SUBTREEUNMAPPED
        SUBTREEUNMAPPED => the whole subtree is unmapped.
        See Also:
        Constant Field Values
      • modified

        protected int modified
        The current modification state.
      • type

        protected int type
        The node type.
      • xPath

        protected String xPath
        The XPath of this node.
      • doc

        protected TreeDocument doc
        The corresponding document.
      • level

        protected int level
        The level in the tree document.
      • ownHash

        protected String ownHash
        The hash of this single node
    • Constructor Detail

      • TreeNode

        public TreeNode​(int type,
                        DocumentNode parent,
                        TreeDocument doc,
                        int level)
        Instantiates a new tree node.
        Parameters:
        type - the node type
        parent - the parent node
        doc - the corresponding document
        level - the level in the tree
    • Method Detail

      • getLevel

        public int getLevel()
        Returns the level of this node in its tree. Root has level 0.
        Returns:
        the level
      • getModification

        public int getModification()
        Returns the modification state.
        Returns:
        the modification
      • rmModification

        public void rmModification​(int mod)
        Remove a modification.
        Parameters:
        mod - the modification
      • addModification

        public void addModification​(int mod)
        Add a modification.
        Parameters:
        mod - the modification
      • setModification

        public void setModification​(int mod)
        Sets the modification.
        Parameters:
        mod - the new modification
      • hasModification

        public boolean hasModification​(int mod)
        Checks for a certain modification.
        Parameters:
        mod - the modification
        Returns:
        true, if this node has modification mod
      • getType

        public int getType()
        Gets the node type.
        Returns:
        the node type
        See Also:
        DOC_NODE, TEXT_NODE
      • getParent

        public DocumentNode getParent()
        Gets the parent node.
        Returns:
        the parent node
      • getXPath

        public String getXPath()
        Gets the XPath expression corresponding to this node.
        Returns:
        the XPath to the node
      • isRoot

        public boolean isRoot()
        Checks if this is the root of the tree.
        Returns:
        true, if this is root
      • resetModifications

        public void resetModifications()
        Resets all modifications.
      • getDocument

        public TreeDocument getDocument()
        Gets the corresponding document.
        Returns:
        the document
      • networkDiffers

        public boolean networkDiffers​(TreeNode tn,
                                      ConnectionManager conMgmr,
                                      Connection c)
        Checks if the network of two nodes differs.
        Parameters:
        tn - the node in another tree document
        conMgmr - the connection manager
        c - the connection
        Returns:
        true, if parents of these nodes are not connected.
      • contentDiffers

        public boolean contentDiffers​(TreeNode tn)
        Check if content between two nodes differs. Just compares the nodes, neglects everything else of the tree (e.g. network, kids etc).
        Parameters:
        tn - the other node to compare
        Returns:
        true, if nodes differ
      • getTagName

        public abstract String getTagName()
        Gets the tag name. For document nodes it's the actual tag name, in case of text nodes you'll receive TreeNode.TEXT_TAG.
        Returns:
        the tag name
      • getWeight

        public abstract double getWeight()
        Gets the weight of this node.
        Returns:
        the weight
      • getOwnHash

        public abstract String getOwnHash()
        Gets the hash of this single node (w/o its subtree).
        Returns:
        the hash of the node
      • getSubTreeHash

        public abstract String getSubTreeHash()
        Gets the calculated hash of the subtree rooted in this node, in TextNodes it equals the own hash.
        Returns:
        the hash of the current subtree
      • evaluate

        public abstract boolean evaluate​(ConnectionManager conMgmr)
        Evaluate the modifications of this node. Just useful for tree comparisons.
        Parameters:
        conMgmr - the connection manager
        Returns:
        true, if node was changed
      • dump

        public abstract String dump​(String prefix)
        Dump this node. Just for debugging purposes..
        Parameters:
        prefix - the prefix for a line (indention)
        Returns:
        the produced dump
      • getSubDoc

        public abstract org.jdom2.Element getSubDoc​(org.jdom2.Element parent)
        Attaches the subtree rooted in this node to the node parent. Recursively attaches its children. Will fail for parent == null && this.getType () == TreeNode.TEXT_NODE That means a text node cannot become root.
        Parameters:
        parent - the parent element which will root this node. If null, this node will be root in the document
        Returns:
        the sub doc
      • reSetupStructureDown

        protected abstract void reSetupStructureDown​(TreeDocument doc,
                                                     int numChild)
        Re-setup the document structure downwards. (e.g. recompute XPaths etc.)
        Parameters:
        doc - the document this node corresponds to
        numChild - the child number of this node
      • reSetupStructureUp

        protected abstract void reSetupStructureUp()
        Re-setup the document structure upwards. (e.g. recompute hashes etc.)
      • getNodeStats

        public abstract void getNodeStats​(HashMap<String,​Integer> map)
        Gets the node statistics of the subtree rooted in this node: tagname => number nodes having this tag name.
        Parameters:
        map - the map to write our statistics to