org.jboss.managed.plugins.factory
Class AbstractManagedObjectFactory

java.lang.Object
  extended by org.jboss.managed.api.factory.ManagedObjectFactory
      extended by org.jboss.managed.plugins.factory.AbstractManagedObjectFactory
All Implemented Interfaces:
ManagedObjectBuilder

public class AbstractManagedObjectFactory
extends ManagedObjectFactory
implements ManagedObjectBuilder

The base ManagedObjectFactory implementation.

Version:
$Revision: 87524 $
Author:
Adrian Brock, Scott.Stark@jboss.org

Field Summary
static GenericMetaType MANAGED_OBJECT_META_TYPE
          The managed object meta type
 
Constructor Summary
AbstractManagedObjectFactory()
          Create an AbstractManagedObjectFactory that uses an AbstractInstanceClassFactory as the defaultInstanceFactory and AbstractManagedObjectPopulator as the defaultManagedObjectPopulator.
AbstractManagedObjectFactory(MetaTypeFactory metaTypeFactory, MetaValueFactory metaValueFactory, InstanceClassFactory<?> defaultInstanceFactory, ManagedObjectPopulator<?> defaultManagedObjectPopulator, Map<Class<?>,ManagedObjectBuilder> builders, Map<Class<?>,InstanceClassFactory<?>> instanceFactories)
          Create an AbstractManagedObjectFactory the given factories, supporting information.
 
Method Summary
 void addDefaultValueBuilder(DefaultValueBuilder builder)
           
 void addManagedObjectDefinition(ManagedObjectDefinition definition)
          Add managed object definition.
 ManagedObject buildManagedObject(Class<?> clazz, org.jboss.metadata.spi.MetaData metaData)
          The ManagedObjectBuilder.buildManagedObject implementation.
protected  ManagedProperty createDefaultManagedProperty(Fields fields)
          Create default MangedProperty instance.
<T> ManagedObject
createManagedObject(Class<T> clazz, org.jboss.metadata.spi.MetaData metaData)
           
static ManagedProperty createManagedProperty(Class<? extends ManagedProperty> factory, Fields fields)
          Create a ManagedProperty by looking to the factory for ctor(Fields)
protected
<T> ManagedObject
createSkeletonManagedObject(Class<T> clazz, org.jboss.metadata.spi.MetaData metaData)
          Create a skeleton managed object
protected
<X extends Annotation>
X
getAnnotation(Class<X> annotationType, org.jboss.reflect.spi.AnnotatedInfo info, org.jboss.metadata.spi.MetaData metaData)
           
protected  Collection<?> getAsCollection(Object value)
           
protected  org.jboss.beans.info.spi.BeanInfo getBeanInfo(Class<?> iface)
          Build up a BeanInfo from the interface class and all interfaces it implements.
protected  ManagedObjectBuilder getBuilder(Class<?> clazz)
          Get the builder for a class
 Map<Class<?>,ManagedObjectBuilder> getBuilders()
           
 org.jboss.config.spi.Configuration getConfiguration()
          Get the configuration
 InstanceClassFactory<?> getDefaultInstanceFactory()
          Get the default InstanceClassFactory
 ManagedObjectPopulator<?> getDefaultManagedObjectPopulator()
           
<X> InstanceClassFactory<X>
getInstanceClassFactory(Class<X> clazz, org.jboss.metadata.spi.MetaData metaData)
          Get the instance factory for a class
 Map<Class<?>,InstanceClassFactory<?>> getInstanceFactories()
           
protected  ManagedOperation getManagedOperation(org.jboss.reflect.spi.MethodInfo methodInfo, ManagementOperation opAnnotation, org.jboss.metadata.spi.MetaData metaData)
           
protected  ManagedProperty getManagedProperty(Class<? extends ManagedProperty> factory, Fields fields)
          Look for ctor(Fields)
