summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-03-09 22:52:50 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-03-09 22:52:50 +0000
commited6bbdf735951eb33c6b67506cb9f4e77df15c57 (patch)
tree5f3d8225b0c078ee2e23e3b5edb6e0fe8e879252
parent5c95289917fdc473d29857282fe5ca56c3ebcb5d (diff)
Add a document processor for the service descriptions
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@751895 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java204
-rw-r--r--java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsDocumentProcessor.java99
-rw-r--r--java/sca/modules/implementation-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor19
3 files changed, 197 insertions, 125 deletions
diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java
index f5fc2e3747..3d0831f1bb 100644
--- a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java
+++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java
@@ -19,12 +19,11 @@
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.Hashtable;
+import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
@@ -34,7 +33,6 @@ import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
import org.apache.tuscany.sca.assembly.AssemblyFactory;
-import org.apache.tuscany.sca.assembly.ComponentProperty;
import org.apache.tuscany.sca.assembly.ComponentType;
import org.apache.tuscany.sca.assembly.Property;
import org.apache.tuscany.sca.assembly.Reference;
@@ -47,10 +45,10 @@ 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.impl.OSGiImplementationImpl;
+import org.apache.tuscany.sca.implementation.osgi.OSGiImplementationFactory;
+import org.apache.tuscany.sca.implementation.osgi.OSGiProperty;
import org.apache.tuscany.sca.implementation.osgi.runtime.OSGiImplementationActivator;
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.JavaInterfaceFactory;
import org.apache.tuscany.sca.monitor.Monitor;
@@ -72,12 +70,14 @@ public class OSGiImplementationProcessor implements StAXArtifactProcessor<OSGiIm
private JavaInterfaceFactory javaInterfaceFactory;
private AssemblyFactory assemblyFactory;
private FactoryExtensionPoint modelFactories;
+ private OSGiImplementationFactory osgiImplementationFactory;
private Monitor monitor;
public OSGiImplementationProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) {
this.monitor = monitor;
this.modelFactories = modelFactories;
this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class);
+ this.osgiImplementationFactory = modelFactories.getFactory(OSGiImplementationFactory.class);
this.javaInterfaceFactory = modelFactories.getFactory(JavaInterfaceFactory.class);
}
@@ -145,50 +145,22 @@ public class OSGiImplementationProcessor implements StAXArtifactProcessor<OSGiIm
String bundleSymbolicName = reader.getAttributeValue(null, BUNDLE_SYMBOLICNAME);
String bundleVersion = reader.getAttributeValue(null, BUNDLE_VERSION);
- Hashtable<String, List<ComponentProperty>> refProperties = new Hashtable<String, List<ComponentProperty>>();
- Hashtable<String, List<ComponentProperty>> serviceProperties = new Hashtable<String, List<ComponentProperty>>();
- Hashtable<String, List<ComponentProperty>> refCallbackProperties =
- new Hashtable<String, List<ComponentProperty>>();
- Hashtable<String, List<ComponentProperty>> serviceCallbackProperties =
- new Hashtable<String, List<ComponentProperty>>();
+ List<OSGiProperty> refProperties = new ArrayList<OSGiProperty>();
+ List<OSGiProperty> serviceProperties = new ArrayList<OSGiProperty>();
+ List<OSGiProperty> refCallbackProperties = new ArrayList<OSGiProperty>();
+ List<OSGiProperty> serviceCallbackProperties = new ArrayList<OSGiProperty>();
+ // Skip to the end of <implementation.osgi>
while (reader.hasNext()) {
-
int next = reader.next();
if (next == END_ELEMENT && IMPLEMENTATION_OSGI.equals(reader.getName())) {
break;
- } else if (next == START_ELEMENT && PROPERTY_QNAME.equals(reader.getName())) {
-
- // FIXME: This is temporary code which allows reference and service properties used
- // for filtering OSGi services to be specified in <implementation.osgi/>
- // This should really be provided in the component type file since these
- // properties are associated with an implementation rather than a configured
- // instance of an implementation.
- String refName = reader.getAttributeValue(null, "reference");
- String serviceName = reader.getAttributeValue(null, "service");
- String refCallbackName = reader.getAttributeValue(null, "referenceCallback");
- String serviceCallbackName = reader.getAttributeValue(null, "serviceCallback");
- List<ComponentProperty> props = readProperties(reader);
- if (refName != null)
- refProperties.put(refName, props);
- else if (serviceName != null)
- serviceProperties.put(serviceName, props);
- else if (refCallbackName != null)
- refCallbackProperties.put(refCallbackName, props);
- else if (serviceCallbackName != null)
- serviceCallbackProperties.put(serviceCallbackName, props);
- else {
- error("PropertyShouldSpecifySR", reader);
- //throw new ContributionReadException("Properties in implementation.osgi should specify service or reference");
- }
}
-
}
- OSGiImplementationImpl implementation =
- new OSGiImplementationImpl(modelFactories, bundleSymbolicName, bundleVersion,
- refProperties, serviceProperties);
- implementation.setCallbackProperties(refCallbackProperties, serviceCallbackProperties);
+ OSGiImplementation implementation = osgiImplementationFactory.createOSGiImplementation();
+ implementation.setBundleSymbolicName(bundleSymbolicName);
+ implementation.setBundleVersion(bundleVersion);
implementation.setUnresolved(true);
@@ -198,103 +170,85 @@ public class OSGiImplementationProcessor implements StAXArtifactProcessor<OSGiIm
public void resolve(OSGiImplementation impl, ModelResolver resolver) throws ContributionResolveException {
- try {
+ if (impl == null || !impl.isUnresolved())
+ return;
- if (impl == null || !impl.isUnresolved())
- return;
+ impl.setUnresolved(false);
- 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(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;
- }
+ BundleContext bundleContext = OSGiImplementationActivator.getBundleContext();
+ Bundle bundle = null;
+ for (Bundle b : bundleContext.getBundles()) {
+ String sn = b.getSymbolicName();
+ String ver = (String)b.getHeaders().get(BUNDLE_VERSION);
+ if (!impl.getBundleSymbolicName().equals(sn)) {
+ continue;
}
- if (bundle != null) {
- impl.setBundle(bundle);
- } else {
- error("CouldNotLocateOSGiBundle", impl, impl.getBundleSymbolicName());
- //throw new ContributionResolveException("Could not locate OSGi bundle " +
- //impl.getBundleSymbolicName());
- return;
- }
-
- String bundleName = resolvedBundle.getBundleRelativePath();
- String ctURI =
- bundleName.endsWith(".jar") || bundleName.endsWith(".JAR") ? bundleName.substring(0, bundleName
- .lastIndexOf(".")) : bundleName;
- ctURI = ctURI.replaceAll("\\.", "/");
- ctURI = ctURI + ".componentType";
-
- ComponentType componentType = assemblyFactory.createComponentType();
- componentType.setURI(ctURI);
- componentType.setUnresolved(true);
- componentType = resolver.resolveModel(ComponentType.class, componentType);
- if (componentType.isUnresolved()) {
- error("MissingComponentTypeFile", impl, ctURI);
- //throw new ContributionResolveException("missing .componentType side file " + ctURI);
- return;
+ 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;
+ }
- 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) {
+ ComponentType componentType = assemblyFactory.createComponentType();
+ componentType.setURI("META-INF/bundle.componentType");
+ componentType.setUnresolved(true);
+ componentType = resolver.resolveModel(ComponentType.class, componentType);
+ if (componentType.isUnresolved()) {
+ error("MissingComponentTypeFile", impl, componentType.getURI());
+ //throw new ContributionResolveException("missing .componentType side file " + ctURI);
+ return;
+ }
- javaInterface.setJavaClass(getJavaClass(resolver, javaInterface.getName()));
- }
- Class<?> callback = null;
- if (service.getInterfaceContract().getCallbackInterface() instanceof JavaInterface) {
- JavaInterface callbackInterface =
- (JavaInterface)service.getInterfaceContract().getCallbackInterface();
- if (callbackInterface.getJavaClass() == null) {
- callbackInterface.setJavaClass(getJavaClass(resolver, callbackInterface.getName()));
- }
- callback = callbackInterface.getJavaClass();
+ 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()));
+ }
+ Class<?> callback = null;
+ if (service.getInterfaceContract().getCallbackInterface() instanceof JavaInterface) {
+ JavaInterface callbackInterface =
+ (JavaInterface)service.getInterfaceContract().getCallbackInterface();
+ if (callbackInterface.getJavaClass() == null) {
+ callbackInterface.setJavaClass(getJavaClass(resolver, callbackInterface.getName()));
}
-
- Service serv = createService(service, javaInterface.getJavaClass(), callback);
- impl.getServices().add(serv);
+ callback = callbackInterface.getJavaClass();
}
- }
- 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()));
- }
- Reference ref = createReference(reference, javaInterface.getJavaClass());
- impl.getReferences().add(ref);
- } else
- impl.getReferences().add(reference);
+ impl.getServices().add(service);
}
+ }
- List<Property> properties = componentType.getProperties();
- for (Property property : properties) {
- impl.getProperties().add(property);
- }
- impl.setConstrainingType(componentType.getConstrainingType());
+ 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);
+ }
- } catch (InvalidInterfaceException e) {
- ContributionResolveException ce = new ContributionResolveException(e);
- error("ContributionResolveException", resolver, ce);
- //throw ce;
+ List<Property> properties = componentType.getProperties();
+ for (Property property : properties) {
+ impl.getProperties().add(property);
}
+ impl.setConstrainingType(componentType.getConstrainingType());
}
diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsDocumentProcessor.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsDocumentProcessor.java
new file mode 100644
index 0000000000..d2d433d6c2
--- /dev/null
+++ b/java/sca/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 = extensionProcessor;
+ 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/java/sca/modules/implementation-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor b/java/sca/modules/implementation-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor
new file mode 100644
index 0000000000..974dd4588d
--- /dev/null
+++ b/java/sca/modules/implementation-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor
@@ -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.
+
+# Implementation class for the artifact processor extension
+org.apache.tuscany.sca.implementation.osgi.xml.ServiceDescriptionsDocumentProcessor;type=/OSGI-INF/remote-service/remote-services.xml,model=org.apache.tuscany.sca.implementation.osgi.ServiceDescriptions