diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AuthenticatorBootstrap.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AuthenticatorBootstrap.java index 8aedc63..5661a7b 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AuthenticatorBootstrap.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AuthenticatorBootstrap.java @@ -36,13 +36,19 @@ */ package br.gov.frameworkdemoiselle.internal.bootstrap; -import br.gov.frameworkdemoiselle.internal.implementation.DefaultAuthenticator; +import javax.enterprise.event.Observes; +import javax.enterprise.inject.spi.ProcessAnnotatedType; + import br.gov.frameworkdemoiselle.security.Authenticator; +import br.gov.frameworkdemoiselle.util.Reflections; + +public class AuthenticatorBootstrap extends AbstractBootstrap { -public class AuthenticatorBootstrap extends AbstractStrategyBootstrap { + public void processAnnotatedType(@Observes final ProcessAnnotatedType event) { + Class annotated = event.getAnnotatedType().getJavaClass(); - public String getConfigKey() { - return "frameworkdemoiselle.security.authenticator.class"; + if (Reflections.isOfType(annotated, Authenticator.class)) { + event.veto(); + } } - } diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AuthorizerBootstrap.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AuthorizerBootstrap.java index 6c5858e..ec5a849 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AuthorizerBootstrap.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AuthorizerBootstrap.java @@ -36,13 +36,19 @@ */ package br.gov.frameworkdemoiselle.internal.bootstrap; -import br.gov.frameworkdemoiselle.internal.implementation.DefaultAuthorizer; +import javax.enterprise.event.Observes; +import javax.enterprise.inject.spi.ProcessAnnotatedType; + import br.gov.frameworkdemoiselle.security.Authorizer; +import br.gov.frameworkdemoiselle.util.Reflections; + +public class AuthorizerBootstrap extends AbstractBootstrap { -public class AuthorizerBootstrap extends AbstractStrategyBootstrap { + public void processAnnotatedType(@Observes final ProcessAnnotatedType event) { + Class annotated = event.getAnnotatedType().getJavaClass(); - public String getConfigKey() { - return "frameworkdemoiselle.security.authorizer.class"; + if (Reflections.isOfType(annotated, Authorizer.class)) { + event.veto(); + } } - } diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/TransactionBootstrap.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/TransactionBootstrap.java index e9021e3..7132f8c 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/TransactionBootstrap.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/TransactionBootstrap.java @@ -37,13 +37,12 @@ package br.gov.frameworkdemoiselle.internal.bootstrap; import javax.enterprise.event.Observes; -import javax.enterprise.inject.spi.Extension; import javax.enterprise.inject.spi.ProcessAnnotatedType; import br.gov.frameworkdemoiselle.transaction.Transaction; import br.gov.frameworkdemoiselle.util.Reflections; -public class TransactionBootstrap implements Extension { +public class TransactionBootstrap extends AbstractBootstrap { public void processAnnotatedType(@Observes final ProcessAnnotatedType event) { Class annotated = event.getAnnotatedType().getJavaClass(); diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoader.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoader.java index abcbf39..905a5ca 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoader.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoader.java @@ -307,6 +307,10 @@ public class ConfigurationLoader implements Serializable { return value; } + public static ClassLoader getClassLoaderForClass(final String canonicalName) throws FileNotFoundException { + return getClassLoaderForResource(canonicalName.replaceAll("\\.", "/") + ".class"); + } + public static ClassLoader getClassLoaderForResource(final String resource) throws FileNotFoundException { final String stripped = resource.startsWith("/") ? resource.substring(1) : resource; @@ -323,7 +327,7 @@ public class ConfigurationLoader implements Serializable { } if (url == null) { - throw new FileNotFoundException(resource + " not found."); + result = null; } return result; 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 index 36c3925..a9cc9dd 100644 --- 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 @@ -50,7 +50,6 @@ import br.gov.frameworkdemoiselle.util.Beans; @Interceptor @Configuration -@SuppressWarnings("cdi-scope") public class ConfigurationInterceptor implements Serializable { private static final long serialVersionUID = 1L; diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/processor/AbstractProcessor.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/processor/AbstractProcessor.java index 8a45f26..04c4990 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/processor/AbstractProcessor.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/processor/AbstractProcessor.java @@ -60,8 +60,6 @@ public abstract class AbstractProcessor implements Processor { private AnnotatedCallable annotatedCallable; - private ResourceBundleProducer bundleFactory = new ResourceBundleProducer(); - private ResourceBundle bundle; protected static final String BUNDLE_BASE_NAME = "demoiselle-core-bundle"; @@ -109,7 +107,7 @@ public abstract class AbstractProcessor implements Processor { protected ResourceBundle getBundle(String baseName) { if (bundle == null) { - bundle = bundleFactory.create(baseName, Locale.getDefault()); + bundle = ResourceBundleProducer.create(baseName, Locale.getDefault()); } return bundle; diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/AbstractStrategyProducer.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/AbstractStrategyProducer.java index da40caf..c4c7716 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/AbstractStrategyProducer.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/AbstractStrategyProducer.java @@ -40,6 +40,10 @@ import java.io.FileNotFoundException; import java.io.Serializable; import java.net.URL; +import javax.enterprise.context.spi.CreationalContext; +import javax.enterprise.inject.spi.AnnotatedType; +import javax.enterprise.inject.spi.BeanManager; +import javax.enterprise.inject.spi.InjectionTarget; import javax.inject.Inject; import org.apache.commons.configuration.Configuration; @@ -48,6 +52,7 @@ import org.apache.commons.configuration.PropertiesConfiguration; import br.gov.frameworkdemoiselle.annotation.Name; import br.gov.frameworkdemoiselle.configuration.ConfigurationException; import br.gov.frameworkdemoiselle.internal.configuration.ConfigurationLoader; +import br.gov.frameworkdemoiselle.util.Beans; import br.gov.frameworkdemoiselle.util.Reflections; import br.gov.frameworkdemoiselle.util.ResourceBundle; import br.gov.frameworkdemoiselle.util.Strings; @@ -66,6 +71,21 @@ public abstract class AbstractStrategyProducer implements Serial @Name("demoiselle-core-bundle") private ResourceBundle bundle; + @SuppressWarnings("unchecked") + public T create() { + BeanManager beanManager = Beans.getBeanManager(); + + AnnotatedType type = ((AnnotatedType) beanManager.createAnnotatedType(getSelected())); + InjectionTarget it = beanManager.createInjectionTarget(type); + CreationalContext ctx = beanManager.createCreationalContext(null); + + T instance = it.produce(ctx); + it.inject(instance, ctx); + it.postConstruct(instance); + + return instance; + } + protected Class getSelected() { if (selected == null) { selected = loadSelected(); @@ -88,26 +108,7 @@ public abstract class AbstractStrategyProducer implements Serial } return this.defaultClass; - }// public void processAnnotatedType(@Observes final ProcessAnnotatedType event) { - // Class annotated = event.getAnnotatedType().getJavaClass(); - - // - // if (Reflections.isOfType(annotated, getType()) && annotated != selected) { - // event.veto(); - // } - // } - - // public void beforeBeanDiscovery(@Observes final BeforeBeanDiscovery event) { - // selected = loadSelected(); - // } - - // public void processAnnotatedType(@Observes final ProcessAnnotatedType event) { - // Class annotated = event.getAnnotatedType().getJavaClass(); - // - // if (Reflections.isOfType(annotated, getType()) && annotated != selected) { - // event.veto(); - // } - // } + } @SuppressWarnings("unchecked") private Class loadSelected() { @@ -121,12 +122,8 @@ public abstract class AbstractStrategyProducer implements Serial Configuration config = new PropertiesConfiguration(url); canonicalName = config.getString(getConfigKey(), getDefaultClass().getCanonicalName()); - ClassLoader classLoader; - - try { - classLoader = ConfigurationLoader.getClassLoaderForResource(canonicalName.replaceAll("\\.", "/") - + ".class"); - } catch (FileNotFoundException e) { + ClassLoader classLoader = ConfigurationLoader.getClassLoaderForClass(canonicalName); + if (classLoader == null) { classLoader = Thread.currentThread().getContextClassLoader(); } diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/AuthenticatorProducer.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/AuthenticatorProducer.java new file mode 100644 index 0000000..b01fcda --- /dev/null +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/AuthenticatorProducer.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. + */ +/* + * 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.producer; + +import javax.enterprise.context.RequestScoped; +import javax.enterprise.inject.Default; +import javax.enterprise.inject.Produces; + +import br.gov.frameworkdemoiselle.internal.implementation.DefaultAuthenticator; +import br.gov.frameworkdemoiselle.security.Authenticator; + +public class AuthenticatorProducer extends AbstractStrategyProducer { + + private static final long serialVersionUID = 1L; + + @Default + @Produces + @RequestScoped + public Authenticator create() { + return super.create(); + } + + @Override + public String getConfigKey() { + return "frameworkdemoiselle.security.authenticator.class"; + } +} diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/AuthorizerProducer.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/AuthorizerProducer.java new file mode 100644 index 0000000..8092bfe --- /dev/null +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/AuthorizerProducer.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. + */ +/* + * 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.producer; + +import javax.enterprise.context.RequestScoped; +import javax.enterprise.inject.Default; +import javax.enterprise.inject.Produces; + +import br.gov.frameworkdemoiselle.internal.implementation.DefaultAuthorizer; +import br.gov.frameworkdemoiselle.security.Authorizer; + +public class AuthorizerProducer extends AbstractStrategyProducer { + + private static final long serialVersionUID = 1L; + + @Default + @Produces + @RequestScoped + public Authorizer create() { + return super.create(); + } + + @Override + public String getConfigKey() { + return "frameworkdemoiselle.security.authorizer.class"; + } +} diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/ResourceBundleProducer.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/ResourceBundleProducer.java index 1a64a97..022c83a 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/ResourceBundleProducer.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/ResourceBundleProducer.java @@ -46,6 +46,7 @@ import javax.enterprise.inject.spi.InjectionPoint; import br.gov.frameworkdemoiselle.DemoiselleException; import br.gov.frameworkdemoiselle.annotation.Name; +import br.gov.frameworkdemoiselle.util.Beans; import br.gov.frameworkdemoiselle.util.ResourceBundle; /** @@ -82,7 +83,7 @@ public class ResourceBundleProducer implements Serializable { */ @Produces @Default - public ResourceBundle create(InjectionPoint ip, Locale locale) { + public ResourceBundle create(InjectionPoint ip) { String baseName; if (ip != null && ip.getAnnotated().isAnnotationPresent(Name.class)) { @@ -91,6 +92,6 @@ public class ResourceBundleProducer implements Serializable { baseName = "messages"; } - return create(baseName, locale); + return create(baseName, Beans.getReference(Locale.class)); } } diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/TransactionProducer.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/TransactionProducer.java index ebc59f4..dbba9a8 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/TransactionProducer.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/TransactionProducer.java @@ -48,6 +48,7 @@ */ package br.gov.frameworkdemoiselle.internal.producer; +import javax.enterprise.context.RequestScoped; import javax.enterprise.inject.Default; import javax.enterprise.inject.Produces; @@ -60,8 +61,9 @@ public class TransactionProducer extends AbstractStrategyProducer - + + + \ No newline at end of file diff --git a/impl/extension/jta/src/main/java/br/gov/frameworkdemoiselle/transaction/JTATransaction.java b/impl/extension/jta/src/main/java/br/gov/frameworkdemoiselle/transaction/JTATransaction.java index f1455b0..e414c3e 100644 --- a/impl/extension/jta/src/main/java/br/gov/frameworkdemoiselle/transaction/JTATransaction.java +++ b/impl/extension/jta/src/main/java/br/gov/frameworkdemoiselle/transaction/JTATransaction.java @@ -36,12 +36,14 @@ */ package br.gov.frameworkdemoiselle.transaction; +import javax.enterprise.context.RequestScoped; import javax.transaction.Status; import javax.transaction.SystemException; import javax.transaction.UserTransaction; import br.gov.frameworkdemoiselle.util.Beans; +@RequestScoped public class JTATransaction implements Transaction { private static final long serialVersionUID = 1L; -- libgit2 0.21.2