Commit 5fa39fa1a2671e636efdff3504aa28c54f239d9a
1 parent
66a1a808
Exists in
master
Refatoração do sistema de escopos personalizados.
Showing
37 changed files
with
785 additions
and
712 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/context/CustomContext.java
0 → 100644
@@ -0,0 +1,27 @@ | @@ -0,0 +1,27 @@ | ||
1 | +package br.gov.frameworkdemoiselle.context; | ||
2 | + | ||
3 | +import javax.enterprise.context.spi.Context; | ||
4 | + | ||
5 | +/** | ||
6 | + * | ||
7 | + * Base interface for contexts managed by the framework. | ||
8 | + * | ||
9 | + * @author serpro | ||
10 | + * | ||
11 | + */ | ||
12 | +public interface CustomContext extends Context { | ||
13 | + | ||
14 | + /** | ||
15 | + * Activates a custom context | ||
16 | + * | ||
17 | + * @return <code>true</code> if context was activated, <code>false</code> if there was already another active | ||
18 | + * context for the same scope and the activation of this scope failed. | ||
19 | + */ | ||
20 | + boolean activate(); | ||
21 | + | ||
22 | + /** | ||
23 | + * Deactivates this context, it will clear all beans stored on this context. | ||
24 | + */ | ||
25 | + void deactivate(); | ||
26 | + | ||
27 | +} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/context/RequestContext.java
0 → 100644
impl/core/src/main/java/br/gov/frameworkdemoiselle/context/SessionContext.java
0 → 100644
impl/core/src/main/java/br/gov/frameworkdemoiselle/context/StaticContext.java
0 → 100644
impl/core/src/main/java/br/gov/frameworkdemoiselle/context/ViewContext.java
0 → 100644
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AbstractLifecycleBootstrap.java
@@ -42,11 +42,7 @@ import java.util.Collections; | @@ -42,11 +42,7 @@ 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 | 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; | 45 | import javax.enterprise.event.Observes; |
49 | -import javax.enterprise.inject.spi.AfterBeanDiscovery; | ||
50 | import javax.enterprise.inject.spi.AnnotatedMethod; | 46 | import javax.enterprise.inject.spi.AnnotatedMethod; |
51 | import javax.enterprise.inject.spi.AnnotatedType; | 47 | import javax.enterprise.inject.spi.AnnotatedType; |
52 | import javax.enterprise.inject.spi.Extension; | 48 | import javax.enterprise.inject.spi.Extension; |
@@ -55,9 +51,9 @@ import javax.enterprise.inject.spi.ProcessAnnotatedType; | @@ -55,9 +51,9 @@ import javax.enterprise.inject.spi.ProcessAnnotatedType; | ||
55 | import org.slf4j.Logger; | 51 | import org.slf4j.Logger; |
56 | 52 | ||
57 | import br.gov.frameworkdemoiselle.DemoiselleException; | 53 | import br.gov.frameworkdemoiselle.DemoiselleException; |
58 | -import br.gov.frameworkdemoiselle.annotation.ViewScoped; | ||
59 | -import br.gov.frameworkdemoiselle.internal.context.ContextManager; | ||
60 | -import br.gov.frameworkdemoiselle.internal.context.ThreadLocalContext; | 54 | +import br.gov.frameworkdemoiselle.internal.context.RequestContextImpl; |
55 | +import br.gov.frameworkdemoiselle.internal.context.SessionContextImpl; | ||
56 | +import br.gov.frameworkdemoiselle.internal.context.ThreadLocalViewContextImpl; | ||
61 | import br.gov.frameworkdemoiselle.internal.implementation.AnnotatedMethodProcessor; | 57 | import br.gov.frameworkdemoiselle.internal.implementation.AnnotatedMethodProcessor; |
62 | import br.gov.frameworkdemoiselle.util.Beans; | 58 | import br.gov.frameworkdemoiselle.util.Beans; |
63 | import br.gov.frameworkdemoiselle.util.NameQualifier; | 59 | import br.gov.frameworkdemoiselle.util.NameQualifier; |
@@ -109,7 +105,7 @@ public abstract class AbstractLifecycleBootstrap<A extends Annotation> implement | @@ -109,7 +105,7 @@ public abstract class AbstractLifecycleBootstrap<A extends Annotation> implement | ||
109 | } | 105 | } |
110 | } | 106 | } |
111 | 107 | ||
112 | - public void loadTempContexts(@Observes final AfterBeanDiscovery event) { | 108 | + /*public void loadTempContexts(@Observes final AfterBeanDiscovery event) { |
113 | // Caso este bootstrap rode antes do CoreBootstrap. Não há problemas em chamar este método várias vezes, ele | 109 | // Caso este bootstrap rode antes do CoreBootstrap. Não há problemas em chamar este método várias vezes, ele |
114 | // ignora chamadas adicionais. | 110 | // ignora chamadas adicionais. |
115 | ContextManager.initialize(event); | 111 | ContextManager.initialize(event); |
@@ -119,7 +115,7 @@ public abstract class AbstractLifecycleBootstrap<A extends Annotation> implement | @@ -119,7 +115,7 @@ public abstract class AbstractLifecycleBootstrap<A extends Annotation> implement | ||
119 | ContextManager.add(new ThreadLocalContext(SessionScoped.class), event); | 115 | ContextManager.add(new ThreadLocalContext(SessionScoped.class), event); |
120 | ContextManager.add(new ThreadLocalContext(ConversationScoped.class), event); | 116 | ContextManager.add(new ThreadLocalContext(ConversationScoped.class), event); |
121 | ContextManager.add(new ThreadLocalContext(RequestScoped.class), event); | 117 | ContextManager.add(new ThreadLocalContext(RequestScoped.class), event); |
122 | - } | 118 | + }*/ |
123 | 119 | ||
124 | @SuppressWarnings({ "unchecked", "rawtypes" }) | 120 | @SuppressWarnings({ "unchecked", "rawtypes" }) |
125 | protected synchronized void proccessEvent() { | 121 | protected synchronized void proccessEvent() { |
@@ -127,12 +123,15 @@ public abstract class AbstractLifecycleBootstrap<A extends Annotation> implement | @@ -127,12 +123,15 @@ public abstract class AbstractLifecycleBootstrap<A extends Annotation> implement | ||
127 | 123 | ||
128 | Collections.sort(processors); | 124 | Collections.sort(processors); |
129 | Exception failure = null; | 125 | Exception failure = null; |
126 | + | ||
127 | + RequestContextImpl tempRequestContext = Beans.getReference(RequestContextImpl.class); | ||
128 | + SessionContextImpl tempSessionContext = Beans.getReference(SessionContextImpl.class); | ||
129 | + ThreadLocalViewContextImpl tempViewContext = Beans.getReference(ThreadLocalViewContextImpl.class); | ||
130 | 130 | ||
131 | if (!registered) { | 131 | if (!registered) { |
132 | - ContextManager.activate(ThreadLocalContext.class, ViewScoped.class); | ||
133 | - ContextManager.activate(ThreadLocalContext.class, SessionScoped.class); | ||
134 | - ContextManager.activate(ThreadLocalContext.class, ConversationScoped.class); | ||
135 | - ContextManager.activate(ThreadLocalContext.class, RequestScoped.class); | 132 | + tempRequestContext.activate(); |
133 | + tempSessionContext.activate(); | ||
134 | + tempViewContext.activate(); | ||
136 | 135 | ||
137 | registered = true; | 136 | registered = true; |
138 | } | 137 | } |
@@ -155,10 +154,9 @@ public abstract class AbstractLifecycleBootstrap<A extends Annotation> implement | @@ -155,10 +154,9 @@ public abstract class AbstractLifecycleBootstrap<A extends Annotation> implement | ||
155 | } | 154 | } |
156 | 155 | ||
157 | if (processors.isEmpty()) { | 156 | if (processors.isEmpty()) { |
158 | - ContextManager.deactivate(ThreadLocalContext.class, ViewScoped.class); | ||
159 | - ContextManager.deactivate(ThreadLocalContext.class, SessionScoped.class); | ||
160 | - ContextManager.deactivate(ThreadLocalContext.class, ConversationScoped.class); | ||
161 | - ContextManager.deactivate(ThreadLocalContext.class, RequestScoped.class); | 157 | + tempRequestContext.deactivate(); |
158 | + tempSessionContext.deactivate(); | ||
159 | + tempViewContext.deactivate(); | ||
162 | } | 160 | } |
163 | 161 | ||
164 | if (failure != null) { | 162 | if (failure != null) { |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/CoreBootstrap.java
@@ -39,7 +39,6 @@ package br.gov.frameworkdemoiselle.internal.bootstrap; | @@ -39,7 +39,6 @@ package br.gov.frameworkdemoiselle.internal.bootstrap; | ||
39 | import java.util.Locale; | 39 | import java.util.Locale; |
40 | 40 | ||
41 | import javax.enterprise.event.Observes; | 41 | import javax.enterprise.event.Observes; |
42 | -import javax.enterprise.inject.spi.AfterBeanDiscovery; | ||
43 | import javax.enterprise.inject.spi.AfterDeploymentValidation; | 42 | import javax.enterprise.inject.spi.AfterDeploymentValidation; |
44 | import javax.enterprise.inject.spi.BeanManager; | 43 | import javax.enterprise.inject.spi.BeanManager; |
45 | import javax.enterprise.inject.spi.BeforeBeanDiscovery; | 44 | import javax.enterprise.inject.spi.BeforeBeanDiscovery; |
@@ -48,9 +47,6 @@ import javax.enterprise.inject.spi.Extension; | @@ -48,9 +47,6 @@ import javax.enterprise.inject.spi.Extension; | ||
48 | 47 | ||
49 | import org.slf4j.Logger; | 48 | import org.slf4j.Logger; |
50 | 49 | ||
51 | -import br.gov.frameworkdemoiselle.annotation.StaticScoped; | ||
52 | -import br.gov.frameworkdemoiselle.internal.context.ContextManager; | ||
53 | -import br.gov.frameworkdemoiselle.internal.context.StaticContext; | ||
54 | import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; | 50 | import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; |
55 | import br.gov.frameworkdemoiselle.util.Beans; | 51 | import br.gov.frameworkdemoiselle.util.Beans; |
56 | import br.gov.frameworkdemoiselle.util.ResourceBundle; | 52 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
@@ -60,7 +56,7 @@ public class CoreBootstrap implements Extension { | @@ -60,7 +56,7 @@ public class CoreBootstrap implements Extension { | ||
60 | private Logger logger; | 56 | private Logger logger; |
61 | 57 | ||
62 | private transient ResourceBundle bundle; | 58 | private transient ResourceBundle bundle; |
63 | - | 59 | + |
64 | private Logger getLogger() { | 60 | private Logger getLogger() { |
65 | if (this.logger == null) { | 61 | if (this.logger == null) { |
66 | this.logger = LoggerProducer.create(CoreBootstrap.class); | 62 | this.logger = LoggerProducer.create(CoreBootstrap.class); |
@@ -84,16 +80,13 @@ public class CoreBootstrap implements Extension { | @@ -84,16 +80,13 @@ public class CoreBootstrap implements Extension { | ||
84 | getLogger().info(getBundle().getString("setting-up-bean-manager", Beans.class.getCanonicalName())); | 80 | getLogger().info(getBundle().getString("setting-up-bean-manager", Beans.class.getCanonicalName())); |
85 | } | 81 | } |
86 | 82 | ||
87 | - public void initializeCustomContexts(@Observes final AfterBeanDiscovery event) { | ||
88 | - // StaticContext já é criado e gerenciado por esta chamada | ||
89 | - ContextManager.initialize(event); | ||
90 | - | ||
91 | - ContextManager.activate(StaticContext.class, StaticScoped.class); | ||
92 | - } | 83 | + /*public void initializeCustomContexts(@Observes final AfterBeanDiscovery event) { |
84 | + Beans.getReference(ContextManager2.class); | ||
85 | + }*/ | ||
93 | 86 | ||
94 | - public void terminateCustomContexts(@Observes final BeforeShutdown event) { | 87 | + /*public void terminateCustomContexts(@Observes final BeforeShutdown event) { |
95 | ContextManager.shutdown(); | 88 | ContextManager.shutdown(); |
96 | - } | 89 | + }*/ |
97 | 90 | ||
98 | public void takeOff(@Observes final AfterDeploymentValidation event) { | 91 | public void takeOff(@Observes final AfterDeploymentValidation event) { |
99 | getLogger().info(getBundle().getString("taking-off")); | 92 | getLogger().info(getBundle().getString("taking-off")); |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ManagementBootstrap.java
@@ -8,7 +8,6 @@ import java.util.Locale; | @@ -8,7 +8,6 @@ import java.util.Locale; | ||
8 | import java.util.Set; | 8 | import java.util.Set; |
9 | 9 | ||
10 | import javax.enterprise.event.Observes; | 10 | import javax.enterprise.event.Observes; |
11 | -import javax.enterprise.inject.spi.AfterBeanDiscovery; | ||
12 | import javax.enterprise.inject.spi.AfterDeploymentValidation; | 11 | import javax.enterprise.inject.spi.AfterDeploymentValidation; |
13 | import javax.enterprise.inject.spi.AnnotatedType; | 12 | import javax.enterprise.inject.spi.AnnotatedType; |
14 | import javax.enterprise.inject.spi.Bean; | 13 | import javax.enterprise.inject.spi.Bean; |
@@ -17,8 +16,6 @@ import javax.enterprise.inject.spi.Extension; | @@ -17,8 +16,6 @@ import javax.enterprise.inject.spi.Extension; | ||
17 | import javax.enterprise.inject.spi.ProcessAnnotatedType; | 16 | import javax.enterprise.inject.spi.ProcessAnnotatedType; |
18 | 17 | ||
19 | import br.gov.frameworkdemoiselle.DemoiselleException; | 18 | import br.gov.frameworkdemoiselle.DemoiselleException; |
20 | -import br.gov.frameworkdemoiselle.internal.context.ContextManager; | ||
21 | -import br.gov.frameworkdemoiselle.internal.context.ManagedContext; | ||
22 | import br.gov.frameworkdemoiselle.internal.management.ManagedType; | 19 | import br.gov.frameworkdemoiselle.internal.management.ManagedType; |
23 | import br.gov.frameworkdemoiselle.internal.management.Management; | 20 | import br.gov.frameworkdemoiselle.internal.management.Management; |
24 | import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess; | 21 | import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess; |
@@ -40,10 +37,10 @@ public class ManagementBootstrap implements Extension { | @@ -40,10 +37,10 @@ public class ManagementBootstrap implements Extension { | ||
40 | } | 37 | } |
41 | } | 38 | } |
42 | 39 | ||
43 | - public void activateContexts(@Observes final AfterBeanDiscovery event) { | 40 | + /*public void activateContexts(@Observes final AfterBeanDiscovery event) { |
44 | ContextManager.initialize(event); | 41 | ContextManager.initialize(event); |
45 | ContextManager.add(new ManagedContext(), event); | 42 | ContextManager.add(new ManagedContext(), event); |
46 | - } | 43 | + }*/ |
47 | 44 | ||
48 | @SuppressWarnings("unchecked") | 45 | @SuppressWarnings("unchecked") |
49 | public void registerAvailableManagedTypes(@Observes final AfterDeploymentValidation event, BeanManager beanManager) { | 46 | public void registerAvailableManagedTypes(@Observes final AfterDeploymentValidation event, BeanManager beanManager) { |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/AbstractCustomContext.java
@@ -42,9 +42,18 @@ import java.util.HashMap; | @@ -42,9 +42,18 @@ import java.util.HashMap; | ||
42 | import java.util.Map; | 42 | import java.util.Map; |
43 | 43 | ||
44 | import javax.enterprise.context.ContextNotActiveException; | 44 | import javax.enterprise.context.ContextNotActiveException; |
45 | +import javax.enterprise.context.spi.Context; | ||
45 | import javax.enterprise.context.spi.Contextual; | 46 | import javax.enterprise.context.spi.Contextual; |
46 | import javax.enterprise.context.spi.CreationalContext; | 47 | import javax.enterprise.context.spi.CreationalContext; |
47 | import javax.enterprise.inject.spi.Bean; | 48 | import javax.enterprise.inject.spi.Bean; |
49 | +import javax.enterprise.inject.spi.BeanManager; | ||
50 | + | ||
51 | +import org.slf4j.Logger; | ||
52 | + | ||
53 | +import br.gov.frameworkdemoiselle.context.CustomContext; | ||
54 | +import br.gov.frameworkdemoiselle.util.Beans; | ||
55 | +import br.gov.frameworkdemoiselle.util.NameQualifier; | ||
56 | +import br.gov.frameworkdemoiselle.util.ResourceBundle; | ||
48 | 57 | ||
49 | public abstract class AbstractCustomContext implements CustomContext { | 58 | public abstract class AbstractCustomContext implements CustomContext { |
50 | 59 | ||
@@ -52,7 +61,7 @@ public abstract class AbstractCustomContext implements CustomContext { | @@ -52,7 +61,7 @@ public abstract class AbstractCustomContext implements CustomContext { | ||
52 | 61 | ||
53 | private final Class<? extends Annotation> scope; | 62 | private final Class<? extends Annotation> scope; |
54 | 63 | ||
55 | - public AbstractCustomContext(final Class<? extends Annotation> scope) { | 64 | + AbstractCustomContext(final Class<? extends Annotation> scope) { |
56 | this.scope = scope; | 65 | this.scope = scope; |
57 | this.active = false; | 66 | this.active = false; |
58 | } | 67 | } |
@@ -97,14 +106,47 @@ public abstract class AbstractCustomContext implements CustomContext { | @@ -97,14 +106,47 @@ public abstract class AbstractCustomContext implements CustomContext { | ||
97 | return this.active; | 106 | return this.active; |
98 | } | 107 | } |
99 | 108 | ||
100 | - public void setActive(boolean active) { | ||
101 | - if (!active && this.active) { | ||
102 | - // Limpando contexto | 109 | + @Override |
110 | + public boolean activate() { | ||
111 | + if (!this.active){ | ||
112 | + Logger logger = getLogger(); | ||
113 | + ResourceBundle bundle = getBundle(); | ||
114 | + | ||
115 | + BeanManager beanManager = Beans.getBeanManager(); | ||
116 | + if (beanManager!=null){ | ||
117 | + try{ | ||
118 | + Context ctx = beanManager.getContext(this.getScope()); | ||
119 | + if (ctx!=null){ | ||
120 | + logger.debug( bundle.getString("custom-context-already-activated" , this.getClass().getCanonicalName() , this.getScope().getSimpleName() , ctx.getClass().getCanonicalName() ) ); | ||
121 | + } | ||
122 | + } | ||
123 | + catch(ContextNotActiveException ce){ | ||
124 | + this.active = true; | ||
125 | + logger.debug( bundle.getString("custom-context-was-activated" , this.getClass().getCanonicalName() , this.getScope().getSimpleName() ) ); | ||
126 | + } | ||
127 | + } | ||
128 | + else{ | ||
129 | + this.active = true; | ||
130 | + logger.debug( bundle.getString("custom-context-was-activated" , this.getClass().getCanonicalName() , this.getScope().getSimpleName() ) ); | ||
131 | + } | ||
132 | + } | ||
133 | + | ||
134 | + return this.active; | ||
135 | + } | ||
136 | + | ||
137 | + @Override | ||
138 | + public void deactivate(){ | ||
139 | + if (this.active){ | ||
103 | if (isStoreInitialized()){ | 140 | if (isStoreInitialized()){ |
104 | getStore().clear(); | 141 | getStore().clear(); |
105 | } | 142 | } |
143 | + | ||
144 | + this.active = false; | ||
145 | + | ||
146 | + Logger logger = getLogger(); | ||
147 | + ResourceBundle bundle = getBundle(); | ||
148 | + logger.debug( bundle.getString("custom-context-was-deactivated" , this.getClass().getCanonicalName() , this.getScope().getSimpleName() ) ); | ||
106 | } | 149 | } |
107 | - this.active = active; | ||
108 | } | 150 | } |
109 | 151 | ||
110 | @Override | 152 | @Override |
@@ -115,6 +157,14 @@ public abstract class AbstractCustomContext implements CustomContext { | @@ -115,6 +157,14 @@ public abstract class AbstractCustomContext implements CustomContext { | ||
115 | protected static Store createStore() { | 157 | protected static Store createStore() { |
116 | return new Store(); | 158 | return new Store(); |
117 | } | 159 | } |
160 | + | ||
161 | + private ResourceBundle getBundle(){ | ||
162 | + return Beans.getReference(ResourceBundle.class , new NameQualifier("demoiselle-core-bundle")); | ||
163 | + } | ||
164 | + | ||
165 | + private Logger getLogger(){ | ||
166 | + return Beans.getReference(Logger.class); | ||
167 | + } | ||
118 | 168 | ||
119 | static class Store { | 169 | static class Store { |
120 | 170 |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/AbstractThreadLocalContext.java
0 → 100644
@@ -0,0 +1,81 @@ | @@ -0,0 +1,81 @@ | ||
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 | +/* | ||
38 | + * Demoiselle Framework Copyright (c) 2010 Serpro and other contributors as indicated by the @author tag. See the | ||
39 | + * copyright.txt in the distribution for a full listing of contributors. Demoiselle Framework is an open source Java EE | ||
40 | + * library designed to accelerate the development of transactional database Web applications. Demoiselle Framework is | ||
41 | + * released under the terms of the LGPL license 3 http://www.gnu.org/licenses/lgpl.html LGPL License 3 This file is part | ||
42 | + * of Demoiselle Framework. Demoiselle Framework is free software: you can redistribute it and/or modify it under the | ||
43 | + * terms of the GNU Lesser General Public License 3 as published by the Free Software Foundation. Demoiselle Framework | ||
44 | + * is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
45 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You | ||
46 | + * should have received a copy of the GNU Lesser General Public License along with Demoiselle Framework. If not, see | ||
47 | + * <http://www.gnu.org/licenses/>. | ||
48 | + */ | ||
49 | +package br.gov.frameworkdemoiselle.internal.context; | ||
50 | + | ||
51 | +import java.lang.annotation.Annotation; | ||
52 | + | ||
53 | +/** | ||
54 | + * This context keeps a separated store for beans for each running thread. It is intended | ||
55 | + * to keep beans of short lived scopes like the Request scope, on environments that lack | ||
56 | + * those scopes by default. | ||
57 | + * | ||
58 | + * @author serpro | ||
59 | + */ | ||
60 | +public abstract class AbstractThreadLocalContext extends AbstractCustomContext { | ||
61 | + | ||
62 | + private final ThreadLocal<Store> threadLocal = new ThreadLocal<Store>(); | ||
63 | + | ||
64 | + AbstractThreadLocalContext(final Class<? extends Annotation> scope) { | ||
65 | + super(scope); | ||
66 | + } | ||
67 | + | ||
68 | + @Override | ||
69 | + protected boolean isStoreInitialized() { | ||
70 | + return threadLocal.get()!=null; | ||
71 | + } | ||
72 | + | ||
73 | + @Override | ||
74 | + protected Store getStore() { | ||
75 | + if (this.threadLocal.get() == null) { | ||
76 | + this.threadLocal.set(createStore()); | ||
77 | + } | ||
78 | + | ||
79 | + return this.threadLocal.get(); | ||
80 | + } | ||
81 | +} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/ContextManager.java
@@ -1,324 +0,0 @@ | @@ -1,324 +0,0 @@ | ||
1 | -package br.gov.frameworkdemoiselle.internal.context; | ||
2 | - | ||
3 | -import java.lang.annotation.Annotation; | ||
4 | -import java.util.ArrayList; | ||
5 | -import java.util.Collections; | ||
6 | -import java.util.HashMap; | ||
7 | -import java.util.List; | ||
8 | -import java.util.Locale; | ||
9 | -import java.util.Map; | ||
10 | - | ||
11 | -import javax.enterprise.context.ContextNotActiveException; | ||
12 | -import javax.enterprise.context.spi.Context; | ||
13 | -import javax.enterprise.inject.spi.AfterBeanDiscovery; | ||
14 | -import javax.enterprise.inject.spi.BeanManager; | ||
15 | - | ||
16 | -import org.slf4j.Logger; | ||
17 | - | ||
18 | -import br.gov.frameworkdemoiselle.DemoiselleException; | ||
19 | -import br.gov.frameworkdemoiselle.annotation.StaticScoped; | ||
20 | -import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; | ||
21 | -import br.gov.frameworkdemoiselle.util.Beans; | ||
22 | -import br.gov.frameworkdemoiselle.util.ResourceBundle; | ||
23 | - | ||
24 | -/** | ||
25 | - * <p> | ||
26 | - * Manage custom contexts relevant to Demoiselle operations. | ||
27 | - * </p> | ||
28 | - * <p> | ||
29 | - * When starting, the ContextManager must be initialized by calling {@link #initialize(AfterBeanDiscovery event)} inside | ||
30 | - * any methods observing the {@link AfterBeanDiscovery} event. Upon initialization a {@link StaticContext} will be | ||
31 | - * created to handle {@link StaticScoped} beans (but not activated, you must call | ||
32 | - * {@link #activate(Class customContextClass, Class scope)} to activate this context). | ||
33 | - * </p> | ||
34 | - * <p> | ||
35 | - * If an extension wants to manage another custom context, it must first call | ||
36 | - * {@link #add(CustomContext context, AfterBeanDiscovery event)} to add it's context to the list of managed contexts and | ||
37 | - * then call {@link #activate(Class customContextClass, Class scope)} whenever it wants to activate this added context | ||
38 | - * (contexts added through the {@link #add(CustomContext context, AfterBeanDiscovery event)} method are also not | ||
39 | - * activated upon adding). | ||
40 | - * </p> | ||
41 | - * | ||
42 | - * @author serpro | ||
43 | - */ | ||
44 | -public final class ContextManager { | ||
45 | - | ||
46 | - private static final Map<ClassLoader, List<CustomContextCounter>> contextsCache = Collections | ||
47 | - .synchronizedMap(new HashMap<ClassLoader, List<CustomContextCounter>>()); | ||
48 | - | ||
49 | - private static final Map<ClassLoader, Boolean> initializedCache = Collections | ||
50 | - .synchronizedMap(new HashMap<ClassLoader, Boolean>()); | ||
51 | - | ||
52 | - private ContextManager() { | ||
53 | - } | ||
54 | - | ||
55 | - private synchronized static List<CustomContextCounter> getContexts() { | ||
56 | - List<CustomContextCounter> contexts = contextsCache.get(getCurrentClassLoader()); | ||
57 | - | ||
58 | - if (contexts == null) { | ||
59 | - contexts = Collections.synchronizedList(new ArrayList<CustomContextCounter>()); | ||
60 | - contextsCache.put(getCurrentClassLoader(), contexts); | ||
61 | - } | ||
62 | - | ||
63 | - return contexts; | ||
64 | - } | ||
65 | - | ||
66 | - private synchronized static boolean isInitialized() { | ||
67 | - Boolean initialized = initializedCache.get(getCurrentClassLoader()); | ||
68 | - | ||
69 | - if (initialized == null) { | ||
70 | - initialized = false; | ||
71 | - initializedCache.put(getCurrentClassLoader(), initialized); | ||
72 | - } | ||
73 | - | ||
74 | - return initialized; | ||
75 | - } | ||
76 | - | ||
77 | - private static void setInitialized(boolean initialized) { | ||
78 | - initializedCache.put(getCurrentClassLoader(), initialized); | ||
79 | - } | ||
80 | - | ||
81 | - private static ClassLoader getCurrentClassLoader() { | ||
82 | - return Thread.currentThread().getContextClassLoader(); | ||
83 | - } | ||
84 | - | ||
85 | - /** | ||
86 | - * <p> | ||
87 | - * Initializes this manager and adds the {@link StaticContext} context to the list of managed contexts. Other | ||
88 | - * contexts must be added before they can be activated. | ||
89 | - * </p> | ||
90 | - * <p> | ||
91 | - * It's OK to call this method multiple times, it will be initialized only once. | ||
92 | - * </p> | ||
93 | - * | ||
94 | - * @param event | ||
95 | - * The CDI event indicating all beans have been discovered. | ||
96 | - */ | ||
97 | - public static void initialize(AfterBeanDiscovery event) { | ||
98 | - if (isInitialized()) { | ||
99 | - return; | ||
100 | - } | ||
101 | - | ||
102 | - add(new StaticContext(), event); | ||
103 | - setInitialized(true); | ||
104 | - } | ||
105 | - | ||
106 | - /** | ||
107 | - * <p> | ||
108 | - * Adds a context to the list of managed contexts. | ||
109 | - * </p> | ||
110 | - * <p> | ||
111 | - * A context added through this method will be deactivated before management can start. Only after calling | ||
112 | - * {@link #activate(Class customContextClass, Class scope)} the context will be activated. | ||
113 | - * </p> | ||
114 | - * <p> | ||
115 | - * Trying to add a context already managed will result in this method call being ignored. | ||
116 | - * </p> | ||
117 | - * | ||
118 | - * @param context | ||
119 | - * The context to be added | ||
120 | - * @param event | ||
121 | - * The CDI event indicating all beans have been discovered. | ||
122 | - */ | ||
123 | - public static void add(CustomContext context, AfterBeanDiscovery event) { | ||
124 | - for (CustomContextCounter contextCounter : getContexts()) { | ||
125 | - if (contextCounter.isSame(context.getClass(), context.getScope())) { | ||
126 | - | ||
127 | - ContextManager.getLogger().trace( | ||
128 | - ContextManager.getBundle().getString("bootstrap-context-already-managed", | ||
129 | - context.getClass().getCanonicalName(), context.getScope().getCanonicalName())); | ||
130 | - | ||
131 | - return; | ||
132 | - } | ||
133 | - } | ||
134 | - | ||
135 | - ContextManager.getLogger().trace( | ||
136 | - ContextManager.getBundle().getString("bootstrap-context-added", context.getClass().getCanonicalName(), | ||
137 | - context.getScope().getCanonicalName())); | ||
138 | - | ||
139 | - context.setActive(false); | ||
140 | - event.addContext(context); | ||
141 | - getContexts().add(new CustomContextCounter(context)); | ||
142 | - } | ||
143 | - | ||
144 | - /** | ||
145 | - * <p> | ||
146 | - * Activates a managed context. | ||
147 | - * </p> | ||
148 | - * <p> | ||
149 | - * To be activated, a context must fulfill the following requisites: | ||
150 | - * <ul> | ||
151 | - * <li>Must be managed by this class (be of type {@link StaticScoped} or be added with | ||
152 | - * {@link #add(CustomContext context, AfterBeanDiscovery event)})</li> | ||
153 | - * <li>Must be of a scope not already attached to another active context</li> | ||
154 | - * </ul> | ||
155 | - * </p> | ||
156 | - * | ||
157 | - * @param customContextClass | ||
158 | - * Type of context to activate | ||
159 | - * @param scope | ||
160 | - * The scope to activate this context for | ||
161 | - * @return <code>true</code> if there is a managed context of the provided type and scope and no other context is | ||
162 | - * active for the provided scope, <code>false</code> if there is a managed context of the provided type and | ||
163 | - * scope but another context is active for the provided scope. | ||
164 | - * @throws DemoiselleException | ||
165 | - * if there is no managed context of the provided type and scope. | ||
166 | - */ | ||
167 | - public static synchronized void activate(Class<? extends CustomContext> customContextClass, | ||
168 | - Class<? extends Annotation> scope) { | ||
169 | - if (!isInitialized()) { | ||
170 | - throw new DemoiselleException(getBundle().getString("custom-context-manager-not-initialized")); | ||
171 | - } | ||
172 | - | ||
173 | - for (CustomContextCounter context : getContexts()) { | ||
174 | - if (context.isSame(customContextClass, scope)) { | ||
175 | - context.activate(); | ||
176 | - return; | ||
177 | - } | ||
178 | - } | ||
179 | - | ||
180 | - throw new DemoiselleException(getBundle().getString("custom-context-not-found", | ||
181 | - customContextClass.getCanonicalName(), scope.getSimpleName())); | ||
182 | - } | ||
183 | - | ||
184 | - /** | ||
185 | - * <p> | ||
186 | - * Deactivates a managed context. | ||
187 | - * </p> | ||
188 | - * <p> | ||
189 | - * To be deactivated, a context must fulfill the following requisites: | ||
190 | - * <ul> | ||
191 | - * <li>Must be managed by this class (be of type {@link StaticScoped} or be added with | ||
192 | - * {@link #add(CustomContext context, AfterBeanDiscovery event)})</li> | ||
193 | - * <li>Must have been activated by a previous call to {@link #activate(Class customContextClass, Class scope)}</li> | ||
194 | - * <li>This previous call must have returned <code>true</code>. | ||
195 | - * </ul> | ||
196 | - * </p> | ||
197 | - * | ||
198 | - * @param customContextClass | ||
199 | - * Type of context to deactivate | ||
200 | - * @param scope | ||
201 | - * The scope the context controled when it was active | ||
202 | - * @return <code>true</code> if there was an active context of this type and scope and it was activated by a | ||
203 | - * previous call to {@link #activate(Class customContextClass, Class scope)} | ||
204 | - * @throws DemoiselleException | ||
205 | - * if there is no managed context of the provided type and scope. | ||
206 | - */ | ||
207 | - public static synchronized void deactivate(Class<? extends CustomContext> customContextClass, | ||
208 | - Class<? extends Annotation> scope) { | ||
209 | - if (!isInitialized()) { | ||
210 | - throw new DemoiselleException(getBundle().getString("custom-context-manager-not-initialized")); | ||
211 | - } | ||
212 | - | ||
213 | - for (CustomContextCounter context : getContexts()) { | ||
214 | - if (context.isSame(customContextClass, scope)) { | ||
215 | - context.deactivate(); | ||
216 | - return; | ||
217 | - } | ||
218 | - } | ||
219 | - | ||
220 | - throw new DemoiselleException(getBundle().getString("custom-context-not-found", | ||
221 | - customContextClass.getCanonicalName(), scope.getSimpleName())); | ||
222 | - } | ||
223 | - | ||
224 | - /** | ||
225 | - * <p> | ||
226 | - * This method should be called when the application is shutting down. | ||
227 | - * </p> | ||
228 | - */ | ||
229 | - public static synchronized void shutdown() { | ||
230 | - for (CustomContextCounter context : getContexts()) { | ||
231 | - context.shutdown(); | ||
232 | - } | ||
233 | - | ||
234 | - getContexts().clear(); | ||
235 | - setInitialized(false); | ||
236 | - } | ||
237 | - | ||
238 | - static Logger getLogger() { | ||
239 | - return LoggerProducer.create(ContextManager.class); | ||
240 | - } | ||
241 | - | ||
242 | - static ResourceBundle getBundle() { | ||
243 | - return new ResourceBundle("demoiselle-core-bundle", Locale.getDefault()); | ||
244 | - } | ||
245 | -} | ||
246 | - | ||
247 | -/** | ||
248 | - * Class that counts how many attemps to activate and deactivate this context received, avoiding cases where one client | ||
249 | - * activates given context and another one deactivates it, leaving the first client with no active context before | ||
250 | - * completion. | ||
251 | - * | ||
252 | - * @author serpro | ||
253 | - */ | ||
254 | -class CustomContextCounter { | ||
255 | - | ||
256 | - private CustomContext context; | ||
257 | - | ||
258 | - private int activationCounter = 0; | ||
259 | - | ||
260 | - public CustomContextCounter(CustomContext customContext) { | ||
261 | - this.context = customContext; | ||
262 | - } | ||
263 | - | ||
264 | - public boolean isSame(Class<? extends CustomContext> customContextClass, Class<? extends Annotation> scope) { | ||
265 | - if (context.getClass().getCanonicalName().equals(customContextClass.getCanonicalName()) | ||
266 | - && context.getScope().equals(scope)) { | ||
267 | - return true; | ||
268 | - } | ||
269 | - | ||
270 | - return false; | ||
271 | - } | ||
272 | - | ||
273 | - public CustomContext getInternalContext() { | ||
274 | - return this.context; | ||
275 | - } | ||
276 | - | ||
277 | - public void setInternalContext(CustomContext context) { | ||
278 | - this.context = context; | ||
279 | - } | ||
280 | - | ||
281 | - public synchronized void activate() { | ||
282 | - try { | ||
283 | - BeanManager beanManager = Beans.getReference(BeanManager.class); | ||
284 | - Context c = beanManager.getContext(context.getScope()); | ||
285 | - | ||
286 | - if (c == context) { | ||
287 | - activationCounter++; | ||
288 | - } else { | ||
289 | - ContextManager.getLogger().trace( | ||
290 | - ContextManager.getBundle().getString("custom-context-already-activated", | ||
291 | - context.getClass().getCanonicalName(), c.getScope().getCanonicalName(), | ||
292 | - c.getClass().getCanonicalName())); | ||
293 | - } | ||
294 | - } catch (ContextNotActiveException ce) { | ||
295 | - context.setActive(true); | ||
296 | - activationCounter++; | ||
297 | - ContextManager.getLogger().trace( | ||
298 | - ContextManager.getBundle().getString("custom-context-was-activated", | ||
299 | - context.getClass().getCanonicalName(), context.getScope().getCanonicalName())); | ||
300 | - } | ||
301 | - } | ||
302 | - | ||
303 | - public synchronized void deactivate() { | ||
304 | - try { | ||
305 | - Context c = Beans.getBeanManager().getContext(context.getScope()); | ||
306 | - if (c == context) { | ||
307 | - activationCounter--; | ||
308 | - if (activationCounter == 0) { | ||
309 | - context.setActive(false); | ||
310 | - ContextManager.getLogger().trace( | ||
311 | - ContextManager.getBundle().getString("custom-context-was-deactivated", | ||
312 | - context.getClass().getCanonicalName(), context.getScope().getCanonicalName())); | ||
313 | - } | ||
314 | - } | ||
315 | - } catch (ContextNotActiveException ce) { | ||
316 | - } | ||
317 | - } | ||
318 | - | ||
319 | - public synchronized void shutdown() { | ||
320 | - context.setActive(false); | ||
321 | - context = null; | ||
322 | - activationCounter = 0; | ||
323 | - } | ||
324 | -} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/ContextManager2.java
0 → 100644
@@ -0,0 +1,109 @@ | @@ -0,0 +1,109 @@ | ||
1 | +package br.gov.frameworkdemoiselle.internal.context; | ||
2 | + | ||
3 | +import java.util.ArrayList; | ||
4 | +import java.util.List; | ||
5 | + | ||
6 | +import javax.annotation.PostConstruct; | ||
7 | +import javax.annotation.PreDestroy; | ||
8 | +import javax.enterprise.context.ApplicationScoped; | ||
9 | +import javax.enterprise.inject.Produces; | ||
10 | +import javax.enterprise.inject.spi.InjectionPoint; | ||
11 | + | ||
12 | +import org.slf4j.Logger; | ||
13 | + | ||
14 | +import br.gov.frameworkdemoiselle.context.CustomContext; | ||
15 | +import br.gov.frameworkdemoiselle.internal.implementation.StrategySelector; | ||
16 | +import br.gov.frameworkdemoiselle.util.Beans; | ||
17 | +import br.gov.frameworkdemoiselle.util.NameQualifier; | ||
18 | +import br.gov.frameworkdemoiselle.util.ResourceBundle; | ||
19 | + | ||
20 | +@ApplicationScoped | ||
21 | +public class ContextManager2 { | ||
22 | + | ||
23 | + private List<CustomContext> contexts; | ||
24 | + | ||
25 | + @PostConstruct | ||
26 | + private void initialize(){ | ||
27 | + if (contexts==null || contexts.isEmpty()){ | ||
28 | + Logger logger = getLogger(); | ||
29 | + ResourceBundle bundle = getBundle(); | ||
30 | + | ||
31 | + CustomContext ctx; | ||
32 | + | ||
33 | + contexts = new ArrayList<CustomContext>(); | ||
34 | + | ||
35 | + ctx = new RequestContextImpl(); | ||
36 | + contexts.add(ctx); | ||
37 | + logger.debug( bundle.getString("bootstrap-context-added", RequestContextImpl.class.getCanonicalName() , ctx.getScope().getSimpleName() ) ); | ||
38 | + | ||
39 | + ctx = new SessionContextImpl(); | ||
40 | + contexts.add(ctx); | ||
41 | + logger.debug( bundle.getString("bootstrap-context-added", SessionContextImpl.class.getCanonicalName() , ctx.getScope().getSimpleName() ) ); | ||
42 | + | ||
43 | + ctx = new StaticContextImpl(); | ||
44 | + contexts.add(ctx); | ||
45 | + logger.debug( bundle.getString("bootstrap-context-added", StaticContextImpl.class.getCanonicalName() , ctx.getScope().getSimpleName() ) ); | ||
46 | + | ||
47 | + ctx = new ThreadLocalViewContextImpl(); | ||
48 | + contexts.add(ctx); | ||
49 | + logger.debug( bundle.getString("bootstrap-context-added", ThreadLocalViewContextImpl.class.getCanonicalName() , ctx.getScope().getSimpleName() ) ); | ||
50 | + } | ||
51 | + } | ||
52 | + | ||
53 | + @PreDestroy | ||
54 | + private void closeContexts(){ | ||
55 | + for (CustomContext context : contexts){ | ||
56 | + context.deactivate(); | ||
57 | + } | ||
58 | + | ||
59 | + contexts.clear(); | ||
60 | + } | ||
61 | + | ||
62 | + public void addCustomContext(CustomContext context){ | ||
63 | + Logger logger = getLogger(); | ||
64 | + ResourceBundle bundle = getBundle(); | ||
65 | + | ||
66 | + if (!contexts.contains(context)){ | ||
67 | + contexts.add(context); | ||
68 | + logger.debug( bundle.getString("bootstrap-context-added", context.getClass().getCanonicalName() , context.getScope().getSimpleName() ) ); | ||
69 | + } | ||
70 | + else{ | ||
71 | + logger.debug( bundle.getString("bootstrap-context-already-managed", context.getClass().getCanonicalName() , context.getScope().getSimpleName() ) ); | ||
72 | + } | ||
73 | + } | ||
74 | + | ||
75 | + @Produces | ||
76 | + public CustomContext getContext(InjectionPoint ip){ | ||
77 | + CustomContext producedContext = null; | ||
78 | + | ||
79 | + if (ip!=null){ | ||
80 | + Class<?> beanClass = ip.getBean().getBeanClass(); | ||
81 | + ArrayList<CustomContext> selectableContexts = new ArrayList<CustomContext>(); | ||
82 | + | ||
83 | + for (CustomContext context : contexts){ | ||
84 | + if ( beanClass.isAssignableFrom( context.getClass() ) ){ | ||
85 | + if (context.isActive()){ | ||
86 | + producedContext = context; | ||
87 | + break; | ||
88 | + } | ||
89 | + else{ | ||
90 | + selectableContexts.add(context); | ||
91 | + } | ||
92 | + } | ||
93 | + } | ||
94 | + | ||
95 | + producedContext = StrategySelector.selectInstance(CustomContext.class, selectableContexts); | ||
96 | + } | ||
97 | + | ||
98 | + return producedContext; | ||
99 | + } | ||
100 | + | ||
101 | + private ResourceBundle getBundle(){ | ||
102 | + return Beans.getReference(ResourceBundle.class , new NameQualifier("demoiselle-core-bundle")); | ||
103 | + } | ||
104 | + | ||
105 | + private Logger getLogger(){ | ||
106 | + return Beans.getReference(Logger.class); | ||
107 | + } | ||
108 | + | ||
109 | +} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/CustomContext.java
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/ManagedContext.java
@@ -1,22 +0,0 @@ | @@ -1,22 +0,0 @@ | ||
1 | -package br.gov.frameworkdemoiselle.internal.context; | ||
2 | - | ||
3 | -import javax.enterprise.context.RequestScoped; | ||
4 | - | ||
5 | -import br.gov.frameworkdemoiselle.stereotype.ManagementController; | ||
6 | - | ||
7 | -/** | ||
8 | - * Context that stores {@link RequestScoped} beans during client calls to {@link ManagementController} classes. This | ||
9 | - * context is only activated when no other context is active for {@link RequestScoped}. | ||
10 | - * | ||
11 | - * @author serpro | ||
12 | - */ | ||
13 | -public class ManagedContext extends ThreadLocalContext { | ||
14 | - | ||
15 | - /** | ||
16 | - * Constructs a new context. | ||
17 | - */ | ||
18 | - public ManagedContext() { | ||
19 | - super(RequestScoped.class); | ||
20 | - } | ||
21 | - | ||
22 | -} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/RequestContextImpl.java
0 → 100644
@@ -0,0 +1,21 @@ | @@ -0,0 +1,21 @@ | ||
1 | +package br.gov.frameworkdemoiselle.internal.context; | ||
2 | + | ||
3 | +import javax.enterprise.context.RequestScoped; | ||
4 | + | ||
5 | +import br.gov.frameworkdemoiselle.annotation.Priority; | ||
6 | +import br.gov.frameworkdemoiselle.context.RequestContext; | ||
7 | + | ||
8 | +/** | ||
9 | + * Custom request context that stores beans in a thread local store. | ||
10 | + * | ||
11 | + * @author serpro | ||
12 | + * | ||
13 | + */ | ||
14 | +@Priority(Priority.MIN_PRIORITY) | ||
15 | +public class RequestContextImpl extends AbstractThreadLocalContext implements RequestContext { | ||
16 | + | ||
17 | + RequestContextImpl() { | ||
18 | + super(RequestScoped.class); | ||
19 | + } | ||
20 | + | ||
21 | +} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/SessionContextImpl.java
0 → 100644
@@ -0,0 +1,21 @@ | @@ -0,0 +1,21 @@ | ||
1 | +package br.gov.frameworkdemoiselle.internal.context; | ||
2 | + | ||
3 | +import javax.enterprise.context.SessionScoped; | ||
4 | + | ||
5 | +import br.gov.frameworkdemoiselle.annotation.Priority; | ||
6 | +import br.gov.frameworkdemoiselle.context.SessionContext; | ||
7 | + | ||
8 | + | ||
9 | +/** | ||
10 | + * | ||
11 | + * @author serpro | ||
12 | + * | ||
13 | + */ | ||
14 | +@Priority(Priority.MIN_PRIORITY) | ||
15 | +public class SessionContextImpl extends StaticContextImpl implements SessionContext { | ||
16 | + | ||
17 | + SessionContextImpl() { | ||
18 | + super(SessionScoped.class); | ||
19 | + } | ||
20 | + | ||
21 | +} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/StaticContext.java
@@ -1,58 +0,0 @@ | @@ -1,58 +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.context; | ||
38 | - | ||
39 | -import br.gov.frameworkdemoiselle.annotation.StaticScoped; | ||
40 | - | ||
41 | -public class StaticContext extends AbstractCustomContext { | ||
42 | - | ||
43 | - private final static Store store = createStore(); | ||
44 | - | ||
45 | - public StaticContext() { | ||
46 | - super(StaticScoped.class); | ||
47 | - } | ||
48 | - | ||
49 | - @Override | ||
50 | - protected Store getStore() { | ||
51 | - return store; | ||
52 | - } | ||
53 | - | ||
54 | - @Override | ||
55 | - protected boolean isStoreInitialized() { | ||
56 | - return store!=null; | ||
57 | - } | ||
58 | -} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/StaticContextImpl.java
0 → 100644
@@ -0,0 +1,86 @@ | @@ -0,0 +1,86 @@ | ||
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.context; | ||
38 | + | ||
39 | +import java.lang.annotation.Annotation; | ||
40 | + | ||
41 | +import br.gov.frameworkdemoiselle.annotation.Priority; | ||
42 | +import br.gov.frameworkdemoiselle.annotation.StaticScoped; | ||
43 | +import br.gov.frameworkdemoiselle.configuration.Configuration; | ||
44 | + | ||
45 | +/** | ||
46 | + * | ||
47 | + * <p>This context has a unified static store that keeps all scoped beans available | ||
48 | + * to all threads of an application. It is intended to keep beans avaliable to | ||
49 | + * long lasting scopes (like the Session scope and Application scope) on environments | ||
50 | + * that lack those scopes by default (like desktop Swing applications).</p> | ||
51 | + * | ||
52 | + * <p>This context also keeps beans of the custom {@link StaticScoped} scope, like the beans | ||
53 | + * annotated with {@link Configuration}.</p> | ||
54 | + * | ||
55 | + * @author serpro | ||
56 | + * | ||
57 | + */ | ||
58 | +@Priority(Priority.MIN_PRIORITY) | ||
59 | +public class StaticContextImpl extends AbstractCustomContext { | ||
60 | + | ||
61 | + private final static Store store = createStore(); | ||
62 | + | ||
63 | + /** | ||
64 | + * Constructs this context to control the provided scope | ||
65 | + */ | ||
66 | + StaticContextImpl(Class<? extends Annotation> scope) { | ||
67 | + super(scope); | ||
68 | + } | ||
69 | + | ||
70 | + /** | ||
71 | + * Constructs this context to control {@link StaticScoped} beans | ||
72 | + */ | ||
73 | + StaticContextImpl() { | ||
74 | + super(StaticScoped.class); | ||
75 | + } | ||
76 | + | ||
77 | + @Override | ||
78 | + protected Store getStore() { | ||
79 | + return store; | ||
80 | + } | ||
81 | + | ||
82 | + @Override | ||
83 | + protected boolean isStoreInitialized() { | ||
84 | + return store!=null; | ||
85 | + } | ||
86 | +} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/ThreadLocalContext.java
@@ -1,79 +0,0 @@ | @@ -1,79 +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 | -/* | ||
38 | - * Demoiselle Framework Copyright (c) 2010 Serpro and other contributors as indicated by the @author tag. See the | ||
39 | - * copyright.txt in the distribution for a full listing of contributors. Demoiselle Framework is an open source Java EE | ||
40 | - * library designed to accelerate the development of transactional database Web applications. Demoiselle Framework is | ||
41 | - * released under the terms of the LGPL license 3 http://www.gnu.org/licenses/lgpl.html LGPL License 3 This file is part | ||
42 | - * of Demoiselle Framework. Demoiselle Framework is free software: you can redistribute it and/or modify it under the | ||
43 | - * terms of the GNU Lesser General Public License 3 as published by the Free Software Foundation. Demoiselle Framework | ||
44 | - * is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
45 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You | ||
46 | - * should have received a copy of the GNU Lesser General Public License along with Demoiselle Framework. If not, see | ||
47 | - * <http://www.gnu.org/licenses/>. | ||
48 | - */ | ||
49 | -package br.gov.frameworkdemoiselle.internal.context; | ||
50 | - | ||
51 | -import java.lang.annotation.Annotation; | ||
52 | - | ||
53 | -/** | ||
54 | - * Base context that has a separated store for each thread | ||
55 | - * | ||
56 | - * @author serpro | ||
57 | - */ | ||
58 | -public class ThreadLocalContext extends AbstractCustomContext { | ||
59 | - | ||
60 | - private final ThreadLocal<Store> threadLocal = new ThreadLocal<Store>(); | ||
61 | - | ||
62 | - public ThreadLocalContext(final Class<? extends Annotation> scope) { | ||
63 | - super(scope); | ||
64 | - } | ||
65 | - | ||
66 | - @Override | ||
67 | - protected boolean isStoreInitialized() { | ||
68 | - return threadLocal.get()!=null; | ||
69 | - } | ||
70 | - | ||
71 | - @Override | ||
72 | - protected Store getStore() { | ||
73 | - if (this.threadLocal.get() == null) { | ||
74 | - this.threadLocal.set(createStore()); | ||
75 | - } | ||
76 | - | ||
77 | - return this.threadLocal.get(); | ||
78 | - } | ||
79 | -} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/ThreadLocalViewContextImpl.java
0 → 100644
@@ -0,0 +1,14 @@ | @@ -0,0 +1,14 @@ | ||
1 | +package br.gov.frameworkdemoiselle.internal.context; | ||
2 | + | ||
3 | +import br.gov.frameworkdemoiselle.annotation.Priority; | ||
4 | +import br.gov.frameworkdemoiselle.annotation.ViewScoped; | ||
5 | +import br.gov.frameworkdemoiselle.context.ViewContext; | ||
6 | + | ||
7 | +@Priority(Priority.MIN_PRIORITY) | ||
8 | +public class ThreadLocalViewContextImpl extends AbstractThreadLocalContext implements ViewContext { | ||
9 | + | ||
10 | + ThreadLocalViewContextImpl() { | ||
11 | + super(ViewScoped.class); | ||
12 | + } | ||
13 | + | ||
14 | +} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/management/Management.java
@@ -44,7 +44,6 @@ import java.util.List; | @@ -44,7 +44,6 @@ import java.util.List; | ||
44 | import java.util.Set; | 44 | import java.util.Set; |
45 | 45 | ||
46 | import javax.enterprise.context.ApplicationScoped; | 46 | import javax.enterprise.context.ApplicationScoped; |
47 | -import javax.enterprise.context.RequestScoped; | ||
48 | import javax.inject.Inject; | 47 | import javax.inject.Inject; |
49 | import javax.validation.ConstraintViolation; | 48 | import javax.validation.ConstraintViolation; |
50 | import javax.validation.ConstraintViolationException; | 49 | import javax.validation.ConstraintViolationException; |
@@ -56,8 +55,9 @@ import org.slf4j.Logger; | @@ -56,8 +55,9 @@ import org.slf4j.Logger; | ||
56 | 55 | ||
57 | import br.gov.frameworkdemoiselle.annotation.ManagedProperty; | 56 | import br.gov.frameworkdemoiselle.annotation.ManagedProperty; |
58 | import br.gov.frameworkdemoiselle.annotation.Name; | 57 | import br.gov.frameworkdemoiselle.annotation.Name; |
59 | -import br.gov.frameworkdemoiselle.internal.context.ContextManager; | ||
60 | -import br.gov.frameworkdemoiselle.internal.context.ManagedContext; | 58 | +import br.gov.frameworkdemoiselle.context.RequestContext; |
59 | +import br.gov.frameworkdemoiselle.context.SessionContext; | ||
60 | +import br.gov.frameworkdemoiselle.context.ViewContext; | ||
61 | import br.gov.frameworkdemoiselle.internal.management.ManagedType.MethodDetail; | 61 | import br.gov.frameworkdemoiselle.internal.management.ManagedType.MethodDetail; |
62 | import br.gov.frameworkdemoiselle.lifecycle.ManagementExtension; | 62 | import br.gov.frameworkdemoiselle.lifecycle.ManagementExtension; |
63 | import br.gov.frameworkdemoiselle.management.AttributeChangeNotification; | 63 | import br.gov.frameworkdemoiselle.management.AttributeChangeNotification; |
@@ -301,36 +301,72 @@ public class Management implements Serializable { | @@ -301,36 +301,72 @@ public class Management implements Serializable { | ||
301 | } | 301 | } |
302 | 302 | ||
303 | private void activateContexts(Class<?> managedType) { | 303 | private void activateContexts(Class<?> managedType) { |
304 | - logger.debug(bundle.getString("management-debug-starting-custom-context", | ||
305 | - ManagedContext.class.getCanonicalName(), managedType.getCanonicalName())); | 304 | + |
305 | + RequestContext requestContext = Beans.getReference(RequestContext.class); | ||
306 | + ViewContext viewContext = Beans.getReference(ViewContext.class); | ||
307 | + SessionContext sessionContext = Beans.getReference(SessionContext.class); | ||
308 | + | ||
309 | + if (!requestContext.isActive()){ | ||
310 | + logger.debug(bundle.getString("management-debug-starting-custom-context", | ||
311 | + requestContext.getClass().getCanonicalName(), managedType.getCanonicalName())); | ||
312 | + | ||
313 | + requestContext.activate(); | ||
314 | + } | ||
315 | + | ||
316 | + if (!viewContext.isActive()){ | ||
317 | + logger.debug(bundle.getString("management-debug-starting-custom-context", | ||
318 | + viewContext.getClass().getCanonicalName(), managedType.getCanonicalName())); | ||
319 | + | ||
320 | + viewContext.activate(); | ||
321 | + } | ||
306 | 322 | ||
307 | - ContextManager.activate(ManagedContext.class, RequestScoped.class); | 323 | + if (!sessionContext.isActive()){ |
324 | + logger.debug(bundle.getString("management-debug-starting-custom-context", | ||
325 | + sessionContext.getClass().getCanonicalName(), managedType.getCanonicalName())); | ||
326 | + | ||
327 | + sessionContext.activate(); | ||
328 | + } | ||
308 | } | 329 | } |
309 | 330 | ||
310 | private void deactivateContexts(Class<?> managedType) { | 331 | private void deactivateContexts(Class<?> managedType) { |
311 | - logger.debug(bundle.getString("management-debug-stoping-custom-context", | ||
312 | - ManagedContext.class.getCanonicalName(), managedType.getCanonicalName())); | 332 | + RequestContext requestContext = Beans.getReference(RequestContext.class); |
333 | + ViewContext viewContext = Beans.getReference(ViewContext.class); | ||
334 | + SessionContext sessionContext = Beans.getReference(SessionContext.class); | ||
335 | + | ||
336 | + if (requestContext.isActive()){ | ||
337 | + logger.debug(bundle.getString("management-debug-stoping-custom-context", | ||
338 | + requestContext.getClass().getCanonicalName(), managedType.getCanonicalName())); | ||
339 | + | ||
340 | + requestContext.deactivate(); | ||
341 | + } | ||
342 | + | ||
343 | + if (!viewContext.isActive()){ | ||
344 | + logger.debug(bundle.getString("management-debug-stoping-custom-context", | ||
345 | + viewContext.getClass().getCanonicalName(), managedType.getCanonicalName())); | ||
346 | + | ||
347 | + viewContext.deactivate(); | ||
348 | + } | ||
313 | 349 | ||
314 | - ContextManager.deactivate(ManagedContext.class, RequestScoped.class); | 350 | + if (!sessionContext.isActive()){ |
351 | + logger.debug(bundle.getString("management-debug-stoping-custom-context", | ||
352 | + sessionContext.getClass().getCanonicalName(), managedType.getCanonicalName())); | ||
353 | + | ||
354 | + sessionContext.deactivate(); | ||
355 | + } | ||
315 | } | 356 | } |
316 | 357 | ||
317 | public void shutdown(Collection<Class<? extends ManagementExtension>> monitoringExtensions) { | 358 | public void shutdown(Collection<Class<? extends ManagementExtension>> monitoringExtensions) { |
318 | - | ||
319 | for (Class<? extends ManagementExtension> monitoringExtensionClass : monitoringExtensions) { | 359 | for (Class<? extends ManagementExtension> monitoringExtensionClass : monitoringExtensions) { |
320 | 360 | ||
321 | ManagementExtension monitoringExtension = Beans.getReference(monitoringExtensionClass); | 361 | ManagementExtension monitoringExtension = Beans.getReference(monitoringExtensionClass); |
322 | - | ||
323 | monitoringExtension.shutdown(this.getManagedTypes()); | 362 | monitoringExtension.shutdown(this.getManagedTypes()); |
324 | - | ||
325 | logger.debug(bundle.getString("management-debug-removing-management-extension", monitoringExtension | 363 | logger.debug(bundle.getString("management-debug-removing-management-extension", monitoringExtension |
326 | .getClass().getCanonicalName())); | 364 | .getClass().getCanonicalName())); |
327 | 365 | ||
328 | } | 366 | } |
329 | - | ||
330 | } | 367 | } |
331 | 368 | ||
332 | public void initialize(Collection<Class<? extends ManagementExtension>> monitoringExtensions) { | 369 | public void initialize(Collection<Class<? extends ManagementExtension>> monitoringExtensions) { |
333 | - | ||
334 | for (Class<? extends ManagementExtension> monitoringExtensionClass : monitoringExtensions) { | 370 | for (Class<? extends ManagementExtension> monitoringExtensionClass : monitoringExtensions) { |
335 | ManagementExtension monitoringExtension = Beans.getReference(monitoringExtensionClass); | 371 | ManagementExtension monitoringExtension = Beans.getReference(monitoringExtensionClass); |
336 | 372 | ||
@@ -339,7 +375,6 @@ public class Management implements Serializable { | @@ -339,7 +375,6 @@ public class Management implements Serializable { | ||
339 | 375 | ||
340 | monitoringExtension.initialize(this.getManagedTypes()); | 376 | monitoringExtension.initialize(this.getManagedTypes()); |
341 | } | 377 | } |
342 | - | ||
343 | } | 378 | } |
344 | 379 | ||
345 | private Validator getDefaultValidator() { | 380 | private Validator getDefaultValidator() { |
impl/core/src/main/resources/demoiselle-core-bundle.properties
@@ -66,8 +66,6 @@ configuration-not-conversion=N\u00E3o \u00E9 poss\u00EDvel converter o valor {0} | @@ -66,8 +66,6 @@ configuration-not-conversion=N\u00E3o \u00E9 poss\u00EDvel converter o valor {0} | ||
66 | 66 | ||
67 | transaction-not-defined=Nenhuma transa\u00E7\u00E3o foi definida. Para utilizar @{0} \u00E9 preciso definir a propriedade frameworkdemoiselle.transaction.class com a estrat\u00E9gia de transa\u00E7\u00E3o desejada no arquivo demoiselle.properties | 67 | transaction-not-defined=Nenhuma transa\u00E7\u00E3o foi definida. Para utilizar @{0} \u00E9 preciso definir a propriedade frameworkdemoiselle.transaction.class com a estrat\u00E9gia de transa\u00E7\u00E3o desejada no arquivo demoiselle.properties |
68 | executing-all=Executando todos os \: {0} | 68 | executing-all=Executando todos os \: {0} |
69 | -custom-context-was-registered=O contexto {0} foi registrado | ||
70 | -custom-context-was-unregistered=O contexto {0} foi removido | ||
71 | custom-context-was-activated=O contexto {0} foi ativado para o escopo {1} | 69 | custom-context-was-activated=O contexto {0} foi ativado para o escopo {1} |
72 | custom-context-was-deactivated=O contexto {0} foi desativado para o escopo {1} | 70 | custom-context-was-deactivated=O contexto {0} foi desativado para o escopo {1} |
73 | custom-context-already-activated=N\u00E3o foi poss\u00EDvel ativar o contexto {0}, o escopo {1} j\u00E1 est\u00E1 ativo no contexto {2} | 71 | custom-context-already-activated=N\u00E3o foi poss\u00EDvel ativar o contexto {0}, o escopo {1} j\u00E1 est\u00E1 ativo no contexto {2} |
impl/core/src/test/java/message/MessageContextTest.java
@@ -39,7 +39,6 @@ package message; | @@ -39,7 +39,6 @@ package message; | ||
39 | import static junit.framework.Assert.assertEquals; | 39 | import static junit.framework.Assert.assertEquals; |
40 | import static junit.framework.Assert.assertTrue; | 40 | import static junit.framework.Assert.assertTrue; |
41 | 41 | ||
42 | -import javax.enterprise.context.RequestScoped; | ||
43 | import javax.inject.Inject; | 42 | import javax.inject.Inject; |
44 | 43 | ||
45 | import junit.framework.Assert; | 44 | import junit.framework.Assert; |
@@ -51,8 +50,7 @@ import org.junit.Test; | @@ -51,8 +50,7 @@ import org.junit.Test; | ||
51 | import org.junit.runner.RunWith; | 50 | import org.junit.runner.RunWith; |
52 | 51 | ||
53 | import test.Tests; | 52 | import test.Tests; |
54 | -import br.gov.frameworkdemoiselle.internal.context.ContextManager; | ||
55 | -import br.gov.frameworkdemoiselle.internal.context.ManagedContext; | 53 | +import br.gov.frameworkdemoiselle.context.RequestContext; |
56 | import br.gov.frameworkdemoiselle.message.DefaultMessage; | 54 | import br.gov.frameworkdemoiselle.message.DefaultMessage; |
57 | import br.gov.frameworkdemoiselle.message.Message; | 55 | import br.gov.frameworkdemoiselle.message.Message; |
58 | import br.gov.frameworkdemoiselle.message.MessageContext; | 56 | import br.gov.frameworkdemoiselle.message.MessageContext; |
@@ -80,78 +78,92 @@ public class MessageContextTest { | @@ -80,78 +78,92 @@ public class MessageContextTest { | ||
80 | 78 | ||
81 | @Test | 79 | @Test |
82 | public void testAddMessageWithoutParams() { | 80 | public void testAddMessageWithoutParams() { |
83 | - ContextManager.activate(ManagedContext.class, RequestScoped.class); | 81 | + RequestContext context = Beans.getReference(RequestContext.class); |
82 | + | ||
83 | + context.activate(); | ||
84 | Message message = new DefaultMessage("Menssage without param"); | 84 | Message message = new DefaultMessage("Menssage without param"); |
85 | DummyMessageAppender appender = Beans.getReference(DummyMessageAppender.class); | 85 | DummyMessageAppender appender = Beans.getReference(DummyMessageAppender.class); |
86 | 86 | ||
87 | messageContext.add(message); | 87 | messageContext.add(message); |
88 | assertEquals(appender.getMessages().size(), 1); | 88 | assertEquals(appender.getMessages().size(), 1); |
89 | - ContextManager.deactivate(ManagedContext.class, RequestScoped.class); | 89 | + context.deactivate(); |
90 | } | 90 | } |
91 | 91 | ||
92 | @Test | 92 | @Test |
93 | public void testAddMessageWithoutParamsIfSeverityIsInfo() { | 93 | public void testAddMessageWithoutParamsIfSeverityIsInfo() { |
94 | - ContextManager.activate(ManagedContext.class, RequestScoped.class); | 94 | + RequestContext context = Beans.getReference(RequestContext.class); |
95 | + | ||
96 | + context.activate(); | ||
95 | Message message = new DefaultMessage("Menssage without param"); | 97 | Message message = new DefaultMessage("Menssage without param"); |
96 | DummyMessageAppender appender = Beans.getReference(DummyMessageAppender.class); | 98 | DummyMessageAppender appender = Beans.getReference(DummyMessageAppender.class); |
97 | 99 | ||
98 | messageContext.add(message); | 100 | messageContext.add(message); |
99 | assertEquals(appender.getMessages().get(0).getSeverity(), SeverityType.INFO); | 101 | assertEquals(appender.getMessages().get(0).getSeverity(), SeverityType.INFO); |
100 | - ContextManager.deactivate(ManagedContext.class, RequestScoped.class); | 102 | + context.deactivate(); |
101 | } | 103 | } |
102 | 104 | ||
103 | @Test | 105 | @Test |
104 | public void testAddMessageWitSeverityInfo() { | 106 | public void testAddMessageWitSeverityInfo() { |
105 | - ContextManager.activate(ManagedContext.class, RequestScoped.class); | 107 | + RequestContext context = Beans.getReference(RequestContext.class); |
108 | + | ||
109 | + context.activate(); | ||
106 | Message message = new DefaultMessage("Menssage without param", SeverityType.INFO); | 110 | Message message = new DefaultMessage("Menssage without param", SeverityType.INFO); |
107 | DummyMessageAppender appender = Beans.getReference(DummyMessageAppender.class); | 111 | DummyMessageAppender appender = Beans.getReference(DummyMessageAppender.class); |
108 | 112 | ||
109 | messageContext.add(message); | 113 | messageContext.add(message); |
110 | assertEquals(appender.getMessages().get(0).getSeverity(), SeverityType.INFO); | 114 | assertEquals(appender.getMessages().get(0).getSeverity(), SeverityType.INFO); |
111 | - ContextManager.deactivate(ManagedContext.class, RequestScoped.class); | 115 | + context.deactivate(); |
112 | } | 116 | } |
113 | 117 | ||
114 | @Test | 118 | @Test |
115 | public void testAddMessageWitSeverityWarn() { | 119 | public void testAddMessageWitSeverityWarn() { |
116 | - ContextManager.activate(ManagedContext.class, RequestScoped.class); | 120 | + RequestContext context = Beans.getReference(RequestContext.class); |
121 | + | ||
122 | + context.activate(); | ||
117 | Message message = new DefaultMessage("Menssage without param", SeverityType.WARN); | 123 | Message message = new DefaultMessage("Menssage without param", SeverityType.WARN); |
118 | DummyMessageAppender appender = Beans.getReference(DummyMessageAppender.class); | 124 | DummyMessageAppender appender = Beans.getReference(DummyMessageAppender.class); |
119 | 125 | ||
120 | messageContext.add(message); | 126 | messageContext.add(message); |
121 | assertEquals(appender.getMessages().get(0).getSeverity(), SeverityType.WARN); | 127 | assertEquals(appender.getMessages().get(0).getSeverity(), SeverityType.WARN); |
122 | - ContextManager.deactivate(ManagedContext.class, RequestScoped.class); | 128 | + context.deactivate(); |
123 | } | 129 | } |
124 | 130 | ||
125 | @Test | 131 | @Test |
126 | public void testAddMessageWitSeverityErro() { | 132 | public void testAddMessageWitSeverityErro() { |
127 | - ContextManager.activate(ManagedContext.class, RequestScoped.class); | 133 | + RequestContext context = Beans.getReference(RequestContext.class); |
134 | + | ||
135 | + context.activate(); | ||
128 | Message message = new DefaultMessage("Menssage without param", SeverityType.ERROR); | 136 | Message message = new DefaultMessage("Menssage without param", SeverityType.ERROR); |
129 | DummyMessageAppender appender = Beans.getReference(DummyMessageAppender.class); | 137 | DummyMessageAppender appender = Beans.getReference(DummyMessageAppender.class); |
130 | 138 | ||
131 | messageContext.add(message); | 139 | messageContext.add(message); |
132 | assertEquals(appender.getMessages().get(0).getSeverity(), SeverityType.ERROR); | 140 | assertEquals(appender.getMessages().get(0).getSeverity(), SeverityType.ERROR); |
133 | - ContextManager.deactivate(ManagedContext.class, RequestScoped.class); | 141 | + context.deactivate(); |
134 | } | 142 | } |
135 | 143 | ||
136 | @Test | 144 | @Test |
137 | public void testRecoverStringMessageWithParams() { | 145 | public void testRecoverStringMessageWithParams() { |
138 | - ContextManager.activate(ManagedContext.class, RequestScoped.class); | 146 | + RequestContext context = Beans.getReference(RequestContext.class); |
147 | + | ||
148 | + context.activate(); | ||
139 | DummyMessageAppender appender = Beans.getReference(DummyMessageAppender.class); | 149 | DummyMessageAppender appender = Beans.getReference(DummyMessageAppender.class); |
140 | 150 | ||
141 | messageContext.add("Message with {0} param", 1); | 151 | messageContext.add("Message with {0} param", 1); |
142 | assertTrue(appender.getMessages().get(0).getText().equals("Message with 1 param")); | 152 | assertTrue(appender.getMessages().get(0).getText().equals("Message with 1 param")); |
143 | - ContextManager.deactivate(ManagedContext.class, RequestScoped.class); | 153 | + context.deactivate(); |
144 | } | 154 | } |
145 | 155 | ||
146 | @Test | 156 | @Test |
147 | public void testRecoverMessageWithParams() { | 157 | public void testRecoverMessageWithParams() { |
148 | - ContextManager.activate(ManagedContext.class, RequestScoped.class); | 158 | + RequestContext context = Beans.getReference(RequestContext.class); |
159 | + | ||
160 | + context.activate(); | ||
149 | Message message = new DefaultMessage("Message with {0} param"); | 161 | Message message = new DefaultMessage("Message with {0} param"); |
150 | DummyMessageAppender appender = Beans.getReference(DummyMessageAppender.class); | 162 | DummyMessageAppender appender = Beans.getReference(DummyMessageAppender.class); |
151 | 163 | ||
152 | messageContext.add(message, 1); | 164 | messageContext.add(message, 1); |
153 | assertTrue(appender.getMessages().get(0).getText().equals("Message with 1 param")); | 165 | assertTrue(appender.getMessages().get(0).getText().equals("Message with 1 param")); |
154 | - ContextManager.deactivate(ManagedContext.class, RequestScoped.class); | 166 | + context.deactivate(); |
155 | } | 167 | } |
156 | 168 | ||
157 | @Test | 169 | @Test |
@@ -164,21 +176,25 @@ public class MessageContextTest { | @@ -164,21 +176,25 @@ public class MessageContextTest { | ||
164 | 176 | ||
165 | @Test | 177 | @Test |
166 | public void testMessageParsedText() { | 178 | public void testMessageParsedText() { |
167 | - ContextManager.activate(ManagedContext.class, RequestScoped.class); | 179 | + RequestContext context = Beans.getReference(RequestContext.class); |
180 | + | ||
181 | + context.activate(); | ||
168 | Message MESSAGE_PARSED = new DefaultMessage("{MESSAGE_PARSED}"); | 182 | Message MESSAGE_PARSED = new DefaultMessage("{MESSAGE_PARSED}"); |
169 | String expected = "Message parsed"; | 183 | String expected = "Message parsed"; |
170 | String value = MESSAGE_PARSED.getText(); | 184 | String value = MESSAGE_PARSED.getText(); |
171 | Assert.assertEquals(expected, value); | 185 | Assert.assertEquals(expected, value); |
172 | - ContextManager.deactivate(ManagedContext.class, RequestScoped.class); | 186 | + context.deactivate(); |
173 | } | 187 | } |
174 | 188 | ||
175 | @Test | 189 | @Test |
176 | public void testMessageIsNull() { | 190 | public void testMessageIsNull() { |
177 | - ContextManager.activate(ManagedContext.class, RequestScoped.class); | 191 | + RequestContext context = Beans.getReference(RequestContext.class); |
192 | + | ||
193 | + context.activate(); | ||
178 | Message NULL_MESSAGE = new DefaultMessage(null); | 194 | Message NULL_MESSAGE = new DefaultMessage(null); |
179 | String expected = null; | 195 | String expected = null; |
180 | String value = NULL_MESSAGE.getText(); | 196 | String value = NULL_MESSAGE.getText(); |
181 | Assert.assertEquals(expected, value); | 197 | Assert.assertEquals(expected, value); |
182 | - ContextManager.deactivate(ManagedContext.class, RequestScoped.class); | 198 | + context.deactivate(); |
183 | } | 199 | } |
184 | } | 200 | } |
impl/core/src/test/java/pagination/PaginationContextBasicTest.java
@@ -38,7 +38,6 @@ package pagination; | @@ -38,7 +38,6 @@ package pagination; | ||
38 | 38 | ||
39 | import static junit.framework.Assert.assertEquals; | 39 | import static junit.framework.Assert.assertEquals; |
40 | 40 | ||
41 | -import javax.enterprise.context.SessionScoped; | ||
42 | import javax.inject.Inject; | 41 | import javax.inject.Inject; |
43 | 42 | ||
44 | import org.jboss.arquillian.container.test.api.Deployment; | 43 | import org.jboss.arquillian.container.test.api.Deployment; |
@@ -51,11 +50,11 @@ import org.junit.runner.RunWith; | @@ -51,11 +50,11 @@ import org.junit.runner.RunWith; | ||
51 | 50 | ||
52 | import test.Tests; | 51 | import test.Tests; |
53 | import transaction.defaultstrategy.TransactionDefaultTest; | 52 | import transaction.defaultstrategy.TransactionDefaultTest; |
53 | +import br.gov.frameworkdemoiselle.context.SessionContext; | ||
54 | import br.gov.frameworkdemoiselle.internal.configuration.PaginationConfig; | 54 | import br.gov.frameworkdemoiselle.internal.configuration.PaginationConfig; |
55 | -import br.gov.frameworkdemoiselle.internal.context.ContextManager; | ||
56 | -import br.gov.frameworkdemoiselle.internal.context.ThreadLocalContext; | ||
57 | import br.gov.frameworkdemoiselle.pagination.Pagination; | 55 | import br.gov.frameworkdemoiselle.pagination.Pagination; |
58 | import br.gov.frameworkdemoiselle.pagination.PaginationContext; | 56 | import br.gov.frameworkdemoiselle.pagination.PaginationContext; |
57 | +import br.gov.frameworkdemoiselle.util.Beans; | ||
59 | 58 | ||
60 | @RunWith(Arquillian.class) | 59 | @RunWith(Arquillian.class) |
61 | public class PaginationContextBasicTest { | 60 | public class PaginationContextBasicTest { |
@@ -96,13 +95,15 @@ public class PaginationContextBasicTest { | @@ -96,13 +95,15 @@ public class PaginationContextBasicTest { | ||
96 | 95 | ||
97 | @Before | 96 | @Before |
98 | public void activeContext() { | 97 | public void activeContext() { |
99 | - ContextManager.activate(ThreadLocalContext.class, SessionScoped.class); | 98 | + SessionContext context = Beans.getReference(SessionContext.class); |
99 | + context.activate(); | ||
100 | pagination = paginationContext.getPagination(DummyEntity.class, true); | 100 | pagination = paginationContext.getPagination(DummyEntity.class, true); |
101 | } | 101 | } |
102 | 102 | ||
103 | @After | 103 | @After |
104 | public void deactiveContext() { | 104 | public void deactiveContext() { |
105 | - ContextManager.deactivate(ThreadLocalContext.class, SessionScoped.class); | 105 | + SessionContext context = Beans.getReference(SessionContext.class); |
106 | + context.deactivate(); | ||
106 | } | 107 | } |
107 | 108 | ||
108 | @Test | 109 | @Test |
impl/core/src/test/java/pagination/PaginationContextCache.java
@@ -38,7 +38,6 @@ package pagination; | @@ -38,7 +38,6 @@ package pagination; | ||
38 | 38 | ||
39 | import static org.junit.Assert.assertEquals; | 39 | import static org.junit.Assert.assertEquals; |
40 | 40 | ||
41 | -import javax.enterprise.context.SessionScoped; | ||
42 | import javax.inject.Inject; | 41 | import javax.inject.Inject; |
43 | 42 | ||
44 | import org.jboss.arquillian.container.test.api.Deployment; | 43 | import org.jboss.arquillian.container.test.api.Deployment; |
@@ -51,10 +50,10 @@ import org.junit.runner.RunWith; | @@ -51,10 +50,10 @@ import org.junit.runner.RunWith; | ||
51 | 50 | ||
52 | import test.Tests; | 51 | import test.Tests; |
53 | import transaction.defaultstrategy.TransactionDefaultTest; | 52 | import transaction.defaultstrategy.TransactionDefaultTest; |
54 | -import br.gov.frameworkdemoiselle.internal.context.ContextManager; | ||
55 | -import br.gov.frameworkdemoiselle.internal.context.ThreadLocalContext; | 53 | +import br.gov.frameworkdemoiselle.context.SessionContext; |
56 | import br.gov.frameworkdemoiselle.pagination.Pagination; | 54 | import br.gov.frameworkdemoiselle.pagination.Pagination; |
57 | import br.gov.frameworkdemoiselle.pagination.PaginationContext; | 55 | import br.gov.frameworkdemoiselle.pagination.PaginationContext; |
56 | +import br.gov.frameworkdemoiselle.util.Beans; | ||
58 | 57 | ||
59 | @RunWith(Arquillian.class) | 58 | @RunWith(Arquillian.class) |
60 | public class PaginationContextCache { | 59 | public class PaginationContextCache { |
@@ -74,12 +73,14 @@ public class PaginationContextCache { | @@ -74,12 +73,14 @@ public class PaginationContextCache { | ||
74 | 73 | ||
75 | @Before | 74 | @Before |
76 | public void activeContext() { | 75 | public void activeContext() { |
77 | - ContextManager.activate(ThreadLocalContext.class, SessionScoped.class); | 76 | + SessionContext context = Beans.getReference(SessionContext.class); |
77 | + context.activate(); | ||
78 | } | 78 | } |
79 | 79 | ||
80 | @After | 80 | @After |
81 | public void deactiveContext() { | 81 | public void deactiveContext() { |
82 | - ContextManager.deactivate(ThreadLocalContext.class, SessionScoped.class); | 82 | + SessionContext context = Beans.getReference(SessionContext.class); |
83 | + context.deactivate(); | ||
83 | } | 84 | } |
84 | 85 | ||
85 | @Test | 86 | @Test |
impl/core/src/test/java/pagination/PaginationContextNullTest.java
@@ -38,7 +38,6 @@ package pagination; | @@ -38,7 +38,6 @@ package pagination; | ||
38 | 38 | ||
39 | import static org.junit.Assert.assertNull; | 39 | import static org.junit.Assert.assertNull; |
40 | 40 | ||
41 | -import javax.enterprise.context.SessionScoped; | ||
42 | import javax.inject.Inject; | 41 | import javax.inject.Inject; |
43 | 42 | ||
44 | import org.jboss.arquillian.container.test.api.Deployment; | 43 | import org.jboss.arquillian.container.test.api.Deployment; |
@@ -51,10 +50,10 @@ import org.junit.runner.RunWith; | @@ -51,10 +50,10 @@ import org.junit.runner.RunWith; | ||
51 | 50 | ||
52 | import test.Tests; | 51 | import test.Tests; |
53 | import transaction.defaultstrategy.TransactionDefaultTest; | 52 | import transaction.defaultstrategy.TransactionDefaultTest; |
54 | -import br.gov.frameworkdemoiselle.internal.context.ContextManager; | ||
55 | -import br.gov.frameworkdemoiselle.internal.context.ThreadLocalContext; | 53 | +import br.gov.frameworkdemoiselle.context.SessionContext; |
56 | import br.gov.frameworkdemoiselle.pagination.Pagination; | 54 | import br.gov.frameworkdemoiselle.pagination.Pagination; |
57 | import br.gov.frameworkdemoiselle.pagination.PaginationContext; | 55 | import br.gov.frameworkdemoiselle.pagination.PaginationContext; |
56 | +import br.gov.frameworkdemoiselle.util.Beans; | ||
58 | 57 | ||
59 | @RunWith(Arquillian.class) | 58 | @RunWith(Arquillian.class) |
60 | public class PaginationContextNullTest { | 59 | public class PaginationContextNullTest { |
@@ -72,12 +71,14 @@ public class PaginationContextNullTest { | @@ -72,12 +71,14 @@ public class PaginationContextNullTest { | ||
72 | 71 | ||
73 | @Before | 72 | @Before |
74 | public void activeContext() { | 73 | public void activeContext() { |
75 | - ContextManager.activate(ThreadLocalContext.class, SessionScoped.class); | 74 | + SessionContext context = Beans.getReference(SessionContext.class); |
75 | + context.activate(); | ||
76 | } | 76 | } |
77 | 77 | ||
78 | @After | 78 | @After |
79 | public void deactiveContext() { | 79 | public void deactiveContext() { |
80 | - ContextManager.deactivate(ThreadLocalContext.class, SessionScoped.class); | 80 | + SessionContext context = Beans.getReference(SessionContext.class); |
81 | + context.deactivate(); | ||
81 | } | 82 | } |
82 | 83 | ||
83 | @Test | 84 | @Test |
impl/core/src/test/java/security/athentication/credentials/AcceptOrDenyCredentialsTest.java
@@ -36,7 +36,6 @@ | @@ -36,7 +36,6 @@ | ||
36 | */ | 36 | */ |
37 | package security.athentication.credentials; | 37 | package security.athentication.credentials; |
38 | 38 | ||
39 | -import javax.enterprise.context.RequestScoped; | ||
40 | import javax.inject.Inject; | 39 | import javax.inject.Inject; |
41 | 40 | ||
42 | import junit.framework.Assert; | 41 | import junit.framework.Assert; |
@@ -48,8 +47,7 @@ import org.junit.Test; | @@ -48,8 +47,7 @@ import org.junit.Test; | ||
48 | import org.junit.runner.RunWith; | 47 | import org.junit.runner.RunWith; |
49 | 48 | ||
50 | import test.Tests; | 49 | import test.Tests; |
51 | -import br.gov.frameworkdemoiselle.internal.context.ContextManager; | ||
52 | -import br.gov.frameworkdemoiselle.internal.context.ThreadLocalContext; | 50 | +import br.gov.frameworkdemoiselle.context.RequestContext; |
53 | import br.gov.frameworkdemoiselle.security.AuthenticationException; | 51 | import br.gov.frameworkdemoiselle.security.AuthenticationException; |
54 | import br.gov.frameworkdemoiselle.security.SecurityContext; | 52 | import br.gov.frameworkdemoiselle.security.SecurityContext; |
55 | import br.gov.frameworkdemoiselle.util.Beans; | 53 | import br.gov.frameworkdemoiselle.util.Beans; |
@@ -71,7 +69,8 @@ public class AcceptOrDenyCredentialsTest { | @@ -71,7 +69,8 @@ public class AcceptOrDenyCredentialsTest { | ||
71 | 69 | ||
72 | @Test | 70 | @Test |
73 | public void denyWrongCredentials() { | 71 | public void denyWrongCredentials() { |
74 | - ContextManager.activate(ThreadLocalContext.class, RequestScoped.class); | 72 | + RequestContext ctx = Beans.getReference(RequestContext.class); |
73 | + ctx.activate(); | ||
75 | 74 | ||
76 | Credentials credentials = Beans.getReference(Credentials.class); | 75 | Credentials credentials = Beans.getReference(Credentials.class); |
77 | credentials.setLogin("wronglogin"); | 76 | credentials.setLogin("wronglogin"); |
@@ -84,14 +83,15 @@ public class AcceptOrDenyCredentialsTest { | @@ -84,14 +83,15 @@ public class AcceptOrDenyCredentialsTest { | ||
84 | //Erro esperado | 83 | //Erro esperado |
85 | } | 84 | } |
86 | finally{ | 85 | finally{ |
87 | - ContextManager.deactivate(ThreadLocalContext.class, RequestScoped.class); | 86 | + ctx.deactivate(); |
88 | } | 87 | } |
89 | 88 | ||
90 | } | 89 | } |
91 | 90 | ||
92 | @Test | 91 | @Test |
93 | public void acceptRightCredentials() { | 92 | public void acceptRightCredentials() { |
94 | - ContextManager.activate(ThreadLocalContext.class, RequestScoped.class); | 93 | + RequestContext ctx = Beans.getReference(RequestContext.class); |
94 | + ctx.activate(); | ||
95 | 95 | ||
96 | Credentials credentials = Beans.getReference(Credentials.class); | 96 | Credentials credentials = Beans.getReference(Credentials.class); |
97 | credentials.setLogin("demoiselle"); | 97 | credentials.setLogin("demoiselle"); |
@@ -103,7 +103,7 @@ public class AcceptOrDenyCredentialsTest { | @@ -103,7 +103,7 @@ public class AcceptOrDenyCredentialsTest { | ||
103 | Assert.fail("Authenticator negou credenciais corretas"); | 103 | Assert.fail("Authenticator negou credenciais corretas"); |
104 | } | 104 | } |
105 | finally{ | 105 | finally{ |
106 | - ContextManager.deactivate(ThreadLocalContext.class, RequestScoped.class); | 106 | + ctx.deactivate(); |
107 | } | 107 | } |
108 | 108 | ||
109 | } | 109 | } |
impl/core/src/test/java/security/athentication/custom/CustomAuthenticatorTest.java
@@ -42,7 +42,6 @@ import static org.junit.Assert.assertNotNull; | @@ -42,7 +42,6 @@ import static org.junit.Assert.assertNotNull; | ||
42 | import static org.junit.Assert.assertNull; | 42 | import static org.junit.Assert.assertNull; |
43 | import static org.junit.Assert.assertTrue; | 43 | import static org.junit.Assert.assertTrue; |
44 | 44 | ||
45 | -import javax.enterprise.context.RequestScoped; | ||
46 | import javax.inject.Inject; | 45 | import javax.inject.Inject; |
47 | 46 | ||
48 | import org.jboss.arquillian.container.test.api.Deployment; | 47 | import org.jboss.arquillian.container.test.api.Deployment; |
@@ -52,9 +51,9 @@ import org.junit.Test; | @@ -52,9 +51,9 @@ import org.junit.Test; | ||
52 | import org.junit.runner.RunWith; | 51 | import org.junit.runner.RunWith; |
53 | 52 | ||
54 | import test.Tests; | 53 | import test.Tests; |
55 | -import br.gov.frameworkdemoiselle.internal.context.ContextManager; | ||
56 | -import br.gov.frameworkdemoiselle.internal.context.ThreadLocalContext; | 54 | +import br.gov.frameworkdemoiselle.context.RequestContext; |
57 | import br.gov.frameworkdemoiselle.security.SecurityContext; | 55 | import br.gov.frameworkdemoiselle.security.SecurityContext; |
56 | +import br.gov.frameworkdemoiselle.util.Beans; | ||
58 | import configuration.resource.ConfigurationResourceTest; | 57 | import configuration.resource.ConfigurationResourceTest; |
59 | 58 | ||
60 | @RunWith(Arquillian.class) | 59 | @RunWith(Arquillian.class) |
@@ -82,25 +81,27 @@ public class CustomAuthenticatorTest { | @@ -82,25 +81,27 @@ public class CustomAuthenticatorTest { | ||
82 | 81 | ||
83 | @Test | 82 | @Test |
84 | public void loginProcess() { | 83 | public void loginProcess() { |
85 | - ContextManager.activate(ThreadLocalContext.class, RequestScoped.class); | 84 | + RequestContext ctx = Beans.getReference(RequestContext.class); |
85 | + ctx.activate(); | ||
86 | 86 | ||
87 | context.login(); | 87 | context.login(); |
88 | assertTrue(context.isLoggedIn()); | 88 | assertTrue(context.isLoggedIn()); |
89 | assertNotNull(observer.getEvent()); | 89 | assertNotNull(observer.getEvent()); |
90 | assertEquals("demoiselle", context.getUser().getId()); | 90 | assertEquals("demoiselle", context.getUser().getId()); |
91 | 91 | ||
92 | - ContextManager.deactivate(ThreadLocalContext.class, RequestScoped.class); | 92 | + ctx.deactivate(); |
93 | } | 93 | } |
94 | 94 | ||
95 | @Test | 95 | @Test |
96 | public void logoutProcess() { | 96 | public void logoutProcess() { |
97 | - ContextManager.activate(ThreadLocalContext.class, RequestScoped.class); | 97 | + RequestContext ctx = Beans.getReference(RequestContext.class); |
98 | + ctx.activate(); | ||
98 | 99 | ||
99 | context.login(); | 100 | context.login(); |
100 | context.logout(); | 101 | context.logout(); |
101 | assertFalse(context.isLoggedIn()); | 102 | assertFalse(context.isLoggedIn()); |
102 | assertNull(context.getUser()); | 103 | assertNull(context.getUser()); |
103 | 104 | ||
104 | - ContextManager.deactivate(ThreadLocalContext.class, RequestScoped.class); | 105 | + ctx.deactivate(); |
105 | } | 106 | } |
106 | } | 107 | } |
impl/core/src/test/java/template/TemplateTest.java
@@ -43,7 +43,6 @@ import static junit.framework.Assert.assertNull; | @@ -43,7 +43,6 @@ import static junit.framework.Assert.assertNull; | ||
43 | 43 | ||
44 | import java.util.List; | 44 | import java.util.List; |
45 | 45 | ||
46 | -import javax.enterprise.context.RequestScoped; | ||
47 | import javax.inject.Inject; | 46 | import javax.inject.Inject; |
48 | 47 | ||
49 | import org.jboss.arquillian.container.test.api.Deployment; | 48 | import org.jboss.arquillian.container.test.api.Deployment; |
@@ -55,8 +54,8 @@ import org.junit.Test; | @@ -55,8 +54,8 @@ import org.junit.Test; | ||
55 | import org.junit.runner.RunWith; | 54 | import org.junit.runner.RunWith; |
56 | 55 | ||
57 | import test.Tests; | 56 | import test.Tests; |
58 | -import br.gov.frameworkdemoiselle.internal.context.ContextManager; | ||
59 | -import br.gov.frameworkdemoiselle.internal.context.ManagedContext; | 57 | +import br.gov.frameworkdemoiselle.context.RequestContext; |
58 | +import br.gov.frameworkdemoiselle.util.Beans; | ||
60 | 59 | ||
61 | @RunWith(Arquillian.class) | 60 | @RunWith(Arquillian.class) |
62 | public class TemplateTest { | 61 | public class TemplateTest { |
@@ -83,7 +82,8 @@ public class TemplateTest { | @@ -83,7 +82,8 @@ public class TemplateTest { | ||
83 | @Before | 82 | @Before |
84 | public void initialize() { | 83 | public void initialize() { |
85 | 84 | ||
86 | - ContextManager.activate(ManagedContext.class, RequestScoped.class); | 85 | + RequestContext ctx = Beans.getReference(RequestContext.class); |
86 | + ctx.activate(); | ||
87 | 87 | ||
88 | this.crudImpl.resetEntities(); | 88 | this.crudImpl.resetEntities(); |
89 | 89 | ||
@@ -91,9 +91,8 @@ public class TemplateTest { | @@ -91,9 +91,8 @@ public class TemplateTest { | ||
91 | 91 | ||
92 | @After | 92 | @After |
93 | public void finalize() { | 93 | public void finalize() { |
94 | - | ||
95 | - ContextManager.deactivate(ManagedContext.class, RequestScoped.class); | ||
96 | - | 94 | + RequestContext ctx = Beans.getReference(RequestContext.class); |
95 | + ctx.deactivate(); | ||
97 | } | 96 | } |
98 | 97 | ||
99 | @Test | 98 | @Test |
impl/core/src/test/java/transaction/rollback/TransactionRollbackTest.java
@@ -40,7 +40,6 @@ import static junit.framework.Assert.assertFalse; | @@ -40,7 +40,6 @@ import static junit.framework.Assert.assertFalse; | ||
40 | import static junit.framework.Assert.assertTrue; | 40 | import static junit.framework.Assert.assertTrue; |
41 | import static org.junit.Assert.fail; | 41 | import static org.junit.Assert.fail; |
42 | 42 | ||
43 | -import javax.enterprise.context.RequestScoped; | ||
44 | import javax.inject.Inject; | 43 | import javax.inject.Inject; |
45 | 44 | ||
46 | import org.jboss.arquillian.container.test.api.Deployment; | 45 | import org.jboss.arquillian.container.test.api.Deployment; |
@@ -52,9 +51,8 @@ import org.junit.Test; | @@ -52,9 +51,8 @@ import org.junit.Test; | ||
52 | import org.junit.runner.RunWith; | 51 | import org.junit.runner.RunWith; |
53 | 52 | ||
54 | import test.Tests; | 53 | import test.Tests; |
55 | - | ||
56 | -import br.gov.frameworkdemoiselle.internal.context.ContextManager; | ||
57 | -import br.gov.frameworkdemoiselle.internal.context.ManagedContext; | 54 | +import br.gov.frameworkdemoiselle.context.RequestContext; |
55 | +import br.gov.frameworkdemoiselle.util.Beans; | ||
58 | 56 | ||
59 | @RunWith(Arquillian.class) | 57 | @RunWith(Arquillian.class) |
60 | public class TransactionRollbackTest { | 58 | public class TransactionRollbackTest { |
@@ -76,12 +74,14 @@ public class TransactionRollbackTest { | @@ -76,12 +74,14 @@ public class TransactionRollbackTest { | ||
76 | 74 | ||
77 | @Before | 75 | @Before |
78 | public void activeContext() { | 76 | public void activeContext() { |
79 | - ContextManager.activate(ManagedContext.class, RequestScoped.class); | 77 | + RequestContext ctx = Beans.getReference(RequestContext.class); |
78 | + ctx.activate(); | ||
80 | } | 79 | } |
81 | 80 | ||
82 | @After | 81 | @After |
83 | public void deactiveContext() { | 82 | public void deactiveContext() { |
84 | - ContextManager.deactivate(ManagedContext.class, RequestScoped.class); | 83 | + RequestContext ctx = Beans.getReference(RequestContext.class); |
84 | + ctx.deactivate(); | ||
85 | } | 85 | } |
86 | 86 | ||
87 | @Test | 87 | @Test |
impl/extension/jpa/src/main/java/br/gov/frameworkdemoiselle/annotation/PersistenceScoped.java
0 → 100644
@@ -0,0 +1,56 @@ | @@ -0,0 +1,56 @@ | ||
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.annotation; | ||
38 | + | ||
39 | +import static java.lang.annotation.ElementType.FIELD; | ||
40 | +import static java.lang.annotation.ElementType.METHOD; | ||
41 | +import static java.lang.annotation.ElementType.TYPE; | ||
42 | +import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
43 | + | ||
44 | +import java.lang.annotation.Inherited; | ||
45 | +import java.lang.annotation.Retention; | ||
46 | +import java.lang.annotation.Target; | ||
47 | + | ||
48 | +import javax.enterprise.context.NormalScope; | ||
49 | + | ||
50 | +@Inherited | ||
51 | +@Target({ METHOD, TYPE, FIELD }) | ||
52 | +@Retention(RUNTIME) | ||
53 | +@NormalScope | ||
54 | +public @interface PersistenceScoped { | ||
55 | + | ||
56 | +} |
impl/extension/jpa/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/EntityManagerConfig.java
@@ -52,7 +52,7 @@ import br.gov.frameworkdemoiselle.util.Strings; | @@ -52,7 +52,7 @@ import br.gov.frameworkdemoiselle.util.Strings; | ||
52 | public class EntityManagerConfig implements Serializable { | 52 | public class EntityManagerConfig implements Serializable { |
53 | 53 | ||
54 | private static final long serialVersionUID = 1L; | 54 | private static final long serialVersionUID = 1L; |
55 | - | 55 | + |
56 | /** | 56 | /** |
57 | * @deprecated | 57 | * @deprecated |
58 | */ | 58 | */ |
@@ -62,6 +62,9 @@ public class EntityManagerConfig implements Serializable { | @@ -62,6 +62,9 @@ public class EntityManagerConfig implements Serializable { | ||
62 | 62 | ||
63 | @Name("default.unit.name") | 63 | @Name("default.unit.name") |
64 | private String defaultPersistenceUnitName; | 64 | private String defaultPersistenceUnitName; |
65 | + | ||
66 | + @Name("entitymanager.scope") | ||
67 | + private String entityManagerScope = "request"; | ||
65 | 68 | ||
66 | /** | 69 | /** |
67 | * Getter for persistence unit name. | 70 | * Getter for persistence unit name. |
@@ -92,4 +95,16 @@ public class EntityManagerConfig implements Serializable { | @@ -92,4 +95,16 @@ public class EntityManagerConfig implements Serializable { | ||
92 | 95 | ||
93 | return defaultPersistenceUnitName; | 96 | return defaultPersistenceUnitName; |
94 | } | 97 | } |
98 | + | ||
99 | + | ||
100 | + public String getEntityManagerScope() { | ||
101 | + return entityManagerScope; | ||
102 | + } | ||
103 | + | ||
104 | + | ||
105 | + public void setEntityManagerScope(String entityManagerScope) { | ||
106 | + this.entityManagerScope = entityManagerScope; | ||
107 | + } | ||
108 | + | ||
109 | + | ||
95 | } | 110 | } |
impl/extension/jpa/src/main/java/br/gov/frameworkdemoiselle/internal/context/PersistenceContext.java
0 → 100644
@@ -0,0 +1,12 @@ | @@ -0,0 +1,12 @@ | ||
1 | +package br.gov.frameworkdemoiselle.internal.context; | ||
2 | + | ||
3 | +import java.lang.annotation.Annotation; | ||
4 | + | ||
5 | + | ||
6 | +public class PersistenceContext extends AbstractThreadLocalContext { | ||
7 | + | ||
8 | + public PersistenceContext(Class<? extends Annotation> scope) { | ||
9 | + super(scope); | ||
10 | + } | ||
11 | + | ||
12 | +} |
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/JsfBootstrap.java
@@ -41,10 +41,11 @@ import javax.enterprise.inject.spi.AfterBeanDiscovery; | @@ -41,10 +41,11 @@ import javax.enterprise.inject.spi.AfterBeanDiscovery; | ||
41 | import javax.enterprise.inject.spi.AfterDeploymentValidation; | 41 | import javax.enterprise.inject.spi.AfterDeploymentValidation; |
42 | import javax.enterprise.inject.spi.Extension; | 42 | import javax.enterprise.inject.spi.Extension; |
43 | 43 | ||
44 | -import br.gov.frameworkdemoiselle.annotation.ViewScoped; | ||
45 | -import br.gov.frameworkdemoiselle.internal.context.ContextManager; | ||
46 | -import br.gov.frameworkdemoiselle.internal.context.ViewContext; | 44 | +import br.gov.frameworkdemoiselle.context.ViewContext; |
45 | +import br.gov.frameworkdemoiselle.internal.context.ContextManager2; | ||
46 | +import br.gov.frameworkdemoiselle.internal.context.FacesViewContextImpl; | ||
47 | import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess; | 47 | import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess; |
48 | +import br.gov.frameworkdemoiselle.util.Beans; | ||
48 | 49 | ||
49 | public class JsfBootstrap implements Extension { | 50 | public class JsfBootstrap implements Extension { |
50 | 51 | ||
@@ -54,17 +55,19 @@ public class JsfBootstrap implements Extension { | @@ -54,17 +55,19 @@ public class JsfBootstrap implements Extension { | ||
54 | 55 | ||
55 | public void storeContexts(@Observes final AfterBeanDiscovery event) { | 56 | public void storeContexts(@Observes final AfterBeanDiscovery event) { |
56 | //Registra o ViewContext para controlar o escopo ViewScoped. | 57 | //Registra o ViewContext para controlar o escopo ViewScoped. |
57 | - ContextManager.initialize(event); | ||
58 | - ContextManager.add(new ViewContext(), event); | 58 | + ContextManager2 contextManager = Beans.getReference(ContextManager2.class); |
59 | + contextManager.addCustomContext(new FacesViewContextImpl()); | ||
59 | } | 60 | } |
60 | 61 | ||
61 | public void addContexts(@Observes final AfterDeploymentValidation event) { | 62 | public void addContexts(@Observes final AfterDeploymentValidation event) { |
62 | //Ativa o ViewContext | 63 | //Ativa o ViewContext |
63 | - ContextManager.activate(ViewContext.class, ViewScoped.class); | 64 | + ViewContext ctx = Beans.getReference(FacesViewContextImpl.class); |
65 | + ctx.activate(); | ||
64 | } | 66 | } |
65 | 67 | ||
66 | public void removeContexts(@Observes AfterShutdownProccess event) { | 68 | public void removeContexts(@Observes AfterShutdownProccess event) { |
67 | //Desativa o ViewContext | 69 | //Desativa o ViewContext |
68 | - ContextManager.deactivate(ViewContext.class, ViewScoped.class); | 70 | + ViewContext ctx = Beans.getReference(FacesViewContextImpl.class); |
71 | + ctx.deactivate(); | ||
69 | } | 72 | } |
70 | } | 73 | } |
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/context/FacesViewContextImpl.java
0 → 100644
@@ -0,0 +1,81 @@ | @@ -0,0 +1,81 @@ | ||
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.context; | ||
38 | + | ||
39 | +import java.util.Map; | ||
40 | + | ||
41 | +import javax.faces.component.UIViewRoot; | ||
42 | +import javax.faces.context.FacesContext; | ||
43 | + | ||
44 | +import br.gov.frameworkdemoiselle.annotation.Priority; | ||
45 | +import br.gov.frameworkdemoiselle.annotation.ViewScoped; | ||
46 | +import br.gov.frameworkdemoiselle.context.ViewContext; | ||
47 | +import br.gov.frameworkdemoiselle.util.Faces; | ||
48 | + | ||
49 | +/** | ||
50 | + * | ||
51 | + * This {@link ViewContext} implementation uses a map provided | ||
52 | + * by {@link UIViewRoot#getViewMap()} as a store. Any beans stored on | ||
53 | + * this store are kept as long as the view is still active. | ||
54 | + * | ||
55 | + * @author serpro | ||
56 | + * | ||
57 | + */ | ||
58 | +@Priority(Priority.L2_PRIORITY) | ||
59 | +public class FacesViewContextImpl extends AbstractCustomContext implements ViewContext { | ||
60 | + | ||
61 | + public FacesViewContextImpl() { | ||
62 | + super(ViewScoped.class); | ||
63 | + } | ||
64 | + | ||
65 | + @Override | ||
66 | + protected boolean isStoreInitialized() { | ||
67 | + return FacesContext.getCurrentInstance()!=null; | ||
68 | + } | ||
69 | + | ||
70 | + @Override | ||
71 | + protected Store getStore() { | ||
72 | + Map<String, Object> viewMap = Faces.getViewMap(); | ||
73 | + String key = Store.class.getName(); | ||
74 | + | ||
75 | + if (!viewMap.containsKey(key)) { | ||
76 | + viewMap.put(key, createStore()); | ||
77 | + } | ||
78 | + | ||
79 | + return (Store) viewMap.get(key); | ||
80 | + } | ||
81 | +} |
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/context/ViewContext.java
@@ -1,68 +0,0 @@ | @@ -1,68 +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.context; | ||
38 | - | ||
39 | -import java.util.Map; | ||
40 | - | ||
41 | -import javax.faces.context.FacesContext; | ||
42 | - | ||
43 | -import br.gov.frameworkdemoiselle.annotation.ViewScoped; | ||
44 | -import br.gov.frameworkdemoiselle.util.Faces; | ||
45 | - | ||
46 | -public class ViewContext extends AbstractCustomContext { | ||
47 | - | ||
48 | - public ViewContext() { | ||
49 | - super(ViewScoped.class); | ||
50 | - } | ||
51 | - | ||
52 | - @Override | ||
53 | - protected boolean isStoreInitialized() { | ||
54 | - return FacesContext.getCurrentInstance()!=null; | ||
55 | - } | ||
56 | - | ||
57 | - @Override | ||
58 | - protected Store getStore() { | ||
59 | - Map<String, Object> viewMap = Faces.getViewMap(); | ||
60 | - String key = Store.class.getName(); | ||
61 | - | ||
62 | - if (!viewMap.containsKey(key)) { | ||
63 | - viewMap.put(key, createStore()); | ||
64 | - } | ||
65 | - | ||
66 | - return (Store) viewMap.get(key); | ||
67 | - } | ||
68 | -} |
impl/extension/se/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/SeBootstrap.java
@@ -36,41 +36,35 @@ | @@ -36,41 +36,35 @@ | ||
36 | */ | 36 | */ |
37 | package br.gov.frameworkdemoiselle.internal.bootstrap; | 37 | package br.gov.frameworkdemoiselle.internal.bootstrap; |
38 | 38 | ||
39 | -import javax.enterprise.context.ConversationScoped; | ||
40 | -import javax.enterprise.context.RequestScoped; | ||
41 | -import javax.enterprise.context.SessionScoped; | ||
42 | import javax.enterprise.event.Observes; | 39 | import javax.enterprise.event.Observes; |
43 | -import javax.enterprise.inject.spi.AfterBeanDiscovery; | ||
44 | import javax.enterprise.inject.spi.AfterDeploymentValidation; | 40 | import javax.enterprise.inject.spi.AfterDeploymentValidation; |
45 | import javax.enterprise.inject.spi.Extension; | 41 | import javax.enterprise.inject.spi.Extension; |
46 | 42 | ||
47 | -import br.gov.frameworkdemoiselle.annotation.ViewScoped; | ||
48 | -import br.gov.frameworkdemoiselle.internal.context.ContextManager; | ||
49 | -import br.gov.frameworkdemoiselle.internal.context.ThreadLocalContext; | 43 | +import br.gov.frameworkdemoiselle.context.RequestContext; |
44 | +import br.gov.frameworkdemoiselle.context.SessionContext; | ||
45 | +import br.gov.frameworkdemoiselle.context.ViewContext; | ||
50 | import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess; | 46 | import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess; |
47 | +import br.gov.frameworkdemoiselle.util.Beans; | ||
51 | 48 | ||
52 | public class SeBootstrap implements Extension { | 49 | public class SeBootstrap implements Extension { |
53 | 50 | ||
54 | - public void storeContexts(@Observes final AfterBeanDiscovery event) { | ||
55 | - ContextManager.initialize(event); | ||
56 | - | ||
57 | - ContextManager.add(new ThreadLocalContext(ViewScoped.class), event); | ||
58 | - ContextManager.add(new ThreadLocalContext(SessionScoped.class), event); | ||
59 | - ContextManager.add(new ThreadLocalContext(ConversationScoped.class), event); | ||
60 | - ContextManager.add(new ThreadLocalContext(RequestScoped.class), event); | ||
61 | - } | ||
62 | - | ||
63 | public void addContexts(@Observes final AfterDeploymentValidation event) { | 51 | public void addContexts(@Observes final AfterDeploymentValidation event) { |
64 | - ContextManager.activate(ThreadLocalContext.class, ViewScoped.class); | ||
65 | - ContextManager.activate(ThreadLocalContext.class, SessionScoped.class); | ||
66 | - ContextManager.activate(ThreadLocalContext.class, ConversationScoped.class); | ||
67 | - ContextManager.activate(ThreadLocalContext.class, RequestScoped.class); | 52 | + RequestContext requestContext = Beans.getReference(RequestContext.class); |
53 | + SessionContext sessionContext = Beans.getReference(SessionContext.class); | ||
54 | + ViewContext viewContext = Beans.getReference(ViewContext.class); | ||
55 | + | ||
56 | + requestContext.activate(); | ||
57 | + sessionContext.activate(); | ||
58 | + viewContext.activate(); | ||
68 | } | 59 | } |
69 | 60 | ||
70 | public void removeContexts(@Observes AfterShutdownProccess event) { | 61 | public void removeContexts(@Observes AfterShutdownProccess event) { |
71 | - ContextManager.deactivate(ThreadLocalContext.class, ViewScoped.class); | ||
72 | - ContextManager.deactivate(ThreadLocalContext.class, SessionScoped.class); | ||
73 | - ContextManager.deactivate(ThreadLocalContext.class, ConversationScoped.class); | ||
74 | - ContextManager.deactivate(ThreadLocalContext.class, RequestScoped.class); | 62 | + RequestContext requestContext = Beans.getReference(RequestContext.class); |
63 | + SessionContext sessionContext = Beans.getReference(SessionContext.class); | ||
64 | + ViewContext viewContext = Beans.getReference(ViewContext.class); | ||
65 | + | ||
66 | + requestContext.deactivate(); | ||
67 | + sessionContext.deactivate(); | ||
68 | + viewContext.deactivate(); | ||
75 | } | 69 | } |
76 | } | 70 | } |