Commit ac7ff7891f23dfe8c681350ddccd6d8c0fc04f5c
1 parent
f9b2d89f
Exists in
master
Correção do nome da classe AbstractLifecycleBootstrap.
Showing
4 changed files
with
159 additions
and
159 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AbstractLifecycleBootstrap.java
0 → 100644
@@ -0,0 +1,157 @@ | @@ -0,0 +1,157 @@ | ||
1 | +/* | ||
2 | + * Demoiselle Framework | ||
3 | + * Copyright (C) 2010 SERPRO | ||
4 | + * ---------------------------------------------------------------------------- | ||
5 | + * This file is part of Demoiselle Framework. | ||
6 | + * | ||
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | ||
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | ||
9 | + * as published by the Free Software Foundation. | ||
10 | + * | ||
11 | + * This program is distributed in the hope that it will be useful, | ||
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | + * GNU General Public License for more details. | ||
15 | + * | ||
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | ||
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | + * ---------------------------------------------------------------------------- | ||
21 | + * Este arquivo é parte do Framework Demoiselle. | ||
22 | + * | ||
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
25 | + * do Software Livre (FSF). | ||
26 | + * | ||
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
30 | + * para maiores detalhes. | ||
31 | + * | ||
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
36 | + */ | ||
37 | +package br.gov.frameworkdemoiselle.internal.bootstrap; | ||
38 | + | ||
39 | +import java.lang.annotation.Annotation; | ||
40 | +import java.util.ArrayList; | ||
41 | +import java.util.Collections; | ||
42 | +import java.util.Iterator; | ||
43 | +import java.util.List; | ||
44 | + | ||
45 | +import javax.enterprise.context.ConversationScoped; | ||
46 | +import javax.enterprise.context.RequestScoped; | ||
47 | +import javax.enterprise.context.SessionScoped; | ||
48 | +import javax.enterprise.event.Observes; | ||
49 | +import javax.enterprise.inject.spi.AfterBeanDiscovery; | ||
50 | +import javax.enterprise.inject.spi.AnnotatedMethod; | ||
51 | +import javax.enterprise.inject.spi.AnnotatedType; | ||
52 | +import javax.enterprise.inject.spi.BeanManager; | ||
53 | +import javax.enterprise.inject.spi.ProcessAnnotatedType; | ||
54 | + | ||
55 | +import br.gov.frameworkdemoiselle.DemoiselleException; | ||
56 | +import br.gov.frameworkdemoiselle.annotation.ViewScoped; | ||
57 | +import br.gov.frameworkdemoiselle.internal.configuration.ConfigurationLoader; | ||
58 | +import br.gov.frameworkdemoiselle.internal.context.CustomContext; | ||
59 | +import br.gov.frameworkdemoiselle.internal.context.ThreadLocalContext; | ||
60 | +import br.gov.frameworkdemoiselle.internal.processor.AnnotatedMethodProcessor; | ||
61 | +import br.gov.frameworkdemoiselle.util.Reflections; | ||
62 | + | ||
63 | +public abstract class AbstractLifecycleBootstrap<A extends Annotation> extends AbstractBootstrap { | ||
64 | + | ||
65 | + private Class<A> annotationClass; | ||
66 | + | ||
67 | + @SuppressWarnings("rawtypes") | ||
68 | + private final List<AnnotatedMethodProcessor> processors = Collections | ||
69 | + .synchronizedList(new ArrayList<AnnotatedMethodProcessor>()); | ||
70 | + | ||
71 | + private final List<CustomContext> tempContexts = new ArrayList<CustomContext>(); | ||
72 | + | ||
73 | + private AfterBeanDiscovery afterBeanDiscoveryEvent; | ||
74 | + | ||
75 | + private boolean registered = false; | ||
76 | + | ||
77 | + protected abstract <T> AnnotatedMethodProcessor<T> newProcessorInstance(AnnotatedMethod<T> annotatedMethod, | ||
78 | + BeanManager beanManager); | ||
79 | + | ||
80 | + protected Class<A> getAnnotationClass() { | ||
81 | + if (this.annotationClass == null) { | ||
82 | + this.annotationClass = Reflections.getGenericTypeArgument(this.getClass(), 0); | ||
83 | + } | ||
84 | + | ||
85 | + return this.annotationClass; | ||
86 | + } | ||
87 | + | ||
88 | + public <T> void processAnnotatedType(@Observes final ProcessAnnotatedType<T> event, final BeanManager beanManager) { | ||
89 | + final AnnotatedType<T> annotatedType = event.getAnnotatedType(); | ||
90 | + | ||
91 | + for (AnnotatedMethod<?> am : annotatedType.getMethods()) { | ||
92 | + if (am.isAnnotationPresent(getAnnotationClass())) { | ||
93 | + @SuppressWarnings("unchecked") | ||
94 | + AnnotatedMethod<T> annotatedMethod = (AnnotatedMethod<T>) am; | ||
95 | + processors.add(newProcessorInstance(annotatedMethod, beanManager)); | ||
96 | + } | ||
97 | + } | ||
98 | + } | ||
99 | + | ||
100 | + public void loadTempContexts(@Observes final AfterBeanDiscovery event) { | ||
101 | + // Não registrar o contexto de aplicação pq ele já é registrado pela implementação do CDI | ||
102 | + tempContexts.add(new ThreadLocalContext(ViewScoped.class)); | ||
103 | + tempContexts.add(new ThreadLocalContext(SessionScoped.class)); | ||
104 | + tempContexts.add(new ThreadLocalContext(ConversationScoped.class)); | ||
105 | + tempContexts.add(new ThreadLocalContext(RequestScoped.class)); | ||
106 | + | ||
107 | + afterBeanDiscoveryEvent = event; | ||
108 | + } | ||
109 | + | ||
110 | + @SuppressWarnings({ "unchecked", "rawtypes" }) | ||
111 | + protected synchronized void proccessEvent() { | ||
112 | + getLogger().debug( | ||
113 | + getBundle("demoiselle-core-bundle").getString("executing-all", annotationClass.getSimpleName())); | ||
114 | + | ||
115 | + Collections.sort(processors); | ||
116 | + Throwable failure = null; | ||
117 | + | ||
118 | + if (!registered) { | ||
119 | + for (CustomContext tempContext : tempContexts) { | ||
120 | + addContext(tempContext, afterBeanDiscoveryEvent); | ||
121 | + } | ||
122 | + | ||
123 | + registered = true; | ||
124 | + } | ||
125 | + | ||
126 | + for (Iterator<AnnotatedMethodProcessor> iter = processors.iterator(); iter.hasNext();) { | ||
127 | + AnnotatedMethodProcessor<?> processor = iter.next(); | ||
128 | + | ||
129 | + try { | ||
130 | + ClassLoader classLoader = ConfigurationLoader.getClassLoaderForClass(processor.getAnnotatedMethod() | ||
131 | + .getDeclaringType().getJavaClass().getCanonicalName()); | ||
132 | + | ||
133 | + if (Thread.currentThread().getContextClassLoader().equals(classLoader)) { | ||
134 | + processor.process(); | ||
135 | + iter.remove(); | ||
136 | + } | ||
137 | + | ||
138 | + } catch (Throwable cause) { | ||
139 | + failure = cause; | ||
140 | + } | ||
141 | + } | ||
142 | + | ||
143 | + if (processors.isEmpty()) { | ||
144 | + unloadTempContexts(); | ||
145 | + } | ||
146 | + | ||
147 | + if (failure != null) { | ||
148 | + throw new DemoiselleException(failure); | ||
149 | + } | ||
150 | + } | ||
151 | + | ||
152 | + private void unloadTempContexts() { | ||
153 | + for (CustomContext tempContext : tempContexts) { | ||
154 | + disableContext(tempContext); | ||
155 | + } | ||
156 | + } | ||
157 | +} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AsbratctLifecycleBootstrap.java
@@ -1,157 +0,0 @@ | @@ -1,157 +0,0 @@ | ||
1 | -/* | ||
2 | - * Demoiselle Framework | ||
3 | - * Copyright (C) 2010 SERPRO | ||
4 | - * ---------------------------------------------------------------------------- | ||
5 | - * This file is part of Demoiselle Framework. | ||
6 | - * | ||
7 | - * Demoiselle Framework is free software; you can redistribute it and/or | ||
8 | - * modify it under the terms of the GNU Lesser General Public License version 3 | ||
9 | - * as published by the Free Software Foundation. | ||
10 | - * | ||
11 | - * This program is distributed in the hope that it will be useful, | ||
12 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | - * GNU General Public License for more details. | ||
15 | - * | ||
16 | - * You should have received a copy of the GNU Lesser General Public License version 3 | ||
17 | - * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
18 | - * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
19 | - * Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | - * ---------------------------------------------------------------------------- | ||
21 | - * Este arquivo é parte do Framework Demoiselle. | ||
22 | - * | ||
23 | - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
24 | - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
25 | - * do Software Livre (FSF). | ||
26 | - * | ||
27 | - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
28 | - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
29 | - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
30 | - * para maiores detalhes. | ||
31 | - * | ||
32 | - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
33 | - * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
34 | - * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
35 | - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
36 | - */ | ||
37 | -package br.gov.frameworkdemoiselle.internal.bootstrap; | ||
38 | - | ||
39 | -import java.lang.annotation.Annotation; | ||
40 | -import java.util.ArrayList; | ||
41 | -import java.util.Collections; | ||
42 | -import java.util.Iterator; | ||
43 | -import java.util.List; | ||
44 | - | ||
45 | -import javax.enterprise.context.ConversationScoped; | ||
46 | -import javax.enterprise.context.RequestScoped; | ||
47 | -import javax.enterprise.context.SessionScoped; | ||
48 | -import javax.enterprise.event.Observes; | ||
49 | -import javax.enterprise.inject.spi.AfterBeanDiscovery; | ||
50 | -import javax.enterprise.inject.spi.AnnotatedMethod; | ||
51 | -import javax.enterprise.inject.spi.AnnotatedType; | ||
52 | -import javax.enterprise.inject.spi.BeanManager; | ||
53 | -import javax.enterprise.inject.spi.ProcessAnnotatedType; | ||
54 | - | ||
55 | -import br.gov.frameworkdemoiselle.DemoiselleException; | ||
56 | -import br.gov.frameworkdemoiselle.annotation.ViewScoped; | ||
57 | -import br.gov.frameworkdemoiselle.internal.configuration.ConfigurationLoader; | ||
58 | -import br.gov.frameworkdemoiselle.internal.context.CustomContext; | ||
59 | -import br.gov.frameworkdemoiselle.internal.context.ThreadLocalContext; | ||
60 | -import br.gov.frameworkdemoiselle.internal.processor.AnnotatedMethodProcessor; | ||
61 | -import br.gov.frameworkdemoiselle.util.Reflections; | ||
62 | - | ||
63 | -public abstract class AsbratctLifecycleBootstrap<A extends Annotation> extends AbstractBootstrap { | ||
64 | - | ||
65 | - private Class<A> annotationClass; | ||
66 | - | ||
67 | - @SuppressWarnings("rawtypes") | ||
68 | - private final List<AnnotatedMethodProcessor> processors = Collections | ||
69 | - .synchronizedList(new ArrayList<AnnotatedMethodProcessor>()); | ||
70 | - | ||
71 | - private final List<CustomContext> tempContexts = new ArrayList<CustomContext>(); | ||
72 | - | ||
73 | - private AfterBeanDiscovery afterBeanDiscoveryEvent; | ||
74 | - | ||
75 | - private boolean registered = false; | ||
76 | - | ||
77 | - protected abstract <T> AnnotatedMethodProcessor<T> newProcessorInstance(AnnotatedMethod<T> annotatedMethod, | ||
78 | - BeanManager beanManager); | ||
79 | - | ||
80 | - protected Class<A> getAnnotationClass() { | ||
81 | - if (this.annotationClass == null) { | ||
82 | - this.annotationClass = Reflections.getGenericTypeArgument(this.getClass(), 0); | ||
83 | - } | ||
84 | - | ||
85 | - return this.annotationClass; | ||
86 | - } | ||
87 | - | ||
88 | - public <T> void processAnnotatedType(@Observes final ProcessAnnotatedType<T> event, final BeanManager beanManager) { | ||
89 | - final AnnotatedType<T> annotatedType = event.getAnnotatedType(); | ||
90 | - | ||
91 | - for (AnnotatedMethod<?> am : annotatedType.getMethods()) { | ||
92 | - if (am.isAnnotationPresent(getAnnotationClass())) { | ||
93 | - @SuppressWarnings("unchecked") | ||
94 | - AnnotatedMethod<T> annotatedMethod = (AnnotatedMethod<T>) am; | ||
95 | - processors.add(newProcessorInstance(annotatedMethod, beanManager)); | ||
96 | - } | ||
97 | - } | ||
98 | - } | ||
99 | - | ||
100 | - public void loadTempContexts(@Observes final AfterBeanDiscovery event) { | ||
101 | - // Não registrar o contexto de aplicação pq ele já é registrado pela implementação do CDI | ||
102 | - tempContexts.add(new ThreadLocalContext(ViewScoped.class)); | ||
103 | - tempContexts.add(new ThreadLocalContext(SessionScoped.class)); | ||
104 | - tempContexts.add(new ThreadLocalContext(ConversationScoped.class)); | ||
105 | - tempContexts.add(new ThreadLocalContext(RequestScoped.class)); | ||
106 | - | ||
107 | - afterBeanDiscoveryEvent = event; | ||
108 | - } | ||
109 | - | ||
110 | - @SuppressWarnings({ "unchecked", "rawtypes" }) | ||
111 | - protected synchronized void proccessEvent() { | ||
112 | - getLogger().debug( | ||
113 | - getBundle("demoiselle-core-bundle").getString("executing-all", annotationClass.getSimpleName())); | ||
114 | - | ||
115 | - Collections.sort(processors); | ||
116 | - Throwable failure = null; | ||
117 | - | ||
118 | - if (!registered) { | ||
119 | - for (CustomContext tempContext : tempContexts) { | ||
120 | - addContext(tempContext, afterBeanDiscoveryEvent); | ||
121 | - } | ||
122 | - | ||
123 | - registered = true; | ||
124 | - } | ||
125 | - | ||
126 | - for (Iterator<AnnotatedMethodProcessor> iter = processors.iterator(); iter.hasNext();) { | ||
127 | - AnnotatedMethodProcessor<?> processor = iter.next(); | ||
128 | - | ||
129 | - try { | ||
130 | - ClassLoader classLoader = ConfigurationLoader.getClassLoaderForClass(processor.getAnnotatedMethod() | ||
131 | - .getDeclaringType().getJavaClass().getCanonicalName()); | ||
132 | - | ||
133 | - if (Thread.currentThread().getContextClassLoader().equals(classLoader)) { | ||
134 | - processor.process(); | ||
135 | - iter.remove(); | ||
136 | - } | ||
137 | - | ||
138 | - } catch (Throwable cause) { | ||
139 | - failure = cause; | ||
140 | - } | ||
141 | - } | ||
142 | - | ||
143 | - if (processors.isEmpty()) { | ||
144 | - unloadTempContexts(); | ||
145 | - } | ||
146 | - | ||
147 | - if (failure != null) { | ||
148 | - throw new DemoiselleException(failure); | ||
149 | - } | ||
150 | - } | ||
151 | - | ||
152 | - private void unloadTempContexts() { | ||
153 | - for (CustomContext tempContext : tempContexts) { | ||
154 | - disableContext(tempContext); | ||
155 | - } | ||
156 | - } | ||
157 | -} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ShutdownBootstrap.java
@@ -47,7 +47,7 @@ import br.gov.frameworkdemoiselle.internal.processor.ShutdownProcessor; | @@ -47,7 +47,7 @@ import br.gov.frameworkdemoiselle.internal.processor.ShutdownProcessor; | ||
47 | /** | 47 | /** |
48 | * This class run at application shutdown | 48 | * This class run at application shutdown |
49 | */ | 49 | */ |
50 | -public class ShutdownBootstrap extends AsbratctLifecycleBootstrap<Shutdown> { | 50 | +public class ShutdownBootstrap extends AbstractLifecycleBootstrap<Shutdown> { |
51 | 51 | ||
52 | @Override | 52 | @Override |
53 | protected <T> AnnotatedMethodProcessor<T> newProcessorInstance(AnnotatedMethod<T> annotatedMethod, | 53 | protected <T> AnnotatedMethodProcessor<T> newProcessorInstance(AnnotatedMethod<T> annotatedMethod, |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/StartupBootstrap.java
@@ -47,7 +47,7 @@ import br.gov.frameworkdemoiselle.internal.processor.StartupProcessor; | @@ -47,7 +47,7 @@ import br.gov.frameworkdemoiselle.internal.processor.StartupProcessor; | ||
47 | /** | 47 | /** |
48 | * This class is the bootstrap to execute the processes at load time. | 48 | * This class is the bootstrap to execute the processes at load time. |
49 | */ | 49 | */ |
50 | -public class StartupBootstrap extends AsbratctLifecycleBootstrap<Startup> { | 50 | +public class StartupBootstrap extends AbstractLifecycleBootstrap<Startup> { |
51 | 51 | ||
52 | @Override | 52 | @Override |
53 | protected <T> AnnotatedMethodProcessor<T> newProcessorInstance(AnnotatedMethod<T> annotatedMethod, | 53 | protected <T> AnnotatedMethodProcessor<T> newProcessorInstance(AnnotatedMethod<T> annotatedMethod, |