diff options
author | huangjian <huang.jian12@zte.com.cn> | 2016-08-31 16:47:33 +0800 |
---|---|---|
committer | huangjian <huang.jian12@zte.com.cn> | 2016-08-31 16:47:33 +0800 |
commit | fa49e78cc199526a9e33b59c5194f8e3bf0f0952 (patch) | |
tree | 3478e867a8f304266dbceca6e992cceca410ede4 /winery/org.eclipse.winery.common | |
parent | 159d40f0011559c8f82338b29dca1bffd700f2c8 (diff) |
Add winery source code
Change-Id: I1c5088121d79b71098c3cba1996c6f784737532e
Issue-id: TOSCA-49
Signed-off-by: huangjian <huang.jian12@zte.com.cn>
Diffstat (limited to 'winery/org.eclipse.winery.common')
60 files changed, 4716 insertions, 0 deletions
diff --git a/winery/org.eclipse.winery.common/.gitignore b/winery/org.eclipse.winery.common/.gitignore new file mode 100644 index 0000000..4cac871 --- /dev/null +++ b/winery/org.eclipse.winery.common/.gitignore @@ -0,0 +1,14 @@ +/.gradle +.classpath +.project +.settings/org.eclipse.core.resources.prefs +.settings/org.eclipse.jdt.core.prefs +.settings/org.eclipse.m2e.core.prefs +.settings/org.eclipse.wst.common.component +.settings/org.eclipse.wst.common.project.facet.core.xml +.settings/org.eclipse.wst.validation.prefs +/.sonar +/bin +/build +/src/main/resources/rebel.xml +/target diff --git a/winery/org.eclipse.winery.common/about.html b/winery/org.eclipse.winery.common/about.html new file mode 100644 index 0000000..4e770b7 --- /dev/null +++ b/winery/org.eclipse.winery.common/about.html @@ -0,0 +1,143 @@ +<!DOCTYPE html> +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/> +<title>About</title> +</head> +<body lang="EN-US"> +<h2>About This Content</h2> + +<p>January 24, 2014</p> +<h3>License</h3> + +<p>The Eclipse Foundation makes available all content in this plug-in (“Content”). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +<a href="http://www.eclipse.org/legal/epl-v10.html">Eclipse Public License Version 1.0 (“EPL”)</a> +and <a href="http://www.opensource.org/licenses/apache2.0.php">Apache License Version 2.0</a>. +A copy of the EPL is available at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a> +and a copy of the Apache License Version 2.0 is available at <a href="http://www.opensource.org/licenses/apache2.0.php">http://www.opensource.org/licenses/apache2.0.php</a>. +You may elect to redistribute this code under either of these licenses. +For purposes of the EPL, “Program” will mean the Content. +</p> + +<p> +If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party (“Redistributor”) and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor’s license that was +provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL and Apache License 2.0 still apply to any source code +in the Content and such source code may be obtained at <a href="http://www.eclipse.org">http://www.eclipse.org</a>. +</p> + +<h3>Third Party Content</h3> + +<h4>Java Libraries</h4> + +<h5>Apache Commons IO – Version 2.4</h5> +<table> + <tr> + <td>URL</td> + <td><a href="http://commons.apache.org/proper/commons-io/">http://commons.apache.org/proper/commons-io/</a></td> + </tr> + <tr> + <td>License</td> + <td>Apache 2.0. A copy of the license is contained in the file <a href="about_files/Apache-LICENSE-2.0.txt" target="_blank">Apache-LICENSE-2.0.txt</a> and is also available at <a href="http://www.apache.org/licenses/LICENSE-2.0" target="_blank">http://www.apache.org/licenses/LICENSE-2.0</a></td> + </tr> +</table> + +<h5>Apache Commons Lang3 – Version 3.1</h5> +<table> + <tr> + <td>URL</td> + <td><a href="http://commons.apache.org/proper/commons-lang/">http://commons.apache.org/proper/commons-lang/</a></td> + </tr> + <tr> + <td>License</td> + <td>Apache 2.0. A copy of the license is contained in the file <a href="about_files/Apache-LICENSE-2.0.txt" target="_blank">Apache-LICENSE-2.0.txt</a> and is also available at <a href="http://www.apache.org/licenses/LICENSE-2.0" target="_blank">http://www.apache.org/licenses/LICENSE-2.0</a></td> + </tr> +</table> + +<h5>JSP Standard Tag Library – Version 1.2</h5> +<table> + <tr> + <td>URL</td> + <td><a href="https://jstl.java.net/">https://jstl.java.net/</a></td> + </tr> + <tr> + <td>License</td> + <td>CDDL and GPL with classpath exception (<a href="https://jersey.java.net/license.html" target="_blank">https://jersey.java.net/license.html</a>). + The Eclipse Foundation elects to include this software in this distribution under the CDDL license. + A copy of the license is available at <a href="about_files/CDDL-v1.1.txt" target="_blank">CDDL-v1.1.txt</a>.</td> + </tr> +</table> + +<h5>Logback Classic – Version 1.1.1</h5> +<table> + <tr> + <td>URL</td> + <td><a href="http://logback.qos.ch/">http://logback.qos.ch/</a></td> + </tr> + <tr> + <td>License</td> + <td>EPL/LGPL dual license. + EPL: <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>. + LGPL v2.1: <a href="http://www.gnu.org/licenses/old-licenses/lgpl-2.1">http://www.gnu.org/licenses/old-licenses/lgpl-2.1</a>. + A copy of the license is contained in the file <a href="about_files/LICENSE-logback.txt" target="_blank">LICENSE-logback.txt</a> and is also available at <a href="http://logback.qos.ch/license.html" target="_blank">http://logback.qos.ch/license.html</a>. + The Eclipse Foundation elects to include this software in this distribution under the EPL license.</td> + </tr> +</table> + +<h5>Logback Core – Version 1.1.1</h5> +<table> + <tr> + <td>URL</td> + <td><a href="http://logback.qos.ch/">http://logback.qos.ch/</a></td> + </tr> + <tr> + <td>License</td> + <td>EPL/LGPL dual license. + EPL: <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>. + LGPL v2.1: <a href="http://www.gnu.org/licenses/old-licenses/lgpl-2.1">http://www.gnu.org/licenses/old-licenses/lgpl-2.1</a>. + A copy of the license is contained in the file <a href="about_files/LICENSE-logback.txt" target="_blank">LICENSE-logback.txt</a> and is also available at <a href="http://logback.qos.ch/license.html" target="_blank">http://logback.qos.ch/license.html</a>. + The Eclipse Foundation elects to include this software in this distribution under the EPL license.</td> + </tr> +</table> + +<h5>SLF4J: slf4j-api – Version 1.7.6</h5> +<table> + <tr> + <td>URL</td> + <td><a href="http://www.slf4j.org/">http://www.slf4j.org/</a></td> + </tr> + <tr> + <td>License</td> + <td>MIT. A copy of the license is contained in the file <a href="about_files/LICENSE-slf4j-api.txt" target="_blank">LICENSE-slf4j-api.txt</a> and is also available at <a href="http://www.slf4j.org/license.html" target="_blank">http://www.slf4j.org/license.html</a></td> + </tr> +</table> + +<h5>SLF4J: jcl-over-slf4j – Version 1.7.6</h5> +<table> + <tr> + <td>URL</td> + <td><a href="http://www.slf4j.org/legacy.html">http://www.slf4j.org/legacy.html</a></td> + </tr> + <tr> + <td>License</td> + <td>Apache 2.0. A copy of the license is contained in the file <a href="about_files/Apache-LICENSE-2.0.txt" target="_blank">Apache-LICENSE-2.0.txt</a> and is also available at <a href="http://www.apache.org/licenses/LICENSE-2.0" target="_blank">http://www.apache.org/licenses/LICENSE-2.0</a></td> + </tr> +</table> + +<h5>Winery: org.eclipse.winery.model.tosca – Version 0.1.20</h5> +<table> + <tr> + <td>URL</td> + <td><a href="http://eclipse.org/winery/">http://eclipse.org/winery/</a></td> + </tr> + <tr> + <td>License</td> + <td>EPL/Apache 2.0. A copy of the licenses is contained in the files <a href="../LICENSE-ASL.txt" target="_blank">LICENSE-ASL.txt</a> and <a href="../LICENSE-EPL.txt" target="_blank">LICENSE-EPL.txt</a>. A copy of the EPL is available at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a> and a copy of the Apache License Version 2.0 is available at <a href="http://www.opensource.org/licenses/apache2.0.php">http://www.opensource.org/licenses/apache2.0.php</a>.</td> + </tr> +</table> + +</body> +</html>
\ No newline at end of file diff --git a/winery/org.eclipse.winery.common/about_files/Apache-LICENSE-2.0.txt b/winery/org.eclipse.winery.common/about_files/Apache-LICENSE-2.0.txt new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/winery/org.eclipse.winery.common/about_files/Apache-LICENSE-2.0.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/winery/org.eclipse.winery.common/about_files/CDDL-v1.1.txt b/winery/org.eclipse.winery.common/about_files/CDDL-v1.1.txt new file mode 100644 index 0000000..7cc8719 --- /dev/null +++ b/winery/org.eclipse.winery.common/about_files/CDDL-v1.1.txt @@ -0,0 +1,129 @@ +COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL - Version 1.1) +1. Definitions. + + 1.1. “Contributor” means each individual or entity that creates or contributes to the creation of Modifications. + + 1.2. “Contributor Version” means the combination of the Original Software, prior Modifications used by a Contributor (if any), and the Modifications made by that particular Contributor. + + 1.3. “Covered Software” means (a) the Original Software, or (b) Modifications, or (c) the combination of files containing Original Software with files containing Modifications, in each case including portions thereof. + + 1.4. “Executable” means the Covered Software in any form other than Source Code. + + 1.5. “Initial Developer” means the individual or entity that first makes Original Software available under this License. + + 1.6. “Larger Work” means a work which combines Covered Software or portions thereof with code not governed by the terms of this License. + + 1.7. “License” means this document. + + 1.8. “Licensable” means having the right to grant, to the maximum extent possible, whether at the time of the initial grant or subsequently acquired, any and all of the rights conveyed herein. + + 1.9. “Modifications” means the Source Code and Executable form of any of the following: + + A. Any file that results from an addition to, deletion from or modification of the contents of a file containing Original Software or previous Modifications; + + B. Any new file that contains any part of the Original Software or previous Modification; or + + C. Any new file that is contributed or otherwise made available under the terms of this License. + + 1.10. “Original Software” means the Source Code and Executable form of computer software code that is originally released under this License. + + 1.11. “Patent Claims” means any patent claim(s), now owned or hereafter acquired, including without limitation, method, process, and apparatus claims, in any patent Licensable by grantor. + + 1.12. “Source Code” means (a) the common form of computer software code in which modifications are made and (b) associated documentation included in or with such code. + + 1.13. “You” (or “Your”) means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, “You” includes any entity which controls, is controlled by, or is under common control with You. For purposes of this definition, “control” means (a) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (b) ownership of more than fifty percent (50%) of the outstanding shares or beneficial ownership of such entity. + +2. License Grants. + + 2.1. The Initial Developer Grant. + + Conditioned upon Your compliance with Section 3.1 below and subject to third party intellectual property claims, the Initial Developer hereby grants You a world-wide, royalty-free, non-exclusive license: + + (a) under intellectual property rights (other than patent or trademark) Licensable by Initial Developer, to use, reproduce, modify, display, perform, sublicense and distribute the Original Software (or portions thereof), with or without Modifications, and/or as part of a Larger Work; and + + (b) under Patent Claims infringed by the making, using or selling of Original Software, to make, have made, use, practice, sell, and offer for sale, and/or otherwise dispose of the Original Software (or portions thereof). + + (c) The licenses granted in Sections 2.1(a) and (b) are effective on the date Initial Developer first distributes or otherwise makes the Original Software available to a third party under the terms of this License. + + (d) Notwithstanding Section 2.1(b) above, no patent license is granted: (1) for code that You delete from the Original Software, or (2) for infringements caused by: (i) the modification of the Original Software, or (ii) the combination of the Original Software with other software or devices. + + 2.2. Contributor Grant. + + Conditioned upon Your compliance with Section 3.1 below and subject to third party intellectual property claims, each Contributor hereby grants You a world-wide, royalty-free, non-exclusive license: + + (a) under intellectual property rights (other than patent or trademark) Licensable by Contributor to use, reproduce, modify, display, perform, sublicense and distribute the Modifications created by such Contributor (or portions thereof), either on an unmodified basis, with other Modifications, as Covered Software and/or as part of a Larger Work; and + + (b) under Patent Claims infringed by the making, using, or selling of Modifications made by that Contributor either alone and/or in combination with its Contributor Version (or portions of such combination), to make, use, sell, offer for sale, have made, and/or otherwise dispose of: (1) Modifications made by that Contributor (or portions thereof); and (2) the combination of Modifications made by that Contributor with its Contributor Version (or portions of such combination). + + (c) The licenses granted in Sections 2.2(a) and 2.2(b) are effective on the date Contributor first distributes or otherwise makes the Modifications available to a third party. + + (d) Notwithstanding Section 2.2(b) above, no patent license is granted: (1) for any code that Contributor has deleted from the Contributor Version; (2) for infringements caused by: (i) third party modifications of Contributor Version, or (ii) the combination of Modifications made by that Contributor with other software (except as part of the Contributor Version) or other devices; or (3) under Patent Claims infringed by Covered Software in the absence of Modifications made by that Contributor. + +3. Distribution Obligations. + + 3.1. Availability of Source Code. + + Any Covered Software that You distribute or otherwise make available in Executable form must also be made available in Source Code form and that Source Code form must be distributed only under the terms of this License. You must include a copy of this License with every copy of the Source Code form of the Covered Software You distribute or otherwise make available. You must inform recipients of any such Covered Software in Executable form as to how they can obtain such Covered Software in Source Code form in a reasonable manner on or through a medium customarily used for software exchange. + + 3.2. Modifications. + + The Modifications that You create or to which You contribute are governed by the terms of this License. You represent that You believe Your Modifications are Your original creation(s) and/or You have sufficient rights to grant the rights conveyed by this License. + + 3.3. Required Notices. + + You must include a notice in each of Your Modifications that identifies You as the Contributor of the Modification. You may not remove or alter any copyright, patent or trademark notices contained within the Covered Software, or any notices of licensing or any descriptive text giving attribution to any Contributor or the Initial Developer. + + 3.4. Application of Additional Terms. + + You may not offer or impose any terms on any Covered Software in Source Code form that alters or restricts the applicable version of this License or the recipients’ rights hereunder. You may choose to offer, and to charge a fee for, warranty, support, indemnity or liability obligations to one or more recipients of Covered Software. However, you may do so only on Your own behalf, and not on behalf of the Initial Developer or any Contributor. You must make it absolutely clear that any such warranty, support, indemnity or liability obligation is offered by You alone, and You hereby agree to indemnify the Initial Developer and every Contributor for any liability incurred by the Initial Developer or such Contributor as a result of warranty, support, indemnity or liability terms You offer. + + 3.5. Distribution of Executable Versions. + + You may distribute the Executable form of the Covered Software under the terms of this License or under the terms of a license of Your choice, which may contain terms different from this License, provided that You are in compliance with the terms of this License and that the license for the Executable form does not attempt to limit or alter the recipient’s rights in the Source Code form from the rights set forth in this License. If You distribute the Covered Software in Executable form under a different license, You must make it absolutely clear that any terms which differ from this License are offered by You alone, not by the Initial Developer or Contributor. You hereby agree to indemnify the Initial Developer and every Contributor for any liability incurred by the Initial Developer or such Contributor as a result of any such terms You offer. + + 3.6. Larger Works. + + You may create a Larger Work by combining Covered Software with other code not governed by the terms of this License and distribute the Larger Work as a single product. In such a case, You must make sure the requirements of this License are fulfilled for the Covered Software. + +4. Versions of the License. + + 4.1. New Versions. + + Oracle is the initial license steward and may publish revised and/or new versions of this License from time to time. Each version will be given a distinguishing version number. Except as provided in Section 4.3, no one other than the license steward has the right to modify this License. + + 4.2. Effect of New Versions. + + You may always continue to use, distribute or otherwise make the Covered Software available under the terms of the version of the License under which You originally received the Covered Software. If the Initial Developer includes a notice in the Original Software prohibiting it from being distributed or otherwise made available under any subsequent version of the License, You must distribute and make the Covered Software available under the terms of the version of the License under which You originally received the Covered Software. Otherwise, You may also choose to use, distribute or otherwise make the Covered Software available under the terms of any subsequent version of the License published by the license steward. + + 4.3. Modified Versions. + + When You are an Initial Developer and You want to create a new license for Your Original Software, You may create and use a modified version of this License if You: (a) rename the license and remove any references to the name of the license steward (except to note that the license differs from this License); and (b) otherwise make it clear that the license contains terms which differ from this License. + +5. DISCLAIMER OF WARRANTY. + +COVERED SOFTWARE IS PROVIDED UNDER THIS LICENSE ON AN “AS IS” BASIS, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES THAT THE COVERED SOFTWARE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED SOFTWARE IS WITH YOU. SHOULD ANY COVERED SOFTWARE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF ANY COVERED SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER. +6. TERMINATION. + + 6.1. This License and the rights granted hereunder will terminate automatically if You fail to comply with terms herein and fail to cure such breach within 30 days of becoming aware of the breach. Provisions which, by their nature, must remain in effect beyond the termination of this License shall survive. + + 6.2. If You assert a patent infringement claim (excluding declaratory judgment actions) against Initial Developer or a Contributor (the Initial Developer or Contributor against whom You assert such claim is referred to as “Participant”) alleging that the Participant Software (meaning the Contributor Version where the Participant is a Contributor or the Original Software where the Participant is the Initial Developer) directly or indirectly infringes any patent, then any and all rights granted directly or indirectly to You by such Participant, the Initial Developer (if the Initial Developer is not the Participant) and all Contributors under Sections 2.1 and/or 2.2 of this License shall, upon 60 days notice from Participant terminate prospectively and automatically at the expiration of such 60 day notice period, unless if within such 60 day period You withdraw Your claim with respect to the Participant Software against such Participant either unilaterally or pursuant to a written agreement with Participant. + + 6.3. If You assert a patent infringement claim against Participant alleging that the Participant Software directly or indirectly infringes any patent where such claim is resolved (such as by license or settlement) prior to the initiation of patent infringement litigation, then the reasonable value of the licenses granted by such Participant under Sections 2.1 or 2.2 shall be taken into account in determining the amount or value of any payment or license. + + 6.4. In the event of termination under Sections 6.1 or 6.2 above, all end user licenses that have been validly granted by You or any distributor hereunder prior to termination (excluding licenses granted to You by any distributor) shall survive termination. + +7. LIMITATION OF LIABILITY. + +UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE INITIAL DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO ANY PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL INJURY RESULTING FROM SUCH PARTY’S NEGLIGENCE TO THE EXTENT APPLICABLE LAW PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THIS EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU. +8. U.S. GOVERNMENT END USERS. + +The Covered Software is a “commercial item,” as that term is defined in 48 C.F.R. 2.101 (Oct. 1995), consisting of “commercial computer software” (as that term is defined at 48 C.F.R. § 252.227-7014(a)(1)) and “commercial computer software documentation” as such terms are used in 48 C.F.R. 12.212 (Sept. 1995). Consistent with 48 C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995), all U.S. Government End Users acquire Covered Software with only those rights set forth herein. This U.S. Government Rights clause is in lieu of, and supersedes, any other FAR, DFAR, or other clause or provision that addresses Government rights in computer software under this License. +9. MISCELLANEOUS. + +This License represents the complete agreement concerning subject matter hereof. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. This License shall be governed by the law of the jurisdiction specified in a notice contained within the Original Software (except to the extent applicable law, if any, provides otherwise), excluding such jurisdiction’s conflict-of-law provisions. Any litigation relating to this License shall be subject to the jurisdiction of the courts located in the jurisdiction and venue specified in a notice contained within the Original Software, with the losing party responsible for costs, including, without limitation, court costs and reasonable attorneys’ fees and expenses. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any law or regulation which provides that the language of a contract shall be construed against the drafter shall not apply to this License. You agree that You alone are responsible for compliance with the United States export administration regulations (and the export control laws and regulation of any other countries) when You use, distribute or otherwise make available any Covered Software. +10. RESPONSIBILITY FOR CLAIMS. + +As between Initial Developer and the Contributors, each party is responsible for claims and damages arising, directly or indirectly, out of its utilization of rights under this License and You agree to work with Initial Developer and Contributors to distribute such responsibility on an equitable basis. Nothing herein is intended or shall be deemed to constitute any admission of liability. +NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) + +The code released under the CDDL shall be governed by the laws of the State of California (excluding conflict-of-law provisions). Any litigation relating to this License shall be subject to the jurisdiction of the Federal Courts of the Northern District of California and the state courts of the State of California, with venue lying in Santa Clara County, California.
\ No newline at end of file diff --git a/winery/org.eclipse.winery.common/about_files/LICENSE-logback.txt b/winery/org.eclipse.winery.common/about_files/LICENSE-logback.txt new file mode 100644 index 0000000..b4fe24e --- /dev/null +++ b/winery/org.eclipse.winery.common/about_files/LICENSE-logback.txt @@ -0,0 +1,15 @@ +Logback LICENSE +--------------- + +Logback: the reliable, generic, fast and flexible logging framework. +Copyright (C) 1999-2012, QOS.ch. All rights reserved. + +This program and the accompanying materials are dual-licensed under +either the terms of the Eclipse Public License v1.0 as published by +the Eclipse Foundation + + or (per the licensee's choosing) + +under the terms of the GNU Lesser General Public License version 2.1 +as published by the Free Software Foundation. + diff --git a/winery/org.eclipse.winery.common/about_files/LICENSE-slf4j-api.txt b/winery/org.eclipse.winery.common/about_files/LICENSE-slf4j-api.txt new file mode 100644 index 0000000..37050c9 --- /dev/null +++ b/winery/org.eclipse.winery.common/about_files/LICENSE-slf4j-api.txt @@ -0,0 +1,21 @@ + Copyright (c) 2004-2013 QOS.ch + All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/winery/org.eclipse.winery.common/pom.xml b/winery/org.eclipse.winery.common/pom.xml new file mode 100644 index 0000000..048ff04 --- /dev/null +++ b/winery/org.eclipse.winery.common/pom.xml @@ -0,0 +1,90 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Tobias Unger - initial API and implementation and/or initial documentation + * Oliver Kopp - improvements + *******************************************************************************/ +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.eclipse.winery</groupId> + <artifactId>winery</artifactId> + <version>0.1.37-SNAPSHOT</version> + </parent> + <artifactId>org.eclipse.winery.common</artifactId> + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + <dependencies> + <dependency> + <groupId>ch.qos.logback</groupId> + <artifactId>logback-classic</artifactId> + <version>1.1.1</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.eclipse.winery</groupId> + <artifactId>org.eclipse.winery.model.tosca</artifactId> + <version>0.1.21-SNAPSHOT</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>jcl-over-slf4j</artifactId> + <version>1.7.6</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>jstl</groupId> + <artifactId>jstl</artifactId> + <version>1.2</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>2.4</version> + <scope>compile</scope> + <exclusions> + <exclusion> + <artifactId>commons-logging</artifactId> + <groupId>commons-logging</groupId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-lang3</artifactId> + <version>3.1</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.11</version> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.1</version> + <configuration> + <source>1.7</source> + <target>1.7</target> + </configuration> + </plugin> + </plugins> + </build> +</project> diff --git a/winery/org.eclipse.winery.common/sonar-project.properties b/winery/org.eclipse.winery.common/sonar-project.properties new file mode 100644 index 0000000..09b7e2f --- /dev/null +++ b/winery/org.eclipse.winery.common/sonar-project.properties @@ -0,0 +1,24 @@ +# required metadata +sonar.projectKey=org.eclipse.winery.common +sonar.projectName=org.eclipse.winery.common +sonar.projectVersion=0.1.2 + +# path to source directories (required) +sonar.sources=src/main/java + +# path to test source directories (optional) +#sonar.tests= + +# path to project binaries (optional), for example directory of Java bytecode +#sonar.binaries=binDir + +# optional comma-separated list of paths to libraries. Only path to JAR file and path to directory of classes are supported. +#sonar.libraries=org.eclipse.jgit-2.1.0.201209190230-r.jar + +# The value of the property must be the key of the language. +sonar.language=java + +# enforece Java 1.7 to enable analysis of diamon operator by PMD +sonar.java.source=1.7 + +sonar.sourceEncoding=UTF-8 diff --git a/winery/org.eclipse.winery.common/src/main/java/META-INF/MANIFEST.MF b/winery/org.eclipse.winery.common/src/main/java/META-INF/MANIFEST.MF new file mode 100644 index 0000000..254272e --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ModelUtilities.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ModelUtilities.java new file mode 100644 index 0000000..92d8ec9 --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ModelUtilities.java @@ -0,0 +1,670 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +package org.eclipse.winery.common; + +import java.lang.reflect.Method; +import java.util.Iterator; +import java.util.Map; +import java.util.Properties; +import java.util.UUID; + +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import org.apache.commons.lang3.StringUtils; +import org.eclipse.winery.common.constants.Namespaces; +import org.eclipse.winery.common.constants.QNames; +import org.eclipse.winery.common.propertydefinitionkv.PropertyDefinitionKV; +import org.eclipse.winery.common.propertydefinitionkv.PropertyDefinitionKVList; +import org.eclipse.winery.common.propertydefinitionkv.WinerysPropertiesDefinition; +import org.eclipse.winery.model.tosca.TBoundaryDefinitions; +import org.eclipse.winery.model.tosca.TCapability; +import org.eclipse.winery.model.tosca.TCapabilityDefinition; +import org.eclipse.winery.model.tosca.TEntityTemplate; +import org.eclipse.winery.model.tosca.TEntityType; +import org.eclipse.winery.model.tosca.TExtensibleElements; +import org.eclipse.winery.model.tosca.TNodeTemplate; +import org.eclipse.winery.model.tosca.TNodeTemplate.Capabilities; +import org.eclipse.winery.model.tosca.TNodeTemplate.Requirements; +import org.eclipse.winery.model.tosca.TNodeType; +import org.eclipse.winery.model.tosca.TPlan; +import org.eclipse.winery.model.tosca.TPlans; +import org.eclipse.winery.model.tosca.TRelationshipTemplate; +import org.eclipse.winery.model.tosca.TRelationshipTemplate.SourceElement; +import org.eclipse.winery.model.tosca.TRelationshipTemplate.TargetElement; +import org.eclipse.winery.model.tosca.TRelationshipType; +import org.eclipse.winery.model.tosca.TRequirement; +import org.eclipse.winery.model.tosca.TRequirementDefinition; +import org.eclipse.winery.model.tosca.TServiceTemplate; +import org.eclipse.winery.model.tosca.TTopologyTemplate; +import org.slf4j.LoggerFactory; +import org.w3c.dom.Comment; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.w3c.dom.Text; + +public class ModelUtilities { + + private static final org.slf4j.Logger logger = LoggerFactory.getLogger(ModelUtilities.class); + + + /** + * This is a special method for Winery. Winery allows to define a property + * definition by specifying name/type values. Instead of parsing the + * extensible elements returned TDefinitions, this method is a convenience + * method to access this information + * + * @param t the entitytype to read the properties definition from + * @return a WinerysPropertiesDefinition object, which includes a map of + * name/type-pairs denoting the associated property definitions. A + * default element name and namespace is added if it is not defined + * in the underlying XML. null if no Winery specific KV properties + * are defined for the given entity type + */ + public static WinerysPropertiesDefinition getWinerysPropertiesDefinition(TEntityType et) { + // similar implementation as org.eclipse.winery.repository.resources.entitytypes.properties.PropertiesDefinitionResource.getListFromEntityType(TEntityType) + WinerysPropertiesDefinition res = null; + for (Object o : et.getAny()) { + if (o instanceof WinerysPropertiesDefinition) { + res = (WinerysPropertiesDefinition) o; + } + } + + if (res != null) { + // we put defaults if elementname and namespace have not been set + + if (res.getElementName() == null) { + res.setElementName("Properties"); + } + + if (res.getNamespace() == null) { + // we use the targetnamespace of the original element + String ns = et.getTargetNamespace(); + if (!ns.endsWith("/")) { + ns += "/"; + } + ns += "propertiesdefinition/winery"; + res.setNamespace(ns); + } + } + + return res; + } + + /** + * This is a special method for Winery. Winery allows to define a property + * by specifying name/value values. Instead of parsing the XML contained in + * TNodeType, this method is a convenience method to access this information + * + * The return type "Properties" is used because of the key/value properties. + * + * @param template the node template to get the associated properties + */ + public static Properties getPropertiesKV(TEntityTemplate template) { + Properties properties = new Properties(); + org.eclipse.winery.model.tosca.TEntityTemplate.Properties tprops = template.getProperties(); + if (tprops != null) { + // no checking for validity, just reading + Element el = (Element) tprops.getAny(); + if (el == null) { + // somehow invalid .tosca. We return empty properties instead of throwing a NPE + return properties; + } + NodeList childNodes = el.getChildNodes(); + for (int i = 0; i < childNodes.getLength(); i++) { + Node item = childNodes.item(i); + if (item instanceof Element) { + String key = item.getLocalName(); + String value = item.getTextContent(); + properties.put(key, value); + } + } + } + return properties; + } + + /** + * This is a special method for Winery. Winery allows to define a property + * by specifying name/value values. We convert the given Properties to XML. + * + * @param wpd the Winery's properties definition of the type of the given + * template (i.e., wpd = + * getWinerysPropertiesDefinition(template.getType())) + * @param template the node template to set the associated properties + */ + public static void setPropertiesKV(WinerysPropertiesDefinition wpd, TEntityTemplate template, Properties properties) { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db; + try { + db = dbf.newDocumentBuilder(); + } catch (ParserConfigurationException e) { + ModelUtilities.logger.debug(e.getMessage(), e); + throw new IllegalStateException("Could not instantiate document builder", e); + } + Document doc = db.newDocument(); + + Element root = doc.createElementNS(wpd.getNamespace(), wpd.getElementName()); + doc.appendChild(root); + + // we produce the serialization in the same order the XSD would be generated (because of the usage of xsd:sequence) + for (PropertyDefinitionKV prop : wpd.getPropertyDefinitionKVList()) { + // we always write the element tag as the XSD forces that + Element element = doc.createElementNS(wpd.getNamespace(), prop.getKey()); + root.appendChild(element); + String value = properties.getProperty(prop.getKey()); + if (value != null) { + Text text = doc.createTextNode(value); + element.appendChild(text); + } + } + + org.eclipse.winery.model.tosca.TEntityTemplate.Properties tprops = new org.eclipse.winery.model.tosca.TEntityTemplate.Properties(); + tprops.setAny(doc.getDocumentElement()); + template.setProperties(tprops); + } + + /** + * Generates a XSD when Winery's K/V properties are used. This method is put + * here instead of WinerysPropertiesDefinitionResource to avoid generating + * the subresource + * + * public because of the usage by TOSCAEXportUtil + * + * @return empty Document, if Winery's Properties Definition is not fully + * filled (e.g., no wrapping element defined) + */ + public static Document getWinerysPropertiesDefinitionXSDAsDocument(WinerysPropertiesDefinition wpd) { + /* + * This is a quick hack: an XML schema container is created for each + * element. Smarter solution: create a hash from namespace to XML schema + * element and re-use that for each new element + * Drawback of "smarter" solution: not a single XSD file any more + */ + DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder docBuilder; + try { + docBuilder = docFactory.newDocumentBuilder(); + } catch (ParserConfigurationException e) { + ModelUtilities.logger.debug(e.getMessage(), e); + throw new IllegalStateException("Could not instantiate document builder", e); + } + Document doc = docBuilder.newDocument(); + + if (!ModelUtilities.allRequiredFieldsNonNull(wpd)) { + // wpd not fully filled -> valid XSD cannot be provided + // fallback: add comment and return "empty" document + Comment comment = doc.createComment("Required fields are missing in Winery's key/value properties definition."); + doc.appendChild(comment); + return doc; + } + + // create XSD schema container + Element schemaElement = doc.createElementNS(XMLConstants.W3C_XML_SCHEMA_NS_URI, "schema"); + doc.appendChild(schemaElement); + schemaElement.setAttribute("elementFormDefault", "qualified"); + schemaElement.setAttribute("attributeFormDefault", "unqualified"); + schemaElement.setAttribute("targetNamespace", wpd.getNamespace()); + + // create XSD element itself + Element el = doc.createElementNS(XMLConstants.W3C_XML_SCHEMA_NS_URI, "element"); + schemaElement.appendChild(el); + el.setAttribute("name", wpd.getElementName()); + Element el2 = doc.createElementNS(XMLConstants.W3C_XML_SCHEMA_NS_URI, "complexType"); + el.appendChild(el2); + el = el2; + el2 = doc.createElementNS(XMLConstants.W3C_XML_SCHEMA_NS_URI, "sequence"); + el.appendChild(el2); + el = el2; + + // currently, "xsd" is a hardcoded prefix in the type definition + el.setAttribute("xmlns:xsd", XMLConstants.W3C_XML_SCHEMA_NS_URI); + + for (PropertyDefinitionKV prop : wpd.getPropertyDefinitionKVList()) { + el2 = doc.createElementNS(XMLConstants.W3C_XML_SCHEMA_NS_URI, "element"); + el.appendChild(el2); + el2.setAttribute("name", prop.getKey()); + // prop.getType has the prefix included + el2.setAttribute("type", prop.getType()); + } + + return doc; + } + + /** + * Removes an existing Winery's Properties definition. If no such definition + * exists, the TEntityType is not modified + */ + public static void removeWinerysPropertiesDefinition(TEntityType et) { + for (Iterator<Object> iterator = et.getAny().iterator(); iterator.hasNext();) { + Object o = iterator.next(); + if (o instanceof WinerysPropertiesDefinition) { + iterator.remove(); + break; + } + } + } + + public static void replaceWinerysPropertiesDefinition(TEntityType et, WinerysPropertiesDefinition wpd) { + ModelUtilities.removeWinerysPropertiesDefinition(et); + et.getAny().add(wpd); + } + + public static String getBorderColor(TNodeType nt) { + String borderColor = nt.getOtherAttributes().get(QNames.QNAME_BORDER_COLOR); + if (borderColor == null) { + borderColor = Util.getColor(nt.getName()); + } + return borderColor; + } + + public static String getColor(TRelationshipType rt) { + String color = rt.getOtherAttributes().get(QNames.QNAME_COLOR); + if (color == null) { + color = Util.getColor(rt.getName()); + } + return color; + } + + /** + * Returns the Properties. If no properties exist, the element is created + * + * @return + */ + public static org.eclipse.winery.model.tosca.TBoundaryDefinitions.Properties getProperties(TBoundaryDefinitions defs) { + org.eclipse.winery.model.tosca.TBoundaryDefinitions.Properties properties = defs.getProperties(); + if (properties == null) { + properties = new org.eclipse.winery.model.tosca.TBoundaryDefinitions.Properties(); + defs.setProperties(properties); + } + return properties; + } + + /** + * Special method to get the name of an extensible element as the TOSCA + * specification does not have a separate super type for elements with a + * name + * + * {@link + * org.eclipse.winery.common.Util.instanceSupportsNameAttribute(Class<? + * extends TOSCAComponentId>)} is related + * + * @param e the extensible element offering a name attribute (besides an id + * attribute) + * @return the name of the extensible element + * @throws IllegalStateException if e does not offer the method "getName" + */ + public static String getName(TExtensibleElements e) { + Method method; + Object res; + try { + method = e.getClass().getMethod("getName"); + res = method.invoke(e); + } catch (Exception ex) { + throw new IllegalStateException(ex); + } + return (String) res; + } + + /** + * Returns the name of the given element. If the name does not exist or is + * empty, the id is returned + * + * {@see getName} + * + * @return the name if there is a name field, if not, the id is returned. In + * case there is a Name field, + */ + public static String getNameWithIdFallBack(TExtensibleElements ci) { + Method method; + String res = null; + try { + method = ci.getClass().getMethod("getName"); + res = (String) method.invoke(ci); + } catch (Exception e) { + } + if (StringUtils.isEmpty(res)) { + try { + method = ci.getClass().getMethod("getId"); + res = (String) method.invoke(ci); + } catch (Exception e2) { + throw new IllegalStateException(e2); + } + } + return res; + } + + /** + * Special method to set the name of an extensible element as the TOSCA + * specification does not have a separate super type for elements with a + * name + * + * @param e the extensible element offering a name attribute (besides an id + * attribute) + * @param name the new name + * @throws IllegalStateException if e does not offer the method "getName" + */ + public static void setName(TExtensibleElements e, String name) { + Method method; + try { + method = e.getClass().getMethod("setName", String.class); + method.invoke(e, name); + } catch (Exception ex) { + throw new IllegalStateException(ex); + } + } + + public static boolean allRequiredFieldsNonNull(WinerysPropertiesDefinition wpd) { + boolean valid = wpd.getNamespace() != null; + valid = valid && (wpd.getElementName() != null); + if (valid) { + PropertyDefinitionKVList propertyDefinitionKVList = wpd.getPropertyDefinitionKVList(); + valid = (propertyDefinitionKVList != null); + if (valid) { + for (PropertyDefinitionKV def : propertyDefinitionKVList) { + valid = valid && (def.getKey() != null); + valid = valid && (def.getType() != null); + } + } + } + return valid; + } + + /** + * @return null if no explicit left is set + */ + public static String getLeft(TNodeTemplate nodeTemplate) { + Map<QName, String> otherAttributes = nodeTemplate.getOtherAttributes(); + String left = otherAttributes.get(new QName(Namespaces.TOSCA_WINERY_EXTENSIONS_NAMESPACE, "x")); + return left; + } + + /** + * @return null if no explicit left is set + */ + public static String getTop(TNodeTemplate nodeTemplate) { + Map<QName, String> otherAttributes = nodeTemplate.getOtherAttributes(); + String top = otherAttributes.get(new QName(Namespaces.TOSCA_WINERY_EXTENSIONS_NAMESPACE, "y")); + return top; + } + + /** + * locates targetObjectRef inside a topology template + * + * @param topologyTemplate the topology template to search in + * @param targetObjectRef the object ref as String + * + * @return null if not found, otherwise the entity template in the topology + */ + public static TEntityTemplate findNodeTemplateOrRequirementOfNodeTemplateOrCapabilityOfNodeTemplateOrRelationshipTemplate(TTopologyTemplate topologyTemplate, String targetObjectRef) { + // We cannot use XMLs id pointing capabilities as we work on the Java model + // Other option: modify the stored XML directly. This is more error prune than walking through the whole topology + for (TEntityTemplate t : topologyTemplate.getNodeTemplateOrRelationshipTemplate()) { + if (t instanceof TNodeTemplate) { + if (t.getId().equals(targetObjectRef)) { + return t; + } + TNodeTemplate nt = (TNodeTemplate) t; + + Requirements requirements = nt.getRequirements(); + if (requirements != null) { + for (TRequirement req : requirements.getRequirement()) { + if (req.getId().equals(targetObjectRef)) { + return req; + } + } + } + + Capabilities capabilities = nt.getCapabilities(); + if (capabilities != null) { + for (TCapability cap : capabilities.getCapability()) { + if (cap.getId().equals(targetObjectRef)) { + return cap; + } + } + } + + } else { + assert (t instanceof TRelationshipTemplate); + if (t.getId().equals(targetObjectRef)) { + return t; + } + } + } + + // no return hit inside the loop: nothing was found + return null; + } + + /** + * Returns the id of the given element + * + * The TOSCA specification does NOT always put an id field. In the case of + * EntityTypes and EntityTypeImplementations, there is no id, but a name + * field + * + * This method abstracts from that fact. + */ + public static String getId(TExtensibleElements ci) { + Method method; + Object res; + try { + method = ci.getClass().getMethod("getId"); + res = method.invoke(ci); + } catch (Exception e) { + // If no "getId" method is there, we try "getName" + try { + method = ci.getClass().getMethod("getName"); + res = method.invoke(ci); + } catch (Exception e2) { + throw new IllegalStateException(e2); + } + } + return (String) res; + } + + /** + * Resolves a given id as requirement in the given ServiceTemplate + * + * @return null if not found + */ + public static TRequirement resolveRequirement(TServiceTemplate serviceTemplate, String reference) { + TRequirement resolved = null; + for (TEntityTemplate tmpl : serviceTemplate.getTopologyTemplate().getNodeTemplateOrRelationshipTemplate()) { + if (tmpl instanceof TNodeTemplate) { + TNodeTemplate n = (TNodeTemplate) tmpl; + Requirements requirements = n.getRequirements(); + if (requirements != null) { + for (TRequirement req : n.getRequirements().getRequirement()) { + if (req.getId().equals(reference)) { + resolved = req; + } + } + } + } + } + return resolved; + } + + public static TCapability resolveCapability(TServiceTemplate serviceTemplate, String reference) { + TCapability resolved = null; + for (TEntityTemplate tmpl : serviceTemplate.getTopologyTemplate().getNodeTemplateOrRelationshipTemplate()) { + if (tmpl instanceof TNodeTemplate) { + TNodeTemplate n = (TNodeTemplate) tmpl; + Capabilities capabilities = n.getCapabilities(); + if (capabilities != null) { + for (TCapability cap : n.getCapabilities().getCapability()) { + if (cap.getId().equals(reference)) { + resolved = cap; + } + } + } + } + } + return resolved; + } + + public static TNodeTemplate resolveNodeTemplate(TServiceTemplate serviceTemplate, String reference) { + TNodeTemplate resolved = null; + for (TEntityTemplate tmpl : serviceTemplate.getTopologyTemplate().getNodeTemplateOrRelationshipTemplate()) { + if (tmpl instanceof TNodeTemplate) { + TNodeTemplate n = (TNodeTemplate) tmpl; + if (n.getId().equals(reference)) { + resolved = n; + } + } + } + return resolved; + } + + public static TRelationshipTemplate resolveRelationshipTemplate(TServiceTemplate serviceTemplate, String reference) { + TRelationshipTemplate resolved = null; + for (TEntityTemplate tmpl : serviceTemplate.getTopologyTemplate().getNodeTemplateOrRelationshipTemplate()) { + if (tmpl instanceof TRelationshipTemplate) { + TRelationshipTemplate n = (TRelationshipTemplate) tmpl; + if (n.getId().equals(reference)) { + resolved = n; + } + } + } + return resolved; + } + + public static TPlan resolvePlan(TServiceTemplate serviceTemplate, String reference) { + TPlan resolved = null; + TPlans plans = serviceTemplate.getPlans(); + if (plans == null) { + return null; + } + for (TPlan p : plans.getPlan()) { + if (p.getId().equals(reference)) { + resolved = p; + } + } + return resolved; + } + + /** + * Sets the x coordinate of a {@link TNodeTemplate}. + * + * @param nodeTemplate + * the nodeTemplate to be altered + * @param coordinate + * the value of the coordinate to be set + * @return + * the altered {@link TNodeTemplate} + */ + public static TNodeTemplate setLeft(TNodeTemplate nodeTemplate, String coordinate) { + + Map<QName, String> otherNodeTemplateAttributes = nodeTemplate.getOtherAttributes(); + otherNodeTemplateAttributes.put(new QName(Namespaces.TOSCA_WINERY_EXTENSIONS_NAMESPACE, "x"), coordinate); + + return nodeTemplate; + } + + /** + * Sets the y coordinate of a {@link TNodeTemplate}. + * + * @param nodeTemplate + * the nodeTemplate to be altered + * @param coordinate + * the value of the coordinate to be set + * @return + * the altered {@link TNodeTemplate} + */ + public static TNodeTemplate setTop(TNodeTemplate nodeTemplate, String coordinate) { + + Map<QName, String> otherNodeTemplateAttributes = nodeTemplate.getOtherAttributes(); + otherNodeTemplateAttributes.put(new QName(Namespaces.TOSCA_WINERY_EXTENSIONS_NAMESPACE, "y"), coordinate); + + return nodeTemplate; + + } + + /** + * This method instantiates a {@link TNodeTemplate} for a given {@link TNodeType}. + * + * @param nodeType + * the {@link TNodeType} used for the {@link TNodeTemplate} instantiation. + * + * @return the instantiated {@link TNodeTemplate} + */ + public static TNodeTemplate instantiateNodeTemplate(TNodeType nodeType) { + + TNodeTemplate nodeTemplate = new TNodeTemplate(); + + nodeTemplate.setId(UUID.randomUUID().toString()); + nodeTemplate.setName(nodeType.getName()); + nodeTemplate.setType(new QName(nodeType.getTargetNamespace(), nodeType.getName())); + + // add capabilities to the NodeTemplate + if (nodeType.getCapabilityDefinitions() != null) { + for (TCapabilityDefinition cd : nodeType.getCapabilityDefinitions().getCapabilityDefinition()) { + TCapability capa = new TCapability(); + capa.setId(UUID.randomUUID().toString()); + capa.setName(cd.getCapabilityType().getLocalPart()); + capa.setType(new QName(cd.getCapabilityType().getNamespaceURI(), cd.getCapabilityType().getLocalPart())); + nodeTemplate.setCapabilities(new Capabilities()); + nodeTemplate.getCapabilities().getCapability().add(capa); + } + } + + // add requirements + if (nodeType.getRequirementDefinitions() != null && nodeType.getRequirementDefinitions().getRequirementDefinition() != null) { + Requirements requirementsNode = new Requirements(); + nodeTemplate.setRequirements(requirementsNode); + for (TRequirementDefinition definition : nodeType.getRequirementDefinitions().getRequirementDefinition()) { + TRequirement newRequirement = new TRequirement(); + newRequirement.setName(definition.getName()); + newRequirement.setId(definition.getName()); + newRequirement.setType(definition.getRequirementType()); + nodeTemplate.getRequirements().getRequirement().add(newRequirement); + } + } + + return nodeTemplate; + } + + /** + * This method instantiates a {@link TRelationshipTemplate} for a given {@link TRelationshipType}. + * + * @param nodeType + * the {@link TRelationshipType} used for the {@link TRelationshipTemplate} instantiation. + * @param sourceNodeTemplate + * the source {@link TNodeTemplate} of the connection + * @param targetNodeTemplate + * the target {@link TNodeTemplate} of the connection + * + * @return the instantiated {@link TRelationshipTemplate} + */ + public static TRelationshipTemplate instantiateRelationshipTemplate(TRelationshipType relationshipType, TNodeTemplate sourceNodeTemplate, TNodeTemplate targetNodeTemplate) { + + TRelationshipTemplate relationshipTemplate = new TRelationshipTemplate(); + relationshipTemplate.setId(UUID.randomUUID().toString()); + relationshipTemplate.setName(relationshipType.getName()); + relationshipTemplate.setType(new QName(relationshipType.getTargetNamespace(), relationshipType.getName())); + + // connect the NodeTemplates + SourceElement source = new SourceElement(); + source.setRef(sourceNodeTemplate); + relationshipTemplate.setSourceElement(source); + TargetElement target = new TargetElement(); + target.setRef(targetNodeTemplate); + relationshipTemplate.setTargetElement(target); + + return relationshipTemplate; + } +} diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/RepositoryFileReference.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/RepositoryFileReference.java new file mode 100644 index 0000000..68fb22f --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/RepositoryFileReference.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +package org.eclipse.winery.common; + +import org.eclipse.winery.common.ids.GenericId; + +/** + * Holds a reference to a file "object" stored in the repository + * + * Directories are NOT supported as we would have to reflect parent + * relationships there, too. + * + * One has to create TOSCAelementId-objects for directories (e.g., scc-data) + */ +public class RepositoryFileReference implements Comparable<RepositoryFileReference> { + + protected final GenericId parent; + protected final String fileName; + + + /** + * @param parent the id of the toscaElement the file is nested in + * @param fileName the file name. <em>Must not</em> contain any illegal + * characters. java.nio.Path cannot be used as Path is tied to a + * FileSystem + */ + public RepositoryFileReference(GenericId parent, String fileName) { + if (parent == null) { + throw new IllegalArgumentException("Parent must not be null."); + } + if (fileName == null) { + throw new IllegalArgumentException("Filename must not be null."); + } + this.parent = parent; + this.fileName = fileName; + } + + public GenericId getParent() { + return this.parent; + } + + public String getFileName() { + return this.fileName; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof RepositoryFileReference) { + RepositoryFileReference otherRef = (RepositoryFileReference) obj; + return (otherRef.fileName.equals(this.fileName)) && (otherRef.getParent().equals(this.getParent())); + } else { + return false; + } + } + + @Override + public int hashCode() { + return this.getParent().hashCode() ^ this.getFileName().hashCode(); + } + + @Override + public int compareTo(RepositoryFileReference o) { + int res; + res = this.parent.compareTo(o.parent); + if (res == 0) { + res = this.fileName.compareTo(o.fileName); + } + return res; + } + + @Override + public String toString() { + return this.getParent().toString() + "/" + this.getFileName(); + } +} diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/StringEncodedAndDecoded.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/StringEncodedAndDecoded.java new file mode 100644 index 0000000..cac7a44 --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/StringEncodedAndDecoded.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +package org.eclipse.winery.common; + + + +/** + * Meta class to handle things, where a String (URI, NCName, ...) may be + * URLencoded + */ +public class StringEncodedAndDecoded implements Comparable<StringEncodedAndDecoded> { + + private String decoded = null; + private String encoded = null; + + + /** + * @param uri the URI to store + * @param URLencoded true iff the given URI is URLencoded + */ + public StringEncodedAndDecoded(String uri, boolean URLencoded) { + if (URLencoded) { + this.encoded = uri; + } else { + this.decoded = uri; + } + } + + public String getDecoded() { + if (this.decoded == null) { + this.decoded = Util.URLdecode(this.encoded); + } + return this.decoded; + } + + public String getEncoded() { + if (this.encoded == null) { + this.encoded = Util.URLencode(this.decoded); + } + return this.encoded; + } + + @Override + public int hashCode() { + return this.getDecoded().hashCode(); + } + + /** + * @return the URL path fragment to be used in an URL + */ + public String getPathFragment() { + return this.getEncoded(); + } + + @Override + public String toString() { + return this.getDecoded(); + } + + @Override + public int compareTo(StringEncodedAndDecoded o) { + return this.getDecoded().compareTo(o.getDecoded()); + } + + /** + * Compares with the given object <br /> + * Equality checking is made based on the decoded String + */ + @Override + public boolean equals(Object o) { + if (o instanceof String) { + return this.getDecoded().equals(o); + } else if (o instanceof StringEncodedAndDecoded) { + return ((StringEncodedAndDecoded) o).getDecoded().equals(this.getDecoded()); + } else { + return false; + } + } +} diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/TOSCADocumentBuilderFactory.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/TOSCADocumentBuilderFactory.java new file mode 100644 index 0000000..74a0e26 --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/TOSCADocumentBuilderFactory.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +package org.eclipse.winery.common; + +import java.net.URL; + +import javax.xml.XMLConstants; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.validation.Schema; +import javax.xml.validation.SchemaFactory; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.xml.sax.SAXException; + +/** + * Class to produce DocumentBuilders with a pre-loaded TOSCA XSD. + * + * In a separate class as TOSCA XSD loading takes a few seconds + */ +public class TOSCADocumentBuilderFactory { + + private static final Logger logger = LoggerFactory.getLogger(TOSCADocumentBuilderFactory.class); + + public static final TOSCADocumentBuilderFactory INSTANCE = new TOSCADocumentBuilderFactory(); + private final DocumentBuilderFactory factory; + + + public TOSCADocumentBuilderFactory() { + this.factory = DocumentBuilderFactory.newInstance(); + + this.factory.setNamespaceAware(true); + + // we do not need DTD validation + this.factory.setValidating(false); + + // we do XSD validation + SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + Schema schema; + URL resource = this.getClass().getResource("/TOSCA-v1.0.xsd"); + try { + // takes a few seconds to load + schema = schemaFactory.newSchema(resource); + this.factory.setSchema(schema); + } catch (SAXException e) { + // TODO: load xml.xsd in offline mode + TOSCADocumentBuilderFactory.logger.error("Schema could not be initalized", e); + TOSCADocumentBuilderFactory.logger.debug("We continue nevertheless to enable offline usage"); + } + } + + public DocumentBuilder getTOSCADocumentBuilder() { + DocumentBuilder db; + try { + db = this.factory.newDocumentBuilder(); + } catch (ParserConfigurationException e) { + throw new IllegalStateException("document builder could not be initalized", e); + } + return db; + } + +} diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/Util.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/Util.java new file mode 100644 index 0000000..702bf41 --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/Util.java @@ -0,0 +1,603 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +package org.eclipse.winery.common; + +import java.io.ByteArrayOutputStream; +import java.io.StringWriter; +import java.io.UnsupportedEncodingException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URLDecoder; +import java.net.URLEncoder; +import java.util.List; +import java.util.SortedMap; +import java.util.SortedSet; +import java.util.TreeMap; +import java.util.TreeSet; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlSchema; +import javax.xml.namespace.QName; +import javax.xml.transform.OutputKeys; +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.lang3.StringUtils; +import org.apache.taglibs.standard.functions.Functions; +import org.eclipse.winery.common.ids.GenericId; +import org.eclipse.winery.common.ids.definitions.ArtifactTemplateId; +import org.eclipse.winery.common.ids.definitions.EntityTemplateId; +import org.eclipse.winery.common.ids.definitions.EntityTypeId; +import org.eclipse.winery.common.ids.definitions.EntityTypeImplementationId; +import org.eclipse.winery.common.ids.definitions.PolicyTemplateId; +import org.eclipse.winery.common.ids.definitions.ServiceTemplateId; +import org.eclipse.winery.common.ids.definitions.TOSCAComponentId; +import org.eclipse.winery.common.ids.definitions.imports.GenericImportId; +import org.eclipse.winery.common.ids.definitions.imports.XSDImportId; +import org.eclipse.winery.common.ids.elements.TOSCAElementId; +import org.eclipse.winery.model.tosca.TEntityType; +import org.eclipse.winery.model.tosca.TExtensibleElements; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.w3c.dom.Element; + +public class Util { + + private static final Logger logger = LoggerFactory.getLogger(Util.class); + + public static final String FORBIDDEN_CHARACTER_REPLACEMENT = "_"; + + + public static String URLdecode(String s) { + try { + return URLDecoder.decode(s, "UTF-8"); + } catch (UnsupportedEncodingException e) { + throw new IllegalStateException(); + } + } + + public static String URLencode(String s) { + try { + return URLEncoder.encode(s, "UTF-8"); + } catch (UnsupportedEncodingException e) { + throw new IllegalStateException(); + } + } + + public static String DoubleURLencode(String s) { + return Util.URLencode(Util.URLencode(s)); + } + + /** + * Encodes the namespace and the localname of the given qname, separated by + * "/" + * + * @return <double encoded namespace>"/"<double encoded localname> + */ + public static String DoubleURLencode(QName qname) { + String ns = Util.DoubleURLencode(qname.getNamespaceURI()); + String localName = Util.DoubleURLencode(qname.getLocalPart()); + return ns + "/" + localName; + } + + public static boolean isRelativeURI(String uri) { + URI u; + try { + u = new URI(uri); + } catch (URISyntaxException e) { + Util.logger.debug(e.getMessage(), e); + // fallback + return false; + } + return !u.isAbsolute(); + } + + /** + * @param c the element directly nested below a definitions element in XML + */ + public static String getURLpathFragmentForCollection(Class<? extends TExtensibleElements> c) { + String res = c.getName().toLowerCase(); + int lastDot = res.lastIndexOf('.'); + // classname is something like <package>.T<type>. We are only interested + // in "<type>". Therefore "+2" from the dot onwards + res = res.substring(lastDot + 2); + res = res + "s"; + return res; + } + + public static String getEverythingBetweenTheLastDotAndBeforeId(Class<? extends GenericId> cls) { + String res = cls.getName(); + // Everything between the last "." and before "Id" is the Type + int dotIndex = res.lastIndexOf('.'); + assert (dotIndex >= 0); + return res.substring(dotIndex + 1, res.length() - "Id".length()); + } + + public static String getTypeForElementId(Class<? extends TOSCAElementId> idClass) { + return Util.getEverythingBetweenTheLastDotAndBeforeId(idClass); + } + + /** + * @return Singular type name for the given id. E.g., "ServiceTemplateId" + * gets "ServiceTemplate" + */ + public static String getTypeForComponentId(Class<? extends TOSCAComponentId> idClass) { + return Util.getEverythingBetweenTheLastDotAndBeforeId(idClass); + } + + /** + * Returns the root path fragment for the given + * AbstractComponentIntanceResource + * + * With trailing slash + * + * @return [ComponentName]s/ + */ + public static String getRootPathFragment(Class<? extends TOSCAComponentId> idClass) { + // quick handling of imports special case + // in the package naming, all other component instances have a this intermediate location, but not in the URLs + // The package handling is in {@link org.eclipse.winery.repository.Utils.getIntermediateLocationStringForType(String, String)} + String res; + if (GenericImportId.class.isAssignableFrom(idClass)) { + // this fires if idClass is a sub class from ImportCollectionId + // special treatment for imports + res = "imports/"; + if (XSDImportId.class.isAssignableFrom(idClass)) { + res = res + "http%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema/"; + } else { + throw new IllegalStateException("Not possible to determine local storage for generic imports class"); + } + // we have the complete root path fragment + return res; + } else { + res = ""; + } + res = res + Util.getTypeForComponentId(idClass); + res = res.toLowerCase(); + res = res + "s"; + res = res + "/"; + return res; + } + + /** + * Just calls @link{qname2href} + * + * Introduced because of JSP error + * "The method qname2href(String, Class<? extends TExtensibleElements>, QName) in the type Util is not applicable for the arguments (String, Class<TNodeType>, QName, String)" + */ + public static String qname2hrefWithName(String repositoryUrl, Class<? extends TExtensibleElements> element, QName qname, String name) { + return Util.qname2href(repositoryUrl, element, qname, name); + } + + /** + * + * @param repositoryUrl the URL to the repository + * @param element the element directly nested below a definitions element in + * XML + * @param qname the QName of the element + * @param name (optional) if not null, the name to display as text in the + * reference. Default: localName of the QName + * @return an <code>a</code> HTML element pointing to the given id + */ + public static String qname2href(String repositoryUrl, Class<? extends TExtensibleElements> element, QName qname, String name) { + if (StringUtils.isEmpty(repositoryUrl)) { + throw new IllegalArgumentException("Repository URL must not be empty."); + } + if (element == null) { + throw new IllegalArgumentException("Element class must not be null."); + } + if (qname == null) { + return "(none)"; + } + + String absoluteURL = repositoryUrl + "/" + Util.getURLpathFragmentForCollection(element) + "/" + Util.DoubleURLencode(qname.getNamespaceURI()) + "/" + Util.DoubleURLencode(qname.getLocalPart()); + + if (name == null) { + // fallback if no name is given + name = qname.getLocalPart(); + } + // sanitize name + name = Functions.escapeXml(name); + + String res = "<a target=\"_blank\" data-qname=\"" + qname + "\" href=\"" + absoluteURL + "\">" + name + "</a>"; + return res; + } + + /** + * + * @param repositoryUrl the URL to the repository + * @param element the element directly nested below a definitions element in + * XML + * @param qname the QName of the element + * @return an <code>a</code> HTML element pointing to the given id + */ + public static String qname2href(String repositoryUrl, Class<? extends TExtensibleElements> element, QName qname) { + return Util.qname2href(repositoryUrl, element, qname, null); + } + + /** + * Returns a visual rendering of minInstances + * + * @param minInstances the value to render + */ + public static String renderMinInstances(Integer minInstances) { + if ((minInstances == null) || (minInstances == 1)) { + // == null: default value: display nothing -- *never* happens: + // the function *always* returns 1 even, if no explicit value is set. Therefore, we also display "" if the default value 1 is set + return ""; + } else { + return Integer.toString(minInstances); + } + } + + /** + * Returns a visual rendering of maxInstances + * + * @param maxInstances the value to render + */ + public static String renderMaxInstances(String maxInstances) { + if ((maxInstances == null) || (maxInstances.equals("1"))) { + // default value display nothing + // "1" is returned even if no explicit value has been set. + return ""; + } else if (maxInstances.equals("unbounded")) { + return "∞"; + } else { + // maxInstance is a plain integer + // return as is + return maxInstances; + } + } + + /** + * @return the local name of a Class representing a TOSCA element + */ + private static String getLocalName(@SuppressWarnings("rawtypes") Class clazz) { + String localName = clazz.getName(); + // a class defined within another class is written as superclass$class. E.g., EntityTemplate$Properties + // We use the real class name + int pos = localName.lastIndexOf('$'); + if (pos == -1) { + pos = localName.lastIndexOf('.'); + } + localName = localName.substring(pos + 1); + if (localName.equals("TDocumentation")) { + // special case for documentation: the local name starts with a lower case letter + localName = "documentation"; + } else if (localName.startsWith("T")) { + localName = localName.substring(1); + } + return localName; + } + + public static <T extends Object> JAXBElement<T> getJAXBElement(Class<T> clazz, T obj) { + String namespace = null; + XmlRootElement xmlRootElement = clazz.getAnnotation(XmlRootElement.class); + if (xmlRootElement != null) { + namespace = xmlRootElement.namespace(); + if ("##default".equals(namespace)) { + XmlSchema xmlSchema = clazz.getPackage().getAnnotation(XmlSchema.class); + if (xmlSchema != null) { + namespace = xmlSchema.namespace(); + } else { + // trigger default handling + namespace = null; + } + } + } + if (namespace == null) { + // fallback non-specified namespaces + namespace = org.eclipse.winery.common.constants.Namespaces.TOSCA_NAMESPACE; + } + String localName = Util.getLocalName(clazz); + QName qname = new QName(namespace, localName); + JAXBElement<T> rootElement = new JAXBElement<T>(qname, clazz, obj); + return rootElement; + } + + /** + * Method similar to {@link + * org.eclipse.winery.repository.Utils.getXMLAsString(Class, Object)}. + * + * Differences: + * <ul> + * <li>XML processing instruction is not included in the header</li> + * <li>JAXBcontext is created at each call</li> + * </ul> + */ + public static <T extends Object> String getXMLAsString(Class<T> clazz, T obj) throws Exception { + // copied from Utils java, but we create an own JAXBcontext here + // JAXBSupport cannot be used as this relies on a MockElement, which we do not want to factor out to winery.common + + JAXBContext context; + try { + // For winery classes, eventually the package+jaxb.index method could be better. See http://stackoverflow.com/a/3628525/873282 + // @formatter:off + context = JAXBContext.newInstance( + TEntityType.class); + // @formatter:on + } catch (JAXBException e) { + throw new IllegalStateException(e); + } + + JAXBElement<T> rootElement = Util.getJAXBElement(clazz, obj); + Marshaller m = context.createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); + m.setProperty(Marshaller.JAXB_FRAGMENT, true); + // m.setProperty("com.sun.xml.bind.namespacePrefixMapper", JAXBSupport.prefixMapper); + + StringWriter w = new StringWriter(); + try { + m.marshal(rootElement, w); + } catch (JAXBException e) { + throw new IllegalStateException(e); + } + String res = w.toString(); + return res; + } + + public static String getXMLAsString(Element el) { + TransformerFactory tf = TransformerFactory.newInstance(); + Transformer t; + try { + t = tf.newTransformer(); + } catch (TransformerConfigurationException e) { + throw new IllegalStateException("Could not instantiate Transformer", e); + } + t.setOutputProperty(OutputKeys.INDENT, "yes"); + Source source = new DOMSource(el); + ByteArrayOutputStream os = new ByteArrayOutputStream(); + Result target = new StreamResult(os); + try { + t.transform(source, target); + } catch (TransformerException e) { + Util.logger.debug(e.getMessage(), e); + throw new IllegalStateException("Could not transform dom node to string", e); + } + return os.toString(); + } + + /** + * Determines whether the instance belonging to the given id supports the + * "name" attribute. This cannot be done using the super class as the TOSCA + * specification treats that differently in the case of EntityTemplates + * + * NOTE: The respective subclasses of AbstractComponentInstanceResource have + * to implement {@link org.eclipse.winery.repository.resources.IHasName} + * + * @param id the id to test + * @return true if the TOSCA model class belonging to the given id supports + * the method "getName()" in addition to "getId()" + */ + public static boolean instanceSupportsNameAttribute(Class<? extends TOSCAComponentId> idClass) { + if (ServiceTemplateId.class.isAssignableFrom(idClass)) { + return true; + } else if ((EntityTypeId.class.isAssignableFrom(idClass)) || (EntityTypeImplementationId.class.isAssignableFrom(idClass))) { + // name is available, but no id attribute + return false; + } else if (GenericImportId.class.isAssignableFrom(idClass)) { + return false; + } else { + assert (EntityTemplateId.class.isAssignableFrom(idClass)); + if (ArtifactTemplateId.class.isAssignableFrom(idClass)) { + return true; + } else if (PolicyTemplateId.class.isAssignableFrom(idClass)) { + return true; + } else { + throw new IllegalStateException("Unimplemented branch to determine if getName() exists"); + } + } + } + + public static String getLastURIPart(String loc) { + int posSlash = loc.lastIndexOf('/'); + String fileName = loc.substring(posSlash + 1); + return fileName; + } + + /** + * Determines a color belonging to the given name + */ + public static String getColor(String name) { + int hash = name.hashCode(); + // trim to 3*8=24 bits + hash = hash & 0xFFFFFF; + // check if color is more than #F0F0F0, i.e., too light + if (((hash & 0xF00000) >= 0xF00000) && (((hash & 0x00F000) >= 0x00F000) && ((hash & 0x0000F0) >= 0x0000F0))) { + // set one high bit to zero for each channel. That makes the overall color darker + hash = hash & 0xEFEFEF; + } + String colorStr = String.format("#%06x", hash); + return colorStr; + } + + /** + * Determines the name of the CSS class used for relationshipTypes at + * nodeTemplateRenderer.tag + */ + public static String makeCSSName(String namespace, String localName) { + // according to http://stackoverflow.com/a/79022/873282 everything is allowed + // However, {namespace}id does NOT work + String res = namespace + "_" + localName; + res = res.replaceAll("[^\\w\\d_]", "_"); + return res; + } + + /** + * @see {@link org.eclipse.winery.common.Util.makeCSSName(String, String)} + */ + public static String makeCSSName(QName qname) { + return Util.makeCSSName(qname.getNamespaceURI(), qname.getLocalPart()); + } + + public static SortedMap<String, SortedSet<String>> convertQNameListToNamespaceToLocalNameList(List<QName> list) { + SortedMap<String, SortedSet<String>> res = new TreeMap<>(); + for (QName qname : list) { + SortedSet<String> localNameSet = res.get(qname.getNamespaceURI()); + if (localNameSet == null) { + localNameSet = new TreeSet<>(); + res.put(qname.getNamespaceURI(), localNameSet); + } + localNameSet.add(qname.getLocalPart()); + } + return res; + } + + public static String namespaceToJavaPackage(String namespace) { + URI uri; + try { + uri = new URI(namespace); + } catch (URISyntaxException e) { + Util.logger.debug(e.getMessage(), e); + return "uri.invalid"; + } + StringBuilder sb = new StringBuilder(); + + String host = uri.getHost(); + if (host != null) { + Util.addReversed(sb, host, "\\."); + } + + String path = uri.getPath(); + if (!path.equals("")) { + if (path.startsWith("/")) { + // remove first slash + path = path.substring(1); + } + + // and then handle the string + Util.addAsIs(sb, path, "/"); + } + + // remove the final dot + sb.replace(sb.length() - 1, sb.length(), ""); + + return Util.cleanName(sb.toString()); + } + + private static String cleanName(String s) { + // TODO: Integrate with other name cleaning functions. "." should not be replaced as it is used as separator in the java package name + // @formatter:off + return s.replace(":", Util.FORBIDDEN_CHARACTER_REPLACEMENT) + .replace("/", Util.FORBIDDEN_CHARACTER_REPLACEMENT) + .replace(" ", Util.FORBIDDEN_CHARACTER_REPLACEMENT) + .replace("-", Util.FORBIDDEN_CHARACTER_REPLACEMENT); + // @formatter:on + } + + + /* + * Valid chars: See + * <ul> + * <li>http://www.w3.org/TR/REC-xml-names/#NT-NCName</li> + * <li>http://www.w3.org/TR/REC-xml/#NT-Name</li> + * </ul> + */ + // NameCharRange \u10000-\ueffff is not supported by Java + private static final String NCNameStartChar_RegExp = "[A-Z_a-z\u00c0-\u00d6\u00d8\u00f6\u00f8\u02ff\u0370\u037d\u037f-\u1fff\u200c-\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]"; + private static final String NCNameChar_RegExp = Util.NCNameStartChar_RegExp + "|[-\\.0-9\u00B7\u0300-\u036F\u203F-\u2040]"; + private static final Pattern NCNameStartChar_Pattern = Pattern.compile(Util.NCNameStartChar_RegExp); + private static final Pattern NCNameChar_RegExp_Pattern = Pattern.compile(Util.NCNameChar_RegExp); + + + /** + * Removes all non-NCName characters from the given string and returns the + * result + * + * This function should be consistent with + * org.eclipse.winery.common.Util.cleanName(String) + * + * TODO: This method seems to be equal to {@link + * org.eclipse.winery.repository.Utils.createXMLidAsString(String)}. These + * methods should be merged. + * + */ + public static String makeNCName(String text) { + if (StringUtils.isEmpty(text)) { + return text; + } + + StringBuffer res = new StringBuffer(); + + // handle start + String start = text.substring(0, 1); + Matcher m = Util.NCNameStartChar_Pattern.matcher(start); + if (m.matches()) { + res.append(start); + } else { + // not a valid character + res.append("_"); + } + + // handle remaining characters; + for (int i = 1; i < text.length(); i++) { + String s = text.substring(i, i + 1); + m = Util.NCNameChar_RegExp_Pattern.matcher(s); + if (m.matches()) { + res.append(s); + } else { + // not a valid character + res.append("_"); + } + } + + return res.toString(); + } + + private static void addAsIs(StringBuilder sb, String s, String separator) { + if (s.isEmpty()) { + return; + } + String[] split = s.split(separator); + for (int i = 0; i < split.length; i++) { + sb.append(split[i]); + sb.append("."); + } + } + + private static void addReversed(StringBuilder sb, String s, String separator) { + String[] split = s.split(separator); + for (int i = split.length - 1; i >= 0; i--) { + sb.append(split[i]); + sb.append("."); + } + } + + /** + * Bridge to client.getType(). Just calls client getType(), used by + * functions.tld. + * + * We suppress compiler warnings as JSP 2.0 do not offer support for + * generics, but we're using JSP 2.0... + * + * @param client the repository client to use + * @param qname the QName to resolve + * @param clazz the class the QName is describing + * @return {@inheritDoc} + */ + @SuppressWarnings({"rawtypes", "unchecked"}) + public static org.eclipse.winery.model.tosca.TEntityType getType(org.eclipse.winery.common.interfaces.IWineryRepository client, javax.xml.namespace.QName qname, java.lang.Class clazz) { + return client.getType(qname, clazz); + } +} diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/beans/NamespaceIdOptionalName.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/beans/NamespaceIdOptionalName.java new file mode 100644 index 0000000..872cb04 --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/beans/NamespaceIdOptionalName.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +package org.eclipse.winery.common.beans; + +/** + * Bean containing + * <ul> + * <li>namespace</li> + * <li>id</li> + * <li>name</li> + * </ul> + * The name field is optional + */ +public class NamespaceIdOptionalName { + + private String namespace; + private String id; + private String name = null; + + + public NamespaceIdOptionalName() { + + } + + public String getNamespace() { + return this.namespace; + } + + public void setNamespace(String namespace) { + this.namespace = namespace; + } + + public String getId() { + return this.id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } +}
\ No newline at end of file diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/constants/Defaults.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/constants/Defaults.java new file mode 100644 index 0000000..a3e1368 --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/constants/Defaults.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +package org.eclipse.winery.common.constants; + +public class Defaults { + + public static final String DEFAULT_RT_HOVER_COLOR = "black"; + + // files are in src/main/webapp/images/relationshiptype + // convention: below the prefix, then the filename is either ...Left.png or ...Right.png + public static final String DEFAULT_RT_ARROWHEAD_SOURCE = "none"; + public static final String DEFAULT_RT_ARROWHEAD_TARGET = "PlainArrow"; + + public static final String DEFAULT_RT_DASH = "plain"; + public static final String DEFAULT_RT_LINEWIDTH = "1"; +} diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/constants/MimeTypes.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/constants/MimeTypes.java new file mode 100644 index 0000000..f79593c --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/constants/MimeTypes.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +package org.eclipse.winery.common.constants; + +/** + * See also {@link org.eclipse.winery.repository.backend.constants.MediaTypes} + */ +public class MimeTypes { + + public static final String MIMETYPE_TOSCA_DEFINITIONS = "application/vnd.oasis.tosca.definitions"; + + // text/xsd is NOT used for XSD as text/xml is rendered correctly in browsers + public static final String MIMETYPE_XSD = "text/xml"; + + public static final String MIMETYPE_ZIP = "application/zip"; + +} diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/constants/Namespaces.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/constants/Namespaces.java new file mode 100644 index 0000000..897aa69 --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/constants/Namespaces.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2013-2014 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +package org.eclipse.winery.common.constants; + +/** + * Defines namespace constants not available in Java7's XMLConstants + */ +public class Namespaces { + + public static final String TOSCA_NAMESPACE = "http://docs.oasis-open.org/tosca/ns/2011/12"; + public static final String TOSCA_WINERY_EXTENSIONS_NAMESPACE = "http://www.opentosca.org/winery/extensions/tosca/2013/02/12"; + + // XML Schema namespace is defined at Java7's XMLConstants.W3C_XML_SCHEMA_NS_URI + + public static final String URI_BPMN20_MODEL = "http://www.omg.org/spec/BPMN/20100524/MODEL"; + public static final String URI_BPMN4TOSCA_20 = "http://www.opentosca.org/bpmn4tosca"; + public static final String URI_BPEL20_ABSTRACT = "http://docs.oasis-open.org/wsbpel/2.0/process/abstract"; + public static final String URI_BPEL20_EXECUTABLE = "http://docs.oasis-open.org/wsbpel/2.0/process/executable"; +} diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/constants/QNames.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/constants/QNames.java new file mode 100644 index 0000000..dcc5de0 --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/constants/QNames.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +package org.eclipse.winery.common.constants; + +import javax.xml.namespace.QName; + +public class QNames { + + public static final QName QNAME_BORDER_COLOR = new QName(Namespaces.TOSCA_WINERY_EXTENSIONS_NAMESPACE, "bordercolor"); + public static final QName QNAME_COLOR = new QName(Namespaces.TOSCA_WINERY_EXTENSIONS_NAMESPACE, "color"); + + // Boolean flag to indicate that the import is generated via the Winery Properties Defintion + public static final QName QNAME_WINERYS_PROPERTIES_DEFINITION_ATTRIBUTE = new QName(Namespaces.TOSCA_WINERY_EXTENSIONS_NAMESPACE, "wpd"); +} diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/GenericId.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/GenericId.java new file mode 100644 index 0000000..756137e --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/GenericId.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +package org.eclipse.winery.common.ids; + +/** + * Superclass for all IDs appearing in Winery. These are: + * <ul> + * <li>All IDs of elements directly nested in a Definitions element</li> + * <li>Subelements of those</li> + * </ul> + * + * We assume that TOSCAcomponentId is always the root node of nested IDs + * + */ +public abstract class GenericId implements Comparable<GenericId> { + + private final XMLId xmlId; + + + protected GenericId(XMLId xmlId) { + this.xmlId = xmlId; + } + + /** + * @return null if (this instanceof TOSCAcomponentId). In that case, the + * element is already the root element + */ + public abstract GenericId getParent(); + + /** + * @return the XML id of this thing + */ + public XMLId getXmlId() { + return this.xmlId; + } + + @Override + public abstract boolean equals(Object obj); + + @Override + public abstract int hashCode(); + + @Override + public String toString() { + return this.getClass().toString() + " / " + this.getXmlId().toString(); + } +} diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/IdNames.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/IdNames.java new file mode 100644 index 0000000..fb1af16 --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/IdNames.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +package org.eclipse.winery.common.ids; + +/** + * The names of ids, used to set XMLids for collections of things + */ +public class IdNames { + + public static final String DEPLOYMENTARTIFACTS = "deploymentartifacts"; + public static final String INSTANCESTATES = "instancestates"; + public static final String INTERFACES = "interfaces"; // used at node type + public static final String INPUTPARAMETERS = "inputParameters"; + public static final String IMPLEMENTATIONARTIFACTS = "implementationartifacts"; + public static final String NODETEMPLATES = "nodetemplates"; + public static final String OUTPUTPARAMETERS = "outputParameters"; + public static final String PROPERTIES = "properties"; + public static final String RELATIONSHIPTEMPLATES = "relationshiptemplates"; + public static final String SOURCEINTERFACES = "sourceinterfaces"; + public static final String TARGETINTERFACES = "targetinterfaces"; + public static final String TOPOLOGYTEMPATE = "topologytemplate"; +} diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/IdUtil.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/IdUtil.java new file mode 100644 index 0000000..90970f1 --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/IdUtil.java @@ -0,0 +1,104 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +package org.eclipse.winery.common.ids; + +import org.eclipse.winery.common.Util; +import org.eclipse.winery.common.ids.definitions.TOSCAComponentId; +import org.eclipse.winery.common.ids.elements.TOSCAElementId; + +/** + * Helper methods for Winery's Id system + */ +public class IdUtil { + + /** + * Returns the namespace where the given Id is nested in. As the id is not a + * TOSCAComponentId, it cannot be directly asked for its parent. Merely, the + * parent has to be asked for its namespace. The parent, in turn, if it is + * no TOSCAComponentId has to ask his parent. + * + * @param id the id refering to an element, where the namespace has to be + * checked for + * @return the namespace of the element denoted by id + */ + public static Namespace getNamespace(GenericId id) { + if (id instanceof TOSCAComponentId) { + return ((TOSCAComponentId) id).getNamespace(); + } else { + return IdUtil.getNamespace(id.getParent()); + } + } + + /** + * Executes the real conversion to a path fragment + * + * @param id the id to transform to a path + * @param doubleEncode true if each sub fragment should be double encoded, + * false if it should be encoded only once + * @return + */ + private static String getPathFragment(final GenericId id, final boolean doubleEncode) { + String toInsert; + if (id instanceof TOSCAComponentId) { + // @return "[ComponentName]s/{namespace}/{id}/" + TOSCAComponentId tId = (TOSCAComponentId) id; + String res = Util.getRootPathFragment(tId.getClass()); + toInsert = tId.getNamespace().getEncoded(); + if (doubleEncode) { + toInsert = Util.URLencode(toInsert); + } + res = res + toInsert + "/"; + toInsert = tId.getXmlId().getEncoded(); + if (doubleEncode) { + toInsert = Util.URLencode(toInsert); + } + res = res + toInsert + "/"; + return res; + } else if (id instanceof TOSCAElementId) { + toInsert = id.getXmlId().getEncoded(); + if (doubleEncode) { + toInsert = Util.URLencode(toInsert); + } + return IdUtil.getPathFragment(id.getParent()) + toInsert + "/"; + } else { + throw new IllegalStateException("Unknown subclass of GenericId " + id.getClass()); + } + } + + /** + * Returns the fragment of the path belonging to the id + * + * For instance, an Id of type ServiceTemplateId has + * <code>servicetemplates/{encoded ns}/{encoded name}/</code> + * + * @param id the element to return the path fragment for + * @return the path fragment. This is <em>not</em> intended to be used + * inside a URL + */ + public static String getPathFragment(GenericId id) { + return IdUtil.getPathFragment(id, false); + } + + /** + * Returns the fragment of the URL path belonging to the id + * + * For instance, an Id of type ServiceTemplateId has + * <code>servicetemplates/{double encoded ns}/{double encoded name}/</encode> + * + * @param id the element to return the path fragment for + * @return the path fragment to be used inside an URL + */ + public static String getURLPathFragment(GenericId id) { + return IdUtil.getPathFragment(id, true); + } + +} diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/Namespace.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/Namespace.java new file mode 100644 index 0000000..a848c14 --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/Namespace.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2013,2015 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +package org.eclipse.winery.common.ids; + +import org.apache.commons.lang3.StringUtils; +import org.eclipse.winery.common.StringEncodedAndDecoded; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class Namespace extends StringEncodedAndDecoded { + + private static final Logger logger = LoggerFactory.getLogger(Namespace.class); + + + public Namespace(String uri, boolean URLencoded) { + super(uri, URLencoded); + if (StringUtils.isEmpty(uri)) { + Namespace.logger.error("Empty URI has been passed to Namespace constructor."); + // throw new IllegalArgumentException("uri must not be empty or null."); + } + } + +} diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/XMLId.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/XMLId.java new file mode 100644 index 0000000..67bfb9f --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/XMLId.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +package org.eclipse.winery.common.ids; + +import org.eclipse.winery.common.StringEncodedAndDecoded; + +/** + * Handles an ID given in the XML + * + * We need to have this class as IDs are also passed at URIs at requests. To + * ease handling, we use StringEncodedAndDecoded + * + * There is no check for valid XMLids (AKA allowed NCname characters). This is + * OK as, for instance, properties make use of this fact and store the name as + * ID + */ +public class XMLId extends StringEncodedAndDecoded { + + public XMLId(String id, boolean URLencoded) { + super(id, URLencoded); + } + +} diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/ArtifactTemplateId.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/ArtifactTemplateId.java new file mode 100644 index 0000000..d74c986 --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/ArtifactTemplateId.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +package org.eclipse.winery.common.ids.definitions; + +import javax.xml.namespace.QName; + +import org.eclipse.winery.common.ids.Namespace; +import org.eclipse.winery.common.ids.XMLId; + +public class ArtifactTemplateId extends EntityTemplateId { + + public ArtifactTemplateId(Namespace namespace, XMLId xmlId) { + super(namespace, xmlId); + } + + public ArtifactTemplateId(String ns, String id, boolean URLencoded) { + super(ns, id, URLencoded); + } + + public ArtifactTemplateId(QName qname) { + super(qname); + } +} diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/ArtifactTypeId.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/ArtifactTypeId.java new file mode 100644 index 0000000..80de6a9 --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/ArtifactTypeId.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +package org.eclipse.winery.common.ids.definitions; + +import javax.xml.namespace.QName; + +import org.eclipse.winery.common.ids.Namespace; +import org.eclipse.winery.common.ids.XMLId; + +public class ArtifactTypeId extends EntityTypeId { + + public ArtifactTypeId(Namespace namespace, XMLId xmlId) { + super(namespace, xmlId); + } + + public ArtifactTypeId(String ns, String id, boolean URLencoded) { + super(ns, id, URLencoded); + } + + public ArtifactTypeId(QName qname) { + this(new Namespace(qname.getNamespaceURI(), false), new XMLId(qname.getLocalPart(), false)); + } + +} diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/CapabilityTypeId.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/CapabilityTypeId.java new file mode 100644 index 0000000..18268c9 --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/CapabilityTypeId.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +package org.eclipse.winery.common.ids.definitions; + +import javax.xml.namespace.QName; + +import org.eclipse.winery.common.ids.Namespace; +import org.eclipse.winery.common.ids.XMLId; + +public final class CapabilityTypeId extends EntityTypeId { + + public CapabilityTypeId(Namespace namespace, XMLId xmlId) { + super(namespace, xmlId); + } + + public CapabilityTypeId(String ns, String id, boolean URLencoded) { + super(ns, id, URLencoded); + } + + public CapabilityTypeId(QName qname) { + super(qname); + } + +} diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/EntityTemplateId.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/EntityTemplateId.java new file mode 100644 index 0000000..16995b2 --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/EntityTemplateId.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +package org.eclipse.winery.common.ids.definitions; + +import javax.xml.namespace.QName; + +import org.eclipse.winery.common.ids.Namespace; +import org.eclipse.winery.common.ids.XMLId; +import org.eclipse.winery.common.ids.elements.TOSCAElementId; + +/** + * ArtifactTemplates, PolicyTemplates, and ServiceTemplates are + * <em>directly nested</em> in a Definitions element. RelationshipTemplates and + * NodeTemplates are not. When approaching an EntityTemplateId, it is a thing + * directly nested in a Definitions element. + * + * The others have {@link TOSCAElementId} as parent + */ +public abstract class EntityTemplateId extends TOSCAComponentId { + + public EntityTemplateId(Namespace namespace, XMLId xmlId) { + super(namespace, xmlId); + } + + public EntityTemplateId(String ns, String id, boolean URLencoded) { + super(ns, id, URLencoded); + } + + public EntityTemplateId(QName qname) { + super(qname); + } + +} diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/EntityTypeId.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/EntityTypeId.java new file mode 100644 index 0000000..6378baf --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/EntityTypeId.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +package org.eclipse.winery.common.ids.definitions; + +import javax.xml.namespace.QName; + +import org.eclipse.winery.common.ids.Namespace; +import org.eclipse.winery.common.ids.XMLId; + +public abstract class EntityTypeId extends TOSCAComponentId { + + public EntityTypeId(Namespace namespace, XMLId xmlId) { + super(namespace, xmlId); + } + + public EntityTypeId(String ns, String id, boolean URLencoded) { + super(ns, id, URLencoded); + } + + public EntityTypeId(QName type) { + super(type); + } + +} diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/EntityTypeImplementationId.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/EntityTypeImplementationId.java new file mode 100644 index 0000000..cc10800 --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/EntityTypeImplementationId.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +package org.eclipse.winery.common.ids.definitions; + +import org.eclipse.winery.common.ids.Namespace; +import org.eclipse.winery.common.ids.XMLId; + +public abstract class EntityTypeImplementationId extends TOSCAComponentId { + + public EntityTypeImplementationId(Namespace namespace, XMLId xmlId) { + super(namespace, xmlId); + } + + public EntityTypeImplementationId(String ns, String id, boolean URLencoded) { + super(ns, id, URLencoded); + } +} diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/NodeTypeId.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/NodeTypeId.java new file mode 100644 index 0000000..d1410c0 --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/NodeTypeId.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +package org.eclipse.winery.common.ids.definitions; + +import javax.xml.namespace.QName; + +import org.eclipse.winery.common.ids.Namespace; +import org.eclipse.winery.common.ids.XMLId; + +public final class NodeTypeId extends TopologyGraphElementEntityTypeId { + + public NodeTypeId(Namespace namespace, XMLId xmlId) { + super(namespace, xmlId); + } + + public NodeTypeId(String ns, String id, boolean URLencoded) { + super(ns, id, URLencoded); + } + + public NodeTypeId(QName type) { + super(type); + } + +} diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/NodeTypeImplementationId.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/NodeTypeImplementationId.java new file mode 100644 index 0000000..48ab36a --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/NodeTypeImplementationId.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +package org.eclipse.winery.common.ids.definitions; + +import org.eclipse.winery.common.ids.Namespace; +import org.eclipse.winery.common.ids.XMLId; + +public final class NodeTypeImplementationId extends EntityTypeImplementationId { + + public NodeTypeImplementationId(Namespace namespace, XMLId xmlId) { + super(namespace, xmlId); + } + + public NodeTypeImplementationId(String ns, String id, boolean URLencoded) { + super(ns, id, URLencoded); + } +} diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/PolicyTemplateId.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/PolicyTemplateId.java new file mode 100644 index 0000000..ff9e4b8 --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/PolicyTemplateId.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +package org.eclipse.winery.common.ids.definitions; + +import javax.xml.namespace.QName; + +import org.eclipse.winery.common.ids.Namespace; +import org.eclipse.winery.common.ids.XMLId; + +public final class PolicyTemplateId extends EntityTemplateId { + + public PolicyTemplateId(Namespace namespace, XMLId xmlId) { + super(namespace, xmlId); + } + + public PolicyTemplateId(String ns, String id, boolean URLencoded) { + super(ns, id, URLencoded); + } + + public PolicyTemplateId(QName qname) { + super(qname); + } +} diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/PolicyTypeId.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/PolicyTypeId.java new file mode 100644 index 0000000..48d4a4c --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/PolicyTypeId.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +package org.eclipse.winery.common.ids.definitions; + +import javax.xml.namespace.QName; + +import org.eclipse.winery.common.ids.Namespace; +import org.eclipse.winery.common.ids.XMLId; + +public final class PolicyTypeId extends EntityTypeId { + + public PolicyTypeId(Namespace namespace, XMLId xmlId) { + super(namespace, xmlId); + } + + public PolicyTypeId(String ns, String id, boolean URLencoded) { + super(ns, id, URLencoded); + } + + public PolicyTypeId(QName qname) { + super(qname); + } + +} diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/RelationshipTypeId.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/RelationshipTypeId.java new file mode 100644 index 0000000..1648b09 --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/RelationshipTypeId.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +package org.eclipse.winery.common.ids.definitions; + +import javax.xml.namespace.QName; + +import org.eclipse.winery.common.ids.Namespace; +import org.eclipse.winery.common.ids.XMLId; + +public final class RelationshipTypeId extends TopologyGraphElementEntityTypeId { + + public RelationshipTypeId(Namespace namespace, XMLId xmlId) { + super(namespace, xmlId); + } + + public RelationshipTypeId(String ns, String id, boolean URLencoded) { + super(ns, id, URLencoded); + } + public RelationshipTypeId(QName qname) { + super(qname); + } + +} diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/RelationshipTypeImplementationId.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/RelationshipTypeImplementationId.java new file mode 100644 index 0000000..61c0238 --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/RelationshipTypeImplementationId.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +package org.eclipse.winery.common.ids.definitions; + +import org.eclipse.winery.common.ids.Namespace; +import org.eclipse.winery.common.ids.XMLId; + +public final class RelationshipTypeImplementationId extends EntityTypeImplementationId { + + public RelationshipTypeImplementationId(Namespace namespace, XMLId xmlId) { + super(namespace, xmlId); + } + + public RelationshipTypeImplementationId(String ns, String id, boolean URLencoded) { + super(ns, id, URLencoded); + } +} diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/RequirementTypeId.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/RequirementTypeId.java new file mode 100644 index 0000000..4b01833 --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/RequirementTypeId.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +package org.eclipse.winery.common.ids.definitions; + +import javax.xml.namespace.QName; + +import org.eclipse.winery.common.ids.Namespace; +import org.eclipse.winery.common.ids.XMLId; + +public final class RequirementTypeId extends EntityTypeId { + + public RequirementTypeId(Namespace namespace, XMLId xmlId) { + super(namespace, xmlId); + } + + public RequirementTypeId(String ns, String id, boolean URLencoded) { + super(ns, id, URLencoded); + } + + public RequirementTypeId(QName qname) { + super(qname); + } +} diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/ServiceTemplateId.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/ServiceTemplateId.java new file mode 100644 index 0000000..7001a49 --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/ServiceTemplateId.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +package org.eclipse.winery.common.ids.definitions; + +import javax.xml.namespace.QName; + +import org.eclipse.winery.common.ids.Namespace; +import org.eclipse.winery.common.ids.XMLId; + +public final class ServiceTemplateId extends EntityTemplateId { + + public ServiceTemplateId(Namespace namespace, XMLId xmlId) { + super(namespace, xmlId); + } + + public ServiceTemplateId(String ns, String id, boolean URLencoded) { + super(ns, id, URLencoded); + } + + public ServiceTemplateId(QName qname) { + super(qname); + } + +} diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/TOSCAComponentId.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/TOSCAComponentId.java new file mode 100644 index 0000000..e9ce856 --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/TOSCAComponentId.java @@ -0,0 +1,116 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +package org.eclipse.winery.common.ids.definitions; + +import javax.xml.namespace.QName; + +import org.eclipse.winery.common.ids.GenericId; +import org.eclipse.winery.common.ids.Namespace; +import org.eclipse.winery.common.ids.XMLId; + +/** + * Identifies a TOSCA component. Each component is required to be identified + * subclasses this class + * + * A TOSCAcomponentId has a namespace and an id within that namespace. In XML, + * the ID might be serialized as NCName (in the case of EntityTypes and + * EntityTemplates) and as xs:id (in the case of EntityTypeImplementations) + * + * Components are elements, which may appear directly nested in TDefinitions: + * <ul> + * <li>ServiceTemplates,</li> + * <li>EntityTypes,</li + * <li>EntityTypeImplementations,</li> + * <li>EntityTemplates</li> + * </ul> + */ +public abstract class TOSCAComponentId extends GenericId { + + private final Namespace namespace; + + + public TOSCAComponentId(Namespace namespace, XMLId xmlId) { + super(xmlId); + this.namespace = namespace; + } + + /** + * Creates a new id based on strings. This constructor is required for + * {@link AbstractComponentsResource} + * + * @param ns the namespace to be used + * @param id the id to be used + * @param URLencoded true: both Strings are URLencoded, false: both Strings + * are not URLencoded + */ + public TOSCAComponentId(String ns, String id, boolean URLencoded) { + this(new Namespace(ns, URLencoded), new XMLId(id, URLencoded)); + } + + public TOSCAComponentId(QName qname) { + this(qname.getNamespaceURI(), qname.getLocalPart(), false); + } + + public QName getQName() { + QName qname = new QName(this.getNamespace().getDecoded(), this.getXmlId().getDecoded()); + return qname; + } + + public Namespace getNamespace() { + return this.namespace; + } + + @Override + public int hashCode() { + return this.namespace.hashCode() ^ this.getXmlId().hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof TOSCAComponentId)) { + return false; + } else { + TOSCAComponentId other = (TOSCAComponentId) obj; + return this.getXmlId().equals(other.getXmlId()) && this.namespace.equals(other.namespace); + } + } + + @Override + public String toString() { + QName qn = this.getQName(); + return this.getClass().toString() + " / " + qn.toString(); + } + + @Override + public GenericId getParent() { + return null; + } + + @Override + public int compareTo(GenericId o1) { + if (o1 instanceof TOSCAComponentId) { + TOSCAComponentId o = (TOSCAComponentId) o1; + int res = this.getXmlId().compareTo(o.getXmlId()); + if (res == 0) { + res = this.getNamespace().compareTo(o.getNamespace()); + } + return res; + } else { + // comparing TOSCAcomponentIDs with non-TOSCAcomponentIDs is not + // possible + throw new IllegalStateException(); + } + } +} diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/TopologyGraphElementEntityTypeId.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/TopologyGraphElementEntityTypeId.java new file mode 100644 index 0000000..9eceb42 --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/TopologyGraphElementEntityTypeId.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +package org.eclipse.winery.common.ids.definitions; + +import javax.xml.namespace.QName; + +import org.eclipse.winery.common.ids.Namespace; +import org.eclipse.winery.common.ids.XMLId; + +/** + * An instance of this class is either a NodeTypeId or a RelationShipTypeId + */ +public abstract class TopologyGraphElementEntityTypeId extends EntityTypeId { + + public TopologyGraphElementEntityTypeId(Namespace namespace, XMLId xmlId) { + super(namespace, xmlId); + } + + public TopologyGraphElementEntityTypeId(String ns, String id, boolean URLencoded) { + super(ns, id, URLencoded); + } + + public TopologyGraphElementEntityTypeId(QName type) { + super(type); + } + +} diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/imports/GenericImportId.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/imports/GenericImportId.java new file mode 100644 index 0000000..3b81236 --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/imports/GenericImportId.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +package org.eclipse.winery.common.ids.definitions.imports; + +import org.apache.commons.io.FilenameUtils; +import org.eclipse.winery.model.tosca.TImport; +import org.eclipse.winery.common.Util; +import org.eclipse.winery.common.ids.Namespace; +import org.eclipse.winery.common.ids.XMLId; +import org.eclipse.winery.common.ids.definitions.TOSCAComponentId; + +/** + * class for import ids (not used for definitions) + * + * // Convention: id of import is filename without extension + */ +public class GenericImportId extends TOSCAComponentId { + + private final String type; + + + /** + * @param type the importType (e.g., MimeTypes.MIMETYPE_XSD) + */ + public GenericImportId(Namespace namespace, XMLId xmlId, String type) { + super(namespace, xmlId); + this.type = type; + } + + public GenericImportId(String ns, String id, boolean encoded, String type) { + super(ns, id, encoded); + this.type = type; + } + + /** + * Generates an ImportId based on an TImport object The import has to be an + * import created by winery. This method uses the convention that the id is + * derived from the location + * + * @param i the TImport element to derive an id from + */ + public GenericImportId(TImport i) { + this(i.getNamespace(), GenericImportId.getId(i), false, i.getImportType()); + } + + private static String getId(TImport i) { + String fileName = Util.getLastURIPart(i.getLocation()); + String id = FilenameUtils.removeExtension(fileName); + return id; + } + + public String getType() { + return this.type; + } +} diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/imports/XSDImportId.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/imports/XSDImportId.java new file mode 100644 index 0000000..940e8d3 --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/imports/XSDImportId.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +package org.eclipse.winery.common.ids.definitions.imports; + +import javax.xml.XMLConstants; + +import org.eclipse.winery.common.ids.Namespace; +import org.eclipse.winery.common.ids.XMLId; + +/** + * Models an import of type XML Schema Definition + * + * Required for a special treatment in {@link + * org.eclipse.winery.repository.Utils. + * getAllXSDefinitionsForTypeAheadSelection(short)} + */ +public class XSDImportId extends GenericImportId { + + public XSDImportId(String ns, String id, boolean encoded) { + super(ns, id, encoded, XMLConstants.W3C_XML_SCHEMA_NS_URI); + } + + public XSDImportId(Namespace ns, XMLId id) { + super(ns, id, XMLConstants.W3C_XML_SCHEMA_NS_URI); + } + +} diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/package-info.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/package-info.java new file mode 100644 index 0000000..ac34b49 --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/definitions/package-info.java @@ -0,0 +1,17 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +/** + * This package contains ids for all components, which are directly nested in a + * definitions element. See CSPRD01, Section 4.1 + */ +package org.eclipse.winery.common.ids.definitions; + diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/elements/PlanId.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/elements/PlanId.java new file mode 100644 index 0000000..49c2c2a --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/elements/PlanId.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +package org.eclipse.winery.common.ids.elements; + +import org.eclipse.winery.common.ids.XMLId; + +public class PlanId extends TOSCAElementId { + + public PlanId(PlansId parent, XMLId xmlId) { + super(parent, xmlId); + } + +} diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/elements/PlansId.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/elements/PlansId.java new file mode 100644 index 0000000..bd703dd --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/elements/PlansId.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +package org.eclipse.winery.common.ids.elements; + +import org.eclipse.winery.common.ids.XMLId; +import org.eclipse.winery.common.ids.definitions.ServiceTemplateId; + +/** + * Pseudo-Id for plans nested in one service template + * + * results in the path "plans/" + */ +public class PlansId extends TOSCAElementId { + + public PlansId(ServiceTemplateId parent) { + super(parent, new XMLId("plans", true)); + } + +} diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/elements/TOSCAElementId.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/elements/TOSCAElementId.java new file mode 100644 index 0000000..139a567 --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/elements/TOSCAElementId.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +package org.eclipse.winery.common.ids.elements; + +import org.eclipse.winery.common.ids.GenericId; +import org.eclipse.winery.common.ids.XMLId; + +/** + * Models an ID of a TOSCA element, which is NOT a TOSCAcomponentId + * + * It has a parent and an xmlId + */ +public abstract class TOSCAElementId extends GenericId { + + private final GenericId parent; + + + public TOSCAElementId(GenericId parent, XMLId xmlId) { + super(xmlId); + this.parent = parent; + } + + @Override + public GenericId getParent() { + return this.parent; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof TOSCAElementId) { + TOSCAElementId otherId = (TOSCAElementId) obj; + // the XML id has to be equal and the parents have to be equal + return (otherId.getXmlId().equals(this.getXmlId())) && (otherId.getParent().equals(this.getParent())); + } else { + return false; + } + } + + @Override + public int compareTo(GenericId o1) { + if (o1 instanceof TOSCAElementId) { + TOSCAElementId o = (TOSCAElementId) o1; + if (this.getParent().equals(o.getParent())) { + return this.getXmlId().compareTo(o.getXmlId()); + } else { + return this.getParent().compareTo(o.getParent()); + } + } else { + // comparing TOSCAcomponentIDs with non-TOSCAcomponentIDs is not + // possible + throw new IllegalStateException(); + } + } + + @Override + public int hashCode() { + return this.getParent().hashCode() ^ this.getXmlId().hashCode(); + } + + @Override + public String toString() { + String res; + res = this.getClass().toString() + " / " + this.getXmlId().getDecoded(); + res += "\n"; + res += "parent: " + this.getParent().toString(); + return res; + } +} diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/elements/package-info.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/elements/package-info.java new file mode 100644 index 0000000..0fd2942 --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/ids/elements/package-info.java @@ -0,0 +1,17 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +/** + * This package contains ids for all TOSCA element, which are <b>NOT</b> + * directly nested in a definitions element. + */ +package org.eclipse.winery.common.ids.elements; + diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/interfaces/IWineryRepository.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/interfaces/IWineryRepository.java new file mode 100644 index 0000000..5cfe754 --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/interfaces/IWineryRepository.java @@ -0,0 +1,149 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +package org.eclipse.winery.common.interfaces; + +import java.util.Collection; +import java.util.List; +import java.util.SortedSet; + +import javax.xml.namespace.QName; + +import org.eclipse.winery.common.ids.GenericId; +import org.eclipse.winery.common.ids.definitions.TOSCAComponentId; +import org.eclipse.winery.model.tosca.TDefinitions; +import org.eclipse.winery.model.tosca.TEntityType; +import org.eclipse.winery.model.tosca.TTopologyTemplate; + +/** + * This interface is used by the repository client to get access to the + * repository. + * + * This interface should be removed and the client should be able to use + * "IWineryRepositoryCommon" only. + */ +public interface IWineryRepository extends IWineryRepositoryCommon { + + /** + * Returns all namespaces used by all known TOSCA components and namespaces + * where a prefix is defined for + * + * String is used as return type as Java's QName also uses String as + * parameter to denote a namespace + */ + public SortedSet<String> getNamespaces(); + + /** + * Returns a list of the QNames of all available types. Types can be node + * types, service templates, artifact types, artifact templates. + * + * This method obsoletes methods like "getQNameListOfAllArtifactTypes": One + * just has to call getQNameListOfAllTypes(TArtifactType.class) + * + * @return List of QNames of all types + */ + <T extends TEntityType> List<QName> getQNameListOfAllTypes(Class<T> type); + + /** + * Get the TEntityType belonging to the given QName + * + * @return null if there is no data on the server + */ + <T extends TEntityType> T getType(QName qname, Class<T> type); + + /** + * Queries the repository for instances of the given type. Returns pairs of + * QNames and names. The names are added as some component instances do + * carry a name. + * + * If the component instance does not carry an explicit name, the localName + * of the QName is used as name. + * + * @param type the type to get all instances of + * @return a collection of QName/name pairs + */ + Collection<QNameWithName> getListOfAllInstances(Class<? extends TOSCAComponentId> type); + + /** + * Returns the associated name for the given id. + * + * Since not all TOSCA entities have names, this method may only be used for + * entities supporting names. If it is used for entities not having a name, + * null is returned. + * + * @param id references the entity to query for a name + * @return the name or null if no name is available + */ + String getName(GenericId id); + + /** + * Returns a list of all available types. Types can be node types, service + * templates, artifact types. Note that artifact templates are + * TEntityTemplates and thus cannot be retrieved by this method. + * + * This method obsoletes methods like "getAllArtifactTypes": One just has to + * call getallTypes(TArtifactType.class) + * + * @return List of all types + */ + <T extends TEntityType> Collection<T> getAllTypes(Class<T> type); + + /** + * @return List of all types with associated elements (such as deployment + * artifacts). Each type is nested in a separate Definitions Element + */ + <T extends TEntityType> Collection<TDefinitions> getAllTypesWithAssociatedElements(Class<T> type); + + /** + * Returns the topology template associated to the given service template + * + * @param serviceTemplate a QName of the sericeTemplate with full namespace + * @return null if nothing is found + */ + TTopologyTemplate getTopologyTemplate(QName serviceTemplate); + + /** + * Replaces (or creates) the provided topology template + * + * @param serviceTemplate the service template the given topolgoy template + * belongs to + * @param topologyTemplate the topology template to use + */ + void setTopologyTemplate(QName serviceTemplate, TTopologyTemplate topologyTemplate) throws Exception; + + /** + * Returns a reference to the artifact type registered for the given file + * extensions. Returns null if no such artifact type exists. + * + * @param extension the file extension to look up. + * @return Reference in the form of a QName to the artifact type matching + * the given file extension. + */ + QName getArtifactTypeQNameForExtension(String extension); + + /** + * Creates a component of the type idClass. + * + * @param qname + * @param type + * @throws QNameAlreadyExistsException + */ + void createComponent(QName qname, Class<? extends TOSCAComponentId> idClass) throws QNameAlreadyExistsException; + + /** + * Creates the specified artifact template + * + * @param qname the namespace and name of the artifact template + * @param artifactType the artifact type of the artifact template + * @throws QNameAlreadyExistsException if the given QName already exists + */ + void createArtifactTemplate(QName qname, QName artifactType) throws QNameAlreadyExistsException; +} diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/interfaces/IWineryRepositoryCommon.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/interfaces/IWineryRepositoryCommon.java new file mode 100644 index 0000000..7221489 --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/interfaces/IWineryRepositoryCommon.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +package org.eclipse.winery.common.interfaces; + +import java.io.IOException; + +import org.eclipse.winery.common.ids.GenericId; + +/** + * Enables access to the winery repository via Ids defined in package + * {@link org.eclipse.winery.common.ids} + * + * Methods are moved from + * {@link org.eclipse.winery.repository.backend.IGenericRepository} to here as + * soon there is an implementation for them. The ultimate goal is to eliminate + * IGenericRepository + * + * These methods are shared between {@link IWineryRepository} and + * {@link org.eclipse.winery.repository.backend.IRepository} + */ +public interface IWineryRepositoryCommon { + + /** + * Deletes the TOSCA element <b>and all sub elements</b> referenced by the + * given id from the repository + * + * We assume that each id is a directory + * + * @param id + */ + public void forceDelete(GenericId id) throws IOException; + +} diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/interfaces/QNameAlreadyExistsException.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/interfaces/QNameAlreadyExistsException.java new file mode 100644 index 0000000..d089935 --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/interfaces/QNameAlreadyExistsException.java @@ -0,0 +1,18 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +package org.eclipse.winery.common.interfaces; + +public class QNameAlreadyExistsException extends Exception { + + private static final long serialVersionUID = 1L; + +} diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/interfaces/QNameWithName.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/interfaces/QNameWithName.java new file mode 100644 index 0000000..96c2e43 --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/interfaces/QNameWithName.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +package org.eclipse.winery.common.interfaces; + +import javax.xml.namespace.QName; + +/** + * This class is used to pass around QNames with associated names in string + * format + */ +public class QNameWithName { + + public QName qname; + public String name; +} diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/propertydefinitionkv/PropertyDefinitionKV.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/propertydefinitionkv/PropertyDefinitionKV.java new file mode 100644 index 0000000..f8cc236 --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/propertydefinitionkv/PropertyDefinitionKV.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +package org.eclipse.winery.common.propertydefinitionkv; + +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "PropertyDefinition") +public class PropertyDefinitionKV { + + private String key; + private String type; + + + public PropertyDefinitionKV() { + super(); + } + + public PropertyDefinitionKV(String key, String type) { + super(); + this.setKey(key); + this.setType(type); + } + + public String getKey() { + return this.key; + } + + public void setKey(String key) { + if (key == null) { + throw new IllegalArgumentException(); + } + this.key = key; + } + + public String getType() { + return this.type; + } + + public void setType(String type) { + if (type == null) { + throw new IllegalArgumentException(); + } + this.type = type; + } + + @Override + public int hashCode() { + return this.key.hashCode(); + } +} diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/propertydefinitionkv/PropertyDefinitionKVList.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/propertydefinitionkv/PropertyDefinitionKVList.java new file mode 100644 index 0000000..445bda6 --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/propertydefinitionkv/PropertyDefinitionKVList.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +package org.eclipse.winery.common.propertydefinitionkv; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "PropertyDefinitions") +public class PropertyDefinitionKVList extends ArrayList<PropertyDefinitionKV> { + + private static final long serialVersionUID = -6442041855597987094L; + + + @XmlElement(name = "PropertyDefinition") + public List<PropertyDefinitionKV> getPropertyDefinitionKVs() { + return this; + } + +} diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/propertydefinitionkv/WinerysPropertiesDefinition.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/propertydefinitionkv/WinerysPropertiesDefinition.java new file mode 100644 index 0000000..548e87b --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/propertydefinitionkv/WinerysPropertiesDefinition.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +package org.eclipse.winery.common.propertydefinitionkv; + +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import org.eclipse.winery.common.constants.Namespaces; + +/** + * This is Winery's main extension element for a key/value based properties + * definition + */ +@XmlRootElement(name = "PropertiesDefinition") +public class WinerysPropertiesDefinition { + + private String namespace; + private String elementName; + private PropertyDefinitionKVList propertyDefinitionKVList; + private Boolean isDerivedFromXSD = Boolean.FALSE; + + + @XmlAttribute(name = "namespace") + public String getNamespace() { + return this.namespace; + } + + public void setNamespace(String namespace) { + this.namespace = namespace; + } + + @XmlAttribute(name = "elementname") + public String getElementName() { + return this.elementName; + } + + public void setElementName(String localName) { + this.elementName = localName; + } + + @XmlElement(name = "properties") + public PropertyDefinitionKVList getPropertyDefinitionKVList() { + return this.propertyDefinitionKVList; + } + + public void setPropertyDefinitionKVList(PropertyDefinitionKVList propertyDefinitionKVList) { + this.propertyDefinitionKVList = propertyDefinitionKVList; + } + + /** + * @return null if not derived from XSD, "Boolean.TRUE" otherwise. This + * leads JAXB to write the attribute only if derivedFromXSD is true + */ + @XmlAttribute(name = "derivedFromXSD", namespace = Namespaces.TOSCA_WINERY_EXTENSIONS_NAMESPACE) + public Boolean getIsDerivedFromXSD() { + if ((this.isDerivedFromXSD != null) && (this.isDerivedFromXSD)) { + return Boolean.TRUE; + } else { + return null; + } + } + + public void setIsDerivedFromXSD(Boolean isDerivedFromXSD) { + this.isDerivedFromXSD = isDerivedFromXSD; + } + +} diff --git a/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/propertydefinitionkv/package-info.java b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/propertydefinitionkv/package-info.java new file mode 100644 index 0000000..169e755 --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/java/org/eclipse/winery/common/propertydefinitionkv/package-info.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +/** + * This package defines the data structures for key/value property handling + * + * The XML Schema is generated based on the user configuration. The namespace + * for the schema is the namespace of the respective type with + * {@code /propertiesdefinition/<localname>} appended, where {@code <localname>} + * is the local name of the entity type, where the properties definition is + * defined. + * + */ +@XmlSchema(namespace = Namespaces.TOSCA_WINERY_EXTENSIONS_NAMESPACE, elementFormDefault = XmlNsForm.QUALIFIED) +package org.eclipse.winery.common.propertydefinitionkv; + +import javax.xml.bind.annotation.XmlNsForm; +import javax.xml.bind.annotation.XmlSchema; + +import org.eclipse.winery.common.constants.Namespaces; + diff --git a/winery/org.eclipse.winery.common/src/main/resources/TOSCA-v1.0.xsd b/winery/org.eclipse.winery.common/src/main/resources/TOSCA-v1.0.xsd new file mode 100644 index 0000000..8bed0e0 --- /dev/null +++ b/winery/org.eclipse.winery.common/src/main/resources/TOSCA-v1.0.xsd @@ -0,0 +1,791 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Topology and Orchestration Specification for Cloud Applications Version 1.0 + Committee Specification Draft 08 + 09 May 2013 + Copyright (c) OASIS Open 2013. All rights reserved. + Source: http://docs.oasis-open.org/tosca/TOSCA/v1.0/csd08/schemas/ +--> +<xs:schema targetNamespace="http://docs.oasis-open.org/tosca/ns/2011/12" elementFormDefault="qualified" attributeFormDefault="unqualified" xmlns="http://docs.oasis-open.org/tosca/ns/2011/12" xmlns:xs="http://www.w3.org/2001/XMLSchema"> + <xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://www.w3.org/2001/xml.xsd"/> + <xs:element name="documentation" type="tDocumentation"/> + <xs:complexType name="tDocumentation" mixed="true"> + <xs:sequence> + <xs:any processContents="lax" minOccurs="0" maxOccurs="unbounded"/> + </xs:sequence> + <xs:attribute name="source" type="xs:anyURI"/> + <xs:attribute ref="xml:lang"/> + </xs:complexType> + <xs:complexType name="tExtensibleElements"> + <xs:sequence> + <xs:element ref="documentation" minOccurs="0" maxOccurs="unbounded"/> + <xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/> + </xs:sequence> + <xs:anyAttribute namespace="##other" processContents="lax"/> + </xs:complexType> + <xs:complexType name="tImport"> + <xs:complexContent> + <xs:extension base="tExtensibleElements"> + <xs:attribute name="namespace" type="xs:anyURI"/> + <xs:attribute name="location" type="xs:anyURI"/> + <xs:attribute name="importType" type="importedURI" use="required"/> + </xs:extension> + </xs:complexContent> + </xs:complexType> + <xs:element name="Definitions"> + <xs:complexType> + <xs:complexContent> + <xs:extension base="tDefinitions"/> + </xs:complexContent> + </xs:complexType> + </xs:element> + <xs:complexType name="tDefinitions"> + <xs:complexContent> + <xs:extension base="tExtensibleElements"> + <xs:sequence> + <xs:element name="Extensions" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="Extension" type="tExtension" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="Import" type="tImport" minOccurs="0" maxOccurs="unbounded"/> + <xs:element name="Types" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:choice maxOccurs="unbounded"> + <xs:element name="ServiceTemplate" type="tServiceTemplate"/> + <xs:element name="NodeType" type="tNodeType"/> + <xs:element name="NodeTypeImplementation" type="tNodeTypeImplementation"/> + <xs:element name="RelationshipType" type="tRelationshipType"/> + <xs:element name="RelationshipTypeImplementation" type="tRelationshipTypeImplementation"/> + <xs:element name="RequirementType" type="tRequirementType"/> + <xs:element name="CapabilityType" type="tCapabilityType"/> + <xs:element name="ArtifactType" type="tArtifactType"/> + <xs:element name="ArtifactTemplate" type="tArtifactTemplate"/> + <xs:element name="PolicyType" type="tPolicyType"/> + <xs:element name="PolicyTemplate" type="tPolicyTemplate"/> + </xs:choice> + </xs:sequence> + <xs:attribute name="id" type="xs:ID" use="required"/> + <xs:attribute name="name" type="xs:string" use="optional"/> + <xs:attribute name="targetNamespace" type="xs:anyURI" use="required"/> + </xs:extension> + </xs:complexContent> + </xs:complexType> + <xs:complexType name="tServiceTemplate"> + <xs:complexContent> + <xs:extension base="tExtensibleElements"> + <xs:sequence> + <xs:element name="Tags" type="tTags" minOccurs="0"/> + <xs:element name="BoundaryDefinitions" type="tBoundaryDefinitions" minOccurs="0"/> + <xs:element name="TopologyTemplate" type="tTopologyTemplate"/> + <xs:element name="Plans" type="tPlans" minOccurs="0"/> + </xs:sequence> + <xs:attribute name="id" type="xs:ID" use="required"/> + <xs:attribute name="name" type="xs:string" use="optional"/> + <xs:attribute name="targetNamespace" type="xs:anyURI"/> + <xs:attribute name="substitutableNodeType" type="xs:QName" use="optional"/> + </xs:extension> + </xs:complexContent> + </xs:complexType> + <xs:complexType name="tTags"> + <xs:sequence> + <xs:element name="Tag" type="tTag" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + <xs:complexType name="tTag"> + <xs:attribute name="name" type="xs:string" use="required"/> + <xs:attribute name="value" type="xs:string" use="required"/> + </xs:complexType> + <xs:complexType name="tBoundaryDefinitions"> + <xs:sequence> + <xs:element name="Properties" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:any namespace="##other"/> + <xs:element name="PropertyMappings" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="PropertyMapping" type="tPropertyMapping" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + </xs:element> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="PropertyConstraints" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="PropertyConstraint" type="tPropertyConstraint" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="Requirements" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="Requirement" type="tRequirementRef" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="Capabilities" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="Capability" type="tCapabilityRef" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="Policies" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="Policy" type="tPolicy" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="Interfaces" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="Interface" type="tExportedInterface" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + </xs:element> + </xs:sequence> + </xs:complexType> + <xs:complexType name="tPropertyMapping"> + <xs:attribute name="serviceTemplatePropertyRef" type="xs:string" use="required"/> + <xs:attribute name="targetObjectRef" type="xs:IDREF" use="required"/> + <xs:attribute name="targetPropertyRef" type="xs:string" use="required"/> + </xs:complexType> + <xs:complexType name="tRequirementRef"> + <xs:attribute name="name" type="xs:string" use="optional"/> + <xs:attribute name="ref" type="xs:IDREF" use="required"/> + </xs:complexType> + <xs:complexType name="tCapabilityRef"> + <xs:attribute name="name" type="xs:string" use="optional"/> + <xs:attribute name="ref" type="xs:IDREF" use="required"/> + </xs:complexType> + <xs:complexType name="tEntityType" abstract="true"> + <xs:complexContent> + <xs:extension base="tExtensibleElements"> + <xs:sequence> + <xs:element name="Tags" type="tTags" minOccurs="0"/> + <xs:element name="DerivedFrom" minOccurs="0"> + <xs:complexType> + <xs:attribute name="typeRef" type="xs:QName" use="required"/> + </xs:complexType> + </xs:element> + <xs:element name="PropertiesDefinition" minOccurs="0"> + <xs:complexType> + <xs:attribute name="element" type="xs:QName"/> + <xs:attribute name="type" type="xs:QName"/> + </xs:complexType> + </xs:element> + </xs:sequence> + <xs:attribute name="name" type="xs:NCName" use="required"/> + <xs:attribute name="abstract" type="tBoolean" default="no"/> + <xs:attribute name="final" type="tBoolean" default="no"/> + <xs:attribute name="targetNamespace" type="xs:anyURI" use="optional"/> + </xs:extension> + </xs:complexContent> + </xs:complexType> + <xs:complexType name="tEntityTemplate" abstract="true"> + <xs:complexContent> + <xs:extension base="tExtensibleElements"> + <xs:sequence> + <xs:element name="Properties" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:any namespace="##other" processContents="lax"/> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="PropertyConstraints" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="PropertyConstraint" type="tPropertyConstraint" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + </xs:element> + </xs:sequence> + <xs:attribute name="id" type="xs:ID" use="required"/> + <xs:attribute name="type" type="xs:QName" use="required"/> + </xs:extension> + </xs:complexContent> + </xs:complexType> + <xs:complexType name="tNodeTemplate"> + <xs:complexContent> + <xs:extension base="tEntityTemplate"> + <xs:sequence> + <xs:element name="Requirements" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="Requirement" type="tRequirement" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="Capabilities" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="Capability" type="tCapability" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="Policies" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="Policy" type="tPolicy" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="DeploymentArtifacts" type="tDeploymentArtifacts" minOccurs="0"/> + </xs:sequence> + <xs:attribute name="name" type="xs:string" use="optional"/> + <xs:attribute name="minInstances" type="xs:int" use="optional" default="1"/> + <xs:attribute name="maxInstances" use="optional" default="1"> + <xs:simpleType> + <xs:union> + <xs:simpleType> + <xs:restriction base="xs:nonNegativeInteger"> + <xs:pattern value="([1-9]+[0-9]*)"/> + </xs:restriction> + </xs:simpleType> + <xs:simpleType> + <xs:restriction base="xs:string"> + <xs:enumeration value="unbounded"/> + </xs:restriction> + </xs:simpleType> + </xs:union> + </xs:simpleType> + </xs:attribute> + </xs:extension> + </xs:complexContent> + </xs:complexType> + <xs:complexType name="tTopologyTemplate"> + <xs:complexContent> + <xs:extension base="tExtensibleElements"> + <xs:choice maxOccurs="unbounded"> + <xs:element name="NodeTemplate" type="tNodeTemplate"/> + <xs:element name="RelationshipTemplate" type="tRelationshipTemplate"/> + </xs:choice> + </xs:extension> + </xs:complexContent> + </xs:complexType> + <xs:complexType name="tRelationshipType"> + <xs:complexContent> + <xs:extension base="tEntityType"> + <xs:sequence> + <xs:element name="InstanceStates" type="tTopologyElementInstanceStates" minOccurs="0"/> + <xs:element name="SourceInterfaces" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="Interface" type="tInterface" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="TargetInterfaces" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="Interface" type="tInterface" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="ValidSource" minOccurs="0"> + <xs:complexType> + <xs:attribute name="typeRef" type="xs:QName" use="required"/> + </xs:complexType> + </xs:element> + <xs:element name="ValidTarget" minOccurs="0"> + <xs:complexType> + <xs:attribute name="typeRef" type="xs:QName" use="required"/> + </xs:complexType> + </xs:element> + </xs:sequence> + </xs:extension> + </xs:complexContent> + </xs:complexType> + <xs:complexType name="tRelationshipTypeImplementation"> + <xs:complexContent> + <xs:extension base="tExtensibleElements"> + <xs:sequence> + <xs:element name="Tags" type="tTags" minOccurs="0"/> + <xs:element name="DerivedFrom" minOccurs="0"> + <xs:complexType> + <xs:attribute name="relationshipTypeImplementationRef" type="xs:QName" use="required"/> + </xs:complexType> + </xs:element> + <xs:element name="RequiredContainerFeatures" type="tRequiredContainerFeatures" minOccurs="0"/> + <xs:element name="ImplementationArtifacts" type="tImplementationArtifacts" minOccurs="0"/> + </xs:sequence> + <xs:attribute name="name" type="xs:NCName" use="required"/> + <xs:attribute name="targetNamespace" type="xs:anyURI" use="optional"/> + <xs:attribute name="relationshipType" type="xs:QName" use="required"/> + <xs:attribute name="abstract" type="tBoolean" use="optional" default="no"/> + <xs:attribute name="final" type="tBoolean" use="optional" default="no"/> + </xs:extension> + </xs:complexContent> + </xs:complexType> + <xs:complexType name="tRelationshipTemplate"> + <xs:complexContent> + <xs:extension base="tEntityTemplate"> + <xs:sequence> + <xs:element name="SourceElement"> + <xs:complexType> + <xs:attribute name="ref" type="xs:IDREF" use="required"/> + </xs:complexType> + </xs:element> + <xs:element name="TargetElement"> + <xs:complexType> + <xs:attribute name="ref" type="xs:IDREF" use="required"/> + </xs:complexType> + </xs:element> + <xs:element name="RelationshipConstraints" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="RelationshipConstraint" maxOccurs="unbounded"> + <xs:complexType> + <xs:sequence> + <xs:any namespace="##other" processContents="lax" minOccurs="0"/> + </xs:sequence> + <xs:attribute name="constraintType" type="xs:anyURI" use="required"/> + </xs:complexType> + </xs:element> + </xs:sequence> + </xs:complexType> + </xs:element> + </xs:sequence> + <xs:attribute name="name" type="xs:string" use="optional"/> + </xs:extension> + </xs:complexContent> + </xs:complexType> + <xs:complexType name="tNodeType"> + <xs:complexContent> + <xs:extension base="tEntityType"> + <xs:sequence> + <xs:element name="RequirementDefinitions" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="RequirementDefinition" type="tRequirementDefinition" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="CapabilityDefinitions" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="CapabilityDefinition" type="tCapabilityDefinition" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="InstanceStates" type="tTopologyElementInstanceStates" minOccurs="0"/> + <xs:element name="Interfaces" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="Interface" type="tInterface" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + </xs:element> + </xs:sequence> + </xs:extension> + </xs:complexContent> + </xs:complexType> + <xs:complexType name="tNodeTypeImplementation"> + <xs:complexContent> + <xs:extension base="tExtensibleElements"> + <xs:sequence> + <xs:element name="Tags" type="tTags" minOccurs="0"/> + <xs:element name="DerivedFrom" minOccurs="0"> + <xs:complexType> + <xs:attribute name="nodeTypeImplementationRef" type="xs:QName" use="required"/> + </xs:complexType> + </xs:element> + <xs:element name="RequiredContainerFeatures" type="tRequiredContainerFeatures" minOccurs="0"/> + <xs:element name="ImplementationArtifacts" type="tImplementationArtifacts" minOccurs="0"/> + <xs:element name="DeploymentArtifacts" type="tDeploymentArtifacts" minOccurs="0"/> + </xs:sequence> + <xs:attribute name="name" type="xs:NCName" use="required"/> + <xs:attribute name="targetNamespace" type="xs:anyURI" use="optional"/> + <xs:attribute name="nodeType" type="xs:QName" use="required"/> + <xs:attribute name="abstract" type="tBoolean" use="optional" default="no"/> + <xs:attribute name="final" type="tBoolean" use="optional" default="no"/> + </xs:extension> + </xs:complexContent> + </xs:complexType> + <xs:complexType name="tRequirementType"> + <xs:complexContent> + <xs:extension base="tEntityType"> + <xs:attribute name="requiredCapabilityType" type="xs:QName" use="optional"/> + </xs:extension> + </xs:complexContent> + </xs:complexType> + <xs:complexType name="tRequirementDefinition"> + <xs:complexContent> + <xs:extension base="tExtensibleElements"> + <xs:sequence> + <xs:element name="Constraints" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="Constraint" type="tConstraint" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + </xs:element> + </xs:sequence> + <xs:attribute name="name" type="xs:string" use="required"/> + <xs:attribute name="requirementType" type="xs:QName" use="required"/> + <xs:attribute name="lowerBound" type="xs:int" use="optional" default="1"/> + <xs:attribute name="upperBound" use="optional" default="1"> + <xs:simpleType> + <xs:union> + <xs:simpleType> + <xs:restriction base="xs:nonNegativeInteger"> + <xs:pattern value="([1-9]+[0-9]*)"/> + </xs:restriction> + </xs:simpleType> + <xs:simpleType> + <xs:restriction base="xs:string"> + <xs:enumeration value="unbounded"/> + </xs:restriction> + </xs:simpleType> + </xs:union> + </xs:simpleType> + </xs:attribute> + </xs:extension> + </xs:complexContent> + </xs:complexType> + <xs:complexType name="tRequirement"> + <xs:complexContent> + <xs:extension base="tEntityTemplate"> + <xs:attribute name="name" type="xs:string" use="required"/> + </xs:extension> + </xs:complexContent> + </xs:complexType> + <xs:complexType name="tCapabilityType"> + <xs:complexContent> + <xs:extension base="tEntityType"/> + </xs:complexContent> + </xs:complexType> + <xs:complexType name="tCapabilityDefinition"> + <xs:complexContent> + <xs:extension base="tExtensibleElements"> + <xs:sequence> + <xs:element name="Constraints" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="Constraint" type="tConstraint" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + </xs:element> + </xs:sequence> + <xs:attribute name="name" type="xs:string" use="required"/> + <xs:attribute name="capabilityType" type="xs:QName" use="required"/> + <xs:attribute name="lowerBound" type="xs:int" use="optional" default="1"/> + <xs:attribute name="upperBound" use="optional" default="1"> + <xs:simpleType> + <xs:union> + <xs:simpleType> + <xs:restriction base="xs:nonNegativeInteger"> + <xs:pattern value="([1-9]+[0-9]*)"/> + </xs:restriction> + </xs:simpleType> + <xs:simpleType> + <xs:restriction base="xs:string"> + <xs:enumeration value="unbounded"/> + </xs:restriction> + </xs:simpleType> + </xs:union> + </xs:simpleType> + </xs:attribute> + </xs:extension> + </xs:complexContent> + </xs:complexType> + <xs:complexType name="tCapability"> + <xs:complexContent> + <xs:extension base="tEntityTemplate"> + <xs:attribute name="name" type="xs:string" use="required"/> + </xs:extension> + </xs:complexContent> + </xs:complexType> + <xs:complexType name="tArtifactType"> + <xs:complexContent> + <xs:extension base="tEntityType"/> + </xs:complexContent> + </xs:complexType> + <xs:complexType name="tArtifactTemplate"> + <xs:complexContent> + <xs:extension base="tEntityTemplate"> + <xs:sequence> + <xs:element name="ArtifactReferences" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="ArtifactReference" type="tArtifactReference" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + </xs:element> + </xs:sequence> + <xs:attribute name="name" type="xs:string" use="optional"/> + </xs:extension> + </xs:complexContent> + </xs:complexType> + <xs:complexType name="tDeploymentArtifacts"> + <xs:sequence> + <xs:element name="DeploymentArtifact" type="tDeploymentArtifact" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + <xs:complexType name="tDeploymentArtifact"> + <xs:complexContent> + <xs:extension base="tExtensibleElements"> + <xs:attribute name="name" type="xs:string" use="required"/> + <xs:attribute name="artifactType" type="xs:QName" use="required"/> + <xs:attribute name="artifactRef" type="xs:QName" use="optional"/> + </xs:extension> + </xs:complexContent> + </xs:complexType> + <xs:complexType name="tImplementationArtifacts"> + <xs:sequence> + <xs:element name="ImplementationArtifact" maxOccurs="unbounded"> + <xs:complexType> + <xs:complexContent> + <xs:extension base="tImplementationArtifact"/> + </xs:complexContent> + </xs:complexType> + </xs:element> + </xs:sequence> + </xs:complexType> + <xs:complexType name="tImplementationArtifact"> + <xs:complexContent> + <xs:extension base="tExtensibleElements"> + <xs:attribute name="name" type="xs:string" use="optional"/> + <xs:attribute name="interfaceName" type="xs:anyURI" use="optional"/> + <xs:attribute name="operationName" type="xs:NCName" use="optional"/> + <xs:attribute name="artifactType" type="xs:QName" use="required"/> + <xs:attribute name="artifactRef" type="xs:QName" use="optional"/> + </xs:extension> + </xs:complexContent> + </xs:complexType> + <xs:complexType name="tPlans"> + <xs:sequence> + <xs:element name="Plan" type="tPlan" maxOccurs="unbounded"/> + </xs:sequence> + <xs:attribute name="targetNamespace" type="xs:anyURI" use="optional"/> + </xs:complexType> + <xs:complexType name="tPlan"> + <xs:complexContent> + <xs:extension base="tExtensibleElements"> + <xs:sequence> + <xs:element name="Precondition" type="tCondition" minOccurs="0"/> + <xs:element name="InputParameters" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="InputParameter" type="tParameter" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="OutputParameters" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="OutputParameter" type="tParameter" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:choice> + <xs:element name="PlanModel"> + <xs:complexType> + <xs:sequence> + <xs:any namespace="##other" processContents="lax"/> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="PlanModelReference"> + <xs:complexType> + <xs:attribute name="reference" type="xs:anyURI" use="required"/> + </xs:complexType> + </xs:element> + </xs:choice> + </xs:sequence> + <xs:attribute name="id" type="xs:ID" use="required"/> + <xs:attribute name="name" type="xs:string" use="optional"/> + <xs:attribute name="planType" type="xs:anyURI" use="required"/> + <xs:attribute name="planLanguage" type="xs:anyURI" use="required"/> + </xs:extension> + </xs:complexContent> + </xs:complexType> + <xs:complexType name="tPolicyType"> + <xs:complexContent> + <xs:extension base="tEntityType"> + <xs:sequence> + <xs:element name="AppliesTo" type="tAppliesTo" minOccurs="0"/> + </xs:sequence> + <xs:attribute name="policyLanguage" type="xs:anyURI" use="optional"/> + </xs:extension> + </xs:complexContent> + </xs:complexType> + <xs:complexType name="tPolicyTemplate"> + <xs:complexContent> + <xs:extension base="tEntityTemplate"> + <xs:attribute name="name" type="xs:string" use="optional"/> + </xs:extension> + </xs:complexContent> + </xs:complexType> + <xs:complexType name="tAppliesTo"> + <xs:sequence> + <xs:element name="NodeTypeReference" maxOccurs="unbounded"> + <xs:complexType> + <xs:attribute name="typeRef" type="xs:QName" use="required"/> + </xs:complexType> + </xs:element> + </xs:sequence> + </xs:complexType> + <xs:complexType name="tPolicy"> + <xs:complexContent> + <xs:extension base="tExtensibleElements"> + <xs:attribute name="name" type="xs:string" use="optional"/> + <xs:attribute name="policyType" type="xs:QName" use="required"/> + <xs:attribute name="policyRef" type="xs:QName" use="optional"/> + </xs:extension> + </xs:complexContent> + </xs:complexType> + <xs:complexType name="tConstraint"> + <xs:sequence> + <xs:any namespace="##other" processContents="lax"/> + </xs:sequence> + <xs:attribute name="constraintType" type="xs:anyURI" use="required"/> + </xs:complexType> + <xs:complexType name="tPropertyConstraint"> + <xs:complexContent> + <xs:extension base="tConstraint"> + <xs:attribute name="property" type="xs:string" use="required"/> + </xs:extension> + </xs:complexContent> + </xs:complexType> + <xs:complexType name="tExtensions"> + <xs:complexContent> + <xs:extension base="tExtensibleElements"> + <xs:sequence> + <xs:element name="Extension" type="tExtension" maxOccurs="unbounded"/> + </xs:sequence> + </xs:extension> + </xs:complexContent> + </xs:complexType> + <xs:complexType name="tExtension"> + <xs:complexContent> + <xs:extension base="tExtensibleElements"> + <xs:attribute name="namespace" type="xs:anyURI" use="required"/> + <xs:attribute name="mustUnderstand" type="tBoolean" use="optional" default="yes"/> + </xs:extension> + </xs:complexContent> + </xs:complexType> + <xs:complexType name="tParameter"> + <xs:attribute name="name" type="xs:string" use="required"/> + <xs:attribute name="type" type="xs:string" use="required"/> + <xs:attribute name="required" type="tBoolean" use="optional" default="yes"/> + </xs:complexType> + <xs:complexType name="tInterface"> + <xs:sequence> + <xs:element name="Operation" type="tOperation" maxOccurs="unbounded"/> + </xs:sequence> + <xs:attribute name="name" type="xs:anyURI" use="required"/> + </xs:complexType> + <xs:complexType name="tExportedInterface"> + <xs:sequence> + <xs:element name="Operation" type="tExportedOperation" maxOccurs="unbounded"/> + </xs:sequence> + <xs:attribute name="name" type="xs:anyURI" use="required"/> + </xs:complexType> + <xs:complexType name="tOperation"> + <xs:complexContent> + <xs:extension base="tExtensibleElements"> + <xs:sequence> + <xs:element name="InputParameters" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="InputParameter" type="tParameter" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="OutputParameters" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="OutputParameter" type="tParameter" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + </xs:element> + </xs:sequence> + <xs:attribute name="name" type="xs:NCName" use="required"/> + </xs:extension> + </xs:complexContent> + </xs:complexType> + <xs:complexType name="tExportedOperation"> + <xs:choice> + <xs:element name="NodeOperation"> + <xs:complexType> + <xs:attribute name="nodeRef" type="xs:IDREF" use="required"/> + <xs:attribute name="interfaceName" type="xs:anyURI" use="required"/> + <xs:attribute name="operationName" type="xs:NCName" use="required"/> + </xs:complexType> + </xs:element> + <xs:element name="RelationshipOperation"> + <xs:complexType> + <xs:attribute name="relationshipRef" type="xs:IDREF" use="required"/> + <xs:attribute name="interfaceName" type="xs:anyURI" use="required"/> + <xs:attribute name="operationName" type="xs:NCName" use="required"/> + </xs:complexType> + </xs:element> + <xs:element name="Plan"> + <xs:complexType> + <xs:attribute name="planRef" type="xs:IDREF" use="required"/> + </xs:complexType> + </xs:element> + </xs:choice> + <xs:attribute name="name" type="xs:NCName" use="required"/> + </xs:complexType> + <xs:complexType name="tCondition"> + <xs:sequence> + <xs:any processContents="lax" minOccurs="0" maxOccurs="unbounded"/> + </xs:sequence> + <xs:attribute name="expressionLanguage" type="xs:anyURI" use="required"/> + </xs:complexType> + <xs:complexType name="tTopologyElementInstanceStates"> + <xs:sequence> + <xs:element name="InstanceState" maxOccurs="unbounded"> + <xs:complexType> + <xs:attribute name="state" type="xs:anyURI" use="required"/> + </xs:complexType> + </xs:element> + </xs:sequence> + </xs:complexType> + <xs:complexType name="tArtifactReference"> + <xs:choice minOccurs="0" maxOccurs="unbounded"> + <xs:element name="Include"> + <xs:complexType> + <xs:attribute name="pattern" type="xs:string" use="required"/> + </xs:complexType> + </xs:element> + <xs:element name="Exclude"> + <xs:complexType> + <xs:attribute name="pattern" type="xs:string" use="required"/> + </xs:complexType> + </xs:element> + </xs:choice> + <xs:attribute name="reference" type="xs:anyURI" use="required"/> + </xs:complexType> + <xs:complexType name="tRequiredContainerFeatures"> + <xs:sequence> + <xs:element name="RequiredContainerFeature" type="tRequiredContainerFeature" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + <xs:complexType name="tRequiredContainerFeature"> + <xs:attribute name="feature" type="xs:anyURI" use="required"/> + </xs:complexType> + <xs:simpleType name="tBoolean"> + <xs:restriction base="xs:string"> + <xs:enumeration value="yes"/> + <xs:enumeration value="no"/> + </xs:restriction> + </xs:simpleType> + <xs:simpleType name="importedURI"> + <xs:restriction base="xs:anyURI"/> + </xs:simpleType> +</xs:schema> diff --git a/winery/org.eclipse.winery.common/src/test/java/.gitkeep b/winery/org.eclipse.winery.common/src/test/java/.gitkeep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/winery/org.eclipse.winery.common/src/test/java/.gitkeep diff --git a/winery/org.eclipse.winery.common/src/test/java/META-INF/MANIFEST.MF b/winery/org.eclipse.winery.common/src/test/java/META-INF/MANIFEST.MF new file mode 100644 index 0000000..254272e --- /dev/null +++ b/winery/org.eclipse.winery.common/src/test/java/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/winery/org.eclipse.winery.common/src/test/java/org/eclipse/winery/common/ModelUtilitiesTest.java b/winery/org.eclipse.winery.common/src/test/java/org/eclipse/winery/common/ModelUtilitiesTest.java new file mode 100644 index 0000000..650241d --- /dev/null +++ b/winery/org.eclipse.winery.common/src/test/java/org/eclipse/winery/common/ModelUtilitiesTest.java @@ -0,0 +1,13 @@ +package org.eclipse.winery.common; + +import org.junit.Test; + +public class ModelUtilitiesTest { + + @Test + public void setPropertiesKV() { + // TODO: add some test here + // The test is difficult as a node type has to be generated with a wineryspropertiesdefinition, ... + } + +} diff --git a/winery/org.eclipse.winery.common/src/test/java/org/eclipse/winery/common/TestUtil.java b/winery/org.eclipse.winery.common/src/test/java/org/eclipse/winery/common/TestUtil.java new file mode 100644 index 0000000..8c0c924 --- /dev/null +++ b/winery/org.eclipse.winery.common/src/test/java/org/eclipse/winery/common/TestUtil.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2013 University of Stuttgart. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * Oliver Kopp - initial API and implementation + *******************************************************************************/ +package org.eclipse.winery.common; + +import org.junit.Assert; +import org.junit.Test; + +public class TestUtil { + + @Test + public void testNamespaceToJavaPackageFullURL() { + Assert.assertEquals("org.example.www.tosca.nodetypes", Util.namespaceToJavaPackage("http://www.example.org/tosca/nodetypes")); + } + + @Test + public void testNamespaceToJavaPackageURLWithHostOnly() { + Assert.assertEquals("org.example.www", Util.namespaceToJavaPackage("http://www.example.org/")); + } + + @Test + public void testNamespaceToJavaPackageURLWithHostOnlyAndNoFinalSlash() { + Assert.assertEquals("org.example.www", Util.namespaceToJavaPackage("http://www.example.org")); + } + + @Test + public void testNamespaceToJavaPackageURLWithNoHost() { + Assert.assertEquals("plainNCname", Util.namespaceToJavaPackage("plainNCname")); + } + + @Test + public void testNCNameFromURL() { + Assert.assertEquals("http___www.example.org", Util.makeNCName("http://www.example.org")); + } + + @Test + public void testNCNameFromNCName() { + Assert.assertEquals("NCName", Util.makeNCName("NCName")); + } +} |