FileDocCategorySizeDatePackage
NodeListImpl.javaAPI DocAndroid 1.5 API3941Wed May 06 22:42:46 BST 2009com.android.mms.dom

NodeListImpl

public class NodeListImpl extends Object implements NodeList

Fields Summary
private ArrayList
mSearchNodes
private ArrayList
mStaticNodes
private Node
mRootNode
private String
mTagName
private boolean
mDeepSearch
Constructors Summary
public NodeListImpl(Node rootNode, String tagName, boolean deepSearch)
Constructs a NodeList by searching for all descendants or the direct children of a root node with a given tag name.

param
rootNode The root Node of the search.
param
tagName The tag name to be searched for. If null, all descendants will be returned.
param
deep Limit the search to the direct children of rootNode if false, to all descendants otherwise.

        mRootNode = rootNode;
        mTagName  = tagName;
        mDeepSearch = deepSearch;
    
public NodeListImpl(ArrayList nodes)
Constructs a NodeList for a given static node list.

param
nodes The static node list.

        mStaticNodes = nodes;
    
Methods Summary
private voidfillList(org.w3c.dom.Node node)
A preorder traversal is done in the following order:
  • Visit root.
  • Traverse children from left to right in preorder.
This method fills the live node list.

param
The root of preorder traversal
return
The next match

        // (Re)-initialize the container if this is the start of the search.
        // Visit the root of this iteration otherwise.
        if (node == mRootNode) {
            mSearchNodes = new ArrayList<Node>();
        } else {
            if ((mTagName == null) || node.getNodeName().equals(mTagName)) {
                mSearchNodes.add(node);
            }
        }

        // Descend one generation...
        node = node.getFirstChild();

        // ...and visit in preorder the children if we are in deep search
        // or directly add the children to the list otherwise.
        while (node != null) {
            if (mDeepSearch) {
                fillList(node);
            } else {
                if ((mTagName == null) || node.getNodeName().equals(mTagName)) {
                    mSearchNodes.add(node);
                }
            }
            node = node.getNextSibling();
        }
    
public intgetLength()

        if (mStaticNodes == null) {
            fillList(mRootNode);
            return mSearchNodes.size();
        } else {
            return mStaticNodes.size();
        }
    
public org.w3c.dom.Nodeitem(int index)

        Node node = null;
        if (mStaticNodes == null) {
            fillList(mRootNode);
            try {
                node = mSearchNodes.get(index);
            } catch (IndexOutOfBoundsException e) {
                // Do nothing and return null
            }
        } else {
            try {
                node = mStaticNodes.get(index);
            } catch (IndexOutOfBoundsException e) {
                // Do nothing and return null
            }
        }
        return node;