|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.exolab.adaptx.xml.IDIndexer
public class IDIndexer
A utility class which helps overcome some DOM 1.0 deficiencies.
Constructor Summary | |
---|---|
IDIndexer()
Creates a new DOMHelper |
Method Summary | |
---|---|
void |
addIdAttribute(java.lang.String attrName,
java.lang.String appliesTo)
Adds the given attribute name as an ID attribute. |
void |
addIdReference(java.lang.String id,
XPathNode node)
Associates the given Id with the given Element |
XPathNode |
getElementById(XPathNode root,
java.lang.String id)
Determines the document order of a given node. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public IDIndexer()
Method Detail |
---|
public void addIdAttribute(java.lang.String attrName, java.lang.String appliesTo)
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.public void addIdReference(java.lang.String id, XPathNode node)
id
- the Id to associate with the given Elementelement
- the element which the Id maps topublic XPathNode getElementById(XPathNode root, java.lang.String id)
root
- the "root" XPathNode to search withinid
- the Id of the element to return
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.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |