FileDocCategorySizeDatePackage
TreeWalkerImpl.javaAPI DocJava SE 6 API15210Tue Jun 10 00:22:38 BST 2008com.sun.org.apache.xerces.internal.dom

TreeWalkerImpl

public class TreeWalkerImpl extends Object implements TreeWalker
This class implements the TreeWalker interface.
xerces.internal
version
$Id: TreeWalkerImpl.java,v 1.2.6.1 2005/08/31 12:47:29 sunithareddy Exp $

Fields Summary
private boolean
fEntityReferenceExpansion
When TRUE, the children of entites references are returned in the iterator.
int
fWhatToShow
The whatToShow mask.
NodeFilter
fNodeFilter
The NodeFilter reference.
Node
fCurrentNode
The current Node.
Node
fRoot
The root Node.
Constructors Summary
public TreeWalkerImpl(Node root, int whatToShow, NodeFilter nodeFilter, boolean entityReferenceExpansion)
Public constructor

    
    //
    // Implementation Note: No state is kept except the data above
    // (fWhatToShow, fNodeFilter, fCurrentNode, fRoot) such that 
    // setters could be created for these data values and the 
    // implementation will still work.
    
    
    // 
    // Constructor
    //
    
       
       
                            
                           
                            
        fCurrentNode = root;
        fRoot = root;
        fWhatToShow = whatToShow;
        fNodeFilter = nodeFilter;
        fEntityReferenceExpansion = entityReferenceExpansion;
    
Methods Summary
shortacceptNode(org.w3c.dom.Node node)
Internal function. The node whatToShow and the filter are combined into one result.

        /***
         7.1.2.4. Filters and whatToShow flags 

         Iterator and TreeWalker apply whatToShow flags before applying Filters. If a node is rejected by the
         active whatToShow flags, a Filter will not be called to evaluate that node. When a node is rejected by
         the active whatToShow flags, children of that node will still be considered, and Filters may be called to
         evaluate them.
         ***/
                
        if (fNodeFilter == null) {
            if ( ( fWhatToShow & (1 << node.getNodeType()-1)) != 0) {
                return NodeFilter.FILTER_ACCEPT;
            } else {
                return NodeFilter.FILTER_SKIP;
            }
        } else {
            if ((fWhatToShow & (1 << node.getNodeType()-1)) != 0 ) {
                return fNodeFilter.acceptNode(node);
            } else {
                // What to show has failed. See above excerpt from spec.
                // Equivalent to FILTER_SKIP.
                return NodeFilter.FILTER_SKIP;
            }
        }
    
public org.w3c.dom.NodefirstChild()
Return the first child Node from the current node, after applying filter, whatToshow. If result is not null, set the current Node.

        
        if (fCurrentNode == null) return null;
                
        Node node = getFirstChild(fCurrentNode);
        if (node !=null) {
            fCurrentNode = node;
        }
        return node;
    
public org.w3c.dom.NodegetCurrentNode()
Return the current Node.

        return fCurrentNode;
    
public booleangetExpandEntityReferences()
Return whether children entity references are included in the iterator.

        return fEntityReferenceExpansion;
    
public org.w3c.dom.traversal.NodeFiltergetFilter()
Return the NodeFilter

        return fNodeFilter;
    
org.w3c.dom.NodegetFirstChild(org.w3c.dom.Node node)
Internal function. Return the first child Node, from the input node after applying filter, whatToshow. The current node is not consulted or set.

        if (node == null) return null;
        
        if ( !fEntityReferenceExpansion
             && node.getNodeType() == Node.ENTITY_REFERENCE_NODE)
            return null;
        Node newNode = node.getFirstChild();
        if (newNode == null)  return null;
        int accept = acceptNode(newNode);
        
        if (accept == NodeFilter.FILTER_ACCEPT)
            return newNode;
        else 
        if (accept == NodeFilter.FILTER_SKIP
            && newNode.hasChildNodes()) 
        {
            Node fChild = getFirstChild(newNode);
            
            if (fChild == null) {
                return getNextSibling(newNode, node);
            }
            return fChild;
        }
        else 
        //if (accept == NodeFilter.REJECT_NODE) 
        {
            return getNextSibling(newNode, node);
        }
        
        
    
