net.sf.jguiraffe.di.impl
Class BeanContextWrapper

java.lang.Object
  extended by net.sf.jguiraffe.di.impl.BeanContextWrapper
All Implemented Interfaces:
BeanContext

public class BeanContextWrapper
extends java.lang.Object
implements BeanContext

A simple wrapper implementation of the BeanContext interface.

The main purpose of this class is to override the default BeanStore of a bean context. It is initialized with the BeanContext object to be wrapped and the default BeanStore to be used. All calls to methods defined by the BeanContext interface are delegated to the wrapped bean context object. If they address the default bean store (i.e. no bean store is explicitly passed to the method), the bean store set for this instance is used. That way an already configured bean context can be used in a different context (which means, using another bean store as default entry in the look up mechanism) without manipulating its state.

Version:
$Id: BeanContextWrapper.java 156 2009-03-03 21:04:47Z oheger $
Author:
Oliver Heger

Constructor Summary
BeanContextWrapper(BeanContext wrappedContext)
          Creates a new instance of BeanContextWrapper and sets the wrapped context.
BeanContextWrapper(BeanContext wrappedContext, BeanStore defaultStore)
          Creates a new instance of BeanContextWrapper and sets the wrapped context and the default bean store.
 
Method Summary
 void addBeanCreationListener(BeanCreationListener l)
          Adds the specified BeanCreationListener to this context.
 java.util.Set<java.lang.Class<?>> beanClasses()
          Returns a set of the classes of the beans available in this bean context's default bean store.
 java.util.Set<java.lang.Class<?>> beanClasses(BeanStore store)
          Returns a set of the classes of the beans available in the specified bean store.
 java.lang.String beanNameFor(BeanProvider beanProvider)
          Returns the name of the given BeanProvider starting the search with the default bean store.
 java.lang.String beanNameFor(BeanProvider beanProvider, BeanStore store)
          Returns the name of the given BeanProvider starting the search with the specified bean store.
 java.util.Set<java.lang.String> beanNames()
          Returns a set with the names of the beans defined in this context's default bean store.
 java.util.Set<java.lang.String> beanNames(BeanStore store)
          Returns a set with the names of the beans defined in the given bean store.
 void close()
          Closes this BeanContext.
 boolean containsBean(java.lang.Class<?> beanClass)
          Checks whether a bean with the given class can be found in this bean context's default bean store.
 boolean containsBean(java.lang.Class<?> beanClass, BeanStore store)
          Checks whether a bean with the given class can be found in the specified bean store.
 boolean containsBean(java.lang.String name)
          Checks whether a bean with the given name can be found in the default bean store of this bean context.
 boolean containsBean(java.lang.String name, BeanStore store)
          Checks whether a bean with the given name can be found in the specified bean store.
<T> T
getBean(java.lang.Class<T> beanCls)
          Returns the bean with the given class starting the search with the default bean store.
<T> T
getBean(java.lang.Class<T> beanCls, BeanStore store)
          Returns the bean with the given class starting the search with the specified bean store.
 java.lang.Object getBean(java.lang.String name)
          Returns the bean with the given name starting the search with the default bean store.
 java.lang.Object getBean(java.lang.String name, BeanStore store)
          Returns the bean with the given name starting the search with the specified bean store.
 BeanStore getDefaultBeanStore()
          Returns the default bean store.
 BeanContext getWrappedContext()
          Returns the wrapped bean context.
 void removeBeanCreationListener(BeanCreationListener l)
          Removes the specified BeanCreationListener from this context.
 void setDefaultBeanStore(BeanStore store)
          Sets the default bean store.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BeanContextWrapper

public BeanContextWrapper(BeanContext wrappedContext)
Creates a new instance of BeanContextWrapper and sets the wrapped context.

Parameters:
wrappedContext - the bean context to be wrapped (must not be null)
Throws:
java.lang.IllegalArgumentException - if the bean context is null

BeanContextWrapper

public BeanContextWrapper(BeanContext wrappedContext,
                          BeanStore defaultStore)
Creates a new instance of BeanContextWrapper and sets the wrapped context and the default bean store.

Parameters:
wrappedContext - the bean context to be wrapped (must not be null)
defaultStore - the default bean store ton be used
Throws:
java.lang.IllegalArgumentException - if the bean context is null
Method Detail

getWrappedContext

public BeanContext getWrappedContext()
Returns the wrapped bean context.

Returns:
a reference to the original bean context

beanClasses

public java.util.Set<java.lang.Class<?>> beanClasses()
Returns a set of the classes of the beans available in this bean context's default bean store. This implementation delegates to the wrapped context.

Specified by:
beanClasses in interface BeanContext
Returns:
a set with the classes of the defined beans

beanClasses

public java.util.Set<java.lang.Class<?>> beanClasses(BeanStore store)
Returns a set of the classes of the beans available in the specified bean store. This implementation delegates to the wrapped context.

Specified by:
beanClasses in interface BeanContext
Parameters:
store - the bean store
Returns:
a set with the classes of the defined beans

beanNames

public java.util.Set<java.lang.String> beanNames()
Returns a set with the names of the beans defined in this context's default bean store. This implementation delegates to the wrapped context.

