[jboss-svn-commits] JBL Code SVN: r22807 - in labs/jbossesb/workspace/skeagh/runtime/src: test/java/org/jboss/esb/deploy/config/digest and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Sep 16 07:26:13 EDT 2008


Author: beve
Date: 2008-09-16 07:26:13 -0400 (Tue, 16 Sep 2008)
New Revision: 22807

Modified:
   labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/digest/CreateObject.java
   labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/digest/SetProperty.java
   labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/deploy/config/digest/SetPropertyTest.java
Log:
Fixed a bug in SetProperty


Modified: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/digest/CreateObject.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/digest/CreateObject.java	2008-09-16 10:55:07 UTC (rev 22806)
+++ labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/digest/CreateObject.java	2008-09-16 11:26:13 UTC (rev 22807)
@@ -25,7 +25,6 @@
 import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Properties;
 
 import org.apache.log4j.Logger;
 import org.jboss.esb.annotations.Property;
@@ -233,43 +232,6 @@
                     }
                 }
             }
-
-            org.jboss.esb.annotations.Properties propertiesAnno = field.getAnnotation(org.jboss.esb.annotations.Properties.class);
-            if (propertiesAnno != null)
-            {
-                removeFieldFromPropertiesField(instance, field, setFields);
-            }
         }
     }
-
-    /**
-     * Removes all the fieds that exist in the passed in setFields parameter.
-     * <p/>
-     * @param instance - the instance where the propretiesField exists.
-     * @param propertiesField - the properties field itself
-     * @param setFields - the list of field that are to be removed
-     */
-    private void removeFieldFromPropertiesField(final Object instance, final Field propertiesField, final List<Field> setFields)
-    {
-        try
-        {
-            if (Properties.class.isAssignableFrom(propertiesField.getType()))
-            {
-                final Properties properties = (Properties) ClassUtil.getFieldValue(propertiesField, instance);
-                if (properties != null)
-                {
-                    for (final Field field : setFields)
-                    {
-                        properties.remove(field.getName());
-                    }
-                    // now set the properties instance on the calass
-                    ClassUtil.setFieldValue(propertiesField, instance, properties);
-                }
-            }
-        }
-        catch (IllegalAccessException ignored)
-        {
-            log.error(ignored.getMessage(), ignored);
-        }
-    }
 }

