cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From andreasm...@apache.org
Subject svn commit: r450802 - in /incubator/cxf/trunk: api/src/main/java/org/apache/cxf/ api/src/test/java/org/apache/cxf/ rt/core/src/main/resources/META-INF/services/ rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spi/
Date Thu, 28 Sep 2006 10:59:18 GMT
Author: andreasmyth
Date: Thu Sep 28 03:59:17 2006
New Revision: 450802

URL: http://svn.apache.org/viewvc?view=rev&rev=450802
Log:
Part of [JIRA CXF-30]: Removed the dependency on a particular bus factory from JAX-WS ProviderImpl.

Added:
    incubator/cxf/trunk/api/src/main/java/org/apache/cxf/APIMessages.properties   (with props)
    incubator/cxf/trunk/api/src/main/java/org/apache/cxf/BusFactoryHelper.java   (with props)
    incubator/cxf/trunk/api/src/test/java/org/apache/cxf/BusFactoryHelperTest.java   (with
props)
    incubator/cxf/trunk/rt/core/src/main/resources/META-INF/services/
    incubator/cxf/trunk/rt/core/src/main/resources/META-INF/services/org.apache.cxf.bus.factory
Modified:
    incubator/cxf/trunk/api/src/main/java/org/apache/cxf/BusFactory.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spi/ProviderImpl.java

Added: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/APIMessages.properties
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/APIMessages.properties?view=auto&rev=450802
==============================================================================
--- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/APIMessages.properties (added)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/APIMessages.properties Thu Sep 28
03:59:17 2006
@@ -0,0 +1,2 @@
+FAILED_TO_DETERMINE_BUS_FACTORY_EXC = Failed to determine BusFactory implementation class
name.
+BUS_FACTORY_INSTANTIATION_EXC = Failed to instantiate bus factory.
\ No newline at end of file

Propchange: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/APIMessages.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/APIMessages.properties
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/APIMessages.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/BusFactory.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/BusFactory.java?view=diff&rev=450802&r1=450801&r2=450802
==============================================================================
--- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/BusFactory.java (original)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/BusFactory.java Thu Sep 28 03:59:17
2006
@@ -21,7 +21,29 @@
 
 public interface BusFactory {
     
+    String BUS_FACTORY_PROPERTY_NAME = "org.apache.cxf.bus.factory";
+    String DEFAULT_BUS_FACTORY = "org.apache.cxf.bus.CXFBusFactory";
+    
+    /** 
+     * Creates a new bus. 
+     * While concrete <code>BusFactory</code> may offer differently
+     * parametrized methods for creating a bus, all factories support
+     * this no-arg factory method.
+     *
+     * @return the newly created bus.
+     */
+    Bus createBus();
+    
+    /**
+     * Returns the default bus, creating it if necessary.
+     * 
+     * @return the default bus.
+     */
     Bus getDefaultBus();
     
-    void setDefaultBus(Bus bus);
+    /**
+     * Sets the default bus.
+     * @param bus the default bus.
+     */
+    void setDefaultBus(Bus bus);    
 }

Added: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/BusFactoryHelper.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/BusFactoryHelper.java?view=auto&rev=450802
==============================================================================
--- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/BusFactoryHelper.java (added)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/BusFactoryHelper.java Thu Sep 28
03:59:17 2006
@@ -0,0 +1,120 @@
+/**
+ * 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.cxf;
+
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.cxf.common.logging.LogUtils;
+
+public final class BusFactoryHelper {
+    private static final Logger LOG = LogUtils.getL7dLogger(BusFactoryHelper.class, "APIMessages");
+    private static BusFactory instance;
+    
+    /**
+     * Prevents instantiation.
+     *
+     */
+    private BusFactoryHelper() {
+    }
+    
+    public static BusFactory getInstance() {
+        if (null == instance) {
+            ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+            String className = getBusFactoryClass(null, classLoader);
+            
+            Class<? extends BusFactory> busFactoryClass;
+            try {
+                busFactoryClass = Class.forName(className, true, classLoader).asSubclass(BusFactory.class);
+                instance = busFactoryClass.newInstance();
+            } catch (Exception ex) {
+                LogUtils.log(LOG, Level.SEVERE, "BUS_FACTORY_INSTANTIATION_EXC", ex);
+            }
+        }
+        return instance;
+    }
+    
+    private static String getBusFactoryClass(Map<String, Object> properties, ClassLoader
classLoader) {
+        
+        String busFactoryClass = null;
+        
+        // check properties  
+        if (null != properties) {
+            busFactoryClass = (String)properties.get(BusFactory.BUS_FACTORY_PROPERTY_NAME);
+            if (isValidBusFactoryClass(busFactoryClass)) {
+                return busFactoryClass;
+            }
+        }
+        
+        // next check system properties
+        busFactoryClass = System.getProperty(BusFactory.BUS_FACTORY_PROPERTY_NAME);
+        if (isValidBusFactoryClass(busFactoryClass)) {
+            return busFactoryClass;
+        }
+    
+        try {
+            // next, check for the services stuff in the jar file
+            String serviceId = "META-INF/services/" + BusFactory.BUS_FACTORY_PROPERTY_NAME;
+            InputStream is = null;
+        
+            if (classLoader == null) {
+                classLoader = Thread.currentThread().getContextClassLoader();
+            }
+        
+            if (classLoader == null) {
+                is = ClassLoader.getSystemResourceAsStream(serviceId);
+            } else {
+                is = classLoader.getResourceAsStream(serviceId);
+            }
+            if (is != null) {
+                BufferedReader rd = new BufferedReader(new InputStreamReader(is, "UTF-8"));
+                busFactoryClass = rd.readLine();
+                rd.close();
+            }
+            if (isValidBusFactoryClass(busFactoryClass)) {
+                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);
+        } 
+        return busFactoryClass;
+    }
+    
+    private static boolean isValidBusFactoryClass(String busFactoryClassName) { 
+        return busFactoryClassName != null && !"".equals(busFactoryClassName);
+    }
+    
+    /**
+     * For test purposes only.
+     *
+     */
+    public static void reset() {
+        instance = null;
+    }
+    
+}

