Hi,

I have attached a patch for the Fulcrum Intake service that adds an option for populating mapped objects without overwriting an object's properties with default values. This behaviour is required for Scarab. Here's the log message:

---
At the moment, whenever Group.setProperties() is called on a mapped object
and a Field value is not set, the corresponding property on the object is
overwritten with a default value. This change adds two new methods that
allow Field values to be mapped to an object's properties without overwriting:

 Group.setPropertiesNoOverwrite()
 Field.setPropertyNoOverwrite()

Index: intake/src/java/org/apache/fulcrum/intake/model/Field.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-turbine-fulcrum/intake/src/java/org/apache/fulcrum/intake/model/Field.java,v
retrieving revision 1.6
diff -u -r1.6 Field.java
--- intake/src/java/org/apache/fulcrum/intake/model/Field.java  1 Jul 2004 
11:30:50 -0000       1.6
+++ intake/src/java/org/apache/fulcrum/intake/model/Field.java  20 Aug 2005 
16:51:37 -0000
@@ -888,6 +888,57 @@
     }
 
     /**
+     * Checks whether the field has been set, and if so updates the
+     * corresponding property on the given object. If this field is
+     * <b>not</b> set, then the object is left unmodified.
+     *
+     * @throws IntakeException indicates a problem during the execution of the
+     * object's setter method
+     */
+    public void setPropertyNoOverwrite(Object obj) throws IntakeException
+    {
+        if (isDebugEnabled)
+        {
+            log.debug(name + ".setProperty(" + obj.getClass().getName() + ")");
+        }
+
+        if (!isValid())
+        {
+            throw new IntakeException(
+                    "Attempted to assign an invalid input.");
+        }
+        if (isSet())
+        {
+            valArray[0] = getTestValue();
+
+            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);
+            }
+
+            if (isDebugEnabled)
+            {
+                log.debug(name + ": Property is set, value is " + valArray[0]);
+            }
+        }
+    }
+    
+    /**
      * Used to throw an IntakeException when an error occurs execuing the
      * get/set method of the mapped persistent object.
      *
Index: intake/src/java/org/apache/fulcrum/intake/model/Group.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-turbine-fulcrum/intake/src/java/org/apache/fulcrum/intake/model/Group.java,v
retrieving revision 1.2
diff -u -r1.2 Group.java
--- intake/src/java/org/apache/fulcrum/intake/model/Group.java  1 Jul 2004 
11:30:50 -0000       1.2
+++ intake/src/java/org/apache/fulcrum/intake/model/Group.java  20 Aug 2005 
16:51:38 -0000
@@ -372,6 +372,41 @@
     }
 
     /**
+     * Updates the properties on the given object with values
+     * from this group's fields. If a particular field has not
+     * been set, this method (unlike [EMAIL PROTECTED] #setProperties})
+     * will not change the associated property on the object.
+     *
+     * @param obj Object to be set with the values from the group.
+     * @throws IntakeException indicates that a failure occurred while
+     * executing the setter methods of the mapped object.
+     */
+    public void setPropertiesNoOverwrite(Object obj) throws IntakeException
+    {
+        Class cls = obj.getClass();
+
+        while (cls != null)
+        {
+            if (isDebugEnabled)
+            {
+                log.debug("setProperties(" + cls.getName() + ")");
+            }
+
+            Field[] flds = (Field[]) mapToObjectFields.get(cls.getName());
+            if (flds != null)
+            {
+                for (int i = flds.length - 1; i >= 0; i--)
+                {
+                    flds[i].setPropertyNoOverwrite(obj);
+                }
+            }
+
+            cls = cls.getSuperclass();
+        }
+        log.debug("setProperties() finished");
+    }
+
+    /**
      * Calls a setter methods on obj, for fields which pass validity tests.
      * In most cases one should call Intake.isAllValid() and then if that
      * test passes call setProperties.  Use this method when some data is

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

Reply via email to