Specified by:
beanNames in interface BeanContext
Returns:
a set with the names of the defined beans

beanNames

public java.util.Set<java.lang.String> beanNames(BeanStore store)
Returns a set with the names of the beans defined in the given bean store. This implementation delegates to the wrapped context.

Specified by:
beanNames in interface BeanContext
Parameters:
store - the bean store
Returns:
a set with the names of the defined beans

containsBean

public boolean containsBean(java.lang.String name)
Checks whether a bean with the given name can be found in the default bean store of this bean context. This implementation delegates to the wrapped context.

Specified by:
containsBean in interface BeanContext
Parameters:
name - the name of the searched bean
Returns:
a flag whether this bean can be found

containsBean

public boolean containsBean(java.lang.String name,
                            BeanStore store)
Checks whether a bean with the given name can be found in the specified bean store. This implementation delegates to the wrapped context.

Specified by:
containsBean in interface BeanContext
Parameters:
name - the name of the bean
store - the bean store
Returns:
a flag whether this bean can be found

containsBean

public boolean containsBean(java.lang.Class<?> beanClass)
Checks whether a bean with the given class can be found in this bean context's default bean store. This implementation delegates to the wrapped context.

Specified by:
containsBean in interface BeanContext
Parameters:
beanClass - the class of the bean
Returns:
a flag whether this bean can be found

containsBean

public boolean containsBean(java.lang.Class<?> beanClass,
                            BeanStore store)
Checks whether a bean with the given class can be found in the specified bean store. This implementation delegates to the wrapped context.

Specified by:
containsBean in interface BeanContext
Parameters:
beanClass - the class of the bean
store - the bean store
Returns:
a flag whether this bean can be found

getBean

public java.lang.Object getBean(java.lang.String name)
Returns the bean with the given name starting the search with the default bean store. This implementation delegates to the wrapped context.

Specified by:
getBean in interface BeanContext
Parameters:
name - the name of the desired bean
Returns:
the bean

getBean

public java.lang.Object getBean(java.lang.String name,
                                BeanStore store)
Returns the bean with the given name starting the search with the specified bean store. This implementation delegates to the wrapped context.

Specified by:
getBean in interface BeanContext
Parameters:
name - the name of the desired bean
store - the bean store to start with
Returns:
the bean

getBean

public <T> T getBean(java.lang.Class<T> beanCls)
Returns the bean with the given class starting the search with the default bean store. This implementation delegates to the wrapped context.

Specified by:
getBean in interface BeanContext
Parameters:
beanCls - the class of the desired bean
Returns:
the bean

getBean

public <T> T getBean(java.lang.Class<T> beanCls,
                     BeanStore store)
Returns the bean with the given class starting the search with the specified bean store. This implementation delegates to the wrapped context.

Specified by:
getBean in interface BeanContext
Parameters:
beanCls - the class of the desired bean
store - the store to start with
Returns:
the bean

beanNameFor

public java.lang.String beanNameFor(BeanProvider beanProvider)
Returns the name of the given BeanProvider starting the search with the default bean store. This implementation delegates to the wrapped context.

Specified by:
beanNameFor in interface BeanContext
Parameters:
beanProvider - the BeanProvider
Returns:
the name of this BeanProvider or null
See Also:
BeanContext.beanNameFor(BeanProvider, BeanStore)

beanNameFor

public java.lang.String beanNameFor(BeanProvider beanProvider,
                                    BeanStore store)
Returns the name of the given BeanProvider starting the search with the specified bean store. This implementation delegates to the wrapped context.

Specified by:
beanNameFor in interface BeanContext
Parameters:
beanProvider - the BeanProvider
store - the BeanStore
Returns:
the name of this BeanProvider or null

getDefaultBeanStore

public BeanStore getDefaultBeanStore()
Returns the default bean store. This implementation returns the default store set for this wrapped context and not the one of the underlying context.

Specified by:
getDefaultBeanStore in interface BeanContext
Returns:
the default bean store

setDefaultBeanStore

public void setDefaultBeanStore(BeanStore store)
Sets the default bean store. This implementation only changes the default bean store of this wrapped context. The default store of the underlying context is not touched.

Specified by:
setDefaultBeanStore in interface BeanContext
Parameters:
store - the new default bean store

addBeanCreationListener

public void addBeanCreationListener(BeanCreationListener l)
Adds the specified BeanCreationListener to this context. This implementation ensures that events from the wrapped context are received. However, the events are correctly transformed so that this context is set as the source context of the event.

Specified by:
addBeanCreationListener in interface BeanContext
Parameters:
l - the listener to be added

removeBeanCreationListener

public void removeBeanCreationListener(BeanCreationListener l)
Removes the specified BeanCreationListener from this context.

Specified by:
removeBeanCreationListener in interface BeanContext
Parameters:
l - the listener to be removed

close

public void close()
Closes this BeanContext. This implementation removes the BeanCreationListener registered at the wrapped context. Note that the wrapped context will not be closed! This is because the wrapped context is typically shared.

Specified by:
close in interface BeanContext


Copyright © 2009 The JGUIraffe Team. All Rights Reserved.