TCK: ctor return value validation considers value itself as first leaf bean
Project: http://git-wip-us.apache.org/repos/asf/bval/repo Commit: http://git-wip-us.apache.org/repos/asf/bval/commit/00f3e450 Tree: http://git-wip-us.apache.org/repos/asf/bval/tree/00f3e450 Diff: http://git-wip-us.apache.org/repos/asf/bval/diff/00f3e450 Branch: refs/heads/bv2 Commit: 00f3e450098dc61210f81d6d4d8fbbd4e89f6e4e Parents: 7a332de Author: Matt Benson <[email protected]> Authored: Fri Mar 30 11:10:38 2018 -0500 Committer: Matt Benson <[email protected]> Committed: Tue Oct 16 12:28:20 2018 -0500 ---------------------------------------------------------------------- .../bval/jsr/job/ValidateReturnValue.java | 32 +++++++++++++++----- 1 file changed, 25 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/bval/blob/00f3e450/bval-jsr/src/main/java/org/apache/bval/jsr/job/ValidateReturnValue.java ---------------------------------------------------------------------- diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/job/ValidateReturnValue.java b/bval-jsr/src/main/java/org/apache/bval/jsr/job/ValidateReturnValue.java index f8d030b..4b469bb 100644 --- a/bval-jsr/src/main/java/org/apache/bval/jsr/job/ValidateReturnValue.java +++ b/bval-jsr/src/main/java/org/apache/bval/jsr/job/ValidateReturnValue.java @@ -64,6 +64,16 @@ public abstract class ValidateReturnValue<E extends Executable, T> extends Valid .getBeanDescriptor(object.getClass()) .getConstraintsForMethod(executable.getName(), executable.getParameterTypes()); } + + @Override + protected ValidationJob<T>.Frame<?> createBaseFrame(ReturnValueD<?, ?> descriptor, GraphContext context) { + return new SproutFrame<ReturnValueD<?, ?>>(descriptor, context) { + @Override + Object getBean() { + return getRootBean(); + } + }; + } } public static class ForConstructor<T> extends ValidateReturnValue<Constructor<?>, T> { @@ -93,6 +103,17 @@ public abstract class ValidateReturnValue<E extends Executable, T> extends Valid .getBeanDescriptor(executable.getDeclaringClass()) .getConstraintsForConstructor(executable.getParameterTypes()); } + + @Override + protected ValidationJob<T>.Frame<?> createBaseFrame(ReturnValueD<?, ?> descriptor, GraphContext context) { + final Object returnValue = context.getValue(); + return new SproutFrame<ReturnValueD<?, ?>>(descriptor, context) { + @Override + Object getBean() { + return returnValue; + } + }; + } } private final Object returnValue; @@ -112,13 +133,8 @@ public abstract class ValidateReturnValue<E extends Executable, T> extends Valid final PathImpl path = createBasePath(); path.addNode(new NodeImpl.ReturnValueNodeImpl()); - return new SproutFrame<ReturnValueD<?, ?>>((ReturnValueD<?, ?>) describe().getReturnValueDescriptor(), - new GraphContext(validatorContext, path, returnValue)) { - @Override - Object getBean() { - return getRootBean(); - } - }; + return createBaseFrame((ReturnValueD<?, ?>) describe().getReturnValueDescriptor(), + new GraphContext(validatorContext, path, returnValue)); } @Override @@ -137,4 +153,6 @@ public abstract class ValidateReturnValue<E extends Executable, T> extends Valid protected abstract ExecutableD<?, ?, ?> describe(); protected abstract T getRootBean(); + + protected abstract Frame<?> createBaseFrame(ReturnValueD<?, ?> descriptor, GraphContext context); }
