public class BeanFactoryImpl extends AbstractLoggableComponent implements BeanFactory
BeanFactory
.Modifier and Type | Class and Description |
---|---|
protected class |
BeanFactoryImpl.BeanIntrospectionData
A container for the methods of a
Bean and related introspection data. |
Modifier and Type | Field and Description |
---|---|
private MemoryCache<Class<? extends Bean>,BeanAccessPrototypeInternal<?>> |
cache |
private ClassLoader |
classLoader |
private static BeanFactory |
instance |
private JsonUtil |
jsonUtil |
private static Type |
PROPERTY_VALUE_TYPE_VARIABLE |
private PropertyFactoryManager |
propertyFactoryManager |
private ReflectionUtil |
reflectionUtil |
Constructor and Description |
---|
BeanFactoryImpl()
The constructor.
|
BeanFactoryImpl(ClassLoader classLoader)
The constructor.
|
Modifier and Type | Method and Description |
---|---|
protected void |
collectMethods(Class<?> type,
BeanFactoryImpl.BeanIntrospectionData introspectionData)
|
<BEAN extends Bean> |
copy(BEAN bean)
Creates a copy of the given
Bean . |
<BEAN extends Bean> |
create(BEAN bean) |
private AbstractProperty<?> |
createProperty(BeanMethod beanMethod,
GenericType<?> beanType,
Bean bean) |
protected <V,PROPERTY extends ReadableProperty<V>> |
createProperty(String name,
GenericType<? extends V> valueType,
Bean bean,
Class<PROPERTY> propertyClass) |
protected <V> AbstractProperty<V> |
createProperty(String name,
GenericType<V> type,
Bean bean) |
private AbstractProperty<?> |
createPropertyFromSpecifiedClass(String name,
GenericType<?> type,
Bean bean,
Class<?> propertyClass) |
<BEAN extends Bean> |
createPrototype(Class<BEAN> type)
Creates a prototype of the given
Bean . |
BeanPrototypeBuilder |
createPrototypeBuilder(boolean dynamic) |
protected <BEAN extends Bean> |
createPrototypeInternal(Class<BEAN> type)
Creates the initial internal and not-
dynamic BeanAccessPrototype . |
(package private) <BEAN extends Bean> |
createProxy(BeanAccessBase<BEAN> access,
Class<?>... interfaces) |
protected void |
doInitialize()
This method performs the actual
initialization . |
protected void |
doInitialized()
This method is invoked at the end of the actual
initialization . |
static BeanFactory |
getInstance()
This method gets the singleton instance of this
BeanFactory . |
protected JsonUtil |
getJsonUtil() |
protected PropertyFactoryManager |
getPropertyFactoryManager() |
<BEAN extends Bean> |
getPrototype(BEAN bean) |
protected <BEAN extends Bean> |
getPrototypeInternal(Class<BEAN> type)
Gets the initial internal and not-
dynamic BeanAccessPrototype . |
<BEAN extends Bean> |
getReadOnlyBean(BEAN bean) |
protected ReflectionUtil |
getReflectionUtil() |
private void |
processMethods(BeanFactoryImpl.BeanIntrospectionData introspectionData,
BeanAccessPrototype<?> prototype,
GenericType<?> beanType) |
void |
setJsonUtil(JsonUtil jsonUtil) |
void |
setPropertyFactoryManager(PropertyFactoryManager propertyFactoryManager) |
void |
setReflectionUtil(ReflectionUtil reflectionUtil) |
createLogger, getLogger
getInitializationState, initialize
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
create, getQualifiedName, getQualifiedName
private static BeanFactory instance
private static final Type PROPERTY_VALUE_TYPE_VARIABLE
private final ClassLoader classLoader
private final MemoryCache<Class<? extends Bean>,BeanAccessPrototypeInternal<?>> cache
private ReflectionUtil reflectionUtil
private JsonUtil jsonUtil
private PropertyFactoryManager propertyFactoryManager
public BeanFactoryImpl()
public BeanFactoryImpl(ClassLoader classLoader)
classLoader
- the ClassLoader
to use.protected PropertyFactoryManager getPropertyFactoryManager()
PropertyFactoryManager
to use.@Inject public void setPropertyFactoryManager(PropertyFactoryManager propertyFactoryManager)
propertyFactoryManager
- the PropertyFactoryManager
to Inject
.protected ReflectionUtil getReflectionUtil()
ReflectionUtil
to use.@Inject public void setReflectionUtil(ReflectionUtil reflectionUtil)
reflectionUtil
- is the ReflectionUtil
to Inject
.@Inject public void setJsonUtil(JsonUtil jsonUtil)
jsonUtil
- is the JsonUtil
to Inject
.public static BeanFactory getInstance()
BeanFactory
. Cdi.GET_INSTANCE
before using.protected void doInitialize()
AbstractComponent
initialization
. It is called when AbstractComponent.initialize()
is
invoked for the first time. super.
AbstractComponent.doInitialize()
.doInitialize
in class AbstractLoggableComponent
protected void doInitialized()
AbstractComponent
initialization
. It is called when
AbstractComponent.initialize()
is invoked for the first time after AbstractComponent.doInitialize()
is completed and
initialization-state
has changed to initialized
. super.
AbstractComponent.doInitialized()
.doInitialized
in class AbstractComponent
<BEAN extends Bean> BEAN createProxy(BeanAccessBase<BEAN> access, Class<?>... interfaces)
public BeanPrototypeBuilder createPrototypeBuilder(boolean dynamic)
createPrototypeBuilder
in interface BeanFactory
dynamic
- the dynamic flag
of the Bean
s to build.BeanPrototypeBuilder
instance.public <BEAN extends Bean> BEAN create(BEAN bean)
create
in interface AbstractBeanFactory
BEAN
- the generic type of the Bean
.bean
- the prototype
of the Bean
to create.Bean
instance.BeanFactory.create(Class)
,
BeanPrototypeBuilder.createPrototype(Class, String, Bean...)
public <BEAN extends Bean> BEAN getReadOnlyBean(BEAN bean)
getReadOnlyBean
in interface AbstractBeanFactory
BEAN
- the generic type of the Bean
.bean
- the bean to make read-only
.read-only
view on the given bean. Will be the given instance if already
read-only
.public <BEAN extends Bean> BEAN getPrototype(BEAN bean)
getPrototype
in interface AbstractBeanFactory
BEAN
- the generic type of the Bean
.bean
- the Bean
.prototype
of the given Bean
.public <BEAN extends Bean> BEAN copy(BEAN bean)
AbstractBeanFactory
Bean
.public <BEAN extends Bean> BEAN createPrototype(Class<BEAN> type)
BeanFactory
Bean
. A prototype is used as template to create
regular Bean
s. Such beans will inherit the defaults from the prototype what are the
available properties
as well as their default value
.Class
for reflection and its Object
instance,
this approach makes it a lot easier. The prototype is like the Class
where Bean
-instances can be
created
of that are of the same type.createPrototype
in interface BeanFactory
BEAN
- the generic type of the Bean
.type
- the Class
reflecting the Bean
.Bean
.BeanPrototypeBuilder.createPrototype(Class, String, Bean...)
protected <BEAN extends Bean> BeanAccessPrototypeInternal<BEAN> getPrototypeInternal(Class<BEAN> type)
dynamic
BeanAccessPrototype
.
Using a WeakHashMap
as cache to avoid memory leaking and a ReentrantLock
to be thread-safe.BEAN
- the generic type of the Bean
.type
- the Class
reflecting the Bean
.BeanAccessPrototype
instance of the specified Bean
.protected <BEAN extends Bean> BeanAccessPrototypeInternal<BEAN> createPrototypeInternal(Class<BEAN> type)
dynamic
BeanAccessPrototype
.BEAN
- the generic type of the Bean
.type
- the Class
reflecting the Bean
.BeanAccessPrototype
instance of the specified Bean
.protected void collectMethods(Class<?> type, BeanFactoryImpl.BeanIntrospectionData introspectionData)
BeanMethod
s for a Bean
Class
. Also creates
the properties
for the property
methods.type
- is the current Bean
Class
to introspect.introspectionData
- the BeanFactoryImpl.BeanIntrospectionData
.private void processMethods(BeanFactoryImpl.BeanIntrospectionData introspectionData, BeanAccessPrototype<?> prototype, GenericType<?> beanType)
introspectionData
- the BeanFactoryImpl.BeanIntrospectionData
.prototype
- the BeanAccessPrototype
to process and complete.beanType
- the GenericType
reflecting the Bean
.private AbstractProperty<?> createProperty(BeanMethod beanMethod, GenericType<?> beanType, Bean bean)
beanMethod
- the BeanMethod
.beanType
- the GenericType
reflecting the bean owning the property
to create.bean
- the Bean
instance to create this property for.protected <V> AbstractProperty<V> createProperty(String name, GenericType<V> type, Bean bean)
V
- the generic type of type
.name
- the property name
.type
- the property type
.bean
- the property bean
.protected <V,PROPERTY extends ReadableProperty<V>> AbstractProperty<V> createProperty(String name, GenericType<? extends V> valueType, Bean bean, Class<PROPERTY> propertyClass)
V
- the generic property type.PROPERTY
- the generic type of the property
.name
- the property name
.valueType
- the property type
.bean
- the property bean
.propertyClass
- the Class
reflecting the WritableProperty
or null
if no property
method exists and this method is called for plain getter or setter.AbstractProperty
.private AbstractProperty<?> createPropertyFromSpecifiedClass(String name, GenericType<?> type, Bean bean, Class<?> propertyClass)
Copyright © 2001–2016 mmm-Team. All rights reserved.