001/*
002 * SPDX-FileCopyrightText: none
003 * SPDX-License-Identifier: CC0-1.0
004 */
005
006package dev.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 dev.metaschema.core.datatype.IDataTypeAdapter;
017import dev.metaschema.core.model.constraint.IConstraint;
018import dev.metaschema.core.model.constraint.IConstraint.Level;
019import edu.umd.cs.findbugs.annotations.NonNull;
020
021/**
022 * This annotation defines a rule that requires matching patterns and/or data
023 * types among the target contents of the assembly represented by the containing
024 * {@link MetaschemaAssembly} annotation.
025 */
026@Documented
027@Retention(RUNTIME)
028@Target(ANNOTATION_TYPE)
029public @interface Matches {
030  /**
031   * An optional identifier for the constraint, which must be unique to only this
032   * constraint.
033   *
034   * @return the identifier if provided or an empty string otherwise
035   */
036  @NonNull
037  String id() default "";
038
039  /**
040   * An optional formal name for the constraint.
041   *
042   * @return the formal name if provided or an empty string otherwise
043   */
044  @NonNull
045  String formalName() default "";
046
047  /**
048   * An optional description of the constraint.
049   *
050   * @return the description if provided or an empty string otherwise
051   */
052  @NonNull
053  String description() default "";
054
055  /**
056   * The significance of a violation of this constraint.
057   *
058   * @return the level
059   */
060  @NonNull
061  Level level() default IConstraint.Level.ERROR;
062
063  /**
064   * An optional Metapath that points to the target flag or field value that the
065   * constraint applies to. If omitted the target will be ".", which means the
066   * target is the value of the {@link BoundFlag}, {@link BoundField} or
067   * {@link BoundFieldValue} annotation the constraint appears on. In the prior
068   * case, this annotation may only appear on a {@link BoundField} if the field
069   * has no flags, which results in a {@link BoundField} annotation on a field
070   * instance with a scalar, data type value.
071   *
072   * @return the target metapath
073   */
074  @NonNull
075  String target() default ".";
076
077  /**
078   * An optional set of properties associated with these allowed values.
079   *
080   * @return the properties or an empty array with no properties
081   */
082  Property[] properties() default {};
083
084  /**
085   * Retrieve an optional pattern that the associated value must match. This must
086   * be a pattern that can compile using {@link Pattern#compile(String)}.
087   *
088   * @return a pattern string or an empty string if no pattern is provided
089   */
090  @NonNull
091  String pattern() default "";
092
093  /**
094   * The Module data type adapter for the data type that the associated value must
095   * conform to.
096   *
097   * @return the data type adapter or a {@link NullJavaTypeAdapter} if none is
098   *         provided
099   */
100  @NonNull
101  Class<? extends IDataTypeAdapter<?>> typeAdapter() default NullJavaTypeAdapter.class;
102
103  /**
104   * The message to emit when the constraint is violated.
105   *
106   * @return the message or an empty string otherwise
107   */
108  @NonNull
109  String message() default "";
110
111  /**
112   * Any remarks about the constraint, encoded as an escaped Markdown string.
113   *
114   * @return an encoded markdown string or an empty string if no remarks are
115   *         provided
116   */
117  @NonNull
118  String remarks() default "";
119}