summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src
diff options
context:
space:
mode:
authorantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2010-10-26 07:46:08 +0000
committerantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2010-10-26 07:46:08 +0000
commit6865c59e74f19ed6057d03583944b47abd6e036e (patch)
tree3324c11c7ca4f5ca12f15619ce30e9824e198480 /sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src
parent0d6d7922ed17cca55ec36ff2626d1080e76d6d13 (diff)
Create branch for next release
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1027394 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src')
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/DefaultOSGiImplementationFactory.java34
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/DefaultServiceDescriptionsFactory.java33
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiImplementation.java51
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiImplementationFactory.java47
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiProperty.java242
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/SCAConfig.java65
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/ServiceDescription.java40
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/ServiceDescriptions.java38
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/ServiceDescriptionsFactory.java31
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiImplementationFactoryImpl.java125
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiImplementationImpl.java124
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiPropertyImpl.java69
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/SCAConfigImpl.java58
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/ServiceDescriptionImpl.java51
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/ServiceDescriptionsFactoryImpl.java48
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/ServiceDescriptionsImpl.java36
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/BluePrintComponentsProcessor.java144
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiComponentProcessor.java174
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationActivator.java47
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java342
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiPropertyProcessor.java115
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/SCAConfigProcessor.java194
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsDocumentProcessor.java99
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsModelResolver.java59
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsProcessor.java255
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/resources/META-INF/definitions.xml37
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor22
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor20
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver18
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.osgi.OSGiImplementationFactory19
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.osgi.ServiceDescriptionsFactory18
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/resources/impl-osgi-validation-messages.properties26
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/calculator/dosgi/CalculatorService.java39
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/calculator/dosgi/operations/AddService.java31
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/calculator/dosgi/operations/DivideService.java31
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/calculator/dosgi/operations/MultiplyService.java31
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/calculator/dosgi/operations/SubtractService.java31
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/BluePrintComponentsProcessorTestCase.java89
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiComponentProcessorTestCase.java89
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiReadImplTestCase.java173
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsTestCase.java110
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/TestModelResolver.java105
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/resources/OSGI-INF/calculator-component.xml36
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/resources/OSGI-INF/sca/bundle.componentType63
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/resources/osgitest.composite35
45 files changed, 3544 insertions, 0 deletions
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/DefaultOSGiImplementationFactory.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/DefaultOSGiImplementationFactory.java
new file mode 100644
index 0000000000..20c7e8d60a
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/DefaultOSGiImplementationFactory.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 org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.implementation.osgi.impl.OSGiImplementationFactoryImpl;
+
+/**
+ *
+ */
+public class DefaultOSGiImplementationFactory extends OSGiImplementationFactoryImpl {
+
+ public DefaultOSGiImplementationFactory(ExtensionPointRegistry registry) {
+ super(registry);
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/DefaultServiceDescriptionsFactory.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/DefaultServiceDescriptionsFactory.java
new file mode 100644
index 0000000000..d7296e24bb
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/DefaultServiceDescriptionsFactory.java
@@ -0,0 +1,33 @@
+/*
+ * 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 org.apache.tuscany.sca.implementation.osgi.impl.ServiceDescriptionsFactoryImpl;
+
+/**
+ *
+ */
+public class DefaultServiceDescriptionsFactory extends ServiceDescriptionsFactoryImpl {
+
+ public DefaultServiceDescriptionsFactory() {
+ super();
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiImplementation.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiImplementation.java
new file mode 100644
index 0000000000..ba5e5284be
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiImplementation.java
@@ -0,0 +1,51 @@
+/*
+ * 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 javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.assembly.Extensible;
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.osgi.framework.Bundle;
+
+/**
+ *
+ * The model representing an OSGi implementation in an SCA assembly model.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface OSGiImplementation extends Implementation, Extensible {
+ String BUNDLE_SYMBOLICNAME = "bundleSymbolicName";
+ String BUNDLE_VERSION = "bundleVersion";
+ QName IMPLEMENTATION_OSGI = new QName(SCA11_TUSCANY_NS, "implementation.osgi");
+ QName TYPE = IMPLEMENTATION_OSGI;
+
+ String getBundleSymbolicName();
+
+ void setBundleSymbolicName(String name);
+
+ String getBundleVersion();
+
+ void setBundleVersion(String version);
+
+ Bundle getBundle();
+
+ void setBundle(Bundle bundle);
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiImplementationFactory.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiImplementationFactory.java
new file mode 100644
index 0000000000..23952dfee4
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiImplementationFactory.java
@@ -0,0 +1,47 @@
+/*
+ * 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.Collection;
+import java.util.Map;
+
+import org.osgi.framework.ServiceReference;
+
+/**
+ * The factory interface to create OSGiImplementation instances
+ */
+public interface OSGiImplementationFactory {
+ /**
+ * Create a new instance of OSGiImplementation
+ * @return
+ */
+ OSGiImplementation createOSGiImplementation();
+
+ /**
+ *
+ * @return
+ */
+ OSGiProperty createOSGiProperty();
+ OSGiProperty createOSGiProperty(String name, String stringValue, String type);
+ OSGiProperty createOSGiProperty(String name, Object value);
+ Collection<OSGiProperty> createOSGiProperties(ServiceReference reference);
+ Collection<OSGiProperty> createOSGiProperties(Map<String, Object> properties);
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiProperty.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiProperty.java
new file mode 100644
index 0000000000..ff889f8577
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiProperty.java
@@ -0,0 +1,242 @@
+/*
+ * 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 javax.xml.namespace.QName;
+
+/**
+ * <tuscany:osgi.property>
+ */
+public interface OSGiProperty {
+ String NAME = "name";
+ String TYPE = "type";
+ String VALUE = "value";
+ QName PROPERTY_QNAME = new QName(OSGiImplementation.SCA11_TUSCANY_NS, "osgi.property");
+
+ String REMOTE_CONFIG_SCA = "org.osgi.sca";
+ String SCA_BINDINGS = "org.osgi.sca.bindings";
+ String SCA_REFERENCE = "sca.reference";
+ String SCA_SERVICE = "sca.service";
+ String SCA_REFERENCE_BINDING = "sca.reference.binding";
+ String SCA_SERVICE_BINDING = "sca.service.binding";
+
+ /**
+ * Service property identifying the configuration types supported by a
+ * distribution provider. Registered by the distribution provider on one of
+ * its services to indicate the supported configuration types.
+ * <p>
+ * The value of this property must be of type <code>String</code>,
+ * <code>String[]</code>, or <code>Collection&lt;String&gt;</code>.
+ */
+ public static final String REMOTE_CONFIGS_SUPPORTED = "remote.configs.supported";
+
+ /**
+ * Service property identifying the intents supported by a distribution
+ * provider. Registered by the distribution provider on one of its services
+ * to indicate the vocabulary of implemented intents.
+ *
+ * <p>
+ * The value of this property must be of type <code>String</code>,
+ * <code>String[]</code>, or <code>Collection&lt;String&gt;</code>.
+ */
+ public static final String REMOTE_INTENTS_SUPPORTED = "remote.intents.supported";
+
+ /**
+ * Service property identifying the configuration types that should be used
+ * to export the service. Each configuration type represents the
+ * configuration parameters for an endpoint. A distribution provider should
+ * create an endpoint for each configuration type that it supports.
+ *
+ * <p>
+ * This property may be supplied in the <code>properties</code>
+ * <code>Dictionary</code> object passed to the
+ * <code>BundleContext.registerService</code> method. The value of this
+ * property must be of type <code>String</code>, <code>String[]</code>, or
+ * <code>Collection&lt;String&gt;</code>.
+ */
+ public static final String SERVICE_EXPORTED_CONFIGS = "service.exported.configs";
+
+ /**
+ * Service property identifying the intents that the distribution provider
+ * must implement to distribute the service. Intents listed in this property
+ * are reserved for intents that are critical for the code to function
+ * correctly, for example, ordering of messages. These intents should not be
+ * configurable.
+ *
+ * <p>
+ * This property may be supplied in the <code>properties</code>
+ * <code>Dictionary</code> object passed to the
+ * <code>BundleContext.registerService</code> method. The value of this
+ * property must be of type <code>String</code>, <code>String[]</code>, or
+ * <code>Collection&lt;String&gt;</code>.
+ */
+ public static final String SERVICE_EXPORTED_INTENTS = "service.exported.intents";
+
+ /**
+ * Service property identifying the extra intents that the distribution
+ * provider must implement to distribute the service. This property is
+ * merged with the <code>service.exported.intents</code> property before the
+ * distribution provider interprets the listed intents; it has therefore the
+ * same semantics but the property should be configurable so the
+ * administrator can choose the intents based on the topology. Bundles
+ * should therefore make this property configurable, for example through the
+ * Configuration Admin service.
+ *
+ * <p>
+ * This property may be supplied in the <code>properties</code>
+ * <code>Dictionary</code> object passed to the
+ * <code>BundleContext.registerService</code> method. The value of this
+ * property must be of type <code>String</code>, <code>String[]</code>, or
+ * <code>Collection&lt;String&gt;</code>.
+ */
+ public static final String SERVICE_EXPORTED_INTENTS_EXTRA = "service.exported.intents.extra";
+
+ /**
+ * Service property marking the service for export. It defines the
+ * interfaces under which this service can be exported. This list must be a
+ * subset of the types under which the service was registered. The single
+ * value of an asterisk (&quot;*&quot;, &#92;u002A) indicates all the
+ * interface types under which the service was registered excluding the
+ * non-interface types. It is strongly recommended to only export interface
+ * types and not concrete classes due to the complexity of creating proxies
+ * for some type of concrete classes.
+ *
+ * <p>
+ * This property may be supplied in the <code>properties</code>
+ * <code>Dictionary</code> object passed to the
+ * <code>BundleContext.registerService</code> method. The value of this
+ * property must be of type <code>String</code>, <code>String[]</code>, or
+ * <code>Collection&lt;String&gt;</code>.
+ */
+ public static final String SERVICE_EXPORTED_INTERFACES = "service.exported.interfaces";
+
+ /**
+ * Service property identifying the service as imported. This service
+ * property must be set by a distribution provider to any value when it
+ * registers the endpoint proxy as an imported service. A bundle can use
+ * this property to filter out imported services.
+ *
+ * <p>
+ * The value of this property may be of any type.
+ */
+ public static final String SERVICE_IMPORTED = "service.imported";
+
+ /**
+ * Service property identifying the configuration types used to import the
+ * service. Any associated properties for this configuration types must be
+ * properly mapped to the importing system. For example, a URL in these
+ * properties must point to a valid resource when used in the importing
+ * framework. If multiple configuration types are listed in this property,
+ * then they must be synonyms for exactly the same remote endpoint that is
+ * used to export this service.
+ *
+ * <p>
+ * The value of this property must be of type <code>String</code>,
+ * <code>String[]</code>, or <code>Collection&lt;String&gt;</code>.
+ *
+ * @see #SERVICE_EXPORTED_CONFIGS
+ */
+ public static final String SERVICE_IMPORTED_CONFIGS = "service.imported.configs";
+
+ /**
+ * Service property identifying the intents that this service implement.
+ * This property has a dual purpose:
+ * <ul>
+ * <li>A bundle can use this service property to notify the distribution
+ * provider that these intents are already implemented by the exported
+ * service object.</li>
+ * <li>A distribution provider must use this property to convey the combined
+ * intents of: The exporting service, and, the intents that the exporting
+ * distribution provider adds, and the intents that the importing
+ * distribution provider adds.</li>
+ * </ul>
+ * To export a service, a distribution provider must expand any qualified
+ * intents. Both the exporting and importing distribution providers must
+ * recognize all intents before a service can be distributed.
+ *
+ * <p>
+ * The value of this property must be of type <code>String</code>,
+ * <code>String[]</code>, or <code>Collection&lt;String&gt;</code>.
+ */
+ public static final String SERVICE_INTENTS = "service.intents";
+
+ /* above are from Ch 13 Remote Service spec. */
+
+ /**
+ * Endpoint property identifying the id for this endpoint. This service
+ * property must always be set.
+ *
+ * <p>
+ * The value of this property must be of type <code>String</code>.
+ */
+ String ENDPOINT_ID = "endpoint.id";
+
+ /**
+ * Endpoint property identifying the service id of the exported service. Can
+ * be absent or 0 if the corresponding endpoint is not for an OSGi service.
+ *
+ * <p>
+ * The value of this property must be of type <code>Long</code>.
+ */
+ String ENDPOINT_SERVICE_ID = "endpoint.service.id";
+
+ /**
+ * Endpoint property identifying the universally unique id of the exporting
+ * framework. Can be absent if the corresponding endpoint is not for an OSGi
+ * service.
+ *
+ * <p>
+ * The value of this property must be of type <code>String</code>.
+ */
+ String ENDPOINT_FRAMEWORK_UUID = "endpoint.framework.uuid";
+
+ /**
+ * Prefix for an endpoint property identifying the interface Java package
+ * version for an interface. For example, the property
+ * endpoint.package.version.com.acme=1.3 describes the version of the
+ * package for the com.acme.Foo interface. This endpoint property for an
+ * interface package does not have to be set. If not set, the value must be
+ * assumed to be 0.
+ *
+ * <p>
+ * Since endpoint properties are stored in a case insensitive map, case
+ * variants of a package name are folded together.
+ *
+ * <p>
+ * The value of this property must be of type <code>String</code>.
+ */
+ String ENDPOINT_PACKAGE_VERSION_ = "endpoint.package.version.";
+
+ Object getValue();
+
+ void setValue(Object value);
+
+ String getName();
+
+ void setName(String name);
+
+ String getType();
+
+ void setType(String type);
+
+ String getStringValue();
+
+ void setStringValue(String value);
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/SCAConfig.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/SCAConfig.java
new file mode 100644
index 0000000000..a54324b027
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/SCAConfig.java
@@ -0,0 +1,65 @@
+/*
+ * 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 org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.PolicySet;
+
+/**
+ *
+ */
+public interface SCAConfig {
+ /**
+ * Returns the target namespace for this SCA Definition
+ * @return the target namespace
+ */
+ String getTargetNamespace();
+
+ /**
+ * Sets the target names for this SCA Definition.
+ *
+ * @param ns the target namespace for this SCA Definition
+ */
+ void setTargetNamespace(String ns);
+
+ /**
+ * Returns a list of domain wide Policy Intents
+ *
+ * @return a list of domain wide Policy Intents
+ */
+ List<Intent> getIntents();
+
+ /**
+ * Returns a list of domain wide PolicySets
+ *
+ * @return a list of domain wide PolicySets
+ */
+ List<PolicySet> getPolicySets();
+
+ /**
+ * Returns a list of domain wide binding definition objects
+ *
+ * @return a list of domain wide binding definition objects
+ */
+ List<Binding> getBindings();
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/ServiceDescription.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/ServiceDescription.java
new file mode 100644
index 0000000000..119d7ed657
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/ServiceDescription.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;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * The OSGi RFC 119 description of a remote OSGi service
+ */
+public interface ServiceDescription {
+ /**
+ * Get a list of interfaces
+ * @return
+ */
+ List<String> getInterfaces();
+
+ /**
+ * Get a list of properties
+ * @return
+ */
+ Map<String, Object> getProperties();
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/ServiceDescriptions.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/ServiceDescriptions.java
new file mode 100644
index 0000000000..a5322429ff
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/ServiceDescriptions.java
@@ -0,0 +1,38 @@
+/*
+ * 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;
+
+/**
+ * OSGi RFC 119 service descriptions
+ */
+public interface ServiceDescriptions extends List<ServiceDescription> {
+
+ String REMOTE_SERVICE_FOLDER = "OSGI-INF/remote-service";
+ 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/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/ServiceDescriptionsFactory.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/ServiceDescriptionsFactory.java
new file mode 100644
index 0000000000..535bef2b6b
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/ServiceDescriptionsFactory.java
@@ -0,0 +1,31 @@
+/*
+ * 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;
+
+/**
+ * The factory interface to create OSGi RFC 119 service descriptions
+ */
+public interface ServiceDescriptionsFactory {
+ ServiceDescriptions createServiceDescriptions();
+
+ ServiceDescription createServiceDescription();
+
+ SCAConfig createSCAConfig();
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiImplementationFactoryImpl.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiImplementationFactoryImpl.java
new file mode 100644
index 0000000000..17ebf12903
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiImplementationFactoryImpl.java
@@ -0,0 +1,125 @@
+/*
+ * 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 java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+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.osgi.framework.ServiceReference;
+
+/**
+ *
+ */
+public class OSGiImplementationFactoryImpl implements OSGiImplementationFactory {
+ public OSGiImplementationFactoryImpl(ExtensionPointRegistry registry) {
+ super();
+ }
+
+ public OSGiImplementation createOSGiImplementation() {
+ return new OSGiImplementationImpl();
+ }
+
+ public OSGiProperty createOSGiProperty() {
+ return new OSGiPropertyImpl();
+ }
+
+ public OSGiProperty createOSGiProperty(String propName, String propValue, String propType) {
+ OSGiProperty prop = new OSGiPropertyImpl();
+ if (propType == null) {
+ propType = "String";
+ }
+ prop.setName(propName);
+ prop.setStringValue(propValue);
+ prop.setType(propType);
+
+ Object value = propValue;
+ if ("Integer".equals(propType)) {
+ value = Integer.valueOf(propValue);
+ } else if ("Long".equals(propType)) {
+ value = Long.valueOf(propValue);
+ } else if ("Float".equals(propType)) {
+ value = Float.valueOf(propValue);
+ } else if ("Double".equals(propType)) {
+ value = Double.valueOf(propValue);
+ } else if ("Short".equals(propType)) {
+ value = Short.valueOf(propValue);
+ } else if ("Character".equals(propType)) {
+ value = propValue.charAt(0);
+ } else if ("Byte".equals(propType)) {
+ value = Byte.valueOf(propValue);
+ } else if ("Boolean".equals(propType)) {
+ value = Boolean.valueOf(propValue);
+ } else if ("String+".equals(propType)) {
+ value = propValue.split(" ");
+ } else {
+ // String
+ value = propValue;
+ }
+ prop.setValue(value);
+ return prop;
+ }
+
+ public OSGiProperty createOSGiProperty(String propName, Object value) {
+ OSGiProperty prop = new OSGiPropertyImpl();
+ prop.setName(propName);
+ prop.setValue(value);
+
+ if (value instanceof String[]) {
+ StringBuffer sb = new StringBuffer();
+ for (String s : (String[])value) {
+ sb.append(s).append(' ');
+ }
+ if (sb.length() > 0) {
+ sb.deleteCharAt(sb.length() - 1);
+ }
+ prop.setStringValue(sb.toString());
+ prop.setType("String+");
+ } else if (value != null) {
+ prop.setStringValue(String.valueOf(value));
+ prop.setType(value.getClass().getSimpleName());
+ }
+ return prop;
+ }
+
+ public Collection<OSGiProperty> createOSGiProperties(ServiceReference reference) {
+ List<OSGiProperty> props = new ArrayList<OSGiProperty>();
+ for(String key: reference.getPropertyKeys()) {
+ Object value = reference.getProperty(key);
+ OSGiProperty prop = createOSGiProperty(key, value);
+ props.add(prop);
+ }
+ return props;
+ }
+
+ public Collection<OSGiProperty> createOSGiProperties(Map<String, Object> properties) {
+ List<OSGiProperty> props = new ArrayList<OSGiProperty>();
+ for (Map.Entry<String, Object> e : properties.entrySet()) {
+ OSGiProperty prop = createOSGiProperty(e.getKey(), e.getValue());
+ props.add(prop);
+ }
+ return props;
+ }
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiImplementationImpl.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiImplementationImpl.java
new file mode 100644
index 0000000000..4e89cbb7d3
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiImplementationImpl.java
@@ -0,0 +1,124 @@
+/*
+ * 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 org.apache.tuscany.sca.assembly.impl.ImplementationImpl;
+import org.apache.tuscany.sca.implementation.osgi.OSGiImplementation;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
+
+/**
+ * OSGi implementation
+ * All attributes from <implementation.osgi> have getters in this class
+ * This class implements OSGiImplementationInterface which is associated with OSGiImplementationProvider.
+ *
+ * @version $Rev$ $Date$
+ */
+public class OSGiImplementationImpl extends ImplementationImpl implements OSGiImplementation {
+
+ private String bundleSymbolicName;
+ private String bundleVersion;
+ private Bundle osgiBundle;
+
+ protected OSGiImplementationImpl() {
+ super(TYPE);
+ }
+
+ public OSGiImplementationImpl(String bundleSymbolicName, String bundleVersion) {
+ super(TYPE);
+ this.bundleSymbolicName = bundleSymbolicName;
+ this.bundleVersion = bundleVersion;
+ }
+
+ public String getBundleSymbolicName() {
+ return bundleSymbolicName;
+ }
+
+ public String getBundleVersion() {
+ return bundleVersion;
+ }
+
+ /**
+ * Since OSGi implementation annotations may not be processed until much later, leave it to
+ * the OSGi invoker to decide whether pass-by-reference is allowed.
+ * @return
+ */
+ public boolean isAllowsPassByReference() {
+ return true;
+ }
+
+ public Bundle getBundle() {
+ return osgiBundle;
+ }
+
+ public void setBundle(Bundle osgiBundle) {
+ this.osgiBundle = osgiBundle;
+ if (osgiBundle != null) {
+ this.bundleSymbolicName = osgiBundle.getSymbolicName();
+ this.bundleVersion = (String)osgiBundle.getHeaders().get(Constants.BUNDLE_VERSION);
+ }
+ }
+
+ public void setBundleSymbolicName(String bundleSymbolicName) {
+ this.bundleSymbolicName = bundleSymbolicName;
+ }
+
+ public void setBundleVersion(String bundleVersion) {
+ this.bundleVersion = bundleVersion;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + ((bundleSymbolicName == null) ? 0 : bundleSymbolicName.hashCode());
+ result = prime * result + ((bundleVersion == null) ? 0 : bundleVersion.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!super.equals(obj)) {
+ return false;
+ }
+ if (!(obj instanceof OSGiImplementationImpl)) {
+ return false;
+ }
+ OSGiImplementationImpl other = (OSGiImplementationImpl)obj;
+ if (bundleSymbolicName == null) {
+ if (other.bundleSymbolicName != null) {
+ return false;
+ }
+ } else if (!bundleSymbolicName.equals(other.bundleSymbolicName)) {
+ return false;
+ }
+ if (bundleVersion == null) {
+ if (other.bundleVersion != null) {
+ return false;
+ }
+ } else if (!bundleVersion.equals(other.bundleVersion)) {
+ return false;
+ }
+ return true;
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiPropertyImpl.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiPropertyImpl.java
new file mode 100644
index 0000000000..b3e934a970
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiPropertyImpl.java
@@ -0,0 +1,69 @@
+/*
+ * 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 org.apache.tuscany.sca.implementation.osgi.OSGiProperty;
+
+/**
+ * Implementation of OSGiProperty
+ */
+public class OSGiPropertyImpl implements OSGiProperty {
+ private String name;
+ private String type;
+ private Object value;
+ private String stringValue;
+
+ public OSGiPropertyImpl() {
+ super();
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public void setValue(Object value) {
+ this.value = value;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getStringValue() {
+ return stringValue;
+ }
+
+ public void setStringValue(String stringValue) {
+ this.stringValue = stringValue;
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/SCAConfigImpl.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/SCAConfigImpl.java
new file mode 100644
index 0000000000..4bb1b2340f
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/SCAConfigImpl.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.impl;
+
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.implementation.osgi.SCAConfig;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.PolicySet;
+
+/**
+ *
+ */
+public class SCAConfigImpl implements SCAConfig {
+ private String targetNamespace = null;
+ private List<Intent> intents = new CopyOnWriteArrayList<Intent>();
+ private List<PolicySet> policySets = new CopyOnWriteArrayList<PolicySet>();
+ private List<Binding> bindings = new CopyOnWriteArrayList<Binding>();
+
+ public List<Intent> getIntents() {
+ return intents;
+ }
+
+ public List<PolicySet> getPolicySets() {
+ return policySets;
+ }
+
+ public String getTargetNamespace() {
+ return targetNamespace;
+ }
+
+ public void setTargetNamespace(String ns) {
+ this.targetNamespace = ns;
+ }
+
+ public List<Binding> getBindings() {
+ return bindings;
+ }
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/ServiceDescriptionImpl.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/ServiceDescriptionImpl.java
new file mode 100644
index 0000000000..5bd1d17253
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/ServiceDescriptionImpl.java
@@ -0,0 +1,51 @@
+/*
+ * 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.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 Map<String, Object> properties = new HashMap<String, Object>();
+
+ protected ServiceDescriptionImpl() {
+ super();
+ }
+
+ public List<String> getInterfaces() {
+ return Arrays.asList((String[])properties.get(Constants.OBJECTCLASS));
+ }
+
+ public Map<String, Object> getProperties() {
+ return properties;
+ }
+
+ public String toString() {
+ return "endpoint-description: " + properties;
+ }
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/ServiceDescriptionsFactoryImpl.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/ServiceDescriptionsFactoryImpl.java
new file mode 100644
index 0000000000..716984a13b
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/ServiceDescriptionsFactoryImpl.java
@@ -0,0 +1,48 @@
+/*
+ * 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 org.apache.tuscany.sca.implementation.osgi.SCAConfig;
+import org.apache.tuscany.sca.implementation.osgi.ServiceDescription;
+import org.apache.tuscany.sca.implementation.osgi.ServiceDescriptions;
+import org.apache.tuscany.sca.implementation.osgi.ServiceDescriptionsFactory;
+
+/**
+ * The factory implementation
+ */
+public class ServiceDescriptionsFactoryImpl implements ServiceDescriptionsFactory {
+
+ protected ServiceDescriptionsFactoryImpl() {
+ super();
+ }
+
+ public ServiceDescription createServiceDescription() {
+ return new ServiceDescriptionImpl();
+ }
+
+ public ServiceDescriptions createServiceDescriptions() {
+ return new ServiceDescriptionsImpl();
+ }
+
+ public SCAConfig createSCAConfig() {
+ return new SCAConfigImpl();
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/ServiceDescriptionsImpl.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/ServiceDescriptionsImpl.java
new file mode 100644
index 0000000000..c249c053a4
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/ServiceDescriptionsImpl.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.implementation.osgi.ServiceDescription;
+import org.apache.tuscany.sca.implementation.osgi.ServiceDescriptions;
+
+/**
+ *
+ */
+public class ServiceDescriptionsImpl extends ArrayList<ServiceDescription> implements ServiceDescriptions {
+ private static final long serialVersionUID = 6205649013621747968L;
+
+ protected ServiceDescriptionsImpl() {
+ super();
+ }
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/BluePrintComponentsProcessor.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/BluePrintComponentsProcessor.java
new file mode 100644
index 0000000000..ca6b0b70e1
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/BluePrintComponentsProcessor.java
@@ -0,0 +1,144 @@
+/*
+ * 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.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.ComponentType;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.contribution.processor.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.processor.ContributionWriteException;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+
+/*
+<!-- A sample module-context.xml for OSGI RFC 124 (BluePrint Service) -->
+<components xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+ <component id="CalculatorComponent" class="calculator.dosgi.impl.CalculatorServiceImpl">
+ <property name="addService" ref="AddService" />
+ <property name="subtractService" ref="SubtractService" />
+ <property name="multiplyService" ref="MultiplyService" />
+ <property name="divideService" ref="DivideService" />
+ </component>
+
+ <!-- We can derive the SCA services for the implementation.osgi -->
+ <service id="CalculatorService" ref="CalculatorComponent" interface="calculator.dosgi.CalculatorService">
+ </service>
+
+ <!-- We can derive the SCA references for the implementation.osgi -->
+ <reference id="AddService" interface="calculator.dosgi.operations.AddService">
+ </reference>
+ <reference id="SubtractService" interface="calculator.dosgi.operations.SubtractService">
+ </reference>
+ <reference id="MultiplyService" interface="calculator.dosgi.operations.MultiplyService">
+ </reference>
+ <reference id="DivideService" interface="calculator.dosgi.operations.DivideService">
+ </reference>
+
+</components>
+*/
+public class BluePrintComponentsProcessor implements StAXArtifactProcessor<ComponentType> {
+ private static final String BLUE_PRINT_NS = "http://www.osgi.org/xmlns/blueprint/v1.0.0";
+ private static final String COMPOMENTS = "components";
+ private static final QName COMPONENTS_QNAME = new QName(BLUE_PRINT_NS, COMPOMENTS);
+
+ private AssemblyFactory factory;
+ private JavaInterfaceFactory javaInterfaceFactory;
+
+ public BluePrintComponentsProcessor(FactoryExtensionPoint modelFactories) {
+ this.factory = modelFactories.getFactory(AssemblyFactory.class);
+ this.javaInterfaceFactory = modelFactories.getFactory(JavaInterfaceFactory.class);
+ }
+
+ public ComponentType read(XMLStreamReader reader, ProcessorContext context) throws XMLStreamException {
+ int event = reader.getEventType();
+ ComponentType componentType = factory.createComponentType();
+ while (true) {
+ switch (event) {
+ case XMLStreamConstants.START_ELEMENT:
+ QName name = reader.getName();
+ if (COMPONENTS_QNAME.equals(name)) {
+ //
+ } else if ("reference".equals(name.getLocalPart())) {
+ Reference ref = factory.createReference();
+ ref.setName(reader.getAttributeValue(null, "id"));
+ String interfaceName = reader.getAttributeValue(null, "interface");
+ InterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract();
+ ref.setInterfaceContract(interfaceContract);
+ JavaInterface javaInterface = javaInterfaceFactory.createJavaInterface();
+ javaInterface.setUnresolved(true);
+ javaInterface.setName(interfaceName);
+ interfaceContract.setInterface(javaInterface);
+ componentType.getReferences().add(ref);
+ } else if ("service".equals(name.getLocalPart())) {
+ Service service = factory.createService();
+ String interfaceName = reader.getAttributeValue(null, "interface");
+ InterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract();
+ service.setInterfaceContract(interfaceContract);
+ JavaInterface javaInterface = javaInterfaceFactory.createJavaInterface();
+ javaInterface.setUnresolved(true);
+ javaInterface.setName(interfaceName);
+ interfaceContract.setInterface(javaInterface);
+ componentType.getServices().add(service);
+ }
+ break;
+ case XMLStreamConstants.END_ELEMENT:
+ name = reader.getName();
+ if (COMPONENTS_QNAME.equals(name)) {
+ return componentType;
+ }
+ break;
+ }
+ if (reader.hasNext()) {
+ event = reader.next();
+ } else {
+ return componentType;
+ }
+ }
+ }
+
+ public QName getArtifactType() {
+ return COMPONENTS_QNAME;
+ }
+
+ public void write(ComponentType model, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException,
+ XMLStreamException {
+ // TODO: To be implemented
+ }
+
+ public Class<ComponentType> getModelType() {
+ return ComponentType.class;
+ }
+
+ public void resolve(ComponentType model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException {
+ // TODO: To be implemented
+ }
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiComponentProcessor.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiComponentProcessor.java
new file mode 100644
index 0000000000..860d3f6f45
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiComponentProcessor.java
@@ -0,0 +1,174 @@
+/*
+ * 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.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.ComponentType;
+import org.apache.tuscany.sca.assembly.Property;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.contribution.processor.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.processor.ContributionWriteException;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+
+/*
+<scr:component name="CalculatorComponent"
+ xmlns:scr="http://www.osgi.org/xmlns/scr/v1.0.0">
+ <implementation class="calculator.dosgi.CalculatorServiceDSImpl" />
+ <service>
+ <provide interface="calculator.dosgi.CalculatorService" />
+ </service>
+
+ <reference name="addService" interface="calculator.dosgi.operations.AddService" bind="setAddService" unbind="unsetAddService"
+ policy="dynamic" />
+ <reference name="subtractService" interface="calculator.dosgi.operations.SubtractService" bind="setSubtractService"
+ unbind="unsetSubtractService" policy="dynamic" />
+ <reference name="multiplyService" interface="calculator.dosgi.operations.MultiplyService" bind="setMultiplyService"
+ unbind="unsetMultiplyService" policy="dynamic" />
+ <reference name="divideService" interface="calculator.dosgi.operations.DivideService" bind="setDivideService"
+ unbind="unsetDivideService" policy="dynamic" />
+
+</scr:component>
+*/
+public class OSGiComponentProcessor implements StAXArtifactProcessor<ComponentType> {
+ private static final String OSGI_SCR_NS = "http://www.osgi.org/xmlns/scr/v1.0.0";
+ private static final String COMPOMENT = "component";
+ private static final QName COMPONENT_QNAME = new QName(OSGI_SCR_NS, COMPOMENT);
+
+ private AssemblyFactory factory;
+ private JavaInterfaceFactory javaInterfaceFactory;
+
+
+ public OSGiComponentProcessor(FactoryExtensionPoint modelFactories) {
+ this.factory = modelFactories.getFactory(AssemblyFactory.class);
+ this.javaInterfaceFactory = modelFactories.getFactory(JavaInterfaceFactory.class);
+ }
+
+ public ComponentType read(XMLStreamReader reader, ProcessorContext context) throws XMLStreamException {
+ int event = reader.getEventType();
+ ComponentType componentType = factory.createComponentType();
+ while (true) {
+ switch (event) {
+ case XMLStreamConstants.START_ELEMENT:
+ QName name = reader.getName();
+ if (COMPONENT_QNAME.equals(name)) {
+ //
+ } else if ("reference".equals(name.getLocalPart())) {
+ Reference ref = factory.createReference();
+ ref.setName(reader.getAttributeValue(null, "name"));
+ String interfaceName = reader.getAttributeValue(null, "interface");
+ InterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract();
+ ref.setInterfaceContract(interfaceContract);
+ JavaInterface javaInterface = javaInterfaceFactory.createJavaInterface();
+ javaInterface.setUnresolved(true);
+ javaInterface.setName(interfaceName);
+ interfaceContract.setInterface(javaInterface);
+ componentType.getReferences().add(ref);
+ } else if ("provide".equals(name.getLocalPart())) {
+ Service service = factory.createService();
+ String interfaceName = reader.getAttributeValue(null, "interface");
+ InterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract();
+ service.setInterfaceContract(interfaceContract);
+ JavaInterface javaInterface = javaInterfaceFactory.createJavaInterface();
+ javaInterface.setUnresolved(true);
+ javaInterface.setName(interfaceName);
+ interfaceContract.setInterface(javaInterface);
+ componentType.getServices().add(service);
+ } 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";
+ }
+ if (propValue == null) {
+ propValue = reader.getElementText();
+ }
+ if (propValue != null) {
+ propValue = propValue.trim();
+ }
+ 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);
+ }
+ Property property = factory.createProperty();
+ property.setName(propName);
+ property.setValue(prop);
+ componentType.getProperties().add(property);
+ }
+ break;
+ case XMLStreamConstants.END_ELEMENT:
+ name = reader.getName();
+ if (COMPONENT_QNAME.equals(name)) {
+ return componentType;
+ }
+ break;
+ }
+ if (reader.hasNext()) {
+ event = reader.next();
+ } else {
+ return componentType;
+ }
+ }
+ }
+
+ public QName getArtifactType() {
+ return COMPONENT_QNAME;
+ }
+
+ public void write(ComponentType model, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException,
+ XMLStreamException {
+ // TODO: To be implemented
+ }
+
+ public Class<ComponentType> getModelType() {
+ return ComponentType.class;
+ }
+
+ public void resolve(ComponentType model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException {
+ // TODO: To be implemented
+ }
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationActivator.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationActivator.java
new file mode 100644
index 0000000000..b604447696
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationActivator.java
@@ -0,0 +1,47 @@
+/*
+ * 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 org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+/**
+ * Bundle activator to receive the BundleContext
+ */
+public class OSGiImplementationActivator implements BundleActivator {
+ private static BundleContext bundleContext;
+
+ public void start(BundleContext context) throws Exception {
+ bundleContext = context;
+ }
+
+ public void stop(BundleContext context) throws Exception {
+ bundleContext = null;
+ }
+
+ public static BundleContext getBundleContext() {
+ return bundleContext;
+ }
+
+ static void setBundleContext(BundleContext bundleContext) {
+ OSGiImplementationActivator.bundleContext = bundleContext;
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java
new file mode 100644
index 0000000000..d98616cbc2
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java
@@ -0,0 +1,342 @@
+/*
+ * 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 static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+import static org.apache.tuscany.sca.implementation.osgi.OSGiImplementation.BUNDLE_SYMBOLICNAME;
+import static org.apache.tuscany.sca.implementation.osgi.OSGiImplementation.BUNDLE_VERSION;
+import static org.apache.tuscany.sca.implementation.osgi.OSGiImplementation.IMPLEMENTATION_OSGI;
+
+import java.net.URI;
+import java.net.URL;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.ComponentType;
+import org.apache.tuscany.sca.assembly.Property;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.assembly.Service;
+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.ProcessorContext;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.resolver.ClassReference;
+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.OSGiImplementation;
+import org.apache.tuscany.sca.implementation.osgi.OSGiImplementationFactory;
+import org.apache.tuscany.sca.implementation.osgi.OSGiProperty;
+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.apache.tuscany.sca.interfacedef.Interface;
+import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Version;
+
+/**
+ *
+ * Process an <implementation.osgi/> element in a component definition. An instance of
+ * OSGiImplementation is created.
+ * Also associates the component type file with the implementation.
+ *
+ * @version $Rev$ $Date$
+ */
+public class OSGiImplementationProcessor implements StAXArtifactProcessor<OSGiImplementation> {
+ private static final String BUNDLE_COMPONENT_TYPE = "OSGI-INF/sca/bundle.componentType";
+ private static final String COMPONENT_TYPE_HEADER = "SCA-ComponentType";
+
+ private AssemblyFactory assemblyFactory;
+ private ServiceDescriptionsFactory serviceDescriptionsFactory;
+ private OSGiImplementationFactory osgiImplementationFactory;
+ private JavaInterfaceFactory javaInterfaceFactory;
+
+ private ExtensionPointRegistry registry;
+ private StAXArtifactProcessor artifactProcessor;
+
+ protected OSGiImplementationProcessor(FactoryExtensionPoint modelFactories) {
+ this.serviceDescriptionsFactory = modelFactories.getFactory(ServiceDescriptionsFactory.class);
+ this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class);
+ this.osgiImplementationFactory = modelFactories.getFactory(OSGiImplementationFactory.class);
+ this.javaInterfaceFactory = modelFactories.getFactory(JavaInterfaceFactory.class);
+ }
+
+ public OSGiImplementationProcessor(ExtensionPointRegistry registry, StAXArtifactProcessor processor) {
+ this(registry.getExtensionPoint(FactoryExtensionPoint.class));
+ this.artifactProcessor = processor;
+ this.registry = registry;
+ }
+
+ /**
+ * Report a error.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(Monitor monitor, String message, Object model, Object... messageParameters) {
+ if (monitor != null) {
+ Problem problem =
+ monitor.createProblem(this.getClass().getName(),
+ "impl-osgi-validation-messages",
+ Severity.ERROR,
+ model,
+ message,
+ (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
+ public QName getArtifactType() {
+ return IMPLEMENTATION_OSGI;
+ }
+
+ public Class<OSGiImplementation> getModelType() {
+ return OSGiImplementation.class;
+ }
+
+ public OSGiImplementation read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException {
+ assert IMPLEMENTATION_OSGI.equals(reader.getName());
+
+ String bundleSymbolicName = reader.getAttributeValue(null, BUNDLE_SYMBOLICNAME);
+ String bundleVersion = reader.getAttributeValue(null, BUNDLE_VERSION);
+
+ OSGiImplementation implementation = osgiImplementationFactory.createOSGiImplementation();
+ implementation.setBundleSymbolicName(bundleSymbolicName);
+ implementation.setBundleVersion(bundleVersion);
+
+ implementation.setUnresolved(true);
+
+ // Skip to the end of <implementation.osgi>
+ while (reader.hasNext()) {
+ int next = reader.next();
+ switch (next) {
+ case START_ELEMENT:
+ break;
+ case END_ELEMENT:
+ if (IMPLEMENTATION_OSGI.equals(reader.getName())) {
+ return implementation;
+ }
+ break;
+ }
+ }
+ return implementation;
+ }
+
+ public void resolve(OSGiImplementation impl, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException {
+
+ if (impl == null || !impl.isUnresolved())
+ return;
+ Monitor monitor = context.getMonitor();
+ impl.setUnresolved(false);
+
+ BundleContext bundleContext = OSGiImplementationActivator.getBundleContext();
+ if (bundleContext == null) {
+ // FIXME: What if the OSGi is not started
+ return;
+ }
+ Bundle bundle = null;
+ for (Bundle b : bundleContext.getBundles()) {
+ String sn = b.getSymbolicName();
+ String ver = (String)b.getHeaders().get(Constants.BUNDLE_VERSION);
+ if (!impl.getBundleSymbolicName().equals(sn)) {
+ continue;
+ }
+ Version v1 = Version.parseVersion(ver);
+ Version v2 = Version.parseVersion(impl.getBundleVersion());
+ if (v1.equals(v2)) {
+ bundle = b;
+ break;
+ }
+ }
+ if (bundle != null) {
+ impl.setBundle(bundle);
+ } else {
+ error(monitor, "CouldNotLocateOSGiBundle", impl, impl.getBundleSymbolicName());
+ //throw new ContributionResolveException("Could not locate OSGi bundle " +
+ //impl.getBundleSymbolicName());
+ return;
+ }
+
+ try {
+ if (introspect(impl, resolver, context, bundle)) {
+ return;
+ }
+ } catch (ContributionReadException e) {
+ throw new ContributionResolveException(e);
+ }
+
+ // The bundle may be different from the current contribution
+ ComponentType componentType = assemblyFactory.createComponentType();
+ // Try to find a bundle.componentType for the target bundle
+ componentType.setURI("OSGI-INF/sca/" + bundle.getSymbolicName() + "/bundle.componentType");
+ componentType.setUnresolved(true);
+ componentType = resolver.resolveModel(ComponentType.class, componentType, context);
+ if (componentType.isUnresolved()) {
+ // Create a new instance to prevent it being treated as reentry
+ // See org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver.resolveModel(Class<T>, T)
+ componentType = assemblyFactory.createComponentType();
+ // Try a generic one
+ componentType.setURI(BUNDLE_COMPONENT_TYPE);
+ componentType = resolver.resolveModel(ComponentType.class, componentType, context);
+ }
+ if (componentType.isUnresolved()) {
+ // Try to derive it from the service descriptions
+ if (!deriveFromServiceDescriptions(impl, resolver, context)) {
+ error(monitor, "MissingComponentTypeFile", impl, componentType.getURI());
+ }
+ //throw new ContributionResolveException("missing .componentType side file " + ctURI);
+ return;
+ } else {
+ mergeFromComponentType(impl, componentType, resolver, context);
+ }
+ }
+
+ private boolean deriveFromServiceDescriptions(OSGiImplementation impl, ModelResolver resolver, ProcessorContext context)
+ throws ContributionResolveException {
+ // FIXME: How to find the RFC 119 service descriptions in the contribution and
+ // derive the SCA component type from them?
+ ServiceDescriptions descriptions = serviceDescriptionsFactory.createServiceDescriptions();
+ descriptions = resolver.resolveModel(ServiceDescriptions.class, descriptions, context);
+ if (descriptions != null && !descriptions.isEmpty()) {
+ ComponentType ct = assemblyFactory.createComponentType();
+ int index = 0;
+ for (ServiceDescription ds : descriptions) {
+ for (String i : ds.getInterfaces()) {
+ Class<?> cls = getJavaClass(resolver, i, context);
+ JavaInterface javaInterface;
+ try {
+ javaInterface = javaInterfaceFactory.createJavaInterface(cls);
+ } catch (InvalidInterfaceException e) {
+ throw new ContributionResolveException(e);
+ }
+ Reference reference = assemblyFactory.createReference();
+ JavaInterfaceContract contract = javaInterfaceFactory.createJavaInterfaceContract();
+ contract.setInterface(javaInterface);
+ reference.setInterfaceContract(contract);
+ String refName = (String)ds.getProperties().get(OSGiProperty.SCA_REFERENCE);
+ if (refName == null) {
+ refName = "ref" + (index++);
+ }
+ reference.setName(refName);
+ reference.setUnresolved(false);
+ ct.getReferences().add(reference);
+ }
+ }
+ mergeFromComponentType(impl, ct, resolver, context);
+ return true;
+ }
+ return false;
+ }
+
+ private void mergeFromComponentType(OSGiImplementation impl, ComponentType componentType, ModelResolver resolver, ProcessorContext context) {
+ List<Service> services = componentType.getServices();
+ for (Service service : services) {
+ Interface interfaze = service.getInterfaceContract().getInterface();
+ if (interfaze instanceof JavaInterface) {
+ JavaInterface javaInterface = (JavaInterface)interfaze;
+ if (javaInterface.getJavaClass() == null) {
+ javaInterface.setJavaClass(getJavaClass(resolver, javaInterface.getName(), context));
+ }
+ if (service.getInterfaceContract().getCallbackInterface() instanceof JavaInterface) {
+ JavaInterface callbackInterface =
+ (JavaInterface)service.getInterfaceContract().getCallbackInterface();
+ if (callbackInterface.getJavaClass() == null) {
+ callbackInterface.setJavaClass(getJavaClass(resolver, callbackInterface.getName(), context));
+ }
+ }
+
+ impl.getServices().add(service);
+ }
+ }
+
+ List<Reference> references = componentType.getReferences();
+ for (Reference reference : references) {
+ Interface interfaze = reference.getInterfaceContract().getInterface();
+ if (interfaze instanceof JavaInterface) {
+ JavaInterface javaInterface = (JavaInterface)interfaze;
+ if (javaInterface.getJavaClass() == null) {
+ javaInterface.setJavaClass(getJavaClass(resolver, javaInterface.getName(), context));
+ }
+ impl.getReferences().add(reference);
+ } else
+ impl.getReferences().add(reference);
+ }
+
+ List<Property> properties = componentType.getProperties();
+ for (Property property : properties) {
+ impl.getProperties().add(property);
+ }
+ }
+
+ private Class<?> getJavaClass(ModelResolver resolver, String className, ProcessorContext context) {
+ ClassReference ref = new ClassReference(className);
+ ref = resolver.resolveModel(ClassReference.class, ref, context);
+ return ref.getJavaClass();
+ }
+
+ public void write(OSGiImplementation model, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException,
+ XMLStreamException {
+ String ns = IMPLEMENTATION_OSGI.getNamespaceURI();
+ writer.writeStartElement(ns, IMPLEMENTATION_OSGI.getLocalPart());
+ writer.writeAttribute(BUNDLE_SYMBOLICNAME, model.getBundleSymbolicName());
+ if (model.getBundleVersion() != null) {
+ writer.writeAttribute(BUNDLE_VERSION, model.getBundleVersion());
+ }
+ writer.writeEndElement();
+ }
+
+ private boolean introspect(OSGiImplementation implementation, ModelResolver resolver, ProcessorContext context, Bundle bundle)
+ throws ContributionReadException, ContributionResolveException {
+ String componentTypeFile = (String)bundle.getHeaders().get(COMPONENT_TYPE_HEADER);
+ if (componentTypeFile == null) {
+ componentTypeFile = BUNDLE_COMPONENT_TYPE;
+ }
+ URL url = bundle.getEntry(componentTypeFile);
+ if (url != null) {
+ URLArtifactProcessorExtensionPoint processors =
+ registry.getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
+ URLArtifactProcessor<ComponentType> processor = processors.getProcessor(ComponentType.class);
+ ComponentType componentType = processor.read(null, URI.create(BUNDLE_COMPONENT_TYPE), url, context);
+ artifactProcessor.resolve(componentType, resolver, context);
+ mergeFromComponentType(implementation, componentType, resolver, context);
+ return true;
+ }
+ return false;
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiPropertyProcessor.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiPropertyProcessor.java
new file mode 100644
index 0000000000..a0c9baf6f1
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiPropertyProcessor.java
@@ -0,0 +1,115 @@
+/*
+ * 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 static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.NAME;
+import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.PROPERTY_QNAME;
+import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.TYPE;
+import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.VALUE;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.contribution.processor.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.processor.ContributionWriteException;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+import org.apache.tuscany.sca.implementation.osgi.OSGiImplementationFactory;
+import org.apache.tuscany.sca.implementation.osgi.OSGiProperty;
+
+/**
+ * A processor for <tuscany:osgi.property>
+ */
+public class OSGiPropertyProcessor implements StAXArtifactProcessor<OSGiProperty> {
+ private OSGiImplementationFactory factory;
+
+
+ public OSGiPropertyProcessor(FactoryExtensionPoint modelFactories) {
+ this.factory = modelFactories.getFactory(OSGiImplementationFactory.class);
+ }
+
+ public OSGiProperty read(XMLStreamReader reader, ProcessorContext context) throws XMLStreamException {
+ int event = reader.getEventType();
+ OSGiProperty prop = null;
+ while (true) {
+ switch (event) {
+ case START_ELEMENT:
+ QName name = reader.getName();
+ if (PROPERTY_QNAME.equals(name)) {
+ String propName = reader.getAttributeValue(null, NAME);
+ String propValue = reader.getAttributeValue(null, VALUE);
+ String propType = reader.getAttributeValue(null, TYPE);
+
+ if (propValue == null) {
+ propValue = reader.getElementText();
+ }
+ if (propValue != null) {
+ propValue = propValue.trim();
+ }
+
+ prop = factory.createOSGiProperty(propName, propValue, propType);
+ return prop;
+ }
+ break;
+ case END_ELEMENT:
+ name = reader.getName();
+ if (PROPERTY_QNAME.equals(name)) {
+ return prop;
+ }
+ break;
+ }
+ if (reader.hasNext()) {
+ event = reader.next();
+ } else {
+ return prop;
+ }
+ }
+ }
+
+ public QName getArtifactType() {
+ return PROPERTY_QNAME;
+ }
+
+ public void write(OSGiProperty model, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException {
+ if (model.getStringValue() != null) {
+ writer.writeStartElement(PROPERTY_QNAME.getNamespaceURI(), PROPERTY_QNAME.getLocalPart());
+ writer.writeAttribute(NAME, model.getName());
+ if (model.getType() != null) {
+ writer.writeAttribute(TYPE, model.getType());
+ }
+ writer.writeAttribute(VALUE, model.getStringValue());
+ writer.writeEndElement();
+ }
+ }
+
+ public Class<OSGiProperty> getModelType() {
+ return OSGiProperty.class;
+ }
+
+ public void resolve(OSGiProperty model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException {
+ // TODO: To be implemented
+ }
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/SCAConfigProcessor.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/SCAConfigProcessor.java
new file mode 100644
index 0000000000..86ff968d0e
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/SCAConfigProcessor.java
@@ -0,0 +1,194 @@
+/*
+ * 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.List;
+
+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.BaseStAXArtifactProcessor;
+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.ProcessorContext;
+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.SCAConfig;
+import org.apache.tuscany.sca.implementation.osgi.ServiceDescriptionsFactory;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.PolicySet;
+
+/*
+<?xml version="1.0" encoding="UTF-8"?>
+<scact:sca-config targetNamespace="http://www.foocorp.com/definitions"
+ xmlns:scact="http://www.osgi.org/xmlns/scact/v1.0.0"
+ xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200912"
+ xmlns:foocorp="http://www.foocorp.com/definitions"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.osgi.org/xmlns/scact/v1.0.0 http://www.osgi.org/xmlns/scact/v1.0.0/sca-config.xsd">
+
+ <sca:binding.ws name="com.foocorp.FooOrderWebServiceBinding"
+ uri="http://www.foocorp.com/FooOrderService" requires="sca:soap.1_2" />
+ <foocorp:binding.rmi name="com.foocorp.FooOrderRMIBinding"
+ host="www.foocorp.com" port="8099" serviceName="FooOrderService" />
+</scact:sca-config>
+*/
+public class SCAConfigProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<SCAConfig> {
+ private static final QName SCA_CONFIG_QNAME = new QName("http://www.osgi.org/xmlns/scact/v1.0.0", "sca-config");
+ private ServiceDescriptionsFactory factory;
+ private StAXArtifactProcessor processor;
+
+ public SCAConfigProcessor(ExtensionPointRegistry registry, StAXArtifactProcessor processor) {
+ this.processor = processor;
+ FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class);
+ this.factory = modelFactories.getFactory(ServiceDescriptionsFactory.class);
+ }
+
+ public SCAConfig read(XMLStreamReader reader, ProcessorContext context) throws XMLStreamException,
+ ContributionReadException {
+ int event = reader.getEventType();
+ SCAConfig definitions = factory.createSCAConfig();
+ String targetNamespace = null;
+ while (true) {
+ switch (event) {
+ case XMLStreamConstants.START_ELEMENT:
+ QName name = reader.getName();
+ if (SCA_CONFIG_QNAME.equals(name)) {
+ targetNamespace = reader.getAttributeValue(null, "targetNamespace");
+ definitions.setTargetNamespace(targetNamespace);
+ } else {
+ Object extension = processor.read(reader, context);
+ if (extension != null) {
+ if (extension instanceof Intent) {
+ Intent intent = (Intent)extension;
+ intent.setName(new QName(targetNamespace, intent.getName().getLocalPart()));
+ definitions.getIntents().add(intent);
+ for (Intent i : intent.getQualifiedIntents()) {
+ i.setName(new QName(targetNamespace, i.getName().getLocalPart()));
+ }
+ } else if (extension instanceof PolicySet) {
+ PolicySet policySet = (PolicySet)extension;
+ policySet.setName(new QName(targetNamespace, policySet.getName().getLocalPart()));
+ definitions.getPolicySets().add(policySet);
+ } else if (extension instanceof Binding) {
+ Binding binding = (Binding)extension;
+ definitions.getBindings().add(binding);
+ }
+ }
+ }
+ break;
+ case XMLStreamConstants.END_ELEMENT:
+ name = reader.getName();
+ if (SCA_CONFIG_QNAME.equals(name)) {
+ return definitions;
+ }
+ break;
+ }
+ if (reader.hasNext()) {
+ event = reader.next();
+ } else {
+ return definitions;
+ }
+ }
+ }
+
+ public QName getArtifactType() {
+ return SCA_CONFIG_QNAME;
+ }
+
+ public void write(SCAConfig definitions, XMLStreamWriter writer, ProcessorContext context)
+ throws ContributionWriteException, XMLStreamException {
+
+ writeStartDocument(writer,
+ SCA_CONFIG_QNAME.getNamespaceURI(),
+ SCA_CONFIG_QNAME.getLocalPart(),
+ new XAttr("targetNamespace", definitions.getTargetNamespace()));
+
+ for (Binding binding : definitions.getBindings()) {
+ processor.write(binding, writer, context);
+ }
+
+ for (Intent policyIntent : definitions.getIntents()) {
+ processor.write(policyIntent, writer, context);
+ }
+
+ for (PolicySet policySet : definitions.getPolicySets()) {
+ processor.write(policySet, writer, context);
+ }
+
+ writeEndDocument(writer);
+ }
+
+ public void resolve(SCAConfig scaDefns, ModelResolver resolver, ProcessorContext context)
+ throws ContributionResolveException {
+ // start by adding all of the top level artifacts into the resolver as there
+ // are many cross artifact references in a definitions file and we don't want
+ // to be dependent on the order things appear
+
+ List<Intent> intents = new ArrayList<Intent>();
+ List<PolicySet> policySets = new ArrayList<PolicySet>();
+ List<PolicySet> referredPolicySets = new ArrayList<PolicySet>();
+
+ for (Intent intent : scaDefns.getIntents()) {
+ intents.add(intent);
+ resolver.addModel(intent, context);
+ for (Intent i : intent.getQualifiedIntents()) {
+ intents.add(i);
+ resolver.addModel(i, context);
+ }
+ }
+
+ for (PolicySet policySet : scaDefns.getPolicySets()) {
+ if (policySet.getReferencedPolicySets().isEmpty()) {
+ policySets.add(policySet);
+ } else {
+ referredPolicySets.add(policySet);
+ }
+
+ resolver.addModel(policySet, context);
+ }
+
+ // now resolve everything to ensure that any references between
+ // artifacts are satisfied
+
+ for (Intent policyIntent : intents)
+ processor.resolve(policyIntent, resolver, context);
+
+ for (PolicySet policySet : policySets)
+ processor.resolve(policySet, resolver, context);
+
+ for (PolicySet policySet : referredPolicySets)
+ processor.resolve(policySet, resolver, context);
+
+ }
+
+ public Class<SCAConfig> getModelType() {
+ return SCAConfig.class;
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsDocumentProcessor.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsDocumentProcessor.java
new file mode 100644
index 0000000000..ad175e009c
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsDocumentProcessor.java
@@ -0,0 +1,99 @@
+/*
+ * 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.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URL;
+import java.net.URLConnection;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
+import org.apache.tuscany.sca.contribution.processor.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.ValidatingXMLInputFactory;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+import org.apache.tuscany.sca.implementation.osgi.ServiceDescriptions;
+
+/**
+ * The service descriptions document processor
+ */
+public class ServiceDescriptionsDocumentProcessor implements URLArtifactProcessor<ServiceDescriptions> {
+ private XMLInputFactory inputFactory;
+ private StAXArtifactProcessor extensionProcessor;
+
+ public ServiceDescriptionsDocumentProcessor(FactoryExtensionPoint modelFactories,
+ StAXArtifactProcessor staxProcessor) {
+ super();
+ this.extensionProcessor = staxProcessor;
+ this.inputFactory = modelFactories.getFactory(ValidatingXMLInputFactory.class);
+ }
+
+ public String getArtifactType() {
+ return "/OSGI-INF/remote-service/*.xml";
+ }
+
+ public ServiceDescriptions read(URL contributionURL, URI artifactURI, URL artifactURL, ProcessorContext context)
+ throws ContributionReadException {
+ InputStream is = null;
+ try {
+ URLConnection connection = artifactURL.openConnection();
+ connection.setUseCaches(false);
+ is = connection.getInputStream();
+ } catch (IOException e) {
+ ContributionReadException ce = new ContributionReadException(e);
+ throw ce;
+ }
+ try {
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+ ValidatingXMLInputFactory.setMonitor(reader, context.getMonitor());
+ Object result = extensionProcessor.read(reader, context);
+ return (ServiceDescriptions)result;
+ } catch (XMLStreamException e) {
+ ContributionReadException ce = new ContributionReadException(e);
+ throw ce;
+ } finally {
+ try {
+ if (is != null) {
+ is.close();
+ is = null;
+ }
+ } catch (IOException ioe) {
+ //ignore
+ }
+ }
+
+ }
+
+ public Class<ServiceDescriptions> getModelType() {
+ return ServiceDescriptions.class;
+ }
+
+ public void resolve(ServiceDescriptions model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException {
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsModelResolver.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsModelResolver.java
new file mode 100644
index 0000000000..cd62d5cfaf
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsModelResolver.java
@@ -0,0 +1,59 @@
+/*
+ * 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 org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+import org.apache.tuscany.sca.implementation.osgi.ServiceDescriptions;
+import org.apache.tuscany.sca.implementation.osgi.ServiceDescriptionsFactory;
+
+/**
+ *
+ */
+public class ServiceDescriptionsModelResolver implements ModelResolver {
+ private ServiceDescriptions serviceDescriptions;
+
+ public ServiceDescriptionsModelResolver(Contribution contribution, FactoryExtensionPoint modelFactories) {
+ ServiceDescriptionsFactory factory = modelFactories.getFactory(ServiceDescriptionsFactory.class);
+ this.serviceDescriptions = factory.createServiceDescriptions();
+ }
+
+ public void addModel(Object resolved, ProcessorContext context) {
+ // Merge the service descriptions
+ if (resolved instanceof ServiceDescriptions) {
+ serviceDescriptions.addAll((ServiceDescriptions)resolved);
+ }
+ }
+
+ public Object removeModel(Object resolved, ProcessorContext context) {
+ // Remove the service descriptions
+ if (resolved instanceof ServiceDescriptions) {
+ serviceDescriptions.removeAll((ServiceDescriptions)resolved);
+ }
+ return resolved;
+ }
+
+ public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) {
+ // Always return the aggregated service descriptions
+ return modelClass.cast(serviceDescriptions);
+ }
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsProcessor.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsProcessor.java
new file mode 100644
index 0000000000..891fed13d0
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsProcessor.java
@@ -0,0 +1,255 @@
+/*
+ * 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.Collection;
+import java.util.HashSet;
+import java.util.StringTokenizer;
+
+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.contribution.processor.BaseStAXArtifactProcessor;
+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.ProcessorContext;
+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.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"?>
+<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>
+ <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>
+*/
+public class ServiceDescriptionsProcessor extends BaseStAXArtifactProcessor implements
+ StAXArtifactProcessor<ServiceDescriptions> {
+ private ServiceDescriptionsFactory factory;
+ private 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 {
+ int event = reader.getEventType();
+ 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_DESCRIPTIONS_QNAME.equals(name)) {
+ sds = factory.createServiceDescriptions();
+ } else if (ServiceDescriptions.SERVICE_DESCRIPTION_QNAME.equals(name)) {
+ sd = factory.createServiceDescription();
+ sds.add(sd);
+ } else if ("property".equals(name.getLocalPart())) {
+ 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);
+ }
+ } else if ("list".equals(name.getLocalPart())) {
+ if (propertyValue != null) {
+ throw new IllegalArgumentException("@value and <list> are both present");
+ }
+ propertyValue = new ArrayList<Object>();
+ multiValued = true;
+ } else if ("array".equals(name.getLocalPart())) {
+ if (propertyValue != null) {
+ throw new IllegalArgumentException("@value and <array> are both present");
+ }
+ propertyValue = new ArrayList<Object>();
+ multiValued = true;
+ } else if ("set".equals(name.getLocalPart())) {
+ if (propertyValue != null) {
+ throw new IllegalArgumentException("@value and <set> are both present");
+ }
+ 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;
+ }
+ }
+ } else {
+ // 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;
+ }
+ }
+ }
+ break;
+ case XMLStreamConstants.END_ELEMENT:
+ name = reader.getName();
+ if (ServiceDescriptions.SERVICE_DESCRIPTION_QNAME.equals(name)) {
+ // Reset the sd
+ sd = null;
+ } 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;
+ }
+ if (reader.hasNext()) {
+ event = reader.next();
+ } else {
+ return sds;
+ }
+ }
+ }
+
+ 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
+ * @param value
+ * @return
+ */
+ private String toQNames(XMLStreamReader reader, String value) {
+ if (value == null) {
+ return null;
+ }
+ StringBuffer sb = new StringBuffer();
+ for (StringTokenizer tokens = new StringTokenizer(value, " \t\n\r\f,"); tokens.hasMoreTokens();) {
+ QName qname = getQNameValue(reader, tokens.nextToken());
+ sb.append(qname.toString()).append(' ');
+ }
+ return sb.toString().trim();
+ }
+
+ public QName getArtifactType() {
+ return ServiceDescriptions.SERVICE_DESCRIPTIONS_QNAME;
+ }
+
+ public void write(ServiceDescriptions model, XMLStreamWriter writer, ProcessorContext context)
+ throws ContributionWriteException, XMLStreamException {
+ // TODO: To be implemented
+ }
+
+ public Class<ServiceDescriptions> getModelType() {
+ return ServiceDescriptions.class;
+ }
+
+ public void resolve(ServiceDescriptions model, ModelResolver resolver, ProcessorContext context)
+ throws ContributionResolveException {
+ }
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/resources/META-INF/definitions.xml b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/resources/META-INF/definitions.xml
new file mode 100644
index 0000000000..8718e58d8e
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/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/200912"
+ 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/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
new file mode 100644
index 0000000000..e8973a91db
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
@@ -0,0 +1,22 @@
+# 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.
+
+# 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/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/branches/2.0-Beta1/modules/implementation-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor
new file mode 100644
index 0000000000..7e7a20b69c
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor
@@ -0,0 +1,20 @@
+# 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.
+
+# Implementation class for the artifact processor extension
+org.apache.tuscany.sca.implementation.osgi.xml.ServiceDescriptionsDocumentProcessor;type=/OSGI-INF/remote-service/*.xml,model=org.apache.tuscany.sca.implementation.osgi.ServiceDescriptions
+
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver
new file mode 100644
index 0000000000..78e47fed7e
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver
@@ -0,0 +1,18 @@
+# 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.
+org.apache.tuscany.sca.implementation.osgi.xml.ServiceDescriptionsModelResolver;model=org.apache.tuscany.sca.implementation.osgi.ServiceDescriptions
+
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.osgi.OSGiImplementationFactory b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.osgi.OSGiImplementationFactory
new file mode 100644
index 0000000000..7c6660980b
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.osgi.OSGiImplementationFactory
@@ -0,0 +1,19 @@
+# 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.
+
+org.apache.tuscany.sca.implementation.osgi.DefaultOSGiImplementationFactory
+
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.osgi.ServiceDescriptionsFactory b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.osgi.ServiceDescriptionsFactory
new file mode 100644
index 0000000000..47193ece15
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.osgi.ServiceDescriptionsFactory
@@ -0,0 +1,18 @@
+# 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.
+org.apache.tuscany.sca.implementation.osgi.DefaultServiceDescriptionsFactory
+
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/resources/impl-osgi-validation-messages.properties b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/resources/impl-osgi-validation-messages.properties
new file mode 100644
index 0000000000..a406ea21c3
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/main/resources/impl-osgi-validation-messages.properties
@@ -0,0 +1,26 @@
+#
+#
+# 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.
+#
+#
+ContributionReadException = ContributionReadException occured due to:
+ContributionResolveException = ContributionResolveException occured due to:
+PropertyShouldSpecifySR = Properties in implementation.osgi should specify service or reference
+CouldNotLocateOSGiBundle = Could not locate OSGi bundle: {0}
+MissingComponentTypeFile = Missing .componentType side file: {0}
+OSGiFrameworkNotStarted = OSGi Framework is not started \ No newline at end of file
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/calculator/dosgi/CalculatorService.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/calculator/dosgi/CalculatorService.java
new file mode 100644
index 0000000000..656b78b717
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/calculator/dosgi/CalculatorService.java
@@ -0,0 +1,39 @@
+/*
+ * 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 calculator.dosgi;
+
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+
+import org.oasisopen.sca.annotation.Remotable;
+
+/**
+ * The Calculator service interface.
+ */
+@Remotable
+public interface CalculatorService extends Remote {
+
+ double add(double n1, double n2) throws RemoteException;
+
+ double subtract(double n1, double n2) throws RemoteException;
+
+ double multiply(double n1, double n2) throws RemoteException;
+
+ double divide(double n1, double n2) throws RemoteException;
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/calculator/dosgi/operations/AddService.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/calculator/dosgi/operations/AddService.java
new file mode 100644
index 0000000000..971500782f
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/calculator/dosgi/operations/AddService.java
@@ -0,0 +1,31 @@
+/*
+ * 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 calculator.dosgi.operations;
+
+import org.oasisopen.sca.annotation.Remotable;
+
+/**
+ * The interface for the add service
+ */
+@Remotable
+public interface AddService {
+
+ double add(double n1, double n2);
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/calculator/dosgi/operations/DivideService.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/calculator/dosgi/operations/DivideService.java
new file mode 100644
index 0000000000..49b8a1c0bf
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/calculator/dosgi/operations/DivideService.java
@@ -0,0 +1,31 @@
+/*
+ * 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 calculator.dosgi.operations;
+
+import org.oasisopen.sca.annotation.Remotable;
+
+/**
+ * The interface for the divide service
+ */
+@Remotable
+public interface DivideService {
+
+ double divide(double n1, double n2);
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/calculator/dosgi/operations/MultiplyService.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/calculator/dosgi/operations/MultiplyService.java
new file mode 100644
index 0000000000..f4e59d12ea
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/calculator/dosgi/operations/MultiplyService.java
@@ -0,0 +1,31 @@
+/*
+ * 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 calculator.dosgi.operations;
+
+import org.oasisopen.sca.annotation.Remotable;
+
+/**
+ * The interface for the multiply service
+ */
+@Remotable
+public interface MultiplyService {
+
+ double multiply(double n1, double n2);
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/calculator/dosgi/operations/SubtractService.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/calculator/dosgi/operations/SubtractService.java
new file mode 100644
index 0000000000..bfb9b820f7
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/calculator/dosgi/operations/SubtractService.java
@@ -0,0 +1,31 @@
+/*
+ * 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 calculator.dosgi.operations;
+
+import org.oasisopen.sca.annotation.Remotable;
+
+/**
+ * The interface for the subtract service
+ */
+@Remotable
+public interface SubtractService {
+
+ double subtract(double n1, double n2);
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/BluePrintComponentsProcessorTestCase.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/BluePrintComponentsProcessorTestCase.java
new file mode 100644
index 0000000000..224467181b
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/BluePrintComponentsProcessorTestCase.java
@@ -0,0 +1,89 @@
+/*
+ * 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.io.StringReader;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.assembly.ComponentType;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.core.DefaultFactoryExtensionPoint;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class BluePrintComponentsProcessorTestCase {
+ private static final String xml =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<components xmlns=\"http://www.osgi.org/xmlns/blueprint/v1.0.0\">"
+ + "<component id=\"CalculatorComponent\" class=\"calculator.dosgi.impl.CalculatorServiceImpl\">"
+ + "<property name=\"addService\" ref=\"AddService\" />"
+ + "<property name=\"subtractService\" ref=\"SubtractService\" />"
+ + "<property name=\"multiplyService\" ref=\"MultiplyService\" />"
+ + "<property name=\"divideService\" ref=\"DivideService\" />"
+ + "</component>"
+ + "<service id=\"CalculatorService\" ref=\"CalculatorComponent\" interface=\"calculator.dosgi.CalculatorService\">"
+ + "</service>"
+ + "<reference id=\"AddService\" interface=\"calculator.dosgi.operations.AddService\">"
+ + "</reference>"
+ + "<reference id=\"SubtractService\" interface=\"calculator.dosgi.operations.SubtractService\">"
+ + "</reference>"
+ + "<reference id=\"MultiplyService\" interface=\"calculator.dosgi.operations.MultiplyService\">"
+ + "</reference>"
+ + "<reference id=\"DivideService\" interface=\"calculator.dosgi.operations.DivideService\">"
+ + "</reference>"
+ + "</components>";
+ private static XMLStreamReader reader;
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ XMLInputFactory factory = XMLInputFactory.newInstance();
+ reader = factory.createXMLStreamReader(new StringReader(xml));
+ }
+
+ @Test
+ public void testLoad() throws Exception {
+ BluePrintComponentsProcessor processor =
+ new BluePrintComponentsProcessor(new DefaultFactoryExtensionPoint(new DefaultExtensionPointRegistry()));
+ ComponentType ct = processor.read(reader, new ProcessorContext());
+ Assert.assertEquals(1, ct.getServices().size());
+ Assert.assertEquals(4, ct.getReferences().size());
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ if (reader != null) {
+ reader.close();
+ }
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiComponentProcessorTestCase.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiComponentProcessorTestCase.java
new file mode 100644
index 0000000000..ef49121c2c
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiComponentProcessorTestCase.java
@@ -0,0 +1,89 @@
+/*
+ * 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.io.StringReader;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.assembly.ComponentType;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.core.DefaultFactoryExtensionPoint;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class OSGiComponentProcessorTestCase {
+ private static final String xml =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<scr:component name=\"CalculatorComponent\""
+ + " xmlns:scr=\"http://www.osgi.org/xmlns/scr/v1.0.0\">"
+ + "<implementation class=\"calculator.dosgi.CalculatorServiceDSImpl\" />"
+ + "<service>"
+ + "<provide interface=\"calculator.dosgi.CalculatorService\" />"
+ + "</service>"
+ + "<reference name=\"addService\" interface=\"calculator.dosgi.operations.AddService\""
+ + " bind=\"setAddService\" unbind=\"unsetAddService\" policy=\"dynamic\" />"
+ + "<reference name=\"subtractService\" interface=\"calculator.dosgi.operations.SubtractService\""
+ + " bind=\"setSubtractService\" unbind=\"unsetSubtractService\" policy=\"dynamic\" />"
+ + "<reference name=\"multiplyService\" interface=\"calculator.dosgi.operations.MultiplyService\""
+ + " bind=\"setMultiplyService\" unbind=\"unsetMultiplyService\" policy=\"dynamic\" />"
+ + "<reference name=\"divideService\" interface=\"calculator.dosgi.operations.DivideService\""
+ + " bind=\"setDivideService\" unbind=\"unsetDivideService\" policy=\"dynamic\" />"
+ + "</scr:component>";
+
+ private static XMLStreamReader reader;
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ XMLInputFactory factory = XMLInputFactory.newInstance();
+ reader = factory.createXMLStreamReader(new StringReader(xml));
+ }
+
+ @Test
+ public void testLoad() throws Exception {
+ ExtensionPointRegistry registry = new DefaultExtensionPointRegistry();
+ OSGiComponentProcessor processor =
+ new OSGiComponentProcessor(new DefaultFactoryExtensionPoint(registry));
+ ComponentType ct = processor.read(reader, new ProcessorContext(registry));
+ Assert.assertEquals(1, ct.getServices().size());
+ Assert.assertEquals(4, ct.getReferences().size());
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ if (reader != null) {
+ reader.close();
+ }
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiReadImplTestCase.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiReadImplTestCase.java
new file mode 100644
index 0000000000..614f243eb3
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiReadImplTestCase.java
@@ -0,0 +1,173 @@
+/*
+ * 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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.StringReader;
+import java.io.StringWriter;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.assembly.ComponentType;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.contribution.ContributionMetadata;
+import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.implementation.osgi.OSGiImplementation;
+import org.apache.tuscany.sca.implementation.osgi.OSGiProperty;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * Test reading OSGi implementations.
+ *
+ * @version $Rev$ $Date$
+ */
+public class OSGiReadImplTestCase {
+
+ private static XMLInputFactory inputFactory;
+ private static XMLOutputFactory outputFactory;
+ private static StAXArtifactProcessor<Object> staxProcessor;
+ private static ProcessorContext context;
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ context = new ProcessorContext(extensionPoints);
+ inputFactory = XMLInputFactory.newInstance();
+ outputFactory = XMLOutputFactory.newInstance();
+ outputFactory.setProperty("javax.xml.stream.isRepairingNamespaces", Boolean.TRUE);
+ StAXArtifactProcessorExtensionPoint staxProcessors =
+ new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints);
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null);
+ }
+
+ @Test
+ public void testReadComposite() throws Exception {
+ InputStream is = getClass().getClassLoader().getResourceAsStream("osgitest.composite");
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+ Composite composite = (Composite)staxProcessor.read(reader, context);
+ assertNotNull(composite);
+ reader.close();
+ }
+
+ @Test
+ public void testReadWriteComponentType() throws Exception {
+ InputStream is = getClass().getClassLoader().getResourceAsStream("OSGI-INF/sca/bundle.componentType");
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+ ComponentType componentType = (ComponentType)staxProcessor.read(reader, context);
+ assertNotNull(componentType);
+
+ assertEquals(2, componentType.getServices().get(0).getExtensions().size());
+
+ //write composite back
+ StringWriter stringWriter = new StringWriter();
+ XMLStreamWriter writer = outputFactory.createXMLStreamWriter(stringWriter);
+ staxProcessor.write(componentType, writer, context);
+ stringWriter.close();
+
+ //read from the output from write
+ reader = inputFactory.createXMLStreamReader(new StringReader(stringWriter.toString()));
+ componentType = (ComponentType)staxProcessor.read(reader, context);
+ assertNotNull(componentType);
+
+ assertEquals(2, componentType.getServices().get(0).getExtensions().size());
+
+ reader.close();
+ }
+
+ @Test
+ public void testReadAndResolveComposite() throws Exception {
+ InputStream is = getClass().getClassLoader().getResourceAsStream("osgitest.composite");
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+ Composite composite = (Composite)staxProcessor.read(reader, context);
+ assertNotNull(composite);
+
+ is = getClass().getClassLoader().getResourceAsStream("OSGI-INF/sca/bundle.componentType");
+ reader = inputFactory.createXMLStreamReader(is);
+ ComponentType componentType = (ComponentType)staxProcessor.read(reader, context);
+
+ assertEquals(1, componentType.getServices().size());
+ Object prop1 = componentType.getServices().get(0).getExtensions().get(0);
+ assertTrue(prop1 instanceof OSGiProperty);
+ OSGiProperty osgiProp1 = (OSGiProperty)prop1;
+ assertEquals("1", osgiProp1.getValue());
+ assertEquals("prop1", osgiProp1.getName());
+
+ assertEquals(4, componentType.getReferences().size());
+ Object prop2 = componentType.getReferences().get(0).getExtensions().get(1);
+ assertTrue(prop2 instanceof OSGiProperty);
+ OSGiProperty osgiProp2 = (OSGiProperty)prop2;
+ assertEquals("ABC", osgiProp2.getValue());
+ assertEquals("prop2", osgiProp2.getName());
+
+ ModelResolver resolver = new TestModelResolver(getClass().getClassLoader());
+ staxProcessor.resolve(componentType, resolver, context);
+ resolver.addModel(componentType, context);
+
+ staxProcessor.resolve(composite, resolver, context);
+
+ reader.close();
+ }
+
+ @Test
+ public void testReadOSGiImplementation() throws Exception {
+
+ String str =
+ "<?xml version=\"1.0\" encoding=\"ASCII\"?>" + "<implementation.osgi xmlns=\"http://tuscany.apache.org/xmlns/sca/1.1\" targetNamespace=\"http://test\" "
+ + "bundleSymbolicName=\"osgi.test\" "
+ + "bundleVersion=\"1.0.0\" "
+ + "/>";
+ ByteArrayInputStream is = new ByteArrayInputStream(str.getBytes());
+
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+ reader.nextTag();
+
+ OSGiImplementation osgiImpl = (OSGiImplementation)staxProcessor.read(reader, context);
+
+ assertEquals(osgiImpl.getBundleSymbolicName(), "osgi.test");
+ assertEquals(osgiImpl.getBundleVersion(), "1.0.0");
+
+ StringWriter sw = new StringWriter();
+ XMLStreamWriter writer = outputFactory.createXMLStreamWriter(sw);
+ staxProcessor.write(osgiImpl, writer, context);
+ writer.flush();
+ writer.close();
+ Assert.assertTrue(sw.toString().contains("bundleSymbolicName=\"osgi.test\" bundleVersion=\"1.0.0\""));
+
+ reader.close();
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsTestCase.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsTestCase.java
new file mode 100644
index 0000000000..0e7acc354a
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsTestCase.java
@@ -0,0 +1,110 @@
+/*
+ * 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.io.StringReader;
+import java.util.List;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.implementation.osgi.ServiceDescription;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class ServiceDescriptionsTestCase {
+ private static final String xml =
+ "<?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\">"
+ + "<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=\"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;
+
+ private static ProcessorContext context;
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ context = new ProcessorContext(extensionPoints);
+
+ XMLInputFactory factory = XMLInputFactory.newInstance();
+ StAXArtifactProcessorExtensionPoint staxProcessors =
+ extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ StAXArtifactProcessor staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, factory, null);
+
+ processor = new ServiceDescriptionsProcessor(extensionPoints, staxProcessor);
+
+ reader = factory.createXMLStreamReader(new StringReader(xml));
+ }
+
+ @Test
+ public void testLoad() throws Exception {
+ List<ServiceDescription> descriptions = processor.read(reader, context);
+ Assert.assertEquals(2, descriptions.size());
+ System.out.println(descriptions);
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ if (reader != null) {
+ reader.close();
+ }
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/TestModelResolver.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/TestModelResolver.java
new file mode 100644
index 0000000000..17fef8a05c
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/TestModelResolver.java
@@ -0,0 +1,105 @@
+/*
+ * 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.lang.ref.WeakReference;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tuscany.sca.assembly.ComponentType;
+import org.apache.tuscany.sca.assembly.Property;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
+import org.apache.tuscany.sca.contribution.resolver.ClassReference;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.implementation.osgi.impl.OSGiImplementationImpl;
+
+/**
+ * A default implementation of an artifact resolver, based on a map.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TestModelResolver implements ModelResolver {
+ private static final long serialVersionUID = -7826976465762296634L;
+
+ private Map<Object, Object> map = new HashMap<Object, Object>();
+
+ private WeakReference<ClassLoader> classLoader;
+
+ public TestModelResolver(ClassLoader classLoader) {
+ this.classLoader = new WeakReference<ClassLoader>(classLoader);
+ }
+
+ public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) {
+ Object resolved = map.get(unresolved);
+ if (resolved != null) {
+
+ if (unresolved instanceof OSGiImplementationImpl && !(resolved instanceof OSGiImplementationImpl)) {
+
+ OSGiImplementationImpl impl = ((OSGiImplementationImpl)unresolved);
+ ComponentType componentType = (ComponentType)resolved;
+
+ List<Property> properties = componentType.getProperties();
+ for (Property property : properties) {
+ impl.getProperties().add(property);
+ }
+ impl.setUnresolved(false);
+ return unresolved;
+ }
+
+ // Return the resolved object
+ return modelClass.cast(resolved);
+
+ } else if (unresolved instanceof ClassReference) {
+
+ // Load a class on demand
+ ClassReference classReference = (ClassReference)unresolved;
+ Class clazz;
+ try {
+ clazz = Class.forName(classReference.getClassName(), true, classLoader.get());
+ } catch (ClassNotFoundException e) {
+
+ // Return the unresolved object
+ return unresolved;
+ }
+
+ // Store a new ClassReference wrapping the loaded class
+ resolved = new ClassReference(clazz);
+ map.put(resolved, resolved);
+
+ // Return the resolved ClassReference
+ return modelClass.cast(resolved);
+
+ } else {
+
+ // Return the unresolved object
+ return unresolved;
+ }
+ }
+
+ public void addModel(Object resolved, ProcessorContext context) {
+ map.put(resolved, resolved);
+ }
+
+ public Object removeModel(Object resolved, ProcessorContext context) {
+ return map.remove(resolved);
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/resources/OSGI-INF/calculator-component.xml b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/resources/OSGI-INF/calculator-component.xml
new file mode 100644
index 0000000000..3e537df732
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/resources/OSGI-INF/calculator-component.xml
@@ -0,0 +1,36 @@
+<?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.
+-->
+<scr:component name="CalculatorComponent"
+ xmlns:scr="http://www.osgi.org/xmlns/scr/v1.0.0">
+ <implementation class="calculator.dosgi.CalculatorServiceDSImpl" />
+ <service>
+ <provide interface="calculator.dosgi.CalculatorService" />
+ </service>
+
+ <reference name="addService" interface="calculator.dosgi.operations.AddService" bind="setAddService" unbind="unsetAddService"
+ policy="dynamic" />
+ <reference name="subtractService" interface="calculator.dosgi.operations.SubtractService" bind="setSubtractService"
+ unbind="unsetSubtractService" policy="dynamic" />
+ <reference name="multiplyService" interface="calculator.dosgi.operations.MultiplyService" bind="setMultiplyService"
+ unbind="unsetMultiplyService" policy="dynamic" />
+ <reference name="divideService" interface="calculator.dosgi.operations.DivideService" bind="setDivideService"
+ unbind="unsetDivideService" policy="dynamic" />
+
+</scr:component>
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/resources/OSGI-INF/sca/bundle.componentType b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/resources/OSGI-INF/sca/bundle.componentType
new file mode 100644
index 0000000000..401809c197
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/resources/OSGI-INF/sca/bundle.componentType
@@ -0,0 +1,63 @@
+<?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/200912"
+ 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.dosgi.CalculatorService"/>
+ <!-- The list of OSGi properties -->
+ <extensions>
+ <t:osgi.property name="prop1">1</t:osgi.property>
+ <t:osgi.property name="prop2">ABC</t:osgi.property>
+ </extensions>
+ </service>
+
+ <!-- The reference elment defines an SCA proxy to a remote OSGi service -->
+ <reference name="addService">
+ <interface.java interface="calculator.dosgi.operations.AddService"/>
+ <extensions>
+ <t:osgi.property name="prop1">1</t:osgi.property>
+ <t:osgi.property name="prop2">ABC</t:osgi.property>
+ </extensions>
+ </reference>
+ <reference name="subtractService">
+ <interface.java interface="calculator.dosgi.operations.SubtractService"/>
+ <extensions>
+ <t:osgi.property name="prop1">1</t:osgi.property>
+ <t:osgi.property name="prop2">ABC</t:osgi.property>
+ </extensions>
+ </reference>
+ <reference name="multiplyService">
+ <interface.java interface="calculator.dosgi.operations.MultiplyService"/>
+ <extensions>
+ <t:osgi.property name="prop1">1</t:osgi.property>
+ <t:osgi.property name="prop2">ABC</t:osgi.property>
+ </extensions>
+ </reference>
+ <reference name="divideService">
+ <interface.java interface="calculator.dosgi.operations.DivideService"/>
+ <extensions>
+ <t:osgi.property name="prop1">1</t:osgi.property>
+ <t:osgi.property name="prop2">ABC</t:osgi.property>
+ </extensions>
+ </reference>
+</componentType>
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/resources/osgitest.composite b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/resources/osgitest.composite
new file mode 100644
index 0000000000..7c54e46a54
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/resources/osgitest.composite
@@ -0,0 +1,35 @@
+<?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.
+-->
+<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912"
+ xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://test"
+ name="OSGiTestComposite">
+
+ <component name="OSGiTestServiceComponent">
+ <tuscany:implementation.osgi bundleVersion="1.0.0"
+ bundleSymbolicName="osgi.test" />
+
+ <property name="currency" type="xsd:string">USD</property>
+ <property name="exchangeRate" type="xsd:double">2.0</property>
+
+ </component>
+
+</composite>