public abstract class CollectionBeanProvider extends SimpleBeanProvider
An abstract base class for BeanProvider
implementations that
create beans derived from collections.
This bean provider base implementation can be used when collection beans are to be created. What makes collections a bit special is the fact that their elements are also dependencies, which can reference other beans. So this bean provider has to ensure that all dependencies are registered correctly, so they can be resolved when the collection is created.
This class implements the major part of the functionality required for
creating collection beans. It is initialized with a collection of
dependencies representing the elements of the final collection. These can be
either constant dependencies or references to other beans. In the
getBean()
implementation a collection of the correct type is
created, the element dependencies are resolved, and the resulting objects are
added to the collection.
A concrete subclass is responsible for creating a collection of a specific
type. For this purpose the createCollection()
method has to be
defined. It is invoked by getBean()
for obtaining a new
instance of the collection class supported.
Bean providers of this type are intended to be used together with a
that controls the creation of
new instances.
LifeCycleBeanProvider
Implementation note: Objects of this class are immutable and thus can be shared between multiple threads.
Modifier | Constructor and Description |
---|---|
protected |
CollectionBeanProvider(Collection<Dependency> deps)
Creates a new instance of
CollectionBeanProvider and
initializes it with a collection with the dependencies of the elements. |
Modifier and Type | Method and Description |
---|---|
protected abstract Collection<Object> |
createCollection(int size)
Creates the collection.
|
Object |
getBean(DependencyProvider dependencyProvider)
Returns the bean managed by this provider.
|
Class<?> |
getBeanClass(DependencyProvider dependencyProvider)
Returns the class of the bean created by this provider.
|
Set<Dependency> |
getDependencies()
Returns a set with the dependencies of this bean provider.
|
Collection<Dependency> |
getElementDependencies()
Returns a collection with the dependencies of the collection elements.
|
getLockID, isBeanAvailable, setLockID, shutdown
protected CollectionBeanProvider(Collection<Dependency> deps)
CollectionBeanProvider
and
initializes it with a collection with the dependencies of the elements.deps
- a collection with the element dependencies (must not be
null)IllegalArgumentException
- if the collection is nullpublic Collection<Dependency> getElementDependencies()
public Object getBean(DependencyProvider dependencyProvider)
createCollection()
. Then the
dependencies for the elements are resolved and added to the collection.dependencyProvider
- the dependency providerpublic Class<?> getBeanClass(DependencyProvider dependencyProvider)
Collection.class
. We expect
that collection beans are not so specific that they are queried by class.dependencyProvider
- the dependency providerpublic Set<Dependency> getDependencies()
getDependencies
in interface BeanProvider
getDependencies
in class SimpleBeanProvider
Dependency
protected abstract Collection<Object> createCollection(int size)
size
- the initial size of the new collection; here the number of
elements is passed inCopyright © 2016 The JGUIraffe Team. All rights reserved.