Commit 310bb0d4f4c3c75482ee59b7fd1c4c8220f34731

Authored by Cleverson Sacramento
1 parent 04aa1987
Exists in master

Remoção do AbstractBootstrap e refatoração em todos os Bootstraps

impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AbstractBootstrap.java
@@ -1,77 +0,0 @@ @@ -1,77 +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.util.Locale;  
40 -  
41 -import javax.enterprise.inject.spi.AfterBeanDiscovery;  
42 -import javax.enterprise.inject.spi.Extension;  
43 -  
44 -import org.slf4j.Logger;  
45 -  
46 -import br.gov.frameworkdemoiselle.internal.context.Contexts;  
47 -import br.gov.frameworkdemoiselle.internal.context.CustomContext;  
48 -import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer;  
49 -import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer;  
50 -import br.gov.frameworkdemoiselle.util.ResourceBundle;  
51 -  
52 -public abstract class AbstractBootstrap implements Extension {  
53 -  
54 - protected static ResourceBundle getBundle() {  
55 - return getBundle("demoiselle-core-bundle");  
56 - }  
57 -  
58 - protected static ResourceBundle getBundle(String baseName) {  
59 - return ResourceBundleProducer.create(baseName, Locale.getDefault());  
60 - }  
61 -  
62 - protected static Logger getLogger() {  
63 - return LoggerProducer.create(AbstractBootstrap.class);  
64 - }  
65 -  
66 - protected static void addContext(final CustomContext context, final AfterBeanDiscovery event) {  
67 - Contexts.add(context, event);  
68 - getLogger()  
69 - .trace(getBundle().getString("custom-context-was-registered", context.getScope().getCanonicalName()));  
70 - }  
71 -  
72 - protected static void disableContext(final CustomContext context) {  
73 - Contexts.remove(context);  
74 - getLogger()  
75 - .trace(getBundle().getString("custom-context-was-registered", context.getScope().getCanonicalName()));  
76 - }  
77 -}  
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AbstractLifecycleBootstrap.java
@@ -41,6 +41,7 @@ import java.util.ArrayList; @@ -41,6 +41,7 @@ import java.util.ArrayList;
41 import java.util.Collections; 41 import java.util.Collections;
42 import java.util.Iterator; 42 import java.util.Iterator;
43 import java.util.List; 43 import java.util.List;
  44 +import java.util.Locale;
44 45
45 import javax.enterprise.context.ConversationScoped; 46 import javax.enterprise.context.ConversationScoped;
46 import javax.enterprise.context.RequestScoped; 47 import javax.enterprise.context.RequestScoped;
@@ -49,31 +50,56 @@ import javax.enterprise.event.Observes; @@ -49,31 +50,56 @@ import javax.enterprise.event.Observes;
49 import javax.enterprise.inject.spi.AfterBeanDiscovery; 50 import javax.enterprise.inject.spi.AfterBeanDiscovery;
50 import javax.enterprise.inject.spi.AnnotatedMethod; 51 import javax.enterprise.inject.spi.AnnotatedMethod;
51 import javax.enterprise.inject.spi.AnnotatedType; 52 import javax.enterprise.inject.spi.AnnotatedType;
  53 +import javax.enterprise.inject.spi.Extension;
52 import javax.enterprise.inject.spi.ProcessAnnotatedType; 54 import javax.enterprise.inject.spi.ProcessAnnotatedType;
53 55
  56 +import org.slf4j.Logger;
  57 +
54 import br.gov.frameworkdemoiselle.DemoiselleException; 58 import br.gov.frameworkdemoiselle.DemoiselleException;
55 import br.gov.frameworkdemoiselle.annotation.ViewScoped; 59 import br.gov.frameworkdemoiselle.annotation.ViewScoped;
56 import br.gov.frameworkdemoiselle.internal.configuration.ConfigurationLoader; 60 import br.gov.frameworkdemoiselle.internal.configuration.ConfigurationLoader;
  61 +import br.gov.frameworkdemoiselle.internal.context.Contexts;
57 import br.gov.frameworkdemoiselle.internal.context.CustomContext; 62 import br.gov.frameworkdemoiselle.internal.context.CustomContext;
58 import br.gov.frameworkdemoiselle.internal.context.ThreadLocalContext; 63 import br.gov.frameworkdemoiselle.internal.context.ThreadLocalContext;
59 import br.gov.frameworkdemoiselle.internal.implementation.AnnotatedMethodProcessor; 64 import br.gov.frameworkdemoiselle.internal.implementation.AnnotatedMethodProcessor;
  65 +import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer;
  66 +import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer;
60 import br.gov.frameworkdemoiselle.util.Reflections; 67 import br.gov.frameworkdemoiselle.util.Reflections;
  68 +import br.gov.frameworkdemoiselle.util.ResourceBundle;
