diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-03-09 21:39:29 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-03-09 21:39:29 +0000 |
commit | ab419e5683bdce60404608b9b75b0b94e2940437 (patch) | |
tree | a40c913c82fef4e809858e754560c52fc29dc40a | |
parent | d15659a6b5e347c910dc78c4e2711a5d9b73e143 (diff) |
Work in progress for implementation.osgi
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@751855 13f79535-47bb-0310-9956-ffa450edef68
13 files changed, 225 insertions, 349 deletions
diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiImplementation.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiImplementation.java index 9a90e8b65d..964ec6e92d 100644 --- a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiImplementation.java +++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiImplementation.java @@ -37,8 +37,9 @@ public interface OSGiImplementation extends Implementation, Extensible { String getBundleVersion(); void setBundleVersion(String version); - + Bundle getBundle(); + void setBundle(Bundle bundle); } diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationActivator.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationActivator.java index 4843f0fe52..abb0f3995a 100644 --- a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationActivator.java +++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationActivator.java @@ -23,7 +23,7 @@ import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; public class OSGiImplementationActivator implements BundleActivator { - static BundleContext bundleContext; + private static BundleContext bundleContext; public void start(BundleContext context) throws Exception { bundleContext = context; diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java index 89e60dff13..0ee95b4ee8 100644 --- a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java +++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java @@ -44,11 +44,9 @@ import org.apache.tuscany.sca.assembly.ComponentService; import org.apache.tuscany.sca.assembly.Multiplicity; import org.apache.tuscany.sca.assembly.Reference; import org.apache.tuscany.sca.assembly.Service; -import org.apache.tuscany.sca.context.RequestContextFactory; import org.apache.tuscany.sca.core.factory.InstanceWrapper; import org.apache.tuscany.sca.core.factory.ObjectCreationException; import org.apache.tuscany.sca.core.factory.ObjectFactory; -import org.apache.tuscany.sca.core.invocation.ProxyFactory; import org.apache.tuscany.sca.core.invocation.impl.JDKProxyFactory; import org.apache.tuscany.sca.core.scope.Scope; import org.apache.tuscany.sca.core.scope.ScopeContainer; @@ -111,7 +109,7 @@ public class OSGiImplementationProvider implements ScopedImplementationProvider, private Hashtable<String, Object> componentProperties = new Hashtable<String, Object>(); private RuntimeComponent runtimeComponent; - private Bundle osgiBundle; + Bundle osgiBundle; private ArrayList<Bundle> dependentBundles = new ArrayList<Bundle>(); private OSGiServiceListener osgiServiceListener; private PackageAdmin packageAdmin; @@ -127,41 +125,23 @@ public class OSGiImplementationProvider implements ScopedImplementationProvider, public OSGiImplementationProvider(RuntimeComponent definition, OSGiImplementation impl, DataBindingExtensionPoint dataBindingRegistry, - JavaPropertyValueObjectFactory propertyValueFactory, - ProxyFactory proxyFactory, ScopeRegistry scopeRegistry, - RequestContextFactory requestContextFactory, MessageFactory messageFactory, InterfaceContractMapper mapper) throws BundleException { this.implementation = (OSGiImplementationImpl)impl; this.runtimeComponent = definition; this.dataBindingRegistry = dataBindingRegistry; - this.propertyValueFactory = propertyValueFactory; this.scopeRegistry = scopeRegistry; this.messageFactory = messageFactory; this.mapper = mapper; - BundleContext bundleContext = OSGiImplementationActivator.bundleContext; - osgiBundle = (Bundle)implementation.getOSGiBundle(); + BundleContext bundleContext = OSGiImplementationActivator.getBundleContext(); + osgiBundle = (Bundle)implementation.getBundle(); bundleContext.addBundleListener(this); osgiServiceListener = new OSGiServiceListener(osgiBundle); bundleContext.addServiceListener(osgiServiceListener); - // Install and start all dependent bundles - String[] imports = implementation.getImports(); - for (int i = 0; i < imports.length; i++) { - String location = imports[i].trim(); - if (location.length() > 0) { - Bundle bundle = bundleContext.installBundle(location); - dependentBundles.add(bundle); - } - } - - this.osgiAnnotations = - new OSGiAnnotations(implementation.getModelFactories(), implementation.getClassList(), runtimeComponent, - propertyValueFactory, proxyFactory, requestContextFactory, osgiBundle, dependentBundles); - // PackageAdmin is used to resolve bundles org.osgi.framework.ServiceReference packageAdminReference = bundleContext.getServiceReference("org.osgi.service.packageadmin.PackageAdmin"); diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProviderFactory.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProviderFactory.java index c650f88b73..0b4d2a3f7d 100644 --- a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProviderFactory.java +++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProviderFactory.java @@ -85,9 +85,8 @@ public class OSGiImplementationProviderFactory implements ImplementationProvider try { - return new OSGiImplementationProvider(component, implementation, dataBindings, propertyFactory, - proxyFactory, scopeRegistry, requestContextFactory, messageFactory, - mapper); + return new OSGiImplementationProvider(component, implementation, dataBindings, scopeRegistry, + requestContextFactory, messageFactory, mapper); } catch (BundleException e) { throw new RuntimeException(e); diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiServiceTracker.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiServiceTracker.java new file mode 100644 index 0000000000..c7fd3058dc --- /dev/null +++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiServiceTracker.java @@ -0,0 +1,40 @@ +/* + * 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.runtime; + +import org.osgi.framework.ServiceReference; +import org.osgi.util.tracker.ServiceTrackerCustomizer; + +/** + * A ServiceTracker + */ +public class OSGiServiceTracker implements ServiceTrackerCustomizer { + + public Object addingService(ServiceReference serviceReference) { + return null; + } + + public void modifiedService(ServiceReference serviceReference, Object service) { + } + + public void removedService(ServiceReference serviceReference, Object service) { + } + +} diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTargetInvoker.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTargetInvoker.java index 1ae0a3eb17..3be61074b0 100644 --- a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTargetInvoker.java +++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTargetInvoker.java @@ -23,16 +23,11 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import org.apache.tuscany.sca.core.factory.InstanceWrapper; -import org.apache.tuscany.sca.core.scope.Scope; -import org.apache.tuscany.sca.core.scope.ScopeContainer; -import org.apache.tuscany.sca.core.scope.TargetResolutionException; -import org.apache.tuscany.sca.interfacedef.ConversationSequence; import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; import org.apache.tuscany.sca.interfacedef.java.impl.JavaInterfaceUtil; import org.apache.tuscany.sca.invocation.Invoker; import org.apache.tuscany.sca.invocation.Message; -import org.apache.tuscany.sca.runtime.EndpointReference; -import org.apache.tuscany.sca.runtime.ReferenceParameters; import org.apache.tuscany.sca.runtime.RuntimeComponentService; /** @@ -55,11 +50,6 @@ public class OSGiTargetInvoker<T> implements Invoker { private final OSGiImplementationProvider provider; private final RuntimeComponentService service; - // Scope container is reset by the OSGi implementation provider if @Scope - // annotation is used to modify the scope (default is composite) - // Hence this field is initialized on the first invoke. - private ScopeContainer scopeContainer; - public OSGiTargetInvoker(Operation operation, OSGiImplementationProvider provider, RuntimeComponentService service) { this.operation = operation; @@ -68,82 +58,22 @@ public class OSGiTargetInvoker<T> implements Invoker { } - /** - * Resolves the target service instance or returns a cached one - */ - @SuppressWarnings("unchecked") - protected InstanceWrapper getInstance(Object contextId) throws TargetResolutionException { - - if (scopeContainer == null) - scopeContainer = provider.getScopeContainer(); - - return scopeContainer.getWrapper(contextId); - - } - - @SuppressWarnings("unchecked") private Object invokeTarget(Message msg) throws InvocationTargetException { - if (scopeContainer == null) - scopeContainer = provider.getScopeContainer(); - Operation op = msg.getOperation(); if (op == null) { op = this.operation; } - ConversationSequence sequence = op.getConversationSequence(); - - Object contextId = null; - - EndpointReference from = msg.getFrom(); - ReferenceParameters parameters = null; - - if (from != null) { - parameters = from.getReferenceParameters(); - } - // check what sort of context is required - if (scopeContainer != null) { - Scope scope = scopeContainer.getScope(); - if (scope == Scope.REQUEST) { - contextId = Thread.currentThread(); - } else if (scope == Scope.CONVERSATION && parameters != null) { - contextId = parameters.getConversationID(); - } - } try { - - OSGiInstanceWrapper wrapper = (OSGiInstanceWrapper)getInstance(contextId); - Object instance; - - // detects whether the scope container has created a conversation Id. This will - // happen in the case that the component has conversational scope but only the - // callback interface is conversational. Or in the callback case if the service interface - // is conversational and the callback interface isn't. If we are in this situation we need - // to get the contextId of this component and remove it after we have invoked the method on - // it. It is possible that the component instance will not go away when it is removed below - // because a callback conversation will still be holding a reference to it - boolean removeTemporaryConversationalComponentAfterCall = false; - if (parameters != null && (contextId == null) && (parameters.getConversationID() != null)) { - contextId = parameters.getConversationID(); - removeTemporaryConversationalComponentAfterCall = true; - } - - instance = wrapper.getInstance(service); + JavaInterface javaInterface = (JavaInterface)op.getInterface(); + // FIXME: What is the filter? + Object instance = provider.osgiBundle.getBundleContext().getServiceReference(javaInterface.getName()); Method m = JavaInterfaceUtil.findMethod(instance.getClass(), operation); Object ret = invokeMethod(instance, m, msg); - scopeContainer.returnWrapper(wrapper, contextId); - - if ((sequence == ConversationSequence.CONVERSATION_END) || (removeTemporaryConversationalComponentAfterCall)) { - // if end conversation, or we have the special case where a conversational - // object was created to service the stateless half of a stateful component - scopeContainer.remove(contextId); - parameters.setConversationID(null); - } - return ret; } catch (InvocationTargetException e) { throw e; @@ -173,11 +103,6 @@ public class OSGiTargetInvoker<T> implements Invoker { public Message invoke(Message msg) { try { - // Object messageId = msg.getMessageID(); - // Message workContext = ThreadMessageContext.getMessageContext(); - // if (messageId != null) { - // workContext.setCorrelationID(messageId); - // } Object resp = invokeTarget(msg); msg.setBody(resp); } catch (InvocationTargetException e) { diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java index d10af49147..3113c1d5be 100644 --- a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java +++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java @@ -323,48 +323,6 @@ public class OSGiImplementationProcessor implements StAXArtifactProcessor<OSGiIm return ref.getJavaClass(); } - private Service createService(Service serv, Class<?> interfaze, Class<?> callbackInterfaze) - throws InvalidInterfaceException { - Service service = assemblyFactory.createService(); - JavaInterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract(); - service.setInterfaceContract(interfaceContract); - - // create a relative URI - service.setName(serv.getName()); - - JavaInterface callInterface = javaInterfaceFactory.createJavaInterface(interfaze); - service.getInterfaceContract().setInterface(callInterface); - - if (callbackInterfaze != null) { - JavaInterface callbackInterface = javaInterfaceFactory.createJavaInterface(callbackInterfaze); - service.getInterfaceContract().setCallbackInterface(callbackInterface); - } else if (callInterface.getCallbackClass() != null) { - JavaInterface callbackInterface = - javaInterfaceFactory.createJavaInterface(callInterface.getCallbackClass()); - service.getInterfaceContract().setCallbackInterface(callbackInterface); - } - return service; - } - - private Reference createReference(Reference ref, Class<?> clazz) throws InvalidInterfaceException { - org.apache.tuscany.sca.assembly.Reference reference = assemblyFactory.createReference(); - JavaInterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract(); - reference.setInterfaceContract(interfaceContract); - - reference.setName(ref.getName()); - reference.setMultiplicity(ref.getMultiplicity()); - - JavaInterface callInterface = javaInterfaceFactory.createJavaInterface(clazz); - reference.getInterfaceContract().setInterface(callInterface); - if (callInterface.getCallbackClass() != null) { - JavaInterface callbackInterface = - javaInterfaceFactory.createJavaInterface(callInterface.getCallbackClass()); - reference.getInterfaceContract().setCallbackInterface(callbackInterface); - } - - return reference; - } - public void write(OSGiImplementation model, XMLStreamWriter outputSource) throws ContributionWriteException, XMLStreamException { @@ -386,162 +344,4 @@ public class OSGiImplementationProcessor implements StAXArtifactProcessor<OSGiIm } } - private void declareNamespace(Element element, String prefix, String ns) { - String qname = null; - if ("".equals(prefix)) { - qname = "xmlns"; - } else { - qname = "xmlns:" + prefix; - } - Node node = element; - boolean declared = false; - while (node != null && node.getNodeType() == Node.ELEMENT_NODE) { - NamedNodeMap attrs = node.getAttributes(); - if (attrs == null) { - break; - } - Node attr = attrs.getNamedItem(qname); - if (attr != null) { - declared = ns.equals(attr.getNodeValue()); - break; - } - node = node.getParentNode(); - } - if (!declared) { - org.w3c.dom.Attr attr = element.getOwnerDocument().createAttributeNS(XMLNS_ATTRIBUTE_NS_URI, qname); - attr.setValue(ns); - element.setAttributeNodeNS(attr); - } - } - - private Element createElement(Document document, QName name) { - String prefix = name.getPrefix(); - String qname = - (prefix != null && prefix.length() > 0) ? prefix + ":" + name.getLocalPart() : name.getLocalPart(); - return document.createElementNS(name.getNamespaceURI(), qname); - } - - private void loadElement(XMLStreamReader reader, Element root) throws XMLStreamException { - Document document = root.getOwnerDocument(); - Node current = root; - while (true) { - switch (reader.next()) { - case XMLStreamConstants.START_ELEMENT: - QName name = reader.getName(); - Element child = createElement(document, name); - - // push the new element and make it the current one - current.appendChild(child); - current = child; - - declareNamespace(child, name.getPrefix(), name.getNamespaceURI()); - - int count = reader.getNamespaceCount(); - for (int i = 0; i < count; i++) { - String prefix = reader.getNamespacePrefix(i); - String ns = reader.getNamespaceURI(i); - declareNamespace(child, prefix, ns); - } - - // add the attributes for this element - count = reader.getAttributeCount(); - for (int i = 0; i < count; i++) { - String ns = reader.getAttributeNamespace(i); - String prefix = reader.getAttributePrefix(i); - String localPart = reader.getAttributeLocalName(i); - String value = reader.getAttributeValue(i); - child.setAttributeNS(ns, localPart, value); - declareNamespace(child, prefix, ns); - } - - break; - case XMLStreamConstants.CDATA: - current.appendChild(document.createCDATASection(reader.getText())); - break; - case XMLStreamConstants.CHARACTERS: - current.appendChild(document.createTextNode(reader.getText())); - break; - case XMLStreamConstants.END_ELEMENT: - // if we are back at the root then we are done - if (current == root) { - return; - } - - // pop the element off the stack - current = current.getParentNode(); - } - } - } - - private Document readPropertyValue(XMLStreamReader reader, QName type) throws XMLStreamException, - ParserConfigurationException { - - Document doc = domFactory.newDocumentBuilder().newDocument(); - - // root element has no namespace and local name "value" - Element root = doc.createElementNS(null, "value"); - if (type != null) { - org.w3c.dom.Attr xsi = doc.createAttributeNS(XMLNS_ATTRIBUTE_NS_URI, "xmlns:xsi"); - xsi.setValue(W3C_XML_SCHEMA_INSTANCE_NS_URI); - root.setAttributeNodeNS(xsi); - - String prefix = type.getPrefix(); - if (prefix == null || prefix.length() == 0) { - prefix = "ns"; - } - - declareNamespace(root, prefix, type.getNamespaceURI()); - - org.w3c.dom.Attr xsiType = doc.createAttributeNS(W3C_XML_SCHEMA_INSTANCE_NS_URI, "xsi:type"); - xsiType.setValue(prefix + ":" + type.getLocalPart()); - root.setAttributeNodeNS(xsiType); - } - doc.appendChild(root); - - loadElement(reader, root); - return doc; - } - - private void readProperty(ComponentProperty prop, XMLStreamReader reader) throws XMLStreamException, - ContributionReadException { - - prop.setName(reader.getAttributeValue(null, "name")); - String xsdType = reader.getAttributeValue(null, "type"); - if (xsdType != null) - prop.setXSDType(getQNameValue(reader, xsdType)); - else - prop.setXSDType(SimpleTypeMapperImpl.XSD_STRING); - - try { - Document value = readPropertyValue(reader, prop.getXSDType()); - prop.setValue(value); - } catch (ParserConfigurationException e) { - ContributionReadException ce = new ContributionReadException(e); - error("ContributionReadException", reader, ce); - throw ce; - } - } - - private List<ComponentProperty> readProperties(XMLStreamReader reader) throws XMLStreamException, - ContributionReadException { - - List<ComponentProperty> properties = new ArrayList<ComponentProperty>(); - - while (reader.hasNext()) { - - int next = reader.next(); - if (next == END_ELEMENT && PROPERTIES_QNAME.equals(reader.getName())) { - break; - } else if (next == START_ELEMENT && PROPERTY_QNAME.equals(reader.getName())) { - - ComponentProperty componentProperty = assemblyFactory.createComponentProperty(); - readProperty(componentProperty, reader); - properties.add(componentProperty); - } - } - - return properties; - - } - } diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescription.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescription.java new file mode 100644 index 0000000000..72cc014506 --- /dev/null +++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescription.java @@ -0,0 +1,58 @@ +/* + * 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 java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.namespace.QName; + +/** + * The OSGi RFC 119 description of a remote OSGi service + */ +public class ServiceDescription { + public final static String REMOTE_SERVICE_FOLDER = "OSGI-INF/remote-service"; + public final static String SD_NS = "http://www.osgi.org/xmlns/sd/v1.0.0"; + public final static QName SERVICE_DESCRIPTIONS_QNAME = new QName(SD_NS, "service-descriptions"); + public final static QName SERVICE_DESCRIPTION_QNAME = new QName(SD_NS, "service-description"); + public final static String REMOTE_SERVICE_HEADER = "Remote-Service"; + public final static String PROP_SERVICE_INTENTS = "service.intents"; + public final static String PROP_REQUIRES_INTENTS = "osgi.remote.requires.intents"; + public final static String PROP_CONFIGURATION_TYPE = "osgi.remote.configuration.type"; + public final static String CONFIGURATION_TYPE_SCA = "sca"; + public final static String PROP_CONFIGURATION_SCA_BINDINGS = "osgi.remote.configuration.sca.bindings"; + + private List<String> interfaces = new ArrayList<String>(); + private Map<String, Object> properties = new HashMap<String, Object>(); + + public List<String> getInterfaces() { + return interfaces; + } + + public Map<String, Object> getProperties() { + return properties; + } + + public String toString() { + return "service-description: interfaces=" + interfaces + "properties=" + properties; + } +}
\ No newline at end of file diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsProcessor.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsProcessor.java index 6cce501895..313f17adf8 100644 --- a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsProcessor.java +++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsProcessor.java @@ -20,9 +20,7 @@ package org.apache.tuscany.sca.implementation.osgi.xml; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import javax.xml.namespace.QName; import javax.xml.stream.XMLStreamConstants; @@ -51,30 +49,6 @@ import javax.xml.stream.XMLStreamReader; </service-descriptions> */ public class ServiceDescriptionsProcessor { - public final static String REMOTE_SERVICE_FOLDER = "OSGI-INF/remote-service"; - public final static String SD_NS = "http://www.osgi.org/xmlns/sd/v1.0.0"; - public final static QName SERVICE_DESCRIPTIONS_QNAME = new QName(SD_NS, "service-descriptions"); - public final static QName SERVICE_DESCRIPTION_QNAME = new QName(SD_NS, "service-description"); - public final static String REMOTE_SERVICE_HEADER = "Remote-Service"; - public final static String PROP_SERVICE_INTENTS = "service.intents"; - public final static String PROP_CONFIGURATION_TYPE = "osgi.remote.configuration.type"; - - public static class ServiceDescription { - private List<String> interfaces = new ArrayList<String>(); - private Map<String, Object> properties = new HashMap<String, Object>(); - - public List<String> getInterfaces() { - return interfaces; - } - - public Map<String, Object> getProperties() { - return properties; - } - - public String toString() { - return "service-description: interfaces=" + interfaces + "properties=" + properties; - } - } public List<ServiceDescription> read(XMLStreamReader reader) throws XMLStreamException { int event = reader.getEventType(); @@ -84,13 +58,13 @@ public class ServiceDescriptionsProcessor { switch (event) { case XMLStreamConstants.START_ELEMENT: QName name = reader.getName(); - if (SERVICE_DESCRIPTION_QNAME.equals(name)) { + if (ServiceDescription.SERVICE_DESCRIPTION_QNAME.equals(name)) { sd = new ServiceDescription(); sds.add(sd); } else if ("provide".equals(name.getLocalPart())) { String interfaceName = reader.getAttributeValue(null, "interface"); if (interfaceName != null) { - sd.interfaces.add(interfaceName); + sd.getInterfaces().add(interfaceName); } } else if ("property".equals(name.getLocalPart())) { String propName = reader.getAttributeValue(null, "name"); @@ -123,16 +97,16 @@ public class ServiceDescriptionsProcessor { } else if ("Boolean".equals(propType)) { prop = Boolean.valueOf(propValue); } - sd.properties.put(propName, prop); + sd.getProperties().put(propName, prop); } break; case XMLStreamConstants.END_ELEMENT: name = reader.getName(); - if (SERVICE_DESCRIPTION_QNAME.equals(name)) { + if (ServiceDescription.SERVICE_DESCRIPTION_QNAME.equals(name)) { // Reset the sd sd = null; } - if (SERVICE_DESCRIPTIONS_QNAME.equals(name)) { + if (ServiceDescription.SERVICE_DESCRIPTIONS_QNAME.equals(name)) { return sds; } break; diff --git a/java/sca/modules/implementation-osgi/src/main/resources/META-INF/definitions.xml b/java/sca/modules/implementation-osgi/src/main/resources/META-INF/definitions.xml new file mode 100644 index 0000000000..f531c2c4ed --- /dev/null +++ b/java/sca/modules/implementation-osgi/src/main/resources/META-INF/definitions.xml @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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. +--> +<sca:definitions xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200903" + targetNamespace="http://www.osgi.org/xmlns/sca/intents/v1.0.0"> + + <intent name="passByReference" constrains="sca:implementation" + intentType="implementation"> + <description> + An OSGi intent to pass data by reference + </description> + </intent> + + <intent name="passByValue" constrains="sca:implementation" + intentType="implementation"> + <description> + An OSGi intent to pass data by value + </description> + </intent> + +</sca:definitions>
\ No newline at end of file diff --git a/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsTestCase.java b/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsTestCase.java index 69420d9801..88b6227204 100644 --- a/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsTestCase.java +++ b/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsTestCase.java @@ -25,7 +25,6 @@ import java.util.List; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamReader; -import org.apache.tuscany.sca.implementation.osgi.xml.ServiceDescriptionsProcessor.ServiceDescription; import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; diff --git a/java/sca/modules/implementation-osgi/src/test/resources/bundle.componentType b/java/sca/modules/implementation-osgi/src/test/resources/bundle.componentType new file mode 100644 index 0000000000..ab334d91a7 --- /dev/null +++ b/java/sca/modules/implementation-osgi/src/test/resources/bundle.componentType @@ -0,0 +1,55 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+-->
+<componentType xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200712"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:t = "http://tuscany.apache.org/xmlns/sca/1.1"
+ >
+ <!-- The service elment defines an SCA view of the OSGi service -->
+ <service name="Calculator">
+ <!-- The interface will be mapped into the OSGi service class -->
+ <interface.java interface="calculator.CalculatorService"/>
+ <!-- The list of OSGi properties -->
+ <t:osgi.property name="prop1">1</t:osgi.property>
+ <t:osgi.property name="prop2">ABC</t:osgi.property>
+ </service>
+
+ <!-- The reference elment defines an SCA proxy to a remote OSGi service -->
+ <reference name="addService">
+ <interface.java interface="calculator.AddService"/>
+ <t:osgi.property name="prop1">1</t:osgi.property>
+ <t:osgi.property name="prop2">ABC</t:osgi.property>
+ </reference>
+ <reference name="subtractService">
+ <interface.java interface="calculator.SubtractService"/>
+ <t:osgi.property name="prop1">1</t:osgi.property>
+ <t:osgi.property name="prop2">ABC</t:osgi.property>
+ </reference>
+ <reference name="multiplyService">
+ <interface.java interface="calculator.MultiplyService"/>
+ <t:osgi.property name="prop1">1</t:osgi.property>
+ <t:osgi.property name="prop2">ABC</t:osgi.property>
+ </reference>
+ <reference name="divideService">
+ <interface.java interface="calculator.DivideService"/>
+ <t:osgi.property name="prop1">1</t:osgi.property>
+ <t:osgi.property name="prop2">ABC</t:osgi.property>
+ </reference>
+
+</componentType>
diff --git a/java/sca/modules/implementation-osgi/src/test/resources/osgiproptest.composite b/java/sca/modules/implementation-osgi/src/test/resources/osgiproptest.composite index 3220891d6a..35aa620fcd 100644 --- a/java/sca/modules/implementation-osgi/src/test/resources/osgiproptest.composite +++ b/java/sca/modules/implementation-osgi/src/test/resources/osgiproptest.composite @@ -1,14 +1,22 @@ <?xml version="1.0" encoding="UTF-8"?>
- <!--
- * 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.
- -->
+<!--
+ * 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.
+-->
<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200712" xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="OSGiTestComposite">
|