[jboss-cvs] JBossAS SVN: r81358 - projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/plugins/values.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Nov 20 07:40:07 EST 2008


Author: alesj
Date: 2008-11-20 07:40:07 -0500 (Thu, 20 Nov 2008)
New Revision: 81358

Modified:
   projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/plugins/values/DefaultMetaValueFactory.java
Log:
Optimize a bit.
Remove log, as we know what's the cause for JBMAN-38.

Modified: projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/plugins/values/DefaultMetaValueFactory.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/plugins/values/DefaultMetaValueFactory.java	2008-11-20 11:45:01 UTC (rev 81357)
+++ projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/plugins/values/DefaultMetaValueFactory.java	2008-11-20 12:40:07 UTC (rev 81358)
@@ -85,18 +85,16 @@
 
 /**
  * DefaultMetaValueFactory.
- * 
+ *
  * @author <a href="ales.justin at jboss.com">Ales Justin</a>
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
  * @version $Revision$
  */
 public class DefaultMetaValueFactory extends MetaValueFactory
 {
-   private static final Logger log = Logger.getLogger(DefaultMetaValueFactory.class);
-
    /** The metatype factory */
    private MetaTypeFactory metaTypeFactory = MetaTypeFactory.getInstance();
-   
+
    /** The configuration */
    private static Configuration configuration;
 
@@ -122,7 +120,7 @@
 
    /** The builders */
    private Map<Class<?>, WeakReference<MetaValueBuilder<?>>> builders = new WeakHashMap<Class<?>, WeakReference<MetaValueBuilder<?>>>();
- 
+
    /** The Object type info */
    private static final TypeInfo OBJECT_TYPE_INFO = configuration.getTypeInfo(Object.class);
 
@@ -160,7 +158,7 @@
 
    /**
     * Create a simple value
-    * 
+    *
     * @param type the type
     * @param value the value
     * @return the simple value
@@ -175,7 +173,7 @@
 
    /**
     * Create an enum value
-    * 
+    *
     * @param <T> the enum type
     * @param type the type
     * @param value the value
@@ -191,7 +189,7 @@
 
    /**
     * Create a generic value
-    * 
+    *
     * @param type the type
     * @param value the value
     * @param mapping the mapping
@@ -201,7 +199,7 @@
    {
       if (value == null)
          return null;
-      
+
       if (value instanceof Serializable == false)
          throw new IllegalArgumentException("Not serializable: " + value.getClass().getName());
 
@@ -231,7 +229,7 @@
          // recalculate element info, since usually more deterministic
          TypeInfo typeInfo = configuration.getTypeInfo(ce.getClass());
          MetaType metaType = metaTypeFactory.resolve(typeInfo);
-         elements[i++] = internalCreate(ce, typeInfo, metaType);             
+         elements[i++] = internalCreate(ce, typeInfo, metaType);
       }
       CollectionValue result = new CollectionValueSupport(type, elements);
       mapping.put(value, result);
@@ -240,8 +238,8 @@
 
    /**
     * Transform a primitive array into an Object[]. Converts
-    * a primitive array like char[] to Object[]. 
-    * 
+    * a primitive array like char[] to Object[].
+    *
     * @param type - the primitive array class type info.
     * @param value - the primitive array instance.
     * @return object array
@@ -274,8 +272,8 @@
       {
          oa = (Object[]) value;
       }
-      
-      return oa;      
+
+      return oa;
    }
 
    /**
@@ -294,7 +292,7 @@
 
    /**
     * Create an array value
-    * 
+    *
     * @param type the type
     * @param value the value
     * @param mapping the mapping
@@ -308,12 +306,12 @@
 
       ArrayValueSupport result = new ArrayValueSupport(type);
       mapping.put(value, result);
-      
+
       Object[] array;
-      
+
       MetaType elementType = type.getElementType();
       int dimension = type.getDimension();
-      
+
       Object[] oldArray;
       Class<?> componentType;
       try
@@ -324,7 +322,7 @@
       {
          throw new RuntimeException("Unable to determine component type for " + type, e);
       }
-      
+
       ClassInfo classInfo = configuration.getClassInfo(value.getClass());
       if (classInfo.isArray())
       {
@@ -336,7 +334,7 @@
             arrayInfo = ArrayInfo.class.cast(compInfo);
             compInfo = arrayInfo.getComponentType();
          }
-         // Translate 
+         // Translate
          if (compInfo.isPrimitive())
             oldArray = convertPrimativeArray(classInfo, value);
          else
@@ -344,7 +342,7 @@
       }
       else
          throw new UnsupportedOperationException("Cannot construct array for " + value.getClass());
-      
+
       array = createArray(elementType, componentType.getComponentType(), dimension, oldArray);
       result.setValue(array);
       return result;
@@ -352,7 +350,7 @@
 
    /**
     * Create an array
-    * 
+    *
     * @param elementType the element type
     * @param componentType the component type
     * @param dimension the dimension
@@ -363,9 +361,9 @@
    {
       if (oldArray == null)
          return null;
-      
+
       Object[] newArray = new Object[oldArray.length];
-      
+
       if (dimension > 1)
       {
          Object[] nestedOld;
@@ -384,13 +382,13 @@
          for (int i = 0; i < oldArray.length; ++i)
             newArray[i] = internalCreate(oldArray[i], null, elementType);
       }
-      
+
       return newArray;
    }
-   
+
    /**
     * Create a composite value
-    * 
+    *
     * @param type the type
     * @param value the value
     * @param mapping the mapping
@@ -401,7 +399,7 @@
    {
       if (value == null)
          return null;
-      
+
       // See if this is a Map<String,?> type
       if(type instanceof MapCompositeMetaType)
       {
@@ -462,13 +460,13 @@
          MetaValue item = internalCreate(itemValue, null, itemType);
          result.set(name, item);
       }
-      
+
       return result;
    }
 
    /**
     * Create a table value
-    * 
+    *
     * @param type the type
     * @param value the value
     * @param mapping the mapping
@@ -479,10 +477,10 @@
    {
       if (value == null)
          return null;
-      
+
       TableValueSupport table = new TableValueSupport(type);
       mapping.put(value, table);
-      
+
       CompositeMetaType entryType = type.getRowType();
       MetaType keyType = entryType.getType(DefaultMetaTypeFactory.MAP_KEY);
       MetaType valType = entryType.getType(DefaultMetaTypeFactory.MAP_VALUE);
@@ -498,20 +496,20 @@
 
       return table;
    }
-   
+
    @Override
    public MetaValue create(Object value)
    {
       return internalCreate(value, null, null);
    }
-   
+
    @Override
    public MetaValue create(Object value, Type type)
    {
       TypeInfo typeInfo = configuration.getTypeInfo(type);
       return internalCreate(value, typeInfo, null);
    }
-   
+
    @Override
    public MetaValue create(Object value, TypeInfo type)
    {
@@ -552,7 +550,7 @@
       MetaMapper<?> mapper = MetaMapper.getMetaMapper(type);
       if (mapper != null)
          return mapper.unwrapMetaValue(metaValue);
-      
+
       MetaType metaType = metaValue.getMetaType();
 
       if (metaType.isSimple())
@@ -699,7 +697,7 @@
          cl = typeInfo.getType().getClassLoader();
       else
          cl = Thread.currentThread().getContextClassLoader();
-      
+
       try
       {
          BeanInfo beanInfo = configuration.getBeanInfo(typeName, cl);
@@ -709,7 +707,7 @@
             InvocationHandler handler = createCompositeValueInvocationHandler(compositeValue);
             Class<?> clazz = classInfo.getType();
             Class<?>[] interfaces = new Class[]{clazz};
-            return Proxy.newProxyInstance(clazz.getClassLoader(), interfaces, handler);            
+            return Proxy.newProxyInstance(clazz.getClassLoader(), interfaces, handler);
          }
          Object bean = createNewInstance(beanInfo);
          for (String name : compositeMetaType.itemSet())
@@ -748,11 +746,8 @@
    @SuppressWarnings("unchecked")
    protected Object unwrapCollection(CollectionValue collectionValue, TypeInfo type)
    {
-      boolean trace = log.isTraceEnabled();
       try
       {
-         if (trace)
-            log.trace("unwrapCollection, type: "+type);
          BeanInfo collectionInfo;
          // null is not instance of
          if (type instanceof ClassInfo)
@@ -766,23 +761,14 @@
          }
          ClassInfo classInfo = collectionInfo.getClassInfo();
          Collection collection = (Collection)createNewInstance(collectionInfo);
-         Iterator<MetaValue> iter = collectionValue.iterator();
-         while (iter.hasNext())
+
+         TypeInfo componentType = classInfo.getComponentType();
+         boolean isObjectTypeInfo = OBJECT_TYPE_INFO.equals(componentType);
+
+         for (MetaValue metaValue : collectionValue)
          {
-            MetaValue metaValue = iter.next();
-            TypeInfo componentType = classInfo.getComponentType();
-            if (trace)
-               log.trace("unwrapCollection, componentType: "+componentType);
-            // try better
-            if (OBJECT_TYPE_INFO.equals(componentType))
-            {
-               if (trace)
-                  log.trace("unwrapCollection, value.metaType: "+metaValue.getMetaType());
-               componentType = getTypeInfo(metaValue.getMetaType(), null);
-               if (trace)
-                  log.trace("unwrapCollection, componentType#2: "+componentType);
-            }
-            collection.add(unwrap(metaValue, componentType));
+            TypeInfo iterTypeInfo = isObjectTypeInfo ? getTypeInfo(metaValue.getMetaType(), null) : componentType;
+            collection.add(unwrap(metaValue, iterTypeInfo));
          }
          return collection;
       }
@@ -945,7 +931,7 @@
 
    /**
     * Create a meta value from the object
-    * 
+    *
     * @param value the value
     * @param type the type
     * @param metaType the metaType
@@ -968,9 +954,9 @@
          start = true;
          metaType = metaTypeFactory.resolve(type);
       }
-      
+
       // For more complicated values we need to keep a mapping of objects to meta values
-      // this avoids duplicate meta value construction and recursion 
+      // this avoids duplicate meta value construction and recursion
       Map<Object, MetaValue> mapping;
       if (start)
       {
@@ -1044,17 +1030,13 @@
       }
       catch (Throwable t)
       {
-         log.debug("convertValue failure("+t.getMessage()+"), value="+value.toString()
-               + ", value.class: "+value.getClass().getName()
-               + ", typeInfo: "+typeInfo.toString()
-               );
          throw new UndeclaredThrowableException(t);
       }
    }
 
    /**
     * Check for a builder
-    * 
+    *
     * @param metaType the meta type
     * @param type the type
     * @param value the value
@@ -1076,7 +1058,7 @@
       MetaValue result = builder.buildMetaValue(metaType, value);
       if (result != null)
          mapping.put(value, result);
-      
+
       return result;
    }
 }




More information about the jboss-cvs-commits mailing list