1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 package gov.nist.secauto.metaschema.core.model.xml;
28
29 import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine;
30 import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline;
31 import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition;
32 import gov.nist.secauto.metaschema.core.model.IAssemblyInstance;
33 import gov.nist.secauto.metaschema.core.model.IChoiceInstance;
34 import gov.nist.secauto.metaschema.core.model.IDefinition;
35 import gov.nist.secauto.metaschema.core.model.IFeatureFlagContainer;
36 import gov.nist.secauto.metaschema.core.model.IFeatureModelContainer;
37 import gov.nist.secauto.metaschema.core.model.IFieldInstance;
38 import gov.nist.secauto.metaschema.core.model.IFlagInstance;
39 import gov.nist.secauto.metaschema.core.model.IModelInstance;
40 import gov.nist.secauto.metaschema.core.model.INamedModelInstance;
41 import gov.nist.secauto.metaschema.core.model.ModuleScopeEnum;
42 import gov.nist.secauto.metaschema.core.model.constraint.IConstraint.ExternalModelSource;
43 import gov.nist.secauto.metaschema.core.model.constraint.IModelConstrained;
44 import gov.nist.secauto.metaschema.core.model.xml.xmlbeans.GlobalAssemblyDefinitionType;
45 import gov.nist.secauto.metaschema.core.util.CollectionUtil;
46 import gov.nist.secauto.metaschema.core.util.ObjectUtils;
47
48 import java.util.Map;
49 import java.util.Set;
50
51 import javax.xml.namespace.QName;
52
53 import edu.umd.cs.findbugs.annotations.NonNull;
54 import nl.talsmasoftware.lazy4j.Lazy;
55
56 @SuppressWarnings("PMD.CouplingBetweenObjects")
57 class XmlGlobalAssemblyDefinition
58 implements IAssemblyDefinition,
59 IFeatureModelContainer<IModelInstance, INamedModelInstance, IFieldInstance, IAssemblyInstance, IChoiceInstance>,
60 IFeatureFlagContainer<IFlagInstance> {
61
62 @NonNull
63 private final GlobalAssemblyDefinitionType xmlAssembly;
64 @NonNull
65 private final XmlModule metaschema;
66 @NonNull
67 private final Lazy<XmlFlagContainerSupport> flagContainer;
68 @NonNull
69 private final Lazy<XmlModelContainerSupport> modelContainer;
70 @NonNull
71 private final Lazy<AssemblyConstraintSupport> constraints;
72
73
74
75
76
77
78
79
80
81
82 public XmlGlobalAssemblyDefinition(
83 @NonNull GlobalAssemblyDefinitionType xmlAssembly,
84 @NonNull XmlModule metaschema) {
85 this.xmlAssembly = xmlAssembly;
86 this.metaschema = metaschema;
87 this.flagContainer = ObjectUtils.notNull(Lazy.lazy(() -> new XmlFlagContainerSupport(xmlAssembly, this)));
88 this.modelContainer = ObjectUtils.notNull(Lazy.lazy(() -> new XmlModelContainerSupport(xmlAssembly, this)));
89 this.constraints = ObjectUtils.notNull(Lazy.lazy(() -> AssemblyConstraintSupport.newInstance(
90 xmlAssembly,
91 ExternalModelSource.instance(metaschema.getLocation()))));
92 }
93
94 @Override
95 public XmlFlagContainerSupport getFlagContainer() {
96 return ObjectUtils.notNull(flagContainer.get());
97 }
98
99 @Override
100 public XmlModelContainerSupport getModelContainer() {
101 return ObjectUtils.notNull(modelContainer.get());
102 }
103
104 @Override
105 public IModelConstrained getConstraintSupport() {
106 return ObjectUtils.notNull(constraints.get());
107 }
108
109 @Override
110 public XmlModule getContainingModule() {
111 return metaschema;
112 }
113
114
115
116
117
118
119
120
121
122
123 @NonNull
124 protected GlobalAssemblyDefinitionType getXmlAssembly() {
125 return xmlAssembly;
126 }
127
128 @Override
129 public String getName() {
130 return ObjectUtils.requireNonNull(getXmlAssembly().getName());
131 }
132
133 @Override
134 public String getUseName() {
135 return getXmlAssembly().isSetUseName() ? getXmlAssembly().getUseName() : null;
136 }
137
138 @Override
139 public String getFormalName() {
140 return getXmlAssembly().isSetFormalName() ? getXmlAssembly().getFormalName() : null;
141 }
142
143 @SuppressWarnings("null")
144 @Override
145 public MarkupLine getDescription() {
146 return getXmlAssembly().isSetDescription() ? MarkupStringConverter.toMarkupString(getXmlAssembly().getDescription())
147 : null;
148 }
149
150 @Override
151 public Map<QName, Set<String>> getProperties() {
152 return ModelFactory.toProperties(CollectionUtil.listOrEmpty(getXmlAssembly().getPropList()));
153 }
154
155 @Override
156 public boolean isRoot() {
157 return getXmlAssembly().isSetRootName();
158 }
159
160 @Override
161 public String getRootName() {
162 return getXmlAssembly().isSetRootName() ? getXmlAssembly().getRootName() : null;
163 }
164
165 @SuppressWarnings("null")
166 @Override
167 public ModuleScopeEnum getModuleScope() {
168 return getXmlAssembly().isSetScope() ? getXmlAssembly().getScope() : IDefinition.DEFAULT_DEFINITION_MODEL_SCOPE;
169 }
170
171 @SuppressWarnings("null")
172 @Override
173 public MarkupMultiline getRemarks() {
174 return getXmlAssembly().isSetRemarks() ? MarkupStringConverter.toMarkupString(getXmlAssembly().getRemarks()) : null;
175 }
176
177
178
179
180
181 @Override
182 public boolean isInline() {
183
184 return false;
185 }
186
187 @Override
188 public IAssemblyInstance getInlineInstance() {
189
190 return null;
191 }
192 }