[jboss-cvs] JBossAS SVN: r77998 - in projects/jboss-man/trunk/managed/src: test/java/org/jboss/test/managed/factory and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Sep 4 14:14:49 EDT 2008


Author: scott.stark at jboss.org
Date: 2008-09-04 14:14:49 -0400 (Thu, 04 Sep 2008)
New Revision: 77998

Added:
   projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectPopulator.java
   projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/support/amof/
   projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/support/amof/BigDecimalSimpleValue.java
   projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/support/amof/TestICF.java
   projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/support/amof/TestMOP.java
   projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/support/amof/TestSimpleICF.java
   projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/test/AbstractManagedObjectFactoryUnitTestCase.java
Modified:
   projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractInstanceClassFactory.java
   projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java
   projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/AbstractManagedObjectFactoryTest.java
Log:
JBMAN-2, refactory AbstractManagedObjectFactory to delegate the InstanceClassFactory(Serializable) and ManagedObjectPopulator(Serializable) behaviors to other plugins.

Modified: projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractInstanceClassFactory.java
===================================================================
--- projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractInstanceClassFactory.java	2008-09-04 18:13:43 UTC (rev 77997)
+++ projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractInstanceClassFactory.java	2008-09-04 18:14:49 UTC (rev 77998)
@@ -39,7 +39,6 @@
 import org.jboss.managed.api.annotation.ManagementObjectRef;
 import org.jboss.managed.api.annotation.ManagementRuntimeRef;
 import org.jboss.managed.api.factory.ManagedObjectFactory;
-import org.jboss.managed.plugins.factory.AbstractManagedObjectFactory;
 import org.jboss.managed.spi.factory.InstanceClassFactory;
 import org.jboss.managed.spi.factory.RuntimeComponentNameTransformer;
 import org.jboss.metatype.api.types.ArrayMetaType;
@@ -47,6 +46,7 @@
 import org.jboss.metatype.api.types.MetaType;
 import org.jboss.metatype.api.values.ArrayValueSupport;
 import org.jboss.metatype.api.values.CollectionValueSupport;
+import org.jboss.metatype.api.values.GenericValue;
 import org.jboss.metatype.api.values.GenericValueSupport;
 import org.jboss.metatype.api.values.MetaValue;
 import org.jboss.metatype.api.values.MetaValueFactory;
@@ -68,8 +68,25 @@
    private MetaValueFactory metaValueFactory = MetaValueFactory.getInstance();
    /** The instance to name transformers */
    private Map<TypeInfo, RuntimeComponentNameTransformer> transformers = new WeakHashMap<TypeInfo, RuntimeComponentNameTransformer>();
-   private ManagedObjectFactory mof = new AbstractManagedObjectFactory();
+   /** The ManagedObjectFactory used in getValue for MANAGED_OBJECT_META_TYPEs */
+   private ManagedObjectFactory mof;
 
