[jboss-cvs] jboss-seam/src/main/org/jboss/seam ...

Gavin King gavin.king at jboss.com
Wed Jan 31 09:43:08 EST 2007


  User: gavin   
  Date: 07/01/31 09:43:08

  Modified:    src/main/org/jboss/seam  Component.java
  Log:
  handle arrays
  
  Revision  Changes    Path
  1.226     +23 -6     jboss-seam/src/main/org/jboss/seam/Component.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Component.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/Component.java,v
  retrieving revision 1.225
  retrieving revision 1.226
  diff -u -b -r1.225 -r1.226
  --- Component.java	28 Jan 2007 21:42:33 -0000	1.225
  +++ Component.java	31 Jan 2007 14:43:08 -0000	1.226
  @@ -29,6 +29,7 @@
   
   import java.io.Serializable;
   import java.lang.annotation.Annotation;
  +import java.lang.reflect.Array;
   import java.lang.reflect.Field;
   import java.lang.reflect.Method;
   import java.lang.reflect.Type;
  @@ -122,7 +123,7 @@
    *
    * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
    * @author Gavin King
  - * @version $Revision: 1.225 $
  + * @version $Revision: 1.226 $
    */
   @Scope(ScopeType.APPLICATION)
   @SuppressWarnings("deprecation")
  @@ -2083,12 +2084,16 @@
      {
         private InitialValue[] initialValues;
         private Class elementType;
  +      private boolean isArray;
   
         public ListInitialValue(PropertyValue propertyValue, Class collectionClass, Type collectionType)
         {
            String[] expressions = propertyValue.getMultiValues();
            initialValues = new InitialValue[expressions.length];
  -         elementType = Reflections.getCollectionElementType(collectionType);
  +         isArray = collectionClass.isArray();
  +         elementType = isArray ? 
  +                  collectionClass.getComponentType() : 
  +                  Reflections.getCollectionElementType(collectionType);
            for ( int i=0; i<expressions.length; i++ )
            {
               PropertyValue elementValue = new Conversions.FlatPropertyValue( expressions[i] );
  @@ -2098,12 +2103,24 @@
   
         public Object getValue(Class type)
         {
  -         List result = new ArrayList(initialValues.length);
  +         if (isArray)
  +         {
  +            Object array = Array.newInstance(elementType, initialValues.length);
  +            for (int i=0; i<initialValues.length; i++)
  +            {
  +               Array.set( array, i, initialValues[i].getValue(elementType) );
  +            }
  +            return array;
  +         }
  +         else
  +         {
  +            List list = new ArrayList(initialValues.length);
            for (InitialValue iv: initialValues)
            {
  -            result.add( iv.getValue(elementType) );
  +               list.add( iv.getValue(elementType) );
  +            }
  +            return list;
            }
  -         return result;
         }
         
         @Override
  
  
  



More information about the jboss-cvs-commits mailing list