org.ozoneDB.xml.dom
Class CollectionImpl

java.lang.Object
  |
  +--org.ozoneDB.xml.dom.CollectionImpl
All Implemented Interfaces:
org.w3c.dom.html.HTMLCollection

public class CollectionImpl
extends java.lang.Object
implements org.w3c.dom.html.HTMLCollection

Implements a live collection of elements. This collection is based on the HTMLCollection defined for HTML documents but works with XML documents.

The collection is defined in terms of a root element and the elements to look for under this root. Only elements of the specified type are contained in the collection. Elements are returned by index or by identifier (the id attribute). The collection is live, meaning that changes to the document tree are immediately reflected in the collection. The collection is not optimized for traversing large document trees.

The collection has to meet two requirements: it has to be live, and it has to traverse depth first and always return results in that order. As such, using an object container (such as Vector) is expensive on insert/remove operations. Instead, the collection has been implemented using three traversing functions. As a result, operations on large documents will result in traversal of the entire document tree and consume a considerable amount of time. *

* Note that synchronization on the traversed document cannot be achieved. The document itself cannot be locked, and locking each traversed node is likely to lead to a dead lock condition. Therefore, there is a chance of the document being changed as results are fetched; in all likelihood, the results might be out dated, but not erroneous.

Used to implement both org.openxml.XMLCollection and org.openxml.dom.html.HTMLAnchorElementImpl. *

Version:
$Revision: 1.1 $ $Date: 2001/12/18 11:03:24 $
Author:
Assaf Arkin
See Also:
HTMLCollection

Constructor Summary
CollectionImpl(org.w3c.dom.Element topLevel)
          Hidden constructor used by derived classes that might have different _lookfor properties.
CollectionImpl(org.w3c.dom.Element topLevel, java.lang.String lookFor)
          Construct a new collection that retrieves element of the specific type (lookFor) from the specific document portion (topLevel).
 
Method Summary
protected  boolean collectionMatch(org.w3c.dom.Element elem, java.lang.String name)
          Determines if current element matches based on what we're looking for.
 int getLength()
          Returns the length of the collection.
 org.w3c.dom.Node item(int index)
          Retrieves the indexed node from the collection.
 org.w3c.dom.Node namedItem(java.lang.String name)
          Retrieves the named node from the collection.
protected  boolean recurse()
          Returns true if scanning methods should iterate through the collection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CollectionImpl

public CollectionImpl(org.w3c.dom.Element topLevel,
                      java.lang.String lookFor)
Construct a new collection that retrieves element of the specific type (lookFor) from the specific document portion (topLevel).

Parameters:
topLevel - The element underneath which the collection exists
lookFor - Tag of element to look for

CollectionImpl

public CollectionImpl(org.w3c.dom.Element topLevel)
Hidden constructor used by derived classes that might have different _lookfor properties.

Parameters:
topLevel - The element underneath which the collection exists
Method Detail

getLength

public final int getLength()
Returns the length of the collection. This method might traverse the entire document tree.

Specified by:
getLength in interface org.w3c.dom.html.HTMLCollection
Returns:
Length of the collection

item

public final org.w3c.dom.Node item(int index)
Retrieves the indexed node from the collection. Nodes are numbered in tree order - depth-first traversal order. This method might traverse the entire document tree.

Specified by:
item in interface org.w3c.dom.html.HTMLCollection
Parameters:
index - The index of the node to return
Returns:
The specified node or null if no such node found

namedItem

public final org.w3c.dom.Node namedItem(java.lang.String name)
Retrieves the named node from the collection. The name is matched case sensitive against the id attribute of each element in the collection, returning the first match. The tree is traversed in depth-first order. This method might traverse the entire document tree.

Specified by:
namedItem in interface org.w3c.dom.html.HTMLCollection
Parameters:
name - The name of the node to return
Returns:
The specified node or null if no such node found

recurse

protected boolean recurse()
Returns true if scanning methods should iterate through the collection. When looking for elements in the document, recursing is needed to traverse the full document tree. When looking inside a specific element (e.g. for a cell inside a row), recursing can lead to erroneous results.

Returns:
True if methods should recurse to traverse entire tree

collectionMatch

protected boolean collectionMatch(org.w3c.dom.Element elem,
                                  java.lang.String name)
Determines if current element matches based on what we're looking for. The element is passed along with an optional identifier name. If the element is the one we're looking for, return true. If the name is also specified, the name must match the id attribute.

Parameters:
elem - The current element
name - The identifier name or null
Returns:
The element matches what we're looking for


Copyright © 2002 The Ozone Database Project - www.ozone-db.org. All Rights Reserved.