├── .github ├── FUNDING.yml └── workflows │ └── build.yml ├── .gitignore ├── .gitpod.Dockerfile ├── .gitpod.yml ├── .java-version ├── .theia └── settings.json ├── LICENSE ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src └── main ├── cml └── Insurance-Example-Model.cml ├── java └── org │ └── contextmapper │ └── standalone │ └── example │ ├── ChangingModelExample.java │ ├── ContextMapGeneratorExample.java │ ├── GenericGeneratorExample.java │ ├── MDSLGeneratorExample.java │ ├── PlantUMLGeneratorExample.java │ ├── ReadingModelExample.java │ └── RefactoringExample.java └── resources └── freemarker-sample-template.ftl /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: stefan-ka 2 | 3 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: 4 | push: 5 | pull_request: 6 | 7 | jobs: 8 | build: 9 | runs-on: ubuntu-20.04 10 | 11 | steps: 12 | - uses: actions/checkout@v2 13 | - name: Set up JDK 17 14 | uses: actions/setup-java@v1 15 | with: 16 | java-version: 17 17 | - name: Gradle caches 18 | uses: actions/cache@v2 19 | with: 20 | path: | 21 | ~/.gradle/caches 22 | ~/.gradle/wrapper 23 | key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} 24 | restore-keys: | 25 | ${{ runner.os }}-gradle- 26 | - name: Grant execute permission for gradlew 27 | run: chmod +x gradlew 28 | - name: Build with Gradle 29 | run: ./gradlew clean build 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Eclipse files 5 | *.project 6 | *.classpath 7 | **/.settings 8 | bin 9 | 10 | # IntelliJ files 11 | .idea 12 | 13 | # Gradle 14 | .gradle 15 | build 16 | 17 | # Generated sources 18 | src-gen 19 | 20 | # Generated output 21 | out 22 | 23 | # Log file 24 | *.log 25 | 26 | # BlueJ files 27 | *.ctxt 28 | 29 | # Mobile Tools for Java (J2ME) 30 | .mtj.tmp/ 31 | 32 | # Package Files # 33 | *.jar 34 | *.war 35 | *.nar 36 | *.ear 37 | *.zip 38 | *.tar.gz 39 | *.rar 40 | 41 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 42 | hs_err_pid* 43 | -------------------------------------------------------------------------------- /.gitpod.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM gitpod/workspace-full 2 | 3 | # Install custom tools, runtimes, etc. 4 | # For example "bastet", a command-line tetris clone: 5 | # RUN brew install bastet 6 | # 7 | # More information: https://www.gitpod.io/docs/config-docker/ 8 | 9 | # Install Graphviz 10 | RUN sudo apt-get update \ 11 | && sudo apt-get -y install graphviz 12 | 13 | # Install JHipster 14 | RUN npm install -g generator-jhipster 15 | -------------------------------------------------------------------------------- /.gitpod.yml: -------------------------------------------------------------------------------- 1 | tasks: 2 | - init: ./gradlew clean build 3 | image: 4 | file: .gitpod.Dockerfile 5 | vscode: 6 | extensions: 7 | - contextmapper.context-mapper-vscode-extension 8 | - jebbs.plantuml@2.13.12:q7DiD6H5NTesaWYIXmeMMQ== 9 | -------------------------------------------------------------------------------- /.java-version: -------------------------------------------------------------------------------- 1 | 17.0 2 | -------------------------------------------------------------------------------- /.theia/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.exclude": { 3 | "**/.classpath": true, 4 | "**/.project": true, 5 | "**/.settings": true, 6 | "**/.factorypath": true 7 | } 8 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Context Mapper](https://raw.githubusercontent.com/wiki/ContextMapper/context-mapper-dsl/logo/cm-logo-github-small.png) 2 | # Context Mapping DSL (CML) Standalone Example Project [![Build](https://github.com/ContextMapper/context-mapper-standalone-example/actions/workflows/build.yml/badge.svg)](https://github.com/ContextMapper/context-mapper-standalone-example/actions) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) 3 | 4 | This is an example project illustrating how the [Context Mapper DSL (CML)](https://github.com/ContextMapper/context-mapper-dsl) language can be used as standalone library outside the Eclipse IDE. 5 | 6 | ## Build 7 | The Context Mapper DSL library releases are available via the Maven central repository and can therefore be integrated within your Maven or Gradle builds. 8 | 9 | **Gradle:** 10 | ```gradle 11 | implementation 'org.contextmapper:context-mapper-dsl:6.10.0' 12 | ``` 13 | 14 | **Maven:** 15 | ```xml 16 | 17 | org.contextmapper 18 | context-mapper-dsl 19 | 6.10.0 20 | 21 | ``` 22 | If you want to use our SNAPSHOT's built from the master branch ([context-mapper-dsl](https://github.com/ContextMapper/context-mapper-dsl)) you have to use the following repository: https://oss.sonatype.org/content/repositories/snapshots 23 | 24 | ### Gradle Xtext Builder Plugin 25 | This example project is built with Gradle. Have a look at [build.gradle](./build.gradle) how it is configured. With the Xtext builder plugin you ensure that your CML files are compiled at build time. 26 | 27 | ## Example Model 28 | The CML models are configured to be in the source folder **src/main/cml** (see [build.gradle](./build.gradle)). This example project contains the insurance example model ([./src/main/cml/Insurance-Example-Model.cml](./src/main/cml/Insurance-Example-Model.cml)) which can also be found in our [examples repository](https://github.com/ContextMapper/context-mapper-examples). 29 | 30 | ## Examples how to use CML models in your code 31 | This example project contains the following example classes written in Java which illustrate how to use CML models and our generators: 32 | * [ReadingModelExample](./src/main/java/org/contextmapper/standalone/example/ReadingModelExample.java): Example how to read the CML model 33 | * [ChangingModelExample](./src/main/java/org/contextmapper/standalone/example/ChangingModelExample.java): Illustrates how a model can be changed an then unparsed back to the CML file. 34 | * [PlantUMLGeneratorExample](./src/main/java/org/contextmapper/standalone/example/PlantUMLGeneratorExample.java): Shows how you can read your CML model and generate the [PlantUML diagrams](https://contextmapper.org/docs/plant-uml/) out of it easily. 35 | * [MDSLGeneratorExample](./src/main/java/org/contextmapper/standalone/example/MDSLGeneratorExample.java): Shows how to generate the [MDSL contracts](https://contextmapper.org/docs/mdsl/) out of the CML model. 36 | * [GenericGeneratorExample](./src/main/java/org/contextmapper/standalone/example/GenericGeneratorExample.java): Illustrates how you can use [Freemarker](https://freemarker.apache.org/) templates to generate arbitrary textual files out of your Context Map. 37 | 38 | For details about the generators and the CML language please consult our [online documentation](https://contextmapper.org/docs) (currently we have no further documentation how to use the tools on code level in standalone applications). 39 | If you have questions how to use specific features within your standalone Java application don't hesitate to [create an issue](https://github.com/ContextMapper/context-mapper-standalone-example/issues) or [contact us](https://contextmapper.org/getting-involved/). 40 | 41 | ## Contributing 42 | Contribution is always welcome! Here are some ways how you can contribute: 43 | * Create Github issues if you find bugs or just want to give suggestions for improvements. 44 | * This is an open source project: if you want to code, [create pull requests](https://help.github.com/articles/creating-a-pull-request/) from [forks of this repository](https://help.github.com/articles/fork-a-repo/). Please refer to a Github issue if you contribute this way. 45 | * If you want to contribute to our documentation and user guides on our website [https://contextmapper.org/](https://contextmapper.org/), create pull requests from forks of the corresponding page repo [https://github.com/ContextMapper/contextmapper.github.io](https://github.com/ContextMapper/contextmapper.github.io) or create issues [there](https://github.com/ContextMapper/contextmapper.github.io/issues). 46 | 47 | ## Licence 48 | ContextMapper is released under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0). 49 | 50 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id "java" 3 | id "eclipse" 4 | id "org.xtext.builder" version "3.0.2" 5 | } 6 | 7 | group = 'org.contextmapper' 8 | version = '1.0.0-SNAPSHOT' 9 | 10 | sourceCompatibility = '11' 11 | targetCompatibility = '11' 12 | 13 | repositories { 14 | mavenCentral() 15 | gradlePluginPortal() 16 | } 17 | 18 | dependencies { 19 | xtextLanguages "org.contextmapper:context-mapper-dsl:${cmlVersion}" 20 | 21 | implementation "org.eclipse.xtend:org.eclipse.xtend.lib:${xtendLibVersion}" 22 | implementation "org.contextmapper:context-mapper-dsl:${cmlVersion}" 23 | 24 | implementation "commons-lang:commons-lang:${commonsLangVersion}" 25 | implementation "commons-cli:commons-cli:${commonsCliVersion}" 26 | 27 | testImplementation("org.junit.jupiter:junit-jupiter-api:${junitVersion}") 28 | testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitVersion}") 29 | } 30 | 31 | xtext { 32 | languages { 33 | cml { 34 | fileExtension = 'cml' 35 | setup = 'org.contextmapper.dsl.ContextMappingDSLStandaloneSetup' 36 | generator.outlet.producesJava = true 37 | } 38 | } 39 | 40 | sourceSets { 41 | main { 42 | srcDir 'src/main/cml' 43 | } 44 | } 45 | } 46 | 47 | test { 48 | useJUnitPlatform() 49 | } 50 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # dependency versions 2 | cmlVersion=6.10.0 3 | xtendLibVersion=2.29.0 4 | junitVersion=5.9.1 5 | commonsLangVersion=2.6 6 | commonsCliVersion=1.4 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ContextMapper/context-mapper-standalone-example/87e6b3d60de6f1f7639e8a06ba6fe597f4091bb8/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | # Determine the Java command to use to start the JVM. 86 | if [ -n "$JAVA_HOME" ] ; then 87 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 88 | # IBM's JDK on AIX uses strange locations for the executables 89 | JAVACMD="$JAVA_HOME/jre/sh/java" 90 | else 91 | JAVACMD="$JAVA_HOME/bin/java" 92 | fi 93 | if [ ! -x "$JAVACMD" ] ; then 94 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 95 | 96 | Please set the JAVA_HOME variable in your environment to match the 97 | location of your Java installation." 98 | fi 99 | else 100 | JAVACMD="java" 101 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 102 | 103 | Please set the JAVA_HOME variable in your environment to match the 104 | location of your Java installation." 105 | fi 106 | 107 | # Increase the maximum file descriptors if we can. 108 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 109 | MAX_FD_LIMIT=`ulimit -H -n` 110 | if [ $? -eq 0 ] ; then 111 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 112 | MAX_FD="$MAX_FD_LIMIT" 113 | fi 114 | ulimit -n $MAX_FD 115 | if [ $? -ne 0 ] ; then 116 | warn "Could not set maximum file descriptor limit: $MAX_FD" 117 | fi 118 | else 119 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 120 | fi 121 | fi 122 | 123 | # For Darwin, add options to specify how the application appears in the dock 124 | if $darwin; then 125 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 126 | fi 127 | 128 | # For Cygwin, switch paths to Windows format before running java 129 | if $cygwin ; then 130 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 131 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 132 | JAVACMD=`cygpath --unix "$JAVACMD"` 133 | 134 | # We build the pattern for arguments to be converted via cygpath 135 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 136 | SEP="" 137 | for dir in $ROOTDIRSRAW ; do 138 | ROOTDIRS="$ROOTDIRS$SEP$dir" 139 | SEP="|" 140 | done 141 | OURCYGPATTERN="(^($ROOTDIRS))" 142 | # Add a user-defined pattern to the cygpath arguments 143 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 144 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 145 | fi 146 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 147 | i=0 148 | for arg in "$@" ; do 149 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 150 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 151 | 152 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 153 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 154 | else 155 | eval `echo args$i`="\"$arg\"" 156 | fi 157 | i=$((i+1)) 158 | done 159 | case $i in 160 | (0) set -- ;; 161 | (1) set -- "$args0" ;; 162 | (2) set -- "$args0" "$args1" ;; 163 | (3) set -- "$args0" "$args1" "$args2" ;; 164 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 165 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 166 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 167 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 168 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 169 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 170 | esac 171 | fi 172 | 173 | # Escape application args 174 | save () { 175 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 176 | echo " " 177 | } 178 | APP_ARGS=$(save "$@") 179 | 180 | # Collect all arguments for the java command, following the shell quoting and substitution rules 181 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 182 | 183 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 184 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 185 | cd "$(dirname "$0")" 186 | fi 187 | 188 | exec "$JAVACMD" "$@" 189 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem http://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 33 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 34 | 35 | @rem Find java.exe 36 | if defined JAVA_HOME goto findJavaFromJavaHome 37 | 38 | set JAVA_EXE=java.exe 39 | %JAVA_EXE% -version >NUL 2>&1 40 | if "%ERRORLEVEL%" == "0" goto init 41 | 42 | echo. 43 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 44 | echo. 45 | echo Please set the JAVA_HOME variable in your environment to match the 46 | echo location of your Java installation. 47 | 48 | goto fail 49 | 50 | :findJavaFromJavaHome 51 | set JAVA_HOME=%JAVA_HOME:"=% 52 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 53 | 54 | if exist "%JAVA_EXE%" goto init 55 | 56 | echo. 57 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 58 | echo. 59 | echo Please set the JAVA_HOME variable in your environment to match the 60 | echo location of your Java installation. 61 | 62 | goto fail 63 | 64 | :init 65 | @rem Get command-line arguments, handling Windows variants 66 | 67 | if not "%OS%" == "Windows_NT" goto win9xME_args 68 | 69 | :win9xME_args 70 | @rem Slurp the command line arguments. 71 | set CMD_LINE_ARGS= 72 | set _SKIP=2 73 | 74 | :win9xME_args_slurp 75 | if "x%~1" == "x" goto execute 76 | 77 | set CMD_LINE_ARGS=%* 78 | 79 | :execute 80 | @rem Setup the command line 81 | 82 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 83 | 84 | @rem Execute Gradle 85 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 86 | 87 | :end 88 | @rem End local scope for the variables with windows NT shell 89 | if "%ERRORLEVEL%"=="0" goto mainEnd 90 | 91 | :fail 92 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 93 | rem the _cmd.exe /c_ return code! 94 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 95 | exit /b 1 96 | 97 | :mainEnd 98 | if "%OS%"=="Windows_NT" endlocal 99 | 100 | :omega 101 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'context-mapper-standalone-example' 2 | -------------------------------------------------------------------------------- /src/main/cml/Insurance-Example-Model.cml: -------------------------------------------------------------------------------- 1 | /* Example Context Map written with 'ContextMapper DSL' */ 2 | ContextMap InsuranceContextMap { 3 | type = SYSTEM_LANDSCAPE 4 | state = TO_BE 5 | 6 | /* Add bounded contexts to this context map: */ 7 | contains CustomerManagementContext 8 | contains CustomerSelfServiceContext 9 | contains PrintingContext 10 | contains PolicyManagementContext 11 | contains RiskManagementContext 12 | contains DebtCollection 13 | 14 | /* Define the context relationships: */ 15 | 16 | CustomerSelfServiceContext [D,C]<-[U,S] CustomerManagementContext : Customer_Frontend_Backend_Relationship { // Relationship name is optional 17 | exposedAggregates = Customers 18 | } 19 | 20 | CustomerManagementContext [D,ACL]<-[U,OHS,PL] PrintingContext { 21 | implementationTechnology = "SOAP" 22 | downstreamRights = INFLUENCER 23 | exposedAggregates = Printing 24 | } 25 | 26 | PrintingContext [U,OHS,PL]->[D,ACL] PolicyManagementContext { 27 | implementationTechnology = "SOAP" 28 | exposedAggregates = Printing 29 | } 30 | 31 | RiskManagementContext [P]<->[P] PolicyManagementContext { 32 | implementationTechnology = "RabbitMQ" 33 | } 34 | 35 | PolicyManagementContext [D,CF]<-[U,OHS,PL] CustomerManagementContext { 36 | implementationTechnology = "RESTfulHTTP" 37 | exposedAggregates = Customers 38 | } 39 | 40 | RiskManagementContext [D,CF]<-[U,OHS,PL] CustomerManagementContext { 41 | implementationTechnology = "RESTfulHTTP" 42 | exposedAggregates = Customers 43 | } 44 | 45 | DebtCollection [D,ACL]<-[U,OHS,PL] PrintingContext { 46 | implementationTechnology = "SOAP" 47 | exposedAggregates = Printing 48 | } 49 | 50 | PolicyManagementContext [SK]<->[SK] DebtCollection { 51 | implementationTechnology = "Shared Java Library, Communication over RESTful HTTP" 52 | } 53 | 54 | } 55 | 56 | /* Bounded Context Definitions */ 57 | BoundedContext CustomerManagementContext implements CustomerManagementDomain { 58 | type = FEATURE 59 | domainVisionStatement = "The customer management context is responsible for managing all the data of the insurance companies customers." 60 | implementationTechnology = "Java, JEE Application" 61 | responsibilities = "Customers, Addresses" 62 | 63 | Aggregate Customers { 64 | Entity Customer { 65 | aggregateRoot 66 | 67 | - SocialInsuranceNumber sin 68 | String firstname 69 | String lastname 70 | - List
addresses 71 | 72 | def AddressId createAddress(@Address address); 73 | def boolean changeCustomer(String firstname, String lastname); 74 | } 75 | 76 | Entity Address { 77 | String street 78 | int postalCode 79 | String city 80 | } 81 | 82 | ValueObject SocialInsuranceNumber { 83 | String sin key 84 | } 85 | } 86 | 87 | } 88 | 89 | BoundedContext CustomerSelfServiceContext implements CustomerManagementDomain { 90 | type = APPLICATION 91 | domainVisionStatement = "This context represents a web application which allows the customer to login and change basic data records like the address." 92 | responsibilities = "AddressChange" 93 | implementationTechnology = "PHP Web Application" 94 | 95 | Aggregate CustomerFrontend { 96 | Entity CustomerAddressChange { 97 | aggregateRoot 98 | 99 | - UserAccount issuer 100 | - Address changedAddress 101 | } 102 | } 103 | 104 | Aggregate Acounts { 105 | Entity UserAccount { 106 | aggregateRoot 107 | 108 | String username 109 | - Customer accountCustomer 110 | } 111 | } 112 | } 113 | 114 | BoundedContext PrintingContext implements PrintingDomain { 115 | type = SYSTEM 116 | responsibilities = "Document Printing" 117 | domainVisionStatement = "An external system which provides printing services to the other Bounded Contexts." 118 | 119 | Aggregate Printing { 120 | Entity PrintingJob { 121 | aggregateRoot 122 | 123 | int printingId 124 | - Document document 125 | - Template template 126 | 127 | def PrintStatus printJob(PrintingId printingId); 128 | } 129 | 130 | Entity Document { 131 | DomainObject source 132 | String template 133 | } 134 | } 135 | 136 | Aggregate Templating { 137 | Entity Template { 138 | aggregateRoot 139 | 140 | int templateId 141 | String templateName 142 | } 143 | } 144 | } 145 | 146 | BoundedContext PolicyManagementContext implements PolicyManagementDomain { 147 | type = FEATURE 148 | domainVisionStatement = "This bounded context manages the contracts and policies of the customers." 149 | responsibilities = "Offers, Contracts, Policies" 150 | implementationTechnology = "Java, Spring App" 151 | 152 | Aggregate Offers { 153 | owner ContractsTeam 154 | 155 | Entity Offer { 156 | aggregateRoot 157 | 158 | int offerId 159 | - Customer client 160 | - List products 161 | BigDecimal price 162 | } 163 | } 164 | 165 | Aggregate Products { 166 | owner ProductsTeam 167 | 168 | Entity Product { 169 | aggregateRoot 170 | 171 | - ProductId identifier 172 | String productName 173 | } 174 | 175 | ValueObject ProductId { 176 | int productId key 177 | } 178 | } 179 | 180 | Aggregate Contract { 181 | owner ContractsTeam 182 | 183 | Entity Contract { 184 | aggregateRoot 185 | 186 | - ContractId identifier 187 | - Customer client 188 | - List products 189 | } 190 | 191 | ValueObject ContractId { 192 | int contractId key 193 | } 194 | 195 | Entity Policy { 196 | int policyNr 197 | - Contract contract 198 | BigDecimal price 199 | } 200 | } 201 | } 202 | 203 | BoundedContext RiskManagementContext implements RiskManagementDomain { 204 | type = FEATURE 205 | domainVisionStatement = "Uses data from PolicyManagement context to calculate risks." 206 | responsibilities = "Customer Risk Calculation" 207 | implementationTechnology = "Java, Spring App" 208 | 209 | Aggregate Risks { 210 | Entity CustomerRiskFactor { 211 | aggregateRoot 212 | 213 | int totalRiskFactor 214 | - List risks 215 | - Customer client 216 | } 217 | 218 | ValueObject Risk { 219 | int likelihood 220 | String risk 221 | } 222 | } 223 | } 224 | 225 | BoundedContext DebtCollection implements DebtsDomain { 226 | type = FEATURE 227 | domainVisionStatement = "The debt collection context is responsible for the financial income of the insurance company (the debts) which depend on the corresponding contracts and policies." 228 | responsibilities = "Debts, Dunning" 229 | implementationTechnology = "JEE" 230 | 231 | Aggregate Debts { 232 | Entity Debt { 233 | aggregateRoot 234 | 235 | int debtNr 236 | - Policy policy 237 | Date creationDate 238 | Date paymentDate 239 | Date paymentDeadline 240 | BigDecimal price 241 | PaymentStatus status 242 | - List dunnigs 243 | } 244 | 245 | Entity Dunning { 246 | int dunningNr 247 | - Debt debt 248 | Date dunningDate 249 | Date paymentDeadline 250 | } 251 | } 252 | } 253 | 254 | /* Teams: */ 255 | BoundedContext CustomersTeam { type TEAM } 256 | BoundedContext ContractsTeam { type TEAM } 257 | BoundedContext ProductsTeam { type TEAM } 258 | 259 | /* Domain & Subdomain Definitions */ 260 | Domain InsuranceDomain { 261 | Subdomain CustomerManagementDomain { 262 | type = CORE_DOMAIN 263 | domainVisionStatement = "Subdomain managing everything customer-related." 264 | } 265 | Subdomain PolicyManagementDomain { 266 | type = CORE_DOMAIN 267 | domainVisionStatement = "Subdomain managing contracts and policies." 268 | } 269 | Subdomain PrintingDomain { 270 | type = SUPPORTING_DOMAIN 271 | domainVisionStatement = "Service (external system) to solve printing for all kinds of documents (debts, policies, etc.)" 272 | } 273 | Subdomain RiskManagementDomain { 274 | type = GENERIC_SUBDOMAIN 275 | domainVisionStatement = "Subdomain supporting everything which relates to risk management." 276 | } 277 | Subdomain DebtsDomain { 278 | type = GENERIC_SUBDOMAIN 279 | domainVisionStatement = "Subomain including everything related to the incoming money (debts, dunning, etc.)" 280 | } 281 | } 282 | -------------------------------------------------------------------------------- /src/main/java/org/contextmapper/standalone/example/ChangingModelExample.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Context Mapper Project Team 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.contextmapper.standalone.example; 17 | 18 | import org.contextmapper.dsl.cml.CMLResource; 19 | import org.contextmapper.dsl.contextMappingDSL.Aggregate; 20 | import org.contextmapper.dsl.contextMappingDSL.BoundedContext; 21 | import org.contextmapper.dsl.contextMappingDSL.ContextMappingDSLFactory; 22 | import org.contextmapper.dsl.contextMappingDSL.ContextMappingModel; 23 | import org.contextmapper.dsl.standalone.ContextMapperStandaloneSetup; 24 | import org.contextmapper.dsl.standalone.StandaloneContextMapperAPI; 25 | import org.eclipse.xtext.resource.SaveOptions; 26 | 27 | import java.io.IOException; 28 | 29 | import static org.contextmapper.standalone.example.ReadingModelExample.INSURANCE_EXAMPLE_URI; 30 | 31 | ; 32 | 33 | /** 34 | * This example shows how you can read your CML model, change it, and unparse 35 | * the model back to you CML file. We use the CML model under 36 | * src/main/cml/Insurance-Example-Model.cml, change a Bounded Contexts name, and 37 | * parse it back to the file. 38 | * 39 | * @author Stefan Kapferer 40 | * 41 | */ 42 | public class ChangingModelExample { 43 | 44 | public static void main(String[] args) throws IOException { 45 | // Setup and loading CML file: 46 | StandaloneContextMapperAPI contextMapper = ContextMapperStandaloneSetup.getStandaloneAPI(); 47 | CMLResource resource = contextMapper.loadCML(INSURANCE_EXAMPLE_URI); 48 | ContextMappingModel model = resource.getContextMappingModel(); 49 | 50 | // We search for a Bounded Context ... 51 | BoundedContext customerManagementBC = model.getBoundedContexts().stream() 52 | .filter(bc -> bc.getName().equals("CustomerManagementContext")).findFirst().get(); 53 | 54 | // ... and add a new Aggregate to it 55 | Aggregate newAggregate = ContextMappingDSLFactory.eINSTANCE.createAggregate(); 56 | newAggregate.setName("A_Super_New_Aggregate"); 57 | customerManagementBC.getAggregates().add(newAggregate); 58 | 59 | // unparse model: (running this program changes the Insurance-Example-Model.cml file correspondingly!) 60 | resource.save(SaveOptions.defaultOptions().toOptionsMap()); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/org/contextmapper/standalone/example/ContextMapGeneratorExample.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Context Mapper Project Team 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.contextmapper.standalone.example; 17 | 18 | import org.contextmapper.dsl.cml.CMLResource; 19 | import org.contextmapper.dsl.generator.ContextMapGenerator; 20 | import org.contextmapper.dsl.standalone.ContextMapperStandaloneSetup; 21 | import org.contextmapper.dsl.standalone.StandaloneContextMapperAPI; 22 | 23 | import static org.contextmapper.standalone.example.ReadingModelExample.INSURANCE_EXAMPLE_URI; 24 | 25 | /** 26 | * This example shows how you can read your CML model and generate a graphical 27 | * Context Map from it. Note that for this example you need to have Graphviz 28 | * installed locally and your PATH environment variable must contain its bin 29 | * folder. 30 | *

31 | * This example produces the file 'Insurance-Example-Model_ContextMap.png' 32 | * within the 'src-gen' folder. 33 | * 34 | * @author Stefan Kapferer 35 | */ 36 | public class ContextMapGeneratorExample { 37 | 38 | public static void main(String[] args) { 39 | // Setup and loading CML file: 40 | StandaloneContextMapperAPI contextMapper = ContextMapperStandaloneSetup.getStandaloneAPI(); 41 | CMLResource resource = contextMapper.loadCML(INSURANCE_EXAMPLE_URI); 42 | 43 | // Create the PlantUML generator 44 | ContextMapGenerator generator = new ContextMapGenerator(); 45 | 46 | // Generate the diagrams into 'src-gen' 47 | contextMapper.callGenerator(resource, generator); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/org/contextmapper/standalone/example/GenericGeneratorExample.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Context Mapper Project Team 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.contextmapper.standalone.example; 17 | 18 | import org.contextmapper.dsl.cml.CMLResource; 19 | import org.contextmapper.dsl.generator.GenericContentGenerator; 20 | import org.contextmapper.dsl.standalone.ContextMapperStandaloneSetup; 21 | import org.contextmapper.dsl.standalone.StandaloneContextMapperAPI; 22 | 23 | import java.io.File; 24 | 25 | import static org.contextmapper.standalone.example.ReadingModelExample.INSURANCE_EXAMPLE_URI; 26 | 27 | /** 28 | * This example shows how you can read your CML model and generate arbitrary textual 29 | * files by using Freemarker templates. 30 | * 31 | * @author Stefan Kapferer 32 | */ 33 | public class GenericGeneratorExample { 34 | 35 | public final static String FREEMARKER_TEMPLATE = "./src/main/resources/freemarker-sample-template.ftl"; 36 | 37 | public static void main(String[] args) { 38 | // Setup and loading CML file: 39 | StandaloneContextMapperAPI contextMapper = ContextMapperStandaloneSetup.getStandaloneAPI(); 40 | CMLResource resource = contextMapper.loadCML(INSURANCE_EXAMPLE_URI); 41 | 42 | // Create the generic generator (using Freemarker template) 43 | GenericContentGenerator generator = new GenericContentGenerator(); 44 | generator.setFreemarkerTemplateFile(new File(FREEMARKER_TEMPLATE)); 45 | generator.setTargetFileName("sample-output.md"); 46 | 47 | // Use custom data if you want: 48 | generator.registerCustomModelProperty("customText", "hello freemarker world"); 49 | 50 | // Generate the diagrams into 'src-gen' 51 | contextMapper.callGenerator(resource, generator); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/contextmapper/standalone/example/MDSLGeneratorExample.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Context Mapper Project Team 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.contextmapper.standalone.example; 17 | 18 | import org.contextmapper.dsl.cml.CMLResource; 19 | import org.contextmapper.dsl.generator.MDSLContractsGenerator; 20 | import org.contextmapper.dsl.standalone.ContextMapperStandaloneSetup; 21 | import org.contextmapper.dsl.standalone.StandaloneContextMapperAPI; 22 | 23 | import static org.contextmapper.standalone.example.ReadingModelExample.INSURANCE_EXAMPLE_URI; 24 | 25 | /** 26 | * This example shows how you can read your CML model and generate the MDSL 27 | * contracts from it. 28 | * 29 | * @author Stefan Kapferer 30 | */ 31 | public class MDSLGeneratorExample { 32 | 33 | public static void main(String[] args) { 34 | // Setup and loading CML file: 35 | StandaloneContextMapperAPI contextMapper = ContextMapperStandaloneSetup.getStandaloneAPI(); 36 | CMLResource resource = contextMapper.loadCML(INSURANCE_EXAMPLE_URI); 37 | 38 | // Generate the contracts into 'src-gen' 39 | contextMapper.callGenerator(resource, new MDSLContractsGenerator()); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/contextmapper/standalone/example/PlantUMLGeneratorExample.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Context Mapper Project Team 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.contextmapper.standalone.example; 17 | 18 | import org.contextmapper.dsl.cml.CMLResource; 19 | import org.contextmapper.dsl.generator.PlantUMLGenerator; 20 | import org.contextmapper.dsl.standalone.ContextMapperStandaloneSetup; 21 | import org.contextmapper.dsl.standalone.StandaloneContextMapperAPI; 22 | 23 | import static org.contextmapper.standalone.example.ReadingModelExample.INSURANCE_EXAMPLE_URI; 24 | 25 | /** 26 | * This example shows how you can read your CML model and generate the PlantUML 27 | * component and class diagrams from it. 28 | * 29 | * @author Stefan Kapferer 30 | */ 31 | public class PlantUMLGeneratorExample { 32 | 33 | public static void main(String[] args) { 34 | // Setup and loading CML file: 35 | StandaloneContextMapperAPI contextMapper = ContextMapperStandaloneSetup.getStandaloneAPI(); 36 | CMLResource resource = contextMapper.loadCML(INSURANCE_EXAMPLE_URI); 37 | 38 | // Generate the diagrams into 'src-gen' 39 | contextMapper.callGenerator(resource, new PlantUMLGenerator()); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/contextmapper/standalone/example/ReadingModelExample.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Context Mapper Project Team 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.contextmapper.standalone.example; 17 | 18 | import org.contextmapper.dsl.cml.CMLResource; 19 | import org.contextmapper.dsl.contextMappingDSL.ContextMappingModel; 20 | import org.contextmapper.dsl.contextMappingDSL.Partnership; 21 | import org.contextmapper.dsl.contextMappingDSL.SharedKernel; 22 | import org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship; 23 | import org.contextmapper.dsl.standalone.ContextMapperStandaloneSetup; 24 | import org.contextmapper.dsl.standalone.StandaloneContextMapperAPI; 25 | 26 | /** 27 | * This example shows how you can read your CML model. We use the CML model 28 | * under src/main/cml/Insurance-Example-Model.cml and just printout some model 29 | * content... 30 | * 31 | * @author Stefan Kapferer 32 | */ 33 | public class ReadingModelExample { 34 | 35 | public final static String INSURANCE_EXAMPLE_URI = "./src/main/cml/Insurance-Example-Model.cml"; 36 | 37 | public static void main(String[] args) { 38 | // Setup and loading CML file: 39 | StandaloneContextMapperAPI contextMapper = ContextMapperStandaloneSetup.getStandaloneAPI(); 40 | CMLResource resource = contextMapper.loadCML(INSURANCE_EXAMPLE_URI); 41 | ContextMappingModel model = resource.getContextMappingModel(); 42 | 43 | // Reading from our CML model: 44 | System.out.println("The insurance example contains the following Bounded Contexts:"); 45 | model.getBoundedContexts().forEach(bc -> { 46 | System.out.println(bc.getName()); 47 | }); 48 | 49 | System.out.println("And relationships between these contexts exist:"); 50 | model.getMap().getRelationships().forEach(relationship -> { 51 | if (relationship instanceof UpstreamDownstreamRelationship) { 52 | UpstreamDownstreamRelationship upDownRel = (UpstreamDownstreamRelationship) relationship; 53 | System.out.println(upDownRel.getUpstream().getName() + " -> " + upDownRel.getDownstream().getName()); 54 | } else if (relationship instanceof Partnership) { 55 | Partnership partnership = (Partnership) relationship; 56 | System.out.println(partnership.getParticipant1().getName() + " [P]<->[P] " 57 | + partnership.getParticipant2().getName()); 58 | } else if (relationship instanceof SharedKernel) { 59 | SharedKernel sharedKernel = (SharedKernel) relationship; 60 | System.out.println(sharedKernel.getParticipant1().getName() + " [SK]<->[SK] " 61 | + sharedKernel.getParticipant2().getName()); 62 | } 63 | }); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/org/contextmapper/standalone/example/RefactoringExample.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 The Context Mapper Project Team 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.contextmapper.standalone.example; 17 | 18 | import org.contextmapper.dsl.cml.CMLResource; 19 | import org.contextmapper.dsl.refactoring.SplitBoundedContextByOwner; 20 | import org.contextmapper.dsl.standalone.ContextMapperStandaloneSetup; 21 | import org.contextmapper.dsl.standalone.StandaloneContextMapperAPI; 22 | 23 | /** 24 | * This example shows how you can read your CML model and apply a refactoring. 25 | * We use the CML model under src/main/cml/Insurance-Example-Model.cml and 26 | * apply 'Split Bounded Context by Owner' to the 'PolicyManagementContext'. 27 | * 28 | * @author Stefan Kapferer 29 | */ 30 | public class RefactoringExample { 31 | 32 | public final static String INSURANCE_EXAMPLE_URI = "./src/main/cml/Insurance-Example-Model.cml"; 33 | 34 | public static void main(String[] args) { 35 | // Setup and loading CML file: 36 | StandaloneContextMapperAPI contextMapper = ContextMapperStandaloneSetup.getStandaloneAPI(); 37 | CMLResource resource = contextMapper.loadCML(INSURANCE_EXAMPLE_URI); 38 | 39 | // apply refactoring 40 | contextMapper.applyRefactoring(resource, new SplitBoundedContextByOwner("PolicyManagementContext")); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/resources/freemarker-sample-template.ftl: -------------------------------------------------------------------------------- 1 | # Bounded Contexts in ${fileName} 2 | 3 | The model contains the following Bounded Contexts: 4 | <#list boundedContexts as bc> 5 | * ${bc.name} 6 | 7 | 8 | # Custom variables 9 | 10 | You can also use custom model objects and attributes for rendering. An example: 11 | ${customText} 12 | --------------------------------------------------------------------------------