61 69
62 -public abstract class AbstractLifecycleBootstrap<A extends Annotation> extends AbstractBootstrap { 70 +public abstract class AbstractLifecycleBootstrap<A extends Annotation> implements Extension {
63 71
64 private Class<A> annotationClass; 72 private Class<A> annotationClass;
65 73
66 @SuppressWarnings("rawtypes") 74 @SuppressWarnings("rawtypes")
67 - private final List<AnnotatedMethodProcessor> processors = Collections 75 + private List<AnnotatedMethodProcessor> processors = Collections
68 .synchronizedList(new ArrayList<AnnotatedMethodProcessor>()); 76 .synchronizedList(new ArrayList<AnnotatedMethodProcessor>());
69 77
70 - private final List<CustomContext> tempContexts = new ArrayList<CustomContext>(); 78 + private List<CustomContext> tempContexts = new ArrayList<CustomContext>();
71 79
72 private AfterBeanDiscovery afterBeanDiscoveryEvent; 80 private AfterBeanDiscovery afterBeanDiscoveryEvent;
73 81
74 private boolean registered = false; 82 private boolean registered = false;
75 83
76 - // protected abstract <T> AnnotatedMethodProcessor<T> newProcessorInstance(AnnotatedMethod<T> annotatedMethod); 84 + private static Logger logger;
  85 +
  86 + private static ResourceBundle bundle;
  87 +
  88 + protected static Logger getLogger() {
  89 + if (logger == null) {
  90 + logger = LoggerProducer.create(AbstractLifecycleBootstrap.class);
  91 + }
  92 +
  93 + return logger;
  94 + }
  95 +
  96 + protected static ResourceBundle getBundle() {
  97 + if (bundle == null) {
  98 + bundle = ResourceBundleProducer.create("demoiselle-core-bundle", Locale.getDefault());
  99 + }
  100 +
  101 + return bundle;
  102 + }
77 103
78 protected <T> AnnotatedMethodProcessor<T> newProcessorInstance(AnnotatedMethod<T> annotatedMethod) { 104 protected <T> AnnotatedMethodProcessor<T> newProcessorInstance(AnnotatedMethod<T> annotatedMethod) {
79 return new AnnotatedMethodProcessor<T>(annotatedMethod); 105 return new AnnotatedMethodProcessor<T>(annotatedMethod);
@@ -111,15 +137,14 @@ public abstract class AbstractLifecycleBootstrap&lt;A extends Annotation&gt; extends A @@ -111,15 +137,14 @@ public abstract class AbstractLifecycleBootstrap&lt;A extends Annotation&gt; extends A
111 137
112 @SuppressWarnings({ "unchecked", "rawtypes" }) 138 @SuppressWarnings({ "unchecked", "rawtypes" })
113 protected synchronized void proccessEvent() { 139 protected synchronized void proccessEvent() {
114 - getLogger().debug(  
115 - getBundle("demoiselle-core-bundle").getString("executing-all", annotationClass.getSimpleName())); 140 + getLogger().debug(getBundle().getString("executing-all", annotationClass.getSimpleName()));
116 141
117 Collections.sort(processors); 142 Collections.sort(processors);
118 Throwable failure = null; 143 Throwable failure = null;
119 144
120 if (!registered) { 145 if (!registered) {
121 for (CustomContext tempContext : tempContexts) { 146 for (CustomContext tempContext : tempContexts) {
122 - addContext(tempContext, afterBeanDiscoveryEvent); 147 + Contexts.add(tempContext, afterBeanDiscoveryEvent);
123 } 148 }
124 149
125 registered = true; 150 registered = true;
@@ -153,7 +178,7 @@ public abstract class AbstractLifecycleBootstrap&lt;A extends Annotation&gt; extends A @@ -153,7 +178,7 @@ public abstract class AbstractLifecycleBootstrap&lt;A extends Annotation&gt; extends A
153 178
154 private void unloadTempContexts() { 179 private void unloadTempContexts() {
155 for (CustomContext tempContext : tempContexts) { 180 for (CustomContext tempContext : tempContexts) {
156 - disableContext(tempContext); 181 + Contexts.remove(tempContext);
157 } 182 }
158 } 183 }
159 } 184 }
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AbstractStrategyBootstrap.java
@@ -6,17 +6,31 @@ import java.util.List; @@ -6,17 +6,31 @@ import java.util.List;
6 6
7 import javax.enterprise.event.Observes; 7 import javax.enterprise.event.Observes;
8 import javax.enterprise.inject.spi.AnnotatedType; 8 import javax.enterprise.inject.spi.AnnotatedType;
  9 +import javax.enterprise.inject.spi.Extension;
9 import javax.enterprise.inject.spi.ProcessAnnotatedType; 10 import javax.enterprise.inject.spi.ProcessAnnotatedType;
10 11
  12 +import org.slf4j.Logger;
  13 +
  14 +import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer;
11 import br.gov.frameworkdemoiselle.util.Reflections; 15 import br.gov.frameworkdemoiselle.util.Reflections;
12 16
13 -public class AbstractStrategyBootstrap<I> extends AbstractBootstrap { 17 +public class AbstractStrategyBootstrap<I> implements Extension {
  18 +
  19 + private Class<? extends I> strategyClass;
  20 +
  21 + private List<Class<? extends I>> cache;
14 22
15 - private Class<I> strategyClass; 23 + private static Logger logger;
16 24
17 - private List<Class<I>> cache; 25 + protected static Logger getLogger() {
  26 + if (logger == null) {
  27 + logger = LoggerProducer.create(AbstractStrategyBootstrap.class);
  28 + }
  29 +
  30 + return logger;
  31 + }
18 32
19 - protected Class<I> getStrategyClass() { 33 + protected Class<? extends I> getStrategyClass() {
20 if (this.strategyClass == null) { 34 if (this.strategyClass == null) {
21 this.strategyClass = Reflections.getGenericTypeArgument(this.getClass(), 0); 35 this.strategyClass = Reflections.getGenericTypeArgument(this.getClass(), 0);
22 } 36 }
@@ -24,9 +38,9 @@ public class AbstractStrategyBootstrap&lt;I&gt; extends AbstractBootstrap { @@ -24,9 +38,9 @@ public class AbstractStrategyBootstrap&lt;I&gt; extends AbstractBootstrap {
24 return this.strategyClass; 38 return this.strategyClass;
25 } 39 }
26 40
27 - public List<Class<I>> getCache() { 41 + public List<Class<? extends I>> getCache() {
28 if (this.cache == null) { 42 if (this.cache == null) {
29 - this.cache = Collections.synchronizedList(new ArrayList<Class<I>>()); 43 + this.cache = Collections.synchronizedList(new ArrayList<Class<? extends I>>());
30 } 44 }
31 45
32 return this.cache; 46 return this.cache;
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AuthenticatorBootstrap.java
@@ -36,7 +36,20 @@ @@ -36,7 +36,20 @@
36 */ 36 */
37 package br.gov.frameworkdemoiselle.internal.bootstrap; 37 package br.gov.frameworkdemoiselle.internal.bootstrap;
38 38
  39 +import org.slf4j.Logger;
  40 +
  41 +import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer;
39 import br.gov.frameworkdemoiselle.security.Authenticator; 42 import br.gov.frameworkdemoiselle.security.Authenticator;
40 43
41 public class AuthenticatorBootstrap extends AbstractStrategyBootstrap<Authenticator> { 44 public class AuthenticatorBootstrap extends AbstractStrategyBootstrap<Authenticator> {
  45 +
  46 + private static Logger logger;
  47 +
  48 + protected static Logger getLogger() {
  49 + if (logger == null) {
  50 + logger = LoggerProducer.create(AuthenticatorBootstrap.class);
  51 + }
  52 +
  53 + return logger;
  54 + }
42 } 55 }
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AuthorizerBootstrap.java
@@ -36,7 +36,20 @@ @@ -36,7 +36,20 @@
36 */ 36 */
37 package br.gov.frameworkdemoiselle.internal.bootstrap; 37 package br.gov.frameworkdemoiselle.internal.bootstrap;
38 38
  39 +import org.slf4j.Logger;
  40 +
  41 +import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer;
39 import br.gov.frameworkdemoiselle.security.Authorizer; 42 import br.gov.frameworkdemoiselle.security.Authorizer;
40 43
41 public class AuthorizerBootstrap extends AbstractStrategyBootstrap<Authorizer> { 44 public class AuthorizerBootstrap extends AbstractStrategyBootstrap<Authorizer> {
  45 +
  46 + private static Logger logger;
  47 +
  48 + protected static Logger getLogger() {
  49 + if (logger == null) {
  50 + logger = LoggerProducer.create(AuthorizerBootstrap.class);
  51 + }
  52 +
  53 + return logger;
  54 + }
42 } 55 }
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/CoreBootstrap.java
@@ -37,6 +37,7 @@ @@ -37,6 +37,7 @@
37 package br.gov.frameworkdemoiselle.internal.bootstrap; 37 package br.gov.frameworkdemoiselle.internal.bootstrap;
38 38
39 import java.util.HashMap; 39 import java.util.HashMap;
  40 +import java.util.Locale;
40 import java.util.Map; 41 import java.util.Map;
41 42
42 import javax.enterprise.event.Observes; 43 import javax.enterprise.event.Observes;
@@ -45,18 +46,41 @@ import javax.enterprise.inject.spi.AnnotatedType; @@ -45,18 +46,41 @@ import javax.enterprise.inject.spi.AnnotatedType;
45 import javax.enterprise.inject.spi.BeanManager; 46 import javax.enterprise.inject.spi.BeanManager;
46 import javax.enterprise.inject.spi.BeforeBeanDiscovery; 47 import javax.enterprise.inject.spi.BeforeBeanDiscovery;
47 import javax.enterprise.inject.spi.BeforeShutdown; 48 import javax.enterprise.inject.spi.BeforeShutdown;
  49 +import javax.enterprise.inject.spi.Extension;
48 import javax.enterprise.inject.spi.ProcessAnnotatedType; 50 import javax.enterprise.inject.spi.ProcessAnnotatedType;
49 51
50 import org.slf4j.Logger; 52 import org.slf4j.Logger;
51 53
  54 +import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer;
  55 +import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer;
52 import br.gov.frameworkdemoiselle.util.Beans; 56 import br.gov.frameworkdemoiselle.util.Beans;
  57 +import br.gov.frameworkdemoiselle.util.ResourceBundle;
53 58
54 -//TODO Inter [NQ]: verificar o melhor nome para todas as classes desta natureza.  
55 -public class CoreBootstrap extends AbstractBootstrap { 59 +public class CoreBootstrap implements Extension {
56 60
57 - private static final Map<Class<?>, AnnotatedType<?>> beans = new HashMap<Class<?>, AnnotatedType<?>>(); 61 + private final Map<Class<?>, AnnotatedType<?>> beans = new HashMap<Class<?>, AnnotatedType<?>>();
58 62
59 - public static boolean isAnnotatedType(Class<?> type) { 63 + private static Logger logger;
  64 +
  65 + private static ResourceBundle bundle;
  66 +
  67 + private static Logger getLogger() {
  68 + if (logger == null) {
  69 + logger = LoggerProducer.create(CoreBootstrap.class);
  70 + }
  71 +
  72 + return logger;
  73 + }
  74 +
  75 + private static ResourceBundle getBundle() {
  76 + if (bundle == null) {
  77 + bundle = ResourceBundleProducer.create("demoiselle-core-bundle", Locale.getDefault());
  78 + }
  79 +
  80 + return bundle;
  81 + }
  82 +
  83 + public boolean isAnnotatedType(Class<?> type) {
60 return beans.containsKey(type); 84 return beans.containsKey(type);
61 } 85 }
62 86
@@ -64,13 +88,12 @@ public class CoreBootstrap extends AbstractBootstrap { @@ -64,13 +88,12 @@ public class CoreBootstrap extends AbstractBootstrap {
64 String description; 88 String description;
65 Logger log = getLogger(); 89 Logger log = getLogger();
66 90
67 - description = getBundle("demoiselle-core-bundle").getString("engine-on"); 91 + description = getBundle().getString("engine-on");
68 log.info(description); 92 log.info(description);
69 93
70 Beans.setBeanManager(beanManager); 94 Beans.setBeanManager(beanManager);
71 95
72 - description = getBundle("demoiselle-core-bundle").getString("setting-up-bean-manager",  
73 - Beans.class.getCanonicalName()); 96 + description = getBundle().getString("setting-up-bean-manager", Beans.class.getCanonicalName());
74 log.info(description); 97 log.info(description);
75 } 98 }
76 99
@@ -78,15 +101,15 @@ public class CoreBootstrap extends AbstractBootstrap { @@ -78,15 +101,15 @@ public class CoreBootstrap extends AbstractBootstrap {
78 beans.put(event.getAnnotatedType().getJavaClass(), event.getAnnotatedType()); 101 beans.put(event.getAnnotatedType().getJavaClass(), event.getAnnotatedType());
79 } 102 }
80 103
81 - public static void takeOff(@Observes final AfterDeploymentValidation event) {  
82 - String description = getBundle("demoiselle-core-bundle").getString("taking-off"); 104 + public void takeOff(@Observes final AfterDeploymentValidation event) {
  105 + String description = getBundle().getString("taking-off");
83 106
84 Logger log = getLogger(); 107 Logger log = getLogger();
85 log.info(description); 108 log.info(description);
86 } 109 }
87 110
88 - public static void engineOff(@Observes final BeforeShutdown event) {  
89 - String description = getBundle("demoiselle-core-bundle").getString("engine-off"); 111 + public void engineOff(@Observes final BeforeShutdown event) {
  112 + String description = getBundle().getString("engine-off");
90 113
91 Logger log = getLogger(); 114 Logger log = getLogger();
92 log.info(description); 115 log.info(description);
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/Contexts.java
@@ -39,25 +39,58 @@ package br.gov.frameworkdemoiselle.internal.context; @@ -39,25 +39,58 @@ package br.gov.frameworkdemoiselle.internal.context;
39 import java.lang.annotation.Annotation; 39 import java.lang.annotation.Annotation;
40 import java.util.ArrayList; 40 import java.util.ArrayList;
41 import java.util.Collections; 41 import java.util.Collections;
  42 +import java.util.Iterator;
42 import java.util.List; 43 import java.util.List;
43 44
44 import javax.enterprise.inject.spi.AfterBeanDiscovery; 45 import javax.enterprise.inject.spi.AfterBeanDiscovery;
45 46
  47 +import org.slf4j.Logger;
  48 +
  49 +import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer;
  50 +import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer;
  51 +import br.gov.frameworkdemoiselle.util.ResourceBundle;
  52 +
46 public class Contexts { 53 public class Contexts {
47 54
48 - private static List<CustomContext> activeContexts; 55 + private static List<CustomContext> activeContexts = Collections.synchronizedList(new ArrayList<CustomContext>());
  56 +
  57 + private static List<CustomContext> inactiveContexts = Collections.synchronizedList(new ArrayList<CustomContext>());
  58 +
  59 + private static Logger logger;
  60 +
  61 + private static ResourceBundle bundle;
  62 +
  63 + private static Logger getLogger() {
  64 + if (logger == null) {
  65 + logger = LoggerProducer.create(Contexts.class);
  66 + }
  67 +
  68 + return logger;
  69 + }
  70 +
  71 + private static ResourceBundle getBundle() {
  72 + if (bundle == null) {
  73 + bundle = ResourceBundleProducer.create("demoiselle-core-bundle");
  74 + }
49 75
50 - private static List<CustomContext> inactiveContexts; 76 + return bundle;
  77 + }
51 78
52 - public static void add(CustomContext context, AfterBeanDiscovery event) { 79 + private Contexts() {
  80 + }
  81 +
  82 + public static synchronized void add(CustomContext context, AfterBeanDiscovery event) {
53 Class<? extends Annotation> scope = context.getScope(); 83 Class<? extends Annotation> scope = context.getScope();
54 84
55 - if (get(scope, getActiveContexts()) != null) {  
56 - getInactiveContexts().add(context); 85 + getLogger()
  86 + .trace(getBundle().getString("custom-context-was-registered", context.getScope().getCanonicalName()));
  87 +
  88 + if (get(scope, activeContexts) != null) {
  89 + inactiveContexts.add(context);
57 context.setActive(false); 90 context.setActive(false);
58 91
59 } else { 92 } else {
60 - getActiveContexts().add(context); 93 + activeContexts.add(context);
61 context.setActive(true); 94 context.setActive(true);
62 } 95 }
63 96
@@ -79,45 +112,43 @@ public class Contexts { @@ -79,45 +112,43 @@ public class Contexts {
79 return result; 112 return result;
80 } 113 }
81 114
82 - public static void remove(CustomContext context) {  
83 - if (getActiveContexts().contains(context)) {  
84 - getActiveContexts().remove(context); 115 + public static synchronized void remove(CustomContext context) {
  116 + getLogger().trace(
  117 + getBundle().getString("custom-context-was-unregistered", context.getScope().getCanonicalName()));
  118 +
  119 + if (activeContexts.contains(context)) {
  120 + activeContexts.remove(context);
85 context.setActive(false); 121 context.setActive(false);
86 122
87 - CustomContext inactive = get(context.getScope(), getInactiveContexts()); 123 + CustomContext inactive = get(context.getScope(), inactiveContexts);
88 if (inactive != null) { 124 if (inactive != null) {
89 - getActiveContexts().add(inactive); 125 + activeContexts.add(inactive);
90 inactive.setActive(true); 126 inactive.setActive(true);
91 - getInactiveContexts().remove(inactive); 127 + inactiveContexts.remove(inactive);
92 } 128 }
93 129
94 - } else if (getInactiveContexts().contains(context)) {  
95 - getInactiveContexts().remove(context); 130 + } else if (inactiveContexts.contains(context)) {
  131 + inactiveContexts.remove(context);
96 } 132 }
97 } 133 }
98 134
99 - public static void clear() {  
100 - for (CustomContext context : getActiveContexts()) { 135 + public static synchronized void clear() {
  136 + CustomContext context;
  137 + for (Iterator<CustomContext> iter = activeContexts.iterator(); iter.hasNext();) {
  138 + context = iter.next();
101 context.setActive(false); 139 context.setActive(false);
  140 + iter.remove();
102 } 141 }
103 142
104 - activeContexts = null;  
105 - inactiveContexts = null; 143 + activeContexts.clear();
  144 + inactiveContexts.clear();
106 } 145 }
107 146
108 - public static List<CustomContext> getActiveContexts() {  
109 - if (activeContexts == null) {  
110 - activeContexts = Collections.synchronizedList(new ArrayList<CustomContext>());  
111 - }  
112 - 147 + public static synchronized List<CustomContext> getActiveContexts() {
113 return activeContexts; 148 return activeContexts;
114 } 149 }
115 150
116 - public static List<CustomContext> getInactiveContexts() {  
117 - if (inactiveContexts == null) {  
118 - inactiveContexts = Collections.synchronizedList(new ArrayList<CustomContext>());  
119 - }  
120 - 151 + public static synchronized List<CustomContext> getInactiveContexts() {
121 return inactiveContexts; 152 return inactiveContexts;
122 } 153 }
123 } 154 }
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/interceptor/ExceptionHandlerInterceptor.java
@@ -54,6 +54,7 @@ import br.gov.frameworkdemoiselle.internal.bootstrap.CoreBootstrap; @@ -54,6 +54,7 @@ import br.gov.frameworkdemoiselle.internal.bootstrap.CoreBootstrap;
54 import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; 54 import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer;
55 import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; 55 import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer;
56 import br.gov.frameworkdemoiselle.stereotype.Controller; 56 import br.gov.frameworkdemoiselle.stereotype.Controller;
  57 +import br.gov.frameworkdemoiselle.util.Beans;
57 import br.gov.frameworkdemoiselle.util.ResourceBundle; 58 import br.gov.frameworkdemoiselle.util.ResourceBundle;
58 59
59 @Interceptor 60 @Interceptor
@@ -89,8 +90,9 @@ public class ExceptionHandlerInterceptor implements Serializable { @@ -89,8 +90,9 @@ public class ExceptionHandlerInterceptor implements Serializable {
89 90
90 private final Class<?> getType(final InvocationContext ic) { 91 private final Class<?> getType(final InvocationContext ic) {
91 Class<?> type = ic.getTarget().getClass(); 92 Class<?> type = ic.getTarget().getClass();
  93 + CoreBootstrap bootstrap = Beans.getReference(CoreBootstrap.class);
92 94
93 - if (!CoreBootstrap.isAnnotatedType(type)) { 95 + if (!bootstrap.isAnnotatedType(type)) {
94 type = type.getSuperclass(); 96 type = type.getSuperclass();
95 getLogger().debug( 97 getLogger().debug(
96 getBundle().getString("proxy-detected", ic.getTarget().getClass(), 98 getBundle().getString("proxy-detected", ic.getTarget().getClass(),
impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/bootstrap/AbstractBootstrapTest.java
@@ -1,213 +0,0 @@ @@ -1,213 +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 static org.easymock.EasyMock.expect;  
40 -import static org.powermock.api.easymock.PowerMock.mockStatic;  
41 -import static org.powermock.api.easymock.PowerMock.replayAll;  
42 -import static org.powermock.api.easymock.PowerMock.verifyAll;  
43 -  
44 -import javax.enterprise.inject.spi.AfterBeanDiscovery;  
45 -import javax.inject.Scope;  
46 -  
47 -import org.easymock.EasyMock;  
48 -import org.junit.After;  
49 -import org.junit.Assert;  
50 -import org.junit.Test;  
51 -import org.junit.runner.RunWith;  
52 -import org.powermock.api.easymock.PowerMock;  
53 -import org.powermock.core.classloader.annotations.PrepareForTest;  
54 -import org.powermock.modules.junit4.PowerMockRunner;  
55 -import org.slf4j.Logger;  
56 -  
57 -import br.gov.frameworkdemoiselle.internal.context.Contexts;  
58 -import br.gov.frameworkdemoiselle.internal.context.ThreadLocalContext;  
59 -import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer;  
60 -  
61 -@RunWith(PowerMockRunner.class)  
62 -@PrepareForTest({ LoggerProducer.class, Contexts.class })  
63 -public class AbstractBootstrapTest {  
64 -  
65 - @After  
66 - public void afterTests() {  
67 - for(int x=0; x < Contexts.getActiveContexts().size(); x++)  
68 - Contexts.getActiveContexts().remove(x);  
69 -  
70 - for(int x=0; x < Contexts.getInactiveContexts().size(); x++)  
71 - Contexts.getInactiveContexts().remove(x);  
72 - }  
73 -  
74 - @Test  
75 - @SuppressWarnings({ "unchecked"})  
76 - public void testAddContextThatIsNotActive() {  
77 - mockStatic(LoggerProducer.class);  
78 - Logger logger = PowerMock.createMock(Logger.class);  
79 - logger.trace(EasyMock.anyObject(String.class));  
80 - expect(LoggerProducer.create(EasyMock.anyObject(Class.class))).andReturn(logger);  
81 - replayAll(logger, LoggerProducer.class);  
82 -  
83 - ThreadLocalContext context = new ThreadLocalContext(Scope.class);  
84 -  
85 - AbstractBootstrap.addContext(context, null);  
86 -  
87 - Assert.assertTrue(context.isActive());  
88 - Assert.assertEquals(1, Contexts.getActiveContexts().size());  
89 - }  
90 -  
91 - @Test  
92 - @SuppressWarnings({ "unchecked"})  
93 - public void testAddContextThatIsActive() {  
94 - mockStatic(LoggerProducer.class);  
95 - Logger logger = PowerMock.createMock(Logger.class);  
96 - logger.trace(EasyMock.anyObject(String.class));  
97 - expect(LoggerProducer.create(EasyMock.anyObject(Class.class))).andReturn(logger);  
98 - replayAll(logger, LoggerProducer.class);  
99 -  
100 - ThreadLocalContext context = new ThreadLocalContext(Scope.class);  
101 - Contexts.getActiveContexts().add(context);  
102 -  
103 - AbstractBootstrap.addContext(context, null);  
104 -  
105 - Assert.assertFalse(context.isActive());  
106 - Assert.assertEquals(1, Contexts.getInactiveContexts().size());  
107 - }  
108 -  
109 - @Test  
110 - @SuppressWarnings({ "unchecked"})  
111 - public void testAddContextThatEventIsNotNull() {  
112 - mockStatic(LoggerProducer.class);  
113 - Logger logger = PowerMock.createMock(Logger.class);  
114 - logger.trace(EasyMock.anyObject(String.class));  
115 - expect(LoggerProducer.create(EasyMock.anyObject(Class.class))).andReturn(logger);  
116 - AfterBeanDiscovery event = PowerMock.createMock(AfterBeanDiscovery.class);  
117 -  
118 - ThreadLocalContext context = new ThreadLocalContext(Scope.class);  
119 - event.addContext(context);  
120 -  
121 - replayAll(logger, LoggerProducer.class);  
122 -  
123 -  
124 - AbstractBootstrap.addContext(context, event);  
125 -  
126 - Assert.assertTrue(context.isActive());  
127 - Assert.assertEquals(1, Contexts.getActiveContexts().size());  
128 -  
129 - verifyAll();  
130 - }  
131 -  
132 - @Test  
133 - @SuppressWarnings({ "unchecked"})  
134 - public void testDisableContextIsActive() {  
135 - mockStatic(LoggerProducer.class);  
136 - Logger logger = PowerMock.createMock(Logger.class);  
137 - logger.trace(EasyMock.anyObject(String.class));  
138 - logger.trace(EasyMock.anyObject(String.class));  
139 - expect(LoggerProducer.create(EasyMock.anyObject(Class.class))).andReturn(logger).anyTimes();  
140 -  
141 - ThreadLocalContext context = new ThreadLocalContext(Scope.class);  
142 -  
143 - replayAll(logger, LoggerProducer.class);  
144 -  
145 -  
146 - AbstractBootstrap.addContext(context, null);  
147 -  
148 - Assert.assertTrue(context.isActive());  
149 - Assert.assertEquals(1, Contexts.getActiveContexts().size());  
150 -  
151 - AbstractBootstrap.disableContext(context);  
152 -  
153 - Assert.assertFalse(context.isActive());  
154 - Assert.assertEquals(0, Contexts.getActiveContexts().size());  
155 -  
156 - }  
157 -  
158 - @Test  
159 - @SuppressWarnings({ "unchecked"})  
160 - public void testDisableContextIsNotActive() {  
161 - mockStatic(LoggerProducer.class);  
162 - Logger logger = PowerMock.createMock(Logger.class);  
163 - logger.trace(EasyMock.anyObject(String.class));  
164 - logger.trace(EasyMock.anyObject(String.class));  
165 - expect(LoggerProducer.create(EasyMock.anyObject(Class.class))).andReturn(logger).anyTimes();  
166 -  
167 - ThreadLocalContext context = new ThreadLocalContext(Scope.class);  
168 -  
169 - replayAll(logger, LoggerProducer.class);  
170 -  
171 - Contexts.getInactiveContexts().add(context);  
172 - Assert.assertEquals(1, Contexts.getInactiveContexts().size());  
173 -  
174 - AbstractBootstrap.disableContext(context);  
175 -  
176 - Assert.assertEquals(0, Contexts.getInactiveContexts().size());  
177 -  
178 - }  
179 -  
180 - @Test  
181 - @SuppressWarnings({ "unchecked"})  
182 - public void testDisableContextIsActiveAndExistTheSameScopeInTheInactives() {  
183 - mockStatic(LoggerProducer.class);  
184 - Logger logger = PowerMock.createMock(Logger.class);  
185 - logger.trace(EasyMock.anyObject(String.class));  
186 - logger.trace(EasyMock.anyObject(String.class));  
187 - expect(LoggerProducer.create(EasyMock.anyObject(Class.class))).andReturn(logger).anyTimes();  
188 -  
189 - ThreadLocalContext context = new ThreadLocalContext(Scope.class);  
190 -  
191 - replayAll(logger, LoggerProducer.class);  
192 -  
193 - AbstractBootstrap.addContext(context, null);  
194 -  
195 - ThreadLocalContext context2 = new ThreadLocalContext(Scope.class);  
196 - context2.setActive(false);  
197 - Contexts.getInactiveContexts().add(context2);  
198 -  
199 - Assert.assertTrue(context.isActive());  
200 - Assert.assertEquals(1, Contexts.getActiveContexts().size());  
201 -  
202 - Assert.assertFalse(context2.isActive());  
203 - Assert.assertEquals(1, Contexts.getInactiveContexts().size());  
204 -  
205 - AbstractBootstrap.disableContext(context);  
206 -  
207 - Assert.assertFalse(context.isActive());  
208 - Assert.assertTrue(context2.isActive());  
209 - Assert.assertEquals(1, Contexts.getActiveContexts().size());  
210 - Assert.assertEquals(0, Contexts.getInactiveContexts().size());  
211 -  
212 - }  
213 -}  
impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/context/ContextsTest.java
1 /* 1 /*
2 - * Demoiselle Framework Copyright (C) 2010 SERPRO  
3 - * ---------------------------------------------------------------------------- This file is part of Demoiselle  
4 - * Framework. Demoiselle Framework is free software; you can redistribute it and/or modify it under the terms of the GNU  
5 - * Lesser General Public License version 3 as published by the Free Software Foundation. This program is distributed in  
6 - * the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or  
7 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a  
8 - * copy of the GNU Lesser General Public License version 3 along with this program; if not, see  
9 - * <http://www.gnu.org/licenses/> or write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,  
10 - * Boston, MA 02110-1301, USA. ---------------------------------------------------------------------------- Este arquivo  
11 - * é parte do Framework Demoiselle. O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou  
12 - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação do Software Livre (FSF). Este  
13 - * programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA GARANTIA; sem uma garantia implícita de  
14 - * ADEQUAÇÃO a qualquer MERCADO ou APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português para  
15 - * maiores detalhes. Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título "LICENCA.txt", junto com esse  
16 - * programa. Se não, acesse <http://www.gnu.org/licenses/> ou escreva para a Fundação do Software Livre (FSF) Inc., 51  
17 - * Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. 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.
18 */ 36 */
19 package br.gov.frameworkdemoiselle.internal.context; 37 package br.gov.frameworkdemoiselle.internal.context;
20 38
21 -import org.junit.Ignore;  
22 import static org.easymock.EasyMock.createMock; 39 import static org.easymock.EasyMock.createMock;
23 import static org.easymock.EasyMock.expectLastCall; 40 import static org.easymock.EasyMock.expectLastCall;
24 import static org.easymock.EasyMock.replay; 41 import static org.easymock.EasyMock.replay;
@@ -34,9 +51,7 @@ import javax.enterprise.context.RequestScoped; @@ -34,9 +51,7 @@ import javax.enterprise.context.RequestScoped;
34 import javax.enterprise.context.SessionScoped; 51 import javax.enterprise.context.SessionScoped;
35 import javax.enterprise.inject.spi.AfterBeanDiscovery; 52 import javax.enterprise.inject.spi.AfterBeanDiscovery;
36 53
37 -import org.junit.Assert;  
38 import org.junit.Before; 54 import org.junit.Before;
39 -import org.junit.BeforeClass;  
40 import org.junit.Test; 55 import org.junit.Test;
41 56
42 import br.gov.frameworkdemoiselle.annotation.ViewScoped; 57 import br.gov.frameworkdemoiselle.annotation.ViewScoped;
@@ -45,11 +60,6 @@ public class ContextsTest { @@ -45,11 +60,6 @@ public class ContextsTest {
45 60
46 private AfterBeanDiscovery event; 61 private AfterBeanDiscovery event;
47 62
48 - @BeforeClass  
49 - public static void setUpClass() throws Exception {  
50 - // TODO AfterBeanDiscovery event = ??? mock ???  
51 - }  
52 -  
53 @Before 63 @Before
54 public void setUp() throws Exception { 64 public void setUp() throws Exception {
55 Contexts.clear(); 65 Contexts.clear();
@@ -194,12 +204,4 @@ public class ContextsTest { @@ -194,12 +204,4 @@ public class ContextsTest {
194 Contexts.add(context, event); 204 Contexts.add(context, event);
195 assertEquals(1, Contexts.getActiveContexts().size()); 205 assertEquals(1, Contexts.getActiveContexts().size());
196 } 206 }
197 -  
198 - // Only to get 100% on coverage report  
199 - @Test  
200 - public void testCreateNew() {  
201 - Contexts context = new Contexts();  
202 - Assert.assertNotNull(context);  
203 - }  
204 -  
205 } 207 }
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/JsfBootstrap.java
@@ -36,14 +36,40 @@ @@ -36,14 +36,40 @@
36 */ 36 */
37 package br.gov.frameworkdemoiselle.internal.bootstrap; 37 package br.gov.frameworkdemoiselle.internal.bootstrap;
38 38
  39 +import java.util.ArrayList;
  40 +import java.util.List;
  41 +
39 import javax.enterprise.event.Observes; 42 import javax.enterprise.event.Observes;
40 import javax.enterprise.inject.spi.AfterBeanDiscovery; 43 import javax.enterprise.inject.spi.AfterBeanDiscovery;
  44 +import javax.enterprise.inject.spi.AfterDeploymentValidation;
  45 +import javax.enterprise.inject.spi.Extension;
41 46
  47 +import br.gov.frameworkdemoiselle.internal.context.Contexts;
  48 +import br.gov.frameworkdemoiselle.internal.context.CustomContext;
42 import br.gov.frameworkdemoiselle.internal.context.ViewContext; 49 import br.gov.frameworkdemoiselle.internal.context.ViewContext;
  50 +import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess;
  51 +
  52 +public class JsfBootstrap implements Extension {
  53 +
  54 + private List<CustomContext> tempContexts = new ArrayList<CustomContext>();
  55 +
  56 + private AfterBeanDiscovery afterBeanDiscoveryEvent;
43 57
44 -public class JsfBootstrap extends AbstractBootstrap { 58 + public void storeContexts(@Observes final AfterBeanDiscovery event) {
  59 + tempContexts.add(new ViewContext());
  60 +
  61 + afterBeanDiscoveryEvent = event;
  62 + }
  63 +
  64 + public void addContexts(@Observes final AfterDeploymentValidation event) {
  65 + for (CustomContext tempContext : tempContexts) {
  66 + Contexts.add(tempContext, afterBeanDiscoveryEvent);
  67 + }
  68 + }
45 69
46 - public void loadContexts(@Observes final AfterBeanDiscovery event) {  
47 - addContext(new ViewContext(), event); 70 + public void removeContexts(@Observes AfterShutdownProccess event) {
  71 + for (CustomContext tempContext : tempContexts) {
  72 + Contexts.remove(tempContext);
  73 + }
48 } 74 }
49 } 75 }
impl/extension/jsf/src/test/java/br/gov/frameworkdemoiselle/internal/bootstrap/FacesBootstrapTest.java
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 -import org.junit.Ignore;  
39 -import static org.powermock.api.easymock.PowerMock.createMock;  
40 -import static org.powermock.api.easymock.PowerMock.replay;  
41 -import static org.powermock.api.easymock.PowerMock.verifyAll;  
42 -  
43 -import javax.enterprise.inject.spi.AfterBeanDiscovery;  
44 -  
45 -import org.easymock.EasyMock;  
46 -import org.junit.Before;  
47 -import org.junit.Test;  
48 -import org.junit.runner.RunWith;  
49 -import org.powermock.modules.junit4.PowerMockRunner;  
50 -  
51 -import br.gov.frameworkdemoiselle.internal.context.ViewContext;  
52 -@Ignore  
53 -@RunWith(PowerMockRunner.class)  
54 -public class FacesBootstrapTest {  
55 -  
56 - private JsfBootstrap bootstrap;  
57 -  
58 - @Before  
59 - public void before() {  
60 - bootstrap = new JsfBootstrap();  
61 - }  
62 -  
63 - @Test  
64 - public void testLoadContexts() {  
65 - AfterBeanDiscovery event = createMock(AfterBeanDiscovery.class);  
66 - event.addContext(EasyMock.anyObject(ViewContext.class));  
67 - replay(event);  
68 - bootstrap.loadContexts(event);  
69 - verifyAll();  
70 - }  
71 -  
72 -} 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 +//import org.junit.Ignore;
  39 +//import static org.powermock.api.easymock.PowerMock.createMock;
  40 +//import static org.powermock.api.easymock.PowerMock.replay;
  41 +//import static org.powermock.api.easymock.PowerMock.verifyAll;
  42 +//
  43 +//import javax.enterprise.inject.spi.AfterBeanDiscovery;
  44 +//
  45 +//import org.easymock.EasyMock;
  46 +//import org.junit.Before;
  47 +//import org.junit.Test;
  48 +//import org.junit.runner.RunWith;
  49 +//import org.powermock.modules.junit4.PowerMockRunner;
  50 +//
  51 +//import br.gov.frameworkdemoiselle.internal.context.ViewContext;
  52 +//@Ignore
  53 +//@RunWith(PowerMockRunner.class)
  54 +//public class FacesBootstrapTest {
  55 +//
  56 +// private JsfBootstrap bootstrap;
  57 +//
  58 +// @Before
  59 +// public void before() {
  60 +// bootstrap = new JsfBootstrap();
  61 +// }
  62 +//
  63 +// @Test
  64 +// public void testLoadContexts() {
  65 +// AfterBeanDiscovery event = createMock(AfterBeanDiscovery.class);
  66 +// event.addContext(EasyMock.anyObject(ViewContext.class));
  67 +// replay(event);
  68 +// bootstrap.loadContexts(event);
  69 +// verifyAll();
  70 +// }
  71 +//
  72 +//}
impl/extension/se/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/SeBootstrap.java
@@ -36,19 +36,47 @@ @@ -36,19 +36,47 @@
36 */ 36 */
37 package br.gov.frameworkdemoiselle.internal.bootstrap; 37 package br.gov.frameworkdemoiselle.internal.bootstrap;
38 38
  39 +import java.util.ArrayList;
  40 +import java.util.List;
  41 +
  42 +import javax.enterprise.context.ConversationScoped;
39 import javax.enterprise.context.RequestScoped; 43 import javax.enterprise.context.RequestScoped;
40 import javax.enterprise.context.SessionScoped; 44 import javax.enterprise.context.SessionScoped;
41 import javax.enterprise.event.Observes; 45 import javax.enterprise.event.Observes;
42 import javax.enterprise.inject.spi.AfterBeanDiscovery; 46 import javax.enterprise.inject.spi.AfterBeanDiscovery;
  47 +import javax.enterprise.inject.spi.AfterDeploymentValidation;
  48 +import javax.enterprise.inject.spi.Extension;
43 49
44 import br.gov.frameworkdemoiselle.annotation.ViewScoped; 50 import br.gov.frameworkdemoiselle.annotation.ViewScoped;
  51 +import br.gov.frameworkdemoiselle.internal.context.Contexts;
  52 +import br.gov.frameworkdemoiselle.internal.context.CustomContext;
45 import br.gov.frameworkdemoiselle.internal.context.ThreadLocalContext; 53 import br.gov.frameworkdemoiselle.internal.context.ThreadLocalContext;
  54 +import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess;
  55 +
  56 +public class SeBootstrap implements Extension {
  57 +
  58 + private List<CustomContext> tempContexts = new ArrayList<CustomContext>();
  59 +
  60 + private AfterBeanDiscovery afterBeanDiscoveryEvent;
46 61
47 -public class SeBootstrap extends AbstractBootstrap { 62 + public void storeContexts(@Observes final AfterBeanDiscovery event) {
  63 + tempContexts.add(new ThreadLocalContext(ViewScoped.class));
  64 + tempContexts.add(new ThreadLocalContext(SessionScoped.class));
  65 + tempContexts.add(new ThreadLocalContext(ConversationScoped.class));
  66 + tempContexts.add(new ThreadLocalContext(RequestScoped.class));
  67 +
  68 + afterBeanDiscoveryEvent = event;
  69 + }
  70 +
  71 + public void addContexts(@Observes final AfterDeploymentValidation event) {
  72 + for (CustomContext tempContext : tempContexts) {
  73 + Contexts.add(tempContext, afterBeanDiscoveryEvent);
  74 + }
  75 + }
48 76
49 - public void loadContext(@Observes final AfterBeanDiscovery event) {  
50 - addContext(new ThreadLocalContext(RequestScoped.class), event);  
51 - addContext(new ThreadLocalContext(SessionScoped.class), event);  
52 - addContext(new ThreadLocalContext(ViewScoped.class), event); 77 + public void removeContexts(@Observes AfterShutdownProccess event) {
  78 + for (CustomContext tempContext : tempContexts) {
  79 + Contexts.remove(tempContext);
  80 + }
53 } 81 }
54 -}  
55 \ No newline at end of file 82 \ No newline at end of file
  83 +}