org.jboss.metatype.plugins.values
Class DefaultMetaValueFactory

java.lang.Object
  extended by org.jboss.metatype.api.values.MetaValueFactory
      extended by org.jboss.metatype.plugins.values.DefaultMetaValueFactory

public class DefaultMetaValueFactory
extends MetaValueFactory

DefaultMetaValueFactory.

Version:
$Revision: 87758 $
Author:
Ales Justin, Adrian Brock, Scott.Stark@jboss.org

Constructor Summary
DefaultMetaValueFactory()
           
 
Method Summary
protected  org.jboss.reflect.spi.TypeInfo checkTypeInfo(org.jboss.reflect.spi.TypeInfo type, Object value, MetaType metaType)
          Do a simple check.
static Object[] convertPrimativeArray(Object value)
          Transform a primitive array into an Object[].
static Object[] convertPrimativeArray(org.jboss.reflect.spi.TypeInfo type, Object value)
          Transform a primitive array into an Object[].
protected  Object convertValue(Object value, org.jboss.reflect.spi.TypeInfo typeInfo)
          Convert the value.
 MetaValue create(Object value)
          Create a meta value
 MetaValue create(Object value, MetaType type)
          Create a meta value given its MetaType
 MetaValue create(Object value, Type type)
          Create a meta value
 MetaValue create(Object value, org.jboss.reflect.spi.TypeInfo type)
          Create a meta value
protected  Object[] createArray(MetaType elementType, Class<?> componentType, int dimension, Object[] oldArray)
          Create an array
 ArrayValue createArrayValue(ArrayMetaType type, Object value, Map<Object,MetaValue> mapping)
          Create an array value
 CollectionValue createCollectionValue(CollectionMetaType type, Object value, Map<Object,MetaValue> mapping)
          Create a collection value
 CompositeValue createCompositeValue(CompositeMetaType type, Object value, Map<Object,MetaValue> mapping)
          Create a composite value
protected  InvocationHandler createCompositeValueInvocationHandler(CompositeValue compositeValue)
          Create composite invocation handler.
static
<T extends Enum<?>>
EnumValue
createEnumValue(EnumMetaType type, T value)
          Create an enum value
static GenericValue createGenericValue(GenericMetaType type, Object value, Map<Object,MetaValue> mapping)
          Create a generic value
protected  Map<?,?> createMap(TableValue tableValue, org.jboss.reflect.spi.TypeInfo keyType, org.jboss.reflect.spi.TypeInfo valueType)
          Create a map
protected  Object createNewInstance(org.jboss.beans.info.spi.BeanInfo beanInfo)
          Create new instance.
protected  MetaValue createPropertiesValue(PropertiesMetaType metaType, Object value, Map<Object,MetaValue> mapping)
          Create a PropertiesMetaValue
static SimpleValue createSimpleValue(SimpleMetaType type, Serializable value)
          Create a simple value
 TableValue createTableValue(TableMetaType type, Map value, Map<Object,MetaValue> mapping)
          Create a table value
protected  org.jboss.reflect.spi.TypeInfo getTypeInfo(MetaType metaType, ClassLoader cl)
          Get the class info from meta type.
protected  org.jboss.reflect.spi.TypeInfo getTypeInfo(MetaType metaType, Object value)
          Get the class info from meta type.
protected  Object getValue(MetaType metaType, org.jboss.reflect.spi.TypeInfo typeInfo, Object value)
          Get the value.
protected  MetaValue internalCreate(Object value, org.jboss.reflect.spi.TypeInfo type, MetaType metaType)
          Create a meta value from the object
protected  Object internalUnwrap(MetaValue metaValue, org.jboss.reflect.spi.TypeInfo type)
          Unwrap value from meta value.
protected  MetaValue isBuilder(MetaType metaType, org.jboss.reflect.spi.TypeInfo type, Object value, Map<Object,MetaValue> mapping)
          Check for a builder
static Object mapNullToPrimitive(org.jboss.reflect.spi.TypeInfo type)
          Map null to primitive.
