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/10/20 05:47:18 UTC
cvs commit: jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/container ContainerPointer.java
dmitri 2002/10/19 20:47:18
Modified: jxpath/src/java/org/apache/commons/jxpath/ri/model
VariablePointer.java NodePointer.java
jxpath/src/java/org/apache/commons/jxpath/ri/model/beans
PropertyPointer.java PropertyOwnerPointer.java
NullPropertyPointer.java NullPointer.java
NullElementPointer.java LangAttributePointer.java
DynamicPropertyPointer.java DynamicPointer.java
CollectionPointer.java BeanPropertyPointer.java
BeanPointer.java
jxpath/src/java/org/apache/commons/jxpath/ri/model/dom
NamespacePointer.java DOMAttributePointer.java
jxpath/src/java/org/apache/commons/jxpath/ri/model/jdom
JDOMNodeIterator.java JDOMNamespacePointer.java
JDOMAttributePointer.java
jxpath/src/java/org/apache/commons/jxpath/ri/model/dynabeans
DynaBeanPropertyPointer.java
jxpath/src/java/org/apache/commons/jxpath/ri/model/container
ContainerPointer.java
Log:
Cleaned up isCollection, getLength and asPath methods
Revision Changes Path
1.7 +21 -5 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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- VariablePointer.java 10 Aug 2002 16:13:03 -0000 1.6
+++ VariablePointer.java 20 Oct 2002 03:47:17 -0000 1.7
@@ -64,6 +64,7 @@
import org.apache.commons.jxpath.AbstractFactory;
import org.apache.commons.jxpath.JXPathContext;
import org.apache.commons.jxpath.JXPathException;
+import org.apache.commons.jxpath.JXPathIntrospector;
import org.apache.commons.jxpath.Variables;
import org.apache.commons.jxpath.ri.QName;
import org.apache.commons.jxpath.ri.compiler.NodeTest;
@@ -108,6 +109,17 @@
}
return variables.getVariable(name.getName());
}
+
+ public boolean isLeaf() {
+ Object value = getNode();
+ return value == null
+ || JXPathIntrospector.getBeanInfo(value.getClass()).isAtomic();
+ }
+
+ public boolean isCollection(){
+ Object value = getBaseValue();
+ return value != null && ValueUtils.isCollection(value);
+ }
public Object getNode(){
Object value = getBaseValue();
@@ -148,7 +160,11 @@
public int getLength(){
if (actual){
- return super.getLength();
+ Object value = getBaseValue();
+ if (value == null) {
+ return 1;
+ }
+ return ValueUtils.getLength(value);
}
return 0;
}
1.12 +11 -22 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.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- NodePointer.java 13 Oct 2002 02:59:01 -0000 1.11
+++ NodePointer.java 20 Oct 2002 03:47:17 -0000 1.12
@@ -75,7 +75,6 @@
import org.apache.commons.jxpath.ri.compiler.NodeTypeTest;
import org.apache.commons.jxpath.ri.model.beans.NullElementPointer;
import org.apache.commons.jxpath.ri.model.beans.NullPointer;
-import org.apache.commons.jxpath.util.ValueUtils;
/**
* Common superclass for Pointers of all kinds. A NodePointer maps to
@@ -178,11 +177,7 @@
/**
* If true, this node does not have children
*/
- public boolean isLeaf() {
- Object value = getNode();
- return value == null
- || JXPathIntrospector.getBeanInfo(value.getClass()).isAtomic();
- }
+ public abstract boolean isLeaf();
/**
* If false, this node is axiliary and can only be used as an intermediate
@@ -211,23 +206,14 @@
* Returns <code>true</code> if the value of the pointer is an array or
* a Collection.
*/
- public boolean isCollection() {
- Object value = getBaseValue();
- return value != null && ValueUtils.isCollection(value);
- }
+ public abstract boolean isCollection();
/**
* If the pointer represents a collection (or collection element),
* returns the length of the collection.
* Otherwise returns 1 (even if the value is null).
*/
- public int getLength() {
- Object value = getBaseValue();
- if (value == null) {
- return 1;
- }
- return ValueUtils.getLength(value);
- }
+ public abstract int getLength();
/**
* By default, returns <code>getNodeValue()</code>, can be overridden to
@@ -564,7 +550,10 @@
if (getParent().isNode() || (parent instanceof NullElementPointer)){
QName name = getName();
if (name != null) {
- buffer.append('/');
+ if (buffer.length() == 0 ||
+ buffer.charAt(buffer.length()-1) != '/'){
+ buffer.append('/');
+ }
if (attribute){
buffer.append('@');
}
1.6 +25 -9 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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- PropertyPointer.java 10 Aug 2002 16:13:04 -0000 1.5
+++ PropertyPointer.java 20 Oct 2002 03:47:17 -0000 1.6
@@ -61,6 +61,7 @@
*/
package org.apache.commons.jxpath.ri.model.beans;
+import org.apache.commons.jxpath.JXPathIntrospector;
import org.apache.commons.jxpath.ri.QName;
import org.apache.commons.jxpath.ri.model.NodePointer;
import org.apache.commons.jxpath.util.ValueUtils;
@@ -86,11 +87,6 @@
super(parent);
}
- public boolean isCollection(){
- Object value = getBaseValue();
- return value != null && ValueUtils.isCollection(value);
- }
-
public int getPropertyIndex(){
return propertyIndex;
}
@@ -143,6 +139,26 @@
}
return value;
}
+
+ public boolean isCollection(){
+ Object value = getBaseValue();
+ return value != null && ValueUtils.isCollection(value);
+ }
+
+ public boolean isLeaf() {
+ Object value = getNode();
+ return value == null
+ || JXPathIntrospector.getBeanInfo(value.getClass()).isAtomic();
+ }
+
+ /**
+ * If the property contains a collection, then the length of that
+ * collection, otherwise - 1.
+ */
+ public int getLength(){
+ return ValueUtils.getLength(getBaseValue());
+ }
+
/**
* Returns a NodePointer that can be used to access the currently
1.9 +37 -10 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.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- PropertyOwnerPointer.java 10 Aug 2002 16:13:04 -0000 1.8
+++ PropertyOwnerPointer.java 20 Oct 2002 03:47:17 -0000 1.9
@@ -73,7 +73,6 @@
import org.apache.commons.jxpath.ri.model.NodePointer;
import org.apache.commons.jxpath.util.ValueUtils;
-
/**
* A pointer describing a node that has properties, each of which could be
* a collection.
@@ -121,11 +120,6 @@
super(parent);
}
- public boolean isCollection(){
- Object value = getBaseValue();
- return value != null && ValueUtils.isCollection(value);
- }
-
public void setIndex(int index){
if (this.index != index){
super.setIndex(index);
@@ -149,8 +143,41 @@
}
public abstract QName getName();
+
+ /**
+ * Throws an exception if you try to change the root element, otherwise
+ * forwards the call to the parent pointer.
+ */
public void setValue(Object value){
this.value = value;
+ if (parent instanceof PropertyPointer){
+ parent.setValue(value);
+ }
+ else if (parent != null){
+ throw new UnsupportedOperationException(
+ "Cannot setValue of an object that is not " +
+ "some other object's property");
+ }
+ else {
+ throw new UnsupportedOperationException(
+ "Cannot replace the root object");
+ }
+ }
+
+ /**
+ * If this is a root node pointer, throws an exception; otherwise
+ * forwards the call to the parent node.
+ */
+ public void remove(){
+ this.value = null;
+ if (parent != null){
+ parent.remove();
+ }
+ else {
+ throw new UnsupportedOperationException(
+ "Cannot remove an object that is not " +
+ "some other object's property or a collection element");
+ }
}
public abstract PropertyPointer getPropertyPointer();
1.9 +16 -6 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.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- NullPropertyPointer.java 13 Oct 2002 02:59:01 -0000 1.8
+++ NullPropertyPointer.java 20 Oct 2002 03:47:17 -0000 1.9
@@ -100,6 +100,10 @@
return null;
}
+ public boolean isLeaf() {
+ return true;
+ }
+
public NodePointer getValuePointer(){
return new NullPointer(this, new QName(getPropertyName()));
}
@@ -117,8 +121,14 @@
}
public void setValue(Object value){
- throw new JXPathException("Cannot set property " + asPath() +
- ", the target object is null");
+ if (parent == null || !parent.isNode()){
+ throw new JXPathException("Cannot set property " + asPath() +
+ ", the target object is null");
+ }
+ else {
+ throw new JXPathException("Cannot set property " + asPath() +
+ ", path does not match a changeable location");
+ }
}
public NodePointer createPath(JXPathContext context){
1.7 +11 -13 jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/NullPointer.java
Index: NullPointer.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/NullPointer.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- NullPointer.java 10 Aug 2002 01:49:46 -0000 1.6
+++ NullPointer.java 20 Oct 2002 03:47:17 -0000 1.7
@@ -100,16 +100,14 @@
public Object getBaseValue(){
return null;
}
-
- public void setValue(Object value){
- super.setValue(value);
- if (parent instanceof PropertyPointer){
- parent.setValue(value);
- }
- else {
- throw new UnsupportedOperationException("Cannot setValue of an object that is not some other object's property/child");
- }
+
+ public boolean isCollection(){
+ return false;
}
+
+ public boolean isLeaf() {
+ return true;
+ }
public boolean isActual(){
return false;
1.9 +12 -4 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.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- NullElementPointer.java 10 Aug 2002 16:13:04 -0000 1.8
+++ NullElementPointer.java 20 Oct 2002 03:47:17 -0000 1.9
@@ -97,6 +97,14 @@
public Object getNode(){
return null;
}
+
+ public boolean isLeaf() {
+ return true;
+ }
+
+ public boolean isCollection(){
+ return false;
+ }
public PropertyPointer getPropertyPointer(){
return new NullPropertyPointer(this);
1.5 +16 -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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- LangAttributePointer.java 10 Aug 2002 16:13:04 -0000 1.4
+++ LangAttributePointer.java 20 Oct 2002 03:47:17 -0000 1.5
@@ -89,6 +89,14 @@
return null;
}
+ public boolean isCollection(){
+ return false;
+ }
+
+ public int getLength(){
+ return 1;
+ }
+
public Object getBaseValue(){
return parent.getLocale().toString().replace('_', '-');
}
@@ -114,7 +122,10 @@
StringBuffer buffer = new StringBuffer();
if (parent != null){
buffer.append(parent.asPath());
- buffer.append('/');
+ if (buffer.length() == 0 ||
+ buffer.charAt(buffer.length()-1) != '/'){
+ buffer.append('/');
+ }
}
buffer.append("@xml:lang");
return buffer.toString();
1.9 +5 -12 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.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- DynamicPropertyPointer.java 10 Aug 2002 16:13:04 -0000 1.8
+++ DynamicPropertyPointer.java 20 Oct 2002 03:47:17 -0000 1.9
@@ -67,6 +67,7 @@
import org.apache.commons.jxpath.DynamicPropertyHandler;
import org.apache.commons.jxpath.JXPathContext;
import org.apache.commons.jxpath.JXPathException;
+import org.apache.commons.jxpath.JXPathIntrospector;
import org.apache.commons.jxpath.ri.QName;
import org.apache.commons.jxpath.ri.model.NodePointer;
import org.apache.commons.jxpath.util.ValueUtils;
@@ -186,14 +187,6 @@
super.setPropertyIndex(index);
name = null;
}
- }
-
- /**
- * If the property contains a collection, then the length of that
- * collection, otherwise - 1.
- */
- public int getLength(){
- return ValueUtils.getLength(getBaseValue());
}
/**
1.6 +23 -26 jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/DynamicPointer.java
Index: DynamicPointer.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/DynamicPointer.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DynamicPointer.java 10 Aug 2002 01:49:46 -0000 1.5
+++ DynamicPointer.java 20 Oct 2002 03:47:17 -0000 1.6
@@ -64,9 +64,9 @@
import java.util.Locale;
import org.apache.commons.jxpath.DynamicPropertyHandler;
+import org.apache.commons.jxpath.JXPathIntrospector;
import org.apache.commons.jxpath.ri.QName;
import org.apache.commons.jxpath.ri.model.NodePointer;
-import org.apache.commons.jxpath.util.ValueUtils;
/**
* A Pointer that points to an object with Dynamic Properties. It is used
@@ -81,14 +81,18 @@
private DynamicPropertyHandler handler;
private String[] names;
- public DynamicPointer(QName name, Object bean, DynamicPropertyHandler handler, Locale locale){
+ public DynamicPointer(QName name, Object bean,
+ DynamicPropertyHandler handler, Locale locale)
+ {
super(null, locale);
this.name = name;
this.bean = bean;
this.handler = handler;
}
- public DynamicPointer(NodePointer parent, QName name, Object bean, DynamicPropertyHandler handler){
+ public DynamicPointer(NodePointer parent, QName name,
+ Object bean, DynamicPropertyHandler handler)
+ {
super(parent);
this.name = name;
this.bean = bean;
@@ -109,36 +113,29 @@
public Object getBaseValue(){
return bean;
}
-
- public void setValue(Object value){
- super.setValue(value);
- if (parent instanceof PropertyPointer){
- parent.setValue(value);
- }
- else if (parent != null){
- throw new UnsupportedOperationException("Cannot setValue of an object that is not some other object's property");
- }
- else {
- throw new UnsupportedOperationException("Cannot replace the root object");
- }
+
+ public boolean isLeaf() {
+ Object value = getNode();
+ return value == null
+ || JXPathIntrospector.getBeanInfo(value.getClass()).isAtomic();
+ }
+
+ public boolean isCollection(){
+ return false;
}
/**
- * If the bean is a collection, returns the length of that collection,
- * otherwise returns 1.
+ * Returns 1.
*/
public int getLength(){
- return ValueUtils.getLength(getBaseValue());
+ return 1;
}
- /**
- * Empty string
- */
public String asPath(){
if (parent != null){
return super.asPath();
}
- return "";
+ return "/";
}
public int hashCode(){
1.7 +56 -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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- CollectionPointer.java 10 Aug 2002 16:13:04 -0000 1.6
+++ CollectionPointer.java 20 Oct 2002 03:47:17 -0000 1.7
@@ -64,6 +64,7 @@
import java.util.Locale;
import org.apache.commons.jxpath.JXPathContext;
+import org.apache.commons.jxpath.JXPathIntrospector;
import org.apache.commons.jxpath.ri.QName;
import org.apache.commons.jxpath.ri.compiler.NodeTest;
import org.apache.commons.jxpath.ri.model.NodeIterator;
@@ -98,6 +99,20 @@
return collection;
}
+ public boolean isCollection(){
+ return true;
+ }
+
+ public int getLength(){
+ return ValueUtils.getLength(getBaseValue());
+ }
+
+ public boolean isLeaf() {
+ Object value = getNode();
+ return value == null
+ || JXPathIntrospector.getBeanInfo(value.getClass()).isAtomic();
+ }
+
public boolean isNode(){
return index == WHOLE_COLLECTION;
}
@@ -130,13 +145,16 @@
}
else {
Object value = getNode();
- valuePointer = NodePointer.newChildNodePointer(this, getName(), value);
+ valuePointer = NodePointer.
+ newChildNodePointer(this, getName(), value);
}
}
return valuePointer;
}
- public NodePointer createChild(JXPathContext context, QName name, int index, Object value){
+ public NodePointer createChild(JXPathContext context,
+ QName name, int index, Object value)
+ {
if (parent instanceof PropertyPointer){
return parent.createChild(context, name, index, value);
}
@@ -165,7 +183,9 @@
}
}
- public NodePointer createChild(JXPathContext context, QName name, int index){
+ public NodePointer createChild(JXPathContext context,
+ QName name, int index)
+ {
if (parent instanceof PropertyPointer){
return parent.createChild(context, name, index);
}
@@ -196,7 +216,9 @@
index == other.index;
}
- public NodeIterator childIterator(NodeTest test, boolean reverse, NodePointer startWith){
+ public NodeIterator childIterator(NodeTest test,
+ boolean reverse, NodePointer startWith)
+ {
if (index == WHOLE_COLLECTION){
return null;
}
@@ -225,10 +247,35 @@
}
public boolean testNode(NodeTest nodeTest){
+// if (index
+ /** @todo: infinite loop here */
return getValuePointer().testNode(nodeTest);
}
- public int compareChildNodePointers(NodePointer pointer1, NodePointer pointer2){
+ public int compareChildNodePointers(
+ NodePointer pointer1, NodePointer pointer2)
+ {
return pointer1.getIndex() - pointer2.getIndex();
+ }
+
+ /**
+ * Returns an XPath that maps to this Pointer.
+ */
+ public String asPath() {
+ StringBuffer buffer = new StringBuffer();
+ NodePointer parent = getParent();
+ if (parent != null) {
+ buffer.append(parent.asPath());
+ }
+ if (index != WHOLE_COLLECTION) {
+ // Address the list[1][2] case
+ if (parent != null && !parent.isNode() &&
+ parent.getIndex() != WHOLE_COLLECTION){
+ buffer.append("/.");
+ }
+ buffer.append("[").append(index + 1).append(']');
+ }
+
+ return buffer.toString();
}
}
1.9 +6 -12 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.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- BeanPropertyPointer.java 12 Oct 2002 21:02:24 -0000 1.8
+++ BeanPropertyPointer.java 20 Oct 2002 03:47:17 -0000 1.9
@@ -62,11 +62,13 @@
package org.apache.commons.jxpath.ri.model.beans;
import java.beans.PropertyDescriptor;
+import java.util.Arrays;
import org.apache.commons.jxpath.AbstractFactory;
import org.apache.commons.jxpath.JXPathBeanInfo;
import org.apache.commons.jxpath.JXPathContext;
import org.apache.commons.jxpath.JXPathException;
+import org.apache.commons.jxpath.JXPathIntrospector;
import org.apache.commons.jxpath.ri.QName;
import org.apache.commons.jxpath.ri.model.NodePointer;
import org.apache.commons.jxpath.util.ValueUtils;
@@ -139,14 +141,6 @@
baseValue = UNINITIALIZED;
value = UNINITIALIZED;
}
- }
-
- /**
- * If the property contains a collection, then the length of that
- * collection, otherwise - 1.
- */
- public int getLength(){
- return ValueUtils.getLength(getBaseValue());
}
/**
1.7 +25 -37 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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- BeanPointer.java 10 Aug 2002 01:49:46 -0000 1.6
+++ BeanPointer.java 20 Oct 2002 03:47:17 -0000 1.7
@@ -65,13 +65,16 @@
import java.util.Locale;
import org.apache.commons.jxpath.JXPathBeanInfo;
+import org.apache.commons.jxpath.JXPathIntrospector;
import org.apache.commons.jxpath.ri.QName;
import org.apache.commons.jxpath.ri.model.NodePointer;
import org.apache.commons.jxpath.util.ValueUtils;
/**
- * A Pointer that points to a JavaBean or a collection. It is the first element of
- * a path, following elements will by of type PropertyPointer.
+ * A Pointer that points to a JavaBean or a collection. It is either
+ * the first element of a path or a pointer for a property value.
+ * Typically there is a BeanPropertyPointer between two BeanPointers
+ * in the chain.
*
* @author Dmitri Plotnikov
* @version $Revision$ $Date$
@@ -80,8 +83,6 @@
private QName name;
private Object bean;
private JXPathBeanInfo beanInfo;
- private PropertyDescriptor propertyDescriptors[];
- private String[] names;
public BeanPointer(QName name, Object bean, JXPathBeanInfo beanInfo, Locale locale){
super(null, locale);
@@ -116,39 +117,23 @@
}
/**
- * Throws an exception if you try to change the root element.
+ * Returns false
*/
- public void setValue(Object value){
- super.setValue(value);
- if (parent instanceof PropertyPointer){
- parent.setValue(value);
- }
- else if (parent != null){
- throw new UnsupportedOperationException("Cannot setValue of an object that is not some other object's property");
- }
- else {
- throw new UnsupportedOperationException("Cannot replace the root object");
- }
- }
-
- public void remove(){
- super.setValue(null);
- if (parent != null){
- parent.remove();
- }
- else {
- throw new UnsupportedOperationException(
- "Cannot remove an object that is not " +
- "some other object's property or a collection element");
- }
+ public boolean isCollection(){
+ return false;
}
/**
- * If the bean is a collection, returns the length of that collection,
- * otherwise returns 1.
+ * Returns 1.
*/
public int getLength(){
- return ValueUtils.getLength(getBaseValue());
+ return 1;
+ }
+
+ public boolean isLeaf() {
+ Object value = getNode();
+ return value == null
+ || JXPathIntrospector.getBeanInfo(value.getClass()).isAtomic();
}
public int hashCode(){
@@ -189,7 +174,10 @@
}
/**
- * Empty string
+ * If the pointer has a parent, then parent's path.
+ * If the bean is null, "null()".
+ * If the bean is a primitive value, the value itself.
+ * Otherwise - an empty string.
*/
public String asPath(){
if (parent != null){
@@ -211,6 +199,6 @@
else if (bean instanceof String){
return "'" + bean + "'";
}
- return "";
+ return "/";
}
}
1.6 +16 -5 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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- NamespacePointer.java 10 Aug 2002 16:13:04 -0000 1.5
+++ NamespacePointer.java 20 Oct 2002 03:47:18 -0000 1.6
@@ -95,6 +95,14 @@
public Object getBaseValue(){
return null;
}
+
+ public boolean isCollection(){
+ return false;
+ }
+
+ public int getLength(){
+ return 1;
+ }
public Object getNode(){
return getNamespaceURI();
@@ -128,7 +136,10 @@
StringBuffer buffer = new StringBuffer();
if (parent != null){
buffer.append(parent.asPath());
- buffer.append('/');
+ if (buffer.length() == 0 ||
+ buffer.charAt(buffer.length()-1) != '/'){
+ buffer.append('/');
+ }
}
buffer.append("namespace::");
buffer.append(prefix);
1.7 +16 -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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- DOMAttributePointer.java 10 Aug 2002 16:13:04 -0000 1.6
+++ DOMAttributePointer.java 20 Oct 2002 03:47:18 -0000 1.7
@@ -102,6 +102,14 @@
public Object getBaseValue(){
return attr;
}
+
+ public boolean isCollection(){
+ return false;
+ }
+
+ public int getLength(){
+ return 1;
+ }
public Object getNode(){
String value = attr.getValue();
@@ -145,7 +153,10 @@
StringBuffer buffer = new StringBuffer();
if (parent != null){
buffer.append(parent.asPath());
- buffer.append('/');
+ if (buffer.length() == 0 ||
+ buffer.charAt(buffer.length()-1) != '/'){
+ buffer.append('/');
+ }
}
buffer.append('@');
buffer.append(getName());
1.2 +28 -21 jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMNodeIterator.java
Index: JDOMNodeIterator.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMNodeIterator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JDOMNodeIterator.java 26 Aug 2002 22:29:48 -0000 1.1
+++ JDOMNodeIterator.java 20 Oct 2002 03:47:18 -0000 1.2
@@ -83,12 +83,11 @@
private boolean reverse;
private int position = 0;
private int index = 0;
-// private Element node;
private List children;
private Object child;
public JDOMNodeIterator(
- NodePointer parent, NodeTest nodeTest,
+ NodePointer parent, NodeTest nodeTest,
boolean reverse, NodePointer startWith)
{
this.parent = parent;
@@ -139,22 +138,30 @@
return true;
}
+ /**
+ * This is actually never invoked during the normal evaluation
+ * of xpaths - an iterator is always going forward, never backwards.
+ * So, this is implemented only for completeness and perhaps for
+ * those who use these iterators outside of XPath evaluation.
+ */
private boolean previous(){
- System.err.println("PREVIOUS"); // TBD
-// position--;
-// if (!reverse){
-// child = child.getPreviousSibling();
-// while (child != null && !testChild()){
-// child = child.getPreviousSibling();
-// }
-// }
-// else {
-// child = child.getNextSibling();
-// while (child != null && !testChild()){
-// child = child.getNextSibling();
-// }
-// }
-// return child != null;
+ position--;
+ if (!reverse){
+ while (--index >= 0){
+ child = children.get(index);
+ if (testChild()){
+ return true;
+ }
+ }
+ }
+ else {
+ for (;index < children.size(); index++){
+ child = children.get(index);
+ if (testChild()){
+ return true;
+ }
+ }
+ }
return false;
}
1.2 +16 -5 jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMNamespacePointer.java
Index: JDOMNamespacePointer.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMNamespacePointer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JDOMNamespacePointer.java 26 Aug 2002 22:29:48 -0000 1.1
+++ JDOMNamespacePointer.java 20 Oct 2002 03:47:18 -0000 1.2
@@ -95,6 +95,14 @@
public Object getBaseValue(){
return null;
}
+
+ public boolean isCollection(){
+ return false;
+ }
+
+ public int getLength(){
+ return 1;
+ }
public Object getNode(){
return getNamespaceURI();
@@ -129,7 +137,10 @@
StringBuffer buffer = new StringBuffer();
if (parent != null){
buffer.append(parent.asPath());
- buffer.append('/');
+ if (buffer.length() == 0 ||
+ buffer.charAt(buffer.length()-1) != '/'){
+ buffer.append('/');
+ }
}
buffer.append("namespace::");
buffer.append(prefix);
1.2 +16 -13 jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMAttributePointer.java
Index: JDOMAttributePointer.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMAttributePointer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JDOMAttributePointer.java 26 Aug 2002 22:29:48 -0000 1.1
+++ JDOMAttributePointer.java 20 Oct 2002 03:47:18 -0000 1.2
@@ -97,25 +97,25 @@
uri = null;
}
return uri;
-// String prefix = DOMNodePointer.getPrefix(attr);
-// if (prefix == null){
-// return null;
-// }
-// return parent.getNamespaceURI(prefix);
}
public Object getBaseValue(){
return attr;
}
+
+ public boolean isCollection(){
+ return false;
+ }
+
+ public int getLength(){
+ return 1;
+ }
public Object getNode(){
String value = attr.getValue();
if (value == null){
return null;
}
-// if (value.equals("") && !attr.getSpecified()){
-// return null;
-// }
return value;
}
@@ -150,7 +150,10 @@
StringBuffer buffer = new StringBuffer();
if (parent != null){
buffer.append(parent.asPath());
- buffer.append('/');
+ if (buffer.length() == 0 ||
+ buffer.charAt(buffer.length()-1) != '/'){
+ buffer.append('/');
+ }
}
buffer.append('@');
buffer.append(getName());
1.2 +4 -5 jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dynabeans/DynaBeanPropertyPointer.java
Index: DynaBeanPropertyPointer.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dynabeans/DynaBeanPropertyPointer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DynaBeanPropertyPointer.java 20 Oct 2002 03:44:18 -0000 1.1
+++ DynaBeanPropertyPointer.java 20 Oct 2002 03:47:18 -0000 1.2
@@ -134,7 +134,6 @@
}
}
Arrays.sort(names);
-// System.err.println("D.PROPERTIES: " + Arrays.asList(names));
}
return names;
}
1.5 +22 -5 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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ContainerPointer.java 26 Aug 2002 22:29:22 -0000 1.4
+++ ContainerPointer.java 20 Oct 2002 03:47:18 -0000 1.5
@@ -106,6 +106,23 @@
public Object getBaseValue(){
return container.getValue();
}
+
+ public boolean isCollection(){
+ Object value = getBaseValue();
+ return value != null && ValueUtils.isCollection(value);
+ }
+
+ public int getLength(){
+ Object value = getBaseValue();
+ if (value == null) {
+ return 1;
+ }
+ return ValueUtils.getLength(value);
+ }
+
+ public boolean isLeaf() {
+ return getValuePointer().isLeaf();
+ }
public Object getNode(){
Object value = getBaseValue();
@@ -178,6 +195,6 @@
if (parent != null){
return parent.asPath();
}
- return "";
+ return "/";
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>