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.
CONTEXT_CLASS_LOADER
Constructor and Description |
---|
RestrictedDependencyProvider(ClassLoaderProvider clp,
InvocationHelper invHlp)
Creates a new instance of
RestrictedDependencyProvider and
initializes it with the specified ClassLoaderProvider and the
InvocationHelper . |
Modifier and Type | Method and Description |
---|---|
void |
addInitializer(BeanInitializer initializer)
Adds a
BeanInitializer . |
void |
beanCreated(Object bean,
BeanProvider provider)
Notifies this dependency provider about a newly created bean.
|
Set<String> |
classLoaderNames()
Returns a set with the names of all class loaders registered at this
object.
|
ClassLoader |
getClassLoader(String name)
Returns the class loader that was registered under the given name.
|
ClassLoaderProvider |
getClassLoaderProvider()
Returns the wrapped
ClassLoaderProvider . |
String |
getDefaultClassLoaderName()
Returns the name of the default class loader.
|
Object |
getDependentBean(Dependency dependency)
Returns a dependent bean.
|
InvocationHelper |
getInvocationHelper()
Returns the
InvocationHelper object. |
boolean |
isBeanAvailable(Dependency dependency)
Checks whether a bean is available.
|
Class<?> |
loadClass(String name,
String loaderRef)
Loads a class using the specified class loader.
|
void |
registerClassLoader(String name,
ClassLoader loader)
Registers a class loader under a name.
|
void |
setCreationBeanContext(BeanContext context)
Sets the context that is responsible for a bean creation event.
|
void |
setDefaultClassLoaderName(String loaderName)
Sets the name of the default class loader.
|
public RestrictedDependencyProvider(ClassLoaderProvider clp, InvocationHelper invHlp)
RestrictedDependencyProvider
and
initializes it with the specified ClassLoaderProvider
and the
InvocationHelper
.clp
- the ClassLoaderProvider
(must not be null)invHlp
- the InvocationHelper
(must not be null)IllegalArgumentException
- if a required parameter is nullpublic ClassLoaderProvider getClassLoaderProvider()
ClassLoaderProvider
.ClassLoaderProvider
public void addInitializer(BeanInitializer initializer)
BeanInitializer
. This implementation just throws an
exception.addInitializer
in interface DependencyProvider
initializer
- the initializerpublic void beanCreated(Object bean, BeanProvider provider)
beanCreated
in interface DependencyProvider
bean
- the new beanprovider
- the responsible bean providerpublic Object getDependentBean(Dependency dependency)
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.getDependentBean
in interface DependencyProvider
dependency
- the dependency to resolveInjectionException
- if the Dependency
cannot be resolvedpublic boolean isBeanAvailable(Dependency dependency)
isBeanAvailable
in interface DependencyProvider
dependency
- the dependency to the beanDependencyProvider.addInitializer(BeanInitializer)
public void setCreationBeanContext(BeanContext context)
setCreationBeanContext
in interface DependencyProvider
context
- the contextpublic Set<String> classLoaderNames()
ClassLoaderProvider
.classLoaderNames
in interface ClassLoaderProvider
public ClassLoader getClassLoader(String name)
ClassLoaderProvider
.getClassLoader
in interface ClassLoaderProvider
name
- the name of the class loaderInjectionException
- if the name is unknownpublic String getDefaultClassLoaderName()
ClassLoaderProvider
.getDefaultClassLoaderName
in interface ClassLoaderProvider
#setDefaultClassLoader(ClassLoader)
public Class<?> loadClass(String name, String loaderRef)
ClassLoaderProvider
.loadClass
in interface ClassLoaderProvider
name
- the name of the class to loadloaderRef
- the name of the class loaderInjectionException
- if an error occurspublic void registerClassLoader(String name, ClassLoader loader)
ClassLoaderProvider
.registerClassLoader
in interface ClassLoaderProvider
name
- the nameloader
- the class loaderpublic void setDefaultClassLoaderName(String loaderName)
ClassLoaderProvider
.setDefaultClassLoaderName
in interface ClassLoaderProvider
loaderName
- the new default class loader namepublic InvocationHelper getInvocationHelper()
InvocationHelper
object. This implementation returns
the object that was passed to the constructor.getInvocationHelper
in interface DependencyProvider
InvocationHelper
objectCopyright © 2016 The JGUIraffe Team. All rights reserved.