+   public AbstractInstanceClassFactory()
+   {
+      this(null);
+   }
+   /**
+    * Create an AbstractInstanceClassFactory with a ManagedObjectFactory. The
+    * ManagedObjectFactory is neede for GenericValue creation.
+    * @param mof - the ManagedObjectFactory delegated to for GenericValue handling.
+    * @see #getManagedObjectValue(BeanInfo, ManagedProperty, Object)
+    * @see #getManagedObjectArray(BeanInfo, ManagedProperty, Object)
+    */
+   public AbstractInstanceClassFactory(ManagedObjectFactory mof)
+   {
+      this.mof = mof;
+   }
+
    public Map<TypeInfo, RuntimeComponentNameTransformer> getTransformers()
    {
       return transformers;
@@ -78,7 +95,23 @@
    {
       this.transformers = transformers;
    }
+   public void setNameTransformers(Class<?> clazz, RuntimeComponentNameTransformer transformer)
+   {
+      TypeInfo type = configuration.getTypeInfo(clazz);
+      setNameTransformers(type, transformer);
+   }
 
+   public void setNameTransformers(TypeInfo type, RuntimeComponentNameTransformer transformer)
+   {
+      synchronized (transformers)
+      {
+         if (transformer == null)
+            transformers.remove(type);
+         else
+            transformers.put(type, transformer);
+      }
+   }
+
    public Configuration getConfiguration()
    {
       return configuration;
@@ -106,7 +139,10 @@
       this.mof = mof;
    }
 
-   
+   /**
+    * Default InstanceClassFactory implementation simply returns the
+    * attachment class. 
+    */
    public Class<? extends Serializable> getManagedObjectClass(T attachment)
          throws ClassNotFoundException
    {
@@ -187,30 +223,18 @@
       MetaType propertyType = property.getMetaType();
       if (AbstractManagedObjectFactory.MANAGED_OBJECT_META_TYPE == propertyType)
       {
-         if (value instanceof Serializable == false)
-            throw new IllegalStateException("Object is not serializable: " + value.getClass().getName());
-         // Look for a ManagementObjectRef
-         ManagementObjectRef ref = (ManagementObjectRef) property.getAnnotations().get(ManagementObjectRef.class.getName());
-         String moName = (ref != null ? ref.name() : value.getClass().getName());
-         String moNameType = (ref != null ? ref.type() : "");
-         ManagedObject mo = mof.initManagedObject((Serializable) value, moName, moNameType);
-         return new GenericValueSupport(AbstractManagedObjectFactory.MANAGED_OBJECT_META_TYPE, mo);
+         GenericValue gvs = getManagedObjectValue(beanInfo, property, value);
+         return gvs;
       }
       else if (propertyType.isArray())
       {
          ArrayMetaType arrayType = ArrayMetaType.class.cast(propertyType);
          if (AbstractManagedObjectFactory.MANAGED_OBJECT_META_TYPE == arrayType.getElementType())
          {
-            Collection<?> cvalue = getAsCollection(value);
             ArrayMetaType moType = new ArrayMetaType(1, AbstractManagedObjectFactory.MANAGED_OBJECT_META_TYPE);
             ArrayValueSupport moArrayValue = new ArrayValueSupport(moType);
-            List<GenericValueSupport> tmp = new ArrayList<GenericValueSupport>();
-            for(Object element : cvalue)
-            {
-               ManagedObject mo = mof.initManagedObject((Serializable) element, null, null);
-               tmp.add(new GenericValueSupport(AbstractManagedObjectFactory.MANAGED_OBJECT_META_TYPE, mo));
-            }
-            GenericValueSupport[] mos = new GenericValueSupport[tmp.size()];
+            List<GenericValue> tmp = getManagedObjectArray(beanInfo, property, value);
+            GenericValue[] mos = new GenericValue[tmp.size()];
             moArrayValue.setValue(tmp.toArray(mos));
             return moArrayValue;
          }
@@ -220,23 +244,16 @@
          CollectionMetaType collectionType = CollectionMetaType.class.cast(propertyType);
          if (AbstractManagedObjectFactory.MANAGED_OBJECT_META_TYPE == collectionType.getElementType())
          {
-            Collection<?> cvalue = getAsCollection(value);
-            List<GenericValueSupport> tmp = new ArrayList<GenericValueSupport>();
-            for(Object element : cvalue)
-            {
-               ManagedObject mo = mof.initManagedObject((Serializable) element, null, null);
-               tmp.add(new GenericValueSupport(AbstractManagedObjectFactory.MANAGED_OBJECT_META_TYPE, mo));
-            }
-            GenericValueSupport[] mos = new GenericValueSupport[tmp.size()];
+            List<GenericValue> tmp = getManagedObjectArray(beanInfo, property, value);
+            GenericValue[] mos = new GenericValue[tmp.size()];
             CollectionMetaType moType = new CollectionMetaType(propertyType.getClassName(), AbstractManagedObjectFactory.MANAGED_OBJECT_META_TYPE);
             return new CollectionValueSupport(moType, tmp.toArray(mos));
          }
       }
 
-      return metaValueFactory.create(value, propertyInfo.getType());
+      return getNonManagedObjectValue(beanInfo, property, propertyInfo, value);
    }
 
-
    /**
     * Set a value
     *
@@ -261,6 +278,34 @@
       }
    }
 
+   protected GenericValue getManagedObjectValue(BeanInfo beanInfo, ManagedProperty property, Object value)
+   {
+      if (value instanceof Serializable == false)
+         throw new IllegalStateException("Object is not serializable: " + value.getClass().getName());
+      // Look for a ManagementObjectRef
+      ManagementObjectRef ref = (ManagementObjectRef) property.getAnnotations().get(ManagementObjectRef.class.getName());
+      String moName = (ref != null ? ref.name() : value.getClass().getName());
+      String moNameType = (ref != null ? ref.type() : "");
+      ManagedObject mo = mof.initManagedObject((Serializable) value, moName, moNameType);
+      return new GenericValueSupport(AbstractManagedObjectFactory.MANAGED_OBJECT_META_TYPE, mo);
+   }
+   protected List<GenericValue> getManagedObjectArray(BeanInfo beanInfo, ManagedProperty property, Object value)
+   {
+      Collection<?> cvalue = getAsCollection(value);
+      List<GenericValue> tmp = new ArrayList<GenericValue>();
+      for(Object element : cvalue)
+      {
+         ManagedObject mo = mof.initManagedObject((Serializable) element, null, null);
+         tmp.add(new GenericValueSupport(AbstractManagedObjectFactory.MANAGED_OBJECT_META_TYPE, mo));
+      }
+      return tmp;
+   }
+   protected MetaValue getNonManagedObjectValue(BeanInfo beanInfo, ManagedProperty property,
+         PropertyInfo propertyInfo, Object value)
+   {
+      return metaValueFactory.create(value, propertyInfo.getType());
+   }
+
    /**
     * Get component name transformer.
     *

Modified: projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java
===================================================================
--- projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java	2008-09-04 18:13:43 UTC (rev 77997)
+++ projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java	2008-09-04 18:14:49 UTC (rev 77998)
@@ -24,13 +24,11 @@
 import java.io.Serializable;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Constructor;
-import java.lang.reflect.UndeclaredThrowableException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.WeakHashMap;
@@ -70,32 +68,26 @@
 import org.jboss.managed.spi.factory.ManagedParameterConstraintsPopulatorFactory;
 import org.jboss.managed.spi.factory.ManagedPropertyConstraintsPopulator;
 import org.jboss.managed.spi.factory.ManagedPropertyConstraintsPopulatorFactory;
-import org.jboss.managed.spi.factory.RuntimeComponentNameTransformer;
 import org.jboss.metatype.api.types.ArrayMetaType;
 import org.jboss.metatype.api.types.CollectionMetaType;
 import org.jboss.metatype.api.types.GenericMetaType;
 import org.jboss.metatype.api.types.MetaType;
 import org.jboss.metatype.api.types.MetaTypeFactory;
-import org.jboss.metatype.api.values.ArrayValueSupport;
-import org.jboss.metatype.api.values.CollectionValueSupport;
-import org.jboss.metatype.api.values.GenericValueSupport;
-import org.jboss.metatype.api.values.MetaValue;
 import org.jboss.metatype.api.values.MetaValueFactory;
-import org.jboss.metatype.api.values.SimpleValue;
 import org.jboss.reflect.spi.ClassInfo;
 import org.jboss.reflect.spi.MethodInfo;
 import org.jboss.reflect.spi.ParameterInfo;
 import org.jboss.reflect.spi.TypeInfo;
 
 /**
- * AbstractManagedObjectFactory.
+ * The base ManagedObjectFactory implementation.
  * 
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
  * @author Scott.Stark at jboss.org
- * @version $Revision: 1.1 $
+ * @version $Revision$
  */
 public class AbstractManagedObjectFactory extends ManagedObjectFactory
-   implements ManagedObjectBuilder, InstanceClassFactory<Serializable>, ManagedObjectPopulator<Serializable>
+   implements ManagedObjectBuilder
 {
    private static final Logger log = Logger.getLogger(AbstractManagedObjectFactory.class);
 
@@ -110,16 +102,17 @@
 
    /** The meta value factory */
    private MetaValueFactory metaValueFactory = MetaValueFactory.getInstance();
-   
+   /** A default InstanceClassFactory used when there is no explicit ICF for a given class */
+   private InstanceClassFactory<? extends Serializable> defaultInstanceFactory;
+   /** A default ManagedObjectPopulator used when there is no explicit ManagedObjectBuilder for a given class */
+   private ManagedObjectPopulator<? extends Serializable> defaultManagedObjectPopulator;
+
    /** The managed object builders */
    private Map<Class<?>, ManagedObjectBuilder> builders = new WeakHashMap<Class<?>, ManagedObjectBuilder>();
 
    /** The instance to class factories */
    private Map<Class<?>, InstanceClassFactory<? extends Serializable>> instanceFactories = new WeakHashMap<Class<?>, InstanceClassFactory<? extends Serializable>>();
 
-   /** The instance to name transformers */
-   private Map<TypeInfo, RuntimeComponentNameTransformer> transformers = new WeakHashMap<TypeInfo, RuntimeComponentNameTransformer>();
-
    /**
     * Create a ManagedProperty by looking to the factory for ctor(Fields)
     * @param factory - the ManagedProperty implementation class
@@ -143,6 +136,133 @@
       return property;
    }
 
+   /**
+    * Create an AbstractManagedObjectFactory that uses an AbstractInstanceClassFactory
+    * as the defaultInstanceFactory and AbstractManagedObjectPopulator as the
+    * defaultManagedObjectPopulator. The MetaTypeFactory, MetaValueFactory are
+    * obtained from the respective getInstance() factory methods.
+    */
+   public AbstractManagedObjectFactory()
+   {
+      // Create an AbstractInstanceClassFactory as the default ICF
+      AbstractInstanceClassFactory<Serializable> icf = new AbstractInstanceClassFactory<Serializable>();
+      icf.setMof(this);
+      defaultInstanceFactory = icf;
+      // Create an AbstractManagedObjectPopulator as the default
+      defaultManagedObjectPopulator = new AbstractManagedObjectPopulator<Serializable>(configuration, icf, instanceFactories);
+   }
+   /**
+    * Create an AbstractManagedObjectFactory the given factories, supporting
+    * information.
+    * 
+    * @param metaTypeFactory
+    * @param metaValueFactory
+    * @param defaultInstanceFactory
+    * @param defaultManagedObjectPopulator
+    * @param builders
+    * @param instanceFactories
+    * @param transformers
+    */
+   public AbstractManagedObjectFactory(MetaTypeFactory metaTypeFactory,
+         MetaValueFactory metaValueFactory,
+         InstanceClassFactory<? extends Serializable> defaultInstanceFactory,
+         ManagedObjectPopulator<? extends Serializable> defaultManagedObjectPopulator,
+         Map<Class<?>, ManagedObjectBuilder> builders,
+         Map<Class<?>, InstanceClassFactory<? extends Serializable>> instanceFactories)
+   {
+      this.metaTypeFactory = metaTypeFactory;
+      this.metaValueFactory = metaValueFactory;
+      this.defaultInstanceFactory = defaultInstanceFactory;
+      this.defaultManagedObjectPopulator = defaultManagedObjectPopulator;
+      this.builders = builders;
+      this.instanceFactories = instanceFactories;
+   }
+
+   /**
+    * 
+    * @return
+    */
+   public Configuration getConfiguration()
+   {
+      return configuration;
+   }
+
+   
+   public MetaTypeFactory getMetaTypeFactory()
+   {
+      return metaTypeFactory;
+   }
+
+   public void setMetaTypeFactory(MetaTypeFactory metaTypeFactory)
+   {
+      this.metaTypeFactory = metaTypeFactory;
+   }
+
+   public MetaValueFactory getMetaValueFactory()
+   {
+      return metaValueFactory;
+   }
+
+   public void setMetaValueFactory(MetaValueFactory metaValueFactory)
+   {
+      this.metaValueFactory = metaValueFactory;
+   }
+
+   public Map<Class<?>, ManagedObjectBuilder> getBuilders()
+   {
+      return builders;
+   }
+
+   public void setBuilders(Map<Class<?>, ManagedObjectBuilder> builders)
+   {
+      this.builders = builders;
+   }
+
+   public Map<Class<?>, InstanceClassFactory<? extends Serializable>> getInstanceFactories()
+   {
+      return instanceFactories;
+   }
+
+   public void setInstanceFactories(
+         Map<Class<?>, InstanceClassFactory<? extends Serializable>> instanceFactories)
+   {
+      this.instanceFactories = instanceFactories;
+   }
+
+   /**
+    * Get the default InstanceClassFactory
+    * @return the current default InstanceClassFactory
+    */
+   public InstanceClassFactory<? extends Serializable> getDefaultInstanceFactory()
+   {
+      return defaultInstanceFactory;
+   }
+   /**
+    * Set the default InstanceClassFactory. This is used when there is not
+    * match an exact match by the {@linkplain #getInstanceClassFactory(Class)}
+    * factory method.
+    * 
+    * @param defaultInstanceFactory the default InstanceClassFactory to fall
+    * back to. It may be null if no default should be used.
+    */
+   public void setDefaultInstanceFactory(
+         InstanceClassFactory<? extends Serializable> defaultInstanceFactory)
+   {
+      this.defaultInstanceFactory = defaultInstanceFactory;
+   }
+
+   
+   public ManagedObjectPopulator<? extends Serializable> getDefaultManagedObjectPopulator()
+   {
+      return defaultManagedObjectPopulator;
+   }
+
+   public void setDefaultManagedObjectPopulator(
+         ManagedObjectPopulator<? extends Serializable> defaultManagedObjectPopulator)
+   {
+      this.defaultManagedObjectPopulator = defaultManagedObjectPopulator;
+   }
+
    @Override
    public <T extends Serializable> ManagedObject createManagedObject(Class<T> clazz)
    {
@@ -210,33 +330,7 @@
       }      
    }
 
-   public void setNameTransformers(Class<?> clazz, RuntimeComponentNameTransformer transformer)
-   {
-      TypeInfo type = configuration.getTypeInfo(clazz);
-      setNameTransformers(type, transformer);
-   }
-
-   public void setNameTransformers(TypeInfo type, RuntimeComponentNameTransformer transformer)
-   {
-      synchronized (transformers)
-      {
-         if (transformer == null)
-            transformers.remove(type);
-         else
-            transformers.put(type, transformer);
-      }
-   }
-
    /**
-    * Default InstanceClassFactory implementation simply returns the
-    * instance class. 
-    */
-   public Class<? extends Serializable> getManagedObjectClass(Serializable instance)
-   {
-      return instance.getClass();
-   }
-
-   /**
     * Create a skeleton managed object
     * 
     * @param <T> the type
@@ -530,125 +624,7 @@
       return new WritethroughManagedPropertyImpl(fields, metaValueFactory, this);
    }
 
-   public void createObject(ManagedObject managedObject, Class<? extends Serializable> clazz)
-   {
-      if (managedObject == null)
-         throw new IllegalArgumentException("Null managed object");
-      
-      if (managedObject instanceof ManagedObjectImpl == false)
-         throw new IllegalStateException("Unable to create object " + managedObject.getClass().getName());
-      
-      ManagedObjectImpl managedObjectImpl = (ManagedObjectImpl) managedObject;
-      Serializable object = createUnderlyingObject(managedObjectImpl, clazz);
-      populateManagedObject(managedObject, object);
-   }
-   
-   public void populateManagedObject(ManagedObject managedObject, Serializable object)
-   {
-      if (managedObject instanceof ManagedObjectImpl == false)
-         throw new IllegalStateException("Unable to populate managed object " + managedObject.getClass().getName());
-      
-      ManagedObjectImpl managedObjectImpl = (ManagedObjectImpl) managedObject;
-      managedObjectImpl.setAttachment(object);
-      populateValues(managedObjectImpl, object);
-   }
-   
    /**
-    * Create the underlying object
-    * 
-    * @param managedObject the managed object
-    * @param clazz the class
-    * @return the object
-    */
-   protected Serializable createUnderlyingObject(ManagedObjectImpl managedObject, Class<? extends Serializable> clazz)
-   {
-      BeanInfo beanInfo = configuration.getBeanInfo(clazz);
-      try
-      {
-         Object result = beanInfo.newInstance();
-         return Serializable.class.cast(result);
-      }
-      catch (Throwable t)
-      {
-         throw new RuntimeException("Unable to create new object for " + managedObject + " clazz=" + clazz, t);
-      }
-   }
-   
-   /**
-    * Populate the values
-    * 
-    * @param managedObject the managed object
-    * @param object the object
-    */
-   @SuppressWarnings("unchecked")
-   protected void populateValues(ManagedObjectImpl managedObject, Serializable object)
-   {
-      InstanceClassFactory icf = getInstanceClassFactory(object.getClass());
-      Class moClass;
-      try
-      {
-         moClass = icf.getManagedObjectClass(object);
-      }
-      catch(ClassNotFoundException e)
-      {
-         throw new IllegalStateException(e);
-      }
-      BeanInfo beanInfo = configuration.getBeanInfo(moClass);
-
-      Object componentName = null;
-      Map<String, ManagedProperty> properties = managedObject.getProperties();
-      if (properties != null && properties.size() > 0)
-      {
-         for (ManagedProperty property : properties.values())
-         {
-            MetaValue value = null;
-            try
-            {
-               value = icf.getValue(beanInfo, property, object);
-            }
-            catch(Throwable t)
-            {
-               if(log.isTraceEnabled())
-                  log.trace("Failed to access value for property: "+property);
-            }
-
-            if (value != null)
-               property.setField(Fields.VALUE, value);
-            /* Need to look for a ManagementObjectID at the property level which
-               defines the ManagedObject id name from the property value.
-             */
-            Map<String, Annotation> annotations = property.getAnnotations();
-            if (annotations == null)
-               continue;
-            ManagementObjectID id = (ManagementObjectID) annotations.get(ManagementObjectID.class.getName());
-            if (id != null)
-            {
-               if (value == null || value.getMetaType().isSimple() == false)
-               {
-                  log.warn("Cannot create String name from non-Simple property: " + property + ", value=" + value);
-                  continue;
-               }
-               SimpleValue svalue = (SimpleValue) value;
-               String name = "" + svalue.getValue();
-               managedObject.setName(name);
-            }
-            ManagementRuntimeRef runtimeRef = (ManagementRuntimeRef) annotations.get(ManagementRuntimeRef.class.getName());
-            if (runtimeRef != null)
-            {
-               componentName = icf.getComponentName(beanInfo, property, object, value);
-               // let's try this as well
-               if (componentName == null && icf != this)
-                  componentName = getComponentName(beanInfo, property, object, value);
-            }
-         }
-      }
-      if (componentName == null)
-         componentName = icf.getComponentName(null, null, object, null);
-      // set it, even if it's null
-      managedObject.setComponentName(componentName);
-   }
-
-   /**
     * Get the property name.
     *
     * @param property managed property
@@ -663,151 +639,8 @@
       return name;
    }
 
-   public Object getComponentName(BeanInfo beanInfo, ManagedProperty property, Serializable object, MetaValue value)
-   {
-      if (beanInfo != null && property != null && value != null)
-      {
-         String name = getPropertyName(property);
-         PropertyInfo propertyInfo = beanInfo.getProperty(name);
-
-         ManagementRuntimeRef componentRef = propertyInfo.getUnderlyingAnnotation(ManagementRuntimeRef.class);
-         if (componentRef != null)
-         {
-            Object original = metaValueFactory.unwrap(value, propertyInfo.getType());
-            try
-            {
-               Class<? extends RuntimeComponentNameTransformer> tClass = componentRef.transformer();
-               RuntimeComponentNameTransformer transformer;
-               if (tClass != ManagementRuntimeRef.DEFAULT_NAME_TRANSFORMER.class)
-                  transformer = getComponentNameTransformer(configuration.getTypeInfo(tClass));
-               else
-                  transformer = getComponentNameTransformer(propertyInfo.getType());
-
-               return (transformer != null) ? transformer.transform(original) : original;
-            }
-            catch (Throwable t)
-            {
-               throw new UndeclaredThrowableException(t);
-            }
-         }
-      }
-      return null;
-   }
-
    /**
-    * Get a value
     * 
-    * @param beanInfo the bean info
-    * @param property the property
-    * @param object the object
-    * @return the meta value
-    */
-   @SuppressWarnings("unchecked")
-   public MetaValue getValue(BeanInfo beanInfo, ManagedProperty property, Serializable object)
-   {
-      String name = getPropertyName(property);
-      PropertyInfo propertyInfo = beanInfo.getProperty(name);
-
-      Object value;
-      try
-      {
-         value = propertyInfo.get(object);
-      }
-      catch (RuntimeException e)
-      {
-         throw e;
-      }
-      catch (Error e)
-      {
-         throw e;
-      }
-      catch (Throwable t)
-      {
-         throw new RuntimeException("Error getting property " + name + " for " + object.getClass().getName(), t);
-      }
-
-      if (value == null)
-         return null;
-
-      MetaType propertyType = property.getMetaType();
-      if (MANAGED_OBJECT_META_TYPE == propertyType)
-      {
-         if (value instanceof Serializable == false)
-            throw new IllegalStateException("Object is not serializable: " + value.getClass().getName());
-         // Look for a ManagementObjectRef
-         ManagementObjectRef ref = (ManagementObjectRef) property.getAnnotations().get(ManagementObjectRef.class.getName());
-         String moName = (ref != null ? ref.name() : value.getClass().getName());
-         String moNameType = (ref != null ? ref.type() : "");
-         ManagedObject mo = initManagedObject((Serializable) value, moName, moNameType);
-         return new GenericValueSupport(MANAGED_OBJECT_META_TYPE, mo);
-      }
-      else if (propertyType.isArray())
-      {
-         ArrayMetaType arrayType = ArrayMetaType.class.cast(propertyType);
-         if (MANAGED_OBJECT_META_TYPE == arrayType.getElementType())
-         {
-            Collection<?> cvalue = getAsCollection(value);
-            // todo - AJ: changed some generics by best guess
-            ArrayMetaType moType = new ArrayMetaType(1, MANAGED_OBJECT_META_TYPE);
-            ArrayValueSupport moArrayValue = new ArrayValueSupport(moType);
-            List<GenericValueSupport> tmp = new ArrayList<GenericValueSupport>();
-            for(Object element : cvalue)
-            {
-               ManagedObject mo = initManagedObject((Serializable) element, null, null);
-               tmp.add(new GenericValueSupport(MANAGED_OBJECT_META_TYPE, mo));
-            }
-            GenericValueSupport[] mos = new GenericValueSupport[tmp.size()];
-            moArrayValue.setValue(tmp.toArray(mos));
-            return moArrayValue;
-         }
-      }
-      else if (propertyType.isCollection())
-      {
-         CollectionMetaType collectionType = CollectionMetaType.class.cast(propertyType);
-         if (MANAGED_OBJECT_META_TYPE == collectionType.getElementType())
-         {
-            Collection<?> cvalue = getAsCollection(value);
-            List<GenericValueSupport> tmp = new ArrayList<GenericValueSupport>();
-            for(Object element : cvalue)
-            {
-               ManagedObject mo = initManagedObject((Serializable) element, null, null);
-               tmp.add(new GenericValueSupport(MANAGED_OBJECT_META_TYPE, mo));
-            }
-            GenericValueSupport[] mos = new GenericValueSupport[tmp.size()];
-            CollectionMetaType moType = new CollectionMetaType(propertyType.getClassName(), MANAGED_OBJECT_META_TYPE);
-            return new CollectionValueSupport(moType, tmp.toArray(mos));
-         }
-      }
-
-      return metaValueFactory.create(value, propertyInfo.getType());
-   }
-
-   /**
-    * Set a value
-    *
-    * @param beanInfo the bean info
-    * @param property the property
-    * @param object the object
-    * @param value the meta value
-    */
-   public void setValue(BeanInfo beanInfo, ManagedProperty property, Serializable object, MetaValue value)
-   {
-      String name = getPropertyName(property);
-      PropertyInfo propertyInfo = beanInfo.getProperty(name);
-
-      Object plainValue = metaValueFactory.unwrap(value, propertyInfo.getType());
-      try
-      {
-         propertyInfo.set(object, plainValue);
-      }
-      catch (Throwable t)
-      {
-         throw new UndeclaredThrowableException(t);
-      }
-   }
-
-   /**
-    * 
     * @param methodInfo
     * @param opAnnotation
     * @return the managed operation
@@ -910,38 +743,11 @@
          if (factory != null)
             return factory;
       }
-      return (InstanceClassFactory<T>)this;
+      InstanceClassFactory<T> factory = (InstanceClassFactory<T>) defaultInstanceFactory;
+      return factory;
    }
 
    /**
-    * Get component name transformer.
-    *
-    * @param type the type info
-    * @return transformer instance
-    * @throws Throwable for any error
-    */
-   protected RuntimeComponentNameTransformer getComponentNameTransformer(TypeInfo type) throws Throwable
-   {
-      synchronized(transformers)
-      {
-         RuntimeComponentNameTransformer transformer = transformers.get(type);
-         if (transformer != null)
-            return transformer;
-
-         TypeInfo rcntType = configuration.getTypeInfo(RuntimeComponentNameTransformer.class);
-         if (rcntType.isAssignableFrom(type))
-         {
-            BeanInfo beanInfo = configuration.getBeanInfo(type);
-            RuntimeComponentNameTransformer newTransformer = (RuntimeComponentNameTransformer)beanInfo.newInstance();
-            transformers.put(type, newTransformer);
-            return newTransformer;
-         }
-
-         return null;
-      }
-   }
-
-   /**
     * Get the populator for a class
     * 
     * @param clazz the class
@@ -953,7 +759,8 @@
       ManagedObjectBuilder builder = getBuilder(clazz);
       if (builder instanceof ManagedObjectPopulator)
          return (ManagedObjectPopulator) builder;
-      return this;
+      ManagedObjectPopulator<Serializable> mop = (ManagedObjectPopulator<Serializable>) defaultManagedObjectPopulator;
+      return mop;
    }
 
    protected Collection<?> getAsCollection(Object value)


Property changes on: projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision

Added: projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectPopulator.java
===================================================================
--- projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectPopulator.java	                        (rev 0)
+++ projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectPopulator.java	2008-09-04 18:14:49 UTC (rev 77998)
@@ -0,0 +1,238 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.managed.plugins.factory;
+
+import java.io.Serializable;
+import java.lang.annotation.Annotation;
+import java.util.Map;
+
+import org.jboss.beans.info.spi.BeanInfo;
+import org.jboss.config.spi.Configuration;
+import org.jboss.logging.Logger;
+import org.jboss.managed.api.Fields;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.managed.api.annotation.ManagementObjectID;
+import org.jboss.managed.api.annotation.ManagementRuntimeRef;
+import org.jboss.managed.plugins.ManagedObjectImpl;
+import org.jboss.managed.spi.factory.InstanceClassFactory;
+import org.jboss.managed.spi.factory.ManagedObjectPopulator;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.SimpleValue;
+
+/**
+ * A default ManagedObjectPopulator implementation that relies on mc configuration
+ * for obtaining BeanInfos for a class, and InstanceClassFactorys for
+ * class, name and values from a value to be managed.
+ * 
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class AbstractManagedObjectPopulator<T extends Serializable>
+   implements ManagedObjectPopulator<T>
+{
+   private static Logger log = Logger.getLogger(AbstractManagedObjectPopulator.class);
+
+   /** The configuration */
+   private Configuration configuration;
+   private InstanceClassFactory<? extends Serializable> defaultInstanceFactory;
+   /** The instance to class factories */
+   private Map<Class<?>, InstanceClassFactory<? extends Serializable>> instanceFactories;
+
+
+   public AbstractManagedObjectPopulator(Configuration configuration)
+   {
+      this(configuration, null, null);
+   }
+   public AbstractManagedObjectPopulator(
+         Configuration configuration,
+         InstanceClassFactory<? extends Serializable> defaultInstanceFactory,
+         Map<Class<?>, InstanceClassFactory<? extends Serializable>> instanceFactories)
+   {
+      super();
+      this.configuration = configuration;
+      this.defaultInstanceFactory = defaultInstanceFactory;
+      this.instanceFactories = instanceFactories;
+   }
+   
+   public Configuration getConfiguration()
+   {
+      return configuration;
+   }
+   public void setConfiguration(Configuration configuration)
+   {
+      this.configuration = configuration;
+   }
+
+   public InstanceClassFactory<? extends Serializable> getDefaultInstanceFactory()
+   {
+      return defaultInstanceFactory;
+   }
+   public void setDefaultInstanceFactory(InstanceClassFactory<? extends Serializable> defaultInstanceFactory)
+   {
+      this.defaultInstanceFactory = defaultInstanceFactory;
+   }
+
+   public Map<Class<?>, InstanceClassFactory<? extends Serializable>> getInstanceFactories()
+   {
+      return instanceFactories;
+   }
+   public void setInstanceFactories(Map<Class<?>, InstanceClassFactory<? extends Serializable>> instanceFactories)
+   {
+      this.instanceFactories = instanceFactories;
+   }
+
+   public void createObject(ManagedObject managedObject, Class<? extends Serializable> clazz)
+   {
+      if (managedObject == null)
+         throw new IllegalArgumentException("Null managed object");
+      
+      if (managedObject instanceof ManagedObjectImpl == false)
+         throw new IllegalStateException("Unable to create object " + managedObject.getClass().getName());
+      
+      ManagedObjectImpl managedObjectImpl = (ManagedObjectImpl) managedObject;
+      Serializable object = createUnderlyingObject(managedObjectImpl, clazz);
+      populateManagedObject(managedObject, object);
+   }
+
+   public void populateManagedObject(ManagedObject managedObject, Serializable object)
+   {
+      if (managedObject instanceof ManagedObjectImpl == false)
+         throw new IllegalStateException("Unable to populate managed object " + managedObject.getClass().getName());
+      
+      ManagedObjectImpl managedObjectImpl = (ManagedObjectImpl) managedObject;
+      managedObjectImpl.setAttachment(object);
+      populateValues(managedObjectImpl, object);
+   }
+
+   /**
+    * Get the instance factory for a class
+    * 
+    * @param clazz the class
+    * @return the InstanceClassFactory
+    */
+   @SuppressWarnings("unchecked")
+   public <T extends Serializable> InstanceClassFactory<T> getInstanceClassFactory(Class<T> clazz)
+   {
+      synchronized (instanceFactories)
+      {
+         InstanceClassFactory factory = instanceFactories.get(clazz);
+         if (factory != null)
+            return factory;
+      }
+      InstanceClassFactory<T> factory = (InstanceClassFactory<T>) defaultInstanceFactory;
+      return factory;
+   }
+
+   /**
+    * Create the underlying object
+    * 
+    * @param managedObject the managed object
+    * @param clazz the class
+    * @return the object
+    */
+   protected Serializable createUnderlyingObject(ManagedObjectImpl managedObject, Class<? extends Serializable> clazz)
+   {
+      BeanInfo beanInfo = configuration.getBeanInfo(clazz);
+      try
+      {
+         Object result = beanInfo.newInstance();
+         return Serializable.class.cast(result);
+      }
+      catch (Throwable t)
+      {
+         throw new RuntimeException("Unable to create new object for " + managedObject + " clazz=" + clazz, t);
+      }
+   }
+
+   /**
+    * Populate the values
+    * 
+    * @param managedObject the managed object
+    * @param object the object
+    */
+   @SuppressWarnings("unchecked")
+   protected void populateValues(ManagedObjectImpl managedObject, Serializable object)
+   {
+      InstanceClassFactory icf = getInstanceClassFactory(object.getClass());
+      Class moClass;
+      try
+      {
+         moClass = icf.getManagedObjectClass(object);
+      }
+      catch(ClassNotFoundException e)
+      {
+         throw new IllegalStateException(e);
+      }
+      BeanInfo beanInfo = configuration.getBeanInfo(moClass);
+
+      Object componentName = null;
+      Map<String, ManagedProperty> properties = managedObject.getProperties();
+      if (properties != null && properties.size() > 0)
+      {
+         for (ManagedProperty property : properties.values())
+         {
+            MetaValue value = null;
+            try
+            {
+               value = icf.getValue(beanInfo, property, object);
+            }
+            catch(Throwable t)
+            {
+               if(log.isTraceEnabled())
+                  log.trace("Failed to access value for property: "+property, t);
+            }
+
+            if (value != null)
+               property.setField(Fields.VALUE, value);
+            /* Need to look for a ManagementObjectID at the property level which
+               defines the ManagedObject id name from the property value.
+             */
+            Map<String, Annotation> annotations = property.getAnnotations();
+            if (annotations == null)
+               continue;
+            ManagementObjectID id = (ManagementObjectID) annotations.get(ManagementObjectID.class.getName());
+            if (id != null)
+            {
+               if (value == null || value.getMetaType().isSimple() == false)
+               {
+                  log.warn("Cannot create String name from non-Simple property: " + property + ", value=" + value);
+                  continue;
+               }
+               SimpleValue svalue = (SimpleValue) value;
+               String name = "" + svalue.getValue();
+               managedObject.setName(name);
+            }
+            ManagementRuntimeRef runtimeRef = (ManagementRuntimeRef) annotations.get(ManagementRuntimeRef.class.getName());
+            if (runtimeRef != null)
+            {
+               componentName = icf.getComponentName(beanInfo, property, object, value);
+            }
+         }
+      }
+      if (componentName == null)
+         componentName = icf.getComponentName(null, null, object, null);
+      // set it, even if it's null
+      managedObject.setComponentName(componentName);
+   }
+
+}


