summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/node-impl-osgi/src/main
diff options
context:
space:
mode:
authorslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2010-04-22 15:08:08 +0000
committerslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2010-04-22 15:08:08 +0000
commit1a8b5e5f74351ca496c243a4949bc07d9f5177c0 (patch)
treeead6037cdd2ae022f1e33f8a3e72922cafa743cd /sca-java-2.x/trunk/modules/node-impl-osgi/src/main
parent082884141610be91c2c615f9effb3da875c2d6c2 (diff)
Add code to add the org.osgi.sca.config.xml property to the exported service. See page 450 of the OSGi 4.2 enterprise spec for an example of what the exported endpoint description should look like.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@936890 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/node-impl-osgi/src/main')
-rw-r--r--sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointIntrospector.java56
-rw-r--r--sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceExporter.java20
2 files changed, 73 insertions, 3 deletions
diff --git a/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointIntrospector.java b/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointIntrospector.java
index 22bcb5af41..94ad7fbfc7 100644
--- a/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointIntrospector.java
+++ b/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointIntrospector.java
@@ -21,11 +21,14 @@ package org.apache.tuscany.sca.osgi.remoteserviceadmin.impl;
import static org.apache.tuscany.sca.assembly.Base.SCA11_TUSCANY_NS;
import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.SCA_BINDINGS;
+import static org.apache.tuscany.sca.osgi.remoteserviceadmin.impl.OSGiHelper.createOSGiProperty;
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;
import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -39,6 +42,7 @@ import java.util.UUID;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
import org.apache.tuscany.sca.assembly.AssemblyFactory;
import org.apache.tuscany.sca.assembly.Base;
@@ -65,6 +69,7 @@ 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.implementation.osgi.ServiceDescriptionsFactory;
import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException;
import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract;
@@ -73,7 +78,9 @@ import org.apache.tuscany.sca.osgi.service.discovery.impl.LocalDiscoveryService;
import org.apache.tuscany.sca.osgi.service.discovery.impl.LocalDiscoveryService.ExtenderConfiguration;
import org.apache.tuscany.sca.policy.Intent;
import org.apache.tuscany.sca.policy.PolicyFactory;
+import org.apache.tuscany.sca.policy.PolicySet;
import org.oasisopen.sca.ServiceRuntimeException;
+import org.oasisopen.sca.annotation.PolicySets;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
@@ -91,7 +98,7 @@ public class EndpointIntrospector {
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;
@@ -125,6 +132,7 @@ public class EndpointIntrospector {
*/
public EndpointIntrospector(BundleContext context, ExtensionPointRegistry registry, ServiceTracker discoveryTracker) {
super();
+ this.registry = registry;
// this.context = context;
this.discoveryTracker = discoveryTracker;
this.factories = registry.getExtensionPoint(FactoryExtensionPoint.class);
@@ -266,6 +274,48 @@ public class EndpointIntrospector {
return contribution;
}
+ public String instrospectSCAConfig(ServiceReference reference, Map<String, Object> props, ComponentService service){
+
+ ServiceDescriptionsFactory serviceDescriptionFactory = registry.getExtensionPoint(ServiceDescriptionsFactory.class);
+ SCAConfig scaConfig = serviceDescriptionFactory.createSCAConfig();
+
+ // add the binding configurations
+ List<Binding> bindings = scaConfig.getBindings();
+ bindings.addAll(service.getBindings());
+
+ // add the intent configurations
+ List<Intent> intents = scaConfig.getIntents();
+ intents.addAll(service.getRequiredIntents());
+
+ // add the policy set configurations
+ List<PolicySet> policySets = scaConfig.getPolicySets();
+ policySets.addAll(service.getPolicySets());
+
+ // set up the target namespace
+ // TODO - there is a bug in the spec which only allow bindings from one
+ // namsepace to be included in sca-config element. Here we just
+ // the first bindings namespace
+ Map<String, Object> properties = getProperties(reference, props);
+ String[] bindingNames = getStringArray(properties.get(SCA_BINDINGS));
+ if (bindingNames.length > 0){
+ QName firstBindingQName = getQName(bindingNames[0]);
+ scaConfig.setTargetNamespace(firstBindingQName.getNamespaceURI());
+ }
+
+ // write the sca config out to XML
+ String scaConfigXMLString = "";
+
+ try {
+ Writer writer = new StringWriter();
+ deployer.saveXMLDocument(scaConfig, writer, deployer.createMonitor());
+ scaConfigXMLString = writer.toString();
+ } catch (Exception ex){
+ throw new ServiceRuntimeException(ex);
+ }
+
+ return scaConfigXMLString;
+ }
+
/*
public Contribution loadContribution(Bundle bundle, Composite composite) {
try {
@@ -474,8 +524,8 @@ public class EndpointIntrospector {
for (ExtenderConfiguration config : discoveryService.getConfigurations()) {
for (SCAConfig sc : config.getSCAConfigs()) {
for (QName bindingName : bindingNames) {
- if ("".equals(bindingName.getNamespaceURI()) || sc.getTargetNamespace().equals(bindingName
- .getNamespaceURI())) {
+ if ("".equals(bindingName.getNamespaceURI()) ||
+ sc.getTargetNamespace().equals(bindingName.getNamespaceURI())) {
for (Binding binding : sc.getBindings()) {
if (bindingName.getLocalPart().equals(binding.getName())) {
// We need to check duplications
diff --git a/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceExporter.java b/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceExporter.java
index 4466c04563..081a3a60c0 100644
--- a/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceExporter.java
+++ b/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceExporter.java
@@ -35,10 +35,14 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
+import org.apache.tuscany.sca.assembly.Binding;
import org.apache.tuscany.sca.assembly.Component;
import org.apache.tuscany.sca.assembly.ComponentService;
import org.apache.tuscany.sca.assembly.Endpoint;
import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.implementation.osgi.OSGiProperty;
+import org.apache.tuscany.sca.implementation.osgi.SCAConfig;
+import org.apache.tuscany.sca.implementation.osgi.ServiceDescriptionsFactory;
import org.apache.tuscany.sca.node.configuration.NodeConfiguration;
import org.apache.tuscany.sca.node.impl.NodeImpl;
import org.osgi.framework.BundleContext;
@@ -102,6 +106,9 @@ public class OSGiServiceExporter extends AbstractOSGiServiceHandler implements S
.getBundleContext())));
service.getExtensions().add(createOSGiProperty(registry, ENDPOINT_SERVICE_ID, reference
.getProperty(SERVICE_ID)));
+
+ // create the org.osgi.sca.config.xml property
+ service.getExtensions().add(createSCAConfigXMLProperty(reference, properties, service));
// FIXME: Configure the domain and node URI
NodeImpl node = new NodeImpl(nodeFactory, configuration, Collections.singletonList(contribution));
@@ -140,4 +147,17 @@ public class OSGiServiceExporter extends AbstractOSGiServiceHandler implements S
exportRegistration.close();
}
}
+
+ private OSGiProperty createSCAConfigXMLProperty(ServiceReference reference, Map<String, Object> props, ComponentService service){
+
+ // create the <sca-config> element
+ String scaConfigXMLString = introspector.instrospectSCAConfig(reference, props, service);
+
+ // wrap the <sca-config> element in an <xml> element
+ String scaConfigXMLStringWithoutXMLHeader = scaConfigXMLString.substring(scaConfigXMLString.indexOf("><") + 1);
+ scaConfigXMLString = "<xml>" + scaConfigXMLStringWithoutXMLHeader + "</xml>";
+
+ // create and return the OSGI property
+ return createOSGiProperty(registry, "org.osgi.sca.config.xml", scaConfigXMLString);
+ }
}