From 5808540381a02319a260d80e1eff2dc0a684fe5a Mon Sep 17 00:00:00 2001 From: Cleverson Sacramento Date: Wed, 15 Aug 2012 08:31:02 -0300 Subject: [PATCH] Melhoria na implementação do StartupBootstrap e do ShutdownBootstrap --- impl/core/src/main/java/br/gov/frameworkdemoiselle/annotation/Priority.java | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ impl/core/src/main/java/br/gov/frameworkdemoiselle/annotation/Shutdown.java | 16 +++++++++++++++- impl/core/src/main/java/br/gov/frameworkdemoiselle/annotation/Startup.java | 17 ++++++++++++++++- impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ApplicationLifecycleEvent.java | 6 ++++++ impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AsbratctLifecycleBootstrap.java | 158 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/BeforeApplicationFinalization.java | 5 +++++ impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/BeforeApplicationInitialization.java | 5 +++++ impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ShutdownBootstrap.java | 124 ++++++++-------------------------------------------------------------------------------------------------------------------- impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/StartupBootstrap.java | 122 ++++++++------------------------------------------------------------------------------------------------------------------ impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/processor/AbstractProcessor.java | 20 ++++++++++---------- impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/processor/AnnotatedMethodProcessor.java | 20 +++++++++++++++----- impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/processor/ShutdownProcessor.java | 23 ++++++++++------------- impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/processor/StartupProcessor.java | 20 ++++++-------------- impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/bootstrap/ShutdownBootstrapTest.java | 400 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/bootstrap/StartupBootstrapTest.java | 524 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/util/ServletContextListener.java | 19 ------------------- impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/util/ServletListener.java | 20 ++++++++++++++++---- 17 files changed, 806 insertions(+), 759 deletions(-) create mode 100644 impl/core/src/main/java/br/gov/frameworkdemoiselle/annotation/Priority.java create mode 100644 impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ApplicationLifecycleEvent.java create mode 100644 impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AsbratctLifecycleBootstrap.java create mode 100644 impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/BeforeApplicationFinalization.java create mode 100644 impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/BeforeApplicationInitialization.java delete mode 100644 impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/util/ServletContextListener.java diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/annotation/Priority.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/annotation/Priority.java new file mode 100644 index 0000000..3fdd48d --- /dev/null +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/annotation/Priority.java @@ -0,0 +1,66 @@ +/* + * 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.annotation; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +/** + * @author SERPRO + */ +@Target(METHOD) +@Retention(RUNTIME) +public @interface Priority { + + /** + * Most important priority value. + */ + public static int MAX_PRIORITY = Integer.MIN_VALUE; + + /** + * Less important priority value. + */ + public static int MIN_PRIORITY = Integer.MAX_VALUE; + + /** + * An integer value defines the priority order. + */ + int value(); +} diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/annotation/Shutdown.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/annotation/Shutdown.java index 4312bd5..0a1a7d2 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/annotation/Shutdown.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/annotation/Shutdown.java @@ -52,7 +52,8 @@ import java.lang.annotation.Target; *
  * public class Finalizer {
  * 
- * 	@Shutdown(priority = 5)
+ * 	@Shutdown
+ * 	@Priority(5)
  *    public void finalize() {
  *       ...
  *    }
@@ -60,6 +61,7 @@ import java.lang.annotation.Target;
  * 
  * 
  * 
+ * 
  * 
* * @@ -75,17 +77,29 @@ public @interface Shutdown { /** * Most important priority value. + * + * @deprecated + * @see Priority */ + @Deprecated public static int MAX_PRIORITY = Integer.MIN_VALUE; /** * Less important priority value. + * + * @deprecated + * @see Priority */ + @Deprecated public static int MIN_PRIORITY = Integer.MAX_VALUE; /** * An integer value defines method execution order (i.e., priority). + * + * @deprecated + * @see Priority */ + @Deprecated int priority() default MIN_PRIORITY; } diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/annotation/Startup.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/annotation/Startup.java index 5dc87ed..e24625f 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/annotation/Startup.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/annotation/Startup.java @@ -52,13 +52,16 @@ import java.lang.annotation.Target; *
  * public class Initializer {
  * 
- * 	@Startup(priority = 1)
+ * 	@Startup
+ * 	@Priority(1)
  *    public void initialize() {
  *       ...
  *    }
  * }
  * 
  * 
+ * 
+ * 
  * 
* * @@ -74,17 +77,29 @@ public @interface Startup { /** * Most important priority value. + * + * @deprecated + * @see Priority */ + @Deprecated public static int MAX_PRIORITY = Integer.MIN_VALUE; /** * Less important priority value. + * + * @deprecated + * @see Priority */ + @Deprecated public static int MIN_PRIORITY = Integer.MAX_VALUE; /** * An integer value defines method execution order (i.e., priority). + * + * @deprecated + * @see Priority */ + @Deprecated int priority() default MIN_PRIORITY; } diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ApplicationLifecycleEvent.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ApplicationLifecycleEvent.java new file mode 100644 index 0000000..537249c --- /dev/null +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ApplicationLifecycleEvent.java @@ -0,0 +1,6 @@ +package br.gov.frameworkdemoiselle.internal.bootstrap; + +public interface ApplicationLifecycleEvent { + + boolean removeProcessors(); +} diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AsbratctLifecycleBootstrap.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AsbratctLifecycleBootstrap.java new file mode 100644 index 0000000..5865c9a --- /dev/null +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AsbratctLifecycleBootstrap.java @@ -0,0 +1,158 @@ +/* + * 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.lang.annotation.Annotation; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +import javax.enterprise.context.ConversationScoped; +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.AnnotatedMethod; +import javax.enterprise.inject.spi.AnnotatedType; +import javax.enterprise.inject.spi.BeanManager; +import javax.enterprise.inject.spi.ProcessAnnotatedType; + +import br.gov.frameworkdemoiselle.DemoiselleException; +import br.gov.frameworkdemoiselle.annotation.ViewScoped; +import br.gov.frameworkdemoiselle.internal.configuration.ConfigurationLoader; +import br.gov.frameworkdemoiselle.internal.context.CustomContext; +import br.gov.frameworkdemoiselle.internal.context.ThreadLocalContext; +import br.gov.frameworkdemoiselle.internal.processor.AnnotatedMethodProcessor; +import br.gov.frameworkdemoiselle.util.Reflections; + +public abstract class AsbratctLifecycleBootstrap extends AbstractBootstrap { + + private Class annotationClass; + + private final List> processors = Collections + .synchronizedList(new ArrayList>()); + + private final List tempContexts = new ArrayList(); + + private AfterBeanDiscovery afterBeanDiscoveryEvent; + + protected abstract AnnotatedMethodProcessor newProcessorInstance(AnnotatedMethod annotatedMethod, + BeanManager beanManager); + + protected Class getAnnotationClass() { + if (this.annotationClass == null) { + this.annotationClass = Reflections.getGenericTypeArgument(this.getClass(), 0); + } + + return this.annotationClass; + } + + public void processAnnotatedType(@Observes final ProcessAnnotatedType event, final BeanManager beanManager) { + final AnnotatedType annotatedType = event.getAnnotatedType(); + + for (AnnotatedMethod am : annotatedType.getMethods()) { + if (am.isAnnotationPresent(getAnnotationClass())) { + @SuppressWarnings("unchecked") + AnnotatedMethod annotatedMethod = (AnnotatedMethod) am; + processors.add(newProcessorInstance(annotatedMethod, beanManager)); + } + } + } + + public void loadTempContexts(@Observes final AfterBeanDiscovery event) { + // Não registrar o contexto de aplicação pq ele já é registrado pela implementação do CDI + tempContexts.add(new ThreadLocalContext(ViewScoped.class)); + tempContexts.add(new ThreadLocalContext(SessionScoped.class)); + tempContexts.add(new ThreadLocalContext(ConversationScoped.class)); + tempContexts.add(new ThreadLocalContext(RequestScoped.class)); + + afterBeanDiscoveryEvent = event; + } + + private static boolean x = true; + + protected synchronized void proccessEvent(final ApplicationLifecycleEvent event) { + getLogger().debug( + getBundle("demoiselle-core-bundle").getString("executing-all", annotationClass.getSimpleName())); + + Collections.sort(processors); + Throwable failure = null; + + if (x) { + for (CustomContext tempContext : tempContexts) { + addContext(tempContext, afterBeanDiscoveryEvent); + } + + x = false; + } + + for (Iterator> iter = processors.iterator(); iter.hasNext();) { + AnnotatedMethodProcessor processor = iter.next(); + + try { + ClassLoader classLoader = ConfigurationLoader.getClassLoaderForClass(processor.getAnnotatedMethod() + .getDeclaringType().getJavaClass().getCanonicalName()); + + if (Thread.currentThread().getContextClassLoader().equals(classLoader)) { + processor.process(); + + if (event.removeProcessors()) { + iter.remove(); + } + } + + } catch (Throwable cause) { + failure = cause; + } + } + + if (processors.isEmpty()) { + unloadTempContexts(); + } + + if (failure != null) { + throw new DemoiselleException(failure); + } + } + + private void unloadTempContexts() { + for (CustomContext tempContext : tempContexts) { + disableContext(tempContext); + } + } +} diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/BeforeApplicationFinalization.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/BeforeApplicationFinalization.java new file mode 100644 index 0000000..e8e6f46 --- /dev/null +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/BeforeApplicationFinalization.java @@ -0,0 +1,5 @@ +package br.gov.frameworkdemoiselle.internal.bootstrap; + +public interface BeforeApplicationFinalization extends ApplicationLifecycleEvent { + +} diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/BeforeApplicationInitialization.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/BeforeApplicationInitialization.java new file mode 100644 index 0000000..90ce216 --- /dev/null +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/BeforeApplicationInitialization.java @@ -0,0 +1,5 @@ +package br.gov.frameworkdemoiselle.internal.bootstrap; + +public interface BeforeApplicationInitialization extends ApplicationLifecycleEvent { + +} diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ShutdownBootstrap.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ShutdownBootstrap.java index a2c5cdd..de18562 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ShutdownBootstrap.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ShutdownBootstrap.java @@ -36,134 +36,26 @@ */ package br.gov.frameworkdemoiselle.internal.bootstrap; -import java.lang.annotation.Annotation; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; - -import javax.enterprise.context.ConversationScoped; -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.AnnotatedMethod; -import javax.enterprise.inject.spi.AnnotatedType; import javax.enterprise.inject.spi.BeanManager; -import javax.enterprise.inject.spi.ProcessAnnotatedType; -import br.gov.frameworkdemoiselle.DemoiselleException; import br.gov.frameworkdemoiselle.annotation.Shutdown; -import br.gov.frameworkdemoiselle.annotation.ViewScoped; -import br.gov.frameworkdemoiselle.internal.configuration.ConfigurationLoader; -import br.gov.frameworkdemoiselle.internal.context.CustomContext; -import br.gov.frameworkdemoiselle.internal.context.ThreadLocalContext; +import br.gov.frameworkdemoiselle.internal.processor.AnnotatedMethodProcessor; import br.gov.frameworkdemoiselle.internal.processor.ShutdownProcessor; /** * This class run at application shutdown */ -public class ShutdownBootstrap extends AbstractBootstrap { - - private static final Class annotationClass = Shutdown.class; - - private static final List tempContexts = new ArrayList(); - - private static AfterBeanDiscovery abdEvent; - - @SuppressWarnings("rawtypes") - private static final List processors = Collections - .synchronizedList(new ArrayList()); - - /** - * Observes all methods annotated with @Shutdown and create an instance of ShutdownProcessor for them - * - * @param - * @param event - * @param beanManager - */ - public void processAnnotatedType(@Observes final ProcessAnnotatedType event, final BeanManager beanManager) { - final AnnotatedType annotatedType = event.getAnnotatedType(); - for (AnnotatedMethod am : annotatedType.getMethods()) { - if (am.isAnnotationPresent(annotationClass)) { - @SuppressWarnings("unchecked") - AnnotatedMethod annotatedMethod = (AnnotatedMethod) am; - processors.add(new ShutdownProcessor(annotatedMethod, beanManager)); - } - } - } - - public static void loadTempContexts(@Observes final AfterBeanDiscovery event) { - // Não registrar o contexto de aplicação pq ele já é registrado pela - // implementação do CDI - tempContexts.add(new ThreadLocalContext(ViewScoped.class)); - tempContexts.add(new ThreadLocalContext(SessionScoped.class, false)); - tempContexts.add(new ThreadLocalContext(ConversationScoped.class)); - tempContexts.add(new ThreadLocalContext(RequestScoped.class)); - abdEvent = event; - } - - /** - * Before Shutdown it execute the methods annotateds with @Shutdown considering the priority order; - */ - public synchronized static void shutdown() { - shutdown(true); - } - - private static boolean x = true; - - /** - * Before Shutdown it execute the methods annotateds with @Shutdown considering the priority order; - */ - @SuppressWarnings({ "unchecked", "rawtypes" }) - public synchronized static void shutdown(boolean remove) { - getLogger().debug( - getBundle("demoiselle-core-bundle").getString("executing-all", annotationClass.getSimpleName())); - - Collections.sort(processors); - Throwable failure = null; - - if (x) { - for (CustomContext tempContext : tempContexts) { - addContext(tempContext, abdEvent); - } - - x = false; - } - - for (Iterator iter = processors.iterator(); iter.hasNext();) { - ShutdownProcessor processor = iter.next(); - - try { - ClassLoader classLoader = ConfigurationLoader.getClassLoaderForClass(processor.getAnnotatedMethod() - .getDeclaringType().getJavaClass().getCanonicalName()); - - if (Thread.currentThread().getContextClassLoader().equals(classLoader)) { - - processor.process(); - - if (remove) { - iter.remove(); - } - } - - } catch (Throwable cause) { - failure = cause; - } - } - - if (processors.isEmpty()) { - unloadTempContexts(); - } +public class ShutdownBootstrap extends AsbratctLifecycleBootstrap { - if (failure != null) { - throw new DemoiselleException(failure); - } + @Override + protected AnnotatedMethodProcessor newProcessorInstance(AnnotatedMethod annotatedMethod, + BeanManager beanManager) { + return new ShutdownProcessor(annotatedMethod, beanManager); } - private static void unloadTempContexts() { - for (CustomContext tempContext : tempContexts) { - disableContext(tempContext); - } + public void shutdown(@Observes BeforeApplicationFinalization event) { + proccessEvent(event); } } diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/StartupBootstrap.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/StartupBootstrap.java index b1f63a4..f09eb97 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/StartupBootstrap.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/StartupBootstrap.java @@ -36,132 +36,26 @@ */ package br.gov.frameworkdemoiselle.internal.bootstrap; -import java.lang.annotation.Annotation; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; - -import javax.enterprise.context.ConversationScoped; -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.AnnotatedMethod; -import javax.enterprise.inject.spi.AnnotatedType; import javax.enterprise.inject.spi.BeanManager; -import javax.enterprise.inject.spi.ProcessAnnotatedType; -import br.gov.frameworkdemoiselle.DemoiselleException; import br.gov.frameworkdemoiselle.annotation.Startup; -import br.gov.frameworkdemoiselle.annotation.ViewScoped; -import br.gov.frameworkdemoiselle.internal.configuration.ConfigurationLoader; -import br.gov.frameworkdemoiselle.internal.context.CustomContext; -import br.gov.frameworkdemoiselle.internal.context.ThreadLocalContext; +import br.gov.frameworkdemoiselle.internal.processor.AnnotatedMethodProcessor; import br.gov.frameworkdemoiselle.internal.processor.StartupProcessor; /** * This class is the bootstrap to execute the processes at load time. */ -public class StartupBootstrap extends AbstractBootstrap { - - private static final Class annotationClass = Startup.class; - - private static final List tempContexts = new ArrayList(); - - @SuppressWarnings("rawtypes") - private static final List processors = Collections - .synchronizedList(new ArrayList()); - - private static AfterBeanDiscovery abdEvent; - - /** - * Observes all methods annotated with @Startup and create an instance of StartupAction for them - * - * @param - * @param event - * @param beanManager - */ - public void processAnnotatedType(@Observes final ProcessAnnotatedType event, final BeanManager beanManager) { - final AnnotatedType annotatedType = event.getAnnotatedType(); - for (AnnotatedMethod am : annotatedType.getMethods()) { - if (am.isAnnotationPresent(annotationClass)) { - @SuppressWarnings("unchecked") - AnnotatedMethod annotatedMethod = (AnnotatedMethod) am; - processors.add(new StartupProcessor(annotatedMethod, beanManager)); - } - } - } - - public void loadTempContexts(@Observes final AfterBeanDiscovery event) { - // Não registrar o contexto de aplicação pq ele já é registrado pela implementação do CDI - tempContexts.add(new ThreadLocalContext(ViewScoped.class)); - tempContexts.add(new ThreadLocalContext(SessionScoped.class)); - tempContexts.add(new ThreadLocalContext(ConversationScoped.class)); - tempContexts.add(new ThreadLocalContext(RequestScoped.class)); - abdEvent = event; - } - - /** - * After the deployment validation it execute the methods annotateds with @Startup considering the priority order; - */ - public synchronized static void startup() { - startup(true); - } - - private static boolean x = true; - - /** - * After the deployment validation it execute the methods annotateds with @Startup considering the priority order; - */ - @SuppressWarnings({ "unchecked", "rawtypes" }) - public synchronized static void startup(boolean remove) { - getLogger().debug( - getBundle("demoiselle-core-bundle").getString("executing-all", annotationClass.getSimpleName())); - - Collections.sort(processors); - Throwable failure = null; - - if (x) { - for (CustomContext tempContext : tempContexts) { - addContext(tempContext, abdEvent); - } - - x = false; - } - - for (Iterator iter = processors.iterator(); iter.hasNext();) { - StartupProcessor processor = iter.next(); - - try { - ClassLoader classLoader = ConfigurationLoader.getClassLoaderForClass(processor.getAnnotatedMethod() - .getDeclaringType().getJavaClass().getCanonicalName()); - - if (Thread.currentThread().getContextClassLoader().equals(classLoader)) { - processor.process(); - - if (remove) { - iter.remove(); - } - } - - } catch (Throwable cause) { - failure = cause; - } - } - - if (processors.isEmpty()) { - unloadTempContexts(); - } +public class StartupBootstrap extends AsbratctLifecycleBootstrap { - if (failure != null) { - throw new DemoiselleException(failure); - } + @Override + protected AnnotatedMethodProcessor newProcessorInstance(AnnotatedMethod annotatedMethod, + BeanManager beanManager) { + return new StartupProcessor(annotatedMethod, beanManager); } - private static void unloadTempContexts() { - for (CustomContext tempContext : tempContexts) { - disableContext(tempContext); - } + public void startup(@Observes BeforeApplicationInitialization event) { + proccessEvent(event); } } 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 04c4990..a593ec4 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 @@ -51,14 +51,14 @@ import br.gov.frameworkdemoiselle.util.ResourceBundle; /** * It abstract the integration between Processor and the context; * - * @param + * @param * the declaring class */ -public abstract class AbstractProcessor implements Processor { +public abstract class AbstractProcessor implements Processor { private BeanManager beanManager; - private AnnotatedCallable annotatedCallable; + private AnnotatedCallable annotatedCallable; private ResourceBundle bundle; @@ -68,12 +68,12 @@ public abstract class AbstractProcessor implements Processor { this.beanManager = beanManager; } - public AbstractProcessor(final AnnotatedCallable annotatedCallable, final BeanManager beanManager) { + public AbstractProcessor(final AnnotatedCallable annotatedCallable, final BeanManager beanManager) { this.annotatedCallable = annotatedCallable; this.beanManager = beanManager; } - protected AnnotatedCallable getAnnotatedCallable() { + protected AnnotatedCallable getAnnotatedCallable() { return this.annotatedCallable; } @@ -90,15 +90,15 @@ public abstract class AbstractProcessor implements Processor { * @return */ @SuppressWarnings("unchecked") - protected DC getReferencedBean() { - Class classType = (Class) getAnnotatedCallable().getJavaMember().getDeclaringClass(); + protected T getReferencedBean() { + Class classType = (Class) getAnnotatedCallable().getJavaMember().getDeclaringClass(); return getReferencedBean(classType); } @SuppressWarnings("unchecked") - protected DC getReferencedBean(final Class type) { - Bean bean = (Bean) beanManager.getBeans(type).iterator().next(); - return (DC) beanManager.getReference(bean, type, beanManager.createCreationalContext(bean)); + protected T getReferencedBean(final Class type) { + Bean bean = (Bean) beanManager.getBeans(type).iterator().next(); + return (T) beanManager.getReference(bean, type, beanManager.createCreationalContext(bean)); } protected ResourceBundle getBundle() { diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/processor/AnnotatedMethodProcessor.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/processor/AnnotatedMethodProcessor.java index e343099..2117359 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/processor/AnnotatedMethodProcessor.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/processor/AnnotatedMethodProcessor.java @@ -47,17 +47,27 @@ import br.gov.frameworkdemoiselle.message.SeverityType; /** * Represents an annotated method to be processed; * - * @param + * @param * declaring class owner of the method */ -public class AnnotatedMethodProcessor extends AbstractProcessor { +public abstract class AnnotatedMethodProcessor extends AbstractProcessor implements + Comparable> { - public AnnotatedMethodProcessor(final AnnotatedMethod annotatedMethod, final BeanManager beanManager) { + public AnnotatedMethodProcessor(final AnnotatedMethod annotatedMethod, final BeanManager beanManager) { super(annotatedMethod, beanManager); } - public AnnotatedMethod getAnnotatedMethod() { - return (AnnotatedMethod) getAnnotatedCallable(); + public AnnotatedMethod getAnnotatedMethod() { + return (AnnotatedMethod) getAnnotatedCallable(); + } + + abstract protected Integer getPriority(AnnotatedMethod annotatedMethod); + + public int compareTo(final AnnotatedMethodProcessor other) { + Integer orderThis = getPriority(getAnnotatedMethod()); + Integer orderOther = getPriority(other.getAnnotatedMethod()); + + return orderThis.compareTo(orderOther); } public boolean process(Object... args) throws Throwable { diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/processor/ShutdownProcessor.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/processor/ShutdownProcessor.java index b249e90..6a1500a 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/processor/ShutdownProcessor.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/processor/ShutdownProcessor.java @@ -41,23 +41,20 @@ import javax.enterprise.inject.spi.BeanManager; import br.gov.frameworkdemoiselle.annotation.Shutdown; -public class ShutdownProcessor extends AnnotatedMethodProcessor implements Comparable> { +/** + * Processor for a {@code Shutdown} annotated method, making it comparable. + * + * @param + */ +public class ShutdownProcessor extends AnnotatedMethodProcessor { public ShutdownProcessor(AnnotatedMethod annotatedMethod, BeanManager beanManager) { super(annotatedMethod, beanManager); } - @Override - public int compareTo(final ShutdownProcessor other) { - int result = 0; - Shutdown annotationThis = getAnnotatedMethod().getAnnotation(Shutdown.class); - Shutdown annotationOther = other.getAnnotatedMethod().getAnnotation(Shutdown.class); - if (annotationThis != null && annotationThis != null) { - Integer orderThis = annotationThis.priority(); - Integer orderOther = annotationOther.priority(); - result = orderThis.compareTo(orderOther); - } - return result; + @SuppressWarnings("deprecation") + protected Integer getPriority(AnnotatedMethod annotatedMethod) { + Shutdown annotation = annotatedMethod.getAnnotation(Shutdown.class); + return annotation.priority(); } - } diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/processor/StartupProcessor.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/processor/StartupProcessor.java index 01a5eee..823bbc7 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/processor/StartupProcessor.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/processor/StartupProcessor.java @@ -43,26 +43,18 @@ import br.gov.frameworkdemoiselle.annotation.Startup; /** * Processor for a {@code @Startup} annotated method, making it comparable. - * + * * @param */ -public class StartupProcessor extends AnnotatedMethodProcessor implements Comparable> { +public class StartupProcessor extends AnnotatedMethodProcessor { public StartupProcessor(final AnnotatedMethod annotatedMethod, final BeanManager beanManager) { super(annotatedMethod, beanManager); } - @Override - public int compareTo(final StartupProcessor other) { - int result = 0; - Startup annotationThis = getAnnotatedMethod().getAnnotation(Startup.class); - Startup annotationOther = other.getAnnotatedMethod().getAnnotation(Startup.class); - if (annotationThis != null && annotationOther != null) { - Integer orderThis = annotationThis.priority(); - Integer orderOther = annotationOther.priority(); - result = orderThis.compareTo(orderOther); - } - return result; + @SuppressWarnings("deprecation") + protected Integer getPriority(AnnotatedMethod annotatedMethod) { + Startup annotation = annotatedMethod.getAnnotation(Startup.class); + return annotation.priority(); } - } diff --git a/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/bootstrap/ShutdownBootstrapTest.java b/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/bootstrap/ShutdownBootstrapTest.java index 77456c0..1dd88b0 100644 --- a/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/bootstrap/ShutdownBootstrapTest.java +++ b/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/bootstrap/ShutdownBootstrapTest.java @@ -1,200 +1,200 @@ -/* - * 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 static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Locale; -import java.util.Set; - -import javax.enterprise.inject.spi.AfterBeanDiscovery; -import javax.enterprise.inject.spi.AnnotatedMethod; -import javax.enterprise.inject.spi.AnnotatedType; -import javax.enterprise.inject.spi.BeanManager; -import javax.enterprise.inject.spi.ProcessAnnotatedType; - -import org.easymock.EasyMock; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.api.easymock.PowerMock; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.reflect.Whitebox; -import org.slf4j.Logger; - -import br.gov.frameworkdemoiselle.annotation.Shutdown; -import br.gov.frameworkdemoiselle.internal.context.Contexts; -import br.gov.frameworkdemoiselle.internal.context.ThreadLocalContext; -import br.gov.frameworkdemoiselle.internal.processor.ShutdownProcessor; -import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; -import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; -import br.gov.frameworkdemoiselle.util.ResourceBundle; - -@Ignore -@RunWith(PowerMockRunner.class) -@PrepareForTest({ Contexts.class, LoggerProducer.class, ResourceBundle.class, ResourceBundleProducer.class }) -@SuppressWarnings("rawtypes") -public class ShutdownBootstrapTest { - - private ProcessAnnotatedType event; - - private BeanManager beanManager; - - private AnnotatedType annotatedType; - - @Before - public void before() { - event = EasyMock.createMock(ProcessAnnotatedType.class); - annotatedType = EasyMock.createMock(AnnotatedType.class); - beanManager = null; - } - - @SuppressWarnings("unchecked") - private List getProcessors(ShutdownBootstrap bootstrap) throws IllegalArgumentException, - IllegalAccessException { - Set fields = Whitebox.getAllStaticFields(ShutdownBootstrap.class); - List list = new ArrayList(); - for (Field field : fields) { - if (field.getName().equals("processors")) { - list = (List) field.get(bootstrap); - } - } - return list; - } - - @SuppressWarnings({ "unchecked" }) - @Test - public void processAnnotatedType() throws IllegalArgumentException, IllegalAccessException { - ShutdownBootstrap bootstrap = new ShutdownBootstrap(); - List list = getProcessors(bootstrap); - - assertTrue(list.isEmpty()); - - AnnotatedMethod am1 = PowerMock.createMock(AnnotatedMethod.class); - AnnotatedMethod am2 = PowerMock.createMock(AnnotatedMethod.class); - AnnotatedMethod am3 = PowerMock.createMock(AnnotatedMethod.class); - - Set set = new HashSet(); - set.add(am1); - set.add(am2); - set.add(am3); - - expect(am1.isAnnotationPresent(Shutdown.class)).andReturn(true); - expect(am2.isAnnotationPresent(Shutdown.class)).andReturn(true); - expect(am3.isAnnotationPresent(Shutdown.class)).andReturn(false); - expect(event.getAnnotatedType()).andReturn(annotatedType); - expect(annotatedType.getMethods()).andReturn(set); - - replay(event, annotatedType, am1, am2, am3); - bootstrap.processAnnotatedType(event, beanManager); - verify(event, annotatedType); - - list = getProcessors(bootstrap); - assertNotNull(list); - assertFalse(list.isEmpty()); - assertTrue(list.size() == 2); - } - - @SuppressWarnings({ "unchecked", "static-access" }) - @Test - public void testShuttingDown() throws Throwable { - ShutdownBootstrap bootstrap = new ShutdownBootstrap(); - - PowerMock.mockStatic(Contexts.class); - PowerMock.mockStatic(LoggerProducer.class); - - Logger logger = PowerMock.createMock(Logger.class); - ResourceBundleProducer bundleFactory = PowerMock.createMock(ResourceBundleProducer.class); - ResourceBundle bundle = PowerMock.createMock(ResourceBundle.class); - - expect(LoggerProducer.create(EasyMock.anyObject(Class.class))).andReturn(logger).anyTimes(); - expect(bundleFactory.create(EasyMock.anyObject(String.class), EasyMock.anyObject(Locale.class))).andReturn( - bundle).anyTimes(); - expect(bundle.getString(EasyMock.anyObject(String.class), EasyMock.anyObject(String.class))).andReturn("") - .anyTimes(); - - logger.debug(EasyMock.anyObject(String.class)); - logger.trace(EasyMock.anyObject(String.class)); - EasyMock.expectLastCall().anyTimes(); - - Whitebox.setInternalState(AbstractBootstrap.class, ResourceBundleProducer.class, bundleFactory); - - List list = getProcessors(bootstrap); - list.clear(); - - MyShuttingDownProcessor processor = PowerMock.createMock(MyShuttingDownProcessor.class); - list.add(processor); - expect(processor.process()).andReturn(true).times(1); - - Contexts.add(EasyMock.anyObject(ThreadLocalContext.class), EasyMock.anyObject(AfterBeanDiscovery.class)); - EasyMock.expectLastCall().anyTimes(); - - Contexts.remove(EasyMock.anyObject(ThreadLocalContext.class)); - EasyMock.expectLastCall().anyTimes(); - - PowerMock.replayAll(); - ShutdownBootstrap.shutdown(); - - assertTrue(list.isEmpty()); - PowerMock.verifyAll(); - } -} - -@SuppressWarnings("rawtypes") -class MyShuttingDownProcessor extends ShutdownProcessor { - - @SuppressWarnings("unchecked") - public MyShuttingDownProcessor(AnnotatedMethod annotatedMethod, BeanManager beanManager) { - super(annotatedMethod, beanManager); - } - - @Override - public int compareTo(final ShutdownProcessor other) { - return 1; - } -} +///* +// * 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 static org.easymock.EasyMock.expect; +//import static org.easymock.EasyMock.replay; +//import static org.easymock.EasyMock.verify; +//import static org.junit.Assert.assertFalse; +//import static org.junit.Assert.assertNotNull; +//import static org.junit.Assert.assertTrue; +// +//import java.lang.reflect.Field; +//import java.util.ArrayList; +//import java.util.HashSet; +//import java.util.List; +//import java.util.Locale; +//import java.util.Set; +// +//import javax.enterprise.inject.spi.AfterBeanDiscovery; +//import javax.enterprise.inject.spi.AnnotatedMethod; +//import javax.enterprise.inject.spi.AnnotatedType; +//import javax.enterprise.inject.spi.BeanManager; +//import javax.enterprise.inject.spi.ProcessAnnotatedType; +// +//import org.easymock.EasyMock; +//import org.junit.Before; +//import org.junit.Ignore; +//import org.junit.Test; +//import org.junit.runner.RunWith; +//import org.powermock.api.easymock.PowerMock; +//import org.powermock.core.classloader.annotations.PrepareForTest; +//import org.powermock.modules.junit4.PowerMockRunner; +//import org.powermock.reflect.Whitebox; +//import org.slf4j.Logger; +// +//import br.gov.frameworkdemoiselle.annotation.Shutdown; +//import br.gov.frameworkdemoiselle.internal.context.Contexts; +//import br.gov.frameworkdemoiselle.internal.context.ThreadLocalContext; +//import br.gov.frameworkdemoiselle.internal.processor.ShutdownProcessor; +//import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; +//import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; +//import br.gov.frameworkdemoiselle.util.ResourceBundle; +// +//@Ignore +//@RunWith(PowerMockRunner.class) +//@PrepareForTest({ Contexts.class, LoggerProducer.class, ResourceBundle.class, ResourceBundleProducer.class }) +//@SuppressWarnings("rawtypes") +//public class ShutdownBootstrapTest { +// +// private ProcessAnnotatedType event; +// +// private BeanManager beanManager; +// +// private AnnotatedType annotatedType; +// +// @Before +// public void before() { +// event = EasyMock.createMock(ProcessAnnotatedType.class); +// annotatedType = EasyMock.createMock(AnnotatedType.class); +// beanManager = null; +// } +// +// @SuppressWarnings("unchecked") +// private List getProcessors(ShutdownBootstrap bootstrap) throws IllegalArgumentException, +// IllegalAccessException { +// Set fields = Whitebox.getAllStaticFields(ShutdownBootstrap.class); +// List list = new ArrayList(); +// for (Field field : fields) { +// if (field.getName().equals("processors")) { +// list = (List) field.get(bootstrap); +// } +// } +// return list; +// } +// +// @SuppressWarnings({ "unchecked" }) +// @Test +// public void processAnnotatedType() throws IllegalArgumentException, IllegalAccessException { +// ShutdownBootstrap bootstrap = new ShutdownBootstrap(); +// List list = getProcessors(bootstrap); +// +// assertTrue(list.isEmpty()); +// +// AnnotatedMethod am1 = PowerMock.createMock(AnnotatedMethod.class); +// AnnotatedMethod am2 = PowerMock.createMock(AnnotatedMethod.class); +// AnnotatedMethod am3 = PowerMock.createMock(AnnotatedMethod.class); +// +// Set set = new HashSet(); +// set.add(am1); +// set.add(am2); +// set.add(am3); +// +// expect(am1.isAnnotationPresent(Shutdown.class)).andReturn(true); +// expect(am2.isAnnotationPresent(Shutdown.class)).andReturn(true); +// expect(am3.isAnnotationPresent(Shutdown.class)).andReturn(false); +// expect(event.getAnnotatedType()).andReturn(annotatedType); +// expect(annotatedType.getMethods()).andReturn(set); +// +// replay(event, annotatedType, am1, am2, am3); +// bootstrap.processAnnotatedType(event, beanManager); +// verify(event, annotatedType); +// +// list = getProcessors(bootstrap); +// assertNotNull(list); +// assertFalse(list.isEmpty()); +// assertTrue(list.size() == 2); +// } +// +// @SuppressWarnings({ "unchecked", "static-access" }) +// @Test +// public void testShuttingDown() throws Throwable { +// ShutdownBootstrap bootstrap = new ShutdownBootstrap(); +// +// PowerMock.mockStatic(Contexts.class); +// PowerMock.mockStatic(LoggerProducer.class); +// +// Logger logger = PowerMock.createMock(Logger.class); +// ResourceBundleProducer bundleFactory = PowerMock.createMock(ResourceBundleProducer.class); +// ResourceBundle bundle = PowerMock.createMock(ResourceBundle.class); +// +// expect(LoggerProducer.create(EasyMock.anyObject(Class.class))).andReturn(logger).anyTimes(); +// expect(bundleFactory.create(EasyMock.anyObject(String.class), EasyMock.anyObject(Locale.class))).andReturn( +// bundle).anyTimes(); +// expect(bundle.getString(EasyMock.anyObject(String.class), EasyMock.anyObject(String.class))).andReturn("") +// .anyTimes(); +// +// logger.debug(EasyMock.anyObject(String.class)); +// logger.trace(EasyMock.anyObject(String.class)); +// EasyMock.expectLastCall().anyTimes(); +// +// Whitebox.setInternalState(AbstractBootstrap.class, ResourceBundleProducer.class, bundleFactory); +// +// List list = getProcessors(bootstrap); +// list.clear(); +// +// MyShuttingDownProcessor processor = PowerMock.createMock(MyShuttingDownProcessor.class); +// list.add(processor); +// expect(processor.process()).andReturn(true).times(1); +// +// Contexts.add(EasyMock.anyObject(ThreadLocalContext.class), EasyMock.anyObject(AfterBeanDiscovery.class)); +// EasyMock.expectLastCall().anyTimes(); +// +// Contexts.remove(EasyMock.anyObject(ThreadLocalContext.class)); +// EasyMock.expectLastCall().anyTimes(); +// +// PowerMock.replayAll(); +// ShutdownBootstrap.shutdown(); +// +// assertTrue(list.isEmpty()); +// PowerMock.verifyAll(); +// } +//} +// +//@SuppressWarnings("rawtypes") +//class MyShuttingDownProcessor extends ShutdownProcessor { +// +// @SuppressWarnings("unchecked") +// public MyShuttingDownProcessor(AnnotatedMethod annotatedMethod, BeanManager beanManager) { +// super(annotatedMethod, beanManager); +// } +// +// @Override +// public int compareTo(final ShutdownProcessor other) { +// return 1; +// } +//} diff --git a/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/bootstrap/StartupBootstrapTest.java b/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/bootstrap/StartupBootstrapTest.java index 97ec58a..ed71a4c 100644 --- a/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/bootstrap/StartupBootstrapTest.java +++ b/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/bootstrap/StartupBootstrapTest.java @@ -1,262 +1,262 @@ -/* - * 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 static junit.framework.Assert.assertEquals; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.lang.reflect.Field; -import java.util.HashSet; -import java.util.List; -import java.util.Locale; -import java.util.Set; - -import javax.enterprise.context.ConversationScoped; -import javax.enterprise.context.RequestScoped; -import javax.enterprise.context.SessionScoped; -import javax.enterprise.inject.spi.AfterBeanDiscovery; -import javax.enterprise.inject.spi.AnnotatedMethod; -import javax.enterprise.inject.spi.AnnotatedType; -import javax.enterprise.inject.spi.BeanManager; -import javax.enterprise.inject.spi.ProcessAnnotatedType; - -import junit.framework.Assert; - -import org.easymock.EasyMock; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.api.easymock.PowerMock; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.reflect.Whitebox; -import org.slf4j.Logger; - -import br.gov.frameworkdemoiselle.annotation.Startup; -import br.gov.frameworkdemoiselle.annotation.ViewScoped; -import br.gov.frameworkdemoiselle.internal.context.Contexts; -import br.gov.frameworkdemoiselle.internal.context.ThreadLocalContext; -import br.gov.frameworkdemoiselle.internal.processor.StartupProcessor; -import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; -import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; -import br.gov.frameworkdemoiselle.util.ResourceBundle; - -@Ignore -@RunWith(PowerMockRunner.class) -@PrepareForTest({ Contexts.class, LoggerProducer.class, ResourceBundle.class, ResourceBundleProducer.class }) -@SuppressWarnings({ "rawtypes", "unchecked" }) -public class StartupBootstrapTest { - - private ProcessAnnotatedType event; - - private BeanManager beanManager; - - private AnnotatedType annotatedType; - - @Before - public void before() { - event = EasyMock.createMock(ProcessAnnotatedType.class); - annotatedType = EasyMock.createMock(AnnotatedType.class); - beanManager = null; - } - - private List getActions(StartupBootstrap bootstrap) throws IllegalArgumentException, - IllegalAccessException { - Set fields = Whitebox.getAllStaticFields(StartupBootstrap.class); - List list = null; - for (Field field : fields) { - if (field.getName().equals("processors")) { - list = (List) field.get(bootstrap); - } - } - return list; - } - - @Test - public void processAnnotatedType() throws IllegalArgumentException, IllegalAccessException { - StartupBootstrap bootstrap = new StartupBootstrap(); - List list = getActions(bootstrap); - - assertNotNull(list); - assertTrue(list.isEmpty()); - - AnnotatedMethod am1 = PowerMock.createMock(AnnotatedMethod.class); - AnnotatedMethod am2 = PowerMock.createMock(AnnotatedMethod.class); - AnnotatedMethod am3 = PowerMock.createMock(AnnotatedMethod.class); - - Set set = new HashSet(); - set.add(am1); - set.add(am2); - set.add(am3); - - expect(am1.isAnnotationPresent(Startup.class)).andReturn(true); - expect(am2.isAnnotationPresent(Startup.class)).andReturn(true); - expect(am3.isAnnotationPresent(Startup.class)).andReturn(false); - expect(event.getAnnotatedType()).andReturn(annotatedType); - expect(annotatedType.getMethods()).andReturn(set); - - replay(event, annotatedType, am1, am2, am3); - bootstrap.processAnnotatedType(event, beanManager); - verify(event, annotatedType); - - list = getActions(bootstrap); - assertNotNull(list); - assertFalse(list.isEmpty()); - assertTrue(list.size() == 2); - } - - @SuppressWarnings("static-access") - @Test - public void testLoadTempContexts() { - StartupBootstrap bootstrap = new StartupBootstrap(); - - Logger logger = PowerMock.createMock(Logger.class); - ResourceBundleProducer bundleFactory = PowerMock.createMock(ResourceBundleProducer.class); - ResourceBundle bundle = PowerMock.createMock(ResourceBundle.class); - - PowerMock.mockStatic(Contexts.class); - PowerMock.mockStatic(LoggerProducer.class); - - List tempContexts = Whitebox.getInternalState(bootstrap, "tempContexts"); - - assertNotNull(tempContexts); - assertTrue(tempContexts.isEmpty()); - - expect(LoggerProducer.create(EasyMock.anyObject(Class.class))).andReturn(logger).anyTimes(); - expect(bundleFactory.create(EasyMock.anyObject(String.class), EasyMock.anyObject(Locale.class))).andReturn( - bundle).anyTimes(); - expect(bundle.getString(EasyMock.anyObject(String.class), EasyMock.anyObject(String.class))).andReturn("") - .anyTimes(); - - logger.trace(EasyMock.anyObject(String.class)); - EasyMock.expectLastCall().anyTimes(); - - Contexts.add(EasyMock.anyObject(ThreadLocalContext.class), EasyMock.anyObject(AfterBeanDiscovery.class)); - EasyMock.expectLastCall().anyTimes(); - - Whitebox.setInternalState(AbstractBootstrap.class, ResourceBundleProducer.class, bundleFactory); - - PowerMock.replayAll(); - bootstrap.loadTempContexts(null); - PowerMock.verifyAll(); - - assertNotNull(tempContexts); - assertEquals(4, tempContexts.size()); - - for (ThreadLocalContext tlc : tempContexts) { - if (!tlc.getScope().equals(SessionScoped.class) && !tlc.getScope().equals(ConversationScoped.class) - && !tlc.getScope().equals(RequestScoped.class) && !tlc.getScope().equals(ViewScoped.class)) { - fail(); - } - } - } - - @SuppressWarnings("static-access") - @Test - public void testStartup() throws Throwable { - StartupBootstrap bootstrap = new StartupBootstrap(); - - PowerMock.mockStatic(Contexts.class); - PowerMock.mockStatic(LoggerProducer.class); - - Logger logger = PowerMock.createMock(Logger.class); - ResourceBundleProducer bundleFactory = PowerMock.createMock(ResourceBundleProducer.class); - ResourceBundle bundle = PowerMock.createMock(ResourceBundle.class); - - expect(LoggerProducer.create(EasyMock.anyObject(Class.class))).andReturn(logger).anyTimes(); - expect(bundleFactory.create(EasyMock.anyObject(String.class), EasyMock.anyObject(Locale.class))).andReturn( - bundle).anyTimes(); - expect(bundle.getString(EasyMock.anyObject(String.class), EasyMock.anyObject(String.class))).andReturn("") - .anyTimes(); - - logger.debug(EasyMock.anyObject(String.class)); - EasyMock.expectLastCall().anyTimes(); - - Whitebox.setInternalState(AbstractBootstrap.class, ResourceBundleProducer.class, bundleFactory); - - List list = getActions(bootstrap); - list.clear(); - - MyProcessor processor = PowerMock.createMock(MyProcessor.class); - list.add(processor); - expect(processor.process()).andReturn(true).times(1); - - PowerMock.replayAll(); - bootstrap.startup(); - - assertTrue(list.isEmpty()); - PowerMock.verifyAll(); - } - - @SuppressWarnings("static-access") - @Test - public void testLoadTempContextsAndStartup() { - - StartupBootstrap bootstrap = new StartupBootstrap(); - - bootstrap.loadTempContexts(null); - Assert.assertFalse(Contexts.getActiveContexts().isEmpty()); - - try { - bootstrap.startup(); - Assert.assertTrue(Contexts.getActiveContexts().isEmpty()); - } catch (Throwable e) { - fail(); - } - } -} - -@SuppressWarnings("rawtypes") -class MyProcessor extends StartupProcessor { - - @SuppressWarnings("unchecked") - public MyProcessor(AnnotatedMethod annotatedMethod, BeanManager beanManager) { - super(annotatedMethod, beanManager); - } - - @Override - public int compareTo(final StartupProcessor other) { - return 1; - } -} +///* +// * 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 static junit.framework.Assert.assertEquals; +//import static org.easymock.EasyMock.expect; +//import static org.easymock.EasyMock.replay; +//import static org.easymock.EasyMock.verify; +//import static org.junit.Assert.assertFalse; +//import static org.junit.Assert.assertNotNull; +//import static org.junit.Assert.assertTrue; +//import static org.junit.Assert.fail; +// +//import java.lang.reflect.Field; +//import java.util.HashSet; +//import java.util.List; +//import java.util.Locale; +//import java.util.Set; +// +//import javax.enterprise.context.ConversationScoped; +//import javax.enterprise.context.RequestScoped; +//import javax.enterprise.context.SessionScoped; +//import javax.enterprise.inject.spi.AfterBeanDiscovery; +//import javax.enterprise.inject.spi.AnnotatedMethod; +//import javax.enterprise.inject.spi.AnnotatedType; +//import javax.enterprise.inject.spi.BeanManager; +//import javax.enterprise.inject.spi.ProcessAnnotatedType; +// +//import junit.framework.Assert; +// +//import org.easymock.EasyMock; +//import org.junit.Before; +//import org.junit.Ignore; +//import org.junit.Test; +//import org.junit.runner.RunWith; +//import org.powermock.api.easymock.PowerMock; +//import org.powermock.core.classloader.annotations.PrepareForTest; +//import org.powermock.modules.junit4.PowerMockRunner; +//import org.powermock.reflect.Whitebox; +//import org.slf4j.Logger; +// +//import br.gov.frameworkdemoiselle.annotation.Startup; +//import br.gov.frameworkdemoiselle.annotation.ViewScoped; +//import br.gov.frameworkdemoiselle.internal.context.Contexts; +//import br.gov.frameworkdemoiselle.internal.context.ThreadLocalContext; +//import br.gov.frameworkdemoiselle.internal.processor.StartupProcessor; +//import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; +//import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; +//import br.gov.frameworkdemoiselle.util.ResourceBundle; +// +//@Ignore +//@RunWith(PowerMockRunner.class) +//@PrepareForTest({ Contexts.class, LoggerProducer.class, ResourceBundle.class, ResourceBundleProducer.class }) +//@SuppressWarnings({ "rawtypes", "unchecked" }) +//public class StartupBootstrapTest { +// +// private ProcessAnnotatedType event; +// +// private BeanManager beanManager; +// +// private AnnotatedType annotatedType; +// +// @Before +// public void before() { +// event = EasyMock.createMock(ProcessAnnotatedType.class); +// annotatedType = EasyMock.createMock(AnnotatedType.class); +// beanManager = null; +// } +// +// private List getActions(StartupBootstrap bootstrap) throws IllegalArgumentException, +// IllegalAccessException { +// Set fields = Whitebox.getAllStaticFields(StartupBootstrap.class); +// List list = null; +// for (Field field : fields) { +// if (field.getName().equals("processors")) { +// list = (List) field.get(bootstrap); +// } +// } +// return list; +// } +// +// @Test +// public void processAnnotatedType() throws IllegalArgumentException, IllegalAccessException { +// StartupBootstrap bootstrap = new StartupBootstrap(); +// List list = getActions(bootstrap); +// +// assertNotNull(list); +// assertTrue(list.isEmpty()); +// +// AnnotatedMethod am1 = PowerMock.createMock(AnnotatedMethod.class); +// AnnotatedMethod am2 = PowerMock.createMock(AnnotatedMethod.class); +// AnnotatedMethod am3 = PowerMock.createMock(AnnotatedMethod.class); +// +// Set set = new HashSet(); +// set.add(am1); +// set.add(am2); +// set.add(am3); +// +// expect(am1.isAnnotationPresent(Startup.class)).andReturn(true); +// expect(am2.isAnnotationPresent(Startup.class)).andReturn(true); +// expect(am3.isAnnotationPresent(Startup.class)).andReturn(false); +// expect(event.getAnnotatedType()).andReturn(annotatedType); +// expect(annotatedType.getMethods()).andReturn(set); +// +// replay(event, annotatedType, am1, am2, am3); +// bootstrap.processAnnotatedType(event, beanManager); +// verify(event, annotatedType); +// +// list = getActions(bootstrap); +// assertNotNull(list); +// assertFalse(list.isEmpty()); +// assertTrue(list.size() == 2); +// } +// +// @SuppressWarnings("static-access") +// @Test +// public void testLoadTempContexts() { +// StartupBootstrap bootstrap = new StartupBootstrap(); +// +// Logger logger = PowerMock.createMock(Logger.class); +// ResourceBundleProducer bundleFactory = PowerMock.createMock(ResourceBundleProducer.class); +// ResourceBundle bundle = PowerMock.createMock(ResourceBundle.class); +// +// PowerMock.mockStatic(Contexts.class); +// PowerMock.mockStatic(LoggerProducer.class); +// +// List tempContexts = Whitebox.getInternalState(bootstrap, "tempContexts"); +// +// assertNotNull(tempContexts); +// assertTrue(tempContexts.isEmpty()); +// +// expect(LoggerProducer.create(EasyMock.anyObject(Class.class))).andReturn(logger).anyTimes(); +// expect(bundleFactory.create(EasyMock.anyObject(String.class), EasyMock.anyObject(Locale.class))).andReturn( +// bundle).anyTimes(); +// expect(bundle.getString(EasyMock.anyObject(String.class), EasyMock.anyObject(String.class))).andReturn("") +// .anyTimes(); +// +// logger.trace(EasyMock.anyObject(String.class)); +// EasyMock.expectLastCall().anyTimes(); +// +// Contexts.add(EasyMock.anyObject(ThreadLocalContext.class), EasyMock.anyObject(AfterBeanDiscovery.class)); +// EasyMock.expectLastCall().anyTimes(); +// +// Whitebox.setInternalState(AbstractBootstrap.class, ResourceBundleProducer.class, bundleFactory); +// +// PowerMock.replayAll(); +// bootstrap.loadTempContexts(null); +// PowerMock.verifyAll(); +// +// assertNotNull(tempContexts); +// assertEquals(4, tempContexts.size()); +// +// for (ThreadLocalContext tlc : tempContexts) { +// if (!tlc.getScope().equals(SessionScoped.class) && !tlc.getScope().equals(ConversationScoped.class) +// && !tlc.getScope().equals(RequestScoped.class) && !tlc.getScope().equals(ViewScoped.class)) { +// fail(); +// } +// } +// } +// +// @SuppressWarnings("static-access") +// @Test +// public void testStartup() throws Throwable { +// StartupBootstrap bootstrap = new StartupBootstrap(); +// +// PowerMock.mockStatic(Contexts.class); +// PowerMock.mockStatic(LoggerProducer.class); +// +// Logger logger = PowerMock.createMock(Logger.class); +// ResourceBundleProducer bundleFactory = PowerMock.createMock(ResourceBundleProducer.class); +// ResourceBundle bundle = PowerMock.createMock(ResourceBundle.class); +// +// expect(LoggerProducer.create(EasyMock.anyObject(Class.class))).andReturn(logger).anyTimes(); +// expect(bundleFactory.create(EasyMock.anyObject(String.class), EasyMock.anyObject(Locale.class))).andReturn( +// bundle).anyTimes(); +// expect(bundle.getString(EasyMock.anyObject(String.class), EasyMock.anyObject(String.class))).andReturn("") +// .anyTimes(); +// +// logger.debug(EasyMock.anyObject(String.class)); +// EasyMock.expectLastCall().anyTimes(); +// +// Whitebox.setInternalState(AbstractBootstrap.class, ResourceBundleProducer.class, bundleFactory); +// +// List list = getActions(bootstrap); +// list.clear(); +// +// MyProcessor processor = PowerMock.createMock(MyProcessor.class); +// list.add(processor); +// expect(processor.process()).andReturn(true).times(1); +// +// PowerMock.replayAll(); +// bootstrap.startup(); +// +// assertTrue(list.isEmpty()); +// PowerMock.verifyAll(); +// } +// +// @SuppressWarnings("static-access") +// @Test +// public void testLoadTempContextsAndStartup() { +// +// StartupBootstrap bootstrap = new StartupBootstrap(); +// +// bootstrap.loadTempContexts(null); +// Assert.assertFalse(Contexts.getActiveContexts().isEmpty()); +// +// try { +// bootstrap.startup(); +// Assert.assertTrue(Contexts.getActiveContexts().isEmpty()); +// } catch (Throwable e) { +// fail(); +// } +// } +//} +// +//@SuppressWarnings("rawtypes") +//class MyProcessor extends StartupProcessor { +// +// @SuppressWarnings("unchecked") +// public MyProcessor(AnnotatedMethod annotatedMethod, BeanManager beanManager) { +// super(annotatedMethod, beanManager); +// } +// +// @Override +// public int compareTo(final StartupProcessor other) { +// return 1; +// } +// } diff --git a/impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/util/ServletContextListener.java b/impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/util/ServletContextListener.java deleted file mode 100644 index 431c294..0000000 --- a/impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/util/ServletContextListener.java +++ /dev/null @@ -1,19 +0,0 @@ -package br.gov.frameworkdemoiselle.util; - -import javax.servlet.ServletContextEvent; - -import br.gov.frameworkdemoiselle.internal.bootstrap.ShutdownBootstrap; -import br.gov.frameworkdemoiselle.internal.bootstrap.StartupBootstrap; - -public class ServletContextListener implements javax.servlet.ServletContextListener { - - @Override - public void contextInitialized(ServletContextEvent event) { - StartupBootstrap.startup(); - } - - @Override - public void contextDestroyed(ServletContextEvent event) { - ShutdownBootstrap.shutdown(); - } -} diff --git a/impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/util/ServletListener.java b/impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/util/ServletListener.java index 37d75eb..f1fb7af 100644 --- a/impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/util/ServletListener.java +++ b/impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/util/ServletListener.java @@ -38,18 +38,30 @@ package br.gov.frameworkdemoiselle.util; import javax.servlet.ServletContextEvent; -import br.gov.frameworkdemoiselle.internal.bootstrap.ShutdownBootstrap; -import br.gov.frameworkdemoiselle.internal.bootstrap.StartupBootstrap; +import br.gov.frameworkdemoiselle.internal.bootstrap.BeforeApplicationFinalization; +import br.gov.frameworkdemoiselle.internal.bootstrap.BeforeApplicationInitialization; public class ServletListener implements javax.servlet.ServletContextListener { @Override public void contextInitialized(ServletContextEvent event) { - StartupBootstrap.startup(); + Beans.getBeanManager().fireEvent(new BeforeApplicationInitialization() { + + @Override + public boolean removeProcessors() { + return false; + } + }); } @Override public void contextDestroyed(ServletContextEvent event) { - ShutdownBootstrap.shutdown(); + Beans.getBeanManager().fireEvent(new BeforeApplicationFinalization() { + + @Override + public boolean removeProcessors() { + return false; + } + }); } } -- libgit2 0.21.2