Author: dkulp Date: Mon Mar 25 18:31:11 2013 New Revision: 1460813 URL: http://svn.apache.org/r1460813 Log: Merged revisions 1457957 via git cherry-pick from https://svn.apache.org/repos/asf/cxf/branches/2.7.x-fixes
........ r1457957 | dkulp | 2013-03-18 16:05:19 -0400 (Mon, 18 Mar 2013) | 11 lines Merged revisions 1457806 via git cherry-pick from https://svn.apache.org/repos/asf/cxf/trunk ........ r1457806 | dkulp | 2013-03-18 11:23:18 -0400 (Mon, 18 Mar 2013) | 3 lines [CXF-4870] Fix checkstyle issues Also fix issue of bundleContext not being registered as a Bus extension using the proper class. ........ ........ Modified: cxf/branches/2.6.x-fixes/rt/core/src/main/java/org/apache/cxf/bus/spring/SpringBeanLocator.java 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=1460813&r1=1460812&r2=1460813&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 25 18:31:11 2013 @@ -92,40 +92,39 @@ public class SpringBeanLocator implement } private void loadOSGIContext(Bus b) { - Object bundleContext = findBundleContext(context); + bundleContext = findBundleContext(context, b); if (bundleContext == null) { osgi = false; - } else { - if (b != null) { - @SuppressWarnings("unchecked") - Class<Object> cls = (Class<Object>)bundleContext.getClass(); - b.setExtension(bundleContext, cls); - } } } - private Object findBundleContext(ApplicationContext applicationContext) { + private Object findBundleContext(ApplicationContext applicationContext, Bus b) { 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(); + while (aContext != null && answer != null) { + answer = getBundleContext(aContext, b); + aContext = aContext.getParent(); } return answer; } - private Object getBundleContext(ApplicationContext applicationContext) { - Object bundleContext = null; + private Object getBundleContext(ApplicationContext applicationContext, Bus b) { 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) { + Object o = m.invoke(applicationContext); + if (o != null && b != null) { + @SuppressWarnings("unchecked") + Class<Object> cls = (Class<Object>)m.getReturnType(); + b.setExtension(o, cls); + } + return o; + } catch (Throwable t) { // do nothing here } - return bundleContext; + return null; } public <T> T getBeanOfType(String name, Class<T> type) {
