Commit f9b2d89fc6f83efc54556f0533079edb0da767c5
Exists in
master
Merge branch '2.3' of https://github.com/demoiselle/framework.git into 2.3
Showing
17 changed files
with
123 additions
and
165 deletions
Show diff stats
archetype/jsf-jpa/src/main/resources/archetype-resources/pom.xml
| @@ -38,9 +38,10 @@ | @@ -38,9 +38,10 @@ | ||
| 38 | <artifactId>primefaces</artifactId> | 38 | <artifactId>primefaces</artifactId> |
| 39 | <scope>compile</scope> | 39 | <scope>compile</scope> |
| 40 | </dependency> | 40 | </dependency> |
| 41 | + | ||
| 41 | <dependency> | 42 | <dependency> |
| 42 | - <groupId>org.powermock</groupId> | ||
| 43 | - <artifactId>powermock-api-easymock</artifactId> | 43 | + <groupId>org.slf4j</groupId> |
| 44 | + <artifactId>slf4j-log4j12</artifactId> | ||
| 44 | <scope>test</scope> | 45 | <scope>test</scope> |
| 45 | </dependency> | 46 | </dependency> |
| 46 | </dependencies> | 47 | </dependencies> |
archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/java/persistence/BookmarkDAO.java
| 1 | package ${package}.persistence; | 1 | package ${package}.persistence; |
| 2 | 2 | ||
| 3 | -import javax.inject.Inject; | ||
| 4 | - | ||
| 5 | -import org.slf4j.Logger; | ||
| 6 | - | ||
| 7 | import br.gov.frameworkdemoiselle.stereotype.PersistenceController; | 3 | import br.gov.frameworkdemoiselle.stereotype.PersistenceController; |
| 8 | import br.gov.frameworkdemoiselle.template.JPACrud; | 4 | import br.gov.frameworkdemoiselle.template.JPACrud; |
| 9 | 5 |
archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/resources/log4j.properties
| 1 | -# Set root logger level to DEBUG and its only appender to A1. | ||
| 2 | log4j.rootLogger=INFO, A1 | 1 | log4j.rootLogger=INFO, A1 |
| 3 | -log4j.logger.br.gov.demoiselle=DEBUG, A1 | ||
| 4 | - | ||
| 5 | -# A1 is set to be a ConsoleAppender. | ||
| 6 | log4j.appender.A1=org.apache.log4j.ConsoleAppender | 2 | log4j.appender.A1=org.apache.log4j.ConsoleAppender |
| 7 | - | ||
| 8 | -# A1 uses PatternLayout. | ||
| 9 | log4j.appender.A1.layout=org.apache.log4j.PatternLayout | 3 | log4j.appender.A1.layout=org.apache.log4j.PatternLayout |
| 10 | -log4j.appender.A1.layout.ConversionPattern=%-4r %-5p %c - %m%n | ||
| 11 | \ No newline at end of file | 4 | \ No newline at end of file |
| 5 | +log4j.appender.A1.layout.ConversionPattern=%-4r %-5p %c - %m%n |
archetype/jsf-jpa/src/main/resources/archetype-resources/src/test/java/readme.txt
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ApplicationLifecycleEvent.java
| @@ -1,42 +0,0 @@ | @@ -1,42 +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.bootstrap; | ||
| 38 | - | ||
| 39 | -interface ApplicationLifecycleEvent { | ||
| 40 | - | ||
| 41 | - boolean removeProcessors(); | ||
| 42 | -} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AsbratctLifecycleBootstrap.java
| @@ -72,6 +72,8 @@ public abstract class AsbratctLifecycleBootstrap<A extends Annotation> extends A | @@ -72,6 +72,8 @@ public abstract class AsbratctLifecycleBootstrap<A extends Annotation> extends A | ||
| 72 | 72 | ||
| 73 | private AfterBeanDiscovery afterBeanDiscoveryEvent; | 73 | private AfterBeanDiscovery afterBeanDiscoveryEvent; |
| 74 | 74 | ||
| 75 | + private boolean registered = false; | ||
| 76 | + | ||
| 75 | protected abstract <T> AnnotatedMethodProcessor<T> newProcessorInstance(AnnotatedMethod<T> annotatedMethod, | 77 | protected abstract <T> AnnotatedMethodProcessor<T> newProcessorInstance(AnnotatedMethod<T> annotatedMethod, |
| 76 | BeanManager beanManager); | 78 | BeanManager beanManager); |
| 77 | 79 | ||
| @@ -105,22 +107,20 @@ public abstract class AsbratctLifecycleBootstrap<A extends Annotation> extends A | @@ -105,22 +107,20 @@ public abstract class AsbratctLifecycleBootstrap<A extends Annotation> extends A | ||
| 105 | afterBeanDiscoveryEvent = event; | 107 | afterBeanDiscoveryEvent = event; |
| 106 | } | 108 | } |
| 107 | 109 | ||
| 108 | - private boolean x = true; | ||
| 109 | - | ||
| 110 | @SuppressWarnings({ "unchecked", "rawtypes" }) | 110 | @SuppressWarnings({ "unchecked", "rawtypes" }) |
| 111 | - protected synchronized void proccessEvent(final ApplicationLifecycleEvent event) { | 111 | + protected synchronized void proccessEvent() { |
| 112 | getLogger().debug( | 112 | getLogger().debug( |
| 113 | getBundle("demoiselle-core-bundle").getString("executing-all", annotationClass.getSimpleName())); | 113 | getBundle("demoiselle-core-bundle").getString("executing-all", annotationClass.getSimpleName())); |
| 114 | 114 | ||
| 115 | Collections.sort(processors); | 115 | Collections.sort(processors); |
| 116 | Throwable failure = null; | 116 | Throwable failure = null; |
| 117 | 117 | ||
| 118 | - if (x) { | 118 | + if (!registered) { |
| 119 | for (CustomContext tempContext : tempContexts) { | 119 | for (CustomContext tempContext : tempContexts) { |
| 120 | addContext(tempContext, afterBeanDiscoveryEvent); | 120 | addContext(tempContext, afterBeanDiscoveryEvent); |
| 121 | } | 121 | } |
| 122 | 122 | ||
| 123 | - x = false; | 123 | + registered = true; |
| 124 | } | 124 | } |
| 125 | 125 | ||
| 126 | for (Iterator<AnnotatedMethodProcessor> iter = processors.iterator(); iter.hasNext();) { | 126 | for (Iterator<AnnotatedMethodProcessor> iter = processors.iterator(); iter.hasNext();) { |
| @@ -132,10 +132,7 @@ public abstract class AsbratctLifecycleBootstrap<A extends Annotation> extends A | @@ -132,10 +132,7 @@ public abstract class AsbratctLifecycleBootstrap<A extends Annotation> extends A | ||
| 132 | 132 | ||
| 133 | if (Thread.currentThread().getContextClassLoader().equals(classLoader)) { | 133 | if (Thread.currentThread().getContextClassLoader().equals(classLoader)) { |
| 134 | processor.process(); | 134 | processor.process(); |
| 135 | - | ||
| 136 | - if (event.removeProcessors()) { | ||
| 137 | - iter.remove(); | ||
| 138 | - } | 135 | + iter.remove(); |
| 139 | } | 136 | } |
| 140 | 137 | ||
| 141 | } catch (Throwable cause) { | 138 | } catch (Throwable cause) { |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/BeforeApplicationFinalization.java
| @@ -36,6 +36,6 @@ | @@ -36,6 +36,6 @@ | ||
| 36 | */ | 36 | */ |
| 37 | package br.gov.frameworkdemoiselle.internal.bootstrap; | 37 | package br.gov.frameworkdemoiselle.internal.bootstrap; |
| 38 | 38 | ||
| 39 | -public interface BeforeApplicationFinalization extends ApplicationLifecycleEvent { | 39 | +public interface BeforeApplicationFinalization { |
| 40 | 40 | ||
| 41 | } | 41 | } |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/BeforeApplicationInitialization.java
| @@ -36,6 +36,6 @@ | @@ -36,6 +36,6 @@ | ||
| 36 | */ | 36 | */ |
| 37 | package br.gov.frameworkdemoiselle.internal.bootstrap; | 37 | package br.gov.frameworkdemoiselle.internal.bootstrap; |
| 38 | 38 | ||
| 39 | -public interface BeforeApplicationInitialization extends ApplicationLifecycleEvent { | 39 | +public interface BeforeApplicationInitialization { |
| 40 | 40 | ||
| 41 | } | 41 | } |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ShutdownBootstrap.java
| @@ -56,6 +56,6 @@ public class ShutdownBootstrap extends AsbratctLifecycleBootstrap<Shutdown> { | @@ -56,6 +56,6 @@ public class ShutdownBootstrap extends AsbratctLifecycleBootstrap<Shutdown> { | ||
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | public void shutdown(@Observes BeforeApplicationFinalization event) { | 58 | public void shutdown(@Observes BeforeApplicationFinalization event) { |
| 59 | - proccessEvent(event); | 59 | + proccessEvent(); |
| 60 | } | 60 | } |
| 61 | } | 61 | } |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/StartupBootstrap.java
| @@ -56,6 +56,6 @@ public class StartupBootstrap extends AsbratctLifecycleBootstrap<Startup> { | @@ -56,6 +56,6 @@ public class StartupBootstrap extends AsbratctLifecycleBootstrap<Startup> { | ||
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | public void startup(@Observes BeforeApplicationInitialization event) { | 58 | public void startup(@Observes BeforeApplicationInitialization event) { |
| 59 | - proccessEvent(event); | 59 | + proccessEvent(); |
| 60 | } | 60 | } |
| 61 | } | 61 | } |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/TrancationContextImpl.java
| @@ -1,60 +0,0 @@ | @@ -1,60 +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.implementation; | ||
| 38 | - | ||
| 39 | -import javax.inject.Named; | ||
| 40 | - | ||
| 41 | -import br.gov.frameworkdemoiselle.transaction.Transaction; | ||
| 42 | -import br.gov.frameworkdemoiselle.transaction.TransactionContext; | ||
| 43 | - | ||
| 44 | -/** | ||
| 45 | - * This is the default implementation of {@link TransactionContext} interface. | ||
| 46 | - * | ||
| 47 | - * @author SERPRO | ||
| 48 | - */ | ||
| 49 | -@Named("transactionContext") | ||
| 50 | -public class TrancationContextImpl implements TransactionContext { | ||
| 51 | - | ||
| 52 | - private static final long serialVersionUID = 1L; | ||
| 53 | - | ||
| 54 | - @Override | ||
| 55 | - public Transaction getCurrentTransaction() { | ||
| 56 | - return StrategySelector.getReference("frameworkdemoiselle.transaction.class", Transaction.class, | ||
| 57 | - DefaultTransaction.class); | ||
| 58 | - } | ||
| 59 | - | ||
| 60 | -} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/TransactionContextImpl.java
0 → 100644
| @@ -0,0 +1,60 @@ | @@ -0,0 +1,60 @@ | ||
| 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.implementation; | ||
| 38 | + | ||
| 39 | +import javax.inject.Named; | ||
| 40 | + | ||
| 41 | +import br.gov.frameworkdemoiselle.transaction.Transaction; | ||
| 42 | +import br.gov.frameworkdemoiselle.transaction.TransactionContext; | ||
| 43 | + | ||
| 44 | +/** | ||
| 45 | + * This is the default implementation of {@link TransactionContext} interface. | ||
| 46 | + * | ||
| 47 | + * @author SERPRO | ||
| 48 | + */ | ||
| 49 | +@Named("transactionContext") | ||
| 50 | +public class TransactionContextImpl implements TransactionContext { | ||
| 51 | + | ||
| 52 | + private static final long serialVersionUID = 1L; | ||
| 53 | + | ||
| 54 | + @Override | ||
| 55 | + public Transaction getCurrentTransaction() { | ||
| 56 | + return StrategySelector.getReference("frameworkdemoiselle.transaction.class", Transaction.class, | ||
| 57 | + DefaultTransaction.class); | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | +} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/processor/AbstractProcessor.java
| @@ -39,13 +39,13 @@ package br.gov.frameworkdemoiselle.internal.processor; | @@ -39,13 +39,13 @@ package br.gov.frameworkdemoiselle.internal.processor; | ||
| 39 | import java.util.Locale; | 39 | import java.util.Locale; |
| 40 | 40 | ||
| 41 | import javax.enterprise.inject.spi.AnnotatedCallable; | 41 | import javax.enterprise.inject.spi.AnnotatedCallable; |
| 42 | -import javax.enterprise.inject.spi.Bean; | ||
| 43 | import javax.enterprise.inject.spi.BeanManager; | 42 | import javax.enterprise.inject.spi.BeanManager; |
| 44 | 43 | ||
| 45 | import org.slf4j.Logger; | 44 | import org.slf4j.Logger; |
| 46 | 45 | ||
| 47 | import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; | 46 | import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; |
| 48 | import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; | 47 | import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; |
| 48 | +import br.gov.frameworkdemoiselle.util.Beans; | ||
| 49 | import br.gov.frameworkdemoiselle.util.ResourceBundle; | 49 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
| 50 | 50 | ||
| 51 | /** | 51 | /** |
| @@ -92,13 +92,7 @@ public abstract class AbstractProcessor<T> implements Processor { | @@ -92,13 +92,7 @@ public abstract class AbstractProcessor<T> implements Processor { | ||
| 92 | @SuppressWarnings("unchecked") | 92 | @SuppressWarnings("unchecked") |
| 93 | protected T getReferencedBean() { | 93 | protected T getReferencedBean() { |
| 94 | Class<T> classType = (Class<T>) getAnnotatedCallable().getJavaMember().getDeclaringClass(); | 94 | Class<T> classType = (Class<T>) getAnnotatedCallable().getJavaMember().getDeclaringClass(); |
| 95 | - return getReferencedBean(classType); | ||
| 96 | - } | ||
| 97 | - | ||
| 98 | - @SuppressWarnings("unchecked") | ||
| 99 | - protected T getReferencedBean(final Class<T> type) { | ||
| 100 | - Bean<T> bean = (Bean<T>) beanManager.getBeans(type).iterator().next(); | ||
| 101 | - return (T) beanManager.getReference(bean, type, beanManager.createCreationalContext(bean)); | 95 | + return Beans.getReference(classType); |
| 102 | } | 96 | } |
| 103 | 97 | ||
| 104 | protected ResourceBundle getBundle() { | 98 | protected ResourceBundle getBundle() { |
impl/core/src/main/java/br/gov/frameworkdemoiselle/transaction/TransactionContext.java
| @@ -39,7 +39,7 @@ package br.gov.frameworkdemoiselle.transaction; | @@ -39,7 +39,7 @@ package br.gov.frameworkdemoiselle.transaction; | ||
| 39 | import java.io.Serializable; | 39 | import java.io.Serializable; |
| 40 | 40 | ||
| 41 | /** | 41 | /** |
| 42 | - * Structure used to handle trancationa mechanisms. | 42 | + * Structure used to handle transaction mechanisms. |
| 43 | * | 43 | * |
| 44 | * @author SERPRO | 44 | * @author SERPRO |
| 45 | */ | 45 | */ |
impl/core/src/main/java/br/gov/frameworkdemoiselle/util/Beans.java
| @@ -76,33 +76,62 @@ public final class Beans { | @@ -76,33 +76,62 @@ public final class Beans { | ||
| 76 | 76 | ||
| 77 | @SuppressWarnings("unchecked") | 77 | @SuppressWarnings("unchecked") |
| 78 | public static <T> T getReference(final Class<T> beanClass, Annotation... qualifiers) { | 78 | public static <T> T getReference(final Class<T> beanClass, Annotation... qualifiers) { |
| 79 | - return (T) getReference(manager.getBeans(beanClass, qualifiers)); | 79 | + T instance; |
| 80 | + | ||
| 81 | + try { | ||
| 82 | + instance = (T) getReference(manager.getBeans(beanClass, qualifiers)); | ||
| 83 | + | ||
| 84 | + } catch (NoSuchElementException cause) { | ||
| 85 | + StringBuffer buffer = new StringBuffer(); | ||
| 86 | + buffer.append(beanClass.getCanonicalName()); | ||
| 87 | + | ||
| 88 | + for (Annotation qualifier : qualifiers) { | ||
| 89 | + buffer.append(", "); | ||
| 90 | + buffer.append(qualifier.getClass().getCanonicalName()); | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + String message = getBundle() | ||
| 94 | + .getString("bean-not-found", buffer.toString()); | ||
| 95 | + throw new DemoiselleException(message, cause); | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + return instance; | ||
| 80 | } | 99 | } |
| 81 | 100 | ||
| 82 | - @SuppressWarnings("unchecked") | ||
| 83 | public static <T> T getReference(final Class<T> beanClass) { | 101 | public static <T> T getReference(final Class<T> beanClass) { |
| 84 | - return (T) getReference(manager.getBeans(beanClass)); | 102 | + |
| 103 | + T instance; | ||
| 104 | + | ||
| 105 | + try { | ||
| 106 | + instance = (T) getReference(manager.getBeans(beanClass)); | ||
| 107 | + }catch (NoSuchElementException cause) { | ||
| 108 | + String message = getBundle() | ||
| 109 | + .getString("bean-not-found", beanClass.getCanonicalName()); | ||
| 110 | + throw new DemoiselleException(message, cause); | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + return instance; | ||
| 85 | } | 114 | } |
| 86 | 115 | ||
| 87 | @SuppressWarnings("unchecked") | 116 | @SuppressWarnings("unchecked") |
| 88 | public static <T> T getReference(String beanName) { | 117 | public static <T> T getReference(String beanName) { |
| 89 | - return (T) getReference(manager.getBeans(beanName)); | ||
| 90 | - } | ||
| 91 | - | ||
| 92 | - @SuppressWarnings("unchecked") | ||
| 93 | - private static <T> T getReference(Set<Bean<?>> beans) { | ||
| 94 | - T result = null; | ||
| 95 | - | 118 | + T instance; |
| 119 | + | ||
| 96 | try { | 120 | try { |
| 97 | - Bean<?> bean = beans.iterator().next(); | ||
| 98 | - result = (T) manager.getReference(bean, bean.getBeanClass(), manager.createCreationalContext(bean)); | ||
| 99 | - | ||
| 100 | - } catch (NoSuchElementException cause) { | ||
| 101 | - String message = getBundle().getString("bean-not-found"); | 121 | + instance = (T) getReference(manager.getBeans(beanName)); |
| 122 | + }catch (NoSuchElementException cause) { | ||
| 123 | + String message = getBundle() | ||
| 124 | + .getString("bean-not-found", beanName); | ||
| 102 | throw new DemoiselleException(message, cause); | 125 | throw new DemoiselleException(message, cause); |
| 103 | } | 126 | } |
| 127 | + | ||
| 128 | + return instance; | ||
| 129 | + } | ||
| 104 | 130 | ||
| 105 | - return result; | 131 | + @SuppressWarnings("unchecked") |
| 132 | + private static <T> T getReference(Set<Bean<?>> beans) { | ||
| 133 | + Bean<?> bean = beans.iterator().next(); | ||
| 134 | + return (T) manager.getReference(bean, bean.getBeanClass(), manager.createCreationalContext(bean)); | ||
| 106 | } | 135 | } |
| 107 | 136 | ||
| 108 | private static ResourceBundle getBundle() { | 137 | private static ResourceBundle getBundle() { |
impl/core/src/main/resources/demoiselle-core-bundle.properties
| @@ -34,7 +34,7 @@ | @@ -34,7 +34,7 @@ | ||
| 34 | # 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | 34 | # 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. |
| 35 | 35 | ||
| 36 | engine-on=Ligando os motores do Demoiselle ${project.version} | 36 | engine-on=Ligando os motores do Demoiselle ${project.version} |
| 37 | -bean-not-found=Voc\u00EA est\u00E1 tentando obter um objeto n\u00E3o reconhecido pelo CDI via Beans.getReference(...) | 37 | +bean-not-found=Voc\u00EA est\u00E1 tentando obter um objeto n\u00E3o reconhecido pelo CDI via Beans.getReference({0}) |
| 38 | more-than-one-exceptionhandler-defined-for-same-class=Foi definido mais de um m\u00E9todo na classe {0} para tratar a exce\u00E7\u00E3o {1} | 38 | more-than-one-exceptionhandler-defined-for-same-class=Foi definido mais de um m\u00E9todo na classe {0} para tratar a exce\u00E7\u00E3o {1} |
| 39 | handling-exception=Tratando a exce\u00E7\u00E3o {0} | 39 | handling-exception=Tratando a exce\u00E7\u00E3o {0} |
| 40 | proxy-detected=Detectado o proxy {0} da classe {1} | 40 | proxy-detected=Detectado o proxy {0} da classe {1} |
impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/util/ServletListener.java
| @@ -46,22 +46,12 @@ public class ServletListener implements javax.servlet.ServletContextListener { | @@ -46,22 +46,12 @@ public class ServletListener implements javax.servlet.ServletContextListener { | ||
| 46 | @Override | 46 | @Override |
| 47 | public void contextInitialized(ServletContextEvent event) { | 47 | public void contextInitialized(ServletContextEvent event) { |
| 48 | Beans.getBeanManager().fireEvent(new BeforeApplicationInitialization() { | 48 | Beans.getBeanManager().fireEvent(new BeforeApplicationInitialization() { |
| 49 | - | ||
| 50 | - @Override | ||
| 51 | - public boolean removeProcessors() { | ||
| 52 | - return true; | ||
| 53 | - } | ||
| 54 | }); | 49 | }); |
| 55 | } | 50 | } |
| 56 | 51 | ||
| 57 | @Override | 52 | @Override |
| 58 | public void contextDestroyed(ServletContextEvent event) { | 53 | public void contextDestroyed(ServletContextEvent event) { |
| 59 | Beans.getBeanManager().fireEvent(new BeforeApplicationFinalization() { | 54 | Beans.getBeanManager().fireEvent(new BeforeApplicationFinalization() { |
| 60 | - | ||
| 61 | - @Override | ||
| 62 | - public boolean removeProcessors() { | ||
| 63 | - return true; | ||
| 64 | - } | ||
| 65 | }); | 55 | }); |
| 66 | } | 56 | } |
| 67 | } | 57 | } |