1   
2   package dev.metaschema.core.metapath.item.node;
3   
4   import java.net.URI;
5   
6   import dev.metaschema.core.metapath.DynamicContext;
7   import dev.metaschema.core.metapath.StaticContext;
8   import dev.metaschema.core.metapath.format.IPathFormatter;
9   import dev.metaschema.core.metapath.item.ICollectionValue;
10  import dev.metaschema.core.metapath.type.IItemType;
11  import dev.metaschema.core.model.IModule;
12  import edu.umd.cs.findbugs.annotations.NonNull;
13  
14  /**
15   * Supports querying of global definitions and associated instances in a
16   * Metaschema module by effective name.
17   * <p>
18   * All definitions in the
19   * {@link dev.metaschema.core.model.IDefinition.ModuleScope#PUBLIC} are visible.
20   * This allows the exported structure of the Metaschema module to be queried.
21   */
22  public interface IModuleNodeItem extends IDocumentBasedNodeItem, IFeatureNoDataValuedItem {
23    /**
24     * Get the static type information of the node item.
25     *
26     * @return the item type
27     */
28    @NonNull
29    static IItemType type() {
30      return IItemType.module();
31    }
32  
33    @Override
34    default NodeType getNodeType() {
35      return NodeType.MODULE;
36    }
37  
38    @Override
39    default IItemType getType() {
40      return type();
41    }
42  
43    /**
44     * The Metaschema module this item is based on.
45     *
46     * @return the Metaschema module
47     */
48    @NonNull
49    IModule getModule();
50  
51    @Override
52    default URI getDocumentUri() {
53      return getModule().getLocation();
54    }
55  
56    @Override
57    default NodeItemKind getNodeItemKind() {
58      return NodeItemKind.METASCHEMA;
59    }
60  
61    @Override
62    default IModuleNodeItem getNodeItem() {
63      return this;
64    }
65  
66    @Override
67    default String format(@NonNull IPathFormatter formatter) {
68      return formatter.formatMetaschema(this);
69    }
70  
71    @Override
72    default <CONTEXT, RESULT> RESULT accept(@NonNull INodeItemVisitor<CONTEXT, RESULT> visitor, CONTEXT context) {
73      return visitor.visitMetaschema(this, context);
74    }
75  
76    @Override
77    default StaticContext getStaticContext() {
78      return getModule().getModuleStaticContext();
79    }
80  
81    @Override
82    default boolean deepEquals(ICollectionValue other, DynamicContext dynamicContext) {
83      return other instanceof IModuleNodeItem
84          && NodeComparators.compareNodeItem(this, (IModuleNodeItem) other, dynamicContext);
85    }
86  }