You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by ra...@apache.org on 2018/10/12 15:00:51 UTC
svn commit: r1843674 [5/22] - in /tomee/deps/branches/bval-2: ./ bundle/
bundle/src/ bundle/src/main/ bundle/src/main/appended-resources/
bundle/src/main/appended-resources/META-INF/ bval-extras/ bval-extras/src/
bval-extras/src/main/ bval-extras/src/m...
Added: tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/MinValidatorForNumber.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/MinValidatorForNumber.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/MinValidatorForNumber.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/MinValidatorForNumber.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,52 @@
+/*
+ * 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.Min;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+
+/**
+ * Description: validate that number-value of passed object is >= min-value<br/>
+ */
+public class MinValidatorForNumber implements ConstraintValidator<Min, Number> {
+
+ private long minValue;
+
+ @Override
+ public void initialize(Min annotation) {
+ this.minValue = annotation.value();
+ }
+
+ @Override
+ public boolean isValid(Number value, ConstraintValidatorContext context) {
+ if (value == null) {
+ return true;
+ }
+ if (value instanceof BigDecimal) {
+ return ((BigDecimal) value).compareTo(BigDecimal.valueOf(minValue)) >= 0;
+ }
+ if (value instanceof BigInteger) {
+ return ((BigInteger) value).compareTo(BigInteger.valueOf(minValue)) >= 0;
+ }
+ return value.longValue() >= minValue;
+ }
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/MinValidatorForString.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/MinValidatorForString.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/MinValidatorForString.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/MinValidatorForString.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,50 @@
+/*
+ * 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.Min;
+import java.math.BigDecimal;
+
+/**
+ * Check that the String being validated represents a number, and has a value
+ * more than or equal to the minimum value specified.
+ */
+public class MinValidatorForString implements ConstraintValidator<Min, String> {
+
+ private long minValue;
+
+ @Override
+ public void initialize(Min annotation) {
+ this.minValue = annotation.value();
+ }
+
+ @Override
+ public boolean isValid(String value, ConstraintValidatorContext context) {
+ if (value == null) {
+ return true;
+ }
+ try {
+ return new BigDecimal(value).compareTo(BigDecimal.valueOf(minValue)) >= 0;
+ } catch (NumberFormatException nfe) {
+ return false;
+ }
+ }
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/NotBlankValidator.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/NotBlankValidator.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/NotBlankValidator.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/NotBlankValidator.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,34 @@
+/*
+ * 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.NotBlank;
+
+/**
+ * Validate {@link NotBlank} for {@link CharSequence}.
+ */
+public class NotBlankValidator implements ConstraintValidator<NotBlank, CharSequence> {
+
+ @Override
+ public boolean isValid(CharSequence value, ConstraintValidatorContext context) {
+ return value != null && value.length() > 0 && !value.chars().allMatch(Character::isWhitespace);
+ }
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/NotEmpty.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/NotEmpty.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/NotEmpty.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/NotEmpty.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,60 @@
+/*
+ * 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 static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import static java.lang.annotation.ElementType.CONSTRUCTOR;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE_USE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.validation.Constraint;
+import javax.validation.OverridesAttribute;
+import javax.validation.Payload;
+
+/**
+ * <pre>
+ * This class is NOT part of the bean_validation spec and might disappear
+ * as soon as a final version of the specification contains a similar functionality.
+ * </pre>
+ */
+@Documented
+@Constraint(validatedBy = {})
+@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE })
+@Retention(RUNTIME)
+@javax.validation.constraints.NotEmpty
+@Deprecated
+public @interface NotEmpty {
+ Class<?>[] groups() default {};
+
+ @OverridesAttribute(constraint = javax.validation.constraints.NotEmpty.class, name = "message")
+ String message() default "{org.apache.bval.constraints.NotEmpty.message}";
+
+ Class<? extends Payload>[] payload() default {};
+
+ public @interface List {
+ NotEmpty[] value();
+ }
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/NotEmptyValidator.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/NotEmptyValidator.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/NotEmptyValidator.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/NotEmptyValidator.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,52 @@
+/*
+ * 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 java.lang.reflect.Array;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+/**
+ * Description: Check the non emptiness of an
+ * any object that has a public isEmpty():boolean or a valid toString() method
+ */
+public class NotEmptyValidator implements ConstraintValidator<javax.validation.constraints.NotEmpty, Object> {
+
+ @Override
+ public boolean isValid(Object value, ConstraintValidatorContext context) {
+ if (value == null) {
+ return true;
+ }
+ if (value.getClass().isArray()) {
+ return Array.getLength(value) > 0;
+ }
+ try {
+ final Method isEmptyMethod = value.getClass().getMethod("isEmpty");
+ if (isEmptyMethod != null) {
+ return !Boolean.TRUE.equals(isEmptyMethod.invoke(value));
+ }
+ } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException iae) {
+ // do nothing
+ }
+ final String s = value.toString();
+ return s != null && !s.isEmpty();
+ }
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/NotEmptyValidatorForCharSequence.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/NotEmptyValidatorForCharSequence.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/NotEmptyValidatorForCharSequence.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/NotEmptyValidatorForCharSequence.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,34 @@
+/*
+ * 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;
+
+/**
+ * Description: <br/>
+ */
+public class NotEmptyValidatorForCharSequence
+ implements ConstraintValidator<javax.validation.constraints.NotEmpty, CharSequence> {
+
+ @Override
+ public boolean isValid(CharSequence value, ConstraintValidatorContext context) {
+ return value == null || value.length() > 0;
+ }
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/NotEmptyValidatorForCollection.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/NotEmptyValidatorForCollection.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/NotEmptyValidatorForCollection.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/NotEmptyValidatorForCollection.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,35 @@
+/*
+ * 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 java.util.Collection;
+
+/**
+ * Description: <br/>
+ */
+public class NotEmptyValidatorForCollection
+ implements ConstraintValidator<javax.validation.constraints.NotEmpty, Collection<?>> {
+
+ @Override
+ public boolean isValid(Collection<?> value, ConstraintValidatorContext context) {
+ return value == null || !value.isEmpty();
+ }
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/NotEmptyValidatorForMap.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/NotEmptyValidatorForMap.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/NotEmptyValidatorForMap.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/NotEmptyValidatorForMap.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,34 @@
+/*
+ * 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 java.util.Map;
+
+/**
+ * Description: <br/>
+ */
+public class NotEmptyValidatorForMap implements ConstraintValidator<javax.validation.constraints.NotEmpty, Map<?, ?>> {
+
+ @Override
+ public boolean isValid(Map<?, ?> value, ConstraintValidatorContext context) {
+ return value == null || !value.isEmpty();
+ }
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/NotNullValidator.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/NotNullValidator.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/NotNullValidator.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/NotNullValidator.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,32 @@
+/*
+ * 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.NotNull;
+
+/** valid when object is NOT null */
+public class NotNullValidator implements ConstraintValidator<NotNull, Object> {
+
+ @Override
+ public boolean isValid(Object value, ConstraintValidatorContext context) {
+ return value != null;
+ }
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/NullValidator.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/NullValidator.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/NullValidator.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/NullValidator.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,34 @@
+/*
+ * 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.Null;
+
+/**
+ * Description: valid when object is null<br/>
+ */
+public class NullValidator implements ConstraintValidator<Null, Object> {
+
+ @Override
+ public boolean isValid(Object object, ConstraintValidatorContext context) {
+ return object == null;
+ }
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/NumberSignValidator.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/NumberSignValidator.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/NumberSignValidator.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/NumberSignValidator.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,79 @@
+/*
+ * 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.lang.annotation.Annotation;
+import java.util.function.IntPredicate;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.Negative;
+import javax.validation.constraints.NegativeOrZero;
+import javax.validation.constraints.Positive;
+import javax.validation.constraints.PositiveOrZero;
+
+import org.apache.bval.util.Validate;
+
+/**
+ * Description: validate positive/negative number values.
+ */
+public abstract class NumberSignValidator<A extends Annotation> implements ConstraintValidator<A, Number> {
+ public static class ForPositive extends NumberSignValidator<Positive> {
+ public static class OrZero extends NumberSignValidator<PositiveOrZero> {
+ public OrZero() {
+ super(n -> n >= 0);
+ }
+ }
+
+ public ForPositive() {
+ super(n -> n > 0);
+ }
+ }
+
+ public static class ForNegative extends NumberSignValidator<Negative> {
+ public static class OrZero extends NumberSignValidator<NegativeOrZero> {
+ public OrZero() {
+ super(n -> n <= 0);
+ }
+ }
+
+ public ForNegative() {
+ super(n -> n < 0);
+ }
+ }
+
+ private final IntPredicate comparisonTest;
+
+ protected NumberSignValidator(IntPredicate comparisonTest) {
+ super();
+ this.comparisonTest = Validate.notNull(comparisonTest);
+ }
+
+ @Override
+ public boolean isValid(Number value, ConstraintValidatorContext context) {
+ if (value == null) {
+ return true;
+ }
+ final double d = value.doubleValue();
+ if (Double.isNaN(d)) {
+ return false;
+ }
+ return comparisonTest.test(Double.compare(d, 0.0));
+ }
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/PastOrPresentValidator.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/PastOrPresentValidator.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/PastOrPresentValidator.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/PastOrPresentValidator.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,146 @@
+/*
+ * 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.time.Clock;
+import java.time.Instant;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.MonthDay;
+import java.time.OffsetDateTime;
+import java.time.OffsetTime;
+import java.time.Year;
+import java.time.YearMonth;
+import java.time.ZonedDateTime;
+import java.time.chrono.ChronoLocalDate;
+import java.time.chrono.ChronoLocalDateTime;
+import java.time.chrono.ChronoZonedDateTime;
+import java.util.Calendar;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.function.Function;
+import java.util.function.IntPredicate;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.constraints.PastOrPresent;
+
+/**
+ * Defines built-in {@link ConstraintValidator} implementations for {@link PastOrPresent}.
+ *
+ * @param <T>
+ * validated type
+ */
+public abstract class PastOrPresentValidator<T extends Comparable<T>> extends TimeValidator<PastOrPresent, T> {
+
+ public static class ForDate extends PastOrPresentValidator<Date> {
+
+ public ForDate() {
+ super(clock -> Date.from(clock.instant()));
+ }
+ }
+
+ public static class ForCalendar extends PastOrPresentValidator<Calendar> {
+
+ public ForCalendar() {
+ super(clock -> GregorianCalendar.from(clock.instant().atZone(clock.getZone())));
+ }
+ }
+
+ public static class ForInstant extends PastOrPresentValidator<Instant> {
+
+ public ForInstant() {
+ super(Instant::now);
+ }
+ }
+
+ public static class ForChronoLocalDate extends PastOrPresentValidator<ChronoLocalDate> {
+
+ public ForChronoLocalDate() {
+ super(LocalDate::now, CHRONO_LOCAL_DATE_COMPARATOR);
+ }
+ }
+
+ public static class ForChronoLocalDateTime extends PastOrPresentValidator<ChronoLocalDateTime<?>> {
+
+ public ForChronoLocalDateTime() {
+ super(LocalDateTime::now, CHRONO_LOCAL_DATE_TIME_COMPARATOR);
+ }
+ }
+
+ public static class ForLocalTime extends PastOrPresentValidator<LocalTime> {
+
+ public ForLocalTime() {
+ super(LocalTime::now);
+ }
+ }
+
+ public static class ForOffsetDateTime extends PastOrPresentValidator<OffsetDateTime> {
+
+ public ForOffsetDateTime() {
+ super(OffsetDateTime::now);
+ }
+ }
+
+ public static class ForOffsetTime extends PastOrPresentValidator<OffsetTime> {
+
+ public ForOffsetTime() {
+ super(OffsetTime::now);
+ }
+ }
+
+ public static class ForChronoZonedDateTime extends PastOrPresentValidator<ChronoZonedDateTime<?>> {
+
+ public ForChronoZonedDateTime() {
+ super(ZonedDateTime::now, CHRONO_ZONED_DATE_TIME_COMPARATOR);
+ }
+ }
+
+ public static class ForMonthDay extends PastOrPresentValidator<MonthDay> {
+
+ public ForMonthDay() {
+ super(MonthDay::now);
+ }
+ }
+
+ public static class ForYear extends PastOrPresentValidator<Year> {
+
+ public ForYear() {
+ super(Year::now);
+ }
+ }
+
+ public static class ForYearMonth extends PastOrPresentValidator<YearMonth> {
+
+ public ForYearMonth() {
+ super(YearMonth::now);
+ }
+ }
+
+ private static final IntPredicate TEST = n -> n <= 0;
+
+ protected PastOrPresentValidator(Function<Clock, T> now) {
+ super(now, TEST);
+ }
+
+ protected PastOrPresentValidator(Function<Clock, T> now, Comparator<? super T> cmp) {
+ super(now, cmp, TEST);
+ }
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/PastValidator.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/PastValidator.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/PastValidator.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/PastValidator.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,146 @@
+/*
+ * 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.time.Clock;
+import java.time.Instant;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.MonthDay;
+import java.time.OffsetDateTime;
+import java.time.OffsetTime;
+import java.time.Year;
+import java.time.YearMonth;
+import java.time.ZonedDateTime;
+import java.time.chrono.ChronoLocalDate;
+import java.time.chrono.ChronoLocalDateTime;
+import java.time.chrono.ChronoZonedDateTime;
+import java.util.Calendar;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.function.Function;
+import java.util.function.IntPredicate;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.constraints.Past;
+
+/**
+ * Defines built-in {@link ConstraintValidator} implementations for {@link Past}.
+ *
+ * @param <T>
+ * validated type
+ */
+public abstract class PastValidator<T extends Comparable<T>> extends TimeValidator<Past, T> {
+
+ public static class ForDate extends PastValidator<Date> {
+
+ public ForDate() {
+ super(clock -> Date.from(clock.instant()));
+ }
+ }
+
+ public static class ForCalendar extends PastValidator<Calendar> {
+
+ public ForCalendar() {
+ super(clock -> GregorianCalendar.from(clock.instant().atZone(clock.getZone())));
+ }
+ }
+
+ public static class ForInstant extends PastValidator<Instant> {
+
+ public ForInstant() {
+ super(Instant::now);
+ }
+ }
+
+ public static class ForChronoLocalDate extends PastValidator<ChronoLocalDate> {
+
+ public ForChronoLocalDate() {
+ super(LocalDate::now, CHRONO_LOCAL_DATE_COMPARATOR);
+ }
+ }
+
+ public static class ForChronoLocalDateTime extends PastValidator<ChronoLocalDateTime<?>> {
+
+ public ForChronoLocalDateTime() {
+ super(LocalDateTime::now, CHRONO_LOCAL_DATE_TIME_COMPARATOR);
+ }
+ }
+
+ public static class ForLocalTime extends PastValidator<LocalTime> {
+
+ public ForLocalTime() {
+ super(LocalTime::now);
+ }
+ }
+
+ public static class ForOffsetDateTime extends PastValidator<OffsetDateTime> {
+
+ public ForOffsetDateTime() {
+ super(OffsetDateTime::now);
+ }
+ }
+
+ public static class ForOffsetTime extends PastValidator<OffsetTime> {
+
+ public ForOffsetTime() {
+ super(OffsetTime::now);
+ }
+ }
+
+ public static class ForChronoZonedDateTime extends PastValidator<ChronoZonedDateTime<?>> {
+
+ public ForChronoZonedDateTime() {
+ super(ZonedDateTime::now, PastValidator.CHRONO_ZONED_DATE_TIME_COMPARATOR);
+ }
+ }
+
+ public static class ForMonthDay extends PastValidator<MonthDay> {
+
+ public ForMonthDay() {
+ super(MonthDay::now);
+ }
+ }
+
+ public static class ForYear extends PastValidator<Year> {
+
+ public ForYear() {
+ super(Year::now);
+ }
+ }
+
+ public static class ForYearMonth extends PastValidator<YearMonth> {
+
+ public ForYearMonth() {
+ super(YearMonth::now);
+ }
+ }
+
+ private static final IntPredicate TEST = n -> n < 0;
+
+ protected PastValidator(Function<Clock, T> now) {
+ super(now, TEST);
+ }
+
+ protected PastValidator(Function<Clock, T> now, Comparator<? super T> cmp) {
+ super(now, cmp, TEST);
+ }
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/PatternValidator.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/PatternValidator.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/PatternValidator.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/PatternValidator.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,42 @@
+/*
+ * 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.constraints.Pattern;
+import javax.validation.constraints.Pattern.Flag;
+
+/**
+ * validator using a regular expression, based on the jsr Pattern constraint annotation.
+ */
+public class PatternValidator extends AbstractPatternValidator<Pattern, CharSequence> {
+ public PatternValidator() {
+ super(p -> new PatternDescriptor() {
+
+ @Override
+ public String regexp() {
+ return p.regexp();
+ }
+
+ @Override
+ public Flag[] flags() {
+ return p.flags();
+ }
+ });
+ }
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidator.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidator.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidator.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidator.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,125 @@
+/*
+ * 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.lang.reflect.Array;
+import java.util.Collection;
+import java.util.Map;
+import java.util.function.ToIntFunction;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.ValidationException;
+import javax.validation.constraints.Size;
+
+/**
+ * Description: Abstract validator impl. for @Size annotation.
+ */
+public abstract class SizeValidator<T> implements ConstraintValidator<Size, T> {
+ public static class ForArray<T> extends SizeValidator<T> {
+ public static class OfObject extends ForArray<Object[]> {
+ }
+
+ public static class OfByte extends ForArray<byte[]> {
+ }
+
+ public static class OfShort extends ForArray<short[]> {
+ }
+
+ public static class OfInt extends ForArray<int[]> {
+ }
+
+ public static class OfLong extends ForArray<long[]> {
+ }
+
+ public static class OfChar extends ForArray<char[]> {
+ }
+
+ public static class OfFloat extends ForArray<float[]> {
+ }
+
+ public static class OfDouble extends ForArray<double[]> {
+ }
+
+ public static class OfBoolean extends ForArray<boolean[]> {
+ }
+
+ protected ForArray() {
+ super(Array::getLength);
+ }
+ }
+
+ public static class ForCharSequence extends SizeValidator<CharSequence> {
+ public ForCharSequence() {
+ super(CharSequence::length);
+ }
+ }
+
+ public static class ForCollection extends SizeValidator<Collection<?>> {
+
+ public ForCollection() {
+ super(Collection::size);
+ }
+ }
+
+ public static class ForMap extends SizeValidator<Map<?, ?>> {
+ public ForMap() {
+ super(Map::size);
+ }
+ }
+
+ private final ToIntFunction<? super T> sizeOf;
+
+ protected int min;
+ protected int max;
+
+ protected SizeValidator(ToIntFunction<? super T> sizeOf) {
+ super();
+ this.sizeOf = sizeOf;
+ }
+
+ /**
+ * Configure the constraint validator based on the elements specified at the time it was defined.
+ *
+ * @param constraint
+ * the constraint definition
+ */
+ public void initialize(Size constraint) {
+ min = constraint.min();
+ max = constraint.max();
+ if (min < 0) {
+ throw new ValidationException("Min cannot be negative");
+ }
+ if (max < 0) {
+ throw new ValidationException("Max cannot be negative");
+ }
+ if (max < min) {
+ throw new ValidationException("Max cannot be less than Min");
+ }
+ }
+
+ @Override
+ public boolean isValid(T value, ConstraintValidatorContext context) {
+ if (value == null) {
+ return true;
+ }
+ final int size = sizeOf.applyAsInt(value);
+ return min <= size && size <= max;
+ }
+}
\ No newline at end of file
Added: tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/TimeValidator.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/TimeValidator.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/TimeValidator.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/constraints/TimeValidator.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,63 @@
+/*
+ * 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.lang.annotation.Annotation;
+import java.time.Clock;
+import java.time.chrono.ChronoLocalDate;
+import java.time.chrono.ChronoLocalDateTime;
+import java.time.chrono.ChronoZonedDateTime;
+import java.util.Comparator;
+import java.util.function.Function;
+import java.util.function.IntPredicate;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+public abstract class TimeValidator<A extends Annotation, T> implements ConstraintValidator<A, T> {
+ protected static final Comparator<ChronoLocalDate> CHRONO_LOCAL_DATE_COMPARATOR =
+ Comparator.nullsFirst((quid, quo) -> quid.isBefore(quo) ? -1 : quid.isAfter(quo) ? 1 : 0);
+
+ protected static final Comparator<ChronoLocalDateTime<?>> CHRONO_LOCAL_DATE_TIME_COMPARATOR =
+ Comparator.nullsFirst((quid, quo) -> quid.isBefore(quo) ? -1 : quid.isAfter(quo) ? 1 : 0);
+
+ protected static final Comparator<ChronoZonedDateTime<?>> CHRONO_ZONED_DATE_TIME_COMPARATOR =
+ Comparator.nullsFirst((quid, quo) -> quid.isBefore(quo) ? -1 : quid.isAfter(quo) ? 1 : 0);
+
+ private final Function<Clock, T> now;
+ private final Comparator<? super T> cmp;
+ private final IntPredicate test;
+
+ @SuppressWarnings("unchecked")
+ protected TimeValidator(Function<Clock, T> now, IntPredicate test) {
+ this(now, (Comparator<T>) Comparator.naturalOrder(), test);
+ }
+
+ protected TimeValidator(Function<Clock, T> now, Comparator<? super T> cmp,IntPredicate test) {
+ super();
+ this.now = now;
+ this.cmp = cmp;
+ this.test = test;
+ }
+
+ @Override
+ public final boolean isValid(T value, ConstraintValidatorContext context) {
+ return value == null || test.test(cmp.compare(value, now.apply(context.getClockProvider().getClock())));
+ }
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/el/ELFacade.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/el/ELFacade.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/el/ELFacade.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/el/ELFacade.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,137 @@
+/*
+ * 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.el;
+
+import javax.el.ArrayELResolver;
+import javax.el.BeanELResolver;
+import javax.el.CompositeELResolver;
+import javax.el.ELContext;
+import javax.el.ELResolver;
+import javax.el.ExpressionFactory;
+import javax.el.FunctionMapper;
+import javax.el.ListELResolver;
+import javax.el.MapELResolver;
+import javax.el.ResourceBundleELResolver;
+import javax.el.ValueExpression;
+import javax.el.VariableMapper;
+import java.lang.reflect.Method;
+import java.util.Formatter;
+import java.util.HashMap;
+import java.util.Map;
+
+// ELProcessor or JavaEE 7 would be perfect too but this impl can be used in javaee 6
+public final class ELFacade implements MessageEvaluator {
+ private static final ExpressionFactory EXPRESSION_FACTORY;
+ static {
+ ExpressionFactory ef;
+ try {
+ ef = ExpressionFactory.newInstance();
+ } catch (final Exception e) {
+ ef = null;
+ }
+ EXPRESSION_FACTORY = ef;
+ }
+ private static final ELResolver RESOLVER = initResolver();
+
+ @Override
+ public String interpolate(final String message, final Map<String, Object> annotationParameters,
+ final Object validatedValue) {
+ try {
+ if (EXPRESSION_FACTORY != null) {
+ final BValELContext context = new BValELContext();
+ final VariableMapper variables = context.getVariableMapper();
+ annotationParameters.forEach(
+ (k, v) -> variables.setVariable(k, EXPRESSION_FACTORY.createValueExpression(v, Object.class)));
+
+ variables.setVariable("validatedValue",
+ EXPRESSION_FACTORY.createValueExpression(validatedValue, Object.class));
+
+ // #{xxx} shouldn't be evaluated
+ return EXPRESSION_FACTORY.createValueExpression(context, message.replace("#{", "\\#{"), String.class)
+ .getValue(context).toString();
+ }
+ } catch (final Exception e) {
+ // no-op
+ }
+
+ return message;
+ }
+
+ private static ELResolver initResolver() {
+ final CompositeELResolver resolver = new CompositeELResolver();
+ resolver.add(new MapELResolver());
+ resolver.add(new ListELResolver());
+ resolver.add(new ArrayELResolver());
+ resolver.add(new ResourceBundleELResolver());
+ resolver.add(new BeanELResolver());
+ return resolver;
+ }
+
+ private static class BValELContext extends ELContext {
+ private final FunctionMapper functions = new BValFunctionMapper();
+ private final VariableMapper variables = new BValVariableMapper();
+
+ @Override
+ public ELResolver getELResolver() {
+ return RESOLVER;
+ }
+
+ @Override
+ public FunctionMapper getFunctionMapper() {
+ return functions;
+ }
+
+ @Override
+ public VariableMapper getVariableMapper() {
+ return variables;
+ }
+ }
+
+ private static class BValFunctionMapper extends FunctionMapper {
+ @Override
+ public Method resolveFunction(final String prefix, final String localName) {
+ return null;
+ }
+ }
+
+ private static class BValVariableMapper extends VariableMapper {
+ private final Map<String, ValueExpression> variables = new HashMap<String, ValueExpression>();
+
+ @Override
+ public ValueExpression resolveVariable(final String variable) {
+ if ("formatter".equals(variable)) {
+ return EXPRESSION_FACTORY.createValueExpression(new BValFormatter(), Object.class);
+ }
+ return variables.get(variable);
+ }
+
+ @Override
+ public ValueExpression setVariable(final String variable, final ValueExpression expression) {
+ variables.put(variable, expression);
+ return expression;
+ }
+ }
+
+ // used to not expose all method and avoid ambiguity with format(Local, String, Object...) in EL
+ public static class BValFormatter {
+ private final Formatter formatter = new Formatter();
+
+ public Formatter format(final String format, final Object... args) {
+ return formatter.format(format, args);
+ }
+ }
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/el/MessageEvaluator.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/el/MessageEvaluator.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/el/MessageEvaluator.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/el/MessageEvaluator.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,25 @@
+/*
+ * 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.el;
+
+import java.util.Map;
+
+// just here to ensure we can use Expression Language if at classpath
+// but not fail if not here (as before)
+public interface MessageEvaluator {
+ String interpolate(String message, Map<String, Object> annotationParameters, Object validatedValue);
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheFactoryContext.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheFactoryContext.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheFactoryContext.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheFactoryContext.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,184 @@
+/*
+ * 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;
+
+import javax.validation.ClockProvider;
+import javax.validation.ConstraintValidatorFactory;
+import javax.validation.MessageInterpolator;
+import javax.validation.ParameterNameProvider;
+import javax.validation.TraversableResolver;
+import javax.validation.Validator;
+import javax.validation.ValidatorContext;
+import javax.validation.valueextraction.ValueExtractor;
+
+import org.apache.bval.jsr.descriptor.DescriptorManager;
+import org.apache.bval.jsr.groups.GroupsComputer;
+import org.apache.bval.jsr.valueextraction.ValueExtractors;
+import org.apache.bval.util.reflection.Reflection;
+import org.apache.commons.weaver.privilizer.Privilizing;
+import org.apache.commons.weaver.privilizer.Privilizing.CallTo;
+
+/**
+ * Description: Represents the context that is used to create {@link ClassValidator} instances.
+ */
+@Privilizing(@CallTo(Reflection.class))
+public class ApacheFactoryContext implements ValidatorContext {
+ private final ApacheValidatorFactory factory;
+ private final ValueExtractors valueExtractors;
+
+ private MessageInterpolator messageInterpolator;
+ private TraversableResolver traversableResolver;
+ private ParameterNameProvider parameterNameProvider;
+ private ConstraintValidatorFactory constraintValidatorFactory;
+ private ClockProvider clockProvider;
+
+ /**
+ * Create a new ApacheFactoryContext instance.
+ *
+ * @param factory
+ * validator factory
+ * @param metaBeanFinder
+ * meta finder
+ */
+ public ApacheFactoryContext(ApacheValidatorFactory factory) {
+ this.factory = factory;
+ valueExtractors = factory.getValueExtractors().createChild();
+ }
+
+ /**
+ * Discard cached metadata. Calling this method unnecessarily has the effect of severly limiting performance,
+ * therefore only do so when changes have been made that affect validation metadata, i.e. particularly NOT in
+ * response to:
+ * <ul>
+ * <li>{@link #messageInterpolator(MessageInterpolator)}</li>
+ * <li>{@link #traversableResolver(TraversableResolver)}</li>
+ * <li>{@link #constraintValidatorFactory(ConstraintValidatorFactory)</li>
+ * </ul>
+ */
+ private synchronized void resetMeta() {
+ getDescriptorManager().clear();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public ApacheFactoryContext messageInterpolator(MessageInterpolator messageInterpolator) {
+ this.messageInterpolator = messageInterpolator;
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public ApacheFactoryContext traversableResolver(TraversableResolver traversableResolver) {
+ this.traversableResolver = traversableResolver;
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public ApacheFactoryContext constraintValidatorFactory(ConstraintValidatorFactory constraintValidatorFactory) {
+ this.constraintValidatorFactory = constraintValidatorFactory;
+ return this;
+ }
+
+ @Override
+ public ApacheFactoryContext parameterNameProvider(ParameterNameProvider parameterNameProvider) {
+ this.parameterNameProvider = parameterNameProvider;
+ resetMeta(); // needed since parameter names are a component of validation metadata
+ return this;
+ }
+
+ @Override
+ public ApacheFactoryContext clockProvider(ClockProvider clockProvider) {
+ this.clockProvider = clockProvider;
+ return this;
+ }
+
+ @Override
+ public ApacheFactoryContext addValueExtractor(ValueExtractor<?> extractor) {
+ valueExtractors.add(extractor);
+ return this;
+ }
+
+ /**
+ * Get the {@link ConstraintValidatorFactory}.
+ *
+ * @return {@link ConstraintValidatorFactory}
+ */
+ public ConstraintValidatorFactory getConstraintValidatorFactory() {
+ return constraintValidatorFactory == null ? factory.getConstraintValidatorFactory()
+ : constraintValidatorFactory;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Validator getValidator() {
+ return new ValidatorImpl(this);
+ }
+
+ /**
+ * Get the {@link MessageInterpolator}.
+ *
+ * @return {@link MessageInterpolator}
+ */
+ public MessageInterpolator getMessageInterpolator() {
+ return messageInterpolator == null ? factory.getMessageInterpolator() : messageInterpolator;
+ }
+
+ /**
+ * Get the {@link TraversableResolver}.
+ *
+ * @return {@link TraversableResolver}
+ */
+ public TraversableResolver getTraversableResolver() {
+ return traversableResolver == null ? factory.getTraversableResolver() : traversableResolver;
+ }
+
+ public ParameterNameProvider getParameterNameProvider() {
+ return parameterNameProvider == null ? factory.getParameterNameProvider() : parameterNameProvider;
+ }
+
+ public ClockProvider getClockProvider() {
+ return clockProvider == null ? factory.getClockProvider() : clockProvider;
+ }
+
+ public ValueExtractors getValueExtractors() {
+ return valueExtractors;
+ }
+
+ public DescriptorManager getDescriptorManager() {
+ // TODO implementation-specific feature to handle context-local descriptor customizations
+ return factory.getDescriptorManager();
+ }
+
+ public GroupsComputer getGroupsComputer() {
+ return factory.getGroupsComputer();
+ }
+
+ public ConstraintCached getConstraintsCache() {
+ return factory.getConstraintsCache();
+ }
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheValidationProvider.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheValidationProvider.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheValidationProvider.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheValidationProvider.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,105 @@
+/*
+ * 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;
+
+import javax.validation.Configuration;
+import javax.validation.ValidationException;
+import javax.validation.ValidatorFactory;
+import javax.validation.spi.BootstrapState;
+import javax.validation.spi.ConfigurationState;
+import javax.validation.spi.ValidationProvider;
+
+import org.apache.bval.util.Exceptions;
+import org.apache.bval.util.reflection.Reflection;
+
+/**
+ * Description: Implementation of {@link ValidationProvider} for jsr
+ * implementation of the apache-validation framework.
+ * <p/>
+ * <br/>
+ * User: roman.stumm <br/>
+ * Date: 29.10.2008 <br/>
+ * Time: 14:45:41 <br/>
+ */
+public class ApacheValidationProvider implements ValidationProvider<ApacheValidatorConfiguration> {
+
+ /**
+ * Learn whether a particular builder class is suitable for this
+ * {@link ValidationProvider}.
+ *
+ * @param builderClass
+ * @return boolean suitability
+ */
+ public boolean isSuitable(Class<? extends Configuration<?>> builderClass) {
+ return ApacheValidatorConfiguration.class.equals(builderClass);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public ApacheValidatorConfiguration createSpecializedConfiguration(BootstrapState state) {
+ return new ConfigurationImpl(state, this);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Configuration<?> createGenericConfiguration(BootstrapState state) {
+ return new ConfigurationImpl(state, null);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @throws javax.validation.ValidationException
+ * if the ValidatorFactory cannot be built
+ */
+ @Override
+ public ValidatorFactory buildValidatorFactory(final ConfigurationState configuration) {
+ final Class<? extends ValidatorFactory> validatorFactoryClass;
+ try {
+ final String validatorFactoryClassname =
+ configuration.getProperties().get(ApacheValidatorConfiguration.Properties.VALIDATOR_FACTORY_CLASSNAME);
+
+ if (validatorFactoryClassname == null) {
+ validatorFactoryClass = ApacheValidatorFactory.class;
+ } else {
+ validatorFactoryClass =
+ Reflection.toClass(validatorFactoryClassname).asSubclass(ValidatorFactory.class);
+ }
+ } catch (ValidationException ex) {
+ throw ex;
+ } catch (Exception ex) {
+ throw new ValidationException("error building ValidatorFactory", ex);
+ }
+
+ try {
+ return validatorFactoryClass.getConstructor(ConfigurationState.class).newInstance(configuration);
+ } catch (Exception e) {
+ final Throwable t = Exceptions.causeOf(e);
+ if (t instanceof ValidationException) {
+ throw (ValidationException) t;
+ }
+ throw Exceptions.create(ValidationException::new, t, "Cannot instantiate %s",
+ validatorFactoryClass.getName());
+ }
+ }
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheValidatorConfiguration.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheValidatorConfiguration.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheValidatorConfiguration.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheValidatorConfiguration.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,53 @@
+/*
+ * 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;
+
+import javax.validation.Configuration;
+import javax.validation.ValidatorFactory;
+import javax.validation.spi.ConfigurationState;
+
+/**
+ * Description: Uniquely identify Apache BVal in the Bean Validation bootstrap
+ * strategy. Also contains Apache BVal specific configurations<br/>
+ */
+public interface ApacheValidatorConfiguration extends Configuration<ApacheValidatorConfiguration> {
+
+ /**
+ * Proprietary property keys for {@link ConfigurationImpl}
+ */
+ interface Properties {
+ /**
+ * the location where to look for the validation.xml file.
+ * default: "META-INF/validation.xml"
+ */
+ String VALIDATION_XML_PATH = "apache.bval.validation-xml-path";
+
+ /**
+ * Specifies the classname of the {@link ValidatorFactory} to use: this
+ * class is presumed have a constructor that accepts a single
+ * {@link ConfigurationState} argument.
+ */
+ String VALIDATOR_FACTORY_CLASSNAME = "apache.bval.validator-factory-classname";
+
+ /**
+ * Size to use for caching of constraint-related information. Default is {@code 50}.
+ */
+ String CONSTRAINTS_CACHE_SIZE = "apache.bval.constraints-cache-size";
+ }
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheValidatorFactory.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheValidatorFactory.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheValidatorFactory.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheValidatorFactory.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,373 @@
+/*
+ * 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;
+
+import java.io.Closeable;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.BiConsumer;
+
+import javax.validation.ClockProvider;
+import javax.validation.ConstraintValidatorFactory;
+import javax.validation.MessageInterpolator;
+import javax.validation.ParameterNameProvider;
+import javax.validation.TraversableResolver;
+import javax.validation.Validation;
+import javax.validation.ValidationException;
+import javax.validation.Validator;
+import javax.validation.ValidatorFactory;
+import javax.validation.spi.ConfigurationState;
+import javax.validation.valueextraction.ValueExtractor;
+
+import org.apache.bval.jsr.descriptor.DescriptorManager;
+import org.apache.bval.jsr.groups.GroupsComputer;
+import org.apache.bval.jsr.metadata.MetadataBuilder;
+import org.apache.bval.jsr.metadata.MetadataBuilder.ForBean;
+import org.apache.bval.jsr.metadata.MetadataBuilders;
+import org.apache.bval.jsr.metadata.MetadataSource;
+import org.apache.bval.jsr.util.AnnotationsManager;
+import org.apache.bval.jsr.valueextraction.ValueExtractors;
+import org.apache.bval.jsr.valueextraction.ValueExtractors.OnDuplicateContainerElementKey;
+import org.apache.bval.util.CloseableAble;
+import org.apache.bval.util.reflection.Reflection;
+import org.apache.commons.weaver.privilizer.Privilizing;
+import org.apache.commons.weaver.privilizer.Privilizing.CallTo;
+
+/**
+ * Description: a factory is a complete configurated object that can create
+ * validators.<br/>
+ * This instance is not thread-safe.<br/>
+ */
+@Privilizing(@CallTo(Reflection.class))
+public class ApacheValidatorFactory implements ValidatorFactory, Cloneable {
+
+ private static volatile ApacheValidatorFactory DEFAULT_FACTORY;
+
+ /**
+ * Convenience method to retrieve a default global ApacheValidatorFactory
+ *
+ * @return {@link ApacheValidatorFactory}
+ */
+ public static ApacheValidatorFactory getDefault() {
+ if (DEFAULT_FACTORY == null) {
+ synchronized (ApacheValidatorFactory.class) {
+ if (DEFAULT_FACTORY == null) {
+ DEFAULT_FACTORY = Validation.byProvider(ApacheValidationProvider.class).configure()
+ .buildValidatorFactory().unwrap(ApacheValidatorFactory.class);
+ }
+ }
+ }
+ return DEFAULT_FACTORY;
+ }
+
+ /**
+ * Set a particular {@link ApacheValidatorFactory} instance as the default.
+ *
+ * @param aDefaultFactory
+ */
+ public static void setDefault(ApacheValidatorFactory aDefaultFactory) {
+ DEFAULT_FACTORY = aDefaultFactory;
+ }
+
+ private static ValueExtractors createBaseValueExtractors(ParticipantFactory participantFactory) {
+ final ValueExtractors result = new ValueExtractors(OnDuplicateContainerElementKey.OVERWRITE);
+ participantFactory.loadServices(ValueExtractor.class).forEach(result::add);
+ return result;
+ }
+
+ private final Map<String, String> properties;
+ private final AnnotationsManager annotationsManager;
+ private final DescriptorManager descriptorManager = new DescriptorManager(this);
+ private final MetadataBuilders metadataBuilders = new MetadataBuilders();
+ private final ConstraintCached constraintsCache = new ConstraintCached();
+ private final Collection<Closeable> toClose = new ArrayList<>();
+ private final GroupsComputer groupsComputer = new GroupsComputer();
+ private final ParticipantFactory participantFactory;
+ private final ValueExtractors valueExtractors;
+
+ private MessageInterpolator messageResolver;
+ private TraversableResolver traversableResolver;
+ private ConstraintValidatorFactory constraintValidatorFactory;
+ private ParameterNameProvider parameterNameProvider;
+ private ClockProvider clockProvider;
+
+ /**
+ * Create a new ApacheValidatorFactory instance.
+ */
+ public ApacheValidatorFactory(ConfigurationState configuration) {
+ properties = new HashMap<>(configuration.getProperties());
+ parameterNameProvider = configuration.getParameterNameProvider();
+ messageResolver = configuration.getMessageInterpolator();
+ traversableResolver = configuration.getTraversableResolver();
+ constraintValidatorFactory = configuration.getConstraintValidatorFactory();
+ clockProvider = configuration.getClockProvider();
+
+ if (configuration instanceof CloseableAble) {
+ toClose.add(((CloseableAble) configuration).getCloseable());
+ }
+ participantFactory = new ParticipantFactory(Thread.currentThread().getContextClassLoader(),
+ ApacheValidatorFactory.class.getClassLoader());
+
+ toClose.add(participantFactory);
+
+ valueExtractors = createBaseValueExtractors(participantFactory).createChild();
+ configuration.getValueExtractors().forEach(valueExtractors::add);
+
+ annotationsManager = new AnnotationsManager(this);
+ loadAndVerifyUserCustomizations(configuration);
+ }
+
+ /**
+ * Get the property map of this {@link ApacheValidatorFactory}.
+ *
+ * @return Map<String, String>
+ */
+ public Map<String, String> getProperties() {
+ return properties;
+ }
+
+ /**
+ * Shortcut method to create a new Validator instance with factory's settings
+ *
+ * @return the new validator instance
+ */
+ @Override
+ public Validator getValidator() {
+ return usingContext().getValidator();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @return the validator factory's context
+ */
+ @Override
+ public ApacheFactoryContext usingContext() {
+ return new ApacheFactoryContext(this);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public synchronized ApacheValidatorFactory clone() {
+ try {
+ return (ApacheValidatorFactory) super.clone();
+ } catch (CloneNotSupportedException e) {
+ throw new InternalError(); // VM bug.
+ }
+ }
+
+ /**
+ * Set the {@link MessageInterpolator} used.
+ *
+ * @param messageResolver
+ */
+ public final void setMessageInterpolator(MessageInterpolator messageResolver) {
+ if (messageResolver != null) {
+ this.messageResolver = messageResolver;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public MessageInterpolator getMessageInterpolator() {
+ return messageResolver;
+ }
+
+ /**
+ * Set the {@link TraversableResolver} used.
+ *
+ * @param traversableResolver
+ */
+ public final void setTraversableResolver(TraversableResolver traversableResolver) {
+ if (traversableResolver != null) {
+ this.traversableResolver = traversableResolver;
+ }
+ }
+
+ public void setParameterNameProvider(final ParameterNameProvider parameterNameProvider) {
+ if (parameterNameProvider != null) {
+ this.parameterNameProvider = parameterNameProvider;
+ }
+ }
+
+ public void setClockProvider(final ClockProvider clockProvider) {
+ if (clockProvider != null) {
+ this.clockProvider = clockProvider;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public TraversableResolver getTraversableResolver() {
+ return traversableResolver;
+ }
+
+ /**
+ * Set the {@link ConstraintValidatorFactory} used.
+ *
+ * @param constraintValidatorFactory
+ */
+ public final void setConstraintValidatorFactory(ConstraintValidatorFactory constraintValidatorFactory) {
+ if (constraintValidatorFactory != null) {
+ this.constraintValidatorFactory = constraintValidatorFactory;
+ if (DefaultConstraintValidatorFactory.class.isInstance(constraintValidatorFactory)) {
+ toClose.add(Closeable.class.cast(constraintValidatorFactory));
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public ConstraintValidatorFactory getConstraintValidatorFactory() {
+ return constraintValidatorFactory;
+ }
+
+ @Override
+ public ParameterNameProvider getParameterNameProvider() {
+ return parameterNameProvider;
+ }
+
+ @Override
+ public ClockProvider getClockProvider() {
+ return clockProvider;
+ }
+
+ @Override
+ public void close() {
+ try {
+ for (final Closeable c : toClose) {
+ c.close();
+ }
+ toClose.clear();
+ } catch (final Exception e) {
+ // no-op
+ }
+ }
+
+ /**
+ * Return an object of the specified type to allow access to the provider-specific API. If the Bean Validation
+ * provider implementation does not support the specified class, the ValidationException is thrown.
+ *
+ * @param type
+ * the class of the object to be returned.
+ * @return an instance of the specified class
+ * @throws ValidationException
+ * if the provider does not support the call.
+ */
+ @Override
+ public <T> T unwrap(final Class<T> type) {
+ if (type.isInstance(this)) {
+ @SuppressWarnings("unchecked")
+ final T result = (T) this;
+ return result;
+ }
+
+ // FIXME 2011-03-27 jw:
+ // This code is unsecure.
+ // It should allow only a fixed set of classes.
+ // Can't fix this because don't know which classes this method should support.
+
+ if (!(type.isInterface() || Modifier.isAbstract(type.getModifiers()))) {
+ return newInstance(type);
+ }
+ try {
+ final Class<?> cls = Reflection.toClass(type.getName() + "Impl");
+ if (type.isAssignableFrom(cls)) {
+ @SuppressWarnings("unchecked")
+ T result = (T) newInstance(cls);
+ return result;
+ }
+ } catch (ClassNotFoundException e) {
+ // do nothing
+ }
+ throw new ValidationException("Type " + type + " not supported");
+ }
+
+ private <T> T newInstance(final Class<T> cls) {
+ try {
+ return Reflection.newInstance(cls);
+ } catch (final RuntimeException e) {
+ throw new ValidationException(e.getCause());
+ }
+ }
+
+ /**
+ * Get the constraint cache used.
+ *
+ * @return {@link ConstraintCached}
+ */
+ public ConstraintCached getConstraintsCache() {
+ return constraintsCache;
+ }
+
+ /**
+ * Get the {@link AnnotationsManager}.
+ *
+ * @return {@link AnnotationsManager}
+ */
+ public AnnotationsManager getAnnotationsManager() {
+ return annotationsManager;
+ }
+
+ /**
+ * Get the {@link DescriptorManager}.
+ *
+ * @return {@link DescriptorManager}
+ */
+ public DescriptorManager getDescriptorManager() {
+ return descriptorManager;
+ }
+
+ /**
+ * Get the {@link ValueExtractors}.
+ *
+ * @return {@link ValueExtractors}
+ */
+ public ValueExtractors getValueExtractors() {
+ return valueExtractors;
+ }
+
+ public MetadataBuilders getMetadataBuilders() {
+ return metadataBuilders;
+ }
+
+ public GroupsComputer getGroupsComputer() {
+ return groupsComputer;
+ }
+
+ private void loadAndVerifyUserCustomizations(ConfigurationState configuration) {
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ final BiConsumer<Class<?>, ForBean<?>> addBuilder = (t, b) -> {
+ getMetadataBuilders().registerCustomBuilder((Class) t, (MetadataBuilder.ForBean) b);
+ };
+ participantFactory.loadServices(MetadataSource.class)
+ .forEach(ms -> ms.process(configuration, getConstraintsCache()::add, addBuilder));
+ }
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/jsr/BootstrapConfigurationImpl.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/jsr/BootstrapConfigurationImpl.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/jsr/BootstrapConfigurationImpl.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/main/java/org/apache/bval/jsr/BootstrapConfigurationImpl.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,138 @@
+/*
+ * 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;
+
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.validation.BootstrapConfiguration;
+import javax.validation.executable.ExecutableType;
+
+import org.apache.bval.jsr.util.ExecutableTypes;
+
+public class BootstrapConfigurationImpl implements BootstrapConfiguration {
+ public static final BootstrapConfigurationImpl DEFAULT = new BootstrapConfigurationImpl(Collections.emptySet(),
+ true, EnumSet.of(ExecutableType.IMPLICIT), Collections.emptyMap(), Collections.emptySet());
+
+ private final Set<String> constraintMappingResourcePaths;
+ private final boolean executableValidationEnabled;
+ private final Set<ExecutableType> defaultValidatedExecutableTypes;
+ private final Map<String, String> properties;
+ private final Set<String> valueExtractorClassNames;
+
+ private String parameterNameProviderClassName;
+ private String traversableResolverClassName;
+ private String messageInterpolatorClassName;
+ private String constraintValidatorFactoryClassName;
+ private String defaultProviderClassName;
+ private String clockProviderClassName;
+
+ public BootstrapConfigurationImpl(final String defaultProviderClassName,
+ final String constraintValidatorFactoryClassName, final String messageInterpolatorClassName,
+ final String traversableResolverClassName, final String parameterNameProviderClassName,
+ final Set<String> constraintMappingResourcePaths, final boolean executableValidationEnabled,
+ final Set<ExecutableType> defaultValidatedExecutableTypes, final Map<String, String> properties,
+ final String clockProviderClassName, final Set<String> valueExtractorClassNames) {
+
+ this(Collections.unmodifiableSet(constraintMappingResourcePaths), executableValidationEnabled,
+ defaultValidatedExecutableTypes, Collections.unmodifiableMap(properties),
+ Collections.unmodifiableSet(valueExtractorClassNames));
+
+ this.parameterNameProviderClassName = parameterNameProviderClassName;
+ this.traversableResolverClassName = traversableResolverClassName;
+ this.messageInterpolatorClassName = messageInterpolatorClassName;
+ this.constraintValidatorFactoryClassName = constraintValidatorFactoryClassName;
+ this.defaultProviderClassName = defaultProviderClassName;
+ this.clockProviderClassName = clockProviderClassName;
+ }
+
+ private BootstrapConfigurationImpl(final Set<String> constraintMappingResourcePaths,
+ final boolean executableValidationEnabled, final Set<ExecutableType> defaultValidatedExecutableTypes,
+ final Map<String, String> properties, final Set<String> valueExtractorClassNames) {
+
+ this.constraintMappingResourcePaths = constraintMappingResourcePaths;
+ this.executableValidationEnabled = executableValidationEnabled;
+ this.defaultValidatedExecutableTypes = ExecutableTypes.interpret(defaultValidatedExecutableTypes);
+ this.properties = properties;
+ this.valueExtractorClassNames = valueExtractorClassNames;
+ }
+
+ @Override
+ public String getDefaultProviderClassName() {
+ return defaultProviderClassName;
+ }
+
+ @Override
+ public String getConstraintValidatorFactoryClassName() {
+ return constraintValidatorFactoryClassName;
+ }
+
+ @Override
+ public String getMessageInterpolatorClassName() {
+ return messageInterpolatorClassName;
+ }
+
+ @Override
+ public String getTraversableResolverClassName() {
+ return traversableResolverClassName;
+ }
+
+ @Override
+ public String getParameterNameProviderClassName() {
+ return parameterNameProviderClassName;
+ }
+
+ @Override
+ public Set<String> getConstraintMappingResourcePaths() {
+ return Collections.unmodifiableSet(constraintMappingResourcePaths);
+ }
+
+ @Override
+ public boolean isExecutableValidationEnabled() {
+ return executableValidationEnabled;
+ }
+
+ @Override
+ public Set<ExecutableType> getDefaultValidatedExecutableTypes() {
+ return Collections.unmodifiableSet(defaultValidatedExecutableTypes);
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return Collections.unmodifiableMap(properties);
+ }
+
+ /**
+ * @since 2.0
+ */
+ @Override
+ public String getClockProviderClassName() {
+ return clockProviderClassName;
+ }
+
+ /**
+ * @since 2.0
+ */
+ @Override
+ public Set<String> getValueExtractorClassNames() {
+ return Collections.unmodifiableSet(valueExtractorClassNames);
+ }
+}