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.StaticContext;
9   import gov.nist.secauto.metaschema.core.model.IModule;
10  import gov.nist.secauto.metaschema.core.model.constraint.impl.ExternalSource;
11  import gov.nist.secauto.metaschema.core.model.constraint.impl.InternalModelSource;
12  
13  import java.net.URI;
14  
15  import edu.umd.cs.findbugs.annotations.NonNull;
16  import edu.umd.cs.findbugs.annotations.Nullable;
17  
18  /**
19   * A descriptor that identifies where a given constraint was defined.
20   */
21  public interface ISource {
22    enum SourceType {
23      /**
24       * A constraint embedded in a model.
25       */
26      MODEL,
27      /**
28       * A constraint defined externally from a model.
29       */
30      EXTERNAL;
31    }
32  
33    /**
34     * Get the descriptor for a
35     * {@link gov.nist.secauto.metaschema.core.model.constraint.ISource.SourceType#MODEL}
36     * source with as associated resource.
37     *
38     * @param module
39     *          the Metaschema module the constraint was defined in
40     * @return the source descriptor
41     */
42    @NonNull
43    static ISource modelSource(@NonNull IModule module) {
44      return InternalModelSource.instance(module);
45    }
46  
47    /**
48     * Get the descriptor for a
49     * {@link gov.nist.secauto.metaschema.core.model.constraint.ISource.SourceType#EXTERNAL}
50     * source with as associated resource.
51     *
52     * @param staticContext
53     *          the static Metapath context to use for compiling Metapath
54     *          expressions in this source
55     *
56     * @return the source descriptor
57     */
58    @NonNull
59    static ISource externalSource(@NonNull StaticContext staticContext) {
60      return ExternalSource.instance(staticContext);
61    }
62  
63    /**
64     * Get the type of source.
65     *
66     * @return the type
67     */
68    @NonNull
69    ISource.SourceType getSourceType();
70  
71    /**
72     * Get the resource where the constraint was defined, if known.
73     *
74     * @return the resource or {@code null} if the resource is not known
75     */
76    @Nullable
77    URI getSource();
78  
79    /**
80     * Get the static Metapath context to use when compiling Metapath expressions.
81     *
82     * @return the static Metapath context
83     */
84    @NonNull
85    StaticContext getStaticContext();
86  }