summaryrefslogtreecommitdiffstats
path: root/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache
diff options
context:
space:
mode:
authorantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2009-03-28 09:46:58 +0000
committerantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2009-03-28 09:46:58 +0000
commit699d2df521ee26e343c53505a2ac1d546ba1965e (patch)
treebf474699526bcec86049d407b01a2d4b08757d69 /branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache
parent35f81a620ea2d8423a49d8630bcef1d69027f444 (diff)
Create M2 relese branch
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@759448 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache')
-rw-r--r--branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/DefaultOSGiImplementationFactory.java34
-rw-r--r--branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/DefaultServiceDescriptionsFactory.java33
-rw-r--r--branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiImplementation.java53
-rw-r--r--branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiImplementationFactory.java37
-rw-r--r--branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiProperty.java53
-rw-r--r--branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/ServiceDescription.java40
-rw-r--r--branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/ServiceDescriptions.java36
-rw-r--r--branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/ServiceDescriptionsFactory.java29
-rw-r--r--branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiImplementationFactoryImpl.java46
-rw-r--r--branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiImplementationImpl.java116
-rw-r--r--branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiPropertyImpl.java51
-rw-r--r--branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/ServiceDescriptionImpl.java51
-rw-r--r--branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/ServiceDescriptionsFactoryImpl.java43
-rw-r--r--branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/ServiceDescriptionsImpl.java36
-rw-r--r--branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationActivator.java47
-rw-r--r--branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java286
-rw-r--r--branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiPropertyProcessor.java105
-rw-r--r--branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsDocumentProcessor.java99
-rw-r--r--branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsModelResolver.java58
-rw-r--r--branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsProcessor.java153
20 files changed, 1406 insertions, 0 deletions
diff --git a/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/DefaultOSGiImplementationFactory.java b/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/DefaultOSGiImplementationFactory.java
new file mode 100644
index 0000000000..545898fe5f
--- /dev/null
+++ b/branches/sca-java-2.0-M2/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.FactoryExtensionPoint;
+import org.apache.tuscany.sca.implementation.osgi.impl.OSGiImplementationFactoryImpl;
+
+/**
+ *
+ */
+public class DefaultOSGiImplementationFactory extends OSGiImplementationFactoryImpl {
+
+ public DefaultOSGiImplementationFactory(FactoryExtensionPoint factoryExtensionPoint) {
+ super(factoryExtensionPoint);
+ }
+
+}
diff --git a/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/DefaultServiceDescriptionsFactory.java b/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/DefaultServiceDescriptionsFactory.java
new file mode 100644
index 0000000000..d7296e24bb
--- /dev/null
+++ b/branches/sca-java-2.0-M2/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/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiImplementation.java b/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiImplementation.java
new file mode 100644
index 0000000000..4551821f5a
--- /dev/null
+++ b/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiImplementation.java
@@ -0,0 +1,53 @@
+/*
+ * 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 SCA11_NS = "http://docs.oasis-open.org/ns/opencsa/sca/200903";
+ String SCA11_TUSCANY_NS = "http://tuscany.apache.org/xmlns/sca/1.1";
+
+ String BUNDLE_SYMBOLICNAME = "bundleSymbolicName";
+ String BUNDLE_VERSION = "bundleVersion";
+ QName IMPLEMENTATION_OSGI = new QName(SCA11_TUSCANY_NS, "implementation.osgi");
+
+ String getBundleSymbolicName();
+
+ void setBundleSymbolicName(String name);
+
+ String getBundleVersion();
+
+ void setBundleVersion(String version);
+
+ Bundle getBundle();
+
+ void setBundle(Bundle bundle);
+
+}
diff --git a/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiImplementationFactory.java b/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiImplementationFactory.java
new file mode 100644
index 0000000000..0a83624e76
--- /dev/null
+++ b/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiImplementationFactory.java
@@ -0,0 +1,37 @@
+/*
+ * 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 OSGiImplementation instances
+ */
+public interface OSGiImplementationFactory {
+ /**
+ * Create a new instance of OSGiImplementation
+ * @return
+ */
+ OSGiImplementation createOSGiImplementation();
+
+ /**
+ *
+ * @return
+ */
+ OSGiProperty createOSGiProperty();
+}
diff --git a/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiProperty.java b/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiProperty.java
new file mode 100644
index 0000000000..26b588a099
--- /dev/null
+++ b/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiProperty.java
@@ -0,0 +1,53 @@
+/*
+ * 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";
+ QName PROPERTY_QNAME = new QName(OSGiImplementation.SCA11_TUSCANY_NS, "osgi.property");
+
+ /**
+ * Standard OSGi property names
+ */
+ String OSGI_REMOTE = "osgi.remote";
+ String SERVICE_INTENTS = "service.intents";
+ String OSGI_REMOTE_INTERFACES = "osgi.remote.interfaces";
+ String OSGI_REMOTE_INTENTS = "osgi.remote.requires.intents";
+ String OSGI_REMOTE_CONFIGURATION_TYPE = "osgi.remote.configuration.type";
+ String SCA_BINDINGS = "osgi.remote.configuration.sca.bindings";
+ String SCA_REFERENCE = "osgi.remote.configuration.sca.reference";
+ String SCA_SERVICE = "osgi.remote.configuration.sca.service";
+ String SCA_REFERENCE_BINDING = "osgi.remote.configuration.sca.reference.binding";
+ String SCA_SERVICE_BINDING = "osgi.remote.configuration.sca.service.binding";
+ String OSGI_REMOTE_CONFIGURATION_TYPE_SCA = "sca";
+
+ String getValue();
+
+ void setValue(String value);
+
+ String getName();
+
+ void setName(String name);
+}
diff --git a/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/ServiceDescription.java b/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/ServiceDescription.java
new file mode 100644
index 0000000000..119d7ed657
--- /dev/null
+++ b/branches/sca-java-2.0-M2/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/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/ServiceDescriptions.java b/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/ServiceDescriptions.java
new file mode 100644
index 0000000000..35866938d6
--- /dev/null
+++ b/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/ServiceDescriptions.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;
+
+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/sd/v1.0.0";
+ QName SERVICE_DESCRIPTIONS_QNAME = new QName(OSGI_SD_NS, "service-descriptions");
+ QName SERVICE_DESCRIPTION_QNAME = new QName(OSGI_SD_NS, "service-description");
+ String REMOTE_SERVICE_HEADER = "Remote-Service";
+}
diff --git a/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/ServiceDescriptionsFactory.java b/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/ServiceDescriptionsFactory.java
new file mode 100644
index 0000000000..0e4c51b1f9
--- /dev/null
+++ b/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/ServiceDescriptionsFactory.java
@@ -0,0 +1,29 @@
+/*
+ * 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();
+}
diff --git a/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiImplementationFactoryImpl.java b/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiImplementationFactoryImpl.java
new file mode 100644
index 0000000000..80b68d1728
--- /dev/null
+++ b/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiImplementationFactoryImpl.java
@@ -0,0 +1,46 @@
+/*
+ * 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.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;
+
+/**
+ *
+ */
+public class OSGiImplementationFactoryImpl implements OSGiImplementationFactory {
+ private final FactoryExtensionPoint factoryExtensionPoint;
+
+ public OSGiImplementationFactoryImpl(FactoryExtensionPoint factoryExtensionPoint) {
+ super();
+ this.factoryExtensionPoint = factoryExtensionPoint;
+ }
+
+ public OSGiImplementation createOSGiImplementation() {
+ return new OSGiImplementationImpl(factoryExtensionPoint);
+ }
+
+ public OSGiProperty createOSGiProperty() {
+ return new OSGiPropertyImpl();
+ }
+
+}
diff --git a/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiImplementationImpl.java b/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiImplementationImpl.java
new file mode 100644
index 0000000000..41deef131f
--- /dev/null
+++ b/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiImplementationImpl.java
@@ -0,0 +1,116 @@
+/*
+ * 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.core.FactoryExtensionPoint;
+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;
+
+ private FactoryExtensionPoint modelFactories;
+
+ protected OSGiImplementationImpl(FactoryExtensionPoint modelFactories) {
+ this.modelFactories = modelFactories;
+ }
+
+ public OSGiImplementationImpl(FactoryExtensionPoint modelFactories, String bundleSymbolicName, String bundleVersion) {
+
+ super();
+ this.bundleSymbolicName = bundleSymbolicName;
+ this.bundleVersion = bundleVersion;
+ this.modelFactories = modelFactories;
+ }
+
+ public String getBundleSymbolicName() {
+ return bundleSymbolicName;
+ }
+
+ public String getBundleVersion() {
+ return bundleVersion;
+ }
+
+ public FactoryExtensionPoint getModelFactories() {
+ return modelFactories;
+ }
+
+ /**
+ * 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);
+ }
+ }
+
+ private boolean areEqual(Object obj1, Object obj2) {
+ if (obj1 == obj2)
+ return true;
+ if (obj1 == null || obj2 == null)
+ return false;
+ return obj1.equals(obj2);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+
+ if (!(obj instanceof OSGiImplementationImpl))
+ return super.equals(obj);
+ OSGiImplementationImpl impl = (OSGiImplementationImpl)obj;
+ if (!areEqual(bundleSymbolicName, impl.bundleSymbolicName))
+ return false;
+ if (!areEqual(bundleVersion, impl.bundleVersion))
+ return false;
+ return super.equals(obj);
+ }
+
+ public void setBundleSymbolicName(String bundleSymbolicName) {
+ this.bundleSymbolicName = bundleSymbolicName;
+ }
+
+ public void setBundleVersion(String bundleVersion) {
+ this.bundleVersion = bundleVersion;
+ }
+
+}
diff --git a/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiPropertyImpl.java b/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiPropertyImpl.java
new file mode 100644
index 0000000000..a3944c66c0
--- /dev/null
+++ b/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiPropertyImpl.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 org.apache.tuscany.sca.implementation.osgi.OSGiProperty;
+
+/**
+ * Implementation of OSGiProperty
+ */
+public class OSGiPropertyImpl implements OSGiProperty {
+ protected OSGiPropertyImpl() {
+ super();
+ }
+
+ private String name;
+ private String value;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+}
diff --git a/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/ServiceDescriptionImpl.java b/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/ServiceDescriptionImpl.java
new file mode 100644
index 0000000000..b990cf5980
--- /dev/null
+++ b/branches/sca-java-2.0-M2/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.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tuscany.sca.implementation.osgi.ServiceDescription;
+
+/**
+ * The OSGi RFC 119 description of a remote OSGi service
+ */
+public class ServiceDescriptionImpl implements ServiceDescription {
+ private List<String> interfaces = new ArrayList<String>();
+ private Map<String, Object> properties = new HashMap<String, Object>();
+
+ protected ServiceDescriptionImpl() {
+ super();
+ }
+
+ public List<String> getInterfaces() {
+ return interfaces;
+ }
+
+ public Map<String, Object> getProperties() {
+ return properties;
+ }
+
+ public String toString() {
+ return "service-description: interfaces=" + interfaces + " properties=" + properties;
+ }
+}
diff --git a/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/ServiceDescriptionsFactoryImpl.java b/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/ServiceDescriptionsFactoryImpl.java
new file mode 100644
index 0000000000..8cd3867610
--- /dev/null
+++ b/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/ServiceDescriptionsFactoryImpl.java
@@ -0,0 +1,43 @@
+/*
+ * 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.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();
+ }
+
+}
diff --git a/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/ServiceDescriptionsImpl.java b/branches/sca-java-2.0-M2/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/branches/sca-java-2.0-M2/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/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationActivator.java b/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationActivator.java
new file mode 100644
index 0000000000..ce7b1dc920
--- /dev/null
+++ b/branches/sca-java-2.0-M2/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;
+ }
+
+ static BundleContext getBundleContext() {
+ return bundleContext;
+ }
+
+ static void setBundleContext(BundleContext bundleContext) {
+ OSGiImplementationActivator.bundleContext = bundleContext;
+ }
+
+}
diff --git a/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java b/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java
new file mode 100644
index 0000000000..db011a95db
--- /dev/null
+++ b/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java
@@ -0,0 +1,286 @@
+/*
+ * 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.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.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ClassReference;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+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 AssemblyFactory assemblyFactory;
+ private ServiceDescriptionsFactory serviceDescriptionsFactory;
+ private OSGiImplementationFactory osgiImplementationFactory;
+ private JavaInterfaceFactory javaInterfaceFactory;
+ private Monitor monitor;
+
+ public OSGiImplementationProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) {
+ this.monitor = monitor;
+ this.serviceDescriptionsFactory = modelFactories.getFactory(ServiceDescriptionsFactory.class);
+ this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class);
+ this.osgiImplementationFactory = modelFactories.getFactory(OSGiImplementationFactory.class);
+ this.javaInterfaceFactory = modelFactories.getFactory(JavaInterfaceFactory.class);
+ }
+
+ /**
+ * Report a error.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(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) 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) throws ContributionResolveException {
+
+ if (impl == null || !impl.isUnresolved())
+ return;
+
+ impl.setUnresolved(false);
+
+ BundleContext bundleContext = OSGiImplementationActivator.getBundleContext();
+ 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("CouldNotLocateOSGiBundle", impl, impl.getBundleSymbolicName());
+ //throw new ContributionResolveException("Could not locate OSGi bundle " +
+ //impl.getBundleSymbolicName());
+ return;
+ }
+
+ ComponentType componentType = assemblyFactory.createComponentType();
+ componentType.setURI("OSGI-INF/sca/bundle.componentType");
+ componentType.setUnresolved(true);
+ componentType = resolver.resolveModel(ComponentType.class, componentType);
+ if (componentType.isUnresolved()) {
+ // Try to derive it from the service descriptions
+ if (!deriveFromServiceDescriptions(impl, resolver)) {
+ error("MissingComponentTypeFile", impl, componentType.getURI());
+ }
+ //throw new ContributionResolveException("missing .componentType side file " + ctURI);
+ return;
+ } else {
+ mergeFromComponentType(impl, componentType, resolver);
+ }
+ }
+
+ private boolean deriveFromServiceDescriptions(OSGiImplementation impl, ModelResolver resolver)
+ 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);
+ 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);
+ 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);
+ return true;
+ }
+ return false;
+ }
+
+ private void mergeFromComponentType(OSGiImplementation impl, ComponentType componentType, ModelResolver resolver) {
+ 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()));
+ }
+ if (service.getInterfaceContract().getCallbackInterface() instanceof JavaInterface) {
+ JavaInterface callbackInterface =
+ (JavaInterface)service.getInterfaceContract().getCallbackInterface();
+ if (callbackInterface.getJavaClass() == null) {
+ callbackInterface.setJavaClass(getJavaClass(resolver, callbackInterface.getName()));
+ }
+ }
+
+ 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()));
+ }
+ impl.getReferences().add(reference);
+ } else
+ impl.getReferences().add(reference);
+ }
+
+ List<Property> properties = componentType.getProperties();
+ for (Property property : properties) {
+ impl.getProperties().add(property);
+ }
+ impl.setConstrainingType(componentType.getConstrainingType());
+ }
+
+ private Class<?> getJavaClass(ModelResolver resolver, String className) {
+ ClassReference ref = new ClassReference(className);
+ ref = resolver.resolveModel(ClassReference.class, ref);
+ return ref.getJavaClass();
+ }
+
+ public void write(OSGiImplementation model, XMLStreamWriter writer) 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();
+ }
+
+}
diff --git a/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiPropertyProcessor.java b/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiPropertyProcessor.java
new file mode 100644
index 0000000000..5a8f5c4694
--- /dev/null
+++ b/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiPropertyProcessor.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 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 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.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;
+import org.apache.tuscany.sca.monitor.Monitor;
+
+/**
+ * A processor for <tuscany:osgi.property>
+ */
+public class OSGiPropertyProcessor implements StAXArtifactProcessor<OSGiProperty> {
+ private OSGiImplementationFactory factory;
+ private Monitor monitor;
+
+ public OSGiPropertyProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) {
+ this.monitor = monitor;
+ this.factory = modelFactories.getFactory(OSGiImplementationFactory.class);
+ }
+
+ public OSGiProperty read(XMLStreamReader reader) 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)) {
+ prop = factory.createOSGiProperty();
+ prop.setName(reader.getAttributeValue(null, NAME));
+ // After the following call, the reader will be positioned at END_ELEMENT
+ String text = reader.getElementText();
+ if (text != null) {
+ text = text.trim();
+ }
+ prop.setValue(text);
+ 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) throws ContributionWriteException, XMLStreamException {
+ writer.writeStartElement(PROPERTY_QNAME.getNamespaceURI(), PROPERTY_QNAME.getLocalPart());
+ writer.writeAttribute(NAME, model.getName());
+ writer.writeCharacters(model.getValue());
+ writer.writeEndElement();
+ }
+
+ public Class<OSGiProperty> getModelType() {
+ return OSGiProperty.class;
+ }
+
+ public void resolve(OSGiProperty model, ModelResolver resolver) throws ContributionResolveException {
+ // TODO: To be implemented
+ }
+}
diff --git a/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsDocumentProcessor.java b/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsDocumentProcessor.java
new file mode 100644
index 0000000000..b692531a38
--- /dev/null
+++ b/branches/sca-java-2.0-M2/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.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;
+import org.apache.tuscany.sca.monitor.Monitor;
+
+/**
+ * The service descriptions document processor
+ */
+public class ServiceDescriptionsDocumentProcessor implements URLArtifactProcessor<ServiceDescriptions> {
+ private XMLInputFactory inputFactory;
+ private StAXArtifactProcessor extensionProcessor;
+
+ public ServiceDescriptionsDocumentProcessor(FactoryExtensionPoint modelFactories,
+ StAXArtifactProcessor staxProcessor,
+ Monitor monitor) {
+ 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)
+ 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);
+ Object result = extensionProcessor.read(reader);
+ 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) throws ContributionResolveException {
+ }
+
+}
diff --git a/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsModelResolver.java b/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsModelResolver.java
new file mode 100644
index 0000000000..deafe8ccc9
--- /dev/null
+++ b/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsModelResolver.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.osgi.xml;
+
+import org.apache.tuscany.sca.contribution.Contribution;
+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) {
+ // Merge the service descriptions
+ if (resolved instanceof ServiceDescriptions) {
+ serviceDescriptions.addAll((ServiceDescriptions)resolved);
+ }
+ }
+
+ public Object removeModel(Object resolved) {
+ // Remove the service descriptions
+ if (resolved instanceof ServiceDescriptions) {
+ serviceDescriptions.removeAll((ServiceDescriptions)resolved);
+ }
+ return resolved;
+ }
+
+ public <T> T resolveModel(Class<T> modelClass, T unresolved) {
+ // Always return the aggregated service descriptions
+ return modelClass.cast(serviceDescriptions);
+ }
+}
diff --git a/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsProcessor.java b/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsProcessor.java
new file mode 100644
index 0000000000..bef07d159d
--- /dev/null
+++ b/branches/sca-java-2.0-M2/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsProcessor.java
@@ -0,0 +1,153 @@
+/*
+ * 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.contribution.processor.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.processor.ContributionWriteException;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.core.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.apache.tuscany.sca.monitor.Monitor;
+
+/*
+<?xml version="1.0" encoding="UTF-8"?>
+<service-descriptions xmlns="http://www.osgi.org/xmlns/sd/v1.0.0">
+ <service-description>
+ <provide interface="com.iona.soa.pojo.hello.HelloService"/>
+ <property name="service.intents">SOAP HTTP</property>
+ <property name="osgi.remote.configuration.type">pojo</property>
+ <property name="osgi.remote.configuration.pojo.address">
+ http://localhost:9000/hello
+ </property>
+ </service-description>
+ <service-description>
+ <provide interface="com.iona.soa.pojo.hello.GreeterService"/>
+ <property name="service.intents">SOAP HTTP</property>
+ <property name="osgi.remote.configuration.type">pojo</property>
+ <property name="osgi.remote.configuration.pojo.address">
+ http://localhost:9005/greeter
+ </property>
+ </service-description>
+</service-descriptions>
+*/
+public class ServiceDescriptionsProcessor implements StAXArtifactProcessor<ServiceDescriptions> {
+ private ServiceDescriptionsFactory factory;
+ private Monitor monitor;
+
+ public ServiceDescriptionsProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) {
+ this.monitor = monitor;
+ this.factory = modelFactories.getFactory(ServiceDescriptionsFactory.class);
+ }
+
+ public ServiceDescriptions read(XMLStreamReader reader) throws XMLStreamException {
+ int event = reader.getEventType();
+ ServiceDescriptions sds = factory.createServiceDescriptions();
+ ServiceDescription sd = null;
+ while (true) {
+ switch (event) {
+ case XMLStreamConstants.START_ELEMENT:
+ QName name = reader.getName();
+ if (ServiceDescriptions.SERVICE_DESCRIPTION_QNAME.equals(name)) {
+ sd = factory.createServiceDescription();
+ sds.add(sd);
+ } else if ("provide".equals(name.getLocalPart())) {
+ String interfaceName = reader.getAttributeValue(null, "interface");
+ if (interfaceName != null) {
+ sd.getInterfaces().add(interfaceName);
+ }
+ } else if ("property".equals(name.getLocalPart())) {
+ String propName = reader.getAttributeValue(null, "name");
+ String propValue = reader.getAttributeValue(null, "value");
+ String propType = reader.getAttributeValue(null, "type");
+ if (propType == null) {
+ propType = "String";
+ }
+ 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);
+ }
+ sd.getProperties().put(propName, prop);
+ }
+ break;
+ case XMLStreamConstants.END_ELEMENT:
+ name = reader.getName();
+ if (ServiceDescriptions.SERVICE_DESCRIPTION_QNAME.equals(name)) {
+ // Reset the sd
+ sd = null;
+ }
+ if (ServiceDescriptions.SERVICE_DESCRIPTIONS_QNAME.equals(name)) {
+ return sds;
+ }
+ break;
+ }
+ if (reader.hasNext()) {
+ event = reader.next();
+ } else {
+ return sds;
+ }
+ }
+ }
+
+ public QName getArtifactType() {
+ return ServiceDescriptions.SERVICE_DESCRIPTIONS_QNAME;
+ }
+
+ public void write(ServiceDescriptions model, XMLStreamWriter writer) throws ContributionWriteException,
+ XMLStreamException {
+ // TODO: To be implemented
+ }
+
+ public Class<ServiceDescriptions> getModelType() {
+ return ServiceDescriptions.class;
+ }
+
+ public void resolve(ServiceDescriptions model, ModelResolver resolver) throws ContributionResolveException {
+ // TODO: To be implemented
+ }
+}