Class RestrictedDependencyProvider

  • All Implemented Interfaces:
    ClassLoaderProvider, DependencyProvider

    public class RestrictedDependencyProvider
    extends Object
    implements DependencyProvider

    An implementation of the DependencyProvider interface, which does not support external dependencies.

    This class allows the execution of simple Invokable objects, which do not require access to other beans stored in a BeanContext. The methods defined by the ClassLoaderProvider interface are fully implemented (by delegating to a wrapped ClassLoaderProvider). But other methods for dealing with dependencies throw an exception. This makes it possible to execute simple invocation scripts (e.g. defined by a ChainedInvocation), including access to local variables. However, other bean providers cannot be accessed.

    A use case for this class is the execution of a shutdown script by a bean provider that is no longer needed. At the time the shutdown script is invoked the corresponding BeanContext (or BeanStore) may already be partly destroyed, so access to other beans is not safe. Nevertheless arbitrary methods on the affected bean can be invoked.

    When creating an instance of this class a ClassLoaderProvider object must be provided. All methods dealing with classes and class loaders are passed to this object. The other methods are implemented by simply throwing an exception.

    Version:
    $Id: RestrictedDependencyProvider.java 205 2012-01-29 18:29:57Z oheger $
    Author:
    Oliver Heger
    • Constructor Detail

      • RestrictedDependencyProvider

        public RestrictedDependencyProvider​(ClassLoaderProvider clp,
                                            InvocationHelper invHlp)
        Creates a new instance of RestrictedDependencyProvider and initializes it with the specified ClassLoaderProvider and the InvocationHelper.
        Parameters:
        clp - the ClassLoaderProvider (must not be null)
        invHlp - the InvocationHelper (must not be null)
        Throws:
        IllegalArgumentException - if a required parameter is null
    • Method Detail

      • getClassLoaderProvider

        public ClassLoaderProvider getClassLoaderProvider()
        Returns the wrapped ClassLoaderProvider.
        Returns:
        the ClassLoaderProvider
      • addInitializer

        public void addInitializer​(BeanInitializer initializer)
        Adds a BeanInitializer. This implementation just throws an exception.
        Specified by:
        addInitializer in interface DependencyProvider
        Parameters:
        initializer - the initializer
      • beanCreated

        public void beanCreated​(Object bean,
                                BeanProvider provider)
        Notifies this dependency provider about a newly created bean. This implementation just throws an exception.
        Specified by:
        beanCreated in interface DependencyProvider
        Parameters:
        bean - the new bean
        provider - the responsible bean provider
      • getDependentBean

        public Object getDependentBean​(Dependency dependency)
        Returns a dependent bean. This implementation invokes the passed in Dependency with a null bean store. If a bean provider is returned, this provider's bean is queried. This way certain Dependency implementations can be served, while others cause an exception.
        Specified by:
        getDependentBean in interface DependencyProvider
        Parameters:
        dependency - the dependency to resolve
        Returns:
        the corresponding bean
        Throws:
        InjectionException - if the Dependency cannot be resolved
      • setCreationBeanContext

        public void setCreationBeanContext​(BeanContext context)
        Sets the context that is responsible for a bean creation event. This implementation just throws an exception.
        Specified by:
        setCreationBeanContext in interface DependencyProvider
        Parameters:
        context - the context
      • classLoaderNames

        public Set<String> classLoaderNames()
        Returns a set with the names of all class loaders registered at this object. This implementation delegates to the wrapped ClassLoaderProvider.
        Specified by:
        classLoaderNames in interface ClassLoaderProvider
        Returns:
        a set with the names of the known class loaders
      • getClassLoader

        public ClassLoader getClassLoader​(String name)
        Returns the class loader that was registered under the given name. This implementation delegates to the wrapped ClassLoaderProvider.
        Specified by:
        getClassLoader in interface ClassLoaderProvider
        Parameters:
        name - the name of the class loader
        Returns:
        the corresponding class loader
        Throws:
        InjectionException - if the name is unknown
      • getDefaultClassLoaderName

        public String getDefaultClassLoaderName()
        Returns the name of the default class loader. This implementation delegates to the wrapped ClassLoaderProvider.
        Specified by:
        getDefaultClassLoaderName in interface ClassLoaderProvider
        Returns:
        the default class loader
        See Also:
        #setDefaultClassLoader(ClassLoader)
      • loadClass

        public Class<?> loadClass​(String name,
                                  String loaderRef)
        Loads a class using the specified class loader. This implementation delegates to the wrapped ClassLoaderProvider.
        Specified by:
        loadClass in interface ClassLoaderProvider
        Parameters:
        name - the name of the class to load
        loaderRef - the name of the class loader
        Returns:
        the corresponding class
        Throws:
        InjectionException - if an error occurs
      • registerClassLoader

        public void registerClassLoader​(String name,
                                        ClassLoader loader)
        Registers a class loader under a name. This implementation delegates to the wrapped ClassLoaderProvider.
        Specified by:
        registerClassLoader in interface ClassLoaderProvider
        Parameters:
        name - the name
        loader - the class loader
      • setDefaultClassLoaderName

        public void setDefaultClassLoaderName​(String loaderName)
        Sets the name of the default class loader. This implementation delegates to the wrapped ClassLoaderProvider.
        Specified by:
        setDefaultClassLoaderName in interface ClassLoaderProvider
        Parameters:
        loaderName - the new default class loader name
      • getInvocationHelper

        public InvocationHelper getInvocationHelper()
        Returns the InvocationHelper object. This implementation returns the object that was passed to the constructor.
        Specified by:
        getInvocationHelper in interface DependencyProvider
        Returns:
        the InvocationHelper object