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.datatype.IDataTypeAdapter;
12  import gov.nist.secauto.metaschema.core.model.constraint.IConstraint;
13  import gov.nist.secauto.metaschema.core.model.constraint.IConstraint.Level;
14  
15  import java.lang.annotation.Documented;
16  import java.lang.annotation.Retention;
17  import java.lang.annotation.Target;
18  import java.util.regex.Pattern;
19  
20  import edu.umd.cs.findbugs.annotations.NonNull;
21  
22  /**
23   * This annotation defines a rule that requires matching patterns and/or data
24   * types among the target contents of the assembly represented by the containing
25   * {@link MetaschemaAssembly} annotation.
26   */
27  @Documented
28  @Retention(RUNTIME)
29  @Target(ANNOTATION_TYPE)
30  public @interface Matches {
31    /**
32     * An optional identifier for the constraint, which must be unique to only this
33     * constraint.
34     *
35     * @return the identifier if provided or an empty string otherwise
36     */
37    @SuppressWarnings("PMD.ShortMethodName")
38    @NonNull
39    String id() default "";
40  
41    /**
42     * An optional formal name for the constraint.
43     *
44     * @return the formal name if provided or an empty string otherwise
45     */
46    @NonNull
47    String formalName() default "";
48  
49    /**
50     * An optional description of the constraint.
51     *
52     * @return the description if provided or an empty string otherwise
53     */
54    @NonNull
55    String description() default "";
56  
57    /**
58     * The significance of a violation of this constraint.
59     *
60     * @return the level
61     */
62    @NonNull
63    Level level() default IConstraint.Level.ERROR;
64  
65    /**
66     * An optional Metapath that points to the target flag or field value that the
67     * constraint applies to. If omitted the target will be ".", which means the
68     * target is the value of the {@link BoundFlag}, {@link BoundField} or
69     * {@link BoundFieldValue} annotation the constraint appears on. In the prior
70     * case, this annotation may only appear on a {@link BoundField} if the field
71     * has no flags, which results in a {@link BoundField} annotation on a field
72     * instance with a scalar, data type value.
73     *
74     * @return the target metapath
75     */
76    @NonNull
77    String target() default ".";
78  
79    /**
80     * An optional set of properties associated with these allowed values.
81     *
82     * @return the properties or an empty array with no properties
83     */
84    Property[] properties() default {};
85  
86    /**
87     * Retrieve an optional pattern that the associated value must match. This must
88     * be a pattern that can compile using {@link Pattern#compile(String)}.
89     *
90     * @return a pattern string or an empty string if no pattern is provided
91     */
92    @NonNull
93    String pattern() default "";
94  
95    /**
96     * The Module data type adapter for the data type that the associated value must
97     * conform to.
98     *
99     * @return the data type adapter or a {@link NullJavaTypeAdapter} if none is
100    *         provided
101    */
102   @NonNull
103   Class<? extends IDataTypeAdapter<?>> typeAdapter() default NullJavaTypeAdapter.class;
104 
105   /**
106    * The message to emit when the constraint is violated.
107    *
108    * @return the message or an empty string otherwise
109    */
110   @NonNull
111   String message() default "";
112 
113   /**
114    * Any remarks about the constraint, encoded as an escaped Markdown string.
115    *
116    * @return an encoded markdown string or an empty string if no remarks are
117    *         provided
118    */
119   @NonNull
120   String remarks() default "";
121 }