From 8163af31d3aa4bdc19c0461ec66802f1f1f91c6b Mon Sep 17 00:00:00 2001 From: Stefan Kapferer Date: Mon, 19 Oct 2026 23:05:47 +0200 Subject: [PATCH 1/2] Document reading CML models from code and tests Documentation for ContextMapper/context-mapper-dsl#381 (part 1). --- _docs/standalone-usage.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/_docs/standalone-usage.md b/_docs/standalone-usage.md index d3c048f..02cd714 100644 --- a/_docs/standalone-usage.md +++ b/_docs/standalone-usage.md @@ -25,6 +25,27 @@ implementation 'org.contextmapper:context-mapper-dsl:{our-latest-version}' The latest release can be found here: [org.contextmapper:context-mapper-dsl on Maven Central](https://central.sonatype.com/artifact/org.contextmapper/context-mapper-dsl) +The library runs on Java 11 or newer (tested with Java 11, 17 and 21). + +## Reading a CML Model in Your Code or Tests +A common use case is to read your CML model in your own build or tests, for example to derive architecture tests or other checks from the context map. The following snippet loads a CML file and iterates over the relationships of its context map: + +```java +StandaloneContextMapperAPI contextMapper = ContextMapperStandaloneSetup.getStandaloneAPI(); +CMLResource cml = contextMapper.loadCML("./src/main/cml/transit.cml"); + +for (Relationship relationship : cml.getContextMappingModel().getMap().getRelationships()) { + if (relationship instanceof UpstreamDownstreamRelationship) { + UpstreamDownstreamRelationship upDown = (UpstreamDownstreamRelationship) relationship; + System.out.println(upDown.getUpstream().getName() + " " + upDown.getUpstreamRoles() + " -> " + + upDown.getDownstream().getName() + " " + upDown.getDownstreamRoles()); + } +} +// prints for example: PaymentProvider [OHS] -> TicketSales [ACL] +``` + +The model classes (`BoundedContext`, `Aggregate`, `UpstreamDownstreamRelationship`, etc.) are located in the package `org.contextmapper.dsl.contextMappingDSL`; the API in `org.contextmapper.dsl.standalone`. If you want to check tactic DDD elements (Aggregates, Entities, etc.) against your Java code, have a look at our [ArchUnit extension](https://github.com/ContextMapper/context-mapper-archunit-extension). + ## Example Project If you want to use Context Mapper as library within your application, have a look at our standalone example project: [https://github.com/ContextMapper/context-mapper-standalone-example](https://github.com/ContextMapper/context-mapper-standalone-example) From 1c51608da448df4e56c5c91f4ae9e5cfe0bbd3be Mon Sep 17 00:00:00 2001 From: Stefan Kapferer Date: Tue, 20 Oct 2026 23:55:30 +0200 Subject: [PATCH 2/2] Update Java version in standalone usage docs to 17 --- _docs/standalone-usage.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_docs/standalone-usage.md b/_docs/standalone-usage.md index 02cd714..300f558 100644 --- a/_docs/standalone-usage.md +++ b/_docs/standalone-usage.md @@ -25,7 +25,7 @@ implementation 'org.contextmapper:context-mapper-dsl:{our-latest-version}' The latest release can be found here: [org.contextmapper:context-mapper-dsl on Maven Central](https://central.sonatype.com/artifact/org.contextmapper/context-mapper-dsl) -The library runs on Java 11 or newer (tested with Java 11, 17 and 21). +The library runs on Java 17 or newer (tested with Java 17 and 21). ## Reading a CML Model in Your Code or Tests A common use case is to read your CML model in your own build or tests, for example to derive architecture tests or other checks from the context map. The following snippet loads a CML file and iterates over the relationships of its context map: