Commit a1cf72f1281fa6f598ebb92026d13630348787cb
1 parent
c2470614
Exists in
master
Resolvido bug que impedia levantamento de aplicação web após refatoração
de contextos.
Showing
7 changed files
with
68 additions
and
20 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AbstractLifecycleBootstrap.java
| @@ -51,6 +51,7 @@ import javax.enterprise.inject.spi.ProcessAnnotatedType; | @@ -51,6 +51,7 @@ import javax.enterprise.inject.spi.ProcessAnnotatedType; | ||
| 51 | import org.slf4j.Logger; | 51 | import org.slf4j.Logger; |
| 52 | 52 | ||
| 53 | import br.gov.frameworkdemoiselle.DemoiselleException; | 53 | import br.gov.frameworkdemoiselle.DemoiselleException; |
| 54 | +import br.gov.frameworkdemoiselle.context.ConversationContext; | ||
| 54 | import br.gov.frameworkdemoiselle.context.RequestContext; | 55 | import br.gov.frameworkdemoiselle.context.RequestContext; |
| 55 | import br.gov.frameworkdemoiselle.context.SessionContext; | 56 | import br.gov.frameworkdemoiselle.context.SessionContext; |
| 56 | import br.gov.frameworkdemoiselle.context.ViewContext; | 57 | import br.gov.frameworkdemoiselle.context.ViewContext; |
| @@ -127,11 +128,25 @@ public abstract class AbstractLifecycleBootstrap<A extends Annotation> implement | @@ -127,11 +128,25 @@ public abstract class AbstractLifecycleBootstrap<A extends Annotation> implement | ||
| 127 | RequestContext tempRequestContext = Beans.getReference(RequestContext.class); | 128 | RequestContext tempRequestContext = Beans.getReference(RequestContext.class); |
| 128 | SessionContext tempSessionContext = Beans.getReference(SessionContext.class); | 129 | SessionContext tempSessionContext = Beans.getReference(SessionContext.class); |
| 129 | ViewContext tempViewContext = Beans.getReference(ViewContext.class); | 130 | ViewContext tempViewContext = Beans.getReference(ViewContext.class); |
| 131 | + ConversationContext tempConversationContext = Beans.getReference(ConversationContext.class); | ||
| 130 | 132 | ||
| 133 | + boolean requestActivatedHere = !tempRequestContext.isActive(); | ||
| 134 | + boolean sessionActivatedHere = !tempSessionContext.isActive(); | ||
| 135 | + boolean viewActivatedHere = !tempViewContext.isActive(); | ||
| 136 | + boolean conversationActivatedHere = !tempConversationContext.isActive(); | ||
| 137 | + | ||
| 131 | if (!registered) { | 138 | if (!registered) { |
| 132 | - tempRequestContext.activate(); | ||
| 133 | - tempSessionContext.activate(); | ||
| 134 | - tempViewContext.activate(); | 139 | + if (!tempRequestContext.isActive()) |
| 140 | + tempRequestContext.activate(); | ||
| 141 | + | ||
| 142 | + if (!tempSessionContext.isActive()) | ||
| 143 | + tempSessionContext.activate(); | ||
| 144 | + | ||
| 145 | + if (!tempViewContext.isActive()) | ||
| 146 | + tempViewContext.activate(); | ||
| 147 | + | ||
| 148 | + if (!tempConversationContext.isActive()) | ||
| 149 | + tempConversationContext.activate(); | ||
| 135 | 150 | ||
| 136 | registered = true; | 151 | registered = true; |
| 137 | } | 152 | } |
| @@ -154,9 +169,21 @@ public abstract class AbstractLifecycleBootstrap<A extends Annotation> implement | @@ -154,9 +169,21 @@ public abstract class AbstractLifecycleBootstrap<A extends Annotation> implement | ||
| 154 | } | 169 | } |
| 155 | 170 | ||
| 156 | if (processors.isEmpty()) { | 171 | if (processors.isEmpty()) { |
| 157 | - tempRequestContext.deactivate(); | ||
| 158 | - tempSessionContext.deactivate(); | ||
| 159 | - tempViewContext.deactivate(); | 172 | + if (requestActivatedHere){ |
| 173 | + tempRequestContext.deactivate(); | ||
| 174 | + } | ||
| 175 | + | ||
| 176 | + if (sessionActivatedHere){ | ||
| 177 | + tempSessionContext.deactivate(); | ||
| 178 | + } | ||
| 179 | + | ||
| 180 | + if (viewActivatedHere){ | ||
| 181 | + tempViewContext.deactivate(); | ||
| 182 | + } | ||
| 183 | + | ||
| 184 | + if (conversationActivatedHere){ | ||
| 185 | + tempConversationContext.deactivate(); | ||
| 186 | + } | ||
| 160 | } | 187 | } |
| 161 | 188 | ||
| 162 | if (failure != null) { | 189 | if (failure != null) { |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/AbstractCustomContext.java
| @@ -175,6 +175,23 @@ public abstract class AbstractCustomContext implements CustomContext { | @@ -175,6 +175,23 @@ public abstract class AbstractCustomContext implements CustomContext { | ||
| 175 | 175 | ||
| 176 | return logger; | 176 | return logger; |
| 177 | } | 177 | } |
| 178 | + | ||
| 179 | + @Override | ||
| 180 | + public boolean equals(Object obj) { | ||
| 181 | + if (this == obj) | ||
| 182 | + return true; | ||
| 183 | + if (obj == null) | ||
| 184 | + return false; | ||
| 185 | + if ( !this.getClass().equals(obj.getClass()) ) | ||
| 186 | + return false; | ||
| 187 | + AbstractCustomContext other = (AbstractCustomContext) obj; | ||
| 188 | + if (scope == null) { | ||
| 189 | + if (other.scope != null) | ||
| 190 | + return false; | ||
| 191 | + } else if (!scope.equals(other.scope)) | ||
| 192 | + return false; | ||
| 193 | + return true; | ||
| 194 | + } | ||
| 178 | 195 | ||
| 179 | static class Store { | 196 | static class Store { |
| 180 | 197 |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/CustomContextProducer.java
| @@ -103,7 +103,7 @@ public class CustomContextProducer { | @@ -103,7 +103,7 @@ public class CustomContextProducer { | ||
| 103 | logger.debug( bundle.getString("bootstrap-context-added", context.getClass().getCanonicalName() , context.getScope().getSimpleName() ) ); | 103 | logger.debug( bundle.getString("bootstrap-context-added", context.getClass().getCanonicalName() , context.getScope().getSimpleName() ) ); |
| 104 | } | 104 | } |
| 105 | else{ | 105 | else{ |
| 106 | - logger.debug( bundle.getString("bootstrap-context-already-managed", context.getClass().getCanonicalName() , context.getScope().getSimpleName() ) ); | 106 | + logger.warn( bundle.getString("bootstrap-context-already-managed", context.getClass().getCanonicalName() , context.getScope().getSimpleName() ) ); |
| 107 | } | 107 | } |
| 108 | } | 108 | } |
| 109 | 109 |
impl/extension/jpa/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/EntityManagerBootstrap.java
| @@ -10,17 +10,14 @@ import javax.enterprise.context.ApplicationScoped; | @@ -10,17 +10,14 @@ import javax.enterprise.context.ApplicationScoped; | ||
| 10 | import javax.enterprise.context.ConversationScoped; | 10 | import javax.enterprise.context.ConversationScoped; |
| 11 | import javax.enterprise.context.RequestScoped; | 11 | import javax.enterprise.context.RequestScoped; |
| 12 | import javax.enterprise.context.SessionScoped; | 12 | import javax.enterprise.context.SessionScoped; |
| 13 | -import javax.enterprise.event.Observes; | ||
| 14 | import javax.enterprise.inject.spi.AnnotatedConstructor; | 13 | import javax.enterprise.inject.spi.AnnotatedConstructor; |
| 15 | import javax.enterprise.inject.spi.AnnotatedField; | 14 | import javax.enterprise.inject.spi.AnnotatedField; |
| 16 | import javax.enterprise.inject.spi.AnnotatedMethod; | 15 | import javax.enterprise.inject.spi.AnnotatedMethod; |
| 17 | import javax.enterprise.inject.spi.AnnotatedType; | 16 | import javax.enterprise.inject.spi.AnnotatedType; |
| 18 | import javax.enterprise.inject.spi.BeanManager; | 17 | import javax.enterprise.inject.spi.BeanManager; |
| 19 | -import javax.enterprise.inject.spi.BeforeBeanDiscovery; | ||
| 20 | import javax.enterprise.inject.spi.Extension; | 18 | import javax.enterprise.inject.spi.Extension; |
| 21 | import javax.enterprise.inject.spi.ProcessAnnotatedType; | 19 | import javax.enterprise.inject.spi.ProcessAnnotatedType; |
| 22 | import javax.enterprise.inject.spi.ProcessBean; | 20 | import javax.enterprise.inject.spi.ProcessBean; |
| 23 | -import javax.enterprise.inject.spi.ProcessManagedBean; | ||
| 24 | 21 | ||
| 25 | import org.apache.commons.configuration.PropertiesConfiguration; | 22 | import org.apache.commons.configuration.PropertiesConfiguration; |
| 26 | import org.slf4j.Logger; | 23 | import org.slf4j.Logger; |
| @@ -42,7 +39,7 @@ public class EntityManagerBootstrap implements Extension { | @@ -42,7 +39,7 @@ public class EntityManagerBootstrap implements Extension { | ||
| 42 | 39 | ||
| 43 | private EntityManagerScope selectedScope; | 40 | private EntityManagerScope selectedScope; |
| 44 | 41 | ||
| 45 | - public void replaceAnnotatedType(@Observes final ProcessAnnotatedType<EntityManagerProducer> event , BeanManager manager){ | 42 | + public void replaceAnnotatedType(final ProcessAnnotatedType<EntityManagerProducer> event , BeanManager manager){ |
| 46 | 43 | ||
| 47 | if (event.getAnnotatedType().getJavaClass().equals(EntityManagerProducer.class)){ | 44 | if (event.getAnnotatedType().getJavaClass().equals(EntityManagerProducer.class)){ |
| 48 | AnnotatedType<EntityManagerProducer> wrapper = new AnnotatedType<EntityManagerProducer>() { | 45 | AnnotatedType<EntityManagerProducer> wrapper = new AnnotatedType<EntityManagerProducer>() { |
| @@ -135,10 +132,7 @@ public class EntityManagerBootstrap implements Extension { | @@ -135,10 +132,7 @@ public class EntityManagerBootstrap implements Extension { | ||
| 135 | } | 132 | } |
| 136 | } | 133 | } |
| 137 | 134 | ||
| 138 | - public void a(@Observes BeforeBeanDiscovery event){ | ||
| 139 | - } | ||
| 140 | - | ||
| 141 | - public void configureBean(@Observes ProcessBean<EntityManagerProducer> event , BeanManager manager){ | 135 | + public void configureBean(ProcessBean<EntityManagerProducer> event , BeanManager manager){ |
| 142 | Class<? extends Annotation> beanScope = event.getBean().getScope(); | 136 | Class<? extends Annotation> beanScope = event.getBean().getScope(); |
| 143 | System.out.println(beanScope.toString()); | 137 | System.out.println(beanScope.toString()); |
| 144 | } | 138 | } |
impl/extension/jpa/src/main/java/br/gov/frameworkdemoiselle/internal/producer/EntityManagerProducer.java
| @@ -44,6 +44,7 @@ import java.util.Set; | @@ -44,6 +44,7 @@ import java.util.Set; | ||
| 44 | 44 | ||
| 45 | import javax.annotation.PostConstruct; | 45 | import javax.annotation.PostConstruct; |
| 46 | import javax.annotation.PreDestroy; | 46 | import javax.annotation.PreDestroy; |
| 47 | +import javax.enterprise.context.RequestScoped; | ||
| 47 | import javax.enterprise.inject.Default; | 48 | import javax.enterprise.inject.Default; |
| 48 | import javax.enterprise.inject.Produces; | 49 | import javax.enterprise.inject.Produces; |
| 49 | import javax.enterprise.inject.spi.InjectionPoint; | 50 | import javax.enterprise.inject.spi.InjectionPoint; |
| @@ -66,6 +67,7 @@ import br.gov.frameworkdemoiselle.util.ResourceBundle; | @@ -66,6 +67,7 @@ import br.gov.frameworkdemoiselle.util.ResourceBundle; | ||
| 66 | * persistence.xml, demoiselle.properties or @PersistenceUnit annotation. | 67 | * persistence.xml, demoiselle.properties or @PersistenceUnit annotation. |
| 67 | * </p> | 68 | * </p> |
| 68 | */ | 69 | */ |
| 70 | +@RequestScoped | ||
| 69 | public class EntityManagerProducer implements Serializable { | 71 | public class EntityManagerProducer implements Serializable { |
| 70 | 72 | ||
| 71 | private static final long serialVersionUID = 1L; | 73 | private static final long serialVersionUID = 1L; |
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/JsfBootstrap.java
| @@ -41,7 +41,6 @@ import javax.enterprise.inject.spi.AfterBeanDiscovery; | @@ -41,7 +41,6 @@ import javax.enterprise.inject.spi.AfterBeanDiscovery; | ||
| 41 | import javax.enterprise.inject.spi.AfterDeploymentValidation; | 41 | import javax.enterprise.inject.spi.AfterDeploymentValidation; |
| 42 | import javax.enterprise.inject.spi.Extension; | 42 | import javax.enterprise.inject.spi.Extension; |
| 43 | 43 | ||
| 44 | -import br.gov.frameworkdemoiselle.context.ViewContext; | ||
| 45 | import br.gov.frameworkdemoiselle.internal.context.CustomContextProducer; | 44 | import br.gov.frameworkdemoiselle.internal.context.CustomContextProducer; |
| 46 | import br.gov.frameworkdemoiselle.internal.context.FacesViewContextImpl; | 45 | import br.gov.frameworkdemoiselle.internal.context.FacesViewContextImpl; |
| 47 | import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess; | 46 | import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess; |
| @@ -54,6 +53,7 @@ public class JsfBootstrap implements Extension { | @@ -54,6 +53,7 @@ public class JsfBootstrap implements Extension { | ||
| 54 | //private AfterBeanDiscovery afterBeanDiscoveryEvent; | 53 | //private AfterBeanDiscovery afterBeanDiscoveryEvent; |
| 55 | 54 | ||
| 56 | private FacesViewContextImpl context; | 55 | private FacesViewContextImpl context; |
| 56 | + private boolean contextActivatedHere; | ||
| 57 | 57 | ||
| 58 | public void createCustomContext(@Observes AfterBeanDiscovery event){ | 58 | public void createCustomContext(@Observes AfterBeanDiscovery event){ |
| 59 | context = new FacesViewContextImpl(); | 59 | context = new FacesViewContextImpl(); |
| @@ -65,13 +65,19 @@ public class JsfBootstrap implements Extension { | @@ -65,13 +65,19 @@ public class JsfBootstrap implements Extension { | ||
| 65 | producer.addRegisteredContext(context); | 65 | producer.addRegisteredContext(context); |
| 66 | 66 | ||
| 67 | //Ativa o ViewContext | 67 | //Ativa o ViewContext |
| 68 | - ViewContext ctx = Beans.getReference(FacesViewContextImpl.class); | ||
| 69 | - ctx.activate(); | 68 | + if (!context.isActive()){ |
| 69 | + context.activate(); | ||
| 70 | + contextActivatedHere = true; | ||
| 71 | + } | ||
| 72 | + else{ | ||
| 73 | + contextActivatedHere = false; | ||
| 74 | + } | ||
| 70 | } | 75 | } |
| 71 | 76 | ||
| 72 | public void removeContexts(@Observes AfterShutdownProccess event) { | 77 | public void removeContexts(@Observes AfterShutdownProccess event) { |
| 73 | //Desativa o ViewContext | 78 | //Desativa o ViewContext |
| 74 | - ViewContext ctx = Beans.getReference(FacesViewContextImpl.class); | ||
| 75 | - ctx.deactivate(); | 79 | + if (contextActivatedHere){ |
| 80 | + context.deactivate(); | ||
| 81 | + } | ||
| 76 | } | 82 | } |
| 77 | } | 83 | } |
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/context/FacesViewContextImpl.java
| @@ -38,6 +38,7 @@ package br.gov.frameworkdemoiselle.internal.context; | @@ -38,6 +38,7 @@ package br.gov.frameworkdemoiselle.internal.context; | ||
| 38 | 38 | ||
| 39 | import java.util.Map; | 39 | import java.util.Map; |
| 40 | 40 | ||
| 41 | +import javax.enterprise.inject.Alternative; | ||
| 41 | import javax.faces.component.UIViewRoot; | 42 | import javax.faces.component.UIViewRoot; |
| 42 | import javax.faces.context.FacesContext; | 43 | import javax.faces.context.FacesContext; |
| 43 | 44 | ||
| @@ -56,6 +57,7 @@ import br.gov.frameworkdemoiselle.util.Faces; | @@ -56,6 +57,7 @@ import br.gov.frameworkdemoiselle.util.Faces; | ||
| 56 | * | 57 | * |
| 57 | */ | 58 | */ |
| 58 | @Priority(Priority.L2_PRIORITY) | 59 | @Priority(Priority.L2_PRIORITY) |
| 60 | +@Alternative | ||
| 59 | public class FacesViewContextImpl extends AbstractCustomContext implements ViewContext { | 61 | public class FacesViewContextImpl extends AbstractCustomContext implements ViewContext { |
| 60 | 62 | ||
| 61 | public FacesViewContextImpl() { | 63 | public FacesViewContextImpl() { |