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/08/10 03:49:46 UTC
cvs commit: jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans BeanPointer.java DynamicPointer.java NullElementPointer.java NullPointer.java NullPropertyPointer.java PropertyOwnerPointer.java
dmitri 2002/08/09 18:49:46
Modified: jxpath/src/java/org/apache/commons/jxpath/ri/model
NodePointer.java
jxpath/src/java/org/apache/commons/jxpath/ri/model/beans
BeanPointer.java DynamicPointer.java
NullElementPointer.java NullPointer.java
NullPropertyPointer.java PropertyOwnerPointer.java
Log:
Promoted a common method to the superclass
Revision Changes Path
1.9 +25 -11 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.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- NodePointer.java 3 Jul 2002 21:12:36 -0000 1.8
+++ NodePointer.java 10 Aug 2002 01:49:46 -0000 1.9
@@ -421,6 +421,10 @@
* May return null if the object does not support the attributes.
*/
public NodeIterator attributeIterator(QName qname) {
+ NodePointer valuePointer = getValuePointer();
+ if (valuePointer != null && valuePointer != this){
+ return valuePointer.attributeIterator(qname);
+ }
return null;
}
@@ -612,14 +616,24 @@
return p1.parent.compareChildNodePointers(p1, p2);
}
+ /**
+ * Print internal structure of a pointer for debugging
+ */
public void printPointerChain(){
- Pointer p = this;
- while (p != null){
- System.err.println((p == this ? "POINTER: " : " PARENT: ")
- + p.getClass() + " " + p.asPath());
- if (p instanceof NodePointer){
- p = ((NodePointer)p).getParent();
- }
+ printDeep(this, "");
+ }
+
+ private static void printDeep(NodePointer pointer, String indent){
+ if (indent.length() == 0){
+ System.err.println("POINTER: " + pointer + "(" +
+ pointer.getClass().getName() + ")");
+ }
+ else {
+ System.err.println(indent + " of " + pointer + "(" +
+ pointer.getClass().getName() + ")");
+ }
+ if (pointer.getParent() != null){
+ printDeep(pointer.getParent(), indent + " ");
}
}
}
1.6 +16 -0 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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- BeanPointer.java 11 Jul 2002 01:17:16 -0000 1.5
+++ BeanPointer.java 10 Aug 2002 01:49:46 -0000 1.6
@@ -115,6 +115,22 @@
return bean;
}
+ /**
+ * Throws an exception if you try to change the root element.
+ */
+ 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){
1.5 +13 -0 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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DynamicPointer.java 11 Jul 2002 01:17:16 -0000 1.4
+++ DynamicPointer.java 10 Aug 2002 01:49:46 -0000 1.5
@@ -110,6 +110,19 @@
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");
+ }
+ }
+
/**
* If the bean is a collection, returns the length of that collection,
* otherwise returns 1.
1.7 +10 -0 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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- NullElementPointer.java 11 Jul 2002 01:17:16 -0000 1.6
+++ NullElementPointer.java 10 Aug 2002 01:49:46 -0000 1.7
@@ -106,6 +106,16 @@
return new NullPointer(this, getName());
}
+ 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");
+ }
+ }
+
public boolean isActual(){
return false;
}
1.6 +10 -0 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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- NullPointer.java 11 Jul 2002 01:17:16 -0000 1.5
+++ NullPointer.java 10 Aug 2002 01:49:46 -0000 1.6
@@ -101,6 +101,16 @@
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 isActual(){
return false;
}
1.6 +17 -12 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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- NullPropertyPointer.java 8 May 2002 23:05:05 -0000 1.5
+++ NullPropertyPointer.java 10 Aug 2002 01:49:46 -0000 1.6
@@ -73,7 +73,7 @@
public class NullPropertyPointer extends PropertyPointer {
private String propertyName = "*";
- private boolean dynamic = false;
+ private boolean byNameAttribute = false;
/**
*/
@@ -129,11 +129,13 @@
return parent.createChild(context, getName(), getIndex(), value);
}
- public NodePointer createChild(JXPathContext context, QName name, int index, Object value){
+ public NodePointer createChild(JXPathContext context,
+ QName name, int index, Object value){
return createPath(context).createChild(context, name, index, value);
}
- public NodePointer createChild(JXPathContext context, QName name, int index){
+ public NodePointer createChild(JXPathContext context,
+ QName name, int index){
return createPath(context).createChild(context, name, index);
}
@@ -145,8 +147,9 @@
this.propertyName = propertyName;
}
- public void setDynamic(boolean flag){
- dynamic = flag;
+ public void setNameAttributeValue(String attributeValue){
+ this.propertyName = attributeValue;
+ byNameAttribute = true;
}
public boolean isCollection(){
@@ -162,7 +165,7 @@
}
public String asPath(){
- if (!dynamic){
+ if (!byNameAttribute){
return super.asPath();
}
else {
@@ -181,12 +184,14 @@
private String escape(String string){
int index = string.indexOf('\'');
while (index != -1){
- string = string.substring(0, index) + "'" + string.substring(index + 1);
+ string = string.substring(0, index) + "'" +
+ string.substring(index + 1);
index = string.indexOf('\'');
}
index = string.indexOf('\"');
while (index != -1){
- string = string.substring(0, index) + """ + string.substring(index + 1);
+ string = string.substring(0, index) + """ +
+ string.substring(index + 1);
index = string.indexOf('\"');
}
return string;
1.7 +0 -15 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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- PropertyOwnerPointer.java 11 Jul 2002 01:17:16 -0000 1.6
+++ PropertyOwnerPointer.java 10 Aug 2002 01:49:46 -0000 1.7
@@ -149,23 +149,8 @@
}
public abstract QName getName();
-
public void setValue(Object value){
this.value = value;
- if (parent != null){
- if (!parent.isNode()){
- parent.setValue(value);
- }
- else {
- 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 abstract PropertyPointer getPropertyPointer();
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>