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 javax.naming.NamingException; |
22 | |
import javax.naming.Context; |
23 | |
import javax.annotation.Resource; |
24 | |
import javax.ejb.EJB; |
25 | |
import javax.persistence.PersistenceContext; |
26 | |
import javax.persistence.PersistenceUnit; |
27 | |
|
28 | |
|
29 | |
import java.lang.reflect.Method; |
30 | |
import java.lang.reflect.InvocationTargetException; |
31 | |
import java.lang.reflect.Field; |
32 | |
|
33 | |
|
34 | |
public class AllAnnotationLifecycleProvider extends ResourceAnnotationLifecycleProvider |
35 | |
{ |
36 | |
|
37 | |
public AllAnnotationLifecycleProvider(Context context) |
38 | |
{ |
39 | 0 | super(context); |
40 | 0 | } |
41 | |
|
42 | |
protected void checkMethodAnnotation(Method method, Object instance) |
43 | |
throws NamingException, IllegalAccessException, InvocationTargetException |
44 | |
{ |
45 | 0 | super.checkMethodAnnotation(method, instance); |
46 | 0 | if (method.isAnnotationPresent(Resource.class)) |
47 | |
{ |
48 | 0 | Resource annotation = method.getAnnotation(Resource.class); |
49 | 0 | lookupMethodResource(context, instance, method, annotation.name()); |
50 | |
} |
51 | 0 | if (method.isAnnotationPresent(EJB.class)) |
52 | |
{ |
53 | 0 | EJB annotation = method.getAnnotation(EJB.class); |
54 | 0 | lookupMethodResource(context, instance, method, annotation.name()); |
55 | |
} |
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | 0 | if (method.isAnnotationPresent(PersistenceContext.class)) |
63 | |
{ |
64 | 0 | PersistenceContext annotation = method.getAnnotation(PersistenceContext.class); |
65 | 0 | lookupMethodResource(context, instance, method, annotation.name()); |
66 | |
} |
67 | 0 | if (method.isAnnotationPresent(PersistenceUnit.class)) |
68 | |
{ |
69 | 0 | PersistenceUnit annotation = method.getAnnotation(PersistenceUnit.class); |
70 | 0 | lookupMethodResource(context, instance, method, annotation.name()); |
71 | |
} |
72 | 0 | } |
73 | |
|
74 | |
protected void checkFieldAnnotation(Field field, Object instance) |
75 | |
throws NamingException, IllegalAccessException |
76 | |
{ |
77 | 0 | super.checkFieldAnnotation(field, instance); |
78 | 0 | if (field.isAnnotationPresent(EJB.class)) |
79 | |
{ |
80 | 0 | EJB annotation = field.getAnnotation(EJB.class); |
81 | 0 | lookupFieldResource(context, instance, field, annotation.name()); |
82 | |
} |
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | 0 | if (field.isAnnotationPresent(PersistenceContext.class)) |
89 | |
{ |
90 | 0 | PersistenceContext annotation = field.getAnnotation(PersistenceContext.class); |
91 | 0 | lookupFieldResource(context, instance, field, annotation.name()); |
92 | |
} |
93 | 0 | if (field.isAnnotationPresent(PersistenceUnit.class)) |
94 | |
{ |
95 | 0 | PersistenceUnit annotation = field.getAnnotation(PersistenceUnit.class); |
96 | 0 | lookupFieldResource(context, instance, field, annotation.name()); |
97 | |
} |
98 | 0 | } |
99 | |
} |