public final class ConstantBeanProvider extends SimpleBeanProvider implements BeanProvider, Dependency
A concrete implementation of the BeanProvider
interface that
will always return the same bean instance.
When an instance of this class is created, the managed bean instance (and
optionally the target class if a type conversion is required) is passed in.
On its first call the getBean(DependencyProvider)
method checks
whether a type conversion if required. If this is the case, the conversion is
performed, and the resulting object is stored. Later invocations will then
always return this bean instance. The other methods defined by the
BeanProvider
interface are implemented as dummies: There are no
dependencies, and synchronization support is not needed.
In addition to the BeanProvider
interface, the
Dependency
interface is also implemented. This makes it possible
to have static dependencies, which are always resolved to a
BeanProvider
returning a constant bean. Dependencies of this
type may seem strange first, but they make sense in some cases. For instance
when a method is to be invoked, its parameters need to be defined. The
current parameter values may be dependencies to other beans in the current
bean store; so they need to be defined using dependencies. In simple cases
however constant values need to be passed (e.g. integers, flags, or string
values). For this purpose such a constant dependency can be used.
Instances of this class can be created using the static
getInstance()
factory methods. In any case the constant value of
the dependency must be passed in. It is also possible to specify the class of
this dependency. In this case the class will try a type conversion as
described above.
Modifier and Type | Field and Description |
---|---|
static ConstantBeanProvider |
NULL
Constant for a dependency that will be resolved to null.
|
Modifier and Type | Method and Description |
---|---|
Object |
getBean()
Returns the bean 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.
|
static ConstantBeanProvider |
getInstance(Class<?> valueClass,
Object value)
Returns an instance of this class that refers to the specified value of
the given class.
|
static ConstantBeanProvider |
getInstance(Object bean)
Creates a new instance of this class and initializes it with the bean to
be managed.
|
BeanProvider |
resolve(BeanStore store,
DependencyProvider depProvider)
Returns the
BeanProvider this Dependency refers
to. |
String |
toString()
Returns a string representation of this object.
|
getDependencies, getLockID, isBeanAvailable, setLockID, shutdown
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getDependencies, getLockID, isBeanAvailable, setLockID, shutdown
public static final ConstantBeanProvider NULL
public Object getBean()
public Object getBean(DependencyProvider dependencyProvider)
getBean
in interface BeanProvider
dependencyProvider
- the dependency providerpublic Class<?> getBeanClass(DependencyProvider dependencyProvider)
java.lang.Object
is returned.getBeanClass
in interface BeanProvider
dependencyProvider
- the dependency providerpublic BeanProvider resolve(BeanStore store, DependencyProvider depProvider)
BeanProvider
this Dependency
refers
to. This implementation simply returns the this pointer.resolve
in interface Dependency
store
- the bean storedepProvider
- the dependency providerBeanProvider
this Dependency
refers topublic String toString()
public static ConstantBeanProvider getInstance(Object bean)
bean
- the bean to be managedpublic static ConstantBeanProvider getInstance(Class<?> valueClass, Object value)
valueClass
- the class of this bean provider (can be null)value
- the value of the managed beanIllegalArgumentException
- if a conversion is necessary, but cannot
be performedCopyright © 2016 The JGUIraffe Team. All rights reserved.