1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.myfaces.config.annotation; |
20 | |
|
21 | |
import org.apache.myfaces.shared_impl.util.ClassUtils; |
22 | |
import org.apache.commons.logging.Log; |
23 | |
import org.apache.commons.logging.LogFactory; |
24 | |
|
25 | |
import javax.naming.NamingException; |
26 | |
import javax.faces.context.ExternalContext; |
27 | |
import javax.servlet.ServletContext; |
28 | |
import java.lang.reflect.InvocationTargetException; |
29 | |
|
30 | |
public class TomcatAnnotationLifecycleProvider implements |
31 | |
DiscoverableLifecycleProvider, LifecycleProvider2 |
32 | |
{ |
33 | 0 | private static Log log = LogFactory.getLog(TomcatAnnotationLifecycleProvider.class); |
34 | |
|
35 | |
private ExternalContext externalContext; |
36 | |
private org.apache.AnnotationProcessor annotationProcessor; |
37 | |
|
38 | |
public TomcatAnnotationLifecycleProvider(ExternalContext externalContext) |
39 | 0 | { |
40 | 0 | this.externalContext = externalContext; |
41 | 0 | } |
42 | |
|
43 | |
|
44 | |
public Object newInstance(String className) |
45 | |
throws InstantiationException, IllegalAccessException, InvocationTargetException, NamingException, ClassNotFoundException { |
46 | 0 | Class clazz = ClassUtils.classForName(className); |
47 | 0 | log.info("Creating instance of " + className); |
48 | 0 | Object object = clazz.newInstance(); |
49 | 0 | annotationProcessor.processAnnotations(object); |
50 | |
|
51 | 0 | return object; |
52 | |
} |
53 | |
|
54 | |
|
55 | |
public void destroyInstance(Object o) throws IllegalAccessException, InvocationTargetException |
56 | |
{ |
57 | 0 | log.info("Destroy instance of " + o.getClass().getName()); |
58 | 0 | annotationProcessor.preDestroy(o); |
59 | 0 | } |
60 | |
|
61 | |
public boolean isAvailable() |
62 | |
{ |
63 | |
try |
64 | |
{ |
65 | 0 | annotationProcessor = (org.apache.AnnotationProcessor) ((ServletContext) |
66 | |
externalContext.getContext()).getAttribute(org.apache.AnnotationProcessor.class.getName()); |
67 | 0 | return annotationProcessor != null; |
68 | 0 | } catch (Exception e) { |
69 | |
|
70 | |
} |
71 | 0 | return false; |
72 | |
} |
73 | |
|
74 | |
|
75 | |
public void postConstruct(Object o) throws IllegalAccessException, |
76 | |
InvocationTargetException |
77 | |
{ |
78 | 0 | annotationProcessor.postConstruct(o); |
79 | 0 | } |
80 | |
|
81 | |
} |