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.IAllowedValuesConstraint;
16 import dev.metaschema.core.model.constraint.IConstraint;
17 import dev.metaschema.core.model.constraint.IConstraint.Level;
18 import edu.umd.cs.findbugs.annotations.NonNull;
19
20 /**
21 * This annotation defines a set of values permitted to be used in the context
22 * of the containing annotation.
23 */
24 @Documented
25 @Retention(RUNTIME)
26 @Target(ANNOTATION_TYPE)
27 public @interface AllowedValues {
28 /**
29 * An optional identifier for the constraint, which must be unique to only this
30 * constraint.
31 *
32 * @return the identifier if provided or an empty string otherwise
33 */
34 @NonNull
35 String id() default "";
36
37 /**
38 * An optional formal name for the constraint.
39 *
40 * @return the formal name if provided or an empty string otherwise
41 */
42 @NonNull
43 String formalName() default "";
44
45 /**
46 * An optional description of the constraint.
47 *
48 * @return the description if provided or an empty string otherwise
49 */
50 @NonNull
51 String description() default "";
52
53 /**
54 * The significance of a violation of this constraint.
55 *
56 * @return the level
57 */
58 @NonNull
59 Level level() default IConstraint.Level.ERROR;
60
61 /**
62 * An optional metapath that points to the target flag or field value that the
63 * constraint applies to. If omitted the target will be ".", which means the
64 * target is the value of the {@link BoundFlag}, {@link BoundField} or
65 * {@link BoundFieldValue} annotation the constraint appears on. In the prior
66 * case, this annotation may only appear on a {@link BoundField} if the field
67 * has no flags, which results in a {@link BoundField} annotation on a field
68 * instance with a scalar, data type value.
69 *
70 * @return the target metapath
71 */
72 @NonNull
73 String target() default ".";
74
75 /**
76 * An optional set of properties associated with these allowed values.
77 *
78 * @return the properties or an empty array with no properties
79 */
80 Property[] properties() default {};
81
82 /**
83 * Get any allowed values for this constraint.
84 *
85 * @return an array of allowed value enumerations
86 */
87 @NonNull
88 AllowedValue[] values();
89
90 /**
91 * Indicates if the constraint allows other values not included in the
92 * enumerated list.
93 *
94 * @return {@code true} if other values are allowed or {@code false} otherwise
95 */
96 boolean allowOthers() default IAllowedValuesConstraint.ALLOW_OTHER_DEFAULT;
97
98 /**
99 * Indicates if the constraint can be extended by other constraints.
100 *
101 * @return the extension mode
102 */
103 @NonNull
104 IAllowedValuesConstraint.Extensible extensible() default IAllowedValuesConstraint.Extensible.EXTERNAL;
105
106 /**
107 * Any remarks about the constraint, encoded as an escaped Markdown string.
108 *
109 * @return an encoded markdown string or an empty string if no remarks are
110 * provided
111 */
112 @NonNull
113 String remarks() default "";
114 }