summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/branches/2.0/modules/implementation-bpel
diff options
context:
space:
mode:
authorlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2013-09-26 20:33:20 +0000
committerlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2013-09-26 20:33:20 +0000
commite5b7380c874745c989d1816b8f552504f038e1bc (patch)
tree3084133139737c821ce5384bd27fc2258e795826 /sca-java-2.x/branches/2.0/modules/implementation-bpel
parent33b786453598495cde754c80f5a9397de68ff60e (diff)
2.0 branch for possible maintenance release
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1526672 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/LICENSE251
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/META-INF/MANIFEST.MF52
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/NOTICE17
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/pom.xml473
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/BPELODEDeployFile.java233
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/DeploymentWorkspace.java233
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/EmbeddedODEServer.java563
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/GeronimoTxFactory.java48
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEBindingContext.java91
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEDeployment.java55
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEDeploymentException.java41
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEEndpointReference.java96
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEEprContext.java75
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEExternalService.java370
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEInitializationException.java41
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEMessageExchangeContext.java57
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEShutdownException.java41
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/TuscanyEPR.java49
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/TuscanyPRC.java62
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/TuscanyProcessConfImpl.java823
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/provider/BPELImplementationProvider.java187
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/provider/BPELImplementationProviderFactory.java69
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/provider/BPELInvoker.java286
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/provider/ODEInvocationException.java33
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory20
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/test/java/org/apache/tuscany/sca/implementation/bpel/ode/EmbeddedODEServerTestCase.java124
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/test/resources/helloworld/deploy.xml30
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/test/resources/helloworld/greetings.wsdl87
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/test/resources/helloworld/helloworld.bpel81
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/test/resources/helloworld/helloworld.wsdl82
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/test/resources/log4j.properties36
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel/LICENSE251
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel/META-INF/MANIFEST.MF32
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel/NOTICE17
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel/pom.xml64
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELFactory.java42
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELImplementation.java109
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELProcessDefinition.java115
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELFactoryImpl.java44
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELImplementationImpl.java160
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELProcessDefinitionImpl.java128
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELDocumentModelResolver.java401
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELDocumentProcessor.java355
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELImplementationProcessor.java452
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELImportElement.java65
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELPartnerLinkElement.java132
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELPartnerLinkTypeElement.java118
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELProcessorConstants.java61
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor19
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor19
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver19
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.bpel.BPELFactory19
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/resources/impl-bpel-validation-messages.properties34
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELDocumentProcessorTestCase.java62
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELImplementationProcessorTestCase.java102
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel/src/test/resources/helloworld/helloworld.bpel66
-rw-r--r--sca-java-2.x/branches/2.0/modules/implementation-bpel/src/test/resources/helloworld/helloworld.wsdl82
57 files changed, 7674 insertions, 0 deletions
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/LICENSE b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/LICENSE
new file mode 100644
index 0000000000..baba9ca048
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/LICENSE
@@ -0,0 +1,251 @@
+
+ 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.
+
+===============================================================================================================
+
+Apache Tuscany SCA for Java Subcomponents
+=========================================:
+
+The Tuscany SCA for Java release includes a number of subcomponents with
+separate copyright notices and license terms. Your use of the source
+code for the these subcomponents is subject to the terms and
+conditions of the following licenses.
+
+=================================================================================================================
+
+This module implementation-script temporarily includes one file under the following BSD license:
+
+ Copyright (c) 2006, Sun Microsystems, Inc.
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ - Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ - Neither the name of the Sun Microsystems, Inc. nor the names of
+ contributors may be used to endorse or promote products derived from this
+ software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ DAMAGE.
+
+=================================================================================================================
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/META-INF/MANIFEST.MF b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/META-INF/MANIFEST.MF
new file mode 100644
index 0000000000..79977c6864
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/META-INF/MANIFEST.MF
@@ -0,0 +1,52 @@
+Manifest-Version: 1.0
+Private-Package: org.apache.tuscany.sca.implementation.bpel.ode;versio
+ n="2.0",org.apache.tuscany.sca.implementation.bpel.ode.provider;versi
+ on="2.0"
+SCA-Version: 1.1
+Bundle-Name: Apache Tuscany SCA BPEL ODE Implementation Extension
+Bundle-Vendor: The Apache Software Foundation
+Bundle-Version: 2.0
+Bundle-ManifestVersion: 2
+Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
+Bundle-ClassPath: .
+Bundle-Description: Apache Tuscany SCA BPEL ODE Implementation Extensi
+ on
+Import-Package: javax.persistence;version="1.0.0",
+ javax.persistence.spi;version="1.0.0",
+ javax.resource.spi,
+ javax.transaction;version="1.1.0",
+ javax.wsdl;resolution:=optional,
+ javax.xml.namespace;resolution:=optional,
+ org.apache.commons.logging;resolution:=optional,
+ org.apache.geronimo.transaction.manager,
+ org.apache.ode.bpel.compiler;version="1.3.2",
+ org.apache.ode.bpel.dao;version="1.3.2",
+ org.apache.ode.bpel.engine;version="1.3.2",
+ org.apache.ode.bpel.evt;version="1.3.2",
+ org.apache.ode.bpel.iapi;version="1.3.2",
+ org.apache.ode.bpel.memdao;version="1.3.2",
+ org.apache.ode.dao.jpa;version="1.3.2",
+ org.apache.ode.il.config;version="1.3.2",
+ org.apache.ode.il.dbutil;version="1.3.2",
+ org.apache.ode.scheduler.simple;version="1.3.2",
+ org.apache.ode.utils;version="1.3.2",
+ org.apache.openjpa.persistence;version="1.2.1",
+ org.apache.tuscany.sca.assembly;version="2.0",
+ org.apache.tuscany.sca.core;version="2.0",
+ org.apache.tuscany.sca.databinding;version="2.0",
+ org.apache.tuscany.sca.databinding.impl;version="2.0",
+ org.apache.tuscany.sca.databinding.xml;version="2.0",
+ org.apache.tuscany.sca.extensibility;version="2.0.0",
+ org.apache.tuscany.sca.implementation.bpel;version="2.0",
+ org.apache.tuscany.sca.interfacedef;version="2.0",
+ org.apache.tuscany.sca.interfacedef.wsdl;version="2.0",
+ org.apache.tuscany.sca.invocation;version="2.0",
+ org.apache.tuscany.sca.policy;version="2.0.0",
+ org.apache.tuscany.sca.provider;version="2.0",
+ org.apache.tuscany.sca.runtime;version="2.0",
+ org.eclipse.core.runtime;common=split;resolution:=optional,
+ org.oasisopen.sca.annotation;version="2.0",
+ org.w3c.dom;resolution:=optional
+Bundle-SymbolicName: org.apache.tuscany.sca.implementation.bpel.runtime
+Bundle-DocURL: http://www.apache.org/
+Bundle-RequiredExecutionEnvironment: J2SE-1.5,JavaSE-1.6
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/NOTICE b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/NOTICE
new file mode 100644
index 0000000000..a2f696be26
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/NOTICE
@@ -0,0 +1,17 @@
+${pom.name}
+Copyright (c) 2005 - 2008 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
+Unless otherwise indicated, all distribution made available by the Apache Software Foundation
+is provided to you under the terms and conditions of the Apache License Version 2.0 ("AL").
+A copy of the AL is provided with this distribution as the LICENSE file present in the
+root directory, and is also available at http://www.apache.org/licenses/.
+
+This product also includes software under the BSD license
+(see the LICENSE file contained in this distribution), with
+the following copyright:
+
+Copyright (c) 2006, Sun Microsystems, Inc.
+All rights reserved.
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/pom.xml b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/pom.xml
new file mode 100644
index 0000000000..b12798d8d5
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/pom.xml
@@ -0,0 +1,473 @@
+<?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</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>tuscany-implementation-bpel-runtime</artifactId>
+ <name>Apache Tuscany SCA BPEL ODE Implementation Extension</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-base-runtime-pom</artifactId>
+ <type>pom</type>
+ <version>2.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <!-- ODE Jars -->
+ <dependency>
+ <groupId>org.apache.ode</groupId>
+ <artifactId>ode-bpel-epr</artifactId>
+ <version>1.3.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ode</groupId>
+ <artifactId>ode-bpel-store</artifactId>
+ <version>1.3.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ode</groupId>
+ <artifactId>ode-bpel-dao</artifactId>
+ <version>1.3.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ode</groupId>
+ <artifactId>ode-dao-jpa</artifactId>
+ <version>1.3.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ode</groupId>
+ <artifactId>ode-dao-jpa-ojpa-derby</artifactId>
+ <version>1.3.2</version>
+ <type>zip</type>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ode</groupId>
+ <artifactId>ode-bpel-runtime</artifactId>
+ <version>1.3.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ode</groupId>
+ <artifactId>ode-bpel-api</artifactId>
+ <version>1.3.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ode</groupId>
+ <artifactId>ode-scheduler-simple</artifactId>
+ <version>1.3.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ode</groupId>
+ <artifactId>ode-utils</artifactId>
+ <version>1.3.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ode</groupId>
+ <artifactId>ode-bpel-compiler</artifactId>
+ <version>1.3.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ode</groupId>
+ <artifactId>ode-bpel-schemas</artifactId>
+ <version>1.3.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ode</groupId>
+ <artifactId>ode-bpel-obj</artifactId>
+ <version>1.3.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ode</groupId>
+ <artifactId>ode-jacob</artifactId>
+ <version>1.3.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ode</groupId>
+ <artifactId>ode-jacob-ap</artifactId>
+ <version>1.3.2</version>
+ </dependency>
+ <!-- http://issues.apache.org/jira/browse/ODE-604 -->
+ <dependency>
+ <groupId>org.apache.ode</groupId>
+ <artifactId>ode-agents</artifactId>
+ <version>1.3.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ode</groupId>
+ <artifactId>ode-dao-hibernate</artifactId>
+ <version>1.3.2</version>
+ </dependency>
+
+ <!-- implementation-bpel non-sca dependencies -->
+ <dependency>
+ <groupId>org.eclipse.equinox</groupId>
+ <artifactId>common</artifactId>
+ <version>3.5.0-v20090520-1800</version>
+ </dependency>
+
+ <!-- ODE Dependencies -->
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.3</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ <version>3.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.modules</groupId>
+ <artifactId>geronimo-kernel</artifactId>
+ <version>2.0.1</version>
+ <exclusions>
+ <exclusion>
+ <groupId>asm</groupId>
+ <artifactId>asm-commons</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>mx4j</groupId>
+ <artifactId>mx4j</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>cglib</groupId>
+ <artifactId>cglib-nodep</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>xpp3</groupId>
+ <artifactId>xpp3</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>xstream</groupId>
+ <artifactId>xstream</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.components</groupId>
+ <artifactId>geronimo-transaction</artifactId>
+ <version>2.1.4</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-jta_1.1_spec</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-ejb_2.1_spec</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-j2ee-connector_1.5_spec</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>ognl</groupId>
+ <artifactId>ognl</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-ejb_3.0_spec</artifactId>
+ <version>1.0.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-jta_1.1_spec</artifactId>
+ <version>1.1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-jpa_3.0_spec</artifactId>
+ <version>1.1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-jms_1.1_spec</artifactId>
+ <version>1.1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-j2ee-connector_1.5_spec</artifactId>
+ <version>2.0.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.components</groupId>
+ <artifactId>geronimo-connector</artifactId>
+ <version>2.1.4</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-jta_1.0.1B_spec</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-j2ee-connector_1.5_spec</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>xmlbeans</groupId>
+ <artifactId>xbean</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>stax</groupId>
+ <artifactId>stax-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.derby</groupId>
+ <artifactId>derby</artifactId>
+ <version>10.4.1.3</version>
+ </dependency>
+ <dependency>
+ <groupId>tranql</groupId>
+ <artifactId>tranql-connector</artifactId>
+ <version>1.1</version>
+ <exclusions>
+ <exclusion>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>geronimo-spec</groupId>
+ <artifactId>geronimo-spec-j2ee-connector</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>geronimo-spec</groupId>
+ <artifactId>geronimo-spec-jta</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>axion</groupId>
+ <artifactId>axion</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>commons-primitives</groupId>
+ <artifactId>commons-primitives</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <!-- http://issues.apache.org/jira/browse/ODE-605 -->
+ <dependency>
+ <groupId>org.apache.openjpa</groupId>
+ <artifactId>openjpa</artifactId>
+ <version>1.2.1</version>
+
+ <exclusions>
+ <exclusion>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-jta_1.1_spec</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-jpa_3.0_spec</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-jms_1.1_spec</artifactId>
+ </exclusion>
+ </exclusions>
+
+ </dependency>
+ <dependency>
+ <groupId>net.sourceforge.serp</groupId>
+ <artifactId>serp</artifactId>
+ <version>1.13.1</version>
+ <exclusions>
+ <exclusion>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>jaxen</groupId>
+ <artifactId>jaxen</artifactId>
+ <version>1.1.1</version>
+ <exclusions>
+ <exclusion>
+ <groupId>xom</groupId>
+ <artifactId>xom</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>xml-apis</groupId>
+ <artifactId>xml-apis</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>xerces</groupId>
+ <artifactId>xercesImpl</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>xalan</groupId>
+ <artifactId>xalan</artifactId>
+ <version>2.7.0</version>
+ <exclusions>
+ <exclusion>
+ <groupId>xml-apis</groupId>
+ <artifactId>xml-apis</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>xerces</groupId>
+ <artifactId>xercesImpl</artifactId>
+ <version>2.8.1</version>
+ <exclusions>
+ <exclusion>
+ <groupId>xml-apis</groupId>
+ <artifactId>xml-apis</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.xmlbeans</groupId>
+ <artifactId>xmlbeans</artifactId>
+ <version>2.3.0</version>
+ <exclusions>
+ <exclusion>
+ <groupId>stax</groupId>
+ <artifactId>stax-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>net.sourceforge.saxon</groupId>
+ <artifactId>saxon</artifactId>
+ <version>9.1.0.8</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sourceforge.saxon</groupId>
+ <artifactId>saxon</artifactId>
+ <classifier>dom</classifier>
+ <version>9.1.0.8</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sourceforge.saxon</groupId>
+ <artifactId>saxon</artifactId>
+ <classifier>xpath</classifier>
+ <version>9.1.0.8</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sourceforge.saxon</groupId>
+ <artifactId>saxon</artifactId>
+ <classifier>xqj</classifier>
+ <version>9.1.0.8</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ <version>1.3</version>
+ <exclusions>
+ <exclusion>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.15</version>
+ <exclusions>
+ <exclusion>
+ <groupId>com.sun.jdmk</groupId>
+ <artifactId>jmxtools</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>com.sun.jmx</groupId>
+ <artifactId>jmxri</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>javax.jms</groupId>
+ <artifactId>jms</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>javax.mail</groupId>
+ <artifactId>mail</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <!-- Explicitly add slf4j so that ODE uses the latest versions -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.6.1</version>
+ <scope>runtime</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-jdk14</artifactId>
+ <version>1.6.1</version>
+ <scope>runtime</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>unpack</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>unpack</goal>
+ </goals>
+ <configuration>
+ <artifactItems>
+ <artifactItem>
+ <groupId>org.apache.ode</groupId>
+ <artifactId>ode-dao-jpa-ojpa-derby</artifactId>
+ <version>1.3.2</version>
+ <type>zip</type>
+ <overWrite>true</overWrite>
+ <outputDirectory>${project.build.directory}/test-classes/
+ </outputDirectory>
+ </artifactItem>
+ </artifactItems>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ </plugins>
+ </build>
+</project>
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/BPELODEDeployFile.java b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/BPELODEDeployFile.java
new file mode 100644
index 0000000000..fe1e2d620b
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/BPELODEDeployFile.java
@@ -0,0 +1,233 @@
+/*
+ * 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.bpel.ode;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.net.URI;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+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.implementation.bpel.BPELImplementation;
+
+/**
+ * A class that handles the deploy.xml file required for each BPEL process by the ODE runtime
+ * @author Mike Edwards
+ *
+ * An explanation of the structure of the ODE deploy file:
+ *
+ * <deploy xmlns="http://www.apache.org/ode/schemas/dd/2007/03"
+ * xmlns:tns="http://helloworld"
+ * xmlns:tus="http://tuscany.apache.org/xmlns/sca/1.1">
+ *
+ * <process name="tns:HelloWorld">
+ * <active>true</active>
+ * <provide partnerLink="helloPartnerLink">
+ * <service name="tus:helloPartnerLink" port="HelloWorld"/>
+ * </provide>
+ * <invoke partnerLink="greetingsPartnerLink">
+ * <service name="tus:greetingsPartnerLink" port="Greetings"/>
+ * </invoke>
+ * </process>
+ * </deploy>
+ *
+ * For SCA purposes:
+ *
+ * a) Each partner link in the BPEL process is declared using either a <provide.../>
+ * (for a service) or using a <invoke.../> (for a reference).
+ *
+ * b) Each <provide/> and <invoke/> must use the partnerLink name, as declared in the
+ * BPEL process.
+ *
+ * c) The <provide/> and <invoke/> elements each have a single child <service/> element.
+ * The <service/> elements have name and port attributes. The NAME attribute MUST be set
+ * to the same name as the partnerLink and MUST be prefixed by a prefix which references
+ * the namespace "http://tuscany.apache.org" ("tus" in the example above).
+ * The port attribute can be set to any name (it must be present but it is not actually
+ * used for anything significant).
+ *
+ * When SCA loads a BPEL process to the ODE server, this file is read by the ODE server to
+ * characterize the process. When SCA interacts with ODE at later points - either when a
+ * service is being invoked or the process invokes a reference - it is the service @name
+ * attribute that identifies the service or reference involved.
+ *
+ * @version
+ */
+public class BPELODEDeployFile {
+ private final Log __log = LogFactory.getLog(getClass());
+
+ static final String DEPLOY_ELEMENT_START = "<deploy xmlns=\"http://www.apache.org/ode/schemas/dd/2007/03\"";
+ static final String DEPLOY_ENDELEMENT = "</deploy>";
+ static final String PROCESS_NAMESPACE_DECL = "xmlns:tns=";
+ static final String SERVICE_NAMESPACE = "xmlns:tus=\"http://tuscany.apache.org\"";
+ static final String PROCESS_ELEMENT_START = "<process name=\"tns:";
+ static final String PROCESS_ELEMENT_END = "\">";
+ static final String PROCESS_ENDELEMENT = "</process>";
+ static final String ACTIVE_ELEMENT = "<active>true</active>";
+ static final String PROVIDE_ELEMENT_START = "<provide partnerLink=\"";
+ static final String PROVIDE_ELEMENT_END = "\">";
+ static final String PROVIDE_ENDELEMENT = "</provide>";
+ static final String SERVICE_ELEMENT_START = "<service name=\"tus:";
+ static final String SERVICE_ELEMENT_PORT = "\" port=\"";
+ static final String SERVICE_ELEMENT_END = "Port\"/>";
+ static final String INVOKE_ELEMENT_START = "<invoke partnerLink=\"";
+ static final String INVOKE_ELEMENT_END = "\">";
+ static final String INVOKE_ENDELEMENT = "</invoke>";
+
+ static final String DEPLOY_FILENAME = "deploy.xml";
+
+ private BPELImplementation implementation;
+
+ /**
+ * Constructor - requires a BPELImplementation as a parameter
+ * The ODE deploy.xml file is for this supplied BPELImplementation
+ * @param theImplementation
+ */
+ public BPELODEDeployFile( BPELImplementation theImplementation ) {
+
+ implementation = theImplementation;
+
+ } // end BPELODEDeployFile constructor
+
+ /**
+ * Writes the deploy file into the same directory as the BPEL process file, with the name
+ * "deploy.xml"
+ */
+ public void writeDeployfile() throws IOException {
+
+ File theDirectory = getDirectory();
+
+ File deployFile = new File( theDirectory, DEPLOY_FILENAME );
+ new FileOutputStream( deployFile );
+ //if( !deployFile.canWrite() ) throw new IOException( "Unable to write to deploy file" +
+ // deployFile.getPath() );
+
+ // Create a stream for the data and write the data to the file
+ PrintStream theStream = new PrintStream( new FileOutputStream( deployFile ) );
+ try {
+ constructDeployXML( theStream );
+ if( theStream.checkError() ) throw new IOException();
+ } catch (Exception e) {
+ throw new IOException( "Unable to write data to deploy file" +
+ deployFile.getPath() );
+ } finally {
+ theStream.close();
+ } // end try
+
+ } // end writeDeployFile
+
+ /**
+ * Creates the deploy.xml data and writes it to a supplied PrintStream
+ * @param stream
+ */
+ public void constructDeployXML( PrintStream stream ) {
+
+ // <deploy + namespace...
+ stream.println( DEPLOY_ELEMENT_START );
+ // namespace of the BPEL process
+ QName process = implementation.getProcess();
+ String processNamespace = process.getNamespaceURI();
+ stream.println( PROCESS_NAMESPACE_DECL + "\"" + processNamespace + "\"" );
+ // namespace for the service name elements
+ stream.println( SERVICE_NAMESPACE + ">" );
+
+ // <process> element
+ stream.println( PROCESS_ELEMENT_START + process.getLocalPart() +
+ PROCESS_ELEMENT_END );
+
+ // <active/> element
+ stream.println( ACTIVE_ELEMENT );
+
+ ComponentType componentType = implementation.getComponentType();
+ List<Service> theServices = componentType.getServices();
+ // Loop over the <provide/> elements - one per service
+ for ( Service service : theServices ) {
+ String serviceName = service.getName();
+ // Provide element...
+ stream.println( PROVIDE_ELEMENT_START + serviceName + PROVIDE_ELEMENT_END );
+ // Child service element...
+ stream.println( SERVICE_ELEMENT_START + serviceName +
+ SERVICE_ELEMENT_PORT + serviceName + SERVICE_ELEMENT_END );
+ stream.println( PROVIDE_ENDELEMENT );
+ } // end for
+
+ // Loop over the <invoke/> elements - one per reference
+ List<Reference> theReferences = componentType.getReferences();
+ for ( Reference reference : theReferences ) {
+ String referenceName = reference.getName();
+ stream.println( INVOKE_ELEMENT_START + referenceName + INVOKE_ELEMENT_END );
+ // Child service element...
+ stream.println( SERVICE_ELEMENT_START + referenceName +
+ SERVICE_ELEMENT_PORT + referenceName + SERVICE_ELEMENT_END );
+ stream.println( INVOKE_ENDELEMENT );
+
+ } // end for
+
+ // </process> element
+ stream.println( PROCESS_ENDELEMENT );
+
+ // </deploy>
+ stream.println( DEPLOY_ENDELEMENT );
+
+ } // end constructDeployXML
+
+ /**
+ * Gets the directory containing the BPEL process
+ * @return
+ */
+ private File getDirectory() {
+ File theDir = getBPELFile().getParentFile();
+ return theDir;
+ } // end getDirectory
+
+ /**
+ * Gets the File containing the BPEL process definition
+ * @return - the File object containing the BPEL process
+ */
+ private File getBPELFile() {
+ try {
+ String location = this.implementation.getProcessDefinition().getLocation();
+ URI locationURI;
+ if (location.indexOf('%') != -1) {
+ locationURI = URI.create(location);
+ } else {
+ locationURI = new URI(null, location, null);
+ }
+
+ File theProcess = new File(locationURI);
+ return theProcess;
+ } catch( Exception e ) {
+ if(__log.isDebugEnabled()) {
+ __log.debug("Exception converting BPEL file URL to an URI: " + e );
+ }
+ } // end try
+ return null;
+ } // end getBPELFile
+
+
+
+} // end class BPELODEDeployFile
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/DeploymentWorkspace.java b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/DeploymentWorkspace.java
new file mode 100644
index 0000000000..8553574aa9
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/DeploymentWorkspace.java
@@ -0,0 +1,233 @@
+/*
+ * 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.bpel.ode;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.UUID;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.tuscany.sca.implementation.bpel.BPELImplementation;
+
+/**
+ *
+ */
+public class DeploymentWorkspace {
+ private static final Logger logger = Logger.getLogger(DeploymentWorkspace.class.getName());
+
+ static final String DEPLOY_FILENAME = "deploy.xml";
+
+ private BPELImplementation implementation;
+ private File workingDir;
+ private File bpelFile;
+
+ /**
+ * @param implementation
+ */
+ public DeploymentWorkspace(BPELImplementation implementation) {
+ super();
+ this.implementation = implementation;
+ this.workingDir = createWorkingDirectory();
+ }
+
+ /**
+ * @param implementation
+ */
+ public DeploymentWorkspace(BPELImplementation implementation, File workingDir) {
+ super();
+ this.implementation = implementation;
+ this.workingDir = workingDir;
+ if (this.workingDir == null) {
+ this.workingDir = createWorkingDirectory();
+ }
+ }
+
+ public File getCBPFile() throws IOException {
+ String name = getBPELFile().getName();
+ int index = name.lastIndexOf('.');
+ if (index != -1) {
+ name = name.substring(0, index);
+ }
+ return new File(workingDir, name + ".cbp");
+ }
+
+ public synchronized File getBPELFile() throws IOException {
+ if (bpelFile != null) {
+ String location = implementation.getProcessDefinition().getLocation();
+ String fileName = implementation.getProcessDefinition().getURI();
+ File file = new File(workingDir, fileName);
+ if (file.isFile()) {
+ bpelFile = file;
+ return file;
+ }
+ URL url = new URL(location);
+ this.bpelFile = copy(url, workingDir, fileName);
+ }
+ return bpelFile;
+ }
+
+ /**
+ * Escape the space in URL string
+ * @param uri
+ * @return
+ */
+ public static URI createURI(String uri) {
+ if (uri == null) {
+ return null;
+ }
+ if (uri.indexOf('%') != -1) {
+ // Avoid double-escaping
+ return URI.create(uri);
+ }
+ int index = uri.indexOf(':');
+ String scheme = null;
+ String ssp = uri;
+ if (index != -1) {
+ scheme = uri.substring(0, index);
+ ssp = uri.substring(index + 1);
+ }
+ try {
+ return new URI(scheme, ssp, null);
+ } catch (URISyntaxException e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+
+ /**
+ * Gets the File containing the BPEL process definition
+ * @return - the File object containing the BPEL process
+ */
+ private static File getContainer(String location) {
+ try {
+ File theProcess = null;
+ URI locationURI = createURI(location);
+ String protocol = locationURI.getScheme();
+ if ("file".equals(protocol)) {
+ theProcess = new File(locationURI);
+ } else if ("jar".equals(protocol) || "wsjar".equals(protocol) || "zip".equals(protocol)) {
+ String uri = locationURI.toString();
+ // jar contribution
+ uri = uri.substring(protocol.length() + 1, uri.lastIndexOf("!/"));
+ locationURI = createURI(uri);
+ if ("file".equals(locationURI.getScheme())) {
+ theProcess = new File(locationURI);
+ }
+ }
+ return theProcess;
+ } catch (Exception e) {
+ logger.log(Level.SEVERE, "Exception converting BPEL file URL to an URI: " + location, e);
+ } // end try
+ return null;
+ } // end getBPELFile
+
+ /**
+ * Gets the directory containing the BPEL process
+ * @return
+ */
+ static File getDirectory(String location) {
+ File file = getContainer(location);
+ if (file == null) {
+ return null;
+ }
+ File theDir = file.getParentFile();
+ return theDir;
+ } // end getDirectory
+
+ public File getDeployFile() {
+ return new File(workingDir, DEPLOY_FILENAME);
+ }
+
+ private static String getSystemProperty(final String name) {
+ return AccessController.doPrivileged(new PrivilegedAction<String>() {
+ public String run() {
+ return System.getProperty(name);
+ }
+ });
+ }
+
+ private File createWorkingDirectory() {
+ String tmpDir = getSystemProperty("java.io.tmpdir");
+ File root = new File(tmpDir);
+ // Add user name as the prefix. For multiple users on the same Lunix,
+ // there will be permission issue if one user creates the .tuscany folder
+ // first under /tmp with no write permission for others.
+ String userName = getSystemProperty("user.name");
+ if (userName != null) {
+ root = new File(root, userName);
+ }
+ root = new File(root, ".tuscany/bpel/" + UUID.randomUUID().toString());
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("BPEL working directory: " + root);
+ }
+ return root;
+ }
+
+ public static File copy(URL url, File directory, String fileName) throws IOException {
+ File file = new File(directory, fileName);
+ file.getParentFile().mkdirs();
+ FileOutputStream os = new FileOutputStream(file);
+ URLConnection connection = url.openConnection();
+ connection.setUseCaches(false);
+ InputStream is = connection.getInputStream();
+ byte[] buf = new byte[8192];
+ while (true) {
+ int size = is.read(buf);
+ if (size < 0)
+ break;
+ os.write(buf, 0, size);
+ }
+ is.close();
+ os.close();
+ return file;
+ }
+
+ private static boolean deleteFiles(File file) {
+ boolean result = true;
+ if (file.isFile()) {
+ if (!file.delete()) {
+ result = false;
+ }
+ } else if (file.isDirectory()) {
+ for (File f : file.listFiles()) {
+ if (!deleteFiles(f)) {
+ result = false;
+ }
+ }
+ if (!file.delete()) {
+ result = false;
+ }
+ }
+ return result;
+ }
+
+ public boolean delete() {
+ return deleteFiles(workingDir);
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/EmbeddedODEServer.java b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/EmbeddedODEServer.java
new file mode 100644
index 0000000000..939c33c21c
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/EmbeddedODEServer.java
@@ -0,0 +1,563 @@
+/*
+ * 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.bpel.ode;
+
+import java.io.File;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.locks.Condition;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+import javax.transaction.TransactionManager;
+import javax.xml.namespace.QName;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ode.bpel.dao.BpelDAOConnectionFactoryJDBC;
+import org.apache.ode.bpel.engine.BpelServerImpl;
+import org.apache.ode.bpel.engine.CountLRUDehydrationPolicy;
+import org.apache.ode.bpel.evt.BpelEvent;
+import org.apache.ode.bpel.evt.CorrelationMatchEvent;
+import org.apache.ode.bpel.evt.NewProcessInstanceEvent;
+import org.apache.ode.bpel.evt.ProcessMessageExchangeEvent;
+import org.apache.ode.bpel.iapi.BpelEventListener;
+import org.apache.ode.bpel.iapi.Scheduler;
+import org.apache.ode.bpel.memdao.BpelDAOConnectionFactoryImpl;
+import org.apache.ode.il.config.OdeConfigProperties;
+import org.apache.ode.il.dbutil.Database;
+import org.apache.ode.scheduler.simple.JdbcDelegate;
+import org.apache.ode.scheduler.simple.SimpleScheduler;
+import org.apache.ode.utils.GUID;
+import org.apache.tuscany.sca.assembly.EndpointReference;
+import org.apache.tuscany.sca.implementation.bpel.BPELImplementation;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.eclipse.core.runtime.FileLocator;
+
+
+
+/**
+ * Embedded ODE process server
+ *
+ * @version $Rev$ $Date$
+ */
+public class EmbeddedODEServer {
+ private static final String TUSCANY_IMPL_BPEL_DBLOCATION = "TUSCANY_IMPL_BPEL_DBLOCATION";
+
+ protected final Log __log = LogFactory.getLog(getClass());
+
+ private boolean _initialized;
+
+ private OdeConfigProperties _config;
+
+ private TransactionManager _txMgr;
+
+ private Database _db;
+
+ private File _workRoot;
+
+ private BpelDAOConnectionFactoryJDBC _daoCF;
+
+ private BpelServerImpl _bpelServer;
+
+ private Scheduler _scheduler;
+
+ protected ExecutorService _executorService;
+
+ private Map<QName, RuntimeComponent> tuscanyRuntimeComponents = new ConcurrentHashMap<QName, RuntimeComponent>();
+
+ private Map<String, Long> mexToProcessMap = new ConcurrentHashMap<String, Long>();
+
+ private Map<Long, Map<String, EndpointReference>> callbackMap = new ConcurrentHashMap<Long, Map<String, EndpointReference>>();
+
+ private final Lock metadataLock = new ReentrantLock();
+ private final Condition mexAdded = metadataLock.newCondition();
+ private final Condition callbackAdded = metadataLock.newCondition();
+
+ public EmbeddedODEServer(TransactionManager txMgr) {
+ _txMgr = txMgr;
+ }
+
+ public void init() throws ODEInitializationException {
+
+ Properties p = System.getProperties();
+ p.put("derby.system.home", "target");
+
+ Properties confProps = new Properties();
+ confProps.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=false)");
+
+ _config = new OdeConfigProperties(confProps, "ode-sca");
+
+ // Setting work root as the directory containing our database
+ try {
+ _workRoot = getDatabaseLocationAsFile();
+ } catch (URISyntaxException e) {
+ throw new ODEInitializationException(e);
+ }
+
+ initTxMgr();
+ initPersistence();
+ initBpelServer();
+
+ try {
+ _bpelServer.start();
+ } catch (Exception ex) {
+ String errmsg = "An error occured during the ODE BPEL server startup.";
+ __log.error(errmsg, ex);
+ throw new ODEInitializationException(errmsg, ex);
+ }
+
+ // Start ODE scheduler
+ _scheduler.start();
+
+ __log.info("ODE BPEL server started.");
+ _initialized = true;
+
+ } // end method init()
+
+ /**
+ * Gets the location of the database used for the ODE BPEL engine as a File object for
+ * the directory containing the database
+ * @return
+ * @throws ODEInitializationException
+ * @throws URISyntaxException
+ */
+ private File getDatabaseLocationAsFile() throws ODEInitializationException, URISyntaxException {
+ File locationFile = null;
+ URL dbLocation = null;
+
+ // An environment variable to set the path to the DB
+ String dbFile = System.getenv(TUSCANY_IMPL_BPEL_DBLOCATION);
+ if( dbFile != null ) {
+ try {
+ locationFile = new File(dbFile).getParentFile();
+ } catch (Exception e ) {
+ System.out.println("Environment variable " + TUSCANY_IMPL_BPEL_DBLOCATION + " has the wrong format: " + dbFile);
+ System.out.println("Exception is: " + e.getClass().toString() + " " + e.getMessage());
+ } // end try
+ } else {
+ dbLocation = getClass().getClassLoader().getResource("jpadb");
+ if (dbLocation == null) {
+ throw new ODEInitializationException("Couldn't find database in the classpath:" +
+ " try setting the " + TUSCANY_IMPL_BPEL_DBLOCATION + " environment variable");
+ }
+ // Handle OSGI bundle case
+ if( dbLocation.getProtocol() == "bundleresource" ) {
+ try {
+ dbLocation = FileLocator.toFileURL( dbLocation );
+ } catch (Exception ce ) {
+ throw new ODEInitializationException("Couldn't find database in the OSGi bundle");
+ } // end try
+ } // end if
+ locationFile = new File(dbLocation.toURI()).getParentFile();
+ } // end if
+
+ return locationFile;
+ } // end method getDatabaseLocationAsFile
+
+ private void initTxMgr() {
+ if(_txMgr == null) {
+ try {
+ GeronimoTxFactory txFactory = new GeronimoTxFactory();
+ _txMgr = txFactory.getTransactionManager();
+ } catch (Exception e) {
+ __log.fatal("Couldn't initialize a transaction manager using Geronimo's transaction factory.", e);
+ throw new ODEInitializationException("Couldn't initialize a transaction manager using " + "Geronimo's transaction factory.", e);
+ }
+ }
+ }
+
+ private void initPersistence() {
+ _db = new Database(_config);
+ _db.setTransactionManager(_txMgr);
+ _db.setWorkRoot(_workRoot);
+
+ try {
+ _db.start();
+ _daoCF = _db.createDaoCF();
+ } catch (Exception ex) {
+ String errmsg = "Error while configuring ODE persistence.";
+ __log.error(errmsg, ex);
+ throw new ODEInitializationException(errmsg, ex);
+ }
+ }
+
+ private void initBpelServer() {
+ if (__log.isDebugEnabled()) {
+ __log.debug("ODE initializing");
+ }
+ ThreadFactory threadFactory = new ThreadFactory() {
+ int threadNumber = 0;
+ public Thread newThread(Runnable r) {
+ threadNumber += 1;
+ Thread t = new Thread(r, "ODEServer-"+threadNumber);
+ t.setDaemon(true);
+ return t;
+ }
+ };
+
+ _executorService = Executors.newCachedThreadPool(threadFactory);
+
+ // executor service for long running bulk transactions
+ ExecutorService _polledRunnableExecutorService = Executors.newCachedThreadPool(new ThreadFactory() {
+ int threadNumber = 0;
+ public Thread newThread(Runnable r) {
+ threadNumber += 1;
+ Thread t = new Thread(r, "PolledRunnable-"+threadNumber);
+ t.setDaemon(true);
+ return t;
+ }
+ });
+
+ _bpelServer = new BpelServerImpl();
+ _scheduler = createScheduler();
+ _scheduler.setJobProcessor(_bpelServer);
+
+ BpelServerImpl.PolledRunnableProcessor polledRunnableProcessor = new BpelServerImpl.PolledRunnableProcessor();
+ polledRunnableProcessor.setPolledRunnableExecutorService(_polledRunnableExecutorService);
+ polledRunnableProcessor.setContexts(_bpelServer.getContexts());
+ //_scheduler.setPolledRunnableProcesser(polledRunnableProcessor);
+
+ _bpelServer.setDaoConnectionFactory(_daoCF);
+ _bpelServer.setInMemDaoConnectionFactory(new BpelDAOConnectionFactoryImpl(_scheduler));
+
+ _bpelServer.setEndpointReferenceContext( new ODEEprContext() );
+ _bpelServer.setMessageExchangeContext(new ODEMessageExchangeContext(this));
+ _bpelServer.setBindingContext(new ODEBindingContext());
+ _bpelServer.setScheduler(_scheduler);
+ if (_config.isDehydrationEnabled()) {
+ CountLRUDehydrationPolicy dehy = new CountLRUDehydrationPolicy();
+ dehy.setProcessMaxAge(_config.getDehydrationMaximumAge());
+ dehy.setProcessMaxCount(_config.getDehydrationMaximumCount());
+ _bpelServer.setDehydrationPolicy(dehy);
+ }
+
+ _bpelServer.setConfigProperties(_config.getProperties());
+ _bpelServer.init();
+ _bpelServer.setInstanceThrottledMaximumCount(_config.getInstanceThrottledMaximumCount());
+ _bpelServer.setProcessThrottledMaximumCount(_config.getProcessThrottledMaximumCount());
+ _bpelServer.setProcessThrottledMaximumSize(_config.getProcessThrottledMaximumSize());
+ _bpelServer.setHydrationLazy(_config.isHydrationLazy());
+ _bpelServer.setHydrationLazyMinimumSize(_config.getHydrationLazyMinimumSize());
+
+ // Register event listener on the BPEL server
+ _bpelServer.registerBpelEventListener( new ODEEventListener( this, _bpelServer) );
+ } // end method initBpelLServer
+
+ public void stop() throws ODEShutdownException {
+ if(_bpelServer != null) {
+ try {
+ __log.debug("Stopping BPEL Embedded server");
+ _bpelServer.shutdown();
+ _bpelServer = null;
+ } catch (Exception ex) {
+ __log.debug("Error stopping BPEL server");
+ }
+ }
+
+ if(_scheduler != null) {
+ try {
+ __log.debug("Stopping scheduler");
+ _scheduler.shutdown();
+ _scheduler = null;
+ } catch (Exception ex) {
+ __log.debug("Error stopping scheduler");
+ }
+ }
+
+ if(_daoCF != null) {
+ try {
+ __log.debug("Stopping DAO");
+ _daoCF.shutdown();
+ _daoCF = null;
+ } catch (Exception ex) {
+ __log.debug("Error stopping DAO");
+ }
+ }
+
+ if(_db != null) {
+ try {
+ __log.debug("Stopping DB");
+ _db.shutdown();
+ _db = null;
+ } catch (Exception ex) {
+ __log.debug("Error stopping DB");
+ }
+ }
+
+ if(_txMgr != null) {
+ try {
+ __log.debug("Stopping Transaction Manager");
+ _txMgr = null;
+ } catch (Exception ex) {
+ __log.debug("Error stopping Transaction Manager");
+ }
+ }
+ }
+
+ protected Scheduler createScheduler() {
+ Properties odeProperties = new Properties();
+ // TODO Find correct values for these properties - MJE 22/06/2009
+ odeProperties.put("ode.scheduler.queueLength", "100" );
+ odeProperties.put("ode.scheduler.immediateInterval", "30000" );
+ odeProperties.put("ode.scheduler.nearFutureInterval", "600000" );
+ odeProperties.put("ode.scheduler.staleInterval", "100000" );
+
+ SimpleScheduler scheduler = new SimpleScheduler(new GUID().toString(),
+ new JdbcDelegate(_db.getDataSource()),
+ odeProperties );
+ scheduler.setExecutorService(_executorService);
+ scheduler.setTransactionManager(_txMgr);
+
+ return scheduler;
+ }
+
+ public boolean isInitialized() {
+ return _initialized;
+ }
+
+ public BpelServerImpl getBpelServer() {
+ return _bpelServer;
+ }
+
+ public Scheduler getScheduler() {
+ return _scheduler;
+ }
+
+ public ExecutorService getExecutor() {
+ return _executorService;
+ }
+
+ /**
+ * Deploy the BPEL process implementation to the ODE Engine
+ * @param d - ODEDeployment structure
+ * @param implementation - the BPEL Implementation
+ * @param component - the SCA component which uses the implementation
+ */
+ public void deploy(ODEDeployment d, BPELImplementation implementation, RuntimeComponent component ) {
+ try {
+ TuscanyProcessConfImpl processConf = new TuscanyProcessConfImpl( implementation, component );
+ _bpelServer.register(processConf);
+ d.setProcessConf(processConf);
+ __log.debug("Completed calling new Process deployment code...");
+ } catch (Exception ex) {
+ String errMsg = ">>> DEPLOY: Unexpected exception during deploy of BPEL. /n Component = "
+ + component.getName()
+ + " implementation = "
+ + implementation.getProcess()
+ + ex.getMessage();
+ __log.debug(errMsg, ex);
+ throw new ODEDeploymentException(errMsg,ex);
+ }
+ }
+
+ /**
+ * Undeploy the BPEL process implementation from the ODE Engine
+ * @param d - ODEDeployment structure
+ */
+ public void undeploy(ODEDeployment d) {
+ TuscanyProcessConfImpl processConf = d.getProcessConf();
+ if( processConf != null ) {
+ processConf.stop();
+ } // end if
+ } // end method undeploy
+
+ public void registerTuscanyRuntimeComponent(QName processName,RuntimeComponent componentContext) {
+ tuscanyRuntimeComponents.put(processName, componentContext);
+ }
+
+ public RuntimeComponent getTuscanyRuntimeComponent(QName processName) {
+ return tuscanyRuntimeComponents.get(processName);
+ }
+
+ /**
+ * Records a connection between a MessageExchange ID and a Process Instance ID
+ * @param mexID
+ * @param processID
+ */
+ public void addMexToProcessIDLink( String mexID, Long processID ) {
+ //System.out.println("Add mapping Mex - ProcessID = " + mexID + " " + processID.toString());
+ if( mexID == null ) {
+ //System.out.println("Mex ID is null !");
+ return;
+ } // end if
+ metadataLock.lock();
+ try {
+ mexToProcessMap.put(mexID, processID);
+ mexAdded.signalAll();
+ return;
+ } catch (Exception e) {
+ return;
+ } finally {
+ metadataLock.unlock();
+ } // end try
+ } // end method addMexToProcessIDLink( mexID, processID )
+
+ /**
+ * Connects from a MessageExchangeID to a Process Instance ID
+ * @param mexID - the MessageExchange ID
+ * @return - a Long which is the Process Instance ID
+ */
+ public Long getProcessIDFromMex( String mexID ) {
+ //System.out.println("Get mapping for Mex: " + mexID);
+ metadataLock.lock();
+ try {
+ Long processID = mexToProcessMap.get(mexID);
+ while( processID == null ) {
+ mexAdded.await();
+ processID = mexToProcessMap.get(mexID);
+ } // end while
+ return processID;
+ } catch (Exception e) {
+ return null;
+ } finally {
+ metadataLock.unlock();
+ } // end try
+
+ } // end method getProcessIDFromMex
+
+ /**
+ * Remove the connection between a Message Exchange ID and a Process Instance ID
+ * @param mexID - the Message Exchange ID
+ */
+ public void removeMexToProcessIDLink( String mexID ) {
+ mexToProcessMap.remove(mexID);
+ } // end method removeMexToProcessIDLink
+
+ /**
+ * Stores the metadata for a Callback
+ * @param processID - Process ID of the BPEL Process Instance for which this callback applies
+ * @param serviceName - the name of the service which has the callback
+ * @param callbackEndpoint - a Tuscany Endpoint which is the target of the callback
+ */
+ public void saveCallbackMetadata( Long processID, String serviceName, EndpointReference callbackEPR ) {
+ //System.out.println("Save callback metadata: ProcessID " + processID.toString() + " service: " + serviceName);
+ metadataLock.lock();
+ try {
+ Map<String, EndpointReference> processMap = callbackMap.get(processID);
+ if( processMap == null ) {
+ processMap = new ConcurrentHashMap<String, EndpointReference>();
+ callbackMap.put(processID, processMap);
+ } // end if
+ // Put the mapping of service name to callback endpoint - note that this overwrites any
+ // previous mapping for the same service name
+ processMap.put(serviceName, callbackEPR);
+ callbackAdded.signalAll();
+ } finally {
+ metadataLock.unlock();
+ } // end try
+ } // end saveCallbackMetadata
+
+ /**
+ * Get the metadata for a Callback, based on a BPEL Process Instance ID and a Service name
+ * @param processID - the BPEL Process Instance ID
+ * @param serviceName - the service name
+ * @return - and Endpoint which is the Callback endpoint for the service for this process instance.
+ * Returns null if there is no callback metadata for this service.
+ */
+ public EndpointReference getCallbackMetadata( Long processID, String serviceName ) {
+ EndpointReference theEPR;
+ //System.out.println("Get callback metadata: ProcessID " + processID.toString() + " service: " + serviceName);
+
+ metadataLock.lock();
+ try {
+ while(true) {
+ Map<String, EndpointReference> processMap = callbackMap.get(processID);
+ theEPR = processMap.get(serviceName);
+ if( theEPR != null ) return theEPR;
+ callbackAdded.await();
+ } // end while
+ } catch (Exception e) {
+ return null;
+ } finally {
+ metadataLock.unlock();
+ } // end try
+ } // end method getCallbackMetadata
+
+ /**
+ * Removes the metadata for a Callback
+ * @param processID - the Process Instance ID of the process instance to which the callback metadata applies
+ * @param serviceName - the service name for the service which has a callback - can be NULL, in which case ALL
+ * callback metadata for the process instance is removed
+ */
+ public void removeCallbackMetadata( Long processID, String serviceName ) {
+
+ if( serviceName == null ) {
+ callbackMap.remove(processID);
+ } else {
+ Map<String, EndpointReference> processMap = callbackMap.get(processID);
+ processMap.remove(serviceName);
+ } // end if
+
+ } // end method removeCallbackMetadata
+
+ private class ODEEventListener implements BpelEventListener {
+
+ private EmbeddedODEServer ODEServer;
+ private BpelServerImpl bpelServer;
+
+ ODEEventListener( EmbeddedODEServer ODEServer, BpelServerImpl bpelServer ) {
+ this.ODEServer = ODEServer;
+ this.bpelServer = bpelServer;
+ } // end constructor
+
+ /**
+ * Method which receives events from the ODE Engine as processing proceeds
+ */
+ public void onEvent(BpelEvent bpelEvent) {
+ if( bpelEvent instanceof ProcessMessageExchangeEvent ||
+ bpelEvent instanceof NewProcessInstanceEvent ||
+ bpelEvent instanceof CorrelationMatchEvent ) {
+ handleProcMexEvent( (ProcessMessageExchangeEvent) bpelEvent );
+ return;
+ } // end if
+
+ } // end method onEvent
+
+ /**
+ * Handle a ProcessMessageExchangeEvent
+ * - the important aspect of this event is that it establishes a connection between a MessageExchange object
+ * and the BPEL Process instance to which it relates.
+ * @param bpelEvent - the ProcessMessageExchangeEvent
+ */
+ private void handleProcMexEvent( ProcessMessageExchangeEvent bpelEvent) {
+ // Extract the message ID and the process instance ID - it is the connection between these
+ // that is vital to know
+ String mexID = bpelEvent.getMessageExchangeId();
+ Long processID = bpelEvent.getProcessInstanceId();
+ ODEServer.addMexToProcessIDLink( mexID, processID );
+ } // end method handleProcMexEvent
+
+ public void shutdown() {
+ // Intentionally left blank
+ }
+
+ public void startup(Properties configProperties) {
+ // Intentionally left blank
+ }
+
+ } // end Class BPELEventListener
+}
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/GeronimoTxFactory.java b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/GeronimoTxFactory.java
new file mode 100644
index 0000000000..11af0f8b50
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/GeronimoTxFactory.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.bpel.ode;
+
+import javax.transaction.TransactionManager;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Geronimo transaction factory
+ *
+ * @version $Rev$ $Date$
+ */
+public class GeronimoTxFactory {
+ private static final Log __log = LogFactory.getLog(GeronimoTxFactory.class);
+
+ /* Public no-arg constructor is required */
+ public GeronimoTxFactory() {
+ }
+
+ public TransactionManager getTransactionManager() {
+ __log.info("Using embedded Geronimo transaction manager");
+ try {
+ Object obj = new org.apache.geronimo.transaction.manager.GeronimoTransactionManager();
+ return (TransactionManager) obj;
+ } catch (Exception except) {
+ throw new IllegalStateException("Unable to instantiate Geronimo Transaction Manager", except);
+ }
+ }
+}
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEBindingContext.java b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEBindingContext.java
new file mode 100644
index 0000000000..8e339812cd
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEBindingContext.java
@@ -0,0 +1,91 @@
+/*
+ * 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.bpel.ode;
+
+import javax.wsdl.PortType;
+import javax.xml.namespace.QName;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ode.bpel.iapi.BindingContext;
+import org.apache.ode.bpel.iapi.Endpoint;
+import org.apache.ode.bpel.iapi.EndpointReference;
+import org.apache.ode.bpel.iapi.PartnerRoleChannel;
+
+/**
+ * Binding Context information
+ *
+ * @version $Rev$ $Date$
+ */
+public class ODEBindingContext implements BindingContext {
+ protected final Log __log = LogFactory.getLog(getClass());
+
+ public ODEBindingContext() {
+
+ }
+
+ public EndpointReference activateMyRoleEndpoint(QName pid, Endpoint endpoint) {
+ // This will be needed when we support callBacks
+ if (__log.isDebugEnabled()) {
+ __log.debug("Activating MyRole Endpoint : " + pid + " - " + endpoint.serviceName);
+ }
+
+ QName processName = getProcessName(pid);
+
+ return new TuscanyEPR(processName, endpoint);
+ }
+
+ public void deactivateMyRoleEndpoint(Endpoint endpoint) {
+ if (__log.isDebugEnabled()) {
+ __log.debug("Deactivate MyRole Endpoint : " + endpoint.serviceName);
+ }
+
+ }
+
+ public PartnerRoleChannel createPartnerRoleChannel(QName pid, PortType portType, Endpoint endpoint) {
+ if (__log.isDebugEnabled()) {
+ __log.debug("Create PartnerRole channel : " + pid + " - " + portType.getQName() + " - "+ endpoint.serviceName);
+ }
+
+ QName processName = getProcessName(pid);
+ return new TuscanyPRC(processName, pid, portType, endpoint);
+ }
+
+ /**
+ * Helper method to retrieve the BPEL process name from a processID (where processID have version concatenated to it)
+ * @param pid
+ * @return QName the BPEL process name
+ */
+ private static QName getProcessName(QName pid) {
+ String processName = pid.getLocalPart().substring(0, pid.getLocalPart().lastIndexOf("-"));
+ return new QName(pid.getNamespaceURI(), processName);
+ }
+
+ /**
+ * Calculate the size of the service that this endpoint references.
+ * @param epr the endpoint reference for the service
+ * @returns the size of the service
+ */
+ public long calculateSizeofService(EndpointReference epr) {
+ // TODO It is not at all clear from the ODE code what "size" means
+ // eg number of service operations? size of the process in bytes?
+ // So for the present, return a fixed random value...
+ return 10000;
+ }
+}
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEDeployment.java b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEDeployment.java
new file mode 100644
index 0000000000..0eedd5d0e5
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEDeployment.java
@@ -0,0 +1,55 @@
+/*
+ * 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.bpel.ode;
+
+import java.io.File;
+
+/**
+ * Deployment information
+ *
+ * @version $Rev$ $Date$
+ */
+public class ODEDeployment {
+ /** The directory containing the deploy.xml and artifacts. */
+ public File deployDir;
+
+ // The Tuscany version of the ODE Process Conf implementation
+ private TuscanyProcessConfImpl conf;
+
+ /** If non-null the type of exception we expect to get when we deploy. */
+ public Class<?> expectedException = null;
+
+ public ODEDeployment(File deployDir) {
+ this.deployDir = deployDir;
+ }
+
+ @Override
+ public String toString() {
+ return "Deployment#" + deployDir;
+ }
+
+ public void setProcessConf( TuscanyProcessConfImpl conf ) {
+ this.conf = conf;
+ }
+
+ public TuscanyProcessConfImpl getProcessConf() {
+ return conf;
+ }
+} \ No newline at end of file
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEDeploymentException.java b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEDeploymentException.java
new file mode 100644
index 0000000000..b03f69d9aa
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEDeploymentException.java
@@ -0,0 +1,41 @@
+/*
+ * 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.bpel.ode;
+
+/**
+ * Thrown when ODE failed to shutdown.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ODEDeploymentException extends RuntimeException {
+ private static final long serialVersionUID = -2869674556330744215L;
+
+ public ODEDeploymentException(Throwable cause) {
+ super(cause);
+ }
+
+ public ODEDeploymentException(String message) {
+ super(message);
+ }
+
+ public ODEDeploymentException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEEndpointReference.java b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEEndpointReference.java
new file mode 100644
index 0000000000..700443d9b7
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEEndpointReference.java
@@ -0,0 +1,96 @@
+/*
+ * 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.bpel.ode;
+
+import org.apache.ode.bpel.iapi.Endpoint;
+import org.apache.ode.bpel.iapi.EndpointReference;
+import org.apache.ode.utils.DOMUtils;
+import org.apache.tuscany.sca.assembly.Base;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * Tuscany implementation of the ODE EndpointReference interface
+ *
+ */
+public class ODEEndpointReference implements EndpointReference {
+
+
+ private Document doc = DOMUtils.newDocument();
+ private Element serviceref;
+
+ /**
+ * Private constructor for the EndpointReference
+ */
+ private ODEEndpointReference() {
+ super();
+ } // end ODEEndpointReference()
+
+ /**
+ * Add a new <service-ref/> element to the EndpointReference
+ */
+ private void addServiceRef() {
+ serviceref = doc.createElementNS(EndpointReference.SERVICE_REF_QNAME.getNamespaceURI(),
+ EndpointReference.SERVICE_REF_QNAME.getLocalPart());
+ doc.appendChild(serviceref);
+ } // end method addServiceRef()
+
+ /**
+ * Create an EndpointReference from an Endpoint object
+ * @param anEndpoint - the endpoint object
+ */
+ public ODEEndpointReference( Endpoint anEndpoint ) {
+ this();
+ addServiceRef();
+ // If there is an endpoint for this reference (ie the reference is wired)
+ // then add an element to indicate this
+ String eprCount = anEndpoint.portName;
+ if( !"0".equals(eprCount) ) {
+ Element eprElement = doc.createElementNS( Base.SCA11_TUSCANY_NS, "EPR");
+ serviceref.appendChild(eprElement);
+ } // end if
+ return;
+ } // end
+
+ /**
+ * Create a new EndpointReference from an existing endpointElement, which is assumed
+ * to be of the form:
+ * <sref:service-ref>
+ * <EPR/>
+ * </sref:service-ref>
+ *
+ * @param endpointElement the endpointElement
+ */
+ public ODEEndpointReference( Element endpointElement ) {
+ this();
+ if( endpointElement != null ) {
+ // import the service-ref element into this EndpointReference, if the
+ // root element is a <sref:service-ref/>
+ if( endpointElement.getLocalName().equals("service-ref") ) {
+ doc.appendChild( doc.importNode(endpointElement, true) );
+ } // end if
+ } // end if
+ return;
+ } // end
+
+ public Document toXML() {
+ return doc;
+ } // end toXML()
+
+}
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEEprContext.java b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEEprContext.java
new file mode 100644
index 0000000000..972f77ad65
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEEprContext.java
@@ -0,0 +1,75 @@
+/*
+ * 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.bpel.ode;
+
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.apache.ode.bpel.iapi.EndpointReference;
+import org.apache.ode.bpel.iapi.EndpointReferenceContext;
+import org.w3c.dom.Element;
+
+/**
+ * Implementation of the ODE EndpointReferenceContext interface, used by the ODE BPEL Engine
+ * to handle conversions of EndpointReferences at runtime.
+ *
+ * An ODE Endpoint reference relates to SCA Reference EndpointReferences (pointers to target
+ * services) and to BPEL PartnerLink elements and any associated BPEL process variables with
+ * type set to element="sref:service-ref"
+ *
+ */
+public class ODEEprContext implements EndpointReferenceContext {
+
+ /**
+ * Converts an endpoint reference from its XML representation to another
+ * type of endpoint reference.
+ *
+ * @param targetType
+ * @param sourceEndpoint
+ * @return converted EndpointReference, being of targetType
+ */
+ public EndpointReference convertEndpoint( QName targetType,
+ Element sourceEndpoint) {
+ // For the present, Tuscany only has one type of EndpointReference, so that the
+ // targetType parameter is of no significance.
+ return new ODEEndpointReference( sourceEndpoint );
+ } // end method convertEndpoint
+
+ public Map getConfigLookup(EndpointReference epr) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /**
+ * Resolve an end-point reference from its XML representation. The
+ * nature of the representation is determined by the integration
+ * layer. The BPEL engine uses this method to reconstruct
+ * {@link EndpointReference} objects that have been persisted in the
+ * database via {@link EndpointReference#toXML(javax.xml.transform.Result)}
+ * method.
+ *
+ * @param XML representation of the EPR
+ * @return reconstituted EPR object {@link EndpointReference}
+ */
+ public EndpointReference resolveEndpointReference(Element epr) {
+ return new ODEEndpointReference( epr );
+ } // end method resolveEndpointReference
+
+} // end class ODEEprContext
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEExternalService.java b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEExternalService.java
new file mode 100644
index 0000000000..d2dbd4880d
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEExternalService.java
@@ -0,0 +1,370 @@
+/*
+ * 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.bpel.ode;
+
+import java.util.List;
+import java.util.concurrent.Callable;
+
+import javax.wsdl.Part;
+import javax.xml.namespace.QName;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ode.bpel.iapi.Message;
+import org.apache.ode.bpel.iapi.MessageExchange;
+import org.apache.ode.bpel.iapi.PartnerRoleMessageExchange;
+import org.apache.ode.bpel.iapi.Scheduler;
+import org.apache.ode.utils.DOMUtils;
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.EndpointReference;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * Helper Class to handle invocation to Tuscany Component References
+ *
+ * @version $Rev$ $Date$
+ */
+public class ODEExternalService {
+ protected final Log __log = LogFactory.getLog(getClass());
+
+ private EmbeddedODEServer _server;
+ private Scheduler _sched;
+
+ public ODEExternalService(EmbeddedODEServer server) {
+ this._server = server;
+ this._sched = _server.getScheduler();
+ }
+
+ public void invoke(final PartnerRoleMessageExchange partnerRoleMessageExchange) {
+ boolean isTwoWay =
+ partnerRoleMessageExchange.getMessageExchangePattern() == org.apache.ode.bpel.iapi.MessageExchange.MessageExchangePattern.REQUEST_RESPONSE;
+
+ if (isTwoWay) {
+ // Defer the invoke until the transaction commits.
+ _sched.registerSynchronizer(new Scheduler.Synchronizer() {
+ public void beforeCompletion() {
+
+ }
+
+ public void afterCompletion(boolean success) {
+ // If the TX is rolled back, then we don't send the request.
+ if (!success) return;
+
+ // The invocation must happen in a separate thread, holding on the afterCompletion
+ // blocks other operations that could have been listed there as well.
+ _server.getExecutor().submit(new Callable<Object>() {
+ public Object call() throws Exception {
+ try {
+ // do execution
+ if(! (partnerRoleMessageExchange.getChannel() instanceof TuscanyPRC)) {
+ throw new IllegalArgumentException("Channel should be an instance of TuscanyPRC");
+ }
+
+ TuscanyPRC channel = (TuscanyPRC) partnerRoleMessageExchange.getChannel();
+ RuntimeComponent tuscanyRuntimeComponent = _server.getTuscanyRuntimeComponent(channel.getProcessName());
+
+ // Fetching the reference based on the data held in the PRC / Endpoint
+ String refName = channel.getEndpoint().serviceName.getLocalPart();
+ RuntimeComponentReference runtimeComponentReference = getReferenceByName( tuscanyRuntimeComponent, refName );
+ RuntimeEndpointReference epr = getEndpointReference( runtimeComponentReference, partnerRoleMessageExchange );
+ // convert operations
+ Operation operation =
+ findOperation(partnerRoleMessageExchange.getOperation().getName(), epr);
+
+ /*
+ This is how a request looks like (payload is wrapped with extra info)
+ <?xml version="1.0" encoding="UTF-8"?>
+ <message>
+ <parameters>
+ <getGreetings xmlns="http://greetings">
+ <message xmlns="http://helloworld">Luciano</message>
+ </getGreetings>
+ </parameters>
+ </message>
+ */
+ Element msg = partnerRoleMessageExchange.getRequest().getMessage();
+ if (msg != null) {
+
+ if(__log.isDebugEnabled()) {
+ String xml = DOMUtils.domToString(msg);
+ String payload = DOMUtils.domToString(getPayload(partnerRoleMessageExchange.getRequest()));
+ __log.debug("Starting invocation of SCA Reference");
+ __log.debug(">>> Original message: " + xml);
+ __log.debug(">>> Payload: " + payload);
+ } // end if
+
+ Object[] args = new Object[] {getPayload(partnerRoleMessageExchange.getRequest())};
+
+ Object result = null;
+ boolean success = false;
+
+ try {
+ result = epr.invoke(operation, args);
+ success = true;
+ } catch (Exception e) {
+ e.printStackTrace();
+ partnerRoleMessageExchange.replyWithFailure(MessageExchange.FailureType.OTHER,
+ e.getMessage(),
+ null);
+ } // end try
+
+ if(__log.isDebugEnabled()) {
+ __log.debug("SCA Reference invocation finished");
+ __log.debug(">>> Result : " + DOMUtils.domToString((Element)result));
+ } // end if
+
+ if (!success) { return null; }
+
+ // two way invocation
+ // process results based on type of message invocation
+ replyTwoWayInvocation(partnerRoleMessageExchange.getMessageExchangeId(),
+ operation,
+ (Element)result);
+ } // end if
+
+ } catch (Throwable t) {
+ // some error
+ String errmsg = "Error sending message (mex=" + partnerRoleMessageExchange + "): " + t.getMessage();
+ __log.error(errmsg, t);
+ /*replyWithFailure(partnerRoleMessageExchange.getMessageExchangeId(),
+ MessageExchange.FailureType.COMMUNICATION_ERROR,
+ errmsg,
+ null);*/
+ }
+ return null;
+ }
+ });
+
+ }
+ });
+ partnerRoleMessageExchange.replyAsync();
+
+ } else {
+ /** one-way case * */
+ _server.getExecutor().submit(new Callable<Object>() {
+ public Object call() throws Exception {
+ // do reply
+ // operationClient.execute(false);
+ return null;
+ }
+ });
+ partnerRoleMessageExchange.replyOneWayOk();
+ }
+ }
+
+ /**
+ * Gets a RuntimeComponentReference of a supplied RuntimeComponent by name
+ * @param tuscanyRuntimeComponent - the runtime component
+ * @param name - the name of the reference
+ * @return - the RuntimeComponentReference with the supplied name - null if there is no reference with that name
+ */
+ private RuntimeComponentReference getReferenceByName( RuntimeComponent tuscanyRuntimeComponent, String name ) {
+ if( name == null ) return null;
+ for( ComponentReference reference : tuscanyRuntimeComponent.getReferences() ) {
+ if( name.equals(reference.getName()) ) return (RuntimeComponentReference)reference;
+ } // end for
+ return null;
+ } // end method getReferenceByName
+
+ /**
+ * Get the Runtime Wire for the supplied reference
+ * @param componentReference - the reference
+ * @return - the RuntimeWire - null if it cannot be found
+ */
+ private RuntimeEndpointReference getEndpointReference( RuntimeComponentReference componentReference,
+ PartnerRoleMessageExchange mex) {
+ if( componentReference.isForCallback() ) {
+ // Where there is a callback, it is necessary to create a specialized wire, based on callback information
+ // present on the forward call
+
+ // Get the callbackEPR for the callback using the BPEL Process ID and the Reference name
+ // - which is the same name as the service name for a callback
+ Long processID = _server.getProcessIDFromMex(mex.getMessageExchangeId());
+ org.apache.tuscany.sca.assembly.EndpointReference callbackEPR =
+ _server.getCallbackMetadata(processID, componentReference.getName());
+ RuntimeEndpointReference wire = selectCallbackWire( callbackEPR.getTargetEndpoint(), componentReference );
+ wire = clone_bind( componentReference, callbackEPR.getCallbackEndpoint() );
+ return wire;
+ } else {
+ // No callback case...
+ //TODO - fix the x..n multiplicity case, which needs to select the correct ONE of multiple
+ // EndpointReferences here
+ return (RuntimeEndpointReference) componentReference.getEndpointReferences().get(0);
+ } // end if
+ } // end method getEndpointReference
+
+ private RuntimeEndpointReference selectCallbackWire( org.apache.tuscany.sca.assembly.Endpoint endpoint,
+ RuntimeComponentReference componentReference) {
+ // Look for callback binding with same name as service binding
+ if (endpoint == null) {
+ throw new RuntimeException("Destination for forward call is not available");
+ }
+
+ for (EndpointReference epr : componentReference.getEndpointReferences()) {
+ if (epr.getBinding().getName().equals(endpoint.getBinding().getName())) {
+ return (RuntimeEndpointReference) epr;
+ }
+ }
+
+ // if no match, look for callback binding with same type as service binding
+ for (EndpointReference epr : componentReference.getEndpointReferences()) {
+ if (epr.getBinding().getType().equals(endpoint.getBinding().getType())) {
+ return (RuntimeEndpointReference) epr;
+ }
+ }
+
+ // no suitable callback wire was found
+ return null;
+ } // end method selectCallbackWire
+
+ private RuntimeEndpointReference clone_bind(RuntimeComponentReference reference,
+ org.apache.tuscany.sca.assembly.Endpoint callbackEndpoint) {
+
+ try {
+ // clone the callback reference ready to configure it for this callback endpoint
+ RuntimeComponentReference ref = (RuntimeComponentReference)reference.clone();
+ ref.getTargets().clear();
+ ref.getBindings().clear();
+ ref.getEndpointReferences().clear();
+
+ // clone epr
+ EndpointReference callbackEndpointReference = (EndpointReference)reference.getEndpointReferences().get(0).clone();
+ callbackEndpointReference.setReference(ref);
+ callbackEndpointReference.setTargetEndpoint(callbackEndpoint);
+ callbackEndpointReference.setUnresolved(true);
+
+ // The callback endpoint will be resolved when the wire chains are created
+ ref.getEndpointReferences().add(callbackEndpointReference);
+ return (RuntimeEndpointReference) ref.getEndpointReferences().get(0);
+ } catch ( CloneNotSupportedException e ) {
+ return null;
+ } // end try clone_bind
+
+ } // end method
+
+ /**
+ * Find the SCA Reference operation
+ *
+ * @param operationName
+ * @param runtimeComponentReference
+ * @return
+ */
+ private Operation findOperation(String operationName, RuntimeEndpointReference epr) {
+ Operation reseultOperation = null;
+
+ for (Operation operation : epr.getComponentTypeReferenceInterfaceContract().getInterface().getOperations()) {
+ if (operationName.equalsIgnoreCase(operation.getName())) {
+ reseultOperation = operation;
+ break;
+ }
+ }
+ return reseultOperation;
+ }
+
+ /**
+ * Get payload from a given ODEMessage
+ * @param odeMessage - the ODE message
+ * @return the payload of the Message, as a DOM Element
+ */
+ private Element getPayload(Message odeMessage) {
+ Element payload = null;
+
+ // Get the message parts - these correspond to the message parts for the invocation
+ // as defined in the WSDL for the service operation being invoked
+ List<String> parts = odeMessage.getParts();
+ if( parts.size() == 0 ) return null;
+
+ // For the present, just deal with the ** FIRST ** part
+ // TODO Deal with operations that have messages with multiple parts
+ // - that will require returning an array of Elements, one for each part
+ Element part = odeMessage.getPart(parts.get(0));
+
+ // Get the payload which is the First child
+ if (part != null && part.hasChildNodes()) {
+ payload = (Element)part.getFirstChild();
+ }
+
+ return payload;
+ } // end getPayload
+
+
+ private void replyTwoWayInvocation(final String odeMexId, final Operation operation, final Element result) {
+ // ODE MEX needs to be invoked in a TX.
+ try {
+ _server.getScheduler().execIsolatedTransaction(new Callable<Void>() {
+ public Void call() throws Exception {
+ PartnerRoleMessageExchange odeMex = null;
+ try {
+ odeMex = (PartnerRoleMessageExchange)_server.getBpelServer().getEngine().getMessageExchange(odeMexId);
+ if (odeMex != null) {
+ Message response = createResponseMessage(odeMex, operation, (Element)result);
+ odeMex.reply(response);
+ }
+ } catch (Exception ex) {
+ String errmsg = "Unable to process response: " + ex.getMessage();
+ if (odeMex != null) {
+ odeMex.replyWithFailure(MessageExchange.FailureType.OTHER, errmsg, null);
+ }
+ }
+
+ return null;
+ }
+ });
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+
+ }
+
+ private Message createResponseMessage(PartnerRoleMessageExchange partnerRoleMessageExchange,
+ Operation operation,
+ Element invocationResult) {
+ Document dom = DOMUtils.newDocument();
+
+ String operationName = operation.getName();
+ Part bpelOperationOutputPart =
+ (Part)((WSDLInterface)operation.getInterface()).getPortType().getOperation(operationName, null, null)
+ .getOutput().getMessage().getParts().values().iterator().next();
+
+ Element contentMessage = dom.createElement("message");
+ Element contentPart = dom.createElement(bpelOperationOutputPart.getName());
+
+ contentPart.appendChild(dom.importNode(invocationResult, true));
+ contentMessage.appendChild(contentPart);
+ dom.appendChild(contentMessage);
+
+ if(__log.isDebugEnabled()) {
+ __log.debug("Creating result message:");
+ __log.debug(">>>" + DOMUtils.domToString(dom.getDocumentElement()));
+ }
+
+ QName id = partnerRoleMessageExchange.getOperation().getOutput().getMessage().getQName();
+ Message response = partnerRoleMessageExchange.createMessage(id);
+ response.setMessage(dom.getDocumentElement());
+
+ return response;
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEInitializationException.java b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEInitializationException.java
new file mode 100644
index 0000000000..2fa91e4e86
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEInitializationException.java
@@ -0,0 +1,41 @@
+/*
+ * 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.bpel.ode;
+
+/**
+ * Thrown when ODE failed to initialize one if its needed resources.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ODEInitializationException extends RuntimeException {
+ private static final long serialVersionUID = -2869674556330744215L;
+
+ public ODEInitializationException(Throwable cause) {
+ super(cause);
+ }
+
+ public ODEInitializationException(String message) {
+ super(message);
+ }
+
+ public ODEInitializationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEMessageExchangeContext.java b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEMessageExchangeContext.java
new file mode 100644
index 0000000000..1ec82390cf
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEMessageExchangeContext.java
@@ -0,0 +1,57 @@
+/*
+ * 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.bpel.ode;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ode.bpel.iapi.BpelEngineException;
+import org.apache.ode.bpel.iapi.ContextException;
+import org.apache.ode.bpel.iapi.MessageExchangeContext;
+import org.apache.ode.bpel.iapi.MyRoleMessageExchange;
+import org.apache.ode.bpel.iapi.PartnerRoleMessageExchange;
+
+/**
+ * Message Exchange Context information
+ *
+ * @version $Rev$ $Date$
+ */
+public class ODEMessageExchangeContext implements MessageExchangeContext {
+ private static final Log __log = LogFactory.getLog(ODEMessageExchangeContext.class);
+
+ private EmbeddedODEServer _server;
+
+ public ODEMessageExchangeContext(EmbeddedODEServer _server) {
+ this._server = _server;
+ }
+
+ public void invokePartner(PartnerRoleMessageExchange partnerRoleMessageExchange) throws ContextException {
+ if (__log.isDebugEnabled()) {
+ __log.debug("Invoking a partner operation: " + partnerRoleMessageExchange.getOperationName());
+ }
+
+ ODEExternalService scaService = new ODEExternalService(_server);
+ scaService.invoke(partnerRoleMessageExchange);
+ }
+
+ public void onAsyncReply(MyRoleMessageExchange myRoleMessageExchange) throws BpelEngineException {
+ if (__log.isDebugEnabled()) {
+ __log.debug("Processing an async reply from service " + myRoleMessageExchange.getServiceName());
+ }
+ }
+ }
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEShutdownException.java b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEShutdownException.java
new file mode 100644
index 0000000000..a928379ba9
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEShutdownException.java
@@ -0,0 +1,41 @@
+/*
+ * 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.bpel.ode;
+
+/**
+ * Thrown when ODE failed to shutdown.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ODEShutdownException extends RuntimeException {
+ private static final long serialVersionUID = -2869674556330744215L;
+
+ public ODEShutdownException(Throwable cause) {
+ super(cause);
+ }
+
+ public ODEShutdownException(String message) {
+ super(message);
+ }
+
+ public ODEShutdownException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/TuscanyEPR.java b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/TuscanyEPR.java
new file mode 100644
index 0000000000..deaeaec040
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/TuscanyEPR.java
@@ -0,0 +1,49 @@
+/*
+ * 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.bpel.ode;
+
+import javax.xml.namespace.QName;
+
+import org.apache.ode.bpel.iapi.Endpoint;
+import org.apache.ode.bpel.iapi.EndpointReference;
+import org.apache.ode.utils.DOMUtils;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * This should hold something that makes sense for Tuscany so that the
+ * process has an address that makes sense from the outside world perspective
+ *
+ * @version $Rev$ $Date$
+ */
+public class TuscanyEPR implements EndpointReference {
+ private final Document doc = DOMUtils.newDocument();
+
+ public TuscanyEPR(QName processName, Endpoint endpoint) {
+ Element serviceref = doc.createElementNS(EndpointReference.SERVICE_REF_QNAME.getNamespaceURI(),
+ EndpointReference.SERVICE_REF_QNAME.getLocalPart());
+ serviceref.setNodeValue(endpoint.serviceName + ":" + endpoint.portName);
+ doc.appendChild(serviceref);
+ }
+
+ public Document toXML() {
+ return doc;
+ }
+}
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/TuscanyPRC.java b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/TuscanyPRC.java
new file mode 100644
index 0000000000..aaa00069f5
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/TuscanyPRC.java
@@ -0,0 +1,62 @@
+/*
+ * 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.bpel.ode;
+
+import javax.wsdl.PortType;
+import javax.xml.namespace.QName;
+
+import org.apache.ode.bpel.iapi.Endpoint;
+import org.apache.ode.bpel.iapi.EndpointReference;
+import org.apache.ode.bpel.iapi.PartnerRoleChannel;
+
+/**
+ * Tuscany Partner Role Channel for ODE Integration
+ *
+ * @version $Rev$ $Date$
+ */
+public class TuscanyPRC implements PartnerRoleChannel {
+ private final QName processName;
+ private final QName pid;
+ private final Endpoint endpoint;
+
+ public TuscanyPRC(QName processName, QName pid, PortType portType, Endpoint endpoint){
+ this.processName = processName;
+ this.pid = pid;
+ this.endpoint = endpoint;
+ }
+
+ public QName getProcessName() {
+ return this.processName;
+ }
+
+ public Endpoint getEndpoint() {
+ return this.endpoint;
+ }
+
+ public void close() {
+
+ }
+
+ public EndpointReference getInitialEndpointReference() {
+
+ return new ODEEndpointReference( this.endpoint );
+ } // end method getInitialEndpointReference
+
+}
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/TuscanyProcessConfImpl.java b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/TuscanyProcessConfImpl.java
new file mode 100644
index 0000000000..2c904a37f8
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/TuscanyProcessConfImpl.java
@@ -0,0 +1,823 @@
+/*
+ * 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.bpel.ode;
+
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.wsdl.Definition;
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ode.bpel.compiler.BpelC;
+import org.apache.ode.bpel.evt.BpelEvent.TYPE;
+import org.apache.ode.bpel.iapi.Endpoint;
+import org.apache.ode.bpel.iapi.EndpointReference;
+import org.apache.ode.bpel.iapi.ProcessConf;
+import org.apache.ode.bpel.iapi.ProcessState;
+import org.apache.tuscany.sca.assembly.Base;
+import org.apache.tuscany.sca.assembly.ComponentProperty;
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.databinding.SimpleTypeMapper;
+import org.apache.tuscany.sca.databinding.impl.SimpleTypeMapperImpl;
+import org.apache.tuscany.sca.implementation.bpel.BPELImplementation;
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * A Tuscany implementation of the ODE Process Conf
+ *
+ * @version $Rev$ $Date$
+ */
+public class TuscanyProcessConfImpl implements ProcessConf {
+ private final Log __log = LogFactory.getLog(getClass());
+
+ private BPELImplementation implementation;
+ private RuntimeComponent component;
+ private Map<String, Endpoint> invokeEndpoints = null;
+ private Map<String, Endpoint> provideEndpoints = null;
+ private Map<QName, Node> properties = null;
+ private ProcessState processState;
+ private Date deployDate;
+
+ private File theBPELFile;
+ // Marks whether the BPEL file was rewritten (eg for initializer statements)
+ private boolean rewritten = false;
+
+ private final SimpleTypeMapper mapper = new SimpleTypeMapperImpl();
+ private final String TUSCANY_NAMESPACE = Base.SCA11_TUSCANY_NS;
+
+ /**
+ * Constructor for the ProcessConf implementation
+ * @param theImplementation the BPEL implementation for which this is the ProcessConf
+ * @param component - the SCA component which uses the implementation
+ */
+ public TuscanyProcessConfImpl( BPELImplementation theImplementation, RuntimeComponent component ) {
+ //System.out.println("New TuscanyProcessConfImpl...");
+ this.implementation = theImplementation;
+ this.component = component;
+
+ processState = ProcessState.ACTIVE;
+ deployDate = new Date();
+
+ // Compile the process
+ compile( getBPELFile() );
+ } // end TuscanyProcessConfImpl constructor
+
+ public void stop() {
+ // If the BPEL file was rewritten, destroy the rewritten version of it so that
+ // it is not used again. Also delete the related compiled cbp file
+ if( rewritten ) {
+ try {
+ String cbpName = theBPELFile.getCanonicalPath();
+ // Remove the "bpel_tmp" suffix and add "cbp"
+ if ( cbpName.endsWith("bpel_tmp") ) {
+ cbpName = cbpName.substring( 0, cbpName.length() - 8) + "cbp";
+ File cbpFile = new File( cbpName );
+ if ( cbpFile.exists() ) cbpFile.delete();
+ } // end if
+ } catch (Exception e ) {
+ // Do nothing with an exception
+ } // end try
+ theBPELFile.delete();
+ } // end if
+
+ } // end method stop
+
+ /**
+ * Returns the URI for the directory containing the BPEL process
+ */
+ public URI getBaseURI() {
+ //System.out.println("getBaseURI called");
+ File theDir = getDirectory();
+ return theDir.toURI();
+ }
+
+ /**
+ * Returns a String containing the (local) name of the file containing the BPEL process
+ */
+ public String getBpelDocument() {
+ //System.out.println("getBPELDocument called");
+ try {
+ String location = this.implementation.getProcessDefinition().getLocation();
+ URI locationURI = new URI(null, location, null);
+ File processFile = new File(locationURI);
+ return getRelativePath( getDirectory(), processFile);
+ } catch (Exception e) {
+ if(__log.isWarnEnabled()) {
+ __log.warn("Unable to resolve relative path of BPEL process" + implementation.getProcessDefinition().getLocation(), e );
+ }
+ return null;
+ } // end try
+ } // end getBpelDocument
+
+ /**
+ * Returns an InputStream containing the Compiled BPEL Process (CBP)
+ */
+ public InputStream getCBPInputStream() {
+ //System.out.println("getCBPInputStream called");
+
+ File cbpFile = getCBPFile();
+ if( cbpFile == null ) return null;
+
+ if( cbpFile.exists() ) {
+ // Create an InputStream from the cbp file...
+ try {
+ return new FileInputStream( cbpFile );
+ } catch ( Exception e ) {
+ if(__log.isDebugEnabled()) {
+ __log.debug("Unable to open the cbp file for BPEL process: " +
+ implementation.getProcessDefinition().getName(), e);
+ }
+ } // end try
+ } else {
+ // Cannot find the cbp file
+ if(__log.isWarnEnabled()){
+ __log.warn("Cannot find the cbp file for process: " +
+ implementation.getProcessDefinition().getName());
+ }
+ } // end if
+ // TODO - need better exception handling if we can't open the cbp file for any reason
+ return null;
+ } // end getCBPInputStream
+
+ /**
+ * Gets the File object for the CBP file for this BPEL Process
+ * @return - the File object for the CBP file
+ */
+ private File getCBPFile() {
+ // Find the CBP file - it has the same name as the BPEL process and lives in the same
+ // directory as the process file
+ String cbpFileName = null;
+ try {
+ String fileName = getRelativePath( getDirectory(), getBPELFile() );
+ cbpFileName = fileName.substring(0, fileName.lastIndexOf(".")) + ".cbp";
+ } catch (Exception e ) {
+ // IOException trying to fetch the BPEL file name
+ if(__log.isDebugEnabled()) {
+ __log.debug("Unable to calculate the file name for BPEL process: " +
+ implementation.getProcessDefinition().getName(), e);
+ return null;
+ } // end if
+ } // end try
+ File cbpFile = new File( getDirectory(), cbpFileName );
+ return cbpFile;
+ } // end getCBPFile
+
+ /**
+ * Return the WSDL Definition for a given PortType
+ * @param portTypeName - the QName of the PortType
+ */
+ public Definition getDefinitionForPortType( QName portTypeName ) {
+ //System.out.println("getDefinitionForPortType called for portType: " + portTypeName );
+ // Find the named PortType in the list of WSDL interfaces associated with this BPEL Process
+ Collection<WSDLInterface> theInterfaces = implementation.getProcessDefinition().getInterfaces();
+ for( WSDLInterface wsdlInterface : theInterfaces ) {
+ if ( wsdlInterface.getPortType().getQName().equals( portTypeName ) ) {
+ // Extract and return the Definition associated with the WSDLDefinition...
+ return wsdlInterface.getWsdlDefinition().getDefinition();
+ } // end if
+ } // end for
+ return null;
+ } // end getDefinitionforPortType
+
+ /**
+ * Returns a WSDL Definition for a given Service QName
+ *
+ * 22/05/2008 - it is very unclear what this service QName is really meant to be.
+ * From the handling of the deploy.xml file by the current ODE code, it seems that the key link
+ * is from the Service QName to the PartnerLink name (done in the deploy.xml file).
+ *
+ * The curious part about this is that the QName for the service is ONLY defined in deploy.xml file
+ * and does not appear to relate to anything else, except for the QName of the PartnerLink
+ *
+ * The PartnerLink name is the same as the name of the SCA service (or reference) which in turn points
+ * at the PartnerLinkType which in turn points at an (WSDL) interface definition.
+ */
+ public Definition getDefinitionForService(QName serviceQName ) {
+ //System.out.println("getDefinitionForService called for Service: " + serviceQName );
+ if(__log.isDebugEnabled()){
+ __log.debug("getDefinitionforService called for service: " + serviceQName );
+ }
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /**
+ * Returns the date of deployment of the process
+ * - for SCA returns the date at which this object was created
+ */
+ public Date getDeployDate() {
+ //System.out.println("getDeployDate called");
+ return deployDate;
+ }
+
+ /**
+ * Returns userid of deployer
+ * - always "SCA Tuscany" for Tuscany...
+ */
+ public String getDeployer() {
+ //System.out.println("getDeployer called");
+ return "SCA Tuscany";
+ } // end getDeployer
+
+ /**
+ * Returns a list of the files in the directory containing the BPEL Process
+ */
+ public List<File> getFiles() {
+ //System.out.println("getFiles called");
+ File theDir = getDirectory();
+ List<File> theFiles = Arrays.asList( (File[]) theDir.listFiles() );
+ // TODO recurse into subdirectories
+ return theFiles;
+ } // end getFiles
+
+ /**
+ * Returns a Map containing all the "invoke endpoints" - for which read "SCA references"
+ * The map is keyed by partnerLink name and holds Endpoint objects
+ * 0..1 multiplicity references are not included in the returned Map (it is as if the reference is not there...)
+ * TODO deal with multiplicity 0..n and 1..n
+ * TODO deal with service callbacks on bidirectional services
+ */
+ public Map<String, Endpoint> getInvokeEndpoints() {
+ if( invokeEndpoints == null ) {
+ invokeEndpoints = new HashMap<String, Endpoint>();
+ // Get a collection of the component references - note that this includes "pseudo-references" for any
+ // services that have a callback interface
+ List<ComponentReference> theReferences = component.getReferences();
+ //List<Reference> theReferences = implementation.getReferences();
+ // Create an endpoint for each reference, using the reference name combined with
+ // http://tuscany.apache.org to make a QName
+ // Note that the key used for this put operation MUST be the name of one of the partnerLinks of the
+ // BPEL process. The SCA reference MAY have an alias for the name (can be given using the sca-bpel:reference
+ // element, if present) and this alias must not be used
+ for( Reference reference : theReferences ) {
+ String partnerlinkName = implementation.getReferencePartnerlinkName( reference.getName() );
+ // Check that there is at least 1 configured SCA endpointReference for the reference, since it is
+ // possible for 0..1 multiplicity references to have no SCA endpointReferences configured
+ List<org.apache.tuscany.sca.assembly.EndpointReference> eprs = reference.getEndpointReferences();
+ String eprCount = Integer.toString( eprs.size() );
+ invokeEndpoints.put( partnerlinkName,
+ new Endpoint( new QName( TUSCANY_NAMESPACE, reference.getName() ), eprCount));
+ } // end for
+ } // end if
+ return invokeEndpoints;
+ } // end getInvokeEndpoints
+
+ /**
+ * Returns the name of the directory containing the BPEL files
+ */
+ public String getPackage() {
+ //System.out.println("getPackage called");
+ File theDir = getDirectory();
+ return theDir.getName();
+ } // end getPackage
+
+ /**
+ * Return the BPEL Process ID - which is the Process QName appended "-versionnumber"
+ */
+ public QName getProcessId() {
+ //System.out.println("getProcessId called");
+ QName processType = getType();
+ QName processID = new QName( processType.getNamespaceURI(),
+ processType.getLocalPart() + "-" + getVersion() );
+ return processID;
+ } // end getProcessID
+
+ /**
+ * TODO - What are properties?
+ */
+ public Map<QName, Node> getProperties() {
+ //System.out.println("getProperties called");
+ if ( properties == null ) {
+ properties = new HashMap<QName, Node>();
+ } // end if
+ return properties;
+ } // end getProperties
+
+ /**
+ * Returns a Map containing all the "provide endpoints" - for which read "SCA services"
+ * The map is keyed by partnerLink name and holds Endpoint objects
+ *
+ * TODO deal with reference callbacks on bidirectional references
+ */
+ public Map<String, Endpoint> getProvideEndpoints() {
+ //System.out.println("getProvideEndpoints called");
+ if( provideEndpoints == null ) {
+ provideEndpoints = new HashMap<String, Endpoint>();
+ String componentURI = component.getURI();
+ // Get a collection of the services - note that the Component services include additional
+ // "pseudo-services" for each reference that has a callback...
+
+ List<ComponentService> theServices = component.getServices();
+ // Create an endpoint for each service, using the service name combined with
+ // http://tuscany.apache.org to make a QName
+ // Note that the key used for this put operation MUST be the name of one of the partnerLinks of the
+ // BPEL process. The SCA service MAY have an alias for the name (can be given using the sca-bpel:service
+ // element, if present) and this alias must not be used
+ for( ComponentService service : theServices ) {
+ String partnerlinkName = implementation.getServicePartnerlinkName( service.getName() );
+ // MJE 14/07/2009 - added componentURI to the service name to get unique service name
+ provideEndpoints.put( partnerlinkName,
+ new Endpoint( new QName( TUSCANY_NAMESPACE, componentURI + service.getName() ),
+ "ServicePort"));
+ } // end for
+ } // end if
+ return provideEndpoints;
+ } // end getProvideEndpoints
+
+ /**
+ * Return the process state
+ */
+ public ProcessState getState() {
+ //System.out.println("getState called");
+ return processState;
+ }
+
+ /**
+ * Returns the QName of the BPEL process
+ */
+ public QName getType() {
+ //System.out.println("getType called");
+ return implementation.getProcess();
+ }
+
+ /**
+ * Gets the process Version number
+ * - current code does not have versions for BPEL processes and always returns "1"
+ */
+ public long getVersion() {
+ //System.out.println("getVersion called");
+ return 1;
+ }
+
+ /**
+ * Returns true if the supplied event type is enabled for any of the scopes in the provided
+ * List. These events are "ODE Execution Events" and there is a definition of them on this
+ * page: http://ode.apache.org/user-guide.html#UserGuide-ProcessDeployment
+ *
+ * Tuscany currently uses:
+ * - instanceLifecycle events in order to establish the relationship of MessageExchange objects
+ * to the BPEL Process instances
+ * @param scopeNames - list of BPEL process Scope names
+ * @param type - the event type
+ */
+ public boolean isEventEnabled(List<String> scopeNames, TYPE type) {
+ if( type == TYPE.dataHandling ) return false;
+ if( type == TYPE.activityLifecycle ) return false;
+ if( type == TYPE.scopeHandling ) return true;
+ if( type == TYPE.instanceLifecycle ) return true;
+ if( type == TYPE.correlation ) return true;
+ return false;
+ } // end isEventEnabled
+
+ /**
+ * Returns whether the process is persisted in the store
+ *
+ * Returns false for SCA configuration
+ * - returning true causes problems in communicating with the BPEL process
+ */
+ public boolean isTransient() {
+ return false;
+ } // end isTransient
+
+ /**
+ * Compiles a BPEL process file into a compiled form CBP file in the main directory
+ * (ie same directory as the BPEL process file)
+ * @param bpelFile - the BPEL process file
+ */
+ private void compile( File bpelFile ) {
+ // Set up the compiler
+ BpelC compiler = BpelC.newBpelCompiler();
+ // Provide a null set of initial properties for now
+ Map<QName, Node> processProps = new HashMap<QName, Node>();
+ Map<String, Object> compileProps = new HashMap<String, Object>();
+ compileProps.put( BpelC.PROCESS_CUSTOM_PROPERTIES, processProps );
+ compiler.setCompileProperties( compileProps );
+ compiler.setBaseDirectory( getDirectory() );
+
+ // Inject any property values
+ bpelFile = injectPropertyValues( bpelFile );
+
+ // Run the compiler and generate the CBP file into the given directory
+ try {
+ compiler.compile( bpelFile );
+ } catch (IOException e) {
+ if(__log.isDebugEnabled()) {
+ __log.debug("Compile error in " + bpelFile, e);
+ }
+ // TODO - need better exception handling here
+ } // end try
+ } // end compile
+
+ /**
+ * Adds the values for SCA declared properties to the BPEL process.
+ * The values for the properties are held in the SCA RuntimeComponent supplied to this
+ * TuscanyProcessConfImpl.
+ * The properties map to <variable/> declarations in the BPEL process that are specifically
+ * marked with @sca-bpel:property="yes"
+ * @param bpelFile the file containing the BPEL process
+ * @return the (updated) file containing the BPEL process
+ */
+ private File injectPropertyValues( File bpelFile ) {
+ // Get the properties
+ List<ComponentProperty> properties = component.getProperties();
+
+ // If there are no properties, we're done!
+ if( properties.size() == 0 ) return bpelFile;
+
+ Document bpelDOM = readDOMFromProcess( bpelFile );
+
+ for( ComponentProperty property : properties ) {
+ //System.out.println("BPEL: Property - name = " + property.getName() );
+ insertSCAPropertyInitializer( bpelDOM, property );
+ } // end for
+
+ File bpelFile2 = writeProcessFromDOM( bpelDOM,
+ getTransformedBPELFile( bpelFile) );
+ if( bpelFile2 != null ) {
+ theBPELFile = bpelFile2;
+ rewritten = true;
+ return bpelFile2;
+ } // end if
+
+ return bpelFile;
+ } // end injectPropertyValues
+
+ /**
+ * Insert an initializer which supplies the value of an SCA property as specified by the
+ * SCA Component using the BPEL process
+ * @param bpelDOM - a DOM model representation of the BPEL process
+ * @param property - an SCA ComponentProperty element for the property
+ * This DOM model is updated, with an initializer being added for the BPEL variable
+ * corresponding to the SCA property
+ */
+ private void insertSCAPropertyInitializer( Document bpelDOM, ComponentProperty property ) {
+ // Only insert a Property initializer where there is a value for the Property
+ if( property.getValue() == null ) return;
+
+ Element insertionElement = findInitializerInsertionPoint( bpelDOM );
+ if( insertionElement == null ) return;
+
+ Element initializer = getInitializerSequence( bpelDOM, property );
+ if( initializer == null ) return;
+
+ // Insert the initializer sequence as the next sibling element of the insertion point
+ Element parent = (Element)insertionElement.getParentNode();
+ // Get the next sibling element, if there is one
+ Node sibling = insertionElement.getNextSibling();
+ while( sibling != null && sibling.getNodeType() != Node.ELEMENT_NODE ) {
+ sibling = sibling.getNextSibling();
+ } // end while
+ // Either insert at the end or before the next element
+ if ( sibling == null ) {
+ parent.appendChild( initializer );
+ } else {
+ parent.insertBefore( initializer, sibling );
+ } // end if
+
+ } // end insertSCAPropertyInitializer
+
+ /**
+ * Gets the variable initializer DOM sequence for a given property, in the context of a supplied
+ * DOM model of the BPEL process
+ * @param bpelDOM - DOM representation of the BPEL process
+ * @param property - SCA Property which relates to one of the variables in the BPEL process
+ * @return - a DOM model representation of the XML statements required to initialize the
+ * BPEL variable with the value of the SCA property.
+ */
+ private Element getInitializerSequence( Document bpelDOM, ComponentProperty property ) {
+ // For an XML simple type (string, int, etc), the BPEL initializer sequence is:
+ // <assign><copy><from><literal>value</literal></from><to variable="variableName"/></copy></assign>
+ QName type = property.getXSDType();
+ if( type != null ) {
+ if( mapper.isSimpleXSDType( type ) ) {
+ // Simple types
+ String NS_URI = bpelDOM.getDocumentElement().getNamespaceURI();
+ String valueText = getPropertyValueText( property.getValue() );
+ Element literalElement = bpelDOM.createElementNS(NS_URI, "literal");
+ literalElement.setTextContent(valueText);
+ Element fromElement = bpelDOM.createElementNS(NS_URI, "from");
+ fromElement.appendChild(literalElement);
+ Element toElement = bpelDOM.createElementNS(NS_URI, "to");
+ Attr variableAttribute = bpelDOM.createAttribute("variable");
+ variableAttribute.setValue( property.getName() );
+ toElement.setAttributeNode( variableAttribute );
+ Element copyElement = bpelDOM.createElementNS(NS_URI, "copy");
+ copyElement.appendChild(fromElement);
+ copyElement.appendChild(toElement);
+ Element assignElement = bpelDOM.createElementNS(NS_URI, "assign");
+ assignElement.appendChild(copyElement);
+ return assignElement;
+ } // end if
+ // TODO Deal with Properties which have a non-simple type
+ } else {
+ // TODO Deal with Properties which have an element as the type
+ } // end if
+
+ return null;
+ } // end method getInitializerSequence
+
+ /**
+ * Gets the text value of a property that is a simple type
+ * @param propValue - the SCA Property value
+ * @return - the text content of the Property value, as a String
+ */
+ private String getPropertyValueText( Object propValue ) {
+ String text = null;
+ if( propValue instanceof Document ) {
+ Element docElement = ((Document)propValue).getDocumentElement();
+ if( docElement != null ){
+ Element valueElement = (Element)docElement.getFirstChild();
+ if( valueElement != null ) {
+ text = valueElement.getTextContent();
+ } // end if
+ } // end if
+ } // end if
+
+ return text;
+ } // end method getPropertyValueText
+
+ private Element findInitializerInsertionPoint( Document bpelDOM ) {
+ // The concept is to find the first Activity child element of the BPEL process document
+ Element docElement = bpelDOM.getDocumentElement();
+ NodeList elements = docElement.getElementsByTagName("*");
+
+ Element element;
+ for ( int i = 0 ; i < elements.getLength() ; i++ ) {
+ element = (Element)elements.item(i);
+ if( isInsertableActivityElement( element ) ) {
+ return element;
+ } // end if
+ } // end for
+
+ return null;
+ } // end method findInitializerInsertionPoint
+
+ /**
+ * A WS-BPEL activity can be any of the following:
+ * <receive>
+ * <reply>
+ * <invoke>
+ * <assign>
+ * <throw>
+ * <exit>
+ * <wait>
+ * <empty>
+ * <sequence>
+ * <if>
+ * <while>
+ * <repeatUntil>
+ * <forEach>
+ * <pick>
+ * <flow>
+ * <scope>
+ * <compensate>
+ * <compensateScope>
+ * <rethrow>
+ * <validate>
+ * <extensionActivity>
+ * A WS-BPEL start activity is a <receive> or <pick> with @create_instance="yes"
+ */
+ private static String SEQUENCE_ELEMENT = "sequence";
+ private static String REPLY_ELEMENT = "reply";
+ private static String INVOKE_ELEMENT = "invoke";
+ private static String ASSIGN_ELEMENT = "assign";
+ private static String PICK_ELEMENT = "pick";
+ private static String RECEIVE_ELEMENT = "receive";
+ private static String FLOW_ELEMENT = "flow";
+ private static String SCOPE_ELEMENT = "scope";
+ /**
+ * Determine if an Element is a BPEL start activity element which can have an Assign
+ * inserted following it
+ * @param element - a DOM Element containing the BPEL activity
+ * @return - true if the Element is a BPEL Activity element, false otherwise
+ */
+ private boolean isInsertableActivityElement( Element element ) {
+ String name = element.getTagName();
+ // For the present, only <receive/> and <pick/> elements with create_instance="yes" count
+ // if( SEQUENCE_ELEMENT.equalsIgnoreCase(name) ) return true;
+ String start = element.getAttribute("createInstance");
+ if( start == null ) return false;
+ if( !"yes".equals(start) ) return false;
+ if( RECEIVE_ELEMENT.equalsIgnoreCase(name) ) return true;
+ if( PICK_ELEMENT.equalsIgnoreCase(name) ) return true;
+ return false;
+ } // end method isActivityElement
+
+ /**
+ * Reads a BPEL Process file into a DOM Document structure
+ * @param bpelFile - a File object referencing the BPEL process document
+ * @return - a DOM Document structure representing the same BPEL process
+ */
+ private Document readDOMFromProcess( File bpelFile ) {
+ try {
+ DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
+ docFactory.setNamespaceAware(true);
+ docFactory.setXIncludeAware(true);
+ DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
+
+ Document bpelDOM = docBuilder.parse( bpelFile );
+ return bpelDOM;
+ } catch (Exception e) {
+ return null;
+ } // end try
+ } // end method
+
+ /**
+ * Writes a BPEL Process file from a DOM Document structure representing the Process
+ * @param bpelDOM - the DOM Document representation of the BPEL process
+ * @param file - a File object to which the BPEL Process is to be written
+ * @return
+ */
+ private File writeProcessFromDOM( Document bpelDOM, File file ) {
+ try {
+ // Prepare the DOM document for writing
+ Source source = new DOMSource( bpelDOM );
+
+ // Prepare the output file
+ Result result = new StreamResult(file);
+
+ // Write the DOM document to the file
+ Transformer xformer = TransformerFactory.newInstance().newTransformer();
+ xformer.transform(source, result);
+ } catch (TransformerConfigurationException e) {
+ } catch (TransformerException e) {
+ return null;
+ }
+ return file;
+ } // end writeProcessFromDOM
+
+ private File getTransformedBPELFile( File bpelFile ) {
+ String name = bpelFile.getName();
+ File parent = bpelFile.getParentFile();
+ File bpelFile2 = null;
+ try {
+ bpelFile2 = File.createTempFile(name, ".bpel_tmp", parent);
+ } catch (Exception e ){
+
+ } // end try
+ return bpelFile2;
+ } // end getTransformedBPELFile
+
+ /**
+ * Gets the directory containing the BPEL process
+ * @return
+ */
+ private File getDirectory() {
+ File theDir = getBPELFile().getParentFile();
+ return theDir;
+ } // end getDirectory
+
+ /**
+ * Gets the File containing the BPEL process definition
+ * @return - the File object containing the BPEL process
+ */
+ private File getBPELFile() {
+ if( theBPELFile != null ) return theBPELFile;
+ try {
+ String location = this.implementation.getProcessDefinition().getLocation();
+ URI locationURI;
+ if (location.indexOf('%') != -1) {
+ locationURI = URI.create(location);
+ } else {
+ locationURI = new URI(null, location, null);
+ }
+ File theProcess = new File(locationURI);
+ theBPELFile = theProcess;
+ return theProcess;
+ } catch( Exception e ) {
+ if(__log.isDebugEnabled()) {
+ __log.debug("Exception converting BPEL file URL to an URI: " + e );
+ }
+ } // end try
+ return null;
+ } // end getBPELFile
+
+ /**
+ * Gets the relative path of a file against a directory in its hierarchy
+ * @param base - the base directory
+ * @param path - the file
+ * @return
+ * @throws IOException
+ */
+ private String getRelativePath(File base, File path) throws IOException {
+ String basePath = base.getCanonicalPath();
+ String filePath = path.getCanonicalPath();
+ if (!filePath.startsWith(basePath)) {
+ throw new IOException("Invalid relative path: base=" + base + " path=" + path);
+ }
+ String relative = filePath.substring(basePath.length());
+ if (relative.startsWith(File.separator)) {
+ relative = relative.substring(1);
+ }
+ return relative;
+ } // end getRelativePath
+
+ //-----------------------------------------------------------------------------
+ // other public APIs which ProcessConfImpl displays which are not in ProcessConf interface
+
+ public List<String> getMexInterceptors(QName processId) {
+// System.out.println("getMexInterceptors for processID: " + processId );
+ return null;
+ }
+
+ public void setTransient(boolean t) {
+// System.out.println("setTransient called with boolean: " + t );
+ }
+
+ public List<Element> getExtensionElement(QName arg0) {
+ return Collections.emptyList();
+ }
+ // end of other public APIs
+ //-----------------------------------------------------------------------------
+
+ /**
+ * Get the size in bytes of the CBP file
+ * @return - this size in bytes of the CBP file, 0 if the file cannot be found
+ */
+ public long getCBPFileSize() {
+ File cbpFile = getCBPFile();
+ if( cbpFile == null ) return 0;
+
+ return cbpFile.length();
+ } // end getCBPFileSize
+
+ private final Set<CLEANUP_CATEGORY> successCategories = EnumSet.noneOf(CLEANUP_CATEGORY.class);
+ private final Set<CLEANUP_CATEGORY> failureCategories = EnumSet.noneOf(CLEANUP_CATEGORY.class);
+
+ public Set<CLEANUP_CATEGORY> getCleanupCategories(boolean instanceSucceeded) {
+ if( instanceSucceeded ) return successCategories;
+ else return failureCategories;
+ }
+
+ private final Map<String, String> emptyPropertyMap = new Hashtable<String, String>();
+ public Map<String, String> getEndpointProperties(EndpointReference epr) {
+ return emptyPropertyMap;
+ }
+
+ private final Map<QName, Node> emptyProcessProperties = new Hashtable<QName, Node>();
+ public Map<QName, Node> getProcessProperties() {
+ return emptyProcessProperties;
+ }
+
+ public boolean isCleanupCategoryEnabled(boolean instanceSucceeded,
+ CLEANUP_CATEGORY category) {
+ // TODO Currently returns false - should this be changed for some categories?
+ return false;
+ }
+
+ public boolean isSharedService(QName serviceName) {
+ // Tuscany does not share the service
+ return false;
+ }
+
+} // end class TuscanyProcessConfImpl
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/provider/BPELImplementationProvider.java b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/provider/BPELImplementationProvider.java
new file mode 100644
index 0000000000..b3824bffe1
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/provider/BPELImplementationProvider.java
@@ -0,0 +1,187 @@
+/*
+ * 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.bpel.ode.provider;
+
+import java.io.File;
+import java.net.URI;
+
+import javax.transaction.TransactionManager;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ode.dao.jpa.ProcessDAOImpl;
+import org.apache.openjpa.persistence.PersistenceProviderImpl;
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.assembly.EndpointReference;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.databinding.xml.DOMDataBinding;
+import org.apache.tuscany.sca.extensibility.ClassLoaderContext;
+import org.apache.tuscany.sca.implementation.bpel.BPELImplementation;
+import org.apache.tuscany.sca.implementation.bpel.ode.EmbeddedODEServer;
+import org.apache.tuscany.sca.implementation.bpel.ode.ODEDeployment;
+import org.apache.tuscany.sca.implementation.bpel.ode.ODEInitializationException;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.provider.ImplementationProvider;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+
+/**
+ * BPEL Implementation provider
+ *
+ * @version $Rev$ $Date$
+ */
+public class BPELImplementationProvider implements ImplementationProvider {
+ private final Log __log = LogFactory.getLog(getClass());
+
+ private RuntimeComponent component;
+ private BPELImplementation implementation;
+
+ private EmbeddedODEServer odeServer;
+ private TransactionManager txMgr;
+
+ private ODEDeployment deployment;
+
+ /**
+ * Constructs a new BPEL Implementation.
+ */
+ public BPELImplementationProvider(RuntimeComponent component,
+ BPELImplementation implementation,
+ EmbeddedODEServer odeServer,
+ TransactionManager txMgr) {
+ this.component = component;
+ this.implementation = implementation;
+ this.odeServer = odeServer;
+ this.txMgr = txMgr;
+
+ // Configure the service and reference interfaces to use a DOM databinding
+ // as it's what ODE expects
+ for(Service service: implementation.getServices() ){
+ service.getInterfaceContract().getInterface().resetDataBinding(DOMDataBinding.NAME);
+ } // end for
+
+ for(Reference reference: implementation.getReferences() ) {
+ reference.getInterfaceContract().getInterface().resetDataBinding(DOMDataBinding.NAME);
+ } // end for
+
+ for (Service service: component.getServices()) {
+ //TODO - MJE, 06/06/2009 - we can eventually remove the reset of the service interface
+ // contract and leave it to the Endpoints only
+ service.getInterfaceContract().getInterface().resetDataBinding(DOMDataBinding.NAME);
+ for( Endpoint endpoint : service.getEndpoints() ) {
+ RuntimeEndpoint ep = (RuntimeEndpoint) endpoint;
+ if (ep.getComponentTypeServiceInterfaceContract() != null) {
+ ep.getComponentTypeServiceInterfaceContract().getInterface().resetDataBinding(DOMDataBinding.NAME);
+ }
+ } // end for
+ } // end for
+
+ for (Reference reference : component.getReferences()) {
+ reference.getInterfaceContract().getInterface().resetDataBinding(DOMDataBinding.NAME);
+ for (EndpointReference endpointReference : reference.getEndpointReferences()) {
+ RuntimeEndpointReference epr = (RuntimeEndpointReference)endpointReference;
+ if (epr.getComponentTypeReferenceInterfaceContract() != null) {
+ epr.getComponentTypeReferenceInterfaceContract().getInterface().resetDataBinding(DOMDataBinding.NAME);
+ }
+ } // end for */
+ } // end for
+
+ }
+
+ public Invoker createInvoker(RuntimeComponentService service, Operation operation) {
+ BPELInvoker invoker = new BPELInvoker(component, service, operation, odeServer, txMgr);
+ return invoker;
+ }
+
+ public boolean supportsOneWayInvocation() {
+ return false;
+ }
+
+ public void start() {
+ if(__log.isInfoEnabled()) {
+ __log.info("Starting " + component.getName());
+ } // end if
+
+ // Switch TCCL - use a classloader that can find classes related to the non-OSGi services
+ // referenced from the implementation-bpel module which include the Persistence provider (OpenJPA) and
+ // the JPA DAO implementation contained in the ODE project
+ ClassLoader tccl = ClassLoaderContext.setContextClassLoader(EmbeddedODEServer.class.getClassLoader(),
+ PersistenceProviderImpl.class.getClassLoader(),
+ ProcessDAOImpl.class.getClassLoader() );
+
+ try {
+ if (!odeServer.isInitialized()) {
+ // start ode server
+ odeServer.init();
+ }
+
+ String location = this.implementation.getProcessDefinition().getLocation();
+ URI deployURI = new URI(null, location, null);
+
+ File deploymentDir = new File(deployURI).getParentFile();
+
+ if(__log.isInfoEnabled()) {
+ __log.info(">>> Deploying : " + deploymentDir.toString());
+ }
+
+ // Deploy the BPEL process
+ if (odeServer.isInitialized()) {
+ deployment = new ODEDeployment( deploymentDir );
+ try {
+ odeServer.registerTuscanyRuntimeComponent(implementation.getProcess(), component);
+
+ odeServer.deploy(deployment, implementation, component );
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ } catch (ODEInitializationException inite) {
+ throw new RuntimeException("BPEL Component Type Implementation : Error initializing embedded ODE server " + inite.getMessage(), inite);
+ } catch(Exception e) {
+ throw new RuntimeException("BPEL Component Type Implementation initialization failure : " + e.getMessage(), e);
+ } finally {
+ // Restore the TCCL if we changed it
+ if( tccl != null ) Thread.currentThread().setContextClassLoader(tccl);
+ } // end try
+ } // end method start()
+
+ public void stop() {
+ if(__log.isInfoEnabled()) {
+ __log.info("Stopping " + component.getName());
+ }
+
+ odeServer.undeploy(deployment);
+
+ if (odeServer.isInitialized()) {
+ // stop ode server
+ odeServer.stop();
+ }
+
+ txMgr = null;
+
+ if(__log.isInfoEnabled()) {
+ __log.info("Stopped !!!");
+ }
+ } // end method stop()
+
+}
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/provider/BPELImplementationProviderFactory.java b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/provider/BPELImplementationProviderFactory.java
new file mode 100644
index 0000000000..ed327e237b
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/provider/BPELImplementationProviderFactory.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.bpel.ode.provider;
+
+import javax.transaction.TransactionManager;
+
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.implementation.bpel.BPELImplementation;
+import org.apache.tuscany.sca.implementation.bpel.ode.EmbeddedODEServer;
+import org.apache.tuscany.sca.implementation.bpel.ode.GeronimoTxFactory;
+import org.apache.tuscany.sca.provider.ImplementationProvider;
+import org.apache.tuscany.sca.provider.ImplementationProviderFactory;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.oasisopen.sca.annotation.Destroy;
+
+/**
+ * BPEL Implementation provider factory
+ *
+ * We use the provider factory to instantiate a ODE server that is going to be injected in all BPEL components
+ *
+ * @version $Rev$ $Date$
+ */
+public class BPELImplementationProviderFactory implements ImplementationProviderFactory<BPELImplementation> {
+
+ private EmbeddedODEServer odeServer;
+ private TransactionManager txMgr;
+
+ /**
+ * Default constructor receiving an extension point
+ * @param extensionPoints
+ */
+ public BPELImplementationProviderFactory(ExtensionPointRegistry extensionPoints) {
+ GeronimoTxFactory txFactory = new GeronimoTxFactory();
+ txMgr = txFactory.getTransactionManager();
+ this.odeServer = new EmbeddedODEServer(txMgr);
+ }
+
+ /**
+ * Creates a new BPEL Implementation and inject the EmbeddedODEServer
+ */
+ public ImplementationProvider createImplementationProvider(RuntimeComponent component, BPELImplementation implementation) {
+ return new BPELImplementationProvider(component, implementation, odeServer, txMgr);
+ }
+
+ public Class<BPELImplementation> getModelType() {
+ return BPELImplementation.class;
+ }
+
+ @Destroy
+ public void destroy() {
+ txMgr = null;
+ }
+}
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/provider/BPELInvoker.java b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/provider/BPELInvoker.java
new file mode 100644
index 0000000000..4a99fe705c
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/provider/BPELInvoker.java
@@ -0,0 +1,286 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.bpel.ode.provider;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+
+import javax.transaction.SystemException;
+import javax.transaction.TransactionManager;
+import javax.wsdl.Part;
+import javax.xml.namespace.QName;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ode.bpel.iapi.MyRoleMessageExchange;
+import org.apache.ode.bpel.iapi.MessageExchange.Status;
+import org.apache.ode.utils.DOMUtils;
+import org.apache.ode.utils.GUID;
+import org.apache.tuscany.sca.assembly.Base;
+import org.apache.tuscany.sca.assembly.EndpointReference;
+import org.apache.tuscany.sca.implementation.bpel.ode.EmbeddedODEServer;
+import org.apache.tuscany.sca.interfacedef.Interface;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * Implements a target invoker for BPEL component implementations.
+ *
+ * The target invoker is responsible for dispatching invocations to the particular
+ * component implementation logic. In this example we are simply delegating the
+ * CRUD operation invocations to the corresponding methods on our fake
+ * resource manager.
+ *
+ * @version $Rev$ $Date$
+ */
+public class BPELInvoker implements Invoker {
+ private final static long TIME_OUT = 10000L;
+
+ protected final Log __log = LogFactory.getLog(getClass());
+
+ private EmbeddedODEServer odeServer;
+ private TransactionManager txMgr;
+
+ private RuntimeComponentService service;
+ private Operation operation;
+ private QName bpelServiceName;
+ private String bpelOperationName;
+ private Part bpelOperationInputPart;
+ private Part bpelOperationOutputPart;
+ private RuntimeComponent component;
+ // Marks if this service has a callback interface
+ private Boolean isCallback = false;
+ private EndpointReference callbackEPR;
+
+ public BPELInvoker(RuntimeComponent component, RuntimeComponentService service, Operation operation,
+ EmbeddedODEServer odeServer, TransactionManager txMgr) {
+ this.service = service;
+ this.component = component;
+ this.operation = operation;
+ this.bpelOperationName = operation.getName();
+ this.odeServer = odeServer;
+ this.txMgr = txMgr;
+ this.isCallback = serviceHasCallback( service );
+
+ initializeInvocation();
+ } // end method BPELInvoker
+
+ private boolean serviceHasCallback( RuntimeComponentService service ) {
+ if(service.getInterfaceContract().getCallbackInterface() != null) return true;
+ return false;
+ } // end method serviceHasCallback
+
+ private void initializeInvocation() {
+
+ __log.debug("Initializing BPELInvoker");
+
+ Interface interfaze = operation.getInterface();
+ if(interfaze instanceof WSDLInterface){
+ WSDLInterface wsdlInterface = null;
+ wsdlInterface = (WSDLInterface) interfaze;
+
+ // Fetch the service name from the service object - including the componentURI guarantees a unique service name
+ String componentURI = component.getURI();
+ bpelServiceName = new QName( Base.SCA11_TUSCANY_NS, componentURI + service.getName() );
+
+ bpelOperationInputPart = (Part) wsdlInterface.getPortType().getOperation(bpelOperationName,null,null).getInput().getMessage().getParts().values().iterator().next();
+ bpelOperationOutputPart = (Part) wsdlInterface.getPortType().getOperation(bpelOperationName,null,null).getOutput().getMessage().getParts().values().iterator().next();
+ }
+ } // end method initializeInvocation
+
+ public Message invoke(Message msg) {
+ try {
+ if( isCallback ) {
+ // Extract the callback endpoint metadata
+ callbackEPR = msg.getFrom();
+ } // end if
+ Object[] args = msg.getBody();
+ Object resp = doTheWork(args);
+ msg.setBody(resp);
+ } catch (InvocationTargetException e) {
+ msg.setFaultBody(e.getCause());
+ }
+ return msg;
+ }
+
+ public Object doTheWork(Object[] args) throws InvocationTargetException {
+ Element response = null;
+
+ if(! (operation.getInterface() instanceof WSDLInterface)) {
+ throw new InvocationTargetException(null,"Unsupported service contract");
+ }
+
+ org.apache.ode.bpel.iapi.MyRoleMessageExchange mex = null;
+ Future<?> onhold = null;
+
+ //Process the BPEL process invocation
+ Long processID = 0L;
+ try {
+ txMgr.begin();
+ mex = odeServer.getBpelServer().getEngine().createMessageExchange(new GUID().toString(),
+ bpelServiceName,
+ bpelOperationName);
+ //TODO - this will not be true for OneWay operations - need to handle those
+ mex.setProperty("isTwoWay", "true");
+ onhold = mex.invoke(createInvocationMessage(mex, args));
+
+ txMgr.commit();
+ // Deal with callback cases - store the callback metadata by process instance ID
+ if( isCallback ) {
+ processID = odeServer.getProcessIDFromMex(mex.getMessageExchangeId());
+ // Store the callback metadata for this invocation
+ odeServer.saveCallbackMetadata( processID, service.getName(), callbackEPR );
+ } // end if
+ } catch (Exception e) {
+ try {
+ txMgr.rollback();
+ } catch (SystemException se) {
+
+ }
+ throw new InvocationTargetException(e, "Error invoking BPEL process : " + e.getMessage());
+ } // end try
+
+ // Waiting until the reply is ready in case the engine needs to continue in a different thread
+ if (onhold != null) {
+ try {
+ //add timeout to avoid blocking when there is a exception/failure
+ onhold.get(TIME_OUT, TimeUnit.MILLISECONDS);
+ } catch (Exception e) {
+ throw new InvocationTargetException(e,"Error invoking BPEL process : " + e.getMessage());
+ } // end try
+ } // end if
+
+ //Process the BPEL invocation response
+ try {
+ txMgr.begin();
+ // Reloading the mex in the current transaction, otherwise we can't
+ // be sure we have the "freshest" one.
+ mex = (MyRoleMessageExchange)odeServer.getBpelServer().getEngine().getMessageExchange(mex.getMessageExchangeId());
+
+ Status status = mex.getStatus();
+
+ switch (status) {
+ case FAULT:
+ if (__log.isDebugEnabled())
+ __log.debug("Fault response message: " + mex.getFault());
+ throw new ODEInvocationException("FAULT received from BPEL process : " + mex.getFault()
+ + " "
+ + mex.getFaultExplanation());
+ case ASYNC:
+ case RESPONSE:
+ //process the method invocation result
+ response = processResponse(mex.getResponse().getMessage());
+ if (__log.isDebugEnabled())
+ __log.debug("Response message " + response);
+ break;
+ case FAILURE:
+ if (__log.isDebugEnabled())
+ __log.debug("Failure response message: " + mex.getFault());
+ break;
+ default:
+ throw new ODEInvocationException("FAILURE received from BPEL process : " + mex.getStatus() + " - " + mex.getFault());
+ } // end switch
+
+ txMgr.commit();
+ // end of transaction two
+ } catch (Exception e) {
+ try {
+ txMgr.rollback();
+ } catch (SystemException se) {
+
+ }
+ throw new InvocationTargetException(e, "Error retrieving BPEL process invocation status : " + e.getMessage());
+ } // end try
+
+ // Cleanup the ODE MessageExchange object
+ //mex.release();
+
+ return response;
+ }
+
+ /**
+ * Create BPEL Invocation message
+ *
+ * BPEL invocation message like :
+ * <message>
+ * <TestPart>
+ * <hello xmlns="http://tuscany.apache.org/implementation/bpel/example/helloworld.wsdl">Hello</hello>
+ * </TestPart>
+ * </message>
+ * @param args
+ * @return
+ */
+ private org.apache.ode.bpel.iapi.Message createInvocationMessage(org.apache.ode.bpel.iapi.MyRoleMessageExchange mex, Object[] args) {
+ Document dom = DOMUtils.newDocument();
+
+ Element contentMessage = dom.createElement("message");
+ Element contentPart = dom.createElement(bpelOperationInputPart.getName());
+ Element payload = null;
+
+ // TODO handle WSDL input messages with multiple Parts...
+ //TUSCANY-2321 - Properly handling Document or Element types
+ if(args[0] instanceof Document) {
+ payload = (Element) ((Document) args[0]).getFirstChild();
+ } else {
+ payload = (Element) args[0];
+ }
+
+ contentPart.appendChild(dom.importNode(payload, true));
+ contentMessage.appendChild(contentPart);
+ dom.appendChild(contentMessage);
+
+ if (__log.isDebugEnabled()) {
+ __log.debug("Creating invocation message:");
+ __log.debug(">> args.....: " + DOMUtils.domToString(payload));
+ __log.debug(">> message..:" + DOMUtils.domToString(dom.getDocumentElement()));
+ }
+
+ org.apache.ode.bpel.iapi.Message request = mex.createMessage(new QName("", ""));
+ request.setMessage(dom.getDocumentElement());
+
+ return request;
+ }
+
+ /**
+ * Process BPEL response
+ *
+ * <message>
+ * <TestPart>
+ * <hello xmlns="http://tuscany.apache.org/implementation/bpel/example/helloworld.wsdl">World</hello>
+ * </TestPart>
+ * </message>
+ *
+ * @param response
+ * @return
+ */
+ private Element processResponse(Element response) {
+ return (Element) DOMUtils.findChildByName(response, new QName("",bpelOperationOutputPart.getName())).getFirstChild();
+
+ // MJE, 12/06/2009 - changed to return the message without the PART wrapper element, since this element is not
+ // transmitted in the SOAP messages on the wire
+ } // end method processResponse
+} // end class BPELInvoker
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/provider/ODEInvocationException.java b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/provider/ODEInvocationException.java
new file mode 100644
index 0000000000..7b6f9ceafa
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/provider/ODEInvocationException.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.bpel.ode.provider;
+
+public class ODEInvocationException extends Exception {
+
+ /**
+ * Thrown when the result of the invocation of a BPEL Process operation
+ * returns a Fault or Failure code
+ */
+ private static final long serialVersionUID = 5096941965798566018L;
+
+ public ODEInvocationException(String message) {
+ super(message);
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory
new file mode 100644
index 0000000000..763f8a601b
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory
@@ -0,0 +1,20 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Implementation class for the implementation extension
+org.apache.tuscany.sca.implementation.bpel.ode.provider.BPELImplementationProviderFactory;model=org.apache.tuscany.sca.implementation.bpel.BPELImplementation
+
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/test/java/org/apache/tuscany/sca/implementation/bpel/ode/EmbeddedODEServerTestCase.java b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/test/java/org/apache/tuscany/sca/implementation/bpel/ode/EmbeddedODEServerTestCase.java
new file mode 100644
index 0000000000..0f59990377
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/test/java/org/apache/tuscany/sca/implementation/bpel/ode/EmbeddedODEServerTestCase.java
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.bpel.ode;
+
+import javax.transaction.TransactionManager;
+
+import junit.framework.TestCase;
+
+/**
+ * Test to Deploy and Invoke a HelloWorld BPEL process using EmbeddedODEServer
+ *
+ * Major changes introduced to this testcase on 27/05/2008 associated with changes in the
+ * implementation of EmbeddedODEServer which remove the need for the ODE deploy.xml file -
+ * instead a Tuscany BPELImplementation object is passed to the EmbeddedODEServer and this is
+ * introspected to get all the necessary information about the BPEL process
+ *
+ * @version $Rev$ $Date$
+ */
+public class EmbeddedODEServerTestCase extends TestCase {
+
+ private EmbeddedODEServer odeServer;
+
+ private TransactionManager txMgr;
+
+ @Override
+ protected void setUp() throws Exception {
+ // Set up the ODE BPEL server...
+ GeronimoTxFactory txFactory = new GeronimoTxFactory();
+ txMgr = txFactory.getTransactionManager();
+
+ this.odeServer = new EmbeddedODEServer(txMgr);
+ odeServer.init();
+
+ } // end setUp
+
+ @Override
+ protected void tearDown() throws Exception {
+ odeServer.stop();
+ }
+
+ public void testProcessInvocation() throws Exception {
+ if (!odeServer.isInitialized()) {
+ fail("Server did not start !");
+ }
+// TODO - write effective testcase - made problematic by the need to supply a resolved
+// BPELImplementation
+/*
+ URL deployURL = getClass().getClassLoader().getResource("helloworld/deploy.xml");
+ File deploymentDir = new File(deployURL.toURI().getPath()).getParentFile();
+ System.out.println("Deploying : " + deploymentDir.toString());
+ System.out.println(deploymentDir);
+
+ if (odeServer.isInitialized()) {
+ try {
+ txMgr.begin();
+ odeServer.deploy(new ODEDeployment(deploymentDir), implementation);
+ txMgr.commit();
+ } catch (Exception e) {
+ e.printStackTrace();
+ txMgr.rollback();
+ }
+
+ // transaction one
+ MyRoleMessageExchange mex = null;
+ Future onhold = null;
+ try {
+ // invoke the process
+ txMgr.begin();
+ mex = odeServer.getBpelServer().getEngine().createMessageExchange(new GUID().toString(),
+ new QName("http://tuscany.apache.org/implementation/bpel/example/helloworld.wsdl", "HelloService"), "hello");
+
+ Message request = mex.createMessage(new QName("", ""));
+ request.setMessage(DOMUtils.stringToDOM("<message><TestPart><hello xmlns=\"http://tuscany.apache.org/implementation/bpel/example/helloworld.wsdl\">Hello</hello></TestPart></message>"));
+ onhold = mex.invoke(request);
+ txMgr.commit();
+ } catch (Exception e) {
+ e.printStackTrace();
+ txMgr.rollback();
+ }
+ // - end of transaction one
+
+ // Waiting until the reply is ready in case the engine needs to continue in a different thread
+ if (onhold != null)
+ onhold.get();
+
+ // transaction two
+ try {
+ txMgr.begin();
+ // Reloading the mex in the current transaction, otherwise we can't be sure we have
+ // the "freshest" one.
+ mex = (MyRoleMessageExchange) odeServer.getBpelServer().getEngine().getMessageExchange(mex.getMessageExchangeId());
+
+ Status status = mex.getStatus();
+ System.out.println("Status: " + status.name());
+ Element response = mex.getResponse().getMessage();
+ System.out.println("Response: " + DOMUtils.domToString(response));
+ txMgr.commit();
+ // end of transaction two
+ } catch (Exception e) {
+ e.printStackTrace();
+ txMgr.rollback();
+ } // end try
+ } // end if
+*/
+ } // end testProcessInvocation
+
+}
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/test/resources/helloworld/deploy.xml b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/test/resources/helloworld/deploy.xml
new file mode 100644
index 0000000000..571aa37d58
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/test/resources/helloworld/deploy.xml
@@ -0,0 +1,30 @@
+<!--
+ ~ 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.
+ -->
+<deploy xmlns="http://www.apache.org/ode/schemas/dd/2007/03"
+ xmlns:tns="http://tuscany.apache.org/implementation/bpel/example/helloworld"
+ xmlns:wns="http://tuscany.apache.org/implementation/bpel/example/helloworld.wsdl">
+
+
+ <process name="tns:HelloWorld">
+ <active>true</active>
+ <provide partnerLink="helloPartnerLink">
+ <service name="wns:HelloService" port="HelloPort"/>
+ </provide>
+ </process>
+</deploy>
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/test/resources/helloworld/greetings.wsdl b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/test/resources/helloworld/greetings.wsdl
new file mode 100644
index 0000000000..e768707ccd
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/test/resources/helloworld/greetings.wsdl
@@ -0,0 +1,87 @@
+<?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.
+-->
+<wsdl:definitions name="greetings"
+ targetNamespace="http://greetings"
+ xmlns:tns="http://greetings"
+ xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+ xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:plnk="http://schemas.xmlsoap.org/ws/2004/03/partner-link/">
+
+ <wsdl:types>
+ <schema elementFormDefault="qualified" targetNamespace="http://greetings" xmlns="http://www.w3.org/2001/XMLSchema">
+
+ <element name="getGreetings">
+ <complexType>
+ <sequence>
+ <element name="name" type="xsd:string"/>
+ </sequence>
+ </complexType>
+ </element>
+
+ <element name="getGreetingsResponse">
+ <complexType>
+ <sequence>
+ <element name="getGreetingsReturn" type="xsd:string"/>
+ </sequence>
+ </complexType>
+ </element>
+
+ </schema>
+ </wsdl:types>
+
+ <wsdl:message name="getGreetingsRequest">
+ <wsdl:part element="tns:getGreetings" name="parameters"/>
+ </wsdl:message>
+
+ <wsdl:message name="getGreetingsResponse">
+ <wsdl:part element="tns:getGreetingsResponse" name="parameters"/>
+ </wsdl:message>
+
+ <wsdl:portType name="Greetings">
+ <wsdl:operation name="getGreetings">
+ <wsdl:input message="tns:getGreetingsRequest" name="getGreetingsRequest"/>
+ <wsdl:output message="tns:getGreetingsResponse" name="getGreetingsResponse"/>
+ </wsdl:operation>
+ </wsdl:portType>
+
+ <wsdl:binding name="GreetingsSoapBinding" type="tns:Greetings">
+ <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
+ <wsdl:operation name="getGreetings">
+ <wsdlsoap:operation soapAction=""/>
+ <wsdl:input name="getGreetingsRequest">
+ <wsdlsoap:body use="literal"/>
+ </wsdl:input>
+ <wsdl:output name="getGreetingsResponse">
+ <wsdlsoap:body use="literal"/>
+ </wsdl:output>
+ </wsdl:operation>
+ </wsdl:binding>
+
+ <wsdl:service name="GreetingsService">
+ <wsdl:port name="GreetingsSoapPort" binding="tns:GreetingsSoapBinding">
+ <wsdlsoap:address location="http://localhost:8085/GreetingsServiceComponent"/>
+ </wsdl:port>
+ </wsdl:service>
+
+ <plnk:partnerLinkType name="GreetingsPartnerLinkType">
+ <plnk:role name="Provider" portType="tns:Greetings"/>
+ </plnk:partnerLinkType>
+</wsdl:definitions>
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/test/resources/helloworld/helloworld.bpel b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/test/resources/helloworld/helloworld.bpel
new file mode 100644
index 0000000000..1799a5ebd3
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/test/resources/helloworld/helloworld.bpel
@@ -0,0 +1,81 @@
+<!--
+ ~ 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.
+ -->
+<process name="HelloWorld"
+ targetNamespace="http://tuscany.apache.org/implementation/bpel/example/helloworld"
+ xmlns="http://schemas.xmlsoap.org/ws/2004/03/business-process/"
+ xmlns:bpws="http://schemas.xmlsoap.org/ws/2004/03/business-process/"
+ xmlns:tns="http://tuscany.apache.org/implementation/bpel/example/helloworld"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:test="http://tuscany.apache.org/implementation/bpel/example/helloworld.wsdl"
+ queryLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xpath2.0"
+ expressionLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xpath2.0">
+
+ <import location="helloworld.wsdl" importType="http://schemas.xmlsoap.org/wsdl/"
+ namespace="http://tuscany.apache.org/implementation/bpel/example/helloworld.wsdl"/>
+
+ <partnerLinks>
+ <partnerLink name="helloPartnerLink" partnerLinkType="test:HelloPartnerLinkType" myRole="me" />
+ </partnerLinks>
+
+ <variables>
+ <variable name="helloMessage" messageType="test:HelloMessage"/>
+ <variable name="tmpVar" type="xsd:string"/>
+ </variables>
+
+ <sequence>
+ <receive
+ name="start"
+ partnerLink="helloPartnerLink"
+ portType="test:HelloPortType"
+ operation="hello"
+ variable="helloMessage"
+ createInstance="yes"/>
+
+ <variables>
+ <variable name="myVar" messageType="test:HelloMessage"/>
+ <variable name="tmpVar" type="xsd:string"/>
+ </variables>
+
+ <sequence>
+ <receive
+ name="start"
+ partnerLink="helloPartnerLink"
+ portType="test:HelloPortType"
+ operation="hello"
+ variable="myVar"
+ createInstance="yes"/>
+
+ <assign name="assign1">
+ <copy>
+ <from>concat($myVar.TestPart/test:message/text(), ' World')</from>
+ <to variable="tmpVar"/>
+ </copy>
+ <copy>
+ <from>$tmpVar</from>
+ <to>$myVar.TestPart/test:message</to>
+ </copy>
+ </assign>
+
+ <reply name="end"
+ partnerLink="helloPartnerLink"
+ portType="test:HelloPortType"
+ operation="hello"
+ variable="helloMessage"/>
+ </sequence>
+</process>
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/test/resources/helloworld/helloworld.wsdl b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/test/resources/helloworld/helloworld.wsdl
new file mode 100644
index 0000000000..610bda3cc4
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/test/resources/helloworld/helloworld.wsdl
@@ -0,0 +1,82 @@
+<?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.
+ -->
+
+<wsdl:definitions name="helloworld"
+ targetNamespace="http://tuscany.apache.org/implementation/bpel/example/helloworld.wsdl"
+ xmlns="http://schemas.xmlsoap.org/wsdl/"
+ xmlns:tns="http://tuscany.apache.org/implementation/bpel/example/helloworld.wsdl"
+ xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+ xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
+ xmlns:bpws="http://schemas.xmlsoap.org/ws/2004/03/business-process/"
+ xmlns:plnk="http://schemas.xmlsoap.org/ws/2004/03/partner-link/">
+
+ <wsdl:types>
+ <schema elementFormDefault="qualified"
+ targetNamespace="http://tuscany.apache.org/implementation/bpel/example/helloworld.wsdl"
+ xmlns="http://www.w3.org/2001/XMLSchema">
+
+ <element name="hello">
+ <complexType>
+ <sequence>
+ <element name="message" type="xsd:string"/>
+ </sequence>
+ </complexType>
+ </element>
+ </schema>
+ </wsdl:types>
+
+ <wsdl:message name="HelloMessage">
+ <wsdl:part element="tns:hello" name="TestPart"/>
+ </wsdl:message>
+
+ <wsdl:portType name="HelloPortType">
+ <wsdl:operation name="hello">
+ <wsdl:input message="tns:HelloMessage" name="TestIn"/>
+ <wsdl:output message="tns:HelloMessage" name="TestOut"/>
+ </wsdl:operation>
+ </wsdl:portType>
+
+
+ <wsdl:binding name="HelloSoapBinding" type="tns:HelloPortType">
+ <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
+ <wsdl:operation name="hello">
+ <wsdlsoap:operation soapAction=""/>
+ <wsdl:input name="TestIn">
+ <wsdlsoap:body use="literal"/>
+ </wsdl:input>
+ <wsdl:output name="TestOut">
+ <wsdlsoap:body use="literal"/>
+ </wsdl:output>
+ </wsdl:operation>
+ </wsdl:binding>
+
+ <wsdl:service name="HelloService">
+ <wsdl:port name="HelloPort" binding="tns:HelloSoapBinding">
+ <soap:address location="http://localhost:8085/ode/processes/helloWorld"/>
+ </wsdl:port>
+ </wsdl:service>
+
+ <plnk:partnerLinkType name="HelloPartnerLinkType">
+ <plnk:role name="me" portType="tns:HelloPortType"/>
+ <plnk:role name="you" portType="tns:HelloPortType"/>
+ </plnk:partnerLinkType>
+</wsdl:definitions> \ No newline at end of file
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/test/resources/log4j.properties b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/test/resources/log4j.properties
new file mode 100644
index 0000000000..82b3c09723
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel-runtime/src/test/resources/log4j.properties
@@ -0,0 +1,36 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# Set root logger level to WARN and its only appender to CONSOLE
+log4j.rootLogger=OFF, CONSOLE
+
+# log4j properties to work with commandline tools.
+log4j.category.org.mortbay=OFF
+log4j.category.org.hibernate.type=OFF
+log4j.category.org.objectweb=OFF
+log4j.category.org.apache.ode.axis2=OFF
+log4j.category.org.apache.ode.bpel.engine=OFF
+log4j.category.org.apache.ode.daohib.bpel.CorrelatorDaoImpl=OFF
+log4j.category.org.apache.ode.bpel.epr=OFF
+log4j.category.org.apache.tuscany.sca.implementation.bpel=OFF
+log4j.category.org.apache.tuscany.sca.implementation.bpel.ode=OFF
+log4j.category.org.apache.tuscany.sca.implementation.bpel.ode.provider=OFF
+
+# Console appender
+log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
+log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
+log4j.appender.CONSOLE.layout.ConversionPattern=[%p] - %C{1}.%M(%L) | %m%n
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel/LICENSE b/sca-java-2.x/branches/2.0/modules/implementation-bpel/LICENSE
new file mode 100644
index 0000000000..baba9ca048
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel/LICENSE
@@ -0,0 +1,251 @@
+
+ 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.
+
+===============================================================================================================
+
+Apache Tuscany SCA for Java Subcomponents
+=========================================:
+
+The Tuscany SCA for Java release includes a number of subcomponents with
+separate copyright notices and license terms. Your use of the source
+code for the these subcomponents is subject to the terms and
+conditions of the following licenses.
+
+=================================================================================================================
+
+This module implementation-script temporarily includes one file under the following BSD license:
+
+ Copyright (c) 2006, Sun Microsystems, Inc.
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ - Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ - Neither the name of the Sun Microsystems, Inc. nor the names of
+ contributors may be used to endorse or promote products derived from this
+ software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ DAMAGE.
+
+=================================================================================================================
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel/META-INF/MANIFEST.MF b/sca-java-2.x/branches/2.0/modules/implementation-bpel/META-INF/MANIFEST.MF
new file mode 100644
index 0000000000..dce7e9e25f
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel/META-INF/MANIFEST.MF
@@ -0,0 +1,32 @@
+Manifest-Version: 1.0
+Export-Package: org.apache.tuscany.sca.implementation.bpel;version="2.0.0"
+ ;uses:="org.apache.tuscany.sca.assembly,org.apache.tuscany.sca.contribution.
+ resolver,javax.xml.namespace"
+Private-Package: org.apache.tuscany.sca.implementation.bpel.impl;versi
+ on="2.0.0",org.apache.tuscany.sca.implementation.bpel.xml;version="2.0.0"
+SCA-Version: 1.1
+Bundle-Name: Apache Tuscany SCA BPEL Implementation Model
+Bundle-Vendor: The Apache Software Foundation
+Bundle-Version: 2.0.0
+Bundle-ManifestVersion: 2
+Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
+Bundle-Description: Apache Tuscany SCA BPEL Implementation Model
+Import-Package: javax.wsdl,
+ javax.wsdl.extensions,
+ javax.xml.namespace,
+ javax.xml.stream,
+ org.apache.tuscany.sca.assembly;version="2.0.0",
+ org.apache.tuscany.sca.assembly.impl;version="2.0.0",
+ org.apache.tuscany.sca.contribution;version="2.0.0",
+ org.apache.tuscany.sca.contribution.namespace;version="2.0.0",
+ org.apache.tuscany.sca.contribution.processor;version="2.0.0",
+ org.apache.tuscany.sca.contribution.resolver;version="2.0.0",
+ org.apache.tuscany.sca.core;version="2.0.0",
+ org.apache.tuscany.sca.implementation.bpel;version="2.0.0",
+ org.apache.tuscany.sca.interfacedef;version="2.0.0",
+ org.apache.tuscany.sca.interfacedef.wsdl;version="2.0.0",
+ org.apache.tuscany.sca.monitor;version="2.0.0",
+ org.apache.tuscany.sca.policy;version="2.0.0"
+Bundle-SymbolicName: org.apache.tuscany.sca.implementation.bpel
+Bundle-DocURL: http://www.apache.org/
+Bundle-RequiredExecutionEnvironment: J2SE-1.5,JavaSE-1.6
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel/NOTICE b/sca-java-2.x/branches/2.0/modules/implementation-bpel/NOTICE
new file mode 100644
index 0000000000..a2f696be26
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel/NOTICE
@@ -0,0 +1,17 @@
+${pom.name}
+Copyright (c) 2005 - 2008 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
+Unless otherwise indicated, all distribution made available by the Apache Software Foundation
+is provided to you under the terms and conditions of the Apache License Version 2.0 ("AL").
+A copy of the AL is provided with this distribution as the LICENSE file present in the
+root directory, and is also available at http://www.apache.org/licenses/.
+
+This product also includes software under the BSD license
+(see the LICENSE file contained in this distribution), with
+the following copyright:
+
+Copyright (c) 2006, Sun Microsystems, Inc.
+All rights reserved.
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel/pom.xml b/sca-java-2.x/branches/2.0/modules/implementation-bpel/pom.xml
new file mode 100644
index 0000000000..ea562063b9
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel/pom.xml
@@ -0,0 +1,64 @@
+<?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</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>tuscany-implementation-bpel</artifactId>
+ <name>Apache Tuscany SCA BPEL Implementation Extension</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-assembly</artifactId>
+ <version>2.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-assembly-xml</artifactId>
+ <version>2.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-interface-wsdl</artifactId>
+ <version>2.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-interface-java</artifactId>
+ <version>2.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELFactory.java b/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELFactory.java
new file mode 100644
index 0000000000..9f8f9c0e9a
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELFactory.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.implementation.bpel;
+
+/**
+ * A factory for the BPEL implementation model.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface BPELFactory {
+
+ /**
+ * Creates a new BPEL implementation.
+ *
+ * @return
+ */
+ BPELImplementation createBPELImplementation();
+
+ /**
+ * Creates a new BPEL Process Definition
+ *
+ * @return
+ */
+ BPELProcessDefinition createBPELProcessDefinition();
+}
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELImplementation.java b/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELImplementation.java
new file mode 100644
index 0000000000..db5d808f7a
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELImplementation.java
@@ -0,0 +1,109 @@
+/*
+ * 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.bpel;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.assembly.ComponentType;
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+
+/**
+ * The model representing the BPEL implementation in an SCA assembly model.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface BPELImplementation extends Implementation {
+ QName TYPE = new QName(SCA11_NS, "implementation.bpel");
+ /**
+ * Get the BPEL process Name
+ *
+ * @return
+ */
+ QName getProcess();
+
+ /**
+ * Set the BPEL process Name
+ *
+ * @param processName process QName
+ */
+ void setProcess(QName processName);
+
+ /**
+ * Get the BPEL process definition
+ *
+ * @return
+ */
+ BPELProcessDefinition getProcessDefinition();
+
+ /**
+ * Set the BPEL process definition
+ *
+ * @param processDefinition
+ */
+ void setProcessDefinition(BPELProcessDefinition processDefinition);
+
+ /**
+ * Returns the componentType for this implementation.
+ *
+ * @return
+ */
+ public ComponentType getComponentType();
+
+ /**
+ * Sets the componentType for this implementation
+ *
+ * @param componentType the component type to set
+ */
+ public void setComponentType(ComponentType componentType);
+
+ /**
+ * Returns the model resolver that can be used to resolve WSDLs and XSDs
+ * referenced by the BPEL process.
+ *
+ * @return
+ */
+ ModelResolver getModelResolver();
+
+ /**
+ * Sets the model resolver that can be used to resolve WSDLs and XSDs referenced
+ * by the BPEL process.
+ *
+ * @param modelResolver
+ */
+ void setModelResolver(ModelResolver modelResolver);
+
+ /**
+ * Gets the name of the partnerLink which corresponds to the SCA service with the supplied name
+ * This deals in particular with cases where the SCA service name is an alias which is not the
+ * same as the partnerLink name
+ * @param serviceName - the name of the SCA service
+ * @return
+ */
+ String getServicePartnerlinkName( String serviceName );
+
+ /**
+ * Gets the name of the partnerLink which corresponds to the SCA reference with the supplied name
+ * This deals in particular with cases where the SCA reference name is an alias which is not the
+ * same as the partnerLink name
+ * @param referenceName - the name of the SCA reference
+ * @return
+ */
+ String getReferencePartnerlinkName( String referenceName );
+}
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELProcessDefinition.java b/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELProcessDefinition.java
new file mode 100644
index 0000000000..2ad088719b
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELProcessDefinition.java
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.bpel;
+
+import java.util.List;
+
+import javax.wsdl.PortType;
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.assembly.Base;
+import org.apache.tuscany.sca.assembly.Property;
+import org.apache.tuscany.sca.implementation.bpel.xml.BPELImportElement;
+import org.apache.tuscany.sca.implementation.bpel.xml.BPELPartnerLinkElement;
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface;
+
+
+/**
+ * The model representing a BPEL process definition.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface BPELProcessDefinition extends Base {
+
+ /**
+ * Get the BPEL process Name
+ *
+ * @return
+ */
+ QName getName();
+
+ /**
+ * Set the BPEL process Name
+ *
+ * @param processName process QName
+ */
+ void setName(QName name);
+
+ /**
+ * Get BPEL process URI
+ *
+ * @return URI for the process
+ */
+ String getURI();
+
+ /**
+ * Set the BPEL process URI
+ *
+ * @param uri for the process
+ */
+ void setURI(String uri);
+
+ /**
+ * Get the URL for the process location
+ *
+ * @return
+ */
+ String getLocation();
+
+ /**
+ * Set the URL for the process location
+ *
+ * @param url
+ */
+ void setLocation(String location);
+
+ /**
+ * Return the list of PartnerLinks for this process
+ *
+ * @return
+ */
+ List<BPELPartnerLinkElement> getPartnerLinks();
+
+ /**
+ * Return the list of imports for this process
+ *
+ * @return
+ */
+ List<BPELImportElement> getImports();
+
+ /**
+ * Return the collection of associated port types
+ *
+ * @return
+ */
+ public List<PortType> getPortTypes() ;
+
+ /**
+ * Return the collection of associated WSDL interfaces
+ * @return
+ */
+ public List<WSDLInterface> getInterfaces() ;
+
+ /**
+ * Return a collection of (SCA) Properties associated with this process
+ * @return - a List of SCA Property objects
+ */
+ public List<Property> getProperties();
+}
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELFactoryImpl.java b/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELFactoryImpl.java
new file mode 100644
index 0000000000..bd98a4af95
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELFactoryImpl.java
@@ -0,0 +1,44 @@
+/*
+ * 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.bpel.impl;
+
+import org.apache.tuscany.sca.implementation.bpel.BPELFactory;
+import org.apache.tuscany.sca.implementation.bpel.BPELImplementation;
+import org.apache.tuscany.sca.implementation.bpel.BPELProcessDefinition;
+
+/**
+ * A factory for the BPEL implementation model.
+ *
+ * @version $Rev$ $Date$
+ */
+public class BPELFactoryImpl implements BPELFactory {
+
+ public BPELFactoryImpl() {
+ }
+
+ public BPELImplementation createBPELImplementation() {
+ return new BPELImplementationImpl();
+ }
+
+ public BPELProcessDefinition createBPELProcessDefinition() {
+ return new BPELProcessDefinitionImpl();
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELImplementationImpl.java b/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELImplementationImpl.java
new file mode 100644
index 0000000000..a2ea5e306e
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELImplementationImpl.java
@@ -0,0 +1,160 @@
+/*
+ * 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.bpel.impl;
+
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+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.assembly.impl.ImplementationImpl;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.implementation.bpel.BPELImplementation;
+import org.apache.tuscany.sca.implementation.bpel.BPELProcessDefinition;
+import org.apache.tuscany.sca.implementation.bpel.xml.BPELPartnerLinkElement;
+
+/**
+ * The model representing a BPEL implementation in an SCA assembly model.
+ *
+ * @version $Rev$ $Date$
+ */
+class BPELImplementationImpl extends ImplementationImpl implements BPELImplementation {
+
+ private QName processName;
+ private BPELProcessDefinition processDefinition;
+ private ComponentType componentType;
+ private ModelResolver modelResolver;
+
+ protected BPELImplementationImpl() {
+ super(TYPE);
+ }
+
+ public QName getProcess() {
+ return processName;
+ }
+
+ public void setProcess(QName processName) {
+ this.processName = processName;
+ }
+
+ public BPELProcessDefinition getProcessDefinition() {
+ return this.processDefinition;
+ }
+
+ public void setProcessDefinition(BPELProcessDefinition processDefinition) {
+ this.processDefinition = processDefinition;
+ }
+
+ @Override
+ public String getURI() {
+ // The BPEL implementation does not have a URI
+ return null;
+ }
+
+ @Override
+ public void setURI(String uri) {
+ // The BPEL implementation does not have a URI
+ }
+
+ @Override
+ public List<Property> getProperties() {
+ return componentType.getProperties();
+ }
+
+ public ComponentType getComponentType() {
+ return componentType;
+ }
+
+ public void setComponentType(ComponentType componentType) {
+ this.componentType = componentType;
+ }
+
+ public ModelResolver getModelResolver() {
+ return modelResolver;
+ }
+
+ public void setModelResolver(ModelResolver modelResolver) {
+ this.modelResolver = modelResolver;
+ }
+
+ @Override
+ public List<Service> getServices() {
+ if (componentType != null){
+ return componentType.getServices();
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public List<Reference> getReferences() {
+ if (componentType != null){
+ return componentType.getReferences();
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public int hashCode() {
+ return String.valueOf(this.getProcess()).hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ } else if (obj instanceof BPELImplementation) {
+ if (getProcess() != null) {
+ return getProcess().equals(((BPELImplementation)obj).getProcess());
+ } else {
+ return ((BPELImplementation)obj).getProcess() == null;
+ }
+ } else {
+ return false;
+ }
+ }
+
+ public String getReferencePartnerlinkName(String referenceName) {
+ if( referenceName == null ) return null;
+ // Find the partnerLink which has its SCAName set to the supplied name
+ List<BPELPartnerLinkElement> partnerLinks = processDefinition.getPartnerLinks();
+ for( BPELPartnerLinkElement partnerLink : partnerLinks ) {
+ if( referenceName.equals(partnerLink.getSCAName()) ) {
+ return partnerLink.getName();
+ } // end if
+ } // end for
+ return null;
+ } // end method getReferencePartnerlinkName
+
+ public String getServicePartnerlinkName(String serviceName) {
+ if( serviceName == null ) return null;
+ // Find the partnerLink which has its SCAName set to the supplied name
+ List<BPELPartnerLinkElement> partnerLinks = processDefinition.getPartnerLinks();
+ for( BPELPartnerLinkElement partnerLink : partnerLinks ) {
+ if( serviceName.equals(partnerLink.getSCAName()) ) {
+ return partnerLink.getName();
+ } // end if
+ } // end for
+ return null;
+ } // end method getServicePartnerlinkName
+}
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELProcessDefinitionImpl.java b/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELProcessDefinitionImpl.java
new file mode 100644
index 0000000000..5ef4a4c113
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELProcessDefinitionImpl.java
@@ -0,0 +1,128 @@
+/*
+ * 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.bpel.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.wsdl.PortType;
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.assembly.Property;
+import org.apache.tuscany.sca.implementation.bpel.BPELProcessDefinition;
+import org.apache.tuscany.sca.implementation.bpel.xml.BPELImportElement;
+import org.apache.tuscany.sca.implementation.bpel.xml.BPELPartnerLinkElement;
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface;
+
+/**
+ * The BPEL process definition implementation.
+ *
+ * @version $Rev$ $Date$
+ */
+class BPELProcessDefinitionImpl implements BPELProcessDefinition {
+ private QName name;
+ private String uri;
+ private String location;
+ private boolean unresolved;
+ private List<BPELPartnerLinkElement> partnerLinks = new ArrayList<BPELPartnerLinkElement>();
+ private List<BPELImportElement> imports = new ArrayList<BPELImportElement>();
+ private List<PortType> thePortTypes = new ArrayList<PortType>();
+ private List<WSDLInterface> theInterfaces = new ArrayList<WSDLInterface>();
+ private List<Property> theProperties = new ArrayList<Property>();
+
+ public QName getName() {
+ return name;
+ }
+
+ public void setName(QName name) {
+ this.name = name;
+ }
+
+ public String getURI() {
+ return uri;
+ }
+
+ public void setURI(String uri) {
+ this.uri = uri;
+ }
+
+ public String getLocation() {
+ return location;
+ }
+
+ public void setLocation(String location) {
+ this.location = location;
+ }
+
+ public boolean isUnresolved() {
+ return unresolved;
+ }
+
+ public void setUnresolved(boolean undefined) {
+ this.unresolved = undefined;
+ }
+
+ public List<BPELPartnerLinkElement> getPartnerLinks() {
+ return partnerLinks;
+ }
+
+ public List<BPELImportElement> getImports() {
+ return imports;
+ }
+
+ public List<PortType> getPortTypes() {
+ return thePortTypes;
+ }
+
+ public List<WSDLInterface> getInterfaces() {
+ return theInterfaces;
+ }
+
+ @Override
+ public int hashCode() {
+ return String.valueOf(getName()).hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ } else if (obj instanceof BPELProcessDefinition) {
+ if (getName() != null) {
+ return getName().equals(((BPELProcessDefinition)obj).getName());
+ } else {
+ return ((BPELProcessDefinition)obj).getName() == null;
+ }
+ } else {
+ return false;
+ }
+ }
+
+ public List<Property> getProperties() {
+ return theProperties;
+ } // end method getProperties
+
+ /**
+ * toString() method to produce a useful String to characterize this BPEL Process implementation during debugging
+ */
+ public String toString() {
+ return "BPEL Process: " + name.toString();
+ }
+} // end class BPELProcessDefinitionImpl
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELDocumentModelResolver.java b/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELDocumentModelResolver.java
new file mode 100644
index 0000000000..2821130ca7
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELDocumentModelResolver.java
@@ -0,0 +1,401 @@
+/*
+ * 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.bpel.xml;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.wsdl.Definition;
+import javax.wsdl.PortType;
+import javax.wsdl.extensions.ExtensibilityElement;
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.Import;
+import org.apache.tuscany.sca.contribution.namespace.NamespaceImport;
+import org.apache.tuscany.sca.contribution.processor.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+import org.apache.tuscany.sca.implementation.bpel.BPELProcessDefinition;
+import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException;
+import org.apache.tuscany.sca.interfacedef.wsdl.BPELPartnerLinkTypeExt;
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition;
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory;
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface;
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLObject;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+
+/**
+ * A Model Resolver for BPEL process models.
+ *
+ * @version $Rev$ $Date$
+ */
+public class BPELDocumentModelResolver implements ModelResolver {
+
+ private WSDLFactory wsdlFactory;
+ private Contribution contribution;
+ private Map<QName, BPELProcessDefinition> map = new HashMap<QName, BPELProcessDefinition>();
+
+ public BPELDocumentModelResolver(Contribution contribution, FactoryExtensionPoint modelFactories) {
+ this.wsdlFactory = modelFactories.getFactory(WSDLFactory.class);
+ this.contribution = contribution;
+ }
+
+ public void addModel(Object resolved, ProcessorContext context) {
+ BPELProcessDefinition process = (BPELProcessDefinition)resolved;
+ map.put(process.getName(), process);
+ }
+
+ public Object removeModel(Object resolved, ProcessorContext context) {
+ return map.remove(((BPELProcessDefinition)resolved).getName());
+ }
+
+ public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) {
+ BPELProcessDefinition resolved = null;
+ QName qname = ((BPELProcessDefinition)unresolved).getName();
+
+ // Lookup a definition for the given namespace, from imports
+ List<String> locations = new ArrayList<String>();
+ // Collection of namespace imports with location
+ Map<String, NamespaceImport> locationMap = new HashMap<String, NamespaceImport>();
+ for (Import import_ : this.contribution.getImports()) {
+ if (import_ instanceof NamespaceImport) {
+ NamespaceImport namespaceImport = (NamespaceImport)import_;
+ if (namespaceImport.getNamespace().equals(qname.getNamespaceURI())) {
+ if (namespaceImport.getLocation() == null) {
+ // Delegate the resolution to the import resolver
+ resolved = namespaceImport.getModelResolver().resolveModel(BPELProcessDefinition.class, (BPELProcessDefinition)unresolved, context);
+ if (!resolved.isUnresolved()) {
+ return modelClass.cast(resolved);
+ }
+ } else {
+ // We might have multiple imports for the same namespace,
+ // need to search them in lexical order.
+ locations.add(namespaceImport.getLocation());
+ }
+ }
+ }
+ }
+ // Search namespace imports with locations in lexical order
+ Collections.sort(locations);
+ for (String location : locations) {
+ NamespaceImport namespaceImport = (NamespaceImport)locationMap.get(location);
+ // Delegate the resolution to the namespace import resolver
+ resolved = namespaceImport.getModelResolver().resolveModel(BPELProcessDefinition.class, (BPELProcessDefinition)unresolved, context);
+ if (!resolved.isUnresolved()) {
+ return modelClass.cast(resolved);
+ }
+ }
+
+
+ // Not found, Lookup a definition for the given namespace, within contribution
+ resolved = (BPELProcessDefinition) map.get(qname);
+
+ if(resolved != null && resolved.isUnresolved()) {
+ try {
+ resolve(resolved, context);
+ } catch(Exception e) {
+ //FIXME
+ }
+ }
+
+ if (resolved != null) {
+ return modelClass.cast(resolved);
+ }
+
+ return (T)unresolved;
+ }
+
+ public void resolve(BPELProcessDefinition unresolved, ProcessorContext context) throws ContributionResolveException {
+ // FIXME - serious resolving needs to happen here
+
+ // Step 1 is to resolve the WSDL files referenced from this BPEL process
+ // - one complexity here is that the WSDL definitions hold BPEL extension elements for
+ // the partnerLinkType declarations - and these must be used in later steps
+ //
+ // Step 2 is to take all the partnerLink definitions and establish the PortType being
+ // used, by tracing through the related partnerLinkType declarations - the PortType is
+ // effectively a definition of the interface used by the partnerLink.
+ // - another consideration here is that each partnerLink can involve 2 interfaces, one
+ // for the forward calls to the process, the other for calls from the process - depending
+ // on whether the partnerLink is a reference or a service, one of these interfaces is a
+ // callback interface.
+
+ List<BPELImportElement> theImports = unresolved.getImports();
+ Set<Definition> wsdlDefinitions = getImportedWSDLDefinitions( theImports, contribution.getModelResolver(), context );
+
+ // Fetch the sets of partner links, port types and interfaces
+ List<BPELPartnerLinkTypeElement> thePLinkTypes = getPartnerLinkTypes( wsdlDefinitions, context.getMonitor() );
+ Collection<WSDLInterface> theInterfaces = (Collection<WSDLInterface>)new ArrayList<WSDLInterface>();
+ Collection<PortType> thePortTypes = getAllPortTypes( theImports, theInterfaces, contribution.getModelResolver(), context );
+
+ // Store the Port Types and the Interfaces for later calculation of the component type...
+ unresolved.getPortTypes().addAll(thePortTypes);
+ unresolved.getInterfaces().addAll(theInterfaces);
+
+ // Now, for each partnerLink in the BPEL process, find the related partnerLinkType element
+ List<BPELPartnerLinkElement> thePartnerLinks = unresolved.getPartnerLinks();
+ for (BPELPartnerLinkElement thePartnerLink : thePartnerLinks) {
+ QName partnerLinkType = thePartnerLink.getPartnerLinkType();
+ BPELPartnerLinkTypeElement pLinkType = findPartnerLinkType(partnerLinkType, thePLinkTypes);
+ if (pLinkType == null) {
+ error(context.getMonitor(), "PartnerLinkNoMatchingType", thePartnerLink, thePartnerLink.getName());
+ } else {
+ thePartnerLink.setPartnerLinkType(pLinkType);
+ }
+ } // end for
+
+ unresolved.setUnresolved(false);
+
+ } // end resolve
+
+ /**
+ * Get all the WSDL definitions referenced through the import statements of the BPEL process
+ * @param theImports - a list of the import statements
+ * @return - a Set containing all the referenced WSDL definitions
+ */
+ private Set<Definition> getImportedWSDLDefinitions( List<BPELImportElement> theImports, ModelResolver resolver, ProcessorContext context ) {
+ Set<Definition> wsdlDefinitions = null;
+ for (BPELImportElement theImport : theImports) {
+ if (theImport.getImportType().equals(BPELProcessorConstants.WSDL_NS)) {
+ // If the Import is a WSDL import, resolve the WSDL
+ WSDLDefinition theWSDL = resolveWSDLDefinition( theImport.getLocation(),
+ theImport.getNamespace(), resolver, context );
+ if( theWSDL != null ) {
+ theImport.setWSDLDefinition( theWSDL );
+
+ // Find all the WSDL definitions matching the imported namespace
+ if( wsdlDefinitions == null ) {
+ wsdlDefinitions = new HashSet<Definition>();
+ } // end if
+
+ wsdlDefinitions.add(theWSDL.getDefinition());
+ } // end if
+ } // end if
+ } // end for
+
+ return wsdlDefinitions;
+ } // end getImportedWSDLDefinitions
+
+ /**
+ * Resolve a reference to a WSDL, given by a namespace and a location
+ * @param wsdlLocation - a string containing the WSDL location
+ * @param wsdlNamespace - a string containing the WSDL namespace
+ * @param resolver - a model resolver
+ * @param context
+ * @return - a WSDLDefinition object for the referenced WSDL, or null if the WSDL cannot be resolved
+ */
+ private WSDLDefinition resolveWSDLDefinition( String wsdlLocation, String wsdlNamespace, ModelResolver resolver, ProcessorContext context ) {
+
+ // Resolve the WSDL definition
+ WSDLDefinition proxy = wsdlFactory.createWSDLDefinition();
+ proxy.setUnresolved(true);
+ proxy.setNamespace(wsdlNamespace);
+ if (wsdlLocation != null) {
+ proxy.setLocation(URI.create(wsdlLocation));
+ }
+ WSDLDefinition resolved = resolver.resolveModel(WSDLDefinition.class, proxy, context);
+ if (resolved != null && !resolved.isUnresolved()) {
+ return resolved;
+ } else {
+ error(context.getMonitor(), "CannotResolveWSDLReference", resolver, wsdlLocation, wsdlNamespace);
+ return null;
+ } // end if
+ } // end resolveWSDLDefinition
+
+
+ /**
+ * Retrieve all the Partner Link types defined in the imported WSDL files
+ *
+ * @param wsdlDefinitions - the set of imported WSDL definitions
+ * @return - a List of PartnerLinkType elements
+ */
+ @SuppressWarnings("unchecked")
+ private List<BPELPartnerLinkTypeElement> getPartnerLinkTypes( Set<Definition> wsdlDefinitions, Monitor monitor ) throws ContributionResolveException {
+
+ List<BPELPartnerLinkTypeElement> thePLinks = new ArrayList<BPELPartnerLinkTypeElement>();
+
+ // The BPEL partnerLinkType elements are extension elements within the WSDL definitions
+ for (Definition wsdlDefinition: wsdlDefinitions) {
+ for (ExtensibilityElement theElement : (List<ExtensibilityElement>)wsdlDefinition.getExtensibilityElements()) {
+ QName elementType = theElement.getElementType();
+ if (elementType.equals(BPELProcessorConstants.LINKTYPE_ELEMENT) || elementType.equals(BPELProcessorConstants.LINKTYPE_ELEMENT_20)) {
+ BPELPartnerLinkTypeExt pLinkExt = (BPELPartnerLinkTypeExt)theElement;
+
+ // Fetch the name of the partnerLinkType
+ QName qName = new QName(wsdlDefinition.getTargetNamespace(), pLinkExt.getName());
+ BPELPartnerLinkTypeElement pLinkElement = new BPELPartnerLinkTypeElement(qName);
+
+ // The partnerLinkType must have one and may have 2 role child elements
+ int count = 0;
+ for (int i = 0; i < 2; i++) {
+ if( count > 1 ) break;
+ if (pLinkExt.getRoleName(i) == null) continue;
+ PortType pType = wsdlDefinition.getPortType(pLinkExt.getRolePortType(i));
+ if (count == 0) {
+ pLinkElement.setRole1(pLinkExt.getRoleName(i), pLinkExt.getRolePortType(i), pType);
+ } else {
+ pLinkElement.setRole2(pLinkExt.getRoleName(i), pLinkExt.getRolePortType(i), pType);
+ } // end if
+ count++;
+ } // end for
+
+ if (count == 0) {
+ error(monitor, "PartnerLinkTypeNoRoles", theElement, pLinkElement.getName());
+ throw new ContributionResolveException("partnerLinkType " + pLinkElement.getName() + " has no Roles defined");
+ } else
+ thePLinks.add(pLinkElement);
+ } // end if
+ } // end for
+ } // end for
+ return thePLinks;
+ } // end getPartnerLinkTypes
+
+
+ /**
+ * Finds a partnerLinkType definition within the WSDLs imported by the BPEL
+ * process.
+ *
+ * @param partnerLinkTypeName - the name of the partnerLinkType
+ * @param theImports a list of the WSDL import declarations
+ * @return a BPELPartnerLinkTypeElement for the partnerLinkType or null if it cannot be
+ * found
+ */
+ private BPELPartnerLinkTypeElement findPartnerLinkType( QName partnerLinkTypeName, List<BPELPartnerLinkTypeElement> thePLinkTypes) {
+ // We must find the partner link type element from amongst the imported WSDLs
+ for ( BPELPartnerLinkTypeElement thePLinkType : thePLinkTypes ){
+ if( thePLinkType.getName().equals(partnerLinkTypeName) ) return thePLinkType;
+ } // end for
+ return null;
+ } // end findPartnerLinkType
+
+
+ /**
+ * Returns all the portTypes referenced by the process.
+ *
+ * @param theImports
+ * @param theInterfaces
+ * @param resolver
+ * @return
+ * @throws ContributionResolveException
+ */
+ @SuppressWarnings("unchecked")
+ private Collection<PortType> getAllPortTypes(List<BPELImportElement> theImports,
+ Collection<WSDLInterface> theInterfaces,
+ ModelResolver resolver,
+ ProcessorContext context) throws ContributionResolveException {
+
+ Set<PortType> thePortTypes = new HashSet<PortType>();
+ for (BPELImportElement theImport : theImports) {
+ if (theImport.getImportType().equals(BPELProcessorConstants.WSDL_NS)) {
+
+ // Find all the WSDL definitions matching the imported namespace
+ List<Definition> wsdlDefinitions = new ArrayList<Definition>();
+ WSDLDefinition theWSDL = theImport.getWSDLDefinition();
+ wsdlDefinitions.add(theWSDL.getDefinition());
+ for (WSDLDefinition importedWSDL: theWSDL.getImportedDefinitions()) {
+ wsdlDefinitions.add(importedWSDL.getDefinition());
+ }
+ for (Definition wsdlDefinition: wsdlDefinitions) {
+
+ Collection<PortType> portTypes = (Collection<PortType>)wsdlDefinition.getPortTypes().values();
+
+ // Create WSDLInterface elements for each unique PortType found
+ for (PortType portType : portTypes) {
+ if( thePortTypes.contains(portType) ) continue;
+ thePortTypes.add( portType );
+
+ WSDLObject<PortType> wsdlPortType = theWSDL.getWSDLObject(PortType.class, portType.getQName());
+ WSDLInterface wsdlInterface;
+ if (wsdlPortType != null) {
+ // Introspect the WSDL portType and add the resulting WSDLInterface to the resolver
+ try {
+ wsdlInterface = wsdlFactory.createWSDLInterface(wsdlPortType.getElement(), theWSDL, resolver, context.getMonitor());
+ wsdlInterface.setWsdlDefinition(theWSDL);
+ } catch (InvalidInterfaceException e) {
+ ContributionResolveException ce =
+ new ContributionResolveException("Unable to create WSDLInterface for portType " + portType.getQName(),e);
+ error(context.getMonitor(), "ContributionResolveException", resolver, ce);
+ throw ce;
+ } // end try
+ resolver.addModel(wsdlInterface, context);
+ theInterfaces.add(wsdlInterface);
+ } // end if
+ } // end for
+ }
+ }
+ } // end for
+
+ return thePortTypes;
+ } // end getAllPortTypes
+
+ /**
+ * Report a warning.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void warning(Monitor monitor, String message, Object model, Object... messageParameters) {
+ if (monitor != null) {
+ Problem problem = monitor.createProblem(this.getClass().getName(), "impl-bpel-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
+ /**
+ * Report a error.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(Monitor monitor, String message, Object model, Object... messageParameters) {
+ if (monitor != null) {
+ Problem problem = monitor.createProblem(this.getClass().getName(), "impl-bpel-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
+ /**
+ * Report a exception.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(Monitor monitor, String message, Object model, Exception ex) {
+ if (monitor != null) {
+ Problem problem = monitor.createProblem(this.getClass().getName(), "impl-bpel-validation-messages", Severity.ERROR, model, message, ex);
+ monitor.problem(problem);
+ }
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELDocumentProcessor.java b/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELDocumentProcessor.java
new file mode 100644
index 0000000000..2c50ae98c3
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELDocumentProcessor.java
@@ -0,0 +1,355 @@
+/*
+ * 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.bpel.xml;
+
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URL;
+import java.util.Iterator;
+import java.util.List;
+
+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.Property;
+import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
+import org.apache.tuscany.sca.contribution.processor.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+import org.apache.tuscany.sca.implementation.bpel.BPELFactory;
+import org.apache.tuscany.sca.implementation.bpel.BPELProcessDefinition;
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+
+/**
+ * BPEL document processor responsible for reading a BPEL file and producing necessary model info about it
+ *
+ * Handles both BPEL 1.1 documents and BPEL 2.0 documents
+ * @version $Rev$ $Date$
+ */
+public class BPELDocumentProcessor extends BaseStAXArtifactProcessor implements URLArtifactProcessor<BPELProcessDefinition> {
+
+ private final static XMLInputFactory inputFactory = XMLInputFactory.newInstance();
+
+ private final BPELFactory factory;
+ private WSDLFactory WSDLfactory;
+ private AssemblyFactory assemblyFactory;
+
+ public BPELDocumentProcessor(FactoryExtensionPoint modelFactories) {
+ this.factory = modelFactories.getFactory(BPELFactory.class);
+ this.WSDLfactory = modelFactories.getFactory(WSDLFactory.class);
+ this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class);
+ }
+
+ public String getArtifactType() {
+ return "*.bpel";
+ }
+
+ public Class<BPELProcessDefinition> getModelType() {
+ return BPELProcessDefinition.class;
+ }
+
+ /**
+ * Read the BPEL Process definition file from the location identified by an artifact URL
+ * @param contributionURL - URL of the Contribution containing the Process definition
+ * @param artifactURI - URI of the artifact containing the BPEL Process definition
+ * @param artifactURL - URL of the artifact containing the BPEL Process definition
+ * @return BPELProcessDefinition - SCA model of the BPEL Process
+ */
+ public BPELProcessDefinition read(URL contributionURL, URI artifactURI, URL artifactURL, ProcessorContext context) throws ContributionReadException {
+ BPELProcessDefinition processDefinition = null;
+ try {
+ processDefinition = readProcessDefinition(artifactURL, context.getMonitor());
+ processDefinition.setURI(artifactURI.toString());
+ processDefinition.setUnresolved(true);
+ } catch (Exception e) {
+ ContributionReadException ce = new ContributionReadException(e);
+ error(context.getMonitor(), "ContributionReadException", artifactURL, ce);
+ }
+
+ return processDefinition;
+ }
+
+ public void resolve(BPELProcessDefinition model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException {
+ // Delegate resolving to model resolver
+ if (model != null || model.isUnresolved()) {
+ resolver.resolveModel(BPELProcessDefinition.class, model, context);
+ }
+
+ } // end resolve
+
+ /**
+ * Read a process definition.
+ *
+ * @param doc
+ * @return
+ * @throws Exception
+ */
+ private BPELProcessDefinition readProcessDefinition(URL doc, Monitor monitor) throws Exception {
+ BPELProcessDefinition processDefinition = factory.createBPELProcessDefinition();
+ processDefinition.setUnresolved(true);
+ processDefinition.setLocation(doc.toString());
+
+ InputStream is = doc.openStream();
+ XMLStreamReader reader = null;
+ try {
+ reader = inputFactory.createXMLStreamReader(is);
+
+ /*
+ * The principle here is to look for partnerLink elements, which
+ * form either services or references. A partnerLink can be EITHER -
+ * the algorithm for deciding is:
+ * 1) Explicit marking with sca:reference or sca:service attribute
+ * 2) "first use" of the partnerLink by specific BPEL activity elements:
+ * <onEvent../>, <receive../> or <pick../> elements imply a service
+ * <invoke../> implies a reference
+ */
+
+ // TODO - need to handle <scope../> elements as kind of "nested" processes
+ // - and scopes introduce the possibility of partnerLinks with the
+ // same name at different levels of scope.... (yuk!!)
+ boolean completed = false;
+ while (!completed) {
+ switch (reader.next()) {
+ case START_ELEMENT:
+ QName qname = reader.getName();
+ if (BPELProcessorConstants.PROCESS_ELEMENT.equals(qname) || BPELProcessorConstants.PROCESS_ELEMENT_20.equals(qname)) {
+ QName processName = new QName(getString(reader, BPELProcessorConstants.TARGET_NAMESPACE), getString(reader, BPELProcessorConstants.NAME_ELEMENT));
+ processDefinition.setName(processName);
+ } else if (BPELProcessorConstants.PARTNERLINK_ELEMENT.equals(qname) || BPELProcessorConstants.PARTNERLINK_ELEMENT_20.equals(qname)) {
+ processDefinition.getPartnerLinks().add(processPartnerLinkElement(reader, monitor));
+ } else if (BPELProcessorConstants.ONEVENT_ELEMENT.equals(qname) || BPELProcessorConstants.RECEIVE_ELEMENT.equals(qname) || BPELProcessorConstants.ONMESSAGE_ELEMENT.equals(qname) ||
+ BPELProcessorConstants.ONEVENT_ELEMENT_20.equals(qname) || BPELProcessorConstants.RECEIVE_ELEMENT_20.equals(qname) || BPELProcessorConstants.ONMESSAGE_ELEMENT_20.equals(qname)) {
+ processPartnerLinkAsService(reader.getAttributeValue(null, "partnerLink"), processDefinition.getPartnerLinks(), monitor);
+ } else if (BPELProcessorConstants.INVOKE_ELEMENT.equals(qname) || BPELProcessorConstants.INVOKE_ELEMENT_20.equals(qname)) {
+ processPartnerLinkAsReference(reader.getAttributeValue(null, "partnerLink"), processDefinition.getPartnerLinks(), monitor);
+ } else if (BPELProcessorConstants.IMPORT_ELEMENT.equals(qname) || BPELProcessorConstants.IMPORT_ELEMENT_20.equals(qname)) {
+ processDefinition.getImports().add(processImportElement(reader));
+ } else if (BPELProcessorConstants.VARIABLE_ELEMENT.equals(qname) || BPELProcessorConstants.VARIABLE_ELEMENT_20.equals(qname)) {
+ // deal with variables that are SCA properties through the presence of a sca-bpel:property="yes" attribute
+ Property aProperty = processVariableElement(reader);
+ if( aProperty != null ) {
+ processDefinition.getProperties().add( aProperty );
+ } // end if
+ } // end if
+ break;
+ case END_ELEMENT:
+ qname = reader.getName();
+ if (BPELProcessorConstants.PROCESS_ELEMENT.equals(qname) || BPELProcessorConstants.PROCESS_ELEMENT_20.equals(qname)) {
+ completed = true;
+ break;
+ } // end if
+ } // end switch
+ } // end while
+ } finally {
+ if (reader != null)
+ reader.close();
+ is.close();
+ } // end try
+
+ return processDefinition;
+ } // end readProcessDefinition
+
+ /**
+ * Processes a BPEL <variable/> element and creates an SCA <property/> element if the variable is
+ * marked with sca-bpel:property="yes"
+ * A BPEL <variable/> element can declare its type in one of 3 ways:
+ * 1. using @type attribute, which must reference an XSD declared type
+ * 2. using @element attribute, which must reference an XSD global element
+ * 3. using @message attribute, which must reference a WSDL defined message type
+ * @param reader - XMLStreamReader reading the BPEL process
+ * @throws ContributionReadException
+ */
+ private Property processVariableElement( XMLStreamReader reader) throws ContributionReadException {
+ String scaProperty = reader.getAttributeValue(BPELProcessorConstants.SCA_BPEL_NS, "property");
+ if( "yes".equals(scaProperty)) {
+ String varName = reader.getAttributeValue(null ,"name");
+ String varType = reader.getAttributeValue(null, "type");
+ String varElement = reader.getAttributeValue(null, "element");
+ String varMessage = reader.getAttributeValue(null, "message");
+ // Pass over this variable if there is no name, or if there is no type information
+ if( varName == null ) return null;
+ if( varType == null && varElement == null && varMessage == null ) return null;
+ QName typeQName = getQNameValue( reader, varType );
+ QName elementQName = getQNameValue( reader, varElement );
+ // TODO deal with properties declared with @message for typing
+ Property theProperty = assemblyFactory.createProperty();
+ theProperty.setName(varName);
+ theProperty.setXSDType(typeQName);
+ theProperty.setXSDElement(elementQName);
+ return theProperty;
+ } // end if
+ return null;
+
+ } // end processVariableElement
+
+ /**
+ * Processes a partnerLink element from the BPEL process and creates a
+ * BPELPartnerLink object
+ *
+ * @param reader
+ */
+ private BPELPartnerLinkElement processPartnerLinkElement(XMLStreamReader reader, Monitor monitor) throws ContributionReadException {
+ BPELPartnerLinkElement partnerLink = new BPELPartnerLinkElement( reader.getAttributeValue(null, "name"),
+ getQNameValue(reader, reader.getAttributeValue(null, "partnerLinkType")),
+ reader.getAttributeValue(null, "myRole"),
+ reader.getAttributeValue(null, "partnerRole"));
+
+ // See if there are any SCA extension attributes
+ String scaService = reader.getAttributeValue(BPELProcessorConstants.SCA_BPEL_NS, "service");
+ String scaReference = reader.getAttributeValue(BPELProcessorConstants.SCA_BPEL_NS, "reference");
+ if ((scaService != null) && (scaReference != null)) {
+ // It is incorrect to set both service & reference attributes
+ error(monitor, "PartnerLinkHasBothAttr", partnerLink, reader.getAttributeValue(null, "name"));
+ throw new ContributionReadException("BPEL PartnerLink " + reader.getAttributeValue(null, "name") +
+ " has both sca:reference and sca:service attributes set");
+ } // end if
+
+ // Set the SCA type and the related name, if present
+ if (scaService != null)
+ partnerLink.setAsService(scaService);
+ else if (scaReference != null)
+ partnerLink.setAsReference(scaReference);
+ return partnerLink;
+
+ } // end processPartnerLinkElement
+
+ /**
+ * Processes an <import../> element from the BPEL process and creates a
+ * BPELImportElement object
+ *
+ * @param reader
+ */
+ private BPELImportElement processImportElement(XMLStreamReader reader) {
+ return (new BPELImportElement(reader.getAttributeValue(null, "location"),
+ reader.getAttributeValue(null, "importType"),
+ reader.getAttributeValue(null, "namespace")));
+
+ } // end processImportElement
+
+ /**
+ * Mark a named partnerLink as a Service, unless it is already marked as a
+ * Reference
+ *
+ * @param partnerLinkName
+ * @param partnerLinks
+ */
+ private void processPartnerLinkAsService(String partnerLinkName, List<BPELPartnerLinkElement> partnerLinks, Monitor monitor) {
+ BPELPartnerLinkElement partnerLink = findPartnerLinkByName(partnerLinks, partnerLinkName);
+ if (partnerLink == null) {
+ warning(monitor, "ReferencePartnerLinkNotInList", partnerLinkName, partnerLinkName);
+ } else {
+ // Set the type of the partnerLink to "service" if not already
+ // set...
+ if (!partnerLink.isSCATyped())
+ partnerLink.setAsService(partnerLinkName);
+ } // endif
+ } // end processPartnerLinkAsReference
+
+ /**
+ * Mark a named partnerLink as a Reference, unless it is already marked as a
+ * Service
+ *
+ * @param partnerLinkName
+ * @param partnerLinks
+ */
+ private void processPartnerLinkAsReference(String partnerLinkName, List<BPELPartnerLinkElement> partnerLinks, Monitor monitor) {
+ BPELPartnerLinkElement partnerLink = findPartnerLinkByName(partnerLinks, partnerLinkName);
+ if (partnerLink == null) {
+ warning(monitor, "ReferencePartnerLinkNotInList", partnerLinkName, partnerLinkName);
+ } else {
+ // Set the type of the partnerLink to "service" if not already
+ // set...
+ if (!partnerLink.isSCATyped())
+ partnerLink.setAsReference(partnerLinkName);
+ } // endif
+ } // end processPartnerLinkAsReference
+
+ /**
+ * Finds a PartnerLink by name from a List of PartnerLinks returns null if
+ * there is no partnerLink with a matching name - returns the PartnerLink
+ * with a matching name
+ *
+ * @param partnerLinks
+ * @param partnerLinkName
+ */
+ private BPELPartnerLinkElement findPartnerLinkByName(List<BPELPartnerLinkElement> partnerLinks, String partnerLinkName) {
+ // Scan the list looking for a partner link with the supplied name
+ Iterator<BPELPartnerLinkElement> it = partnerLinks.iterator();
+ while (it.hasNext()) {
+ BPELPartnerLinkElement thePartnerLink = it.next();
+ if (thePartnerLink.getName().equals(partnerLinkName))
+ return thePartnerLink;
+ }
+ return null;
+ } // end method findPartnerLinkByName
+
+ /**
+ * Report a warning.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void warning(Monitor monitor, String message, Object model, Object... messageParameters) {
+ if (monitor != null) {
+ Problem problem = monitor.createProblem(this.getClass().getName(), "impl-bpel-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
+ /**
+ * Report a error.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(Monitor monitor, String message, Object model, Object... messageParameters) {
+ if (monitor != null) {
+ Problem problem = monitor.createProblem(this.getClass().getName(), "impl-bpel-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
+ /**
+ * Report a exception.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(Monitor monitor, String message, Object model, Exception ex) {
+ if (monitor != null) {
+ Problem problem = monitor.createProblem(this.getClass().getName(), "impl-bpel-validation-messages", Severity.ERROR, model, message, ex);
+ monitor.problem(problem);
+ }
+ }
+}
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELImplementationProcessor.java b/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELImplementationProcessor.java
new file mode 100644
index 0000000000..c149d228c6
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELImplementationProcessor.java
@@ -0,0 +1,452 @@
+/*
+ * 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.bpel.xml;
+
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Collection;
+import java.util.List;
+
+import javax.wsdl.PortType;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.ComponentType;
+import org.apache.tuscany.sca.assembly.Multiplicity;
+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.BaseStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
+import org.apache.tuscany.sca.contribution.processor.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.processor.ContributionWriteException;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+import org.apache.tuscany.sca.implementation.bpel.BPELFactory;
+import org.apache.tuscany.sca.implementation.bpel.BPELImplementation;
+import org.apache.tuscany.sca.implementation.bpel.BPELProcessDefinition;
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition;
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory;
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface;
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterfaceContract;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+
+/**
+ * Implements a StAX artifact processor for BPEL implementations.
+ *
+ * The artifact processor is responsible for processing <implementation.bpel>
+ * elements in SCA assembly XML composite files and populating the BPEL
+ * implementation model, resolving its references to other artifacts in the SCA
+ * contribution, and optionally write the model back to SCA assembly XML.
+ *
+ * @version $Rev$ $Date$
+ */
+public class BPELImplementationProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<BPELImplementation> {
+ private static final String SCA11_NS = "http://docs.oasis-open.org/ns/opencsa/sca/200912";
+ private static final String PROCESS = "process";
+ private static final String IMPLEMENTATION_BPEL = "implementation.bpel";
+ private static final QName IMPLEMENTATION_BPEL_QNAME = new QName(SCA11_NS, IMPLEMENTATION_BPEL);
+
+ private AssemblyFactory assemblyFactory;
+ private BPELFactory bpelFactory;
+ private WSDLFactory wsdlFactory;
+
+
+ public BPELImplementationProcessor(FactoryExtensionPoint modelFactories) {
+ this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class);
+ this.wsdlFactory = modelFactories.getFactory(WSDLFactory.class);
+ this.bpelFactory = modelFactories.getFactory(BPELFactory.class);
+ }
+
+ public QName getArtifactType() {
+ // Returns the QName of the XML element processed by this processor
+ return IMPLEMENTATION_BPEL_QNAME;
+ }
+
+ public Class<BPELImplementation> getModelType() {
+ // Returns the type of model processed by this processor
+ return BPELImplementation.class;
+ }
+
+ public BPELImplementation read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException {
+ assert IMPLEMENTATION_BPEL_QNAME.equals(reader.getName());
+
+ // Read an <implementation.bpel> element
+ BPELImplementation implementation = null;
+
+ // Read the process attribute.
+ QName process = getAttributeValueNS(reader, PROCESS, context.getMonitor());
+ if (process == null) {
+ return implementation;
+ }
+
+ // Create and initialize the BPEL implementation model
+ implementation = bpelFactory.createBPELImplementation();
+ implementation.setProcess(process);
+ implementation.setUnresolved(true);
+
+ // Skip to end element
+ while (reader.hasNext()) {
+ if (reader.next() == END_ELEMENT && IMPLEMENTATION_BPEL_QNAME.equals(reader.getName())) {
+ break;
+ }
+ }
+
+ return implementation;
+ }
+
+ public void resolve(BPELImplementation implementation, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException {
+
+ if( implementation != null && implementation.isUnresolved())
+ {
+ implementation.setModelResolver(resolver);
+
+ BPELProcessDefinition processDefinition = resolveBPELProcessDefinition(implementation, resolver, context);
+ //resolveBPELImports(processDefinition, resolver);
+ if(processDefinition.isUnresolved()) {
+ error(context.getMonitor(), "BPELProcessNotFound", implementation, processDefinition.getName());
+ } else {
+ implementation.setProcessDefinition(processDefinition);
+
+ // Get the component type from the process definition
+ generateComponentType( implementation, context.getMonitor() );
+
+ //set current implementation resolved
+ implementation.setUnresolved(false);
+ }
+ }
+
+ } // end resolve
+
+ public void write( BPELImplementation bpelImplementation,
+ XMLStreamWriter writer, ProcessorContext context ) throws ContributionWriteException, XMLStreamException {
+ //FIXME Deal with policy processing...
+ // Write <implementation.bpel process="..."/>
+ // policyProcessor.writePolicyPrefixes(bpelImplementation, writer);
+ writer.writeStartElement(SCA11_NS, IMPLEMENTATION_BPEL);
+ // policyProcessor.writePolicyAttributes(bpelImplementation, writer);
+
+ if (bpelImplementation.getProcess() != null) {
+ writer.writeAttribute(PROCESS, bpelImplementation.getProcess().toString() );
+ }
+
+ writer.writeEndElement();
+
+ } // end write
+
+ private BPELProcessDefinition resolveBPELProcessDefinition(BPELImplementation impl, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException {
+ QName processName = impl.getProcess();
+ BPELProcessDefinition processDefinition = this.bpelFactory.createBPELProcessDefinition();
+ processDefinition.setName(processName);
+ processDefinition.setUnresolved(true);
+
+ return resolver.resolveModel(BPELProcessDefinition.class, processDefinition, context);
+ } // end resolveBPELProcessDefinition
+
+ private void resolveBPELImports(BPELProcessDefinition processDefinition, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException {
+ for (BPELImportElement bpelImport : processDefinition.getImports()) {
+ String namespace = bpelImport.getNamespace();
+ String location = bpelImport.getLocation();
+
+ WSDLDefinition wsdl = bpelImport.getWSDLDefinition();
+ if (wsdl == null) {
+ try {
+ wsdl = wsdlFactory.createWSDLDefinition();
+ wsdl.setUnresolved(true);
+ wsdl.setNamespace(bpelImport.getNamespace());
+ wsdl.setLocation(new URI(null, bpelImport.getLocation(), null));
+ wsdl = resolver.resolveModel(WSDLDefinition.class, wsdl, context);
+
+ if(! wsdl.isUnresolved()) {
+ bpelImport.setWSDLDefinition(wsdl);
+ } else {
+ //error("BPELProcessNotFound", implementation, processDefinition.getName());
+ }
+ } catch (URISyntaxException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+
+ }
+ }
+
+
+ /**
+ * Calculates the component type of the supplied implementation and attaches it to the
+ * implementation.
+ *
+ * @param impl
+ * @throws ContributionResolveException
+ */
+ private void generateComponentType(BPELImplementation impl, Monitor monitor) throws ContributionResolveException {
+
+ // Create a ComponentType and mark it unresolved
+ ComponentType componentType = assemblyFactory.createComponentType();
+ componentType.setUnresolved(true);
+ impl.setComponentType(componentType);
+
+ // Each partner link in the process represents either a service or a reference
+ // - or both, in the sense of involving a callback
+ BPELProcessDefinition theProcess = impl.getProcessDefinition();
+ List<BPELPartnerLinkElement> partnerLinks = theProcess.getPartnerLinks();
+
+ for (BPELPartnerLinkElement pLink : partnerLinks) {
+
+ // check that the partner link has been designated as service or
+ // reference in SCA terms
+ if (pLink.isSCATyped()) {
+ String scaName = pLink.getSCAName();
+ if (pLink.querySCAType().equals("reference")) {
+ componentType.getReferences().add(generateReference(scaName, pLink.getMyRolePortType(), pLink.getPartnerRolePortType(), theProcess.getInterfaces(), monitor));
+ } else {
+ componentType.getServices().add(generateService(scaName, pLink.getMyRolePortType(), pLink.getPartnerRolePortType(), theProcess.getInterfaces(), monitor));
+ } // end if
+ } // end if
+ } // end for
+
+ // Each SCA Property in the process becomes a Property in the ComponentType
+ for( Property property : theProcess.getProperties() ) {
+ componentType.getProperties().add(property);
+ } // end for
+
+ } // end getComponentType
+
+ /**
+ * Create an SCA reference for a partnerLink
+ * @param name - name of the reference
+ * @param myRolePT - partner link type of myRole
+ * @param partnerRolePT - partner link type of partnerRole
+ * @param theInterfaces - list of WSDL interfaces associated with the BPEL process
+ * @return
+ */
+ private Reference generateReference( String name, PortType myRolePT,
+ PortType partnerRolePT, Collection<WSDLInterface> theInterfaces, Monitor monitor) throws ContributionResolveException {
+
+ Reference reference = assemblyFactory.createReference();
+ WSDLInterfaceContract interfaceContract = wsdlFactory.createWSDLInterfaceContract();
+ reference.setInterfaceContract(interfaceContract);
+
+ // Establish whether there is just a call interface or a call + callback interface
+ PortType callPT = null;
+ PortType callbackPT = null;
+ if (partnerRolePT != null) {
+ callPT = partnerRolePT;
+ // If the 2 port types are not the same one, there is a callback...
+ if (myRolePT != null) {
+ if (!myRolePT.getQName().equals(partnerRolePT.getQName())) {
+ callbackPT = myRolePT;
+ } // end if
+ } // end if
+ } else if (myRolePT != null) {
+ callPT = myRolePT;
+ } // end if
+
+ // No interfaces mean an error
+ if (callPT == null && callbackPT == null) {
+ error(monitor, "MyRolePartnerRoleNull", theInterfaces);
+ } // end if
+
+ // Set the name of the reference to the supplied name and the
+ // multiplicity of the reference to 1..1
+ // TODO: support other multiplicities
+ reference.setName(name);
+ reference.setMultiplicity(Multiplicity.ONE_ONE);
+
+ if (callPT != null) {
+ // Set the call interface and, if present, the callback interface
+ WSDLInterface callInterface = null;
+ for (WSDLInterface anInterface : theInterfaces) {
+ if (anInterface.getPortType().getQName().equals(callPT.getQName()))
+ callInterface = anInterface;
+ } // end for
+ if (callInterface == null) {
+ error(monitor, "NoInterfaceForPortType", theInterfaces, callPT.getQName().toString());
+ } else
+ reference.getInterfaceContract().setInterface(callInterface);
+ } // end if
+
+ // There is a callback if the partner role is not null and if the
+ // partner role port type is not the same as the port type for my role
+ if (callbackPT != null) {
+ WSDLInterface callbackInterface = null;
+ for (WSDLInterface anInterface : theInterfaces) {
+ if (anInterface.getPortType().getQName().equals(callbackPT.getQName()))
+ callbackInterface = anInterface;
+ } // end for
+ if (callbackInterface == null) {
+ error(monitor, "NoInterfaceForPortType", theInterfaces, callbackPT.getQName().toString());
+ } else
+ reference.getInterfaceContract().setCallbackInterface(callbackInterface);
+ } // end if
+
+ return reference;
+ } // end generateReference
+
+ /**
+ * Create an SCA service for a partnerLink
+ * @param name - name of the service
+ * @param myRolePT - partner link type of myRole
+ * @param partnerRolePT - partner link type of partnerRole
+ * @param theInterfaces - list of WSDL interfaces associated with the BPEL process
+ * @return
+ */
+ private Service generateService( String name, PortType myRolePT,
+ PortType partnerRolePT, Collection<WSDLInterface> theInterfaces, Monitor monitor )
+ throws ContributionResolveException {
+ Service service = assemblyFactory.createService();
+ WSDLInterfaceContract interfaceContract = wsdlFactory.createWSDLInterfaceContract();
+ service.setInterfaceContract(interfaceContract);
+
+ // Set the name of the service to the supplied name
+ service.setName(name);
+
+ // Establish whether there is just a call interface or a call + callback
+ // interface
+ PortType callPT = null;
+ PortType callbackPT = null;
+ if (myRolePT != null) {
+ callPT = myRolePT;
+ // If the 2 port types are not the same one, there is a callback...
+ if (partnerRolePT != null) {
+ if (!myRolePT.getQName().equals(partnerRolePT.getQName())) {
+ callbackPT = partnerRolePT;
+ } // end if
+ } // end if
+ } else if (partnerRolePT != null) {
+ callPT = partnerRolePT;
+ } // end if
+
+ // No interfaces mean an error
+ if (callPT == null && callbackPT == null) {
+ error(monitor, "MyRolePartnerRoleNull", theInterfaces);
+ } // end if
+
+ if (callPT != null) {
+ // Set the call interface and, if present, the callback interface
+ WSDLInterface callInterface = null;
+ for (WSDLInterface anInterface : theInterfaces) {
+ if (anInterface.getPortType().getQName().equals(callPT.getQName()))
+ callInterface = anInterface;
+ } // end for
+ if (callInterface == null) {
+ error(monitor, "NoInterfaceForPortType", theInterfaces, callPT.getQName().toString());
+ } else
+ service.getInterfaceContract().setInterface(callInterface);
+ } // end if
+
+ // There is a callback if the partner role is not null and if the
+ // partner role port type is not the same as the port type for my role
+ if (callbackPT != null) {
+ WSDLInterface callbackInterface = null;
+ for (WSDLInterface anInterface : theInterfaces) {
+ if (anInterface.getPortType().getQName().equals(callbackPT.getQName()))
+ callbackInterface = anInterface;
+ } // end for
+ if (callbackInterface == null) {
+ error(monitor, "NoInterfaceForPortType", theInterfaces, callbackPT.getQName().toString());
+ } else
+ service.getInterfaceContract().setCallbackInterface(callbackInterface);
+ } // end if
+
+ return service;
+ } // end generateService
+
+ /**
+ * Returns a QName from its string representation in a named attribute of an XML element
+ * supplied in an XMLStreamReader
+ *
+ * QName attributes of an XML element (such as BPEL process) is presented in one of
+ * two alternative formats:
+ * 1) In the form of a local name with a prefix, with the prefix referencing a namespace
+ * URI declaration elsewhere in the composite (typically on the composite element)
+ *
+ * ie: nms:SomeName
+ * xmlns:nms="http://example.com/somenamespace"
+ *
+ * 2) In the XML Namespaces recommendation format (see http://jclark.com/xml/xmlns.htm )
+ * where the namespace URI and the local name are encoded into a single string, with the
+ * namespace URI enclosed between a pair of braces {...}
+ *
+ * ie: {http://example.com/somenamespace}SomeName
+ */
+ private QName getAttributeValueNS(XMLStreamReader reader, String attribute, Monitor monitor) {
+ String fullValue = reader.getAttributeValue(null, attribute);
+ if (fullValue == null) {
+ error(monitor, "AttributeProcessMissing", reader);
+ return null;
+ }
+
+ // Deal with the attribute in the XML Namespaces recommendation format
+ // - trim off any leading/trailing spaces and check that the first
+ // character is '{'
+ if (fullValue.trim().charAt(0) == '{') {
+ try {
+ // Attempt conversion to a QName object
+ QName theProcess = QName.valueOf(fullValue);
+ return theProcess;
+ } catch (IllegalArgumentException e) {
+ // This exception happens if the attribute begins with '{' but
+ // doesn't conform
+ // to the XML Namespaces recommendation format
+ error(monitor, "AttributeWithoutNamespace", reader, attribute, fullValue);
+ return null;
+ }
+ } // endif
+
+ // Deal with the attribute in the local name + prefix format
+ if (fullValue.indexOf(":") < 0) {
+ error(monitor, "AttributeWithoutPrefix", reader, attribute, fullValue);
+ return null;
+ }
+ String prefix = fullValue.substring(0, fullValue.indexOf(":"));
+ String name = fullValue.substring(fullValue.indexOf(":") + 1);
+ String nsUri = reader.getNamespaceContext().getNamespaceURI(prefix);
+ if (nsUri == null) {
+ error(monitor, "AttributeUnrecognizedNamespace", reader, attribute, fullValue);
+ return null;
+ }
+ return new QName(nsUri, name, prefix);
+ }
+
+ /**
+ * Report a error.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(Monitor monitor, String message, Object model, Object... messageParameters) {
+ if (monitor != null) {
+ Problem problem = monitor.createProblem(this.getClass().getName(), "impl-bpel-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELImportElement.java b/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELImportElement.java
new file mode 100644
index 0000000000..959d1ec5d5
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELImportElement.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.bpel.xml;
+
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition;
+
+/**
+ * Represents an <import.../> element in a BPEL process
+ * - this has attributes:
+ * location
+ * importType
+ * namespace
+ *
+ * @version $Rev$ $Date$
+ */
+public class BPELImportElement {
+
+ private String location;
+ private String importType;
+ private String namespace;
+ private WSDLDefinition theWSDL = null;
+
+ public BPELImportElement(String location, String importType, String namespace) {
+ this.location = location;
+ this.importType = importType;
+ this.namespace = namespace;
+ }
+
+ public String getImportType() {
+ return importType;
+ }
+
+ public String getLocation() {
+ return location;
+ }
+
+ public String getNamespace() {
+ return namespace;
+ }
+
+ public void setWSDLDefinition(WSDLDefinition theDefinition) {
+ theWSDL = theDefinition;
+ }
+
+ public WSDLDefinition getWSDLDefinition() {
+ return theWSDL;
+ }
+
+} // end class BPELImportElement
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELPartnerLinkElement.java b/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELPartnerLinkElement.java
new file mode 100644
index 0000000000..ea645e1304
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELPartnerLinkElement.java
@@ -0,0 +1,132 @@
+/*
+ * 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.bpel.xml;
+
+import javax.wsdl.PortType;
+import javax.xml.namespace.QName;
+
+/**
+ * Represents a <partnerLink.../> element in a BPEL process
+ * - this has attributes:
+ * name
+ * partnerLinkType
+ * myRole
+ * partnerRole
+ * - plus zero or more property elements as children
+ *
+ * The partnerlink may also be given an SCA Type - either of service or of reference - this must
+ * generally be calculated and set on the partnerLink by inspecting the BPEL process
+ *
+ * @version $Rev$ $Date$
+ */
+public class BPELPartnerLinkElement {
+
+ private String REFERENCE_TYPE = "reference";
+ private String SERVICE_TYPE = "service";
+ private String name;
+ private QName partnerLinkType;
+ private BPELPartnerLinkTypeElement pLinkType = null;
+ private String myRole;
+ private String partnerRole;
+ private String scaName; // Holds the SCA reference or service name
+ private String scaType = null; // Holds the SCA type = null | service | reference
+
+ public BPELPartnerLinkElement(String name,
+ QName partnerLinkType,
+ String myRole,
+ String partnerRole ) {
+ this.name = name;
+ this.partnerLinkType = partnerLinkType;
+ this.myRole = myRole;
+ this.partnerRole = partnerRole;
+
+ scaName = null;
+ }
+
+ public QName getPartnerLinkType() {
+ return partnerLinkType;
+ }
+
+ public void setPartnerLinkType( BPELPartnerLinkTypeElement pLinkType ) {
+ this.pLinkType = pLinkType;
+ }
+
+
+ public PortType getMyRolePortType() {
+ return getRolePortType( myRole );
+ }
+
+ public PortType getPartnerRolePortType() {
+ return getRolePortType( partnerRole );
+ }
+
+ private PortType getRolePortType( String theRole ) {
+ if (theRole == null || theRole.length() == 0) {
+ return null;
+ } // end if
+ if( pLinkType == null ) {
+ throw new IllegalStateException("BPELPartnerLinkElement: " + this.name + " has no Partner Link type object set");
+ } // end if
+ if (theRole.equals(pLinkType.getRole1Name())) {
+ return pLinkType.getRole1pType();
+ } else if (theRole.equals(pLinkType.getRole2Name())) {
+ return pLinkType.getRole2pType();
+ } // end if
+ return null;
+ } // end getRolePortType
+
+ public String getName() {
+ return name;
+ }
+
+ public String getMyRole() {
+ return myRole;
+ }
+
+ public String getPartnerRole() {
+ return partnerRole;
+ }
+
+ public void setSCAName( String name ) {
+ scaName = name;
+ }
+
+ public String getSCAName() {
+ return scaName;
+ }
+
+ public boolean isSCATyped() {
+ return ( !(scaType == null) );
+ }
+
+ public void setAsReference( String name ) {
+ scaType = REFERENCE_TYPE;
+ scaName = name;
+ }
+
+ public void setAsService( String name ) {
+ scaType = SERVICE_TYPE;
+ scaName = name;
+ }
+
+ public String querySCAType() {
+ return scaType;
+ }
+
+} // end class BPELPartnerLinkElement
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELPartnerLinkTypeElement.java b/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELPartnerLinkTypeElement.java
new file mode 100644
index 0000000000..8786837e97
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELPartnerLinkTypeElement.java
@@ -0,0 +1,118 @@
+/*
+ * 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.bpel.xml;
+
+ import javax.wsdl.PortType;
+import javax.wsdl.extensions.ExtensibilityElement;
+import javax.xml.namespace.QName;
+
+/**
+ * Represents a <partnerLinkType.../> element related to a BPEL process
+ * - this has attributes:
+ * name
+ * Role1 name
+ * Role1 portType
+ * Role2 name
+ * Role2 portType
+ *
+ * - in the XML the 2 roles are child elements of the partnerLinkType element, but there
+ * seems little point in reflecting this back into this model - it is simpler to include
+ * both roles within the representation of the partnerLinkType itself
+ *
+ * @version $Rev$ $Date$
+ */
+public class BPELPartnerLinkTypeElement implements ExtensibilityElement {
+
+ private QName name;
+ private String Role1name = null;
+ private QName Role1porttype = null;
+ private PortType Role1pType = null;
+ private String Role2name = null;
+ private QName Role2porttype = null;
+ private PortType Role2pType = null;
+ private QName elementType = null;
+ private Boolean required = false;
+
+ public BPELPartnerLinkTypeElement(QName name) {
+ this.name = name;
+ }
+
+ public QName getName() {
+ return name;
+ }
+
+ public void setRole1(String name, QName portType, PortType pType) {
+ Role1name = name;
+ Role1porttype = portType;
+ Role1pType = pType;
+ }
+
+ public void setRole2(String name, QName portType, PortType pType) {
+ Role2name = name;
+ Role2porttype = portType;
+ Role2pType = pType;
+ }
+
+ public String getRole1Name() {
+ return Role1name;
+ }
+
+ public String getRole2Name() {
+ return Role2name;
+ }
+
+ public QName getRole1PortType() {
+ return Role1porttype;
+ }
+
+ public QName getRole2PortType() {
+ return Role2porttype;
+ }
+
+ public PortType getRole1pType() {
+ return Role1pType;
+ }
+
+ public PortType getRole2pType() {
+ return Role2pType;
+ }
+
+ public QName getElementType() {
+ return elementType;
+ }
+
+ public Boolean getRequired() {
+ return required;
+ }
+
+ public void setElementType(QName elementType) {
+ this.elementType = elementType;
+ }
+
+ public void setRequired(java.lang.Boolean required) {
+ this.required = required;
+ }
+
+ /**
+ * toString method to return a description of this BPELPartnerLinkType useful for debugging
+ */
+ public String toString() {
+ return "BPELPartnerLinkType: " + name.toString();
+ } // end method toString
+
+} // end BPELPartnerLinkType
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELProcessorConstants.java b/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELProcessorConstants.java
new file mode 100644
index 0000000000..952ba9fe78
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELProcessorConstants.java
@@ -0,0 +1,61 @@
+/*
+ * 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.bpel.xml;
+
+import javax.xml.namespace.QName;
+
+
+/**
+ * BPEL Constants
+ *
+ * @version $Rev$ $Date$
+ */
+public class BPELProcessorConstants {
+ static final String SCA_BPEL_NS = "http://docs.oasis-open.org/ns/opencsa/sca-bpel/200801";
+ static final String WSDL_NS = "http://schemas.xmlsoap.org/wsdl/";
+
+ // BPEL 1.1
+ static final String BPEL_NS = "http://schemas.xmlsoap.org/ws/2004/03/business-process/";
+ static final String BPEL_PLINK_NS = "http://schemas.xmlsoap.org/ws/2004/03/partner-link/";
+ final static String NAME_ELEMENT = "name";
+ static final String LINKTYPE_NAME = "partnerLinkType";
+ final static String TARGET_NAMESPACE = "targetNamespace";
+ static final QName PROCESS_ELEMENT = new QName(BPEL_NS, "process");
+ static final QName PARTNERLINK_ELEMENT = new QName(BPEL_NS, "partnerLink");
+ static final QName ONEVENT_ELEMENT = new QName(BPEL_NS, "onEvent");
+ static final QName RECEIVE_ELEMENT = new QName(BPEL_NS, "receive");
+ static final QName ONMESSAGE_ELEMENT = new QName(BPEL_NS, "onMessage");
+ static final QName INVOKE_ELEMENT = new QName(BPEL_NS, "invoke");
+ static final QName IMPORT_ELEMENT = new QName(BPEL_NS, "import");
+ static final QName VARIABLE_ELEMENT = new QName(BPEL_NS, "variable");
+ static final QName LINKTYPE_ELEMENT = new QName(BPEL_PLINK_NS, LINKTYPE_NAME);
+
+ // BPEL 2.0
+ static final String BPEL_NS_20 = "http://docs.oasis-open.org/wsbpel/2.0/process/executable";
+ static final String BPEL_PLINK_NS_20 = "http://docs.oasis-open.org/wsbpel/2.0/plnktype";
+ static final QName PROCESS_ELEMENT_20 = new QName(BPEL_NS_20, "process");
+ static final QName PARTNERLINK_ELEMENT_20 = new QName(BPEL_NS_20, "partnerLink");
+ static final QName ONEVENT_ELEMENT_20 = new QName(BPEL_NS_20, "onEvent");
+ static final QName RECEIVE_ELEMENT_20 = new QName(BPEL_NS_20, "receive");
+ static final QName ONMESSAGE_ELEMENT_20 = new QName(BPEL_NS_20, "onMessage");
+ static final QName INVOKE_ELEMENT_20 = new QName(BPEL_NS_20, "invoke");
+ static final QName IMPORT_ELEMENT_20 = new QName(BPEL_NS_20, "import");
+ static final QName VARIABLE_ELEMENT_20 = new QName(BPEL_NS_20, "variable");
+ static final QName LINKTYPE_ELEMENT_20 = new QName(BPEL_PLINK_NS_20, LINKTYPE_NAME);
+}
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
new file mode 100644
index 0000000000..ffb781d3b4
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Implementation class for the artifact processor extension
+org.apache.tuscany.sca.implementation.bpel.xml.BPELImplementationProcessor;qname=http://docs.oasis-open.org/ns/opencsa/sca/200912#implementation.bpel,model=org.apache.tuscany.sca.implementation.bpel.BPELImplementation
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor b/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor
new file mode 100644
index 0000000000..1e11d2fc0c
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Implementation class for the artifact processor extension
+org.apache.tuscany.sca.implementation.bpel.xml.BPELDocumentProcessor;type=.bpel,model=org.apache.tuscany.sca.implementation.bpel.BPELProcessDefinition
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver b/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver
new file mode 100644
index 0000000000..d5b5b15984
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.implementation.bpel.xml.BPELDocumentModelResolver;model=org.apache.tuscany.sca.implementation.bpel.BPELProcessDefinition
+
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.bpel.BPELFactory b/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.bpel.BPELFactory
new file mode 100644
index 0000000000..34af3316d5
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.bpel.BPELFactory
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.implementation.bpel.impl.BPELFactoryImpl
+
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/resources/impl-bpel-validation-messages.properties b/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/resources/impl-bpel-validation-messages.properties
new file mode 100644
index 0000000000..419f7a8c15
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/main/resources/impl-bpel-validation-messages.properties
@@ -0,0 +1,34 @@
+#
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#
+CannotResolveWSDLReference = BPELDocumentProcessor:resolve - unable to resolve WSDL referenced by BPEL import WSDL location: {0} WSDLNamespace: {1}
+ContributionReadException = ContributionReadException occured due to :
+PartnerLinkNoMatchingType = PartnerLink {0} has no matching partner link type
+PartnerLinkTypeNoRoles = PartnerLinkType {0} has no Roles defined
+ContributionResolveException = ContributionResolveException occured due to :
+PartnerLinkHasBothAttr = BPEL PartnerLink {0} has both sca:reference and sca:service attributes set
+ReferencePartnerLinkNotInList = BPEL TypeLoader - element references partnerLink {0} not in the list
+MyRolePartnerRoleNull = Error: myRole and partnerRole port types are both null
+NoInterfaceForPortType = Interface not found for port type {0}
+AttributeProcessMissing = Attribute ''process'' is missing.
+AttributeWithoutNamespace = Attribute {0} with value {1} in your composite should be of the form {namespaceURI}localname
+AttributeWithoutPrefix = Attribute {0} with value {1} in your composite should be prefixed (process=\"prefix:name\").
+AttributeUnrecognizedNamespace = Attribute {0} with value {1} in your composite has un unrecognized namespace prefix.
+BPELProcessNotFound = Can''t find BPEL Process : {0}
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELDocumentProcessorTestCase.java b/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELDocumentProcessorTestCase.java
new file mode 100644
index 0000000000..1ef972342a
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELDocumentProcessorTestCase.java
@@ -0,0 +1,62 @@
+/*
+ * 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.bpel;
+
+import java.net.URI;
+import java.net.URL;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class BPELDocumentProcessorTestCase extends TestCase {
+
+ protected static final String BPEL_PROCESS_FILE = "helloworld/helloworld.bpel";
+
+ private URLArtifactProcessor<Object> documentProcessor;
+ private ProcessorContext context;
+
+ @Override
+ protected void setUp() throws Exception {
+ DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ context = new ProcessorContext(extensionPoints);
+ URLArtifactProcessorExtensionPoint documentProcessors = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
+ documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors);
+ }
+
+ public void testLoadBPELProcessDefinition() throws Exception {
+ URI processURI = getClass().getClassLoader().getResource(BPEL_PROCESS_FILE).toURI();
+ URL processLocation = getClass().getClassLoader().getResource(BPEL_PROCESS_FILE);
+ BPELProcessDefinition bpelProcessDefinition = (BPELProcessDefinition)documentProcessor.read(null, processURI, processLocation, context);
+
+ assertNotNull(bpelProcessDefinition);
+ assertEquals(new QName("http://tuscany.apache.org/implementation/bpel/example/helloworld", "HelloWorld"), bpelProcessDefinition.getName());
+ assertEquals(processLocation.toString(), bpelProcessDefinition.getLocation());
+ }
+}
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELImplementationProcessorTestCase.java b/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELImplementationProcessorTestCase.java
new file mode 100644
index 0000000000..37e5660636
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELImplementationProcessorTestCase.java
@@ -0,0 +1,102 @@
+/*
+ * 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.bpel;
+
+import java.io.StringReader;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.monitor.Problem;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class BPELImplementationProcessorTestCase extends TestCase {
+
+ private static final String COMPOSITE =
+ "<?xml version=\"1.0\" encoding=\"ASCII\"?>"
+ + "<composite xmlns=\"http://docs.oasis-open.org/ns/opencsa/sca/200912\" xmlns:hns=\"http://tuscany.apache.org/implementation/bpel/example/helloworld\" targetNamespace=\"http://bpel\" name=\"bpel\">"
+ + " <component name=\"BPELHelloWorldComponent\">"
+ + " <implementation.bpel process=\"hns:HelloWorld\" />"
+ + " </component>"
+ + "</composite>";
+
+ private static final String COMPOSITE_INVALID =
+ "<?xml version=\"1.0\" encoding=\"ASCII\"?>"
+ + "<composite xmlns=\"http://docs.oasis-open.org/ns/opencsa/sca/200912\" xmlns:hns=\"http://tuscany.apache.org/implementation/bpel/example/helloworld\" targetNamespace=\"http://bpel\" name=\"bpel\">"
+ + " <component name=\"BPELHelloWorldComponent\">"
+ + " <implementation.bpel/>"
+ + " </component>"
+ + "</composite>";
+
+ private XMLInputFactory inputFactory;
+ private StAXArtifactProcessor<Object> staxProcessor;
+ private ProcessorContext context;
+
+ @Override
+ protected void setUp() throws Exception {
+ DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ context = new ProcessorContext(extensionPoints);
+ inputFactory = XMLInputFactory.newInstance();
+ // Create a monitor
+ UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
+
+ StAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints);
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null);
+ }
+
+ /**
+ * Test parsing valid composite definition. Valid composite populated with correct values expected.
+ * @throws Exception
+ */
+ public void testLoadValidComposite() throws Exception {
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(COMPOSITE));
+
+ Composite composite = (Composite)staxProcessor.read(reader, context);
+ BPELImplementation implementation = (BPELImplementation)composite.getComponents().get(0).getImplementation();
+
+ assertNotNull(implementation);
+ assertEquals(new QName("http://tuscany.apache.org/implementation/bpel/example/helloworld", "HelloWorld"), implementation.getProcess());
+ }
+
+ /**
+ * Test parsing invalid composite definition. Exception should be thrown
+ * @throws Exception
+ */
+ public void testLoadInvalidComposite() throws Exception {
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(COMPOSITE_INVALID));
+ staxProcessor.read(reader, context);
+ Problem problem = context.getMonitor().getLastProblem();
+ assertNotNull(problem);
+ assertEquals("AttributeProcessMissing", problem.getMessageId());
+ }
+}
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/test/resources/helloworld/helloworld.bpel b/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/test/resources/helloworld/helloworld.bpel
new file mode 100644
index 0000000000..8cf91adc2c
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/test/resources/helloworld/helloworld.bpel
@@ -0,0 +1,66 @@
+<!--
+ ~ 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.
+ -->
+<process name="HelloWorld"
+ targetNamespace="http://tuscany.apache.org/implementation/bpel/example/helloworld"
+ xmlns="http://schemas.xmlsoap.org/ws/2004/03/business-process/"
+ xmlns:bpws="http://schemas.xmlsoap.org/ws/2004/03/business-process/"
+ xmlns:tns="http://tuscany.apache.org/implementation/bpel/example/helloworld"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:test="http://tuscany.apache.org/implementation/bpel/example/helloworld.wsdl"
+ queryLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xpath2.0"
+ expressionLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xpath2.0">
+
+ <import location="helloworld.wsdl" importType="http://schemas.xmlsoap.org/wsdl/"
+ namespace="http://tuscany.apache.org/implementation/bpel/example/helloworld.wsdl"/>
+
+ <partnerLinks>
+ <partnerLink name="helloPartnerLink" partnerLinkType="test:HelloPartnerLinkType" myRole="me" />
+ </partnerLinks>
+
+ <variables>
+ <variable name="helloMessage" messageType="test:HelloMessage"/>
+ <variable name="tmpVar" type="xsd:string"/>
+ </variables>
+
+ <sequence>
+ <receive
+ name="start"
+ partnerLink="helloPartnerLink"
+ portType="test:HelloPortType"
+ operation="hello"
+ variable="helloMessage"
+ createInstance="yes"/>
+
+ <assign name="assign1">
+ <copy>
+ <from variable="helloMessage" part="TestPart"/>
+ <to variable="tmpVar"/>
+ </copy>
+ <copy>
+ <from>concat($tmpVar,' World')</from>
+ <to variable="helloMessage" part="TestPart"/>
+ </copy>
+ </assign>
+ <reply name="end"
+ partnerLink="helloPartnerLink"
+ portType="test:HelloPortType"
+ operation="hello"
+ variable="helloMessage"/>
+ </sequence>
+</process>
diff --git a/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/test/resources/helloworld/helloworld.wsdl b/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/test/resources/helloworld/helloworld.wsdl
new file mode 100644
index 0000000000..610bda3cc4
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/implementation-bpel/src/test/resources/helloworld/helloworld.wsdl
@@ -0,0 +1,82 @@
+<?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.
+ -->
+
+<wsdl:definitions name="helloworld"
+ targetNamespace="http://tuscany.apache.org/implementation/bpel/example/helloworld.wsdl"
+ xmlns="http://schemas.xmlsoap.org/wsdl/"
+ xmlns:tns="http://tuscany.apache.org/implementation/bpel/example/helloworld.wsdl"
+ xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+ xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
+ xmlns:bpws="http://schemas.xmlsoap.org/ws/2004/03/business-process/"
+ xmlns:plnk="http://schemas.xmlsoap.org/ws/2004/03/partner-link/">
+
+ <wsdl:types>
+ <schema elementFormDefault="qualified"
+ targetNamespace="http://tuscany.apache.org/implementation/bpel/example/helloworld.wsdl"
+ xmlns="http://www.w3.org/2001/XMLSchema">
+
+ <element name="hello">
+ <complexType>
+ <sequence>
+ <element name="message" type="xsd:string"/>
+ </sequence>
+ </complexType>
+ </element>
+ </schema>
+ </wsdl:types>
+
+ <wsdl:message name="HelloMessage">
+ <wsdl:part element="tns:hello" name="TestPart"/>
+ </wsdl:message>
+
+ <wsdl:portType name="HelloPortType">
+ <wsdl:operation name="hello">
+ <wsdl:input message="tns:HelloMessage" name="TestIn"/>
+ <wsdl:output message="tns:HelloMessage" name="TestOut"/>
+ </wsdl:operation>
+ </wsdl:portType>
+
+
+ <wsdl:binding name="HelloSoapBinding" type="tns:HelloPortType">
+ <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
+ <wsdl:operation name="hello">
+ <wsdlsoap:operation soapAction=""/>
+ <wsdl:input name="TestIn">
+ <wsdlsoap:body use="literal"/>
+ </wsdl:input>
+ <wsdl:output name="TestOut">
+ <wsdlsoap:body use="literal"/>
+ </wsdl:output>
+ </wsdl:operation>
+ </wsdl:binding>
+
+ <wsdl:service name="HelloService">
+ <wsdl:port name="HelloPort" binding="tns:HelloSoapBinding">
+ <soap:address location="http://localhost:8085/ode/processes/helloWorld"/>
+ </wsdl:port>
+ </wsdl:service>
+
+ <plnk:partnerLinkType name="HelloPartnerLinkType">
+ <plnk:role name="me" portType="tns:HelloPortType"/>
+ <plnk:role name="you" portType="tns:HelloPortType"/>
+ </plnk:partnerLinkType>
+</wsdl:definitions> \ No newline at end of file