seade       2003/11/09 20:05:42

  Modified:    intake/src/java/org/apache/fulcrum/intake/model
                        FloatField.java DoubleField.java BooleanField.java
                        LongField.java Field.java IntegerField.java
                        ShortField.java
               intake/xdocs changes.xml
  Log:
  Porting changes from Turbine: 
  
    Make use of the emptyValue attribute on the field element when no value has been 
set.  This makes it possible to clear values in an existing object that is being 
overwritten with Intake data using group.setProperties(obj).
  
    Ensure an NPE does not occur when emptyValue is used to set an object's primitive 
properties.
  
  Revision  Changes    Path
  1.2       +17 -1     
jakarta-turbine-fulcrum/intake/src/java/org/apache/fulcrum/intake/model/FloatField.java
  
  Index: FloatField.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-fulcrum/intake/src/java/org/apache/fulcrum/intake/model/FloatField.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FloatField.java   26 Sep 2003 13:52:25 -0000      1.1
  +++ FloatField.java   10 Nov 2003 04:05:41 -0000      1.2
  @@ -67,6 +67,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]>John McNally</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Henning P. Schmiedehausen</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Quinton McCombs</a>
  + * @author <a href="mailto:[EMAIL PROTECTED]">Scott Eade</a>
    * @version $Id$
    */
   public class FloatField
  @@ -121,6 +122,21 @@
           }
   
           emptyValue = new Double(prop);
  +    }
  +
  +    /**
  +     * Provides access to emptyValue such that the value returned will be 
  +     * acceptable as an argument parameter to Method.invoke.  Subclasses
  +     * that deal with primitive types should ensure that they return an 
  +     * appropriate value wrapped in the object wrapper class for the 
  +     * primitive type.
  +     *   
  +     * @return the value to use when the field is empty or an Object that
  +     * wraps the empty value for primitive types.
  +     */
  +    protected Object getSafeEmptyValue()
  +    {
  +        return (null == getEmptyValue()) ? new Float(0.0) : getEmptyValue(); 
       }
   
       /**
  
  
  
  1.2       +17 -1     
jakarta-turbine-fulcrum/intake/src/java/org/apache/fulcrum/intake/model/DoubleField.java
  
  Index: DoubleField.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-fulcrum/intake/src/java/org/apache/fulcrum/intake/model/DoubleField.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DoubleField.java  26 Sep 2003 13:52:25 -0000      1.1
  +++ DoubleField.java  10 Nov 2003 04:05:41 -0000      1.2
  @@ -64,6 +64,7 @@
    * Creates Double Field objects.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Quinton McCombs</a>
  + * @author <a href="mailto:[EMAIL PROTECTED]">Scott Eade</a>
    * @version $Id$
    */
   public class DoubleField
  @@ -117,6 +118,21 @@
           }
   
           emptyValue = new Double(prop);
  +    }
  +
  +    /**
  +     * Provides access to emptyValue such that the value returned will be 
  +     * acceptable as an argument parameter to Method.invoke.  Subclasses
  +     * that deal with primitive types should ensure that they return an 
  +     * appropriate value wrapped in the object wrapper class for the 
  +     * primitive type.
  +     *   
  +     * @return the value to use when the field is empty or an Object that
  +     * wraps the empty value for primitive types.
  +     */
  +    protected Object getSafeEmptyValue()
  +    {
  +        return (null == getEmptyValue()) ? new Double(0.0) : getEmptyValue(); 
       }
   
       /**
  
  
  
  1.2       +17 -1     
jakarta-turbine-fulcrum/intake/src/java/org/apache/fulcrum/intake/model/BooleanField.java
  
  Index: BooleanField.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-fulcrum/intake/src/java/org/apache/fulcrum/intake/model/BooleanField.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BooleanField.java 26 Sep 2003 13:52:25 -0000      1.1
  +++ BooleanField.java 10 Nov 2003 04:05:41 -0000      1.2
  @@ -67,6 +67,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]">John McNally</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Henning P. Schmiedehausen</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Quinton McCombs</a>
  + * @author <a href="mailto:[EMAIL PROTECTED]">Scott Eade</a>
    * @version $Id$
    */
   public class BooleanField
  @@ -113,6 +114,21 @@
           }
   
           emptyValue = new Boolean(prop);
  +    }
  +
  +    /**
  +     * Provides access to emptyValue such that the value returned will be 
  +     * acceptable as an argument parameter to Method.invoke.  Subclasses
  +     * that deal with primitive types should ensure that they return an 
  +     * appropriate value wrapped in the object wrapper class for the 
  +     * primitive type.
  +     *   
  +     * @return the value to use when the field is empty or an Object that
  +     * wraps the empty value for primitive types.
  +     */
  +    protected Object getSafeEmptyValue()
  +    {
  +        return (null == getEmptyValue()) ? Boolean.FALSE : getEmptyValue(); 
       }
   
       /**
  
  
  
  1.2       +17 -1     
jakarta-turbine-fulcrum/intake/src/java/org/apache/fulcrum/intake/model/LongField.java
  
  Index: LongField.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-fulcrum/intake/src/java/org/apache/fulcrum/intake/model/LongField.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LongField.java    26 Sep 2003 13:52:25 -0000      1.1
  +++ LongField.java    10 Nov 2003 04:05:41 -0000      1.2
  @@ -65,6 +65,7 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]>John McNally</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Colin Chalmers</a>
  + * @author <a href="mailto:[EMAIL PROTECTED]">Scott Eade</a>
    * @version $Id$
    */
   public class LongField
  @@ -119,6 +120,21 @@
           }
   
           emptyValue = new Long(prop);
  +    }
  +
  +    /**
  +     * Provides access to emptyValue such that the value returned will be 
  +     * acceptable as an argument parameter to Method.invoke.  Subclasses
  +     * that deal with primitive types should ensure that they return an 
  +     * appropriate value wrapped in the object wrapper class for the 
  +     * primitive type.
  +     *   
  +     * @return the value to use when the field is empty or an Object that
  +     * wraps the empty value for primitive types.
  +     */
  +    protected Object getSafeEmptyValue()
  +    {
  +        return (null == getEmptyValue()) ? new Long(0l) : getEmptyValue(); 
       }
   
       /**
  
  
  
  1.4       +38 -24    
jakarta-turbine-fulcrum/intake/src/java/org/apache/fulcrum/intake/model/Field.java
  
  Index: Field.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-fulcrum/intake/src/java/org/apache/fulcrum/intake/model/Field.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Field.java        10 Nov 2003 03:49:37 -0000      1.3
  +++ Field.java        10 Nov 2003 04:05:41 -0000      1.4
  @@ -625,7 +625,6 @@
                   }
               }
   
  -
               if (validator != null)
               {
                   // set the test value as a String[] which might be replaced by
  @@ -889,39 +888,39 @@
           if (isSet())
           {
               valArray[0] = getTestValue();
  -
               if (isDebugEnabled)
               {
                   log.debug(name + ": Property is set, value is " + valArray[0]);
               }
  -
  -            try
  -            {
  -                setter.invoke(obj, valArray);
  -            }
  -            catch (IllegalAccessException e)
  -            {
  -                throwSetGetException("setter", obj, this.getDisplayName(),
  -                        this.group.getIntakeGroupName(), e);
  -            }
  -            catch (IllegalArgumentException e)
  -            {
  -                throwSetGetException("setter", obj, this.getDisplayName(),
  -                        this.group.getIntakeGroupName(), e);
  -            }
  -            catch (InvocationTargetException e)
  -            {
  -                throwSetGetException("setter", obj, this.getDisplayName(),
  -                        this.group.getIntakeGroupName(), e);
  -            }
           }
           else
           {
  +            valArray[0] = getSafeEmptyValue();
               if (isDebugEnabled)
               {
  -                log.debug(name+ ": Property is not set, skipping");
  +                log.debug(name + ": Property is not set, using emptyValue " + 
valArray[0]);
               }
           }
  +
  +        try
  +        {
  +            setter.invoke(obj, valArray);
  +        }
  +        catch (IllegalAccessException e)
  +        {
  +            throwSetGetException("setter", obj, this.getDisplayName(),
  +                    this.group.getIntakeGroupName(), e);
  +        }
  +        catch (IllegalArgumentException e)
  +        {
  +            throwSetGetException("setter", obj, this.getDisplayName(),
  +                    this.group.getIntakeGroupName(), e);
  +        }
  +        catch (InvocationTargetException e)
  +        {
  +            throwSetGetException("setter", obj, this.getDisplayName(),
  +                    this.group.getIntakeGroupName(), e);
  +        }
       }
   
       /**
  @@ -963,6 +962,21 @@
       public Object getEmptyValue()
       {
           return emptyValue;
  +    }
  +
  +    /**
  +     * Provides access to emptyValue such that the value returned will be 
  +     * acceptable as an argument parameter to Method.invoke.  Subclasses
  +     * that deal with primitive types should ensure that they return an 
  +     * appropriate value wrapped in the object wrapper class for the 
  +     * primitive type.
  +     *   
  +     * @return the value to use when the field is empty or an Object that
  +     * wraps the empty value for primitive types.
  +     */
  +    protected Object getSafeEmptyValue()
  +    {
  +        return getEmptyValue();
       }
   
       /**
  
  
  
  1.2       +17 -1     
jakarta-turbine-fulcrum/intake/src/java/org/apache/fulcrum/intake/model/IntegerField.java
  
  Index: IntegerField.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-fulcrum/intake/src/java/org/apache/fulcrum/intake/model/IntegerField.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- IntegerField.java 26 Sep 2003 13:52:25 -0000      1.1
  +++ IntegerField.java 10 Nov 2003 04:05:41 -0000      1.2
  @@ -64,6 +64,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]">John McNally</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Henning P. Schmiedehausen</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Quinton McCombs</a>
  + * @author <a href="mailto:[EMAIL PROTECTED]">Scott Eade</a>
    * @version $Id$
    */
   public class IntegerField
  @@ -118,6 +119,21 @@
           }
   
           emptyValue = new Integer(prop);
  +    }
  +
  +    /**
  +     * Provides access to emptyValue such that the value returned will be 
  +     * acceptable as an argument parameter to Method.invoke.  Subclasses
  +     * that deal with primitive types should ensure that they return an 
  +     * appropriate value wrapped in the object wrapper class for the 
  +     * primitive type.
  +     *   
  +     * @return the value to use when the field is empty or an Object that
  +     * wraps the empty value for primitive types.
  +     */
  +    protected Object getSafeEmptyValue()
  +    {
  +        return (null == getEmptyValue()) ? new Integer(0) : getEmptyValue(); 
       }
   
       /**
  
  
  
  1.2       +18 -1     
jakarta-turbine-fulcrum/intake/src/java/org/apache/fulcrum/intake/model/ShortField.java
  
  Index: ShortField.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-fulcrum/intake/src/java/org/apache/fulcrum/intake/model/ShortField.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ShortField.java   26 Sep 2003 13:52:25 -0000      1.1
  +++ ShortField.java   10 Nov 2003 04:05:41 -0000      1.2
  @@ -65,6 +65,7 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]>John McNally</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Colin Chalmers</a>
  + * @author <a href="mailto:[EMAIL PROTECTED]">Scott Eade</a>
    * @version $Id$
    */
   public class ShortField
  @@ -119,6 +120,22 @@
           }
   
           emptyValue = new Short(prop);
  +    }
  +
  +    /**
  +     * Provides access to emptyValue such that the value returned will be 
  +     * acceptable as an argument parameter to Method.invoke.  Subclasses
  +     * that deal with primitive types should ensure that they return an 
  +     * appropriate value wrapped in the object wrapper class for the 
  +     * primitive type.
  +     *   
  +     * @return the value to use when the field is empty or an Object that
  +     * wraps the empty value for primitive types.
  +     */
  +    protected Object getSafeEmptyValue()
  +    {
  +        return (null == getEmptyValue()) 
  +                ? new Short((short) 0) : getEmptyValue(); 
       }
   
       /**
  
  
  
  1.5       +11 -0     jakarta-turbine-fulcrum/intake/xdocs/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-fulcrum/intake/xdocs/changes.xml,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- changes.xml       10 Nov 2003 03:49:37 -0000      1.4
  +++ changes.xml       10 Nov 2003 04:05:42 -0000      1.5
  @@ -31,6 +31,17 @@
          <em>$group.foo.StringValue</em> rather than <em>$group.foo.Value</em> 
          (you can do this for all values, not just DateString).
         </action>
  +      <action>
  +       Intake now makes use of the the emptyValue attribute from the field 
  +       elements when mapping from the group to the object when no value has 
  +       been set.  This makes it possible to clear values in an existing object
  +       that is being overwritten with Intake data using 
  +       <em>group.setProperties(obj)</em> (or you can provide non-null values
  +       in your intake.xml file).  Make sure you do not inadvertently include 
  +       the primary key for the object in the intake group without actually 
  +       setting it to the appropriate value (it shouldn't be in the group 
  +       anyway).
  +      </action>
        
       </release>
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to