myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject svn commit: r1296792 - in /myfaces/extensions/cdi/trunk: core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/provider/ test-modules/base-test-infrastructure-module/src/main/java/org/apache/myfaces/extensions/cdi/test/strategy/
Date Sun, 04 Mar 2012 12:52:36 GMT
Author: gpetracek
Date: Sun Mar  4 12:52:35 2012
New Revision: 1296792

URL: http://svn.apache.org/viewvc?rev=1296792&view=rev
Log:
EXTCDI-271 root-bean-manager support

Added:
    myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/provider/BeanManagerHolder.java
    myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/provider/RootBeanManagerHolder.java
Modified:
    myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/provider/BeanManagerProvider.java
    myfaces/extensions/cdi/trunk/test-modules/base-test-infrastructure-module/src/main/java/org/apache/myfaces/extensions/cdi/test/strategy/AbstractCdiAwareTestStrategy.java

Added: myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/provider/BeanManagerHolder.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/provider/BeanManagerHolder.java?rev=1296792&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/provider/BeanManagerHolder.java
(added)
+++ myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/provider/BeanManagerHolder.java
Sun Mar  4 12:52:35 2012
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.cdi.core.api.provider;
+
+import javax.enterprise.inject.Typed;
+import javax.enterprise.inject.spi.BeanManager;
+
+@Typed()
+class BeanManagerHolder
+{
+    private BeanManager beanManager;
+
+    BeanManagerHolder(BeanManager beanManager)
+    {
+        this.beanManager = beanManager;
+    }
+
+    BeanManager getBeanManager()
+    {
+        return beanManager;
+    }
+}

Modified: myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/provider/BeanManagerProvider.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/provider/BeanManagerProvider.java?rev=1296792&r1=1296791&r2=1296792&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/provider/BeanManagerProvider.java
(original)
+++ myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/provider/BeanManagerProvider.java
Sun Mar  4 12:52:35 2012
@@ -52,7 +52,7 @@ public class BeanManagerProvider impleme
 {
     private static BeanManagerProvider bmp = null;
 
-    private volatile Map<ClassLoader, BeanManager> bms = new ConcurrentHashMap<ClassLoader,
BeanManager>();
+    private volatile Map<ClassLoader, BeanManagerHolder> bms = new ConcurrentHashMap<ClassLoader,
BeanManagerHolder>();
 
     /**
      * Returns if the {@link BeanManagerProvider} has been initialized
@@ -96,17 +96,39 @@ public class BeanManagerProvider impleme
     {
         ClassLoader classLoader = ClassUtils.getClassLoader(null);
 
-        BeanManager result = bms.get(classLoader);
+        BeanManagerHolder resultHolder = bms.get(classLoader);
+        BeanManager result;
 
-        if (result == null)
+        if (resultHolder == null)
         {
             result = resolveBeanManagerViaJndi();
 
             if(result != null)
             {
-                bms.put(classLoader, result);
+                bms.put(classLoader, new RootBeanManagerHolder(result));
             }
         }
+        else
+        {
+            result = resultHolder.getBeanManager();
+
+            if (!(resultHolder instanceof RootBeanManagerHolder))
+            {
+                BeanManager jndiBeanManager = resolveBeanManagerViaJndi();
+
+                if (jndiBeanManager != null && /*same instance check:*/jndiBeanManager
!= result)
+                {
+                    setRootBeanManager(jndiBeanManager);
+
+                    result = jndiBeanManager;
+                }
+                else
+                {
+                    setRootBeanManager(result);
+                }
+            }
+        }
+
         return result;
     }
 
@@ -217,10 +239,26 @@ public class BeanManagerProvider impleme
      */
     public void setBeanManager(@Observes AfterBeanDiscovery afterBeanDiscovery, BeanManager
beanManager)
     {
+        setBeanManager(new BeanManagerHolder(beanManager));
+    }
+
+    public void setRootBeanManager(BeanManager beanManager)
+    {
+        setBeanManager(new RootBeanManagerHolder(beanManager));
+    }
+
+    private void setBeanManager(BeanManagerHolder beanManagerHolder)
+    {
         BeanManagerProvider bmpFirst = setBeanManagerProvider(this);
 
         ClassLoader cl = ClassUtils.getClassLoader(null);
-        bmpFirst.bms.put(cl, beanManager);
+
+        if (beanManagerHolder instanceof RootBeanManagerHolder ||
+                //the lat bm wins - as before, but don't replace a root-bmh with a normal
bmh
+                (!(bmpFirst.bms.get(cl) instanceof RootBeanManagerHolder)))
+        {
+            bmpFirst.bms.put(cl, beanManagerHolder);
+        }
 
         CodiStartupBroadcaster.broadcastStartup();
     }

Added: myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/provider/RootBeanManagerHolder.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/provider/RootBeanManagerHolder.java?rev=1296792&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/provider/RootBeanManagerHolder.java
(added)
+++ myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/provider/RootBeanManagerHolder.java
Sun Mar  4 12:52:35 2012
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.cdi.core.api.provider;
+
+import javax.enterprise.inject.Typed;
+import javax.enterprise.inject.spi.BeanManager;
+
+@Typed()
+class RootBeanManagerHolder extends BeanManagerHolder
+{
+    RootBeanManagerHolder(BeanManager beanManager)
+    {
+        super(beanManager);
+    }
+}

Modified: myfaces/extensions/cdi/trunk/test-modules/base-test-infrastructure-module/src/main/java/org/apache/myfaces/extensions/cdi/test/strategy/AbstractCdiAwareTestStrategy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/test-modules/base-test-infrastructure-module/src/main/java/org/apache/myfaces/extensions/cdi/test/strategy/AbstractCdiAwareTestStrategy.java?rev=1296792&r1=1296791&r2=1296792&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/test-modules/base-test-infrastructure-module/src/main/java/org/apache/myfaces/extensions/cdi/test/strategy/AbstractCdiAwareTestStrategy.java
(original)
+++ myfaces/extensions/cdi/trunk/test-modules/base-test-infrastructure-module/src/main/java/org/apache/myfaces/extensions/cdi/test/strategy/AbstractCdiAwareTestStrategy.java
Sun Mar  4 12:52:35 2012
@@ -18,6 +18,7 @@
  */
 package org.apache.myfaces.extensions.cdi.test.strategy;
 
+import org.apache.myfaces.extensions.cdi.core.api.provider.BeanManagerProvider;
 import org.apache.myfaces.extensions.cdi.test.TestContainerFactory;
 import org.apache.myfaces.extensions.cdi.test.spi.CdiTestContainer;
 
@@ -82,6 +83,7 @@ public abstract class AbstractCdiAwareTe
     //@After
     public void after()
     {
+        BeanManagerProvider.getInstance().cleanupStoredBeanManagerOnShutdown(null);
         this.testContainer.stopContexts();
         this.testContainer.stopContainer();
     }



Mime
View raw message