protected  Object newArrayInstance(org.jboss.reflect.spi.TypeInfo typeInfo, int size)
          Get new array instance.
 void setBuilder(Class<?> clazz, MetaValueBuilder<?> builder)
          Set a meta value builder.
<T> void
setInstanceFactory(Class<T> clazz, InstanceFactory<T> factory)
          Set an instance factory.
 Object unwrap(MetaValue metaValue)
          Unwrap meta value.
 Object unwrap(MetaValue metaValue, Type type)
          Unwrap meta value.
 Object unwrap(MetaValue metaValue, org.jboss.reflect.spi.TypeInfo type)
          Unwrap meta value.
protected  Object unwrapArray(Object array, Object element)
          Unwrap array.
protected  Object unwrapCollection(CollectionValue collectionValue, org.jboss.reflect.spi.TypeInfo type)
          Unwrap collection meta value.
protected  Object unwrapComposite(CompositeValue compositeValue, org.jboss.reflect.spi.TypeInfo typeInfo)
          Unwrap composite.
protected  Map unwrapCompositeMap(CompositeValue compositeValue)
           
protected  Object unwrapMetaValue(MetaValue element, org.jboss.reflect.spi.TypeInfo type, Object array)
          Unwrap MetaValue.
protected  Object unwrapProperties(PropertiesMetaValue propsValue, org.jboss.reflect.spi.TypeInfo type)
           
protected  Object unwrapTable(TableValue tableValue, org.jboss.reflect.spi.TypeInfo type)
          Unwrap table meta value.
 
Methods inherited from class org.jboss.metatype.api.values.MetaValueFactory
getInstance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultMetaValueFactory

public DefaultMetaValueFactory()
Method Detail

setBuilder

public void setBuilder(Class<?> clazz,
                       MetaValueBuilder<?> builder)
Description copied from class: MetaValueFactory
Set a meta value builder.

Specified by:
setBuilder in class MetaValueFactory
Parameters:
clazz - the class
builder - the builder

setInstanceFactory

public <T> void setInstanceFactory(Class<T> clazz,
                                   InstanceFactory<T> factory)
Description copied from class: MetaValueFactory
Set an instance factory.

Specified by:
setInstanceFactory in class MetaValueFactory
Type Parameters:
T - exact instance type
Parameters:
clazz - the class
factory - the factory

createSimpleValue

public static SimpleValue createSimpleValue(SimpleMetaType type,
                                            Serializable value)
Create a simple value

Parameters:
type - the type
value - the value
Returns:
the simple value

createEnumValue

public static <T extends Enum<?>> EnumValue createEnumValue(EnumMetaType type,
                                                            T value)
Create an enum value

Type Parameters:
T - the enum type
Parameters:
type - the type
value - the value
Returns:
the enum value

createGenericValue

public static GenericValue createGenericValue(GenericMetaType type,
                                              Object value,
                                              Map<Object,MetaValue> mapping)
Create a generic value

Parameters:
type - the type
value - the value
mapping - the mapping
Returns:
the generic value

createCollectionValue

public CollectionValue createCollectionValue(CollectionMetaType type,
                                             Object value,
                                             Map<Object,MetaValue> mapping)
Create a collection value

Parameters:
type - the type
value - the value
mapping - the mapping
Returns:
the generic value

convertPrimativeArray

public static Object[] convertPrimativeArray(org.jboss.reflect.spi.TypeInfo type,
                                             Object value)
Transform a primitive array into an Object[]. Converts a primitive array like char[] to Object[].

Parameters:
type - - the primitive array class type info.
value - - the primitive array instance.
Returns:
object array

mapNullToPrimitive

public static Object mapNullToPrimitive(org.jboss.reflect.spi.TypeInfo type)
Map null to primitive.

Parameters:
type - the type info
Returns:
default value

convertPrimativeArray

public static Object[] convertPrimativeArray(Object value)
Transform a primitive array into an Object[]. Converts a primitive array like char[] to Object[].

