1   /*
2    * SPDX-FileCopyrightText: none
3    * SPDX-License-Identifier: CC0-1.0
4    */
5   
6   package dev.metaschema.core.model.constraint;
7   
8   import java.util.Collection;
9   
10  import dev.metaschema.core.metapath.item.node.IModuleNodeItem;
11  import dev.metaschema.core.model.IModelElementVisitor;
12  import dev.metaschema.core.model.ISource;
13  import edu.umd.cs.findbugs.annotations.NonNull;
14  
15  /**
16   * A set of constraints targeted at the contents of a Metaschema module.
17   */
18  public interface IConstraintSet {
19    /**
20     * Get information about where the constraint set was sourced from.
21     *
22     * @return the source information
23     */
24    @NonNull
25    ISource getSource();
26  
27    /**
28     * Get constraint sets imported by this constraint set.
29     *
30     * @return the imported constraint sets
31     */
32    @NonNull
33    Collection<? extends IConstraintSet> getImportedConstraintSets();
34  
35    /**
36     * Apply the constraints associated with this constraint set to the provided
37     * module, if applicable.
38     * <p>
39     * Callers of this method are required to track which definitions have been
40     * previously targeted based on the result of this method and to provide these
41     * to subsequent calls of this method targeting different modules. This approach
42     * ensures that a given constraint is not applied more than once.
43     *
44     * @param moduleItem
45     *          the module node item to apply applicable constraints to
46     * @param visitor
47     *          the visitor used to apply constraints to target definitions
48     */
49    void applyConstraintsForModule(
50        @NonNull IModuleNodeItem moduleItem,
51        @NonNull IModelElementVisitor<ITargetedConstraints, Void> visitor);
52  }