1   /*
2    * SPDX-FileCopyrightText: none
3    * SPDX-License-Identifier: CC0-1.0
4    */
5   
6   package dev.metaschema.core.model.constraint;
7   
8   import dev.metaschema.core.metapath.DynamicContext;
9   import dev.metaschema.core.metapath.item.node.INodeItem;
10  import edu.umd.cs.findbugs.annotations.NonNull;
11  import edu.umd.cs.findbugs.annotations.Nullable;
12  
13  /**
14   * Represents a constraint that allows a configurable message.
15   *
16   * @since 2.0.0
17   */
18  public interface IConfigurableMessageConstraint extends IConstraint {
19  
20    /**
21     * A message to emit when the constraint is violated. Allows embedded Metapath
22     * expressions using the syntax {@code \{ metapath \}}.
23     *
24     * @return the message if defined or {@code null} otherwise
25     */
26    @Nullable
27    String getMessage();
28  
29    /**
30     * Generate a violation message using the provided item and dynamic context for
31     * inline Metapath value insertion.
32     *
33     * @param item
34     *          the target Metapath item to use as the focus for Metapath evaluation
35     * @param context
36     *          the dynamic context for Metapath evaluation
37     * @return the message
38     * @throws ConstraintInitializationException
39     *           if a custom message is not defined, which will occur if this method
40     *           is called while {@link #getMessage()} returns {@code null}
41     * @throws ConstraintValidationException
42     *           if the custom message contains a Metapath expression that is
43     *           invalid or if the expression failed to evaluate
44     */
45    @NonNull
46    String generateMessage(@NonNull INodeItem item, @NonNull DynamicContext context) throws ConstraintValidationException;
47  }