[seam-commits] Seam SVN: r13539 - modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Sun Aug 1 06:07:25 EDT 2010


Author: swd847
Date: 2010-08-01 06:07:24 -0400 (Sun, 01 Aug 2010)
New Revision: 13539

Modified:
   modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/ArrayFieldSet.java
   modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/CollectionFieldSet.java
   modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/MapFieldSet.java
   modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/SimpleFieldValue.java
Log:
more refactoring



Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/ArrayFieldSet.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/ArrayFieldSet.java	2010-08-01 09:50:28 UTC (rev 13538)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/ArrayFieldSet.java	2010-08-01 10:07:24 UTC (rev 13539)
@@ -41,28 +41,18 @@
 public class ArrayFieldSet implements FieldValueObject
 {
    final private Property field;
-   final private List<AFS> values;
+   final private List<Object> values;
    final private Class<?> arrayType;
 
    public ArrayFieldSet(Property<?> field, List<ValueXmlItem> items)
    {
       this.field = field;
-      this.values = new ArrayList<AFS>();
-
+      this.values = new ArrayList<Object>();
       arrayType = field.getJavaClass().getComponentType();
-      AFS setter;
       for (XmlItem i : items)
       {
-         final Object fv = XmlObjectConverter.convert(arrayType, i.getInnerText());
-         final Object val = fv;
-         setter = new AFS()
-         {
-            public void set(Object o, int i) throws IllegalAccessException
-            {
-               Array.set(o, i, val);
-            }
-         };
-         values.add(setter);
+         Object fv = XmlObjectConverter.convert(arrayType, i.getInnerText());
+         values.add(fv);
       }
 
    }
@@ -75,7 +65,7 @@
          field.setValue(instance, array);
          for (int i = 0; i < values.size(); ++i)
          {
-            values.get(i).set(array, i);
+            Array.set(array, i, values.get(i));
          }
       }
       catch (Exception e)
@@ -83,10 +73,4 @@
          throw new RuntimeException(e);
       }
    }
-
-   interface AFS
-   {
-      void set(Object o, int i) throws IllegalAccessException;
-   }
-
 }

Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/CollectionFieldSet.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/CollectionFieldSet.java	2010-08-01 09:50:28 UTC (rev 13538)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/CollectionFieldSet.java	2010-08-01 10:07:24 UTC (rev 13539)
@@ -53,14 +53,14 @@
 public class CollectionFieldSet implements FieldValueObject
 {
    private final Property field;
-   private final List<CFS> values;
+   private final List<Object> values;
    private final Class<?> elementType;
    private final Class<? extends Collection> collectionType;
 
    public CollectionFieldSet(Property field, List<ValueXmlItem> items)
    {
       this.field = field;
-      this.values = new ArrayList<CFS>();
+      this.values = new ArrayList<Object>();
 
       Type type = field.getBaseType();
       if (type instanceof ParameterizedType)
@@ -114,22 +114,11 @@
          throw new RuntimeException("Could not determine element type for " + field.getDeclaringClass().getName() + "." + field.getName());
       }
 
-      CFS setter;
       for (XmlItem i : items)
       {
          final Object fv = XmlObjectConverter.convert(elementType, i.getInnerText());
-
-         setter = new CFS()
-         {
-            public void add(Collection<Object> o) throws IllegalAccessException
-            {
-               o.add(fv);
-            }
-         };
-
-         values.add(setter);
+         values.add(fv);
       }
-
    }
 
    public void setValue(Object instance, CreationalContext<?> ctx)
@@ -140,7 +129,7 @@
          field.setValue(instance, res);
          for (int i = 0; i < values.size(); ++i)
          {
-            values.get(i).add(res);
+            res.add(values.get(i));
          }
       }
       catch (Exception e)
@@ -149,9 +138,4 @@
       }
    }
 
-   interface CFS
-   {
-      void add(Collection<Object> o) throws IllegalAccessException;
-   }
-
 }

Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/MapFieldSet.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/MapFieldSet.java	2010-08-01 09:50:28 UTC (rev 13538)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/MapFieldSet.java	2010-08-01 10:07:24 UTC (rev 13539)
@@ -30,6 +30,7 @@
 import java.util.Map;
 import java.util.SortedMap;
 import java.util.TreeMap;
