cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r1457656 - in /cxf/branches/2.6.x-fixes: ./ rt/core/src/main/java/org/apache/cxf/bus/spring/SpringBeanLocator.java
Date Mon, 18 Mar 2013 06:35:24 GMT
Author: ningjiang
Date: Mon Mar 18 06:35:24 2013
New Revision: 1457656

URL: http://svn.apache.org/r1457656
Log:
Merged revisions 1457653 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/branches/2.7.x-fixes

................
  r1457653 | ningjiang | 2013-03-18 14:12:18 +0800 (Mon, 18 Mar 2013) | 9 lines
  
  Merged revisions 1457650 via svnmerge from 
  https://svn.apache.org/repos/asf/cxf/trunk
  
  ........
    r1457650 | ningjiang | 2013-03-18 13:42:25 +0800 (Mon, 18 Mar 2013) | 1 line
    
    CXF-4870 fixed the osgi field issue when using SpringBusFactory to create the bus
  ........
................

Modified:
    cxf/branches/2.6.x-fixes/   (props changed)
    cxf/branches/2.6.x-fixes/rt/core/src/main/java/org/apache/cxf/bus/spring/SpringBeanLocator.java

Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/branches/2.7.x-fixes:r1457653
  Merged /cxf/trunk:r1457650

Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.6.x-fixes/rt/core/src/main/java/org/apache/cxf/bus/spring/SpringBeanLocator.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/core/src/main/java/org/apache/cxf/bus/spring/SpringBeanLocator.java?rev=1457656&r1=1457655&r2=1457656&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/core/src/main/java/org/apache/cxf/bus/spring/SpringBeanLocator.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/core/src/main/java/org/apache/cxf/bus/spring/SpringBeanLocator.java
Mon Mar 18 06:35:24 2013
@@ -88,27 +88,46 @@ public class SpringBeanLocator implement
                 ((ExtensionManagerImpl)orig).removeBeansOfNames(names);
             }
         }
-        
         loadOSGIContext(bus);
     }
 
     private void loadOSGIContext(Bus b) {
-        try {
-            //use a little reflection to allow this to work without the spring-dm jars
-            //for the non-osgi cases
-            Method m = context.getClass().getMethod("getBundleContext");
-            bundleContext = m.invoke(context);
+        Object bundleContext = findBundleContext(context);
+        if (bundleContext == null) {
+            osgi = false;
+        } else {
             if (b != null) {
                 @SuppressWarnings("unchecked")
-                Class<Object> cls = (Class<Object>)m.getReturnType();
+                Class<Object> cls = (Class<Object>)bundleContext.getClass();
                 b.setExtension(bundleContext, cls);
             }
-        } catch (Throwable t) {
-            //ignore
-            osgi = false;
         }
     }
     
+    private Object findBundleContext(ApplicationContext applicationContext) {
+        Object answer = null;
+        ApplicationContext aContext = applicationContext;
+        // try to find out the bundleContext by going through the parent context
+        while(aContext != null || answer != null) {
+           answer = getBundleContext(aContext);
+           aContext = aContext.getParent();
+        }
+        return answer;
+    }
+    
+    private Object getBundleContext(ApplicationContext applicationContext) {
+        Object bundleContext = null;
+        try {
+            //use a little reflection to allow this to work without the spring-dm jars
+            //for the non-osgi cases
+            Method m = applicationContext.getClass().getMethod("getBundleContext");
+            bundleContext = m.invoke(applicationContext);
+        } catch(Throwable t) {
+            // do nothing here
+        }
+        return bundleContext;
+    }
+    
     public <T> T getBeanOfType(String name, Class<T> type) {
         T t = null;
         try {



Mime
View raw message