Parameters:
value - - the primitive array instance.
Returns:
object array

createArrayValue

public ArrayValue createArrayValue(ArrayMetaType type,
                                   Object value,
                                   Map<Object,MetaValue> mapping)
Create an array value

Parameters:
type - the type
value - the value
mapping - the mapping
Returns:
the composite value

createArray

protected Object[] createArray(MetaType elementType,
                               Class<?> componentType,
                               int dimension,
                               Object[] oldArray)
Create an array

Parameters:
elementType - the element type
componentType - the component type
dimension - the dimension
oldArray - the old array
Returns:
the array

createCompositeValue

public CompositeValue createCompositeValue(CompositeMetaType type,
                                           Object value,
                                           Map<Object,MetaValue> mapping)
Create a composite value

Parameters:
type - the type
value - the value
mapping - the mapping
Returns:
the composite value

createTableValue

public TableValue createTableValue(TableMetaType type,
                                   Map value,
                                   Map<Object,MetaValue> mapping)
Create a table value

Parameters:
type - the type
value - the value
mapping - the mapping
Returns:
the table value

create

public MetaValue create(Object value)
Description copied from class: MetaValueFactory
Create a meta value

Specified by:
create in class MetaValueFactory
Parameters:
value - the value
Returns:
the meta value

create

public MetaValue create(Object value,
                        Type type)
Description copied from class: MetaValueFactory
Create a meta value

Specified by:
create in class MetaValueFactory
Parameters:
value - the value
type - the type
Returns:
the meta value

create

public MetaValue create(Object value,
                        org.jboss.reflect.spi.TypeInfo type)
Description copied from class: MetaValueFactory
Create a meta value

Specified by:
create in class MetaValueFactory
Parameters:
value - the value
type - the type
Returns:
the meta value

create

public MetaValue create(Object value,
                        MetaType type)
Description copied from class: MetaValueFactory
Create a meta value given its MetaType

Specified by:
create in class MetaValueFactory
type - the meta type
Returns:
the meta value

unwrap

public Object unwrap(MetaValue metaValue)
Description copied from class: MetaValueFactory
Unwrap meta value. Supports simple and generic meta value.

Specified by:
unwrap in class MetaValueFactory
Parameters:
metaValue - meta value
Returns:
meta value's value

unwrap

public Object unwrap(MetaValue metaValue,
                     Type type)
Description copied from class: MetaValueFactory
Unwrap meta value. Supports simple and generic meta value.

Specified by:
unwrap in class MetaValueFactory
Parameters:
metaValue - meta value
type - the type
Returns:
meta value's value

unwrap

public Object unwrap(MetaValue metaValue,
                     org.jboss.reflect.spi.TypeInfo type)
Description copied from class: MetaValueFactory
Unwrap meta value. Supports simple and generic meta value.

Specified by:
unwrap in class MetaValueFactory
Parameters:
metaValue - meta value
type - the type
Returns:
meta value's value

internalUnwrap

protected Object internalUnwrap(MetaValue metaValue,
                                org.jboss.reflect.spi.TypeInfo type)
Unwrap value from meta value.

Parameters:
metaValue - the meta value
type - expected type info
Returns:
unwrapped value

checkTypeInfo

protected org.jboss.reflect.spi.TypeInfo checkTypeInfo(org.jboss.reflect.spi.TypeInfo type,
                                                       Object value,
                                                       MetaType metaType)
Do a simple check. If current type param is null, try getting type info from meta type and value's classloader.

Parameters:
type - the type info
value - tester value
metaType - the meta type
Returns:
type info

getValue

protected Object getValue(MetaType metaType,
                          org.jboss.reflect.spi.TypeInfo typeInfo,
                          Object value)
Get the value. Join type check and value conversion.

Parameters:
metaType - the meta type
typeInfo - the type info
value - the value
Returns:
the converted value

unwrapMetaValue

protected Object unwrapMetaValue(MetaValue element,
                                 org.jboss.reflect.spi.TypeInfo type,
                                 Object array)
Unwrap MetaValue.

