org.exolab.adaptx.xml
public class IDIndexer extends Object
Version: $Revision: 3633 $ $Date: 2003-03-01 02:38:44 -0500 (Sat, 01 Mar 2003) $
Constructor Summary | |
---|---|
IDIndexer()
Creates a new DOMHelper
|
Method Summary | |
---|---|
void | addIdAttribute(String attrName, String appliesTo)
Adds the given attribute name as an ID attribute. |
void | addIdReference(String id, XPathNode node)
Associates the given Id with the given Element |
XPathNode | getElementById(XPathNode root, String id)
Determines the document order of a given node.
|
Parameters: attrName the name of the attribute to treat as an Id. appliesTo the element that this ID attribute appliesTo, "*" may be used to indicate all Elements.
Parameters: id the Id to associate with the given Element element the element which the Id maps to
Parameters: root the "root" XPathNode to search within id the Id of the element to return
Returns: the element XPathNode that is associated with the given Id, or null if no XPathNode was found
See Also: org.exolab.adaptx.xpath.ExprContext
public int[] getDocumentOrder(Node node) {
int[] order = null;
if (node == null) {
order = new int[1];
order[0] = -1;
return order;
}
//-- check cache
//-- * due to bugs in XML4J 1.1.x (2.x works fine)
//-- * we need to use the System.identityHash to
//-- * create a unique key. The problem is Attr nodes
//-- * with the same name, generate the same hash code.
Object key = createKey(node);
order = (int[]) documentOrders.get(key);
if (order != null) return order;
Node parent = null;
//-- calculate document order
if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
// Use parent's document order for attributes
parent = getParentNode((Attr)node);
if (parent == null) {
// int[3] {0 = document, 0 = att-list, att-number}
order = new int[3];
order[0] = 0;
order[1] = 0;
order[2] = childNumber(node);
}
else {
int[] porder = getDocumentOrder(parent);
order = new int[porder.length+2];
for (int i = 0; i < porder.length; i++)
order[i] = porder[i];
order[order.length-2] = 0; //-- signal att-list
order[order.length-1] = childNumber(node);
}
}
else if (node.getNodeType() == Node.DOCUMENT_NODE) {
order = new int[1];
order[0] = 0;
}
else {
//-- get parent's document order
parent = getParentNode(node);
int[] porder = getDocumentOrder(getParentNode(node));
order = new int[porder.length+1];
for (int i = 0; i < porder.length; i++)
order[i] = porder[i];
order[order.length-1] = childNumber(node);
}
//-- add to cache
documentOrders.put(key,order);
return order;
} //-- getDocumentOrder
/**
Returns the element XPathNode that is associated with the given Id.