Commit a84535ab32175ee118ecf428cd68d3662517534c

Authored by Dancovich
1 parent d3ebc763
Exists in master

IN PROGRESS - issue FWK-148: Não é possível anotar métodos com @Startup

se o método usa um EntityManager injetado e o escopo do EntityManager é
de visão (ViewScoped). 
https://demoiselle.atlassian.net/browse/FWK-148
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AbstractLifecycleBootstrap.java
@@ -53,9 +53,11 @@ import org.slf4j.Logger; @@ -53,9 +53,11 @@ import org.slf4j.Logger;
53 53
54 import br.gov.frameworkdemoiselle.DemoiselleException; 54 import br.gov.frameworkdemoiselle.DemoiselleException;
55 import br.gov.frameworkdemoiselle.context.ConversationContext; 55 import br.gov.frameworkdemoiselle.context.ConversationContext;
  56 +import br.gov.frameworkdemoiselle.context.CustomContext;
56 import br.gov.frameworkdemoiselle.context.RequestContext; 57 import br.gov.frameworkdemoiselle.context.RequestContext;
57 import br.gov.frameworkdemoiselle.context.SessionContext; 58 import br.gov.frameworkdemoiselle.context.SessionContext;
58 import br.gov.frameworkdemoiselle.context.ViewContext; 59 import br.gov.frameworkdemoiselle.context.ViewContext;
  60 +import br.gov.frameworkdemoiselle.internal.context.TemporaryViewContextImpl;
59 import br.gov.frameworkdemoiselle.internal.implementation.AnnotatedMethodProcessor; 61 import br.gov.frameworkdemoiselle.internal.implementation.AnnotatedMethodProcessor;
60 import br.gov.frameworkdemoiselle.util.Beans; 62 import br.gov.frameworkdemoiselle.util.Beans;
61 import br.gov.frameworkdemoiselle.util.NameQualifier; 63 import br.gov.frameworkdemoiselle.util.NameQualifier;
@@ -75,6 +77,8 @@ public abstract class AbstractLifecycleBootstrap<A extends Annotation> implement @@ -75,6 +77,8 @@ public abstract class AbstractLifecycleBootstrap<A extends Annotation> implement
75 private boolean registered = false; 77 private boolean registered = false;
76 78
77 private HashMap<String, Boolean> startedContextHere = new HashMap<String, Boolean>(); 79 private HashMap<String, Boolean> startedContextHere = new HashMap<String, Boolean>();
  80 +
  81 + private transient CustomContext backupContext = null;
78 82
79 protected abstract Logger getLogger(); 83 protected abstract Logger getLogger();
80 84
@@ -157,14 +161,34 @@ public abstract class AbstractLifecycleBootstrap&lt;A extends Annotation&gt; implement @@ -157,14 +161,34 @@ public abstract class AbstractLifecycleBootstrap&lt;A extends Annotation&gt; implement
157 startedContextHere.put("session", sessionContext.activate()); 161 startedContextHere.put("session", sessionContext.activate());
158 } 162 }
159 163
160 - if (viewContext!=null){  
161 - startedContextHere.put("view", viewContext.activate());  
162 - }  
163 164
164 if (conversationContext!=null){ 165 if (conversationContext!=null){
165 startedContextHere.put("conversation", conversationContext.activate()); 166 startedContextHere.put("conversation", conversationContext.activate());
166 } 167 }
167 168
  169 + //Contexto temporário de visão precisa de tratamento especial
  170 + //para evitar conflito com o contexto presente na extensão demoiselle-jsf
  171 + if (viewContext!=null){
  172 + if (TemporaryViewContextImpl.class.isInstance(viewContext)){
  173 + startedContextHere.put("view", viewContext.activate());
  174 + }
  175 + else{
  176 + //Precisamos desativar temporariamente o contexto
  177 + if (viewContext.isActive()){
  178 + backupContext = viewContext;
  179 + viewContext.deactivate();
  180 +
  181 + CustomContextBootstrap customContextBootstrap = Beans.getReference(CustomContextBootstrap.class);
  182 + for (CustomContext customContext : customContextBootstrap.getCustomContexts()){
  183 + if ( TemporaryViewContextImpl.class.isInstance(customContext) ){
  184 + startedContextHere.put("view", customContext.activate());
  185 + break;
  186 + }
  187 + }
  188 + }
  189 + }
  190 + }
  191 +
168 registered = true; 192 registered = true;
169 } 193 }
170 } 194 }
@@ -184,13 +208,22 @@ public abstract class AbstractLifecycleBootstrap&lt;A extends Annotation&gt; implement @@ -184,13 +208,22 @@ public abstract class AbstractLifecycleBootstrap&lt;A extends Annotation&gt; implement
184 sessionContext.deactivate(); 208 sessionContext.deactivate();
185 } 209 }
186 210
187 - if (viewContext!=null && Boolean.TRUE.equals(startedContextHere.get("view"))){  
188 - viewContext.deactivate();  
189 - }  
190 -  
191 if (conversationContext!=null && Boolean.TRUE.equals(startedContextHere.get("conversation"))){ 211 if (conversationContext!=null && Boolean.TRUE.equals(startedContextHere.get("conversation"))){
192 conversationContext.deactivate(); 212 conversationContext.deactivate();
193 } 213 }
  214 +
  215 + //Contexto temporário de visão precisa de tratamento especial
  216 + //para evitar conflito com o contexto presente na extensão demoiselle-jsf
  217 + if (viewContext!=null){
  218 + if (TemporaryViewContextImpl.class.isInstance(viewContext) && startedContextHere.get("view")){
  219 + viewContext.deactivate();
  220 +
  221 + if (backupContext!=null){
  222 + backupContext.activate();
  223 + backupContext = null;
  224 + }
  225 + }
  226 + }
194 } 227 }
195 } 228 }
196 } 229 }