Class BeanContextWrapper

  • All Implemented Interfaces:
    BeanContext

    public class BeanContextWrapper
    extends 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 205 2012-01-29 18:29:57Z oheger $
    Author:
    Oliver Heger
    • 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:
        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:
        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 Set<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 Set<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 Set<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 Set<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​(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​(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​(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​(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 Object getBean​(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 Object getBean​(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​(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
        Type Parameters:
        T - the type of the bean
        Parameters:
        beanCls - the class of the desired bean
        Returns:
        the bean
      • getBean

        public <T> T getBean​(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
        Type Parameters:
        T - the type of the bean
        Parameters:
        beanCls - the class of the desired bean
        store - the store to start with
        Returns:
        the bean
      • beanNameFor

        public 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
      • 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
      • getClassLoaderProvider

        public ClassLoaderProvider getClassLoaderProvider()
        Returns the ClassLoaderProvider used by this context. This implementation delegates to the wrapped context.
        Specified by:
        getClassLoaderProvider in interface BeanContext
        Returns:
        the ClassLoaderProvider
      • setClassLoaderProvider

        public void setClassLoaderProvider​(ClassLoaderProvider clp)
        Sets the ClassLoaderProvider to be used by this context. This implementation delegates to the wrapped context.
        Specified by:
        setClassLoaderProvider in interface BeanContext
        Parameters:
        clp - the new ClassLoaderProvider