You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bval.apache.org by mb...@apache.org on 2018/03/16 22:59:01 UTC

[01/12] bval git commit: executable descriptor cleanup

Repository: bval
Updated Branches:
  refs/heads/bv2 36920e87f -> f8da02117


executable descriptor cleanup


Project: http://git-wip-us.apache.org/repos/asf/bval/repo
Commit: http://git-wip-us.apache.org/repos/asf/bval/commit/433e42b2
Tree: http://git-wip-us.apache.org/repos/asf/bval/tree/433e42b2
Diff: http://git-wip-us.apache.org/repos/asf/bval/diff/433e42b2

Branch: refs/heads/bv2
Commit: 433e42b2ed1d7799053031b8bd0866501e032c4b
Parents: 36920e8
Author: Matt Benson <mb...@apache.org>
Authored: Thu Mar 15 15:21:25 2018 -0500
Committer: Matt Benson <mb...@apache.org>
Committed: Thu Mar 15 15:21:25 2018 -0500

----------------------------------------------------------------------
 .../java/org/apache/bval/jsr/descriptor/ConstructorD.java |  5 -----
 .../org/apache/bval/jsr/descriptor/DescriptorManager.java |  9 +++++++--
 .../java/org/apache/bval/jsr/descriptor/ExecutableD.java  | 10 ++--------
 .../main/java/org/apache/bval/jsr/descriptor/MethodD.java |  5 -----
 4 files changed, 9 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/bval/blob/433e42b2/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/ConstructorD.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/ConstructorD.java b/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/ConstructorD.java
index 2385384..f917d35 100644
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/ConstructorD.java
+++ b/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/ConstructorD.java
@@ -33,9 +33,4 @@ public class ConstructorD<T> extends ExecutableD<Constructor<? extends T>, Metad
     public Class<?> getElementClass() {
         return getParent().getElementClass();
     }
-
-    @Override
-    protected String nameOf(Constructor<? extends T> e) {
-        return e.getDeclaringClass().getSimpleName();
-    }
 }

http://git-wip-us.apache.org/repos/asf/bval/blob/433e42b2/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/DescriptorManager.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/DescriptorManager.java b/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/DescriptorManager.java
index 3c7365e..8f1e22f 100644
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/DescriptorManager.java
+++ b/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/DescriptorManager.java
@@ -25,6 +25,7 @@ import javax.validation.metadata.BeanDescriptor;
 import javax.validation.metadata.CascadableDescriptor;
 import javax.validation.metadata.ContainerDescriptor;
 import javax.validation.metadata.ElementDescriptor;
+import javax.validation.metadata.ExecutableDescriptor;
 
 import org.apache.bval.jsr.ApacheValidatorFactory;
 import org.apache.bval.jsr.metadata.AnnotationBehaviorMergeStrategy;
@@ -38,8 +39,12 @@ import org.apache.bval.util.Validate;
 public class DescriptorManager {
     public static <D extends ElementDescriptor & CascadableDescriptor & ContainerDescriptor> boolean isConstrained(
         D descriptor) {
-        return descriptor.hasConstraints() || descriptor.isCascaded()
-            || !descriptor.getConstrainedContainerElementTypes().isEmpty();
+        return descriptor != null && (descriptor.hasConstraints() || descriptor.isCascaded()
+            || !descriptor.getConstrainedContainerElementTypes().isEmpty());
+    }
+
+    public static <E extends ExecutableDescriptor> boolean isConstrained(E descriptor) {
+        return descriptor != null && (descriptor.hasConstrainedParameters() || descriptor.hasConstrainedReturnValue());
     }
 
     private final ApacheValidatorFactory validatorFactory;

http://git-wip-us.apache.org/repos/asf/bval/blob/433e42b2/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/ExecutableD.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/ExecutableD.java b/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/ExecutableD.java
index 4cbb22f..eab7a9a 100644
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/ExecutableD.java
+++ b/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/ExecutableD.java
@@ -68,17 +68,11 @@ public abstract class ExecutableD<E extends Executable, R extends MetadataReader
 
     @Override
     public final boolean hasConstrainedParameters() {
-        return parameters.stream().anyMatch(this::isConstrained);
+        return parameters.stream().anyMatch(DescriptorManager::isConstrained) || getCrossParameterDescriptor().hasConstraints();
     }
 
     @Override
     public final boolean hasConstrainedReturnValue() {
-        return isConstrained(returnValue);
-    }
-
-    protected abstract String nameOf(E e);
-
-    private boolean isConstrained(CascadableContainerD<?, ?> child) {
-        return child.isCascaded() || child.hasConstraints();
+        return DescriptorManager.isConstrained(returnValue);
     }
 }

http://git-wip-us.apache.org/repos/asf/bval/blob/433e42b2/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/MethodD.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/MethodD.java b/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/MethodD.java
index 73585b5..04ff63e 100644
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/MethodD.java
+++ b/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/MethodD.java
@@ -41,9 +41,4 @@ class MethodD extends ExecutableD<Method, MetadataReader.ForMethod, MethodD> imp
     MethodType getMethodType() {
         return methodType;
     }
-
-    @Override
-    protected String nameOf(Method e) {
-        return e.getName();
-    }
 }


[06/12] bval git commit: refactor decimal min/max constraints and support new #inclusive() members of associated constraints

Posted by mb...@apache.org.
refactor decimal min/max constraints and support new #inclusive() members of associated constraints


Project: http://git-wip-us.apache.org/repos/asf/bval/repo
Commit: http://git-wip-us.apache.org/repos/asf/bval/commit/e34b20bb
Tree: http://git-wip-us.apache.org/repos/asf/bval/tree/e34b20bb
Diff: http://git-wip-us.apache.org/repos/asf/bval/diff/e34b20bb

Branch: refs/heads/bv2
Commit: e34b20bb8eea81685b25f9aefeabe8575f17c28a
Parents: 0bf9b3a
Author: Matt Benson <mb...@apache.org>
Authored: Fri Mar 16 17:52:06 2018 -0500
Committer: Matt Benson <mb...@apache.org>
Committed: Fri Mar 16 17:52:06 2018 -0500

----------------------------------------------------------------------
 .../bval/constraints/DecimalMaxValidator.java   | 75 ++++++++++++++++++++
 .../DecimalMaxValidatorForNumber.java           | 56 ---------------
 .../DecimalMaxValidatorForString.java           | 54 --------------
 .../bval/constraints/DecimalMinValidator.java   | 75 ++++++++++++++++++++
 .../DecimalMinValidatorForNumber.java           | 56 ---------------
 .../DecimalMinValidatorForString.java           | 56 ---------------
 .../bval/jsr/DefaultConstraints.properties      | 10 +--
 7 files changed, 156 insertions(+), 226 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/bval/blob/e34b20bb/bval-jsr/src/main/java/org/apache/bval/constraints/DecimalMaxValidator.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/constraints/DecimalMaxValidator.java b/bval-jsr/src/main/java/org/apache/bval/constraints/DecimalMaxValidator.java
new file mode 100644
index 0000000..1862168
--- /dev/null
+++ b/bval-jsr/src/main/java/org/apache/bval/constraints/DecimalMaxValidator.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.bval.constraints;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.DecimalMax;
+
+public abstract class DecimalMaxValidator<T> implements ConstraintValidator<DecimalMax, T> {
+    public static class ForString extends DecimalMaxValidator<String> {
+        @Override
+        public boolean isValid(String value, ConstraintValidatorContext context) {
+            return value == null || isValid(new BigDecimal(value));
+        }
+    }
+
+    public static class ForNumber extends DecimalMaxValidator<Number> {
+        @Override
+        public boolean isValid(Number value, ConstraintValidatorContext context) {
+            if (value == null) {
+                return true;
+            }
+            final BigDecimal bigValue;
+            if (value instanceof BigDecimal) {
+                bigValue = (BigDecimal) value;
+            } else if (value instanceof BigInteger) {
+                bigValue = new BigDecimal((BigInteger) value);
+            } else {
+                bigValue = new BigDecimal(value.doubleValue());
+            }
+            return isValid(bigValue);
+        }
+    }
+
+    private BigDecimal maxValue;
+    private boolean inclusive;
+
+    @Override
+    public void initialize(DecimalMax annotation) {
+        try {
+            this.maxValue = new BigDecimal(annotation.value());
+        } catch (NumberFormatException nfe) {
+            throw new IllegalArgumentException(annotation.value() + " does not represent a valid BigDecimal format");
+        }
+        this.inclusive = annotation.inclusive();
+    }
+
+    protected boolean isValid(BigDecimal value) {
+        // null values are valid
+        if (value == null) {
+            return true;
+        }
+        final int comparison = value.compareTo(maxValue);
+        return comparison < 0 || inclusive && comparison == 0;
+    }
+}

http://git-wip-us.apache.org/repos/asf/bval/blob/e34b20bb/bval-jsr/src/main/java/org/apache/bval/constraints/DecimalMaxValidatorForNumber.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/constraints/DecimalMaxValidatorForNumber.java b/bval-jsr/src/main/java/org/apache/bval/constraints/DecimalMaxValidatorForNumber.java
deleted file mode 100644
index 725613c..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/constraints/DecimalMaxValidatorForNumber.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.bval.constraints;
-
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-import javax.validation.constraints.DecimalMax;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-
-/** Description: validate that number-value of passed object is <= maxvalue<br/> */
-public class DecimalMaxValidatorForNumber implements ConstraintValidator<DecimalMax, Number> {
-
-    private BigDecimal maxValue;
-
-    @Override
-    public void initialize(DecimalMax annotation) {
-        try {
-            this.maxValue = new BigDecimal(annotation.value());
-        } catch (NumberFormatException nfe) {
-            throw new IllegalArgumentException(annotation.value() + " does not represent a valid BigDecimal format");
-        }
-    }
-
-    @Override
-    public boolean isValid(Number value, ConstraintValidatorContext context) {
-        if (value == null) {
-            return true;
-        }
-        BigDecimal bigValue;
-        if (value instanceof BigDecimal) {
-            bigValue = (BigDecimal) value;
-        } else if (value instanceof BigInteger) {
-            bigValue = new BigDecimal((BigInteger) value);
-        } else {
-            bigValue = new BigDecimal(value.doubleValue());
-        }
-        return bigValue.compareTo(maxValue) < 1;
-    }
-}

