1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.myfaces.spi.impl; |
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 AllAnnotationInjectionProvider extends ResourceAnnotationInjectionProvider |
35 | |
{ |
36 | |
|
37 | |
public AllAnnotationInjectionProvider(Context context) |
38 | |
{ |
39 | 0 | super(context); |
40 | 0 | } |
41 | |
|
42 | |
@Override |
43 | |
protected void checkMethodAnnotation(Method method, Object instance) |
44 | |
throws NamingException, IllegalAccessException, InvocationTargetException |
45 | |
{ |
46 | 0 | super.checkMethodAnnotation(method, instance); |
47 | 0 | if (method.isAnnotationPresent(Resource.class)) |
48 | |
{ |
49 | 0 | Resource annotation = method.getAnnotation(Resource.class); |
50 | 0 | lookupMethodResource(context, instance, method, annotation.name()); |
51 | |
} |
52 | 0 | if (method.isAnnotationPresent(EJB.class)) |
53 | |
{ |
54 | 0 | EJB annotation = method.getAnnotation(EJB.class); |
55 | 0 | lookupMethodResource(context, instance, method, annotation.name()); |
56 | |
} |
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | 0 | if (method.isAnnotationPresent(PersistenceContext.class)) |
64 | |
{ |
65 | 0 | PersistenceContext annotation = method.getAnnotation(PersistenceContext.class); |
66 | 0 | lookupMethodResource(context, instance, method, annotation.name()); |
67 | |
} |
68 | 0 | if (method.isAnnotationPresent(PersistenceUnit.class)) |
69 | |
{ |
70 | 0 | PersistenceUnit annotation = method.getAnnotation(PersistenceUnit.class); |
71 | 0 | lookupMethodResource(context, instance, method, annotation.name()); |
72 | |
} |
73 | 0 | } |
74 | |
|
75 | |
@Override |
76 | |
protected void checkFieldAnnotation(Field field, Object instance) |
77 | |
throws NamingException, IllegalAccessException |
78 | |
{ |
79 | 0 | super.checkFieldAnnotation(field, instance); |
80 | 0 | if (field.isAnnotationPresent(EJB.class)) |
81 | |
{ |
82 | 0 | EJB annotation = field.getAnnotation(EJB.class); |
83 | 0 | lookupFieldResource(context, instance, field, annotation.name()); |
84 | |
} |
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | 0 | if (field.isAnnotationPresent(PersistenceContext.class)) |
91 | |
{ |
92 | 0 | PersistenceContext annotation = field.getAnnotation(PersistenceContext.class); |
93 | 0 | lookupFieldResource(context, instance, field, annotation.name()); |
94 | |
} |
95 | 0 | if (field.isAnnotationPresent(PersistenceUnit.class)) |
96 | |
{ |
97 | 0 | PersistenceUnit annotation = field.getAnnotation(PersistenceUnit.class); |
98 | 0 | lookupFieldResource(context, instance, field, annotation.name()); |
99 | |
} |
100 | 0 | } |
101 | |
} |