Commit 0b5ebd8c699b35134441140f057a229f760c79a0
Exists in
master
Merge remote branch 'origin/2.4.0' into 2.4.0
Conflicts: impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ManagementBootstrap.java impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/Management.java impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/DynamicMBeanProxy.java impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/JMXManagementExtension.java impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/NotificationEventListener.java impl/extension/jsf/src/test/java/test/Tests.java
Showing
47 changed files
with
1237 additions
and
836 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/context/CustomContext.java
0 → 100644
| ... | ... | @@ -0,0 +1,62 @@ |
| 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.context; | |
| 38 | + | |
| 39 | +import javax.enterprise.context.spi.Context; | |
| 40 | + | |
| 41 | +/** | |
| 42 | + * | |
| 43 | + * Base interface for contexts managed by the framework. | |
| 44 | + * | |
| 45 | + * @author serpro | |
| 46 | + * | |
| 47 | + */ | |
| 48 | +public interface CustomContext extends Context { | |
| 49 | + | |
| 50 | + /** | |
| 51 | + * Activates a custom context | |
| 52 | + * | |
| 53 | + * @return <code>true</code> if context was activated, <code>false</code> if there was already another active | |
| 54 | + * context for the same scope and the activation of this scope failed. | |
| 55 | + */ | |
| 56 | + boolean activate(); | |
| 57 | + | |
| 58 | + /** | |
| 59 | + * Deactivates this context, it will clear all beans stored on this context. | |
| 60 | + */ | |
| 61 | + void deactivate(); | |
| 62 | +} | ... | ... |
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 | 42 | import java.util.Iterator; |
| 43 | 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 | 45 | import javax.enterprise.event.Observes; |
| 49 | -import javax.enterprise.inject.spi.AfterBeanDiscovery; | |
| 50 | 46 | import javax.enterprise.inject.spi.AnnotatedMethod; |
| 51 | 47 | import javax.enterprise.inject.spi.AnnotatedType; |
| 52 | 48 | import javax.enterprise.inject.spi.Extension; |
| ... | ... | @@ -55,9 +51,9 @@ import javax.enterprise.inject.spi.ProcessAnnotatedType; |
| 55 | 51 | import org.slf4j.Logger; |
| 56 | 52 | |
| 57 | 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.context.RequestContext; | |
| 55 | +import br.gov.frameworkdemoiselle.context.SessionContext; | |
| 56 | +import br.gov.frameworkdemoiselle.context.ViewContext; | |
| 61 | 57 | import br.gov.frameworkdemoiselle.internal.implementation.AnnotatedMethodProcessor; |
| 62 | 58 | import br.gov.frameworkdemoiselle.util.Beans; |
| 63 | 59 | import br.gov.frameworkdemoiselle.util.NameQualifier; |
| ... | ... | @@ -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 | 109 | // Caso este bootstrap rode antes do CoreBootstrap. Não há problemas em chamar este método várias vezes, ele |
| 114 | 110 | // ignora chamadas adicionais. |
| 115 | 111 | ContextManager.initialize(event); |
| ... | ... | @@ -119,7 +115,7 @@ public abstract class AbstractLifecycleBootstrap<A extends Annotation> implement |
| 119 | 115 | ContextManager.add(new ThreadLocalContext(SessionScoped.class), event); |
| 120 | 116 | ContextManager.add(new ThreadLocalContext(ConversationScoped.class), event); |
| 121 | 117 | ContextManager.add(new ThreadLocalContext(RequestScoped.class), event); |
| 122 | - } | |
| 118 | + }*/ | |
| 123 | 119 | |
| 124 | 120 | @SuppressWarnings({ "unchecked", "rawtypes" }) |
| 125 | 121 | protected synchronized void proccessEvent() { |
| ... | ... | @@ -127,12 +123,15 @@ public abstract class AbstractLifecycleBootstrap<A extends Annotation> implement |
| 127 | 123 | |
| 128 | 124 | Collections.sort(processors); |
| 129 | 125 | Exception failure = null; |
| 126 | + | |
| 127 | + RequestContext tempRequestContext = Beans.getReference(RequestContext.class); | |
| 128 | + SessionContext tempSessionContext = Beans.getReference(SessionContext.class); | |
| 129 | + ViewContext tempViewContext = Beans.getReference(ViewContext.class); | |
| 130 | 130 | |
| 131 | 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 | 136 | registered = true; |
| 138 | 137 | } |
| ... | ... | @@ -155,10 +154,9 @@ public abstract class AbstractLifecycleBootstrap<A extends Annotation> implement |
| 155 | 154 | } |
| 156 | 155 | |
| 157 | 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 | 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 | 39 | import java.util.Locale; |
| 40 | 40 | |
| 41 | 41 | import javax.enterprise.event.Observes; |
| 42 | -import javax.enterprise.inject.spi.AfterBeanDiscovery; | |
| 43 | 42 | import javax.enterprise.inject.spi.AfterDeploymentValidation; |
| 44 | 43 | import javax.enterprise.inject.spi.BeanManager; |
| 45 | 44 | import javax.enterprise.inject.spi.BeforeBeanDiscovery; |
| ... | ... | @@ -48,9 +47,6 @@ import javax.enterprise.inject.spi.Extension; |
| 48 | 47 | |
| 49 | 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 | 50 | import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; |
| 55 | 51 | import br.gov.frameworkdemoiselle.util.Beans; |
| 56 | 52 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
| ... | ... | @@ -60,7 +56,7 @@ public class CoreBootstrap implements Extension { |
| 60 | 56 | private Logger logger; |
| 61 | 57 | |
| 62 | 58 | private transient ResourceBundle bundle; |
| 63 | - | |
| 59 | + | |
| 64 | 60 | private Logger getLogger() { |
| 65 | 61 | if (this.logger == null) { |
| 66 | 62 | this.logger = LoggerProducer.create(CoreBootstrap.class); |
| ... | ... | @@ -83,18 +79,7 @@ public class CoreBootstrap implements Extension { |
| 83 | 79 | Beans.setBeanManager(beanManager); |
| 84 | 80 | getLogger().info(getBundle().getString("setting-up-bean-manager", Beans.class.getCanonicalName())); |
| 85 | 81 | } |
| 86 | - | |
| 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 | - } | |
| 93 | - | |
| 94 | - public void terminateCustomContexts(@Observes final BeforeShutdown event) { | |
| 95 | - ContextManager.shutdown(); | |
| 96 | - } | |
| 97 | - | |
| 82 | + | |
| 98 | 83 | public void takeOff(@Observes final AfterDeploymentValidation event) { |
| 99 | 84 | getLogger().info(getBundle().getString("taking-off")); |
| 100 | 85 | } | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/CustomContextBootstrap.java
0 → 100644
| ... | ... | @@ -0,0 +1,90 @@ |
| 1 | +package br.gov.frameworkdemoiselle.internal.bootstrap; | |
| 2 | + | |
| 3 | +import java.util.ArrayList; | |
| 4 | +import java.util.List; | |
| 5 | + | |
| 6 | +import javax.enterprise.event.Observes; | |
| 7 | +import javax.enterprise.inject.spi.AfterBeanDiscovery; | |
| 8 | +import javax.enterprise.inject.spi.AfterDeploymentValidation; | |
| 9 | +import javax.enterprise.inject.spi.Extension; | |
| 10 | + | |
| 11 | +import br.gov.frameworkdemoiselle.context.CustomContext; | |
| 12 | +import br.gov.frameworkdemoiselle.context.StaticContext; | |
| 13 | +import br.gov.frameworkdemoiselle.internal.context.CustomContextProducer; | |
| 14 | +import br.gov.frameworkdemoiselle.internal.context.RequestContextImpl; | |
| 15 | +import br.gov.frameworkdemoiselle.internal.context.SessionContextImpl; | |
| 16 | +import br.gov.frameworkdemoiselle.internal.context.StaticContextImpl; | |
| 17 | +import br.gov.frameworkdemoiselle.internal.context.ThreadLocalViewContextImpl; | |
| 18 | +import br.gov.frameworkdemoiselle.util.Beans; | |
| 19 | + | |
| 20 | +/** | |
| 21 | + * This portable extension registers and starts custom contexts used by | |
| 22 | + * the framework. | |
| 23 | + * | |
| 24 | + * @author serpro | |
| 25 | + * | |
| 26 | + */ | |
| 27 | +public class CustomContextBootstrap implements Extension{ | |
| 28 | + | |
| 29 | + private List<CustomContext> contexts; | |
| 30 | + | |
| 31 | + /*private Logger logger; | |
| 32 | + | |
| 33 | + private transient ResourceBundle bundle; | |
| 34 | + | |
| 35 | + private Logger getLogger() { | |
| 36 | + if (this.logger == null) { | |
| 37 | + this.logger = LoggerProducer.create(CoreBootstrap.class); | |
| 38 | + } | |
| 39 | + | |
| 40 | + return this.logger; | |
| 41 | + } | |
| 42 | + | |
| 43 | + private ResourceBundle getBundle() { | |
| 44 | + if (bundle == null) { | |
| 45 | + bundle = new ResourceBundle("demoiselle-core-bundle", Locale.getDefault()); | |
| 46 | + } | |
| 47 | + | |
| 48 | + return bundle; | |
| 49 | + }*/ | |
| 50 | + | |
| 51 | + public void initializeContexts(@Observes AfterBeanDiscovery event){ | |
| 52 | + //Cadastra os contextos contidos no demoiselle-core | |
| 53 | + if (contexts==null || contexts.isEmpty()){ | |
| 54 | + CustomContext ctx; | |
| 55 | + | |
| 56 | + contexts = new ArrayList<CustomContext>(); | |
| 57 | + | |
| 58 | + ctx = new RequestContextImpl(); | |
| 59 | + contexts.add(ctx); | |
| 60 | + | |
| 61 | + ctx = new SessionContextImpl(); | |
| 62 | + contexts.add(ctx); | |
| 63 | + | |
| 64 | + ctx = new StaticContextImpl(); | |
| 65 | + contexts.add(ctx); | |
| 66 | + | |
| 67 | + ctx = new ThreadLocalViewContextImpl(); | |
| 68 | + contexts.add(ctx); | |
| 69 | + | |
| 70 | + for (CustomContext c : contexts){ | |
| 71 | + event.addContext(c); | |
| 72 | + } | |
| 73 | + } | |
| 74 | + | |
| 75 | + //Ativa um contexto para gerenciar o StaticScope, um escopo criado para gerenciar classes de configuração. | |
| 76 | + for (CustomContext ctx : contexts){ | |
| 77 | + if (ctx instanceof StaticContext){ | |
| 78 | + StaticContext staticContext = (StaticContext)ctx; | |
| 79 | + staticContext.activate(); | |
| 80 | + break; | |
| 81 | + } | |
| 82 | + } | |
| 83 | + } | |
| 84 | + | |
| 85 | + public void storeContexts(@Observes AfterDeploymentValidation event){ | |
| 86 | + CustomContextProducer producer = Beans.getReference(CustomContextProducer.class); | |
| 87 | + producer.addRegisteredContexts(contexts); | |
| 88 | + } | |
| 89 | + | |
| 90 | +} | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ManagementBootstrap.java
| ... | ... | @@ -44,7 +44,6 @@ import java.util.Locale; |
| 44 | 44 | import java.util.Set; |
| 45 | 45 | |
| 46 | 46 | import javax.enterprise.event.Observes; |
| 47 | -import javax.enterprise.inject.spi.AfterBeanDiscovery; | |
| 48 | 47 | import javax.enterprise.inject.spi.AfterDeploymentValidation; |
| 49 | 48 | import javax.enterprise.inject.spi.AnnotatedType; |
| 50 | 49 | import javax.enterprise.inject.spi.Bean; |
| ... | ... | @@ -53,8 +52,6 @@ import javax.enterprise.inject.spi.Extension; |
| 53 | 52 | import javax.enterprise.inject.spi.ProcessAnnotatedType; |
| 54 | 53 | |
| 55 | 54 | import br.gov.frameworkdemoiselle.DemoiselleException; |
| 56 | -import br.gov.frameworkdemoiselle.internal.context.ContextManager; | |
| 57 | -import br.gov.frameworkdemoiselle.internal.context.ManagedContext; | |
| 58 | 55 | import br.gov.frameworkdemoiselle.internal.implementation.ManagedType; |
| 59 | 56 | import br.gov.frameworkdemoiselle.internal.implementation.Management; |
| 60 | 57 | import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess; |
| ... | ... | @@ -76,10 +73,10 @@ public class ManagementBootstrap implements Extension { |
| 76 | 73 | } |
| 77 | 74 | } |
| 78 | 75 | |
| 79 | - public void activateContexts(@Observes final AfterBeanDiscovery event) { | |
| 76 | + /*public void activateContexts(@Observes final AfterBeanDiscovery event) { | |
| 80 | 77 | ContextManager.initialize(event); |
| 81 | 78 | ContextManager.add(new ManagedContext(), event); |
| 82 | - } | |
| 79 | + }*/ | |
| 83 | 80 | |
| 84 | 81 | @SuppressWarnings("unchecked") |
| 85 | 82 | public void registerAvailableManagedTypes(@Observes final AfterDeploymentValidation event, BeanManager beanManager) { | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/AbstractCustomContext.java
| ... | ... | @@ -39,20 +39,34 @@ package br.gov.frameworkdemoiselle.internal.context; |
| 39 | 39 | import java.lang.annotation.Annotation; |
| 40 | 40 | import java.util.Collections; |
| 41 | 41 | import java.util.HashMap; |
| 42 | +import java.util.Locale; | |
| 42 | 43 | import java.util.Map; |
| 43 | 44 | |
| 44 | 45 | import javax.enterprise.context.ContextNotActiveException; |
| 46 | +import javax.enterprise.context.spi.Context; | |
| 45 | 47 | import javax.enterprise.context.spi.Contextual; |
| 46 | 48 | import javax.enterprise.context.spi.CreationalContext; |
| 47 | 49 | import javax.enterprise.inject.spi.Bean; |
| 50 | +import javax.enterprise.inject.spi.BeanManager; | |
| 51 | + | |
| 52 | +import org.slf4j.Logger; | |
| 53 | + | |
| 54 | +import br.gov.frameworkdemoiselle.context.CustomContext; | |
| 55 | +import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; | |
| 56 | +import br.gov.frameworkdemoiselle.util.Beans; | |
| 57 | +import br.gov.frameworkdemoiselle.util.ResourceBundle; | |
| 48 | 58 | |
| 49 | 59 | public abstract class AbstractCustomContext implements CustomContext { |
| 50 | 60 | |
| 51 | 61 | private boolean active; |
| 52 | 62 | |
| 53 | 63 | private final Class<? extends Annotation> scope; |
| 64 | + | |
| 65 | + private Logger logger; | |
| 66 | + | |
| 67 | + private transient ResourceBundle bundle; | |
| 54 | 68 | |
| 55 | - public AbstractCustomContext(final Class<? extends Annotation> scope) { | |
| 69 | + AbstractCustomContext(final Class<? extends Annotation> scope) { | |
| 56 | 70 | this.scope = scope; |
| 57 | 71 | this.active = false; |
| 58 | 72 | } |
| ... | ... | @@ -97,14 +111,44 @@ public abstract class AbstractCustomContext implements CustomContext { |
| 97 | 111 | return this.active; |
| 98 | 112 | } |
| 99 | 113 | |
| 100 | - public void setActive(boolean active) { | |
| 101 | - if (!active && this.active) { | |
| 102 | - // Limpando contexto | |
| 114 | + @Override | |
| 115 | + public boolean activate() { | |
| 116 | + if (!this.active){ | |
| 117 | + BeanManager beanManager = Beans.getBeanManager(); | |
| 118 | + if (beanManager!=null){ | |
| 119 | + try{ | |
| 120 | + Context ctx = beanManager.getContext(this.getScope()); | |
| 121 | + if (ctx!=null){ | |
| 122 | + getLogger().debug( getBundle().getString("custom-context-already-activated" , this.getClass().getCanonicalName() , this.getScope().getSimpleName() , ctx.getClass().getCanonicalName() ) ); | |
| 123 | + } | |
| 124 | + } | |
| 125 | + catch(ContextNotActiveException ce){ | |
| 126 | + this.active = true; | |
| 127 | + getLogger().debug( getBundle().getString("custom-context-was-activated" , this.getClass().getCanonicalName() , this.getScope().getSimpleName() ) ); | |
| 128 | + } | |
| 129 | + } | |
| 130 | + else{ | |
| 131 | + this.active = true; | |
| 132 | + getLogger().debug( getBundle().getString("custom-context-was-activated" , this.getClass().getCanonicalName() , this.getScope().getSimpleName() ) ); | |
| 133 | + } | |
| 134 | + } | |
| 135 | + | |
| 136 | + return this.active; | |
| 137 | + } | |
| 138 | + | |
| 139 | + @Override | |
| 140 | + public void deactivate(){ | |
| 141 | + if (this.active){ | |
| 103 | 142 | if (isStoreInitialized()){ |
| 104 | 143 | getStore().clear(); |
| 105 | 144 | } |
| 145 | + | |
| 146 | + this.active = false; | |
| 147 | + | |
| 148 | + Logger logger = getLogger(); | |
| 149 | + ResourceBundle bundle = getBundle(); | |
| 150 | + logger.debug( bundle.getString("custom-context-was-deactivated" , this.getClass().getCanonicalName() , this.getScope().getSimpleName() ) ); | |
| 106 | 151 | } |
| 107 | - this.active = active; | |
| 108 | 152 | } |
| 109 | 153 | |
| 110 | 154 | @Override |
| ... | ... | @@ -115,6 +159,22 @@ public abstract class AbstractCustomContext implements CustomContext { |
| 115 | 159 | protected static Store createStore() { |
| 116 | 160 | return new Store(); |
| 117 | 161 | } |
| 162 | + | |
| 163 | + private ResourceBundle getBundle(){ | |
| 164 | + if (bundle==null){ | |
| 165 | + bundle = new ResourceBundle("demoiselle-core-bundle", Locale.getDefault()); | |
| 166 | + } | |
| 167 | + | |
| 168 | + return bundle; | |
| 169 | + } | |
| 170 | + | |
| 171 | + private Logger getLogger(){ | |
| 172 | + if (logger==null){ | |
| 173 | + logger = LoggerProducer.create(this.getClass()); | |
| 174 | + } | |
| 175 | + | |
| 176 | + return logger; | |
| 177 | + } | |
| 118 | 178 | |
| 119 | 179 | static class Store { |
| 120 | 180 | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/AbstractStaticContext.java
0 → 100644
| ... | ... | @@ -0,0 +1,79 @@ |
| 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 abstract class AbstractStaticContext extends AbstractCustomContext { | |
| 60 | + | |
| 61 | + private final static Store store = createStore(); | |
| 62 | + | |
| 63 | + /** | |
| 64 | + * Constructs this context to control the provided scope | |
| 65 | + */ | |
| 66 | + AbstractStaticContext(Class<? extends Annotation> scope) { | |
| 67 | + super(scope); | |
| 68 | + } | |
| 69 | + | |
| 70 | + @Override | |
| 71 | + protected Store getStore() { | |
| 72 | + return store; | |
| 73 | + } | |
| 74 | + | |
| 75 | + @Override | |
| 76 | + protected boolean isStoreInitialized() { | |
| 77 | + return store!=null; | |
| 78 | + } | |
| 79 | +} | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/AbstractThreadLocalContext.java
0 → 100644
| ... | ... | @@ -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,360 +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.lang.annotation.Annotation; | |
| 40 | -import java.util.ArrayList; | |
| 41 | -import java.util.Collections; | |
| 42 | -import java.util.HashMap; | |
| 43 | -import java.util.List; | |
| 44 | -import java.util.Locale; | |
| 45 | -import java.util.Map; | |
| 46 | - | |
| 47 | -import javax.enterprise.context.ContextNotActiveException; | |
| 48 | -import javax.enterprise.context.spi.Context; | |
| 49 | -import javax.enterprise.inject.spi.AfterBeanDiscovery; | |
| 50 | -import javax.enterprise.inject.spi.BeanManager; | |
| 51 | - | |
| 52 | -import org.slf4j.Logger; | |
| 53 | - | |
| 54 | -import br.gov.frameworkdemoiselle.DemoiselleException; | |
| 55 | -import br.gov.frameworkdemoiselle.annotation.StaticScoped; | |
| 56 | -import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; | |
| 57 | -import br.gov.frameworkdemoiselle.util.Beans; | |
| 58 | -import br.gov.frameworkdemoiselle.util.ResourceBundle; | |
| 59 | - | |
| 60 | -/** | |
| 61 | - * <p> | |
| 62 | - * Manage custom contexts relevant to Demoiselle operations. | |
| 63 | - * </p> | |
| 64 | - * <p> | |
| 65 | - * When starting, the ContextManager must be initialized by calling {@link #initialize(AfterBeanDiscovery event)} inside | |
| 66 | - * any methods observing the {@link AfterBeanDiscovery} event. Upon initialization a {@link StaticContext} will be | |
| 67 | - * created to handle {@link StaticScoped} beans (but not activated, you must call | |
| 68 | - * {@link #activate(Class customContextClass, Class scope)} to activate this context). | |
| 69 | - * </p> | |
| 70 | - * <p> | |
| 71 | - * If an extension wants to manage another custom context, it must first call | |
| 72 | - * {@link #add(CustomContext context, AfterBeanDiscovery event)} to add it's context to the list of managed contexts and | |
| 73 | - * then call {@link #activate(Class customContextClass, Class scope)} whenever it wants to activate this added context | |
| 74 | - * (contexts added through the {@link #add(CustomContext context, AfterBeanDiscovery event)} method are also not | |
| 75 | - * activated upon adding). | |
| 76 | - * </p> | |
| 77 | - * | |
| 78 | - * @author SERPRO | |
| 79 | - */ | |
| 80 | -public final class ContextManager { | |
| 81 | - | |
| 82 | - private static final Map<ClassLoader, List<CustomContextCounter>> contextsCache = Collections | |
| 83 | - .synchronizedMap(new HashMap<ClassLoader, List<CustomContextCounter>>()); | |
| 84 | - | |
| 85 | - private static final Map<ClassLoader, Boolean> initializedCache = Collections | |
| 86 | - .synchronizedMap(new HashMap<ClassLoader, Boolean>()); | |
| 87 | - | |
| 88 | - private ContextManager() { | |
| 89 | - } | |
| 90 | - | |
| 91 | - private synchronized static List<CustomContextCounter> getContexts() { | |
| 92 | - List<CustomContextCounter> contexts = contextsCache.get(getCurrentClassLoader()); | |
| 93 | - | |
| 94 | - if (contexts == null) { | |
| 95 | - contexts = Collections.synchronizedList(new ArrayList<CustomContextCounter>()); | |
| 96 | - contextsCache.put(getCurrentClassLoader(), contexts); | |
| 97 | - } | |
| 98 | - | |
| 99 | - return contexts; | |
| 100 | - } | |
| 101 | - | |
| 102 | - private synchronized static boolean isInitialized() { | |
| 103 | - Boolean initialized = initializedCache.get(getCurrentClassLoader()); | |
| 104 | - | |
| 105 | - if (initialized == null) { | |
| 106 | - initialized = false; | |
| 107 | - initializedCache.put(getCurrentClassLoader(), initialized); | |
| 108 | - } | |
| 109 | - | |
| 110 | - return initialized; | |
| 111 | - } | |
| 112 | - | |
| 113 | - private static void setInitialized(boolean initialized) { | |
| 114 | - initializedCache.put(getCurrentClassLoader(), initialized); | |
| 115 | - } | |
| 116 | - | |
| 117 | - private static ClassLoader getCurrentClassLoader() { | |
| 118 | - return Thread.currentThread().getContextClassLoader(); | |
| 119 | - } | |
| 120 | - | |
| 121 | - /** | |
| 122 | - * <p> | |
| 123 | - * Initializes this manager and adds the {@link StaticContext} context to the list of managed contexts. Other | |
| 124 | - * contexts must be added before they can be activated. | |
| 125 | - * </p> | |
| 126 | - * <p> | |
| 127 | - * It's OK to call this method multiple times, it will be initialized only once. | |
| 128 | - * </p> | |
| 129 | - * | |
| 130 | - * @param event | |
| 131 | - * The CDI event indicating all beans have been discovered. | |
| 132 | - */ | |
| 133 | - public static void initialize(AfterBeanDiscovery event) { | |
| 134 | - if (isInitialized()) { | |
| 135 | - return; | |
| 136 | - } | |
| 137 | - | |
| 138 | - add(new StaticContext(), event); | |
| 139 | - setInitialized(true); | |
| 140 | - } | |
| 141 | - | |
| 142 | - /** | |
| 143 | - * <p> | |
| 144 | - * Adds a context to the list of managed contexts. | |
| 145 | - * </p> | |
| 146 | - * <p> | |
| 147 | - * A context added through this method will be deactivated before management can start. Only after calling | |
| 148 | - * {@link #activate(Class customContextClass, Class scope)} the context will be activated. | |
| 149 | - * </p> | |
| 150 | - * <p> | |
| 151 | - * Trying to add a context already managed will result in this method call being ignored. | |
| 152 | - * </p> | |
| 153 | - * | |
| 154 | - * @param context | |
| 155 | - * The context to be added | |
| 156 | - * @param event | |
| 157 | - * The CDI event indicating all beans have been discovered. | |
| 158 | - */ | |
| 159 | - public static void add(CustomContext context, AfterBeanDiscovery event) { | |
| 160 | - for (CustomContextCounter contextCounter : getContexts()) { | |
| 161 | - if (contextCounter.isSame(context.getClass(), context.getScope())) { | |
| 162 | - | |
| 163 | - ContextManager.getLogger().trace( | |
| 164 | - ContextManager.getBundle().getString("bootstrap-context-already-managed", | |
| 165 | - context.getClass().getCanonicalName(), context.getScope().getCanonicalName())); | |
| 166 | - | |
| 167 | - return; | |
| 168 | - } | |
| 169 | - } | |
| 170 | - | |
| 171 | - ContextManager.getLogger().trace( | |
| 172 | - ContextManager.getBundle().getString("bootstrap-context-added", context.getClass().getCanonicalName(), | |
| 173 | - context.getScope().getCanonicalName())); | |
| 174 | - | |
| 175 | - context.setActive(false); | |
| 176 | - event.addContext(context); | |
| 177 | - getContexts().add(new CustomContextCounter(context)); | |
| 178 | - } | |
| 179 | - | |
| 180 | - /** | |
| 181 | - * <p> | |
| 182 | - * Activates a managed context. | |
| 183 | - * </p> | |
| 184 | - * <p> | |
| 185 | - * To be activated, a context must fulfill the following requisites: | |
| 186 | - * <ul> | |
| 187 | - * <li>Must be managed by this class (be of type {@link StaticScoped} or be added with | |
| 188 | - * {@link #add(CustomContext context, AfterBeanDiscovery event)})</li> | |
| 189 | - * <li>Must be of a scope not already attached to another active context</li> | |
| 190 | - * </ul> | |
| 191 | - * </p> | |
| 192 | - * | |
| 193 | - * @param customContextClass | |
| 194 | - * Type of context to activate | |
| 195 | - * @param scope | |
| 196 | - * The scope to activate this context for | |
| 197 | - * @return <code>true</code> if there is a managed context of the provided type and scope and no other context is | |
| 198 | - * active for the provided scope, <code>false</code> if there is a managed context of the provided type and | |
| 199 | - * scope but another context is active for the provided scope. | |
| 200 | - * @throws DemoiselleException | |
| 201 | - * if there is no managed context of the provided type and scope. | |
| 202 | - */ | |
| 203 | - public static synchronized void activate(Class<? extends CustomContext> customContextClass, | |
| 204 | - Class<? extends Annotation> scope) { | |
| 205 | - if (!isInitialized()) { | |
| 206 | - throw new DemoiselleException(getBundle().getString("custom-context-manager-not-initialized")); | |
| 207 | - } | |
| 208 | - | |
| 209 | - for (CustomContextCounter context : getContexts()) { | |
| 210 | - if (context.isSame(customContextClass, scope)) { | |
| 211 | - context.activate(); | |
| 212 | - return; | |
| 213 | - } | |
| 214 | - } | |
| 215 | - | |
| 216 | - throw new DemoiselleException(getBundle().getString("custom-context-not-found", | |
| 217 | - customContextClass.getCanonicalName(), scope.getSimpleName())); | |
| 218 | - } | |
| 219 | - | |
| 220 | - /** | |
| 221 | - * <p> | |
| 222 | - * Deactivates a managed context. | |
| 223 | - * </p> | |
| 224 | - * <p> | |
| 225 | - * To be deactivated, a context must fulfill the following requisites: | |
| 226 | - * <ul> | |
| 227 | - * <li>Must be managed by this class (be of type {@link StaticScoped} or be added with | |
| 228 | - * {@link #add(CustomContext context, AfterBeanDiscovery event)})</li> | |
| 229 | - * <li>Must have been activated by a previous call to {@link #activate(Class customContextClass, Class scope)}</li> | |
| 230 | - * <li>This previous call must have returned <code>true</code>. | |
| 231 | - * </ul> | |
| 232 | - * </p> | |
| 233 | - * | |
| 234 | - * @param customContextClass | |
| 235 | - * Type of context to deactivate | |
| 236 | - * @param scope | |
| 237 | - * The scope the context controled when it was active | |
| 238 | - * @return <code>true</code> if there was an active context of this type and scope and it was activated by a | |
| 239 | - * previous call to {@link #activate(Class customContextClass, Class scope)} | |
| 240 | - * @throws DemoiselleException | |
| 241 | - * if there is no managed context of the provided type and scope. | |
| 242 | - */ | |
| 243 | - public static synchronized void deactivate(Class<? extends CustomContext> customContextClass, | |
| 244 | - Class<? extends Annotation> scope) { | |
| 245 | - if (!isInitialized()) { | |
| 246 | - throw new DemoiselleException(getBundle().getString("custom-context-manager-not-initialized")); | |
| 247 | - } | |
| 248 | - | |
| 249 | - for (CustomContextCounter context : getContexts()) { | |
| 250 | - if (context.isSame(customContextClass, scope)) { | |
| 251 | - context.deactivate(); | |
| 252 | - return; | |
| 253 | - } | |
| 254 | - } | |
| 255 | - | |
| 256 | - throw new DemoiselleException(getBundle().getString("custom-context-not-found", | |
| 257 | - customContextClass.getCanonicalName(), scope.getSimpleName())); | |
| 258 | - } | |
| 259 | - | |
| 260 | - /** | |
| 261 | - * <p> | |
| 262 | - * This method should be called when the application is shutting down. | |
| 263 | - * </p> | |
| 264 | - */ | |
| 265 | - public static synchronized void shutdown() { | |
| 266 | - for (CustomContextCounter context : getContexts()) { | |
| 267 | - context.shutdown(); | |
| 268 | - } | |
| 269 | - | |
| 270 | - getContexts().clear(); | |
| 271 | - setInitialized(false); | |
| 272 | - } | |
| 273 | - | |
| 274 | - static Logger getLogger() { | |
| 275 | - return LoggerProducer.create(ContextManager.class); | |
| 276 | - } | |
| 277 | - | |
| 278 | - static ResourceBundle getBundle() { | |
| 279 | - return new ResourceBundle("demoiselle-core-bundle", Locale.getDefault()); | |
| 280 | - } | |
| 281 | -} | |
| 282 | - | |
| 283 | -/** | |
| 284 | - * Class that counts how many attemps to activate and deactivate this context received, avoiding cases where one client | |
| 285 | - * activates given context and another one deactivates it, leaving the first client with no active context before | |
| 286 | - * completion. | |
| 287 | - * | |
| 288 | - * @author serpro | |
| 289 | - */ | |
| 290 | -class CustomContextCounter { | |
| 291 | - | |
| 292 | - private CustomContext context; | |
| 293 | - | |
| 294 | - private int activationCounter = 0; | |
| 295 | - | |
| 296 | - public CustomContextCounter(CustomContext customContext) { | |
| 297 | - this.context = customContext; | |
| 298 | - } | |
| 299 | - | |
| 300 | - public boolean isSame(Class<? extends CustomContext> customContextClass, Class<? extends Annotation> scope) { | |
| 301 | - if (context.getClass().getCanonicalName().equals(customContextClass.getCanonicalName()) | |
| 302 | - && context.getScope().equals(scope)) { | |
| 303 | - return true; | |
| 304 | - } | |
| 305 | - | |
| 306 | - return false; | |
| 307 | - } | |
| 308 | - | |
| 309 | - public CustomContext getInternalContext() { | |
| 310 | - return this.context; | |
| 311 | - } | |
| 312 | - | |
| 313 | - public void setInternalContext(CustomContext context) { | |
| 314 | - this.context = context; | |
| 315 | - } | |
| 316 | - | |
| 317 | - public synchronized void activate() { | |
| 318 | - try { | |
| 319 | - BeanManager beanManager = Beans.getReference(BeanManager.class); | |
| 320 | - Context c = beanManager.getContext(context.getScope()); | |
| 321 | - | |
| 322 | - if (c == context) { | |
| 323 | - activationCounter++; | |
| 324 | - } else { | |
| 325 | - ContextManager.getLogger().trace( | |
| 326 | - ContextManager.getBundle().getString("custom-context-already-activated", | |
| 327 | - context.getClass().getCanonicalName(), c.getScope().getCanonicalName(), | |
| 328 | - c.getClass().getCanonicalName())); | |
| 329 | - } | |
| 330 | - } catch (ContextNotActiveException ce) { | |
| 331 | - context.setActive(true); | |
| 332 | - activationCounter++; | |
| 333 | - ContextManager.getLogger().trace( | |
| 334 | - ContextManager.getBundle().getString("custom-context-was-activated", | |
| 335 | - context.getClass().getCanonicalName(), context.getScope().getCanonicalName())); | |
| 336 | - } | |
| 337 | - } | |
| 338 | - | |
| 339 | - public synchronized void deactivate() { | |
| 340 | - try { | |
| 341 | - Context c = Beans.getBeanManager().getContext(context.getScope()); | |
| 342 | - if (c == context) { | |
| 343 | - activationCounter--; | |
| 344 | - if (activationCounter == 0) { | |
| 345 | - context.setActive(false); | |
| 346 | - ContextManager.getLogger().trace( | |
| 347 | - ContextManager.getBundle().getString("custom-context-was-deactivated", | |
| 348 | - context.getClass().getCanonicalName(), context.getScope().getCanonicalName())); | |
| 349 | - } | |
| 350 | - } | |
| 351 | - } catch (ContextNotActiveException ce) { | |
| 352 | - } | |
| 353 | - } | |
| 354 | - | |
| 355 | - public synchronized void shutdown() { | |
| 356 | - context.setActive(false); | |
| 357 | - context = null; | |
| 358 | - activationCounter = 0; | |
| 359 | - } | |
| 360 | -} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/CustomContext.java
| ... | ... | @@ -1,45 +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 javax.enterprise.context.spi.Context; | |
| 40 | - | |
| 41 | -public interface CustomContext extends Context { | |
| 42 | - | |
| 43 | - void setActive(boolean active); | |
| 44 | - | |
| 45 | -} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/CustomContextProducer.java
0 → 100644
| ... | ... | @@ -0,0 +1,160 @@ |
| 1 | +package br.gov.frameworkdemoiselle.internal.context; | |
| 2 | + | |
| 3 | +import java.util.ArrayList; | |
| 4 | +import java.util.Collection; | |
| 5 | +import java.util.List; | |
| 6 | +import java.util.Locale; | |
| 7 | + | |
| 8 | +import javax.annotation.PreDestroy; | |
| 9 | +import javax.enterprise.context.ApplicationScoped; | |
| 10 | +import javax.enterprise.inject.Produces; | |
| 11 | +import javax.enterprise.inject.spi.InjectionPoint; | |
| 12 | + | |
| 13 | +import org.slf4j.Logger; | |
| 14 | + | |
| 15 | +import br.gov.frameworkdemoiselle.context.CustomContext; | |
| 16 | +import br.gov.frameworkdemoiselle.context.RequestContext; | |
| 17 | +import br.gov.frameworkdemoiselle.context.SessionContext; | |
| 18 | +import br.gov.frameworkdemoiselle.context.StaticContext; | |
| 19 | +import br.gov.frameworkdemoiselle.context.ViewContext; | |
| 20 | +import br.gov.frameworkdemoiselle.internal.bootstrap.CustomContextBootstrap; | |
| 21 | +import br.gov.frameworkdemoiselle.internal.implementation.StrategySelector; | |
| 22 | +import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; | |
| 23 | +import br.gov.frameworkdemoiselle.util.ResourceBundle; | |
| 24 | + | |
| 25 | +/** | |
| 26 | + * Produces instances of {@link CustomContext} to control contexts not active | |
| 27 | + * by the container | |
| 28 | + * | |
| 29 | + * @author serpro | |
| 30 | + * | |
| 31 | + */ | |
| 32 | +@ApplicationScoped | |
| 33 | +public class CustomContextProducer { | |
| 34 | + | |
| 35 | + private Logger logger; | |
| 36 | + | |
| 37 | + private transient ResourceBundle bundle; | |
| 38 | + | |
| 39 | + private List<CustomContext> contexts = new ArrayList<CustomContext>(); | |
| 40 | + | |
| 41 | + /** | |
| 42 | + * Store a list of contexts into this producer. The contexts must have | |
| 43 | + * been registered into CDI by a portable extension, this method will not do this. | |
| 44 | + * | |
| 45 | + */ | |
| 46 | + public void addRegisteredContexts(Collection<CustomContext> contexts){ | |
| 47 | + for (CustomContext context : contexts){ | |
| 48 | + addRegisteredContext(context); | |
| 49 | + } | |
| 50 | + } | |
| 51 | + | |
| 52 | + /** | |
| 53 | + * Store a context into this producer. The context must have | |
| 54 | + * been registered into CDI by a portable extension, this method will not do this. | |
| 55 | + * | |
| 56 | + */ | |
| 57 | + public void addRegisteredContext(CustomContext context){ | |
| 58 | + Logger logger = getLogger(); | |
| 59 | + ResourceBundle bundle = getBundle(); | |
| 60 | + | |
| 61 | + if (!contexts.contains(context)){ | |
| 62 | + contexts.add(context); | |
| 63 | + logger.debug( bundle.getString("bootstrap-context-added", context.getClass().getCanonicalName() , context.getScope().getSimpleName() ) ); | |
| 64 | + } | |
| 65 | + else{ | |
| 66 | + logger.debug( bundle.getString("bootstrap-context-already-managed", context.getClass().getCanonicalName() , context.getScope().getSimpleName() ) ); | |
| 67 | + } | |
| 68 | + } | |
| 69 | + | |
| 70 | + /** | |
| 71 | + * Deactivates all registered contexts and clear the context collection | |
| 72 | + */ | |
| 73 | + @PreDestroy | |
| 74 | + public void closeContexts(){ | |
| 75 | + //Desativa todos os contextos registrados. | |
| 76 | + for (CustomContext context : contexts){ | |
| 77 | + context.deactivate(); | |
| 78 | + } | |
| 79 | + | |
| 80 | + contexts.clear(); | |
| 81 | + } | |
| 82 | + | |
| 83 | + @Produces | |
| 84 | + public RequestContext getRequestContext(InjectionPoint ip , CustomContextBootstrap extension){ | |
| 85 | + return getContext(ip, extension); | |
| 86 | + } | |
| 87 | + | |
| 88 | + @Produces | |
| 89 | + public SessionContext getSessionContext(InjectionPoint ip , CustomContextBootstrap extension){ | |
| 90 | + return getContext(ip, extension); | |
| 91 | + } | |
| 92 | + | |
| 93 | + @Produces | |
| 94 | + public ViewContext getViewContext(InjectionPoint ip , CustomContextBootstrap extension){ | |
| 95 | + return getContext(ip, extension); | |
| 96 | + } | |
| 97 | + | |
| 98 | + @Produces | |
| 99 | + public StaticContext getStaticContext(InjectionPoint ip , CustomContextBootstrap extension){ | |
| 100 | + return getContext(ip, extension); | |
| 101 | + } | |
| 102 | + | |
| 103 | + | |
| 104 | + @SuppressWarnings("unchecked") | |
| 105 | + private <T extends CustomContext> T getContext(InjectionPoint ip , CustomContextBootstrap extension){ | |
| 106 | + T producedContext = null; | |
| 107 | + | |
| 108 | + if (ip!=null){ | |
| 109 | + Class<T> beanClass = (Class<T>) ip.getType(); | |
| 110 | + producedContext = (T) getContext(beanClass); | |
| 111 | + } | |
| 112 | + | |
| 113 | + if (producedContext!=null){ | |
| 114 | + getLogger().debug( getBundle().getString("custom-context-selected" , producedContext.getClass().getCanonicalName()) ); | |
| 115 | + } | |
| 116 | + | |
| 117 | + return producedContext; | |
| 118 | + } | |
| 119 | + | |
| 120 | + private CustomContext getContext(Class<? extends CustomContext> contextClass){ | |
| 121 | + CustomContext producedContext = null; | |
| 122 | + | |
| 123 | + ArrayList<CustomContext> selectableContexts = new ArrayList<CustomContext>(); | |
| 124 | + | |
| 125 | + for (CustomContext context : contexts){ | |
| 126 | + if ( contextClass.isAssignableFrom( context.getClass() ) ){ | |
| 127 | + if (context.isActive()){ | |
| 128 | + producedContext = context; | |
| 129 | + break; | |
| 130 | + } | |
| 131 | + else{ | |
| 132 | + selectableContexts.add(context); | |
| 133 | + } | |
| 134 | + } | |
| 135 | + } | |
| 136 | + | |
| 137 | + if (producedContext==null && !selectableContexts.isEmpty()){ | |
| 138 | + producedContext = StrategySelector.selectInstance(CustomContext.class, selectableContexts); | |
| 139 | + } | |
| 140 | + | |
| 141 | + return producedContext; | |
| 142 | + } | |
| 143 | + | |
| 144 | + private Logger getLogger() { | |
| 145 | + if (this.logger == null) { | |
| 146 | + this.logger = LoggerProducer.create(this.getClass()); | |
| 147 | + } | |
| 148 | + | |
| 149 | + return this.logger; | |
| 150 | + } | |
| 151 | + | |
| 152 | + private ResourceBundle getBundle() { | |
| 153 | + if (bundle == null) { | |
| 154 | + bundle = new ResourceBundle("demoiselle-core-bundle", Locale.getDefault()); | |
| 155 | + } | |
| 156 | + | |
| 157 | + return bundle; | |
| 158 | + } | |
| 159 | + | |
| 160 | +} | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/ManagedContext.java
| ... | ... | @@ -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 javax.enterprise.context.RequestScoped; | |
| 40 | - | |
| 41 | -import br.gov.frameworkdemoiselle.stereotype.ManagementController; | |
| 42 | - | |
| 43 | -/** | |
| 44 | - * Context that stores {@link RequestScoped} beans during client calls to {@link ManagementController} classes. This | |
| 45 | - * context is only activated when no other context is active for {@link RequestScoped}. | |
| 46 | - * | |
| 47 | - * @author SERPRO | |
| 48 | - */ | |
| 49 | -public class ManagedContext extends ThreadLocalContext { | |
| 50 | - | |
| 51 | - /** | |
| 52 | - * Constructs a new context. | |
| 53 | - */ | |
| 54 | - public ManagedContext() { | |
| 55 | - super(RequestScoped.class); | |
| 56 | - } | |
| 57 | - | |
| 58 | -} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/RequestContextImpl.java
0 → 100644
| ... | ... | @@ -0,0 +1,71 @@ |
| 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 javax.enterprise.context.RequestScoped; | |
| 52 | +import javax.enterprise.inject.Alternative; | |
| 53 | + | |
| 54 | +import br.gov.frameworkdemoiselle.annotation.Priority; | |
| 55 | +import br.gov.frameworkdemoiselle.context.RequestContext; | |
| 56 | + | |
| 57 | +/** | |
| 58 | + * Custom request context that stores beans in a thread local store. | |
| 59 | + * | |
| 60 | + * @author serpro | |
| 61 | + * | |
| 62 | + */ | |
| 63 | +@Priority(Priority.MIN_PRIORITY) | |
| 64 | +@Alternative | |
| 65 | +public class RequestContextImpl extends AbstractThreadLocalContext implements RequestContext { | |
| 66 | + | |
| 67 | + public RequestContextImpl() { | |
| 68 | + super(RequestScoped.class); | |
| 69 | + } | |
| 70 | + | |
| 71 | +} | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/SessionContextImpl.java
0 → 100644
| ... | ... | @@ -0,0 +1,71 @@ |
| 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 javax.enterprise.context.SessionScoped; | |
| 52 | +import javax.enterprise.inject.Alternative; | |
| 53 | + | |
| 54 | +import br.gov.frameworkdemoiselle.annotation.Priority; | |
| 55 | +import br.gov.frameworkdemoiselle.context.SessionContext; | |
| 56 | + | |
| 57 | + | |
| 58 | +/** | |
| 59 | + * | |
| 60 | + * @author serpro | |
| 61 | + * | |
| 62 | + */ | |
| 63 | +@Priority(Priority.MIN_PRIORITY) | |
| 64 | +@Alternative | |
| 65 | +public class SessionContextImpl extends AbstractStaticContext implements SessionContext { | |
| 66 | + | |
| 67 | + public SessionContextImpl() { | |
| 68 | + super(SessionScoped.class); | |
| 69 | + } | |
| 70 | + | |
| 71 | +} | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/StaticContext.java
| ... | ... | @@ -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,64 @@ |
| 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 javax.enterprise.inject.Alternative; | |
| 52 | + | |
| 53 | +import br.gov.frameworkdemoiselle.annotation.Priority; | |
| 54 | +import br.gov.frameworkdemoiselle.annotation.StaticScoped; | |
| 55 | +import br.gov.frameworkdemoiselle.context.StaticContext; | |
| 56 | + | |
| 57 | +@Priority(Priority.MIN_PRIORITY) | |
| 58 | +@Alternative | |
| 59 | +public class StaticContextImpl extends AbstractStaticContext implements StaticContext { | |
| 60 | + | |
| 61 | + public StaticContextImpl() { | |
| 62 | + super(StaticScoped.class); | |
| 63 | + } | |
| 64 | +} | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/ThreadLocalContext.java
| ... | ... | @@ -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,65 @@ |
| 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 javax.enterprise.inject.Alternative; | |
| 52 | + | |
| 53 | +import br.gov.frameworkdemoiselle.annotation.Priority; | |
| 54 | +import br.gov.frameworkdemoiselle.annotation.ViewScoped; | |
| 55 | +import br.gov.frameworkdemoiselle.context.ViewContext; | |
| 56 | + | |
| 57 | +@Priority(Priority.MIN_PRIORITY) | |
| 58 | +@Alternative | |
| 59 | +public class ThreadLocalViewContextImpl extends AbstractThreadLocalContext implements ViewContext { | |
| 60 | + | |
| 61 | + public ThreadLocalViewContextImpl() { | |
| 62 | + super(ViewScoped.class); | |
| 63 | + } | |
| 64 | + | |
| 65 | +} | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/Management.java
| ... | ... | @@ -44,7 +44,6 @@ import java.util.List; |
| 44 | 44 | import java.util.Set; |
| 45 | 45 | |
| 46 | 46 | import javax.enterprise.context.ApplicationScoped; |
| 47 | -import javax.enterprise.context.RequestScoped; | |
| 48 | 47 | import javax.inject.Inject; |
| 49 | 48 | import javax.validation.ConstraintViolation; |
| 50 | 49 | import javax.validation.ConstraintViolationException; |
| ... | ... | @@ -56,8 +55,10 @@ import org.slf4j.Logger; |
| 56 | 55 | |
| 57 | 56 | import br.gov.frameworkdemoiselle.annotation.ManagedProperty; |
| 58 | 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.implementation.ManagedType; | |
| 61 | 62 | import br.gov.frameworkdemoiselle.internal.implementation.ManagedType.MethodDetail; |
| 62 | 63 | import br.gov.frameworkdemoiselle.management.AttributeChangeNotification; |
| 63 | 64 | import br.gov.frameworkdemoiselle.management.ManagedAttributeNotFoundException; |
| ... | ... | @@ -301,36 +302,72 @@ public class Management implements Serializable { |
| 301 | 302 | } |
| 302 | 303 | |
| 303 | 304 | private void activateContexts(Class<?> managedType) { |
| 304 | - logger.debug(bundle.getString("management-debug-starting-custom-context", | |
| 305 | - ManagedContext.class.getCanonicalName(), managedType.getCanonicalName())); | |
| 305 | + | |
| 306 | + RequestContext requestContext = Beans.getReference(RequestContext.class); | |
| 307 | + ViewContext viewContext = Beans.getReference(ViewContext.class); | |
| 308 | + SessionContext sessionContext = Beans.getReference(SessionContext.class); | |
| 309 | + | |
| 310 | + if (!requestContext.isActive()){ | |
| 311 | + logger.debug(bundle.getString("management-debug-starting-custom-context", | |
| 312 | + requestContext.getClass().getCanonicalName(), managedType.getCanonicalName())); | |
| 313 | + | |
| 314 | + requestContext.activate(); | |
| 315 | + } | |
| 316 | + | |
| 317 | + if (!viewContext.isActive()){ | |
| 318 | + logger.debug(bundle.getString("management-debug-starting-custom-context", | |
| 319 | + viewContext.getClass().getCanonicalName(), managedType.getCanonicalName())); | |
| 320 | + | |
| 321 | + viewContext.activate(); | |
| 322 | + } | |
| 306 | 323 | |
| 307 | - ContextManager.activate(ManagedContext.class, RequestScoped.class); | |
| 324 | + if (!sessionContext.isActive()){ | |
| 325 | + logger.debug(bundle.getString("management-debug-starting-custom-context", | |
| 326 | + sessionContext.getClass().getCanonicalName(), managedType.getCanonicalName())); | |
| 327 | + | |
| 328 | + sessionContext.activate(); | |
| 329 | + } | |
| 308 | 330 | } |
| 309 | 331 | |
| 310 | 332 | private void deactivateContexts(Class<?> managedType) { |
| 311 | - logger.debug(bundle.getString("management-debug-stoping-custom-context", | |
| 312 | - ManagedContext.class.getCanonicalName(), managedType.getCanonicalName())); | |
| 333 | + RequestContext requestContext = Beans.getReference(RequestContext.class); | |
| 334 | + ViewContext viewContext = Beans.getReference(ViewContext.class); | |
| 335 | + SessionContext sessionContext = Beans.getReference(SessionContext.class); | |
| 336 | + | |
| 337 | + if (requestContext.isActive()){ | |
| 338 | + logger.debug(bundle.getString("management-debug-stoping-custom-context", | |
| 339 | + requestContext.getClass().getCanonicalName(), managedType.getCanonicalName())); | |
| 340 | + | |
| 341 | + requestContext.deactivate(); | |
| 342 | + } | |
| 343 | + | |
| 344 | + if (!viewContext.isActive()){ | |
| 345 | + logger.debug(bundle.getString("management-debug-stoping-custom-context", | |
| 346 | + viewContext.getClass().getCanonicalName(), managedType.getCanonicalName())); | |
| 347 | + | |
| 348 | + viewContext.deactivate(); | |
| 349 | + } | |
| 313 | 350 | |
| 314 | - ContextManager.deactivate(ManagedContext.class, RequestScoped.class); | |
| 351 | + if (!sessionContext.isActive()){ | |
| 352 | + logger.debug(bundle.getString("management-debug-stoping-custom-context", | |
| 353 | + sessionContext.getClass().getCanonicalName(), managedType.getCanonicalName())); | |
| 354 | + | |
| 355 | + sessionContext.deactivate(); | |
| 356 | + } | |
| 315 | 357 | } |
| 316 | 358 | |
| 317 | 359 | public void shutdown(Collection<Class<? extends ManagementExtension>> monitoringExtensions) { |
| 318 | - | |
| 319 | 360 | for (Class<? extends ManagementExtension> monitoringExtensionClass : monitoringExtensions) { |
| 320 | 361 | |
| 321 | 362 | ManagementExtension monitoringExtension = Beans.getReference(monitoringExtensionClass); |
| 322 | - | |
| 323 | 363 | monitoringExtension.shutdown(this.getManagedTypes()); |
| 324 | - | |
| 325 | 364 | logger.debug(bundle.getString("management-debug-removing-management-extension", monitoringExtension |
| 326 | 365 | .getClass().getCanonicalName())); |
| 327 | 366 | |
| 328 | 367 | } |
| 329 | - | |
| 330 | 368 | } |
| 331 | 369 | |
| 332 | 370 | public void initialize(Collection<Class<? extends ManagementExtension>> monitoringExtensions) { |
| 333 | - | |
| 334 | 371 | for (Class<? extends ManagementExtension> monitoringExtensionClass : monitoringExtensions) { |
| 335 | 372 | ManagementExtension monitoringExtension = Beans.getReference(monitoringExtensionClass); |
| 336 | 373 | |
| ... | ... | @@ -339,7 +376,6 @@ public class Management implements Serializable { |
| 339 | 376 | |
| 340 | 377 | monitoringExtension.initialize(this.getManagedTypes()); |
| 341 | 378 | } |
| 342 | - | |
| 343 | 379 | } |
| 344 | 380 | |
| 345 | 381 | private Validator getDefaultValidator() { | ... | ... |
impl/core/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
| 1 | 1 | br.gov.frameworkdemoiselle.internal.bootstrap.CoreBootstrap |
| 2 | +br.gov.frameworkdemoiselle.internal.bootstrap.CustomContextBootstrap | |
| 2 | 3 | br.gov.frameworkdemoiselle.internal.bootstrap.ConfigurationBootstrap |
| 3 | 4 | br.gov.frameworkdemoiselle.internal.bootstrap.ManagementBootstrap |
| 4 | 5 | br.gov.frameworkdemoiselle.internal.bootstrap.StartupBootstrap | ... | ... |
impl/core/src/main/resources/demoiselle-core-bundle.properties
| ... | ... | @@ -68,8 +68,7 @@ configuration-not-conversion=N\u00E3o \u00E9 poss\u00EDvel converter o valor {0} |
| 68 | 68 | |
| 69 | 69 | 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 |
| 70 | 70 | executing-all=Executando todos os \: {0} |
| 71 | -custom-context-was-registered=O contexto {0} foi registrado | |
| 72 | -custom-context-was-unregistered=O contexto {0} foi removido | |
| 71 | +custom-context-selected=Produzindo inst\u00E2ncia do contexto {0} | |
| 73 | 72 | custom-context-was-activated=O contexto {0} foi ativado para o escopo {1} |
| 74 | 73 | custom-context-was-deactivated=O contexto {0} foi desativado para o escopo {1} |
| 75 | 74 | 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/management/validation/ValidationTest.java
| 1 | 1 | package management.validation; |
| 2 | 2 | |
| 3 | +import javax.validation.ConstraintViolationException; | |
| 4 | + | |
| 3 | 5 | import management.testclasses.DummyManagedClass; |
| 4 | 6 | import management.testclasses.DummyManagementExtension; |
| 5 | 7 | import management.testclasses.DummyValidator; |
| ... | ... | @@ -14,7 +16,6 @@ import org.junit.Test; |
| 14 | 16 | import org.junit.runner.RunWith; |
| 15 | 17 | |
| 16 | 18 | import test.Tests; |
| 17 | -import br.gov.frameworkdemoiselle.DemoiselleException; | |
| 18 | 19 | import br.gov.frameworkdemoiselle.util.Beans; |
| 19 | 20 | |
| 20 | 21 | @RunWith(Arquillian.class) |
| ... | ... | @@ -52,8 +53,8 @@ public class ValidationTest { |
| 52 | 53 | store.setProperty(DummyManagedClass.class, "id", (Integer) null); |
| 53 | 54 | |
| 54 | 55 | Assert.fail(); |
| 55 | - } catch (DemoiselleException de) { | |
| 56 | - // Classes de gerenciamento disparam Demoiselle Exception quando uma validação falha | |
| 56 | + } catch (ConstraintViolationException ce) { | |
| 57 | + // Classes de gerenciamento disparam ConstraintViolationException quando uma validação falha | |
| 57 | 58 | } |
| 58 | 59 | } |
| 59 | 60 | |
| ... | ... | @@ -72,7 +73,7 @@ public class ValidationTest { |
| 72 | 73 | store.setProperty(DummyManagedClass.class, "gender", "J"); |
| 73 | 74 | |
| 74 | 75 | Assert.fail(); |
| 75 | - } catch (DemoiselleException e) { | |
| 76 | + } catch (ConstraintViolationException e) { | |
| 76 | 77 | Assert.assertTrue(e.getMessage().contains("Test Message")); |
| 77 | 78 | } |
| 78 | 79 | ... | ... |
impl/core/src/test/java/message/MessageContextTest.java
| ... | ... | @@ -39,7 +39,6 @@ package message; |
| 39 | 39 | import static junit.framework.Assert.assertEquals; |
| 40 | 40 | import static junit.framework.Assert.assertTrue; |
| 41 | 41 | |
| 42 | -import javax.enterprise.context.RequestScoped; | |
| 43 | 42 | import javax.inject.Inject; |
| 44 | 43 | |
| 45 | 44 | import junit.framework.Assert; |
| ... | ... | @@ -51,8 +50,7 @@ import org.junit.Test; |
| 51 | 50 | import org.junit.runner.RunWith; |
| 52 | 51 | |
| 53 | 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 | 54 | import br.gov.frameworkdemoiselle.message.DefaultMessage; |
| 57 | 55 | import br.gov.frameworkdemoiselle.message.Message; |
| 58 | 56 | import br.gov.frameworkdemoiselle.message.MessageContext; |
| ... | ... | @@ -80,78 +78,92 @@ public class MessageContextTest { |
| 80 | 78 | |
| 81 | 79 | @Test |
| 82 | 80 | public void testAddMessageWithoutParams() { |
| 83 | - ContextManager.activate(ManagedContext.class, RequestScoped.class); | |
| 81 | + RequestContext context = Beans.getReference(RequestContext.class); | |
| 82 | + | |
| 83 | + context.activate(); | |
| 84 | 84 | Message message = new DefaultMessage("Menssage without param"); |
| 85 | 85 | DummyMessageAppender appender = Beans.getReference(DummyMessageAppender.class); |
| 86 | 86 | |
| 87 | 87 | messageContext.add(message); |
| 88 | 88 | assertEquals(appender.getMessages().size(), 1); |
| 89 | - ContextManager.deactivate(ManagedContext.class, RequestScoped.class); | |
| 89 | + context.deactivate(); | |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | @Test |
| 93 | 93 | public void testAddMessageWithoutParamsIfSeverityIsInfo() { |
| 94 | - ContextManager.activate(ManagedContext.class, RequestScoped.class); | |
| 94 | + RequestContext context = Beans.getReference(RequestContext.class); | |
| 95 | + | |
| 96 | + context.activate(); | |
| 95 | 97 | Message message = new DefaultMessage("Menssage without param"); |
| 96 | 98 | DummyMessageAppender appender = Beans.getReference(DummyMessageAppender.class); |
| 97 | 99 | |
| 98 | 100 | messageContext.add(message); |
| 99 | 101 | assertEquals(appender.getMessages().get(0).getSeverity(), SeverityType.INFO); |
| 100 | - ContextManager.deactivate(ManagedContext.class, RequestScoped.class); | |
| 102 | + context.deactivate(); | |
| 101 | 103 | } |
| 102 | 104 | |
| 103 | 105 | @Test |
| 104 | 106 | public void testAddMessageWitSeverityInfo() { |
| 105 | - ContextManager.activate(ManagedContext.class, RequestScoped.class); | |
| 107 | + RequestContext context = Beans.getReference(RequestContext.class); | |
| 108 | + | |
| 109 | + context.activate(); | |
| 106 | 110 | Message message = new DefaultMessage("Menssage without param", SeverityType.INFO); |
| 107 | 111 | DummyMessageAppender appender = Beans.getReference(DummyMessageAppender.class); |
| 108 | 112 | |
| 109 | 113 | messageContext.add(message); |
| 110 | 114 | assertEquals(appender.getMessages().get(0).getSeverity(), SeverityType.INFO); |
| 111 | - ContextManager.deactivate(ManagedContext.class, RequestScoped.class); | |
| 115 | + context.deactivate(); | |
| 112 | 116 | } |
| 113 | 117 | |
| 114 | 118 | @Test |
| 115 | 119 | public void testAddMessageWitSeverityWarn() { |
| 116 | - ContextManager.activate(ManagedContext.class, RequestScoped.class); | |
| 120 | + RequestContext context = Beans.getReference(RequestContext.class); | |
| 121 | + | |
| 122 | + context.activate(); | |
| 117 | 123 | Message message = new DefaultMessage("Menssage without param", SeverityType.WARN); |
| 118 | 124 | DummyMessageAppender appender = Beans.getReference(DummyMessageAppender.class); |
| 119 | 125 | |
| 120 | 126 | messageContext.add(message); |
| 121 | 127 | assertEquals(appender.getMessages().get(0).getSeverity(), SeverityType.WARN); |
| 122 | - ContextManager.deactivate(ManagedContext.class, RequestScoped.class); | |
| 128 | + context.deactivate(); | |
| 123 | 129 | } |
| 124 | 130 | |
| 125 | 131 | @Test |
| 126 | 132 | public void testAddMessageWitSeverityErro() { |
| 127 | - ContextManager.activate(ManagedContext.class, RequestScoped.class); | |
| 133 | + RequestContext context = Beans.getReference(RequestContext.class); | |
| 134 | + | |
| 135 | + context.activate(); | |
| 128 | 136 | Message message = new DefaultMessage("Menssage without param", SeverityType.ERROR); |
| 129 | 137 | DummyMessageAppender appender = Beans.getReference(DummyMessageAppender.class); |
| 130 | 138 | |
| 131 | 139 | messageContext.add(message); |
| 132 | 140 | assertEquals(appender.getMessages().get(0).getSeverity(), SeverityType.ERROR); |
| 133 | - ContextManager.deactivate(ManagedContext.class, RequestScoped.class); | |
| 141 | + context.deactivate(); | |
| 134 | 142 | } |
| 135 | 143 | |
| 136 | 144 | @Test |
| 137 | 145 | public void testRecoverStringMessageWithParams() { |
| 138 | - ContextManager.activate(ManagedContext.class, RequestScoped.class); | |
| 146 | + RequestContext context = Beans.getReference(RequestContext.class); | |
| 147 | + | |
| 148 | + context.activate(); | |
| 139 | 149 | DummyMessageAppender appender = Beans.getReference(DummyMessageAppender.class); |
| 140 | 150 | |
| 141 | 151 | messageContext.add("Message with {0} param", 1); |
| 142 | 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 | 156 | @Test |
| 147 | 157 | public void testRecoverMessageWithParams() { |
| 148 | - ContextManager.activate(ManagedContext.class, RequestScoped.class); | |
| 158 | + RequestContext context = Beans.getReference(RequestContext.class); | |
| 159 | + | |
| 160 | + context.activate(); | |
| 149 | 161 | Message message = new DefaultMessage("Message with {0} param"); |
| 150 | 162 | DummyMessageAppender appender = Beans.getReference(DummyMessageAppender.class); |
| 151 | 163 | |
| 152 | 164 | messageContext.add(message, 1); |
| 153 | 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 | 169 | @Test |
| ... | ... | @@ -164,21 +176,25 @@ public class MessageContextTest { |
| 164 | 176 | |
| 165 | 177 | @Test |
| 166 | 178 | public void testMessageParsedText() { |
| 167 | - ContextManager.activate(ManagedContext.class, RequestScoped.class); | |
| 179 | + RequestContext context = Beans.getReference(RequestContext.class); | |
| 180 | + | |
| 181 | + context.activate(); | |
| 168 | 182 | Message MESSAGE_PARSED = new DefaultMessage("{MESSAGE_PARSED}"); |
| 169 | 183 | String expected = "Message parsed"; |
| 170 | 184 | String value = MESSAGE_PARSED.getText(); |
| 171 | 185 | Assert.assertEquals(expected, value); |
| 172 | - ContextManager.deactivate(ManagedContext.class, RequestScoped.class); | |
| 186 | + context.deactivate(); | |
| 173 | 187 | } |
| 174 | 188 | |
| 175 | 189 | @Test |
| 176 | 190 | public void testMessageIsNull() { |
| 177 | - ContextManager.activate(ManagedContext.class, RequestScoped.class); | |
| 191 | + RequestContext context = Beans.getReference(RequestContext.class); | |
| 192 | + | |
| 193 | + context.activate(); | |
| 178 | 194 | Message NULL_MESSAGE = new DefaultMessage(null); |
| 179 | 195 | String expected = null; |
| 180 | 196 | String value = NULL_MESSAGE.getText(); |
| 181 | 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 | 38 | |
| 39 | 39 | import static junit.framework.Assert.assertEquals; |
| 40 | 40 | |
| 41 | -import javax.enterprise.context.SessionScoped; | |
| 42 | 41 | import javax.inject.Inject; |
| 43 | 42 | |
| 44 | 43 | import org.jboss.arquillian.container.test.api.Deployment; |
| ... | ... | @@ -51,11 +50,11 @@ import org.junit.runner.RunWith; |
| 51 | 50 | |
| 52 | 51 | import test.Tests; |
| 53 | 52 | import transaction.defaultstrategy.TransactionDefaultTest; |
| 53 | +import br.gov.frameworkdemoiselle.context.SessionContext; | |
| 54 | 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 | 55 | import br.gov.frameworkdemoiselle.pagination.Pagination; |
| 58 | 56 | import br.gov.frameworkdemoiselle.pagination.PaginationContext; |
| 57 | +import br.gov.frameworkdemoiselle.util.Beans; | |
| 59 | 58 | |
| 60 | 59 | @RunWith(Arquillian.class) |
| 61 | 60 | public class PaginationContextBasicTest { |
| ... | ... | @@ -96,13 +95,15 @@ public class PaginationContextBasicTest { |
| 96 | 95 | |
| 97 | 96 | @Before |
| 98 | 97 | public void activeContext() { |
| 99 | - ContextManager.activate(ThreadLocalContext.class, SessionScoped.class); | |
| 98 | + SessionContext context = Beans.getReference(SessionContext.class); | |
| 99 | + context.activate(); | |
| 100 | 100 | pagination = paginationContext.getPagination(DummyEntity.class, true); |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | @After |
| 104 | 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 | 109 | @Test | ... | ... |
impl/core/src/test/java/pagination/PaginationContextCache.java
| ... | ... | @@ -38,7 +38,6 @@ package pagination; |
| 38 | 38 | |
| 39 | 39 | import static org.junit.Assert.assertEquals; |
| 40 | 40 | |
| 41 | -import javax.enterprise.context.SessionScoped; | |
| 42 | 41 | import javax.inject.Inject; |
| 43 | 42 | |
| 44 | 43 | import org.jboss.arquillian.container.test.api.Deployment; |
| ... | ... | @@ -51,10 +50,10 @@ import org.junit.runner.RunWith; |
| 51 | 50 | |
| 52 | 51 | import test.Tests; |
| 53 | 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 | 54 | import br.gov.frameworkdemoiselle.pagination.Pagination; |
| 57 | 55 | import br.gov.frameworkdemoiselle.pagination.PaginationContext; |
| 56 | +import br.gov.frameworkdemoiselle.util.Beans; | |
| 58 | 57 | |
| 59 | 58 | @RunWith(Arquillian.class) |
| 60 | 59 | public class PaginationContextCache { |
| ... | ... | @@ -74,12 +73,14 @@ public class PaginationContextCache { |
| 74 | 73 | |
| 75 | 74 | @Before |
| 76 | 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 | 80 | @After |
| 81 | 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 | 86 | @Test | ... | ... |
impl/core/src/test/java/pagination/PaginationContextNullTest.java
| ... | ... | @@ -38,7 +38,6 @@ package pagination; |
| 38 | 38 | |
| 39 | 39 | import static org.junit.Assert.assertNull; |
| 40 | 40 | |
| 41 | -import javax.enterprise.context.SessionScoped; | |
| 42 | 41 | import javax.inject.Inject; |
| 43 | 42 | |
| 44 | 43 | import org.jboss.arquillian.container.test.api.Deployment; |
| ... | ... | @@ -51,10 +50,10 @@ import org.junit.runner.RunWith; |
| 51 | 50 | |
| 52 | 51 | import test.Tests; |
| 53 | 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 | 54 | import br.gov.frameworkdemoiselle.pagination.Pagination; |
| 57 | 55 | import br.gov.frameworkdemoiselle.pagination.PaginationContext; |
| 56 | +import br.gov.frameworkdemoiselle.util.Beans; | |
| 58 | 57 | |
| 59 | 58 | @RunWith(Arquillian.class) |
| 60 | 59 | public class PaginationContextNullTest { |
| ... | ... | @@ -72,12 +71,14 @@ public class PaginationContextNullTest { |
| 72 | 71 | |
| 73 | 72 | @Before |
| 74 | 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 | 78 | @After |
| 79 | 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 | 84 | @Test | ... | ... |
impl/core/src/test/java/security/athentication/credentials/AcceptOrDenyCredentialsTest.java
| ... | ... | @@ -36,7 +36,6 @@ |
| 36 | 36 | */ |
| 37 | 37 | package security.athentication.credentials; |
| 38 | 38 | |
| 39 | -import javax.enterprise.context.RequestScoped; | |
| 40 | 39 | import javax.inject.Inject; |
| 41 | 40 | |
| 42 | 41 | import junit.framework.Assert; |
| ... | ... | @@ -48,8 +47,7 @@ import org.junit.Test; |
| 48 | 47 | import org.junit.runner.RunWith; |
| 49 | 48 | |
| 50 | 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 | 51 | import br.gov.frameworkdemoiselle.security.AuthenticationException; |
| 54 | 52 | import br.gov.frameworkdemoiselle.security.SecurityContext; |
| 55 | 53 | import br.gov.frameworkdemoiselle.util.Beans; |
| ... | ... | @@ -71,7 +69,8 @@ public class AcceptOrDenyCredentialsTest { |
| 71 | 69 | |
| 72 | 70 | @Test |
| 73 | 71 | public void denyWrongCredentials() { |
| 74 | - ContextManager.activate(ThreadLocalContext.class, RequestScoped.class); | |
| 72 | + RequestContext ctx = Beans.getReference(RequestContext.class); | |
| 73 | + ctx.activate(); | |
| 75 | 74 | |
| 76 | 75 | Credentials credentials = Beans.getReference(Credentials.class); |
| 77 | 76 | credentials.setLogin("wronglogin"); |
| ... | ... | @@ -84,14 +83,15 @@ public class AcceptOrDenyCredentialsTest { |
| 84 | 83 | //Erro esperado |
| 85 | 84 | } |
| 86 | 85 | finally{ |
| 87 | - ContextManager.deactivate(ThreadLocalContext.class, RequestScoped.class); | |
| 86 | + ctx.deactivate(); | |
| 88 | 87 | } |
| 89 | 88 | |
| 90 | 89 | } |
| 91 | 90 | |
| 92 | 91 | @Test |
| 93 | 92 | public void acceptRightCredentials() { |
| 94 | - ContextManager.activate(ThreadLocalContext.class, RequestScoped.class); | |
| 93 | + RequestContext ctx = Beans.getReference(RequestContext.class); | |
| 94 | + ctx.activate(); | |
| 95 | 95 | |
| 96 | 96 | Credentials credentials = Beans.getReference(Credentials.class); |
| 97 | 97 | credentials.setLogin("demoiselle"); |
| ... | ... | @@ -103,7 +103,7 @@ public class AcceptOrDenyCredentialsTest { |
| 103 | 103 | Assert.fail("Authenticator negou credenciais corretas"); |
| 104 | 104 | } |
| 105 | 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 | 42 | import static org.junit.Assert.assertNull; |
| 43 | 43 | import static org.junit.Assert.assertTrue; |
| 44 | 44 | |
| 45 | -import javax.enterprise.context.RequestScoped; | |
| 46 | 45 | import javax.inject.Inject; |
| 47 | 46 | |
| 48 | 47 | import org.jboss.arquillian.container.test.api.Deployment; |
| ... | ... | @@ -52,9 +51,9 @@ import org.junit.Test; |
| 52 | 51 | import org.junit.runner.RunWith; |
| 53 | 52 | |
| 54 | 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 | 55 | import br.gov.frameworkdemoiselle.security.SecurityContext; |
| 56 | +import br.gov.frameworkdemoiselle.util.Beans; | |
| 58 | 57 | import configuration.resource.ConfigurationResourceTest; |
| 59 | 58 | |
| 60 | 59 | @RunWith(Arquillian.class) |
| ... | ... | @@ -82,25 +81,27 @@ public class CustomAuthenticatorTest { |
| 82 | 81 | |
| 83 | 82 | @Test |
| 84 | 83 | public void loginProcess() { |
| 85 | - ContextManager.activate(ThreadLocalContext.class, RequestScoped.class); | |
| 84 | + RequestContext ctx = Beans.getReference(RequestContext.class); | |
| 85 | + ctx.activate(); | |
| 86 | 86 | |
| 87 | 87 | context.login(); |
| 88 | 88 | assertTrue(context.isLoggedIn()); |
| 89 | 89 | assertNotNull(observer.getEvent()); |
| 90 | 90 | assertEquals("demoiselle", context.getUser().getId()); |
| 91 | 91 | |
| 92 | - ContextManager.deactivate(ThreadLocalContext.class, RequestScoped.class); | |
| 92 | + ctx.deactivate(); | |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | @Test |
| 96 | 96 | public void logoutProcess() { |
| 97 | - ContextManager.activate(ThreadLocalContext.class, RequestScoped.class); | |
| 97 | + RequestContext ctx = Beans.getReference(RequestContext.class); | |
| 98 | + ctx.activate(); | |
| 98 | 99 | |
| 99 | 100 | context.login(); |
| 100 | 101 | context.logout(); |
| 101 | 102 | assertFalse(context.isLoggedIn()); |
| 102 | 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 | 43 | |
| 44 | 44 | import java.util.List; |
| 45 | 45 | |
| 46 | -import javax.enterprise.context.RequestScoped; | |
| 47 | 46 | import javax.inject.Inject; |
| 48 | 47 | |
| 49 | 48 | import org.jboss.arquillian.container.test.api.Deployment; |
| ... | ... | @@ -55,8 +54,8 @@ import org.junit.Test; |
| 55 | 54 | import org.junit.runner.RunWith; |
| 56 | 55 | |
| 57 | 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 | 60 | @RunWith(Arquillian.class) |
| 62 | 61 | public class TemplateTest { |
| ... | ... | @@ -83,7 +82,8 @@ public class TemplateTest { |
| 83 | 82 | @Before |
| 84 | 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 | 88 | this.crudImpl.resetEntities(); |
| 89 | 89 | |
| ... | ... | @@ -91,9 +91,8 @@ public class TemplateTest { |
| 91 | 91 | |
| 92 | 92 | @After |
| 93 | 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 | 98 | @Test | ... | ... |
impl/core/src/test/java/transaction/rollback/TransactionRollbackTest.java
| ... | ... | @@ -40,7 +40,6 @@ import static junit.framework.Assert.assertFalse; |
| 40 | 40 | import static junit.framework.Assert.assertTrue; |
| 41 | 41 | import static org.junit.Assert.fail; |
| 42 | 42 | |
| 43 | -import javax.enterprise.context.RequestScoped; | |
| 44 | 43 | import javax.inject.Inject; |
| 45 | 44 | |
| 46 | 45 | import org.jboss.arquillian.container.test.api.Deployment; |
| ... | ... | @@ -52,9 +51,8 @@ import org.junit.Test; |
| 52 | 51 | import org.junit.runner.RunWith; |
| 53 | 52 | |
| 54 | 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 | 57 | @RunWith(Arquillian.class) |
| 60 | 58 | public class TransactionRollbackTest { |
| ... | ... | @@ -76,12 +74,14 @@ public class TransactionRollbackTest { |
| 76 | 74 | |
| 77 | 75 | @Before |
| 78 | 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 | 81 | @After |
| 83 | 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 | 87 | @Test | ... | ... |
impl/extension/jmx/src/main/resources/META-INF/beans.xml
| 1 | -<?xml version="1.0" encoding="UTF-8"?> | |
| 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 | +--> | |
| 2 | 37 | <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| 3 | 38 | xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> |
| 4 | -</beans> | |
| 5 | 39 | \ No newline at end of file |
| 40 | + | |
| 41 | +</beans> | ... | ... |
impl/extension/jpa/src/main/java/br/gov/frameworkdemoiselle/annotation/PersistenceScoped.java
0 → 100644
| ... | ... | @@ -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 | 52 | public class EntityManagerConfig implements Serializable { |
| 53 | 53 | |
| 54 | 54 | private static final long serialVersionUID = 1L; |
| 55 | - | |
| 55 | + | |
| 56 | 56 | /** |
| 57 | 57 | * @deprecated |
| 58 | 58 | */ |
| ... | ... | @@ -62,6 +62,9 @@ public class EntityManagerConfig implements Serializable { |
| 62 | 62 | |
| 63 | 63 | @Name("default.unit.name") |
| 64 | 64 | private String defaultPersistenceUnitName; |
| 65 | + | |
| 66 | + @Name("entitymanager.scope") | |
| 67 | + private String entityManagerScope = "request"; | |
| 65 | 68 | |
| 66 | 69 | /** |
| 67 | 70 | * Getter for persistence unit name. |
| ... | ... | @@ -92,4 +95,16 @@ public class EntityManagerConfig implements Serializable { |
| 92 | 95 | |
| 93 | 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 @@ |
| 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,30 +41,37 @@ import javax.enterprise.inject.spi.AfterBeanDiscovery; |
| 41 | 41 | import javax.enterprise.inject.spi.AfterDeploymentValidation; |
| 42 | 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.CustomContextProducer; | |
| 46 | +import br.gov.frameworkdemoiselle.internal.context.FacesViewContextImpl; | |
| 47 | 47 | import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess; |
| 48 | +import br.gov.frameworkdemoiselle.util.Beans; | |
| 48 | 49 | |
| 49 | 50 | public class JsfBootstrap implements Extension { |
| 50 | 51 | |
| 51 | 52 | //private List<CustomContext> customContexts = new ArrayList<CustomContext>(); |
| 52 | 53 | |
| 53 | 54 | //private AfterBeanDiscovery afterBeanDiscoveryEvent; |
| 54 | - | |
| 55 | - public void storeContexts(@Observes final AfterBeanDiscovery event) { | |
| 56 | - //Registra o ViewContext para controlar o escopo ViewScoped. | |
| 57 | - ContextManager.initialize(event); | |
| 58 | - ContextManager.add(new ViewContext(), event); | |
| 55 | + | |
| 56 | + private FacesViewContextImpl context; | |
| 57 | + | |
| 58 | + public void createCustomContext(@Observes AfterBeanDiscovery event){ | |
| 59 | + context = new FacesViewContextImpl(); | |
| 60 | + event.addContext(context); | |
| 59 | 61 | } |
| 60 | 62 | |
| 61 | 63 | public void addContexts(@Observes final AfterDeploymentValidation event) { |
| 64 | + CustomContextProducer producer = Beans.getReference(CustomContextProducer.class); | |
| 65 | + producer.addRegisteredContext(context); | |
| 66 | + | |
| 62 | 67 | //Ativa o ViewContext |
| 63 | - ContextManager.activate(ViewContext.class, ViewScoped.class); | |
| 68 | + ViewContext ctx = Beans.getReference(FacesViewContextImpl.class); | |
| 69 | + ctx.activate(); | |
| 64 | 70 | } |
| 65 | 71 | |
| 66 | 72 | public void removeContexts(@Observes AfterShutdownProccess event) { |
| 67 | 73 | //Desativa o ViewContext |
| 68 | - ContextManager.deactivate(ViewContext.class, ViewScoped.class); | |
| 74 | + ViewContext ctx = Beans.getReference(FacesViewContextImpl.class); | |
| 75 | + ctx.deactivate(); | |
| 69 | 76 | } |
| 70 | 77 | } | ... | ... |
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/context/FacesViewContextImpl.java
0 → 100644
| ... | ... | @@ -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 | -/* | |
| 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/jsf/src/test/java/test/Tests.java
| ... | ... | @@ -50,7 +50,7 @@ import br.gov.frameworkdemoiselle.annotation.Redirect; |
| 50 | 50 | import br.gov.frameworkdemoiselle.internal.bootstrap.JsfBootstrap; |
| 51 | 51 | import br.gov.frameworkdemoiselle.internal.configuration.ExceptionHandlerConfig; |
| 52 | 52 | import br.gov.frameworkdemoiselle.internal.configuration.JsfSecurityConfig; |
| 53 | -import br.gov.frameworkdemoiselle.internal.context.ViewContext; | |
| 53 | +import br.gov.frameworkdemoiselle.internal.context.FacesViewContextImpl; | |
| 54 | 54 | import br.gov.frameworkdemoiselle.internal.implementation.AbstractExceptionHandler; |
| 55 | 55 | import br.gov.frameworkdemoiselle.internal.implementation.ApplicationExceptionHandler; |
| 56 | 56 | import br.gov.frameworkdemoiselle.internal.implementation.ApplicationExceptionHandlerFactory; |
| ... | ... | @@ -103,7 +103,7 @@ public final class Tests { |
| 103 | 103 | .addClass(FileRenderer.class) |
| 104 | 104 | .addClass(JsfSecurityConfig.class) |
| 105 | 105 | .addClass(ExceptionHandlerConfig.class) |
| 106 | - .addClass(ViewContext.class) | |
| 106 | + .addClass(FacesViewContextImpl.class) | |
| 107 | 107 | .addClass(AuthorizationExceptionHandlerFactory.class) |
| 108 | 108 | .addClass(ApplicationExceptionHandler.class) |
| 109 | 109 | .addClass(FileRendererImpl.class) | ... | ... |
impl/extension/jta/pom.xml
| ... | ... | @@ -71,6 +71,12 @@ |
| 71 | 71 | <groupId>javax.transaction</groupId> |
| 72 | 72 | <artifactId>jta</artifactId> |
| 73 | 73 | </dependency> |
| 74 | + | |
| 75 | + <dependency> | |
| 76 | + <groupId>org.hibernate</groupId> | |
| 77 | + <artifactId>hibernate-entitymanager</artifactId> | |
| 78 | + <scope>test</scope> | |
| 79 | + </dependency> | |
| 74 | 80 | </dependencies> |
| 75 | 81 | |
| 76 | 82 | <repositories> | ... | ... |
impl/extension/jta/src/test/java/jtatransaction/interceptor/InterceptorJTATransactionTest.java
| ... | ... | @@ -6,7 +6,7 @@ import static junit.framework.Assert.assertNull; |
| 6 | 6 | |
| 7 | 7 | import javax.persistence.EntityManager; |
| 8 | 8 | import javax.persistence.PersistenceContext; |
| 9 | -import javax.persistence.TransactionRequiredException; | |
| 9 | +import javax.transaction.TransactionRequiredException; | |
| 10 | 10 | |
| 11 | 11 | import org.jboss.arquillian.container.test.api.Deployment; |
| 12 | 12 | import org.jboss.arquillian.junit.Arquillian; | ... | ... |
impl/extension/jta/src/test/resources/.arquillian-glassfish-embedded.profile
0 → 100644
impl/extension/jta/src/test/resources/.glassfish.profile
impl/extension/se/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/SeBootstrap.java
| ... | ... | @@ -36,41 +36,35 @@ |
| 36 | 36 | */ |
| 37 | 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 | 39 | import javax.enterprise.event.Observes; |
| 43 | -import javax.enterprise.inject.spi.AfterBeanDiscovery; | |
| 44 | 40 | import javax.enterprise.inject.spi.AfterDeploymentValidation; |
| 45 | 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 | 46 | import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess; |
| 47 | +import br.gov.frameworkdemoiselle.util.Beans; | |
| 51 | 48 | |
| 52 | 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 | 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 | 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 | } | ... | ... |