protected  MetaType getMetaType(org.jboss.reflect.spi.AnnotatedInfo info, org.jboss.reflect.spi.TypeInfo infoType, org.jboss.metadata.spi.MetaData metaData, boolean useTypeFactory, MetaMapper[] mapperReturn)
          Get the MetaType for info by looking for MetaMapping/MetaMappingFactory annotations in addition to the info type.
 MetaTypeFactory getMetaTypeFactory()
           
 MetaValueFactory getMetaValueFactory()
           
protected
<X> ManagedObjectPopulator<X>
getPopulator(Class<X> clazz)
          Get the populator for a class
protected  String getPropertyName(ManagedProperty property)
          Get the property name.
protected  void initDefaultValueBuilders()
          Initialize the DefaultValueBuilder map with known implementations
 ManagedObject initManagedObject(Object instance, Class<?> instanceType, org.jboss.metadata.spi.MetaData metaData, String name, String nameType)
          Create a managed object from the given object
 void removeDefaltValueBuilder(DefaultValueBuilder builder)
           
 void removeManagedObjectDefinition(ManagedObjectDefinition definition)
          Remove managed object definition.
 void setBuilder(Class<?> clazz, ManagedObjectBuilder builder)
          Set a managed object builder
 void setBuilders(Map<Class<?>,ManagedObjectBuilder> builders)
           
 void setDefaultInstanceFactory(InstanceClassFactory<? extends Serializable> defaultInstanceFactory)
          Set the default InstanceClassFactory.
 void setDefaultManagedObjectPopulator(ManagedObjectPopulator<? extends Serializable> defaultManagedObjectPopulator)
          A default implementation of ManagedObjectPopulator that is used when there is no ManagedObjectBuilder registered for a given type.
 void setDefaultsBuilder(MetaType type, DefaultValueBuilder builder)
           
<T> void
setInstanceClassFactory(Class<T> clazz, InstanceClassFactory<T> factory)
          Set the InstanceClassFactory for an instance type.
 void setInstanceFactories(Map<Class<?>,InstanceClassFactory<?>> instanceFactories)
           
 void setMetaTypeFactory(MetaTypeFactory metaTypeFactory)
           
 void setMetaValueFactory(MetaValueFactory metaValueFactory)
           
 
Methods inherited from class org.jboss.managed.api.factory.ManagedObjectFactory
addInstanceClassFactory, createManagedObject, getInstance, getInstanceClassFactory, initManagedObject, initManagedObject, initManagedObject, removeInstanceClassFactory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MANAGED_OBJECT_META_TYPE

public static final GenericMetaType MANAGED_OBJECT_META_TYPE
The managed object meta type

Constructor Detail

AbstractManagedObjectFactory

public AbstractManagedObjectFactory()
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.


AbstractManagedObjectFactory

public AbstractManagedObjectFactory(MetaTypeFactory metaTypeFactory,
                                    MetaValueFactory metaValueFactory,
                                    InstanceClassFactory<?> defaultInstanceFactory,
                                    ManagedObjectPopulator<?> defaultManagedObjectPopulator,
                                    Map<Class<?>,ManagedObjectBuilder> builders,
                                    Map<Class<?>,InstanceClassFactory<?>> instanceFactories)
Create an AbstractManagedObjectFactory the given factories, supporting information.

Parameters:
metaTypeFactory -
metaValueFactory -
defaultInstanceFactory -
defaultManagedObjectPopulator -
builders -
instanceFactories -
Method Detail

createManagedProperty

public static ManagedProperty createManagedProperty(Class<? extends ManagedProperty> factory,
                                                    Fields fields)
Create a ManagedProperty by looking to the factory for ctor(Fields)

Parameters:
factory - - the ManagedProperty implementation class
fields - - the fields to pass to the ctor
Returns:
the managed property if successful, null otherwise

addManagedObjectDefinition

public void addManagedObjectDefinition(ManagedObjectDefinition definition)
Add managed object definition.

Parameters:
definition - the MO definition

removeManagedObjectDefinition

public void removeManagedObjectDefinition(ManagedObjectDefinition definition)
Remove managed object definition.

Parameters:
definition - the MO definition

addDefaultValueBuilder

