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