org.w3c.dom.NodegetLastChild(org.w3c.dom.Node node)
Internal function. Return the last child Node, from the input node after applying filter, whatToshow. The current node is not consulted or set.

        
        if (node == null) return null;
        
        if ( !fEntityReferenceExpansion
             && node.getNodeType() == Node.ENTITY_REFERENCE_NODE)
            return null;
            
        Node newNode = node.getLastChild();
        if (newNode == null)  return null; 
        
        int accept = acceptNode(newNode);
        
        if (accept == NodeFilter.FILTER_ACCEPT)
            return newNode;
        else 
        if (accept == NodeFilter.FILTER_SKIP
            && newNode.hasChildNodes()) 
        {
            Node lChild = getLastChild(newNode);
            if (lChild == null) {
                return getPreviousSibling(newNode, node);
            }
            return lChild;
        }
        else 
        //if (accept == NodeFilter.REJECT_NODE) 
        {
            return getPreviousSibling(newNode, node);
        }
        
        
    
org.w3c.dom.NodegetNextSibling(org.w3c.dom.Node node)
Internal function. Return the nextSibling Node, from the input node after applying filter, whatToshow. The current node is not consulted or set.

		return getNextSibling(node, fRoot);
	
org.w3c.dom.NodegetNextSibling(org.w3c.dom.Node node, org.w3c.dom.Node root)
Internal function. Return the nextSibling Node, from the input node after applying filter, whatToshow. NEVER TRAVERSES ABOVE THE SPECIFIED ROOT NODE. The current node is not consulted or set.

        
        if (node == null || node == root) return null;
        
        Node newNode = node.getNextSibling();
        if (newNode == null) {
                
            newNode = node.getParentNode();
                
            if (newNode == null || newNode == root)  return null; 
                
            int parentAccept = acceptNode(newNode);
                
            if (parentAccept==NodeFilter.FILTER_SKIP) {
                return getNextSibling(newNode, root);
            }
                
            return null;
        }
        
        int accept = acceptNode(newNode);
        
        if (accept == NodeFilter.FILTER_ACCEPT)
            return newNode;
        else 
        if (accept == NodeFilter.FILTER_SKIP) {
            Node fChild = getFirstChild(newNode);
            if (fChild == null) {
                return getNextSibling(newNode, root);
            }
            return fChild;
        }
        else 
        //if (accept == NodeFilter.REJECT_NODE) 
        {
            return getNextSibling(newNode, root);
        }
        
    
org.w3c.dom.NodegetParentNode(org.w3c.dom.Node node)
Internal function. Return the parent Node, from the input node after applying filter, whatToshow. The current node is not consulted or set.

        
        if (node == null || node == fRoot) return null;
        
        Node newNode = node.getParentNode();
        if (newNode == null)  return null; 
                        
        int accept = acceptNode(newNode);
        
        if (accept == NodeFilter.FILTER_ACCEPT)
            return newNode;
        else 
        //if (accept == NodeFilter.SKIP_NODE) // and REJECT too.
        {
            return getParentNode(newNode);
        }
        
        
    
org.w3c.dom.NodegetPreviousSibling(org.w3c.dom.Node node)
Internal function. Return the previous sibling Node, from the input node after applying filter, whatToshow. The current node is not consulted or set.

		return getPreviousSibling(node, fRoot);
	
org.w3c.dom.NodegetPreviousSibling(org.w3c.dom.Node node, org.w3c.dom.Node root)
Internal function. Return the previousSibling Node, from the input node after applying filter, whatToshow. NEVER TRAVERSES ABOVE THE SPECIFIED ROOT NODE. The current node is not consulted or set.

        
        if (node == null || node == root) return null;
        
        Node newNode = node.getPreviousSibling();
        if (newNode == null) {
                
            newNode = node.getParentNode();
            if (newNode == null || newNode == root)  return null; 
                
            int parentAccept = acceptNode(newNode);
                
            if (parentAccept==NodeFilter.FILTER_SKIP) {
                return getPreviousSibling(newNode, root);
            }
            
            return null;
        }
        
        int accept = acceptNode(newNode);
        
        if (accept == NodeFilter.FILTER_ACCEPT)
            return newNode;
        else 
        if (accept == NodeFilter.FILTER_SKIP) {
            Node fChild =  getLastChild(newNode);
            if (fChild == null) {
                return getPreviousSibling(newNode, root);
            }
            return fChild;
        }
        else 
        //if (accept == NodeFilter.REJECT_NODE) 
        {
            return getPreviousSibling(newNode, root);
        }
        
    
