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; 014 015import dev.metaschema.core.model.constraint.IConstraint; 016import dev.metaschema.core.model.constraint.IConstraint.Level; 017import edu.umd.cs.findbugs.annotations.NonNull; 018 019/** 020 * This annotation defines a rule that requires that the target contents of the 021 * assembly, represented by the containing {@link MetaschemaAssembly} 022 * annotation, reference items in a name index defined by the {@link Index} 023 * constraint. 024 */ 025 026@Documented 027@Retention(RUNTIME) 028@Target(ANNOTATION_TYPE) 029public @interface IndexHasKey { 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 * A reference to a named index. 086 * 087 * @return the index name 088 */ 089 @NonNull 090 String indexName(); 091 092 /** 093 * A list of one or more keys to use in looking up an entry in a given index. 094 * 095 * @return one or more keys 096 */ 097 @NonNull 098 KeyField[] keyFields(); 099 100 /** 101 * The message to emit when the constraint is violated. 102 * 103 * @return the message or an empty string otherwise 104 */ 105 @NonNull 106 String message() default ""; 107 108 /** 109 * Any remarks about the constraint, encoded as an escaped Markdown string. 110 * 111 * @return an encoded markdown string or an empty string if no remarks are 112 * provided 113 */ 114 @NonNull 115 String remarks() default ""; 116}