cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1005222 - in /cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus: CXFBusImpl.java extension/ExtensionManagerBus.java
Date Wed, 06 Oct 2010 20:05:13 GMT
Author: dkulp
Date: Wed Oct  6 20:05:13 2010
New Revision: 1005222

URL: http://svn.apache.org/viewvc?rev=1005222&view=rev
Log:
[CXF-2927] Create a ConfiguredBeanLocator if there isn't one to make
sure we don't get NPE's

Modified:
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/CXFBusImpl.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/ExtensionManagerBus.java

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/CXFBusImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/CXFBusImpl.java?rev=1005222&r1=1005221&r2=1005222&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/CXFBusImpl.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/CXFBusImpl.java Wed Oct  6 20:05:13
2010
@@ -20,6 +20,7 @@
 package org.apache.cxf.bus;
 
 import java.util.Collection;
+import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.CopyOnWriteArrayList;
@@ -90,6 +91,9 @@ public class CXFBusImpl extends Abstract
         Object obj = extensions.get(extensionType);
         if (obj == null) {
             ConfiguredBeanLocator loc = (ConfiguredBeanLocator)extensions.get(ConfiguredBeanLocator.class);
+            if (loc == null) {
+                loc = createConfiguredBeanLocator();
+            }
             if (loc != null) {
                 //force loading
                 Collection<?> objs = loc.getBeansOfType(extensionType);
@@ -107,6 +111,33 @@ public class CXFBusImpl extends Abstract
         return null;
     }
     
+    protected synchronized ConfiguredBeanLocator createConfiguredBeanLocator() {
+        ConfiguredBeanLocator loc = (ConfiguredBeanLocator)extensions.get(ConfiguredBeanLocator.class);
+        if (loc == null) {
+            loc = new ConfiguredBeanLocator() {
+                public List<String> getBeanNamesOfType(Class<?> type) {
+                    return null;
+                }
+                public <T> Collection<? extends T> getBeansOfType(Class<T>
type) {
+                    return null;
+                }
+                public <T> T getBeanOfType(String name, Class<T> type) {
+                    return null;
+                }
+                public <T> boolean loadBeansOfType(Class<T> type, BeanLoaderListener<T>
listener) {
+                    return false;
+                }
+                public boolean hasConfiguredPropertyValue(String beanName, 
+                                                          String propertyName,
+                                                          String value) {
+                    return false;
+                }
+            };
+            this.setExtension(loc, ConfiguredBeanLocator.class);
+        }
+        return loc;
+    }
+
     public <T> void setExtension(T extension, Class<T> extensionType) {
         extensions.put(extensionType, extension);
     }

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/ExtensionManagerBus.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/ExtensionManagerBus.java?rev=1005222&r1=1005221&r2=1005222&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/ExtensionManagerBus.java
(original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/ExtensionManagerBus.java
Wed Oct  6 20:05:13 2010
@@ -18,7 +18,10 @@
  */
 package org.apache.cxf.bus.extension;
 
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.cxf.binding.BindingFactory;
@@ -27,6 +30,7 @@ import org.apache.cxf.binding.BindingFac
 import org.apache.cxf.bus.BusState;
 import org.apache.cxf.bus.CXFBusImpl;
 import org.apache.cxf.buslifecycle.BusLifeCycleManager;
+import org.apache.cxf.configuration.ConfiguredBeanLocator;
 import org.apache.cxf.configuration.Configurer;
 import org.apache.cxf.configuration.NullConfigurer;
 import org.apache.cxf.resource.DefaultResourceManager;
@@ -52,7 +56,7 @@ public class ExtensionManagerBus extends
     
     public static final String BUS_PROPERTY_NAME = "bus";
     private static final String BUS_ID_PROPERTY_NAME = "org.apache.cxf.bus.id";
-    
+    private final ExtensionManagerImpl extensionManager;
     
     public ExtensionManagerBus(Map<Class, Object> e, Map<String, Object> properties)
{
         super(e);
@@ -88,11 +92,11 @@ public class ExtensionManagerBus extends
         
         extensions.put(ResourceManager.class, resourceManager);
 
-        ExtensionManagerImpl em = new ExtensionManagerImpl(new String[0],
-                                                           Thread.currentThread().getContextClassLoader(),
-                                                           extensions,
-                                                           resourceManager, 
-                                                           this);
+        extensionManager = new ExtensionManagerImpl(new String[0],
+                                                    Thread.currentThread().getContextClassLoader(),
+                                                    extensions,
+                                                    resourceManager, 
+                                                    this);
                                   
         setState(BusState.INITIAL);
         
@@ -104,33 +108,76 @@ public class ExtensionManagerBus extends
         DestinationFactoryManager dfm = this.getExtension(DestinationFactoryManager.class);
         if (null == dfm) {
             dfm = new DestinationFactoryManagerImpl(
-                new DeferredMap<DestinationFactory>(em, DestinationFactory.class),
+                new DeferredMap<DestinationFactory>(extensionManager,
+                        DestinationFactory.class),
                 this);
         }
 
         ConduitInitiatorManager cfm = this.getExtension(ConduitInitiatorManager.class);
         if (null == cfm) {
-            cfm = new ConduitInitiatorManagerImpl(new DeferredMap<ConduitInitiator>(em,

+            cfm = new ConduitInitiatorManagerImpl(new DeferredMap<ConduitInitiator>(extensionManager,

                 ConduitInitiator.class), this);
         }
         
         BindingFactoryManager bfm = this.getExtension(BindingFactoryManager.class);
         if (null == bfm) {
-            bfm = new BindingFactoryManagerImpl(new DeferredMap<BindingFactory>(em,
BindingFactory.class),
+            bfm = new BindingFactoryManagerImpl(new DeferredMap<BindingFactory>(extensionManager,
+                                                    BindingFactory.class),
                                                 this);
             extensions.put(BindingFactoryManager.class, bfm);
         }
-        em.load(new String[] {ExtensionManagerImpl.BUS_EXTENSION_RESOURCE,
-                              ExtensionManagerImpl.BUS_EXTENSION_RESOURCE_COMPAT});
+        extensionManager.load(new String[] {
+            ExtensionManagerImpl.BUS_EXTENSION_RESOURCE,
+            ExtensionManagerImpl.BUS_EXTENSION_RESOURCE_COMPAT});
         
         
-        this.setExtension(em, ExtensionManager.class);
+        this.setExtension(extensionManager, ExtensionManager.class);
     }
 
     public ExtensionManagerBus() {
         this(null, null);
     }
-    
+    protected synchronized ConfiguredBeanLocator createConfiguredBeanLocator() {
+        ConfiguredBeanLocator loc = (ConfiguredBeanLocator)extensions.get(ConfiguredBeanLocator.class);
+        if (loc == null) {
+            loc = new ConfiguredBeanLocator() {
+                public List<String> getBeanNamesOfType(Class<?> type) {
+                    return null;
+                }
+                public <T> Collection<? extends T> getBeansOfType(Class<T>
type) {
+                    extensionManager.activateAllByType(type);
+                    List<T> lst = new ArrayList<T>();
+                    for (Object o : extensions.values()) {
+                        if (type.isInstance(o)) {
+                            lst.add(type.cast(o));
+                        }
+                    }
+                    return lst;
+                }
+                public <T> T getBeanOfType(String name, Class<T> type) {
+                    T t = extensionManager.getExtension(name, type);
+                    if (t != null) {
+                        return t;
+                    }
+                    extensionManager.activateAllByType(type);
+                    return type.cast(extensions.get(type));
+                }
+                public <T> boolean loadBeansOfType(Class<T> type, BeanLoaderListener<T>
listener) {
+                    int s = extensions.size();
+                    extensionManager.activateAllByType(type);
+                    return s != extensions.size();
+                }
+                public boolean hasConfiguredPropertyValue(String beanName, 
+                                                          String propertyName,
+                                                          String value) {
+                    return false;
+                }
+            };
+            this.setExtension(loc, ConfiguredBeanLocator.class);
+        }
+        return loc;
+    }
+
     private String getBusId(Map<String, Object> properties) {
 
         String busId = null;



Mime
View raw message