Modified: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/digest/SetProperty.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/digest/SetProperty.java	2008-09-16 10:55:07 UTC (rev 22806)
+++ labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/digest/SetProperty.java	2008-09-16 11:26:13 UTC (rev 22807)
@@ -95,7 +95,10 @@
             try
             {
                 List<Field> fieldsList = FieldListAccessor.get(executionContext, beanId);
-                attemptAnnotationFieldSet(objectClass, instance, propertyName, value, fieldsList);
+                if (!attemptAnnotationFieldSet(objectClass, instance, propertyName, value, fieldsList))
+                {
+                    attemptAnnotationPropertySet(objectClass, instance, propertyName, value);
+                }
             }
             catch (final IllegalAccessException e)
             {
@@ -114,38 +117,58 @@
      * @param value              the value to set the field to
      * @throws IllegalAccessException if the field was not accessible.
      */
-    final void attemptAnnotationFieldSet(
+    final boolean attemptAnnotationFieldSet(
             final Class<?> clazz,
             final Object instance,
             final String configPropertyName,
             final String value,
             final List<Field> fieldsList) throws IllegalAccessException
     {
+        boolean fieldSet = false;
         final Class<?> superclass = clazz.getSuperclass();
         if (superclass != null)
         {
-            attemptAnnotationFieldSet(superclass, instance, configPropertyName, value, fieldsList);
+            fieldSet = attemptAnnotationFieldSet(superclass, instance, configPropertyName, value, fieldsList);
         }
 
-        for (Field field : clazz.getDeclaredFields())
+        if (!fieldSet)
         {
-            Property propertyAnno = field.getAnnotation(Property.class);
-
-            if (propertyAnno != null)
+            for (Field field : clazz.getDeclaredFields())
             {
-                final String fieldName = AnnotationConstants.NULL_STRING.equals(propertyAnno.name()) ? field.getName() : propertyAnno.name();
-
-                if (fieldName.equals(configPropertyName))
+                Property propertyAnno = field.getAnnotation(Property.class);
+                if (propertyAnno != null)
                 {
-                    fieldsList.add(field);
-                    assertValidChoice(propertyAnno.choice(), configPropertyName, value);
-                    setPropertyValue(field, instance, value == null ? propertyAnno.defaultVal() : value);
-                    break;
+                    final String fieldName = AnnotationConstants.NULL_STRING.equals(propertyAnno.name()) ? field.getName() : propertyAnno.name();
+                    if (fieldName.equals(configPropertyName))
+                    {
+                        fieldsList.add(field);
+                        assertValidChoice(propertyAnno.choice(), configPropertyName, value);
+                        setPropertyValue(field, instance, value == null ? propertyAnno.defaultVal() : value);
+                        fieldSet = true;
+                        break;
+                    }
                 }
             }
+        }
+        return fieldSet;
+    }
 
+    final void attemptAnnotationPropertySet(
+            final Class<?> clazz,
+            final Object instance,
+            final String configPropertyName,
+            final String value) throws IllegalAccessException
+    {
+        final Class<?> superclass = clazz.getSuperclass();
+        if (superclass != null)
+        {
+            attemptAnnotationPropertySet(superclass, instance, configPropertyName, value);
+        }
+
+        for (Field field : clazz.getDeclaredFields())
+        {
             org.jboss.esb.annotations.Properties propertiesAnno = field.getAnnotation(org.jboss.esb.annotations.Properties.class);
-            if (propertiesAnno != null && !fieldsList.contains(field))
+            if (propertiesAnno != null)
             {
                 attemptPropertiesFieldSet(instance, field, configPropertyName, value);
             }

Modified: labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/deploy/config/digest/SetPropertyTest.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/deploy/config/digest/SetPropertyTest.java	2008-09-16 10:55:07 UTC (rev 22806)
+++ labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/deploy/config/digest/SetPropertyTest.java	2008-09-16 11:26:13 UTC (rev 22807)
@@ -82,8 +82,8 @@
         final String expectedName = "Dr.Rosen";
 
         setProperty.attemptAnnotationFieldSet(pojo.getClass(), pojo , "userName", expectedName, fieldsSet);
-        setProperty.attemptAnnotationFieldSet(pojo.getClass(), pojo , propKey1, propValue1, fieldsSet);
-        setProperty.attemptAnnotationFieldSet(pojo.getClass(), pojo , propKey2, propValue2, fieldsSet);
+        setProperty.attemptAnnotationPropertySet(pojo.getClass(), pojo , propKey1, propValue1);
+        setProperty.attemptAnnotationPropertySet(pojo.getClass(), pojo , propKey2, propValue2);
 
         assertTrue(pojo.getProps().size() == 2 );
         assertTrue("Properties did not contain key: " + propKey1, pojo.getProps().containsKey(propKey1));
@@ -104,8 +104,8 @@
         final String expectedName = "Dr.Rosen";
 
         setProperty.attemptAnnotationFieldSet(pojo.getClass(), pojo , "userName", expectedName, fieldsSet);
-        setProperty.attemptAnnotationFieldSet(pojo.getClass(), pojo , propKey1, propValue1, fieldsSet);
-        setProperty.attemptAnnotationFieldSet(pojo.getClass(), pojo , propKey2, propValue2, fieldsSet);
+        setProperty.attemptAnnotationPropertySet(pojo.getClass(), pojo , propKey1, propValue1);
+        setProperty.attemptAnnotationPropertySet(pojo.getClass(), pojo , propKey2, propValue2);
 
         assertTrue(pojo.getProperties().size() == 2 );
         assertTrue("Properties did not contain key: " + propKey1, pojo.getProperties().containsKey(propKey1));




More information about the jboss-svn-commits mailing list