bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r995583 - in /incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/util: NestedPathNavigator.java PathNavigation.java
Date Thu, 09 Sep 2010 21:42:35 GMT
Author: mbenson
Date: Thu Sep  9 21:42:35 2010
New Revision: 995583

URL: http://svn.apache.org/viewvc?rev=995583&view=rev
Log:
add a result to the PathNavigation callback interface; some comments

Modified:
    incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/NestedPathNavigator.java
    incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/PathNavigation.java
  (contents, props changed)

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/NestedPathNavigator.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/NestedPathNavigator.java?rev=995583&r1=995582&r2=995583&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/NestedPathNavigator.java
(original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/NestedPathNavigator.java
Thu Sep  9 21:42:35 2010
@@ -20,7 +20,7 @@ import java.lang.reflect.Type;
 
 import org.apache.bval.DynamicMetaBean;
 import org.apache.bval.jsr303.UnknownPropertyException;
-import org.apache.bval.jsr303.util.PathNavigation.Callback;
+import org.apache.bval.jsr303.util.PathNavigation.CallbackProcedure;
 import org.apache.bval.model.MetaBean;
 import org.apache.bval.model.MetaProperty;
 import org.apache.bval.model.ValidationContext;
@@ -70,7 +70,7 @@ public class NestedPathNavigator {
     /**
      * Graph traversal worker.
      */
-    protected static class Traversal implements Callback {
+    protected static class Traversal extends CallbackProcedure {
         private ValidationContext<?> validationContext;
         private Type type;
         private Class<?> rawType;

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/PathNavigation.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/PathNavigation.java?rev=995583&r1=995582&r2=995583&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/PathNavigation.java
(original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/PathNavigation.java
Thu Sep  9 21:42:35 2010
@@ -25,14 +25,13 @@ import javax.validation.ValidationExcept
  * 
  * @version $Rev$ $Date$
  */
+//TODO share code with PathImpl
 public class PathNavigation {
+
     /**
-     * Interface defining calls that PathNavigation makes as it traverses a path
-     * expression.
-     * 
-     * @version $Rev$ $Date$
+     * Path traversal callback function interface.
      */
-    public interface Callback {
+    public interface Callback<T> {
         /**
          * Handle a .-delimited property.
          * 
@@ -46,6 +45,26 @@ public class PathNavigation {
          * @param value
          */
         void handleIndexOrKey(String value);
+
+        /**
+         * Return a result. Called after navigation is complete.
+         * 
+         * @return result
+         */
+        T result();
+    }
+
+    /**
+     * Callback "procedure" that always returns null.
+     */
+    public static abstract class CallbackProcedure implements Callback<Object> {
+
+        /**
+         * {@inheritDoc}
+         */
+        public final Object result() {
+            return null;
+        }
     }
 
     /**
@@ -60,7 +79,19 @@ public class PathNavigation {
      * @param propertyPath
      * @param callback
      */
-    public static void navigate(String propertyPath, Callback callback) {
+    public static void navigate(String propertyPath, Callback<?> callback) {
+        navigateAndReturn(propertyPath, callback);
+    }
+
+    /**
+     * Navigate a path using the specified callback, returning its result.
+     * 
+     * @param <T>
+     * @param propertyPath
+     * @param callback
+     * @return T result
+     */
+    public static <T> T navigateAndReturn(String propertyPath, Callback<? extends
T> callback) {
         try {
             StringTokenizer tokens = new StringTokenizer(propertyPath, ".[]", true);
             while (tokens.hasMoreTokens()) {
@@ -82,6 +113,7 @@ public class PathNavigation {
                 // else, it is a property name
                 callback.handleProperty(token);
             }
+            return callback.result();
         } catch (ValidationException ex) {
             throw ex;
         } catch (Exception ex) {

Propchange: incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/PathNavigation.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message