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 gov.nist.secauto.metaschema.core.model.constraint.IConstraint;
012import gov.nist.secauto.metaschema.core.model.constraint.IConstraint.Level;
013
014import java.lang.annotation.Documented;
015import java.lang.annotation.Retention;
016import java.lang.annotation.Target;
017
018import edu.umd.cs.findbugs.annotations.NonNull;
019
020/**
021 * This annotation defines a unqiue index over the contents of the assembly
022 * represented by the containing {@link MetaschemaAssembly} annotation.
023 */
024@Documented
025@Retention(RUNTIME)
026@Target(ANNOTATION_TYPE)
027public @interface Index {
028  /**
029   * An optional identifier for the constraint, which must be unique to only this
030   * constraint.
031   *
032   * @return the identifier if provided or an empty string otherwise
033   */
034  @SuppressWarnings("PMD.ShortMethodName")
035  @NonNull
036  String id() default "";
037
038  /**
039   * An optional formal name for the constraint.
040   *
041   * @return the formal name if provided or an empty string otherwise
042   */
043  @NonNull
044  String formalName() default "";
045
046  /**
047   * An optional description of the constraint.
048   *
049   * @return the description if provided or an empty string otherwise
050   */
051  @NonNull
052  String description() default "";
053
054  /**
055   * The significance of a violation of this constraint.
056   *
057   * @return the level
058   */
059  @NonNull
060  Level level() default IConstraint.Level.ERROR;
061
062  /**
063   * An optional metapath that points to the target flag or field value that the
064   * constraint applies to. If omitted the target will be ".", which means the
065   * target is the value of the {@link BoundFlag}, {@link BoundField} or
066   * {@link BoundFieldValue} annotation the constraint appears on. In the prior
067   * case, this annotation may only appear on a {@link BoundField} if the field
068   * has no flags, which results in a {@link BoundField} annotation on a field
069   * instance with a scalar, data type value.
070   *
071   * @return the target metapath
072   */
073  @NonNull
074  String target() default ".";
075
076  /**
077   * An optional set of properties associated with these allowed values.
078   *
079   * @return the properties or an empty array with no properties
080   */
081  Property[] properties() default {};
082
083  /**
084   * The unique name of the index.
085   *
086   * @return the index name
087   */
088  @NonNull
089  String name();
090
091  /**
092   * A list of one or more keys to use in looking up an entry in a given index.
093   *
094   * @return one or more keys
095   */
096  @NonNull
097  KeyField[] keyFields();
098
099  /**
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}