dmitri 02/05/28 17:40:59 Modified: jxpath/src/java/org/apache/commons/jxpath/ri/model/beans BeanPointer.java PropertyPointer.java jxpath/src/java/org/apache/commons/jxpath/ri/model/dom DOMNodePointer.java NamespacePointer.java Log: Fix problems with pointer comparison Revision Changes Path 1.4 +16 -4 jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/BeanPointer.java Index: BeanPointer.java =================================================================== RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/BeanPointer.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- BeanPointer.java 8 May 2002 23:05:05 -0000 1.3 +++ BeanPointer.java 29 May 2002 00:40:58 -0000 1.4 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/BeanPointer.java,v 1.3 2002/05/08 23:05:05 dmitri Exp $ - * $Revision: 1.3 $ - * $Date: 2002/05/08 23:05:05 $ + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/BeanPointer.java,v 1.4 2002/05/29 00:40:58 dmitri Exp $ + * $Revision: 1.4 $ + * $Date: 2002/05/29 00:40:58 $ * * ==================================================================== * The Apache Software License, Version 1.1 @@ -74,7 +74,7 @@ * a path, following elements will by of type PropertyPointer. * * @author Dmitri Plotnikov - * @version $Revision: 1.3 $ $Date: 2002/05/08 23:05:05 $ + * @version $Revision: 1.4 $ $Date: 2002/05/29 00:40:58 $ */ public class BeanPointer extends PropertyOwnerPointer { private QName name; @@ -162,8 +162,20 @@ } BeanPointer other = (BeanPointer)object; + if (parent != other.parent){ + if (parent == null || !parent.equals(other.parent)){ + return false; + } + } + if ((name == null && other.name != null) || (name != null && !name.equals(other.name))){ + return false; + } + + int i_this = (index == WHOLE_COLLECTION ? 0 : index); + int i_other = (other.index == WHOLE_COLLECTION ? 0 : other.index); + if (i_this != i_other){ return false; } 1.4 +18 -7 jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/PropertyPointer.java Index: PropertyPointer.java =================================================================== RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/PropertyPointer.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- PropertyPointer.java 26 Apr 2002 01:00:37 -0000 1.3 +++ PropertyPointer.java 29 May 2002 00:40:58 -0000 1.4 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/PropertyPointer.java,v 1.3 2002/04/26 01:00:37 dmitri Exp $ - * $Revision: 1.3 $ - * $Date: 2002/04/26 01:00:37 $ + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/PropertyPointer.java,v 1.4 2002/05/29 00:40:58 dmitri Exp $ + * $Revision: 1.4 $ + * $Date: 2002/05/29 00:40:58 $ * * ==================================================================== * The Apache Software License, Version 1.1 @@ -70,7 +70,7 @@ * a property of the parent object. * * @author Dmitri Plotnikov - * @version $Revision: 1.3 $ $Date: 2002/04/26 01:00:37 $ + * @version $Revision: 1.4 $ $Date: 2002/05/29 00:40:58 $ */ public abstract class PropertyPointer extends NodePointer { public static int UNSPECIFIED_PROPERTY = Integer.MIN_VALUE; @@ -166,9 +166,20 @@ } PropertyPointer other = (PropertyPointer)object; - return getParent() == other.getParent() && - propertyIndex == other.propertyIndex && - index == other.index; + if (parent != other.parent){ + if (parent == null || !parent.equals(other.parent)){ + return false; + } + } + + if (getPropertyIndex() != other.getPropertyIndex() || + !getPropertyName().equals(other.getPropertyName())){ + return false; + } + + int i_this = (index == WHOLE_COLLECTION ? 0 : index); + int i_other = (other.index == WHOLE_COLLECTION ? 0 : other.index); + return i_this == i_other; } public int compareChildNodePointers(NodePointer pointer1, NodePointer pointer2){ 1.6 +30 -6 jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodePointer.java Index: DOMNodePointer.java =================================================================== RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodePointer.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- DOMNodePointer.java 8 May 2002 23:05:05 -0000 1.5 +++ DOMNodePointer.java 29 May 2002 00:40:58 -0000 1.6 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodePointer.java,v 1.5 2002/05/08 23:05:05 dmitri Exp $ - * $Revision: 1.5 $ - * $Date: 2002/05/08 23:05:05 $ + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodePointer.java,v 1.6 2002/05/29 00:40:58 dmitri Exp $ + * $Revision: 1.6 $ + * $Date: 2002/05/29 00:40:58 $ * * ==================================================================== * The Apache Software License, Version 1.1 @@ -80,6 +80,7 @@ import org.w3c.dom.Attr; import org.w3c.dom.Comment; import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.w3c.dom.ProcessingInstruction; @@ -88,7 +89,7 @@ * A Pointer that points to a DOM node. * * @author Dmitri Plotnikov - * @version $Revision: 1.5 $ $Date: 2002/05/08 23:05:05 $ + * @version $Revision: 1.6 $ $Date: 2002/05/29 00:40:58 $ */ public class DOMNodePointer extends NodePointer { private Node node; @@ -560,10 +561,33 @@ } public int compareChildNodePointers(NodePointer pointer1, NodePointer pointer2){ - Node node1 = (Node)pointer1.getNodeValue(); - Node node2 = (Node)pointer2.getNodeValue(); + Node node1 = (Node)pointer1.getBaseValue(); + Node node2 = (Node)pointer2.getBaseValue(); if (node1 == node2){ return 0; + } + + int t1 = node1.getNodeType(); + int t2 = node2.getNodeType(); + if (t1 == Node.ATTRIBUTE_NODE && t2 != Node.ATTRIBUTE_NODE){ + return -1; + } + else if (t1 != Node.ATTRIBUTE_NODE && t2 == Node.ATTRIBUTE_NODE){ + return 1; + } + else if (t1 == Node.ATTRIBUTE_NODE && t2 == Node.ATTRIBUTE_NODE){ + NamedNodeMap map = ((Node)getNodeValue()).getAttributes(); + int length = map.getLength(); + for (int i = 0; i < length; i++){ + Node n = map.item(i); + if (n == node1){ + return -1; + } + else if (n == node2){ + return 1; + } + } + return 0; // Should not happen } Node current = node.getFirstChild(); 1.4 +7 -16 jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/NamespacePointer.java Index: NamespacePointer.java =================================================================== RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/NamespacePointer.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- NamespacePointer.java 26 Apr 2002 01:00:38 -0000 1.3 +++ NamespacePointer.java 29 May 2002 00:40:58 -0000 1.4 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/NamespacePointer.java,v 1.3 2002/04/26 01:00:38 dmitri Exp $ - * $Revision: 1.3 $ - * $Date: 2002/04/26 01:00:38 $ + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/NamespacePointer.java,v 1.4 2002/05/29 00:40:58 dmitri Exp $ + * $Revision: 1.4 $ + * $Date: 2002/05/29 00:40:58 $ * * ==================================================================== * The Apache Software License, Version 1.1 @@ -71,7 +71,7 @@ * Represents a namespace node. * * @author Dmitri Plotnikov - * @version $Revision: 1.3 $ $Date: 2002/04/26 01:00:38 $ + * @version $Revision: 1.4 $ $Date: 2002/05/29 00:40:58 $ */ public class NamespacePointer extends NodePointer { private String prefix; @@ -136,13 +136,7 @@ } public int hashCode(){ - String nsURI = getNamespaceURI(); - if (nsURI == null){ - return 0; - } - else { - return nsURI.hashCode(); - } + return prefix.hashCode(); } public boolean equals(Object object){ @@ -155,12 +149,9 @@ } NamespacePointer other = (NamespacePointer)object; - String nsURI = getNamespaceURI(); - String otherNSURI = other.getNamespaceURI(); - return (nsURI == null && otherNSURI == null) || - (nsURI != null && nsURI.endsWith(otherNSURI)); + return prefix.equals(other.prefix); } - + public int compareChildNodePointers(NodePointer pointer1, NodePointer pointer2){ // Won't happen - namespaces don't have children return 0;
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>