1   /*
2    * SPDX-FileCopyrightText: none
3    * SPDX-License-Identifier: CC0-1.0
4    */
5   
6   package gov.nist.secauto.metaschema.core.model;
7   
8   import gov.nist.secauto.metaschema.core.MetaschemaConstants;
9   import gov.nist.secauto.metaschema.core.model.constraint.IFeatureModelConstrained;
10  
11  import javax.xml.namespace.QName;
12  
13  import edu.umd.cs.findbugs.annotations.Nullable;
14  
15  public interface IAssemblyDefinition
16      extends IModelDefinition, IContainerModelAssembly, IAssembly, IFeatureModelConstrained {
17    QName MODEL_QNAME = new QName(MetaschemaConstants.METASCHEMA_NAMESPACE, "model");
18  
19    /**
20     * Check if the assembly is a top-level root assembly.
21     *
22     * @return {@code true} if the assembly is a top-level root, or {@code false}
23     *         otherwise
24     */
25    default boolean isRoot() {
26      // not a root by default
27      return false;
28    }
29  
30    /**
31     * Get the root name if this assembly is a top-level root.
32     *
33     * @return the root name if this assembly is a top-level root, or {@code null}
34     *         otherwise
35     */
36    @Nullable
37    default String getRootName() {
38      // not a root by default
39      return null;
40    }
41  
42    /**
43     * Get the root index to use for binary data, if this assembly is a top-level
44     * root.
45     *
46     * @return the root index if provided and this assembly is a top-level root, or
47     *         {@code null} otherwise
48     */
49    @Nullable
50    default Integer getRootIndex() {
51      // not a root by default
52      return null;
53    }
54  
55    /**
56     * Get the XML qualified name to use in XML as the root element.
57     *
58     * @return the root XML qualified name if this assembly is a top-level root, or
59     *         {@code null} otherwise
60     */
61    default QName getRootXmlQName() {
62      QName retval = null;
63      String rootName = getRootName();
64      if (rootName != null) {
65        retval = getContainingModule().toModelQName(rootName);
66      }
67      return retval;
68    }
69  
70    /**
71     * Get the name used for the associated property in JSON/YAML.
72     *
73     * @return the root JSON property name if this assembly is a top-level root, or
74     *         {@code null} otherwise
75     */
76    default String getRootJsonName() {
77      return getRootName();
78    }
79  
80    @Override
81    default boolean isInline() {
82      // not inline by default
83      return false;
84    }
85  
86    @Override
87    default IAssemblyInstance getInlineInstance() {
88      // not inline by default
89      return null;
90    }
91  
92    @Override
93    default IAssemblyDefinition getOwningDefinition() {
94      return this;
95    }
96    //
97    // @Override
98    // default IAssemblyNodeItem getNodeItem() {
99    // return null;
100   // }
101 
102   @Override
103   default boolean hasChildren() {
104     return IModelDefinition.super.hasChildren() || IContainerModelAssembly.super.hasChildren();
105   }
106 }