1   /*
2    * SPDX-FileCopyrightText: none
3    * SPDX-License-Identifier: CC0-1.0
4    */
5   
6   package gov.nist.secauto.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 gov.nist.secauto.metaschema.core.model.constraint.IConstraint;
12  import gov.nist.secauto.metaschema.core.model.constraint.IConstraint.Level;
13  
14  import java.lang.annotation.Documented;
15  import java.lang.annotation.Retention;
16  import java.lang.annotation.Target;
17  
18  import edu.umd.cs.findbugs.annotations.NonNull;
19  
20  /**
21   * This annotation defines a unqiue index over the contents of the assembly
22   * represented by the containing {@link MetaschemaAssembly} annotation.
23   */
24  @Documented
25  @Retention(RUNTIME)
26  @Target(ANNOTATION_TYPE)
27  public @interface Index {
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    @SuppressWarnings("PMD.ShortMethodName")
35    @NonNull
36    String id() default "";
37  
38    /**
39     * An optional formal name for the constraint.
40     *
41     * @return the formal name if provided or an empty string otherwise
42     */
43    @NonNull
44    String formalName() default "";
45  
46    /**
47     * An optional description of the constraint.
48     *
49     * @return the description if provided or an empty string otherwise
50     */
51    @NonNull
52    String description() default "";
53  
54    /**
55     * The significance of a violation of this constraint.
56     *
57     * @return the level
58     */
59    @NonNull
60    Level level() default IConstraint.Level.ERROR;
61  
62    /**
63     * An optional metapath that points to the target flag or field value that the
64     * constraint applies to. If omitted the target will be ".", which means the
65     * target is the value of the {@link BoundFlag}, {@link BoundField} or
66     * {@link BoundFieldValue} annotation the constraint appears on. In the prior
67     * case, this annotation may only appear on a {@link BoundField} if the field
68     * has no flags, which results in a {@link BoundField} annotation on a field
69     * instance with a scalar, data type value.
70     *
71     * @return the target metapath
72     */
73    @NonNull
74    String target() default ".";
75  
76    /**
77     * An optional set of properties associated with these allowed values.
78     *
79     * @return the properties or an empty array with no properties
80     */
81    Property[] properties() default {};
82  
83    /**
84     * The unique name of the index.
85     *
86     * @return the index name
87     */
88    @NonNull
89    String name();
90  
91    /**
92     * A list of one or more keys to use in looking up an entry in a given index.
93     *
94     * @return one or more keys
95     */
96    @NonNull
97    KeyField[] keyFields();
98  
99    /**
100    * The message to emit when the constraint is violated.
101    *
102    * @return the message or an empty string otherwise
103    */
104   @NonNull
105   String message() default "";
106 
107   /**
108    * Any remarks about the constraint, encoded as an escaped Markdown string.
109    *
110    * @return an encoded markdown string or an empty string if no remarks are
111    *         provided
112    */
113   @NonNull
114   String remarks() default "";
115 }