Propchange: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/BusFactoryHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/BusFactoryHelper.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/api/src/test/java/org/apache/cxf/BusFactoryHelperTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/test/java/org/apache/cxf/BusFactoryHelperTest.java?view=auto&rev=450802
==============================================================================
--- incubator/cxf/trunk/api/src/test/java/org/apache/cxf/BusFactoryHelperTest.java (added)
+++ incubator/cxf/trunk/api/src/test/java/org/apache/cxf/BusFactoryHelperTest.java Thu Sep
28 03:59:17 2006
@@ -0,0 +1,55 @@
+/**
+ * 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.cxf;
+
+import junit.framework.TestCase;
+
+
+
+public class BusFactoryHelperTest extends TestCase {
+    
+    public void tearDown() {
+        System.clearProperty(BusFactory.BUS_FACTORY_PROPERTY_NAME);        
+    }
+    
+    public void testGetInstance() {
+        BusFactory factory = BusFactoryHelper.getInstance();
+        assertNull(factory);
+        BusFactoryHelper.reset();
+        System.setProperty(BusFactory.BUS_FACTORY_PROPERTY_NAME, TestBusFactory.class.getName());
+        factory = BusFactoryHelper.getInstance();
+        assertTrue(factory instanceof TestBusFactory);
+    }
+    
+    
+    public static class TestBusFactory implements BusFactory {
+
+        public Bus createBus() {
+            return null;
+        }
+
+        public Bus getDefaultBus() {
+            return null;
+        }
+
+        public void setDefaultBus(Bus bus) {         
+        }
+    }
+}

Propchange: incubator/cxf/trunk/api/src/test/java/org/apache/cxf/BusFactoryHelperTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/api/src/test/java/org/apache/cxf/BusFactoryHelperTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/core/src/main/resources/META-INF/services/org.apache.cxf.bus.factory
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/resources/META-INF/services/org.apache.cxf.bus.factory?view=auto&rev=450802
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/resources/META-INF/services/org.apache.cxf.bus.factory
(added)
+++ incubator/cxf/trunk/rt/core/src/main/resources/META-INF/services/org.apache.cxf.bus.factory
Thu Sep 28 03:59:17 2006
@@ -0,0 +1 @@
+org.apache.cxf.bus.cxf.CXFBusFactory
\ No newline at end of file

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spi/ProviderImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spi/ProviderImpl.java?view=diff&rev=450802&r1=450801&r2=450802
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spi/ProviderImpl.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spi/ProviderImpl.java
Thu Sep 28 03:59:17 2006
@@ -28,7 +28,7 @@
 import javax.xml.ws.spi.ServiceDelegate;
 
 import org.apache.cxf.Bus;
-import org.apache.cxf.bus.cxf.CXFBusFactory;
+import org.apache.cxf.BusFactoryHelper;
 import org.apache.cxf.common.i18n.Message;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.jaxws.EndpointImpl;
@@ -44,7 +44,7 @@
     public ServiceDelegate createServiceDelegate(URL url,
                                                  QName qname,
                                                  Class cls) {
-        Bus bus = new CXFBusFactory().getDefaultBus();
+        Bus bus = BusFactoryHelper.getInstance().getDefaultBus();
         return new ServiceImpl(bus, url, qname, cls);
     }
 
@@ -53,7 +53,7 @@
 
         Endpoint ep = null;
         if (EndpointUtils.isValidImplementor(implementor)) {
-            Bus bus = new CXFBusFactory().getDefaultBus();
+            Bus bus = BusFactoryHelper.getInstance().getDefaultBus();
             ep = new EndpointImpl(bus, implementor, bindingId);
             return ep;
         } else {



Mime
View raw message