public org.w3c.dom.NodegetRoot()

	return fRoot;
    
public intgetWhatToShow()
Return the whatToShow value

        return fWhatToShow;
    
public org.w3c.dom.NodelastChild()
Return the last child Node from the current node, after applying filter, whatToshow. If result is not null, set the current Node.


        if (fCurrentNode == null) return null;
                
        Node node = getLastChild(fCurrentNode);
        if (node !=null) {
            fCurrentNode = node;
        }
        return node;
    
public org.w3c.dom.NodenextNode()
Return the next Node from the current node, after applying filter, whatToshow. If result is not null, set the current Node.

        
        if (fCurrentNode == null) return null;
        
        Node result = getFirstChild(fCurrentNode);
        
        if (result != null) {
            fCurrentNode = result;
            return result;
        }
        
        result = getNextSibling(fCurrentNode);
        
        if (result != null) {
            fCurrentNode = result;
            return result;
        }
                
        // return parent's 1st sibling.
        Node parent = getParentNode(fCurrentNode);
        while (parent != null) {
            result = getNextSibling(parent);
            if (result != null) {
                fCurrentNode = result;
                return result;
            } else {
                parent = getParentNode(parent);
            }
        }
        
        // end , return null
        return null;
    
public org.w3c.dom.NodenextSibling()
Return the next sibling Node from the current node, after applying filter, whatToshow. If result is not null, set the current Node.

        if (fCurrentNode == null) return null;
                
        Node node = getNextSibling(fCurrentNode);
        if (node !=null) {
            fCurrentNode = node;
        }
        return node;
    
public org.w3c.dom.NodeparentNode()
Return the parent Node from the current node, after applying filter, whatToshow. If result is not null, set the current Node.


        if (fCurrentNode == null) return null;
                
        Node node = getParentNode(fCurrentNode);
        if (node !=null) {
            fCurrentNode = node;
        }
        return node;
        
    
public org.w3c.dom.NodepreviousNode()
Return the previous Node from the current node, after applying filter, whatToshow. If result is not null, set the current Node.

        Node result;
        
        if (fCurrentNode == null) return null;
        
        // get sibling
        result = getPreviousSibling(fCurrentNode);
        if (result == null) {
            result = getParentNode(fCurrentNode);
            if (result != null) {
                fCurrentNode = result;
                return fCurrentNode;
            } 
            return null;
        }
        
        // get the lastChild of result.
        Node lastChild  = getLastChild(result);
        
        Node prev = lastChild ;
        while (lastChild != null) {
          prev = lastChild ;
          lastChild = getLastChild(prev) ;
        }

        lastChild = prev ;
        
        // if there is a lastChild which passes filters return it.
        if (lastChild != null) {
            fCurrentNode = lastChild;
            return fCurrentNode;
        } 
        
        // otherwise return the previous sibling.
        if (result != null) {
            fCurrentNode = result;
            return fCurrentNode;
        }
        
        // otherwise return null.
        return null;
    
public org.w3c.dom.NodepreviousSibling()
Return the previous sibling Node from the current node, after applying filter, whatToshow. If result is not null, set the current Node.


        if (fCurrentNode == null) return null;
                
        Node node = getPreviousSibling(fCurrentNode);
        if (node !=null) {
            fCurrentNode = node;
        }
        return node;
    
public voidsetCurrentNode(org.w3c.dom.Node node)
Return the current Node.

        if (node == null) {
            String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NOT_SUPPORTED_ERR", null);
              throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
        }

        fCurrentNode = node;
    
public voidsetWhatShow(int whatToShow)

        fWhatToShow = whatToShow;