From 1cf966d7dccc8d1551885670c604c2c6eda94306 Mon Sep 17 00:00:00 2001 From: Oliver Drotbohm Date: Mon, 19 Oct 2020 20:10:31 +0200 Subject: [PATCH] GH-20 - Additional attributes for @BoundedContext and @Module. --- .../ddd/annotation/BoundedContext.java | 51 +++++++++++++++++-- .../org/jmolecules/ddd/annotation/Module.java | 51 +++++++++++++++++-- 2 files changed, 94 insertions(+), 8 deletions(-) diff --git a/jmolecules-ddd/src/main/java/org/jmolecules/ddd/annotation/BoundedContext.java b/jmolecules-ddd/src/main/java/org/jmolecules/ddd/annotation/BoundedContext.java index b268af9..9afde1e 100644 --- a/jmolecules-ddd/src/main/java/org/jmolecules/ddd/annotation/BoundedContext.java +++ b/jmolecules-ddd/src/main/java/org/jmolecules/ddd/annotation/BoundedContext.java @@ -13,9 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jddd.core.annotation; +package org.jmolecules.ddd.annotation; -import java.lang.annotation.*; +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; /** * Identifies a bounded context. A description of a boundary (typically a subsystem, or the work of a particular team) @@ -31,9 +35,48 @@ * Reference (Evans) - Bounded Contexts */ @Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.PACKAGE) -//TODO: with Java 9 or higher @Target(ElementType.MODULE) +@Target({ ElementType.PACKAGE, ElementType.ANNOTATION_TYPE }) @Documented public @interface BoundedContext { + /** + * A stable identifier for the bounded context. If not defined, an identifier will be derived from the annotated + * element, usually a package. That allows tooling to derive name and description by applying some kind of convention + * to the identifier. + *

+ * Assuming a package {@code com.acme.myapp} annotated with {@code BoundedContext}, tooling could use a resource + * bundle to lookup the keys {@code com.acme.myapp._name} and {@code com.acme.myapp._description} to resolve name and + * description respectively. + * + * @return + */ + String id() default ""; + + /** + * A human readable name for the bounded context. Might be overridden by an external resolution mechanism via + * {@link #id()}. Tooling should prevent both {@link #value()} and {@link #name()} from being configured at the same + * time. If in doubt, the value defined in {@link #name()} will be preferred. + * + * @return + * @see #id() + */ + String name() default ""; + + /** + * An alias for {@link #name()}. Tooling should prevent both {@link #value()} and {@link #name()} from being + * configured at the same time. If in doubt, the value defined in {@link #name()} will be preferred. + * + * @return + * @see #name() + */ + String value() default ""; + + /** + * A human readable description for the bounded context. Might be overridden by an external resolution mechanism via + * {@link #id()}. + * + * @return + * @see #id() + */ + String description() default ""; } diff --git a/jmolecules-ddd/src/main/java/org/jmolecules/ddd/annotation/Module.java b/jmolecules-ddd/src/main/java/org/jmolecules/ddd/annotation/Module.java index 30c488c..e1a1257 100644 --- a/jmolecules-ddd/src/main/java/org/jmolecules/ddd/annotation/Module.java +++ b/jmolecules-ddd/src/main/java/org/jmolecules/ddd/annotation/Module.java @@ -13,9 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jddd.core.annotation; +package org.jmolecules.ddd.annotation; -import java.lang.annotation.*; +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; /** * Identifies a DDD module. @@ -29,9 +33,48 @@ * Reference (Evans) - Bounded Contexts */ @Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.PACKAGE) -//TODO: with Java 9 or higher @Target(ElementType.MODULE) +@Target({ ElementType.PACKAGE, ElementType.ANNOTATION_TYPE }) @Documented public @interface Module { + /** + * A stable identifier for the module. If not defined, an identifier will be derived from the annotated element, + * usually a package. That allows tooling to derive name and description by applying some kind of convention to the + * identifier. + *

+ * Assuming a package {@code com.acme.myapp.module} annotated with {@code Module}, tooling could use a resource bundle + * to lookup the keys {@code com.acme.myapp.module._name} and {@code com.acme.myapp.module_description} to resolve + * name and description respectively. + * + * @return + */ + String id() default ""; + + /** + * A human readable name for the module. Might be overridden by an external resolution mechanism via {@link #id()}. + * Tooling should prevent both {@link #value()} and {@link #name()} from being configured at the same time. If in + * doubt, the value defined in {@link #name()} will be preferred. + * + * @return + * @see #id() + */ + String name() default ""; + + /** + * An alias for {@link #name()}. Tooling should prevent both {@link #value()} and {@link #name()} from being + * configured at the same time. If in doubt, the value defined in {@link #name()} will be preferred. + * + * @return + * @see #name() + */ + String value() default ""; + + /** + * A human readable description for the module. Might be overridden by an external resolution mechanism via + * {@link #id()}. + * + * @return + * @see #id() + */ + String description() default ""; }