public class DIBuilderData extends Object
A data class for maintaining all information required for a DI builder operation.
An instance of this class will be present in the Jelly context when a Jelly
script for populating a BeanContext
is running. The specific tag
handler classes can access the information they need for adding newly created
beans to the correct BeanStore
or for accessing required helper
objects.
One important task of this class is dealing with BeanStore
objects: One root bean store must be provided, to which bean definitions are
added per default. In a builder script, it is possible to create an arbitrary
number of further bean stores below this root store. In a bean definition the
target bean store (where the bean should be stored) can be specified.
This class also maintains the current InvocationHelper
instance which
is responsible for reflection operations and (indirectly) for data type
conversions required by the current builder script. Either an instance of
InvocationHelper
can be set explicitly using the
setInvocationHelper(InvocationHelper)
method or a default instance
will be created. If the root BeanStore
is created by this object, the
ConversionHelper
will be set
automatically. If the root BeanStore
is set manually using the
initRootBeanStore(MutableBeanStore)
method, the caller is
responsible for initializing the root store with the correct
ConversionHelper
instance.
Implementation note: This class is not thread-safe. It is intended to be used inside a Jelly script, which runs in a single thread.
Constructor and Description |
---|
DIBuilderData()
Creates a new instance of
DIBuilderData . |
Modifier and Type | Method and Description |
---|---|
String |
addAnonymousBeanProvider(String storeName,
BeanProvider bean)
Adds an "anonymous"
BeanProvider to a
BeanStore . |
void |
addBeanProvider(String storeName,
String beanName,
BeanProvider bean)
Adds a
BeanProvider to a BeanStore . |
void |
addBeanStore(String name,
String parentName)
Creates a
BeanStore with the specified name and adds it to
the internal list of existing bean stores. |
protected MutableBeanStore |
createRootStore()
Creates the root bean store.
|
static DIBuilderData |
get(org.apache.commons.jelly.JellyContext context)
Obtains an instance of this class from the specified Jelly context.
|
BeanStore |
getBeanStore(String name)
Returns the
BeanStore with the specified name. |
Set<String> |
getBeanStoreNames()
Returns a set with the names of the existing bean stores.
|
ClassLoaderProvider |
getClassLoaderProvider()
Returns the
ClassLoaderProvider to be used. |
InvocationHelper |
getInvocationHelper()
Returns the current
InvocationHelper . |
BeanStore |
getRootBeanStore()
Returns the root bean store.
|
boolean |
hasBeanStore(String name)
Returns a flag whether the bean store with the given name is present.
|
void |
initRootBeanStore(MutableBeanStore rootBeanStore)
Sets the root bean store.
|
protected MutableBeanStore |
internalGetBeanStore(String name)
Returns the internal bean store with the given name.
|
void |
put(org.apache.commons.jelly.JellyContext context)
Stores this instance in the specified context.
|
void |
setClassLoaderProvider(ClassLoaderProvider classLoaderProvider)
Sets the
ClassLoaderProvider to be used. |
void |
setInvocationHelper(InvocationHelper invocationHelper)
Sets the
InvocationHelper to be used by this object. |
public ClassLoaderProvider getClassLoaderProvider()
ClassLoaderProvider
to be used. This method
never returns null. If no specific
ClassLoaderProvider
has been set so far (by using the
setClassLoaderProvider(ClassLoaderProvider)
method), a new default provider is created and returned, which does not
contain any specific registered class loaders.ClassLoaderProvider
to be usedpublic void setClassLoaderProvider(ClassLoaderProvider classLoaderProvider)
ClassLoaderProvider
to be used. This object is
especially required for resolving ClassDescription
objects.classLoaderProvider
- the ClassLoaderProvider
to be
usedpublic InvocationHelper getInvocationHelper()
InvocationHelper
. This object can be used by
all components involved in the builder process if reflection operations
or data type conversions are needed. If custom type converters are
needed, they have to be registered at conversion helper managed by this
instance.InvocationHelper
setInvocationHelper(InvocationHelper)
public void setInvocationHelper(InvocationHelper invocationHelper)
InvocationHelper
to be used by this object. Using this
method a specific InvocationHelper
instance can be set which will
then be returned by getInvocationHelper()
. If
getInvocationHelper()
is called and no helper object has been
set, a new default instance is created automatically.invocationHelper
- the InvocationHelper
to be usedpublic BeanStore getRootBeanStore()
public void initRootBeanStore(MutableBeanStore rootBeanStore)
addBeanStore()
method it is possible to create further bean
stores below this root store.rootBeanStore
- the root bean storepublic BeanStore getBeanStore(String name)
BeanStore
with the specified name. The root
store can be obtained by passing in null for the name. If a name
cannot be resolved, an exception is thrown.name
- the name of the desired bean storeNoSuchElementException
- if the name cannot be resolvedpublic boolean hasBeanStore(String name)
name
- the name of the bean store in questionpublic Set<String> getBeanStoreNames()
addBeanStore()
method. Note that the root bean store (which is identified by the name
null) is not contained in this set.public void addBeanStore(String name, String parentName)
BeanStore
with the specified name and adds it to
the internal list of existing bean stores. The new store is added as a
child of the specified parent bean store. If null is passed in for
the parent, the new store will become a child of the root bean store.
Note that the names of bean stores must be unique, even if they are at
different levels of the hierarchy.name
- the name of the bean store to be added (must not be
null)parentName
- the name of the parent bean storeNoSuchElementException
- if the parent name cannot be resolvedIllegalArgumentException
- if the name is null or is already
used by an existing bean storepublic void addBeanProvider(String storeName, String beanName, BeanProvider bean)
BeanProvider
to a BeanStore
. The bean
store with the specified name is resolved (null selects the root
bean store), and the provided BeanProvider
is added to it
under the given name.storeName
- the name of the bean storebeanName
- the name of the bean provider (must not be null)bean
- the bean provider to be added (must not be null)NoSuchElementException
- if the bean store cannot be resolvedIllegalArgumentException
- if the bean name or the bean provider is
nullpublic String addAnonymousBeanProvider(String storeName, BeanProvider bean)
BeanProvider
to a
BeanStore
. This method can be used for beans that are
visible in a local context only. It works similar to
addBeanProvider()
, but the bean store's
addAnonymousBeanProvider()
method will be called. This class
will keep a counter for generating indices for anonymous bean providers.
This ensures that the generated names used internally for these beans are
unique.storeName
- the name of the bean storebean
- the bean provider to be added (must not be null)IllegalArgumentException
- if no provider is specifiedpublic void put(org.apache.commons.jelly.JellyContext context)
context
- the Jelly contextpublic static DIBuilderData get(org.apache.commons.jelly.JellyContext context)
put()
method. If no instance can be found in this
context, null is returned.context
- the Jelly contextprotected MutableBeanStore internalGetBeanStore(String name)
DefaultBeanStore
objects. To its
clients only the immutable BeanStore
interface is exposed.name
- the name of the bean store to be retrieved (null means
the root bean store)NoSuchElementException
- if the bean store cannot be resolvedprotected MutableBeanStore createRootStore()
internalGetBeanStore()
when the root bean store is accessed
for the first time and has not been explicitly initialized.Copyright © 2016 The JGUIraffe Team. All rights reserved.