incubator-bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r929893 - in /incubator/bval/trunk/bval-core/src: main/java/org/apache/bval/ main/java/org/apache/bval/model/ main/java/org/apache/bval/routines/ test/java/org/apache/bval/routines/
Date Thu, 01 Apr 2010 09:33:35 GMT
Author: simonetripodi
Date: Thu Apr  1 09:33:34 2010
New Revision: 929893

URL: http://svn.apache.org/viewvc?rev=929893&view=rev
Log:
fixed ValidationContext generics warnings, references have to be types with <VL extends
ValidationListener>
added generics types to collections

Modified:
    incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/BeanValidator.java
    incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/ValidationResults.java
    incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/model/Validation.java
    incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/model/ValidationListener.java
    incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/routines/EMailValidation.java
    incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/routines/NOPValidation.java
    incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/routines/StandardValidation.java
    incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/routines/StandardValidationTest.java

Modified: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/BeanValidator.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/BeanValidator.java?rev=929893&r1=929892&r2=929893&view=diff
==============================================================================
--- incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/BeanValidator.java (original)
+++ incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/BeanValidator.java Thu Apr
 1 09:33:34 2010
@@ -131,13 +131,13 @@ public class BeanValidator<T extends Val
     }
 
     /** @return true when validation should happen, false to skip it */
