You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bval.apache.org by rm...@apache.org on 2013/08/26 15:59:20 UTC

svn commit: r1517540 [2/15] - in /bval/branches/bval-11/bval-jsr: ./ src/ src/main/ src/main/appended-resources/ src/main/appended-resources/META-INF/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/bval/ src/main/j...

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/AssertTrueValidator.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/AssertTrueValidator.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/AssertTrueValidator.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/AssertTrueValidator.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,37 @@
+/*
+ * 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.AssertTrue;
+
+/**
+ * Description: assert that value is true<br/>
+ */
+public class AssertTrueValidator implements ConstraintValidator<AssertTrue, Boolean> {
+
+    public void initialize(AssertTrue annotation) {
+    }
+
+    public boolean isValid(Boolean value, ConstraintValidatorContext context) {
+        return value == null || value;
+    }
+
+}
\ No newline at end of file

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/DecimalMaxValidatorForNumber.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/DecimalMaxValidatorForNumber.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/DecimalMaxValidatorForNumber.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/DecimalMaxValidatorForNumber.java Mon Aug 26 13:59:15 2013
@@ -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.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;
+
+    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");
+        }
+    }
+
+    public boolean isValid(Number value, ConstraintValidatorContext context) {
+        if (value == null) {
+            return true;
+        } else if (value instanceof BigDecimal) {
+            return ((BigDecimal) value).compareTo(maxValue) != 1;
+        } else if (value instanceof BigInteger) {
+            return (new BigDecimal((BigInteger) value)).compareTo(maxValue) != 1;
+        } else {
+            return (new BigDecimal(value.doubleValue()).compareTo(maxValue)) != 1;
+        }
+    }           
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/DecimalMaxValidatorForString.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/DecimalMaxValidatorForString.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/DecimalMaxValidatorForString.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/DecimalMaxValidatorForString.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,54 @@
+/*
+ * 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;
+
+    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");
+        }
+    }
+
+    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;
+        }
+    }
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/DecimalMinValidatorForNumber.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/DecimalMinValidatorForNumber.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/DecimalMinValidatorForNumber.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/DecimalMinValidatorForNumber.java Mon Aug 26 13:59:15 2013
@@ -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.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;
+
+    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");
+        }
+    }
+
+    public boolean isValid(Number value, ConstraintValidatorContext context) {
+        if (value == null) {
+            return true;
+        } else if (value instanceof BigDecimal) {
+            return ((BigDecimal) value).compareTo(minValue) != -1;
+        } else if (value instanceof BigInteger) {
+            return (new BigDecimal((BigInteger) value)).compareTo(minValue) != -1;
+        } else {
+            return (new BigDecimal(value.doubleValue()).compareTo(minValue)) != -1;
+        }
+    }
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/DecimalMinValidatorForString.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/DecimalMinValidatorForString.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/DecimalMinValidatorForString.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/DecimalMinValidatorForString.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,56 @@
+/*
+ * 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;
+
+    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");
+        }
+    }
+
+    public boolean isValid(String value, ConstraintValidatorContext context) {
+        //null values are valid
+        if (value == null) {
+            return true;
+        }
+        try {
+            return new BigDecimal(value).compareTo(minValue) != -1;
+        } catch (NumberFormatException nfe) {
+            return false;
+        }
+    }
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/DigitsValidatorForNumber.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/DigitsValidatorForNumber.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/DigitsValidatorForNumber.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/DigitsValidatorForNumber.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,85 @@
+/*
+ * 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.Digits;
+import java.math.BigDecimal;
+
+/**
+ * Validates that the <code>Number</code> being validates matches the pattern
+ * defined in the constraint.
+ */
+public class DigitsValidatorForNumber implements ConstraintValidator<Digits, Number> {
+
+    private int integral;
+    private int fractional;
+
+    public int getIntegral() {
+        return integral;
+    }
+
+    public void setIntegral(int integral) {
+        this.integral = integral;
+    }
+
+    public int getFractional() {
+        return fractional;
+    }
+
+    public void setFractional(int fractional) {
+        this.fractional = fractional;
+    }
+
+    public void initialize(Digits annotation) {
+        this.integral = annotation.integer();
+        this.fractional = annotation.fraction();
+        if (integral < 0) {
+            throw new IllegalArgumentException(
+                  "The length of the integer part cannot be negative.");
+        }
+        if (fractional < 0) {
+            throw new IllegalArgumentException(
+                  "The length of the fraction part cannot be negative.");
+        }
+    }
+
+    public boolean isValid(Number num, ConstraintValidatorContext context) {
+        if (num == null) {
+            return true;
+        }
+
+        BigDecimal bigDecimal;
+        if (num instanceof BigDecimal) {
+            bigDecimal = (BigDecimal) num;
+        } else {
+            bigDecimal = new BigDecimal(num.toString());
+        }
+        bigDecimal = bigDecimal.stripTrailingZeros();
+
+        int intLength = bigDecimal.precision() - bigDecimal.scale();
+        if (integral >= intLength) {
+            int factionLength = bigDecimal.scale() < 0 ? 0 : bigDecimal.scale();
+            return fractional >= factionLength;
+        } else {
+            return false;
+        }
+    }
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/DigitsValidatorForString.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/DigitsValidatorForString.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/DigitsValidatorForString.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/DigitsValidatorForString.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,93 @@
+/*
+ * 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.Digits;
+import java.math.BigDecimal;
+
+/**
+ * Validates that the <code>String</code> being validated consists of digits,
+ * and matches the pattern defined in the constraint.
+ */
+public class DigitsValidatorForString implements ConstraintValidator<Digits, String> {
+
+    private int integral;
+    private int fractional;
+
+    public int getIntegral() {
+        return integral;
+    }
+
+    public void setIntegral(int integral) {
+        this.integral = integral;
+    }
+
+    public int getFractional() {
+        return fractional;
+    }
+
+    public void setFractional(int fractional) {
+        this.fractional = fractional;
+    }
+
+    public void initialize(Digits annotation) {
+        this.integral = annotation.integer();
+        this.fractional = annotation.fraction();
+        if (integral < 0) {
+            throw new IllegalArgumentException(
+                  "The length of the integer part cannot be negative.");
+        }
+        if (fractional < 0) {
+            throw new IllegalArgumentException(
+                  "The length of the fraction part cannot be negative.");
+        }
+    }
+
+    public boolean isValid(String str, ConstraintValidatorContext context) {
+        //null values are valid
+        if (str == null) {
+            return true;
+        }
+
+        BigDecimal bigDecimal = getBigDecimalValue(str);
+        if (bigDecimal == null) {
+            return false;
+        }
+
+        int intLength = bigDecimal.precision() - bigDecimal.scale();
+        if (integral >= intLength) {
+            int factionLength = bigDecimal.scale() < 0 ? 0 : bigDecimal.scale();
+            return fractional >= factionLength;
+        } else {
+            return false;
+        }
+    }
+
+    private BigDecimal getBigDecimalValue(String str) {
+        BigDecimal bd;
+        try {
+            bd = new BigDecimal(str);
+        } catch (NumberFormatException nfe) {
+            return null;
+        }
+        return bd;
+    }
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/Email.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/Email.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/Email.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/Email.java Mon Aug 26 13:59:15 2013
@@ -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.Constraint;
+import javax.validation.Payload;
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+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.RetentionPolicy.RUNTIME;
+
+/**
+ * <p>
+ * --
+ * TODO - 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.
+ * --
+ * </p>
+ * Description: annotation to validate an email address (by pattern)<br/>
+ */
+@Documented
+@Constraint(validatedBy = EmailValidator.class)
+@Target({METHOD, FIELD, ANNOTATION_TYPE, PARAMETER})
+@Retention(RUNTIME)
+public @interface Email {
+    Class<?>[] groups() default {};
+
+    String message() default "{org.apache.bval.constraints.Email.message}";
+
+    Class<? extends Payload>[] payload() default {};
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/EmailValidator.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/EmailValidator.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/EmailValidator.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/EmailValidator.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,39 @@
+/*
+ * 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 org.apache.bval.routines.EMailValidationUtils;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+
+/**
+ * Description: <br/>
+ */
+public class EmailValidator implements ConstraintValidator<Email, CharSequence> {
+
+    public boolean isValid(CharSequence value, ConstraintValidatorContext context) {
+        return EMailValidationUtils.isValid(value);
+    }
+
+    public void initialize(Email parameters) {
+        // do nothing (as long as Email has no properties)
+    }
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/FutureValidatorForCalendar.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/FutureValidatorForCalendar.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/FutureValidatorForCalendar.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/FutureValidatorForCalendar.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,47 @@
+/*
+ * 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.Future;
+import java.util.Calendar;
+
+/**
+ * Description: validate a date or calendar representing a date in the future <br/>
+ */
+public class FutureValidatorForCalendar implements ConstraintValidator<Future, Calendar> {
+
+    public void initialize(Future annotation) {
+    }
+
+    public boolean isValid(Calendar cal, ConstraintValidatorContext context) {
+        return cal == null || cal.after(now());
+    }
+
+
+    /**
+     * overwrite when you need a different algorithm for 'now'.
+     *
+     * @return current date/time
+     */
+    protected Calendar now() {
+        return Calendar.getInstance();
+    }
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/FutureValidatorForDate.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/FutureValidatorForDate.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/FutureValidatorForDate.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/FutureValidatorForDate.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,46 @@
+/*
+ * 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.Future;
+import java.util.Date;
+
+/**
+ * Description: validate a date or calendar representing a date in the future <br/>
+ */
+public class FutureValidatorForDate implements ConstraintValidator<Future, Date> {
+
+    public void initialize(Future annotation) {
+    }
+
+    public boolean isValid(Date date, ConstraintValidatorContext context) {
+        return date == null || date.after(now());
+    }
+
+    /**
+     * overwrite when you need a different algorithm for 'now'.
+     *
+     * @return current date/time
+     */
+    protected Date now() {
+        return new Date();
+    }
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/MaxValidatorForNumber.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/MaxValidatorForNumber.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/MaxValidatorForNumber.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/MaxValidatorForNumber.java Mon Aug 26 13:59:15 2013
@@ -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.Max;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+
+/**
+ * Check that the number being validated is less than or equal to the maximum
+ * value specified.
+ */
+public class MaxValidatorForNumber implements ConstraintValidator<Max, Number> {
+
+    private long max;
+
+    public void initialize(Max annotation) {
+        this.max = annotation.value();
+    }
+
+    public boolean isValid(Number value, ConstraintValidatorContext context) {
+        if (value == null) {
+            return true;
+        } else if (value instanceof BigDecimal) {
+            return ((BigDecimal) value).compareTo(BigDecimal.valueOf(max)) != 1;
+        } else if (value instanceof BigInteger) {
+            return ((BigInteger) value).compareTo(BigInteger.valueOf(max)) != 1;
+        } else {
+            return value.longValue() <= max;
+        }
+    }
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/MaxValidatorForString.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/MaxValidatorForString.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/MaxValidatorForString.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/MaxValidatorForString.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,48 @@
+/*
+ * 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.Max;
+import java.math.BigDecimal;
+
+/**
+ * Check that the String being validated represents a number, and has a value
+ * less than or equal to the maximum value specified.
+ */
+public class MaxValidatorForString implements ConstraintValidator<Max, String> {
+
+    private long max;
+
+    public void initialize(Max annotation) {
+        this.max = annotation.value();
+    }
+
+    public boolean isValid(String value, ConstraintValidatorContext context) {
+        if (value == null) {
+            return true;
+        }
+        try {
+            return new BigDecimal(value).compareTo(BigDecimal.valueOf(max)) != 1;
+        } catch (NumberFormatException nfe) {
+            return false;
+        }
+    }
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/MinValidatorForNumber.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/MinValidatorForNumber.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/MinValidatorForNumber.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/MinValidatorForNumber.java Mon Aug 26 13:59:15 2013
@@ -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;
+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;
+
+    public void initialize(Min annotation) {
+        this.minValue = annotation.value();
+    }
+
+    public boolean isValid(Number value, ConstraintValidatorContext context) {
+        if (value == null) {
+            return true;
+        } else if (value instanceof BigDecimal) {
+            return ((BigDecimal) value).compareTo(BigDecimal.valueOf(minValue)) != -1;
+        } else if (value instanceof BigInteger) {
+            return ((BigInteger) value).compareTo(BigInteger.valueOf(minValue)) != -1;
+        } else {
+            return value.longValue() >= minValue;
+        }
+
+    }
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/MinValidatorForString.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/MinValidatorForString.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/MinValidatorForString.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/MinValidatorForString.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,48 @@
+/*
+ * 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;
+
+    public void initialize(Min annotation) {
+        this.minValue = annotation.value();
+    }
+
+    public boolean isValid(String value, ConstraintValidatorContext context) {
+        if (value == null) {
+            return true;
+        }
+        try {
+            return new BigDecimal(value).compareTo(BigDecimal.valueOf(minValue)) != -1;
+        } catch (NumberFormatException nfe) {
+            return false;
+        }
+    }
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/NotEmpty.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/NotEmpty.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/NotEmpty.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/NotEmpty.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,51 @@
+/*
+ * 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.Constraint;
+import javax.validation.Payload;
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+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.RetentionPolicy.RUNTIME;
+
+/**
+ * <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 = {NotEmptyValidatorForCollection.class, NotEmptyValidatorForMap.class,
+            NotEmptyValidatorForString.class, NotEmptyValidator.class})
+@Target({METHOD, FIELD, ANNOTATION_TYPE, PARAMETER})
+@Retention(RUNTIME)
+public @interface NotEmpty {
+    Class<?>[] groups() default {};
+
+    String message() default "{org.apache.bval.constraints.NotEmpty.message}";
+
+    Class<? extends Payload>[] payload() default {};
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/NotEmptyValidator.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/NotEmptyValidator.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/NotEmptyValidator.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/NotEmptyValidator.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,56 @@
+/*
+ * 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 emptyness of an
+ * any object that has a public isEmpty():boolean or a valid toString() method
+ */
+public class NotEmptyValidator implements ConstraintValidator<NotEmpty, Object> {
+    public void initialize(NotEmpty constraintAnnotation) {
+        // do nothing
+    }
+
+    public boolean isValid(Object value, ConstraintValidatorContext context) {
+        if (value == null) return true;
+        if (value.getClass().isArray()) {
+            return Array.getLength(value) > 0;
+        } else {
+            try {
+                Method isEmptyMethod = value.getClass().getMethod("isEmpty");
+                if (isEmptyMethod != null) {
+                    return !((Boolean) isEmptyMethod.invoke(value)).booleanValue();
+                }
+            } catch (IllegalAccessException iae) {
+                // do nothing
+            } catch (NoSuchMethodException nsme) {
+                // do nothing
+            } catch (InvocationTargetException ite) {
+                // do nothing
+            }
+            return value.toString().length() > 0;
+        }
+    }
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/NotEmptyValidatorForCollection.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/NotEmptyValidatorForCollection.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/NotEmptyValidatorForCollection.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/NotEmptyValidatorForCollection.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,36 @@
+/*
+ * 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<NotEmpty, Collection<?>> {
+    public void initialize(NotEmpty constraintAnnotation) {
+        // do nothing
+    }
+
+    public boolean isValid(Collection<?> value, ConstraintValidatorContext context) {
+        return value == null || !value.isEmpty();
+    }
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/NotEmptyValidatorForMap.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/NotEmptyValidatorForMap.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/NotEmptyValidatorForMap.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/NotEmptyValidatorForMap.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,36 @@
+/*
+ * 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<NotEmpty, Map<?, ?>> {
+    public void initialize(NotEmpty constraintAnnotation) {
+        // do nothing
+    }
+
+    public boolean isValid(Map<?, ?> value, ConstraintValidatorContext context) {
+        return value == null || !value.isEmpty();
+    }
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/NotEmptyValidatorForString.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/NotEmptyValidatorForString.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/NotEmptyValidatorForString.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/NotEmptyValidatorForString.java Mon Aug 26 13:59:15 2013
@@ -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;
+
+/**
+ * Description: <br/>
+ */
+public class NotEmptyValidatorForString implements ConstraintValidator<NotEmpty, String> {
+    public void initialize(NotEmpty constraintAnnotation) {
+        // do nothing
+    }
+
+    public boolean isValid(String value, ConstraintValidatorContext context) {
+        return value == null || value.length() > 0;
+    }
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/NotNullValidator.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/NotNullValidator.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/NotNullValidator.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/NotNullValidator.java Mon Aug 26 13:59:15 2013
@@ -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.NotNull;
+
+/** valid when object is NOT null */
+public class NotNullValidator implements ConstraintValidator<NotNull, Object> {
+    public void initialize(NotNull constraintAnnotation) {
+        // do nothing
+    }
+
+    public boolean isValid(Object value, ConstraintValidatorContext context) {
+        return value != null;
+    }
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/NullValidator.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/NullValidator.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/NullValidator.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/NullValidator.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,37 @@
+/*
+ * 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> {
+
+    public void initialize(Null annotation) {
+        // do nothing
+    }
+
+    public boolean isValid(Object object, ConstraintValidatorContext context) {
+        return object == null;
+    }
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/PastValidatorForCalendar.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/PastValidatorForCalendar.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/PastValidatorForCalendar.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/PastValidatorForCalendar.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,47 @@
+/*
+ * 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.Past;
+import java.util.Calendar;
+
+/**
+ * Description: validate a date or calendar representing a date in the past<br/>
+ */
+public class PastValidatorForCalendar implements ConstraintValidator<Past, Calendar> {
+
+    public void initialize(Past annotation) {
+    }
+
+    public boolean isValid(Calendar cal, ConstraintValidatorContext context) {
+        return cal == null || cal.before(now());
+    }
+
+
+    /**
+     * overwrite when you need a different algorithm for 'now'.
+     *
+     * @return current date/time
+     */
+    protected Calendar now() {
+        return Calendar.getInstance();
+    }
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/PastValidatorForDate.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/PastValidatorForDate.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/PastValidatorForDate.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/PastValidatorForDate.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,46 @@
+/*
+ * 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.Past;
+import java.util.Date;
+
+/**
+ * Description: validate a date or calendar representing a date in the past<br/>
+ */
+public class PastValidatorForDate implements ConstraintValidator<Past, Date> {
+
+    public void initialize(Past annotation) {
+    }
+
+    public boolean isValid(Date date, ConstraintValidatorContext context) {
+        return date == null || date.before(now());
+    }
+
+    /**
+     * overwrite when you need a different algorithm for 'now'.
+     *
+     * @return current date/time
+     */
+    protected Date now() {
+        return new Date();
+    }
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/PatternValidator.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/PatternValidator.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/PatternValidator.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/PatternValidator.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,51 @@
+/*
+ * 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.Pattern;
+import java.util.regex.PatternSyntaxException;
+
+/**
+ * validator using a regular expression,
+ * based on the jsr Pattern constraint annotation.
+ */
+public class PatternValidator implements ConstraintValidator<Pattern, String> {
+    protected java.util.regex.Pattern pattern;
+
+    public void initialize(Pattern annotation) {
+        Pattern.Flag flags[] = annotation.flags();
+        int intFlag = 0;
+        for (Pattern.Flag flag : flags) {
+            intFlag = intFlag | flag.getValue();
+        }
+
+        try {
+            pattern = java.util.regex.Pattern.compile(annotation.regexp(), intFlag);
+        } catch (PatternSyntaxException e) {
+            throw new IllegalArgumentException("Invalid regular expression.", e);
+        }
+    }
+
+
+    public boolean isValid(String value, ConstraintValidatorContext context) {
+        return value == null || pattern.matcher(value).matches();
+    }
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidator.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidator.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidator.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidator.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,44 @@
+/*
+ * 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.ValidationException;
+import javax.validation.constraints.Size;
+
+/**
+ * Description: Abstract validator impl. for @Size annotation<br/>
+ */
+public abstract class SizeValidator {
+    protected int min;
+    protected int max;
+
+    /**
+     * 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");
+    }
+}
\ No newline at end of file

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfBoolean.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfBoolean.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfBoolean.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfBoolean.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,45 @@
+/*
+ * 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.Size;
+import java.lang.reflect.Array;
+
+public class SizeValidatorForArrayOfBoolean extends SizeValidator
+      implements ConstraintValidator<Size, boolean[]> {
+
+    /**
+     * Checks the number of entries in an array.
+     *
+     * @param array   The array to validate.
+     * @param context context in which the constraint is evaluated.
+     * @return Returns <code>true</code> if the array is <code>null</code> or the number of entries in
+     *         <code>array</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
+     *         <code>false</code> otherwise.
+     */
+    public boolean isValid(boolean[] array, ConstraintValidatorContext context) {
+        if (array == null) {
+            return true;
+        }
+        int length = Array.getLength(array);
+        return length >= min && length <= max;
+	}
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfByte.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfByte.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfByte.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfByte.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,45 @@
+/*
+ * 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.Size;
+import java.lang.reflect.Array;
+
+public class SizeValidatorForArrayOfByte extends SizeValidator
+      implements ConstraintValidator<Size, byte[]> {
+
+    /**
+     * Checks the number of entries in an array.
+     *
+     * @param array   The array to validate.
+     * @param context context in which the constraint is evaluated.
+     * @return Returns <code>true</code> if the array is <code>null</code> or the number of entries in
+     *         <code>array</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
+     *         <code>false</code> otherwise.
+     */
+    public boolean isValid(byte[] array, ConstraintValidatorContext context) {
+        if (array == null) {
+            return true;
+        }
+        int length = Array.getLength(array);
+        return length >= min && length <= max;
+	}
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfChar.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfChar.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfChar.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfChar.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,45 @@
+/*
+ * 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.Size;
+import java.lang.reflect.Array;
+
+public class SizeValidatorForArrayOfChar extends SizeValidator
+      implements ConstraintValidator<Size, char[]> {
+
+    /**
+     * Checks the number of entries in an array.
+     *
+     * @param array   The array to validate.
+     * @param context context in which the constraint is evaluated.
+     * @return Returns <code>true</code> if the array is <code>null</code> or the number of entries in
+     *         <code>array</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
+     *         <code>false</code> otherwise.
+     */
+    public boolean isValid(char[] array, ConstraintValidatorContext context) {
+        if (array == null) {
+            return true;
+        }
+        int length = Array.getLength(array);
+        return length >= min && length <= max;
+	}
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfDouble.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfDouble.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfDouble.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfDouble.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,45 @@
+/*
+ * 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.Size;
+import java.lang.reflect.Array;
+
+public class SizeValidatorForArrayOfDouble extends SizeValidator
+      implements ConstraintValidator<Size, double[]> {
+
+    /**
+     * Checks the number of entries in an array.
+     *
+     * @param array   The array to validate.
+     * @param context context in which the constraint is evaluated.
+     * @return Returns <code>true</code> if the array is <code>null</code> or the number of entries in
+     *         <code>array</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
+     *         <code>false</code> otherwise.
+     */
+    public boolean isValid(double[] array, ConstraintValidatorContext context) {
+        if (array == null) {
+            return true;
+        }
+        int length = Array.getLength(array);
+        return length >= min && length <= max;
+	}
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfFloat.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfFloat.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfFloat.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfFloat.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,45 @@
+/*
+ * 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.Size;
+import java.lang.reflect.Array;
+
+public class SizeValidatorForArrayOfFloat extends SizeValidator
+      implements ConstraintValidator<Size, float[]> {
+
+    /**
+     * Checks the number of entries in an array.
+     *
+     * @param array   The array to validate.
+     * @param context context in which the constraint is evaluated.
+     * @return Returns <code>true</code> if the array is <code>null</code> or the number of entries in
+     *         <code>array</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
+     *         <code>false</code> otherwise.
+     */
+    public boolean isValid(float[] array, ConstraintValidatorContext context) {
+        if (array == null) {
+            return true;
+        }
+        int length = Array.getLength(array);
+        return length >= min && length <= max;
+	}
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfInt.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfInt.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfInt.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfInt.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,45 @@
+/*
+ * 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.Size;
+import java.lang.reflect.Array;
+
+public class SizeValidatorForArrayOfInt extends SizeValidator
+      implements ConstraintValidator<Size, int[]> {
+
+    /**
+     * Checks the number of entries in an array.
+     *
+     * @param array   The array to validate.
+     * @param context context in which the constraint is evaluated.
+     * @return Returns <code>true</code> if the array is <code>null</code> or the number of entries in
+     *         <code>array</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
+     *         <code>false</code> otherwise.
+     */
+    public boolean isValid(int[] array, ConstraintValidatorContext context) {
+        if (array == null) {
+            return true;
+        }
+        int length = Array.getLength(array);
+        return length >= min && length <= max;
+	}
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfLong.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfLong.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfLong.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfLong.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,45 @@
+/*
+ * 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.Size;
+import java.lang.reflect.Array;
+
+public class SizeValidatorForArrayOfLong extends SizeValidator
+      implements ConstraintValidator<Size, long[]> {
+
+    /**
+     * Checks the number of entries in an array.
+     *
+     * @param array   The array to validate.
+     * @param context context in which the constraint is evaluated.
+     * @return Returns <code>true</code> if the array is <code>null</code> or the number of entries in
+     *         <code>array</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
+     *         <code>false</code> otherwise.
+     */
+    public boolean isValid(long[] array, ConstraintValidatorContext context) {
+        if (array == null) {
+            return true;
+        }
+        int length = Array.getLength(array);
+        return length >= min && length <= max;
+	}
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfObject.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfObject.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfObject.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfObject.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,46 @@
+/*
+ * 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.Size;
+import java.lang.reflect.Array;
+
+/** Check that the length of an array is between <i>min</i> and <i>max</i> */
+public class SizeValidatorForArrayOfObject extends SizeValidator
+      implements ConstraintValidator<Size, Object[]> {
+    /**
+     * Checks the number of entries in an array.
+     *
+     * @param array   The array to validate.
+     * @param context context in which the constraint is evaluated.
+     * @return Returns <code>true</code> if the array is <code>null</code> or the number of entries in
+     *         <code>array</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
+     *         <code>false</code> otherwise.
+     */
+    public boolean isValid(Object[] array, ConstraintValidatorContext context) {
+        if (array == null) {
+            return true;
+        }
+        int length = Array.getLength(array);
+        return length >= min && length <= max;
+    }
+
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfShort.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfShort.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfShort.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfShort.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,45 @@
+/*
+ * 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.Size;
+import java.lang.reflect.Array;
+
+public class SizeValidatorForArrayOfShort extends SizeValidator
+      implements ConstraintValidator<Size, short[]> {
+
+    /**
+     * Checks the number of entries in an array.
+     *
+     * @param array   The array to validate.
+     * @param context context in which the constraint is evaluated.
+     * @return Returns <code>true</code> if the array is <code>null</code> or the number of entries in
+     *         <code>array</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
+     *         <code>false</code> otherwise.
+     */
+    public boolean isValid(short[] array, ConstraintValidatorContext context) {
+        if (array == null) {
+            return true;
+        }
+        int length = Array.getLength(array);
+        return length >= min && length <= max;
+	}
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForCharSequence.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForCharSequence.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForCharSequence.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForCharSequence.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,44 @@
+/*
+ * 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.Size;
+
+/** Check that a string's length is between min and max. */
+public class SizeValidatorForCharSequence extends SizeValidator
+      implements ConstraintValidator<Size, CharSequence> {
+    /**
+     * Checks the length of the specified string.
+     *
+     * @param s       The string to validate.
+     * @param context context in which the constraint is evaluated.
+     * @return Returns <code>true</code> if the string is <code>null</code> or the length of <code>s</code> between the specified
+     *         <code>min</code> and <code>max</code> values (inclusive), <code>false</code> otherwise.
+     */
+    public boolean isValid(CharSequence s, ConstraintValidatorContext context) {
+        if (s == null) {
+            return true;
+        }
+        int length = s.length();
+        return length >= min && length <= max;
+    }
+
+}