diff options
11 files changed, 1053 insertions, 358 deletions
diff --git a/sandbox/slaws/backward-compatibility/contribution-processor/LICENSE b/sandbox/slaws/backward-compatibility/contribution-processor/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sandbox/slaws/backward-compatibility/contribution-processor/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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. + + + diff --git a/sandbox/slaws/backward-compatibility/contribution-processor/NOTICE b/sandbox/slaws/backward-compatibility/contribution-processor/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sandbox/slaws/backward-compatibility/contribution-processor/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sandbox/slaws/backward-compatibility/contribution-processor/pom.xml b/sandbox/slaws/backward-compatibility/contribution-processor/pom.xml new file mode 100644 index 0000000000..edc344fd12 --- /dev/null +++ b/sandbox/slaws/backward-compatibility/contribution-processor/pom.xml @@ -0,0 +1,180 @@ +<?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. +--> +<project> + + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-modules</artifactId> + <version>2.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <artifactId>bc-contribution-processor</artifactId> + <name>Apache Tuscany SCA Contribution Processor</name> + + <dependencies> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-assembly</artifactId> + <version>2.0-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-contribution</artifactId> + <version>2.0-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-node-api</artifactId> + <version>2.0-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-implementation-node</artifactId> + <version>2.0-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-core</artifactId> + <version>2.0-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-contribution</artifactId> + <version>2.0-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-assembly-xml</artifactId> + <version>2.0-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-workspace</artifactId> + <version>2.0-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-workspace-impl</artifactId> + <version>2.0-SNAPSHOT</version> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-definitions-xml</artifactId> + <version>2.0-SNAPSHOT</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-sca-client-impl</artifactId> + <version>2.0-SNAPSHOT</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-binding-sca</artifactId> + <version>2.0-SNAPSHOT</version> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-policy-xml</artifactId> + <version>2.0-SNAPSHOT</version> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-core-databinding</artifactId> + <version>2.0-SNAPSHOT</version> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-assembly-xsd</artifactId> + <version>2.0-SNAPSHOT</version> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-endpoint</artifactId> + <version>2.0-SNAPSHOT</version> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-implementation-java-runtime</artifactId> + <version>2.0-SNAPSHOT</version> + <scope>test</scope> + </dependency> + + <!-- backward compaibility --> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-assembly-xsd-osoa</artifactId> + <version>2.0-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-assembly-xml-osoa</artifactId> + <version>2.0-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-binding-sca-xml-osoa</artifactId> + <version>2.0-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-implementation-java-xml-osoa</artifactId> + <version>2.0-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-sca-api-osoa</artifactId> + <version>2.0-SNAPSHOT</version> + </dependency> + + </dependencies> + +</project> diff --git a/sandbox/slaws/backward-compatibility/contribution-processor/src/main/java/org/apache/tuscany/sca/bc/ContributionProcessorImpl.java b/sandbox/slaws/backward-compatibility/contribution-processor/src/main/java/org/apache/tuscany/sca/bc/ContributionProcessorImpl.java new file mode 100644 index 0000000000..a82378268a --- /dev/null +++ b/sandbox/slaws/backward-compatibility/contribution-processor/src/main/java/org/apache/tuscany/sca/bc/ContributionProcessorImpl.java @@ -0,0 +1,617 @@ +/* +* 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.bc; + +import static java.lang.System.currentTimeMillis; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.InputStream; +import java.net.URI; +import java.net.URL; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.CompositeService; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderExtensionPoint; +import org.apache.tuscany.sca.client.impl.SCAClientImpl; +import org.apache.tuscany.sca.contribution.Artifact; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.ContributionFactory; +import org.apache.tuscany.sca.contribution.DefaultImport; +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ExtendedURLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ValidationSchemaExtensionPoint; +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.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.core.ModuleActivator; +import org.apache.tuscany.sca.core.ModuleActivatorExtensionPoint; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.core.assembly.ActivationException; +import org.apache.tuscany.sca.core.assembly.CompositeActivator; +import org.apache.tuscany.sca.core.assembly.RuntimeAssemblyFactory; +import org.apache.tuscany.sca.core.invocation.ExtensibleProxyFactory; +import org.apache.tuscany.sca.core.invocation.ProxyFactory; +import org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint; +import org.apache.tuscany.sca.definitions.Definitions; +import org.apache.tuscany.sca.definitions.DefinitionsFactory; +import org.apache.tuscany.sca.definitions.util.DefinitionsUtil; +import org.apache.tuscany.sca.definitions.xml.DefinitionsExtensionPoint; +import org.apache.tuscany.sca.implementation.node.ConfiguredNodeImplementation; +import org.apache.tuscany.sca.implementation.node.NodeImplementationFactory; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.MonitorFactory; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.node.Client; +import org.apache.tuscany.sca.node.ContributionLocationHelper; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.provider.DefinitionsProvider; +import org.apache.tuscany.sca.provider.DefinitionsProviderException; +import org.apache.tuscany.sca.provider.DefinitionsProviderExtensionPoint; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentContext; +import org.apache.tuscany.sca.work.WorkScheduler; +import org.apache.tuscany.sca.workspace.Workspace; +import org.apache.tuscany.sca.workspace.WorkspaceFactory; +import org.apache.tuscany.sca.workspace.builder.ContributionBuilder; +import org.apache.tuscany.sca.workspace.builder.ContributionBuilderExtensionPoint; +import org.oasisopen.sca.CallableReference; +import org.oasisopen.sca.NoSuchDomainException; +import org.oasisopen.sca.NoSuchServiceException; +import org.oasisopen.sca.ServiceReference; +import org.oasisopen.sca.ServiceRuntimeException; +import org.oasisopen.sca.client.SCAClient; + +/** + * Represents an SCA runtime node. + * + * @version $Rev$ $Date$ + */ +public class ContributionProcessorImpl { + + private static final String SCA11_TUSCANY_NS = "http://tuscany.apache.org/xmlns/sca/1.1"; + + private static final Logger logger = Logger.getLogger(ContributionProcessorImpl.class.getName()); + + // The node configuration name, used for logging + private String configurationName; + + // The composite loaded into this node + private Composite composite; + private boolean useDeploymentComposite; + + private ExtensionPointRegistry extensionPoints; + private Monitor monitor; + private ExtendedURLArtifactProcessor<Contribution> contributionProcessor; + private ModelResolverExtensionPoint modelResolvers; + private FactoryExtensionPoint modelFactories; + private WorkspaceFactory workspaceFactory; + private ContributionFactory contributionFactory; + private AssemblyFactory assemblyFactory; + private XMLInputFactory inputFactory; + private ContributionBuilder contributionDependencyBuilder; + private CompositeBuilder compositeBuilder; + private CompositeBuilder endpointReferenceBuilder; + private StAXArtifactProcessorExtensionPoint xmlProcessors; + private StAXArtifactProcessor<Composite> compositeProcessor; + private ProxyFactory proxyFactory; + private List<ModuleActivator> moduleActivators = new ArrayList<ModuleActivator>(); + private CompositeActivator compositeActivator; + private WorkScheduler workScheduler; + private Contribution systemContribution; + private Definitions systemDefinitions; + // Added MJE 28/04/2009 + private URLArtifactProcessor<Composite> compositeDocumentProcessor; + + + /** + * Constructs a new SCA node. + * + * @param compositeURI + * @param contributions + */ + ContributionProcessorImpl(org.apache.tuscany.sca.node.Contribution[] contributions) { + configurationName = "temp"; + logger.log(Level.INFO, "Creating contribution processor: " + configurationName); + + try { + // Initialize the runtime + init(); + + // Create a node configuration + NodeImplementationFactory nodeImplementationFactory = + modelFactories.getFactory(NodeImplementationFactory.class); + ConfiguredNodeImplementation configuration = nodeImplementationFactory.createConfiguredNodeImplementation(); + + // Create contribution models + for (org.apache.tuscany.sca.node.Contribution c : contributions) { + Contribution contribution = contribution(contributionFactory, c); + configuration.getContributions().add(contribution); + } + + // Configure the node + configureNode(configuration); + + } catch (Exception e) { + throw new ServiceRuntimeException(e); + } + } + + static Contribution contribution(ContributionFactory contributionFactory, org.apache.tuscany.sca.node.Contribution c) { + Contribution contribution = contributionFactory.createContribution(); + contribution.setURI(c.getURI()); + contribution.setLocation(c.getLocation()); + contribution.setUnresolved(true); + return contribution; + } + + + + private static String getSystemProperty(final String name) { + return AccessController.doPrivileged(new PrivilegedAction<String>() { + public String run() { + return System.getProperty(name); + } + }); + } + + static URI createURI(String uri) { + if (uri.indexOf(' ') != -1) { + uri = uri.replace(" ", "%20"); + } + return URI.create(uri); + } + + private void init() { + long start = currentTimeMillis(); + + // Create extension point registry + extensionPoints = new DefaultExtensionPointRegistry(); + + // Enable schema validation only of the logger level is FINE or higher + ValidationSchemaExtensionPoint schemas = + extensionPoints.getExtensionPoint(ValidationSchemaExtensionPoint.class); + if (schemas != null) { + String enabled = getSystemProperty(ValidationSchemaExtensionPoint.class.getName() + ".enabled"); + if (enabled == null) { + enabled = "true"; + } + boolean debug = logger.isLoggable(Level.FINE); + schemas.setEnabled("true".equals(enabled) || debug); + } + + // Use the runtime-enabled assembly factory + modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); + assemblyFactory = new RuntimeAssemblyFactory(); + modelFactories.addFactory(assemblyFactory); + + // Create a monitor + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); + monitor = monitorFactory.createMonitor(); + + // Initialize the Tuscany module activators + ModuleActivatorExtensionPoint activators = + extensionPoints.getExtensionPoint(ModuleActivatorExtensionPoint.class); + for (ModuleActivator moduleActivator : activators.getModuleActivators()) { + try { + moduleActivator.start(extensionPoints); + moduleActivators.add(moduleActivator); + } catch (Throwable e) { + // Ignore the failing module for now + logger.log(Level.SEVERE, e.getMessage(), e); + } + } + + // Get XML input/output factories + inputFactory = modelFactories.getFactory(XMLInputFactory.class); + + // Get contribution workspace and assembly model factories + contributionFactory = modelFactories.getFactory(ContributionFactory.class); + workspaceFactory = modelFactories.getFactory(WorkspaceFactory.class); + + // Create XML artifact processors + xmlProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + compositeProcessor = xmlProcessors.getProcessor(Composite.class); + + // Create contribution content processor + URLArtifactProcessorExtensionPoint docProcessorExtensions = + extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); + contributionProcessor = (ExtendedURLArtifactProcessor<Contribution>) docProcessorExtensions.getProcessor(Contribution.class); + + // Added MJE 28/04/2009 + // Create Composite Document processor + compositeDocumentProcessor = docProcessorExtensions.getProcessor(Composite.class); + + // Get the model resolvers + modelResolvers = extensionPoints.getExtensionPoint(ModelResolverExtensionPoint.class); + + // Get a contribution dependency builder + ContributionBuilderExtensionPoint contributionBuilders = + extensionPoints.getExtensionPoint(ContributionBuilderExtensionPoint.class); + contributionDependencyBuilder = + contributionBuilders + .getContributionBuilder("org.apache.tuscany.sca.workspace.builder.ContributionDependencyBuilder"); + + // Get composite builders + CompositeBuilderExtensionPoint compositeBuilders = + extensionPoints.getExtensionPoint(CompositeBuilderExtensionPoint.class); + compositeBuilder = + compositeBuilders.getCompositeBuilder("org.apache.tuscany.sca.assembly.builder.CompositeBuilder"); + + // Get endpoint builders + // TODO - new extension point? + endpointReferenceBuilder = + compositeBuilders.getCompositeBuilder("org.apache.tuscany.sca.endpoint.impl.EndpointReferenceBuilderImpl"); + + // Initialize runtime + + // Get proxy factory + ProxyFactoryExtensionPoint proxyFactories = extensionPoints.getExtensionPoint(ProxyFactoryExtensionPoint.class); + proxyFactory = new ExtensibleProxyFactory(proxyFactories); + + // Get the composite activator + compositeActivator = utilities.getUtility(CompositeActivator.class); + + workScheduler = utilities.getUtility(WorkScheduler.class); + + DefinitionsFactory definitionsFactory = modelFactories.getFactory(DefinitionsFactory.class); + systemDefinitions = definitionsFactory.createDefinitions(); + + DefinitionsExtensionPoint definitionsExtensionPoint = + extensionPoints.getExtensionPoint(DefinitionsExtensionPoint.class); + for (Definitions defs : definitionsExtensionPoint.getDefinitions()) { + DefinitionsUtil.aggregate(systemDefinitions, defs); + } + + // Load the system definitions.xml from all of the loaded extension points + DefinitionsProviderExtensionPoint definitionsProviders = + extensionPoints.getExtensionPoint(DefinitionsProviderExtensionPoint.class); + + // aggregate all the definitions into a single definitions model + try { + for (DefinitionsProvider definitionsProvider : definitionsProviders.getDefinitionsProviders()) { + DefinitionsUtil.aggregate(definitionsProvider.getDefinitions(), systemDefinitions); + } + } catch (DefinitionsProviderException e) { + throw new IllegalStateException(e); + } + + // create a system contribution to hold the definitions. The contribution + // will be extended later with definitions from application contributions + systemContribution = contributionFactory.createContribution(); + systemContribution.setURI("http://tuscany.apache.org/SystemContribution"); + systemContribution.setLocation("http://tuscany.apache.org/SystemContribution"); + ModelResolver modelResolver = new ExtensibleModelResolver(systemContribution, modelResolvers, modelFactories); + systemContribution.setModelResolver(modelResolver); + systemContribution.setUnresolved(true); + + // create an artifact to represent the system defintions and + // add it to the contribution + List<Artifact> artifacts = systemContribution.getArtifacts(); + Artifact artifact = contributionFactory.createArtifact(); + artifact.setURI("http://tuscany.apache.org/SystemContribution/Definitions"); + artifact.setLocation("Derived"); + artifact.setModel(systemDefinitions); + artifacts.add(artifact); + + // don't resolve the system contribution until all the application + // level definitions have been added + + // + // // Configure a resolver for the system definitions + // ModelResolver definitionsResolver = new DefaultModelResolver(); + // for (Intent intent : systemDefinitions.getPolicyIntents()) { + // definitionsResolver.addModel(intent); + // } + // for (PolicySet policySet : systemDefinitions.getPolicySets()) { + // definitionsResolver.addModel(policySet); + // } + // for (ExtensionType bindingType : systemDefinitions.getBindingTypes()) { + // definitionsResolver.addModel(bindingType); + // } + // for (ExtensionType implementationType : systemDefinitions.getImplementationTypes()) { + // definitionsResolver.addModel(implementationType); + // } + // + // // Now that all system sca definitions have been read, let's resolve them + // URLArtifactProcessorExtensionPoint documentProcessors = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); + // URLArtifactProcessor<Definitions> definitionsProcessor = documentProcessors.getProcessor(Definitions.class); + // try { + // definitionsProcessor.resolve(systemDefinitions, definitionsResolver); + // } catch (ContributionResolveException e) { + // throw new IllegalStateException(e); + // } + + if (logger.isLoggable(Level.FINE)) { + long end = currentTimeMillis(); + logger.fine("The tuscany runtime started in " + (end - start) + " ms."); + } + } + + private void configureNode(ConfiguredNodeImplementation configuration) throws Exception { + + // Create workspace model + Workspace workspace = workspaceFactory.createWorkspace(); + workspace.setModelResolver(new ExtensibleModelResolver(workspace, modelResolvers, modelFactories)); + + // Load the specified contributions + for (Contribution c : configuration.getContributions()) { + URI contributionURI = URI.create(c.getURI()); + + URI uri = createURI(c.getLocation()); + if (uri.getScheme() == null) { + uri = new File(c.getLocation()).toURI(); + } + URL contributionURL = uri.toURL(); + + // Load the contribution + logger.log(Level.INFO, "Loading contribution: " + contributionURL); + Contribution contribution = contributionProcessor.read(null, contributionURI, contributionURL); + workspace.getContributions().add(contribution); + analyzeProblems(); + } + + // Build an aggregated SCA definitions model. Must be done before we try and + // resolve any contributions or composites as they may depend on the full + // definitions.xml picture + + // get all definitions.xml artifacts from contributions and aggregate + // into the system contribution. In turn add a default import into + // each contribution so that for unresolved items the resolution + // processing will look in the system contribution + for (Contribution contribution : workspace.getContributions()) { + // aggregate definitions + for (Artifact artifact : contribution.getArtifacts()) { + Object model = artifact.getModel(); + if (model instanceof Definitions) { + DefinitionsUtil.aggregate((Definitions)model, systemDefinitions); + } + } + + // create a default import and wire it up to the system contribution + // model resolver. This is the trick that makes the resolution processing + // skip over to the system contribution if resolution is unsuccessful + // in the current contribution + DefaultImport defaultImport = contributionFactory.createDefaultImport(); + defaultImport.setModelResolver(systemContribution.getModelResolver()); + contribution.getImports().add(defaultImport); + } + + // now resolve the system contribution and add the contribution + // to the workspace + contributionProcessor.resolve(systemContribution, workspace.getModelResolver()); + workspace.getContributions().add(systemContribution); + + // TODO - Now we can calculate applicable policy sets for each composite + + // pre-resolve the contributions + contributionsPreresolve( workspace.getContributions(), workspace.getModelResolver() ); + + // Build the contribution dependencies + Set<Contribution> resolved = new HashSet<Contribution>(); + for (Contribution contribution : workspace.getContributions()) { + contributionDependencyBuilder.build(contribution, workspace, monitor); + + // Resolve contributions + for (Contribution dependency : contribution.getDependencies()) { + if (!resolved.contains(dependency)) { + resolved.add(dependency); + contributionProcessor.resolve(dependency, workspace.getModelResolver()); + } + } + } + + // Create a top level composite to host our composites + // This is temporary to make the activator happy + composite = assemblyFactory.createComposite(); + composite.setName(new QName(SCA11_TUSCANY_NS, "_tempComposite")); + composite.setURI(SCA11_TUSCANY_NS); + + for (Contribution contribution : workspace.getContributions()) { + // find all the (deployable) composites + for (Composite deployable: contribution.getDeployables()) { + composite.getIncludes().add(deployable); + } + } + + // Build the composite and wire the components included in it + compositeBuilder.build(composite, systemDefinitions, monitor); + analyzeProblems(); + + // build the endpoint references + endpointReferenceBuilder.build(composite, systemDefinitions, monitor); + analyzeProblems(); + + + + +/* + composite = configuration.getComposite(); + + // If a composite was not originally supplied when the Node was created, pick one of the deployable + // composites from the supplied contributions. Note: throws an exception if none can be found. + if (composite == null) { + setDefaultComposite(configuration, workspace); + } + + // Find the composite in the given contributions + boolean found = false; + if (!useDeploymentComposite) { + Artifact compositeFile = contributionFactory.createArtifact(); + compositeFile.setUnresolved(true); + compositeFile.setURI(composite.getURI()); + for (Contribution contribution : workspace.getContributions()) { + ModelResolver resolver = contribution.getModelResolver(); + + Artifact resolvedArtifact = resolver.resolveModel(Artifact.class, compositeFile); + if (!resolvedArtifact.isUnresolved() && resolvedArtifact.getModel() instanceof Composite) { + + if (!composite.isUnresolved()) { + + // The composite content was passed into the node and read into a composite model, + // don't use the composite found in the contribution, use that composite, but just resolve + // it within the context of the contribution + compositeProcessor.resolve(composite, resolver); + + } else { + + // Use the resolved composite we've found in the contribution + composite = (Composite)resolvedArtifact.getModel(); + } + found = true; + break; + } // end if + } // end for + } + + if (!found) { + if (!useDeploymentComposite) { + // If the composite was not found, then it must be a separate composite file outside any of the contributions + // - a "composite by value" - this requires its URI to be absolute and pointing at the composite file itself. + // First read in the composite file to create a composite model object... + URI compositeURI = new URI(composite.getURI()); + URL compositeURL = compositeURI.toURL(); + composite = compositeDocumentProcessor.read(compositeURL, compositeURI, compositeURL); + if (composite == null) { + throw new IllegalArgumentException("Composite not found: " + compositeURI); + } + } + + // Resolve the "composite by value" against the FIRST contribution + Contribution contribution = workspace.getContributions().get(0); + ModelResolver resolver = contribution.getModelResolver(); + compositeProcessor.resolve(composite, resolver); + if (composite.isUnresolved()) { + throw new IllegalArgumentException("Could not resolve composite: " + composite.getURI() + + " in contribution " + + contribution.getURI()); + } + } // end if + + // Build the composite and wire the components included in it + compositeBuilder.build(composite, systemDefinitions, monitor); + analyzeProblems(); + + // build the endpoint references + endpointReferenceBuilder.build(composite, systemDefinitions, monitor); + analyzeProblems(); + + // Create a top level composite to host our composite + // This is temporary to make the activator happy + Composite tempComposite = assemblyFactory.createComposite(); + tempComposite.setName(new QName(SCA11_TUSCANY_NS, "_tempComposite")); + tempComposite.setURI(SCA11_TUSCANY_NS); + + // Include the node composite in the top-level composite + tempComposite.getIncludes().add(composite); + + // Set the top level composite on the composite activator as + // logic in callable reference resolution relies on this being + // available + compositeActivator.setDomainComposite(tempComposite); +*/ + + } + + /** + * Pre-resolve phase for contributions, to set up handling of imports and exports prior to full resolution + * @param contributions - the contributions to preresolve + * @param resolver - the ModelResolver to use + * @throws ContributionResolveException + */ + private void contributionsPreresolve( List<Contribution> contributions, ModelResolver resolver ) + throws ContributionResolveException { + + for( Contribution contribution : contributions ) { + contributionProcessor.preResolve(contribution, resolver); + } // end for + } // end method contributionsPreresolve + + + + + /** + * Analyze problems reported by the artifact processors and builders. + * + * @throws Exception + */ + private void analyzeProblems() throws Exception { + for (Problem problem : monitor.getProblems()) { + if ((problem.getSeverity() == Severity.ERROR) && (!problem.getMessageId().equals("SchemaError"))) { + if (problem.getCause() != null) { + throw problem.getCause(); + } else { + throw new ServiceRuntimeException(problem.toString()); + } + } + } + } + + /* + * Sets a default composite by using any deployable one. + */ + private void setDefaultComposite(ConfiguredNodeImplementation configuration, Workspace workspace) { + // just use the first deployable composite + for (Contribution contribution : workspace.getContributions()) { + for (Composite c : contribution.getDeployables()) { + // Ensure that we pick a composite that has actually been found in its contribution!! + if( c.getURI() != null ) { + composite = assemblyFactory.createComposite(); + composite.setURI(c.getURI()); + composite.setUnresolved(true); + configuration.setComposite(composite); + return; + } // end if + } // end for + } // end for + throw new ServiceRuntimeException("No deployable composite found"); + } // end method setDefaultComposite + + public ExtensionPointRegistry getExtensionPoints() { + return extensionPoints; + } + + +} diff --git a/sandbox/slaws/backward-compatibility/contribution-processor/src/test/java/org/apache/tuscany/sca/bc/ConributionProcessorTestCase.java b/sandbox/slaws/backward-compatibility/contribution-processor/src/test/java/org/apache/tuscany/sca/bc/ConributionProcessorTestCase.java new file mode 100644 index 0000000000..0a06f4bcd7 --- /dev/null +++ b/sandbox/slaws/backward-compatibility/contribution-processor/src/test/java/org/apache/tuscany/sca/bc/ConributionProcessorTestCase.java @@ -0,0 +1,42 @@ +/* + * 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.bc; + + +import java.io.File; + +import org.apache.tuscany.sca.node.Contribution; +import org.junit.Test; + +/** + * Test case for NodeImpl + */ +public class ConributionProcessorTestCase { + + @Test + public void testContributionProcessor() { + Contribution contribution = new Contribution("c1", new File("../references/target/classes").toURI().toString()); + Contribution[] contributions = new Contribution[]{contribution}; + + ContributionProcessorImpl cp = new ContributionProcessorImpl(contributions); + + } + +} diff --git a/sandbox/slaws/backward-compatibility/pom.xml b/sandbox/slaws/backward-compatibility/pom.xml index f17a6089a5..9e672f9fef 100644 --- a/sandbox/slaws/backward-compatibility/pom.xml +++ b/sandbox/slaws/backward-compatibility/pom.xml @@ -59,6 +59,7 @@ <activeByDefault>true</activeByDefault> </activation> <modules> + <module>contribution-processor</module> <module>references</module> </modules> </profile> @@ -66,6 +67,7 @@ <profile> <id>eclipse</id> <modules> + <module>contribution-processor</module> <module>references</module> </modules> <build> diff --git a/sandbox/slaws/backward-compatibility/references/src/main/resources/AutoWiredReferencesTest.composite b/sandbox/slaws/backward-compatibility/references/src/main/resources/AutoWiredReferencesTest.composite deleted file mode 100644 index 4f1604223b..0000000000 --- a/sandbox/slaws/backward-compatibility/references/src/main/resources/AutoWiredReferencesTest.composite +++ /dev/null @@ -1,65 +0,0 @@ -<?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 - * 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://www.osoa.org/xmlns/sca/1.0" xmlns:foo="http://foo" targetNamespace="http://foo" - name="AutowireReferencesTest" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" autowire="true"> - - <service name="AComponent" promote="AComponent"> - <interface.java interface="org.apache.tuscany.sca.itest.references.AComponent" /> - </service> - - <component name="AComponent" autowire="false"> - <implementation.java class="org.apache.tuscany.sca.itest.references.AComponentImpl" /> - <reference name="bReference" target="BComponent" /> - <reference name="cReference" autowire="true" /> - <reference name="dReference1" /> - <!-- - <reference name="dReference1" target="DComponent" /> - --> - <reference name="DReference2" target="DComponent" /> - <reference name="dReferences" autowire="true" /> - <reference name="dReferenceArray" autowire="true" /> - <reference name="dServiceReferences" target="DComponent DComponent1" /> - - </component> - - <component name="AComponentAutowire" autowire="true"> - <implementation.java class="org.apache.tuscany.sca.itest.references.AComponentImpl" /> - <reference name="bReference" target="BComponent" /> - </component> - - <component name="BComponentWrongTarget"> - <implementation.java class="org.apache.tuscany.sca.itest.references.BComponentWrongTargetImpl" /> - </component> - - <component name="BComponent"> - <implementation.java class="org.apache.tuscany.sca.itest.references.BComponentImpl" /> - </component> - - <component name="CComponent"> - <implementation.java class="org.apache.tuscany.sca.itest.references.CComponentImpl" /> - </component> - - <component name="DComponent"> - <implementation.java class="org.apache.tuscany.sca.itest.references.DComponentImpl" /> - </component> - - <component name="DComponent1"> - <implementation.java class="org.apache.tuscany.sca.itest.references.DComponentImpl" /> - </component> -</composite>
\ No newline at end of file diff --git a/sandbox/slaws/backward-compatibility/references/src/main/resources/InnerReferencesTest.composite b/sandbox/slaws/backward-compatibility/references/src/main/resources/InnerReferencesTest.composite deleted file mode 100644 index 2e70038d4d..0000000000 --- a/sandbox/slaws/backward-compatibility/references/src/main/resources/InnerReferencesTest.composite +++ /dev/null @@ -1,54 +0,0 @@ -<?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 - * 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://www.osoa.org/xmlns/sca/1.0" xmlns:foo="http://foo" targetNamespace="http://foo" - name="InnerReferencesTest" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - - <service name="AComponent" promote="AComponent"> - <interface.java interface="org.apache.tuscany.sca.itest.references.AComponent" /> - </service> - - <component name="AComponent"> - <implementation.java class="org.apache.tuscany.sca.itest.references.AComponentImpl" /> - <reference name="bReference" target="BComponent" /> - <reference name="cReference" target="CComponent" /> - <reference name="dReference1" target="DComponent" /> - <reference name="DReference2" target="DComponent" /> - <reference name="dReferences" target="DComponent DComponent1" /> - <reference name="dReferenceArray" target="DComponent1" /> - <reference name="dServiceReferences" target="DComponent DComponent1" /> - </component> - - <component name="BComponent"> - <implementation.java class="org.apache.tuscany.sca.itest.references.BComponentImpl" /> - <reference name="cReference" target="CComponent" /> - </component> - - <component name="CComponent"> - <implementation.java class="org.apache.tuscany.sca.itest.references.CComponentImpl" /> - </component> - - <component name="DComponent"> - <implementation.java class="org.apache.tuscany.sca.itest.references.DComponentImpl" /> - </component> - - <component name="DComponent1"> - <implementation.java class="org.apache.tuscany.sca.itest.references.DComponentImpl" /> - </component> - -</composite>
\ No newline at end of file diff --git a/sandbox/slaws/backward-compatibility/references/src/main/resources/ManualWiredReferencesTest.composite b/sandbox/slaws/backward-compatibility/references/src/main/resources/ManualWiredReferencesTest.composite index 708960974b..3cfd80cde5 100644 --- a/sandbox/slaws/backward-compatibility/references/src/main/resources/ManualWiredReferencesTest.composite +++ b/sandbox/slaws/backward-compatibility/references/src/main/resources/ManualWiredReferencesTest.composite @@ -20,7 +20,7 @@ name="ManualWiredReferencesTest" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" autowire="true"> <service name="AComponent" promote="AComponent"> - <interface.java interface="org.apache.tuscany.sca.itest.references.AComponent" /> + <!--interface.java interface="org.apache.tuscany.sca.itest.references.AComponent" /--> </service> <component name="AComponent" > diff --git a/sandbox/slaws/backward-compatibility/references/src/test/java/org/apache/tuscany/sca/itest/references/AutoWiredReferenceTestCase.java b/sandbox/slaws/backward-compatibility/references/src/test/java/org/apache/tuscany/sca/itest/references/AutoWiredReferenceTestCase.java deleted file mode 100644 index 83bf3e6da7..0000000000 --- a/sandbox/slaws/backward-compatibility/references/src/test/java/org/apache/tuscany/sca/itest/references/AutoWiredReferenceTestCase.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * 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.itest.references; - -import static junit.framework.Assert.assertEquals; -import junit.framework.Assert; - -import org.apache.tuscany.sca.node.Node; -import org.apache.tuscany.sca.node.equinox.launcher.Contribution; -import org.apache.tuscany.sca.node.equinox.launcher.NodeLauncher; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; - -public class AutoWiredReferenceTestCase { - - private static NodeLauncher launcher; - private static Node node; - private static AComponent acomponent; - private static AComponent acomponentAutowire; - - - @BeforeClass - public static void setUpBeforeClass() throws Exception { - launcher = NodeLauncher.newInstance(); - node = launcher.createNode("AutoWiredReferencesTest.composite", - new Contribution("test", "./target/classes")); - - try { - node.start(); - } catch (Exception ex) { - String status = ex.toString(); - System.out.println(status); - } - - acomponent = node.getService(AComponent.class, "AComponent"); - acomponentAutowire = node.getService(AComponent.class, "AComponentAutowire"); - } - - @AfterClass - public static void tearDownAfterClass() throws Exception { - if (node != null) { - node.stop(); - node.destroy(); - } - if (launcher != null) { - launcher.destroy(); - } - } - - @Test - public void testBReference() { - assertEquals("BComponent", acomponent.fooB()); - } - - @Test - public void testCReference() { - assertEquals("CComponent", acomponent.fooC()); - } - - @Test - public void testBCReference() { - assertEquals("BCComponent", acomponent.fooBC()); - } - - @Test(expected = NullPointerException.class) - public void testD1Reference() { - acomponent.fooD1(); - } - - @Test - public void testD2Reference() { - assertEquals("DComponent", acomponent.fooD2()); - } - - @Test - public void testMultiDReferenceArray() { - String components = acomponent.fooMultipleDArray(); - Assert.assertTrue(components.contains("DComponent1")); - } - - @Test - public void testMultiDServiceReference() { - String components = acomponent.fooMultipleDServiceRef(); - Assert.assertTrue(components.contains("DComponent")); - Assert.assertTrue(components.contains("DComponent1")); - } - - @Test - public void testRequiredFalseReference() { - try { - acomponent.getDReference().dFoo(); - } catch (Exception e) { - Assert.assertTrue(true); - } - } - - @Test - public void testTargetPrecendence() { - try { - assertEquals("BComponent", acomponentAutowire.fooB()); - } catch (Exception e) { - Assert.assertTrue(true); - } - } - -} diff --git a/sandbox/slaws/backward-compatibility/references/src/test/java/org/apache/tuscany/sca/itest/references/InnerReferenceTestCase.java b/sandbox/slaws/backward-compatibility/references/src/test/java/org/apache/tuscany/sca/itest/references/InnerReferenceTestCase.java deleted file mode 100644 index e4bbe4bcba..0000000000 --- a/sandbox/slaws/backward-compatibility/references/src/test/java/org/apache/tuscany/sca/itest/references/InnerReferenceTestCase.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * 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.itest.references; - -import static junit.framework.Assert.assertEquals; -import junit.framework.Assert; - -import org.apache.tuscany.sca.node.Node; -import org.apache.tuscany.sca.node.equinox.launcher.Contribution; -import org.apache.tuscany.sca.node.equinox.launcher.NodeLauncher; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; - -public class InnerReferenceTestCase { - - private static NodeLauncher launcher; - private static Node node; - private static AComponent acomponent; - - - @BeforeClass - public static void setUpBeforeClass() throws Exception { - launcher = NodeLauncher.newInstance(); - node = launcher.createNode("InnerReferencesTest.composite", - new Contribution("test", "./target/classes")); - - try { - node.start(); - } catch (Exception ex) { - String status = ex.toString(); - System.out.println(status); - } - - acomponent = node.getService(AComponent.class, "AComponent"); - } - - @AfterClass - public static void tearDownAfterClass() throws Exception { - if (node != null) { - node.stop(); - node.destroy(); - } - if (launcher != null) { - launcher.destroy(); - } - } - - @Test - public void testBReference() { - assertEquals("BComponent", acomponent.fooB()); - } - - @Test - public void testCReference() { - assertEquals("CComponent", acomponent.fooC()); - } - - @Test - public void testBCReference() { - assertEquals("BCComponent", acomponent.fooBC()); - } - - @Test - public void testD1Reference() { - assertEquals("DComponent", acomponent.fooD1()); - } - - @Test - public void testD2Reference() { - assertEquals("DComponent", acomponent.fooD2()); - } - - @Test - public void testMultiDReference() { - String components = acomponent.fooMultipleD(); - Assert.assertTrue(components.contains("DComponent")); - Assert.assertTrue(components.contains("DComponent1")); - } - - @Test - public void testMultiDReferenceArray() { - String components = acomponent.fooMultipleDArray(); - Assert.assertTrue(components.equals("DComponent1")); - } - - @Test - public void testMultiDServiceReference() { - String components = acomponent.fooMultipleDServiceRef(); - Assert.assertTrue(components.contains("DComponent")); - Assert.assertTrue(components.contains("DComponent1")); - } - - @Test(expected = NullPointerException.class) - public void testRequiredFalseReference() { - acomponent.getDReference().dFoo(); - } - -} |