org.jdom.contrib.ids
Class IdDocument

java.lang.Object
  |
  +--org.jdom.Document
        |
        +--org.jdom.contrib.ids.IdDocument

public class IdDocument
extends org.jdom.Document

IdDocument extends the default JDOM document to support looking up elements using their ID attribute.

Instances of this class should not be created directly but through the IdFactory. Using this factory ensures that the document is made of IdElement instances which update the look-up table when the element attribute list is updated.

The method getElementById(java.lang.String) allows looking up an element in the document given the value of its ID attribute. Instead of scanning the whole document when searching for an element, IdDocument uses a lookup table for fast direct access to the elements. Hence, applications using this method should see their performances improved compared to walking the document tree.

Author:
Laurent Bihanic
See Also:
Serialized Form

Fields inherited from class org.jdom.Document
baseURI
 
Constructor Summary
IdDocument(org.jdom.Element root)
           Creates a new Document, with the supplied Element as the root element, and no document type declaration.
IdDocument(org.jdom.Element root, org.jdom.DocType docType)
           Creates a new IdDocument, with the supplied Element as the root element and the supplied DocType declaration.
 
Method Summary
protected  void addId(java.lang.String id, org.jdom.Element elt)
           Adds the specified ID to the ID lookup table of this document and make it point to the associated element.
 org.jdom.Element getElementById(java.lang.String id)
           Retrieves an element using the value of its ID attribute as key.
protected  boolean removeId(java.lang.String id)
           Removes the specified ID from the ID lookup table of this document.
 
Methods inherited from class org.jdom.Document
addContent, addContent, addContent, addContent, clone, cloneContent, detachRootElement, equals, getBaseURI, getContent, getContent, getContent, getContentSize, getDescendants, getDescendants, getDocType, getDocument, getParent, getProperty, getRootElement, hashCode, hasRootElement, indexOf, removeContent, removeContent, removeContent, removeContent, setBaseURI, setContent, setContent, setContent, setContent, setDocType, setProperty, setRootElement, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IdDocument

public IdDocument(org.jdom.Element root,
                  org.jdom.DocType docType)

Creates a new IdDocument, with the supplied Element as the root element and the supplied DocType declaration.

Parameters:
rootElement - Element for document root.
docType - DocType declaration.

IdDocument

public IdDocument(org.jdom.Element root)

Creates a new Document, with the supplied Element as the root element, and no document type declaration.

Parameters:
rootElement - Element for document root.
Method Detail

getElementById

public org.jdom.Element getElementById(java.lang.String id)

Retrieves an element using the value of its ID attribute as key.

Parameters:
id - the value of the ID attribute of the element to retrieve.
Returns:
the Element associated to id or null if none was found.

addId

protected void addId(java.lang.String id,
                     org.jdom.Element elt)

Adds the specified ID to the ID lookup table of this document and make it point to the associated element.

Parameters:
id - the ID to add.
elt - the Element associated to the ID.

removeId

protected boolean removeId(java.lang.String id)

Removes the specified ID from the ID lookup table of this document.

Parameters:
id - the ID to remove.
Returns:
true if the ID was found and removed; false otherwise.


Copyright © 2004 Jason Hunter, Brett McLaughlin. All Rights Reserved.