Commit 1ca3606b9591da431c8d0636e38016ccf246fd75
Exists in
master
Merge branch '2.4.0' of git@github.com:demoiselle/framework.git into 2.4.0
Showing
6 changed files
with
28 additions
and
5 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/CoreBootstrap.java
| ... | ... | @@ -91,13 +91,16 @@ public class CoreBootstrap implements Extension { |
| 91 | 91 | |
| 92 | 92 | ContextManager.activate(StaticContext.class, StaticScoped.class); |
| 93 | 93 | } |
| 94 | + | |
| 95 | + public void terminateCustomContexts(@Observes final BeforeShutdown event) { | |
| 96 | + ContextManager.shutdown(); | |
| 97 | + } | |
| 94 | 98 | |
| 95 | 99 | public void takeOff(@Observes final AfterDeploymentValidation event) { |
| 96 | 100 | getLogger().info(getBundle().getString("taking-off")); |
| 97 | 101 | } |
| 98 | 102 | |
| 99 | 103 | public void engineOff(@Observes final BeforeShutdown event) { |
| 100 | - ContextManager.shutdown(); | |
| 101 | 104 | getLogger().info(getBundle().getString("engine-off")); |
| 102 | 105 | } |
| 103 | 106 | } | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/AbstractCustomContext.java
| ... | ... | @@ -58,12 +58,15 @@ public abstract class AbstractCustomContext implements CustomContext { |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | protected abstract Store getStore(); |
| 61 | + | |
| 62 | + protected abstract boolean isStoreInitialized(); | |
| 61 | 63 | |
| 62 | 64 | @Override |
| 63 | 65 | public <T> T get(final Contextual<T> contextual) { |
| 64 | 66 | return get(contextual, null); |
| 65 | 67 | } |
| 66 | 68 | |
| 69 | + @SuppressWarnings("unchecked") | |
| 67 | 70 | @Override |
| 68 | 71 | public <T> T get(final Contextual<T> contextual, final CreationalContext<T> creationalContext) { |
| 69 | 72 | T instance = null; |
| ... | ... | @@ -97,7 +100,9 @@ public abstract class AbstractCustomContext implements CustomContext { |
| 97 | 100 | public void setActive(boolean active) { |
| 98 | 101 | if (!active && this.active) { |
| 99 | 102 | // Limpando contexto |
| 100 | - getStore().clear(); | |
| 103 | + if (isStoreInitialized()){ | |
| 104 | + getStore().clear(); | |
| 105 | + } | |
| 101 | 106 | } |
| 102 | 107 | this.active = active; |
| 103 | 108 | } | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/ContextManager.java
| ... | ... | @@ -10,7 +10,6 @@ import javax.enterprise.context.ContextNotActiveException; |
| 10 | 10 | import javax.enterprise.context.spi.Context; |
| 11 | 11 | import javax.enterprise.inject.spi.AfterBeanDiscovery; |
| 12 | 12 | import javax.enterprise.inject.spi.BeanManager; |
| 13 | -import javax.enterprise.inject.spi.BeforeShutdown; | |
| 14 | 13 | |
| 15 | 14 | import org.slf4j.Logger; |
| 16 | 15 | |
| ... | ... | @@ -196,8 +195,7 @@ public class ContextManager { |
| 196 | 195 | |
| 197 | 196 | /** |
| 198 | 197 | * <p> |
| 199 | - * This method should be called when the application is shutting down, usually by observing the | |
| 200 | - * {@link BeforeShutdown} event. | |
| 198 | + * This method should be called when the application is shutting down. | |
| 201 | 199 | * </p> |
| 202 | 200 | */ |
| 203 | 201 | public static synchronized void shutdown() { | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/StaticContext.java
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/ThreadLocalContext.java
| ... | ... | @@ -62,6 +62,11 @@ public class ThreadLocalContext extends AbstractCustomContext { |
| 62 | 62 | public ThreadLocalContext(final Class<? extends Annotation> scope) { |
| 63 | 63 | super(scope); |
| 64 | 64 | } |
| 65 | + | |
| 66 | + @Override | |
| 67 | + protected boolean isStoreInitialized() { | |
| 68 | + return threadLocal.get()!=null; | |
| 69 | + } | |
| 65 | 70 | |
| 66 | 71 | @Override |
| 67 | 72 | protected Store getStore() { | ... | ... |
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/context/ViewContext.java
| ... | ... | @@ -38,6 +38,8 @@ package br.gov.frameworkdemoiselle.internal.context; |
| 38 | 38 | |
| 39 | 39 | import java.util.Map; |
| 40 | 40 | |
| 41 | +import javax.faces.context.FacesContext; | |
| 42 | + | |
| 41 | 43 | import br.gov.frameworkdemoiselle.annotation.ViewScoped; |
| 42 | 44 | import br.gov.frameworkdemoiselle.util.Faces; |
| 43 | 45 | |
| ... | ... | @@ -46,6 +48,11 @@ public class ViewContext extends AbstractCustomContext { |
| 46 | 48 | public ViewContext() { |
| 47 | 49 | super(ViewScoped.class); |
| 48 | 50 | } |
| 51 | + | |
| 52 | + @Override | |
| 53 | + protected boolean isStoreInitialized() { | |
| 54 | + return FacesContext.getCurrentInstance()!=null; | |
| 55 | + } | |
| 49 | 56 | |
| 50 | 57 | @Override |
| 51 | 58 | protected Store getStore() { | ... | ... |