cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r666686 - in /cxf/trunk: api/src/main/java/org/apache/cxf/BusFactory.java rt/core/src/main/java/org/apache/cxf/bus/spring/SpringBusFactory.java
Date Wed, 11 Jun 2008 14:48:57 GMT
Author: sergeyb
Date: Wed Jun 11 07:48:57 2008
New Revision: 666686

URL: http://svn.apache.org/viewvc?rev=666686&view=rev
Log:
Updating SpringBusFactory and BusFactory to try their own loaders in case of failures

Modified:
    cxf/trunk/api/src/main/java/org/apache/cxf/BusFactory.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/SpringBusFactory.java

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/BusFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/BusFactory.java?rev=666686&r1=666685&r2=666686&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/BusFactory.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/BusFactory.java Wed Jun 11 07:48:57 2008
@@ -149,10 +149,17 @@
      */
     public static BusFactory newInstance(String className) {
         BusFactory instance = null;
-        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
         if (className == null) {
-            className = getBusFactoryClass(classLoader);
+            ClassLoader loader = Thread.currentThread().getContextClassLoader();
+            className = getBusFactoryClass(loader);
+            if (className == null && loader != BusFactory.class.getClassLoader())
{
+                className = getBusFactoryClass(BusFactory.class.getClassLoader()); 
+            }
+        }
+        if (className == null) {
+            className = BusFactory.DEFAULT_BUS_FACTORY;
         }
+        
         Class<? extends BusFactory> busFactoryClass;
         try {
             busFactoryClass = 
@@ -230,10 +237,8 @@
                     return busFactoryClass;
                 }
             }
-
-            // otherwise use default  
-            busFactoryClass = BusFactory.DEFAULT_BUS_FACTORY;
             return busFactoryClass;
+
         } catch (Exception ex) {
             LogUtils.log(LOG, Level.SEVERE, "FAILED_TO_DETERMINE_BUS_FACTORY_EXC", ex);
         } 

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/SpringBusFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/SpringBusFactory.java?rev=666686&r1=666685&r2=666686&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/SpringBusFactory.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/SpringBusFactory.java Wed Jun
11 07:48:57 2008
@@ -64,6 +64,7 @@
     public Bus createBus(String cfgFile) {
         return createBus(cfgFile, defaultBusNotExists());
     }
+    
     public Bus createBus(String cfgFiles[]) {
         return createBus(cfgFiles, defaultBusNotExists());
     }
@@ -71,7 +72,6 @@
     private Bus finishCreatingBus(BusApplicationContext bac) {
         final Bus bus = (Bus)bac.getBean(Bus.DEFAULT_BUS_ID);
 
-        //bus.setExtension(new ConfigurerImpl(bac), Configurer.class);
         bus.setExtension(bac, BusApplicationContext.class);
 
         possiblySetDefaultBus(bus);
@@ -88,15 +88,35 @@
         }
         return createBus(new String[] {cfgFile}, includeDefaults);
     }    
+    
     public Bus createBus(String cfgFiles[], boolean includeDefaults) {
         try {      
-            return finishCreatingBus(new BusApplicationContext(cfgFiles, includeDefaults,
context));
+            return finishCreatingBus(createApplicationContext(cfgFiles, includeDefaults));
         } catch (BeansException ex) {
             LogUtils.log(LOG, Level.WARNING, "APP_CONTEXT_CREATION_FAILED_MSG", ex, (Object[])null);
             throw new RuntimeException(ex);
         }
     }
     
+    private BusApplicationContext createApplicationContext(String cfgFiles[], boolean includeDefaults)
{
+        try {      
+            return new BusApplicationContext(cfgFiles, includeDefaults, context);
+        } catch (BeansException ex) {
+            ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
+            if (contextLoader != BusApplicationContext.class.getClassLoader()) {
+                Thread.currentThread().setContextClassLoader(
+                    BusApplicationContext.class.getClassLoader());
+                try {
+                    return new BusApplicationContext(cfgFiles, includeDefaults, context);
       
+                } finally {
+                    Thread.currentThread().setContextClassLoader(contextLoader);
+                }
+            } else {
+                throw ex;
+            }
+        }
+    }
+    
     public Bus createBus(URL url) {
         return createBus(url, defaultBusNotExists());
     }
@@ -110,6 +130,7 @@
         }
         return createBus(new URL[] {url}, includeDefaults);
     }
+    
     public Bus createBus(URL[] urls, boolean includeDefaults) {
         try {      
             return finishCreatingBus(new BusApplicationContext(urls, includeDefaults, context));



Mime
View raw message