http://git-wip-us.apache.org/repos/asf/bval/blob/e34b20bb/bval-jsr/src/main/java/org/apache/bval/constraints/DecimalMaxValidatorForString.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/constraints/DecimalMaxValidatorForString.java b/bval-jsr/src/main/java/org/apache/bval/constraints/DecimalMaxValidatorForString.java
deleted file mode 100644
index cb0e232..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/constraints/DecimalMaxValidatorForString.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.bval.constraints;
-
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-import javax.validation.constraints.DecimalMax;
-import java.math.BigDecimal;
-
-/**
- * Check that the String being validated represents a number, and has a value
- * <= maxvalue
- */
-public class DecimalMaxValidatorForString implements ConstraintValidator<DecimalMax, String> {
-
-    private BigDecimal maxValue;
-
-    @Override
-    public void initialize(DecimalMax annotation) {
-        try {
-            this.maxValue = new BigDecimal(annotation.value());
-        } catch (NumberFormatException nfe) {
-            throw new IllegalArgumentException(annotation.value() + " does not represent a valid BigDecimal format");
-        }
-    }
-
-    @Override
-    public boolean isValid(String value, ConstraintValidatorContext context) {
-        if (value == null) {
-            return true;
-        }
-        try {
-            return new BigDecimal(value).compareTo(maxValue) < 1;
-        } catch (NumberFormatException nfe) {
-            return false;
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/bval/blob/e34b20bb/bval-jsr/src/main/java/org/apache/bval/constraints/DecimalMinValidator.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/constraints/DecimalMinValidator.java b/bval-jsr/src/main/java/org/apache/bval/constraints/DecimalMinValidator.java
new file mode 100644
index 0000000..9ada336
--- /dev/null
+++ b/bval-jsr/src/main/java/org/apache/bval/constraints/DecimalMinValidator.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.bval.constraints;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.DecimalMin;
+
+public abstract class DecimalMinValidator<T> implements ConstraintValidator<DecimalMin, T> {
+    public static class ForString extends DecimalMinValidator<String> {
+        @Override
+        public boolean isValid(String value, ConstraintValidatorContext context) {
+            return value == null || isValid(new BigDecimal(value));
+        }
+    }
+
+    public static class ForNumber extends DecimalMinValidator<Number> {
+        @Override
+        public boolean isValid(Number value, ConstraintValidatorContext context) {
+            if (value == null) {
+                return true;
+            }
+            final BigDecimal bigValue;
+            if (value instanceof BigDecimal) {
+                bigValue = (BigDecimal) value;
+            } else if (value instanceof BigInteger) {
+                bigValue = new BigDecimal((BigInteger) value);
+            } else {
+                bigValue = new BigDecimal(value.doubleValue());
+            }
+            return isValid(bigValue);
+        }
+    }
+
+    private BigDecimal minValue;
+    private boolean inclusive;
+
+    @Override
+    public void initialize(DecimalMin annotation) {
+        try {
+            this.minValue = new BigDecimal(annotation.value());
+        } catch (NumberFormatException nfe) {
+            throw new IllegalArgumentException(annotation.value() + " does not represent a valid BigDecimal format");
+        }
+        this.inclusive = annotation.inclusive();
+    }
+
+    protected boolean isValid(BigDecimal value) {
+        // null values are valid
+        if (value == null) {
+            return true;
+        }
+        final int comparison = value.compareTo(minValue);
+        return comparison > 0 || inclusive && comparison == 0;
+    }
+}

http://git-wip-us.apache.org/repos/asf/bval/blob/e34b20bb/bval-jsr/src/main/java/org/apache/bval/constraints/DecimalMinValidatorForNumber.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/constraints/DecimalMinValidatorForNumber.java b/bval-jsr/src/main/java/org/apache/bval/constraints/DecimalMinValidatorForNumber.java
deleted file mode 100644
index 17c6c38..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/constraints/DecimalMinValidatorForNumber.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.bval.constraints;
-
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-import javax.validation.constraints.DecimalMin;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-
-/** Description: validate that number-value of passed object is >= minvalue<br/> */
-public class DecimalMinValidatorForNumber implements ConstraintValidator<DecimalMin, Number> {
-
-    private BigDecimal minValue;
-
-    @Override
-    public void initialize(DecimalMin annotation) {
-        try {
-            this.minValue = new BigDecimal(annotation.value());
-        } catch (NumberFormatException nfe) {
-            throw new IllegalArgumentException(annotation.value() + " does not represent a valid BigDecimal format");
-        }
-    }
-
-    @Override
-    public boolean isValid(Number value, ConstraintValidatorContext context) {
-        if (value == null) {
-            return true;
-        }
-        BigDecimal bigValue;
-        if (value instanceof BigDecimal) {
-            bigValue = (BigDecimal) value;
-        } else if (value instanceof BigInteger) {
-            bigValue = new BigDecimal((BigInteger) value);
-        } else {
-            bigValue = new BigDecimal(value.doubleValue());
-        }
-        return bigValue.compareTo(minValue) >= 0;
-    }
-}

http://git-wip-us.apache.org/repos/asf/bval/blob/e34b20bb/bval-jsr/src/main/java/org/apache/bval/constraints/DecimalMinValidatorForString.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/constraints/DecimalMinValidatorForString.java b/bval-jsr/src/main/java/org/apache/bval/constraints/DecimalMinValidatorForString.java
deleted file mode 100644
index ef62387..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/constraints/DecimalMinValidatorForString.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.bval.constraints;
-
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-import javax.validation.constraints.DecimalMin;
-import java.math.BigDecimal;
-
-/**
- * Description:
- * Check that the String being validated represents a number, and has a value
- * >= minvalue
- */
-public class DecimalMinValidatorForString implements ConstraintValidator<DecimalMin, String> {
-
-    private BigDecimal minValue;
-
-    @Override
-    public void initialize(DecimalMin annotation) {
-        try {
-            this.minValue = new BigDecimal(annotation.value());
-        } catch (NumberFormatException nfe) {
-            throw new IllegalArgumentException(annotation.value() + " does not represent a valid BigDecimal format");
-        }
-    }
-
-    @Override
-    public boolean isValid(String value, ConstraintValidatorContext context) {
-        //null values are valid
-        if (value == null) {
-            return true;
-        }
-        try {
-            return new BigDecimal(value).compareTo(minValue) >= 0;
-        } catch (NumberFormatException nfe) {
-            return false;
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/bval/blob/e34b20bb/bval-jsr/src/main/resources/org/apache/bval/jsr/DefaultConstraints.properties
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/resources/org/apache/bval/jsr/DefaultConstraints.properties b/bval-jsr/src/main/resources/org/apache/bval/jsr/DefaultConstraints.properties
index 6f481da..a092cfa 100644
--- a/bval-jsr/src/main/resources/org/apache/bval/jsr/DefaultConstraints.properties
+++ b/bval-jsr/src/main/resources/org/apache/bval/jsr/DefaultConstraints.properties
@@ -23,11 +23,13 @@
 javax.validation.constraints.AssertFalse=org.apache.bval.constraints.AssertFalseValidator
 javax.validation.constraints.AssertTrue=org.apache.bval.constraints.AssertTrueValidator
 
-javax.validation.constraints.DecimalMax=org.apache.bval.constraints.DecimalMaxValidatorForNumber,\
-  org.apache.bval.constraints.DecimalMaxValidatorForString
+javax.validation.constraints.DecimalMax=\
+  org.apache.bval.constraints.DecimalMaxValidator$ForNumber,\
+  org.apache.bval.constraints.DecimalMaxValidator$ForString
 
-javax.validation.constraints.DecimalMin=org.apache.bval.constraints.DecimalMinValidatorForNumber,\
-  org.apache.bval.constraints.DecimalMinValidatorForString
+javax.validation.constraints.DecimalMin=\
+  org.apache.bval.constraints.DecimalMinValidator$ForNumber,\
+  org.apache.bval.constraints.DecimalMinValidator$ForString
 
 javax.validation.constraints.Digits=org.apache.bval.constraints.DigitsValidatorForNumber,\
   org.apache.bval.constraints.DigitsValidatorForString


[08/12] bval git commit: implement spec wrt too many or no available value extractors

Posted by mb...@apache.org.
implement spec wrt too many or no available value extractors


Project: http://git-wip-us.apache.org/repos/asf/bval/repo
Commit: http://git-wip-us.apache.org/repos/asf/bval/commit/a1f1f742
Tree: http://git-wip-us.apache.org/repos/asf/bval/tree/a1f1f742
Diff: http://git-wip-us.apache.org/repos/asf/bval/diff/a1f1f742

Branch: refs/heads/bv2
Commit: a1f1f7424dbce497739d3aa2f6c35c021a358716
Parents: c141d30
Author: Matt Benson <mb...@apache.org>
Authored: Fri Mar 16 17:55:03 2018 -0500
Committer: Matt Benson <mb...@apache.org>
Committed: Fri Mar 16 17:55:03 2018 -0500

----------------------------------------------------------------------
 .../bval/jsr/descriptor/CascadableContainerD.java     |  2 +-
 .../bval/jsr/descriptor/ContainerElementTypeD.java    |  3 ++-
 .../bval/jsr/valueextraction/ValueExtractors.java     | 14 ++++++++++----
 3 files changed, 13 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/bval/blob/a1f1f742/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/CascadableContainerD.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/CascadableContainerD.java b/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/CascadableContainerD.java
index 7404278..a4e05fd 100644
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/CascadableContainerD.java
+++ b/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/CascadableContainerD.java
@@ -78,7 +78,7 @@ public abstract class CascadableContainerD<P extends ElementD<?, ?>, E extends A
         try {
             return readImpl(context);
         } catch (Exception e) {
-            throw new ValidationException(e);
+            throw e instanceof ValidationException ? (ValidationException) e : new ValidationException(e);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/bval/blob/a1f1f742/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/ContainerElementTypeD.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/ContainerElementTypeD.java b/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/ContainerElementTypeD.java
index fb80802..cdae6f0 100644
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/ContainerElementTypeD.java
+++ b/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/ContainerElementTypeD.java
@@ -23,6 +23,7 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.stream.Stream;
 
+import javax.validation.ConstraintDeclarationException;
 import javax.validation.ValidationException;
 import javax.validation.metadata.ContainerElementTypeDescriptor;
 import javax.validation.valueextraction.ValueExtractor;
@@ -108,7 +109,7 @@ public class ContainerElementTypeD extends CascadableContainerD<CascadableContai
     @Override
     protected Stream<GraphContext> readImpl(GraphContext context) throws Exception {
         final ValueExtractor valueExtractor = context.getValidatorContext().getValueExtractors().find(key);
-        Exceptions.raiseIf(valueExtractor == null, ValidationException::new, "No %s found for %s",
+        Exceptions.raiseIf(valueExtractor == null, ConstraintDeclarationException::new, "No %s found for %s",
             ValueExtractor.class.getSimpleName(), key);
 
         final Receiver receiver = new Receiver(context);

http://git-wip-us.apache.org/repos/asf/bval/blob/a1f1f742/bval-jsr/src/main/java/org/apache/bval/jsr/valueextraction/ValueExtractors.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/valueextraction/ValueExtractors.java b/bval-jsr/src/main/java/org/apache/bval/jsr/valueextraction/ValueExtractors.java
index 3adc541..ec1cf23 100644
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/valueextraction/ValueExtractors.java
+++ b/bval-jsr/src/main/java/org/apache/bval/jsr/valueextraction/ValueExtractors.java
@@ -32,6 +32,7 @@ import java.util.function.Supplier;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
+import javax.validation.ConstraintDeclarationException;
 import javax.validation.valueextraction.ValueExtractor;
 import javax.validation.valueextraction.ValueExtractorDeclarationException;
 import javax.validation.valueextraction.ValueExtractorDefinitionException;
@@ -166,11 +167,16 @@ public class ValueExtractors {
         // search for assignable ContainerElementKey:
         Set<ContainerElementKey> assignableKeys = key.getAssignableKeys();
         while (!assignableKeys.isEmpty()) {
-            final Optional<ValueExtractor<?>> found = assignableKeys.stream().filter(allValueExtractors::containsKey)
-                .<ValueExtractor<?>> map(allValueExtractors::get).findFirst();
-            if (found.isPresent()) {
-                return found.get();
+            final Set<ValueExtractor<?>> results = assignableKeys.stream().filter(allValueExtractors::containsKey)
+                .map(allValueExtractors::get).collect(Collectors.toSet());
+
+            final int rz = results.size();
+            if (rz == 1) {
+                return results.iterator().next();
             }
+            Exceptions.raiseIf(rz > 1, ConstraintDeclarationException::new, "%d maximally specific %ss found for %s",
+                rz, ValueExtractor.class.getSimpleName(), key);
+
             assignableKeys = assignableKeys.stream().map(ContainerElementKey::getAssignableKeys)
                 .flatMap(Collection::stream).collect(Collectors.toSet());
         }


[02/12] bval git commit: ExecutableTypes utility class

Posted by mb...@apache.org.
ExecutableTypes utility class


Project: http://git-wip-us.apache.org/repos/asf/bval/repo
Commit: http://git-wip-us.apache.org/repos/asf/bval/commit/47cfebea
Tree: http://git-wip-us.apache.org/repos/asf/bval/tree/47cfebea
Diff: http://git-wip-us.apache.org/repos/asf/bval/diff/47cfebea

Branch: refs/heads/bv2
Commit: 47cfebeac0baf42a6b5903a4c3d6837d8f220294
Parents: 433e42b
Author: Matt Benson <mb...@apache.org>
Authored: Thu Mar 15 15:23:33 2018 -0500
Committer: Matt Benson <mb...@apache.org>
Committed: Thu Mar 15 15:23:33 2018 -0500

----------------------------------------------------------------------
 .../bval/jsr/BootstrapConfigurationImpl.java    | 26 +------
 .../apache/bval/jsr/util/ExecutableTypes.java   | 82 ++++++++++++++++++++
 .../apache/bval/jsr/xml/ValidationParser.java   |  3 +-
 3 files changed, 87 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/bval/blob/47cfebea/bval-jsr/src/main/java/org/apache/bval/jsr/BootstrapConfigurationImpl.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/BootstrapConfigurationImpl.java b/bval-jsr/src/main/java/org/apache/bval/jsr/BootstrapConfigurationImpl.java
index f7a11a3..3871b90 100644
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/BootstrapConfigurationImpl.java
+++ b/bval-jsr/src/main/java/org/apache/bval/jsr/BootstrapConfigurationImpl.java
@@ -26,29 +26,11 @@ import java.util.Set;
 import javax.validation.BootstrapConfiguration;
 import javax.validation.executable.ExecutableType;
 
-public class BootstrapConfigurationImpl implements BootstrapConfiguration {
-    public static final Set<ExecutableType> DEFAULT_DEFAULT_VALIDATED_EXECUTABLE_TYPES =
-        Collections.unmodifiableSet(EnumSet.of(ExecutableType.CONSTRUCTORS, ExecutableType.NON_GETTER_METHODS));
+import org.apache.bval.jsr.util.ExecutableTypes;
 
+public class BootstrapConfigurationImpl implements BootstrapConfiguration {
     public static final BootstrapConfigurationImpl DEFAULT = new BootstrapConfigurationImpl(Collections.emptySet(),
-        true, BootstrapConfigurationImpl.DEFAULT_DEFAULT_VALIDATED_EXECUTABLE_TYPES, Collections.emptyMap(),
-        Collections.emptySet());
-
-    private static Set<ExecutableType> expandExecutableValidation(Set<ExecutableType> executableTypes) {
-        if (executableTypes == DEFAULT_DEFAULT_VALIDATED_EXECUTABLE_TYPES) {
-            return executableTypes;
-        }
-        executableTypes = EnumSet.copyOf(executableTypes);
-        if (executableTypes.contains(ExecutableType.ALL)) {
-            executableTypes.clear();
-            executableTypes.add(ExecutableType.CONSTRUCTORS);
-            executableTypes.add(ExecutableType.NON_GETTER_METHODS);
-            executableTypes.add(ExecutableType.GETTER_METHODS);
-        } else if (executableTypes.contains(ExecutableType.NONE)) { // if both are present ALL trumps NONE
-            executableTypes.clear();
-        }
-        return Collections.unmodifiableSet(executableTypes);
-    }
+        true, EnumSet.of(ExecutableType.IMPLICIT), Collections.emptyMap(), Collections.emptySet());
 
     private final Set<String> constraintMappingResourcePaths;
     private final boolean executableValidationEnabled;
@@ -71,7 +53,7 @@ public class BootstrapConfigurationImpl implements BootstrapConfiguration {
         final String clockProviderClassName, final Set<String> valueExtractorClassNames) {
 
         this(Collections.unmodifiableSet(constraintMappingResourcePaths), executableValidationEnabled,
-            expandExecutableValidation(defaultValidatedExecutableTypes), Collections.unmodifiableMap(properties),
+            ExecutableTypes.interpret(defaultValidatedExecutableTypes), Collections.unmodifiableMap(properties),
             Collections.unmodifiableSet(valueExtractorClassNames));
 
         this.parameterNameProviderClassName = parameterNameProviderClassName;

http://git-wip-us.apache.org/repos/asf/bval/blob/47cfebea/bval-jsr/src/main/java/org/apache/bval/jsr/util/ExecutableTypes.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/util/ExecutableTypes.java b/bval-jsr/src/main/java/org/apache/bval/jsr/util/ExecutableTypes.java
new file mode 100644
index 0000000..b04bf28
--- /dev/null
+++ b/bval-jsr/src/main/java/org/apache/bval/jsr/util/ExecutableTypes.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.bval.jsr.util;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.EnumMap;
+import java.util.EnumSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.validation.executable.ExecutableType;
+
+import org.apache.bval.util.Validate;
+
+/**
+ * Utility methods relating to {@link ExecutableType}.
+ */
+public class ExecutableTypes {
+
+    private static final Map<ExecutableType, Set<ExecutableType>> INTERPRETED_EXECUTABLE_TYPES;
+    static {
+        final Map<ExecutableType, Set<ExecutableType>> m = new EnumMap<>(ExecutableType.class);
+
+        m.put(ExecutableType.ALL, Collections.unmodifiableSet(
+            EnumSet.of(ExecutableType.CONSTRUCTORS, ExecutableType.NON_GETTER_METHODS, ExecutableType.GETTER_METHODS)));
+        m.put(ExecutableType.IMPLICIT,
+            Collections.unmodifiableSet(EnumSet.of(ExecutableType.CONSTRUCTORS, ExecutableType.NON_GETTER_METHODS)));
+        m.put(ExecutableType.NONE, Collections.emptySet());
+
+        INTERPRETED_EXECUTABLE_TYPES = Collections.unmodifiableMap(m);
+    }
+
+    /**
+     * Interpret occurrences of {@link ExecutableType#ALL}, {@link ExecutableType#IMPLICIT}, and
+     * {@link ExecutableType#NONE}.
+     * 
+     * @param executableTypes
+     * @return (unmodifiable) {@link Set} of {@link ExecutableType}
+     */
+    public static Set<ExecutableType> interpret(Collection<ExecutableType> executableTypes) {
+        Validate.notNull(executableTypes);
+
+        for (Map.Entry<ExecutableType, Set<ExecutableType>> e : INTERPRETED_EXECUTABLE_TYPES.entrySet()) {
+            if (e.getValue().equals(executableTypes) || executableTypes.contains(e.getKey())) {
+                return e.getValue();
+            }
+        }
+        return Collections.unmodifiableSet(EnumSet.copyOf(executableTypes));
+    }
+
+    /**
+     * Interpret occurrences of {@link ExecutableType#ALL}, {@link ExecutableType#IMPLICIT}, and
+     * {@link ExecutableType#NONE}.
+     * 
+     * @param executableTypes
+     * @return (unmodifiable) {@link Set} of {@link ExecutableType}
+     */
+    public static Set<ExecutableType> interpret(ExecutableType... executableTypes) {
+        return interpret(Arrays.asList(executableTypes));
+    }
+
+    private ExecutableTypes() {
+    }
+}

http://git-wip-us.apache.org/repos/asf/bval/blob/47cfebea/bval-jsr/src/main/java/org/apache/bval/jsr/xml/ValidationParser.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/xml/ValidationParser.java b/bval-jsr/src/main/java/org/apache/bval/jsr/xml/ValidationParser.java
index 35d510b..a8972e2 100644
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/xml/ValidationParser.java
+++ b/bval-jsr/src/main/java/org/apache/bval/jsr/xml/ValidationParser.java
@@ -79,7 +79,7 @@ public class ValidationParser {
         final Set<ExecutableType> defaultValidatedExecutableTypes;
 
         if (xmlConfig.getExecutableValidation() == null) {
-            defaultValidatedExecutableTypes = BootstrapConfigurationImpl.DEFAULT_DEFAULT_VALIDATED_EXECUTABLE_TYPES;
+            defaultValidatedExecutableTypes = EnumSet.of(ExecutableType.IMPLICIT);
             executableValidationEnabled = true;
         } else {
             final Optional<ExecutableValidationType> executableValidation =
@@ -145,6 +145,5 @@ public class ValidationParser {
     }
 
     private ValidationParser() {
-        // no-op
     }
 }


[10/12] bval git commit: enforce order of ALL>IMPLICIT>NONE; Enum order is not respected when generating Javadoc (alpha is used)

Posted by mb...@apache.org.
enforce order of ALL>IMPLICIT>NONE; Enum order is not respected when generating Javadoc (alpha is used)


Project: http://git-wip-us.apache.org/repos/asf/bval/repo
Commit: http://git-wip-us.apache.org/repos/asf/bval/commit/db49785e
Tree: http://git-wip-us.apache.org/repos/asf/bval/tree/db49785e
Diff: http://git-wip-us.apache.org/repos/asf/bval/diff/db49785e

Branch: refs/heads/bv2
Commit: db49785e31fdac130ea9677bc390926d7c13e85e
Parents: 8c6fdea
Author: Matt Benson <mb...@apache.org>
Authored: Fri Mar 16 17:56:53 2018 -0500
Committer: Matt Benson <mb...@apache.org>
Committed: Fri Mar 16 17:56:53 2018 -0500

----------------------------------------------------------------------
 .../src/main/java/org/apache/bval/jsr/util/ExecutableTypes.java  | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/bval/blob/db49785e/bval-jsr/src/main/java/org/apache/bval/jsr/util/ExecutableTypes.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/util/ExecutableTypes.java b/bval-jsr/src/main/java/org/apache/bval/jsr/util/ExecutableTypes.java
index b04bf28..664da42 100644
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/util/ExecutableTypes.java
+++ b/bval-jsr/src/main/java/org/apache/bval/jsr/util/ExecutableTypes.java
@@ -21,8 +21,8 @@ package org.apache.bval.jsr.util;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.EnumMap;
 import java.util.EnumSet;
+import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.Set;
 
@@ -37,7 +37,7 @@ public class ExecutableTypes {
 
     private static final Map<ExecutableType, Set<ExecutableType>> INTERPRETED_EXECUTABLE_TYPES;
     static {
-        final Map<ExecutableType, Set<ExecutableType>> m = new EnumMap<>(ExecutableType.class);
+        final Map<ExecutableType, Set<ExecutableType>> m = new LinkedHashMap<>();
 
         m.put(ExecutableType.ALL, Collections.unmodifiableSet(
             EnumSet.of(ExecutableType.CONSTRUCTORS, ExecutableType.NON_GETTER_METHODS, ExecutableType.GETTER_METHODS)));


[04/12] bval git commit: CDI refactoring

Posted by mb...@apache.org.
CDI refactoring


Project: http://git-wip-us.apache.org/repos/asf/bval/repo
Commit: http://git-wip-us.apache.org/repos/asf/bval/commit/89260630
Tree: http://git-wip-us.apache.org/repos/asf/bval/tree/89260630
Diff: http://git-wip-us.apache.org/repos/asf/bval/diff/89260630

Branch: refs/heads/bv2
Commit: 8926063027af44aa3e9064c392a9e4df79209cb1
Parents: 48d4ae5
Author: Matt Benson <mb...@apache.org>
Authored: Thu Mar 15 15:58:37 2018 -0500
Committer: Matt Benson <mb...@apache.org>
Committed: Thu Mar 15 15:58:37 2018 -0500

----------------------------------------------------------------------
 .../java/org/apache/bval/cdi/BValExtension.java |  94 +++----
 .../org/apache/bval/cdi/BValInterceptor.java    | 270 +++++++------------
 2 files changed, 132 insertions(+), 232 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/bval/blob/89260630/bval-jsr/src/main/java/org/apache/bval/cdi/BValExtension.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/cdi/BValExtension.java b/bval-jsr/src/main/java/org/apache/bval/cdi/BValExtension.java
index 39823a5..8aa216f 100644
--- a/bval-jsr/src/main/java/org/apache/bval/cdi/BValExtension.java
+++ b/bval-jsr/src/main/java/org/apache/bval/cdi/BValExtension.java
@@ -18,6 +18,14 @@
  */
 package org.apache.bval.cdi;
 
+import java.lang.reflect.Modifier;
+import java.lang.reflect.Type;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
 import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.event.Observes;
 import javax.enterprise.inject.spi.AfterBeanDiscovery;
@@ -42,16 +50,8 @@ import javax.validation.executable.ValidateOnExecution;
 import javax.validation.metadata.BeanDescriptor;
 import javax.validation.metadata.MethodType;
 
-import java.lang.reflect.Modifier;
-import java.lang.reflect.Type;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.EnumSet;
-import java.util.Set;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
 import org.apache.bval.jsr.ConfigurationImpl;
+import org.apache.bval.jsr.util.ExecutableTypes;
 import org.apache.bval.util.Validate;
 
 /**
@@ -60,7 +60,8 @@ import org.apache.bval.util.Validate;
 public class BValExtension implements Extension {
     private static final Logger LOGGER = Logger.getLogger(BValExtension.class.getName());
 
-    private static final AnnotatedTypeFilter DEFAULT_ANNOTATED_TYPE_FILTER = annotatedType -> !annotatedType.getJavaClass().getName().startsWith("org.apache.bval.");
+    private static final AnnotatedTypeFilter DEFAULT_ANNOTATED_TYPE_FILTER =
+        annotatedType -> !annotatedType.getJavaClass().getName().startsWith("org.apache.bval.");
 
     private static AnnotatedTypeFilter annotatedTypeFilter = DEFAULT_ANNOTATED_TYPE_FILTER;
 
@@ -71,11 +72,6 @@ public class BValExtension implements Extension {
     private boolean validatorFound = Boolean.getBoolean("bval.in-container");
     private boolean validatorFactoryFound = Boolean.getBoolean("bval.in-container");
 
-    private boolean validBean;
-    private boolean validConstructors;
-    private boolean validBusinessMethods;
-    private boolean validGetterMethods;
-
     private final Configuration<?> config;
     private ValidatorFactory factory;
     private Validator validator;
@@ -88,16 +84,10 @@ public class BValExtension implements Extension {
         try {
             final BootstrapConfiguration bootstrap = config.getBootstrapConfiguration();
             globalExecutableTypes =
-                Collections.unmodifiableSet(convertToRuntimeTypes(bootstrap.getDefaultValidatedExecutableTypes()));
+                ExecutableTypes.interpret(bootstrap.getDefaultValidatedExecutableTypes());
+
             isExecutableValidationEnabled = bootstrap.isExecutableValidationEnabled();
 
-            // TODO we never contain IMPLICIT or ALL
-            validBean = globalExecutableTypes.contains(ExecutableType.IMPLICIT)
-                || globalExecutableTypes.contains(ExecutableType.ALL);
-            validConstructors = validBean || globalExecutableTypes.contains(ExecutableType.CONSTRUCTORS);
-            validBusinessMethods = validBean || globalExecutableTypes.contains(ExecutableType.NON_GETTER_METHODS);
-            validGetterMethods = globalExecutableTypes.contains(ExecutableType.ALL)
-                || globalExecutableTypes.contains(ExecutableType.GETTER_METHODS);
         } catch (final Exception e) { // custom providers can throw an exception
             LOGGER.log(Level.SEVERE, e.getMessage(), e);
 
@@ -121,29 +111,6 @@ public class BValExtension implements Extension {
         validator = factory.getValidator();
     }
 
-    private static Set<ExecutableType> convertToRuntimeTypes(
-        final Set<ExecutableType> defaultValidatedExecutableTypes) {
-        final Set<ExecutableType> types = EnumSet.noneOf(ExecutableType.class);
-        for (final ExecutableType type : defaultValidatedExecutableTypes) {
-            if (ExecutableType.NONE == type) {
-                continue;
-            }
-            if (ExecutableType.ALL == type) {
-                types.add(ExecutableType.CONSTRUCTORS);
-                types.add(ExecutableType.NON_GETTER_METHODS);
-                types.add(ExecutableType.GETTER_METHODS);
-                break;
-            }
-            if (ExecutableType.IMPLICIT == type) {
-                types.add(ExecutableType.CONSTRUCTORS);
-                types.add(ExecutableType.NON_GETTER_METHODS);
-            } else {
-                types.add(type);
-            }
-        }
-        return types;
-    }
-
     public Set<ExecutableType> getGlobalExecutableTypes() {
         return globalExecutableTypes;
     }
@@ -158,13 +125,11 @@ public class BValExtension implements Extension {
         if (!isExecutableValidationEnabled) {
             return;
         }
-
         final AnnotatedType<A> annotatedType = pat.getAnnotatedType();
 
         if (!annotatedTypeFilter.accept(annotatedType)) {
             return;
         }
-
         final Class<A> javaClass = annotatedType.getJavaClass();
         final int modifiers = javaClass.getModifiers();
         if (!javaClass.isInterface() && !Modifier.isFinal(modifiers) && !Modifier.isAbstract(modifiers)) {
@@ -172,23 +137,28 @@ public class BValExtension implements Extension {
                 ensureFactoryValidator();
                 try {
                     final BeanDescriptor classConstraints = validator.getConstraintsForClass(javaClass);
+
+                    final boolean validConstructors = globalExecutableTypes.contains(ExecutableType.CONSTRUCTORS)
+                        && !classConstraints.getConstrainedConstructors().isEmpty();
+                    final boolean validBusinessMethods =
+                        globalExecutableTypes.contains(ExecutableType.NON_GETTER_METHODS)
+                            && !classConstraints.getConstrainedMethods(MethodType.NON_GETTER).isEmpty();
+                    final boolean validGetterMethods = globalExecutableTypes.contains(ExecutableType.GETTER_METHODS)
+                        && !classConstraints.getConstrainedMethods(MethodType.GETTER).isEmpty();
+
                     if (annotatedType.isAnnotationPresent(ValidateOnExecution.class)
                         || hasValidationAnnotation(annotatedType.getMethods())
-                        || hasValidationAnnotation(annotatedType.getConstructors())
-                        || classConstraints != null && (validBean && classConstraints.isBeanConstrained()
-                            || validConstructors && !classConstraints.getConstrainedConstructors().isEmpty()
-                            || validBusinessMethods
-                                && !classConstraints.getConstrainedMethods(MethodType.NON_GETTER).isEmpty()
-                            || validGetterMethods
-                                && !classConstraints.getConstrainedMethods(MethodType.GETTER).isEmpty())) {
-                        pat.setAnnotatedType(new BValAnnotatedType<A>(annotatedType));
+                        || hasValidationAnnotation(annotatedType.getConstructors()) || validConstructors
+                        || validBusinessMethods || validGetterMethods) {
+                        pat.setAnnotatedType(new BValAnnotatedType<>(annotatedType));
                     }
                 } catch (final NoClassDefFoundError ncdfe) {
                     // skip
                 }
-            } catch (final ValidationException ve) {
-                LOGGER.log(Level.FINEST, ve.getMessage(), ve);
-            } catch (final Exception e) { // just info
+            } catch (final Exception e) {
+                if (e instanceof ValidationException) {
+                    throw e;
+                }
                 LOGGER.log(Level.INFO, e.getMessage());
             }
         }
@@ -229,6 +199,9 @@ public class BValExtension implements Extension {
             try { // recreate the factory
                 afterBeanDiscovery.addBean(new ValidatorFactoryBean(factory = config.buildValidatorFactory()));
             } catch (final Exception e) { // can throw an exception with custom providers
+                if (e instanceof ValidationException) {
+                    throw e;
+                }
                 LOGGER.log(Level.SEVERE, e.getMessage(), e);
             }
         }
@@ -242,6 +215,9 @@ public class BValExtension implements Extension {
                     validatorFound = true;
                 }
             } catch (final Exception e) { // getValidator can throw an exception with custom providers
+                if (e instanceof ValidationException) {
+                    throw e;
+                }
                 afterBeanDiscovery.addBean(new ValidatorBean(factory, null));
                 validatorFound = true;
                 LOGGER.log(Level.SEVERE, e.getMessage(), e);

http://git-wip-us.apache.org/repos/asf/bval/blob/89260630/bval-jsr/src/main/java/org/apache/bval/cdi/BValInterceptor.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/cdi/BValInterceptor.java b/bval-jsr/src/main/java/org/apache/bval/cdi/BValInterceptor.java
index b5d2c8b..4735369 100644
--- a/bval-jsr/src/main/java/org/apache/bval/cdi/BValInterceptor.java
+++ b/bval-jsr/src/main/java/org/apache/bval/cdi/BValInterceptor.java
@@ -18,21 +18,20 @@
  */
 package org.apache.bval.cdi;
 
-import static java.util.Arrays.asList;
-
 import java.io.Serializable;
 import java.lang.reflect.Constructor;
+import java.lang.reflect.Executable;
 import java.lang.reflect.Method;
 import java.util.Arrays;
 import java.util.Collection;
-import java.util.EnumSet;
+import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
-import java.util.stream.Stream;
+import java.util.function.BiPredicate;
 
 import javax.annotation.Priority;
-import javax.enterprise.inject.spi.AnnotatedConstructor;
 import javax.enterprise.inject.spi.AnnotatedMethod;
 import javax.enterprise.inject.spi.AnnotatedType;
 import javax.enterprise.inject.spi.CDI;
@@ -51,10 +50,14 @@ import javax.validation.executable.ValidateOnExecution;
 import javax.validation.metadata.ConstructorDescriptor;
 import javax.validation.metadata.MethodDescriptor;
 
+import org.apache.bval.jsr.descriptor.DescriptorManager;
+import org.apache.bval.jsr.metadata.Signature;
+import org.apache.bval.jsr.util.ExecutableTypes;
 import org.apache.bval.jsr.util.Methods;
 import org.apache.bval.jsr.util.Proxies;
 import org.apache.bval.util.reflection.Reflection;
 import org.apache.bval.util.reflection.Reflection.Interfaces;
+import org.apache.bval.util.reflection.TypeUtils;
 
 /**
  * Interceptor class for the {@link BValBinding} {@link InterceptorBinding}.
@@ -66,9 +69,8 @@ import org.apache.bval.util.reflection.Reflection.Interfaces;
 // TODO: maybe add it through ASM to be compliant with CDI 1.0 containers using simply this class as a template to
 // generate another one for CDI 1.1 impl
 public class BValInterceptor implements Serializable {
-    private transient volatile Map<Method, Boolean> methodConfiguration = new ConcurrentHashMap<>();
     private transient volatile Set<ExecutableType> classConfiguration;
-    private transient volatile Boolean constructorValidated;
+    private transient volatile Map<Signature, Boolean> executableValidation;
 
     @Inject
     private Validator validator;
@@ -78,43 +80,37 @@ public class BValInterceptor implements Serializable {
 
     private transient volatile ExecutableValidator executableValidator;
 
+    @SuppressWarnings({ "unchecked", "rawtypes" })
     @AroundConstruct // TODO: see previous one
     public Object construct(InvocationContext context) throws Exception {
-        @SuppressWarnings("rawtypes")
-        final Constructor constructor = context.getConstructor();
-        final Class<?> targetClass = constructor.getDeclaringClass();
-        if (!isConstructorValidated(targetClass, constructor)) {
+        final Constructor ctor = context.getConstructor();
+        if (!isConstructorValidated(ctor)) {
             return context.proceed();
         }
+        final ConstructorDescriptor constraints = validator.getConstraintsForClass(ctor.getDeclaringClass())
+            .getConstraintsForConstructor(ctor.getParameterTypes());
 
-        final ConstructorDescriptor constraints =
-            validator.getConstraintsForClass(targetClass).getConstraintsForConstructor(constructor.getParameterTypes());
-        if (constraints == null) { // surely implicit constructor
+        if (!DescriptorManager.isConstrained(constraints)) {
             return context.proceed();
         }
-
         initExecutableValidator();
 
-        {
-            @SuppressWarnings("unchecked")
+        if (constraints.hasConstrainedParameters()) {
             final Set<ConstraintViolation<?>> violations =
-                executableValidator.validateConstructorParameters(constructor, context.getParameters());
+                executableValidator.validateConstructorParameters(ctor, context.getParameters());
             if (!violations.isEmpty()) {
                 throw new ConstraintViolationException(violations);
             }
         }
-
         final Object result = context.proceed();
 
-        {
-            @SuppressWarnings("unchecked")
+        if (constraints.hasConstrainedReturnValue()) {
             final Set<ConstraintViolation<?>> violations =
-                executableValidator.validateConstructorReturnValue(constructor, context.getTarget());
+                executableValidator.validateConstructorReturnValue(ctor, context.getTarget());
             if (!violations.isEmpty()) {
                 throw new ConstraintViolationException(violations);
             }
         }
-
         return result;
     }
 
@@ -122,195 +118,134 @@ public class BValInterceptor implements Serializable {
     public Object invoke(final InvocationContext context) throws Exception {
         final Method method = context.getMethod();
         final Class<?> targetClass = Proxies.classFor(context.getTarget().getClass());
-        if (!isMethodValidated(targetClass, method)) {
+
+        if (!isExecutableValidated(targetClass, method, this::computeIsMethodValidated)) {
             return context.proceed();
         }
 
         final MethodDescriptor constraintsForMethod = validator.getConstraintsForClass(targetClass)
             .getConstraintsForMethod(method.getName(), method.getParameterTypes());
-        if (constraintsForMethod == null) {
+
+        if (!DescriptorManager.isConstrained(constraintsForMethod)) {
             return context.proceed();
         }
-
         initExecutableValidator();
 
-        {
+        if (constraintsForMethod.hasConstrainedParameters()) {
             final Set<ConstraintViolation<Object>> violations =
                 executableValidator.validateParameters(context.getTarget(), method, context.getParameters());
             if (!violations.isEmpty()) {
                 throw new ConstraintViolationException(violations);
             }
         }
-
         final Object result = context.proceed();
 
-        {
+        if (constraintsForMethod.hasConstrainedReturnValue()) {
             final Set<ConstraintViolation<Object>> violations =
                 executableValidator.validateReturnValue(context.getTarget(), method, result);
             if (!violations.isEmpty()) {
                 throw new ConstraintViolationException(violations);
             }
         }
-
         return result;
     }
 
-    private boolean isConstructorValidated(final Class<?> targetClass, final Constructor<?> constructor)
-        throws NoSuchMethodException {
-        initClassConfig(targetClass);
-
-        if (constructorValidated == null) {
-            synchronized (this) {
-                if (constructorValidated == null) {
-                    final AnnotatedType<?> annotatedType =
-                        CDI.current().getBeanManager().createAnnotatedType(constructor.getDeclaringClass());
-                    AnnotatedConstructor<?> annotatedConstructor = null;
-                    for (final AnnotatedConstructor<?> ac : annotatedType.getConstructors()) {
-                        if (!constructor.equals(ac.getJavaMember())) {
-                            continue;
-                        }
-                        annotatedConstructor = ac;
-                        break;
-                    }
-                    final ValidateOnExecution annotation = annotatedConstructor != null
-                        ? annotatedConstructor.getAnnotation(ValidateOnExecution.class) : targetClass
-                            .getConstructor(constructor.getParameterTypes()).getAnnotation(ValidateOnExecution.class);
-                    if (annotation == null) {
-                        constructorValidated = classConfiguration.contains(ExecutableType.CONSTRUCTORS);
-                    } else {
-                        final Collection<ExecutableType> types = Arrays.asList(annotation.type());
-                        constructorValidated = types.contains(ExecutableType.CONSTRUCTORS)
-                            || types.contains(ExecutableType.IMPLICIT) || types.contains(ExecutableType.ALL);
-                    }
-                }
-            }
-        }
-
-        return constructorValidated;
+    private <T> boolean isConstructorValidated(final Constructor<T> constructor)
+        {
+        return isExecutableValidated(constructor.getDeclaringClass(), constructor, this::computeIsConstructorValidated);
     }
 
-    private boolean isMethodValidated(final Class<?> targetClass, final Method method) throws NoSuchMethodException {
+    private <T, E extends Executable> boolean isExecutableValidated(final Class<T> targetClass, final E executable,
+        BiPredicate<? super Class<T>, ? super E> compute) {
         initClassConfig(targetClass);
 
-        if (methodConfiguration == null) {
+        if (executableValidation == null) {
             synchronized (this) {
-                if (methodConfiguration == null) {
-                    methodConfiguration = new ConcurrentHashMap<Method, Boolean>();
+                if (executableValidation == null) {
+                    executableValidation = new ConcurrentHashMap<>();
                 }
             }
         }
+        return executableValidation.computeIfAbsent(Signature.of(executable),
+            s -> compute.test(targetClass, executable));
+    }
 
-        Boolean methodConfig = methodConfiguration.get(method);
-        if (methodConfig == null) {
+    private void initClassConfig(Class<?> targetClass) {
+        if (classConfiguration == null) {
             synchronized (this) {
-                methodConfig = methodConfiguration.get(method);
-                if (methodConfig == null) {
-                    // search on method @ValidateOnExecution
-                    ValidateOnExecution validateOnExecution = null;
-                    ValidateOnExecution validateOnExecutionType = null;
-                    for (final Class<?> c : reverseHierarchy(targetClass)) {
-                        final AnnotatedType<?> annotatedType = CDI.current().getBeanManager().createAnnotatedType(c);
-                        AnnotatedMethod<?> annotatedMethod = null;
-
-                        for (final AnnotatedMethod<?> m : annotatedType.getMethods()) {
-                            if (m.getJavaMember().getName().equals(method.getName())
-                                && asList(method.getGenericParameterTypes())
-                                    .equals(asList(m.getJavaMember().getGenericParameterTypes()))) {
-                                annotatedMethod = m;
-                                break;
-                            }
-                        }
-                        if (annotatedMethod == null) {
-                            continue;
-                        }
-                        try {
-                            if (validateOnExecutionType == null) {
-                                final ValidateOnExecution vat = annotatedType.getAnnotation(ValidateOnExecution.class);
-                                if (vat != null) {
-                                    validateOnExecutionType = vat;
-                                }
-                            }
-                            final ValidateOnExecution mvat = annotatedMethod.getAnnotation(ValidateOnExecution.class);
-                            if (mvat != null) {
-                                validateOnExecution = mvat;
-                            }
-                        } catch (final Throwable h) {
-                            // no-op
-                        }
-                    }
-
-                    // if not found look in the class declaring the method
-                    boolean classMeta = false;
-                    if (validateOnExecution == null) {
-                        validateOnExecution = validateOnExecutionType;
-                        classMeta = validateOnExecution != null;
-                    }
+                if (classConfiguration == null) {
+                    final ValidateOnExecution annotation = CDI.current().getBeanManager()
+                        .createAnnotatedType(targetClass).getAnnotation(ValidateOnExecution.class);
 
-                    if (validateOnExecution == null) {
-                        methodConfig = doValidMethod(method, classConfiguration);
+                    if (annotation == null) {
+                        classConfiguration = globalConfiguration.getGlobalExecutableTypes();
                     } else {
-                        final Set<ExecutableType> config = EnumSet.noneOf(ExecutableType.class);
-                        for (final ExecutableType type : validateOnExecution.type()) {
-                            if (ExecutableType.NONE == type) {
-                                continue;
-                            }
-                            if (ExecutableType.ALL == type) {
-                                config.add(ExecutableType.NON_GETTER_METHODS);
-                                config.add(ExecutableType.GETTER_METHODS);
-                                break;
-                            }
-                            if (ExecutableType.IMPLICIT == type) { // on method it just means validate, even on getters
-                                config.add(ExecutableType.NON_GETTER_METHODS);
-                                if (!classMeta) {
-                                    config.add(ExecutableType.GETTER_METHODS);
-                                } // else the annotation was not on the method so implicit doesn't mean getters
-                            } else {
-                                config.add(type);
-                            }
-                        }
-                        methodConfig = doValidMethod(method, config);
+                        classConfiguration = ExecutableTypes.interpret(annotation.type());
                     }
                 }
-                methodConfiguration.put(method, methodConfig);
             }
         }
+    }
 
-        return methodConfig;
+    private <T> boolean computeIsConstructorValidated(Class<T> targetClass, Constructor<T> ctor) {
+        final AnnotatedType<T> annotatedType =
+            CDI.current().getBeanManager().createAnnotatedType(ctor.getDeclaringClass());
+
+        final ValidateOnExecution annotation =
+            annotatedType.getConstructors().stream().filter(ac -> ctor.equals(ac.getJavaMember())).findFirst()
+                .map(ac -> ac.getAnnotation(ValidateOnExecution.class))
+                .orElseGet(() -> ctor.getAnnotation(ValidateOnExecution.class));
+
+        final Set<ExecutableType> validatedExecutableTypes =
+            annotation == null ? classConfiguration : ExecutableTypes.interpret(annotation.type());
+
+        return validatedExecutableTypes.contains(ExecutableType.CONSTRUCTORS);
     }
 
-    private void initClassConfig(Class<?> targetClass) {
-        if (classConfiguration == null) {
-            synchronized (this) {
-                if (classConfiguration == null) {
-                    classConfiguration = EnumSet.noneOf(ExecutableType.class);
+    private <T> boolean computeIsMethodValidated(Class<T> targetClass, Method method) {
+        Collection<ExecutableType> declaredExecutableTypes = null;
 
-                    final AnnotatedType<?> annotatedType =
-                        CDI.current().getBeanManager().createAnnotatedType(targetClass);
-                    final ValidateOnExecution annotation = annotatedType.getAnnotation(ValidateOnExecution.class);
-                    if (annotation == null) {
-                        classConfiguration.addAll(globalConfiguration.getGlobalExecutableTypes());
-                    } else {
-                        for (final ExecutableType type : annotation.type()) {
-                            if (ExecutableType.NONE == type) {
-                                continue;
-                            }
-                            if (ExecutableType.ALL == type) {
-                                classConfiguration.add(ExecutableType.CONSTRUCTORS);
-                                classConfiguration.add(ExecutableType.NON_GETTER_METHODS);
-                                classConfiguration.add(ExecutableType.GETTER_METHODS);
-                                break;
-                            }
-                            if (ExecutableType.IMPLICIT == type) {
-                                classConfiguration.add(ExecutableType.CONSTRUCTORS);
-                                classConfiguration.add(ExecutableType.NON_GETTER_METHODS);
-                            } else {
-                                classConfiguration.add(type);
-                            }
-                        }
+        for (final Class<?> c : Reflection.hierarchy(targetClass, Interfaces.INCLUDE)) {
+            final AnnotatedType<?> annotatedType = CDI.current().getBeanManager().createAnnotatedType(c);
+
+            final AnnotatedMethod<?> annotatedMethod = annotatedType.getMethods().stream()
+                .filter(am -> Signature.of(am.getJavaMember()).equals(Signature.of(method))).findFirst().orElse(null);
+
+            if (annotatedMethod == null) {
+                continue;
+            }
+            if (annotatedMethod.isAnnotationPresent(ValidateOnExecution.class)) {
+                final List<ExecutableType> validatedTypesOnMethod =
+                    Arrays.asList(annotatedMethod.getAnnotation(ValidateOnExecution.class).type());
+
+                // implicit directly on method -> early return:
+                if (validatedTypesOnMethod.contains(ExecutableType.IMPLICIT)) {
+                    return true;
+                }
+                declaredExecutableTypes = validatedTypesOnMethod;
+                // ignore the hierarchy once the lowest method is found:
+                break;
+            }
+            if (declaredExecutableTypes == null) {
+                if (annotatedType.isAnnotationPresent(ValidateOnExecution.class)) {
+                    declaredExecutableTypes =
+                        Arrays.asList(annotatedType.getAnnotation(ValidateOnExecution.class).type());
+                } else {
+                    final Optional<Package> pkg = Optional.of(annotatedType).map(AnnotatedType::getBaseType)
+                        .map(t -> TypeUtils.getRawType(t, null)).map(Class::getPackage)
+                        .filter(p -> p.isAnnotationPresent(ValidateOnExecution.class));
+                    if (pkg.isPresent()) {
+                        declaredExecutableTypes =
+                            Arrays.asList(pkg.get().getAnnotation(ValidateOnExecution.class).type());
                     }
                 }
             }
         }
+        final ExecutableType methodType =
+            Methods.isGetter(method) ? ExecutableType.GETTER_METHODS : ExecutableType.NON_GETTER_METHODS;
+
+        return Optional.ofNullable(declaredExecutableTypes).map(ExecutableTypes::interpret)
+            .orElse(globalConfiguration.getGlobalExecutableTypes()).contains(methodType);
     }
 
     private void initExecutableValidator() {
@@ -322,15 +257,4 @@ public class BValInterceptor implements Serializable {
             }
         }
     }
-
-    private static boolean doValidMethod(final Method method, final Set<ExecutableType> config) {
-        return config
-            .contains(Methods.isGetter(method) ? ExecutableType.GETTER_METHODS : ExecutableType.NON_GETTER_METHODS);
-    }
-
-    private static Iterable<Class<?>> reverseHierarchy(Class<?> t) {
-        final Stream.Builder<Class<?>> builder = Stream.builder();
-        Reflection.hierarchy(t, Interfaces.INCLUDE).forEach(builder);
-        return builder.build()::iterator;
-    }
 }


[05/12] bval git commit: correct v2 xmlns uris

Posted by mb...@apache.org.
correct v2 xmlns uris


Project: http://git-wip-us.apache.org/repos/asf/bval/repo
Commit: http://git-wip-us.apache.org/repos/asf/bval/commit/0bf9b3a7
Tree: http://git-wip-us.apache.org/repos/asf/bval/tree/0bf9b3a7
Diff: http://git-wip-us.apache.org/repos/asf/bval/diff/0bf9b3a7

Branch: refs/heads/bv2
Commit: 0bf9b3a72e07a20c50b29fa1d2e61517ccfe254e
Parents: 8926063
Author: Matt Benson <mb...@apache.org>
Authored: Thu Mar 15 15:59:04 2018 -0500
Committer: Matt Benson <mb...@apache.org>
Committed: Thu Mar 15 15:59:04 2018 -0500

----------------------------------------------------------------------
 .../java/org/apache/bval/jsr/xml/ValidationMappingParser.java    | 2 +-
 .../src/main/java/org/apache/bval/jsr/xml/ValidationParser.java  | 2 +-
 bval-jsr/src/main/xsd/validation-configuration-2.0.xsd           | 4 ++--
 bval-jsr/src/main/xsd/validation-mapping-2.0.xsd                 | 4 ++--
 bval-jsr/src/test/resources/sample-validation2.xml               | 4 ++--
 5 files changed, 8 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/bval/blob/0bf9b3a7/bval-jsr/src/main/java/org/apache/bval/jsr/xml/ValidationMappingParser.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/xml/ValidationMappingParser.java b/bval-jsr/src/main/java/org/apache/bval/jsr/xml/ValidationMappingParser.java
index 766871f..c7e0f75 100644
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/xml/ValidationMappingParser.java
+++ b/bval-jsr/src/main/java/org/apache/bval/jsr/xml/ValidationMappingParser.java
@@ -47,7 +47,7 @@ public class ValidationMappingParser {
         .add(null, "http://jboss.org/xml/ns/javax/validation/mapping", "META-INF/validation-mapping-1.0.xsd")
         .add(XmlBuilder.Version.v11.getId(), "http://jboss.org/xml/ns/javax/validation/mapping",
             "META-INF/validation-mapping-1.1.xsd")
-        .add(XmlBuilder.Version.v20.getId(), "http://xmlns.jcp.org/xml/ns/javax/validation/mapping",
+        .add(XmlBuilder.Version.v20.getId(), "http://xmlns.jcp.org/xml/ns/validation/mapping",
             "META-INF/validation-mapping-2.0.xsd")
         .build();
 

http://git-wip-us.apache.org/repos/asf/bval/blob/0bf9b3a7/bval-jsr/src/main/java/org/apache/bval/jsr/xml/ValidationParser.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/xml/ValidationParser.java b/bval-jsr/src/main/java/org/apache/bval/jsr/xml/ValidationParser.java
index a8972e2..6402971 100644
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/xml/ValidationParser.java
+++ b/bval-jsr/src/main/java/org/apache/bval/jsr/xml/ValidationParser.java
@@ -61,7 +61,7 @@ public class ValidationParser {
             "META-INF/validation-configuration-1.0.xsd")
         .add(XmlBuilder.Version.v11.getId(), "http://jboss.org/xml/ns/javax/validation/configuration",
             "META-INF/validation-configuration-1.1.xsd")
-        .add(XmlBuilder.Version.v20.getId(), "http://xmlns.jcp.org/xml/ns/javax/validation/configuration",
+        .add(XmlBuilder.Version.v20.getId(), "http://xmlns.jcp.org/xml/ns/validation/configuration",
             "META-INF/validation-configuration-2.0.xsd")
         .build();
 

http://git-wip-us.apache.org/repos/asf/bval/blob/0bf9b3a7/bval-jsr/src/main/xsd/validation-configuration-2.0.xsd
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/xsd/validation-configuration-2.0.xsd b/bval-jsr/src/main/xsd/validation-configuration-2.0.xsd
index 6fd7874..6eaaf30 100644
--- a/bval-jsr/src/main/xsd/validation-configuration-2.0.xsd
+++ b/bval-jsr/src/main/xsd/validation-configuration-2.0.xsd
@@ -19,9 +19,9 @@
 -->
 <xs:schema attributeFormDefault="unqualified"
            elementFormDefault="qualified"
-           targetNamespace="http://xmlns.jcp.org/xml/ns/javax/validation/configuration"
+           targetNamespace="http://xmlns.jcp.org/xml/ns/validation/configuration"
            xmlns:xs="http://www.w3.org/2001/XMLSchema"
-           xmlns:config="http://xmlns.jcp.org/xml/ns/javax/validation/configuration"
+           xmlns:config="http://xmlns.jcp.org/xml/ns/validation/configuration"
            version="2.0">
   <xs:element name="validation-config" type="config:validation-configType" />
   <xs:complexType name="validation-configType">

http://git-wip-us.apache.org/repos/asf/bval/blob/0bf9b3a7/bval-jsr/src/main/xsd/validation-mapping-2.0.xsd
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/xsd/validation-mapping-2.0.xsd b/bval-jsr/src/main/xsd/validation-mapping-2.0.xsd
index 9d16bf3..418b68b 100644
--- a/bval-jsr/src/main/xsd/validation-mapping-2.0.xsd
+++ b/bval-jsr/src/main/xsd/validation-mapping-2.0.xsd
@@ -19,9 +19,9 @@
 -->
 <xs:schema attributeFormDefault="unqualified"
            elementFormDefault="qualified"
-           targetNamespace="http://xmlns.jcp.org/xml/ns/javax/validation/mapping"
+           targetNamespace="http://xmlns.jcp.org/xml/ns/validation/mapping"
            xmlns:xs="http://www.w3.org/2001/XMLSchema"
-           xmlns:map="http://xmlns.jcp.org/xml/ns/javax/validation/mapping"
+           xmlns:map="http://xmlns.jcp.org/xml/ns/validation/mapping"
            version="2.0">
   <xs:element name="constraint-mappings" type="map:constraint-mappingsType" />
 

http://git-wip-us.apache.org/repos/asf/bval/blob/0bf9b3a7/bval-jsr/src/test/resources/sample-validation2.xml
----------------------------------------------------------------------
diff --git a/bval-jsr/src/test/resources/sample-validation2.xml b/bval-jsr/src/test/resources/sample-validation2.xml
index 4758454..f4422e5 100644
--- a/bval-jsr/src/test/resources/sample-validation2.xml
+++ b/bval-jsr/src/test/resources/sample-validation2.xml
@@ -16,10 +16,10 @@
     limitations under the License.
 -->
 <validation-config
-    xmlns="http://xmlns.jcp.org/xml/ns/javax/validation/configuration"
+    xmlns="http://xmlns.jcp.org/xml/ns/validation/configuration"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation=
-        "http://xmlns.jcp.org/xml/ns/javax/validation/configuration validation-configuration-2.0.xsd"
+        "http://xmlns.jcp.org/xml/ns/validation/configuration validation-configuration-2.0.xsd"
     version="2.0">
   <default-provider>org.apache.bval.jsr.ApacheValidationProvider</default-provider>
   <message-interpolator>org.apache.bval.jsr.xml.TestMessageInterpolator</message-interpolator>


[12/12] bval git commit: make sure method-invocation-specified participant objects always take precedence over XML-configured ones

Posted by mb...@apache.org.
make sure method-invocation-specified participant objects always take precedence over XML-configured ones


Project: http://git-wip-us.apache.org/repos/asf/bval/repo
Commit: http://git-wip-us.apache.org/repos/asf/bval/commit/f8da0211
Tree: http://git-wip-us.apache.org/repos/asf/bval/tree/f8da0211
Diff: http://git-wip-us.apache.org/repos/asf/bval/diff/f8da0211

Branch: refs/heads/bv2
Commit: f8da02117a9983615a5fc1095738f90a90c8b6b3
Parents: f783358
Author: Matt Benson <mb...@apache.org>
Authored: Fri Mar 16 17:58:52 2018 -0500
Committer: Matt Benson <mb...@apache.org>
Committed: Fri Mar 16 17:58:52 2018 -0500

----------------------------------------------------------------------
 .../org/apache/bval/jsr/ConfigurationImpl.java  | 41 ++++++++++++--------
 1 file changed, 25 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/bval/blob/f8da0211/bval-jsr/src/main/java/org/apache/bval/jsr/ConfigurationImpl.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/ConfigurationImpl.java b/bval-jsr/src/main/java/org/apache/bval/jsr/ConfigurationImpl.java
index 3e2f678..b4d19f6 100644
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/ConfigurationImpl.java
+++ b/bval-jsr/src/main/java/org/apache/bval/jsr/ConfigurationImpl.java
@@ -63,26 +63,35 @@ import org.apache.commons.weaver.privilizer.Privileged;
 public class ConfigurationImpl implements ApacheValidatorConfiguration, ConfigurationState {
 
     private class LazyParticipant<T> extends Lazy<T> {
+        private boolean locked;
 
         private LazyParticipant(Supplier<T> init) {
             super(init);
         }
 
-        @Override
-        public Lazy<T> reset(Supplier<T> init) {
-            try {
-                return super.reset(init);
-            } finally {
-                ConfigurationImpl.this.prepared = false;
-            }
-        }
-
         ConfigurationImpl override(T value) {
             if (value != null) {
-                reset(() -> value);
+                synchronized (this) {
+                    if (!locked) {
+                        try {
+                            reset(() -> value);
+                        } finally {
+                            ConfigurationImpl.this.prepared = false;
+                        }
+                    }
+                }
             }
             return ConfigurationImpl.this;
         }
+
+        synchronized ConfigurationImpl externalOverride(T value) {
+            locked = false;
+            try {
+                return override(value);
+            } finally {
+                locked = true;
+            }
+        }
     }
 
     /**
@@ -187,7 +196,7 @@ public class ConfigurationImpl implements ApacheValidatorConfiguration, Configur
      */
     @Override
     public ConfigurationImpl messageInterpolator(MessageInterpolator resolver) {
-        return messageInterpolator.override(resolver);
+        return messageInterpolator.externalOverride(resolver);
     }
 
     /**
@@ -195,7 +204,7 @@ public class ConfigurationImpl implements ApacheValidatorConfiguration, Configur
      */
     @Override
     public ApacheValidatorConfiguration traversableResolver(TraversableResolver resolver) {
-        return traversableResolver.override(resolver);
+        return traversableResolver.externalOverride(resolver);
     }
 
     /**
@@ -203,17 +212,17 @@ public class ConfigurationImpl implements ApacheValidatorConfiguration, Configur
      */
     @Override
     public ConfigurationImpl constraintValidatorFactory(ConstraintValidatorFactory constraintValidatorFactory) {
-        return this.constraintValidatorFactory.override(constraintValidatorFactory);
+        return this.constraintValidatorFactory.externalOverride(constraintValidatorFactory);
     }
 
     @Override
     public ApacheValidatorConfiguration parameterNameProvider(ParameterNameProvider parameterNameProvider) {
-        return this.parameterNameProvider.override(parameterNameProvider);
+        return this.parameterNameProvider.externalOverride(parameterNameProvider);
     }
 
     @Override
     public ApacheValidatorConfiguration clockProvider(ClockProvider clockProvider) {
-        return this.clockProvider.override(clockProvider);
+        return this.clockProvider.externalOverride(clockProvider);
     }
 
     /**
@@ -469,7 +478,7 @@ public class ConfigurationImpl implements ApacheValidatorConfiguration, Configur
         final String className = getClassName.get();
         if (className != null) {
             final Class<T> t = loadClass(className);
-            participant.reset(() -> newInstance(t));
+            participant.override(newInstance(t));
         }
     }
 


[07/12] bval git commit: if no parameter builder available, return an empty builder in its place

Posted by mb...@apache.org.
if no parameter builder available, return an empty builder in its place


Project: http://git-wip-us.apache.org/repos/asf/bval/repo
Commit: http://git-wip-us.apache.org/repos/asf/bval/commit/c141d30e
Tree: http://git-wip-us.apache.org/repos/asf/bval/tree/c141d30e
Diff: http://git-wip-us.apache.org/repos/asf/bval/diff/c141d30e

Branch: refs/heads/bv2
Commit: c141d30e2c58d505fe09e596a9e95c365c308419
Parents: e34b20b
Author: Matt Benson <mb...@apache.org>
Authored: Fri Mar 16 17:54:00 2018 -0500
Committer: Matt Benson <mb...@apache.org>
Committed: Fri Mar 16 17:54:00 2018 -0500

----------------------------------------------------------------------
 .../main/java/org/apache/bval/jsr/descriptor/MetadataReader.java | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/bval/blob/c141d30e/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/MetadataReader.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/MetadataReader.java b/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/MetadataReader.java
index 177b5c0..c0d5e78 100644
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/MetadataReader.java
+++ b/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/MetadataReader.java
@@ -255,7 +255,9 @@ class MetadataReader {
 
             return IntStream.range(0, parameters.length).mapToObj(i -> {
                 final Meta.ForParameter param = new Meta.ForParameter(parameters[i], parameterNames.get(i));
-                return new ParameterD<>(param, i, new MetadataReader.ForContainer<>(param, builders.get(i)), parent);
+                final MetadataBuilder.ForContainer<Parameter> parameterBuilder =
+                    builders.size() > i ? builders.get(i) : EmptyBuilder.instance().forContainer();
+                return new ParameterD<>(param, i, new MetadataReader.ForContainer<>(param, parameterBuilder), parent);
             }).collect(ToUnmodifiable.list());
         }
 


[09/12] bval git commit: handle null values in JAXB mapping model

Posted by mb...@apache.org.
handle null values in JAXB mapping model


Project: http://git-wip-us.apache.org/repos/asf/bval/repo
Commit: http://git-wip-us.apache.org/repos/asf/bval/commit/8c6fdea9
Tree: http://git-wip-us.apache.org/repos/asf/bval/tree/8c6fdea9
Diff: http://git-wip-us.apache.org/repos/asf/bval/diff/8c6fdea9

Branch: refs/heads/bv2
Commit: 8c6fdea90eb085aece67a84e03468333299170ad
Parents: a1f1f74
Author: Matt Benson <mb...@apache.org>
Authored: Fri Mar 16 17:55:36 2018 -0500
Committer: Matt Benson <mb...@apache.org>
Committed: Fri Mar 16 17:55:36 2018 -0500

----------------------------------------------------------------------
 .../java/org/apache/bval/jsr/metadata/XmlBuilder.java | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/bval/blob/8c6fdea9/bval-jsr/src/main/java/org/apache/bval/jsr/metadata/XmlBuilder.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/metadata/XmlBuilder.java b/bval-jsr/src/main/java/org/apache/bval/jsr/metadata/XmlBuilder.java
index 404954c..26d5224 100644
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/metadata/XmlBuilder.java
+++ b/bval-jsr/src/main/java/org/apache/bval/jsr/metadata/XmlBuilder.java
@@ -242,7 +242,7 @@ public class XmlBuilder {
 
         @Override
         public boolean isCascade(Meta<E> meta) {
-            return lazy(isCascade, "isCascade").booleanValue();
+            return Boolean.TRUE.equals(lazy(isCascade, "isCascade"));
         }
 
         @Override
@@ -356,12 +356,20 @@ public class XmlBuilder {
 
         @Override
         public MetadataBuilder.ForElement<E> getCrossParameter(Meta<E> meta) {
-            return new XmlBuilder.ForCrossParameter<>(lazy(getCrossParameter, "getCrossParameter"));
+            final CrossParameterType cp = lazy(getCrossParameter, "getCrossParameter");
+            if (cp == null) {
+                return EmptyBuilder.instance().<E> forExecutable().getCrossParameter(meta);
+            }
+            return new XmlBuilder.ForCrossParameter<>(cp);
         }
 
         @Override
         public MetadataBuilder.ForContainer<E> getReturnValue(Meta<E> meta) {
-            return new XmlBuilder.ForReturnValue<>(lazy(getReturnValue, "getReturnValue"));
+            final ReturnValueType rv = lazy(getReturnValue, "getReturnValue");
+            if (rv == null) {
+                return EmptyBuilder.instance().<E> forExecutable().getReturnValue(meta);
+            }
+            return new XmlBuilder.ForReturnValue<>(rv);
         }
 
         @Override


[03/12] bval git commit: ws

Posted by mb...@apache.org.
ws


Project: http://git-wip-us.apache.org/repos/asf/bval/repo
Commit: http://git-wip-us.apache.org/repos/asf/bval/commit/48d4ae54
Tree: http://git-wip-us.apache.org/repos/asf/bval/tree/48d4ae54
Diff: http://git-wip-us.apache.org/repos/asf/bval/diff/48d4ae54

Branch: refs/heads/bv2
Commit: 48d4ae5471dd66cc28ca8be3a7ad505cb88b45d3
Parents: 47cfebe
Author: Matt Benson <mb...@apache.org>
Authored: Thu Mar 15 15:24:06 2018 -0500
Committer: Matt Benson <mb...@apache.org>
Committed: Thu Mar 15 15:24:06 2018 -0500

----------------------------------------------------------------------
 .../src/main/java/org/apache/bval/cdi/BValInterceptorBean.java     | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/bval/blob/48d4ae54/bval-jsr/src/main/java/org/apache/bval/cdi/BValInterceptorBean.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/cdi/BValInterceptorBean.java b/bval-jsr/src/main/java/org/apache/bval/cdi/BValInterceptorBean.java
index e8f7e1d..94a173c 100644
--- a/bval-jsr/src/main/java/org/apache/bval/cdi/BValInterceptorBean.java
+++ b/bval-jsr/src/main/java/org/apache/bval/cdi/BValInterceptorBean.java
@@ -120,7 +120,7 @@ public class BValInterceptorBean implements Bean<BValInterceptor>, PassivationCa
 
     @Override
     public String getId() {
-        return String.format("%s-%d",BValInterceptor.class.getSimpleName(), hashCode());
+        return String.format("%s-%d", BValInterceptor.class.getSimpleName(), hashCode());
     }
 
     private static class BValInterceptorInjectionPoint implements InjectionPoint {


[11/12] bval git commit: permit cascading declaration among unrelated convergent methods

Posted by mb...@apache.org.
permit cascading declaration among unrelated convergent methods


Project: http://git-wip-us.apache.org/repos/asf/bval/repo
Commit: http://git-wip-us.apache.org/repos/asf/bval/commit/f7833584
Tree: http://git-wip-us.apache.org/repos/asf/bval/tree/f7833584
Diff: http://git-wip-us.apache.org/repos/asf/bval/diff/f7833584

Branch: refs/heads/bv2
Commit: f7833584f0bef56845bd8e8258c3cfaa3980e01b
Parents: db49785
Author: Matt Benson <mb...@apache.org>
Authored: Fri Mar 16 17:57:47 2018 -0500
Committer: Matt Benson <mb...@apache.org>
Committed: Fri Mar 16 17:57:47 2018 -0500

----------------------------------------------------------------------
 .../main/java/org/apache/bval/jsr/metadata/Liskov.java | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/bval/blob/f7833584/bval-jsr/src/main/java/org/apache/bval/jsr/metadata/Liskov.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/metadata/Liskov.java b/bval-jsr/src/main/java/org/apache/bval/jsr/metadata/Liskov.java
index 2440948..bbd4d2b 100644
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/metadata/Liskov.java
+++ b/bval-jsr/src/main/java/org/apache/bval/jsr/metadata/Liskov.java
@@ -159,11 +159,16 @@ class Liskov {
     }
 
     private static void noRedeclarationOfReturnValueCascading(List<? extends ContainerDelegate<?>> delegates) {
-        final Set<Meta<?>> markedForCascade = delegates.stream().filter(ContainerDelegate::isCascade)
-            .map(HierarchyDelegate::getHierarchyElement).collect(Collectors.toCollection(LinkedHashSet::new));
+        final Map<Class<?>, Meta<?>> cascadedReturnValues =
+            delegates.stream().filter(ContainerDelegate::isCascade).map(HierarchyDelegate::getHierarchyElement)
+                .collect(Collectors.toMap(Meta::getDeclaringClass, Function.identity()));
 
-        Exceptions.raiseIf(markedForCascade.size() > 1, ConstraintDeclarationException::new,
-            "Multiple method return values marked @%s in hierarchy %s", Valid.class.getSimpleName(), markedForCascade);
+        final boolean anyRelated = cascadedReturnValues.keySet().stream().anyMatch(t -> cascadedReturnValues.keySet()
+            .stream().filter(Predicate.isEqual(t).negate()).anyMatch(t2 -> related(t, t2)));
+
+        Exceptions.raiseIf(anyRelated, ConstraintDeclarationException::new,
+            "Multiple method return values marked @%s in hierarchy %s", Valid.class.getSimpleName(),
+            cascadedReturnValues.values());
     }
 
     @SafeVarargs