You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by dm...@apache.org on 2002/04/26 03:00:39 UTC
cvs commit: jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/container ContainerPointer.java
dmitri 02/04/25 18:00:38
Modified: jxpath/src/java/org/apache/commons/jxpath/ri/model
VariablePointer.java NodePointer.java
jxpath/src/java/org/apache/commons/jxpath/ri/axes
PredicateContext.java
jxpath/src/java/org/apache/commons/jxpath/ri/model/beans
PropertyPointer.java PropertyOwnerPointer.java
NullPropertyPointer.java NullElementPointer.java
LangAttributePointer.java
DynamicPropertyPointer.java CollectionPointer.java
BeanPropertyPointer.java
jxpath/src/java/org/apache/commons/jxpath/ri/model/dom
NamespacePointer.java DOMNodePointer.java
DOMNodeIterator.java DOMNamespaceIterator.java
DOMAttributePointer.java DOMAttributeIterator.java
jxpath/src/test/org/apache/commons/jxpath
JXPathTestCase.java
jxpath/src/java/org/apache/commons/jxpath/ri
JXPathContextReferenceImpl.java EvalContext.java
jxpath/src/java/org/apache/commons/jxpath/ri/model/container
ContainerPointer.java
Added: jxpath/src/java/org/apache/commons/jxpath/ri/axes
SimplePathInterpreter.java
Log:
Added pointer comparison to ensure document order
Revision Changes Path
1.3 +11 -7 jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/VariablePointer.java
Index: VariablePointer.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/VariablePointer.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- VariablePointer.java 24 Apr 2002 04:05:39 -0000 1.2
+++ VariablePointer.java 26 Apr 2002 01:00:37 -0000 1.3
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/VariablePointer.java,v 1.2 2002/04/24 04:05:39 dmitri Exp $
- * $Revision: 1.2 $
- * $Date: 2002/04/24 04:05:39 $
+ * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/VariablePointer.java,v 1.3 2002/04/26 01:00:37 dmitri Exp $
+ * $Revision: 1.3 $
+ * $Date: 2002/04/26 01:00:37 $
*
* ====================================================================
* The Apache Software License, Version 1.1
@@ -72,7 +72,7 @@
* Pointer to a context variable.
*
* @author Dmitri Plotnikov
- * @version $Revision: 1.2 $ $Date: 2002/04/24 04:05:39 $
+ * @version $Revision: 1.3 $ $Date: 2002/04/26 01:00:37 $
*/
public class VariablePointer extends NodePointer {
private Variables variables;
@@ -108,7 +108,7 @@
return variables.getVariable(name.getName());
}
- public Object getValue(){
+ public Object getNodeValue(){
Object value = getBaseValue();
if (index != WHOLE_COLLECTION){
return ValueUtils.getValue(value, index);
@@ -138,7 +138,7 @@
if (valuePointer == null){
Object value = null;
if (actual){
- value = getValue();
+ value = getNodeValue();
}
valuePointer = NodePointer.newChildNodePointer(this, null, value);
}
@@ -257,7 +257,7 @@
buffer.append('[').append(index + 1).append(']');
}
}
- else if (index != WHOLE_COLLECTION && (getValue() == null || isCollection())){
+ else if (index != WHOLE_COLLECTION && (getNodeValue() == null || isCollection())){
buffer.append('[').append(index + 1).append(']');
}
return buffer.toString();
@@ -289,5 +289,9 @@
throw new RuntimeException("Factory is not set on the JXPathContext - cannot create path: " + asPath());
}
return factory;
+ }
+
+ public int compareChildNodePointers(NodePointer pointer1, NodePointer pointer2){
+ return pointer1.getIndex() - pointer2.getIndex();
}
}
1.3 +87 -9 jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/NodePointer.java
Index: NodePointer.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/NodePointer.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- NodePointer.java 24 Apr 2002 03:31:59 -0000 1.2
+++ NodePointer.java 26 Apr 2002 01:00:37 -0000 1.3
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/NodePointer.java,v 1.2 2002/04/24 03:31:59 dmitri Exp $
- * $Revision: 1.2 $
- * $Date: 2002/04/24 03:31:59 $
+ * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/NodePointer.java,v 1.3 2002/04/26 01:00:37 dmitri Exp $
+ * $Revision: 1.3 $
+ * $Date: 2002/04/26 01:00:37 $
*
* ====================================================================
* The Apache Software License, Version 1.1
@@ -83,9 +83,9 @@
* context-independent predicates.
*
* @author Dmitri Plotnikov
- * @version $Revision: 1.2 $ $Date: 2002/04/24 03:31:59 $
+ * @version $Revision: 1.3 $ $Date: 2002/04/26 01:00:37 $
*/
-public abstract class NodePointer implements Pointer, Cloneable {
+public abstract class NodePointer implements Pointer, Cloneable, Comparable {
public static int WHOLE_COLLECTION = Integer.MIN_VALUE;
protected int index = WHOLE_COLLECTION;
@@ -158,7 +158,7 @@
* If true, this node does not have children
*/
public boolean isLeaf() {
- Object value = getValue();
+ Object value = getNodeValue();
return value == null
|| JXPathIntrospector.getBeanInfo(value.getClass()).isAtomic();
}
@@ -208,12 +208,12 @@
}
/**
- * By default, returns <code>getValue()</code>, can be overridden to
+ * By default, returns <code>getNodeValue()</code>, can be overridden to
* return a "canonical" value, like for instance a DOM element should
* return its string value.
*/
- public Object getCanonicalValue() {
- return getValue();
+ public Object getValue() {
+ return getNodeValue();
}
/**
@@ -258,9 +258,25 @@
*/
public abstract Object getBaseValue();
+ /**
+ * Returns the object the pointer points to; does not convert it
+ * to a "canonical" type.
+ */
+ public abstract Object getNodeValue();
+
+ /**
+ * Converts the value to the required type and changes the corresponding
+ * object to that value.
+ */
public abstract void setValue(Object value);
/**
+ * Compares two child NodePointers and returns a positive number,
+ * zero or a positive number according to the order of the pointers.
+ */
+ public abstract int compareChildNodePointers(NodePointer pointer1, NodePointer pointer2);
+
+ /**
* Checks if this Pointer matches the supplied NodeTest.
*/
public boolean testNode(NodeTest test) {
@@ -499,5 +515,67 @@
public String toString() {
return asPath();
+ }
+
+ public int compareTo(Object object){
+ NodePointer pointer = (NodePointer) object; // Let it throw a ClassCastException
+ if (parent == pointer.parent){
+ if (parent == null){
+ return 0;
+ }
+ return parent.compareChildNodePointers(this, pointer);
+ }
+
+ // Task 1: find the common parent
+ int depth1 = 0;
+ NodePointer p1 = this;
+ while (p1 != null){
+ depth1 ++;
+ p1 = p1.parent;
+ }
+ int depth2 = 0;
+ NodePointer p2 = pointer;
+ while (p2 != null){
+ depth2 ++;
+ p2 = p2.parent;
+ }
+ return compareNodePointers(this, depth1, pointer, depth2);
+ }
+
+ private int compareNodePointers(NodePointer p1, int depth1, NodePointer p2, int depth2){
+// System.err.println("Comparing " + p1.asPath() + " (" + depth1 + ") ~ " +
+// p2.asPath() + " (" + depth2 + ")");
+ if (depth1 < depth2){
+ int r = compareNodePointers(p1, depth1, p2.parent, depth2-1);
+ if (r != 0){
+ return r;
+ }
+ return -1;
+ }
+ else if (depth1 > depth2){
+ int r = compareNodePointers(p1.parent, depth1-1, p2, depth2);
+ if (r != 0){
+ return r;
+ }
+ return 1;
+ }
+ if (p1 == null && p2 == null){
+ return 0;
+ }
+
+ if (p1 != null && p1.equals(p2)){
+ return 0;
+ }
+
+ if (depth1 == 1){
+ throw new RuntimeException(
+ "Cannot compare pointers that do not belong to the same tree");
+ }
+ int r = compareNodePointers(p1.parent, depth1 - 1, p2.parent, depth2 - 1);
+ if (r != 0){
+ return r;
+ }
+
+ return p1.parent.compareChildNodePointers(p1, p2);
}
}
1.7 +6 -6 jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/axes/PredicateContext.java
Index: PredicateContext.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/axes/PredicateContext.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- PredicateContext.java 24 Apr 2002 04:05:39 -0000 1.6
+++ PredicateContext.java 26 Apr 2002 01:00:37 -0000 1.7
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/axes/PredicateContext.java,v 1.6 2002/04/24 04:05:39 dmitri Exp $
- * $Revision: 1.6 $
- * $Date: 2002/04/24 04:05:39 $
+ * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/axes/PredicateContext.java,v 1.7 2002/04/26 01:00:37 dmitri Exp $
+ * $Revision: 1.7 $
+ * $Date: 2002/04/26 01:00:37 $
*
* ====================================================================
* The Apache Software License, Version 1.1
@@ -73,7 +73,7 @@
* EvalContext that checks predicates.
*
* @author Dmitri Plotnikov
- * @version $Revision: 1.6 $ $Date: 2002/04/24 04:05:39 $
+ * @version $Revision: 1.7 $ $Date: 2002/04/26 01:00:37 $
*/
public class PredicateContext extends EvalContext {
private Expression expression;
@@ -96,7 +96,7 @@
if (setupDynamicPropertyPointer()){
Object pred = parentContext.eval(dynamicPropertyNameExpression);
if (pred instanceof NodePointer){
- pred = ((NodePointer)pred).getCanonicalValue();
+ pred = ((NodePointer)pred).getValue();
}
dynamicPropertyPointer.setPropertyName(stringValue(pred));
done = true;
@@ -105,7 +105,7 @@
else {
Object pred = parentContext.eval(expression);
if (pred instanceof NodePointer){
- pred = ((NodePointer)pred).getValue();
+ pred = ((NodePointer)pred).getNodeValue();
}
if (pred instanceof Number){
int pos = (int)doubleValue(pred);
1.1 jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/axes/SimplePathInterpreter.java
Index: SimplePathInterpreter.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/EvalContext.java,v 1.10 2002/04/24 04:05:40 dmitri Exp $
* $Revision: 1.10 $
* $Date: 2002/04/24 04:05:40 $
*
* ====================================================================
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, Plotnix, Inc,
* <http://www.plotnix.com/>.
* For more information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.commons.jxpath.ri.axes;
import java.util.*;
import org.apache.commons.jxpath.*;
import org.apache.commons.jxpath.ri.QName;
import org.apache.commons.jxpath.ri.EvalContext;
import org.apache.commons.jxpath.ri.compiler.*;
import org.apache.commons.jxpath.ri.model.NodeIterator;
import org.apache.commons.jxpath.ri.model.NodePointer;
import org.apache.commons.jxpath.ri.model.beans.*;
/**
* An simple XPath evaluation mechanism, which works only for some xpaths
* but is much faster than the usual process. It is only used for
* xpaths which have no context-dependent parts, consist entirely of
* child:: steps with predicates that either integer or have the form
* <code>[@name = ...]</code>.
*
* @author Dmitri Plotnikov
* @version $Revision: 1.10 $ $Date: 2002/04/24 04:05:40 $
*/
public class SimplePathInterpreter {
/**
* Walks a location path in a highly simplified fashion: from pointer to
* pointer, no contexts. This is only possible if the path consists of
* simple steps like "/foo[3]" and is context-independent.
*/
public static NodePointer interpretPath(EvalContext context, NodePointer parentPointer, Step steps[]){
if (parentPointer == null){
return null;
}
NodePointer pointer = (NodePointer)parentPointer.clone();
while (pointer != null && !pointer.isNode()){
pointer = pointer.getValuePointer();
}
for (int i = 0; i < steps.length; i++){
Step step = steps[i];
int defaultIndex = (i == steps.length - 1 ? -1 : 0);
QName name = ((NodeNameTest)step.getNodeTest()).getNodeName();
Expression predicates[] = step.getPredicates();
// The following complicated logic is designed to translate
// an xpath like "foo[@name='x'][@name='y'][3]/bar/baz[4]" into
// a sequence of "single steps", each of which takes a node pointer,
// a name and an optional index and gets you another node pointer.
// Note: if the last step is not indexed, the default index used
// for that very last step is "-1", that is "do not index at all",
// not "0" as in all preceeding steps.
int count = (predicates == null ? 0 : predicates.length);
if (count == 0){
pointer = singleStep(context, pointer, name, defaultIndex, false);
}
else {
Expression lastIndexPredicate = null;
if (predicates[count - 1].
getEvaluationHint(CoreOperation.DYNAMIC_PROPERTY_ACCESS_HINT) == null){
lastIndexPredicate = predicates[count - 1];
}
if (lastIndexPredicate != null){
int index = indexFromPredicate(context, lastIndexPredicate);
if (count == 1){
pointer = singleStep(context, pointer, name, index, false);
}
else {
pointer = singleStep(context, pointer, name, -1, false);
for (int j = 0; j < count - 1; j++){
String key = keyFromPredicate(context, predicates[j]);
if (j < count - 2){
pointer = singleStep(context, pointer, key, -1, true);
}
else {
pointer = singleStep(context, pointer, key, index, true);
}
}
}
}
else {
pointer = singleStep(context, pointer, name, -1, false);
for (int j = 0; j < count; j++){
String key = keyFromPredicate(context, predicates[j]);
if (j < count - 1){
pointer = singleStep(context, pointer, key, -1, true);
}
else {
pointer = singleStep(context, pointer, key, defaultIndex, true);
}
}
}
}
}
return pointer;
}
/**
* Interprets predicates for the root expression of an Expression Path without creating
* any intermediate contexts. This is an option used for optimization when the path
* has a simple structure and predicates are context-independent.
*/
public static NodePointer interpretPredicates(EvalContext context, NodePointer pointer, Expression predicates[]){
if (predicates == null || predicates.length == 0 || pointer == null){
return pointer;
}
// The following complicated logic is designed to translate
// an xpath like "$foo[@name='x'][@name='y'][3]" into
// a sequence of "single steps", each of which takes a node pointer,
// a name and an optional index and gets you another node pointer.
int count = predicates.length;
Expression lastIndexPredicate = null;
if (predicates[count - 1].
getEvaluationHint(CoreOperation.DYNAMIC_PROPERTY_ACCESS_HINT) == null){
lastIndexPredicate = predicates[count - 1];
}
if (lastIndexPredicate != null){
int index = indexFromPredicate(context, lastIndexPredicate);
if (count == 1){
if (index >= 0 && index < pointer.getLength()){
pointer.setIndex(index);
}
else {
pointer = new NullElementPointer(pointer, index);
}
}
else {
for (int j = 0; j < count - 1; j++){
String key = keyFromPredicate(context, predicates[j]);
if (j < count - 2){
pointer = singleStep(context, pointer, key, -1, true);
}
else {
pointer = singleStep(context, pointer, key, index, true);
}
}
}
}
else {
for (int j = 0; j < count; j++){
String key = keyFromPredicate(context, predicates[j]);
if (j < count - 1){
pointer = singleStep(context, pointer, key, -1, true);
}
else {
pointer = singleStep(context, pointer, key, -1, true);
}
}
}
return pointer;
}
/**
* @param property can be either a name or a QName
*/
private static NodePointer singleStep(EvalContext context, NodePointer parent, Object property, int index, boolean dynamic){
if (parent instanceof PropertyOwnerPointer){
PropertyPointer pointer = ((PropertyOwnerPointer)parent).getPropertyPointer();
String name;
if (property instanceof QName){
name = ((QName)property).getName();
}
else {
name = (String)property;
}
pointer.setPropertyName(name);
if (pointer instanceof NullPropertyPointer && dynamic){
((NullPropertyPointer)pointer).setDynamic(true);
}
if (index != -1){
if (index >= 0 && index < pointer.getLength()){
pointer.setIndex(index);
return pointer.getValuePointer();
}
else {
return new NullElementPointer(pointer, index).getValuePointer();
}
}
else {
return pointer.getValuePointer();
}
}
else {
QName name;
if (property instanceof QName){
name = (QName)property;
}
else {
name = new QName(null, (String)property);
}
NodeIterator it = parent.childIterator(new NodeNameTest(name), false, null);
if (it != null && it.setPosition(index == -1 ? 1 : index + 1)){
return it.getNodePointer();
}
else {
PropertyPointer pointer = new NullPropertyPointer(parent);
pointer.setPropertyName(name.toString());
pointer.setIndex(index);
return pointer.getValuePointer();
}
}
}
private static int indexFromPredicate(EvalContext context, Expression predicate){
Object value = context.eval(predicate, true);
if (value instanceof EvalContext){
value = ((EvalContext)value).getSingleNodePointer();
}
if (value instanceof NodePointer){
value = ((NodePointer)value).getValue();
}
if (value == null){
throw new RuntimeException("Predicate is null: " + value);
}
if (value instanceof Number){
return (int)(context.doubleValue(value) + 0.5) - 1;
}
else if (context.booleanValue(value)){
return 0;
}
return -1;
}
private static String keyFromPredicate(EvalContext context, Expression predicate){
Expression expr = (Expression)predicate.
getEvaluationHint(CoreOperation.DYNAMIC_PROPERTY_ACCESS_HINT);
return context.stringValue(context.eval(expr));
}
}
1.3 +9 -24 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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PropertyPointer.java 24 Apr 2002 04:05:40 -0000 1.2
+++ PropertyPointer.java 26 Apr 2002 01:00:37 -0000 1.3
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/PropertyPointer.java,v 1.2 2002/04/24 04:05:40 dmitri Exp $
- * $Revision: 1.2 $
- * $Date: 2002/04/24 04:05:40 $
+ * $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 $
*
* ====================================================================
* The Apache Software License, Version 1.1
@@ -70,7 +70,7 @@
* a property of the parent object.
*
* @author Dmitri Plotnikov
- * @version $Revision: 1.2 $ $Date: 2002/04/24 04:05:40 $
+ * @version $Revision: 1.3 $ $Date: 2002/04/26 01:00:37 $
*/
public abstract class PropertyPointer extends NodePointer {
public static int UNSPECIFIED_PROPERTY = Integer.MIN_VALUE;
@@ -102,7 +102,7 @@
public Object getBean(){
if (bean == null){
- bean = getParent().getValue();
+ bean = getParent().getNodeValue();
}
return bean;
}
@@ -132,7 +132,7 @@
private static final Object UNINITIALIZED = new Object();
private Object value = UNINITIALIZED;
- public Object getValue(){
+ public Object getNodeValue(){
if (value == UNINITIALIZED){
if (index == WHOLE_COLLECTION){
value = getBaseValue();
@@ -149,7 +149,7 @@
* selected property value.
*/
public NodePointer getValuePointer(){
- return NodePointer.newChildNodePointer(this, getName(), getValue());
+ return NodePointer.newChildNodePointer(this, getName(), getNodeValue());
}
public int hashCode(){
@@ -171,22 +171,7 @@
index == other.index;
}
- public String toString(){
- StringBuffer buffer = new StringBuffer();
- if (getBean() == null){
- buffer.append("null");
- }
- else {
- buffer.append(getBean().getClass().getName());
- }
- buffer.append('@');
- buffer.append(System.identityHashCode(getBean()));
- buffer.append('.');
- buffer.append(getPropertyName());
- if (index != WHOLE_COLLECTION){
- buffer.append('[').append(index).append(']');
- }
- buffer.append(" = ").append(getValue());
- return buffer.toString();
+ public int compareChildNodePointers(NodePointer pointer1, NodePointer pointer2){
+ return getValuePointer().compareChildNodePointers(pointer1, pointer2);
}
}
1.3 +14 -6 jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/PropertyOwnerPointer.java
Index: PropertyOwnerPointer.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/PropertyOwnerPointer.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PropertyOwnerPointer.java 24 Apr 2002 04:05:40 -0000 1.2
+++ PropertyOwnerPointer.java 26 Apr 2002 01:00:37 -0000 1.3
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/PropertyOwnerPointer.java,v 1.2 2002/04/24 04:05:40 dmitri Exp $
- * $Revision: 1.2 $
- * $Date: 2002/04/24 04:05:40 $
+ * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/PropertyOwnerPointer.java,v 1.3 2002/04/26 01:00:37 dmitri Exp $
+ * $Revision: 1.3 $
+ * $Date: 2002/04/26 01:00:37 $
*
* ====================================================================
* The Apache Software License, Version 1.1
@@ -79,7 +79,7 @@
* a collection.
*
* @author Dmitri Plotnikov
- * @version $Revision: 1.2 $ $Date: 2002/04/24 04:05:40 $
+ * @version $Revision: 1.3 $ $Date: 2002/04/26 01:00:37 $
*/
public abstract class PropertyOwnerPointer extends NodePointer {
@@ -136,7 +136,7 @@
private static final Object UNINITIALIZED = new Object();
private Object value = UNINITIALIZED;
- public Object getValue(){
+ public Object getNodeValue(){
if (value == UNINITIALIZED){
if (index == WHOLE_COLLECTION){
value = getBaseValue();
@@ -158,7 +158,7 @@
* otherwise returns the pointer itself.
*/
public NodePointer getValuePointer() {
- return NodePointer.newChildNodePointer(this, getName(), getValue());
+ return NodePointer.newChildNodePointer(this, getName(), getNodeValue());
}
public void createChild(JXPathContext context, QName name, int index, Object value){
@@ -173,5 +173,13 @@
prop.setPropertyName(name.getName());
prop.setIndex(index);
return prop.createPath(context);
+ }
+
+ public int compareChildNodePointers(NodePointer pointer1, NodePointer pointer2){
+ int r = pointer1.getName().toString().compareTo(pointer2.getName().toString());
+ if (r != 0){
+ return r;
+ }
+ return pointer1.getIndex() - pointer2.getIndex();
}
}
1.3 +5 -5 jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/NullPropertyPointer.java
Index: NullPropertyPointer.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/NullPropertyPointer.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- NullPropertyPointer.java 24 Apr 2002 04:05:40 -0000 1.2
+++ NullPropertyPointer.java 26 Apr 2002 01:00:37 -0000 1.3
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/NullPropertyPointer.java,v 1.2 2002/04/24 04:05:40 dmitri Exp $
- * $Revision: 1.2 $
- * $Date: 2002/04/24 04:05:40 $
+ * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/NullPropertyPointer.java,v 1.3 2002/04/26 01:00:37 dmitri Exp $
+ * $Revision: 1.3 $
+ * $Date: 2002/04/26 01:00:37 $
*
* ====================================================================
* The Apache Software License, Version 1.1
@@ -67,7 +67,7 @@
/**
* @author Dmitri Plotnikov
- * @version $Revision: 1.2 $ $Date: 2002/04/24 04:05:40 $
+ * @version $Revision: 1.3 $ $Date: 2002/04/26 01:00:37 $
*/
public class NullPropertyPointer extends PropertyPointer {
@@ -95,7 +95,7 @@
return null;
}
- public Object getValue(){
+ public Object getNodeValue(){
return null;
}
1.3 +5 -5 jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/NullElementPointer.java
Index: NullElementPointer.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/NullElementPointer.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- NullElementPointer.java 24 Apr 2002 04:05:40 -0000 1.2
+++ NullElementPointer.java 26 Apr 2002 01:00:37 -0000 1.3
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/NullElementPointer.java,v 1.2 2002/04/24 04:05:40 dmitri Exp $
- * $Revision: 1.2 $
- * $Date: 2002/04/24 04:05:40 $
+ * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/NullElementPointer.java,v 1.3 2002/04/26 01:00:37 dmitri Exp $
+ * $Revision: 1.3 $
+ * $Date: 2002/04/26 01:00:37 $
*
* ====================================================================
* The Apache Software License, Version 1.1
@@ -76,7 +76,7 @@
* as the parent.
*
* @author Dmitri Plotnikov
- * @version $Revision: 1.2 $ $Date: 2002/04/24 04:05:40 $
+ * @version $Revision: 1.3 $ $Date: 2002/04/26 01:00:37 $
*/
public class NullElementPointer extends PropertyOwnerPointer {
@@ -93,7 +93,7 @@
return null;
}
- public Object getValue(){
+ public Object getNodeValue(){
return null;
}
1.3 +10 -5 jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/LangAttributePointer.java
Index: LangAttributePointer.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/LangAttributePointer.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- LangAttributePointer.java 24 Apr 2002 04:05:40 -0000 1.2
+++ LangAttributePointer.java 26 Apr 2002 01:00:37 -0000 1.3
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/LangAttributePointer.java,v 1.2 2002/04/24 04:05:40 dmitri Exp $
- * $Revision: 1.2 $
- * $Date: 2002/04/24 04:05:40 $
+ * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/LangAttributePointer.java,v 1.3 2002/04/26 01:00:37 dmitri Exp $
+ * $Revision: 1.3 $
+ * $Date: 2002/04/26 01:00:37 $
*
* ====================================================================
* The Apache Software License, Version 1.1
@@ -70,7 +70,7 @@
* of the attribute is based on the locale supplied to it in the constructor.
*
* @author Dmitri Plotnikov
- * @version $Revision: 1.2 $ $Date: 2002/04/24 04:05:40 $
+ * @version $Revision: 1.3 $ $Date: 2002/04/26 01:00:37 $
*/
public class LangAttributePointer extends NodePointer {
public LangAttributePointer(NodePointer parent){
@@ -93,7 +93,7 @@
return parent.getLocale().toString().replace('_', '-');
}
- public Object getValue(){
+ public Object getNodeValue(){
return getBaseValue();
}
@@ -138,5 +138,10 @@
public boolean testNode(NodeTest test){
return false;
+ }
+
+ public int compareChildNodePointers(NodePointer pointer1, NodePointer pointer2){
+ // Won't happen - lang attributes don't have children
+ return 0;
}
}
1.3 +7 -7 jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/DynamicPropertyPointer.java
Index: DynamicPropertyPointer.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/DynamicPropertyPointer.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DynamicPropertyPointer.java 24 Apr 2002 04:05:40 -0000 1.2
+++ DynamicPropertyPointer.java 26 Apr 2002 01:00:37 -0000 1.3
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/DynamicPropertyPointer.java,v 1.2 2002/04/24 04:05:40 dmitri Exp $
- * $Revision: 1.2 $
- * $Date: 2002/04/24 04:05:40 $
+ * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/DynamicPropertyPointer.java,v 1.3 2002/04/26 01:00:37 dmitri Exp $
+ * $Revision: 1.3 $
+ * $Date: 2002/04/26 01:00:37 $
*
* ====================================================================
* The Apache Software License, Version 1.1
@@ -74,7 +74,7 @@
* Pointer pointing to a property of an object with dynamic properties.
*
* @author Dmitri Plotnikov
- * @version $Revision: 1.2 $ $Date: 2002/04/24 04:05:40 $
+ * @version $Revision: 1.3 $ $Date: 2002/04/26 01:00:37 $
*/
public class DynamicPropertyPointer extends PropertyPointer {
private DynamicPropertyHandler handler;
@@ -192,7 +192,7 @@
* collection, otherwise - 1.
*/
public int getLength(){
- return ValueUtils.getLength(getValue());
+ return ValueUtils.getLength(getNodeValue());
}
/**
@@ -209,7 +209,7 @@
* property. If the property is not a collection, index should be zero
* and the value will be the property itself.
*/
- public Object getValue(){
+ public Object getNodeValue(){
Object value;
if (index == WHOLE_COLLECTION){
value = handler.getProperty(getBean(), getPropertyName());
@@ -300,7 +300,7 @@
}
public NodePointer createPath(JXPathContext context){
- if (getValue() == null){
+ if (getNodeValue() == null){
AbstractFactory factory = getAbstractFactory(context);
int inx = (index == WHOLE_COLLECTION ? 0 : index);
if (!factory.createObject(context, this, getBean(), getPropertyName(), inx)){
1.3 +13 -9 jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/CollectionPointer.java
Index: CollectionPointer.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/CollectionPointer.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- CollectionPointer.java 24 Apr 2002 04:05:40 -0000 1.2
+++ CollectionPointer.java 26 Apr 2002 01:00:37 -0000 1.3
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/CollectionPointer.java,v 1.2 2002/04/24 04:05:40 dmitri Exp $
- * $Revision: 1.2 $
- * $Date: 2002/04/24 04:05:40 $
+ * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/CollectionPointer.java,v 1.3 2002/04/26 01:00:37 dmitri Exp $
+ * $Revision: 1.3 $
+ * $Date: 2002/04/26 01:00:37 $
*
* ====================================================================
* The Apache Software License, Version 1.1
@@ -74,7 +74,7 @@
* Transparent pointer to a collection (array or Collection).
*
* @author Dmitri Plotnikov
- * @version $Revision: 1.2 $ $Date: 2002/04/24 04:05:40 $
+ * @version $Revision: 1.3 $ $Date: 2002/04/26 01:00:37 $
*/
public class CollectionPointer extends NodePointer {
private Object collection;
@@ -98,7 +98,7 @@
return collection;
}
- public Object getValue(){
+ public Object getNodeValue(){
if (index != WHOLE_COLLECTION){
return ValueUtils.getValue(collection, index);
}
@@ -116,7 +116,7 @@
public NodePointer getValuePointer(){
if (valuePointer == null){
- Object value = getValue();
+ Object value = getNodeValue();
valuePointer = NodePointer.newChildNodePointer(this, getName(), value);
}
return valuePointer;
@@ -129,7 +129,7 @@
else {
Object collection = getBaseValue();
if (ValueUtils.getLength(collection) <= index){
- ValueUtils.expandCollection(getValue(), index + 1);
+ ValueUtils.expandCollection(getNodeValue(), index + 1);
}
ValueUtils.setValue(collection, index, value);
}
@@ -142,7 +142,7 @@
else {
Object collection = getBaseValue();
if (ValueUtils.getLength(collection) <= index){
- ValueUtils.expandCollection(getValue(), index + 1);
+ ValueUtils.expandCollection(getNodeValue(), index + 1);
}
return this;
}
@@ -155,7 +155,7 @@
else {
Object collection = getBaseValue();
if (ValueUtils.getLength(collection) <= index){
- ValueUtils.expandCollection(getValue(), index + 1);
+ ValueUtils.expandCollection(getNodeValue(), index + 1);
}
return this;
}
@@ -200,5 +200,9 @@
public boolean testNode(NodeTest nodeTest){
return getValuePointer().testNode(nodeTest);
+ }
+
+ public int compareChildNodePointers(NodePointer pointer1, NodePointer pointer2){
+ return pointer1.getIndex() - pointer2.getIndex();
}
}
1.3 +6 -6 jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/BeanPropertyPointer.java
Index: BeanPropertyPointer.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/BeanPropertyPointer.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- BeanPropertyPointer.java 24 Apr 2002 04:06:46 -0000 1.2
+++ BeanPropertyPointer.java 26 Apr 2002 01:00:37 -0000 1.3
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/BeanPropertyPointer.java,v 1.2 2002/04/24 04:06:46 dmitri Exp $
- * $Revision: 1.2 $
- * $Date: 2002/04/24 04:06:46 $
+ * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/BeanPropertyPointer.java,v 1.3 2002/04/26 01:00:37 dmitri Exp $
+ * $Revision: 1.3 $
+ * $Date: 2002/04/26 01:00:37 $
*
* ====================================================================
* The Apache Software License, Version 1.1
@@ -74,7 +74,7 @@
* Pointer pointing to a property of a JavaBean.
*
* @author Dmitri Plotnikov
- * @version $Revision: 1.2 $ $Date: 2002/04/24 04:06:46 $
+ * @version $Revision: 1.3 $ $Date: 2002/04/26 01:00:37 $
*/
public class BeanPropertyPointer extends PropertyPointer {
private String propertyName;
@@ -175,7 +175,7 @@
* property. If the property is not a collection, index should be zero
* and the value will be the property itself.
*/
- public Object getValue(){
+ public Object getNodeValue(){
if (value == UNINITIALIZED){
PropertyDescriptor pd = getPropertyDescriptor();
if (pd == null){
@@ -218,7 +218,7 @@
}
public NodePointer createPath(JXPathContext context){
- if (getValue() == null){
+ if (getNodeValue() == null){
AbstractFactory factory = getAbstractFactory(context);
int inx = (index == WHOLE_COLLECTION ? 0 : index);
if (!factory.createObject(context, this, getBean(), getPropertyName(), inx)){
1.3 +11 -6 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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- NamespacePointer.java 24 Apr 2002 04:05:40 -0000 1.2
+++ NamespacePointer.java 26 Apr 2002 01:00:38 -0000 1.3
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/NamespacePointer.java,v 1.2 2002/04/24 04:05:40 dmitri Exp $
- * $Revision: 1.2 $
- * $Date: 2002/04/24 04:05:40 $
+ * $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 $
*
* ====================================================================
* The Apache Software License, Version 1.1
@@ -71,7 +71,7 @@
* Represents a namespace node.
*
* @author Dmitri Plotnikov
- * @version $Revision: 1.2 $ $Date: 2002/04/24 04:05:40 $
+ * @version $Revision: 1.3 $ $Date: 2002/04/26 01:00:38 $
*/
public class NamespacePointer extends NodePointer {
private String prefix;
@@ -96,7 +96,7 @@
return null;
}
- public Object getValue(){
+ public Object getNodeValue(){
return getNamespaceURI();
}
@@ -160,4 +160,9 @@
return (nsURI == null && otherNSURI == null) ||
(nsURI != null && nsURI.endsWith(otherNSURI));
}
-}
\ No newline at end of file
+
+ public int compareChildNodePointers(NodePointer pointer1, NodePointer pointer2){
+ // Won't happen - namespaces don't have children
+ return 0;
+ }
+ }
\ No newline at end of file
1.3 +27 -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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DOMNodePointer.java 24 Apr 2002 04:05:40 -0000 1.2
+++ DOMNodePointer.java 26 Apr 2002 01:00:38 -0000 1.3
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodePointer.java,v 1.2 2002/04/24 04:05:40 dmitri Exp $
- * $Revision: 1.2 $
- * $Date: 2002/04/24 04:05:40 $
+ * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodePointer.java,v 1.3 2002/04/26 01:00:38 dmitri Exp $
+ * $Revision: 1.3 $
+ * $Date: 2002/04/26 01:00:38 $
*
* ====================================================================
* The Apache Software License, Version 1.1
@@ -87,7 +87,7 @@
* A Pointer that points to a DOM node.
*
* @author Dmitri Plotnikov
- * @version $Revision: 1.2 $ $Date: 2002/04/24 04:05:40 $
+ * @version $Revision: 1.3 $ $Date: 2002/04/26 01:00:38 $
*/
public class DOMNodePointer extends NodePointer {
private Node node;
@@ -281,7 +281,7 @@
return node;
}
- public Object getValue(){
+ public Object getNodeValue(){
return node;
}
@@ -505,7 +505,7 @@
return name.substring(index + 1);
}
- public Object getCanonicalValue(){
+ public Object getValue(){
return stringValue(node);
}
@@ -547,4 +547,25 @@
}
return factory;
}
+
+ public int compareChildNodePointers(NodePointer pointer1, NodePointer pointer2){
+ Node node1 = (Node)pointer1.getNodeValue();
+ Node node2 = (Node)pointer2.getNodeValue();
+ if (node1 == node2){
+ return 0;
+ }
+
+ Node current = node.getFirstChild();
+ while (current != null){
+ if (current == node1){
+ return -1;
+ }
+ else if (current == node2){
+ return 1;
+ }
+ current = current.getNextSibling();
+ }
+
+ return 0;
+ }
}
1.3 +6 -6 jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodeIterator.java
Index: DOMNodeIterator.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodeIterator.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DOMNodeIterator.java 24 Apr 2002 04:05:40 -0000 1.2
+++ DOMNodeIterator.java 26 Apr 2002 01:00:38 -0000 1.3
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodeIterator.java,v 1.2 2002/04/24 04:05:40 dmitri Exp $
- * $Revision: 1.2 $
- * $Date: 2002/04/24 04:05:40 $
+ * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodeIterator.java,v 1.3 2002/04/26 01:00:38 dmitri Exp $
+ * $Revision: 1.3 $
+ * $Date: 2002/04/26 01:00:38 $
*
* ====================================================================
* The Apache Software License, Version 1.1
@@ -70,7 +70,7 @@
* An iterator of children of a DOM Node.
*
* @author Dmitri Plotnikov
- * @version $Revision: 1.2 $ $Date: 2002/04/24 04:05:40 $
+ * @version $Revision: 1.3 $ $Date: 2002/04/26 01:00:38 $
*/
public class DOMNodeIterator implements NodeIterator {
private NodePointer parent;
@@ -83,9 +83,9 @@
public DOMNodeIterator(NodePointer parent, NodeTest nodeTest, boolean reverse, NodePointer startWith){
this.parent = parent;
- this.node = (Node)parent.getValue();
+ this.node = (Node)parent.getNodeValue();
if (startWith != null){
- this.child = (Node)startWith.getValue();
+ this.child = (Node)startWith.getNodeValue();
}
this.nodeTest = nodeTest;
this.reverse = reverse;
1.3 +5 -5 jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNamespaceIterator.java
Index: DOMNamespaceIterator.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNamespaceIterator.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DOMNamespaceIterator.java 24 Apr 2002 04:05:40 -0000 1.2
+++ DOMNamespaceIterator.java 26 Apr 2002 01:00:38 -0000 1.3
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNamespaceIterator.java,v 1.2 2002/04/24 04:05:40 dmitri Exp $
- * $Revision: 1.2 $
- * $Date: 2002/04/24 04:05:40 $
+ * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNamespaceIterator.java,v 1.3 2002/04/26 01:00:38 dmitri Exp $
+ * $Revision: 1.3 $
+ * $Date: 2002/04/26 01:00:38 $
*
* ====================================================================
* The Apache Software License, Version 1.1
@@ -74,7 +74,7 @@
* An iterator of namespaces of a DOM Node.
*
* @author Dmitri Plotnikov
- * @version $Revision: 1.2 $ $Date: 2002/04/24 04:05:40 $
+ * @version $Revision: 1.3 $ $Date: 2002/04/26 01:00:38 $
*/
public class DOMNamespaceIterator implements NodeIterator {
private NodePointer parent;
@@ -84,7 +84,7 @@
public DOMNamespaceIterator(NodePointer parent){
this.parent = parent;
attributes = new ArrayList();
- collectNamespaces(attributes, (Node)parent.getValue());
+ collectNamespaces(attributes, (Node)parent.getNodeValue());
}
private void collectNamespaces(List attributes, Node node){
1.3 +10 -5 jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/DOMAttributePointer.java
Index: DOMAttributePointer.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/DOMAttributePointer.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DOMAttributePointer.java 24 Apr 2002 04:05:40 -0000 1.2
+++ DOMAttributePointer.java 26 Apr 2002 01:00:38 -0000 1.3
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/DOMAttributePointer.java,v 1.2 2002/04/24 04:05:40 dmitri Exp $
- * $Revision: 1.2 $
- * $Date: 2002/04/24 04:05:40 $
+ * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/DOMAttributePointer.java,v 1.3 2002/04/26 01:00:38 dmitri Exp $
+ * $Revision: 1.3 $
+ * $Date: 2002/04/26 01:00:38 $
*
* ====================================================================
* The Apache Software License, Version 1.1
@@ -73,7 +73,7 @@
* A Pointer that points to a DOM node.
*
* @author Dmitri Plotnikov
- * @version $Revision: 1.2 $ $Date: 2002/04/24 04:05:40 $
+ * @version $Revision: 1.3 $ $Date: 2002/04/26 01:00:38 $
*/
public class DOMAttributePointer extends NodePointer {
private Attr attr;
@@ -103,7 +103,7 @@
return attr;
}
- public Object getValue(){
+ public Object getNodeValue(){
String value = attr.getValue();
if (value == null){
return null;
@@ -164,4 +164,9 @@
DOMAttributePointer other = (DOMAttributePointer)object;
return attr == other.attr;
}
+
+ public int compareChildNodePointers(NodePointer pointer1, NodePointer pointer2){
+ // Won't happen - attributes don't have children
+ return 0;
+ }
}
1.3 +5 -5 jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/DOMAttributeIterator.java
Index: DOMAttributeIterator.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/DOMAttributeIterator.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DOMAttributeIterator.java 24 Apr 2002 04:05:40 -0000 1.2
+++ DOMAttributeIterator.java 26 Apr 2002 01:00:38 -0000 1.3
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/DOMAttributeIterator.java,v 1.2 2002/04/24 04:05:40 dmitri Exp $
- * $Revision: 1.2 $
- * $Date: 2002/04/24 04:05:40 $
+ * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/DOMAttributeIterator.java,v 1.3 2002/04/26 01:00:38 dmitri Exp $
+ * $Revision: 1.3 $
+ * $Date: 2002/04/26 01:00:38 $
*
* ====================================================================
* The Apache Software License, Version 1.1
@@ -76,7 +76,7 @@
* An iterator of attributes of a DOM Node.
*
* @author Dmitri Plotnikov
- * @version $Revision: 1.2 $ $Date: 2002/04/24 04:05:40 $
+ * @version $Revision: 1.3 $ $Date: 2002/04/26 01:00:38 $
*/
public class DOMAttributeIterator implements NodeIterator {
private NodePointer parent;
@@ -88,7 +88,7 @@
this.parent = parent;
this.name = name;
attributes = new ArrayList();
- Node node = (Node)parent.getValue();
+ Node node = (Node)parent.getNodeValue();
if (node.getNodeType() == Node.ELEMENT_NODE){
String lname = name.getName();
if (!lname.equals("*")){
1.13 +45 -8 jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/JXPathTestCase.java
Index: JXPathTestCase.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/JXPathTestCase.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- JXPathTestCase.java 21 Apr 2002 21:52:34 -0000 1.12
+++ JXPathTestCase.java 26 Apr 2002 01:00:38 -0000 1.13
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/JXPathTestCase.java,v 1.12 2002/04/21 21:52:34 dmitri Exp $
- * $Revision: 1.12 $
- * $Date: 2002/04/21 21:52:34 $
+ * $Header: /home/cvs/jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/JXPathTestCase.java,v 1.13 2002/04/26 01:00:38 dmitri Exp $
+ * $Revision: 1.13 $
+ * $Date: 2002/04/26 01:00:38 $
*
* ====================================================================
* The Apache Software License, Version 1.1
@@ -99,7 +99,7 @@
* </p>
*
* @author Dmitri Plotnikov
- * @version $Revision: 1.12 $ $Date: 2002/04/21 21:52:34 $
+ * @version $Revision: 1.13 $ $Date: 2002/04/26 01:00:38 $
*/
public class JXPathTestCase extends TestCase
@@ -283,9 +283,10 @@
testGetValue(context, "integers[1]", new Double(1), Double.class);
testGetValue(context, "2 + 3", "5.0", String.class);
testGetValue(context, "2 + 3", Boolean.TRUE, boolean.class);
+ testGetValue(context, "'true'", Boolean.TRUE, Boolean.class);
boolean exception = false;
try {
- testGetValue(context, "'foo'", null, Date.class);
+ testGetValue(context, "'foo'", null, Date.class);
}
catch(Exception ex){
exception = true;
@@ -372,6 +373,37 @@
assertEquals("Evaluating <" + xpath + ">", expected, expr.isContextDependent());
}
+ public void testDocumentOrder(){
+ if (!enabled){
+ return;
+ }
+
+ JXPathContext context = JXPathContext.newContext(createTestBeanWithDOM());
+ testDocumentOrder(context, "boolean", "int", -1);
+ testDocumentOrder(context, "integers[1]", "integers[2]", -1);
+ testDocumentOrder(context, "integers[1]", "integers[1]", 0);
+ testDocumentOrder(context, "nestedBean/int", "nestedBean", 1);
+ testDocumentOrder(context, "nestedBean/int", "nestedBean/strings", -1);
+ testDocumentOrder(context, "nestedBean/int", "object/int", -1);
+ testDocumentOrder(context, "vendor/location", "vendor/location/address/street", -1);
+ testDocumentOrder(context, "vendor/location[@id = '100']", "vendor/location[@id = '101']", -1);
+ testDocumentOrder(context, "vendor//price:amount", "vendor/location", 1);
+// testDocumentOrder(context, "nonexistent//foo", "vendor/location", 1); // Will throw an exception
+ }
+
+ private void testDocumentOrder(JXPathContext context, String path1, String path2, int expected){
+ NodePointer np1 = (NodePointer)context.locateValue(path1);
+ NodePointer np2 = (NodePointer)context.locateValue(path2);
+ int res = np1.compareTo(np2);
+ if (res < 0){
+ res = -1;
+ }
+ else if (res > 0){
+ res = 1;
+ }
+ assertEquals("Comparing paths '" + path1 + "' and '" + path2 + "'", expected, res);
+ }
+
/**
* Test JXPath.setValue() with various arguments
*/
@@ -609,7 +641,7 @@
}
}
- public void testParserReferenceImpl(){
+ public void testParserReferenceImpl() throws Exception {
if (!enabled){
return;
}
@@ -618,7 +650,7 @@
testParser(JXPathContextFactory.newInstance().newContext(null, bean), false);
}
- public void testParser(JXPathContext ctx, boolean ignorePath){
+ public void testParser(JXPathContext ctx, boolean ignorePath) throws Exception {
ctx.setLocale(Locale.US);
ctx.getVariables().declareVariable("a", new Double(1));
ctx.getVariables().declareVariable("b", new Double(1));
@@ -634,7 +666,8 @@
testXPaths(ctx, xpath_tests, ignorePath);
}
- private void testXPaths(JXPathContext ctx, XP xpath_tests[], boolean ignorePath){
+ private void testXPaths(JXPathContext ctx, XP xpath_tests[], boolean ignorePath) throws Exception{
+ Exception exception = null;
for (int i=0; i < xpath_tests.length; i++) {
try {
Object actual;
@@ -672,6 +705,10 @@
catch (Exception ex){
System.err.println("Exception during <" + xpath_tests[i].xpath + ">");
ex.printStackTrace();
+ exception = ex;
+ }
+ if (exception != null){
+ throw exception;
}
}
1.12 +12 -28 jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java
Index: JXPathContextReferenceImpl.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- JXPathContextReferenceImpl.java 24 Apr 2002 04:05:40 -0000 1.11
+++ JXPathContextReferenceImpl.java 26 Apr 2002 01:00:38 -0000 1.12
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java,v 1.11 2002/04/24 04:05:40 dmitri Exp $
- * $Revision: 1.11 $
- * $Date: 2002/04/24 04:05:40 $
+ * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java,v 1.12 2002/04/26 01:00:38 dmitri Exp $
+ * $Revision: 1.12 $
+ * $Date: 2002/04/26 01:00:38 $
*
* ====================================================================
* The Apache Software License, Version 1.1
@@ -81,7 +81,7 @@
/**
* @author Dmitri Plotnikov
- * @version $Revision: 1.11 $ $Date: 2002/04/24 04:05:40 $
+ * @version $Revision: 1.12 $ $Date: 2002/04/26 01:00:38 $
*/
public class JXPathContextReferenceImpl extends JXPathContext
{
@@ -199,7 +199,7 @@
result = ctx.getSingleNodePointer();
}
if (result instanceof NodePointer){
- result = ((NodePointer)result).getCanonicalValue();
+ result = ((NodePointer)result).getValue();
}
return result;
}
@@ -230,23 +230,15 @@
public List eval(String xpath){
// System.err.println("XPATH: " + xpath);
Object result = eval(xpath, false);
- List list = new ArrayList();
if (result instanceof EvalContext){
- EvalContext context = (EvalContext)result;
- while (context.nextSet()){
- while (context.next()){
- Pointer pointer = context.getCurrentNodePointer();
- list.add(pointer.getValue());
- }
- }
+ return ((EvalContext)result).getValueList();
}
else if (result instanceof Pointer){
- list.add(((Pointer)result).getValue());
+ return Collections.singletonList(((Pointer)result).getValue());
}
else {
- list.add(result);
+ return Collections.singletonList(result);
}
- return list;
}
public Pointer locateValue(String xpath){
@@ -315,23 +307,15 @@
public List locate(String xpath){
Object result = eval(xpath, false);
- List list = new ArrayList();
if (result instanceof EvalContext){
- EvalContext context = (EvalContext)result;
- while (context.nextSet()){
- while (context.next()){
- Pointer pointer = context.getCurrentNodePointer();
- list.add(pointer);
- }
- }
+ return ((EvalContext)result).getPointerList();
}
else if (result instanceof Pointer){
- list.add((Pointer)result);
+ return Collections.singletonList((Pointer)result);
}
else {
- list.add(NodePointer.newNodePointer(null, result, getLocale()));
+ return Collections.singletonList(NodePointer.newNodePointer(null, result, getLocale()));
}
- return list;
}
private Object eval(String xpath, boolean firstMatchLookup) {
@@ -366,7 +350,7 @@
for (int i = 0; i < list.size(); i++){
Object element = list.get(i);
if (element instanceof NodePointer){
- element = ((NodePointer)element).getValue();
+ element = ((NodePointer)element).getNodeValue();
}
result.add(element);
}
1.11 +61 -228 jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/EvalContext.java
Index: EvalContext.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/EvalContext.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- EvalContext.java 24 Apr 2002 04:05:40 -0000 1.10
+++ EvalContext.java 26 Apr 2002 01:00:38 -0000 1.11
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/EvalContext.java,v 1.10 2002/04/24 04:05:40 dmitri Exp $
- * $Revision: 1.10 $
- * $Date: 2002/04/24 04:05:40 $
+ * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/EvalContext.java,v 1.11 2002/04/26 01:00:38 dmitri Exp $
+ * $Revision: 1.11 $
+ * $Date: 2002/04/26 01:00:38 $
*
* ====================================================================
* The Apache Software License, Version 1.1
@@ -78,7 +78,7 @@
* implement behavior of various XPath axes: "child::", "parent::" etc.
*
* @author Dmitri Plotnikov
- * @version $Revision: 1.10 $ $Date: 2002/04/24 04:05:40 $
+ * @version $Revision: 1.11 $ $Date: 2002/04/26 01:00:38 $
*/
public abstract class EvalContext implements ExpressionContext {
protected EvalContext parentContext;
@@ -123,6 +123,52 @@
return list;
}
+ /**
+ * Returns the list of all node values in this context
+ */
+ public List getPointerList() {
+ int pos = position;
+ if (pos != 0) {
+ reset();
+ }
+ List list = new ArrayList();
+ while (nextSet()){
+ while (next()) {
+ list.add(getCurrentNodePointer());
+ }
+ }
+ if (pos != 0) {
+ setPosition(pos);
+ }
+ else {
+ reset();
+ }
+ return list;
+ }
+
+ /**
+ * Returns the list of all node values in this context
+ */
+ public List getValueList() {
+ int pos = position;
+ if (pos != 0) {
+ reset();
+ }
+ List list = new ArrayList();
+ while (nextSet()){
+ while (next()) {
+ list.add(getCurrentNodePointer().getValue());
+ }
+ }
+ if (pos != 0) {
+ setPosition(pos);
+ }
+ else {
+ reset();
+ }
+ return list;
+ }
+
public String toString() {
Pointer ptr = getContextNodePointer();
if (ptr == null) {
@@ -518,10 +564,10 @@
}
if (l instanceof NodePointer){
- l = ((NodePointer)l).getCanonicalValue();
+ l = ((NodePointer)l).getValue();
}
if (r instanceof NodePointer){
- r = ((NodePointer)r).getCanonicalValue();
+ r = ((NodePointer)r).getValue();
}
if (l instanceof Boolean || r instanceof Boolean){
@@ -550,7 +596,7 @@
while(nextSet()){
while(next()){
NodePointer pointer = getCurrentNodePointer();
- set.add(pointer.getCanonicalValue());
+ set.add(pointer.getValue());
}
}
return set;
@@ -597,7 +643,7 @@
return "";
}
else if (object instanceof NodePointer){
- return stringValue(((NodePointer)object).getCanonicalValue());
+ return stringValue(((NodePointer)object).getValue());
}
else if (object instanceof EvalContext){
EvalContext ctx = (EvalContext)object;
@@ -634,7 +680,7 @@
return number(stringValue(object));
}
else if (object instanceof NodePointer){
- return number(((NodePointer)object).getCanonicalValue());
+ return number(((NodePointer)object).getValue());
}
// else if (object instanceof Node){
// System.err.println("HERE");
@@ -668,7 +714,7 @@
return value;
}
else if (object instanceof NodePointer){
- return doubleValue(((NodePointer)object).getCanonicalValue());
+ return doubleValue(((NodePointer)object).getValue());
}
else if (object instanceof EvalContext){
return doubleValue(stringValue(object));
@@ -695,7 +741,7 @@
return ((String)object).length() != 0;
}
else if (object instanceof NodePointer){
- return booleanValue(((NodePointer)object).getCanonicalValue());
+ return booleanValue(((NodePointer)object).getValue());
}
return false;
}
@@ -718,219 +764,6 @@
}
/**
- * Walks a location path in a highly simplified fashion: from pointer to
- * pointer, no contexts. This is only possible if the path consists of
- * simple steps like "/foo[3]" and is context-independent.
- */
- private NodePointer interpretBasicPath(NodePointer parentPointer, Step steps[]){
- if (parentPointer == null){
- return null;
- }
-
- NodePointer pointer = (NodePointer)parentPointer.clone();
- while (pointer != null && !pointer.isNode()){
- pointer = pointer.getValuePointer();
- }
-
- for (int i = 0; i < steps.length; i++){
- Step step = steps[i];
- int defaultIndex = (i == steps.length - 1 ? -1 : 0);
- QName name = ((NodeNameTest)step.getNodeTest()).getNodeName();
- Expression predicates[] = step.getPredicates();
-
- // The following complicated logic is designed to translate
- // an xpath like "foo[@name='x'][@name='y'][3]/bar/baz[4]" into
- // a sequence of "single steps", each of which takes a node pointer,
- // a name and an optional index and gets you another node pointer.
-
- // Note: if the last step is not indexed, the default index used
- // for that very last step is "-1", that is "do not index at all",
- // not "0" as in all preceeding steps.
-
- int count = (predicates == null ? 0 : predicates.length);
- if (count == 0){
- pointer = singleStep(pointer, name, defaultIndex, false);
- }
- else {
- Expression lastIndexPredicate = null;
- if (predicates[count - 1].
- getEvaluationHint(CoreOperation.DYNAMIC_PROPERTY_ACCESS_HINT) == null){
- lastIndexPredicate = predicates[count - 1];
- }
-
- if (lastIndexPredicate != null){
- int index = indexFromPredicate(lastIndexPredicate);
- if (count == 1){
- pointer = singleStep(pointer, name, index, false);
- }
- else {
- pointer = singleStep(pointer, name, -1, false);
- for (int j = 0; j < count - 1; j++){
- String key = keyFromPredicate(predicates[j]);
- if (j < count - 2){
- pointer = singleStep(pointer, key, -1, true);
- }
- else {
- pointer = singleStep(pointer, key, index, true);
- }
- }
- }
- }
- else {
- pointer = singleStep(pointer, name, -1, false);
- for (int j = 0; j < count; j++){
- String key = keyFromPredicate(predicates[j]);
- if (j < count - 1){
- pointer = singleStep(pointer, key, -1, true);
- }
- else {
- pointer = singleStep(pointer, key, defaultIndex, true);
- }
- }
- }
- }
- }
- return pointer;
- }
-
- /**
- * Interprets predicates for the root expression of an Expression Path without creating
- * any intermediate contexts. This is an option used for optimization when the path
- * has a simple structure and predicates are context-independent.
- */
- private NodePointer interpretBasicPredicates(NodePointer pointer, Expression predicates[]){
- if (predicates == null || predicates.length == 0 || pointer == null){
- return pointer;
- }
-
- // The following complicated logic is designed to translate
- // an xpath like "$foo[@name='x'][@name='y'][3]" into
- // a sequence of "single steps", each of which takes a node pointer,
- // a name and an optional index and gets you another node pointer.
-
- int count = predicates.length;
- Expression lastIndexPredicate = null;
- if (predicates[count - 1].
- getEvaluationHint(CoreOperation.DYNAMIC_PROPERTY_ACCESS_HINT) == null){
- lastIndexPredicate = predicates[count - 1];
- }
-
- if (lastIndexPredicate != null){
- int index = indexFromPredicate(lastIndexPredicate);
- if (count == 1){
- if (index >= 0 && index < pointer.getLength()){
- pointer.setIndex(index);
- }
- else {
- pointer = new NullElementPointer(pointer, index);
- }
- }
- else {
- for (int j = 0; j < count - 1; j++){
- String key = keyFromPredicate(predicates[j]);
- if (j < count - 2){
- pointer = singleStep(pointer, key, -1, true);
- }
- else {
- pointer = singleStep(pointer, key, index, true);
- }
- }
- }
- }
- else {
- for (int j = 0; j < count; j++){
- String key = keyFromPredicate(predicates[j]);
- if (j < count - 1){
- pointer = singleStep(pointer, key, -1, true);
- }
- else {
- pointer = singleStep(pointer, key, -1, true);
- }
- }
- }
- return pointer;
- }
-
- /**
- * @param property can be either a name or a QName
- */
- private NodePointer singleStep(NodePointer parent, Object property, int index, boolean dynamic){
- if (parent instanceof PropertyOwnerPointer){
- PropertyPointer pointer = ((PropertyOwnerPointer)parent).getPropertyPointer();
- String name;
- if (property instanceof QName){
- name = ((QName)property).getName();
- }
- else {
- name = (String)property;
- }
- pointer.setPropertyName(name);
- if (pointer instanceof NullPropertyPointer && dynamic){
- ((NullPropertyPointer)pointer).setDynamic(true);
- }
- if (index != -1){
- if (index >= 0 && index < pointer.getLength()){
- pointer.setIndex(index);
- return pointer.getValuePointer();
- }
- else {
- return new NullElementPointer(pointer, index).getValuePointer();
- }
- }
- else {
- return pointer.getValuePointer();
- }
- }
- else {
- QName name;
- if (property instanceof QName){
- name = (QName)property;
- }
- else {
- name = new QName(null, (String)property);
- }
- NodeIterator it = parent.childIterator(new NodeNameTest(name), false, null);
- if (it != null && it.setPosition(index == -1 ? 1 : index + 1)){
- return it.getNodePointer();
- }
- else {
- PropertyPointer pointer = new NullPropertyPointer(parent);
- pointer.setPropertyName(name.toString());
- pointer.setIndex(index);
- return pointer.getValuePointer();
- }
- }
- }
-
- private int indexFromPredicate(Expression predicate){
- Object value = eval(predicate, true);
- if (value instanceof EvalContext){
- value = ((EvalContext)value).getSingleNodePointer();
- }
- if (value instanceof NodePointer){
- value = ((NodePointer)value).getCanonicalValue();
- }
- if (value == null){
- throw new RuntimeException("Predicate is null: " + value);
- }
-
- if (value instanceof Number){
- return (int)(doubleValue(value) + 0.5) - 1;
- }
- else if (booleanValue(value)){
- return 0;
- }
-
- return -1;
- }
-
- private String keyFromPredicate(Expression predicate){
- Expression expr = (Expression)predicate.
- getEvaluationHint(CoreOperation.DYNAMIC_PROPERTY_ACCESS_HINT);
- return stringValue(eval(expr));
- }
-
- /**
* Walks an expression path (a path that starts with an expression)
*/
protected Object expressionPath(ExpressionPath path, boolean firstMatch){
@@ -961,8 +794,8 @@
if (ptr != null &&
(ptr.getIndex() == NodePointer.WHOLE_COLLECTION ||
predicates == null || predicates.length == 0)){
- NodePointer pointer = interpretBasicPredicates(ptr, predicates);
- return interpretBasicPath(pointer, path.getSteps());
+ NodePointer pointer = SimplePathInterpreter.interpretPredicates(this, ptr, predicates);
+ return SimplePathInterpreter.interpretPath(this, pointer, path.getSteps());
}
}
@@ -985,7 +818,7 @@
boolean basic = path.getEvaluationHint(Path.BASIC_PATH_HINT).equals(Boolean.TRUE);
if (basic){
NodePointer ptr = (NodePointer)context.getSingleNodePointer();
- return interpretBasicPath(ptr, steps);
+ return SimplePathInterpreter.interpretPath(this, ptr, steps);
}
}
@@ -1139,7 +972,7 @@
int count = 0;
Object value = eval(arg1, false);
if (value instanceof NodePointer){
- value = ((NodePointer)value).getCanonicalValue();
+ value = ((NodePointer)value).getValue();
}
if (value instanceof EvalContext){
EvalContext ctx = (EvalContext)value;
1.2 +11 -7 jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/container/ContainerPointer.java
Index: ContainerPointer.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/container/ContainerPointer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ContainerPointer.java 21 Apr 2002 21:52:33 -0000 1.1
+++ ContainerPointer.java 26 Apr 2002 01:00:38 -0000 1.2
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/container/ContainerPointer.java,v 1.1 2002/04/21 21:52:33 dmitri Exp $
- * $Revision: 1.1 $
- * $Date: 2002/04/21 21:52:33 $
+ * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/container/ContainerPointer.java,v 1.2 2002/04/26 01:00:38 dmitri Exp $
+ * $Revision: 1.2 $
+ * $Date: 2002/04/26 01:00:38 $
*
* ====================================================================
* The Apache Software License, Version 1.1
@@ -76,7 +76,7 @@
* itself.
*
* @author Dmitri Plotnikov
- * @version $Revision: 1.1 $ $Date: 2002/04/21 21:52:33 $
+ * @version $Revision: 1.2 $ $Date: 2002/04/26 01:00:38 $
*/
public class ContainerPointer extends NodePointer {
private Container container;
@@ -107,7 +107,7 @@
return container.getValue();
}
- public Object getValue(){
+ public Object getNodeValue(){
Object value = getBaseValue();
if (index != WHOLE_COLLECTION){
return ValueUtils.getValue(value, index);
@@ -121,7 +121,7 @@
public NodePointer getValuePointer(){
if (valuePointer == null){
- Object value = getValue();
+ Object value = getNodeValue();
valuePointer = NodePointer.newChildNodePointer(this, getName(), value).getValuePointer();
}
return valuePointer;
@@ -164,4 +164,8 @@
public boolean testNode(NodeTest nodeTest){
return getValuePointer().testNode(nodeTest);
}
-}
\ No newline at end of file
+
+ public int compareChildNodePointers(NodePointer pointer1, NodePointer pointer2){
+ return pointer1.getIndex() - pointer2.getIndex();
+ }
+ }
\ No newline at end of file
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>