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 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 edu.umd.cs.findbugs.annotations.NonNull;
17  
18  /**
19   * Identifies a Metapath expression referencing a value that is used in
20   * generating a key as part of a {@link IsUnique}, {@link Index}, or
21   * {@link IndexHasKey} constraint annotation.
22   */
23  @Documented
24  @Retention(RUNTIME)
25  @Target(ANNOTATION_TYPE)
26  public @interface KeyField {
27    /**
28     * An optional metapath that points to the target flag or field value that the
29     * key applies to. If omitted the target will be ".", which means the target is
30     * the value of the {@link BoundFlag}, {@link BoundField} or
31     * {@link BoundFieldValue} annotation the constraint appears on. In the prior
32     * case, this annotation may only appear on a {@link BoundField} if the field
33     * has no flags, which results in a {@link BoundField} annotation on a field
34     * instance with a scalar, data type value.
35     *
36     * @return the target metapath
37     */
38    @NonNull
39    String target() default ".";
40  
41    /**
42     * Retrieve an optional pattern to use to retrieve the value. If
43     * non-{@code null}, the first capturing group is used to retrieve the value.
44     * This must be a pattern that can compile using
45     * {@link Pattern#compile(String)}.
46     *
47     * @return a pattern string or an empty string if no pattern is provided
48     */
49    @NonNull
50    String pattern() default "";
51  
52    /**
53     * Any remarks about the key field, encoded as an escaped Markdown string.
54     *
55     * @return an encoded markdown string or an empty string if no remarks are
56     *         provided
57     */
58    @NonNull
59    String remarks() default "";
60  }