Author: dkulp
Date: Tue Sep 6 15:54:23 2011
New Revision: 1165725
URL: http://svn.apache.org/viewvc?rev=1165725&view=rev
Log:
Remove requirment of importing cxf-extension-osgi to make it match how
blueprint works.
Modified:
cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/SpringBeanLocator.java
cxf/trunk/rt/transports/http/src/main/resources/META-INF/cxf/osgi/cxf-extension-osgi.xml
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=1165725&r1=1165724&r2=1165725&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
Tue Sep 6 15:54:23 2011
@@ -33,6 +33,7 @@ import java.util.Set;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.extension.ExtensionManagerImpl;
import org.apache.cxf.configuration.ConfiguredBeanLocator;
+import org.osgi.framework.ServiceReference;
import org.springframework.beans.Mergeable;
import org.springframework.beans.PropertyValue;
import org.springframework.beans.factory.config.BeanDefinition;
@@ -47,6 +48,7 @@ public class SpringBeanLocator implement
ApplicationContext context;
ConfiguredBeanLocator orig;
Set<String> passThroughs = new HashSet<String>();
+ boolean osgi = true;
public SpringBeanLocator(ApplicationContext ctx, Bus bus) {
context = ctx;
@@ -95,8 +97,33 @@ public class SpringBeanLocator implement
lst.add(context.getBean(n, type));
}
lst.addAll(orig.getBeansOfType(type));
+ if (lst.isEmpty()) {
+ tryOSGI(lst, type);
+ }
return lst;
}
+ private <T> void tryOSGI(Collection<T> lst, Class<T> type) {
+ if (!osgi) {
+ return;
+ }
+ try {
+ //use a little reflection to allow this to work without the
spring-dm jars
+ //for the non-osgi cases
+ Object bc =
context.getClass().getMethod("getBundleContext").invoke(context);
+ Object o = bc.getClass()
+ .getMethod("getServiceReference", String.class).invoke(bc,
type.getName());
+ if (o != null) {
+ o = bc.getClass().getMethod("getService",
ServiceReference.class).invoke(bc, o);
+ lst.add(type.cast(o));
+ }
+ } catch (NoSuchMethodException e) {
+ osgi = false;
+ //not using OSGi
+ } catch (Throwable e) {
+ //ignore
+ }
+ }
+
public <T> boolean loadBeansOfType(Class<T> type,
BeanLoaderListener<T> listener) {
Modified:
cxf/trunk/rt/transports/http/src/main/resources/META-INF/cxf/osgi/cxf-extension-osgi.xml
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/resources/META-INF/cxf/osgi/cxf-extension-osgi.xml?rev=1165725&r1=1165724&r2=1165725&view=diff
==============================================================================
---
cxf/trunk/rt/transports/http/src/main/resources/META-INF/cxf/osgi/cxf-extension-osgi.xml
(original)
+++
cxf/trunk/rt/transports/http/src/main/resources/META-INF/cxf/osgi/cxf-extension-osgi.xml
Tue Sep 6 15:54:23 2011
@@ -24,10 +24,8 @@
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/osgi
http://www.springframework.org/schema/osgi/spring-osgi.xsd">
- <osgi:reference id="osgiDestinationRegistry"
-
interface="org.apache.cxf.transport.http.DestinationRegistry" />
-
- <bean id="org.apache.cxf.transport.http.HTTPTransportFactory"
class="org.apache.cxf.transport.http.HTTPTransportFactory">
- <constructor-arg ref="osgiDestinationRegistry"/>
- </bean>
+ <bean id="osgiDestinationRegistry-import-not-needed"
+ class="org.apache.cxf.bus.spring.OldSpringSupport" lazy-init="false">
+ <constructor-arg value="cxf-extension-osgi.xml"/>
+ </bean>
</beans>