Property changes on: projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectPopulator.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision

Modified: projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/AbstractManagedObjectFactoryTest.java
===================================================================
--- projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/AbstractManagedObjectFactoryTest.java	2008-09-04 18:13:43 UTC (rev 77997)
+++ projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/AbstractManagedObjectFactoryTest.java	2008-09-04 18:14:49 UTC (rev 77998)
@@ -75,11 +75,16 @@
     */
    protected ManagedObject initManagedObject(Serializable object)
    {
-      ManagedObject result = managedObjectFactory.initManagedObject(object, null, null);
+      ManagedObject result = getMOF().initManagedObject(object, null, null);
       getLog().debug("Inited managed: " + result + " for object=" + Strings.defaultToString(object));
       return result;
    }
 
+   protected ManagedObjectFactory getMOF()
+   {
+      return managedObjectFactory;
+   }
+
    /**
     * Create a managed object
     * 
@@ -89,7 +94,7 @@
     */
    protected <T extends Serializable> ManagedObject createManagedObject(Class<T> clazz)
    {
-      ManagedObject result = managedObjectFactory.createManagedObject(clazz);
+      ManagedObject result = getMOF().createManagedObject(clazz);
       getLog().debug("Created managed: " + result + " for class=" + clazz.getName());
       return result;
    }
