1 /*
2 * SPDX-FileCopyrightText: none
3 * SPDX-License-Identifier: CC0-1.0
4 */
5
6 package dev.metaschema.databind.model.annotations;
7
8 import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
9 import static java.lang.annotation.RetentionPolicy.RUNTIME;
10
11 import java.lang.annotation.Documented;
12 import java.lang.annotation.Retention;
13 import java.lang.annotation.Target;
14 import java.util.regex.Pattern;
15
16 import dev.metaschema.core.datatype.IDataTypeAdapter;
17 import dev.metaschema.core.model.constraint.IConstraint;
18 import dev.metaschema.core.model.constraint.IConstraint.Level;
19 import edu.umd.cs.findbugs.annotations.NonNull;
20
21 /**
22 * This annotation defines a rule that requires matching patterns and/or data
23 * types among the target contents of the assembly represented by the containing
24 * {@link MetaschemaAssembly} annotation.
25 */
26 @Documented
27 @Retention(RUNTIME)
28 @Target(ANNOTATION_TYPE)
29 public @interface Matches {
30 /**
31 * An optional identifier for the constraint, which must be unique to only this
32 * constraint.
33 *
34 * @return the identifier if provided or an empty string otherwise
35 */
36 @NonNull
37 String id() default "";
38
39 /**
40 * An optional formal name for the constraint.
41 *
42 * @return the formal name if provided or an empty string otherwise
43 */
44 @NonNull
45 String formalName() default "";
46
47 /**
48 * An optional description of the constraint.
49 *
50 * @return the description if provided or an empty string otherwise
51 */
52 @NonNull
53 String description() default "";
54
55 /**
56 * The significance of a violation of this constraint.
57 *
58 * @return the level
59 */
60 @NonNull
61 Level level() default IConstraint.Level.ERROR;
62
63 /**
64 * An optional Metapath that points to the target flag or field value that the
65 * constraint applies to. If omitted the target will be ".", which means the
66 * target is the value of the {@link BoundFlag}, {@link BoundField} or
67 * {@link BoundFieldValue} annotation the constraint appears on. In the prior
68 * case, this annotation may only appear on a {@link BoundField} if the field
69 * has no flags, which results in a {@link BoundField} annotation on a field
70 * instance with a scalar, data type value.
71 *
72 * @return the target metapath
73 */
74 @NonNull
75 String target() default ".";
76
77 /**
78 * An optional set of properties associated with these allowed values.
79 *
80 * @return the properties or an empty array with no properties
81 */
82 Property[] properties() default {};
83
84 /**
85 * Retrieve an optional pattern that the associated value must match. This must
86 * be a pattern that can compile using {@link Pattern#compile(String)}.
87 *
88 * @return a pattern string or an empty string if no pattern is provided
89 */
90 @NonNull
91 String pattern() default "";
92
93 /**
94 * The Module data type adapter for the data type that the associated value must
95 * conform to.
96 *
97 * @return the data type adapter or a {@link NullJavaTypeAdapter} if none is
98 * provided
99 */
100 @NonNull
101 Class<? extends IDataTypeAdapter<?>> typeAdapter() default NullJavaTypeAdapter.class;
102
103 /**
104 * The message to emit when the constraint is violated.
105 *
106 * @return the message or an empty string otherwise
107 */
108 @NonNull
109 String message() default "";
110
111 /**
112 * Any remarks about the constraint, encoded as an escaped Markdown string.
113 *
114 * @return an encoded markdown string or an empty string if no remarks are
115 * provided
116 */
117 @NonNull
118 String remarks() default "";
119 }