+import java.util.Map.Entry;
 
 import javax.enterprise.context.spi.CreationalContext;
 
@@ -48,7 +49,7 @@
 public class MapFieldSet implements FieldValueObject
 {
    private final Property field;
-   private final List<MFS> values;
+   private final List<Entry<Object, Object>> values;
    private final Class<?> keyType;
    private final Class<?> valueType;
    private final Class<? extends Map> collectionType;
@@ -56,7 +57,7 @@
    public MapFieldSet(Property field, List<EntryXmlItem> items)
    {
       this.field = field;
-      this.values = new ArrayList<MFS>();
+      this.values = new ArrayList<Entry<Object, Object>>();
       // figure out the collection type
       Type type = field.getBaseType();
       if (type instanceof ParameterizedType)
@@ -98,28 +99,12 @@
 
       for (EntryXmlItem i : items)
       {
-         MFS setter;
          final Object key = XmlObjectConverter.convert(keyType, i.getKey().getInnerText());
          final Object value = XmlObjectConverter.convert(valueType, i.getValue().getInnerText());
-         setter = new MFS()
-         {
-            @SuppressWarnings("unchecked")
-            public void add(Map m) throws IllegalAccessException
-            {
-               m.put(key, value);
-            }
-         };
-
-         values.add(setter);
+         values.add(new EntryImpl(key, value));
       }
-
    }
 
-   public void discoverElementType()
-   {
-
-   }
-
    public void setValue(Object instance, CreationalContext<?> ctx)
    {
       try
@@ -128,7 +113,8 @@
          field.setValue(instance, res);
          for (int i = 0; i < values.size(); ++i)
          {
-            values.get(i).add(res);
+            Entry<Object, Object> e = values.get(i);
+            res.put(e.getKey(), e.getValue());
          }
       }
       catch (Exception e)
@@ -137,9 +123,34 @@
       }
    }
 
-   interface MFS
+   private final class EntryImpl implements Entry<Object, Object>
    {
-      void add(Map<?, ?> o) throws IllegalAccessException;
+      private Object key, value;
+
+      public EntryImpl(Object key, Object value)
+      {
+         this.key = key;
+         this.value = value;
+      }
+
+      public Object getKey()
+      {
+         return key;
+      }
+
+      public Object getValue()
+      {
+         return value;
+      }
+
+      public Object setValue(Object value)
+      {
+         return this.value = value;
+      }
+
+      public void setKey(Object key)
+      {
+         this.key = key;
+      }
    }
-
 }

Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/SimpleFieldValue.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/SimpleFieldValue.java	2010-08-01 09:50:28 UTC (rev 13538)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/SimpleFieldValue.java	2010-08-01 10:07:24 UTC (rev 13539)
@@ -21,12 +21,8 @@
  */
 package org.jboss.seam.xml.fieldset;
 
-import java.lang.reflect.InvocationTargetException;
-
 import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.inject.spi.BeanManager;
 
-import org.jboss.seam.xml.model.ModelBuilder;
 import org.jboss.seam.xml.util.XmlObjectConverter;
 import org.jboss.weld.extensions.util.properties.Property;
 
@@ -35,46 +31,23 @@
 
    private final Property field;
 
-   private final FS setter;
+   private final Object value;
 
    public SimpleFieldValue(Class<?> javaObject, final Property f, final String value)
    {
       this.field = f;
-
-      Object fv = XmlObjectConverter.convert(f.getJavaClass(), value);
-
-      final Object val = fv;
-      setter = new FS()
-      {
-         public void set(Object o) throws IllegalAccessException, InvocationTargetException
-         {
-            field.setValue(o, val);
-         }
-      };
-
+      this.value = XmlObjectConverter.convert(f.getJavaClass(), value);
    }
 
-   interface FS
-   {
-      void set(Object o) throws IllegalAccessException, InvocationTargetException;
-   }
-
    public void setValue(Object instance, CreationalContext<?> ctx)
    {
       try
       {
-         setter.set(instance);
+         field.setValue(instance, value);
       }
       catch (Exception e)
       {
          throw new RuntimeException(e);
       }
    }
-
-   public void initalize(ModelBuilder modelBuilder, BeanManager manager)
-   {
-      // TODO Auto-generated method stub
-
-   }
-
 }



More information about the seam-commits mailing list