Package org.apache.catalina.core
Class DefaultInstanceManager
- java.lang.Object
-
- org.apache.catalina.core.DefaultInstanceManager
-
- All Implemented Interfaces:
InstanceManager
public class DefaultInstanceManager extends Object implements InstanceManager
-
-
Field Summary
Fields Modifier and Type Field Description protected ClassLoaderclassLoaderprotected ClassLoadercontainerClassLoaderprotected booleanignoreAnnotationsprotected booleanprivilegedprotected static StringManagersmThe string manager for this package.
-
Constructor Summary
Constructors Constructor Description DefaultInstanceManager(Context context, Map<String,Map<String,String>> injectionMap, Context catalinaContext, ClassLoader containerClassLoader)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbackgroundProcess()voiddestroyInstance(Object instance)protected intgetAnnotationCacheSize()Makes cache size available to unit tests.protected Class<?>loadClass(String className, ClassLoader classLoader)protected Class<?>loadClassMaybePrivileged(String className, ClassLoader classLoader)protected static voidlookupFieldResource(Context context, Object instance, Field field, String name, Class<?> clazz)Inject resources in specified field.protected static voidlookupMethodResource(Context context, Object instance, Method method, String name, Class<?> clazz)Inject resources in specified method.ObjectnewInstance(Class<?> clazz)voidnewInstance(Object o)ObjectnewInstance(String className)ObjectnewInstance(String className, ClassLoader classLoader)protected voidpopulateAnnotationsCache(Class<?> clazz, Map<String,String> injections)Make sure that the annotations cache has been populated for the provided class.protected voidpostConstruct(Object instance, Class<?> clazz)Call postConstruct method on the specified instance recursively from deepest superclass to actual class.protected voidpreDestroy(Object instance, Class<?> clazz)Call preDestroy method on the specified instance recursively from deepest superclass to actual class.protected voidprocessAnnotations(Object instance, Map<String,String> injections)Inject resources in specified instance.
-
-
-
Field Detail
-
sm
protected static final StringManager sm
The string manager for this package.
-
classLoader
protected final ClassLoader classLoader
-
containerClassLoader
protected final ClassLoader containerClassLoader
-
privileged
protected final boolean privileged
-
ignoreAnnotations
protected final boolean ignoreAnnotations
-
-
Method Detail
-
newInstance
public Object newInstance(Class<?> clazz) throws IllegalAccessException, InvocationTargetException, NamingException, InstantiationException, IllegalArgumentException, NoSuchMethodException, SecurityException
- Specified by:
newInstancein interfaceInstanceManager- Throws:
IllegalAccessExceptionInvocationTargetExceptionNamingExceptionInstantiationExceptionIllegalArgumentExceptionNoSuchMethodExceptionSecurityException
-
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:
newInstancein interfaceInstanceManager- Throws:
IllegalAccessExceptionInvocationTargetExceptionNamingException
-
destroyInstance
public void destroyInstance(Object instance) throws IllegalAccessException, InvocationTargetException
- Specified by:
destroyInstancein interfaceInstanceManager- Throws:
IllegalAccessExceptionInvocationTargetException
-
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()
-
populateAnnotationsCache
protected void populateAnnotationsCache(Class<?> clazz, Map<String,String> injections) throws IllegalAccessException, InvocationTargetException, NamingException
Make 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, NamingException
Inject 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
-
-