deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From johndam...@apache.org
Subject [1/2] git commit: DELTASPIKE-665 Utility method to always create context.
Date Wed, 06 Aug 2014 02:17:34 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master 3a270ec59 -> d76094f6c


DELTASPIKE-665 Utility method to always create context.


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

Branch: refs/heads/master
Commit: ae2291937417f1fb337f55bc987fdda53d1591aa
Parents: 3a270ec
Author: John D. Ament <johndament@apache.org>
Authored: Tue Aug 5 22:16:27 2014 -0400
Committer: John D. Ament <johndament@apache.org>
Committed: Tue Aug 5 22:16:27 2014 -0400

----------------------------------------------------------------------
 .../deltaspike/cdise/api/CdiContainer.java      |  5 ++++
 .../cdise/openejb/OpenEjbContainerControl.java  | 27 ++++++++++++++++++++
 .../cdise/owb/OpenWebBeansContainerControl.java | 24 +++++++++++++++++
 .../cdise/weld/WeldContainerControl.java        | 24 +++++++++++++++++
 4 files changed, 80 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ae229193/deltaspike/cdictrl/api/src/main/java/org/apache/deltaspike/cdise/api/CdiContainer.java
----------------------------------------------------------------------
diff --git a/deltaspike/cdictrl/api/src/main/java/org/apache/deltaspike/cdise/api/CdiContainer.java
b/deltaspike/cdictrl/api/src/main/java/org/apache/deltaspike/cdise/api/CdiContainer.java
index 62c7898..e15453e 100644
--- a/deltaspike/cdictrl/api/src/main/java/org/apache/deltaspike/cdise/api/CdiContainer.java
+++ b/deltaspike/cdictrl/api/src/main/java/org/apache/deltaspike/cdise/api/CdiContainer.java
@@ -72,4 +72,9 @@ public interface CdiContainer
      * @return ContextControl for the started Container. <code>null</code> if
the container is not yet started
      */
     ContextControl getContextControl();
+
+    /**
+     * @return a new - dependent context control object.
+     */
+    ContextControl createContextControl();
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ae229193/deltaspike/cdictrl/impl-openejb/src/main/java/org/apache/deltaspike/cdise/openejb/OpenEjbContainerControl.java
----------------------------------------------------------------------
diff --git a/deltaspike/cdictrl/impl-openejb/src/main/java/org/apache/deltaspike/cdise/openejb/OpenEjbContainerControl.java
b/deltaspike/cdictrl/impl-openejb/src/main/java/org/apache/deltaspike/cdise/openejb/OpenEjbContainerControl.java
index 680b320..5c8f80d 100644
--- a/deltaspike/cdictrl/impl-openejb/src/main/java/org/apache/deltaspike/cdise/openejb/OpenEjbContainerControl.java
+++ b/deltaspike/cdictrl/impl-openejb/src/main/java/org/apache/deltaspike/cdise/openejb/OpenEjbContainerControl.java
@@ -34,6 +34,7 @@ import javax.naming.NamingException;
 import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