@@ -102,7 +107,7 @@
     */
    protected void setBuilder(Class<?> clazz, ManagedObjectBuilder builder)
    {
-      managedObjectFactory.setBuilder(clazz, builder);
+      getMOF().setBuilder(clazz, builder);
    }
    
    /**

Added: projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/support/amof/BigDecimalSimpleValue.java
===================================================================
--- projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/support/amof/BigDecimalSimpleValue.java	                        (rev 0)
+++ projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/support/amof/BigDecimalSimpleValue.java	2008-09-04 18:14:49 UTC (rev 77998)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.managed.factory.support.amof;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+
+import org.jboss.metatype.api.types.SimpleMetaType;
+import org.jboss.metatype.api.values.AbstractMetaValue;
+import org.jboss.metatype.api.values.SimpleValue;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class BigDecimalSimpleValue extends AbstractMetaValue implements SimpleValue
+{
+   private static final long serialVersionUID = 1L;
+
+   /** The value */
+   private BigDecimal value;
+
+   public BigDecimalSimpleValue(BigDecimal value)
+   {
+      this.value = value;
+   }
+
+   public SimpleMetaType getMetaType()
+   {
+      return SimpleMetaType.BIGDECIMAL;
+   }
+
+   public Serializable getValue()
+   {
+      return value;
+   }
+
+}


