[weld-commits] Weld SVN: r6154 - in extensions/trunk/src/main: resources/META-INF/services and 1 other directory.

weld-commits at lists.jboss.org weld-commits at lists.jboss.org
Sat Apr 24 17:52:51 EDT 2010


Author: nickarls
Date: 2010-04-24 17:52:50 -0400 (Sat, 24 Apr 2010)
New Revision: 6154

Added:
   extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/WeldBeanManagerProvider.java
Modified:
   extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/BeanManagerAware.java
   extensions/trunk/src/main/resources/META-INF/services/org.jboss.weld.extensions.beanManager.BeanManagerProvider
Log:
BeanManagerAware for faces module
Fixed precedence
Lazy loading of providers
Weld-specific provider (Pete, can we have this in weld-extensions?)

Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/BeanManagerAware.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/BeanManagerAware.java	2010-04-24 00:06:56 UTC (rev 6153)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/BeanManagerAware.java	2010-04-24 21:52:50 UTC (rev 6154)
@@ -51,26 +51,21 @@
 
    private final List<BeanManagerProvider> beanManagerProviders = new ArrayList<BeanManagerProvider>();
 
-   public BeanManagerAware() 
-   {
-      loadServices();
-      Collections.sort(beanManagerProviders, new ProviderWeightSorter());   
-   }
-   
    private void loadServices()
    {
+      beanManagerProviders.clear();
       Iterator<BeanManagerProvider> providers = DefaultServiceLoader.load(BeanManagerProvider.class).iterator();
       while (providers.hasNext())
       {
          beanManagerProviders.add(providers.next());
       }
    }
-   
+
    private class ProviderWeightSorter implements Comparator<BeanManagerProvider>
    {
       public int compare(BeanManagerProvider provider1, BeanManagerProvider provider2)
       {
-         return Integer.valueOf(provider1.getPrecedence()).compareTo(Integer.valueOf(provider2.getPrecedence()));
+         return -1 * Integer.valueOf(provider1.getPrecedence()).compareTo(Integer.valueOf(provider2.getPrecedence()));
       }
    }
 
@@ -78,19 +73,42 @@
    {
       if (beanManager == null)
       {
+         if (beanManagerProviders.isEmpty())
+         {
+            loadServices();
+            Collections.sort(beanManagerProviders, new ProviderWeightSorter());
+         }
          beanManager = lookupBeanManager();
       }
       if (beanManager == null)
       {
-         throw new IllegalStateException("Could not locate a BeanManager from the providers " + beanManagerProviders);
+         throw new IllegalStateException("Could not locate a BeanManager from the providers " + providersToString());
       }
       return beanManager;
    }
 
+   private String providersToString()
+   {
+      StringBuffer out = new StringBuffer();
+      int i = 0;
+      for (BeanManagerProvider provider : beanManagerProviders)
+      {
+         if (i > 0)
+         {
+            out.append(", ");
+         }
+         out.append(provider.getClass().getName());
+         out.append("(");
+         out.append(provider.getPrecedence());
+         out.append(")");
+         i++;
+      }
+      return out.toString();
+   }
+
    private BeanManager lookupBeanManager()
    {
       BeanManager beanManager = null;
-
       for (BeanManagerProvider provider : beanManagerProviders)
       {
          beanManager = provider.getBeanManager();

Added: extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/WeldBeanManagerProvider.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/WeldBeanManagerProvider.java	                        (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/beanManager/WeldBeanManagerProvider.java	2010-04-24 21:52:50 UTC (rev 6154)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.weld.extensions.beanManager;
+
+import javax.enterprise.inject.spi.BeanManager;
+
+import org.jboss.weld.Container;
+
+/**
+ * A Weld-specific BeanManager provider
+ * 
+ * @author Nicklas Karlsson
+ *
+ */
+public class WeldBeanManagerProvider implements BeanManagerProvider
+{
+
+   public BeanManager getBeanManager()
+   {
+      return Container.instance().deploymentManager();
+   }
+
+   public int getPrecedence()
+   {
+      return 30;
+   }
+}

Modified: extensions/trunk/src/main/resources/META-INF/services/org.jboss.weld.extensions.beanManager.BeanManagerProvider
===================================================================
--- extensions/trunk/src/main/resources/META-INF/services/org.jboss.weld.extensions.beanManager.BeanManagerProvider	2010-04-24 00:06:56 UTC (rev 6153)
+++ extensions/trunk/src/main/resources/META-INF/services/org.jboss.weld.extensions.beanManager.BeanManagerProvider	2010-04-24 21:52:50 UTC (rev 6154)
@@ -1,2 +1,3 @@
 org.jboss.weld.extensions.beanManager.DefaultJndiBeanManagerProvider
 org.jboss.weld.extensions.beanManager.JBossJndiBeanManagerProvider
+org.jboss.weld.extensions.beanManager.WeldBeanManagerProvider



More information about the weld-commits mailing list