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 java.lang.annotation.Annotation; |
22 | |
import java.util.HashMap; |
23 | |
import java.util.HashSet; |
24 | |
import java.util.Map; |
25 | |
import java.util.Set; |
26 | |
import javax.enterprise.event.Observes; |
27 | |
import javax.enterprise.inject.spi.AnnotatedType; |
28 | |
import javax.enterprise.inject.spi.Extension; |
29 | |
import javax.enterprise.inject.spi.ProcessAnnotatedType; |
30 | |
import javax.faces.bean.ManagedBean; |
31 | |
import javax.faces.component.FacesComponent; |
32 | |
import javax.faces.component.behavior.FacesBehavior; |
33 | |
import javax.faces.convert.FacesConverter; |
34 | |
import javax.faces.render.FacesBehaviorRenderer; |
35 | |
import javax.faces.render.FacesRenderer; |
36 | |
import javax.faces.validator.FacesValidator; |
37 | |
import javax.faces.view.facelets.FaceletsResourceResolver; |
38 | |
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFWebConfigParam; |
39 | |
import org.apache.myfaces.config.element.NamedEvent; |
40 | |
|
41 | |
public class CdiAnnotationProviderExtension implements Extension |
42 | |
{ |
43 | |
|
44 | |
|
45 | |
|
46 | |
@JSFWebConfigParam(since="2.2.9") |
47 | |
public static final String USE_CDI_FOR_ANNOTATION_SCANNING |
48 | |
= "org.apache.myfaces.annotation.USE_CDI_FOR_ANNOTATION_SCANNING"; |
49 | |
|
50 | |
private final Map<Class<? extends Annotation>, Set<Class<?>>> map; |
51 | |
private final Class<? extends Annotation>[] annotationsToScan; |
52 | |
|
53 | |
public CdiAnnotationProviderExtension() |
54 | 0 | { |
55 | 0 | map = new HashMap<Class<? extends Annotation>, Set<Class<?>>>(); |
56 | 0 | annotationsToScan = new Class[] { |
57 | |
FacesComponent.class, |
58 | |
FacesBehavior.class, |
59 | |
FacesConverter.class, |
60 | |
FacesValidator.class, |
61 | |
FacesRenderer.class, |
62 | |
ManagedBean.class, |
63 | |
NamedEvent.class, |
64 | |
FacesBehaviorRenderer.class, |
65 | |
FaceletsResourceResolver.class |
66 | |
}; |
67 | 0 | } |
68 | |
|
69 | |
<T> void processAnnotatedType(@Observes ProcessAnnotatedType<T> pat) |
70 | |
{ |
71 | 0 | AnnotatedType<T> type = pat.getAnnotatedType(); |
72 | |
|
73 | 0 | for (Class<? extends Annotation> annotation : annotationsToScan) |
74 | |
{ |
75 | 0 | if (type.isAnnotationPresent(annotation)) |
76 | |
{ |
77 | 0 | Set<Class<?>> set = map.get(annotation); |
78 | 0 | if (set == null) |
79 | |
{ |
80 | 0 | set = new HashSet<Class<?>>(); |
81 | 0 | map.put(annotation, set); |
82 | |
} |
83 | |
|
84 | 0 | set.add(type.getJavaClass()); |
85 | |
} |
86 | |
} |
87 | 0 | } |
88 | |
|
89 | |
public Map<Class<? extends Annotation>, Set<Class<?>>> getMap() |
90 | |
{ |
91 | 0 | return map; |
92 | |
} |
93 | |
} |