cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject cvs commit: cocoon-2.1/src/blocks/forms/test/org/apache/cocoon/forms/datatype/convertor EnumConvertorTestCase.java
Date Thu, 06 May 2004 14:59:45 GMT
bruno       2004/05/06 07:59:45

  Modified:    src/blocks/forms/java/org/apache/cocoon/forms/binding
                        MultiValueJXPathBinding.java
                        RepeaterJXPathBinding.java ValueJXPathBinding.java
               src/blocks/forms/java/org/apache/cocoon/forms/datatype
                        Datatype.java DefaultSelectionListBuilder.java
                        DynamicSelectionList.java
               src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor
                        Convertor.java DummyStringConvertor.java
                        EnumConvertor.java FormattingDateConvertor.java
                        FormattingDecimalConvertor.java
                        FormattingDoubleConvertor.java
                        FormattingFloatConvertor.java
                        FormattingIntegerConvertor.java
                        FormattingLongConvertor.java
                        MillisDateConvertor.java PlainBooleanConvertor.java
                        PlainDecimalConvertor.java
                        PlainDoubleConvertor.java PlainFloatConvertor.java
                        PlainIntegerConvertor.java PlainLongConvertor.java
               src/blocks/forms/java/org/apache/cocoon/forms/datatype/typeimpl
                        AbstractDatatype.java
               src/blocks/forms/java/org/apache/cocoon/forms/formmodel
                        Field.java MultiValueField.java
               src/blocks/forms/test/org/apache/cocoon/forms/datatype/convertor
                        EnumConvertorTestCase.java
  Log:
  Made Convertor.convertFromString contract more solid by letting it
  return a ConversionResult object (instead of null/not-null to indicate
  successful conversion). This also moves the responsibility
  of creating the ValidationError to the Convertor, allowing convertors
  to set more specialised messages in them.
  
  Revision  Changes    Path
  1.3       +5 -2      cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/binding/MultiValueJXPathBinding.java
  
  Index: MultiValueJXPathBinding.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/binding/MultiValueJXPathBinding.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MultiValueJXPathBinding.java	23 Apr 2004 11:42:58 -0000	1.2
  +++ MultiValueJXPathBinding.java	6 May 2004 14:59:44 -0000	1.3
  @@ -21,6 +21,7 @@
   
   import org.apache.avalon.framework.logger.Logger;
   import org.apache.cocoon.forms.datatype.convertor.Convertor;
  +import org.apache.cocoon.forms.datatype.convertor.ConversionResult;
   import org.apache.cocoon.forms.formmodel.Widget;
   import org.apache.commons.jxpath.JXPathContext;
   import org.apache.commons.jxpath.Pointer;
  @@ -76,7 +77,9 @@
   
                   if (value != null && convertor != null) {
                       if (value instanceof String) {
  -                        value = convertor.convertFromString((String)value, convertorLocale,
null);
  +                        ConversionResult conversionResult = convertor.convertFromString((String)value,
convertorLocale, null);
  +                        if (conversionResult.isSuccessful())
  +                            value = conversionResult.getResult();
                       } else {
                           getLogger().warn("Convertor ignored on backend-value which isn't
of type String.");
                       }
  
  
  
  1.7       +5 -2      cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/binding/RepeaterJXPathBinding.java
  
  Index: RepeaterJXPathBinding.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/binding/RepeaterJXPathBinding.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- RepeaterJXPathBinding.java	23 Apr 2004 23:32:26 -0000	1.6
  +++ RepeaterJXPathBinding.java	6 May 2004 14:59:44 -0000	1.7
  @@ -24,6 +24,7 @@
   import org.apache.avalon.framework.logger.Logger;
   import org.apache.cocoon.forms.formmodel.Repeater;
   import org.apache.cocoon.forms.formmodel.Widget;
  +import org.apache.cocoon.forms.datatype.convertor.ConversionResult;
   import org.apache.commons.collections.ListUtils;
   import org.apache.commons.jxpath.JXPathContext;
   import org.apache.commons.jxpath.Pointer;
  @@ -302,8 +303,10 @@
                   Object value = rowContext.getValue(vBinding.getXPath());
                   if (value != null && vBinding.getConvertor() != null) {
                       if (value instanceof String) {
  -                        value = vBinding.getConvertor().convertFromString(
  +                        ConversionResult conversionResult = vBinding.getConvertor().convertFromString(
                                   (String)value, vBinding.getConvertorLocale(), null);
  +                        if (conversionResult.isSuccessful())
  +                            value = conversionResult.getResult();
                       } else {
                           if (getLogger().isWarnEnabled()) {
                               getLogger().warn("Convertor ignored on backend-value " +
  
  
  
  1.5       +5 -2      cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/binding/ValueJXPathBinding.java
  
  Index: ValueJXPathBinding.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/binding/ValueJXPathBinding.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ValueJXPathBinding.java	23 Apr 2004 11:42:58 -0000	1.4
  +++ ValueJXPathBinding.java	6 May 2004 14:59:44 -0000	1.5
  @@ -19,6 +19,7 @@
   
   import org.apache.avalon.framework.logger.Logger;
   import org.apache.cocoon.forms.datatype.convertor.Convertor;
  +import org.apache.cocoon.forms.datatype.convertor.ConversionResult;
   import org.apache.cocoon.forms.formmodel.Widget;
   import org.apache.commons.jxpath.JXPathContext;
   import org.apache.commons.jxpath.JXPathException;
  @@ -89,7 +90,9 @@
           Object value = jxpc.getValue(this.xpath);
           if (value != null && convertor != null) {
               if (value instanceof String) {
  -                value = convertor.convertFromString((String)value, convertorLocale, null);
  +                ConversionResult conversionResult = convertor.convertFromString((String)value,
convertorLocale, null);
  +                if (conversionResult.isSuccessful())
  +                    value = conversionResult.getResult();
               } else {
                   getLogger().warn("Convertor ignored on backend-value which isn't of type
String.");
               }
  
  
  
  1.4       +5 -5      cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/Datatype.java
  
  Index: Datatype.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/Datatype.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Datatype.java	10 Apr 2004 13:40:27 -0000	1.3
  +++ Datatype.java	6 May 2004 14:59:44 -0000	1.4
  @@ -17,6 +17,7 @@
   
   import org.outerj.expression.ExpressionContext;
   import org.apache.cocoon.forms.datatype.convertor.Convertor;
  +import org.apache.cocoon.forms.datatype.convertor.ConversionResult;
   import org.apache.cocoon.forms.validation.ValidationError;
   import org.xml.sax.SAXException;
   import org.xml.sax.ContentHandler;
  @@ -42,11 +43,10 @@
    */
   public interface Datatype {
       /**
  -     * Converts a string to an object of this datatype. Returns null if this
  -     * fails. This method uses the same {@link Convertor} as returned by the
  -     * {@link #getConvertor()} method.
  +     * Converts a string to an object of this datatype. This method uses the
  +     * same {@link Convertor} as returned by the {@link #getConvertor()} method.
        */
  -    Object convertFromString(String value, Locale locale);
  +    ConversionResult convertFromString(String value, Locale locale);
   
       /**
        * Converts an object of this datatype to a string representation.
  
  
  
  1.4       +5 -3      cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/DefaultSelectionListBuilder.java
  
  Index: DefaultSelectionListBuilder.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/DefaultSelectionListBuilder.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefaultSelectionListBuilder.java	28 Mar 2004 20:51:24 -0000	1.3
  +++ DefaultSelectionListBuilder.java	6 May 2004 14:59:44 -0000	1.4
  @@ -25,6 +25,7 @@
   import org.apache.cocoon.forms.Constants;
   import org.apache.cocoon.forms.datatype.convertor.Convertor;
   import org.apache.cocoon.forms.datatype.convertor.DefaultFormatCache;
  +import org.apache.cocoon.forms.datatype.convertor.ConversionResult;
   import org.apache.cocoon.forms.util.DomHelper;
   import org.apache.excalibur.source.Source;
   import org.apache.excalibur.source.SourceResolver;
  @@ -95,12 +96,13 @@
                       // Empty value translates into the null object
                       value = null;
                   } else {
  -                    value = convertor.convertFromString(stringValue, Locale.US, formatCache);
  -                    if (value == null) {
  +                    ConversionResult conversionResult = convertor.convertFromString(stringValue,
Locale.US, formatCache);
  +                    if (!conversionResult.isSuccessful()) {
                           throw new Exception("Could not convert the value \"" + stringValue
+
                                               "\" to the type " + datatype.getDescriptiveName()
+
                                               ", defined at " + DomHelper.getLocation(element));
                       }
  +                    value = conversionResult.getResult();
                   }
   
                   XMLizable label = null;
  
  
  
  1.3       +5 -3      cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/DynamicSelectionList.java
  
  Index: DynamicSelectionList.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/DynamicSelectionList.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DynamicSelectionList.java	9 Mar 2004 13:08:46 -0000	1.2
  +++ DynamicSelectionList.java	6 May 2004 14:59:44 -0000	1.3
  @@ -26,6 +26,7 @@
   import org.apache.cocoon.forms.Constants;
   import org.apache.cocoon.forms.datatype.convertor.Convertor;
   import org.apache.cocoon.forms.datatype.convertor.DefaultFormatCache;
  +import org.apache.cocoon.forms.datatype.convertor.ConversionResult;
   import org.apache.cocoon.xml.AttributesImpl;
   import org.apache.cocoon.xml.AbstractXMLPipe;
   import org.apache.cocoon.xml.dom.DOMBuilder;
  @@ -139,10 +140,11 @@
                           // Empty (or null) value translates into the empty string
                           currentValueAsString = "";
                       } else {
  -                        currentValue = convertor.convertFromString(unparsedValue, locale,
fromFormatCache);
  -                        if (currentValue == null) {
  +                        ConversionResult conversionResult = convertor.convertFromString(unparsedValue,
locale, fromFormatCache);
  +                        if (!conversionResult.isSuccessful()) {
                               throw new SAXException("Could not interpret the following value:
\"" + unparsedValue + "\".");
                           }
  +                        currentValue = conversionResult.getResult();
                           currentValueAsString = datatype.getConvertor().convertToString(currentValue,
locale, toFormatCache);
                       }
                       AttributesImpl attrs = new AttributesImpl();
  
  
  
  1.3       +2 -3      cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/Convertor.java
  
  Index: Convertor.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/Convertor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Convertor.java	10 Apr 2004 13:40:27 -0000	1.2
  +++ Convertor.java	6 May 2004 14:59:44 -0000	1.3
  @@ -38,11 +38,10 @@
       
       /**
        * Converts string representation into the object of convertor's type.
  -     * Returns null if conversion fails.
        *
        * @param formatCache can be null if not needed
        */
  -    Object convertFromString(String value, Locale locale, FormatCache formatCache);
  +    ConversionResult convertFromString(String value, Locale locale, FormatCache formatCache);
   
       String convertToString(Object value, Locale locale, FormatCache formatCache);
   
  
  
  
  1.3       +3 -3      cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/DummyStringConvertor.java
  
  Index: DummyStringConvertor.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/DummyStringConvertor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DummyStringConvertor.java	10 Apr 2004 13:40:27 -0000	1.2
  +++ DummyStringConvertor.java	6 May 2004 14:59:44 -0000	1.3
  @@ -27,8 +27,8 @@
    * @version CVS $Id$
    */
   public class DummyStringConvertor implements Convertor {
  -    public Object convertFromString(String value, Locale locale, Convertor.FormatCache
formatCache) {
  -        return value;
  +    public ConversionResult convertFromString(String value, Locale locale, Convertor.FormatCache
formatCache) {
  +        return new ConversionResult(value);
       }
   
       public String convertToString(Object value, Locale locale, Convertor.FormatCache formatCache)
{
  
  
  
  1.4       +4 -4      cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/EnumConvertor.java
  
  Index: EnumConvertor.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/EnumConvertor.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- EnumConvertor.java	10 Apr 2004 13:40:27 -0000	1.3
  +++ EnumConvertor.java	6 May 2004 14:59:44 -0000	1.4
  @@ -54,7 +54,7 @@
       /* (non-Javadoc)
        * @see org.apache.cocoon.forms.datatype.convertor.Convertor#convertFromString(java.lang.String,
java.util.Locale, org.apache.cocoon.forms.datatype.convertor.Convertor.FormatCache)
        */
  -    public Object convertFromString(String value,
  +    public ConversionResult convertFromString(String value,
   									Locale locale,
   									FormatCache formatCache) {
           try {
  @@ -62,7 +62,7 @@
               try {
                   Method method = getTypeClass().
                       getMethod("fromString", new Class[] { String.class, Locale.class});
  -                return method.invoke(null, new Object[] { value, locale});
  +                return new ConversionResult(method.invoke(null, new Object[] { value, locale}));
               } catch(NoSuchMethodException nsme) {
                   // fromString method was not found, try to convert
                   // the value to a field via reflection.
  @@ -73,7 +73,7 @@
                   }
                   Class clazz = getTypeClass();
                   Field field = clazz.getField(value);
  -                return field.get(null);
  +                return new ConversionResult(field.get(null));
               }
           } catch (Exception e) {
               throw new CascadingRuntimeException("Got exception trying to convert " + value,
e);
  
  
  
  1.3       +4 -4      cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/FormattingDateConvertor.java
  
  Index: FormattingDateConvertor.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/FormattingDateConvertor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FormattingDateConvertor.java	10 Apr 2004 13:40:27 -0000	1.2
  +++ FormattingDateConvertor.java	6 May 2004 14:59:44 -0000	1.3
  @@ -66,12 +66,12 @@
           this.localizedPatterns = new LocaleMap();
       }
   
  -    public Object convertFromString(String value, Locale locale, Convertor.FormatCache
formatCache) {
  +    public ConversionResult convertFromString(String value, Locale locale, Convertor.FormatCache
formatCache) {
           DateFormat dateFormat = getDateFormat(locale, formatCache);
           try {
  -            return dateFormat.parse(value);
  +            return new ConversionResult(dateFormat.parse(value));
           } catch (ParseException e) {
  -            return null;
  +            return ConversionResult.create("date");
           }
       }
   
  
  
  
  1.4       +5 -5      cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/FormattingDecimalConvertor.java
  
  Index: FormattingDecimalConvertor.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/FormattingDecimalConvertor.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- FormattingDecimalConvertor.java	10 Apr 2004 13:40:27 -0000	1.3
  +++ FormattingDecimalConvertor.java	6 May 2004 14:59:44 -0000	1.4
  @@ -66,7 +66,7 @@
           return NUMBER;
       }
   
  -    public Object convertFromString(String value, Locale locale, Convertor.FormatCache
formatCache) {
  +    public ConversionResult convertFromString(String value, Locale locale, Convertor.FormatCache
formatCache) {
           DecimalFormat decimalFormat = getDecimalFormat(locale, formatCache);
           try {
               Number decimalValue = decimalFormat.parse(value);
  @@ -81,11 +81,11 @@
               else if (decimalValue instanceof BigInteger)
                   decimalValue = new BigDecimal((BigInteger)decimalValue);
               else
  -                return null;
  +                return ConversionResult.create("decimal");
   
  -            return decimalValue;
  +            return new ConversionResult(decimalValue);
           } catch (ParseException e) {
  -            return null;
  +            return ConversionResult.create("decimal");
           }
       }
   
  
  
  
  1.2       +5 -5      cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/FormattingDoubleConvertor.java
  
  Index: FormattingDoubleConvertor.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/FormattingDoubleConvertor.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FormattingDoubleConvertor.java	18 Mar 2004 11:45:55 -0000	1.1
  +++ FormattingDoubleConvertor.java	6 May 2004 14:59:44 -0000	1.2
  @@ -35,16 +35,16 @@
           super();
       }
   
  -    public Object convertFromString(String value, Locale locale, Convertor.FormatCache
formatCache) {
  +    public ConversionResult convertFromString(String value, Locale locale, Convertor.FormatCache
formatCache) {
           DecimalFormat decimalFormat = getDecimalFormat(locale, formatCache);
           try {
               Number decimalValue = decimalFormat.parse(value);
               if (decimalValue instanceof Double)
  -                return decimalValue;
  +                return new ConversionResult(decimalValue);
               else
  -                return new Double(decimalValue.doubleValue());
  +                return new ConversionResult(new Double(decimalValue.doubleValue()));
           } catch (ParseException e) {
  -            return null;
  +            return ConversionResult.create("double");
           }
       }
   
  
  
  
  1.3       +5 -5      cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/FormattingFloatConvertor.java
  
  Index: FormattingFloatConvertor.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/FormattingFloatConvertor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FormattingFloatConvertor.java	18 Mar 2004 11:44:58 -0000	1.2
  +++ FormattingFloatConvertor.java	6 May 2004 14:59:44 -0000	1.3
  @@ -35,16 +35,16 @@
           super();
       }
   
  -    public Object convertFromString(String value, Locale locale, Convertor.FormatCache
formatCache) {
  +    public ConversionResult convertFromString(String value, Locale locale, Convertor.FormatCache
formatCache) {
           DecimalFormat decimalFormat = getDecimalFormat(locale, formatCache);
           try {
               Number decimalValue = decimalFormat.parse(value);
               if (decimalValue instanceof Float)
  -                return decimalValue;
  +                return new ConversionResult(decimalValue);
               else
  -                return new Float(decimalValue.floatValue());
  +                return new ConversionResult(new Float(decimalValue.floatValue()));
           } catch (ParseException e) {
  -            return null;
  +            return ConversionResult.create("float");
           }
       }
   
  
  
  
  1.2       +5 -5      cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/FormattingIntegerConvertor.java
  
  Index: FormattingIntegerConvertor.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/FormattingIntegerConvertor.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FormattingIntegerConvertor.java	9 Mar 2004 10:34:06 -0000	1.1
  +++ FormattingIntegerConvertor.java	6 May 2004 14:59:44 -0000	1.2
  @@ -36,16 +36,16 @@
           super();
       }
   
  -    public Object convertFromString(String value, Locale locale, Convertor.FormatCache
formatCache) {
  +    public ConversionResult convertFromString(String value, Locale locale, Convertor.FormatCache
formatCache) {
           DecimalFormat decimalFormat = getDecimalFormat(locale, formatCache);
           try {
               Number decimalValue = decimalFormat.parse(value);
               if (decimalValue instanceof Integer)
  -                return decimalValue;
  +                return new ConversionResult(decimalValue);
               else
  -                return new Integer(decimalValue.intValue());
  +                return new ConversionResult(new Integer(decimalValue.intValue()));
           } catch (ParseException e) {
  -            return null;
  +            return ConversionResult.create("integer");
           }
       }
   
  
  
  
  1.2       +5 -5      cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/FormattingLongConvertor.java
  
  Index: FormattingLongConvertor.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/FormattingLongConvertor.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FormattingLongConvertor.java	9 Mar 2004 10:34:06 -0000	1.1
  +++ FormattingLongConvertor.java	6 May 2004 14:59:44 -0000	1.2
  @@ -35,16 +35,16 @@
           super();
       }
   
  -    public Object convertFromString(String value, Locale locale, Convertor.FormatCache
formatCache) {
  +    public ConversionResult convertFromString(String value, Locale locale, Convertor.FormatCache
formatCache) {
           DecimalFormat decimalFormat = getDecimalFormat(locale, formatCache);
           try {
               Number decimalValue = decimalFormat.parse(value);
               if (decimalValue instanceof Long)
  -                return decimalValue;
  +                return new ConversionResult(decimalValue);
               else
  -                return new Long(decimalValue.longValue());
  +                return new ConversionResult(new Long(decimalValue.longValue()));
           } catch (ParseException e) {
  -            return null;
  +            return ConversionResult.create("long");
           }
       }
   
  
  
  
  1.3       +4 -4      cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/MillisDateConvertor.java
  
  Index: MillisDateConvertor.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/MillisDateConvertor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MillisDateConvertor.java	10 Apr 2004 13:40:27 -0000	1.2
  +++ MillisDateConvertor.java	6 May 2004 14:59:44 -0000	1.3
  @@ -28,12 +28,12 @@
    * @version CVS $Id$
    */
   public class MillisDateConvertor implements Convertor {
  -    public Object convertFromString(String value, Locale locale, Convertor.FormatCache
formatCache) {
  +    public ConversionResult convertFromString(String value, Locale locale, Convertor.FormatCache
formatCache) {
           try {
               long date = Long.parseLong(value);
  -            return new Date(date);
  +            return new ConversionResult(new Date(date));
           } catch (NumberFormatException e) {
  -            return null;
  +            return ConversionResult.create("date");
           }
       }
   
  
  
  
  1.3       +3 -3      cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/PlainBooleanConvertor.java
  
  Index: PlainBooleanConvertor.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/PlainBooleanConvertor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PlainBooleanConvertor.java	10 Apr 2004 13:40:27 -0000	1.2
  +++ PlainBooleanConvertor.java	6 May 2004 14:59:44 -0000	1.3
  @@ -26,8 +26,8 @@
    * @version CVS $Id$
    */
   public class PlainBooleanConvertor implements Convertor {
  -    public Object convertFromString(String value, Locale locale, Convertor.FormatCache
formatCache) {
  -        return Boolean.valueOf(value);
  +    public ConversionResult convertFromString(String value, Locale locale, Convertor.FormatCache
formatCache) {
  +        return new ConversionResult(Boolean.valueOf(value));
       }
   
       public String convertToString(Object value, Locale locale, Convertor.FormatCache formatCache)
{
  
  
  
  1.3       +4 -4      cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/PlainDecimalConvertor.java
  
  Index: PlainDecimalConvertor.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/PlainDecimalConvertor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PlainDecimalConvertor.java	10 Apr 2004 13:40:27 -0000	1.2
  +++ PlainDecimalConvertor.java	6 May 2004 14:59:44 -0000	1.3
  @@ -28,11 +28,11 @@
    * @version CVS $Id$
    */
   public class PlainDecimalConvertor implements Convertor {
  -    public Object convertFromString(String value, Locale locale, Convertor.FormatCache
formatCache) {
  +    public ConversionResult convertFromString(String value, Locale locale, Convertor.FormatCache
formatCache) {
           try {
  -            return new BigDecimal(value);
  +            return new ConversionResult(new BigDecimal(value));
           } catch (NumberFormatException e) {
  -            return null;
  +            return ConversionResult.create("decimal");
           }
       }
   
  
  
  
  1.3       +4 -4      cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/PlainDoubleConvertor.java
  
  Index: PlainDoubleConvertor.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/PlainDoubleConvertor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PlainDoubleConvertor.java	10 Apr 2004 13:40:27 -0000	1.2
  +++ PlainDoubleConvertor.java	6 May 2004 14:59:44 -0000	1.3
  @@ -27,11 +27,11 @@
    * @version CVS $Id$
    */
   public class PlainDoubleConvertor implements Convertor {
  -    public Object convertFromString(String value, Locale locale, Convertor.FormatCache
formatCache) {
  +    public ConversionResult convertFromString(String value, Locale locale, Convertor.FormatCache
formatCache) {
           try {
  -            return new Double(Double.parseDouble(value));
  +            return new ConversionResult(new Double(Double.parseDouble(value)));
           } catch (NumberFormatException e) {
  -            return null;
  +            return ConversionResult.create("double");
           }
       }
   
  
  
  
  1.3       +4 -4      cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/PlainFloatConvertor.java
  
  Index: PlainFloatConvertor.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/PlainFloatConvertor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PlainFloatConvertor.java	10 Apr 2004 13:40:27 -0000	1.2
  +++ PlainFloatConvertor.java	6 May 2004 14:59:44 -0000	1.3
  @@ -27,11 +27,11 @@
    * @version CVS $Id$
    */
   public class PlainFloatConvertor implements Convertor {
  -    public Object convertFromString(String value, Locale locale, Convertor.FormatCache
formatCache) {
  +    public ConversionResult convertFromString(String value, Locale locale, Convertor.FormatCache
formatCache) {
           try {
  -            return new Float(value);
  +            return new ConversionResult(new Float(value));
           } catch (NumberFormatException e) {
  -            return null;
  +            return ConversionResult.create("float");
           }
       }
   
  
  
  
  1.3       +4 -4      cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/PlainIntegerConvertor.java
  
  Index: PlainIntegerConvertor.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/PlainIntegerConvertor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PlainIntegerConvertor.java	10 Apr 2004 13:40:27 -0000	1.2
  +++ PlainIntegerConvertor.java	6 May 2004 14:59:44 -0000	1.3
  @@ -28,11 +28,11 @@
    * @version CVS $Id$ 
    */
   public class PlainIntegerConvertor implements Convertor {
  -    public Object convertFromString(String value, Locale locale, Convertor.FormatCache
formatCache) {
  +    public ConversionResult convertFromString(String value, Locale locale, Convertor.FormatCache
formatCache) {
           try {
  -            return new Integer(Integer.parseInt(value));
  +            return new ConversionResult(new Integer(Integer.parseInt(value)));
           } catch (NumberFormatException e) {
  -            return null;
  +            return ConversionResult.create("integer");
           }
       }
   
  
  
  
  1.3       +4 -4      cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/PlainLongConvertor.java
  
  Index: PlainLongConvertor.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/PlainLongConvertor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PlainLongConvertor.java	10 Apr 2004 13:40:27 -0000	1.2
  +++ PlainLongConvertor.java	6 May 2004 14:59:44 -0000	1.3
  @@ -27,11 +27,11 @@
    * @version CVS $Id$
    */
   public class PlainLongConvertor implements Convertor {
  -    public Object convertFromString(String value, Locale locale, Convertor.FormatCache
formatCache) {
  +    public ConversionResult convertFromString(String value, Locale locale, Convertor.FormatCache
formatCache) {
           try {
  -            return new Long(Long.parseLong(value));
  +            return new ConversionResult(new Long(Long.parseLong(value)));
           } catch (NumberFormatException e) {
  -            return null;
  +            return ConversionResult.create("long");
           }
       }
   
  
  
  
  1.5       +3 -2      cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/typeimpl/AbstractDatatype.java
  
  Index: AbstractDatatype.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/typeimpl/AbstractDatatype.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AbstractDatatype.java	10 Apr 2004 13:40:27 -0000	1.4
  +++ AbstractDatatype.java	6 May 2004 14:59:44 -0000	1.5
  @@ -24,6 +24,7 @@
   import org.apache.cocoon.forms.datatype.DatatypeBuilder;
   import org.apache.cocoon.forms.datatype.ValidationRule;
   import org.apache.cocoon.forms.datatype.convertor.Convertor;
  +import org.apache.cocoon.forms.datatype.convertor.ConversionResult;
   import org.apache.cocoon.forms.validation.ValidationError;
   import org.apache.cocoon.forms.Constants;
   import org.apache.cocoon.xml.AttributesImpl;
  @@ -85,7 +86,7 @@
           return convertor;
       }
   
  -    public Object convertFromString(String value, Locale locale) {
  +    public ConversionResult convertFromString(String value, Locale locale) {
           return getConvertor().convertFromString(value, locale, null);
       }
   
  
  
  
  1.15      +6 -9      cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Field.java
  
  Index: Field.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Field.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- Field.java	30 Apr 2004 12:23:33 -0000	1.14
  +++ Field.java	6 May 2004 14:59:44 -0000	1.15
  @@ -19,6 +19,7 @@
   import org.apache.cocoon.forms.FormContext;
   import org.apache.cocoon.forms.datatype.Datatype;
   import org.apache.cocoon.forms.datatype.SelectionList;
  +import org.apache.cocoon.forms.datatype.convertor.ConversionResult;
   import org.apache.cocoon.forms.event.*;
   import org.apache.cocoon.forms.util.I18nMessage;
   import org.apache.cocoon.forms.validation.ValidationError;
  @@ -82,17 +83,13 @@
               this.value = null;
               if (this.enteredValue != null) {
                   // Parse the value
  -                this.value = getDatatype().convertFromString(this.enteredValue, getForm().getLocale());
  -                if (this.value != null) {       // Conversion successfull
  +                ConversionResult conversionResult = getDatatype().convertFromString(this.enteredValue,
getForm().getLocale());
  +                if (conversionResult.isSuccessful()) {
  +                    this.value = conversionResult.getResult();
                       this.needsParse = false;
                       this.needsValidate = true;
                   } else {        // Conversion failed
  -                    this.validationError = new ValidationError(new I18nMessage(
  -                        "datatype.conversion-failed",
  -                        new String[] {"datatype." + getDatatype().getDescriptiveName()},
  -                        new boolean[] { true },
  -                        Constants.I18N_CATALOGUE
  -                    ));
  +                    this.validationError = conversionResult.getValidationError();
                       // No need for further validation (and need to keep the above error)
                       this.needsValidate = false;
                   }
  
  
  
  1.10      +6 -4      cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/MultiValueField.java
  
  Index: MultiValueField.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/MultiValueField.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- MultiValueField.java	30 Apr 2004 12:19:01 -0000	1.9
  +++ MultiValueField.java	6 May 2004 14:59:44 -0000	1.10
  @@ -20,6 +20,7 @@
   import org.apache.cocoon.forms.Constants;
   import org.apache.cocoon.forms.FormContext;
   import org.apache.cocoon.forms.datatype.SelectionList;
  +import org.apache.cocoon.forms.datatype.convertor.ConversionResult;
   import org.apache.cocoon.forms.event.ValueChangedEvent;
   import org.apache.cocoon.forms.event.WidgetEvent;
   import org.apache.cocoon.forms.util.I18nMessage;
  @@ -77,8 +78,10 @@
               Object[] tempValues = new Object[enteredValues.length];
               for (int i = 0; i < enteredValues.length; i++) {
                   String param = enteredValues[i];
  -                tempValues[i] = definition.getDatatype().convertFromString(param, formContext.getLocale());
  -                if (tempValues[i] == null) {
  +                ConversionResult conversionResult = definition.getDatatype().convertFromString(param,
formContext.getLocale());
  +                if (conversionResult.isSuccessful()) {
  +                    tempValues[i] = conversionResult.getResult();
  +                } else {
                       conversionFailed = true;
                       break;
                   }
  @@ -98,7 +101,6 @@
               validationError = definition.getDatatype().validate(values, new ExpressionContextImpl(this));
           else
               validationError = new ValidationError(new I18nMessage("multivaluefield.conversionfailed",
Constants.I18N_CATALOGUE));
  -
   
           return validationError == null ? super.validate() : false;
       }
  
  
  
  1.3       +3 -3      cocoon-2.1/src/blocks/forms/test/org/apache/cocoon/forms/datatype/convertor/EnumConvertorTestCase.java
  
  Index: EnumConvertorTestCase.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/test/org/apache/cocoon/forms/datatype/convertor/EnumConvertorTestCase.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- EnumConvertorTestCase.java	10 Mar 2004 09:13:22 -0000	1.2
  +++ EnumConvertorTestCase.java	6 May 2004 14:59:45 -0000	1.3
  @@ -38,9 +38,9 @@
        */
       public void testConvertFromString() {
           EnumConvertor convertor = new EnumConvertor("org.apache.cocoon.forms.datatype.Sex");
  -        Object sex = convertor.convertFromString
  +        ConversionResult conversionResult = convertor.convertFromString
               (Sex.class.getName() + ".FEMALE", Locale.getDefault(), null);
  -        assertSame("Returned sex must be FEMALE", Sex.FEMALE, sex);
  +        assertSame("Returned sex must be FEMALE", Sex.FEMALE, conversionResult.getResult());
       }
       
       /**
  
  
  

Mime
View raw message