Return-Path: Delivered-To: apmail-incubator-bval-commits-archive@minotaur.apache.org Received: (qmail 2512 invoked from network); 9 Sep 2010 21:42:59 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 9 Sep 2010 21:42:59 -0000 Received: (qmail 59362 invoked by uid 500); 9 Sep 2010 21:42:59 -0000 Delivered-To: apmail-incubator-bval-commits-archive@incubator.apache.org Received: (qmail 59329 invoked by uid 500); 9 Sep 2010 21:42:59 -0000 Mailing-List: contact bval-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: bval-dev@incubator.apache.org Delivered-To: mailing list bval-commits@incubator.apache.org Received: (qmail 59321 invoked by uid 99); 9 Sep 2010 21:42:59 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Sep 2010 21:42:59 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Sep 2010 21:42:56 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id BA5BB238897D; Thu, 9 Sep 2010 21:42:35 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: bval-commits@incubator.apache.org From: mbenson@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100909214235.BA5BB238897D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 { /** * 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 { + + /** + * {@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 + * @param propertyPath + * @param callback + * @return T result + */ + public static T navigateAndReturn(String propertyPath, Callback 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