Package org.apache.catalina.core
Class DefaultInstanceManager
java.lang.Object
org.apache.catalina.core.DefaultInstanceManager
- All Implemented Interfaces:
InstanceManager
-
Field Summary
Modifier and TypeFieldDescriptionprotected final ClassLoader
protected final ClassLoader
protected final boolean
protected final boolean
protected static final StringManager
The string manager for this package. -
Constructor Summary
ConstructorDescriptionDefaultInstanceManager
(Context context, Map<String, Map<String, String>> injectionMap, Context catalinaContext, ClassLoader containerClassLoader) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Called by the component using the InstanceManager periodically to perform any regular maintenance that might be required.void
destroyInstance
(Object instance) protected int
Makes cache size available to unit tests.protected Class<?>
loadClass
(String className, ClassLoader classLoader) protected Class<?>
loadClassMaybePrivileged
(String className, ClassLoader classLoader) protected static void
Inject resources in specified field.protected static void
Inject resources in specified method.newInstance
(Class<?> clazz) void
newInstance
(String className) newInstance
(String className, ClassLoader classLoader) protected void
populateAnnotationsCache
(Class<?> clazz, Map<String, String> injections) Make sure that the annotations cache has been populated for the provided class.protected void
postConstruct
(Object instance, Class<?> clazz) Call postConstruct method on the specified instance recursively from deepest superclass to actual class.protected void
preDestroy
(Object instance, Class<?> clazz) Call preDestroy method on the specified instance recursively from deepest superclass to actual class.protected void
processAnnotations
(Object instance, Map<String, String> injections) Inject resources in specified instance.
-
Field Details
-
sm
The string manager for this package. -
classLoader
-
containerClassLoader
-
privileged
protected final boolean privileged -
ignoreAnnotations
protected final boolean ignoreAnnotations
-
-
Constructor Details
-
DefaultInstanceManager
-
-
Method Details
-
newInstance
public Object newInstance(Class<?> clazz) throws IllegalAccessException, InvocationTargetException, NamingException, InstantiationException, IllegalArgumentException, NoSuchMethodException, SecurityException - Specified by:
newInstance
in interfaceInstanceManager
- Throws:
IllegalAccessException
InvocationTargetException
NamingException
InstantiationException
IllegalArgumentException
NoSuchMethodException
SecurityException
-
newInstance
public Object newInstance(String className) throws IllegalAccessException, InvocationTargetException, NamingException, InstantiationException, ClassNotFoundException, IllegalArgumentException, NoSuchMethodException, SecurityException -
newInstance
public Object newInstance(String className, ClassLoader classLoader) throws IllegalAccessException, NamingException, InvocationTargetException, InstantiationException, ClassNotFoundException, IllegalArgumentException, NoSuchMethodException, SecurityException -
newInstance
public void newInstance(Object o) throws IllegalAccessException, InvocationTargetException, NamingException - Specified by:
newInstance
in interfaceInstanceManager
- Throws:
IllegalAccessException
InvocationTargetException
NamingException
-
destroyInstance
public void destroyInstance(Object instance) throws IllegalAccessException, InvocationTargetException - Specified by:
destroyInstance
in interfaceInstanceManager
- Throws:
IllegalAccessException
InvocationTargetException
-
postConstruct
protected void postConstruct(Object instance, Class<?> clazz) throws IllegalAccessException, InvocationTargetException Call postConstruct method on the specified instance recursively from deepest superclass to actual class.- Parameters:
instance
- object to call postconstruct methods onclazz
- (super) class to examine for postConstruct annotation.- Throws:
IllegalAccessException
- if postConstruct method is inaccessible.InvocationTargetException
- if call fails
-
preDestroy
protected void preDestroy(Object instance, Class<?> clazz) throws IllegalAccessException, InvocationTargetException Call preDestroy method on the specified instance recursively from deepest superclass to actual class.- Parameters:
instance
- object to call preDestroy methods onclazz
- (super) class to examine for preDestroy annotation.- Throws:
IllegalAccessException
- if preDestroy method is inaccessible.InvocationTargetException
- if call fails
-
backgroundProcess
public void backgroundProcess()Description copied from interface:InstanceManager
Called by the component using the InstanceManager periodically to perform any regular maintenance that might be required. By default, this method is a NO-OP.- Specified by:
backgroundProcess
in interfaceInstanceManager
-
populateAnnotationsCache
protected void populateAnnotationsCache(Class<?> clazz, Map<String, String> injections) throws IllegalAccessException, InvocationTargetException, NamingExceptionMake sure that the annotations cache has been populated for the provided class.- Parameters:
clazz
- clazz to populate annotations forinjections
- map of injections for this class from xml deployment descriptor- Throws:
IllegalAccessException
- if injection target is inaccessibleNamingException
- if value cannot be looked up in jndiInvocationTargetException
- if injection fails
-
processAnnotations
protected void processAnnotations(Object instance, Map<String, String> injections) throws IllegalAccessException, InvocationTargetException, NamingExceptionInject resources in specified instance.- Parameters:
instance
- instance to inject intoinjections
- map of injections for this class from xml deployment descriptor- Throws:
IllegalAccessException
- if injection target is inaccessibleNamingException
- if value cannot be looked up in jndiInvocationTargetException
- if injection fails
-
getAnnotationCacheSize
protected int getAnnotationCacheSize()Makes cache size available to unit tests.- Returns:
- the cache size
-
loadClassMaybePrivileged
protected Class<?> loadClassMaybePrivileged(String className, ClassLoader classLoader) throws ClassNotFoundException - Throws:
ClassNotFoundException
-
loadClass
protected Class<?> loadClass(String className, ClassLoader classLoader) throws ClassNotFoundException - Throws:
ClassNotFoundException
-
lookupFieldResource
protected static void lookupFieldResource(Context context, Object instance, Field field, String name, Class<?> clazz) throws NamingException, IllegalAccessException Inject resources in specified field.- Parameters:
context
- jndi context to extract value frominstance
- object to inject intofield
- field target for injectionname
- jndi name value is bound underclazz
- class annotation is defined in- Throws:
IllegalAccessException
- if field is inaccessibleNamingException
- if value is not accessible in naming context
-
lookupMethodResource
protected static void lookupMethodResource(Context context, Object instance, Method method, String name, Class<?> clazz) throws NamingException, IllegalAccessException, InvocationTargetException Inject resources in specified method.- Parameters:
context
- jndi context to extract value frominstance
- object to inject intomethod
- field target for injectionname
- jndi name value is bound underclazz
- class annotation is defined in- Throws:
IllegalAccessException
- if method is inaccessibleNamingException
- if value is not accessible in naming contextInvocationTargetException
- if setter call fails
-