-    protected boolean determineMetaBean(Validate validate, Object parameter,
-                                        ValidationContext context) {
+    protected <VL extends ValidationListener> boolean determineMetaBean(Validate validate,
Object parameter,
+                                        ValidationContext<VL> context) {
         if (validate.value().length() == 0) {
             if (parameter == null) return false;
-            Class beanClass;
-            if (parameter instanceof Collection) {   // do not validate empty collection
-                Collection coll = ((Collection) parameter);
+            Class<?> beanClass;
+            if (parameter instanceof Collection<?>) {   // do not validate empty collection
+                Collection<?> coll = ((Collection<?>) parameter);
                 if (coll.isEmpty()) return false;
                 beanClass = coll.iterator().next().getClass(); // get first object
             } else if (parameter.getClass().isArray()) {
@@ -187,7 +187,7 @@ public class BeanValidator<T extends Val
      * validate a single property only. performs all validations
      * for this property.
      */
-    public void validateProperty(ValidationContext context) {
+    public <VL extends ValidationListener> void validateProperty(ValidationContext<VL>
context) {
         for (Validation validation : context.getMetaProperty().getValidations()) {
             validation.validate(context);
         }
@@ -203,11 +203,11 @@ public class BeanValidator<T extends Val
      *                <br>&nbsp;&nbsp;metaBean - the meta information for the
root object(s)
      * @return a new instance of validation results
      */
-    public void validateContext(ValidationContext context) {
+    public <VL extends ValidationListener> void validateContext(ValidationContext<VL>
context) {
         if (context.getBean() != null) {
-            if (!treatMapsLikeBeans && context.getBean() instanceof Map) {
+            if (!treatMapsLikeBeans && context.getBean() instanceof Map<?, ?>)
{
                 validateMapInContext(context);
-            } else if (context.getBean() instanceof Iterable) {
+            } else if (context.getBean() instanceof Iterable<?>) {
                 validateIteratableInContext(context);
             } else if (context.getBean() instanceof Object[]) {
                 validateArrayInContext(context);
@@ -217,7 +217,7 @@ public class BeanValidator<T extends Val
         }
     }
 
-    private void validateBeanInContext(ValidationContext context) {
+    private <VL extends ValidationListener> void validateBeanInContext(ValidationContext<VL>
context) {
         if (getDynamicMetaBean(context) != null) {
             context.setMetaBean(
                   getDynamicMetaBean(context).resolveMetaBean(context.getBean()));
@@ -225,7 +225,7 @@ public class BeanValidator<T extends Val
         validateBeanNet(context);
     }
 
-    private void validateArrayInContext(ValidationContext context) {
+    private <VL extends ValidationListener> void validateArrayInContext(ValidationContext<VL>
context) {
         int index = 0;
         DynamicMetaBean dyn = getDynamicMetaBean(context);
         for (Object each : ((Object[]) context.getBean())) {
@@ -240,14 +240,14 @@ public class BeanValidator<T extends Val
         }
     }
 
-    private DynamicMetaBean getDynamicMetaBean(ValidationContext context) {
+    private <VL extends ValidationListener> DynamicMetaBean getDynamicMetaBean(ValidationContext<VL>
context) {
         return context.getMetaBean() instanceof DynamicMetaBean ?
               (DynamicMetaBean) context.getMetaBean() : null;
     }
 
     /** Any object implementing java.lang.Iterable is supported */
-    private void validateIteratableInContext(ValidationContext context) {
-        Iterator it = ((Iterable) context.getBean()).iterator();
+    private <VL extends ValidationListener> void validateIteratableInContext(ValidationContext<VL>
context) {
+        Iterator<?> it = ((Iterable<?>) context.getBean()).iterator();
         int index = 0;
         // jsr303 spec: Each object provided by the iterator is validated.
         final DynamicMetaBean dyn = getDynamicMetaBean(context);
@@ -265,12 +265,12 @@ public class BeanValidator<T extends Val
         }
     }
 
-    private void validateMapInContext(ValidationContext context) {
+    private <VL extends ValidationListener> void validateMapInContext(ValidationContext<VL>
context) {
         // jsr303 spec: For Map, the value of each Map.Entry is validated (key is not validated).
-        Iterator<Map.Entry> it = ((Map) context.getBean()).entrySet().iterator();
+        Iterator<Map.Entry<Object, Object>> it = ((Map<Object, Object>)
context.getBean()).entrySet().iterator();
         final DynamicMetaBean dyn = getDynamicMetaBean(context);
         while (it.hasNext()) { // to Many
-            Map.Entry entry = it.next();
+            Map.Entry<Object, Object> entry = it.next();
             context.setCurrentKey(entry.getKey());
             if (entry.getValue() == null)
                 continue; // enhancement: throw IllegalArgumentException? (=> spec)
@@ -284,7 +284,7 @@ public class BeanValidator<T extends Val
     }
 
     /** internal validate a bean (=not a collection of beans) and its related beans */
-    protected void validateBeanNet(ValidationContext context) {
+    protected <VL extends ValidationListener> void validateBeanNet(ValidationContext<VL>
context) {
         if (context.collectValidated()) {
             validateBean(context);
             for (MetaProperty prop : context.getMetaBean().getProperties()) {
@@ -293,7 +293,7 @@ public class BeanValidator<T extends Val
         }
     }
 
-    private void validateRelatedBean(ValidationContext context, MetaProperty prop) {
+    private <VL extends ValidationListener> void validateRelatedBean(ValidationContext<VL>
context, MetaProperty prop) {
         AccessStrategy[] access = prop.getFeature(Features.Property.REF_CASCADE);
         if (access == null && prop.getMetaBean() != null) { // single property access
strategy
             // save old values from context
@@ -319,7 +319,7 @@ public class BeanValidator<T extends Val
     }
 
     /** validate a single bean only. no related beans will be validated */
-    public void validateBean(ValidationContext context) {
+    public <VL extends ValidationListener> void validateBean(ValidationContext<VL>
context) {
         /**
          * execute all property level validations
          */

Modified: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/ValidationResults.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/ValidationResults.java?rev=929893&r1=929892&r2=929893&view=diff
==============================================================================
--- incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/ValidationResults.java (original)
+++ incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/ValidationResults.java Thu
Apr  1 09:33:34 2010
@@ -27,6 +27,8 @@ import org.apache.bval.model.ValidationL
  * Description: Implements a contains to hold and transport validation results<br/>
  */
 public class ValidationResults implements ValidationListener, Serializable {
+    private static final long serialVersionUID = 1L;
+
     private Map<String, List<Error>> errorsByReason;
     private Map<Object, Map<String, List<Error>>> errorsByOwner;
 
@@ -38,7 +40,7 @@ public class ValidationResults implement
      *                       or custom reason of validation error
      * @param context        - context information (bean, propertyName, value, ...)
      */
-    public void addError(String reason, ValidationContext context) {
+    public <T extends ValidationListener> void addError(String reason, ValidationContext<T>
context) {
         Error error = createError(reason, context.getBean(), context.getPropertyName());
         addError(error, context);
     }
@@ -51,7 +53,7 @@ public class ValidationResults implement
       *                     the validation error
      * @param context     - null or the context to provide additional information
      */
-    public void addError(Error error, ValidationContext context) {
+    public <T extends ValidationListener> void addError(Error error, ValidationContext<T>
context) {
         if (errorsByReason == null) {
             initialize();
         }
@@ -80,8 +82,8 @@ public class ValidationResults implement
      * not on instance creation to save memory garbage.
      */
     protected void initialize() {
-        errorsByReason = new LinkedHashMap();
-        errorsByOwner = new LinkedHashMap();
+        errorsByReason = new LinkedHashMap<String, List<Error>>();
+        errorsByOwner = new LinkedHashMap<Object, Map<String, List<Error>>>();
     }
 
     protected void addToReasonBucket(Error error) {

Modified: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/model/Validation.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/model/Validation.java?rev=929893&r1=929892&r2=929893&view=diff
==============================================================================
--- incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/model/Validation.java (original)
+++ incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/model/Validation.java Thu
Apr  1 09:33:34 2010
@@ -26,5 +26,5 @@ public interface Validation {
      *
      * @param context - to access the property, value, constraints
      */
-    void validate(ValidationContext context);
+    <T extends ValidationListener> void validate(ValidationContext<T> context);
 }

Modified: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/model/ValidationListener.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/model/ValidationListener.java?rev=929893&r1=929892&r2=929893&view=diff
==============================================================================
--- incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/model/ValidationListener.java
(original)
+++ incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/model/ValidationListener.java
Thu Apr  1 09:33:34 2010
@@ -35,16 +35,18 @@ public interface ValidationListener {
      *                bean =         the object that contains the error (owner)
      *                propertyName = the Name of the attribute that caused the error
      */
-    void addError(String reason, ValidationContext context);
+    <T extends ValidationListener> void addError(String reason, ValidationContext<T>
context);
 
     /** Alternative method to add a fully initialized {@link ValidationListener.Error} object.
*/
-    void addError(Error error, ValidationContext context);
+    <T extends ValidationListener> void addError(Error error, ValidationContext<T>
context);
 
     /**
      * an object holding a single validation constraint violation
      * found during the validation process.
      */
     public class Error implements Serializable {
+        private static final long serialVersionUID = 1L;
+
         final String reason;
         final Object owner;
         final String propertyName;

Modified: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/routines/EMailValidation.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/routines/EMailValidation.java?rev=929893&r1=929892&r2=929893&view=diff
==============================================================================
--- incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/routines/EMailValidation.java
(original)
+++ incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/routines/EMailValidation.java
Thu Apr  1 09:33:34 2010
@@ -19,6 +19,7 @@ package org.apache.bval.routines;
 
 import org.apache.bval.model.Validation;
 import org.apache.bval.model.ValidationContext;
+import org.apache.bval.model.ValidationListener;
 
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -49,7 +50,7 @@ public class EMailValidation implements 
 
     private java.util.regex.Pattern pattern = DEFAULT_PATTERN;
 
-    public void validate(ValidationContext context) {
+    public <T extends ValidationListener> void validate(ValidationContext<T>
context) {
         if (context.getPropertyValue() == null) return;
         if (!isValid(context.getPropertyValue(), pattern)) {
             context.getListener().addError(Reasons.EMAIL_ADDRESS, context);

Modified: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/routines/NOPValidation.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/routines/NOPValidation.java?rev=929893&r1=929892&r2=929893&view=diff
==============================================================================
--- incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/routines/NOPValidation.java
(original)
+++ incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/routines/NOPValidation.java
Thu Apr  1 09:33:34 2010
@@ -18,6 +18,7 @@ package org.apache.bval.routines;
 
 import org.apache.bval.model.Validation;
 import org.apache.bval.model.ValidationContext;
+import org.apache.bval.model.ValidationListener;
 
 /**
  * Description: DO NOTHING VALIDATION (can be used to turn off standard validation)<br/>
@@ -26,7 +27,7 @@ import org.apache.bval.model.ValidationC
  */
 public class NOPValidation implements Validation {
 
-    public void validate(ValidationContext context) {
+    public <T extends ValidationListener> void validate(ValidationContext<T>
context) {
         // do nothing
     }
 }

Modified: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/routines/StandardValidation.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/routines/StandardValidation.java?rev=929893&r1=929892&r2=929893&view=diff
==============================================================================
--- incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/routines/StandardValidation.java
(original)
+++ incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/routines/StandardValidation.java
Thu Apr  1 09:33:34 2010
@@ -20,6 +20,7 @@ import org.apache.bval.model.Features;
 import org.apache.bval.model.MetaProperty;
 import org.apache.bval.model.Validation;
 import org.apache.bval.model.ValidationContext;
+import org.apache.bval.model.ValidationListener;
 import org.apache.bval.xml.XMLMetaValue;
 
 import java.util.Collection;
@@ -42,7 +43,7 @@ public class StandardValidation implemen
         return "standard";
     }
 
-    public void validate(ValidationContext context) {
+    public <T extends ValidationListener> void validate(ValidationContext<T>
context) {
         validateMandatory(context);
         validateMaxLength(context);
         validateMinLength(context);
@@ -52,7 +53,7 @@ public class StandardValidation implemen
         validateTimeLag(context);
     }
 
-    protected void validateTimeLag(ValidationContext context) {
+    protected <T extends ValidationListener> void validateTimeLag(ValidationContext<T>
context) {
         String lag = (String) context.getMetaProperty().getFeature(TIME_LAG);
         if (lag == null) return;
         if (context.getPropertyValue() == null) return;
@@ -73,7 +74,7 @@ public class StandardValidation implemen
 
     private static final String REG_EXP_PATTERN = "cachedRegExpPattern";
 
-    protected void validateRegExp(ValidationContext context) {
+    protected <T extends ValidationListener> void validateRegExp(ValidationContext<T>
context) {
         final MetaProperty meta = context.getMetaProperty();
         final String regExp = (String) meta.getFeature(REG_EXP);
         if (regExp == null) return;
@@ -95,7 +96,7 @@ public class StandardValidation implemen
         }
     }
 
-    protected void validateMinValue(ValidationContext context) {
+    protected <T extends ValidationListener> void validateMinValue(ValidationContext<T>
context) {
         Comparable minValue = (Comparable) context.getMetaProperty().getFeature(MIN_VALUE);
         if (minValue == null || context.getPropertyValue() == null) return;
         if (compare(context, minValue, context.getPropertyValue()) > 0) {
@@ -103,7 +104,7 @@ public class StandardValidation implemen
         }
     }
 
-    protected void validateMaxValue(ValidationContext context) {
+    protected <T extends ValidationListener> void validateMaxValue(ValidationContext<T>
context) {
         Comparable maxValue = (Comparable) context.getMetaProperty().getFeature(MAX_VALUE);
         if (maxValue == null || context.getPropertyValue() == null) return;
         if (compare(context, maxValue, context.getPropertyValue()) < 0) {
@@ -111,7 +112,7 @@ public class StandardValidation implemen
         }
     }
 
-    private int compare(ValidationContext context, Comparable constraintValue,
+    private <T extends ValidationListener> int compare(ValidationContext<T> context,
Comparable constraintValue,
                         Object currentValue) {
         int r;
         if (constraintValue.getClass().isAssignableFrom(currentValue.getClass())) {
@@ -126,7 +127,7 @@ public class StandardValidation implemen
         return r;
     }
 
-    protected void validateMaxLength(ValidationContext context) {
+    protected <T extends ValidationListener> void validateMaxLength(ValidationContext<T>
context) {
         Integer maxLength = (Integer) context.getMetaProperty()
               .getFeature(Features.Property.MAX_LENGTH);
         if (maxLength == null) return;
@@ -144,7 +145,7 @@ public class StandardValidation implemen
         }
     }
 
-    protected void validateMinLength(ValidationContext context) {
+    protected <T extends ValidationListener> void validateMinLength(ValidationContext<T>
context) {
         Integer maxLength = (Integer) context.getMetaProperty()
               .getFeature(Features.Property.MIN_LENGTH);
         if (maxLength == null) return;
@@ -162,7 +163,7 @@ public class StandardValidation implemen
         }
     }
 
-    protected void validateMandatory(ValidationContext context) {
+    protected <T extends ValidationListener> void validateMandatory(ValidationContext<T>
context) {
         if (context.getMetaProperty().isMandatory()) {
             if (context.getPropertyValue() == null) {
                 context.getListener().addError(MANDATORY, context);

Modified: incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/routines/StandardValidationTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/routines/StandardValidationTest.java?rev=929893&r1=929892&r2=929893&view=diff
==============================================================================
--- incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/routines/StandardValidationTest.java
(original)
+++ incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/routines/StandardValidationTest.java
Thu Apr  1 09:33:34 2010
@@ -39,7 +39,7 @@ import org.apache.bval.xml.XMLMetaValue;
  */
 public class StandardValidationTest extends TestCase implements ValidationListener {
     private StandardValidation validation;
-    private BeanValidationContext context;
+    private BeanValidationContext<StandardValidationTest> context;
     private List<String> reasons = new ArrayList<String>();
     private MetaProperty metaProperty;
     private String stringValue;
@@ -53,7 +53,7 @@ public class StandardValidationTest exte
     public void setUp() throws Exception {
         super.setUp();
         validation = new StandardValidation();
-        context = new BeanValidationContext(this);
+        context = new BeanValidationContext<StandardValidationTest>(this);
         metaProperty = new MetaProperty();
         context.setBean(this, null);
         context.setMetaProperty(metaProperty);
@@ -215,11 +215,11 @@ public class StandardValidationTest exte
         return new TestSuite(StandardValidationTest.class);
     }
 
-    public void addError(String reason, ValidationContext context) {
+    public <T extends ValidationListener> void addError(String reason, ValidationContext<T>
context) {
         reasons.add(reason);
     }
 
-    public void addError(ValidationListener.Error error, ValidationContext context) {
+    public <T extends ValidationListener> void addError(ValidationListener.Error error,
ValidationContext<T> context) {
         reasons.add(error.getReason());
     }
 



Mime
View raw message