Commit 926849526752f86e83df165d6b556b03dc5801d5
1 parent
bab685f7
Exists in
master
Refatoração de gerenciador de contextos
Showing
17 changed files
with
570 additions
and
322 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/context/CustomContext.java
| 1 | +/* | |
| 2 | + * Demoiselle Framework | |
| 3 | + * Copyright (C) 2010 SERPRO | |
| 4 | + * ---------------------------------------------------------------------------- | |
| 5 | + * This file is part of Demoiselle Framework. | |
| 6 | + * | |
| 7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
| 8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
| 9 | + * as published by the Free Software Foundation. | |
| 10 | + * | |
| 11 | + * This program is distributed in the hope that it will be useful, | |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | + * GNU General Public License for more details. | |
| 15 | + * | |
| 16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
| 17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
| 18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
| 19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
| 20 | + * ---------------------------------------------------------------------------- | |
| 21 | + * Este arquivo é parte do Framework Demoiselle. | |
| 22 | + * | |
| 23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
| 24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
| 25 | + * do Software Livre (FSF). | |
| 26 | + * | |
| 27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
| 28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
| 29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
| 30 | + * para maiores detalhes. | |
| 31 | + * | |
| 32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
| 33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
| 34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
| 35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
| 36 | + */ | |
| 1 | 37 | package br.gov.frameworkdemoiselle.context; |
| 2 | 38 | |
| 3 | 39 | import javax.enterprise.context.spi.Context; |
| ... | ... | @@ -23,5 +59,4 @@ public interface CustomContext extends Context { |
| 23 | 59 | * Deactivates this context, it will clear all beans stored on this context. |
| 24 | 60 | */ |
| 25 | 61 | void deactivate(); |
| 26 | - | |
| 27 | 62 | } | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AbstractLifecycleBootstrap.java
| ... | ... | @@ -51,9 +51,9 @@ import javax.enterprise.inject.spi.ProcessAnnotatedType; |
| 51 | 51 | import org.slf4j.Logger; |
| 52 | 52 | |
| 53 | 53 | import br.gov.frameworkdemoiselle.DemoiselleException; |
| 54 | -import br.gov.frameworkdemoiselle.internal.context.RequestContextImpl; | |
| 55 | -import br.gov.frameworkdemoiselle.internal.context.SessionContextImpl; | |
| 56 | -import br.gov.frameworkdemoiselle.internal.context.ThreadLocalViewContextImpl; | |
| 54 | +import br.gov.frameworkdemoiselle.context.RequestContext; | |
| 55 | +import br.gov.frameworkdemoiselle.context.SessionContext; | |
| 56 | +import br.gov.frameworkdemoiselle.context.ViewContext; | |
| 57 | 57 | import br.gov.frameworkdemoiselle.internal.implementation.AnnotatedMethodProcessor; |
| 58 | 58 | import br.gov.frameworkdemoiselle.util.Beans; |
| 59 | 59 | import br.gov.frameworkdemoiselle.util.NameQualifier; |
| ... | ... | @@ -124,9 +124,9 @@ public abstract class AbstractLifecycleBootstrap<A extends Annotation> implement |
| 124 | 124 | Collections.sort(processors); |
| 125 | 125 | Exception failure = null; |
| 126 | 126 | |
| 127 | - RequestContextImpl tempRequestContext = Beans.getReference(RequestContextImpl.class); | |
| 128 | - SessionContextImpl tempSessionContext = Beans.getReference(SessionContextImpl.class); | |
| 129 | - ThreadLocalViewContextImpl tempViewContext = Beans.getReference(ThreadLocalViewContextImpl.class); | |
| 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 | 132 | tempRequestContext.activate(); | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/CoreBootstrap.java
| ... | ... | @@ -79,15 +79,7 @@ public class CoreBootstrap implements Extension { |
| 79 | 79 | Beans.setBeanManager(beanManager); |
| 80 | 80 | getLogger().info(getBundle().getString("setting-up-bean-manager", Beans.class.getCanonicalName())); |
| 81 | 81 | } |
| 82 | - | |
| 83 | - /*public void initializeCustomContexts(@Observes final AfterBeanDiscovery event) { | |
| 84 | - Beans.getReference(ContextManager2.class); | |
| 85 | - }*/ | |
| 86 | - | |
| 87 | - /*public void terminateCustomContexts(@Observes final BeforeShutdown event) { | |
| 88 | - ContextManager.shutdown(); | |
| 89 | - }*/ | |
| 90 | - | |
| 82 | + | |
| 91 | 83 | public void takeOff(@Observes final AfterDeploymentValidation event) { |
| 92 | 84 | getLogger().info(getBundle().getString("taking-off")); |
| 93 | 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/context/AbstractCustomContext.java
| ... | ... | @@ -39,6 +39,7 @@ 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; |
| ... | ... | @@ -51,8 +52,8 @@ import javax.enterprise.inject.spi.BeanManager; |
| 51 | 52 | import org.slf4j.Logger; |
| 52 | 53 | |
| 53 | 54 | import br.gov.frameworkdemoiselle.context.CustomContext; |
| 55 | +import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; | |
| 54 | 56 | import br.gov.frameworkdemoiselle.util.Beans; |
| 55 | -import br.gov.frameworkdemoiselle.util.NameQualifier; | |
| 56 | 57 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
| 57 | 58 | |
| 58 | 59 | public abstract class AbstractCustomContext implements CustomContext { |
| ... | ... | @@ -60,6 +61,10 @@ public abstract class AbstractCustomContext implements CustomContext { |
| 60 | 61 | private boolean active; |
| 61 | 62 | |
| 62 | 63 | private final Class<? extends Annotation> scope; |
| 64 | + | |
| 65 | + private Logger logger; | |
| 66 | + | |
| 67 | + private transient ResourceBundle bundle; | |
| 63 | 68 | |
| 64 | 69 | AbstractCustomContext(final Class<? extends Annotation> scope) { |
| 65 | 70 | this.scope = scope; |
| ... | ... | @@ -109,25 +114,22 @@ public abstract class AbstractCustomContext implements CustomContext { |
| 109 | 114 | @Override |
| 110 | 115 | public boolean activate() { |
| 111 | 116 | if (!this.active){ |
| 112 | - Logger logger = getLogger(); | |
| 113 | - ResourceBundle bundle = getBundle(); | |
| 114 | - | |
| 115 | 117 | BeanManager beanManager = Beans.getBeanManager(); |
| 116 | 118 | if (beanManager!=null){ |
| 117 | 119 | try{ |
| 118 | 120 | Context ctx = beanManager.getContext(this.getScope()); |
| 119 | 121 | if (ctx!=null){ |
| 120 | - logger.debug( bundle.getString("custom-context-already-activated" , this.getClass().getCanonicalName() , this.getScope().getSimpleName() , ctx.getClass().getCanonicalName() ) ); | |
| 122 | + getLogger().debug( getBundle().getString("custom-context-already-activated" , this.getClass().getCanonicalName() , this.getScope().getSimpleName() , ctx.getClass().getCanonicalName() ) ); | |
| 121 | 123 | } |
| 122 | 124 | } |
| 123 | 125 | catch(ContextNotActiveException ce){ |
| 124 | 126 | this.active = true; |
| 125 | - logger.debug( bundle.getString("custom-context-was-activated" , this.getClass().getCanonicalName() , this.getScope().getSimpleName() ) ); | |
| 127 | + getLogger().debug( getBundle().getString("custom-context-was-activated" , this.getClass().getCanonicalName() , this.getScope().getSimpleName() ) ); | |
| 126 | 128 | } |
| 127 | 129 | } |
| 128 | 130 | else{ |
| 129 | 131 | this.active = true; |
| 130 | - logger.debug( bundle.getString("custom-context-was-activated" , this.getClass().getCanonicalName() , this.getScope().getSimpleName() ) ); | |
| 132 | + getLogger().debug( getBundle().getString("custom-context-was-activated" , this.getClass().getCanonicalName() , this.getScope().getSimpleName() ) ); | |
| 131 | 133 | } |
| 132 | 134 | } |
| 133 | 135 | |
| ... | ... | @@ -159,11 +161,19 @@ public abstract class AbstractCustomContext implements CustomContext { |
| 159 | 161 | } |
| 160 | 162 | |
| 161 | 163 | private ResourceBundle getBundle(){ |
| 162 | - return Beans.getReference(ResourceBundle.class , new NameQualifier("demoiselle-core-bundle")); | |
| 164 | + if (bundle==null){ | |
| 165 | + bundle = new ResourceBundle("demoiselle-core-bundle", Locale.getDefault()); | |
| 166 | + } | |
| 167 | + | |
| 168 | + return bundle; | |
| 163 | 169 | } |
| 164 | 170 | |
| 165 | 171 | private Logger getLogger(){ |
| 166 | - return Beans.getReference(Logger.class); | |
| 172 | + if (logger==null){ | |
| 173 | + logger = LoggerProducer.create(this.getClass()); | |
| 174 | + } | |
| 175 | + | |
| 176 | + return logger; | |
| 167 | 177 | } |
| 168 | 178 | |
| 169 | 179 | static class Store { | ... | ... |
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/ContextManager2.java
| ... | ... | @@ -1,109 +0,0 @@ |
| 1 | -package br.gov.frameworkdemoiselle.internal.context; | |
| 2 | - | |
| 3 | -import java.util.ArrayList; | |
| 4 | -import java.util.List; | |
| 5 | - | |
| 6 | -import javax.annotation.PostConstruct; | |
| 7 | -import javax.annotation.PreDestroy; | |
| 8 | -import javax.enterprise.context.ApplicationScoped; | |
| 9 | -import javax.enterprise.inject.Produces; | |
| 10 | -import javax.enterprise.inject.spi.InjectionPoint; | |
| 11 | - | |
| 12 | -import org.slf4j.Logger; | |
| 13 | - | |
| 14 | -import br.gov.frameworkdemoiselle.context.CustomContext; | |
| 15 | -import br.gov.frameworkdemoiselle.internal.implementation.StrategySelector; | |
| 16 | -import br.gov.frameworkdemoiselle.util.Beans; | |
| 17 | -import br.gov.frameworkdemoiselle.util.NameQualifier; | |
| 18 | -import br.gov.frameworkdemoiselle.util.ResourceBundle; | |
| 19 | - | |
| 20 | -@ApplicationScoped | |
| 21 | -public class ContextManager2 { | |
| 22 | - | |
| 23 | - private List<CustomContext> contexts; | |
| 24 | - | |
| 25 | - @PostConstruct | |
| 26 | - private void initialize(){ | |
| 27 | - if (contexts==null || contexts.isEmpty()){ | |
| 28 | - Logger logger = getLogger(); | |
| 29 | - ResourceBundle bundle = getBundle(); | |
| 30 | - | |
| 31 | - CustomContext ctx; | |
| 32 | - | |
| 33 | - contexts = new ArrayList<CustomContext>(); | |
| 34 | - | |
| 35 | - ctx = new RequestContextImpl(); | |
| 36 | - contexts.add(ctx); | |
| 37 | - logger.debug( bundle.getString("bootstrap-context-added", RequestContextImpl.class.getCanonicalName() , ctx.getScope().getSimpleName() ) ); | |
| 38 | - | |
| 39 | - ctx = new SessionContextImpl(); | |
| 40 | - contexts.add(ctx); | |
| 41 | - logger.debug( bundle.getString("bootstrap-context-added", SessionContextImpl.class.getCanonicalName() , ctx.getScope().getSimpleName() ) ); | |
| 42 | - | |
| 43 | - ctx = new StaticContextImpl(); | |
| 44 | - contexts.add(ctx); | |
| 45 | - logger.debug( bundle.getString("bootstrap-context-added", StaticContextImpl.class.getCanonicalName() , ctx.getScope().getSimpleName() ) ); | |
| 46 | - | |
| 47 | - ctx = new ThreadLocalViewContextImpl(); | |
| 48 | - contexts.add(ctx); | |
| 49 | - logger.debug( bundle.getString("bootstrap-context-added", ThreadLocalViewContextImpl.class.getCanonicalName() , ctx.getScope().getSimpleName() ) ); | |
| 50 | - } | |
| 51 | - } | |
| 52 | - | |
| 53 | - @PreDestroy | |
| 54 | - private void closeContexts(){ | |
| 55 | - for (CustomContext context : contexts){ | |
| 56 | - context.deactivate(); | |
| 57 | - } | |
| 58 | - | |
| 59 | - contexts.clear(); | |
| 60 | - } | |
| 61 | - | |
| 62 | - public void addCustomContext(CustomContext context){ | |
| 63 | - Logger logger = getLogger(); | |
| 64 | - ResourceBundle bundle = getBundle(); | |
| 65 | - | |
| 66 | - if (!contexts.contains(context)){ | |
| 67 | - contexts.add(context); | |
| 68 | - logger.debug( bundle.getString("bootstrap-context-added", context.getClass().getCanonicalName() , context.getScope().getSimpleName() ) ); | |
| 69 | - } | |
| 70 | - else{ | |
| 71 | - logger.debug( bundle.getString("bootstrap-context-already-managed", context.getClass().getCanonicalName() , context.getScope().getSimpleName() ) ); | |
| 72 | - } | |
| 73 | - } | |
| 74 | - | |
| 75 | - @Produces | |
| 76 | - public CustomContext getContext(InjectionPoint ip){ | |
| 77 | - CustomContext producedContext = null; | |
| 78 | - | |
| 79 | - if (ip!=null){ | |
| 80 | - Class<?> beanClass = ip.getBean().getBeanClass(); | |
| 81 | - ArrayList<CustomContext> selectableContexts = new ArrayList<CustomContext>(); | |
| 82 | - | |
| 83 | - for (CustomContext context : contexts){ | |
| 84 | - if ( beanClass.isAssignableFrom( context.getClass() ) ){ | |
| 85 | - if (context.isActive()){ | |
| 86 | - producedContext = context; | |
| 87 | - break; | |
| 88 | - } | |
| 89 | - else{ | |
| 90 | - selectableContexts.add(context); | |
| 91 | - } | |
| 92 | - } | |
| 93 | - } | |
| 94 | - | |
| 95 | - producedContext = StrategySelector.selectInstance(CustomContext.class, selectableContexts); | |
| 96 | - } | |
| 97 | - | |
| 98 | - return producedContext; | |
| 99 | - } | |
| 100 | - | |
| 101 | - private ResourceBundle getBundle(){ | |
| 102 | - return Beans.getReference(ResourceBundle.class , new NameQualifier("demoiselle-core-bundle")); | |
| 103 | - } | |
| 104 | - | |
| 105 | - private Logger getLogger(){ | |
| 106 | - return Beans.getReference(Logger.class); | |
| 107 | - } | |
| 108 | - | |
| 109 | -} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/CustomContext.java
| ... | ... | @@ -1,62 +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 | -/** | |
| 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/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/RequestContextImpl.java
| 1 | +/* | |
| 2 | + * Demoiselle Framework | |
| 3 | + * Copyright (C) 2010 SERPRO | |
| 4 | + * ---------------------------------------------------------------------------- | |
| 5 | + * This file is part of Demoiselle Framework. | |
| 6 | + * | |
| 7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
| 8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
| 9 | + * as published by the Free Software Foundation. | |
| 10 | + * | |
| 11 | + * This program is distributed in the hope that it will be useful, | |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | + * GNU General Public License for more details. | |
| 15 | + * | |
| 16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
| 17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
| 18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
| 19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
| 20 | + * ---------------------------------------------------------------------------- | |
| 21 | + * Este arquivo é parte do Framework Demoiselle. | |
| 22 | + * | |
| 23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
| 24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
| 25 | + * do Software Livre (FSF). | |
| 26 | + * | |
| 27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
| 28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
| 29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
| 30 | + * para maiores detalhes. | |
| 31 | + * | |
| 32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
| 33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
| 34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
| 35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
| 36 | + */ | |
| 37 | +/* | |
| 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 | + */ | |
| 1 | 49 | package br.gov.frameworkdemoiselle.internal.context; |
| 2 | 50 | |
| 3 | 51 | import javax.enterprise.context.RequestScoped; |
| 52 | +import javax.enterprise.inject.Alternative; | |
| 4 | 53 | |
| 5 | 54 | import br.gov.frameworkdemoiselle.annotation.Priority; |
| 6 | 55 | import br.gov.frameworkdemoiselle.context.RequestContext; |
| ... | ... | @@ -12,9 +61,10 @@ import br.gov.frameworkdemoiselle.context.RequestContext; |
| 12 | 61 | * |
| 13 | 62 | */ |
| 14 | 63 | @Priority(Priority.MIN_PRIORITY) |
| 64 | +@Alternative | |
| 15 | 65 | public class RequestContextImpl extends AbstractThreadLocalContext implements RequestContext { |
| 16 | 66 | |
| 17 | - RequestContextImpl() { | |
| 67 | + public RequestContextImpl() { | |
| 18 | 68 | super(RequestScoped.class); |
| 19 | 69 | } |
| 20 | 70 | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/SessionContextImpl.java
| 1 | +/* | |
| 2 | + * Demoiselle Framework | |
| 3 | + * Copyright (C) 2010 SERPRO | |
| 4 | + * ---------------------------------------------------------------------------- | |
| 5 | + * This file is part of Demoiselle Framework. | |
| 6 | + * | |
| 7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
| 8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
| 9 | + * as published by the Free Software Foundation. | |
| 10 | + * | |
| 11 | + * This program is distributed in the hope that it will be useful, | |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | + * GNU General Public License for more details. | |
| 15 | + * | |
| 16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
| 17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
| 18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
| 19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
| 20 | + * ---------------------------------------------------------------------------- | |
| 21 | + * Este arquivo é parte do Framework Demoiselle. | |
| 22 | + * | |
| 23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
| 24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
| 25 | + * do Software Livre (FSF). | |
| 26 | + * | |
| 27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
| 28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
| 29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
| 30 | + * para maiores detalhes. | |
| 31 | + * | |
| 32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
| 33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
| 34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
| 35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
| 36 | + */ | |
| 37 | +/* | |
| 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 | + */ | |
| 1 | 49 | package br.gov.frameworkdemoiselle.internal.context; |
| 2 | 50 | |
| 3 | 51 | import javax.enterprise.context.SessionScoped; |
| 52 | +import javax.enterprise.inject.Alternative; | |
| 4 | 53 | |
| 5 | 54 | import br.gov.frameworkdemoiselle.annotation.Priority; |
| 6 | 55 | import br.gov.frameworkdemoiselle.context.SessionContext; |
| ... | ... | @@ -12,9 +61,10 @@ import br.gov.frameworkdemoiselle.context.SessionContext; |
| 12 | 61 | * |
| 13 | 62 | */ |
| 14 | 63 | @Priority(Priority.MIN_PRIORITY) |
| 15 | -public class SessionContextImpl extends StaticContextImpl implements SessionContext { | |
| 64 | +@Alternative | |
| 65 | +public class SessionContextImpl extends AbstractStaticContext implements SessionContext { | |
| 16 | 66 | |
| 17 | - SessionContextImpl() { | |
| 67 | + public SessionContextImpl() { | |
| 18 | 68 | super(SessionScoped.class); |
| 19 | 69 | } |
| 20 | 70 | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/StaticContextImpl.java
| ... | ... | @@ -34,53 +34,31 @@ |
| 34 | 34 | * ou escreva para a Fundação do Software Livre (FSF) Inc., |
| 35 | 35 | * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. |
| 36 | 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 | + */ | |
| 37 | 49 | package br.gov.frameworkdemoiselle.internal.context; |
| 38 | 50 | |
| 39 | -import java.lang.annotation.Annotation; | |
| 51 | +import javax.enterprise.inject.Alternative; | |
| 40 | 52 | |
| 41 | 53 | import br.gov.frameworkdemoiselle.annotation.Priority; |
| 42 | 54 | import br.gov.frameworkdemoiselle.annotation.StaticScoped; |
| 43 | -import br.gov.frameworkdemoiselle.configuration.Configuration; | |
| 55 | +import br.gov.frameworkdemoiselle.context.StaticContext; | |
| 44 | 56 | |
| 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 | 57 | @Priority(Priority.MIN_PRIORITY) |
| 59 | -public class StaticContextImpl extends AbstractCustomContext { | |
| 58 | +@Alternative | |
| 59 | +public class StaticContextImpl extends AbstractStaticContext implements StaticContext { | |
| 60 | 60 | |
| 61 | - private final static Store store = createStore(); | |
| 62 | - | |
| 63 | - /** | |
| 64 | - * Constructs this context to control the provided scope | |
| 65 | - */ | |
| 66 | - StaticContextImpl(Class<? extends Annotation> scope) { | |
| 67 | - super(scope); | |
| 68 | - } | |
| 69 | - | |
| 70 | - /** | |
| 71 | - * Constructs this context to control {@link StaticScoped} beans | |
| 72 | - */ | |
| 73 | - StaticContextImpl() { | |
| 61 | + public StaticContextImpl() { | |
| 74 | 62 | super(StaticScoped.class); |
| 75 | 63 | } |
| 76 | - | |
| 77 | - @Override | |
| 78 | - protected Store getStore() { | |
| 79 | - return store; | |
| 80 | - } | |
| 81 | - | |
| 82 | - @Override | |
| 83 | - protected boolean isStoreInitialized() { | |
| 84 | - return store!=null; | |
| 85 | - } | |
| 86 | 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
| 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 | + */ | |
| 1 | 49 | package br.gov.frameworkdemoiselle.internal.context; |
| 2 | 50 | |
| 51 | +import javax.enterprise.inject.Alternative; | |
| 52 | + | |
| 3 | 53 | import br.gov.frameworkdemoiselle.annotation.Priority; |
| 4 | 54 | import br.gov.frameworkdemoiselle.annotation.ViewScoped; |
| 5 | 55 | import br.gov.frameworkdemoiselle.context.ViewContext; |
| 6 | 56 | |
| 7 | 57 | @Priority(Priority.MIN_PRIORITY) |
| 58 | +@Alternative | |
| 8 | 59 | public class ThreadLocalViewContextImpl extends AbstractThreadLocalContext implements ViewContext { |
| 9 | 60 | |
| 10 | - ThreadLocalViewContextImpl() { | |
| 61 | + public ThreadLocalViewContextImpl() { | |
| 11 | 62 | super(ViewScoped.class); |
| 12 | 63 | } |
| 13 | 64 | ... | ... |
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,6 +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-selected=Produzindo inst\u00E2ncia do contexto {0} | |
| 71 | 72 | custom-context-was-activated=O contexto {0} foi ativado para o escopo {1} |
| 72 | 73 | custom-context-was-deactivated=O contexto {0} foi desativado para o escopo {1} |
| 73 | 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 | ... | ... |