Author: ningjiang
Date: Mon Mar 18 06:12:18 2013
New Revision: 1457653
URL: http://svn.apache.org/r1457653
Log:
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.7.x-fixes/ (props changed)
cxf/branches/2.7.x-fixes/rt/core/src/main/java/org/apache/cxf/bus/spring/SpringBeanLocator.java
Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
Merged /cxf/trunk:r1457650
Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified:
cxf/branches/2.7.x-fixes/rt/core/src/main/java/org/apache/cxf/bus/spring/SpringBeanLocator.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/core/src/main/java/org/apache/cxf/bus/spring/SpringBeanLocator.java?rev=1457653&r1=1457652&r2=1457653&view=diff
==============================================================================
---
cxf/branches/2.7.x-fixes/rt/core/src/main/java/org/apache/cxf/bus/spring/SpringBeanLocator.java
(original)
+++
cxf/branches/2.7.x-fixes/rt/core/src/main/java/org/apache/cxf/bus/spring/SpringBeanLocator.java
Mon Mar 18 06:12:18 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 {