+import java.util.logging.Logger;
 
 /**
  * OpenEJB specific implementation of {@link org.apache.deltaspike.cdise.api.CdiContainer}.
@@ -41,6 +42,8 @@ import java.util.Set;
 @SuppressWarnings("UnusedDeclaration")
 public class OpenEjbContainerControl implements CdiContainer
 {
+    private static final Logger LOG = Logger.getLogger(OpenEjbContainerControl.class.getName());
+
     // global container config
     private static final Properties PROPERTIES = new Properties();
 
@@ -148,4 +151,28 @@ public class OpenEjbContainerControl implements CdiContainer
         }
         return ctxCtrl;
     }
+
+    @Override
+    public ContextControl createContextControl()
+    {
+        BeanManager beanManager = getBeanManager();
+
+        if (beanManager == null)
+        {
+            LOG.warning("If the CDI-container was started by the environment, you can't use
this helper." +
+                    "Instead you can resolve ContextControl manually " +
+                    "(e.g. via BeanProvider.getContextualReference(ContextControl.class)
). " +
+                    "If the container wasn't started already, you have to use CdiContainer#boot
before.");
+
+            return null;
+        }
+        Set<Bean<?>> beans = beanManager.getBeans(ContextControl.class);
+        Bean<ContextControl> depCtxCtrlBean = (Bean<ContextControl>) beanManager.resolve(beans);
+
+        CreationalContext<ContextControl> depCtxCtrlCreationalContext = getBeanManager()
+                .createCreationalContext(ctxCtrlBean);
+
+        return (ContextControl)
+                getBeanManager().getReference(depCtxCtrlBean, ContextControl.class, depCtxCtrlCreationalContext);
+    }
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ae229193/deltaspike/cdictrl/impl-owb/src/main/java/org/apache/deltaspike/cdise/owb/OpenWebBeansContainerControl.java
----------------------------------------------------------------------
diff --git a/deltaspike/cdictrl/impl-owb/src/main/java/org/apache/deltaspike/cdise/owb/OpenWebBeansContainerControl.java
b/deltaspike/cdictrl/impl-owb/src/main/java/org/apache/deltaspike/cdise/owb/OpenWebBeansContainerControl.java
index 7f1fa71..0b11cb3 100644
--- a/deltaspike/cdictrl/impl-owb/src/main/java/org/apache/deltaspike/cdise/owb/OpenWebBeansContainerControl.java
+++ b/deltaspike/cdictrl/impl-owb/src/main/java/org/apache/deltaspike/cdise/owb/OpenWebBeansContainerControl.java
@@ -122,4 +122,28 @@ public class OpenWebBeansContainerControl implements CdiContainer
         }
         return ctxCtrl;
     }
+
+    @Override
+    public ContextControl createContextControl()
+    {
+        BeanManager beanManager = getBeanManager();
+
+        if (beanManager == null)
+        {
+            LOG.warning("If the CDI-container was started by the environment, you can't use
this helper." +
+                    "Instead you can resolve ContextControl manually " +
+                    "(e.g. via BeanProvider.getContextualReference(ContextControl.class)
). " +
+                    "If the container wasn't started already, you have to use CdiContainer#boot
before.");
+
+            return null;
+        }
+        Set<Bean<?>> beans = beanManager.getBeans(ContextControl.class);
+        Bean<ContextControl> depCtxCtrlBean = (Bean<ContextControl>) beanManager.resolve(beans);
+
+        CreationalContext<ContextControl> depCtxCtrlCreationalContext = getBeanManager()
+                .createCreationalContext(ctxCtrlBean);
+
+        return (ContextControl)
+                getBeanManager().getReference(depCtxCtrlBean, ContextControl.class, depCtxCtrlCreationalContext);
+    }
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ae229193/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/WeldContainerControl.java
----------------------------------------------------------------------
diff --git a/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/WeldContainerControl.java
b/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/WeldContainerControl.java
index 361b8b2..a193aa8 100644
--- a/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/WeldContainerControl.java
+++ b/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/WeldContainerControl.java
@@ -115,4 +115,28 @@ public class WeldContainerControl implements CdiContainer
         }
         return ctxCtrl;
     }
+
+    @Override
+    public ContextControl createContextControl()
+    {
+        BeanManager beanManager = getBeanManager();
+
+        if (beanManager == null)
+        {
+            LOG.warning("If the CDI-container was started by the environment, you can't use
this helper." +
+                    "Instead you can resolve ContextControl manually " +
+                    "(e.g. via BeanProvider.getContextualReference(ContextControl.class)
). " +
+                    "If the container wasn't started already, you have to use CdiContainer#boot
before.");
+
+            return null;
+        }
+        Set<Bean<?>> beans = beanManager.getBeans(ContextControl.class);
+        Bean<ContextControl> depCtxCtrlBean = (Bean<ContextControl>) beanManager.resolve(beans);
+
+        CreationalContext<ContextControl> depCtxCtrlCreationalContext = getBeanManager()
+                .createCreationalContext(ctxCtrlBean);
+
+        return (ContextControl)
+                getBeanManager().getReference(depCtxCtrlBean, ContextControl.class, depCtxCtrlCreationalContext);
+    }
 }


Mime
View raw message