Property changes on: projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/support/amof/BigDecimalSimpleValue.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision

Added: projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/support/amof/TestICF.java
===================================================================
--- projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/support/amof/TestICF.java	                        (rev 0)
+++ projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/support/amof/TestICF.java	2008-09-04 18:14:49 UTC (rev 77998)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.managed.factory.support.amof;
+
+import java.io.Serializable;
+
+import org.jboss.managed.plugins.factory.AbstractInstanceClassFactory;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class TestICF extends AbstractInstanceClassFactory<Serializable>
+{
+   
+}


Property changes on: projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/support/amof/TestICF.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision

Added: projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/support/amof/TestMOP.java
===================================================================
--- projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/support/amof/TestMOP.java	                        (rev 0)
+++ projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/support/amof/TestMOP.java	2008-09-04 18:14:49 UTC (rev 77998)
@@ -0,0 +1,76 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.managed.factory.support.amof;
+
+import java.io.Serializable;
+import java.util.Map;
+
+import org.jboss.config.spi.Configuration;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.plugins.factory.AbstractManagedObjectPopulator;
+import org.jboss.managed.spi.factory.InstanceClassFactory;
+import org.jboss.managed.spi.factory.ManagedObjectPopulator;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class TestMOP extends AbstractManagedObjectPopulator<Serializable>
+   implements ManagedObjectPopulator<Serializable>
+{
+   private boolean createObjectCalled;
+   private boolean populateManagedObjectCalled;
+
+   public TestMOP(Configuration configuration,
+         InstanceClassFactory<? extends Serializable> defaultInstanceFactory,
+         Map<Class<?>, InstanceClassFactory<? extends Serializable>> instanceFactories)
+   {
+      super(configuration, defaultInstanceFactory, instanceFactories);
+   }
+   public TestMOP(Configuration configuration)
+   {
+      super(configuration);
+   }
+
+   public void createObject(ManagedObject managedObject,
+         Class<? extends Serializable> clazz)
+   {
+      createObjectCalled = true;
+      super.createObject(managedObject, clazz);
+   }
+
+   public void populateManagedObject(ManagedObject managedObject,
+         Serializable object)
+   {
+      populateManagedObjectCalled = true;
+      super.populateManagedObject(managedObject, object);
+   }
+
+   public boolean isCreateObjectCalled()
+   {
+      return createObjectCalled;
+   }
+   public boolean isPopulateManagedObjectCalled()
+   {
+      return populateManagedObjectCalled;
+   }
+}


