001/*
002 * SPDX-FileCopyrightText: none
003 * SPDX-License-Identifier: CC0-1.0
004 */
005
006package dev.metaschema.core.model;
007
008import java.net.URI;
009import java.util.Collection;
010import java.util.List;
011import java.util.Map;
012
013import dev.metaschema.core.datatype.markup.MarkupLine;
014import dev.metaschema.core.datatype.markup.MarkupMultiline;
015import dev.metaschema.core.metapath.StaticContext;
016import dev.metaschema.core.qname.IEnhancedQName;
017import edu.umd.cs.findbugs.annotations.NonNull;
018import edu.umd.cs.findbugs.annotations.Nullable;
019
020/**
021 * Represents a Metaschema module.
022 */
023public interface IModule {
024  /**
025   * Retrieves the location where the Metaschema module was loaded from.
026   *
027   * @return the location, or {@code null} if this information is not available
028   */
029  URI getLocation();
030
031  /**
032   * Get a hint about where the source is location.
033   * <p>
034   * This value will typically be a URI or class name.
035   *
036   * @return the hint
037   */
038  @NonNull
039  String getLocationHint();
040
041  /**
042   * Get the source information for the module.
043   *
044   * @return the source information
045   */
046  @NonNull
047  ISource getSource();
048
049  /**
050   * Get the long name for the Metaschema module.
051   *
052   * @return the name
053   */
054  @NonNull
055  MarkupLine getName();
056
057  /**
058   * Get the revision of the Metaschema module.
059   *
060   * @return the revision
061   */
062  @NonNull
063  String getVersion();
064
065  /**
066   * Retrieve the remarks associated with this Metaschema module, if any.
067   *
068   * @return the remarks or {@code null} if no remarks are defined
069   */
070  @Nullable
071  MarkupMultiline getRemarks();
072
073  /**
074   * Retrieves the unique short name for the Metaschema module, which provides a
075   * textual identifier for the Metaschema module.
076   *
077   * @return the short name
078   */
079  @NonNull
080  String getShortName();
081
082  /**
083   * Retrieves the XML namespace associated with the Metaschema module.
084   *
085   * @return a namespace
086   */
087  @NonNull
088  URI getXmlNamespace();
089
090  /**
091   * Retrieve the JSON schema base URI associated with the Metaschema module.
092   *
093   * @return the base URI
094   */
095  @NonNull
096  URI getJsonBaseUri();
097
098  /**
099   * Get the qualified name associated with the Metaschema module.
100   *
101   * @return the qualified name
102   */
103  @NonNull
104  IEnhancedQName getQName();
105
106  /**
107   * Retrieves all Metaschema modules imported by this Metaschema module.
108   *
109   * @return a list of imported Metaschema modules
110   */
111  @NonNull
112  List<? extends IModule> getImportedModules();
113
114  /**
115   * Retrieve the imported Metaschema module with the specified name, if it
116   * exists.
117   *
118   * @param name
119   *          the short name of the Metschema module to retrieve
120   * @return the imported Metaschema module or {@code null} if it doesn't exist
121   */
122  @Nullable
123  IModule getImportedModuleByShortName(String name);
124
125  /**
126   * Retrieves the top-level assembly definitions in this Metaschema module.
127   *
128   * @return the collection of assembly definitions
129   */
130  @NonNull
131  Collection<? extends IAssemblyDefinition> getAssemblyDefinitions();
132
133  /**
134   * Retrieves the top-level assembly definition in this Metaschema module with
135   * the matching name, if it exists.
136   *
137   * @param name
138   *          the definition name
139   *
140   * @return the matching assembly definition, or {@code null} if none match
141   */
142  @Nullable
143  IAssemblyDefinition getAssemblyDefinitionByName(@NonNull Integer name);
144
145  /**
146   * Retrieves the top-level field definitions in this Metaschema module.
147   *
148   * @return the collection of field definitions
149   */
150  @NonNull
151  Collection<? extends IFieldDefinition> getFieldDefinitions();
152
153  /**
154   * Retrieves the top-level field definition in this Metaschema module with the
155   * matching name, if it exists.
156   *
157   * @param name
158   *          the definition name
159   *
160   * @return the matching field definition, or {@code null} if none match
161   */
162  @Nullable
163  IFieldDefinition getFieldDefinitionByName(@NonNull Integer name);
164
165  /**
166   * Retrieves the top-level assembly and field definitions in this Metaschema
167   * module.
168   *
169   * @return a listing of assembly and field definitions
170   */
171  @NonNull
172  List<? extends IModelDefinition> getAssemblyAndFieldDefinitions();
173
174  /**
175   * Retrieves the top-level flag definitions in this Metaschema module.
176   *
177   * @return the collection of flag definitions
178   */
179  @NonNull
180  Collection<? extends IFlagDefinition> getFlagDefinitions();
181
182  /**
183   * Retrieves the top-level flag definition in this Metaschema module with the
184   * matching name, if it exists.
185   *
186   * @param name
187   *          the definition name
188   *
189   * @return the matching flag definition, or {@code null} if none match
190   */
191  @Nullable
192  IFlagDefinition getFlagDefinitionByName(@NonNull IEnhancedQName name);
193
194  /**
195   * Retrieves the assembly definition with a matching name from either: 1) the
196   * top-level assembly definitions from this Metaschema module, or 2) global
197   * assembly definitions from each imported Metaschema module in reverse order of
198   * import.
199   *
200   * @param name
201   *          the name of the assembly to find
202   * @return the assembly definition
203   */
204  @Nullable
205  IAssemblyDefinition getScopedAssemblyDefinitionByName(@NonNull Integer name);
206
207  /**
208   * Retrieves the field definition with a matching name from either: 1) the
209   * top-level field definitions from this Metaschema module, or 2) global field
210   * definitions from each imported Metaschema module in reverse order of import.
211   *
212   * @param name
213   *          the name of the field definition to find
214   * @return the field definition
215   */
216  @Nullable
217  IFieldDefinition getScopedFieldDefinitionByName(@NonNull Integer name);
218
219  /**
220   * Retrieves the flag definition with a matching name from either: 1) the
221   * top-level flag definitions from this Metaschema module, or 2) global flag
222   * definitions from each imported Metaschema module in reverse order of import.
223   *
224   * @param name
225   *          the name of the flag definition to find
226   * @return the flag definition
227   */
228  @Nullable
229  IFlagDefinition getScopedFlagDefinitionByName(@NonNull IEnhancedQName name);
230
231  /**
232   * Retrieves the top-level assembly definitions that are marked as roots from
233   * the current Metaschema module.
234   *
235   * @return a listing of assembly definitions marked as root
236   */
237  @NonNull
238  Collection<? extends IAssemblyDefinition> getRootAssemblyDefinitions();
239
240  /**
241   * Retrieve the top-level flag definitions that are marked global in this
242   * Metaschema module or in any imported Metaschema modules. The resulting
243   * collection is built by adding global definitions from each imported
244   * Metaschema module in order of import, then adding global definitions from the
245   * current Metaschema module. Such a map is built in this way for each imported
246   * Metaschema module in the chain. Values for clashing keys will be replaced in
247   * this order, giving preference to the "closest" definition.
248   *
249   * @return the collection of exported flag definitions
250   */
251  @NonNull
252  Collection<? extends IFlagDefinition> getExportedFlagDefinitions();
253
254  /**
255   * Retrieves the exported named flag definition, if it exists.
256   * <p>
257   * For information about how flag definitions are exported see
258   * {@link #getExportedFlagDefinitions()}.
259   *
260   * @param name
261   *          the definition name
262   * @return the flag definition, or {@code null} if it doesn't exist.
263   */
264  @Nullable
265  IFlagDefinition getExportedFlagDefinitionByName(@NonNull IEnhancedQName name);
266
267  /**
268   * Retrieve the top-level field definitions that are marked global in this
269   * Metaschema module or in any imported Metaschema module. The resulting
270   * collection is built by adding global definitions from each imported
271   * Metaschema module in order of import, then adding global definitions from the
272   * current Metaschema module. Such a map is built in this way for each imported
273   * Metaschema module in the chain. Values for clashing keys will be replaced in
274   * this order, giving preference to the "closest" definition
275   *
276   * @return the collection of exported field definitions
277   */
278  @NonNull
279  Collection<? extends IFieldDefinition> getExportedFieldDefinitions();
280
281  /**
282   * Retrieves the exported named field definition, if it exists.
283   * <p>
284   * For information about how field definitions are exported see
285   * {@link #getExportedFieldDefinitions()}.
286   *
287   * @param name
288   *          the definition name
289   * @return the field definition, or {@code null} if it doesn't exist.
290   */
291  @Nullable
292  IFieldDefinition getExportedFieldDefinitionByName(@NonNull Integer name);
293
294  /**
295   * Retrieve the top-level assembly definitions that are marked global in this
296   * Metaschema module or in any imported Metaschema module. The resulting
297   * collection is built by adding global definitions from each imported
298   * Metaschema module in order of import, then adding global definitions from the
299   * current Metaschema module. This collection is built in this way for each
300   * imported Metaschema module in the chain. Items with duplicate names will be
301   * replaced in this order, giving preference to the "closest" definition
302   *
303   * @return the collection of exported assembly definitions
304   */
305  @NonNull
306  Collection<? extends IAssemblyDefinition> getExportedAssemblyDefinitions();
307
308  /**
309   * Retrieves the exported named assembly definition, if it exists.
310   * <p>
311   * For information about how assembly definitions are exported see
312   * {@link #getExportedAssemblyDefinitions()}.
313   *
314   * @param name
315   *          the definition name
316   * @return the assembly definition, or {@code null} if it doesn't exist.
317   */
318  @Nullable
319  IAssemblyDefinition getExportedAssemblyDefinitionByName(@NonNull Integer name);
320
321  /**
322   * Retrieves the top-level assembly definitions that are marked as roots from
323   * the current Metaschema module and any imported Metaschema modules.
324   *
325   * @return a listing of assembly definitions marked as root
326   */
327  @NonNull
328  Collection<? extends IAssemblyDefinition> getExportedRootAssemblyDefinitions();
329
330  /**
331   * Retrieves the exported named root assembly definition, if it exists.
332   * <p>
333   * For information about how assembly definitions are exported see
334   * {@link #getExportedAssemblyDefinitions()}.
335   *
336   * @param name
337   *          the root name
338   * @return the assembly definition, or {@code null} if it doesn't exist.
339   */
340  @Nullable
341  IAssemblyDefinition getExportedRootAssemblyDefinitionByName(Integer name);
342
343  /**
344   * Get the mapping of prefix to namespace URI for use in resolving the namespace
345   * of lexical qualified named in Metapath.
346   *
347   * @return the mapping
348   */
349  @NonNull
350  Map<String, String> getNamespaceBindings();
351
352  /**
353   * Get the Metapath static context for compiling Metapath expressions that query
354   * instances of this model.
355   *
356   * @return the static context
357   */
358  @NonNull
359  StaticContext getModuleStaticContext();
360}