summaryrefslogtreecommitdiffstats
path: root/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/AbstractOSGiServiceHandler.java7
-rw-r--r--branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointHelper.java28
-rw-r--r--branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointIntrospector.java256
-rw-r--r--branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiHelper.java69
-rw-r--r--branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceExporter.java21
-rw-r--r--branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceImporter.java3
-rw-r--r--branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/RemoteServiceAdminImpl.java5
7 files changed, 235 insertions, 154 deletions
diff --git a/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/AbstractOSGiServiceHandler.java b/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/AbstractOSGiServiceHandler.java
index a043e33c32..7c9cf8ef6e 100644
--- a/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/AbstractOSGiServiceHandler.java
+++ b/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/AbstractOSGiServiceHandler.java
@@ -37,6 +37,7 @@ public class AbstractOSGiServiceHandler implements LifeCycleListener {
protected EndpointIntrospector introspector;
protected ServiceTracker discoveryTracker;
protected String domainRegistry;
+ protected String domainURI;
/**
* @param context
@@ -45,6 +46,8 @@ public class AbstractOSGiServiceHandler implements LifeCycleListener {
*/
protected AbstractOSGiServiceHandler(BundleContext context) {
this.context = context;
+ this.domainRegistry = context.getProperty("org.osgi.sca.domain.registry");
+ this.domainURI = context.getProperty("org.osgi.sca.domain.uri");
}
protected ExtensionPointRegistry getExtensionPointRegistry() {
@@ -87,4 +90,8 @@ public class AbstractOSGiServiceHandler implements LifeCycleListener {
this.domainRegistry = domainRegistry;
}
+ public void setDomainURI(String domainURI) {
+ this.domainURI = domainURI;
+ }
+
}
diff --git a/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointHelper.java b/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointHelper.java
index 8ac949ccc5..d50d1ef9f9 100644
--- a/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointHelper.java
+++ b/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointHelper.java
@@ -23,9 +23,9 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.UUID;
import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.implementation.osgi.OSGiProperty;
import org.apache.tuscany.sca.interfacedef.Interface;
import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
import org.apache.tuscany.sca.osgi.remoteserviceadmin.EndpointDescription;
@@ -37,7 +37,6 @@ import org.osgi.framework.Constants;
* Implementation of {@link EndpointDescription}
*/
public class EndpointHelper {
- private final static String FRAMEWORK_UUID = "org.osgi.framework.uuid";
private EndpointHelper() {
}
@@ -54,11 +53,21 @@ public class EndpointHelper {
private static Map<String, Object> getProperties(BundleContext bundleContext, Endpoint endpoint) {
Map<String, Object> props = new HashMap<String, Object>();
- String uuid = getFrameworkUUID(bundleContext);
+ if (!endpoint.isRemote()) {
+ String uuid = OSGiHelper.getFrameworkUUID(bundleContext);
+ props.put(RemoteConstants.SERVICE_REMOTE_FRAMEWORK_UUID, uuid);
+ }
+
+ for (Object ext : endpoint.getService().getExtensions()) {
+ if (ext instanceof OSGiProperty) {
+ OSGiProperty prop = (OSGiProperty)ext;
+ props.put(prop.getName(), prop.getStringValue());
+ }
+ }
- props.put(RemoteConstants.SERVICE_REMOTE_FRAMEWORK_UUID, uuid);
+ props.put(RemoteConstants.SERVICE_REMOTE_ID, props.get(Constants.SERVICE_ID));
props.put(RemoteConstants.SERVICE_REMOTE_URI, endpoint.getURI());
- props.put(RemoteConstants.SERVICE_REMOTE_ID, String.valueOf(System.currentTimeMillis()));
+ // FIXME: [rfeng] How to pass in the remote service id from the endpoint XML
props.put(RemoteConstants.SERVICE_EXPORTED_CONFIGS, new String[] {"org.osgi.sca"});
props.put(Endpoint.class.getName(), endpoint);
List<String> interfaces = getInterfaces(endpoint);
@@ -66,15 +75,6 @@ public class EndpointHelper {
return props;
}
- public synchronized static String getFrameworkUUID(BundleContext bundleContext) {
- String uuid = System.getProperty(FRAMEWORK_UUID);
- if (uuid == null) {
- uuid = UUID.randomUUID().toString();
- }
- System.setProperty(FRAMEWORK_UUID, uuid);
- return uuid;
- }
-
public static Endpoint getEndpoint(EndpointDescription endpointDescription) {
return (Endpoint)endpointDescription.getProperties().get(Endpoint.class.getName());
}
diff --git a/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointIntrospector.java b/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointIntrospector.java
index c88632407c..a649dac357 100644
--- a/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointIntrospector.java
+++ b/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointIntrospector.java
@@ -24,6 +24,7 @@ import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.SCA_BINDIN
import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.SERVICE_EXPORTED_INTENTS;
import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.SERVICE_EXPORTED_INTENTS_EXTRA;
import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.SERVICE_EXPORTED_INTERFACES;
+import static org.apache.tuscany.sca.osgi.remoteserviceadmin.impl.OSGiHelper.getStringArray;
import static org.osgi.framework.Constants.OBJECTCLASS;
import static org.osgi.framework.Constants.SERVICE_ID;
@@ -55,17 +56,17 @@ import org.apache.tuscany.sca.assembly.Service;
import org.apache.tuscany.sca.contribution.Contribution;
import org.apache.tuscany.sca.contribution.ContributionFactory;
import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
+import org.apache.tuscany.sca.contribution.processor.ContributionResolveException;
import org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver;
import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
-import org.apache.tuscany.sca.core.UtilityExtensionPoint;
-import org.apache.tuscany.sca.deployment.Deployer;
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.implementation.osgi.SCAConfig;
+import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException;
import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract;
import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
@@ -86,16 +87,17 @@ import org.osgi.util.tracker.ServiceTracker;
* implementation.osgi
*/
public class EndpointIntrospector {
- private BundleContext context;
+ // private BundleContext context;
private AssemblyFactory assemblyFactory;
private ContributionFactory contributionFactory;
private OSGiImplementationFactory implementationFactory;
private PolicyFactory policyFactory;
- private ExtensionPointRegistry registry;
+ // private ExtensionPointRegistry registry;
private FactoryExtensionPoint factories;
private ModelResolverExtensionPoint modelResolvers;
+ // private StAXArtifactProcessor<Composite> compositeProcessor;
private JavaInterfaceFactory javaInterfaceFactory;
- private Deployer deployer;
+ // private Deployer deployer;
private ServiceTracker discoveryTracker;
/**
@@ -124,17 +126,19 @@ public class EndpointIntrospector {
*/
public EndpointIntrospector(BundleContext context, ExtensionPointRegistry registry, ServiceTracker discoveryTracker) {
super();
- this.context = context;
+ // this.context = context;
this.discoveryTracker = discoveryTracker;
- this.registry = registry;
+ // this.registry = registry;
this.factories = registry.getExtensionPoint(FactoryExtensionPoint.class);
this.modelResolvers = registry.getExtensionPoint(ModelResolverExtensionPoint.class);
+// this.compositeProcessor =
+// registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class).getProcessor(Composite.class);
this.assemblyFactory = factories.getFactory(AssemblyFactory.class);
this.contributionFactory = factories.getFactory(ContributionFactory.class);
this.policyFactory = factories.getFactory(PolicyFactory.class);
this.implementationFactory = factories.getFactory(OSGiImplementationFactory.class);
this.javaInterfaceFactory = factories.getFactory(JavaInterfaceFactory.class);
- this.deployer = registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(Deployer.class);
+ // this.deployer = registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(Deployer.class);
}
private Intent getIntent(String intent) {
@@ -232,54 +236,79 @@ public class EndpointIntrospector {
* @throws Exception
*/
public Contribution introspect(ServiceReference reference, Map<String, Object> props) throws Exception {
+ Bundle bundle = reference.getBundle();
Map<String, Object> properties = getProperties(reference, props);
+ Long sid = (Long)reference.getProperty(SERVICE_ID);
- OSGiProperty serviceID = implementationFactory.createOSGiProperty();
- serviceID.setName(SERVICE_ID);
- // The service.id is Long
- serviceID.setValue(String.valueOf(reference.getProperty(SERVICE_ID)));
+ String[] requiredIntents = getStringArray(properties.get(SERVICE_EXPORTED_INTENTS));
+ List<Intent> intents = getIntents(requiredIntents);
+ String[] requiredIntentsExtra = getStringArray(properties.get(SERVICE_EXPORTED_INTENTS_EXTRA));
+ List<Intent> extraIntents = getIntents(requiredIntentsExtra);
+ Set<Intent> allIntents = new HashSet<Intent>(intents);
+ allIntents.addAll(extraIntents);
+
+ String[] bindingNames = getStringArray(properties.get(SCA_BINDINGS));
+ Collection<Binding> bindings = loadBindings(bindingNames);
+
+ String[] remoteInterfaces = getStringArray(reference.getProperty(SERVICE_EXPORTED_INTERFACES));
+ if (remoteInterfaces == null || remoteInterfaces.length > 0 && "*".equals(remoteInterfaces[0])) {
+ remoteInterfaces = getStringArray(reference.getProperty(OBJECTCLASS));
+ } else {
+ remoteInterfaces = parse(remoteInterfaces);
+ String[] objectClasses = getStringArray(reference.getProperty(OBJECTCLASS));
+ Set<String> objectClassSet = new HashSet<String>(Arrays.asList(objectClasses));
+ if (!objectClassSet.containsAll(Arrays.asList(remoteInterfaces))) {
+ throw new IllegalArgumentException(
+ "The exported interfaces are not a subset of the types" + " listed in the objectClass service property from the Service Reference");
+ }
+ }
+
+ Contribution contribution = generateContribution(bundle, sid, remoteInterfaces, bindings, allIntents);
+ return contribution;
+ }
+ /**
+ * Generate a contribution that contains the composite for the exported service
+ * @param bundle The OSGi bundle
+ * @param sid The service id
+ * @param remoteInterfaces
+ * @param bindings
+ * @param allIntents
+ * @return
+ * @throws ClassNotFoundException
+ * @throws InvalidInterfaceException
+ */
+ private Contribution generateContribution(Bundle bundle,
+ Long sid,
+ String[] remoteInterfaces,
+ Collection<Binding> bindings,
+ Set<Intent> allIntents) throws ClassNotFoundException,
+ InvalidInterfaceException {
String id = "osgi.service." + UUID.randomUUID();
Composite composite = assemblyFactory.createComposite();
composite.setName(new QName(SCA11_TUSCANY_NS, id));
Component component = assemblyFactory.createComponent();
component.setName(id);
- component.setAutowire(Boolean.TRUE);
composite.getComponents().add(component);
- Bundle bundle = reference.getBundle();
OSGiImplementation implementation = implementationFactory.createOSGiImplementation();
implementation.setBundle(bundle);
component.setImplementation(implementation);
implementation.setUnresolved(false);
- String[] remoteInterfaces = getStrings(reference.getProperty(SERVICE_EXPORTED_INTERFACES));
- if (remoteInterfaces == null || remoteInterfaces.length > 0 && "*".equals(remoteInterfaces[0])) {
- remoteInterfaces = getStrings(reference.getProperty(OBJECTCLASS));
- } else {
- remoteInterfaces = parse(remoteInterfaces);
- String[] objectClasses = getStrings(reference.getProperty(OBJECTCLASS));
- Set<String> objectClassSet = new HashSet<String>(Arrays.asList(objectClasses));
- if (!objectClassSet.containsAll(Arrays.asList(remoteInterfaces))) {
- throw new IllegalArgumentException(
- "The exported interfaces are not a subset of the types" + " listed in the objectClass service property from the Service Reference");
- }
- }
+ OSGiProperty serviceID = implementationFactory.createOSGiProperty();
+ serviceID.setName(SERVICE_ID);
+ // The service.id is Long
+ serviceID.setValue(String.valueOf(sid));
+
for (String intf : remoteInterfaces) {
Service service = assemblyFactory.createService();
- JavaInterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract();
- Class<?> interfaceClass = bundle.loadClass(intf);
- JavaInterface javaInterface = javaInterfaceFactory.createJavaInterface(interfaceClass);
- interfaceContract.setInterface(javaInterface);
- if (javaInterface.getCallbackClass() != null) {
- interfaceContract.setCallbackInterface(javaInterfaceFactory.createJavaInterface(javaInterface
- .getCallbackClass()));
- }
-
- service.setName(interfaceClass.getSimpleName());
+ JavaInterfaceContract interfaceContract = createJavaInterfaceContract(bundle, intf);
+ String name = intf.substring(intf.lastIndexOf('.') + 1);
+ service.setName(name);
service.setInterfaceContract(interfaceContract);
service.getExtensions().add(serviceID);
@@ -292,39 +321,63 @@ public class EndpointIntrospector {
componentService.setService(service);
}
- String[] requiredIntents = getStrings(properties.get(SERVICE_EXPORTED_INTENTS));
- List<Intent> intents = getIntents(requiredIntents);
- String[] requiredIntentsExtra = getStrings(properties.get(SERVICE_EXPORTED_INTENTS_EXTRA));
- List<Intent> extraIntents = getIntents(requiredIntentsExtra);
-
- String[] bindingNames = getStrings(properties.get(SCA_BINDINGS));
- Collection<Binding> bindings = loadBindings(bindingNames);
-
for (ComponentService componentService : component.getServices()) {
- componentService.getRequiredIntents().addAll(intents);
- componentService.getRequiredIntents().addAll(extraIntents);
+ componentService.getRequiredIntents().addAll(allIntents);
componentService.getBindings().addAll(bindings);
}
// FIXME: Should we scan the owning bundle to create the SCA contribution?
+ Contribution contribution = createContribution(bundle, id, composite);
+ return contribution;
+ }
+
+ private Contribution createContribution(Bundle bundle, String id, Composite composite) {
Contribution contribution = contributionFactory.createContribution();
+ contribution.setClassLoader(OSGiHelper.createBundleClassLoader(bundle));
contribution.setURI("urn:" + id);
contribution.setLocation(bundle.getEntry("/").toString());
contribution.getDeployables().add(composite);
ModelResolver modelResolver = new ExtensibleModelResolver(contribution, modelResolvers, factories);
contribution.setModelResolver(modelResolver);
+ // compositeProcessor.resolve(composite, modelResolver, new ProcessorContext(registry));
contribution.setUnresolved(true);
return contribution;
}
+ /**
+ * @param bundle
+ * @param endpoint
+ * @return
+ * @throws Exception
+ */
public Contribution introspect(Bundle bundle, EndpointDescription endpoint) throws Exception {
+ Collection<Binding> bindings = Collections.emptyList();
+ Collection<String> interfaces = Collections.emptyList();
+ Collection<Intent> intents = Collections.emptyList();
Endpoint ep = (Endpoint)endpoint.getProperties().get(Endpoint.class.getName());
if (ep != null) {
- return introspect(bundle, ep);
+ bindings = Collections.singletonList(ep.getBinding());
+ interfaces = Collections.singletonList(((JavaInterface)ep.getInterfaceContract().getInterface()).getName());
+ intents = ep.getRequiredIntents();
+ } else {
+ Map<String, Object> properties = endpoint.getProperties();
+ interfaces = endpoint.getInterfaces();
+ String[] requiredIntents = getStringArray(properties.get(SERVICE_EXPORTED_INTENTS));
+ intents = getIntents(requiredIntents);
+
+ String[] bindingNames = getStringArray(properties.get(SCA_BINDINGS));
+ bindings = loadBindings(bindingNames);
}
- Map<String, Object> properties = endpoint.getProperties();
- List<String> remoteInterfaces = endpoint.getInterfaces();
+ Contribution contribution = generateContribution(bundle, interfaces, bindings, intents);
+ return contribution;
+ }
+
+ private Contribution generateContribution(Bundle bundle,
+ Collection<String> remoteInterfaces,
+ Collection<Binding> bindings,
+ Collection<Intent> intents) throws ClassNotFoundException,
+ InvalidInterfaceException, ContributionResolveException {
String id = "osgi.reference." + UUID.randomUUID();
Composite composite = assemblyFactory.createComposite();
composite.setName(new QName(Base.SCA11_TUSCANY_NS, id));
@@ -344,14 +397,7 @@ public class EndpointIntrospector {
int count = 0;
for (String intf : remoteInterfaces) {
Reference reference = assemblyFactory.createReference();
- JavaInterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract();
- Class<?> interfaceClass = bundle.loadClass(intf);
- JavaInterface javaInterface = javaInterfaceFactory.createJavaInterface(interfaceClass);
- interfaceContract.setInterface(javaInterface);
- if (javaInterface.getCallbackClass() != null) {
- interfaceContract.setCallbackInterface(javaInterfaceFactory.createJavaInterface(javaInterface
- .getCallbackClass()));
- }
+ JavaInterfaceContract interfaceContract = createJavaInterfaceContract(bundle, intf);
reference.setName("ref" + (count++));
reference.setInterfaceContract(interfaceContract);
@@ -365,77 +411,30 @@ public class EndpointIntrospector {
componentReference.setWiredByImpl(true);
}
- String[] requiredIntents = getStrings(properties.get(SERVICE_EXPORTED_INTENTS));
- List<Intent> intents = getIntents(requiredIntents);
-
- String[] bindingNames = getStrings(properties.get(SCA_BINDINGS));
- Collection<Binding> bindings = loadBindings(bindingNames);
-
for (ComponentReference componentReference : component.getReferences()) {
componentReference.getRequiredIntents().addAll(intents);
componentReference.getBindings().addAll(bindings);
}
- // FIXME: Should we scan the owning bundle to create the SCA contribution?
- Contribution contribution = contributionFactory.createContribution();
- contribution.setURI("urn:" + id);
- contribution.setLocation(bundle.getEntry("/").toString());
- contribution.getDeployables().add(composite);
- ModelResolver modelResolver = new ExtensibleModelResolver(contribution, modelResolvers, factories);
- contribution.setModelResolver(modelResolver);
- contribution.setUnresolved(true);
+
+ Contribution contribution = createContribution(bundle, id, composite);
return contribution;
}
- public Contribution introspect(Bundle bundle, Endpoint endpoint) throws Exception {
- String id = "osgi.reference." + UUID.randomUUID();
- Composite composite = assemblyFactory.createComposite();
- composite.setName(new QName(Base.SCA11_TUSCANY_NS, id));
-
- Component component = assemblyFactory.createComponent();
- component.setName(id);
- // component.setAutowire(Boolean.TRUE);
-
- composite.getComponents().add(component);
-
- OSGiImplementation implementation = implementationFactory.createOSGiImplementation();
-
- implementation.setBundle(bundle);
- component.setImplementation(implementation);
- implementation.setUnresolved(false);
-
- Reference reference = assemblyFactory.createReference();
- Service service = endpoint.getService().getService();
- reference.setInterfaceContract(service.getInterfaceContract());
- reference.setName("ref");
-
- reference.getBindings().add(endpoint.getBinding());
-
- /*
- reference.getRequiredIntents().addAll(service.getRequiredIntents());
- reference.getPolicySets().addAll(service.getPolicySets());
- */
-
- implementation.getReferences().add(reference);
-
- ComponentReference componentReference = assemblyFactory.createComponentReference();
- component.getReferences().add(componentReference);
- componentReference.setReference(reference);
- componentReference.setName(reference.getName());
- componentReference.setWiredByImpl(true);
-
- // FIXME: Should we scan the owning bundle to create the SCA contribution?
- Contribution contribution = contributionFactory.createContribution();
- contribution.setURI("urn:" + id);
- contribution.setLocation(bundle.getEntry("/").toString());
- contribution.getDeployables().add(composite);
- ModelResolver modelResolver = new ExtensibleModelResolver(contribution, modelResolvers, factories);
- contribution.setModelResolver(modelResolver);
- contribution.setUnresolved(true);
- return contribution;
+ private JavaInterfaceContract createJavaInterfaceContract(Bundle bundle, String intf)
+ throws ClassNotFoundException, InvalidInterfaceException {
+ JavaInterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract();
+ Class<?> interfaceClass = bundle.loadClass(intf);
+ JavaInterface javaInterface = javaInterfaceFactory.createJavaInterface(interfaceClass);
+ interfaceContract.setInterface(javaInterface);
+ if (javaInterface.getCallbackClass() != null) {
+ interfaceContract.setCallbackInterface(javaInterfaceFactory.createJavaInterface(javaInterface
+ .getCallbackClass()));
+ }
+ return interfaceContract;
}
- private Collection<Binding> loadBindings(String[] qnames) throws IOException,
- ContributionReadException, XMLStreamException {
+ private Collection<Binding> loadBindings(String[] qnames) throws IOException, ContributionReadException,
+ XMLStreamException {
if (qnames == null || qnames.length == 0) {
return Collections.emptyList();
}
@@ -472,23 +471,4 @@ public class EndpointIntrospector {
return bindingMap.values();
}
- /**
- * In OSGi, the value of String+ can be a single String, String[] or Collection<String>
- * @param value
- * @return
- */
- private String[] getStrings(Object value) {
- if (value == null) {
- return null;
- }
- if (value instanceof String) {
- return new String[] {(String)value};
- } else if (value instanceof Collection) {
- Collection<String> collection = (Collection)value;
- return collection.toArray(new String[collection.size()]);
- }
- return (String[])value;
-
- }
-
}
diff --git a/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiHelper.java b/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiHelper.java
index d5a2b7aa95..a4b51d9d0c 100644
--- a/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiHelper.java
+++ b/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiHelper.java
@@ -19,13 +19,20 @@
package org.apache.tuscany.sca.osgi.remoteserviceadmin.impl;
+import java.io.IOException;
import java.net.URL;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashSet;
+import java.util.List;
+import java.util.UUID;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+import org.apache.tuscany.sca.implementation.osgi.OSGiImplementationFactory;
+import org.apache.tuscany.sca.implementation.osgi.OSGiProperty;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Filter;
@@ -36,6 +43,8 @@ import org.osgi.framework.ServiceReference;
*
*/
public class OSGiHelper {
+ public final static String FRAMEWORK_UUID = "org.osgi.framework.uuid";
+
private OSGiHelper() {
}
@@ -131,5 +140,65 @@ public class OSGiHelper {
}
return files;
}
+
+ public static Collection<OSGiProperty> getOSGiProperties(ExtensionPointRegistry registry, ServiceReference reference) {
+ FactoryExtensionPoint factoryExtensionPoint = registry.getExtensionPoint(FactoryExtensionPoint.class);
+ OSGiImplementationFactory implementationFactory= factoryExtensionPoint.getFactory(OSGiImplementationFactory.class);
+ return implementationFactory.createOSGiProperties(reference);
+ }
+
+ public static OSGiProperty createOSGiProperty(ExtensionPointRegistry registry, String name, Object value) {
+ FactoryExtensionPoint factoryExtensionPoint = registry.getExtensionPoint(FactoryExtensionPoint.class);
+ OSGiImplementationFactory implementationFactory= factoryExtensionPoint.getFactory(OSGiImplementationFactory.class);
+ return implementationFactory.createOSGiProperty(name, value);
+ }
+
+
+ public synchronized static String getFrameworkUUID(BundleContext bundleContext) {
+ String uuid = null;
+ if (bundleContext != null) {
+ uuid = bundleContext.getProperty(FRAMEWORK_UUID);
+ } else {
+ uuid = System.getProperty(FRAMEWORK_UUID);
+ }
+ if (uuid == null) {
+ uuid = UUID.randomUUID().toString();
+ }
+ System.setProperty(FRAMEWORK_UUID, uuid);
+ return uuid;
+ }
+
+ public static ClassLoader createBundleClassLoader(Bundle bundle) {
+ return new BundleClassLoader(bundle);
+ }
+
+ private static class BundleClassLoader extends ClassLoader {
+ private Bundle bundle;
+ public BundleClassLoader(Bundle bundle) {
+ super(null);
+ this.bundle = bundle;
+ }
+
+ @Override
+ protected Class<?> findClass(String name) throws ClassNotFoundException {
+ return bundle.loadClass(name);
+ }
+
+ @Override
+ protected URL findResource(String name) {
+ return bundle.getResource(name);
+ }
+
+ @Override
+ protected Enumeration<URL> findResources(String name) throws IOException {
+ Enumeration<URL> urls = bundle.getResources(name);
+ if (urls == null) {
+ List<URL> list = Collections.emptyList();
+ return Collections.enumeration(list);
+ } else {
+ return urls;
+ }
+ }
+ }
}
diff --git a/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceExporter.java b/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceExporter.java
index 02603417cc..479ae54e42 100644
--- a/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceExporter.java
+++ b/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceExporter.java
@@ -19,7 +19,13 @@
package org.apache.tuscany.sca.osgi.remoteserviceadmin.impl;
+import static org.apache.tuscany.sca.osgi.remoteserviceadmin.RemoteConstants.SERVICE_REMOTE_FRAMEWORK_UUID;
+import static org.apache.tuscany.sca.osgi.remoteserviceadmin.RemoteConstants.SERVICE_REMOTE_ID;
import static org.apache.tuscany.sca.osgi.remoteserviceadmin.impl.EndpointHelper.createEndpointDescription;
+import static org.apache.tuscany.sca.osgi.remoteserviceadmin.impl.OSGiHelper.createOSGiProperty;
+import static org.apache.tuscany.sca.osgi.remoteserviceadmin.impl.OSGiHelper.getFrameworkUUID;
+import static org.apache.tuscany.sca.osgi.remoteserviceadmin.impl.OSGiHelper.getOSGiProperties;
+import static org.osgi.framework.Constants.SERVICE_ID;
import java.util.ArrayList;
import java.util.Collections;
@@ -70,14 +76,25 @@ public class OSGiServiceExporter extends AbstractOSGiServiceHandler implements S
if (domainRegistry != null) {
configuration.setDomainRegistryURI(domainRegistry);
}
+ if (domainURI != null) {
+ configuration.setDomainURI(domainURI);
+ }
configuration.setURI(contribution.getURI());
configuration.getExtensions().add(reference.getBundle());
+ Component component = contribution.getDeployables().get(0).getComponents().get(0);
+ ComponentService service = component.getServices().get(0);
+ service.getExtensions().addAll(getOSGiProperties(registry, reference));
+ service.getExtensions().add(createOSGiProperty(registry,
+ SERVICE_REMOTE_FRAMEWORK_UUID,
+ getFrameworkUUID(reference.getBundle()
+ .getBundleContext())));
+ service.getExtensions().add(createOSGiProperty(registry, SERVICE_REMOTE_ID, reference
+ .getProperty(SERVICE_ID)));
+
// FIXME: Configure the domain and node URI
NodeImpl node = new NodeImpl(nodeFactory, configuration, Collections.singletonList(contribution));
node.start();
List<ExportRegistration> exportedServices = new ArrayList<ExportRegistration>();
- Component component = contribution.getDeployables().get(0).getComponents().get(0);
- ComponentService service = component.getServices().get(0);
for (Endpoint endpoint : service.getEndpoints()) {
EndpointDescription endpointDescription = createEndpointDescription(context, endpoint);
ExportRegistration exportRegistration =
diff --git a/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceImporter.java b/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceImporter.java
index 59a21ade06..c869ab8c14 100644
--- a/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceImporter.java
+++ b/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceImporter.java
@@ -61,6 +61,9 @@ public class OSGiServiceImporter extends AbstractOSGiServiceHandler {
if (domainRegistry != null) {
configuration.setDomainRegistryURI(domainRegistry);
}
+ if (domainURI != null) {
+ configuration.setDomainURI(domainURI);
+ }
configuration.setURI(contribution.getURI());
configuration.getExtensions().add(bundle);
// FIXME: Configure the domain and node URI
diff --git a/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/RemoteServiceAdminImpl.java b/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/RemoteServiceAdminImpl.java
index bc2e3ce012..9da7b5f014 100644
--- a/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/RemoteServiceAdminImpl.java
+++ b/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/RemoteServiceAdminImpl.java
@@ -276,9 +276,14 @@ public class RemoteServiceAdminImpl implements RemoteServiceAdmin, ManagedServic
return;
}
String domainRegistry = (String)props.get("org.osgi.sca.domain.registry");
+ String domainURI = (String)props.get("org.osgi.sca.domain.uri");
if (domainRegistry != null) {
exporter.setDomainRegistry(domainRegistry);
importer.setDomainRegistry(domainRegistry);
}
+ if (domainURI != null) {
+ exporter.setDomainURI(domainURI);
+ importer.setDomainURI(domainURI);
+ }
}
}