Property changes on: projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/support/amof/TestMOP.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision

Added: projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/support/amof/TestSimpleICF.java
===================================================================
--- projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/support/amof/TestSimpleICF.java	                        (rev 0)
+++ projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/support/amof/TestSimpleICF.java	2008-09-04 18:14:49 UTC (rev 77998)
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.managed.factory.support.amof;
+
+
+import org.jboss.beans.info.spi.BeanInfo;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.managed.plugins.factory.AbstractInstanceClassFactory;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.test.managed.factory.support.Simple;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class TestSimpleICF extends AbstractInstanceClassFactory<Simple>
+{
+   private boolean getValueCalled;
+   private boolean setValueCalled;
+
+   @Override
+   public MetaValue getValue(BeanInfo beanInfo, ManagedProperty property,
+         Simple object)
+   {
+      getValueCalled = true;
+      return super.getValue(beanInfo, property, object);
+   }
+
+   public boolean isGetValueCalled()
+   {
+      return getValueCalled;
+   }
+
+   @Override
+   public void setValue(BeanInfo beanInfo, ManagedProperty property,
+         Simple object, MetaValue value)
+   {
+      setValueCalled = true;
+      super.setValue(beanInfo, property, object, value);
+   }
+
+   public boolean isSetValueCalled()
+   {
+      return setValueCalled;
+   }
+
+}


