summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/implementation-osgi-runtime
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-10-30 22:10:11 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-10-30 22:10:11 +0000
commitef25a099e9ea2064b9523ec33a15f114ee52ce45 (patch)
tree8bba02f2ca100c9331fb24d018293ae10cc6395c /java/sca/modules/implementation-osgi-runtime
parentd058702bea1602cdb0f4a7887419c0db1104a0a9 (diff)
Propagate osgi properties for OSGi remote services
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@831468 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/implementation-osgi-runtime')
-rw-r--r--java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java33
-rw-r--r--java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProviderFactory.java16
2 files changed, 34 insertions, 15 deletions
diff --git a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java
index 7b5b5f2ea1..1cf17c6356 100644
--- a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java
+++ b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java
@@ -37,6 +37,7 @@ import org.apache.tuscany.sca.assembly.Extensible;
import org.apache.tuscany.sca.core.invocation.ProxyFactory;
import org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint;
import org.apache.tuscany.sca.implementation.osgi.OSGiImplementation;
+import org.apache.tuscany.sca.implementation.osgi.OSGiImplementationFactory;
import org.apache.tuscany.sca.implementation.osgi.OSGiProperty;
import org.apache.tuscany.sca.interfacedef.InterfaceContract;
import org.apache.tuscany.sca.interfacedef.Operation;
@@ -65,12 +66,15 @@ public class OSGiImplementationProvider implements ImplementationProvider {
private Bundle osgiBundle;
private OSGiImplementation implementation;
private List<ServiceRegistration> registrations = new ArrayList<ServiceRegistration>();
+ private OSGiImplementationFactory implementationFactory;
public OSGiImplementationProvider(RuntimeComponent component,
OSGiImplementation impl,
- ProxyFactoryExtensionPoint proxyFactoryExtensionPoint) throws BundleException {
+ ProxyFactoryExtensionPoint proxyFactoryExtensionPoint,
+ OSGiImplementationFactory implementationFactory) throws BundleException {
this.component = component;
this.proxyFactoryExtensionPoint = proxyFactoryExtensionPoint;
+ this.implementationFactory = implementationFactory;
this.implementation = impl;
this.osgiBundle = impl.getBundle();
}
@@ -123,6 +127,14 @@ public class OSGiImplementationProvider implements ImplementationProvider {
registrations.add(registration);
}
}
+
+ // Set the OSGi service reference properties into the SCA service
+ for (ComponentService service : component.getServices()) {
+ ServiceReference serviceReference = getServiceReference(osgiBundle.getBundleContext(), service);
+ if (serviceReference != null) {
+ service.getExtensions().addAll(implementationFactory.createOSGiProperties(serviceReference));
+ }
+ }
}
public void stop() {
@@ -165,24 +177,29 @@ public class OSGiImplementationProvider implements ImplementationProvider {
}
protected Object getOSGiService(ComponentService service) {
+ BundleContext bundleContext = osgiBundle.getBundleContext();
+ ServiceReference ref = getServiceReference(bundleContext, service);
+ if (ref != null) {
+ Object instance = bundleContext.getService(ref);
+ return instance;
+ } else {
+ return null;
+ }
+ }
+
+ private ServiceReference getServiceReference(BundleContext bundleContext, ComponentService service) {
JavaInterface javaInterface = (JavaInterface)service.getInterfaceContract().getInterface();
// String filter = getOSGiFilter(provider.getOSGiProperties(service));
// FIXME: What is the filter?
String filter = "(!(" + SERVICE_IMPORTED + "=*))";
// "(sca.service=" + component.getURI() + "#service-name\\(" + service.getName() + "\\))";
- BundleContext bundleContext = osgiBundle.getBundleContext();
ServiceReference ref;
try {
ref = bundleContext.getServiceReferences(javaInterface.getName(), filter)[0];
} catch (InvalidSyntaxException e) {
throw new ServiceRuntimeException(e);
}
- if (ref != null) {
- Object instance = bundleContext.getService(ref);
- return instance;
- } else {
- return null;
- }
+ return ref;
}
RuntimeComponent getComponent() {
diff --git a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProviderFactory.java b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProviderFactory.java
index 0e4a3ef995..11b29de248 100644
--- a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProviderFactory.java
+++ b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProviderFactory.java
@@ -19,8 +19,10 @@
package org.apache.tuscany.sca.implementation.osgi.runtime;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
import org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint;
import org.apache.tuscany.sca.implementation.osgi.OSGiImplementation;
+import org.apache.tuscany.sca.implementation.osgi.OSGiImplementationFactory;
import org.apache.tuscany.sca.provider.ImplementationProvider;
import org.apache.tuscany.sca.provider.ImplementationProviderFactory;
import org.apache.tuscany.sca.runtime.RuntimeComponent;
@@ -32,20 +34,20 @@ import org.osgi.framework.BundleException;
* @version $Rev$ $Date$
*/
public class OSGiImplementationProviderFactory implements ImplementationProviderFactory<OSGiImplementation> {
-
+ private OSGiImplementationFactory implementationFactory;
private ProxyFactoryExtensionPoint proxyFactoryExtensionPoint;
- public OSGiImplementationProviderFactory(ExtensionPointRegistry extensionPoints) {
- proxyFactoryExtensionPoint = extensionPoints.getExtensionPoint(ProxyFactoryExtensionPoint.class);
+ public OSGiImplementationProviderFactory(ExtensionPointRegistry registry) {
+ proxyFactoryExtensionPoint = registry.getExtensionPoint(ProxyFactoryExtensionPoint.class);
+ FactoryExtensionPoint factoryExtensionPoint = registry.getExtensionPoint(FactoryExtensionPoint.class);
+ this.implementationFactory = factoryExtensionPoint.getFactory(OSGiImplementationFactory.class);
}
public ImplementationProvider createImplementationProvider(RuntimeComponent component,
OSGiImplementation implementation) {
-
try {
-
- return new OSGiImplementationProvider(component, implementation, proxyFactoryExtensionPoint);
-
+ return new OSGiImplementationProvider(component, implementation, proxyFactoryExtensionPoint,
+ implementationFactory);
} catch (BundleException e) {
throw new RuntimeException(e);
}