summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/implementation-osgi
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-07-21 07:03:47 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-07-21 07:03:47 +0000
commitab6904bc2f622129bc548391745b08eb0c219e57 (patch)
tree5c7599119182bfa8e65c0d6605e933396aedffd2 /java/sca/modules/implementation-osgi
parent8d70ef6d556ad29b93d5d40e91c4c9304638c9e9 (diff)
Fix svn:eol-style and svn:keywords properties for java/xml files
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@796166 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/implementation-osgi')
-rw-r--r--java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/BindingDescriptions.java68
-rw-r--r--java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/BindingDescriptionsImpl.java72
-rw-r--r--java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/introspection/ExportedServiceIntrospector.java896
-rw-r--r--java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/BindingDescriptionsProcessor.java234
-rw-r--r--java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/BluePrintComponentsProcessor.java292
-rw-r--r--java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiComponentProcessor.java350
-rw-r--r--java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/BluePrintComponentsProcessorTestCase.java178
-rw-r--r--java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiComponentProcessorTestCase.java172
-rw-r--r--java/sca/modules/implementation-osgi/src/test/resources/OSGI-INF/sca/bundle.componentType108
-rw-r--r--java/sca/modules/implementation-osgi/src/test/resources/osgitest.composite70
10 files changed, 1220 insertions, 1220 deletions
diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/BindingDescriptions.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/BindingDescriptions.java
index 068374c7cf..5265241920 100644
--- a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/BindingDescriptions.java
+++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/BindingDescriptions.java
@@ -1,34 +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 java.util.List;
-
-import javax.xml.namespace.QName;
-
-import org.apache.tuscany.sca.assembly.Binding;
-
-/**
- * OSGi RFC 119 SCA binding descriptions
- */
-public interface BindingDescriptions extends List<Binding> {
- String OSGI_SD_NS = ServiceDescriptions.OSGI_SD_NS;
- QName BINDINGS_QNAME = new QName(OSGI_SD_NS, "bindings");
-}
+/*
+ * 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;
+
+import org.apache.tuscany.sca.assembly.Binding;
+
+/**
+ * OSGi RFC 119 SCA binding descriptions
+ */
+public interface BindingDescriptions extends List<Binding> {
+ String OSGI_SD_NS = ServiceDescriptions.OSGI_SD_NS;
+ QName BINDINGS_QNAME = new QName(OSGI_SD_NS, "bindings");
+}
diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/BindingDescriptionsImpl.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/BindingDescriptionsImpl.java
index 67a724877d..66ca01bacf 100644
--- a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/BindingDescriptionsImpl.java
+++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/BindingDescriptionsImpl.java
@@ -1,36 +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.assembly.Binding;
-import org.apache.tuscany.sca.implementation.osgi.BindingDescriptions;
-
-/**
- *
- */
-public class BindingDescriptionsImpl extends ArrayList<Binding> implements BindingDescriptions {
- private static final long serialVersionUID = 7647814680087128002L;
-
- public BindingDescriptionsImpl() {
- super();
- }
-}
+/*
+ * 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.assembly.Binding;
+import org.apache.tuscany.sca.implementation.osgi.BindingDescriptions;
+
+/**
+ *
+ */
+public class BindingDescriptionsImpl extends ArrayList<Binding> implements BindingDescriptions {
+ private static final long serialVersionUID = 7647814680087128002L;
+
+ public BindingDescriptionsImpl() {
+ super();
+ }
+}
diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/introspection/ExportedServiceIntrospector.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/introspection/ExportedServiceIntrospector.java
index a997724ce0..409e14bdd9 100644
--- a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/introspection/ExportedServiceIntrospector.java
+++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/introspection/ExportedServiceIntrospector.java
@@ -1,448 +1,448 @@
-/*
- * 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.introspection;
-
-import static org.apache.tuscany.sca.assembly.Base.SCA11_TUSCANY_NS;
-import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.REMOTE_CONFIG_SCA;
-import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.SCA_BINDINGS;
-import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.SERVICE_EXPORTED_INTENTS;
-import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.SERVICE_EXPORTED_INTENTS_EXTRA;
-import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.SERVICE_EXPORTED_INTERFACES;
-import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.SERVICE_IMPORTED_CONFIGS;
-import static org.osgi.framework.Constants.OBJECTCLASS;
-import static org.osgi.framework.Constants.SERVICE_ID;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URI;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Dictionary;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLOutputFactory;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-
-import org.apache.tuscany.sca.assembly.AssemblyFactory;
-import org.apache.tuscany.sca.assembly.Base;
-import org.apache.tuscany.sca.assembly.Binding;
-import org.apache.tuscany.sca.assembly.Component;
-import org.apache.tuscany.sca.assembly.ComponentReference;
-import org.apache.tuscany.sca.assembly.ComponentService;
-import org.apache.tuscany.sca.assembly.Composite;
-import org.apache.tuscany.sca.assembly.Reference;
-import org.apache.tuscany.sca.assembly.Service;
-import org.apache.tuscany.sca.contribution.Contribution;
-import org.apache.tuscany.sca.contribution.ContributionFactory;
-import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
-import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
-import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
-import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
-import org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver;
-import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
-import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint;
-import org.apache.tuscany.sca.core.ExtensionPointRegistry;
-import org.apache.tuscany.sca.core.FactoryExtensionPoint;
-import org.apache.tuscany.sca.core.UtilityExtensionPoint;
-import org.apache.tuscany.sca.implementation.osgi.BindingDescriptions;
-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.ServiceDescriptionsFactory;
-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.MonitorFactory;
-import org.apache.tuscany.sca.policy.Intent;
-import org.apache.tuscany.sca.policy.PolicyFactory;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.Filter;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
-
-/**
- * Introspect an OSGi Service to create an SCA composite that contains a single component with
- * implementation.osgi
- */
-public class ExportedServiceIntrospector {
- private AssemblyFactory assemblyFactory;
- private ContributionFactory contributionFactory;
- private OSGiImplementationFactory implementationFactory;
- private ServiceDescriptionsFactory serviceDescriptionsFactory;
- private PolicyFactory policyFactory;
- private ExtensionPointRegistry registry;
- private FactoryExtensionPoint factories;
- private ModelResolverExtensionPoint modelResolvers;
- private XMLInputFactory xmlInputFactory;
- private XMLOutputFactory xmlOutputFactory;
- private JavaInterfaceFactory javaInterfaceFactory;
- private StAXArtifactProcessor processor;
-
- /**
- * @param intentName
- * @return
- */
- private static QName getQName(String intentName) {
- QName qname;
- if (intentName.startsWith("{")) {
- int i = intentName.indexOf('}');
- if (i != -1) {
- qname = new QName(intentName.substring(1, i), intentName.substring(i + 1));
- } else {
- throw new IllegalArgumentException("Invalid intent: " + intentName);
- }
- } else {
- // Default to SCA namespace
- qname = new QName(Base.SCA11_NS, intentName);
- }
- return qname;
- }
-
- /**
- * @param registry
- */
- public ExportedServiceIntrospector(ExtensionPointRegistry registry) {
- super();
- this.registry = registry;
- this.factories = registry.getExtensionPoint(FactoryExtensionPoint.class);
- this.modelResolvers = registry.getExtensionPoint(ModelResolverExtensionPoint.class);
- this.assemblyFactory = factories.getFactory(AssemblyFactory.class);
- this.contributionFactory = factories.getFactory(ContributionFactory.class);
- this.policyFactory = factories.getFactory(PolicyFactory.class);
- this.implementationFactory = factories.getFactory(OSGiImplementationFactory.class);
- this.serviceDescriptionsFactory = factories.getFactory(ServiceDescriptionsFactory.class);
- this.xmlInputFactory = factories.getFactory(XMLInputFactory.class);
- this.xmlOutputFactory = factories.getFactory(XMLOutputFactory.class);
- this.javaInterfaceFactory = factories.getFactory(JavaInterfaceFactory.class);
- StAXArtifactProcessorExtensionPoint processors =
- registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
- UtilityExtensionPoint utilities = this.registry.getExtensionPoint(UtilityExtensionPoint.class);
- MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class);
- Monitor monitor = null;
- if (monitorFactory != null) {
- monitor = monitorFactory.createMonitor();
- }
- processor = new ExtensibleStAXArtifactProcessor(processors, xmlInputFactory, xmlOutputFactory, monitor);
- }
-
- private Intent getIntent(String intent) {
- QName name = getQName(intent);
- Intent i = policyFactory.createIntent();
- i.setName(name);
- return i;
- }
-
- private List<Intent> getIntents(String[] intents) {
- if (intents == null || intents.length == 0) {
- return Collections.emptyList();
- }
- List<Intent> intentList = new ArrayList<Intent>();
- for (String i : intents) {
- Intent intent = getIntent(i);
- if (intent != null) {
- intentList.add(intent);
- }
- }
- return intentList;
- }
-
- private Map<String, Object> getProperties(ServiceReference reference) {
- String[] names = reference.getPropertyKeys();
- if (names != null) {
- Map<String, Object> properties = new HashMap<String, Object>();
- for (String name : names) {
- properties.put(name, reference.getProperty(name));
- }
- return properties;
- } else {
- return Collections.emptyMap();
- }
- }
-
- /**
- * Parse the Stringp[] to support values that are separated by comma
- * @param interfaces
- * @return
- */
- private String[] parse(String[] interfaces) {
- if (interfaces == null) {
- return null;
- }
- List<String> names = new ArrayList<String>();
- for (String i : interfaces) {
- String[] parts = i.split(",");
- for (String p : parts) {
- names.add(p.trim());
- }
- }
- return names.toArray(new String[names.size()]);
- }
-
- /**
- * Introspect a local OSGi Service represented by the ServiceReference to create
- * an SCA service with the required intents and bindings
- * @param reference The service reference for a local OSGi service
- * @return An SCA contribution with a deployable composite for the SCA service
- * @throws Exception
- */
- public Contribution introspect(ServiceReference reference) throws Exception {
- Map<String, Object> properties = getProperties(reference);
-
- OSGiProperty serviceID = implementationFactory.createOSGiProperty();
- serviceID.setName(SERVICE_ID);
- // The service.id is Long
- serviceID.setValue(String.valueOf(reference.getProperty(SERVICE_ID)));
-
- String id = "osgi.service." + serviceID.getValue();
- Composite composite = assemblyFactory.createComposite();
- composite.setName(new QName(SCA11_TUSCANY_NS, id));
-
- Component component = assemblyFactory.createComponent();
- component.setName(id);
- component.setAutowire(Boolean.TRUE);
-
- composite.getComponents().add(component);
-
- Bundle bundle = reference.getBundle();
- OSGiImplementation implementation = implementationFactory.createOSGiImplementation();
-
- implementation.setBundle(bundle);
- component.setImplementation(implementation);
- implementation.setUnresolved(false);
-
- String[] remoteInterfaces = getStrings(reference.getProperty(SERVICE_EXPORTED_INTERFACES));
- if (remoteInterfaces == null || remoteInterfaces.length > 0 && "*".equals(remoteInterfaces[0])) {
- remoteInterfaces = getStrings(reference.getProperty(OBJECTCLASS));
- } else {
- remoteInterfaces = parse(remoteInterfaces);
- }
- for (String intf : remoteInterfaces) {
- Service service = assemblyFactory.createService();
- JavaInterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract();
- Class<?> interfaceClass = bundle.loadClass(intf);
- JavaInterface javaInterface = javaInterfaceFactory.createJavaInterface(interfaceClass);
- interfaceContract.setInterface(javaInterface);
- if (javaInterface.getCallbackClass() != null) {
- interfaceContract.setCallbackInterface(javaInterfaceFactory.createJavaInterface(javaInterface
- .getCallbackClass()));
- }
-
- service.setName(interfaceClass.getSimpleName());
- service.setInterfaceContract(interfaceContract);
-
- service.getExtensions().add(serviceID);
-
- implementation.getServices().add(service);
-
- ComponentService componentService = assemblyFactory.createComponentService();
- componentService.setName(service.getName());
- component.getServices().add(componentService);
- componentService.setService(service);
- }
-
- String[] requiredIntents = getStrings(properties.get(SERVICE_EXPORTED_INTENTS));
- List<Intent> intents = getIntents(requiredIntents);
- String[] requiredIntentsExtra = getStrings(properties.get(SERVICE_EXPORTED_INTENTS_EXTRA));
- List<Intent> extraIntents = getIntents(requiredIntentsExtra);
-
- String[] bindingDocuments = getStrings(properties.get(SCA_BINDINGS));
- List<Binding> bindings = loadBindings(reference.getBundle(), bindingDocuments);
-
- for (ComponentService componentService : component.getServices()) {
- componentService.getRequiredIntents().addAll(intents);
- componentService.getRequiredIntents().addAll(extraIntents);
- componentService.getBindings().addAll(bindings);
- }
-
- // FIXME: Should we scan the owning bundle to create the SCA contribution?
- Contribution contribution = contributionFactory.createContribution();
- contribution.setURI("urn:" + id);
- contribution.setLocation(bundle.getEntry("/").toString());
- contribution.getDeployables().add(composite);
- ModelResolver modelResolver = new ExtensibleModelResolver(contribution, modelResolvers, factories);
- contribution.setModelResolver(modelResolver);
- contribution.setUnresolved(true);
- return contribution;
- }
-
- /**
- * Introspect an OSGi filter to create an SCA reference
- *
- * @param bundle
- * @param filterStr
- * @param properties
- * @return
- * @throws Exception
- */
- public Contribution introspect(Bundle bundle, String filterStr, Map<String, Object> properties) throws Exception {
- Filter filter = null;
- try {
- filter = bundle.getBundleContext().createFilter(filterStr);
- } catch (InvalidSyntaxException e) {
- e.printStackTrace();
- return null;
- }
-
- Dictionary<String, Object> props = new Hashtable<String, Object>();
- props.put(SERVICE_IMPORTED_CONFIGS, new String[] {REMOTE_CONFIG_SCA});
- if (!filter.match(props)) {
- return null;
- }
- String id = "osgi.reference." + UUID.randomUUID();
- Composite composite = assemblyFactory.createComposite();
- composite.setName(new QName(Base.SCA11_TUSCANY_NS, id));
-
- Component component = assemblyFactory.createComponent();
- component.setName(id);
- component.setAutowire(Boolean.TRUE);
-
- composite.getComponents().add(component);
-
- OSGiImplementation implementation = implementationFactory.createOSGiImplementation();
-
- implementation.setBundle(bundle);
- component.setImplementation(implementation);
- implementation.setUnresolved(false);
-
- String[] remoteInterfaces = getStrings(properties.get(SERVICE_EXPORTED_INTERFACES));
- if (remoteInterfaces == null || remoteInterfaces.length > 0 && "*".equals(remoteInterfaces[0])) {
- remoteInterfaces = getStrings(properties.get(OBJECTCLASS));
- } else {
- remoteInterfaces = parse(remoteInterfaces);
- }
- for (String intf : remoteInterfaces) {
- Reference reference = assemblyFactory.createReference();
- JavaInterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract();
- Class<?> interfaceClass = bundle.loadClass(intf);
- JavaInterface javaInterface = javaInterfaceFactory.createJavaInterface(interfaceClass);
- interfaceContract.setInterface(javaInterface);
- if (javaInterface.getCallbackClass() != null) {
- interfaceContract.setCallbackInterface(javaInterfaceFactory.createJavaInterface(javaInterface
- .getCallbackClass()));
- }
-
- reference.setName(id);
- reference.setInterfaceContract(interfaceContract);
-
- reference.getExtensions().add(filter);
-
- implementation.getReferences().add(reference);
-
- ComponentReference componentReference = assemblyFactory.createComponentReference();
- component.getReferences().add(componentReference);
- componentReference.setReference(reference);
- componentReference.setWiredByImpl(true);
- }
-
- String[] requiredIntents = getStrings(properties.get(SERVICE_EXPORTED_INTENTS));
- List<Intent> intents = getIntents(requiredIntents);
-
- String[] bindingDocuments = getStrings(properties.get(SCA_BINDINGS));
- List<Binding> bindings = loadBindings(bundle, bindingDocuments);
-
- for (ComponentReference componentReference : component.getReferences()) {
- componentReference.getRequiredIntents().addAll(intents);
- componentReference.getBindings().addAll(bindings);
- }
-
- // FIXME: Should we scan the owning bundle to create the SCA contribution?
- Contribution contribution = contributionFactory.createContribution();
- contribution.setURI("urn:" + id);
- contribution.setLocation(bundle.getEntry("/").toString());
- contribution.getDeployables().add(composite);
- ModelResolver modelResolver = new ExtensibleModelResolver(contribution, modelResolvers, factories);
- contribution.setModelResolver(modelResolver);
- contribution.setUnresolved(true);
- return contribution;
- }
-
- private List<Binding> loadBindings(Bundle bundle, String[] bindingDocuments) throws IOException,
- ContributionReadException {
- if (bindingDocuments == null || bindingDocuments.length == 0) {
- return Collections.emptyList();
- }
- List<Binding> bindings = new ArrayList<Binding>();
- for (String doc : bindingDocuments) {
- URL url = locate(bundle, doc);
- if (url == null) {
- throw new IOException("Entry " + doc + " cannot be found in bundle " + bundle);
- }
- bindings.addAll(loadBindings(url));
- }
- return bindings;
- }
-
- private List<Binding> loadBindings(URL url) throws ContributionReadException, IOException {
- InputStream is = url.openStream();
- try {
- XMLStreamReader reader = xmlInputFactory.createXMLStreamReader(is);
- reader.nextTag();
- Object model = processor.read(reader);
- if (model instanceof BindingDescriptions) {
- return ((BindingDescriptions)model);
- } else {
- return Collections.emptyList();
- }
- } catch (XMLStreamException e) {
- throw new ContributionReadException(e);
- } finally {
- is.close();
- }
- }
-
- private URL locate(Bundle bundle, String location) throws MalformedURLException {
- URI uri = URI.create(location);
- if (uri.isAbsolute()) {
- return uri.toURL();
- }
- return bundle.getEntry(location);
- }
-
- /**
- * In OSGi, the value of String+ can be a single String, String[] or Collection<String>
- * @param value
- * @return
- */
- private String[] getStrings(Object value) {
- if (value == null) {
- return null;
- }
- if (value instanceof String) {
- return new String[] {(String)value};
- } else if (value instanceof Collection) {
- Collection<String> collection = (Collection)value;
- return collection.toArray(new String[collection.size()]);
- }
- return (String[])value;
-
- }
-
-}
+/*
+ * 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.introspection;
+
+import static org.apache.tuscany.sca.assembly.Base.SCA11_TUSCANY_NS;
+import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.REMOTE_CONFIG_SCA;
+import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.SCA_BINDINGS;
+import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.SERVICE_EXPORTED_INTENTS;
+import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.SERVICE_EXPORTED_INTENTS_EXTRA;
+import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.SERVICE_EXPORTED_INTERFACES;
+import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.SERVICE_IMPORTED_CONFIGS;
+import static org.osgi.framework.Constants.OBJECTCLASS;
+import static org.osgi.framework.Constants.SERVICE_ID;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Base;
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.ContributionFactory;
+import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.implementation.osgi.BindingDescriptions;
+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.ServiceDescriptionsFactory;
+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.MonitorFactory;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * Introspect an OSGi Service to create an SCA composite that contains a single component with
+ * implementation.osgi
+ */
+public class ExportedServiceIntrospector {
+ private AssemblyFactory assemblyFactory;
+ private ContributionFactory contributionFactory;
+ private OSGiImplementationFactory implementationFactory;
+ private ServiceDescriptionsFactory serviceDescriptionsFactory;
+ private PolicyFactory policyFactory;
+ private ExtensionPointRegistry registry;
+ private FactoryExtensionPoint factories;
+ private ModelResolverExtensionPoint modelResolvers;
+ private XMLInputFactory xmlInputFactory;
+ private XMLOutputFactory xmlOutputFactory;
+ private JavaInterfaceFactory javaInterfaceFactory;
+ private StAXArtifactProcessor processor;
+
+ /**
+ * @param intentName
+ * @return
+ */
+ private static QName getQName(String intentName) {
+ QName qname;
+ if (intentName.startsWith("{")) {
+ int i = intentName.indexOf('}');
+ if (i != -1) {
+ qname = new QName(intentName.substring(1, i), intentName.substring(i + 1));
+ } else {
+ throw new IllegalArgumentException("Invalid intent: " + intentName);
+ }
+ } else {
+ // Default to SCA namespace
+ qname = new QName(Base.SCA11_NS, intentName);
+ }
+ return qname;
+ }
+
+ /**
+ * @param registry
+ */
+ public ExportedServiceIntrospector(ExtensionPointRegistry registry) {
+ super();
+ this.registry = registry;
+ this.factories = registry.getExtensionPoint(FactoryExtensionPoint.class);
+ this.modelResolvers = registry.getExtensionPoint(ModelResolverExtensionPoint.class);
+ this.assemblyFactory = factories.getFactory(AssemblyFactory.class);
+ this.contributionFactory = factories.getFactory(ContributionFactory.class);
+ this.policyFactory = factories.getFactory(PolicyFactory.class);
+ this.implementationFactory = factories.getFactory(OSGiImplementationFactory.class);
+ this.serviceDescriptionsFactory = factories.getFactory(ServiceDescriptionsFactory.class);
+ this.xmlInputFactory = factories.getFactory(XMLInputFactory.class);
+ this.xmlOutputFactory = factories.getFactory(XMLOutputFactory.class);
+ this.javaInterfaceFactory = factories.getFactory(JavaInterfaceFactory.class);
+ StAXArtifactProcessorExtensionPoint processors =
+ registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ UtilityExtensionPoint utilities = this.registry.getExtensionPoint(UtilityExtensionPoint.class);
+ MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class);
+ Monitor monitor = null;
+ if (monitorFactory != null) {
+ monitor = monitorFactory.createMonitor();
+ }
+ processor = new ExtensibleStAXArtifactProcessor(processors, xmlInputFactory, xmlOutputFactory, monitor);
+ }
+
+ private Intent getIntent(String intent) {
+ QName name = getQName(intent);
+ Intent i = policyFactory.createIntent();
+ i.setName(name);
+ return i;
+ }
+
+ private List<Intent> getIntents(String[] intents) {
+ if (intents == null || intents.length == 0) {
+ return Collections.emptyList();
+ }
+ List<Intent> intentList = new ArrayList<Intent>();
+ for (String i : intents) {
+ Intent intent = getIntent(i);
+ if (intent != null) {
+ intentList.add(intent);
+ }
+ }
+ return intentList;
+ }
+
+ private Map<String, Object> getProperties(ServiceReference reference) {
+ String[] names = reference.getPropertyKeys();
+ if (names != null) {
+ Map<String, Object> properties = new HashMap<String, Object>();
+ for (String name : names) {
+ properties.put(name, reference.getProperty(name));
+ }
+ return properties;
+ } else {
+ return Collections.emptyMap();
+ }
+ }
+
+ /**
+ * Parse the Stringp[] to support values that are separated by comma
+ * @param interfaces
+ * @return
+ */
+ private String[] parse(String[] interfaces) {
+ if (interfaces == null) {
+ return null;
+ }
+ List<String> names = new ArrayList<String>();
+ for (String i : interfaces) {
+ String[] parts = i.split(",");
+ for (String p : parts) {
+ names.add(p.trim());
+ }
+ }
+ return names.toArray(new String[names.size()]);
+ }
+
+ /**
+ * Introspect a local OSGi Service represented by the ServiceReference to create
+ * an SCA service with the required intents and bindings
+ * @param reference The service reference for a local OSGi service
+ * @return An SCA contribution with a deployable composite for the SCA service
+ * @throws Exception
+ */
+ public Contribution introspect(ServiceReference reference) throws Exception {
+ Map<String, Object> properties = getProperties(reference);
+
+ OSGiProperty serviceID = implementationFactory.createOSGiProperty();
+ serviceID.setName(SERVICE_ID);
+ // The service.id is Long
+ serviceID.setValue(String.valueOf(reference.getProperty(SERVICE_ID)));
+
+ String id = "osgi.service." + serviceID.getValue();
+ Composite composite = assemblyFactory.createComposite();
+ composite.setName(new QName(SCA11_TUSCANY_NS, id));
+
+ Component component = assemblyFactory.createComponent();
+ component.setName(id);
+ component.setAutowire(Boolean.TRUE);
+
+ composite.getComponents().add(component);
+
+ Bundle bundle = reference.getBundle();
+ OSGiImplementation implementation = implementationFactory.createOSGiImplementation();
+
+ implementation.setBundle(bundle);
+ component.setImplementation(implementation);
+ implementation.setUnresolved(false);
+
+ String[] remoteInterfaces = getStrings(reference.getProperty(SERVICE_EXPORTED_INTERFACES));
+ if (remoteInterfaces == null || remoteInterfaces.length > 0 && "*".equals(remoteInterfaces[0])) {
+ remoteInterfaces = getStrings(reference.getProperty(OBJECTCLASS));
+ } else {
+ remoteInterfaces = parse(remoteInterfaces);
+ }
+ for (String intf : remoteInterfaces) {
+ Service service = assemblyFactory.createService();
+ JavaInterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract();
+ Class<?> interfaceClass = bundle.loadClass(intf);
+ JavaInterface javaInterface = javaInterfaceFactory.createJavaInterface(interfaceClass);
+ interfaceContract.setInterface(javaInterface);
+ if (javaInterface.getCallbackClass() != null) {
+ interfaceContract.setCallbackInterface(javaInterfaceFactory.createJavaInterface(javaInterface
+ .getCallbackClass()));
+ }
+
+ service.setName(interfaceClass.getSimpleName());
+ service.setInterfaceContract(interfaceContract);
+
+ service.getExtensions().add(serviceID);
+
+ implementation.getServices().add(service);
+
+ ComponentService componentService = assemblyFactory.createComponentService();
+ componentService.setName(service.getName());
+ component.getServices().add(componentService);
+ componentService.setService(service);
+ }
+
+ String[] requiredIntents = getStrings(properties.get(SERVICE_EXPORTED_INTENTS));
+ List<Intent> intents = getIntents(requiredIntents);
+ String[] requiredIntentsExtra = getStrings(properties.get(SERVICE_EXPORTED_INTENTS_EXTRA));
+ List<Intent> extraIntents = getIntents(requiredIntentsExtra);
+
+ String[] bindingDocuments = getStrings(properties.get(SCA_BINDINGS));
+ List<Binding> bindings = loadBindings(reference.getBundle(), bindingDocuments);
+
+ for (ComponentService componentService : component.getServices()) {
+ componentService.getRequiredIntents().addAll(intents);
+ componentService.getRequiredIntents().addAll(extraIntents);
+ componentService.getBindings().addAll(bindings);
+ }
+
+ // FIXME: Should we scan the owning bundle to create the SCA contribution?
+ Contribution contribution = contributionFactory.createContribution();
+ contribution.setURI("urn:" + id);
+ contribution.setLocation(bundle.getEntry("/").toString());
+ contribution.getDeployables().add(composite);
+ ModelResolver modelResolver = new ExtensibleModelResolver(contribution, modelResolvers, factories);
+ contribution.setModelResolver(modelResolver);
+ contribution.setUnresolved(true);
+ return contribution;
+ }
+
+ /**
+ * Introspect an OSGi filter to create an SCA reference
+ *
+ * @param bundle
+ * @param filterStr
+ * @param properties
+ * @return
+ * @throws Exception
+ */
+ public Contribution introspect(Bundle bundle, String filterStr, Map<String, Object> properties) throws Exception {
+ Filter filter = null;
+ try {
+ filter = bundle.getBundleContext().createFilter(filterStr);
+ } catch (InvalidSyntaxException e) {
+ e.printStackTrace();
+ return null;
+ }
+
+ Dictionary<String, Object> props = new Hashtable<String, Object>();
+ props.put(SERVICE_IMPORTED_CONFIGS, new String[] {REMOTE_CONFIG_SCA});
+ if (!filter.match(props)) {
+ return null;
+ }
+ String id = "osgi.reference." + UUID.randomUUID();
+ Composite composite = assemblyFactory.createComposite();
+ composite.setName(new QName(Base.SCA11_TUSCANY_NS, id));
+
+ Component component = assemblyFactory.createComponent();
+ component.setName(id);
+ component.setAutowire(Boolean.TRUE);
+
+ composite.getComponents().add(component);
+
+ OSGiImplementation implementation = implementationFactory.createOSGiImplementation();
+
+ implementation.setBundle(bundle);
+ component.setImplementation(implementation);
+ implementation.setUnresolved(false);
+
+ String[] remoteInterfaces = getStrings(properties.get(SERVICE_EXPORTED_INTERFACES));
+ if (remoteInterfaces == null || remoteInterfaces.length > 0 && "*".equals(remoteInterfaces[0])) {
+ remoteInterfaces = getStrings(properties.get(OBJECTCLASS));
+ } else {
+ remoteInterfaces = parse(remoteInterfaces);
+ }
+ for (String intf : remoteInterfaces) {
+ Reference reference = assemblyFactory.createReference();
+ JavaInterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract();
+ Class<?> interfaceClass = bundle.loadClass(intf);
+ JavaInterface javaInterface = javaInterfaceFactory.createJavaInterface(interfaceClass);
+ interfaceContract.setInterface(javaInterface);
+ if (javaInterface.getCallbackClass() != null) {
+ interfaceContract.setCallbackInterface(javaInterfaceFactory.createJavaInterface(javaInterface
+ .getCallbackClass()));
+ }
+
+ reference.setName(id);
+ reference.setInterfaceContract(interfaceContract);
+
+ reference.getExtensions().add(filter);
+
+ implementation.getReferences().add(reference);
+
+ ComponentReference componentReference = assemblyFactory.createComponentReference();
+ component.getReferences().add(componentReference);
+ componentReference.setReference(reference);
+ componentReference.setWiredByImpl(true);
+ }
+
+ String[] requiredIntents = getStrings(properties.get(SERVICE_EXPORTED_INTENTS));
+ List<Intent> intents = getIntents(requiredIntents);
+
+ String[] bindingDocuments = getStrings(properties.get(SCA_BINDINGS));
+ List<Binding> bindings = loadBindings(bundle, bindingDocuments);
+
+ for (ComponentReference componentReference : component.getReferences()) {
+ componentReference.getRequiredIntents().addAll(intents);
+ componentReference.getBindings().addAll(bindings);
+ }
+
+ // FIXME: Should we scan the owning bundle to create the SCA contribution?
+ Contribution contribution = contributionFactory.createContribution();
+ contribution.setURI("urn:" + id);
+ contribution.setLocation(bundle.getEntry("/").toString());
+ contribution.getDeployables().add(composite);
+ ModelResolver modelResolver = new ExtensibleModelResolver(contribution, modelResolvers, factories);
+ contribution.setModelResolver(modelResolver);
+ contribution.setUnresolved(true);
+ return contribution;
+ }
+
+ private List<Binding> loadBindings(Bundle bundle, String[] bindingDocuments) throws IOException,
+ ContributionReadException {
+ if (bindingDocuments == null || bindingDocuments.length == 0) {
+ return Collections.emptyList();
+ }
+ List<Binding> bindings = new ArrayList<Binding>();
+ for (String doc : bindingDocuments) {
+ URL url = locate(bundle, doc);
+ if (url == null) {
+ throw new IOException("Entry " + doc + " cannot be found in bundle " + bundle);
+ }
+ bindings.addAll(loadBindings(url));
+ }
+ return bindings;
+ }
+
+ private List<Binding> loadBindings(URL url) throws ContributionReadException, IOException {
+ InputStream is = url.openStream();
+ try {
+ XMLStreamReader reader = xmlInputFactory.createXMLStreamReader(is);
+ reader.nextTag();
+ Object model = processor.read(reader);
+ if (model instanceof BindingDescriptions) {
+ return ((BindingDescriptions)model);
+ } else {
+ return Collections.emptyList();
+ }
+ } catch (XMLStreamException e) {
+ throw new ContributionReadException(e);
+ } finally {
+ is.close();
+ }
+ }
+
+ private URL locate(Bundle bundle, String location) throws MalformedURLException {
+ URI uri = URI.create(location);
+ if (uri.isAbsolute()) {
+ return uri.toURL();
+ }
+ return bundle.getEntry(location);
+ }
+
+ /**
+ * In OSGi, the value of String+ can be a single String, String[] or Collection<String>
+ * @param value
+ * @return
+ */
+ private String[] getStrings(Object value) {
+ if (value == null) {
+ return null;
+ }
+ if (value instanceof String) {
+ return new String[] {(String)value};
+ } else if (value instanceof Collection) {
+ Collection<String> collection = (Collection)value;
+ return collection.toArray(new String[collection.size()]);
+ }
+ return (String[])value;
+
+ }
+
+}
diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/BindingDescriptionsProcessor.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/BindingDescriptionsProcessor.java
index 0a94c6ae0a..7efb3f196a 100644
--- a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/BindingDescriptionsProcessor.java
+++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/BindingDescriptionsProcessor.java
@@ -1,117 +1,117 @@
-/*
- * 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.Binding;
-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.ModelResolver;
-import org.apache.tuscany.sca.core.ExtensionPointRegistry;
-import org.apache.tuscany.sca.core.FactoryExtensionPoint;
-import org.apache.tuscany.sca.implementation.osgi.BindingDescriptions;
-import org.apache.tuscany.sca.implementation.osgi.ServiceDescriptionsFactory;
-import org.apache.tuscany.sca.monitor.Monitor;
-
-/*
-<?xml version="1.0" encoding="UTF-8"?>
-<bindings xmlns="http://www.osgi.org/xmlns/sd/v1.0.0" xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200903">
- <binding.ws/>
- <binding.sca/>
-</bindings>
-*/
-public class BindingDescriptionsProcessor implements StAXArtifactProcessor<BindingDescriptions> {
- private Monitor monitor;
- private StAXArtifactProcessor processor;
- private ServiceDescriptionsFactory factory;
-
- public BindingDescriptionsProcessor(ExtensionPointRegistry registry,
- StAXArtifactProcessor processor,
- Monitor monitor) {
- this.monitor = monitor;
- this.processor = processor;
- this.factory =
- registry.getExtensionPoint(FactoryExtensionPoint.class).getFactory(ServiceDescriptionsFactory.class);
- }
-
- public BindingDescriptions read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
- BindingDescriptions bindings = factory.createBindingDescriptions();
- boolean exit = false;
- while (!exit) {
- int event = reader.getEventType();
- switch (event) {
- case XMLStreamConstants.START_ELEMENT:
- QName name = reader.getName();
- if (!"bindings".equals(name.getLocalPart())) {
- Object element = null;
- try {
- element = processor.read(reader);
- } catch (ContributionReadException e) {
- throw e;
- }
- if (element instanceof Binding) {
- bindings.add((Binding)element);
- }
- }
- break;
- case XMLStreamConstants.END_ELEMENT:
- name = reader.getName();
- if ("bindings".equals(name.getLocalPart())) {
- exit = true;
- }
- break;
- }
- if (reader.hasNext()) {
- reader.next();
- } else {
- exit = true;
- }
- }
- return bindings;
- }
-
- public QName getArtifactType() {
- return BindingDescriptions.BINDINGS_QNAME;
- }
-
- public void write(BindingDescriptions model, XMLStreamWriter writer) throws ContributionWriteException,
- XMLStreamException {
- writer.writeStartElement(BindingDescriptions.OSGI_SD_NS, "bindings");
- for (Binding binding : model) {
- processor.write(model, writer);
- }
- writer.writeEndElement();
- }
-
- public Class<BindingDescriptions> getModelType() {
- return BindingDescriptions.class;
- }
-
- public void resolve(BindingDescriptions model, ModelResolver resolver) throws ContributionResolveException {
- // TODO: To be implemented
- }
-}
+/*
+ * 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.Binding;
+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.ModelResolver;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+import org.apache.tuscany.sca.implementation.osgi.BindingDescriptions;
+import org.apache.tuscany.sca.implementation.osgi.ServiceDescriptionsFactory;
+import org.apache.tuscany.sca.monitor.Monitor;
+
+/*
+<?xml version="1.0" encoding="UTF-8"?>
+<bindings xmlns="http://www.osgi.org/xmlns/sd/v1.0.0" xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200903">
+ <binding.ws/>
+ <binding.sca/>
+</bindings>
+*/
+public class BindingDescriptionsProcessor implements StAXArtifactProcessor<BindingDescriptions> {
+ private Monitor monitor;
+ private StAXArtifactProcessor processor;
+ private ServiceDescriptionsFactory factory;
+
+ public BindingDescriptionsProcessor(ExtensionPointRegistry registry,
+ StAXArtifactProcessor processor,
+ Monitor monitor) {
+ this.monitor = monitor;
+ this.processor = processor;
+ this.factory =
+ registry.getExtensionPoint(FactoryExtensionPoint.class).getFactory(ServiceDescriptionsFactory.class);
+ }
+
+ public BindingDescriptions read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+ BindingDescriptions bindings = factory.createBindingDescriptions();
+ boolean exit = false;
+ while (!exit) {
+ int event = reader.getEventType();
+ switch (event) {
+ case XMLStreamConstants.START_ELEMENT:
+ QName name = reader.getName();
+ if (!"bindings".equals(name.getLocalPart())) {
+ Object element = null;
+ try {
+ element = processor.read(reader);
+ } catch (ContributionReadException e) {
+ throw e;
+ }
+ if (element instanceof Binding) {
+ bindings.add((Binding)element);
+ }
+ }
+ break;
+ case XMLStreamConstants.END_ELEMENT:
+ name = reader.getName();
+ if ("bindings".equals(name.getLocalPart())) {
+ exit = true;
+ }
+ break;
+ }
+ if (reader.hasNext()) {
+ reader.next();
+ } else {
+ exit = true;
+ }
+ }
+ return bindings;
+ }
+
+ public QName getArtifactType() {
+ return BindingDescriptions.BINDINGS_QNAME;
+ }
+
+ public void write(BindingDescriptions model, XMLStreamWriter writer) throws ContributionWriteException,
+ XMLStreamException {
+ writer.writeStartElement(BindingDescriptions.OSGI_SD_NS, "bindings");
+ for (Binding binding : model) {
+ processor.write(model, writer);
+ }
+ writer.writeEndElement();
+ }
+
+ public Class<BindingDescriptions> getModelType() {
+ return BindingDescriptions.class;
+ }
+
+ public void resolve(BindingDescriptions model, ModelResolver resolver) throws ContributionResolveException {
+ // TODO: To be implemented
+ }
+}
diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/BluePrintComponentsProcessor.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/BluePrintComponentsProcessor.java
index 92b0316b9c..8dfded0c4e 100644
--- a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/BluePrintComponentsProcessor.java
+++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/BluePrintComponentsProcessor.java
@@ -1,146 +1,146 @@
-/*
- * 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.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;
-import org.apache.tuscany.sca.monitor.Monitor;
-
-/*
-<!-- 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;
- private Monitor monitor;
-
- public BluePrintComponentsProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) {
- this.monitor = monitor;
- this.factory = modelFactories.getFactory(AssemblyFactory.class);
- this.javaInterfaceFactory = modelFactories.getFactory(JavaInterfaceFactory.class);
- }
-
- public ComponentType read(XMLStreamReader reader) 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) throws ContributionWriteException,
- XMLStreamException {
- // TODO: To be implemented
- }
-
- public Class<ComponentType> getModelType() {
- return ComponentType.class;
- }
-
- public void resolve(ComponentType model, ModelResolver resolver) throws ContributionResolveException {
- // TODO: To be implemented
- }
-}
+/*
+ * 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.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;
+import org.apache.tuscany.sca.monitor.Monitor;
+
+/*
+<!-- 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;
+ private Monitor monitor;
+
+ public BluePrintComponentsProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) {
+ this.monitor = monitor;
+ this.factory = modelFactories.getFactory(AssemblyFactory.class);
+ this.javaInterfaceFactory = modelFactories.getFactory(JavaInterfaceFactory.class);
+ }
+
+ public ComponentType read(XMLStreamReader reader) 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) throws ContributionWriteException,
+ XMLStreamException {
+ // TODO: To be implemented
+ }
+
+ public Class<ComponentType> getModelType() {
+ return ComponentType.class;
+ }
+
+ public void resolve(ComponentType model, ModelResolver resolver) throws ContributionResolveException {
+ // TODO: To be implemented
+ }
+}
diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiComponentProcessor.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiComponentProcessor.java
index d70458053e..e62c424a1a 100644
--- a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiComponentProcessor.java
+++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiComponentProcessor.java
@@ -1,175 +1,175 @@
-/*
- * 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.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;
-import org.apache.tuscany.sca.monitor.Monitor;
-
-/*
-<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;
- private Monitor monitor;
-
- public OSGiComponentProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) {
- this.monitor = monitor;
- this.factory = modelFactories.getFactory(AssemblyFactory.class);
- this.javaInterfaceFactory = modelFactories.getFactory(JavaInterfaceFactory.class);
- }
-
- public ComponentType read(XMLStreamReader reader) 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) throws ContributionWriteException,
- XMLStreamException {
- // TODO: To be implemented
- }
-
- public Class<ComponentType> getModelType() {
- return ComponentType.class;
- }
-
- public void resolve(ComponentType model, ModelResolver resolver) throws ContributionResolveException {
- // TODO: To be implemented
- }
-}
+/*
+ * 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.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;
+import org.apache.tuscany.sca.monitor.Monitor;
+
+/*
+<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;
+ private Monitor monitor;
+
+ public OSGiComponentProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) {
+ this.monitor = monitor;
+ this.factory = modelFactories.getFactory(AssemblyFactory.class);
+ this.javaInterfaceFactory = modelFactories.getFactory(JavaInterfaceFactory.class);
+ }
+
+ public ComponentType read(XMLStreamReader reader) 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) throws ContributionWriteException,
+ XMLStreamException {
+ // TODO: To be implemented
+ }
+
+ public Class<ComponentType> getModelType() {
+ return ComponentType.class;
+ }
+
+ public void resolve(ComponentType model, ModelResolver resolver) throws ContributionResolveException {
+ // TODO: To be implemented
+ }
+}
diff --git a/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/BluePrintComponentsProcessorTestCase.java b/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/BluePrintComponentsProcessorTestCase.java
index fd1a89ccf3..1865c27141 100644
--- a/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/BluePrintComponentsProcessorTestCase.java
+++ b/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/BluePrintComponentsProcessorTestCase.java
@@ -1,89 +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.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()),
- null);
- ComponentType ct = processor.read(reader);
- 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();
- }
- }
-
-}
+/*
+ * 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.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()),
+ null);
+ ComponentType ct = processor.read(reader);
+ 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/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiComponentProcessorTestCase.java b/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiComponentProcessorTestCase.java
index 5f2a7d690c..3b26fdb999 100644
--- a/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiComponentProcessorTestCase.java
+++ b/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiComponentProcessorTestCase.java
@@ -1,86 +1,86 @@
-/*
- * 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.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 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 {
- OSGiComponentProcessor processor =
- new OSGiComponentProcessor(new DefaultFactoryExtensionPoint(new DefaultExtensionPointRegistry()), null);
- ComponentType ct = processor.read(reader);
- 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();
- }
- }
-
-}
+/*
+ * 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.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 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 {
+ OSGiComponentProcessor processor =
+ new OSGiComponentProcessor(new DefaultFactoryExtensionPoint(new DefaultExtensionPointRegistry()), null);
+ ComponentType ct = processor.read(reader);
+ 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/java/sca/modules/implementation-osgi/src/test/resources/OSGI-INF/sca/bundle.componentType b/java/sca/modules/implementation-osgi/src/test/resources/OSGI-INF/sca/bundle.componentType
index 7860094626..bc9e4f6aaf 100644
--- a/java/sca/modules/implementation-osgi/src/test/resources/OSGI-INF/sca/bundle.componentType
+++ b/java/sca/modules/implementation-osgi/src/test/resources/OSGI-INF/sca/bundle.componentType
@@ -1,54 +1,54 @@
-<?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/200903"
- 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 -->
- <t:osgi.property name="prop1">1</t:osgi.property>
- <t:osgi.property name="prop2">ABC</t:osgi.property>
- </service>
-
- <!-- The reference elment defines an SCA proxy to a remote OSGi service -->
- <reference name="addService">
- <interface.java interface="calculator.dosgi.operations.AddService"/>
- <t:osgi.property name="prop1">1</t:osgi.property>
- <t:osgi.property name="prop2">ABC</t:osgi.property>
- </reference>
- <reference name="subtractService">
- <interface.java interface="calculator.dosgi.operations.SubtractService"/>
- <t:osgi.property name="prop1">1</t:osgi.property>
- <t:osgi.property name="prop2">ABC</t:osgi.property>
- </reference>
- <reference name="multiplyService">
- <interface.java interface="calculator.dosgi.operations.MultiplyService"/>
- <t:osgi.property name="prop1">1</t:osgi.property>
- <t:osgi.property name="prop2">ABC</t:osgi.property>
- </reference>
- <reference name="divideService">
- <interface.java interface="calculator.dosgi.operations.DivideService"/>
- <t:osgi.property name="prop1">1</t:osgi.property>
- <t:osgi.property name="prop2">ABC</t:osgi.property>
- </reference>
-
-</componentType>
+<?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/200903"
+ 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 -->
+ <t:osgi.property name="prop1">1</t:osgi.property>
+ <t:osgi.property name="prop2">ABC</t:osgi.property>
+ </service>
+
+ <!-- The reference elment defines an SCA proxy to a remote OSGi service -->
+ <reference name="addService">
+ <interface.java interface="calculator.dosgi.operations.AddService"/>
+ <t:osgi.property name="prop1">1</t:osgi.property>
+ <t:osgi.property name="prop2">ABC</t:osgi.property>
+ </reference>
+ <reference name="subtractService">
+ <interface.java interface="calculator.dosgi.operations.SubtractService"/>
+ <t:osgi.property name="prop1">1</t:osgi.property>
+ <t:osgi.property name="prop2">ABC</t:osgi.property>
+ </reference>
+ <reference name="multiplyService">
+ <interface.java interface="calculator.dosgi.operations.MultiplyService"/>
+ <t:osgi.property name="prop1">1</t:osgi.property>
+ <t:osgi.property name="prop2">ABC</t:osgi.property>
+ </reference>
+ <reference name="divideService">
+ <interface.java interface="calculator.dosgi.operations.DivideService"/>
+ <t:osgi.property name="prop1">1</t:osgi.property>
+ <t:osgi.property name="prop2">ABC</t:osgi.property>
+ </reference>
+
+</componentType>
diff --git a/java/sca/modules/implementation-osgi/src/test/resources/osgitest.composite b/java/sca/modules/implementation-osgi/src/test/resources/osgitest.composite
index 24c5716abd..8c59703724 100644
--- a/java/sca/modules/implementation-osgi/src/test/resources/osgitest.composite
+++ b/java/sca/modules/implementation-osgi/src/test/resources/osgitest.composite
@@ -1,35 +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/200903"
- 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>
+<?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/200903"
+ 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>