Author: ningjiang
Date: Mon Mar 18 05:42:25 2013
New Revision: 1457650
URL: http://svn.apache.org/r1457650
Log:
CXF-4870 fixed the osgi field issue when using SpringBusFactory to create the
bus
Modified:
cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/SpringBeanLocator.java
Modified:
cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/SpringBeanLocator.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/SpringBeanLocator.java?rev=1457650&r1=1457649&r2=1457650&view=diff
==============================================================================
---
cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/SpringBeanLocator.java
(original)
+++
cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/SpringBeanLocator.java
Mon Mar 18 05:42:25 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 {