diff --git a/archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/beans.xml b/archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/beans.xml index 2354daf..3d4cdab 100644 --- a/archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/beans.xml +++ b/archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/beans.xml @@ -6,6 +6,7 @@ br.gov.frameworkdemoiselle.internal.interceptor.RequiredPermissionInterceptor br.gov.frameworkdemoiselle.internal.interceptor.RequiredRoleInterceptor br.gov.frameworkdemoiselle.internal.interceptor.TransactionalInterceptor + br.gov.frameworkdemoiselle.internal.interceptor.ConfigurationInterceptor diff --git a/archetype/minimal/src/main/resources/archetype-resources/src/main/resources/META-INF/beans.xml b/archetype/minimal/src/main/resources/archetype-resources/src/main/resources/META-INF/beans.xml index 2354daf..3d4cdab 100644 --- a/archetype/minimal/src/main/resources/archetype-resources/src/main/resources/META-INF/beans.xml +++ b/archetype/minimal/src/main/resources/archetype-resources/src/main/resources/META-INF/beans.xml @@ -6,6 +6,7 @@ br.gov.frameworkdemoiselle.internal.interceptor.RequiredPermissionInterceptor br.gov.frameworkdemoiselle.internal.interceptor.RequiredRoleInterceptor br.gov.frameworkdemoiselle.internal.interceptor.TransactionalInterceptor + br.gov.frameworkdemoiselle.internal.interceptor.ConfigurationInterceptor diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/configuration/Configuration.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/configuration/Configuration.java index a820f80..b4fe5ca 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/configuration/Configuration.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/configuration/Configuration.java @@ -45,6 +45,7 @@ import java.lang.annotation.Target; import javax.enterprise.inject.Stereotype; import javax.inject.Singleton; +import javax.interceptor.InterceptorBinding; /** * Identifies a configuration class, that is, a structure reserved to store configuration values retrieved from a @@ -64,6 +65,7 @@ import javax.inject.Singleton; @Singleton @Stereotype @Inherited +@InterceptorBinding @Target(TYPE) @Retention(RUNTIME) public @interface Configuration { diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ConfigurationBootstrap.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ConfigurationBootstrap.java deleted file mode 100644 index a4c87bf..0000000 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ConfigurationBootstrap.java +++ /dev/null @@ -1,95 +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.bootstrap; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import javax.enterprise.context.RequestScoped; -import javax.enterprise.context.SessionScoped; -import javax.enterprise.event.Observes; -import javax.enterprise.inject.spi.AfterBeanDiscovery; -import javax.enterprise.inject.spi.AfterDeploymentValidation; -import javax.enterprise.inject.spi.AnnotatedType; -import javax.enterprise.inject.spi.BeanManager; -import javax.enterprise.inject.spi.ProcessAnnotatedType; - -import br.gov.frameworkdemoiselle.configuration.Configuration; -import br.gov.frameworkdemoiselle.configuration.ConfigurationException; -import br.gov.frameworkdemoiselle.internal.configuration.ConfigurationLoader; -import br.gov.frameworkdemoiselle.internal.context.ThreadLocalContext; -import br.gov.frameworkdemoiselle.util.Beans; - -/** - * @author SERPRO - */ -public class ConfigurationBootstrap extends AbstractBootstrap { - - private static List> types = Collections.synchronizedList(new ArrayList>()); - - private static final String MSG_PROCESSING = "bootstrap.configuration.processing"; - - private ThreadLocalContext c1; - - private ThreadLocalContext c2; - - public void detectAnnotation(@Observes final ProcessAnnotatedType event, final BeanManager beanManager) { - if (event.getAnnotatedType().isAnnotationPresent(Configuration.class)) { - types.add(event.getAnnotatedType()); - } - } - - public void loadTempContexts(@Observes final AfterBeanDiscovery event) { - c1 = new ThreadLocalContext(RequestScoped.class); - addContext(c1, event); - c2 = new ThreadLocalContext(SessionScoped.class); - addContext(c2, event); - } - - public void processLoader(@Observes final AfterDeploymentValidation event) - throws ConfigurationException { - ConfigurationLoader configurationLoader = Beans.getReference(ConfigurationLoader.class); - for (AnnotatedType type : types) { - getLogger().debug(getBundle().getString(MSG_PROCESSING, type.toString())); - configurationLoader.load(Beans.getReference(type.getJavaClass())); - } - disableContext(c1); - disableContext(c2); - } - -} diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/interceptor/ConfigurationInterceptor.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/interceptor/ConfigurationInterceptor.java new file mode 100644 index 0000000..1a5dcfe --- /dev/null +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/interceptor/ConfigurationInterceptor.java @@ -0,0 +1,73 @@ +/* + * 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.interceptor; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; + +import br.gov.frameworkdemoiselle.configuration.Configuration; +import br.gov.frameworkdemoiselle.internal.configuration.ConfigurationLoader; +import br.gov.frameworkdemoiselle.util.Beans; + +@Interceptor +@Configuration +@SuppressWarnings("cdi-scope") +public class ConfigurationInterceptor implements Serializable { + + private static final long serialVersionUID = 1L; + + private List> cache = new ArrayList>(); + + @AroundInvoke + public synchronized Object manage(final InvocationContext ic) throws Exception { + Class type = ic.getTarget().getClass(); + + if (!cache.contains(type)) { + ConfigurationLoader loader = Beans.getReference(ConfigurationLoader.class); + loader.load(ic.getTarget()); + + cache.add(type); + } + + return ic.proceed(); + } +} 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 188a7f9..ee384da 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,5 +1,4 @@ br.gov.frameworkdemoiselle.internal.bootstrap.CoreBootstrap -br.gov.frameworkdemoiselle.internal.bootstrap.ConfigurationBootstrap br.gov.frameworkdemoiselle.internal.bootstrap.TransactionBootstrap br.gov.frameworkdemoiselle.internal.bootstrap.StartupBootstrap br.gov.frameworkdemoiselle.internal.bootstrap.ShutdownBootstrap -- libgit2 0.21.2