summaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-07-16 06:52:55 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-07-16 06:52:55 +0000
commitb264fae6da998eb032462b7287711d891498cd3e (patch)
tree9342de7ff260bba4568f5975e49a4d7b7cd58c80 /java
parentce9150bd4c4880a4032030213de8626c21764bfd (diff)
Refactor the OSGi discovery service into node-implementation-osgi
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@794553 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java')
-rw-r--r--java/sca/modules/implementation-osgi-runtime/META-INF/MANIFEST.MF6
-rw-r--r--java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java87
-rw-r--r--java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationRuntimeActivator.java15
-rw-r--r--java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTargetInvoker.java20
-rwxr-xr-xjava/sca/modules/implementation-osgi/META-INF/MANIFEST.MF4
-rw-r--r--java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/BindingDescriptions.java34
-rw-r--r--java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/ServiceDescriptionsFactory.java2
-rw-r--r--java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/BindingDescriptionsImpl.java36
-rw-r--r--java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/ServiceDescriptionsFactoryImpl.java5
-rw-r--r--java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/introspection/ExportedServiceIntrospector.java422
-rw-r--r--java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/BindingDescriptionsProcessor.java117
-rw-r--r--java/sca/modules/implementation-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor1
-rw-r--r--java/sca/modules/node-impl-osgi/META-INF/MANIFEST.MF6
-rw-r--r--java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/dosgi/discovery/AbstractDiscoveryService.java (renamed from java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/AbstractDiscoveryService.java)10
-rw-r--r--java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/dosgi/discovery/DiscoveredServiceNotificationImpl.java (renamed from java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/DiscoveredServiceNotificationImpl.java)0
-rw-r--r--java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/dosgi/discovery/DiscoveryActivator.java (renamed from java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/DiscoveryActivator.java)0
-rw-r--r--java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/dosgi/discovery/DomainDiscoveryService.java (renamed from java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/DomainDiscoveryService.java)6
-rw-r--r--java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/dosgi/discovery/EndpointDescription.java (renamed from java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/EndpointDescription.java)0
-rw-r--r--java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/dosgi/discovery/EndpointPublication.java (renamed from java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/EndpointPublication.java)0
-rw-r--r--java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/dosgi/discovery/LocalDiscoveryService.java (renamed from java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/LocalDiscoveryService.java)8
-rw-r--r--java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/dosgi/discovery/ServiceEndpointDescriptionImpl.java (renamed from java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/ServiceEndpointDescriptionImpl.java)0
-rw-r--r--java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/NodeActivator.java17
-rw-r--r--java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/NodeManager.java2
-rw-r--r--java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/OSGiServiceExporter.java127
-rw-r--r--java/sca/modules/node-impl-osgi/src/main/java/org/osgi/service/discovery/DiscoveredServiceNotification.java (renamed from java/sca/modules/implementation-osgi-runtime/src/main/java/org/osgi/service/discovery/DiscoveredServiceNotification.java)0
-rw-r--r--java/sca/modules/node-impl-osgi/src/main/java/org/osgi/service/discovery/DiscoveredServiceTracker.java (renamed from java/sca/modules/implementation-osgi-runtime/src/main/java/org/osgi/service/discovery/DiscoveredServiceTracker.java)0
-rw-r--r--java/sca/modules/node-impl-osgi/src/main/java/org/osgi/service/discovery/Discovery.java (renamed from java/sca/modules/implementation-osgi-runtime/src/main/java/org/osgi/service/discovery/Discovery.java)0
-rw-r--r--java/sca/modules/node-impl-osgi/src/main/java/org/osgi/service/discovery/ServiceEndpointDescription.java (renamed from java/sca/modules/implementation-osgi-runtime/src/main/java/org/osgi/service/discovery/ServiceEndpointDescription.java)0
-rw-r--r--java/sca/modules/node-impl-osgi/src/main/java/org/osgi/service/discovery/ServicePublication.java (renamed from java/sca/modules/implementation-osgi-runtime/src/main/java/org/osgi/service/discovery/ServicePublication.java)0
-rw-r--r--java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java136
-rw-r--r--java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java27
-rw-r--r--java/sca/modules/node-launcher-equinox/pom.xml4
-rw-r--r--java/sca/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java17
33 files changed, 982 insertions, 127 deletions
diff --git a/java/sca/modules/implementation-osgi-runtime/META-INF/MANIFEST.MF b/java/sca/modules/implementation-osgi-runtime/META-INF/MANIFEST.MF
index b2e1c16707..f0704ad240 100644
--- a/java/sca/modules/implementation-osgi-runtime/META-INF/MANIFEST.MF
+++ b/java/sca/modules/implementation-osgi-runtime/META-INF/MANIFEST.MF
@@ -25,9 +25,7 @@ Import-Package: org.apache.tuscany.sca.assembly;version="2.0.0",
org.oasisopen.sca;version="2.0.0",
org.oasisopen.sca.annotation;version="2.0.0";resolution:=optional,
org.osgi.framework;version="1.4.0",
- org.osgi.service.discovery;version="1.0",
- org.osgi.util.tracker
+ org.osgi.util.tracker;version="1.3.3"
Bundle-DocURL: http://www.apache.org/
Bundle-RequiredExecutionEnvironment: J2SE-1.5,JavaSE-1.6
-Export-Package: org.osgi.service.discovery;version="1.0",
- org.osgi.service.distribution;version="1.0"
+Export-Package: org.osgi.service.distribution;version="1.0"
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 c6e01564db..8f032efc47 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
@@ -19,11 +19,16 @@
package org.apache.tuscany.sca.implementation.osgi.runtime;
+import static org.osgi.framework.Constants.SERVICE_RANKING;
+
import java.security.AccessController;
import java.security.PrivilegedAction;
+import java.util.ArrayList;
import java.util.Hashtable;
+import java.util.List;
import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.ComponentService;
import org.apache.tuscany.sca.assembly.Extensible;
import org.apache.tuscany.sca.core.invocation.ProxyFactory;
import org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint;
@@ -40,8 +45,10 @@ import org.apache.tuscany.sca.runtime.RuntimeComponentService;
import org.apache.tuscany.sca.runtime.RuntimeWire;
import org.oasisopen.sca.ServiceRuntimeException;
import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
-import org.osgi.framework.Constants;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
/**
@@ -52,6 +59,7 @@ public class OSGiImplementationProvider implements ImplementationProvider {
private ProxyFactoryExtensionPoint proxyFactoryExtensionPoint;
private Bundle osgiBundle;
private OSGiImplementation implementation;
+ private List<ServiceRegistration> registrations = new ArrayList<ServiceRegistration>();
public OSGiImplementationProvider(RuntimeComponent component,
OSGiImplementation impl,
@@ -76,18 +84,25 @@ public class OSGiImplementationProvider implements ImplementationProvider {
} catch (BundleException e) {
throw new ServiceRuntimeException(e);
}
+
for (ComponentReference ref : component.getReferences()) {
RuntimeComponentReference reference = (RuntimeComponentReference)ref;
InterfaceContract interfaceContract = reference.getInterfaceContract();
JavaInterface javaInterface = (JavaInterface)interfaceContract.getInterface();
final Class<?> interfaceClass = javaInterface.getJavaClass();
+// final Hashtable<String, Object> props = new Hashtable<String, Object>();
+// props.put(FILTER_MATCH_CRITERIA, "");
+// Collection<String> interfaceNames = new ArrayList<String>();
+// props.put(INTERFACE_MATCH_CRITERIA, interfaceNames);
+// interfaceNames.add(interfaceClass.getName());
+
final Hashtable<String, Object> osgiProps = getOSGiProperties(reference);
- osgiProps.put(Constants.SERVICE_RANKING, Integer.MAX_VALUE);
+ osgiProps.put(SERVICE_RANKING, Integer.MAX_VALUE);
osgiProps.put("sca.reference", component.getURI() + "#reference(" + ref.getName() + ")");
osgiProps.put(OSGiProperty.OSGI_REMOTE, "true");
osgiProps.put(OSGiProperty.OSGI_REMOTE_CONFIGURATION_TYPE, "sca");
- osgiProps.put(OSGiProperty.OSGI_REMOTE_INTERFACES, interfaceClass.getName());
+ osgiProps.put(OSGiProperty.OSGI_REMOTE_INTERFACES, new String[] {interfaceClass.getName()});
ProxyFactory proxyService = proxyFactoryExtensionPoint.getInterfaceProxyFactory();
if (!interfaceClass.isInterface()) {
@@ -96,19 +111,29 @@ public class OSGiImplementationProvider implements ImplementationProvider {
for (RuntimeWire wire : reference.getRuntimeWires()) {
final Object proxy = proxyService.createProxy(interfaceClass, wire);
- AccessController.doPrivileged(new PrivilegedAction<ServiceRegistration>() {
- public ServiceRegistration run() {
- return osgiBundle.getBundleContext()
- .registerService(interfaceClass.getName(), proxy, osgiProps);
- }
- });
+ ServiceRegistration registration =
+ AccessController.doPrivileged(new PrivilegedAction<ServiceRegistration>() {
+ public ServiceRegistration run() {
+ // Register the proxy as OSGi service
+ BundleContext context = osgiBundle.getBundleContext();
+ ServiceRegistration registration =
+ context.registerService(interfaceClass.getName(), proxy, osgiProps);
+ // Create a DiscoveredServiceTracker to track the status of the remote service
+// RemoteServiceTracker tracker = new RemoteServiceTracker(registration);
+// context.registerService(DiscoveredServiceTracker.class.getName(), tracker, props);
+ return registration;
+ }
+ });
+ registrations.add(registration);
}
-
}
}
public void stop() {
- // Do we have to unregister the services?
+ for (ServiceRegistration registration : registrations) {
+ registration.unregister();
+ }
+ registrations.clear();
try {
int state = osgiBundle.getState();
if ((state & Bundle.STOPPING) == 0 && (state & Bundle.ACTIVE) != 0) {
@@ -138,6 +163,27 @@ public class OSGiImplementationProvider implements ImplementationProvider {
}
return props;
}
+
+ protected Object getOSGiService(ComponentService service) {
+ JavaInterface javaInterface = (JavaInterface)service.getInterfaceContract().getInterface();
+ // String filter = getOSGiFilter(provider.getOSGiProperties(service));
+ // FIXME: What is the filter?
+ String filter = "(!(sca.reference=*))";
+ // "(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;
+ }
+ }
RuntimeComponent getComponent() {
return component;
@@ -147,4 +193,23 @@ public class OSGiImplementationProvider implements ImplementationProvider {
return implementation;
}
+// private class RemoteServiceTracker implements DiscoveredServiceTracker {
+// private ServiceRegistration referenceRegistration;
+//
+// private RemoteServiceTracker(ServiceRegistration referenceRegistration) {
+// super();
+// this.referenceRegistration = referenceRegistration;
+// }
+//
+// public void serviceChanged(DiscoveredServiceNotification notification) {
+// ServiceEndpointDescription description = notification.getServiceEndpointDescription();
+// switch(notification.getType()) {
+// case UNAVAILABLE:
+// case AVAILABLE:
+// case MODIFIED:
+// case MODIFIED_ENDMATCH:
+// }
+// }
+// }
+
}
diff --git a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationRuntimeActivator.java b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationRuntimeActivator.java
index 9138a0147f..ee8e9ade72 100644
--- a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationRuntimeActivator.java
+++ b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationRuntimeActivator.java
@@ -19,7 +19,6 @@
package org.apache.tuscany.sca.implementation.osgi.runtime;
-import org.apache.tuscany.sca.dosgi.discovery.DiscoveryActivator;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
@@ -30,25 +29,25 @@ import org.osgi.service.distribution.DistributionProvider;
*/
public class OSGiImplementationRuntimeActivator implements BundleActivator {
private static BundleContext bundleContext;
- private DiscoveryActivator discoveryActivator;
+// private DiscoveryActivator discoveryActivator;
private ServiceRegistration distributionProvider;
public void start(BundleContext context) throws Exception {
bundleContext = context;
- discoveryActivator = new DiscoveryActivator();
- discoveryActivator.start(context);
+// discoveryActivator = new DiscoveryActivator();
+// discoveryActivator.start(context);
OSGiDistributionProvider provider = new OSGiDistributionProvider(bundleContext);
distributionProvider = bundleContext.registerService(DistributionProvider.class.getName(), provider, provider.getProperties());
}
public void stop(BundleContext context) throws Exception {
- if (discoveryActivator != null) {
- discoveryActivator.stop(context);
- }
+// if (discoveryActivator != null) {
+// discoveryActivator.stop(context);
+// }
+// discoveryActivator = null;
if (distributionProvider != null) {
distributionProvider.unregister();
}
- discoveryActivator = null;
bundleContext = null;
}
diff --git a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTargetInvoker.java b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTargetInvoker.java
index 1814ab928c..a9a2fdbd0b 100644
--- a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTargetInvoker.java
+++ b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTargetInvoker.java
@@ -29,14 +29,12 @@ import java.util.List;
import org.apache.tuscany.sca.interfacedef.DataType;
import org.apache.tuscany.sca.interfacedef.Interface;
import org.apache.tuscany.sca.interfacedef.Operation;
-import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
import org.apache.tuscany.sca.interfacedef.java.JavaOperation;
import org.apache.tuscany.sca.invocation.Invoker;
import org.apache.tuscany.sca.invocation.Message;
import org.apache.tuscany.sca.runtime.RuntimeComponent;
import org.apache.tuscany.sca.runtime.RuntimeComponentService;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
+import org.osgi.framework.Constants;
/**
* The Invoker looks up the corresponding OSGi service from the OSGi service registry
@@ -69,14 +67,7 @@ public class OSGiTargetInvoker implements Invoker {
}
try {
- BundleContext bundleContext = provider.getImplementation().getBundle().getBundleContext();
- JavaInterface javaInterface = (JavaInterface)op.getInterface();
- // String filter = getOSGiFilter(provider.getOSGiProperties(service));
- // FIXME: What is the filter?
- String filter = "(!(sca.reference=*))";
- // "(sca.service=" + component.getURI() + "#service-name\\(" + service.getName() + "\\))";
- ServiceReference ref = bundleContext.getServiceReferences(javaInterface.getName(), filter)[0];
- Object instance = bundleContext.getService(ref);
+ Object instance = provider.getOSGiService(service);
Method m = findMethod(instance.getClass(), operation);
Object ret = invokeMethod(instance, m, msg);
@@ -119,15 +110,16 @@ public class OSGiTargetInvoker implements Invoker {
}
private String getOSGiFilter(Hashtable<String, Object> props) {
+ Object serviceID = props.get(Constants.SERVICE_ID);
+ if (serviceID != null) {
+ return "(" + Constants.SERVICE_ID + "=" + serviceID + ")";
+ }
String filter = "";
if (props != null && props.size() > 0) {
int propCount = 0;
for (String propName : props.keySet()) {
- if (propName.equals("service.pid")) {
- continue;
- }
String value = String.valueOf(props.get(propName));
StringBuffer buf = new StringBuffer();
for (char c : value.toCharArray()) {
diff --git a/java/sca/modules/implementation-osgi/META-INF/MANIFEST.MF b/java/sca/modules/implementation-osgi/META-INF/MANIFEST.MF
index f417c651b2..c6921b4c4e 100755
--- a/java/sca/modules/implementation-osgi/META-INF/MANIFEST.MF
+++ b/java/sca/modules/implementation-osgi/META-INF/MANIFEST.MF
@@ -19,6 +19,7 @@ Import-Package: javax.xml.namespace,
org.apache.tuscany.sca.contribution.resolver;version="2.0.0",
org.apache.tuscany.sca.core;version="2.0.0",
org.apache.tuscany.sca.implementation.osgi;version="2.0.0",
+ org.apache.tuscany.sca.implementation.osgi.introspection;version="2.0.0",
org.apache.tuscany.sca.interfacedef;version="2.0.0",
org.apache.tuscany.sca.interfacedef.java;version="2.0.0",
org.apache.tuscany.sca.interfacedef.java.impl;version="2.0.0",
@@ -31,5 +32,6 @@ Import-Package: javax.xml.namespace,
org.osgi.service.packageadmin;version="1.2.0",
org.osgi.util.tracker;version="1.3.3"
Bundle-DocURL: http://www.apache.org/
-Export-Package: org.apache.tuscany.sca.implementation.osgi;version="2.0.0"
+Export-Package: org.apache.tuscany.sca.implementation.osgi;version="2.0.0",
+ org.apache.tuscany.sca.implementation.osgi.introspection;version="2.0.0"
Bundle-RequiredExecutionEnvironment: J2SE-1.5,JavaSE-1.6
diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/BindingDescriptions.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/BindingDescriptions.java
new file mode 100644
index 0000000000..068374c7cf
--- /dev/null
+++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/BindingDescriptions.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.osgi;
+
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.assembly.Binding;
+
+/**
+ * OSGi RFC 119 SCA binding descriptions
+ */
+public interface BindingDescriptions extends List<Binding> {
+ String OSGI_SD_NS = ServiceDescriptions.OSGI_SD_NS;
+ QName BINDINGS_QNAME = new QName(OSGI_SD_NS, "bindings");
+}
diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/ServiceDescriptionsFactory.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/ServiceDescriptionsFactory.java
index 0e4c51b1f9..249377e3ea 100644
--- a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/ServiceDescriptionsFactory.java
+++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/ServiceDescriptionsFactory.java
@@ -26,4 +26,6 @@ public interface ServiceDescriptionsFactory {
ServiceDescriptions createServiceDescriptions();
ServiceDescription createServiceDescription();
+
+ BindingDescriptions createBindingDescriptions();
}
diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/BindingDescriptionsImpl.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/BindingDescriptionsImpl.java
new file mode 100644
index 0000000000..67a724877d
--- /dev/null
+++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/BindingDescriptionsImpl.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.osgi.impl;
+
+import java.util.ArrayList;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.implementation.osgi.BindingDescriptions;
+
+/**
+ *
+ */
+public class BindingDescriptionsImpl extends ArrayList<Binding> implements BindingDescriptions {
+ private static final long serialVersionUID = 7647814680087128002L;
+
+ public BindingDescriptionsImpl() {
+ super();
+ }
+}
diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/ServiceDescriptionsFactoryImpl.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/ServiceDescriptionsFactoryImpl.java
index 8cd3867610..625f1e7cfb 100644
--- a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/ServiceDescriptionsFactoryImpl.java
+++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/ServiceDescriptionsFactoryImpl.java
@@ -19,6 +19,7 @@
package org.apache.tuscany.sca.implementation.osgi.impl;
+import org.apache.tuscany.sca.implementation.osgi.BindingDescriptions;
import org.apache.tuscany.sca.implementation.osgi.ServiceDescription;
import org.apache.tuscany.sca.implementation.osgi.ServiceDescriptions;
import org.apache.tuscany.sca.implementation.osgi.ServiceDescriptionsFactory;
@@ -40,4 +41,8 @@ public class ServiceDescriptionsFactoryImpl implements ServiceDescriptionsFactor
return new ServiceDescriptionsImpl();
}
+ public BindingDescriptions createBindingDescriptions() {
+ return new BindingDescriptionsImpl();
+ }
+
}
diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/introspection/ExportedServiceIntrospector.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/introspection/ExportedServiceIntrospector.java
new file mode 100644
index 0000000000..f6abf3b2b4
--- /dev/null
+++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/introspection/ExportedServiceIntrospector.java
@@ -0,0 +1,422 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.osgi.introspection;
+
+import static org.apache.tuscany.sca.assembly.Base.SCA11_TUSCANY_NS;
+import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.OSGI_REMOTE_CONFIGURATION_TYPE;
+import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.OSGI_REMOTE_CONFIGURATION_TYPE_SCA;
+import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.OSGI_REMOTE_INTENTS;
+import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.OSGI_REMOTE_INTERFACES;
+import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.SCA_BINDINGS;
+import static org.osgi.framework.Constants.OBJECTCLASS;
+import static org.osgi.framework.Constants.SERVICE_ID;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Base;
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.Reference;
+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.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+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.implementation.osgi.BindingDescriptions;
+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.ServiceDescriptionsFactory;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.MonitorFactory;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * Introspect an OSGi Service to create an SCA composite that contains a single component with
+ * implementation.osgi
+ */
+public class ExportedServiceIntrospector {
+ private AssemblyFactory assemblyFactory;
+ private ContributionFactory contributionFactory;
+ private OSGiImplementationFactory implementationFactory;
+ private ServiceDescriptionsFactory serviceDescriptionsFactory;
+ private PolicyFactory policyFactory;
+ private ExtensionPointRegistry registry;
+ private FactoryExtensionPoint factories;
+ private ModelResolverExtensionPoint modelResolvers;
+ private XMLInputFactory xmlInputFactory;
+ private XMLOutputFactory xmlOutputFactory;
+ private JavaInterfaceFactory javaInterfaceFactory;
+ private StAXArtifactProcessor processor;
+
+ /**
+ * @param intentName
+ * @return
+ */
+ private static QName getQName(String intentName) {
+ QName qname;
+ if (intentName.startsWith("{")) {
+ int i = intentName.indexOf('}');
+ if (i != -1) {
+ qname = new QName(intentName.substring(1, i), intentName.substring(i + 1));
+ } else {
+ throw new IllegalArgumentException("Invalid intent: " + intentName);
+ }
+ } else {
+ // Default to SCA namespace
+ qname = new QName(Base.SCA11_NS, intentName);
+ }
+ return qname;
+ }
+
+ /**
+ * @param registry
+ */
+ public ExportedServiceIntrospector(ExtensionPointRegistry registry) {
+ super();
+ this.registry = registry;
+ this.factories = registry.getExtensionPoint(FactoryExtensionPoint.class);
+ this.modelResolvers = registry.getExtensionPoint(ModelResolverExtensionPoint.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.serviceDescriptionsFactory = factories.getFactory(ServiceDescriptionsFactory.class);
+ this.xmlInputFactory = factories.getFactory(XMLInputFactory.class);
+ this.xmlOutputFactory = factories.getFactory(XMLOutputFactory.class);
+ this.javaInterfaceFactory = factories.getFactory(JavaInterfaceFactory.class);
+ StAXArtifactProcessorExtensionPoint processors =
+ registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ UtilityExtensionPoint utilities = this.registry.getExtensionPoint(UtilityExtensionPoint.class);
+ MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class);
+ Monitor monitor = null;
+ if (monitorFactory != null) {
+ monitor = monitorFactory.createMonitor();
+ }
+ processor = new ExtensibleStAXArtifactProcessor(processors, xmlInputFactory, xmlOutputFactory, monitor);
+ }
+
+ private Intent getIntent(String intent) {
+ QName name = getQName(intent);
+ Intent i = policyFactory.createIntent();
+ i.setName(name);
+ return i;
+ }
+
+ private List<Intent> getIntents(String[] intents) {
+ if (intents == null || intents.length == 0) {
+ return Collections.emptyList();
+ }
+ List<Intent> intentList = new ArrayList<Intent>();
+ for (String i : intents) {
+ Intent intent = getIntent(i);
+ if (intent != null) {
+ intentList.add(intent);
+ }
+ }
+ return intentList;
+ }
+
+ private Map<String, Object> getProperties(ServiceReference reference) {
+ String[] names = reference.getPropertyKeys();
+ if (names != null) {
+ Map<String, Object> properties = new HashMap<String, Object>();
+ for (String name : names) {
+ properties.put(name, reference.getProperty(name));
+ }
+ return properties;
+ } else {
+ return Collections.emptyMap();
+ }
+ }
+
+ /**
+ * Parse the Stringp[] to support values that are separated by comma
+ * @param interfaces
+ * @return
+ */
+ private String[] parse(String[] interfaces) {
+ if (interfaces == null) {
+ return null;
+ }
+ List<String> names = new ArrayList<String>();
+ for (String i : interfaces) {
+ String[] parts = i.split(",");
+ for (String p : parts) {
+ names.add(p.trim());
+ }
+ }
+ return names.toArray(new String[names.size()]);
+ }
+
+ /**
+ * Introspect a local OSGi Service represented by the ServiceReference to create
+ * an SCA service with the required intents and bindings
+ * @param reference The service reference for a local OSGi service
+ * @return An SCA contribution with a deployable composite for the SCA service
+ * @throws Exception
+ */
+ public Contribution introspect(ServiceReference reference) throws Exception {
+ Map<String, Object> properties = getProperties(reference);
+
+ OSGiProperty serviceID = implementationFactory.createOSGiProperty();
+ serviceID.setName(SERVICE_ID);
+ // The service.id is Long
+ serviceID.setValue(String.valueOf(reference.getProperty(SERVICE_ID)));
+
+ String id = "osgi.service." + serviceID.getValue();
+ 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 = (String[])reference.getProperty(OSGI_REMOTE_INTERFACES);
+ if (remoteInterfaces == null || remoteInterfaces.length > 0 && "*".equals(remoteInterfaces[0])) {
+ remoteInterfaces = (String[])reference.getProperty(OBJECTCLASS);
+ } else {
+ remoteInterfaces = parse(remoteInterfaces);
+ }
+ 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());
+ service.setInterfaceContract(interfaceContract);
+
+ service.getExtensions().add(serviceID);
+
+ implementation.getServices().add(service);
+
+ ComponentService componentService = assemblyFactory.createComponentService();
+ component.getServices().add(componentService);
+ componentService.setService(service);
+ }
+
+ String[] requiredIntents = (String[])properties.get(OSGI_REMOTE_INTENTS);
+ List<Intent> intents = getIntents(requiredIntents);
+
+ String[] bindingDocuments = (String[])properties.get(SCA_BINDINGS);
+ List<Binding> bindings = loadBindings(reference.getBundle(), bindingDocuments);
+
+ for (ComponentService componentService : component.getServices()) {
+ componentService.getRequiredIntents().addAll(intents);
+ componentService.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);
+ return contribution;
+ }
+
+ /**
+ * Introspect an OSGi filter to create an SCA reference
+ *
+ * @param bundle
+ * @param filterStr
+ * @param properties
+ * @return
+ * @throws Exception
+ */
+ public Contribution introspect(Bundle bundle, String filterStr, Map<String, Object> properties) throws Exception {
+ Filter filter = null;
+ try {
+ filter = bundle.getBundleContext().createFilter(filterStr);
+ } catch (InvalidSyntaxException e) {
+ e.printStackTrace();
+ return null;
+ }
+ Dictionary<String, Object> props = new Hashtable<String, Object>();
+ props.put(OSGI_REMOTE_CONFIGURATION_TYPE, OSGI_REMOTE_CONFIGURATION_TYPE_SCA);
+ if(!filter.match(props)) {
+ return null;
+ }
+ 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);
+
+ String[] remoteInterfaces = (String[])properties.get(OSGiProperty.OSGI_REMOTE_INTERFACES);
+ if (remoteInterfaces == null || remoteInterfaces.length > 0 && "*".equals(remoteInterfaces[0])) {
+ remoteInterfaces = (String[])properties.get(OBJECTCLASS);
+ } else {
+ remoteInterfaces = parse(remoteInterfaces);
+ }
+ 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()));
+ }
+
+ reference.setName(id);
+ reference.setInterfaceContract(interfaceContract);
+
+ reference.getExtensions().add(filter);
+
+ implementation.getReferences().add(reference);
+
+ ComponentReference componentReference = assemblyFactory.createComponentReference();
+ component.getReferences().add(componentReference);
+ componentReference.setReference(reference);
+ componentReference.setWiredByImpl(true);
+ }
+
+ String[] requiredIntents = (String[])properties.get(OSGI_REMOTE_INTENTS);
+ List<Intent> intents = getIntents(requiredIntents);
+
+ String[] bindingDocuments = (String[])properties.get(SCA_BINDINGS);
+ List<Binding> bindings = loadBindings(bundle, bindingDocuments);
+
+ 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);
+ return contribution;
+ }
+
+ private List<Binding> loadBindings(Bundle bundle, String[] bindingDocuments) throws IOException,
+ ContributionReadException {
+ if (bindingDocuments == null || bindingDocuments.length == 0) {
+ return Collections.emptyList();
+ }
+ List<Binding> bindings = new ArrayList<Binding>();
+ for (String doc : bindingDocuments) {
+ URL url = locate(bundle, doc);
+ if (url == null) {
+ throw new IOException("Entry " + doc + " cannot be found in bundle " + bundle);
+ }
+ bindings.addAll(loadBindings(url));
+ }
+ return bindings;
+ }
+
+ private List<Binding> loadBindings(URL url) throws ContributionReadException, IOException {
+ InputStream is = url.openStream();
+ try {
+ XMLStreamReader reader = xmlInputFactory.createXMLStreamReader(is);
+ reader.nextTag();
+ Object model = processor.read(reader);
+ if (model instanceof BindingDescriptions) {
+ return ((BindingDescriptions)model);
+ } else {
+ return Collections.emptyList();
+ }
+ } catch (XMLStreamException e) {
+ throw new ContributionReadException(e);
+ } finally {
+ is.close();
+ }
+ }
+
+ private URL locate(Bundle bundle, String location) throws MalformedURLException {
+ URI uri = URI.create(location);
+ if (uri.isAbsolute()) {
+ return uri.toURL();
+ }
+ return bundle.getEntry(location);
+ }
+
+}
diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/BindingDescriptionsProcessor.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/BindingDescriptionsProcessor.java
new file mode 100644
index 0000000000..0a94c6ae0a
--- /dev/null
+++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/BindingDescriptionsProcessor.java
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.osgi.xml;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
+import org.apache.tuscany.sca.contribution.processor.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.processor.ContributionWriteException;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+import org.apache.tuscany.sca.implementation.osgi.BindingDescriptions;
+import org.apache.tuscany.sca.implementation.osgi.ServiceDescriptionsFactory;
+import org.apache.tuscany.sca.monitor.Monitor;
+
+/*
+<?xml version="1.0" encoding="UTF-8"?>
+<bindings xmlns="http://www.osgi.org/xmlns/sd/v1.0.0" xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200903">
+ <binding.ws/>
+ <binding.sca/>
+</bindings>
+*/
+public class BindingDescriptionsProcessor implements StAXArtifactProcessor<BindingDescriptions> {
+ private Monitor monitor;
+ private StAXArtifactProcessor processor;
+ private ServiceDescriptionsFactory factory;
+
+ public BindingDescriptionsProcessor(ExtensionPointRegistry registry,
+ StAXArtifactProcessor processor,
+ Monitor monitor) {
+ this.monitor = monitor;
+ this.processor = processor;
+ this.factory =
+ registry.getExtensionPoint(FactoryExtensionPoint.class).getFactory(ServiceDescriptionsFactory.class);
+ }
+
+ public BindingDescriptions read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+ BindingDescriptions bindings = factory.createBindingDescriptions();
+ boolean exit = false;
+ while (!exit) {
+ int event = reader.getEventType();
+ switch (event) {
+ case XMLStreamConstants.START_ELEMENT:
+ QName name = reader.getName();
+ if (!"bindings".equals(name.getLocalPart())) {
+ Object element = null;
+ try {
+ element = processor.read(reader);
+ } catch (ContributionReadException e) {
+ throw e;
+ }
+ if (element instanceof Binding) {
+ bindings.add((Binding)element);
+ }
+ }
+ break;
+ case XMLStreamConstants.END_ELEMENT:
+ name = reader.getName();
+ if ("bindings".equals(name.getLocalPart())) {
+ exit = true;
+ }
+ break;
+ }
+ if (reader.hasNext()) {
+ reader.next();
+ } else {
+ exit = true;
+ }
+ }
+ return bindings;
+ }
+
+ public QName getArtifactType() {
+ return BindingDescriptions.BINDINGS_QNAME;
+ }
+
+ public void write(BindingDescriptions model, XMLStreamWriter writer) throws ContributionWriteException,
+ XMLStreamException {
+ writer.writeStartElement(BindingDescriptions.OSGI_SD_NS, "bindings");
+ for (Binding binding : model) {
+ processor.write(model, writer);
+ }
+ writer.writeEndElement();
+ }
+
+ public Class<BindingDescriptions> getModelType() {
+ return BindingDescriptions.class;
+ }
+
+ public void resolve(BindingDescriptions model, ModelResolver resolver) throws ContributionResolveException {
+ // TODO: To be implemented
+ }
+}
diff --git a/java/sca/modules/implementation-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/java/sca/modules/implementation-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
index 6407305a77..045159deae 100644
--- a/java/sca/modules/implementation-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
+++ b/java/sca/modules/implementation-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
@@ -19,3 +19,4 @@
org.apache.tuscany.sca.implementation.osgi.xml.OSGiImplementationProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#implementation.osgi,model=org.apache.tuscany.sca.implementation.osgi.OSGiImplementation
org.apache.tuscany.sca.implementation.osgi.xml.ServiceDescriptionsProcessor;qname=http://www.osgi.org/xmlns/sd/v1.0.0#service-descriptions,model=org.apache.tuscany.sca.implementation.osgi.ServiceDescriptions
org.apache.tuscany.sca.implementation.osgi.xml.OSGiPropertyProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#osgi.property,model=org.apache.tuscany.sca.implementation.osgi.OSGiProperty
+org.apache.tuscany.sca.implementation.osgi.xml.BindingDescriptionsProcessor;qname=http://www.osgi.org/xmlns/sd/v1.0.0#bindings,model=org.apache.tuscany.sca.implementation.osgi.BindingDescriptions \ No newline at end of file
diff --git a/java/sca/modules/node-impl-osgi/META-INF/MANIFEST.MF b/java/sca/modules/node-impl-osgi/META-INF/MANIFEST.MF
index 9ddf78f76e..d950198a5e 100644
--- a/java/sca/modules/node-impl-osgi/META-INF/MANIFEST.MF
+++ b/java/sca/modules/node-impl-osgi/META-INF/MANIFEST.MF
@@ -22,6 +22,10 @@ Import-Package: javax.xml.namespace,
org.apache.tuscany.sca.definitions.util;version="2.0.0",
org.apache.tuscany.sca.definitions.xml;version="2.0.0",
org.apache.tuscany.sca.extensibility.equinox;version="2.0.0",
+ org.apache.tuscany.sca.implementation.osgi;version="2.0.0",
+ org.apache.tuscany.sca.implementation.osgi.introspection;version="2.0.0",
+ org.apache.tuscany.sca.interfacedef;version="2.0.0",
+ org.apache.tuscany.sca.interfacedef.java;version="2.0.0",
org.apache.tuscany.sca.monitor;version="2.0.0",
org.apache.tuscany.sca.node;version="2.0.0",
org.apache.tuscany.sca.node.configuration;version="2.0.0",
@@ -33,9 +37,11 @@ Import-Package: javax.xml.namespace,
org.oasisopen.sca;version="2.0.0",
org.oasisopen.sca.annotation;version="2.0.0";resolution:=optional,
org.osgi.framework;version="1.4.0",
+ org.osgi.framework.hooks.service;version="1.0.0";resolution:=optional,
org.osgi.service.packageadmin;version="1.2.0";resolution:=optional,
org.osgi.util.tracker;version="1.3.3";resolution:=optional
Bundle-SymbolicName: org.apache.tuscany.sca.node.osgi.impl
Bundle-DocURL: http://www.apache.org/
Bundle-RequiredExecutionEnvironment: J2SE-1.5,JavaSE-1.6
Bundle-ActivationPolicy: lazy
+Export-Package: org.osgi.service.discovery;version="1.0"
diff --git a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/AbstractDiscoveryService.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/dosgi/discovery/AbstractDiscoveryService.java
index 75c5bc39f9..780fd73c95 100644
--- a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/AbstractDiscoveryService.java
+++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/dosgi/discovery/AbstractDiscoveryService.java
@@ -36,6 +36,8 @@ import java.util.logging.Logger;
import org.apache.tuscany.sca.assembly.Endpoint;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.node.NodeFactory;
+import org.apache.tuscany.sca.node.impl.NodeFactoryImpl;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Filter;
@@ -56,6 +58,8 @@ public abstract class AbstractDiscoveryService implements Discovery {
private final static Logger logger = Logger.getLogger(AbstractDiscoveryService.class.getName());
protected BundleContext context;
+ protected ExtensionPointRegistry registry;
+
private Map<String, List<DiscoveredServiceTracker>> filtersToTrackers =
new HashMap<String, List<DiscoveredServiceTracker>>();
private Map<String, List<DiscoveredServiceTracker>> interfacesToTrackers =
@@ -102,12 +106,14 @@ public abstract class AbstractDiscoveryService implements Discovery {
}
protected ExtensionPointRegistry getExtensionPointRegistry() {
+ NodeFactoryImpl factory = (NodeFactoryImpl) NodeFactory.newInstance();
+ factory.init();
ServiceTracker tracker = new ServiceTracker(context, ExtensionPointRegistry.class.getName(), null);
tracker.open();
// tracker.waitForService(1000);
- ExtensionPointRegistry extensionPointRegistry = (ExtensionPointRegistry)tracker.getService();
+ registry = (ExtensionPointRegistry)tracker.getService();
tracker.close();
- return extensionPointRegistry;
+ return registry;
}
private synchronized void cacheTracker(ServiceReference reference, Object service) {
diff --git a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/DiscoveredServiceNotificationImpl.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/dosgi/discovery/DiscoveredServiceNotificationImpl.java
index a110fa9528..a110fa9528 100644
--- a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/DiscoveredServiceNotificationImpl.java
+++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/dosgi/discovery/DiscoveredServiceNotificationImpl.java
diff --git a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/DiscoveryActivator.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/dosgi/discovery/DiscoveryActivator.java
index 9497619b5b..9497619b5b 100644
--- a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/DiscoveryActivator.java
+++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/dosgi/discovery/DiscoveryActivator.java
diff --git a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/DomainDiscoveryService.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/dosgi/discovery/DomainDiscoveryService.java
index 97eddfa9e5..3136c4cbc9 100644
--- a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/DomainDiscoveryService.java
+++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/dosgi/discovery/DomainDiscoveryService.java
@@ -27,7 +27,6 @@ import java.util.concurrent.ConcurrentHashMap;
import org.apache.tuscany.sca.assembly.Endpoint;
import org.apache.tuscany.sca.assembly.Implementation;
-import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.implementation.osgi.OSGiImplementation;
import org.apache.tuscany.sca.interfacedef.Interface;
@@ -51,8 +50,11 @@ public class DomainDiscoveryService extends AbstractDiscoveryService implements
public DomainDiscoveryService(BundleContext context) {
super(context);
+ init();
+ }
- ExtensionPointRegistry registry = getExtensionPointRegistry();
+ private void init() {
+ getExtensionPointRegistry();
this.endpointRegistry =
registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(EndpointRegistry.class);
this.endpointRegistry.addListener(this);
diff --git a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/EndpointDescription.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/dosgi/discovery/EndpointDescription.java
index 3f47183a56..3f47183a56 100644
--- a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/EndpointDescription.java
+++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/dosgi/discovery/EndpointDescription.java
diff --git a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/EndpointPublication.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/dosgi/discovery/EndpointPublication.java
index 184d3a12bf..184d3a12bf 100644
--- a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/EndpointPublication.java
+++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/dosgi/discovery/EndpointPublication.java
diff --git a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/LocalDiscoveryService.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/dosgi/discovery/LocalDiscoveryService.java
index d39ee4712f..43a19f98cc 100644
--- a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/LocalDiscoveryService.java
+++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/dosgi/discovery/LocalDiscoveryService.java
@@ -31,7 +31,6 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.implementation.osgi.ServiceDescriptions;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -40,12 +39,15 @@ import org.osgi.framework.BundleListener;
import org.osgi.service.discovery.ServiceEndpointDescription;
public class LocalDiscoveryService extends AbstractDiscoveryService implements BundleListener {
- private ExtensionPointRegistry registry;
public LocalDiscoveryService(BundleContext context) {
super(context);
+ init();
+ }
+
+ private void init() {
context.addBundleListener(this);
- this.registry = getExtensionPointRegistry();
+ getExtensionPointRegistry();
processExistingBundles();
}
diff --git a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/ServiceEndpointDescriptionImpl.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/dosgi/discovery/ServiceEndpointDescriptionImpl.java
index 949405472f..949405472f 100644
--- a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/ServiceEndpointDescriptionImpl.java
+++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/dosgi/discovery/ServiceEndpointDescriptionImpl.java
diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/NodeActivator.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/NodeActivator.java
index 43892d44d8..00b0b680be 100644
--- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/NodeActivator.java
+++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/NodeActivator.java
@@ -21,6 +21,7 @@ package org.apache.tuscany.sca.node.osgi.impl;
import static org.apache.tuscany.sca.node.osgi.impl.NodeManager.isSCABundle;
+import org.apache.tuscany.sca.dosgi.discovery.DiscoveryActivator;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
@@ -34,6 +35,9 @@ public class NodeActivator implements BundleActivator, SynchronousBundleListener
private static BundleContext bundleContext;
private boolean inited;
private NodeManager manager;
+
+ private DiscoveryActivator discoveryActivator = new DiscoveryActivator();
+ private OSGiServiceExporter exporter;
private void init() {
synchronized (this) {
@@ -49,6 +53,15 @@ public class NodeActivator implements BundleActivator, SynchronousBundleListener
public void start(BundleContext context) throws Exception {
bundleContext = context;
+
+ // FIXME: We should try to avoid aggressive initialization
+ init();
+
+ exporter = new OSGiServiceExporter(context);
+ exporter.start();
+
+ discoveryActivator.start(context);
+
boolean found = false;
for (Bundle b : context.getBundles()) {
if (isSCABundle(b)) {
@@ -67,6 +80,10 @@ public class NodeActivator implements BundleActivator, SynchronousBundleListener
public void stop(BundleContext context) throws Exception {
context.removeBundleListener(this);
bundleContext = null;
+ exporter.stop();
+ exporter = null;
+ discoveryActivator.stop(context);
+ discoveryActivator = null;
}
public static BundleContext getBundleContext() {
diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/NodeManager.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/NodeManager.java
index 3f71117c1a..6914e09b8e 100644
--- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/NodeManager.java
+++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/NodeManager.java
@@ -39,7 +39,7 @@ import org.osgi.framework.SynchronousBundleListener;
public class NodeManager implements SynchronousBundleListener, ServiceListener {
private static final Logger logger = Logger.getLogger(NodeManager.class.getName());
private BundleContext bundleContext;
- private OSGiNodeFactoryImpl factory;
+ OSGiNodeFactoryImpl factory;
public NodeManager(BundleContext bundleContext) {
super();
diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/OSGiServiceExporter.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/OSGiServiceExporter.java
new file mode 100644
index 0000000000..329ce09a5b
--- /dev/null
+++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/OSGiServiceExporter.java
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.node.osgi.impl;
+
+import java.util.Collections;
+
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.implementation.osgi.introspection.ExportedServiceIntrospector;
+import org.apache.tuscany.sca.node.Node;
+import org.apache.tuscany.sca.node.NodeFactory;
+import org.apache.tuscany.sca.node.configuration.NodeConfiguration;
+import org.apache.tuscany.sca.node.impl.NodeFactoryImpl;
+import org.apache.tuscany.sca.node.impl.NodeImpl;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
+
+/**
+ * Watching and exporting OSGi services
+ */
+public class OSGiServiceExporter implements ServiceTrackerCustomizer {
+ private ExtensionPointRegistry registry;
+ private BundleContext context;
+ private ServiceTracker serviceTracker;
+ private NodeFactoryImpl nodeFactory;
+ private ExportedServiceIntrospector introspector;
+
+ /**
+ * @param context
+ * @param clazz
+ * @param customizer
+ */
+ public OSGiServiceExporter(BundleContext context) {
+ this.context = context;
+ }
+
+ private synchronized void init() {
+ if (nodeFactory == null) {
+ this.nodeFactory = (NodeFactoryImpl)NodeFactory.newInstance();
+ this.nodeFactory.init();
+ this.introspector = new ExportedServiceIntrospector(getExtensionPointRegistry());
+ }
+ }
+
+ public void start() {
+ String filterStr = "(& (osgi.remote.configuration.type=sca) (osgi.remote.interfaces=*) (!(osgi.remote=true)) )";
+ try {
+ Filter filter = context.createFilter(filterStr);
+ serviceTracker = new ServiceTracker(context, filter, this);
+ serviceTracker.open(true);
+ } catch (InvalidSyntaxException e) {
+ // Ignore
+ }
+ }
+
+ public void stop() {
+ if (serviceTracker != null) {
+ serviceTracker.close();
+ serviceTracker = null;
+ }
+ }
+
+ public Object addingService(ServiceReference reference) {
+ init();
+ try {
+ Contribution contribution = introspector.introspect(reference);
+ if (contribution != null) {
+
+ NodeConfiguration configuration = nodeFactory.createNodeConfiguration();
+ configuration.setURI(String.valueOf(reference.getProperty("service.id")));
+ configuration.getExtensions().add(reference.getBundle());
+ // FIXME: Configure the domain and node URI
+ NodeImpl node = new NodeImpl(nodeFactory, configuration, Collections.singletonList(contribution));
+ return node.start();
+ } else {
+ return null;
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ public void modifiedService(ServiceReference reference, Object service) {
+ Node node = (Node)service;
+ node.stop();
+ node.start();
+ }
+
+ public void removedService(ServiceReference reference, Object service) {
+ Node node = (Node)service;
+ node.stop();
+ }
+
+ protected ExtensionPointRegistry getExtensionPointRegistry() {
+ if (registry == null) {
+ ServiceTracker tracker = new ServiceTracker(context, ExtensionPointRegistry.class.getName(), null);
+ tracker.open();
+ // tracker.waitForService(1000);
+ registry = (ExtensionPointRegistry)tracker.getService();
+ tracker.close();
+ }
+ return registry;
+ }
+
+}
diff --git a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/osgi/service/discovery/DiscoveredServiceNotification.java b/java/sca/modules/node-impl-osgi/src/main/java/org/osgi/service/discovery/DiscoveredServiceNotification.java
index 57de9c7c9d..57de9c7c9d 100644
--- a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/osgi/service/discovery/DiscoveredServiceNotification.java
+++ b/java/sca/modules/node-impl-osgi/src/main/java/org/osgi/service/discovery/DiscoveredServiceNotification.java
diff --git a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/osgi/service/discovery/DiscoveredServiceTracker.java b/java/sca/modules/node-impl-osgi/src/main/java/org/osgi/service/discovery/DiscoveredServiceTracker.java
index efd158a2f5..efd158a2f5 100644
--- a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/osgi/service/discovery/DiscoveredServiceTracker.java
+++ b/java/sca/modules/node-impl-osgi/src/main/java/org/osgi/service/discovery/DiscoveredServiceTracker.java
diff --git a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/osgi/service/discovery/Discovery.java b/java/sca/modules/node-impl-osgi/src/main/java/org/osgi/service/discovery/Discovery.java
index cca766a032..cca766a032 100644
--- a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/osgi/service/discovery/Discovery.java
+++ b/java/sca/modules/node-impl-osgi/src/main/java/org/osgi/service/discovery/Discovery.java
diff --git a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/osgi/service/discovery/ServiceEndpointDescription.java b/java/sca/modules/node-impl-osgi/src/main/java/org/osgi/service/discovery/ServiceEndpointDescription.java
index e1f389ea78..e1f389ea78 100644
--- a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/osgi/service/discovery/ServiceEndpointDescription.java
+++ b/java/sca/modules/node-impl-osgi/src/main/java/org/osgi/service/discovery/ServiceEndpointDescription.java
diff --git a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/osgi/service/discovery/ServicePublication.java b/java/sca/modules/node-impl-osgi/src/main/java/org/osgi/service/discovery/ServicePublication.java
index 9b4cb4c905..9b4cb4c905 100644
--- a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/osgi/service/discovery/ServicePublication.java
+++ b/java/sca/modules/node-impl-osgi/src/main/java/org/osgi/service/discovery/ServicePublication.java
diff --git a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java
index 851f5fbe89..2f933486b1 100644
--- a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java
+++ b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java
@@ -24,10 +24,13 @@ import static org.apache.tuscany.sca.node.impl.NodeUtil.createURI;
import static org.apache.tuscany.sca.node.impl.NodeUtil.openStream;
import java.io.File;
+import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringReader;
+import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.security.AccessController;
@@ -433,20 +436,6 @@ public class NodeFactoryImpl extends NodeFactory {
DefinitionsUtil.aggregate(defs, systemDefinitions);
}
- /*
- // Load the system definitions.xml from all of the loaded extension points
- DefinitionsProviderExtensionPoint definitionsProviders = extensionPoints.getExtensionPoint(DefinitionsProviderExtensionPoint.class);
-
- // aggregate all the definitions into a single definitions model
- try {
- for (DefinitionsProvider definitionsProvider : definitionsProviders.getDefinitionsProviders()) {
- DefinitionsUtil.aggregate(definitionsProvider.getDefinitions(), systemDefinitions);
- }
- } catch (DefinitionsProviderException e) {
- throw new IllegalStateException(e);
- }
- */
-
// create a system contribution to hold the definitions. The contribution
// will be extended later with definitions from application contributions
systemContribution = contributionFactory.createContribution();
@@ -477,63 +466,12 @@ public class NodeFactoryImpl extends NodeFactory {
return new DefaultExtensionPointRegistry();
}
- Composite configureNode(NodeConfiguration configuration) throws Exception {
-
- List<Contribution> contributions = new ArrayList<Contribution>();
-
- // Load the specified contributions
- for (ContributionConfiguration contrib : configuration.getContributions()) {
- URI contributionURI = createURI(contrib.getURI());
-
- URI uri = createURI(contrib.getLocation());
- if (uri.getScheme() == null) {
- uri = new File(contrib.getLocation()).toURI();
- }
- URL contributionURL = uri.toURL();
-
- // Load the contribution
- logger.log(Level.INFO, "Loading contribution: " + contributionURL);
- Contribution contribution = contributionProcessor.read(null, contributionURI, contributionURL);
- contributions.add(contribution);
-
- boolean attached = false;
- for (DeploymentComposite dc : contrib.getDeploymentComposites()) {
- if (dc.getContent() != null) {
- Reader xml = new StringReader(dc.getContent());
- attached = attachDeploymentComposite(contribution, xml, null, attached);
- } else if (dc.getLocation() != null) {
- URI dcURI = createURI(dc.getLocation());
- if (!dcURI.isAbsolute()) {
- Composite composite = null;
- // The location is pointing to an artifact within the contribution
- for (Artifact a : contribution.getArtifacts()) {
- if (dcURI.toString().equals(a.getURI())) {
- composite = (Composite)a.getModel();
- if (!attached) {
- contribution.getDeployables().clear();
- attached = true;
- }
- contribution.getDeployables().add(composite);
- break;
- }
- }
- if (composite == null) {
- // Not found
- throw new ServiceRuntimeException("Deployment composite " + dcURI
- + " cannot be found within contribution "
- + contribution.getLocation());
- }
- } else {
- URL url = dcURI.toURL();
- InputStream is = openStream(url);
- Reader xml = new InputStreamReader(is, "UTF-8");
- attached = attachDeploymentComposite(contribution, xml, url.toString(), attached);
- }
- }
- }
- analyzeProblems();
+ protected Composite configureNode(NodeConfiguration configuration, List<Contribution> contributions)
+ throws Exception {
+ if (contributions == null) {
+ // Load contributions
+ contributions = loadContributions(configuration);
}
-
// Build an aggregated SCA definitions model. Must be done before we try and
// resolve any contributions or composites as they may depend on the full
// definitions.xml picture
@@ -613,7 +551,65 @@ public class NodeFactoryImpl extends NodeFactory {
analyzeProblems();
return tempComposite;
+ }
+
+ private List<Contribution> loadContributions(NodeConfiguration configuration) throws MalformedURLException,
+ ContributionReadException, XMLStreamException, IOException, UnsupportedEncodingException, Exception {
+ List<Contribution> contributions = new ArrayList<Contribution>();
+
+ // Load the specified contributions
+ for (ContributionConfiguration contrib : configuration.getContributions()) {
+ URI contributionURI = createURI(contrib.getURI());
+
+ URI uri = createURI(contrib.getLocation());
+ if (uri.getScheme() == null) {
+ uri = new File(contrib.getLocation()).toURI();
+ }
+ URL contributionURL = uri.toURL();
+ // Load the contribution
+ logger.log(Level.INFO, "Loading contribution: " + contributionURL);
+ Contribution contribution = contributionProcessor.read(null, contributionURI, contributionURL);
+ contributions.add(contribution);
+
+ boolean attached = false;
+ for (DeploymentComposite dc : contrib.getDeploymentComposites()) {
+ if (dc.getContent() != null) {
+ Reader xml = new StringReader(dc.getContent());
+ attached = attachDeploymentComposite(contribution, xml, null, attached);
+ } else if (dc.getLocation() != null) {
+ URI dcURI = createURI(dc.getLocation());
+ if (!dcURI.isAbsolute()) {
+ Composite composite = null;
+ // The location is pointing to an artifact within the contribution
+ for (Artifact a : contribution.getArtifacts()) {
+ if (dcURI.toString().equals(a.getURI())) {
+ composite = (Composite)a.getModel();
+ if (!attached) {
+ contribution.getDeployables().clear();
+ attached = true;
+ }
+ contribution.getDeployables().add(composite);
+ break;
+ }
+ }
+ if (composite == null) {
+ // Not found
+ throw new ServiceRuntimeException("Deployment composite " + dcURI
+ + " cannot be found within contribution "
+ + contribution.getLocation());
+ }
+ } else {
+ URL url = dcURI.toURL();
+ InputStream is = openStream(url);
+ Reader xml = new InputStreamReader(is, "UTF-8");
+ attached = attachDeploymentComposite(contribution, xml, url.toString(), attached);
+ }
+ }
+ }
+ analyzeProblems();
+ }
+ return contributions;
}
protected static class NodeKey {
diff --git a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
index 606c4b8c50..a35f078860 100644
--- a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
+++ b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
@@ -33,6 +33,7 @@ import org.apache.tuscany.sca.assembly.Composite;
import org.apache.tuscany.sca.assembly.CompositeService;
import org.apache.tuscany.sca.assembly.Endpoint;
import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.contribution.Contribution;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.core.assembly.ActivationException;
@@ -59,14 +60,32 @@ public class NodeImpl implements Node, Client {
private CompositeActivator compositeActivator;
private NodeConfiguration configuration;
private NodeFactoryImpl manager;
-
+ private List<Contribution> contributions;
private NodeManager mbean;
+ /**
+ * Create a node from the configuration
+ * @param manager
+ * @param configuration
+ */
public NodeImpl(NodeFactoryImpl manager, NodeConfiguration configuration) {
super();
this.configuration = configuration;
this.manager = manager;
}
+
+ /**
+ * Create a node from the configuration and loaded contributions
+ * @param manager
+ * @param configuration
+ * @param contributions
+ */
+ public NodeImpl(NodeFactoryImpl manager, NodeConfiguration configuration, List<Contribution> contributions) {
+ super();
+ this.configuration = configuration;
+ this.manager = manager;
+ this.contributions = new ArrayList<Contribution>(contributions);
+ }
public String getURI() {
return getConfiguration().getURI();
@@ -83,10 +102,12 @@ public class NodeImpl implements Node, Client {
this.proxyFactory = manager.proxyFactory;
this.compositeActivator =
manager.extensionPoints.getExtensionPoint(UtilityExtensionPoint.class).getUtility(CompositeActivator.class,
- this);
+ manager.getNodeKey(configuration));
try {
+ Composite composite = manager.configureNode(configuration, contributions);
+
// get the top level composite for this node
- compositeActivator.setDomainComposite(manager.configureNode(configuration));
+ compositeActivator.setDomainComposite(composite);
// Activate the composite
compositeActivator.activate(compositeActivator.getDomainComposite());
diff --git a/java/sca/modules/node-launcher-equinox/pom.xml b/java/sca/modules/node-launcher-equinox/pom.xml
index 45d6ecc970..b26ca52daa 100644
--- a/java/sca/modules/node-launcher-equinox/pom.xml
+++ b/java/sca/modules/node-launcher-equinox/pom.xml
@@ -40,7 +40,7 @@
<dependency>
<groupId>org.eclipse</groupId>
<artifactId>osgi</artifactId>
- <version>3.4.0-v20080605-1900</version>
+ <version>3.5.0-v20090520</version>
<scope>compile</scope>
</dependency>
@@ -61,7 +61,7 @@
<dependency>
<groupId>org.eclipse.equinox</groupId>
<artifactId>app</artifactId>
- <version>1.0.0-v20070606</version>
+ <version>1.2.0-v20090520-1800</version>
<scope>runtime</scope>
</dependency>
-->
diff --git a/java/sca/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java b/java/sca/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java
index 3853873896..f9f91202ba 100644
--- a/java/sca/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java
+++ b/java/sca/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java
@@ -20,14 +20,14 @@
package org.apache.tuscany.sca.xsd.xml;
import java.io.IOException;
-import java.net.URL;
import java.net.URI;
import java.net.URISyntaxException;
+import java.net.URL;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Collections;
import org.apache.tuscany.sca.contribution.Artifact;
import org.apache.tuscany.sca.contribution.Contribution;
@@ -148,14 +148,19 @@ public class XSDModelResolver implements ModelResolver {
return;
}
// Read an XSD document
- InputSource xsd = XMLDocumentHelper.getInputSource(definition.getLocation().toURL());
+ XmlSchema schema = null;
for (XmlSchema d : schemaCollection.getXmlSchemas()) {
if (d.getTargetNamespace().equals(definition.getNamespace())) {
- if (d.getSourceURI().equals(definition.getLocation().toString()))
- return;
+ if (d.getSourceURI().equals(definition.getLocation().toString())) {
+ schema = d;
+ break;
+ }
}
}
- XmlSchema schema = schemaCollection.read(xsd, null);
+ if (schema == null) {
+ InputSource xsd = XMLDocumentHelper.getInputSource(definition.getLocation().toURL());
+ schema = schemaCollection.read(xsd, null);
+ }
definition.setSchemaCollection(schemaCollection);
definition.setSchema(schema);
}