From 926849526752f86e83df165d6b556b03dc5801d5 Mon Sep 17 00:00:00 2001 From: Dancovich Date: Fri, 6 Sep 2013 17:33:49 -0300 Subject: [PATCH] Refatoração de gerenciador de contextos --- impl/core/src/main/java/br/gov/frameworkdemoiselle/context/CustomContext.java | 37 ++++++++++++++++++++++++++++++++++++- impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AbstractLifecycleBootstrap.java | 12 ++++++------ impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/CoreBootstrap.java | 10 +--------- impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/CustomContextBootstrap.java | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/AbstractCustomContext.java | 28 +++++++++++++++++++--------- impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/AbstractStaticContext.java | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/ContextManager2.java | 109 ------------------------------------------------------------------------------------------------------------- impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/CustomContext.java | 62 -------------------------------------------------------------- impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/CustomContextProducer.java | 160 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/RequestContextImpl.java | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/SessionContextImpl.java | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/StaticContextImpl.java | 56 +++++++++++++++++--------------------------------------- impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/ThreadLocalContext.java | 79 ------------------------------------------------------------------------------- impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/ThreadLocalViewContextImpl.java | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++- impl/core/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension | 1 + impl/core/src/main/resources/demoiselle-core-bundle.properties | 1 + impl/core/src/test/java/management/validation/ValidationTest.java | 9 +++++---- 17 files changed, 570 insertions(+), 322 deletions(-) create mode 100644 impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/CustomContextBootstrap.java create mode 100644 impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/AbstractStaticContext.java delete mode 100644 impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/ContextManager2.java delete mode 100644 impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/CustomContext.java create mode 100644 impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/CustomContextProducer.java delete mode 100644 impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/ThreadLocalContext.java diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/context/CustomContext.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/context/CustomContext.java index 2b15cb3..0ad5e3c 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/context/CustomContext.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/context/CustomContext.java @@ -1,3 +1,39 @@ +/* + * Demoiselle Framework + * Copyright (C) 2010 SERPRO + * ---------------------------------------------------------------------------- + * This file is part of Demoiselle Framework. + * + * Demoiselle Framework is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License version 3 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License version 3 + * along with this program; if not, see + * or write to the Free Software Foundation, Inc., 51 Franklin Street, + * Fifth Floor, Boston, MA 02110-1301, USA. + * ---------------------------------------------------------------------------- + * Este arquivo é parte do Framework Demoiselle. + * + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação + * do Software Livre (FSF). + * + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português + * para maiores detalhes. + * + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título + * "LICENCA.txt", junto com esse programa. Se não, acesse + * ou escreva para a Fundação do Software Livre (FSF) Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. + */ package br.gov.frameworkdemoiselle.context; import javax.enterprise.context.spi.Context; @@ -23,5 +59,4 @@ public interface CustomContext extends Context { * Deactivates this context, it will clear all beans stored on this context. */ void deactivate(); - } diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AbstractLifecycleBootstrap.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AbstractLifecycleBootstrap.java index 92aa532..12d1ce0 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AbstractLifecycleBootstrap.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AbstractLifecycleBootstrap.java @@ -51,9 +51,9 @@ import javax.enterprise.inject.spi.ProcessAnnotatedType; import org.slf4j.Logger; import br.gov.frameworkdemoiselle.DemoiselleException; -import br.gov.frameworkdemoiselle.internal.context.RequestContextImpl; -import br.gov.frameworkdemoiselle.internal.context.SessionContextImpl; -import br.gov.frameworkdemoiselle.internal.context.ThreadLocalViewContextImpl; +import br.gov.frameworkdemoiselle.context.RequestContext; +import br.gov.frameworkdemoiselle.context.SessionContext; +import br.gov.frameworkdemoiselle.context.ViewContext; import br.gov.frameworkdemoiselle.internal.implementation.AnnotatedMethodProcessor; import br.gov.frameworkdemoiselle.util.Beans; import br.gov.frameworkdemoiselle.util.NameQualifier; @@ -124,9 +124,9 @@ public abstract class AbstractLifecycleBootstrap implement Collections.sort(processors); Exception failure = null; - RequestContextImpl tempRequestContext = Beans.getReference(RequestContextImpl.class); - SessionContextImpl tempSessionContext = Beans.getReference(SessionContextImpl.class); - ThreadLocalViewContextImpl tempViewContext = Beans.getReference(ThreadLocalViewContextImpl.class); + RequestContext tempRequestContext = Beans.getReference(RequestContext.class); + SessionContext tempSessionContext = Beans.getReference(SessionContext.class); + ViewContext tempViewContext = Beans.getReference(ViewContext.class); if (!registered) { tempRequestContext.activate(); diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/CoreBootstrap.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/CoreBootstrap.java index eb24925..7b2da5d 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/CoreBootstrap.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/CoreBootstrap.java @@ -79,15 +79,7 @@ public class CoreBootstrap implements Extension { Beans.setBeanManager(beanManager); getLogger().info(getBundle().getString("setting-up-bean-manager", Beans.class.getCanonicalName())); } - - /*public void initializeCustomContexts(@Observes final AfterBeanDiscovery event) { - Beans.getReference(ContextManager2.class); - }*/ - - /*public void terminateCustomContexts(@Observes final BeforeShutdown event) { - ContextManager.shutdown(); - }*/ - + public void takeOff(@Observes final AfterDeploymentValidation event) { getLogger().info(getBundle().getString("taking-off")); } diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/CustomContextBootstrap.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/CustomContextBootstrap.java new file mode 100644 index 0000000..5524b88 --- /dev/null +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/CustomContextBootstrap.java @@ -0,0 +1,90 @@ +package br.gov.frameworkdemoiselle.internal.bootstrap; + +import java.util.ArrayList; +import java.util.List; + +import javax.enterprise.event.Observes; +import javax.enterprise.inject.spi.AfterBeanDiscovery; +import javax.enterprise.inject.spi.AfterDeploymentValidation; +import javax.enterprise.inject.spi.Extension; + +import br.gov.frameworkdemoiselle.context.CustomContext; +import br.gov.frameworkdemoiselle.context.StaticContext; +import br.gov.frameworkdemoiselle.internal.context.CustomContextProducer; +import br.gov.frameworkdemoiselle.internal.context.RequestContextImpl; +import br.gov.frameworkdemoiselle.internal.context.SessionContextImpl; +import br.gov.frameworkdemoiselle.internal.context.StaticContextImpl; +import br.gov.frameworkdemoiselle.internal.context.ThreadLocalViewContextImpl; +import br.gov.frameworkdemoiselle.util.Beans; + +/** + * This portable extension registers and starts custom contexts used by + * the framework. + * + * @author serpro + * + */ +public class CustomContextBootstrap implements Extension{ + + private List contexts; + + /*private Logger logger; + + private transient ResourceBundle bundle; + + private Logger getLogger() { + if (this.logger == null) { + this.logger = LoggerProducer.create(CoreBootstrap.class); + } + + return this.logger; + } + + private ResourceBundle getBundle() { + if (bundle == null) { + bundle = new ResourceBundle("demoiselle-core-bundle", Locale.getDefault()); + } + + return bundle; + }*/ + + public void initializeContexts(@Observes AfterBeanDiscovery event){ + //Cadastra os contextos contidos no demoiselle-core + if (contexts==null || contexts.isEmpty()){ + CustomContext ctx; + + contexts = new ArrayList(); + + ctx = new RequestContextImpl(); + contexts.add(ctx); + + ctx = new SessionContextImpl(); + contexts.add(ctx); + + ctx = new StaticContextImpl(); + contexts.add(ctx); + + ctx = new ThreadLocalViewContextImpl(); + contexts.add(ctx); + + for (CustomContext c : contexts){ + event.addContext(c); + } + } + + //Ativa um contexto para gerenciar o StaticScope, um escopo criado para gerenciar classes de configuração. + for (CustomContext ctx : contexts){ + if (ctx instanceof StaticContext){ + StaticContext staticContext = (StaticContext)ctx; + staticContext.activate(); + break; + } + } + } + + public void storeContexts(@Observes AfterDeploymentValidation event){ + CustomContextProducer producer = Beans.getReference(CustomContextProducer.class); + producer.addRegisteredContexts(contexts); + } + +} diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/AbstractCustomContext.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/AbstractCustomContext.java index fb73408..00aab89 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/AbstractCustomContext.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/AbstractCustomContext.java @@ -39,6 +39,7 @@ package br.gov.frameworkdemoiselle.internal.context; import java.lang.annotation.Annotation; import java.util.Collections; import java.util.HashMap; +import java.util.Locale; import java.util.Map; import javax.enterprise.context.ContextNotActiveException; @@ -51,8 +52,8 @@ import javax.enterprise.inject.spi.BeanManager; import org.slf4j.Logger; import br.gov.frameworkdemoiselle.context.CustomContext; +import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; import br.gov.frameworkdemoiselle.util.Beans; -import br.gov.frameworkdemoiselle.util.NameQualifier; import br.gov.frameworkdemoiselle.util.ResourceBundle; public abstract class AbstractCustomContext implements CustomContext { @@ -60,6 +61,10 @@ public abstract class AbstractCustomContext implements CustomContext { private boolean active; private final Class scope; + + private Logger logger; + + private transient ResourceBundle bundle; AbstractCustomContext(final Class scope) { this.scope = scope; @@ -109,25 +114,22 @@ public abstract class AbstractCustomContext implements CustomContext { @Override public boolean activate() { if (!this.active){ - Logger logger = getLogger(); - ResourceBundle bundle = getBundle(); - BeanManager beanManager = Beans.getBeanManager(); if (beanManager!=null){ try{ Context ctx = beanManager.getContext(this.getScope()); if (ctx!=null){ - logger.debug( bundle.getString("custom-context-already-activated" , this.getClass().getCanonicalName() , this.getScope().getSimpleName() , ctx.getClass().getCanonicalName() ) ); + getLogger().debug( getBundle().getString("custom-context-already-activated" , this.getClass().getCanonicalName() , this.getScope().getSimpleName() , ctx.getClass().getCanonicalName() ) ); } } catch(ContextNotActiveException ce){ this.active = true; - logger.debug( bundle.getString("custom-context-was-activated" , this.getClass().getCanonicalName() , this.getScope().getSimpleName() ) ); + getLogger().debug( getBundle().getString("custom-context-was-activated" , this.getClass().getCanonicalName() , this.getScope().getSimpleName() ) ); } } else{ this.active = true; - logger.debug( bundle.getString("custom-context-was-activated" , this.getClass().getCanonicalName() , this.getScope().getSimpleName() ) ); + getLogger().debug( getBundle().getString("custom-context-was-activated" , this.getClass().getCanonicalName() , this.getScope().getSimpleName() ) ); } } @@ -159,11 +161,19 @@ public abstract class AbstractCustomContext implements CustomContext { } private ResourceBundle getBundle(){ - return Beans.getReference(ResourceBundle.class , new NameQualifier("demoiselle-core-bundle")); + if (bundle==null){ + bundle = new ResourceBundle("demoiselle-core-bundle", Locale.getDefault()); + } + + return bundle; } private Logger getLogger(){ - return Beans.getReference(Logger.class); + if (logger==null){ + logger = LoggerProducer.create(this.getClass()); + } + + return logger; } static class Store { diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/AbstractStaticContext.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/AbstractStaticContext.java new file mode 100644 index 0000000..8db69fe --- /dev/null +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/AbstractStaticContext.java @@ -0,0 +1,79 @@ +/* + * Demoiselle Framework + * Copyright (C) 2010 SERPRO + * ---------------------------------------------------------------------------- + * This file is part of Demoiselle Framework. + * + * Demoiselle Framework is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License version 3 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License version 3 + * along with this program; if not, see + * or write to the Free Software Foundation, Inc., 51 Franklin Street, + * Fifth Floor, Boston, MA 02110-1301, USA. + * ---------------------------------------------------------------------------- + * Este arquivo é parte do Framework Demoiselle. + * + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação + * do Software Livre (FSF). + * + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português + * para maiores detalhes. + * + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título + * "LICENCA.txt", junto com esse programa. Se não, acesse + * ou escreva para a Fundação do Software Livre (FSF) Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. + */ +package br.gov.frameworkdemoiselle.internal.context; + +import java.lang.annotation.Annotation; + +import br.gov.frameworkdemoiselle.annotation.Priority; +import br.gov.frameworkdemoiselle.annotation.StaticScoped; +import br.gov.frameworkdemoiselle.configuration.Configuration; + +/** + * + *

This context has a unified static store that keeps all scoped beans available + * to all threads of an application. It is intended to keep beans avaliable to + * long lasting scopes (like the Session scope and Application scope) on environments + * that lack those scopes by default (like desktop Swing applications).

+ * + *

This context also keeps beans of the custom {@link StaticScoped} scope, like the beans + * annotated with {@link Configuration}.

+ * + * @author serpro + * + */ +@Priority(Priority.MIN_PRIORITY) +public abstract class AbstractStaticContext extends AbstractCustomContext { + + private final static Store store = createStore(); + + /** + * Constructs this context to control the provided scope + */ + AbstractStaticContext(Class scope) { + super(scope); + } + + @Override + protected Store getStore() { + return store; + } + + @Override + protected boolean isStoreInitialized() { + return store!=null; + } +} diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/ContextManager2.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/ContextManager2.java deleted file mode 100644 index 4198b77..0000000 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/ContextManager2.java +++ /dev/null @@ -1,109 +0,0 @@ -package br.gov.frameworkdemoiselle.internal.context; - -import java.util.ArrayList; -import java.util.List; - -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; -import javax.enterprise.context.ApplicationScoped; -import javax.enterprise.inject.Produces; -import javax.enterprise.inject.spi.InjectionPoint; - -import org.slf4j.Logger; - -import br.gov.frameworkdemoiselle.context.CustomContext; -import br.gov.frameworkdemoiselle.internal.implementation.StrategySelector; -import br.gov.frameworkdemoiselle.util.Beans; -import br.gov.frameworkdemoiselle.util.NameQualifier; -import br.gov.frameworkdemoiselle.util.ResourceBundle; - -@ApplicationScoped -public class ContextManager2 { - - private List contexts; - - @PostConstruct - private void initialize(){ - if (contexts==null || contexts.isEmpty()){ - Logger logger = getLogger(); - ResourceBundle bundle = getBundle(); - - CustomContext ctx; - - contexts = new ArrayList(); - - ctx = new RequestContextImpl(); - contexts.add(ctx); - logger.debug( bundle.getString("bootstrap-context-added", RequestContextImpl.class.getCanonicalName() , ctx.getScope().getSimpleName() ) ); - - ctx = new SessionContextImpl(); - contexts.add(ctx); - logger.debug( bundle.getString("bootstrap-context-added", SessionContextImpl.class.getCanonicalName() , ctx.getScope().getSimpleName() ) ); - - ctx = new StaticContextImpl(); - contexts.add(ctx); - logger.debug( bundle.getString("bootstrap-context-added", StaticContextImpl.class.getCanonicalName() , ctx.getScope().getSimpleName() ) ); - - ctx = new ThreadLocalViewContextImpl(); - contexts.add(ctx); - logger.debug( bundle.getString("bootstrap-context-added", ThreadLocalViewContextImpl.class.getCanonicalName() , ctx.getScope().getSimpleName() ) ); - } - } - - @PreDestroy - private void closeContexts(){ - for (CustomContext context : contexts){ - context.deactivate(); - } - - contexts.clear(); - } - - public void addCustomContext(CustomContext context){ - Logger logger = getLogger(); - ResourceBundle bundle = getBundle(); - - if (!contexts.contains(context)){ - contexts.add(context); - logger.debug( bundle.getString("bootstrap-context-added", context.getClass().getCanonicalName() , context.getScope().getSimpleName() ) ); - } - else{ - logger.debug( bundle.getString("bootstrap-context-already-managed", context.getClass().getCanonicalName() , context.getScope().getSimpleName() ) ); - } - } - - @Produces - public CustomContext getContext(InjectionPoint ip){ - CustomContext producedContext = null; - - if (ip!=null){ - Class beanClass = ip.getBean().getBeanClass(); - ArrayList selectableContexts = new ArrayList(); - - for (CustomContext context : contexts){ - if ( beanClass.isAssignableFrom( context.getClass() ) ){ - if (context.isActive()){ - producedContext = context; - break; - } - else{ - selectableContexts.add(context); - } - } - } - - producedContext = StrategySelector.selectInstance(CustomContext.class, selectableContexts); - } - - return producedContext; - } - - private ResourceBundle getBundle(){ - return Beans.getReference(ResourceBundle.class , new NameQualifier("demoiselle-core-bundle")); - } - - private Logger getLogger(){ - return Beans.getReference(Logger.class); - } - -} diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/CustomContext.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/CustomContext.java deleted file mode 100644 index bd025c1..0000000 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/CustomContext.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Demoiselle Framework - * Copyright (C) 2010 SERPRO - * ---------------------------------------------------------------------------- - * This file is part of Demoiselle Framework. - * - * Demoiselle Framework is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License version 3 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License version 3 - * along with this program; if not, see - * or write to the Free Software Foundation, Inc., 51 Franklin Street, - * Fifth Floor, Boston, MA 02110-1301, USA. - * ---------------------------------------------------------------------------- - * Este arquivo é parte do Framework Demoiselle. - * - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação - * do Software Livre (FSF). - * - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português - * para maiores detalhes. - * - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título - * "LICENCA.txt", junto com esse programa. Se não, acesse - * ou escreva para a Fundação do Software Livre (FSF) Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. - */ -package br.gov.frameworkdemoiselle.internal.context; - -import javax.enterprise.context.spi.Context; - -/** - * - * Base interface for contexts managed by the framework. - * - * @author serpro - * - */ -public interface CustomContext extends Context { - - /** - * Activates a custom context - * - * @return true if context was activated, false if there was already another active - * context for the same scope and the activation of this scope failed. - */ - boolean activate(); - - /** - * Deactivates this context, it will clear all beans stored on this context. - */ - void deactivate(); -} diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/CustomContextProducer.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/CustomContextProducer.java new file mode 100644 index 0000000..529e265 --- /dev/null +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/CustomContextProducer.java @@ -0,0 +1,160 @@ +package br.gov.frameworkdemoiselle.internal.context; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Locale; + +import javax.annotation.PreDestroy; +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.inject.Produces; +import javax.enterprise.inject.spi.InjectionPoint; + +import org.slf4j.Logger; + +import br.gov.frameworkdemoiselle.context.CustomContext; +import br.gov.frameworkdemoiselle.context.RequestContext; +import br.gov.frameworkdemoiselle.context.SessionContext; +import br.gov.frameworkdemoiselle.context.StaticContext; +import br.gov.frameworkdemoiselle.context.ViewContext; +import br.gov.frameworkdemoiselle.internal.bootstrap.CustomContextBootstrap; +import br.gov.frameworkdemoiselle.internal.implementation.StrategySelector; +import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; +import br.gov.frameworkdemoiselle.util.ResourceBundle; + +/** + * Produces instances of {@link CustomContext} to control contexts not active + * by the container + * + * @author serpro + * + */ +@ApplicationScoped +public class CustomContextProducer { + + private Logger logger; + + private transient ResourceBundle bundle; + + private List contexts = new ArrayList(); + + /** + * Store a list of contexts into this producer. The contexts must have + * been registered into CDI by a portable extension, this method will not do this. + * + */ + public void addRegisteredContexts(Collection contexts){ + for (CustomContext context : contexts){ + addRegisteredContext(context); + } + } + + /** + * Store a context into this producer. The context must have + * been registered into CDI by a portable extension, this method will not do this. + * + */ + public void addRegisteredContext(CustomContext context){ + Logger logger = getLogger(); + ResourceBundle bundle = getBundle(); + + if (!contexts.contains(context)){ + contexts.add(context); + logger.debug( bundle.getString("bootstrap-context-added", context.getClass().getCanonicalName() , context.getScope().getSimpleName() ) ); + } + else{ + logger.debug( bundle.getString("bootstrap-context-already-managed", context.getClass().getCanonicalName() , context.getScope().getSimpleName() ) ); + } + } + + /** + * Deactivates all registered contexts and clear the context collection + */ + @PreDestroy + public void closeContexts(){ + //Desativa todos os contextos registrados. + for (CustomContext context : contexts){ + context.deactivate(); + } + + contexts.clear(); + } + + @Produces + public RequestContext getRequestContext(InjectionPoint ip , CustomContextBootstrap extension){ + return getContext(ip, extension); + } + + @Produces + public SessionContext getSessionContext(InjectionPoint ip , CustomContextBootstrap extension){ + return getContext(ip, extension); + } + + @Produces + public ViewContext getViewContext(InjectionPoint ip , CustomContextBootstrap extension){ + return getContext(ip, extension); + } + + @Produces + public StaticContext getStaticContext(InjectionPoint ip , CustomContextBootstrap extension){ + return getContext(ip, extension); + } + + + @SuppressWarnings("unchecked") + private T getContext(InjectionPoint ip , CustomContextBootstrap extension){ + T producedContext = null; + + if (ip!=null){ + Class beanClass = (Class) ip.getType(); + producedContext = (T) getContext(beanClass); + } + + if (producedContext!=null){ + getLogger().debug( getBundle().getString("custom-context-selected" , producedContext.getClass().getCanonicalName()) ); + } + + return producedContext; + } + + private CustomContext getContext(Class contextClass){ + CustomContext producedContext = null; + + ArrayList selectableContexts = new ArrayList(); + + for (CustomContext context : contexts){ + if ( contextClass.isAssignableFrom( context.getClass() ) ){ + if (context.isActive()){ + producedContext = context; + break; + } + else{ + selectableContexts.add(context); + } + } + } + + if (producedContext==null && !selectableContexts.isEmpty()){ + producedContext = StrategySelector.selectInstance(CustomContext.class, selectableContexts); + } + + return producedContext; + } + + private Logger getLogger() { + if (this.logger == null) { + this.logger = LoggerProducer.create(this.getClass()); + } + + return this.logger; + } + + private ResourceBundle getBundle() { + if (bundle == null) { + bundle = new ResourceBundle("demoiselle-core-bundle", Locale.getDefault()); + } + + return bundle; + } + +} diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/RequestContextImpl.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/RequestContextImpl.java index 0b4d967..c043acf 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/RequestContextImpl.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/RequestContextImpl.java @@ -1,6 +1,55 @@ +/* + * Demoiselle Framework + * Copyright (C) 2010 SERPRO + * ---------------------------------------------------------------------------- + * This file is part of Demoiselle Framework. + * + * Demoiselle Framework is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License version 3 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License version 3 + * along with this program; if not, see + * or write to the Free Software Foundation, Inc., 51 Franklin Street, + * Fifth Floor, Boston, MA 02110-1301, USA. + * ---------------------------------------------------------------------------- + * Este arquivo é parte do Framework Demoiselle. + * + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação + * do Software Livre (FSF). + * + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português + * para maiores detalhes. + * + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título + * "LICENCA.txt", junto com esse programa. Se não, acesse + * ou escreva para a Fundação do Software Livre (FSF) Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. + */ +/* + * Demoiselle Framework Copyright (c) 2010 Serpro and other contributors as indicated by the @author tag. See the + * copyright.txt in the distribution for a full listing of contributors. Demoiselle Framework is an open source Java EE + * library designed to accelerate the development of transactional database Web applications. Demoiselle Framework is + * released under the terms of the LGPL license 3 http://www.gnu.org/licenses/lgpl.html LGPL License 3 This file is part + * of Demoiselle Framework. Demoiselle Framework is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License 3 as published by the Free Software Foundation. Demoiselle Framework + * is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You + * should have received a copy of the GNU Lesser General Public License along with Demoiselle Framework. If not, see + * . + */ package br.gov.frameworkdemoiselle.internal.context; import javax.enterprise.context.RequestScoped; +import javax.enterprise.inject.Alternative; import br.gov.frameworkdemoiselle.annotation.Priority; import br.gov.frameworkdemoiselle.context.RequestContext; @@ -12,9 +61,10 @@ import br.gov.frameworkdemoiselle.context.RequestContext; * */ @Priority(Priority.MIN_PRIORITY) +@Alternative public class RequestContextImpl extends AbstractThreadLocalContext implements RequestContext { - RequestContextImpl() { + public RequestContextImpl() { super(RequestScoped.class); } diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/SessionContextImpl.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/SessionContextImpl.java index 073ea80..329ac12 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/SessionContextImpl.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/SessionContextImpl.java @@ -1,6 +1,55 @@ +/* + * Demoiselle Framework + * Copyright (C) 2010 SERPRO + * ---------------------------------------------------------------------------- + * This file is part of Demoiselle Framework. + * + * Demoiselle Framework is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License version 3 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License version 3 + * along with this program; if not, see + * or write to the Free Software Foundation, Inc., 51 Franklin Street, + * Fifth Floor, Boston, MA 02110-1301, USA. + * ---------------------------------------------------------------------------- + * Este arquivo é parte do Framework Demoiselle. + * + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação + * do Software Livre (FSF). + * + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português + * para maiores detalhes. + * + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título + * "LICENCA.txt", junto com esse programa. Se não, acesse + * ou escreva para a Fundação do Software Livre (FSF) Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. + */ +/* + * Demoiselle Framework Copyright (c) 2010 Serpro and other contributors as indicated by the @author tag. See the + * copyright.txt in the distribution for a full listing of contributors. Demoiselle Framework is an open source Java EE + * library designed to accelerate the development of transactional database Web applications. Demoiselle Framework is + * released under the terms of the LGPL license 3 http://www.gnu.org/licenses/lgpl.html LGPL License 3 This file is part + * of Demoiselle Framework. Demoiselle Framework is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License 3 as published by the Free Software Foundation. Demoiselle Framework + * is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You + * should have received a copy of the GNU Lesser General Public License along with Demoiselle Framework. If not, see + * . + */ package br.gov.frameworkdemoiselle.internal.context; import javax.enterprise.context.SessionScoped; +import javax.enterprise.inject.Alternative; import br.gov.frameworkdemoiselle.annotation.Priority; import br.gov.frameworkdemoiselle.context.SessionContext; @@ -12,9 +61,10 @@ import br.gov.frameworkdemoiselle.context.SessionContext; * */ @Priority(Priority.MIN_PRIORITY) -public class SessionContextImpl extends StaticContextImpl implements SessionContext { +@Alternative +public class SessionContextImpl extends AbstractStaticContext implements SessionContext { - SessionContextImpl() { + public SessionContextImpl() { super(SessionScoped.class); } diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/StaticContextImpl.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/StaticContextImpl.java index 328dece..706cfb9 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/StaticContextImpl.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/StaticContextImpl.java @@ -34,53 +34,31 @@ * ou escreva para a Fundação do Software Livre (FSF) Inc., * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. */ +/* + * Demoiselle Framework Copyright (c) 2010 Serpro and other contributors as indicated by the @author tag. See the + * copyright.txt in the distribution for a full listing of contributors. Demoiselle Framework is an open source Java EE + * library designed to accelerate the development of transactional database Web applications. Demoiselle Framework is + * released under the terms of the LGPL license 3 http://www.gnu.org/licenses/lgpl.html LGPL License 3 This file is part + * of Demoiselle Framework. Demoiselle Framework is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License 3 as published by the Free Software Foundation. Demoiselle Framework + * is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You + * should have received a copy of the GNU Lesser General Public License along with Demoiselle Framework. If not, see + * . + */ package br.gov.frameworkdemoiselle.internal.context; -import java.lang.annotation.Annotation; +import javax.enterprise.inject.Alternative; import br.gov.frameworkdemoiselle.annotation.Priority; import br.gov.frameworkdemoiselle.annotation.StaticScoped; -import br.gov.frameworkdemoiselle.configuration.Configuration; +import br.gov.frameworkdemoiselle.context.StaticContext; -/** - * - *

This context has a unified static store that keeps all scoped beans available - * to all threads of an application. It is intended to keep beans avaliable to - * long lasting scopes (like the Session scope and Application scope) on environments - * that lack those scopes by default (like desktop Swing applications).

- * - *

This context also keeps beans of the custom {@link StaticScoped} scope, like the beans - * annotated with {@link Configuration}.

- * - * @author serpro - * - */ @Priority(Priority.MIN_PRIORITY) -public class StaticContextImpl extends AbstractCustomContext { +@Alternative +public class StaticContextImpl extends AbstractStaticContext implements StaticContext { - private final static Store store = createStore(); - - /** - * Constructs this context to control the provided scope - */ - StaticContextImpl(Class scope) { - super(scope); - } - - /** - * Constructs this context to control {@link StaticScoped} beans - */ - StaticContextImpl() { + public StaticContextImpl() { super(StaticScoped.class); } - - @Override - protected Store getStore() { - return store; - } - - @Override - protected boolean isStoreInitialized() { - return store!=null; - } } diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/ThreadLocalContext.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/ThreadLocalContext.java deleted file mode 100644 index e776594..0000000 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/ThreadLocalContext.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Demoiselle Framework - * Copyright (C) 2010 SERPRO - * ---------------------------------------------------------------------------- - * This file is part of Demoiselle Framework. - * - * Demoiselle Framework is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License version 3 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License version 3 - * along with this program; if not, see - * or write to the Free Software Foundation, Inc., 51 Franklin Street, - * Fifth Floor, Boston, MA 02110-1301, USA. - * ---------------------------------------------------------------------------- - * Este arquivo é parte do Framework Demoiselle. - * - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação - * do Software Livre (FSF). - * - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português - * para maiores detalhes. - * - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título - * "LICENCA.txt", junto com esse programa. Se não, acesse - * ou escreva para a Fundação do Software Livre (FSF) Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. - */ -/* - * Demoiselle Framework Copyright (c) 2010 Serpro and other contributors as indicated by the @author tag. See the - * copyright.txt in the distribution for a full listing of contributors. Demoiselle Framework is an open source Java EE - * library designed to accelerate the development of transactional database Web applications. Demoiselle Framework is - * released under the terms of the LGPL license 3 http://www.gnu.org/licenses/lgpl.html LGPL License 3 This file is part - * of Demoiselle Framework. Demoiselle Framework is free software: you can redistribute it and/or modify it under the - * terms of the GNU Lesser General Public License 3 as published by the Free Software Foundation. Demoiselle Framework - * is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You - * should have received a copy of the GNU Lesser General Public License along with Demoiselle Framework. If not, see - * . - */ -package br.gov.frameworkdemoiselle.internal.context; - -import java.lang.annotation.Annotation; - -/** - * Base context that has a separated store for each thread - * - * @author SERPRO - */ -public class ThreadLocalContext extends AbstractCustomContext { - - private final ThreadLocal threadLocal = new ThreadLocal(); - - public ThreadLocalContext(final Class scope) { - super(scope); - } - - @Override - protected boolean isStoreInitialized() { - return threadLocal.get()!=null; - } - - @Override - protected Store getStore() { - if (this.threadLocal.get() == null) { - this.threadLocal.set(createStore()); - } - - return this.threadLocal.get(); - } -} diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/ThreadLocalViewContextImpl.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/ThreadLocalViewContextImpl.java index 992ed6f..08c0929 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/ThreadLocalViewContextImpl.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/ThreadLocalViewContextImpl.java @@ -1,13 +1,64 @@ +/* + * Demoiselle Framework + * Copyright (C) 2010 SERPRO + * ---------------------------------------------------------------------------- + * This file is part of Demoiselle Framework. + * + * Demoiselle Framework is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License version 3 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License version 3 + * along with this program; if not, see + * or write to the Free Software Foundation, Inc., 51 Franklin Street, + * Fifth Floor, Boston, MA 02110-1301, USA. + * ---------------------------------------------------------------------------- + * Este arquivo é parte do Framework Demoiselle. + * + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação + * do Software Livre (FSF). + * + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português + * para maiores detalhes. + * + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título + * "LICENCA.txt", junto com esse programa. Se não, acesse + * ou escreva para a Fundação do Software Livre (FSF) Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. + */ +/* + * Demoiselle Framework Copyright (c) 2010 Serpro and other contributors as indicated by the @author tag. See the + * copyright.txt in the distribution for a full listing of contributors. Demoiselle Framework is an open source Java EE + * library designed to accelerate the development of transactional database Web applications. Demoiselle Framework is + * released under the terms of the LGPL license 3 http://www.gnu.org/licenses/lgpl.html LGPL License 3 This file is part + * of Demoiselle Framework. Demoiselle Framework is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License 3 as published by the Free Software Foundation. Demoiselle Framework + * is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You + * should have received a copy of the GNU Lesser General Public License along with Demoiselle Framework. If not, see + * . + */ package br.gov.frameworkdemoiselle.internal.context; +import javax.enterprise.inject.Alternative; + import br.gov.frameworkdemoiselle.annotation.Priority; import br.gov.frameworkdemoiselle.annotation.ViewScoped; import br.gov.frameworkdemoiselle.context.ViewContext; @Priority(Priority.MIN_PRIORITY) +@Alternative public class ThreadLocalViewContextImpl extends AbstractThreadLocalContext implements ViewContext { - ThreadLocalViewContextImpl() { + public ThreadLocalViewContextImpl() { super(ViewScoped.class); } diff --git a/impl/core/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension b/impl/core/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension index 0310ac2..a924896 100644 --- a/impl/core/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension +++ b/impl/core/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension @@ -1,4 +1,5 @@ br.gov.frameworkdemoiselle.internal.bootstrap.CoreBootstrap +br.gov.frameworkdemoiselle.internal.bootstrap.CustomContextBootstrap br.gov.frameworkdemoiselle.internal.bootstrap.ConfigurationBootstrap br.gov.frameworkdemoiselle.internal.bootstrap.ManagementBootstrap br.gov.frameworkdemoiselle.internal.bootstrap.StartupBootstrap diff --git a/impl/core/src/main/resources/demoiselle-core-bundle.properties b/impl/core/src/main/resources/demoiselle-core-bundle.properties index 0ee1932..d06d244 100644 --- a/impl/core/src/main/resources/demoiselle-core-bundle.properties +++ b/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} 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 executing-all=Executando todos os \: {0} +custom-context-selected=Produzindo inst\u00E2ncia do contexto {0} custom-context-was-activated=O contexto {0} foi ativado para o escopo {1} custom-context-was-deactivated=O contexto {0} foi desativado para o escopo {1} custom-context-already-activated=N\u00E3o foi poss\u00EDvel ativar o contexto {0}, o escopo {1} j\u00E1 est\u00E1 ativo no contexto {2} diff --git a/impl/core/src/test/java/management/validation/ValidationTest.java b/impl/core/src/test/java/management/validation/ValidationTest.java index 092ebf8..81bee1b 100644 --- a/impl/core/src/test/java/management/validation/ValidationTest.java +++ b/impl/core/src/test/java/management/validation/ValidationTest.java @@ -1,5 +1,7 @@ package management.validation; +import javax.validation.ConstraintViolationException; + import management.testclasses.DummyManagedClass; import management.testclasses.DummyManagementExtension; import management.testclasses.DummyValidator; @@ -14,7 +16,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import test.Tests; -import br.gov.frameworkdemoiselle.DemoiselleException; import br.gov.frameworkdemoiselle.util.Beans; @RunWith(Arquillian.class) @@ -52,8 +53,8 @@ public class ValidationTest { store.setProperty(DummyManagedClass.class, "id", (Integer) null); Assert.fail(); - } catch (DemoiselleException de) { - // Classes de gerenciamento disparam Demoiselle Exception quando uma validação falha + } catch (ConstraintViolationException ce) { + // Classes de gerenciamento disparam ConstraintViolationException quando uma validação falha } } @@ -72,7 +73,7 @@ public class ValidationTest { store.setProperty(DummyManagedClass.class, "gender", "J"); Assert.fail(); - } catch (DemoiselleException e) { + } catch (ConstraintViolationException e) { Assert.assertTrue(e.getMessage().contains("Test Message")); } -- libgit2 0.21.2