[jboss-cvs] JBossAS SVN: r66290 - projects/microcontainer/trunk/metatype/src/main/org/jboss/metatype/plugins/values.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Oct 19 11:49:18 EDT 2007


Author: alesj
Date: 2007-10-19 11:49:17 -0400 (Fri, 19 Oct 2007)
New Revision: 66290

Modified:
   projects/microcontainer/trunk/metatype/src/main/org/jboss/metatype/plugins/values/DefaultMetaValueFactory.java
Log:
Simple refactoring.
Providing TypeInfo in all cases, if it was null.

Modified: projects/microcontainer/trunk/metatype/src/main/org/jboss/metatype/plugins/values/DefaultMetaValueFactory.java
===================================================================
--- projects/microcontainer/trunk/metatype/src/main/org/jboss/metatype/plugins/values/DefaultMetaValueFactory.java	2007-10-19 15:34:41 UTC (rev 66289)
+++ projects/microcontainer/trunk/metatype/src/main/org/jboss/metatype/plugins/values/DefaultMetaValueFactory.java	2007-10-19 15:49:17 UTC (rev 66290)
@@ -466,18 +466,18 @@
 
       if (metaType.isSimple())
       {
-         return convertValue(((SimpleValue)metaValue).getValue(), type);
+         Serializable value = ((SimpleValue)metaValue).getValue();
+         return getValue(metaType, type, value);
       }
       else if (metaType.isEnum())
       {
-         EnumValue enumValue = ((EnumValue)metaValue);
-         if (type == null)
-            type = getTypeInfo(metaType, null);
-         return convertValue(enumValue.getValue(), type);
+         String value = ((EnumValue)metaValue).getValue();
+         return getValue(metaType, type, value);
       }
       else if (metaType.isGeneric())
       {
-         return convertValue(((GenericValue)metaValue).getValue(), type);
+         Serializable value = ((GenericValue)metaValue).getValue();
+         return getValue(metaType, type, value);
       }
       else if (metaType.isArray())
       {
@@ -507,6 +507,39 @@
    }
 
    /**
+    * Do a simple check.
+    * If current type param is null,
+    * try getting type info from meta type
+    * and value's classloader.
+    *
+    * @param type the type info
+    * @param value tester value
+    * @param metaType the meta type
+    * @return type info
+    */
+   protected TypeInfo checkTypeInfo(TypeInfo type, Object value, MetaType metaType)
+   {
+      if (type == null && value != null)
+         type = getTypeInfo(metaType, value);
+      return type;
+   }
+
+   /**
+    * Get the value.
+    * Join type check and value conversion.
+    *
+    * @param metaType the meta type
+    * @param typeInfo the type info
+    * @param value the value
+    * @return the converted value
+    */
+   protected Object getValue(MetaType metaType, TypeInfo typeInfo, Object value)
+   {
+      typeInfo = checkTypeInfo(typeInfo, value, metaType);
+      return convertValue(value, typeInfo);
+   }
+
+   /**
     * Unwrap MetaValue.
     *
     * @param element the meta value
@@ -623,18 +656,18 @@
     * Get the class info from meta type.
     *
     * @param metaType the meta type
-    * @param array the array to fill
-    * @return class info
+    * @param value the value which can provide classloader
+    * @return type info
     */
-   protected TypeInfo getTypeInfo(MetaType metaType, Object array)
+   protected TypeInfo getTypeInfo(MetaType metaType, Object value)
    {
       if (metaType == null)
          throw new IllegalArgumentException("Null meta type, cannot determine class name.");
-      if (array == null)
-         throw new IllegalArgumentException("Null array, cannot determine classloader.");
+      if (value == null)
+         throw new IllegalArgumentException("Null value, cannot determine classloader.");
 
       // get the classloader from the array we plan to fill
-      ClassLoader cl = array.getClass().getClassLoader();
+      ClassLoader cl = value.getClass().getClassLoader();
       return getTypeInfo(metaType, cl);
    }
 




More information about the jboss-cvs-commits mailing list