Property changes on: projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/support/amof/TestSimpleICF.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision

Added: projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/test/AbstractManagedObjectFactoryUnitTestCase.java
===================================================================
--- projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/test/AbstractManagedObjectFactoryUnitTestCase.java	                        (rev 0)
+++ projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/test/AbstractManagedObjectFactoryUnitTestCase.java	2008-09-04 18:14:49 UTC (rev 77998)
@@ -0,0 +1,124 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.managed.factory.test;
+
+import java.math.BigDecimal;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.factory.ManagedObjectFactory;
+import org.jboss.managed.plugins.factory.AbstractManagedObjectFactory;
+import org.jboss.test.managed.factory.AbstractManagedObjectFactoryTest;
+import org.jboss.test.managed.factory.support.ManagementPropertySimpleManaged;
+import org.jboss.test.managed.factory.support.Simple;
+import org.jboss.test.managed.factory.support.amof.TestICF;
+import org.jboss.test.managed.factory.support.amof.TestMOP;
+import org.jboss.test.managed.factory.support.amof.TestSimpleICF;
+
+/**
+ * Test of behavior of the AbstractManagedObjectFactory
+ * 
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class AbstractManagedObjectFactoryUnitTestCase extends AbstractManagedObjectFactoryTest
+{
+   private ManagedObjectFactory testMOF;
+
+   public static Test suite()
+   {
+      return new TestSuite(AbstractManagedObjectFactoryUnitTestCase.class);
+   }
+
+   public AbstractManagedObjectFactoryUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   /**
+    * Test overriding the AbstractManagedObjectFactory.defaultInstanceFactory 
+    */
+   public void testDefaultInstanceFactory()
+   {
+      AbstractManagedObjectFactory mof = new AbstractManagedObjectFactory();
+      mof.setDefaultInstanceFactory(new TestICF());
+      TestSimpleICF icf = new TestSimpleICF();
+      mof.setInstanceClassFactory(Simple.class, icf);
+      testMOF = mof;
+
+      BigDecimal bigDecimal = new BigDecimal(10);
+      Simple simple = new Simple();
+      simple.setBigDecimalValue(bigDecimal);
+
+      ManagedObject managedObject = initManagedObject(simple);
+      checkManagedObjectDefaults(Simple.class, managedObject);
+      checkDefaultManagedProperties(managedObject, Simple.class);
+
+      checkPropertyDefaults(managedObject, "bigDecimalValue", BigDecimal.class, bigDecimal);
+      assertTrue("TestBigDecimalICF.isGetValueCalled", icf.isGetValueCalled());
+
+      //
+      managedObject = super.createManagedObject(ManagementPropertySimpleManaged.class);
+      checkManagedObjectDefaults(ManagementPropertySimpleManaged.class, managedObject);
+      checkDefaultManagedProperties(managedObject, ManagementPropertySimpleManaged.class);
+   }
+
+   public void testDefaultManagedObjectPopulator()
+   {
+      AbstractManagedObjectFactory mof = new AbstractManagedObjectFactory();
+      TestMOP mop = new TestMOP(mof.getConfiguration(), new TestSimpleICF(), mof.getInstanceFactories());
+      mof.setDefaultManagedObjectPopulator(mop);
+      testMOF = mof;
+
+      BigDecimal bigDecimal = new BigDecimal(10);
+      Simple simple = new Simple();
+      simple.setBigDecimalValue(bigDecimal);
+
+      ManagedObject managedObject = initManagedObject(simple);
+      checkManagedObjectDefaults(Simple.class, managedObject);
+      checkDefaultManagedProperties(managedObject, Simple.class);
+      checkPropertyDefaults(managedObject, "bigDecimalValue", BigDecimal.class, bigDecimal);
+      assertTrue("isPopulateManagedObjectCalled", mop.isPopulateManagedObjectCalled());
+      //
+      managedObject = createManagedObject(ManagementPropertySimpleManaged.class);
+      checkManagedObjectDefaults(ManagementPropertySimpleManaged.class, managedObject);
+      checkDefaultManagedProperties(managedObject, ManagementPropertySimpleManaged.class);
+      assertTrue("isCreateObjectCalled", mop.isCreateObjectCalled());
+ 
+   }
+
+   /**
+    * Override to allow test specific ManagedObjectFactory
+    */
+   @Override
+   protected ManagedObjectFactory getMOF()
+   {
+      ManagedObjectFactory mof = testMOF;
+      if (mof == null)
+         mof = super.getMOF();
+      return mof;
+   }
+
+}


Property changes on: projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/test/AbstractManagedObjectFactoryUnitTestCase.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision




More information about the jboss-cvs-commits mailing list