deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject git commit: DELTASPIKE-530 deactivatable extensions
Date Thu, 27 Feb 2014 11:24:33 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master ab5105bd5 -> 303507d6b


DELTASPIKE-530 deactivatable extensions


Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/303507d6
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/303507d6
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/303507d6

Branch: refs/heads/master
Commit: 303507d6b9bc385699dc926e0ffa5b73737d9f89
Parents: ab5105b
Author: gpetracek <gpetracek@apache.org>
Authored: Thu Feb 27 12:20:58 2014 +0100
Committer: gpetracek <gpetracek@apache.org>
Committed: Thu Feb 27 12:21:42 2014 +0100

----------------------------------------------------------------------
 .../impl/scope/DeltaSpikeContextExtension.java  | 22 +++++++++++++++++++-
 .../data/impl/RepositoryExtension.java          | 22 +++++++++++++++++++-
 2 files changed, 42 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/303507d6/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/DeltaSpikeContextExtension.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/DeltaSpikeContextExtension.java
b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/DeltaSpikeContextExtension.java
index 2e74c0f..536866b 100644
--- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/DeltaSpikeContextExtension.java
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/DeltaSpikeContextExtension.java
@@ -22,6 +22,7 @@ import javax.enterprise.event.Observes;
 import javax.enterprise.inject.spi.AfterBeanDiscovery;
 import javax.enterprise.inject.spi.AfterDeploymentValidation;
 import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.BeforeBeanDiscovery;
 import javax.enterprise.inject.spi.Extension;
 
 import org.apache.deltaspike.core.api.provider.BeanProvider;
@@ -30,19 +31,33 @@ import org.apache.deltaspike.core.impl.scope.conversation.GroupedConversationCon
 import org.apache.deltaspike.core.impl.scope.window.WindowBeanHolder;
 import org.apache.deltaspike.core.impl.scope.window.WindowContextImpl;
 import org.apache.deltaspike.core.impl.scope.window.WindowIdHolder;
+import org.apache.deltaspike.core.spi.activation.Deactivatable;
+import org.apache.deltaspike.core.util.ClassDeactivationUtils;
 
 /**
  * Handle all DeltaSpike WindowContext and ConversationContext
  * related features.
  */
-public class DeltaSpikeContextExtension implements Extension
+public class DeltaSpikeContextExtension implements Extension, Deactivatable
 {
     private WindowContextImpl windowContext;
 
     private GroupedConversationContext conversationContext;
 
+    private Boolean isActivated = true;
+
+    protected void init(@Observes BeforeBeanDiscovery beforeBeanDiscovery)
+    {
+        isActivated = ClassDeactivationUtils.isActivated(getClass());
+    }
+
     public void registerDeltaSpikeContexts(@Observes AfterBeanDiscovery afterBeanDiscovery,
BeanManager beanManager)
     {
+        if (!isActivated)
+        {
+            return;
+        }
+
         windowContext = new WindowContextImpl(beanManager);
         conversationContext = new GroupedConversationContext(beanManager, windowContext);
         afterBeanDiscovery.addContext(windowContext);
@@ -56,6 +71,11 @@ public class DeltaSpikeContextExtension implements Extension
      */
     public void initializeDeltaSpikeContexts(@Observes AfterDeploymentValidation adv, BeanManager
beanManager)
     {
+        if (!isActivated)
+        {
+            return;
+        }
+
         WindowBeanHolder windowBeanHolder =
             BeanProvider.getContextualReference(beanManager, WindowBeanHolder.class, false);
 

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/303507d6/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/RepositoryExtension.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/RepositoryExtension.java
b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/RepositoryExtension.java
index ef098fd..7890942 100755
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/RepositoryExtension.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/RepositoryExtension.java
@@ -32,6 +32,8 @@ import javax.enterprise.inject.spi.BeforeBeanDiscovery;
 import javax.enterprise.inject.spi.Extension;
 import javax.enterprise.inject.spi.ProcessAnnotatedType;
 
+import org.apache.deltaspike.core.spi.activation.Deactivatable;
+import org.apache.deltaspike.core.util.ClassDeactivationUtils;
 import org.apache.deltaspike.data.api.Repository;
 import org.apache.deltaspike.data.impl.meta.RepositoryComponentsFactory;
 import org.apache.deltaspike.data.impl.meta.unit.PersistenceUnits;
@@ -50,7 +52,7 @@ import org.apache.deltaspike.data.impl.meta.unit.PersistenceUnits;
  * <b>{@code @Observes AfterBeanDiscovery<X>}</b>:
  *     Raises any definition errors discovered before.
  */
-public class RepositoryExtension implements Extension
+public class RepositoryExtension implements Extension, Deactivatable
 {
 
     private static final Logger log = Logger.getLogger(RepositoryExtension.class.getName());
@@ -58,13 +60,26 @@ public class RepositoryExtension implements Extension
     private final List<RepositoryDefinitionException> definitionExceptions =
             new LinkedList<RepositoryDefinitionException>();
 
+    private Boolean isActivated = true;
+
     void beforeBeanDiscovery(@Observes BeforeBeanDiscovery before)
     {
+        isActivated = ClassDeactivationUtils.isActivated(getClass());
+
+        if (!isActivated)
+        {
+            return;
+        }
         PersistenceUnits.instance().init();
     }
 
     <X> void processAnnotatedType(@Observes ProcessAnnotatedType<X> event)
     {
+        if (!isActivated)
+        {
+            return;
+        }
+
         if (isRepository(event.getAnnotatedType()))
         {
             Class<X> repoClass = event.getAnnotatedType().getJavaClass();
@@ -87,6 +102,11 @@ public class RepositoryExtension implements Extension
 
     <X> void addDefinitionErrors(@Observes AfterBeanDiscovery afterBeanDiscovery, BeanManager
beanManager)
     {
+        if (!isActivated)
+        {
+            return;
+        }
+
         for (RepositoryDefinitionException ex : definitionExceptions)
         {
             afterBeanDiscovery.addDefinitionError(ex);


Mime
View raw message