public void addDefaultValueBuilder(DefaultValueBuilder builder)

setDefaultsBuilder

public void setDefaultsBuilder(MetaType type,
                               DefaultValueBuilder builder)

removeDefaltValueBuilder

public void removeDefaltValueBuilder(DefaultValueBuilder builder)

getConfiguration

public org.jboss.config.spi.Configuration getConfiguration()
Get the configuration

Returns:
the configuration

getMetaTypeFactory

public MetaTypeFactory getMetaTypeFactory()

setMetaTypeFactory

public void setMetaTypeFactory(MetaTypeFactory metaTypeFactory)

getMetaValueFactory

public MetaValueFactory getMetaValueFactory()

setMetaValueFactory

public void setMetaValueFactory(MetaValueFactory metaValueFactory)

getBuilders

public Map<Class<?>,ManagedObjectBuilder> getBuilders()

setBuilders

public void setBuilders(Map<Class<?>,ManagedObjectBuilder> builders)

getInstanceFactories

public Map<Class<?>,InstanceClassFactory<?>> getInstanceFactories()

setInstanceFactories

public void setInstanceFactories(Map<Class<?>,InstanceClassFactory<?>> instanceFactories)

getDefaultInstanceFactory

public InstanceClassFactory<?> getDefaultInstanceFactory()
Get the default InstanceClassFactory

Returns:
the current default InstanceClassFactory

setDefaultInstanceFactory

public void setDefaultInstanceFactory(InstanceClassFactory<? extends Serializable> defaultInstanceFactory)
Set the default InstanceClassFactory. This is used when there is not match an exact match by the ManagedObjectFactory.getInstanceClassFactory(Class) factory method.

Parameters:
defaultInstanceFactory - the default InstanceClassFactory to fall back to. It may be null if no default should be used.

getDefaultManagedObjectPopulator

public ManagedObjectPopulator<?> getDefaultManagedObjectPopulator()

setDefaultManagedObjectPopulator

public void setDefaultManagedObjectPopulator(ManagedObjectPopulator<? extends Serializable> defaultManagedObjectPopulator)
A default implementation of ManagedObjectPopulator that is used when there is no ManagedObjectBuilder registered for a given type.

Parameters:
defaultManagedObjectPopulator -
See Also:
getBuilder(Class)

createManagedObject

public <T> ManagedObject createManagedObject(Class<T> clazz,
                                             org.jboss.metadata.spi.MetaData metaData)
Specified by:
createManagedObject in class ManagedObjectFactory

initManagedObject

public ManagedObject initManagedObject(Object instance,
                                       Class<?> instanceType,
                                       org.jboss.metadata.spi.MetaData metaData,
                                       String name,
                                       String nameType)
Description copied from class: ManagedObjectFactory
Create a managed object from the given object

Specified by:
initManagedObject in class ManagedObjectFactory
Parameters:
instance - - the object to build the ManagedObject from
instanceType - - the optional type to determine InstanceClassFactory registration from. If not specified instance.getClass() is used.
metaData - - the optional metadata repository accessor used to query for management annotation overrides/additions to the clazz
name - - the name of the managed object. If null, the name will be derived from the object annotations or attachment name.
nameType - - the name of the managed object. If null, the name will be derived from the object annotations or default to "".
Returns:
the managed object
See Also:
ManagementObjectID

setBuilder

public void setBuilder(Class<?> clazz,
                       ManagedObjectBuilder builder)
Description copied from class: ManagedObjectFactory
Set a managed object builder

Specified by:
setBuilder in class ManagedObjectFactory
Parameters:
clazz - the class
builder - the builder (null to remove the builder)

setInstanceClassFactory

public <T> void setInstanceClassFactory(Class<T> clazz,
                                        InstanceClassFactory<T> factory)
Description copied from class: ManagedObjectFactory
Set the InstanceClassFactory for an instance type.

Specified by:
setInstanceClassFactory in class ManagedObjectFactory
Parameters:
clazz - the class
factory - - the factory used to obtain the class to scan for management annotations.

createSkeletonManagedObject

