001/*
002 * SPDX-FileCopyrightText: none
003 * SPDX-License-Identifier: CC0-1.0
004 */
005
006package gov.nist.secauto.metaschema.databind.model.annotations;
007
008import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
009import static java.lang.annotation.RetentionPolicy.RUNTIME;
010
011import java.lang.annotation.Documented;
012import java.lang.annotation.Retention;
013import java.lang.annotation.Target;
014import java.util.regex.Pattern;
015
016import edu.umd.cs.findbugs.annotations.NonNull;
017
018/**
019 * Identifies a Metapath expression referencing a value that is used in
020 * generating a key as part of a {@link IsUnique}, {@link Index}, or
021 * {@link IndexHasKey} constraint annotation.
022 */
023@Documented
024@Retention(RUNTIME)
025@Target(ANNOTATION_TYPE)
026public @interface KeyField {
027  /**
028   * An optional metapath that points to the target flag or field value that the
029   * key applies to. If omitted the target will be ".", which means the target is
030   * the value of the {@link BoundFlag}, {@link BoundField} or
031   * {@link BoundFieldValue} annotation the constraint appears on. In the prior
032   * case, this annotation may only appear on a {@link BoundField} if the field
033   * has no flags, which results in a {@link BoundField} annotation on a field
034   * instance with a scalar, data type value.
035   *
036   * @return the target metapath
037   */
038  @NonNull
039  String target() default ".";
040
041  /**
042   * Retrieve an optional pattern to use to retrieve the value. If
043   * non-{@code null}, the first capturing group is used to retrieve the value.
044   * This must be a pattern that can compile using
045   * {@link Pattern#compile(String)}.
046   *
047   * @return a pattern string or an empty string if no pattern is provided
048   */
049  @NonNull
050  String pattern() default "";
051
052  /**
053   * Any remarks about the key field, encoded as an escaped Markdown string.
054   *
055   * @return an encoded markdown string or an empty string if no remarks are
056   *         provided
057   */
058  @NonNull
059  String remarks() default "";
060}