You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mb...@apache.org on 2012/01/20 18:55:55 UTC

svn commit: r1234034 - in /commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri: JXPathContextReferenceImpl.java model/NodePointer.java

Author: mbenson
Date: Fri Jan 20 17:55:54 2012
New Revision: 1234034

URL: http://svn.apache.org/viewvc?rev=1234034&view=rev
Log:
refactor

Modified:
    commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java
    commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/NodePointer.java

Modified: commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java?rev=1234034&r1=1234033&r2=1234034&view=diff
==============================================================================
--- commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java (original)
+++ commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java Fri Jan 20 17:55:54 2012
@@ -370,21 +370,8 @@ public class JXPathContextReferenceImpl 
         }
         if (result instanceof NodePointer) {
             result = ((NodePointer) result).getValuePointer();
-            if (!isLenient() && !((NodePointer) result).isActual()) {
-                // We need to differentiate between pointers representing
-                // a non-existing property and ones representing a property
-                // whose value is null.  In the latter case, the pointer
-                // is going to have isActual == false, but its parent,
-                // which is a non-node pointer identifying the bean property,
-                // will return isActual() == true.
-                NodePointer parent =
-                    ((NodePointer) result).getImmediateParentPointer();
-                if (parent == null
-                    || !parent.isContainer()
-                    || !parent.isActual()) {
-                    throw new JXPathNotFoundException("No value for xpath: "
-                            + xpath);
-                }
+            if (!isLenient()) {
+                NodePointer.verify((NodePointer) result);
             }
             result = ((NodePointer) result).getValue();
         }

Modified: commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/NodePointer.java
URL: http://svn.apache.org/viewvc/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/NodePointer.java?rev=1234034&r1=1234033&r2=1234034&view=diff
==============================================================================
--- commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/NodePointer.java (original)
+++ commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/NodePointer.java Fri Jan 20 17:55:54 2012
@@ -23,6 +23,7 @@ import org.apache.commons.jxpath.Abstrac
 import org.apache.commons.jxpath.ExceptionHandler;
 import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.jxpath.JXPathException;
+import org.apache.commons.jxpath.JXPathNotFoundException;
 import org.apache.commons.jxpath.NodeSet;
 import org.apache.commons.jxpath.Pointer;
 import org.apache.commons.jxpath.ri.Compiler;
@@ -914,4 +915,28 @@ public abstract class NodePointer implem
     private static boolean safeEquals(Object o1, Object o2) {
         return o1 == o2 || o1 != null && o1.equals(o2);
     }
+
+    /**
+     * Verify the structure of a given NodePointer.
+     * @param nodePointer
+     * @return nodePointer
+     * @throws JXPathNotFoundException
+     */
+    public static NodePointer verify(NodePointer nodePointer) {
+        if (!nodePointer.isActual()) {
+            // We need to differentiate between pointers representing
+            // a non-existing property and ones representing a property
+            // whose value is null.  In the latter case, the pointer
+            // is going to have isActual == false, but its parent,
+            // which is a non-node pointer identifying the bean property,
+            // will return isActual() == true.
+            NodePointer parent = nodePointer.getImmediateParentPointer();
+            if (parent == null
+                || !parent.isContainer()
+                || !parent.isActual()) {
+                throw new JXPathNotFoundException("No value for xpath: " + nodePointer);
+            }
+        }
+        return nodePointer;
+    }
 }