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
15 import dev.metaschema.core.model.constraint.IConstraint;
16 import dev.metaschema.core.model.constraint.IConstraint.Level;
17 import edu.umd.cs.findbugs.annotations.NonNull;
18
19 /**
20 * This annotation defines a rule that requires that the target contents of the
21 * assembly, represented by the containing {@link MetaschemaAssembly}
22 * annotation, reference items in a name index defined by the {@link Index}
23 * constraint.
24 */
25
26 @Documented
27 @Retention(RUNTIME)
28 @Target(ANNOTATION_TYPE)
29 public @interface IndexHasKey {
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 * A reference to a named index.
86 *
87 * @return the index name
88 */
89 @NonNull
90 String indexName();
91
92 /**
93 * A list of one or more keys to use in looking up an entry in a given index.
94 *
95 * @return one or more keys
96 */
97 @NonNull
98 KeyField[] keyFields();
99
100 /**
101 * The message to emit when the constraint is violated.
102 *
103 * @return the message or an empty string otherwise
104 */
105 @NonNull
106 String message() default "";
107
108 /**
109 * Any remarks about the constraint, encoded as an escaped Markdown string.
110 *
111 * @return an encoded markdown string or an empty string if no remarks are
112 * provided
113 */
114 @NonNull
115 String remarks() default "";
116 }