Class MapBeanProvider
- java.lang.Object
-
- net.sf.jguiraffe.di.impl.providers.SimpleBeanProvider
-
- net.sf.jguiraffe.di.impl.providers.MapBeanProvider
-
- All Implemented Interfaces:
BeanProvider
- Direct Known Subclasses:
PropertiesBeanProvider
public class MapBeanProvider extends SimpleBeanProvider
A specialized
BeanProvider
implementation for creating beans of typejava.util.Map
.With this bean provider implementation either a
java.util.HashMap
or ajava.util.LinkedHashMap
can be created and populated. The mechanisms used here are very similar to the ones used byCollectionBeanProvider
: an instance is initialized with two lists ofDependency
objects - one list represents the key, the other list represents the values of the map. ThegetDependencies()
method returns a union of all these dependencies. When theMap
bean is to be created, a new instance of the correctMap
class is created. Then the dependencies for the keys and values are resolved, and the corresponding objects are added to the map.Bean providers of this type are intended to be used together with a
LifeCycleBeanProvider
that controls the creation of new instances.Implementation note: Objects of this class are immutable and thus can be shared between multiple threads.
- Version:
- $Id: MapBeanProvider.java 205 2012-01-29 18:29:57Z oheger $
- Author:
- Oliver Heger
-
-
Constructor Summary
Constructors Constructor Description MapBeanProvider(Collection<Dependency> keyDeps, Collection<Dependency> valDeps, boolean ordered)
Creates a new instance ofMapBeanProvider
and initializes it.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Map<Object,Object>
createMap()
Creates the map managed by this provider.Object
getBean(DependencyProvider dependencyProvider)
Returns the bean managed by this provider.Class<?>
getBeanClass(DependencyProvider dependencyProvider)
Returns the class of the managed bean.Set<Dependency>
getDependencies()
Returns the dependencies of this bean provider.Collection<Dependency>
getKeyDependencies()
Returns the dependencies for the keys of the map.Collection<Dependency>
getValueDependencies()
Returns the dependencies for the values of the map.boolean
isOrdered()
Returns the ordered flag.-
Methods inherited from class net.sf.jguiraffe.di.impl.providers.SimpleBeanProvider
getLockID, isBeanAvailable, setLockID, shutdown
-
-
-
-
Constructor Detail
-
MapBeanProvider
public MapBeanProvider(Collection<Dependency> keyDeps, Collection<Dependency> valDeps, boolean ordered)
Creates a new instance ofMapBeanProvider
and initializes it.- Parameters:
keyDeps
- the dependencies for the keys of the map (must not be null)valDeps
- the dependencies for the values of the map (must not be null)ordered
- a flag whether the order of the dependencies should be maintained- Throws:
IllegalArgumentException
- if eitherkeyDeps
orvalDeps
is null or the sizes of the collections are different
-
-
Method Detail
-
getKeyDependencies
public Collection<Dependency> getKeyDependencies()
Returns the dependencies for the keys of the map.- Returns:
- the key dependencies
-
getValueDependencies
public Collection<Dependency> getValueDependencies()
Returns the dependencies for the values of the map.- Returns:
- the value dependencies
-
isOrdered
public boolean isOrdered()
Returns the ordered flag. This property determines the type of the map created by this provider.- Returns:
- the ordered flag
-
getBean
public Object getBean(DependencyProvider dependencyProvider)
Returns the bean managed by this provider. This implementation callscreateMap()
to create the map. Then the dependencies for keys and values are resolved and added to the map.- Parameters:
dependencyProvider
- the dependency provider- Returns:
- the managed bean
-
getBeanClass
public Class<?> getBeanClass(DependencyProvider dependencyProvider)
Returns the class of the managed bean. This implementation simply returns the unspecificjava.util.Map
class.- Parameters:
dependencyProvider
- the dependency provider- Returns:
- the class of the bean managed by this provider
-
getDependencies
public Set<Dependency> getDependencies()
Returns the dependencies of this bean provider. This implementation returns a union of all key and value dependencies.- Specified by:
getDependencies
in interfaceBeanProvider
- Overrides:
getDependencies
in classSimpleBeanProvider
- Returns:
- a set with all dependencies of this bean provider
- See Also:
Dependency
-
-