cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r485543 - in /incubator/cxf/trunk/rt/core/src: main/java/org/apache/cxf/bus/spring/BusApplicationContext.java main/java/org/apache/cxf/bus/spring/SpringBusFactory.java test/java/org/apache/cxf/bus/spring/SpringBusFactoryTest.java
Date Mon, 11 Dec 2006 07:56:43 GMT
Author: ningjiang
Date: Sun Dec 10 23:56:42 2006
New Revision: 485543

URL: http://svn.apache.org/viewvc?view=rev&rev=485543
Log:
[CXF-146] Add Bus factory method that takes a URL
SpringBusFactory should be extended by
    createBus(URL url)
    createBus(URL url, boolean includeDefaults)  

Modified:
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusApplicationContext.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/SpringBusFactory.java
    incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/SpringBusFactoryTest.java

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusApplicationContext.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusApplicationContext.java?view=diff&rev=485543&r1=485542&r2=485543
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusApplicationContext.java
(original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusApplicationContext.java
Sun Dec 10 23:56:42 2006
@@ -21,6 +21,7 @@
 
 import java.io.IOException;
 import java.net.MalformedURLException;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -47,10 +48,15 @@
     
     private boolean includeDefaults;
     private String cfgFile;
+    private URL cfgFileURL;
     
     BusApplicationContext(String cf, boolean include) {
         this(cf, include, null);
     }
+    
+    BusApplicationContext(URL url, boolean include) {
+        this(url, include, null);
+    }
 
     BusApplicationContext(String cf, boolean include, ApplicationContext parent) {
         super((String[])null, parent);
@@ -58,6 +64,12 @@
         includeDefaults = include;
     }
     
+    BusApplicationContext(URL url, boolean include, ApplicationContext parent) {
+        super((String[])null, parent);
+        cfgFileURL = url;
+        includeDefaults = include;
+    }
+    
     @Override
     protected Resource[] getConfigResources() {
   
@@ -89,19 +101,29 @@
             LOG.log(Level.INFO, new Message("USER_CFG_FILE_NOT_FOUND_MSG", LOG, cfgFile).toString());
         }
         
-        String cfgFileUrl = System.getProperty(Configurer.USER_CFG_FILE_PROPERTY_URL);
-        if (null != cfgFileUrl) {
+        if (null != cfgFileURL) {
+            UrlResource ur = new UrlResource(cfgFileURL);
+            if (ur.exists()) {
+                resources.add(ur);
+            } else {
+                LOG.log(Level.INFO, 
+                        new Message("USER_CFG_FILE_URL_NOT_FOUND_MSG", LOG, cfgFileURL).toString());
+            }    
+        } 
+        
+        String sysCfgFileUrl = System.getProperty(Configurer.USER_CFG_FILE_PROPERTY_URL);
+        if (null != sysCfgFileUrl) {
             try {
-                UrlResource ur = new UrlResource(cfgFileUrl);
+                UrlResource ur = new UrlResource(sysCfgFileUrl);
                 if (ur.exists()) {
                     resources.add(ur);
                 } else {
                     LOG.log(Level.INFO, 
-                            new Message("USER_CFG_FILE_URL_NOT_FOUND_MSG", LOG, cfgFileUrl).toString());
+                            new Message("USER_CFG_FILE_URL_NOT_FOUND_MSG", LOG, sysCfgFileUrl).toString());
                 }            
             } catch (MalformedURLException e) {            
                 LOG.log(Level.WARNING, 
-                        new Message("USER_CFG_FILE_URL_ERROR_MSG", LOG, cfgFileUrl).toString());
+                        new Message("USER_CFG_FILE_URL_ERROR_MSG", LOG, sysCfgFileUrl).toString());
             }
         }
         

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/SpringBusFactory.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/SpringBusFactory.java?view=diff&rev=485543&r1=485542&r2=485543
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/SpringBusFactory.java
(original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/SpringBusFactory.java
Sun Dec 10 23:56:42 2006
@@ -19,6 +19,7 @@
 
 package org.apache.cxf.bus.spring;
 
+import java.net.URL;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -61,7 +62,7 @@
     }
     
     public Bus createBus() {
-        return createBus(null);
+        return createBus((String)null);
     }
     
     public Bus createBus(String cfgFile) {
@@ -77,6 +78,31 @@
         BusApplicationContext bac = null;
         try {      
             bac = new BusApplicationContext(cfgFile, includeDefaults, context);         
 
+        } catch (BeansException ex) {
+            LogUtils.log(LOG, Level.WARNING, "APP_CONTEXT_CREATION_FAILED_MSG", ex, (Object[])null);
+        }
+        
+        bac.refresh();
+        Bus bus = (Bus)bac.getBean(DEFAULT_BUS_ID);
+       
+        Configurer configurer = new ConfigurerImpl(bac);
+        bus.setExtension(configurer, Configurer.class);
+
+        return bus;
+    }
+    
+    public Bus createBus(URL url) {
+        boolean includeDefaults = true;
+        if (context != null) {
+            includeDefaults = !context.containsBean("cxf");
+        }
+        return createBus(url, includeDefaults);
+    }
+    
+    public Bus createBus(URL url, boolean includeDefaults) {
+        BusApplicationContext bac = null;
+        try {      
+            bac = new BusApplicationContext(url, includeDefaults, context);           
         } catch (BeansException ex) {
             LogUtils.log(LOG, Level.WARNING, "APP_CONTEXT_CREATION_FAILED_MSG", ex, (Object[])null);
         }

Modified: incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/SpringBusFactoryTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/SpringBusFactoryTest.java?view=diff&rev=485543&r1=485542&r2=485543
==============================================================================
--- incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/SpringBusFactoryTest.java
(original)
+++ incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/SpringBusFactoryTest.java
Sun Dec 10 23:56:42 2006
@@ -79,12 +79,18 @@
         checkCustomerConfiguration(bus);
     }
     
-    public void testCustomFileURL() {
+    public void testCustomFileURLFromSystemProperty() {
         URL cfgFileURL = this.getClass().getResource("resources/bus-overwrite.xml");    
   
         System.setProperty(Configurer.USER_CFG_FILE_PROPERTY_URL, cfgFileURL.toString());
-        Bus bus = new SpringBusFactory().createBus(null, true);
+        Bus bus = new SpringBusFactory().createBus((String)null, true);
         checkCustomerConfiguration(bus);
         System.clearProperty(Configurer.USER_CFG_FILE_PROPERTY_URL);
+    }
+    
+    public void testCustomFileURL() {
+        URL cfgFileURL = this.getClass().getResource("resources/bus-overwrite.xml");
+        Bus bus = new SpringBusFactory().createBus(cfgFileURL, true);
+        checkCustomerConfiguration(bus);
     }
     
     private void checkCustomerConfiguration(Bus bus) {



Mime
View raw message