summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/implementation-osgi/src
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2010-01-09 18:00:24 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2010-01-09 18:00:24 +0000
commitde3ec14e972052db72a3fd9589c898cf3ae0ae26 (patch)
tree12bc5ebe1034ca71a59e0faf1596f8b76cb5948b /sca-java-2.x/trunk/modules/implementation-osgi/src
parent9c79f7307e589f0e4921f7ec1505fd0bff3eb9f1 (diff)
Update to the latest version of OSGi enterprise draft specs
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@897502 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/implementation-osgi/src')
-rw-r--r--sca-java-2.x/trunk/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/ServiceDescriptions.java8
-rw-r--r--sca-java-2.x/trunk/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/ServiceDescriptionImpl.java8
-rw-r--r--sca-java-2.x/trunk/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsProcessor.java198
-rw-r--r--sca-java-2.x/trunk/modules/implementation-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor2
-rw-r--r--sca-java-2.x/trunk/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsTestCase.java50
5 files changed, 167 insertions, 99 deletions
diff --git a/sca-java-2.x/trunk/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/ServiceDescriptions.java b/sca-java-2.x/trunk/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/ServiceDescriptions.java
index 35866938d6..a5322429ff 100644
--- a/sca-java-2.x/trunk/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/ServiceDescriptions.java
+++ b/sca-java-2.x/trunk/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/ServiceDescriptions.java
@@ -29,8 +29,10 @@ import javax.xml.namespace.QName;
public interface ServiceDescriptions extends List<ServiceDescription> {
String REMOTE_SERVICE_FOLDER = "OSGI-INF/remote-service";
- String OSGI_SD_NS = "http://www.osgi.org/xmlns/sd/v1.0.0";
- QName SERVICE_DESCRIPTIONS_QNAME = new QName(OSGI_SD_NS, "service-descriptions");
- QName SERVICE_DESCRIPTION_QNAME = new QName(OSGI_SD_NS, "service-description");
+ String OSGI_SD_NS = "http://www.osgi.org/xmlns/rsa/v1.0.0";
+ QName SERVICE_DESCRIPTIONS_QNAME = new QName(OSGI_SD_NS, "endpoint-descriptions");
+ QName SERVICE_DESCRIPTION_QNAME = new QName(OSGI_SD_NS, "endpoint-description");
+ QName PROPERTY_QNAME = new QName(OSGI_SD_NS, "property");
+ QName XML_QNAME = new QName(OSGI_SD_NS, "xml");
String REMOTE_SERVICE_HEADER = "Remote-Service";
}
diff --git a/sca-java-2.x/trunk/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/ServiceDescriptionImpl.java b/sca-java-2.x/trunk/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/ServiceDescriptionImpl.java
index b990cf5980..1ffe16bf71 100644
--- a/sca-java-2.x/trunk/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/ServiceDescriptionImpl.java
+++ b/sca-java-2.x/trunk/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/ServiceDescriptionImpl.java
@@ -19,18 +19,18 @@
package org.apache.tuscany.sca.implementation.osgi.impl;
-import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.tuscany.sca.implementation.osgi.ServiceDescription;
+import org.osgi.framework.Constants;
/**
* The OSGi RFC 119 description of a remote OSGi service
*/
public class ServiceDescriptionImpl implements ServiceDescription {
- private List<String> interfaces = new ArrayList<String>();
private Map<String, Object> properties = new HashMap<String, Object>();
protected ServiceDescriptionImpl() {
@@ -38,7 +38,7 @@ public class ServiceDescriptionImpl implements ServiceDescription {
}
public List<String> getInterfaces() {
- return interfaces;
+ return Arrays.asList((String[])properties.get(Constants.OBJECTCLASS));
}
public Map<String, Object> getProperties() {
@@ -46,6 +46,6 @@ public class ServiceDescriptionImpl implements ServiceDescription {
}
public String toString() {
- return "service-description: interfaces=" + interfaces + " properties=" + properties;
+ return "service-description: " + properties;
}
}
diff --git a/sca-java-2.x/trunk/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsProcessor.java b/sca-java-2.x/trunk/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsProcessor.java
index fc6e44d8d6..891fed13d0 100644
--- a/sca-java-2.x/trunk/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsProcessor.java
+++ b/sca-java-2.x/trunk/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsProcessor.java
@@ -19,6 +19,9 @@
package org.apache.tuscany.sca.implementation.osgi.xml;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
import java.util.StringTokenizer;
import javax.xml.namespace.QName;
@@ -39,98 +42,118 @@ import org.apache.tuscany.sca.core.FactoryExtensionPoint;
import org.apache.tuscany.sca.implementation.osgi.ServiceDescription;
import org.apache.tuscany.sca.implementation.osgi.ServiceDescriptions;
import org.apache.tuscany.sca.implementation.osgi.ServiceDescriptionsFactory;
+import org.osgi.framework.Constants;
/*
<?xml version="1.0" encoding="UTF-8"?>
-<service-descriptions xmlns="http://www.osgi.org/xmlns/sd/v1.0.0">
- <service-description>
- <provide interface="com.iona.soa.pojo.hello.HelloService"/>
- <property name="service.intents">SOAP HTTP</property>
- <property name="osgi.remote.configuration.type">pojo</property>
- <property name="osgi.remote.configuration.pojo.address">
- http://localhost:9000/hello
+<endpoint-descriptions xmlns="http://www.osgi.org/xmlns/rsa/v1.0.0">
+ <endpoint-description>
+ <property name="service.intents">
+ <list>
+ <value>SOAP</value>
+ <value>HTTP</value>
+ </list>
</property>
- </service-description>
- <service-description>
- <provide interface="com.iona.soa.pojo.hello.GreeterService"/>
- <property name="service.intents">SOAP HTTP</property>
- <property name="osgi.remote.configuration.type">pojo</property>
- <property name="osgi.remote.configuration.pojo.address">
- http://localhost:9005/greeter
+ <property name="endpoint.id" value="http://ws.acme.com:9000/hello"/>
+ <property name="objectClass" value="com.acme.Foo"/>
+ <property name="endpoint.package.version.com.acme" value="4.2"/>
+ <property name="service.imported.configs" value="com.acme"/>
+ <property name="com.acme.ws.xml">
+ <xml>
+ <config xmlns="http://acme.com/defs">
+ <port>1029</port>
+ <host>www.acme.com</host>
+ </config>
+ </xml>
</property>
- </service-description>
-</service-descriptions>
+ </endpoint-description>
+</endpoint-descriptions>
*/
public class ServiceDescriptionsProcessor extends BaseStAXArtifactProcessor implements
StAXArtifactProcessor<ServiceDescriptions> {
private ServiceDescriptionsFactory factory;
private StAXArtifactProcessor processor;
-
- public ServiceDescriptionsProcessor(ExtensionPointRegistry registry,
- StAXArtifactProcessor processor) {
+ public ServiceDescriptionsProcessor(ExtensionPointRegistry registry, StAXArtifactProcessor processor) {
this.processor = processor;
FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class);
this.factory = modelFactories.getFactory(ServiceDescriptionsFactory.class);
}
- public ServiceDescriptions read(XMLStreamReader reader, ProcessorContext context) throws XMLStreamException, ContributionReadException {
+ public ServiceDescriptions read(XMLStreamReader reader, ProcessorContext context) throws XMLStreamException,
+ ContributionReadException {
int event = reader.getEventType();
- ServiceDescriptions sds = factory.createServiceDescriptions();
+ ServiceDescriptions sds = null;
ServiceDescription sd = null;
+ String propertyName = null;
+ String propertyType = "String";
+ Object propertyValue = null;
+ String propertyLiteral = null;
+ boolean xml = false;
+ boolean multiValued = false;
while (true) {
switch (event) {
case XMLStreamConstants.START_ELEMENT:
QName name = reader.getName();
- if (ServiceDescriptions.SERVICE_DESCRIPTION_QNAME.equals(name)) {
+ if (ServiceDescriptions.SERVICE_DESCRIPTIONS_QNAME.equals(name)) {
+ sds = factory.createServiceDescriptions();
+ } else if (ServiceDescriptions.SERVICE_DESCRIPTION_QNAME.equals(name)) {
sd = factory.createServiceDescription();
sds.add(sd);
- } else if ("provide".equals(name.getLocalPart())) {
- String interfaceName = reader.getAttributeValue(null, "interface");
- if (interfaceName != null) {
- sd.getInterfaces().add(interfaceName);
- }
} else if ("property".equals(name.getLocalPart())) {
- String propName = reader.getAttributeValue(null, "name");
- String propValue = reader.getAttributeValue(null, "value");
- String propType = reader.getAttributeValue(null, "type");
- if (propType == null) {
- propType = "String";
+ multiValued = false;
+ propertyName = reader.getAttributeValue(null, "name");
+ propertyType = reader.getAttributeValue(null, "value-type");
+ if (propertyType == null) {
+ propertyType = "String";
+ }
+ propertyLiteral = reader.getAttributeValue(null, "value");
+ // if (propertyLiteral == null) {
+ // propertyLiteral = reader.getElementText();
+ // }
+ if (propertyLiteral != null) {
+ propertyLiteral = propertyLiteral.trim();
+ propertyValue = getPropertyValue(reader, propertyName, propertyLiteral, propertyType);
}
- if (propValue == null) {
- propValue = reader.getElementText();
+ } else if ("list".equals(name.getLocalPart())) {
+ if (propertyValue != null) {
+ throw new IllegalArgumentException("@value and <list> are both present");
}
- if (propValue != null) {
- propValue = propValue.trim();
+ propertyValue = new ArrayList<Object>();
+ multiValued = true;
+ } else if ("array".equals(name.getLocalPart())) {
+ if (propertyValue != null) {
+ throw new IllegalArgumentException("@value and <array> are both present");
}
- Object prop = propValue;
- if ("Integer".equals(propType)) {
- prop = Integer.valueOf(propValue);
- } else if ("Long".equals(propType)) {
- prop = Long.valueOf(propValue);
- } else if ("Float".equals(propType)) {
- prop = Float.valueOf(propValue);
- } else if ("Double".equals(propType)) {
- prop = Double.valueOf(propValue);
- } else if ("Short".equals(propType)) {
- prop = Short.valueOf(propValue);
- } else if ("Character".equals(propType)) {
- prop = propValue.charAt(0);
- } else if ("Byte".equals(propType)) {
- prop = Byte.valueOf(propValue);
- } else if ("Boolean".equals(propType)) {
- prop = Boolean.valueOf(propValue);
+ propertyValue = new ArrayList<Object>();
+ multiValued = true;
+ } else if ("set".equals(name.getLocalPart())) {
+ if (propertyValue != null) {
+ throw new IllegalArgumentException("@value and <set> are both present");
}
- if (propName.endsWith(".intents")) {
- prop = toQNames(reader, propValue);
+ propertyValue = new HashSet<Object>();
+ multiValued = true;
+ } else if ("xml".equals(name.getLocalPart())) {
+ xml = true;
+ } else if ("value".equals(name.getLocalPart())) {
+ propertyLiteral = reader.getElementText();
+ if (propertyLiteral != null) {
+ propertyLiteral = propertyLiteral.trim();
+ Object value = getPropertyValue(reader, propertyName, propertyLiteral, propertyType);
+ if (multiValued && (propertyValue instanceof Collection)) {
+ ((Collection)propertyValue).add(value);
+ } else if (propertyValue == null) {
+ propertyValue = value;
+ }
}
- sd.getProperties().put(propName, prop);
} else {
- name = reader.getName();
- if (!ServiceDescriptions.SERVICE_DESCRIPTIONS_QNAME.equals(name)) {
- Object ext = processor.read(reader, context);
- if (sd != null) {
- sd.getProperties().put(name.toString(), ext);
+ // FIXME: [rfeng] The rsa spec says the XML should be saved as String
+ Object value = processor.read(reader, context);
+ if (xml) {
+ if (multiValued && (propertyValue instanceof Collection)) {
+ ((Collection)propertyValue).add(value);
+ } else if (propertyValue == null) {
+ propertyValue = value;
}
}
}
@@ -140,8 +163,20 @@ public class ServiceDescriptionsProcessor extends BaseStAXArtifactProcessor impl
if (ServiceDescriptions.SERVICE_DESCRIPTION_QNAME.equals(name)) {
// Reset the sd
sd = null;
- }
- if (ServiceDescriptions.SERVICE_DESCRIPTIONS_QNAME.equals(name)) {
+ } else if (ServiceDescriptions.PROPERTY_QNAME.equals(name)) {
+ if (sd != null && propertyName != null) {
+ if (propertyValue == null) {
+ throw new IllegalArgumentException("No value is defined for " + propertyName);
+ }
+ sd.getProperties().put(propertyName, propertyValue);
+ }
+ propertyName = null;
+ propertyType = "String";
+ propertyValue = null;
+ multiValued = false;
+ } else if (ServiceDescriptions.XML_QNAME.equals(name)) {
+ xml = false;
+ } else if (ServiceDescriptions.SERVICE_DESCRIPTIONS_QNAME.equals(name)) {
return sds;
}
break;
@@ -154,6 +189,35 @@ public class ServiceDescriptionsProcessor extends BaseStAXArtifactProcessor impl
}
}
+ private Object getPropertyValue(XMLStreamReader reader, String propertyName, String propertyLiteral, String propType) {
+ Object propertyValue = null;
+ propertyValue = propertyLiteral;
+ if ("Integer".equals(propType) || "int".equals(propType)) {
+ propertyValue = Integer.valueOf(propertyLiteral);
+ } else if ("Long".equals(propType) || "long".equals(propType)) {
+ propertyValue = Long.valueOf(propertyLiteral);
+ } else if ("Float".equals(propType) || "float".equals(propType)) {
+ propertyValue = Float.valueOf(propertyLiteral);
+ } else if ("Double".equals(propType) || "double".equals(propType)) {
+ propertyValue = Double.valueOf(propertyLiteral);
+ } else if ("Short".equals(propType) || "short".equals(propType)) {
+ propertyValue = Short.valueOf(propertyLiteral);
+ } else if ("Character".equals(propType) || "char".equals(propType)) {
+ propertyValue = propertyLiteral.charAt(0);
+ } else if ("Byte".equals(propType) || "byte".equals(propType)) {
+ propertyValue = Byte.valueOf(propertyLiteral);
+ } else if ("Boolean".equals(propType) || "boolean".equals(propType)) {
+ propertyValue = Boolean.valueOf(propertyLiteral);
+ }
+ if (propertyName.endsWith(".intents")) {
+ propertyValue = toQNames(reader, propertyLiteral);
+ }
+ if (Constants.OBJECTCLASS.equals(propertyName)) {
+ return propertyLiteral.split("( |\t|\n|\r|\f)+");
+ }
+ return propertyValue;
+ }
+
/**
* Convert ns1:e1 ns2:e2 to {http://ns1}e1 {http://ns2}e2
* @param reader
@@ -176,8 +240,8 @@ public class ServiceDescriptionsProcessor extends BaseStAXArtifactProcessor impl
return ServiceDescriptions.SERVICE_DESCRIPTIONS_QNAME;
}
- public void write(ServiceDescriptions model, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException,
- XMLStreamException {
+ public void write(ServiceDescriptions model, XMLStreamWriter writer, ProcessorContext context)
+ throws ContributionWriteException, XMLStreamException {
// TODO: To be implemented
}
@@ -185,7 +249,7 @@ public class ServiceDescriptionsProcessor extends BaseStAXArtifactProcessor impl
return ServiceDescriptions.class;
}
- public void resolve(ServiceDescriptions model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException {
- // TODO: To be implemented
+ public void resolve(ServiceDescriptions model, ModelResolver resolver, ProcessorContext context)
+ throws ContributionResolveException {
}
}
diff --git a/sca-java-2.x/trunk/modules/implementation-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-2.x/trunk/modules/implementation-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
index c3af0902a3..e8973a91db 100644
--- a/sca-java-2.x/trunk/modules/implementation-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
+++ b/sca-java-2.x/trunk/modules/implementation-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
@@ -17,6 +17,6 @@
# Implementation class for the artifact processor extension
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.ServiceDescriptionsProcessor;qname=http://www.osgi.org/xmlns/rsa/v1.0.0#endpoint-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.SCAConfigProcessor;qname=http://www.osgi.org/xmlns/scact/v1.0.0#sca-config,model=org.apache.tuscany.sca.implementation.osgi.SCAConfig
diff --git a/sca-java-2.x/trunk/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsTestCase.java b/sca-java-2.x/trunk/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsTestCase.java
index cef99f5625..0e7acc354a 100644
--- a/sca-java-2.x/trunk/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsTestCase.java
+++ b/sca-java-2.x/trunk/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsTestCase.java
@@ -41,32 +41,34 @@ import org.junit.Test;
*/
public class ServiceDescriptionsTestCase {
private static final String xml =
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
- + "<service-descriptions xmlns=\"http://www.osgi.org/xmlns/sd/v1.0.0\" "
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<endpoint-descriptions xmlns=\"http://www.osgi.org/xmlns/rsa/v1.0.0\" "
+ "xmlns:sca=\"http://docs.oasis-open.org/ns/opencsa/sca/200912\">"
- + "<service-description>"
- + "<provide interface=\"calculator.operations.AddService\"/>"
- + "<property name=\"service.intents\">sca:SOAP sca:HTTP</property>"
- + "<property name=\"osgi.remote.configuration.type\">sca</property>"
- + "<property name=\"osgi.remote.configuration.sca.componentType\">"
- + "OSGI-INF/sca/bundle.componentType"
+ + "<endpoint-description>"
+ + "<property name=\"objectClass\" value=\"calculator.operations.AddService\"/>"
+ + "<property name=\"service.intents\" value=\"sca:SOAP sca:HTTP\"/>"
+ + "<property name=\"service.imported.configs\" value=\"org.osgi.sca\"/>"
+ + "</endpoint-description>"
+ + "<endpoint-description>"
+ + "<property name=\"service.intents\">"
+ + " <list>"
+ + " <value>SOAP</value>"
+ + " <value>HTTP</value>"
+ + " </list>"
+ "</property>"
- + "<property name=\"osgi.remote.configuration.sca.reference\">"
- + "addService"
- + "</property>"
- + "</service-description>"
- + "<service-description>"
- + "<provide interface=\"calculator.operations.SubtractService\"/>"
- + "<property name=\"service.intents\">sca:SOAP sca:HTTP</property>"
- + "<property name=\"osgi.remote.configuration.type\">sca</property>"
- + "<property name=\"osgi.remote.configuration.sca.componentType\">"
- + "OSGI-INF/sca/bundle.componentType"
- + "</property>"
- + "<property name=\"osgi.remote.configuration.sca.reference\">"
- + "subtractService"
- + "</property>"
- + "</service-description>"
- + "</service-descriptions>";
+ + "<property name=\"endpoint.id\" value=\"http://ws.acme.com:9000/hello\"/>"
+ + "<property name=\"objectClass\" value=\"com.acme.Foo\"/>"
+ + "<property name=\"endpoint.package.version.com.acme\" value=\"4.2\"/>"
+ + "<property name=\"service.imported.configs\" value=\"com.acme\"/>"
+ + "<property name=\"com.acme.ws.xml\">"
+ + "<xml>"
+ + " <config xmlns=\"http://acme.com/defs\">"
+ + " <port>1029</port>"
+ + " <host>www.acme.com</host>"
+ + " </config>"
+ + " </xml>"
+ + " </property>"
+ + "</endpoint-description>"
+ + "</endpoint-descriptions>";
private static ServiceDescriptionsProcessor processor;
private static XMLStreamReader reader;