// Special casing for ENTITY, NOTATION, DOCTYPE and ATTRIBUTES
// LM: should rewrite this.
switch (thisAncestorType) {
case Node.NOTATION_NODE:
case Node.ENTITY_NODE: {
DocumentType container = thisOwnerDoc.getDoctype();
if (container == otherAncestor) return
(DOCUMENT_POSITION_CONTAINS | DOCUMENT_POSITION_PRECEDING);
switch (otherAncestorType) {
case Node.NOTATION_NODE:
case Node.ENTITY_NODE: {
if (thisAncestorType != otherAncestorType)
// the nodes are of different types
return ((thisAncestorType>otherAncestorType) ?
DOCUMENT_POSITION_PRECEDING:DOCUMENT_POSITION_FOLLOWING);
else {
// the nodes are of the same type. Find order.
if (thisAncestorType == Node.NOTATION_NODE)
if (((NamedNodeMapImpl)container.getNotations()).precedes(otherAncestor,thisAncestor))
return (DOCUMENT_POSITION_PRECEDING |
DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC);
else
return (DOCUMENT_POSITION_FOLLOWING |
DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC);
else
if (((NamedNodeMapImpl)container.getEntities()).precedes(otherAncestor,thisAncestor))
return (DOCUMENT_POSITION_PRECEDING |
DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC);
else
return (DOCUMENT_POSITION_FOLLOWING |
DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC);
}
}
}
thisNode = thisAncestor = thisOwnerDoc;
break;
}
case Node.DOCUMENT_TYPE_NODE: {
if (otherNode == thisOwnerDoc)
return (DOCUMENT_POSITION_PRECEDING |
DOCUMENT_POSITION_CONTAINS);
else if (thisOwnerDoc!=null && thisOwnerDoc==otherOwnerDoc)
return (DOCUMENT_POSITION_FOLLOWING);
break;
}
case Node.ATTRIBUTE_NODE: {
thisNode = ((AttrImpl)thisAncestor).getOwnerElement();
if (otherAncestorType==Node.ATTRIBUTE_NODE) {
otherNode = ((AttrImpl)otherAncestor).getOwnerElement();
if (otherNode == thisNode) {
if (((NamedNodeMapImpl)thisNode.getAttributes()).precedes(other,this))
return (DOCUMENT_POSITION_PRECEDING |
DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC);
else
return (DOCUMENT_POSITION_FOLLOWING |
DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC);
}
}
// Now, find the ancestor of the element
thisDepth=0;
for (node=thisNode; node != null; node=node.getParentNode()) {
thisDepth +=1;
if (node == otherNode)
// The other node is an ancestor of the owning element
return DOCUMENT_POSITION_PRECEDING;
thisAncestor = node;
}
}
}
switch (otherAncestorType) {
case Node.NOTATION_NODE:
case Node.ENTITY_NODE: {
DocumentType container = thisOwnerDoc.getDoctype();
if (container == this) return (DOCUMENT_POSITION_IS_CONTAINED |
DOCUMENT_POSITION_FOLLOWING);
otherNode = otherAncestor = thisOwnerDoc;
break;
}