protected <T> ManagedObject createSkeletonManagedObject(Class<T> clazz,
                                                        org.jboss.metadata.spi.MetaData metaData)
Create a skeleton managed object

Type Parameters:
T - the type
Parameters:
clazz - the clazz
Returns:
the skeleton managed object, null if clazz is not marked as a ManagementObject. ManagementObject

buildManagedObject

public ManagedObject buildManagedObject(Class<?> clazz,
                                        org.jboss.metadata.spi.MetaData metaData)
The ManagedObjectBuilder.buildManagedObject implementation. This is based on the org.jboss.managed.api.annotation.* package annotations.

Specified by:
buildManagedObject in interface ManagedObjectBuilder
Parameters:
clazz - the attachment class
metaData - - the optional metadata repository accessor used to query for management annotation overrides/additions to the clazz
Returns:
the ManagementObject if clazz is properly annotated, null if it does not have a ManagementObject annotation on the class or metaData. The BeanInfo used by this method is stored as a transient attachment under the BeanInfo.class.getName() ket.

createDefaultManagedProperty

protected ManagedProperty createDefaultManagedProperty(Fields fields)
Create default MangedProperty instance. Override this method for different default.

Parameters:
fields - the fields
Returns:
new ManagedProperty instance

getPropertyName

protected String getPropertyName(ManagedProperty property)
Get the property name.

Parameters:
property - managed property
Returns:
property name

getManagedOperation

protected ManagedOperation getManagedOperation(org.jboss.reflect.spi.MethodInfo methodInfo,
                                               ManagementOperation opAnnotation,
                                               org.jboss.metadata.spi.MetaData metaData)
Parameters:
methodInfo -
opAnnotation -
Returns:
the managed operation

getMetaType

protected MetaType getMetaType(org.jboss.reflect.spi.AnnotatedInfo info,
                               org.jboss.reflect.spi.TypeInfo infoType,
                               org.jboss.metadata.spi.MetaData metaData,
                               boolean useTypeFactory,
                               MetaMapper[] mapperReturn)
Get the MetaType for info by looking for MetaMapping/MetaMappingFactory annotations in addition to the info type.

Parameters:
methodInfo -
metaData -
Returns:
the MetaType for info's type

getBuilder

protected ManagedObjectBuilder getBuilder(Class<?> clazz)
Get the builder for a class

Parameters:
clazz - the class
Returns:
the builder

getInstanceClassFactory

public <X> InstanceClassFactory<X> getInstanceClassFactory(Class<X> clazz,
                                                           org.jboss.metadata.spi.MetaData metaData)
Get the instance factory for a class

Specified by:
getInstanceClassFactory in class ManagedObjectFactory
Parameters:
clazz - the class
Returns:
the InstanceClassFactory

initDefaultValueBuilders

protected void initDefaultValueBuilders()
Initialize the DefaultValueBuilder map with known implementations


getPopulator

protected <X> ManagedObjectPopulator<X> getPopulator(Class<X> clazz)
Get the populator for a class

Parameters:
clazz - the class
Returns:
the populator

getAsCollection

protected Collection<?> getAsCollection(Object value)

getManagedProperty

protected ManagedProperty getManagedProperty(Class<? extends ManagedProperty> factory,
                                             Fields fields)
Look for ctor(Fields)

Parameters:
factory - - the ManagedProperty implementation class
fields - - the fields to pass to the ctor
Returns:
the managed property

getAnnotation

protected <X extends Annotation> X getAnnotation(Class<X> annotationType,
                                                 org.jboss.reflect.spi.AnnotatedInfo info,
                                                 org.jboss.metadata.spi.MetaData metaData)

getBeanInfo

protected org.jboss.beans.info.spi.BeanInfo getBeanInfo(Class<?> iface)
Build up a BeanInfo from the interface class and all interfaces it implements.

Parameters:
iface - - the interface for the managed object
Returns:
the full BeanInfo for the iface


Copyright © 2009 JBoss, a division of Red Hat, Inc.. All Rights Reserved.