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