Commit 8efb1b4269eef48fb840b03c6cf850ff0125b1be
1 parent
1be04f3f
Exists in
master
Definição do escopo estático nas classes de configuração.
Showing
2 changed files
with
9 additions
and
16 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/configuration/Configuration.java
... | ... | @@ -46,6 +46,8 @@ import java.lang.annotation.Target; |
46 | 46 | import javax.enterprise.inject.Stereotype; |
47 | 47 | import javax.enterprise.util.Nonbinding; |
48 | 48 | |
49 | +import br.gov.frameworkdemoiselle.annotation.StaticScoped; | |
50 | + | |
49 | 51 | /** |
50 | 52 | * Identifies a <b>configuration class</b>, that is, a structure reserved to store configuration values retrieved from a |
51 | 53 | * given resource file or system variables. |
... | ... | @@ -61,8 +63,9 @@ import javax.enterprise.util.Nonbinding; |
61 | 63 | * |
62 | 64 | * @author SERPRO |
63 | 65 | */ |
64 | -@Stereotype | |
65 | 66 | @Inherited |
67 | +@Stereotype | |
68 | +@StaticScoped | |
66 | 69 | @Target(TYPE) |
67 | 70 | @Retention(RUNTIME) |
68 | 71 | public @interface Configuration { | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ConfigurationBootstrap.java
... | ... | @@ -51,7 +51,6 @@ import javassist.LoaderClassPath; |
51 | 51 | import javassist.NotFoundException; |
52 | 52 | |
53 | 53 | import javax.enterprise.event.Observes; |
54 | -import javax.enterprise.inject.spi.AfterBeanDiscovery; | |
55 | 54 | import javax.enterprise.inject.spi.AnnotatedType; |
56 | 55 | import javax.enterprise.inject.spi.BeanManager; |
57 | 56 | import javax.enterprise.inject.spi.Extension; |
... | ... | @@ -62,26 +61,17 @@ import br.gov.frameworkdemoiselle.internal.implementation.ConfigurationImpl; |
62 | 61 | |
63 | 62 | public class ConfigurationBootstrap implements Extension { |
64 | 63 | |
65 | - private final List<Class<Object>> cache = Collections.synchronizedList(new ArrayList<Class<Object>>()); | |
66 | - | |
67 | 64 | private static final Map<ClassLoader, Map<String, Class<Object>>> cacheClassLoader = Collections |
68 | 65 | .synchronizedMap(new HashMap<ClassLoader, Map<String, Class<Object>>>()); |
69 | 66 | |
70 | - public void processAnnotatedType(@Observes final ProcessAnnotatedType<Object> event) { | |
67 | + public void processAnnotatedType(@Observes final ProcessAnnotatedType<Object> event, BeanManager beanManager) | |
68 | + throws Exception { | |
71 | 69 | final AnnotatedType<Object> annotatedType = event.getAnnotatedType(); |
72 | 70 | |
73 | 71 | if (annotatedType.getJavaClass().isAnnotationPresent(Configuration.class)) { |
74 | - cache.add(annotatedType.getJavaClass()); | |
75 | - event.veto(); | |
76 | - } | |
77 | - } | |
78 | - | |
79 | - public void afterBeanDiscovery(@Observes AfterBeanDiscovery event, BeanManager beanManager) throws Exception { | |
80 | - Class<Object> proxy; | |
81 | - | |
82 | - for (Class<Object> config : cache) { | |
83 | - proxy = createProxy(config); | |
84 | - event.addBean(new CustomBean(proxy, beanManager)); | |
72 | + Class<Object> proxyClass = createProxy(annotatedType.getJavaClass()); | |
73 | + AnnotatedType<Object> proxyAnnotatedType = beanManager.createAnnotatedType(proxyClass); | |
74 | + event.setAnnotatedType(proxyAnnotatedType); | |
85 | 75 | } |
86 | 76 | } |
87 | 77 | ... | ... |