You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@turbine.apache.org by tv...@apache.org on 2011/11/11 01:05:30 UTC

svn commit: r1200653 [2/2] - in /turbine/fulcrum/trunk/intake: ./ src/changes/ src/java/org/apache/fulcrum/intake/ src/java/org/apache/fulcrum/intake/model/ src/java/org/apache/fulcrum/intake/transform/ src/java/org/apache/fulcrum/intake/validator/ src...

Modified: turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/DefaultValidator.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/DefaultValidator.java?rev=1200653&r1=1200652&r2=1200653&view=diff
==============================================================================
--- turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/DefaultValidator.java (original)
+++ turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/DefaultValidator.java Fri Nov 11 00:05:28 2011
@@ -46,10 +46,10 @@ import org.apache.fulcrum.intake.model.F
  * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
  * @version $Id$
  */
-abstract public class DefaultValidator
-        implements Validator, InitableByConstraintMap
+abstract public class DefaultValidator<T>
+        implements Validator<T>, InitableByConstraintMap
 {
-    /** A boolean value to signify if the field is definately required or not */
+    /** A boolean value to signify if the field is definitely required or not */
     protected boolean required = false;
 
     /** The message to show if field fails required test */
@@ -81,9 +81,10 @@ abstract public class DefaultValidator
      * @exception InvalidMaskException An invalid mask was specified for one of the rules
 
     */
-    public DefaultValidator(Map paramMap)
+    public DefaultValidator(Map<String, Constraint> paramMap)
             throws InvalidMaskException
     {
+        this();
         init(paramMap);
     }
 
@@ -103,10 +104,10 @@ abstract public class DefaultValidator
      * containing constraints on the input.
      * @exception InvalidMaskException An invalid mask was specified for one of the rules
      */
-    public void init(Map paramMap)
+    public void init(Map<String, ? extends Constraint> paramMap)
             throws InvalidMaskException
     {
-        Constraint constraint = (Constraint) paramMap.get(REQUIRED_RULE_NAME);
+        Constraint constraint = paramMap.get(REQUIRED_RULE_NAME);
         if (constraint != null)
         {
             String param = constraint.getValue();
@@ -114,7 +115,7 @@ abstract public class DefaultValidator
             requiredMessage = constraint.getMessage();
         }
 
-        constraint = (Constraint) paramMap.get(MIN_LENGTH_RULE_NAME);
+        constraint = paramMap.get(MIN_LENGTH_RULE_NAME);
         if (constraint != null)
         {
             String param = constraint.getValue();
@@ -122,7 +123,7 @@ abstract public class DefaultValidator
             minLengthMessage = constraint.getMessage();
         }
 
-        constraint = (Constraint) paramMap.get(MAX_LENGTH_RULE_NAME);
+        constraint = paramMap.get(MAX_LENGTH_RULE_NAME);
         if (constraint != null)
         {
             String param = constraint.getValue();
@@ -138,7 +139,7 @@ abstract public class DefaultValidator
      * @param field a <code>Field</code> to be tested
      * @return true if valid, false otherwise
      */
-    public boolean isValid(Field field)
+    public boolean isValid(Field<T> field)
     {
         boolean valid = false;
         try
@@ -161,7 +162,7 @@ abstract public class DefaultValidator
      * @exception ValidationException containing an error message if the
      * testValue did not pass the validation tests.
      */
-    public void assertValidity(Field field)
+    public void assertValidity(Field<T> field)
             throws ValidationException
     {
     	if (field.isMultiValued())

Modified: turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/DoubleValidator.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/DoubleValidator.java?rev=1200653&r1=1200652&r2=1200653&view=diff
==============================================================================
--- turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/DoubleValidator.java (original)
+++ turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/DoubleValidator.java Fri Nov 11 00:05:28 2011
@@ -24,9 +24,6 @@ import java.text.ParseException;
 import java.util.Locale;
 import java.util.Map;
 
-import org.apache.commons.lang.StringUtils;
-import org.apache.fulcrum.intake.model.Field;
-
 /**
  * Validates Doubles with the following constraints in addition to those
  * listed in NumberValidator and DefaultValidator.
@@ -48,25 +45,18 @@ import org.apache.fulcrum.intake.model.F
  * @version $Id$
  */
 public class DoubleValidator
-        extends NumberValidator
+        extends NumberValidator<Double>
 {
-    /* Init the minValue to that for a Double */
-    private double minValue = Double.NEGATIVE_INFINITY;
-
-    /* Init the maxValue to that for a Double */
-    private double maxValue = Double.POSITIVE_INFINITY;
-
     /**
      * Constructor to use when initialising Object
      *
      * @param paramMap
      * @throws InvalidMaskException
      */
-    public DoubleValidator(Map paramMap)
+    public DoubleValidator(Map<String, Constraint> paramMap)
             throws InvalidMaskException
     {
-        this();
-        init(paramMap);
+        super(paramMap);
     }
 
     /**
@@ -74,151 +64,18 @@ public class DoubleValidator
      */
     public DoubleValidator()
     {
+        super();
         invalidNumberMessage = "Entry was not a valid Double";
     }
 
     /**
-     * Method to initialise Object
-     *
-     * @param paramMap
-     * @throws InvalidMaskException
+     * @see org.apache.fulcrum.intake.validator.NumberValidator#parseNumber(java.lang.String, java.util.Locale)
      */
-    public void init(Map paramMap)
-            throws InvalidMaskException
+    @Override
+    protected Double parseNumber(String stringValue, Locale locale) throws ParseException
     {
-        super.init(paramMap);
-
-        Constraint constraint = (Constraint) paramMap.get(MIN_VALUE_RULE_NAME);
-        if (constraint != null)
-        {
-            String param = constraint.getValue();
-            minValue = Double.parseDouble(param);
-            minValueMessage = constraint.getMessage();
-        }
-
-        constraint = (Constraint) paramMap.get(MAX_VALUE_RULE_NAME);
-        if (constraint != null)
-        {
-            String param = constraint.getValue();
-            maxValue = Double.parseDouble(param);
-            maxValueMessage = constraint.getMessage();
-        }
-    }
-
-    /**
-     * Determine whether a field meets the criteria specified
-     * in the constraints defined for this validator
-     *
-     * @param field a <code>Field</code> to be tested
-     * @exception ValidationException containing an error message if the
-     * testValue did not pass the validation tests.
-     */
-    public void assertValidity(Field field)
-            throws ValidationException
-    {
-        Locale locale = field.getLocale();
-
-        if (field.isMultiValued())
-        {
-            String[] stringValues = (String[])field.getTestValue();
-
-            for (int i = 0; i < stringValues.length; i++)
-            {
-                assertValidity(stringValues[i], locale);
-            }
-        }
-        else
-        {
-            assertValidity((String)field.getTestValue(), locale);
-        }
-    }
-
-    /**
-     * Determine whether a testValue meets the criteria specified
-     * in the constraints defined for this validator
-     *
-     * @param testValue a <code>String</code> to be tested
-     * @param locale the Locale of the associated field
-     * @exception ValidationException containing an error message if the
-     * testValue did not pass the validation tests.
-     */
-    public void assertValidity(String testValue, Locale locale)
-            throws ValidationException
-    {
-        super.assertValidity(testValue);
-
-        double d = 0.0D;
-
-        if (required || StringUtils.isNotEmpty(testValue))
-        {
-            NumberFormat nf = NumberFormat.getInstance(locale);
-
-            try
-            {
-                d = nf.parse(testValue).doubleValue();
-            }
-            catch (ParseException e)
-            {
-                errorMessage = invalidNumberMessage;
-                throw new ValidationException(invalidNumberMessage);
-            }
-
-            if (d < minValue)
-            {
-                errorMessage = minValueMessage;
-                throw new ValidationException(minValueMessage);
-            }
+        NumberFormat nf = NumberFormat.getInstance(locale);
 
-            if (d > maxValue)
-            {
-                errorMessage = maxValueMessage;
-                throw new ValidationException(maxValueMessage);
-            }
-        }
-    }
-
-
-    // ************************************************************
-    // **                Bean accessor methods                   **
-    // ************************************************************
-
-    /**
-     * Get the value of minValue.
-     *
-     * @return value of minValue.
-     */
-    public double getMinValue()
-    {
-        return minValue;
-    }
-
-    /**
-     * Set the value of minValue.
-     *
-     * @param value  Value to assign to minValue.
-     */
-    public void setMinValue(double value)
-    {
-        this.minValue = value;
-    }
-
-    /**
-     * Get the value of maxValue.
-     *
-     * @return value of maxValue.
-     */
-    public double getMaxValue()
-    {
-        return maxValue;
-    }
-
-    /**
-     * Set the value of maxValue.
-     *
-     * @param value  Value to assign to maxValue.
-     */
-    public void setMaxValue(double value)
-    {
-        this.maxValue = value;
+        return Double.valueOf(nf.parse(stringValue).doubleValue());
     }
 }

Modified: turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/FieldReference.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/FieldReference.java?rev=1200653&r1=1200652&r2=1200653&view=diff
==============================================================================
--- turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/FieldReference.java (original)
+++ turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/FieldReference.java Fri Nov 11 00:05:28 2011
@@ -19,7 +19,6 @@ package org.apache.fulcrum.intake.valida
  * under the License.
  */
 
-import java.util.Iterator;
 import java.util.List;
 
 import org.apache.commons.logging.Log;
@@ -31,7 +30,7 @@ import org.apache.fulcrum.intake.model.G
 /**
  * Helper Class to manage relations between fields. The following
  * comparisons are supported:
- * 
+ *
  * <table>
  * <tr>
  *   <th>Name</th><th>Valid Values</th><th>Default Value</th>
@@ -65,7 +64,7 @@ public class FieldReference
 {
     /** a local logger */
     protected static final Log log = LogFactory.getLog(FieldReference.class);
-    
+
     /** Rule name for "&lt;" comparison */
     public static final String RANGE_LT = "less-than";
 
@@ -92,13 +91,13 @@ public class FieldReference
 
     /** Numeric comparison */
     private int compare = 0;
-    
+
     /** Name of referenced field */
     private String fieldName = null;
 
     /** Error message */
     private String message = null;
-    
+
     /**
      *  Constructor
      */
@@ -154,17 +153,17 @@ public class FieldReference
     {
         this.message = message;
     }
-    
+
     /**
      * Map the comparison strings to their numeric counterparts
-     * 
+     *
      * @param key the string representation of a comparison operator
      * @return the numeric representation of the given comparison operator
      */
     public static int getCompareType(String key)
     {
         int compareType = 0;
-        
+
         if (key.equals(RANGE_LT))
         {
             compareType = COMPARE_LT;
@@ -181,33 +180,33 @@ public class FieldReference
         {
             compareType = COMPARE_GTE;
         }
-        
+
         return compareType;
     }
-    
+
     /**
      * Check the parsed value against the referenced fields
-     * 
+     *
      * @param fieldReferences List of field references to check
      * @param compareCallback Callback to the actual compare operation
      * @param value the parsed value of the related field
      * @param group the group the related field belongs to
-     * 
+     *
      * @throws ValidationException
      */
-    public static void checkReferences(List fieldReferences, CompareCallback compareCallback, 
-            Object value, Group group)
+    public static <T> void checkReferences(List<FieldReference> fieldReferences, CompareCallback<T> compareCallback,
+            T value, Group group)
         throws ValidationException
     {
-        for (Iterator i = fieldReferences.iterator(); i.hasNext();)
+        for (FieldReference ref : fieldReferences)
         {
-            FieldReference ref = (FieldReference)i.next();
             boolean comp_true = true;
 
             try
             {
-                Field refField = group.get(ref.getFieldName());
-                
+                @SuppressWarnings("unchecked")
+                Field<T> refField = (Field<T>) group.get(ref.getFieldName());
+
                 if (refField.isSet())
                 {
                     /*
@@ -219,20 +218,12 @@ public class FieldReference
                     {
                         refField.validate();
                     }
-                    
+
                     if (refField.isValid())
                     {
-                        try
-                        {
-                            comp_true = compareCallback.compareValues(ref.getCompare(), 
-                                    value, 
-                                    refField.getValue());
-                        }
-                        catch (ClassCastException e)
-                        {
-                            throw new IntakeException("Type mismatch comparing " +
-                                    value + " with " + refField.getValue(), e);
-                        }
+                        comp_true = compareCallback.compareValues(ref.getCompare(),
+                                value,
+                                refField.getValue());
                     }
                 }
             }

Modified: turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/FileValidator.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/FileValidator.java?rev=1200653&r1=1200652&r2=1200653&view=diff
==============================================================================
--- turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/FileValidator.java (original)
+++ turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/FileValidator.java Fri Nov 11 00:05:28 2011
@@ -22,15 +22,12 @@ package org.apache.fulcrum.intake.valida
 import java.util.Map;
 
 import org.apache.commons.fileupload.FileItem;
-
 import org.apache.fulcrum.intake.IntakeException;
 
 /**
  * A validator that will compare a FileItem testValue against the following
  * constraints in addition to those listed in DefaultValidator.
  *
- *
- *
  * This validator can serve as the base class for more specific validators
  *
  * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
@@ -39,7 +36,7 @@ import org.apache.fulcrum.intake.IntakeE
  * @version $Id$
  */
 public class FileValidator
-        extends DefaultValidator
+        extends DefaultValidator<FileItem>
 {
 
     /**
@@ -50,10 +47,10 @@ public class FileValidator
      * containing constraints on the input.
      * @exception InvalidMaskException an invalid mask was specified
      */
-    public FileValidator(Map paramMap)
+    public FileValidator(Map<String, Constraint> paramMap)
             throws IntakeException
     {
-        init(paramMap);
+        super(paramMap);
     }
 
     /**
@@ -61,6 +58,7 @@ public class FileValidator
      */
     public FileValidator()
     {
+        super();
     }
 
     /**

Modified: turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/FloatValidator.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/FloatValidator.java?rev=1200653&r1=1200652&r2=1200653&view=diff
==============================================================================
--- turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/FloatValidator.java (original)
+++ turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/FloatValidator.java Fri Nov 11 00:05:28 2011
@@ -24,9 +24,6 @@ import java.text.ParseException;
 import java.util.Locale;
 import java.util.Map;
 
-import org.apache.commons.lang.StringUtils;
-import org.apache.fulcrum.intake.model.Field;
-
 /**
  * Validates Floats with the following constraints in addition to those
  * listed in NumberValidator and DefaultValidator.
@@ -48,25 +45,18 @@ import org.apache.fulcrum.intake.model.F
  * @version $Id$
  */
 public class FloatValidator
-        extends NumberValidator
+        extends NumberValidator<Float>
 {
-    /* Init the minValue to that for a Float */
-    private float minValue = Float.NEGATIVE_INFINITY;
-
-    /* Init the maxValue to that for a Float */
-    private float maxValue = Float.POSITIVE_INFINITY;
-
     /**
      * Constructor to use when initialising Object
      *
      * @param paramMap
      * @throws InvalidMaskException
      */
-    public FloatValidator(Map paramMap)
+    public FloatValidator(Map<String, Constraint> paramMap)
             throws InvalidMaskException
     {
-        this();
-        init(paramMap);
+        super(paramMap);
     }
 
     /**
@@ -74,149 +64,18 @@ public class FloatValidator
      */
     public FloatValidator()
     {
+        super();
         invalidNumberMessage = "Entry was not a valid Float";
     }
 
     /**
-     * Method to initialise Object
-     *
-     * @param paramMap
-     * @throws InvalidMaskException
-     */
-    public void init(Map paramMap)
-            throws InvalidMaskException
-    {
-        super.init(paramMap);
-
-        Constraint constraint = (Constraint) paramMap.get(MIN_VALUE_RULE_NAME);
-        if (constraint != null)
-        {
-            String param = constraint.getValue();
-            minValue = Float.parseFloat(param);
-            minValueMessage = constraint.getMessage();
-        }
-
-        constraint = (Constraint) paramMap.get(MAX_VALUE_RULE_NAME);
-        if (constraint != null)
-        {
-            String param = constraint.getValue();
-            maxValue = Float.parseFloat(param);
-            maxValueMessage = constraint.getMessage();
-        }
-    }
-
-    /**
-     * Determine whether a field meets the criteria specified
-     * in the constraints defined for this validator
-     *
-     * @param field a <code>Field</code> to be tested
-     * @exception ValidationException containing an error message if the
-     * testValue did not pass the validation tests.
+     * @see org.apache.fulcrum.intake.validator.NumberValidator#parseNumber(java.lang.String, java.util.Locale)
      */
-    public void assertValidity(Field field)
-            throws ValidationException
+    @Override
+    protected Float parseNumber(String stringValue, Locale locale) throws ParseException
     {
-        Locale locale = field.getLocale();
+        NumberFormat nf = NumberFormat.getInstance(locale);
 
-        if (field.isMultiValued())
-        {
-            String[] stringValues = (String[])field.getTestValue();
-
-            for (int i = 0; i < stringValues.length; i++)
-            {
-                assertValidity(stringValues[i], locale);
-            }
-        }
-        else
-        {
-            assertValidity((String)field.getTestValue(), locale);
-        }
-    }
-
-    /**
-     * Determine whether a testValue meets the criteria specified
-     * in the constraints defined for this validator
-     *
-     * @param testValue a <code>String</code> to be tested
-     * @param locale the Locale of the associated field
-     * @exception ValidationException containing an error message if the
-     * testValue did not pass the validation tests.
-     */
-    public void assertValidity(String testValue, Locale locale)
-            throws ValidationException
-    {
-        super.assertValidity(testValue);
-
-        if (required || StringUtils.isNotEmpty(testValue))
-        {
-            float f = 0.0f;
-            NumberFormat nf = NumberFormat.getInstance(locale);
-
-            try
-            {
-                f = nf.parse(testValue).floatValue();
-            }
-            catch (ParseException e)
-            {
-                errorMessage = invalidNumberMessage;
-                throw new ValidationException(invalidNumberMessage);
-            }
-
-            if (f < minValue)
-            {
-                errorMessage = minValueMessage;
-                throw new ValidationException(minValueMessage);
-            }
-            if (f > maxValue)
-            {
-                errorMessage = maxValueMessage;
-                throw new ValidationException(maxValueMessage);
-            }
-        }
-    }
-
-
-    // ************************************************************
-    // **                Bean accessor methods                   **
-    // ************************************************************
-
-    /**
-     * Get the value of minValue.
-     *
-     * @return value of minValue.
-     */
-    public float getMinValue()
-    {
-        return minValue;
-    }
-
-    /**
-     * Set the value of minValue.
-     *
-     * @param minValue  Value to assign to minValue.
-     */
-    public void setMinValue(float minValue)
-    {
-        this.minValue = minValue;
-    }
-
-    /**
-     * Get the value of maxValue.
-     *
-     * @return value of maxValue.
-     */
-    public float getMaxValue()
-    {
-        return maxValue;
-    }
-
-    /**
-     * Set the value of maxValue.
-     *
-     * @param maxValue  Value to assign to maxValue.
-     */
-    public void setMaxValue(float maxValue)
-    {
-        this.maxValue = maxValue;
+        return Float.valueOf(nf.parse(stringValue).floatValue());
     }
 }

Modified: turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/InitableByConstraintMap.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/InitableByConstraintMap.java?rev=1200653&r1=1200652&r2=1200653&view=diff
==============================================================================
--- turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/InitableByConstraintMap.java (original)
+++ turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/InitableByConstraintMap.java Fri Nov 11 00:05:28 2011
@@ -38,6 +38,6 @@ public interface InitableByConstraintMap
      * containing rules and error messages.
      * @exception InvalidMaskException one of the mask rules is invalid
      */
-    void init(Map inputParameters)
+    void init(Map<String, ? extends Constraint> inputParameters)
             throws InvalidMaskException;
 }

Modified: turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/IntegerRangeValidator.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/IntegerRangeValidator.java?rev=1200653&r1=1200652&r2=1200653&view=diff
==============================================================================
--- turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/IntegerRangeValidator.java (original)
+++ turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/IntegerRangeValidator.java Fri Nov 11 00:05:28 2011
@@ -20,7 +20,6 @@ package org.apache.fulcrum.intake.valida
  */
 
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
@@ -65,16 +64,15 @@ public class IntegerRangeValidator
         extends IntegerValidator
 {
     /** List of FieldReferences for multiple comparisons */
-    List fieldReferences; 
+    List<FieldReference> fieldReferences;
 
     /** Callback for the actual compare operation */
-    CompareCallback compareCallback; 
+    CompareCallback<Integer> compareCallback;
 
-    public IntegerRangeValidator(final Map paramMap)
+    public IntegerRangeValidator(Map<String, Constraint> paramMap)
             throws IntakeException
     {
-        this();
-        init(paramMap);
+        super(paramMap);
     }
 
     /**
@@ -91,63 +89,58 @@ public class IntegerRangeValidator
      * @param paramMap
      * @throws InvalidMaskException
      */
-    public void init(final Map paramMap)
+    public void init(Map<String, ? extends Constraint> paramMap)
             throws InvalidMaskException
     {
         super.init(paramMap);
-        
-        compareCallback = new CompareCallback()
+
+        compareCallback = new CompareCallback<Integer>()
             {
                 /**
                  * Compare the given values using the compare operation provided
-                 * 
+                 *
                  * @param compare type of compare operation
                  * @param thisValue value of this field
                  * @param refValue value of the reference field
-                 * 
+                 *
                  * @return the result of the comparison
                  */
-                public boolean compareValues(int compare, Object thisValue, Object refValue)
-                    throws ClassCastException
+                public boolean compareValues(int compare, Integer thisValue, Integer refValue)
                 {
                     boolean result = true;
-                    
-                    Integer thisInt = (Integer)thisValue;
-                    Integer otherInt = (Integer)refValue;
-                    
+
                     switch (compare)
                     {
                         case FieldReference.COMPARE_LT:
-                            result = thisInt.compareTo(otherInt) < 0;
+                            result = thisValue.compareTo(refValue) < 0;
                             break;
-                            
+
                         case FieldReference.COMPARE_LTE:
-                            result = thisInt.compareTo(otherInt) <= 0;
+                            result = thisValue.compareTo(refValue) <= 0;
                             break;
-                            
+
                         case FieldReference.COMPARE_GT:
-                            result = thisInt.compareTo(otherInt) > 0;
+                            result = thisValue.compareTo(refValue) > 0;
                             break;
-                            
+
                         case FieldReference.COMPARE_GTE:
-                            result = thisInt.compareTo(otherInt) >= 0;
+                            result = thisValue.compareTo(refValue) >= 0;
                             break;
                     }
-                    
+
                     return result;
                 }
             };
-        
-        fieldReferences = new ArrayList(10);
 
-        for (Iterator i = paramMap.entrySet().iterator(); i.hasNext();)
+        fieldReferences = new ArrayList<FieldReference>(10);
+
+        for (Map.Entry<String, ? extends Constraint> entry : paramMap.entrySet())
         {
-            Map.Entry entry = (Map.Entry)i.next();
-            String key = (String)entry.getKey();
-            Constraint constraint = (Constraint)entry.getValue();
+            String key = entry.getKey();
+            Constraint constraint = entry.getValue();
 
             int compare = FieldReference.getCompareType(key);
-            
+
             if (compare != 0)
             {
                 // found matching constraint
@@ -155,17 +148,17 @@ public class IntegerRangeValidator
                 fieldref.setCompare(compare);
                 fieldref.setFieldName(constraint.getValue());
                 fieldref.setMessage(constraint.getMessage());
-                
+
                 fieldReferences.add(fieldref);
             }
         }
-        
+
         if (fieldReferences.isEmpty())
         {
             log.warn("No reference field rules have been found.");
         }
     }
-    
+
     /**
      * Determine whether a testValue meets the criteria specified
      * in the constraints defined for this validator
@@ -174,11 +167,11 @@ public class IntegerRangeValidator
      * @exception ValidationException containing an error message if the
      * testValue did not pass the validation tests.
      */
-    public void assertValidity(final Field testField)
+    public void assertValidity(final Field<Integer> testField)
         throws ValidationException
     {
         super.assertValidity(testField);
-        
+
         Group thisGroup = testField.getGroup();
 
         if (testField.isMultiValued())
@@ -193,7 +186,7 @@ public class IntegerRangeValidator
         else
         {
             String testValue = (String)testField.getTestValue();
-        
+
             assertValidity(testValue, thisGroup);
         }
     }
@@ -204,7 +197,7 @@ public class IntegerRangeValidator
      *
      * @param testValue a <code>String</code> to be tested
      * @param group the group this field belongs to
-     * 
+     *
      * @exception ValidationException containing an error message if the
      * testValue did not pass the validation tests.
      */
@@ -214,10 +207,10 @@ public class IntegerRangeValidator
         if (required || StringUtils.isNotEmpty(testValue))
         {
             Integer testInt = new Integer(testValue);
-            
+
             try
             {
-                FieldReference.checkReferences(fieldReferences, compareCallback, 
+                FieldReference.checkReferences(fieldReferences, compareCallback,
                         testInt, group);
             }
             catch (ValidationException e)

Modified: turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/IntegerValidator.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/IntegerValidator.java?rev=1200653&r1=1200652&r2=1200653&view=diff
==============================================================================
--- turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/IntegerValidator.java (original)
+++ turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/IntegerValidator.java Fri Nov 11 00:05:28 2011
@@ -19,10 +19,10 @@ package org.apache.fulcrum.intake.valida
  * under the License.
  */
 
+import java.text.ParseException;
+import java.util.Locale;
 import java.util.Map;
 
-import org.apache.commons.lang.StringUtils;
-
 /**
  * Validates Integers with the following constraints in addition to those
  * listed in NumberValidator and DefaultValidator.
@@ -43,25 +43,18 @@ import org.apache.commons.lang.StringUti
  * @version $Id$
  */
 public class IntegerValidator
-        extends NumberValidator
+        extends NumberValidator<Integer>
 {
-    /* Init the minValue to that for a Integer */
-    private int minValue = Integer.MIN_VALUE;
-
-    /* Init the maxValue to that for a Integer */
-    private int maxValue = Integer.MAX_VALUE;
-
     /**
      * Constructor to use when initialising Object
      *
      * @param paramMap
      * @throws InvalidMaskException
      */
-    public IntegerValidator(Map paramMap)
+    public IntegerValidator(Map<String, Constraint> paramMap)
             throws InvalidMaskException
     {
-        this();
-        init(paramMap);
+        super(paramMap);
     }
 
     /**
@@ -69,118 +62,16 @@ public class IntegerValidator
      */
     public IntegerValidator()
     {
+        super();
         invalidNumberMessage = "Entry was not a valid Integer";
     }
 
     /**
-     * Method to initialise Object
-     *
-     * @param paramMap
-     * @throws InvalidMaskException
-     */
-    public void init(Map paramMap)
-            throws InvalidMaskException
-    {
-        super.init(paramMap);
-
-        Constraint constraint = (Constraint) paramMap.get(MIN_VALUE_RULE_NAME);
-        if (constraint != null)
-        {
-            String param = constraint.getValue();
-            minValue = Integer.parseInt(param);
-            minValueMessage = constraint.getMessage();
-        }
-
-        constraint = (Constraint) paramMap.get(MAX_VALUE_RULE_NAME);
-        if (constraint != null)
-        {
-            String param = constraint.getValue();
-            maxValue = Integer.parseInt(param);
-            maxValueMessage = constraint.getMessage();
-        }
-    }
-
-    /**
-     * Determine whether a testValue meets the criteria specified
-     * in the constraints defined for this validator
-     *
-     * @param testValue a <code>String</code> to be tested
-     * @exception ValidationException containing an error message if the
-     * testValue did not pass the validation tests.
-     */
-    public void assertValidity(String testValue)
-            throws ValidationException
-    {
-        super.assertValidity(testValue);
-
-        if (required || StringUtils.isNotEmpty(testValue))
-        {
-            int i = 0;
-            try
-            {
-                i = Integer.parseInt(testValue);
-            }
-            catch (RuntimeException e)
-            {
-                errorMessage = invalidNumberMessage;
-                throw new ValidationException(invalidNumberMessage);
-            }
-
-            if (i < minValue)
-            {
-                errorMessage = minValueMessage;
-                throw new ValidationException(minValueMessage);
-            }
-            if (i > maxValue)
-            {
-                errorMessage = maxValueMessage;
-                throw new ValidationException(maxValueMessage);
-            }
-        }
-    }
-
-
-    // ************************************************************
-    // **                Bean accessor methods                   **
-    // ************************************************************
-
-    /**
-     * Get the value of minValue.
-     *
-     * @return value of minValue.
-     */
-    public int getMinValue()
-    {
-        return minValue;
-    }
-
-    /**
-     * Set the value of minValue.
-     *
-     * @param minValue  Value to assign to minValue.
-     */
-    public void setMinValue(int minValue)
-    {
-        this.minValue = minValue;
-    }
-
-    /**
-     * Get the value of maxValue.
-     *
-     * @return value of maxValue.
-     */
-    public int getMaxValue()
-    {
-        return maxValue;
-    }
-
-    /**
-     * Set the value of maxValue.
-     *
-     * @param maxValue  Value to assign to maxValue.
+     * @see org.apache.fulcrum.intake.validator.NumberValidator#parseNumber(java.lang.String, java.util.Locale)
      */
-    public void setMaxValue(int maxValue)
+    @Override
+    protected Integer parseNumber(String stringValue, Locale locale) throws ParseException
     {
-        this.maxValue = maxValue;
+        return Integer.valueOf(stringValue);
     }
 }

Modified: turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/LongValidator.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/LongValidator.java?rev=1200653&r1=1200652&r2=1200653&view=diff
==============================================================================
--- turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/LongValidator.java (original)
+++ turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/LongValidator.java Fri Nov 11 00:05:28 2011
@@ -19,10 +19,10 @@ package org.apache.fulcrum.intake.valida
  * under the License.
  */
 
+import java.text.ParseException;
+import java.util.Locale;
 import java.util.Map;
 
-import org.apache.commons.lang.StringUtils;
-
 /**
  * Validates Longs with the following constraints in addition to those
  * listed in NumberValidator and DefaultValidator.
@@ -43,25 +43,18 @@ import org.apache.commons.lang.StringUti
  * @version $Id$
  */
 public class LongValidator
-        extends NumberValidator
+        extends NumberValidator<Long>
 {
-    /* Init the minValue to that for a Long */
-    private long minValue = Long.MIN_VALUE;
-
-    /* Init the maxValue to that for a Long */
-    private long maxValue = Long.MAX_VALUE;
-
     /**
      * Constructor to use when initialising Object
      *
      * @param paramMap
      * @throws InvalidMaskException
      */
-    public LongValidator(Map paramMap)
+    public LongValidator(Map<String, Constraint> paramMap)
             throws InvalidMaskException
     {
-        this();
-        init(paramMap);
+        super(paramMap);
     }
 
     /**
@@ -69,118 +62,16 @@ public class LongValidator
      */
     public LongValidator()
     {
+        super();
         invalidNumberMessage = "Entry was not a valid Long";
     }
 
     /**
-     * Method to initialise Object
-     *
-     * @param paramMap
-     * @throws InvalidMaskException
-     */
-    public void init(Map paramMap)
-            throws InvalidMaskException
-    {
-        super.init(paramMap);
-
-        Constraint constraint = (Constraint) paramMap.get(MIN_VALUE_RULE_NAME);
-        if (constraint != null)
-        {
-            String param = constraint.getValue();
-            minValue = Long.parseLong(param);
-            minValueMessage = constraint.getMessage();
-        }
-
-        constraint = (Constraint) paramMap.get(MAX_VALUE_RULE_NAME);
-        if (constraint != null)
-        {
-            String param = constraint.getValue();
-            maxValue = Long.parseLong(param);
-            maxValueMessage = constraint.getMessage();
-        }
-    }
-
-    /**
-     * Determine whether a testValue meets the criteria specified
-     * in the constraints defined for this validator
-     *
-     * @param testValue a <code>String</code> to be tested
-     * @exception ValidationException containing an error message if the
-     * testValue did not pass the validation tests.
-     */
-    public void assertValidity(String testValue)
-            throws ValidationException
-    {
-        super.assertValidity(testValue);
-
-        if (required || StringUtils.isNotEmpty(testValue))
-        {
-            long l = 0L;
-            try
-            {
-                l = Long.parseLong(testValue);
-            }
-            catch (RuntimeException e)
-            {
-                errorMessage = invalidNumberMessage;
-                throw new ValidationException(invalidNumberMessage);
-            }
-
-            if (l < minValue)
-            {
-                errorMessage = minValueMessage;
-                throw new ValidationException(minValueMessage);
-            }
-            if (l > maxValue)
-            {
-                errorMessage = maxValueMessage;
-                throw new ValidationException(maxValueMessage);
-            }
-        }
-    }
-
-
-    // ************************************************************
-    // **                Bean accessor methods                   **
-    // ************************************************************
-
-    /**
-     * Get the value of minValue.
-     *
-     * @return value of minValue.
-     */
-    public long getMinValue()
-    {
-        return minValue;
-    }
-
-    /**
-     * Set the value of minValue.
-     *
-     * @param minValue  Value to assign to minValue.
-     */
-    public void setMinValue(long minValue)
-    {
-        this.minValue = minValue;
-    }
-
-    /**
-     * Get the value of maxValue.
-     *
-     * @return value of maxValue.
-     */
-    public long getMaxValue()
-    {
-        return maxValue;
-    }
-
-    /**
-     * Set the value of maxValue.
-     *
-     * @param maxValue  Value to assign to maxValue.
+     * @see org.apache.fulcrum.intake.validator.NumberValidator#parseNumber(java.lang.String, java.util.Locale)
      */
-    public void setMaxValue(long maxValue)
+    @Override
+    protected Long parseNumber(String stringValue, Locale locale) throws ParseException
     {
-        this.maxValue = maxValue;
+        return Long.valueOf(stringValue);
     }
 }

Modified: turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/NumberValidator.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/NumberValidator.java?rev=1200653&r1=1200652&r2=1200653&view=diff
==============================================================================
--- turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/NumberValidator.java (original)
+++ turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/NumberValidator.java Fri Nov 11 00:05:28 2011
@@ -19,8 +19,13 @@ package org.apache.fulcrum.intake.valida
  * under the License.
  */
 
+import java.text.ParseException;
+import java.util.Locale;
 import java.util.Map;
 
+import org.apache.commons.lang.StringUtils;
+import org.apache.fulcrum.intake.model.Field;
+
 /**
  * Validates numbers with the following constraints in addition to those
  * listed in DefaultValidator.
@@ -40,8 +45,8 @@ import java.util.Map;
  * @author <a href="mailto:Colin.Chalmers@maxware.nl">Colin Chalmers</a>
  * @version $Id$
  */
-abstract class NumberValidator
-        extends DefaultValidator
+public abstract class NumberValidator<T extends Number>
+        extends DefaultValidator<T>
 {
     /** The message to show if field fails min-value test */
     String minValueMessage = null;
@@ -52,6 +57,29 @@ abstract class NumberValidator
     /** The message to use for invalid numbers */
     String invalidNumberMessage = null;
 
+    private T minValue = null;
+    private T maxValue = null;
+
+    /**
+     * Constructor to use when initializing Object
+     *
+     * @param paramMap
+     * @throws InvalidMaskException
+     */
+    public NumberValidator(Map<String, Constraint> paramMap)
+            throws InvalidMaskException
+    {
+        super(paramMap);
+    }
+
+    /**
+     * Default Constructor
+     */
+    public NumberValidator()
+    {
+        super();
+    }
+
     /**
      * Extract the relevant parameters from the constraints listed
      * in <rule> tags within the intake.xml file.
@@ -60,18 +88,125 @@ abstract class NumberValidator
      * containing constraints on the input.
      * @exception InvalidMaskException an invalid mask was specified
      */
-    public void init(Map paramMap)
+    public void init(Map<String, ? extends Constraint> paramMap)
             throws InvalidMaskException
     {
         super.init(paramMap);
 
-        Constraint constraint =
-                (Constraint) paramMap.get(INVALID_NUMBER_RULE_NAME);
+        Constraint constraint = paramMap.get(INVALID_NUMBER_RULE_NAME);
 
         if (constraint != null)
         {
             invalidNumberMessage = constraint.getMessage();
         }
+
+        constraint = paramMap.get(MIN_VALUE_RULE_NAME);
+        if (constraint != null)
+        {
+            String param = constraint.getValue();
+            try
+            {
+                minValue = parseNumber(param, Locale.US);
+            }
+            catch (ParseException e)
+            {
+                throw new InvalidMaskException("Could not parse minimum value " + param, e);
+            }
+            minValueMessage = constraint.getMessage();
+        }
+
+        constraint = paramMap.get(MAX_VALUE_RULE_NAME);
+        if (constraint != null)
+        {
+            String param = constraint.getValue();
+            try
+            {
+                maxValue = parseNumber(param, Locale.US);
+            }
+            catch (ParseException e)
+            {
+                throw new InvalidMaskException("Could not parse minimum value " + param, e);
+            }
+            maxValueMessage = constraint.getMessage();
+        }
+    }
+
+    /**
+     * Parse the actual value out of a string
+     *
+     * @param stringValue the string value
+     * @param locale the locale to use while parsing
+     *
+     * @return the value
+     *
+     * @throws ParseException if the value could not be parsed
+     */
+    protected abstract T parseNumber(String stringValue, Locale locale) throws ParseException;
+
+    /**
+     * Determine whether a field meets the criteria specified
+     * in the constraints defined for this validator
+     *
+     * @param field a <code>Field</code> to be tested
+     * @exception ValidationException containing an error message if the
+     * testValue did not pass the validation tests.
+     */
+    public void assertValidity(Field<T> field) throws ValidationException
+    {
+        Locale locale = field.getLocale();
+
+        if (field.isMultiValued())
+        {
+            String[] stringValues = (String[])field.getTestValue();
+
+            for (int i = 0; i < stringValues.length; i++)
+            {
+                assertValidity(stringValues[i], locale);
+            }
+        }
+        else
+        {
+            assertValidity((String)field.getTestValue(), locale);
+        }
+    }
+
+    /**
+     * Determine whether a testValue meets the criteria specified
+     * in the constraints defined for this validator
+     *
+     * @param testValue a <code>String</code> to be tested
+     * @param locale the Locale of the associated field
+     * @exception ValidationException containing an error message if the
+     * testValue did not pass the validation tests.
+     */
+    public void assertValidity(String testValue, Locale locale) throws ValidationException
+    {
+        super.assertValidity(testValue);
+
+        if (required || StringUtils.isNotEmpty(testValue))
+        {
+            T number = null;
+            try
+            {
+                number = parseNumber(testValue, locale);
+            }
+            catch (ParseException e)
+            {
+                errorMessage = invalidNumberMessage;
+                throw new ValidationException(invalidNumberMessage);
+            }
+
+            if (minValue != null && number.doubleValue() < minValue.doubleValue())
+            {
+                errorMessage = minValueMessage;
+                throw new ValidationException(minValueMessage);
+            }
+            if (maxValue != null && number.doubleValue() > maxValue.doubleValue())
+            {
+                errorMessage = maxValueMessage;
+                throw new ValidationException(maxValueMessage);
+            }
+        }
     }
 
     // ************************************************************
@@ -138,4 +273,43 @@ abstract class NumberValidator
         this.invalidNumberMessage = invalidNumberMessage;
     }
 
+    /**
+     * Get the value of minValue.
+     *
+     * @return value of minValue.
+     */
+    public T getMinValue()
+    {
+        return minValue;
+    }
+
+    /**
+     * Set the value of minValue.
+     *
+     * @param minValue  Value to assign to minValue.
+     */
+    public void setMinValue(T minValue)
+    {
+        this.minValue = minValue;
+    }
+
+    /**
+     * Get the value of maxValue.
+     *
+     * @return value of maxValue.
+     */
+    public T getMaxValue()
+    {
+        return maxValue;
+    }
+
+    /**
+     * Set the value of maxValue.
+     *
+     * @param maxValue  Value to assign to maxValue.
+     */
+    public void setMaxValue(T maxValue)
+    {
+        this.maxValue = maxValue;
+    }
 }

Modified: turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/ShortValidator.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/ShortValidator.java?rev=1200653&r1=1200652&r2=1200653&view=diff
==============================================================================
--- turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/ShortValidator.java (original)
+++ turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/ShortValidator.java Fri Nov 11 00:05:28 2011
@@ -19,10 +19,10 @@ package org.apache.fulcrum.intake.valida
  * under the License.
  */
 
+import java.text.ParseException;
+import java.util.Locale;
 import java.util.Map;
 
-import org.apache.commons.lang.StringUtils;
-
 /**
  * Validates Shorts with the following constraints in addition to those
  * listed in NumberValidator and DefaultValidator.
@@ -43,25 +43,18 @@ import org.apache.commons.lang.StringUti
  * @version $Id$
  */
 public class ShortValidator
-        extends NumberValidator
+        extends NumberValidator<Short>
 {
-    /* Init the minValue to that for a Short */
-    private short minValue = Short.MIN_VALUE;
-
-    /* Init the maxValue to that for a Short */
-    private short maxValue = Short.MAX_VALUE;
-
     /**
      * Constructor to use when initialising Object
      *
      * @param paramMap
      * @throws InvalidMaskException
      */
-    public ShortValidator(Map paramMap)
+    public ShortValidator(Map<String, Constraint> paramMap)
             throws InvalidMaskException
     {
-        this();
-        init(paramMap);
+        super(paramMap);
     }
 
     /**
@@ -69,118 +62,16 @@ public class ShortValidator
      */
     public ShortValidator()
     {
+        super();
         invalidNumberMessage = "Entry was not a valid Short";
     }
 
     /**
-     * Method to initialise Object
-     *
-     * @param paramMap
-     * @throws InvalidMaskException
-     */
-    public void init(Map paramMap)
-            throws InvalidMaskException
-    {
-        super.init(paramMap);
-
-        Constraint constraint = (Constraint) paramMap.get(MIN_VALUE_RULE_NAME);
-        if (constraint != null)
-        {
-            String param = constraint.getValue();
-            minValue = Short.parseShort(param);
-            minValueMessage = constraint.getMessage();
-        }
-
-        constraint = (Constraint) paramMap.get(MAX_VALUE_RULE_NAME);
-        if (constraint != null)
-        {
-            String param = constraint.getValue();
-            maxValue = Short.parseShort(param);
-            maxValueMessage = constraint.getMessage();
-        }
-    }
-
-    /**
-     * Determine whether a testValue meets the criteria specified
-     * in the constraints defined for this validator
-     *
-     * @param testValue a <code>String</code> to be tested
-     * @exception ValidationException containing an error message if the
-     * testValue did not pass the validation tests.
-     */
-    public void assertValidity(String testValue)
-            throws ValidationException
-    {
-        super.assertValidity(testValue);
-
-        if (required || StringUtils.isNotEmpty(testValue))
-        {
-            short s = 0;
-            try
-            {
-                s = Short.parseShort(testValue);
-            }
-            catch (RuntimeException e)
-            {
-                errorMessage = invalidNumberMessage;
-                throw new ValidationException(invalidNumberMessage);
-            }
-
-            if (s < minValue)
-            {
-                errorMessage = minValueMessage;
-                throw new ValidationException(minValueMessage);
-            }
-            if (s > maxValue)
-            {
-                errorMessage = maxValueMessage;
-                throw new ValidationException(maxValueMessage);
-            }
-        }
-    }
-
-
-    // ************************************************************
-    // **                Bean accessor methods                   **
-    // ************************************************************
-
-    /**
-     * Get the value of minValue.
-     *
-     * @return value of minValue.
-     */
-    public short getMinValue()
-    {
-        return minValue;
-    }
-
-    /**
-     * Set the value of minValue.
-     *
-     * @param minValue  Value to assign to minValue.
-     */
-    public void setMinValue(short minValue)
-    {
-        this.minValue = minValue;
-    }
-
-    /**
-     * Get the value of maxValue.
-     *
-     * @return value of maxValue.
-     */
-    public short getMaxValue()
-    {
-        return maxValue;
-    }
-
-    /**
-     * Set the value of maxValue.
-     *
-     * @param maxValue  Value to assign to maxValue.
+     * @see org.apache.fulcrum.intake.validator.NumberValidator#parseNumber(java.lang.String, java.util.Locale)
      */
-    public void setMaxValue(short maxValue)
+    @Override
+    protected Short parseNumber(String stringValue, Locale locale) throws ParseException
     {
-        this.maxValue = maxValue;
+        return Short.valueOf(stringValue);
     }
 }

Modified: turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/StringValidator.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/StringValidator.java?rev=1200653&r1=1200652&r2=1200653&view=diff
==============================================================================
--- turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/StringValidator.java (original)
+++ turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/StringValidator.java Fri Nov 11 00:05:28 2011
@@ -46,7 +46,7 @@ import org.apache.commons.lang.StringUti
  * @version $Id$
  */
 public class StringValidator
-        extends DefaultValidator
+        extends DefaultValidator<String>
 {
     /** The matching mask String as supplied by the XML input */
     protected String maskString = null;
@@ -66,10 +66,10 @@ public class StringValidator
      * @exception InvalidMaskException An invalid mask was specified for one of the rules
 
     */
-    public StringValidator(Map paramMap)
+    public StringValidator(Map<String, Constraint> paramMap)
             throws InvalidMaskException
     {
-        init(paramMap);
+        super(paramMap);
     }
 
     /**
@@ -77,7 +77,7 @@ public class StringValidator
      */
     public StringValidator()
     {
-        // do nothing
+        super();
     }
 
     /**
@@ -88,12 +88,12 @@ public class StringValidator
      * containing constraints on the input.
      * @exception InvalidMaskException An invalid mask was specified for one of the rules
      */
-    public void init(Map paramMap)
+    public void init(Map<String, ? extends Constraint> paramMap)
             throws InvalidMaskException
     {
         super.init(paramMap);
 
-        Constraint constraint = (Constraint) paramMap.get(MASK_RULE_NAME);
+        Constraint constraint = paramMap.get(MASK_RULE_NAME);
         if (constraint != null)
         {
             String param = constraint.getValue();

Modified: turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/Validator.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/Validator.java?rev=1200653&r1=1200652&r2=1200653&view=diff
==============================================================================
--- turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/Validator.java (original)
+++ turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/Validator.java Fri Nov 11 00:05:28 2011
@@ -28,7 +28,7 @@ import org.apache.fulcrum.intake.model.F
  * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
  * @version $Id$
  */
-public interface Validator
+public interface Validator<T>
 {
     /** "flexible" Rule, used in DateFormat Validator */
     String FLEXIBLE_RULE_NAME = "flexible";
@@ -64,7 +64,7 @@ public interface Validator
      * @param field a <code>Field</code> to be tested
      * @return true if valid, false otherwise
      */
-    boolean isValid(Field field);
+    boolean isValid(Field<T> field);
 
     /**
      * Determine whether a field meets the criteria specified
@@ -74,7 +74,7 @@ public interface Validator
      * @exception ValidationException containing an error message if the
      * testValue did not pass the validation tests.
      */
-    void assertValidity(Field field)
+    void assertValidity(Field<T> field)
             throws ValidationException;
 
     /**

Modified: turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/xmlmodel/AppData.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/xmlmodel/AppData.java?rev=1200653&r1=1200652&r2=1200653&view=diff
==============================================================================
--- turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/xmlmodel/AppData.java (original)
+++ turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/xmlmodel/AppData.java Fri Nov 11 00:05:28 2011
@@ -20,13 +20,10 @@ package org.apache.fulcrum.intake.xmlmod
  */
 
 import java.io.Serializable;
-
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 
 import org.apache.fulcrum.intake.IntakeException;
-
 import org.xml.sax.Attributes;
 
 /**
@@ -46,7 +43,7 @@ public class AppData
     private static final long serialVersionUID = -3953843038383617960L;
 
     /** List of groups */
-    private List inputs;
+    private final List<XmlGroup> inputs;
 
     /** Package that will be used for all mapTo objects */
     private String basePackage;
@@ -59,7 +56,7 @@ public class AppData
      */
     public AppData()
     {
-        inputs = new ArrayList();
+        inputs = new ArrayList<XmlGroup>();
     }
 
     /**
@@ -95,7 +92,7 @@ public class AppData
      * groups with and without prefix in the service.
      *
      */
-    public List getGroups()
+    public List<XmlGroup> getGroups()
     {
         return inputs;
     }
@@ -119,10 +116,8 @@ public class AppData
 
         String groupPrefix = getGroupPrefix();
 
-        for (Iterator it = inputs.iterator(); it.hasNext();)
+        for (XmlGroup group : inputs)
         {
-            XmlGroup group = (XmlGroup) it.next();
-
             if (group.getName().equals(groupName))
             {
                 return group;
@@ -211,7 +206,7 @@ public class AppData
     }
 
     /**
-     * Creats a string representation of this AppData.
+     * Creates a string representation of this AppData.
      * The representation is given in xml format.
      */
     public String toString()
@@ -219,9 +214,9 @@ public class AppData
         StringBuffer result = new StringBuffer();
 
         result.append("<input-data>\n");
-        for (Iterator iter = inputs.iterator(); iter.hasNext();)
+        for (XmlGroup group : inputs)
         {
-            result.append(iter.next());
+            result.append(group);
         }
         result.append("</input-data>");
         return result.toString();

Modified: turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/xmlmodel/XmlField.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/xmlmodel/XmlField.java?rev=1200653&r1=1200652&r2=1200653&view=diff
==============================================================================
--- turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/xmlmodel/XmlField.java (original)
+++ turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/xmlmodel/XmlField.java Fri Nov 11 00:05:28 2011
@@ -23,15 +23,12 @@ import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.io.Serializable;
-
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
 import org.apache.commons.lang.StringUtils;
-
 import org.xml.sax.Attributes;
 
 /**
@@ -57,8 +54,8 @@ public class XmlField
     private String displayName;
     private String multiValued;
     private XmlGroup parent;
-    private List rules;
-    private Map ruleMap;
+    private final List<Rule> rules;
+    private final Map<String, Rule> ruleMap;
     private String ifRequiredMessage;
     private String mapToObject;
     private String mapToProperty;
@@ -73,8 +70,8 @@ public class XmlField
      */
     public XmlField()
     {
-        rules = new ArrayList();
-        ruleMap = new HashMap();
+        rules = new ArrayList<Rule>();
+        ruleMap = new HashMap<String, Rule>();
     }
 
     /**
@@ -82,9 +79,8 @@ public class XmlField
      */
     public XmlField(String name)
     {
+        this();
         this.name = name;
-        rules = new ArrayList();
-        ruleMap = new HashMap();
     }
 
     /**
@@ -421,7 +417,7 @@ public class XmlField
      *
      * @return a <code>List</code> value
      */
-    public List getRules()
+    public List<Rule> getRules()
     {
         return rules;
     }
@@ -432,7 +428,7 @@ public class XmlField
      *
      * @return a <code>Map</code> value
      */
-    public Map getRuleMap()
+    public Map<String, Rule> getRuleMap()
     {
         return ruleMap;
     }
@@ -481,9 +477,9 @@ public class XmlField
         else
         {
             result.append(">\n");
-            for (Iterator i = rules.iterator(); i.hasNext();)
+            for (Rule rule : rules)
             {
-                result.append(i.next());
+                result.append(rule);
             }
             result.append("</field>\n");
         }

Modified: turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/xmlmodel/XmlGroup.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/xmlmodel/XmlGroup.java?rev=1200653&r1=1200652&r2=1200653&view=diff
==============================================================================
--- turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/xmlmodel/XmlGroup.java (original)
+++ turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/xmlmodel/XmlGroup.java Fri Nov 11 00:05:28 2011
@@ -20,13 +20,10 @@ package org.apache.fulcrum.intake.xmlmod
  */
 
 import java.io.Serializable;
-
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 
 import org.apache.commons.lang.StringUtils;
-
 import org.xml.sax.Attributes;
 
 /**
@@ -44,8 +41,8 @@ public class XmlGroup
      */
     private static final long serialVersionUID = 4771953823149519746L;
 
-    private List fields;
-    private List mapToObjects;
+    private final List<XmlField> fields;
+    private final List<String> mapToObjects;
     private String defaultMapToObject;
     private AppData parent;
     private String groupName;
@@ -57,8 +54,8 @@ public class XmlGroup
      */
     public XmlGroup()
     {
-        fields = new ArrayList();
-        mapToObjects = new ArrayList(2);
+        fields = new ArrayList<XmlField>();
+        mapToObjects = new ArrayList<String>(2);
     }
 
     /**
@@ -178,7 +175,7 @@ public class XmlGroup
     /**
      * Returns a collection of fields in this input group
      */
-    public List getFields()
+    public List<XmlField> getFields()
     {
         return fields;
     }
@@ -199,9 +196,8 @@ public class XmlGroup
     {
         String curName;
 
-        for (Iterator iter = fields.iterator(); iter.hasNext();)
+        for (XmlField field : fields)
         {
-            XmlField field = (XmlField) iter.next();
             curName = field.getRawName();
             if (curName.equals(name))
             {
@@ -227,7 +223,7 @@ public class XmlGroup
         return (getField(name) != null);
     }
 
-    public List getMapToObjects()
+    public List<String> getMapToObjects()
     {
         return mapToObjects;
     }
@@ -276,9 +272,9 @@ public class XmlGroup
 
         if (fields != null)
         {
-            for (Iterator iter = fields.iterator(); iter.hasNext();)
+            for (XmlField field : fields)
             {
-                result.append(iter.next());
+                result.append(field);
             }
         }
 

Modified: turbine/fulcrum/trunk/intake/src/test/intake1.xml
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/test/intake1.xml?rev=1200653&r1=1200652&r2=1200653&view=diff
==============================================================================
--- turbine/fulcrum/trunk/intake/src/test/intake1.xml (original)
+++ turbine/fulcrum/trunk/intake/src/test/intake1.xml Fri Nov 11 00:05:28 2011
@@ -46,6 +46,7 @@
 
     <group name="NumberTest" key="nt">
         <field name="EmptyIntegerTestField" key="eitf" type="int"/>
+        <field name="MultiIntegerTestField" key="mitf" type="int" multiValued="true" />
         <field name="EmptyLongTestField" key="eltf" type="long"/>
         <field name="EmptyShortTestField" key="estf" type="short"/>
         <field name="EmptyFloatTestField" key="eftf" type="float"/>

Modified: turbine/fulcrum/trunk/intake/src/test/org/apache/fulcrum/intake/IntakeTest.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/test/org/apache/fulcrum/intake/IntakeTest.java?rev=1200653&r1=1200652&r2=1200653&view=diff
==============================================================================
--- turbine/fulcrum/trunk/intake/src/test/org/apache/fulcrum/intake/IntakeTest.java (original)
+++ turbine/fulcrum/trunk/intake/src/test/org/apache/fulcrum/intake/IntakeTest.java Fri Nov 11 00:05:28 2011
@@ -19,10 +19,13 @@ package org.apache.fulcrum.intake;
  * under the License.
  */
 
+import java.util.Arrays;
+
 import org.apache.fulcrum.intake.model.Field;
 import org.apache.fulcrum.intake.model.Group;
 import org.apache.fulcrum.intake.test.LoginForm;
 import org.apache.fulcrum.intake.validator.BooleanValidator;
+import org.apache.fulcrum.intake.validator.IntegerValidator;
 import org.apache.fulcrum.intake.validator.ValidationException;
 import org.apache.fulcrum.parser.DefaultParameterParser;
 import org.apache.fulcrum.parser.ParserService;
@@ -82,7 +85,7 @@ public class IntakeTest extends BaseUnit
         Group group = is.getGroup("LoginIfcGroup");
         assertNotNull(group);
 
-        Field userNameField = group.get("Username");
+        Field<?> userNameField = group.get("Username");
 
         ParserService ps = (ParserService) this.resolve( ParserService.class.getName() );
         ValueParser pp = ps.getParser(DefaultParameterParser.class);
@@ -103,7 +106,7 @@ public class IntakeTest extends BaseUnit
         Group group = is.getGroup("LoginGroup");
         assertNotNull(group);
 
-        Field userNameField = group.get("Username");
+        Field<?> userNameField = group.get("Username");
 
         ParserService ps = (ParserService) this.resolve( ParserService.class.getName() );
         ValueParser pp = ps.getParser(DefaultParameterParser.class);
@@ -124,7 +127,7 @@ public class IntakeTest extends BaseUnit
         assertNotNull(group);
         assertTrue(IntakeServiceFacade.isInitialized());
         group = IntakeServiceFacade.getGroup("BooleanTest");
-        Field booleanField = group.get("EmptyBooleanTestField");
+        Field<?> booleanField = group.get("EmptyBooleanTestField");
         assertTrue("The Default Validator of an intake Field type boolean should be BooleanValidator", (booleanField.getValidator() instanceof BooleanValidator));
         assertFalse("An Empty intake Field type boolean should not be required", booleanField.isRequired());
     }
@@ -136,7 +139,7 @@ public class IntakeTest extends BaseUnit
         assertNotNull(group);
         assertTrue(IntakeServiceFacade.isInitialized());
         group = IntakeServiceFacade.getGroup("BooleanTest");
-        Field booleanField = group.get("BooleanTestField");
+        Field<?> booleanField = group.get("BooleanTestField");
         assertTrue("The Default Validator of an intake Field type boolean should be BooleanValidator", (booleanField.getValidator() instanceof BooleanValidator));
         assertFalse("An intake Field type boolean, which is not required, should not be required", booleanField.isRequired());
     }
@@ -148,18 +151,41 @@ public class IntakeTest extends BaseUnit
         assertNotNull(group);
         assertTrue(IntakeServiceFacade.isInitialized());
         group = IntakeServiceFacade.getGroup("BooleanTest");
-        Field booleanField = group.get("RequiredBooleanTestField");
+        Field<?> booleanField = group.get("RequiredBooleanTestField");
         assertTrue("The Default Validator of an intake Field type boolean should be BooleanValidator", (booleanField.getValidator() instanceof BooleanValidator));
         assertTrue("An intake Field type boolean, which is required, should be required", booleanField.isRequired());
     }
 
+    public void testMultiValueField() throws Exception
+    {
+        IntakeService is = (IntakeService) this.resolve( IntakeService.class.getName() );
+        Group group = is.getGroup("NumberTest");
+        assertNotNull(group);
+        Field<?> multiValueField = group.get("MultiIntegerTestField");
+        assertTrue("The Default Validator of an intake Field type int should be IntegerValidator", (multiValueField.getValidator() instanceof IntegerValidator));
+        assertTrue("An intake Field type int, which is multiValued, should be multiValued", multiValueField.isMultiValued());
+
+        ParserService ps = (ParserService) this.resolve( ParserService.class.getName() );
+        ValueParser pp = ps.getParser(DefaultParameterParser.class);
+
+        int[] values = new int[] { 1, 2 };
+        pp.add("nt_0mitf", values[0]);
+        pp.add("nt_0mitf", values[1]);
+        group.init(pp);
+
+        assertTrue("The field should be set", multiValueField.isSet());
+        assertTrue("The field should be validated", multiValueField.isValidated());
+        assertTrue("The field should be valid", multiValueField.isValid());
+        assertTrue("The field should have the value [1, 2]", Arrays.equals(values, (int[])multiValueField.getValue()));
+    }
+
     public void testInvalidNumberMessage() throws Exception // TRB-74
     {
         IntakeService is = (IntakeService) this.resolve( IntakeService.class.getName() );
         Group group = is.getGroup("NumberTest");
         assertNotNull(group);
 
-        Field intField = group.get("EmptyIntegerTestField");
+        Field<?> intField = group.get("EmptyIntegerTestField");
         try
         {
             intField.getValidator().assertValidity("aa");
@@ -169,7 +195,7 @@ public class IntakeTest extends BaseUnit
             assertEquals("Invalid number message is wrong.", "Entry was not a valid Integer", ve.getMessage());
         }
 
-        Field longField = group.get("EmptyLongTestField");
+        Field<?> longField = group.get("EmptyLongTestField");
         try
         {
             longField.getValidator().assertValidity("aa");
@@ -179,7 +205,7 @@ public class IntakeTest extends BaseUnit
             assertEquals("Invalid number message is wrong.", "Entry was not a valid Long", ve.getMessage());
         }
 
-        Field shortField = group.get("EmptyShortTestField");
+        Field<?> shortField = group.get("EmptyShortTestField");
         try
         {
             shortField.getValidator().assertValidity("aa");
@@ -189,7 +215,7 @@ public class IntakeTest extends BaseUnit
             assertEquals("Invalid number message is wrong.", "Entry was not a valid Short", ve.getMessage());
         }
 
-        Field floatField = group.get("EmptyFloatTestField");
+        Field<?> floatField = group.get("EmptyFloatTestField");
         try
         {
             floatField.getValidator().assertValidity("aa");
@@ -199,7 +225,7 @@ public class IntakeTest extends BaseUnit
             assertEquals("Invalid number message is wrong.", "Entry was not a valid Float", ve.getMessage());
         }
 
-        Field doubleField = group.get("EmptyDoubleTestField");
+        Field<?> doubleField = group.get("EmptyDoubleTestField");
         try
         {
             doubleField.getValidator().assertValidity("aa");
@@ -209,7 +235,7 @@ public class IntakeTest extends BaseUnit
             assertEquals("Invalid number message is wrong.", "Entry was not a valid Double", ve.getMessage());
         }
 
-        Field bigDecimalField = group.get("EmptyBigDecimalTestField");
+        Field<?> bigDecimalField = group.get("EmptyBigDecimalTestField");
         try
         {
             bigDecimalField.getValidator().assertValidity("aa");
@@ -219,7 +245,7 @@ public class IntakeTest extends BaseUnit
             assertEquals("Invalid number message is wrong.", "Entry was not a valid BigDecimal", ve.getMessage());
         }
 
-        Field numberField = group.get("NumberTestField");
+        Field<?> numberField = group.get("NumberTestField");
         try
         {
             numberField.getValidator().assertValidity("aa");