Parameters:
element - the meta value
type - parent type
array - parent array
Returns:
unwrapped value

unwrapArray

protected Object unwrapArray(Object array,
                             Object element)
Unwrap array.

Parameters:
array - parent array
element - current array element
Returns:
unwrapped array element

unwrapProperties

protected Object unwrapProperties(PropertiesMetaValue propsValue,
                                  org.jboss.reflect.spi.TypeInfo type)

unwrapComposite

protected Object unwrapComposite(CompositeValue compositeValue,
                                 org.jboss.reflect.spi.TypeInfo typeInfo)
Unwrap composite.

Parameters:
compositeValue - the composite value
typeInfo - expected type info
Returns:
unwrapped value

unwrapCompositeMap

protected Map unwrapCompositeMap(CompositeValue compositeValue)

createCompositeValueInvocationHandler

protected InvocationHandler createCompositeValueInvocationHandler(CompositeValue compositeValue)
Create composite invocation handler.

Parameters:
compositeValue - the composite value
Returns:
composite invocation handler

unwrapCollection

protected Object unwrapCollection(CollectionValue collectionValue,
                                  org.jboss.reflect.spi.TypeInfo type)
Unwrap collection meta value.

Parameters:
collectionValue - the collection value
type - the type info
Returns:
unwrapped collection

unwrapTable

protected Object unwrapTable(TableValue tableValue,
                             org.jboss.reflect.spi.TypeInfo type)
Unwrap table meta value.

Parameters:
tableValue - the table value
type - the type info
Returns:
unwrapped table (map)

createMap

protected Map<?,?> createMap(TableValue tableValue,
                             org.jboss.reflect.spi.TypeInfo keyType,
                             org.jboss.reflect.spi.TypeInfo valueType)
Create a map

Parameters:
tableValue - the table value
keyType - the key type
valueType - the value type
Returns:
the map

createPropertiesValue

protected MetaValue createPropertiesValue(PropertiesMetaType metaType,
                                          Object value,
                                          Map<Object,MetaValue> mapping)
Create a PropertiesMetaValue

Parameters:
metaType -
value -
mapping -
Returns:

createNewInstance

protected Object createNewInstance(org.jboss.beans.info.spi.BeanInfo beanInfo)
                            throws Throwable
Create new instance.

Parameters:
beanInfo - the bean info
Returns:
new instance
Throws:
Throwable - for any error

newArrayInstance

protected Object newArrayInstance(org.jboss.reflect.spi.TypeInfo typeInfo,
                                  int size)
Get new array instance.

Parameters:
typeInfo - the type info
size - the size
Returns:
new array instance

getTypeInfo

protected org.jboss.reflect.spi.TypeInfo getTypeInfo(MetaType metaType,
                                                     Object value)
Get the class info from meta type.

Parameters:
metaType - the meta type
value - the value which can provide classloader
Returns:
type info

getTypeInfo

protected org.jboss.reflect.spi.TypeInfo getTypeInfo(MetaType metaType,
                                                     ClassLoader cl)
Get the class info from meta type.

Parameters:
metaType - the meta type
cl - the classloader
Returns:
class info

internalCreate

protected MetaValue internalCreate(Object value,
                                   org.jboss.reflect.spi.TypeInfo type,
                                   MetaType metaType)
Create a meta value from the object

Parameters:
value - the value
type - the type
metaType - the metaType
Returns:
the meta value

convertValue

protected Object convertValue(Object value,
                              org.jboss.reflect.spi.TypeInfo typeInfo)
Convert the value.

Parameters:
value - the value
typeInfo - type info
Returns:
converted value if type info not null
Throws:
UndeclaredThrowableException - for any error

isBuilder

protected MetaValue isBuilder(MetaType metaType,
                              org.jboss.reflect.spi.TypeInfo type,
                              Object value,
                              Map<Object,MetaValue> mapping)
Check for a builder

Parameters:
metaType - the meta type
type - the type
value - the value
mapping - the mappings
Returns:
the meta value


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