INSTANCE handleShadowedInstances(
+ @NonNull QName key,
+ @NonNull INSTANCE shadowed,
+ @NonNull INSTANCE shadowing) {
+ if (!shadowed.equals(shadowing) && LOGGER.isErrorEnabled()) {
+ IModelDefinition owningDefinition = shadowing.getContainingDefinition();
+ IModule module = owningDefinition.getContainingModule();
+ LOGGER.error("Unexpected duplicate flag instance named '%s' in definition '%s' in module name '%s' at '%s'",
+ key,
+ owningDefinition.getDefinitionQName(),
+ module.getShortName(),
+ module.getLocation());
+ }
+ return shadowing;
+ }
+}
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IAssemblyDefinition.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IAssemblyDefinition.java
index ec9bfbc96..a204152cf 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IAssemblyDefinition.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IAssemblyDefinition.java
@@ -26,6 +26,7 @@
package gov.nist.secauto.metaschema.core.model;
+import gov.nist.secauto.metaschema.core.metapath.item.node.IAssemblyNodeItem;
import gov.nist.secauto.metaschema.core.model.constraint.IFeatureModelConstrained;
import javax.xml.namespace.QName;
@@ -108,6 +109,11 @@ default IAssemblyDefinition getOwningDefinition() {
return this;
}
+ @Override
+ default IAssemblyNodeItem getNodeItem() {
+ return null;
+ }
+
@Override
default boolean hasChildren() {
return IModelDefinition.super.hasChildren() || IContainerModelAssembly.super.hasChildren();
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IChoiceGroupInstance.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IChoiceGroupInstance.java
index 727e000f9..4a43cea19 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IChoiceGroupInstance.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IChoiceGroupInstance.java
@@ -31,6 +31,7 @@
import java.util.Locale;
import edu.umd.cs.findbugs.annotations.NonNull;
+import edu.umd.cs.findbugs.annotations.Nullable;
public interface IChoiceGroupInstance
extends IModelInstanceAbsolute, IContainerModelGrouped {
@@ -84,6 +85,18 @@ default boolean isEffectiveValueWrappedInXml() {
return true;
}
+ /**
+ * Get the effective name of the JSON key flag, if a JSON key is configured.
+ *
+ * This name is expected to be in the same namespace as the containing model
+ * element (i.e. choice group, assembly, field).
+ *
+ * @return the name of the JSON key flag if configured, or {@code null}
+ * otherwise
+ */
+ @Nullable
+ String getJsonKeyFlagInstanceName();
+
/**
* Get the named model instance for the provided choice group item.
*
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IContainerFlagSupport.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IContainerFlagSupport.java
index 24ef98b9e..112c0031b 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IContainerFlagSupport.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IContainerFlagSupport.java
@@ -26,11 +26,14 @@
package gov.nist.secauto.metaschema.core.model;
+import gov.nist.secauto.metaschema.core.model.impl.EmptyFlagContainer;
+
import java.util.Map;
import javax.xml.namespace.QName;
import edu.umd.cs.findbugs.annotations.NonNull;
+import edu.umd.cs.findbugs.annotations.Nullable;
public interface IContainerFlagSupport {
/**
@@ -46,6 +49,16 @@ static IContainerFlagSupport empty() {
return (IContainerFlagSupport) EmptyFlagContainer.EMPTY;
}
+ @NonNull
+ static IFlagContainerBuilder builder() {
+ return new FlagContainerBuilder<>(null);
+ }
+
+ @NonNull
+ static IFlagContainerBuilder builder(@NonNull QName jsonKey) {
+ return new FlagContainerBuilder<>(jsonKey);
+ }
+
/**
* Get a mapping of flag effective name to flag instance.
*
@@ -53,6 +66,7 @@ static IContainerFlagSupport empty() {
*/
@NonNull
Map getFlagInstanceMap();
- // @Nullable
- // FI getJsonKeyFlagInstance();
+
+ @Nullable
+ FI getJsonKeyFlagInstance();
}
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IDefinition.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IDefinition.java
index e6a367f3b..b4f6c1131 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IDefinition.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IDefinition.java
@@ -30,6 +30,8 @@
import java.util.Locale;
+import javax.xml.namespace.QName;
+
import edu.umd.cs.findbugs.annotations.NonNull;
public interface IDefinition extends INamedModelElement, IAttributable, IFeatureValueConstrained {
@@ -47,6 +49,21 @@ default ModuleScopeEnum getModuleScope() {
return ModuleScopeEnum.LOCAL;
}
+ /**
+ * The qualified name for the definition.
+ *
+ * This name is the combination of the definition's namespace, which is the
+ * module's namespace, and the definition's name.
+ *
+ * @return the definition's qualified name
+ */
+ @NonNull
+ default QName getDefinitionQName() {
+ return new QName(
+ getContainingModule().getXmlNamespace().toASCIIString(),
+ getName());
+ }
+
/**
* Determine if the definition is defined inline, meaning the definition is
* declared where it is used.
@@ -55,7 +72,7 @@ default ModuleScopeEnum getModuleScope() {
* the definition is able to be globally referenced
*/
default boolean isInline() {
- return false;
+ return getInlineInstance() != null;
}
/**
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IDescribable.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IDescribable.java
index 5aed8308e..e9a2c4530 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IDescribable.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IDescribable.java
@@ -48,4 +48,28 @@ public interface IDescribable {
// from INamedModelElement
@Nullable
MarkupLine getDescription();
+
+ /**
+ * The resolved formal display name, which allows an instance to override a
+ * definition's name.
+ *
+ * @return the formal name or {@code null} if not defined
+ */
+ // from INamedModelElement
+ @Nullable
+ default String getEffectiveFormalName() {
+ return getFormalName();
+ }
+
+ /**
+ * Get the text that describes the basic use of the element, which allows an
+ * instance to override a definition's description.
+ *
+ * @return a line of markup text or {@code null} if not defined
+ */
+ // from INamedModelElement
+ @Nullable
+ default MarkupLine getEffectiveDescription() {
+ return getDescription();
+ }
}
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFeatureContainerFlag.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFeatureContainerFlag.java
index 72ee85aba..51ac31b1a 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFeatureContainerFlag.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFeatureContainerFlag.java
@@ -41,7 +41,7 @@
* @param
* the flag instance Java type
*/
-public interface IFeatureContainerFlag extends IContainerFlag {
+public interface IFeatureContainerFlag extends IModelDefinition {
/**
* Lazy initialize the flag instances associated with this definition.
*
@@ -61,4 +61,9 @@ default FI getFlagInstanceByName(QName name) {
default Collection extends FI> getFlagInstances() {
return ObjectUtils.notNull(getFlagContainer().getFlagInstanceMap().values());
}
+
+ @Override
+ default FI getJsonKey() {
+ return getFlagContainer().getJsonKeyFlagInstance();
+ }
}
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFeatureContainerModelAbsolute.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFeatureContainerModelAbsolute.java
index 4d3fddc78..03d6e5cd2 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFeatureContainerModelAbsolute.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFeatureContainerModelAbsolute.java
@@ -46,7 +46,8 @@ public interface IFeatureContainerModelAbsolute<
MI extends IModelInstanceAbsolute,
NMI extends INamedModelInstanceAbsolute,
FI extends IFieldInstanceAbsolute,
- AI extends IAssemblyInstanceAbsolute> extends IContainerModelAbsolute, IFeatureContainerModel {
+ AI extends IAssemblyInstanceAbsolute>
+ extends IContainerModelAbsolute, IFeatureContainerModel {
@Override
default Collection getModelInstances() {
return getModelContainer().getModelInstances();
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFeatureDefinitionInstanceInlined.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFeatureDefinitionInstanceInlined.java
index 15c748dbb..11b3f48ea 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFeatureDefinitionInstanceInlined.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFeatureDefinitionInstanceInlined.java
@@ -27,9 +27,12 @@
package gov.nist.secauto.metaschema.core.model;
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine;
+import gov.nist.secauto.metaschema.core.util.ObjectUtils;
import java.util.Locale;
+import javax.xml.namespace.QName;
+
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
@@ -42,7 +45,9 @@
* @param
* the associated instance Java type
*/
-public interface IFeatureDefinitionInstanceInlined
+public interface IFeatureDefinitionInstanceInlined<
+ DEFINITION extends IDefinition,
+ INSTANCE extends INamedInstance>
extends IDefinition, INamedInstance {
@Override
default boolean isInline() {
@@ -51,11 +56,20 @@ default boolean isInline() {
}
@Override
- DEFINITION getDefinition();
+ default QName getDefinitionQName() {
+ return getReferencedDefinitionQName();
+ }
+
+ @Override
+ default DEFINITION getDefinition() {
+ return ObjectUtils.asType(this);
+ }
@Override
@NonNull
- INSTANCE getInlineInstance();
+ default INSTANCE getInlineInstance() {
+ return ObjectUtils.asType(this);
+ }
@Override
default String getEffectiveFormalName() {
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFeatureDefinitionReferenceInstance.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFeatureDefinitionReferenceInstance.java
index 16e54f0ff..e4fc03b98 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFeatureDefinitionReferenceInstance.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFeatureDefinitionReferenceInstance.java
@@ -28,8 +28,6 @@
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine;
-import java.util.Locale;
-
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
@@ -103,32 +101,4 @@ default Object getEffectiveDefaultValue() {
}
return retval;
}
-
- /**
- * Generates a "coordinate" string for the provided information element
- * instance.
- *
- * A coordinate consists of the element's:
- *
- * - containing Metaschema module's short name
- * - model type
- * - name
- * - hash code
- * - the hash code of the referenced definition
- *
- *
- * @return the coordinate
- */
- @SuppressWarnings("null")
- @Override
- default String toCoordinates() {
- IDefinition definition = getDefinition();
- return String.format("%s-instance:%s:%s/%s@%d(%d)",
- getModelType().toString().toLowerCase(Locale.ROOT),
- getContainingDefinition().getContainingModule().getShortName(),
- definition.getName(),
- getName(),
- hashCode(),
- definition.hashCode());
- }
}
diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/IFeatureValueless.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFeatureValueless.java
similarity index 93%
rename from databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/IFeatureValueless.java
rename to core/src/main/java/gov/nist/secauto/metaschema/core/model/IFeatureValueless.java
index cfbcae651..59f0b9527 100644
--- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/IFeatureValueless.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFeatureValueless.java
@@ -24,10 +24,9 @@
* OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER.
*/
-package gov.nist.secauto.metaschema.databind.model.metaschema.impl;
-
-import gov.nist.secauto.metaschema.core.model.IInstanceAbsolute;
+package gov.nist.secauto.metaschema.core.model;
+// REFACTOR: rename to IFeatureValuelessInstance
public interface IFeatureValueless extends IInstanceAbsolute {
@Override
default Object getValue(Object parent) {
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFlag.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFlag.java
index 9e08aed4a..a76a352f3 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFlag.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFlag.java
@@ -40,14 +40,4 @@ public interface IFlag extends INamedModelElement, IAttributable {
default ModelType getModelType() {
return ModelType.FLAG;
}
-
- /**
- * {@inheritDoc}
- *
- * Flags by default do not have namespaces.
- */
- @Override
- default String getXmlNamespace() {
- return null;
- }
}
diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBinding.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFlagContainerBuilder.java
similarity index 89%
rename from databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBinding.java
rename to core/src/main/java/gov/nist/secauto/metaschema/core/model/IFlagContainerBuilder.java
index fffff52dd..59ffae730 100644
--- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBinding.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFlagContainerBuilder.java
@@ -24,16 +24,14 @@
* OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER.
*/
-package gov.nist.secauto.metaschema.databind.model.metaschema;
-
-import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem;
+package gov.nist.secauto.metaschema.core.model;
import edu.umd.cs.findbugs.annotations.NonNull;
-public interface IBinding {
+public interface IFlagContainerBuilder {
@NonNull
- Object getBinding();
+ IFlagContainerBuilder flag(@NonNull T instance);
@NonNull
- INodeItem getBoundNodeItem();
+ IContainerFlagSupport build();
}
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFlagDefinition.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFlagDefinition.java
index 7aa06994e..727a7fd69 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFlagDefinition.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFlagDefinition.java
@@ -28,8 +28,5 @@
public interface IFlagDefinition extends IValuedDefinition, IFlag {
@Override
- default IFlagInstance getInlineInstance() {
- // not inline by default
- return null;
- }
+ IFlagInstance getInlineInstance();
}
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFlagInstance.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFlagInstance.java
index f927a2965..3b6038ea9 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFlagInstance.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFlagInstance.java
@@ -26,16 +26,23 @@
package gov.nist.secauto.metaschema.core.model;
+import javax.xml.namespace.QName;
+
public interface IFlagInstance extends IFlag, IValuedInstance, IInstanceAbsolute {
boolean DEFAULT_FLAG_REQUIRED = false;
@Override
- IContainerFlag getParentContainer();
+ IModelDefinition getParentContainer();
@Override
IFlagDefinition getDefinition();
+ @Override
+ default IModelDefinition getContainingDefinition() {
+ return getParentContainer();
+ }
+
/**
* Determines if a flag value is required to be provided.
*
@@ -45,4 +52,15 @@ public interface IFlagInstance extends IFlag, IValuedInstance, IInstanceAbsolute
default boolean isRequired() {
return DEFAULT_FLAG_REQUIRED;
}
+
+ @Override
+ default QName getReferencedDefinitionQName() {
+ return getContainingModule().toFlagQName(getName());
+ }
+
+ @Override
+ default QName getXmlQName() {
+ // flags do not have a namespace by default
+ return getContainingModule().toFlagQName(getEffectiveName());
+ }
}
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IGroupable.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IGroupable.java
index 6cbb04920..e06412a16 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IGroupable.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IGroupable.java
@@ -36,7 +36,7 @@
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
-public interface IGroupable extends IInstanceAbsolute, IKeyed {
+public interface IGroupable extends IInstanceAbsolute {
int DEFAULT_GROUP_AS_MIN_OCCURS = 0;
int DEFAULT_GROUP_AS_MAX_OCCURS = 1;
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IKeyed.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IJsonNamed.java
similarity index 86%
rename from core/src/main/java/gov/nist/secauto/metaschema/core/model/IKeyed.java
rename to core/src/main/java/gov/nist/secauto/metaschema/core/model/IJsonNamed.java
index 88df9aae9..0b1ed76e2 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IKeyed.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IJsonNamed.java
@@ -26,16 +26,16 @@
package gov.nist.secauto.metaschema.core.model;
-import edu.umd.cs.findbugs.annotations.Nullable;
+import edu.umd.cs.findbugs.annotations.NonNull;
-public interface IKeyed {
+public interface IJsonNamed {
/**
- * Get the name of the JSON key, if a JSON key is configured.
+ * Get the name used for the associated property in JSON/YAML
+ * serialization-related operations.
*
- * @return the name of the JSON key flag if configured, or {@code null}
- * otherwise
+ * @return the JSON property name
*/
- @Nullable
- String getJsonKeyFlagName();
+ @NonNull
+ String getJsonName();
}
diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceNamed.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IMetapathQueryable.java
similarity index 77%
rename from databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceNamed.java
rename to core/src/main/java/gov/nist/secauto/metaschema/core/model/IMetapathQueryable.java
index e90e5ebc6..ac8f757a8 100644
--- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceNamed.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IMetapathQueryable.java
@@ -24,15 +24,22 @@
* OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER.
*/
-package gov.nist.secauto.metaschema.databind.model;
+package gov.nist.secauto.metaschema.core.model;
-import gov.nist.secauto.metaschema.core.model.INamedInstance;
+import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem;
-public interface IBoundInstanceNamed extends IBoundInstance, INamedInstance {
+import edu.umd.cs.findbugs.annotations.Nullable;
- @Override
- default String getJsonName() {
- // needed to avoid conflict between IBoundInstance and INamedInstance
- return INamedInstance.super.getJsonName();
+public interface IMetapathQueryable {
+ /**
+ * Get the Metapath node item for this Metaschema module construct, which can be
+ * used to query it.
+ *
+ * @return the node item if the implementation can be queried by a Metapath or
+ * {@code null} otherwise
+ */
+ @Nullable
+ default INodeItem getNodeItem() {
+ return null;
}
}
diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModelAbsolute.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IMetaschemaModule.java
similarity index 87%
rename from databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModelAbsolute.java
rename to core/src/main/java/gov/nist/secauto/metaschema/core/model/IMetaschemaModule.java
index 28c6a7601..8400ef50a 100644
--- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModelAbsolute.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IMetaschemaModule.java
@@ -24,10 +24,14 @@
* OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER.
*/
-package gov.nist.secauto.metaschema.databind.model.metaschema;
+package gov.nist.secauto.metaschema.core.model;
-import gov.nist.secauto.metaschema.core.model.IModelInstanceAbsolute;
-
-public interface IBindingInstanceModelAbsolute extends IModelInstanceAbsolute, IBindingInstanceModel {
+public interface IMetaschemaModule
+ extends IModuleExtended<
+ IMetaschemaModule,
+ IModelDefinition,
+ IFlagDefinition,
+ IFieldDefinition,
+ IAssemblyDefinition> {
// no additional methods
}
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IModelDefinition.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IModelDefinition.java
index 8f6fd06dd..2d8317dda 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IModelDefinition.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IModelDefinition.java
@@ -26,26 +26,39 @@
package gov.nist.secauto.metaschema.core.model;
+import java.util.Collection;
+
+import javax.xml.namespace.QName;
+
+import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
-public interface IModelDefinition extends IDefinition, IContainerFlag {
+public interface IModelDefinition extends IDefinition, IContainer {
+ @Override
+ default boolean hasChildren() {
+ return !getFlagInstances().isEmpty();
+ }
/**
- * Indicates if a flag's value can be used as a property name in the containing
- * object in JSON who's value will be the object containing the flag. In such
- * cases, the flag will not appear in the object. This is only allowed if the
- * flag is required, as determined by a {@code true} result from
- * {@link IFlagInstance#isRequired()}. The {@link IFlagInstance} can be
- * retrieved using {@link #getJsonKeyFlagInstance()}.
+ * Retrieves a flag instance, by the flag's effective name, that is defined on
+ * the containing definition.
*
- * @return {@code true} if the flag's value can be used as a property name, or
- * {@code false} otherwise
- * @see #getJsonKeyFlagInstance()
+ * @param name
+ * the flag's name
+ * @return the matching flag instance, or {@code null} if there is no flag
+ * matching the specified name
*/
- // TODO: remove once moved to the instance side
- default boolean hasJsonKey() {
- return getJsonKeyFlagInstance() != null;
- }
+ @Nullable
+ IFlagInstance getFlagInstanceByName(@NonNull QName name);
+
+ /**
+ * Retrieves the flag instances for all flags defined on the containing
+ * definition.
+ *
+ * @return the flags
+ */
+ @NonNull
+ Collection extends IFlagInstance> getFlagInstances();
/**
* Retrieves the flag instance to use as as the property name for the containing
@@ -53,9 +66,9 @@ default boolean hasJsonKey() {
*
* @return the flag instance if a JSON key is configured, or {@code null}
* otherwise
- * @see #hasJsonKey()
*/
// TODO: remove once moved to the instance side
+ // TODO: Reconsider using toFlagName in favor of getReferencedDefinitionQName
@Nullable
- IFlagInstance getJsonKeyFlagInstance();
+ IFlagInstance getJsonKey();
}
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IModelElement.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IModelElement.java
index b6411e27b..b4da4e52d 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IModelElement.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IModelElement.java
@@ -35,7 +35,7 @@
* A marker interface for Metaschema constructs that can be members of a
* Metaschema definition's model.
*/
-public interface IModelElement extends IDefaultable {
+public interface IModelElement extends IDefaultable, IMetapathQueryable {
/**
* Get the Metaschema model type of the information element.
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IModelInstance.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IModelInstance.java
index f525d5c4b..d2e222590 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IModelInstance.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IModelInstance.java
@@ -35,9 +35,7 @@ public interface IModelInstance extends IInstance {
IContainerModel getParentContainer();
@Override
- default IAssemblyDefinition getContainingDefinition() {
- return getParentContainer().getOwningDefinition();
- }
+ IAssemblyDefinition getContainingDefinition();
/**
* Indicate if the instance allows values without an XML element wrapper.
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IModule.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IModule.java
index bb44743e3..02aae7400 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IModule.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IModule.java
@@ -28,6 +28,7 @@
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine;
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline;
+import gov.nist.secauto.metaschema.core.metapath.item.node.IDocumentNodeItem;
import java.net.URI;
import java.util.Collection;
@@ -38,7 +39,7 @@
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
-public interface IModule {
+public interface IModule extends IMetapathQueryable {
String XML_NAMESPACE = "http://csrc.nist.gov/ns/oscal/metaschema/1.0";
@@ -144,7 +145,7 @@ default QName getQName() {
* @return the matching assembly definition, or {@code null} if none match
*/
@Nullable
- IAssemblyDefinition getAssemblyDefinitionByName(@NonNull String name);
+ IAssemblyDefinition getAssemblyDefinitionByName(@NonNull QName name);
/**
* Retrieves the top-level field definitions in this Metaschema module.
@@ -164,7 +165,7 @@ default QName getQName() {
* @return the matching field definition, or {@code null} if none match
*/
@Nullable
- IFieldDefinition getFieldDefinitionByName(@NonNull String name);
+ IFieldDefinition getFieldDefinitionByName(@NonNull QName name);
/**
* Retrieves the top-level assembly and field definitions in this Metaschema
@@ -194,7 +195,7 @@ default QName getQName() {
* @return the matching flag definition, or {@code null} if none match
*/
@Nullable
- IFlagDefinition getFlagDefinitionByName(@NonNull String name);
+ IFlagDefinition getFlagDefinitionByName(@NonNull QName name);
/**
* Retrieves the assembly definition with a matching name from either: 1) the
@@ -207,7 +208,7 @@ default QName getQName() {
* @return the assembly definition
*/
@Nullable
- IAssemblyDefinition getScopedAssemblyDefinitionByName(@NonNull String name);
+ IAssemblyDefinition getScopedAssemblyDefinitionByName(@NonNull QName name);
/**
* Retrieves the field definition with a matching name from either: 1) the
@@ -219,7 +220,7 @@ default QName getQName() {
* @return the field definition
*/
@Nullable
- IFieldDefinition getScopedFieldDefinitionByName(@NonNull String name);
+ IFieldDefinition getScopedFieldDefinitionByName(@NonNull QName name);
/**
* Retrieves the flag definition with a matching name from either: 1) the
@@ -231,16 +232,7 @@ default QName getQName() {
* @return the flag definition
*/
@Nullable
- IFlagDefinition getScopedFlagDefinitionByName(@NonNull String name);
-
- /**
- * Retrieves the top-level assembly definitions that are marked as roots from
- * the current Metaschema module and any imported Metaschema modules.
- *
- * @return a listing of assembly definitions marked as root
- */
- @NonNull
- Collection extends IAssemblyDefinition> getExportedRootAssemblyDefinitions();
+ IFlagDefinition getScopedFlagDefinitionByName(@NonNull QName name);
/**
* Retrieves the top-level assembly definitions that are marked as roots from
@@ -276,7 +268,7 @@ default QName getQName() {
* @return the flag definition, or {@code null} if it doesn't exist.
*/
@Nullable
- IFlagDefinition getExportedFlagDefinitionByName(String name);
+ IFlagDefinition getExportedFlagDefinitionByName(@NonNull QName name);
/**
* Retrieve the top-level field definitions that are marked global in this
@@ -303,7 +295,7 @@ default QName getQName() {
* @return the field definition, or {@code null} if it doesn't exist.
*/
@Nullable
- IFieldDefinition getExportedFieldDefinitionByName(String name);
+ IFieldDefinition getExportedFieldDefinitionByName(@NonNull QName name);
/**
* Retrieve the top-level assembly definitions that are marked global in this
@@ -323,14 +315,36 @@ default QName getQName() {
* Retrieves the exported named assembly definition, if it exists.
*
* For information about how assembly definitions are exported see
- * {@link #getExportedFieldDefinitions()}.
+ * {@link #getExportedAssemblyDefinitions()}.
*
* @param name
* the definition name
* @return the assembly definition, or {@code null} if it doesn't exist.
*/
@Nullable
- IAssemblyDefinition getExportedAssemblyDefinitionByName(String name);
+ IAssemblyDefinition getExportedAssemblyDefinitionByName(@NonNull QName name);
+
+ /**
+ * Retrieves the top-level assembly definitions that are marked as roots from
+ * the current Metaschema module and any imported Metaschema modules.
+ *
+ * @return a listing of assembly definitions marked as root
+ */
+ @NonNull
+ Collection extends IAssemblyDefinition> getExportedRootAssemblyDefinitions();
+
+ /**
+ * Retrieves the exported named root assembly definition, if it exists.
+ *
+ * For information about how assembly definitions are exported see
+ * {@link #getExportedAssemblyDefinitions()}.
+ *
+ * @param name
+ * the root name
+ * @return the assembly definition, or {@code null} if it doesn't exist.
+ */
+ @Nullable
+ IAssemblyDefinition getExportedRootAssemblyDefinitionByName(QName name);
@NonNull
default QName toFlagQName(@NonNull String nameRef) {
@@ -338,9 +352,35 @@ default QName toFlagQName(@NonNull String nameRef) {
return new QName(nameRef);
}
+ @NonNull
+ default QName toFlagQName(@Nullable String modelNamespace, @NonNull String nameRef) {
+ // TODO: handle namespace prefix
+ return modelNamespace == null
+ ? new QName(nameRef)
+ : new QName(modelNamespace, nameRef);
+ }
+
@NonNull
default QName toModelQName(@NonNull String nameRef) {
+ return toModelQName(null, nameRef);
+ }
+
+ @NonNull
+ default QName toModelQName(@Nullable String modelNamespace, @NonNull String nameRef) {
// TODO: handle namespace prefix
- return new QName(getXmlNamespace().toASCIIString(), nameRef);
+ String namespace = modelNamespace == null ? getXmlNamespace().toASCIIString() : modelNamespace;
+ return new QName(namespace, nameRef);
+ }
+
+ /**
+ * If this module is supported by an underlying Metaschema module
+ * representation, this method retrieves that representation.
+ *
+ * @return the underlying document as a Metapath node item or {@code null}
+ */
+ @Override
+ @Nullable
+ default IDocumentNodeItem getNodeItem() {
+ return null;
}
}
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IModuleExtended.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IModuleExtended.java
index fa0afbf91..8e259c499 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IModuleExtended.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IModuleExtended.java
@@ -34,6 +34,8 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import javax.xml.namespace.QName;
+
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
@@ -44,9 +46,9 @@
* can be accessed using {@link #getImportedModules()}.
*
* Global scoped Metaschema definitions can be accessed using
- * {@link #getScopedAssemblyDefinitionByName(String)},
- * {@link #getScopedFieldDefinitionByName(String)}, and
- * {@link #getScopedFlagDefinitionByName(String)}. These methods take into
+ * {@link #getScopedAssemblyDefinitionByName(QName)},
+ * {@link #getScopedFieldDefinitionByName(QName)}, and
+ * {@link #getScopedFlagDefinitionByName(QName)}. These methods take into
* consideration the import order to provide the global definitions that are in
* scope within the given Metschema module.
*
@@ -120,7 +122,7 @@ static Predicate allRootAssemblyDefinitions() {
@Override
@Nullable
- FL getFlagDefinitionByName(@NonNull String name);
+ FL getFlagDefinitionByName(@NonNull QName name);
@Override
@NonNull
@@ -128,7 +130,7 @@ static Predicate allRootAssemblyDefinitions() {
@Override
@Nullable
- A getAssemblyDefinitionByName(@NonNull String name);
+ A getAssemblyDefinitionByName(@NonNull QName name);
@Override
@NonNull
@@ -136,7 +138,7 @@ static Predicate allRootAssemblyDefinitions() {
@Override
@Nullable
- FI getFieldDefinitionByName(@NonNull String name);
+ FI getFieldDefinitionByName(@NonNull QName name);
@Override
@SuppressWarnings("unchecked")
@@ -151,7 +153,7 @@ default List getAssemblyAndFieldDefinitions() {
@Override
@Nullable
- default A getScopedAssemblyDefinitionByName(@NonNull String name) {
+ default A getScopedAssemblyDefinitionByName(@NonNull QName name) {
// first try local/global top-level definitions from current metaschema module
A retval = getAssemblyDefinitionByName(name);
if (retval == null) {
@@ -163,7 +165,7 @@ default A getScopedAssemblyDefinitionByName(@NonNull String name) {
@Override
@Nullable
- default FI getScopedFieldDefinitionByName(@NonNull String name) {
+ default FI getScopedFieldDefinitionByName(@NonNull QName name) {
// first try local/global top-level definitions from current metaschema module
FI retval = getFieldDefinitionByName(name);
if (retval == null) {
@@ -175,7 +177,7 @@ default FI getScopedFieldDefinitionByName(@NonNull String name) {
@Override
@Nullable
- default FL getScopedFlagDefinitionByName(@NonNull String name) {
+ default FL getScopedFlagDefinitionByName(@NonNull QName name) {
// first try local/global top-level definitions from current metaschema module
FL retval = getFlagDefinitionByName(name);
if (retval == null) {
@@ -207,7 +209,7 @@ default Collection extends A> getRootAssemblyDefinitions() {
@Override
@Nullable
- FL getExportedFlagDefinitionByName(String name);
+ FL getExportedFlagDefinitionByName(QName name);
@Override
@NonNull
@@ -215,7 +217,7 @@ default Collection extends A> getRootAssemblyDefinitions() {
@Override
@Nullable
- FI getExportedFieldDefinitionByName(String name);
+ FI getExportedFieldDefinitionByName(QName name);
@Override
@NonNull
@@ -223,5 +225,5 @@ default Collection extends A> getRootAssemblyDefinitions() {
@Override
@Nullable
- A getExportedAssemblyDefinitionByName(String name);
+ A getExportedAssemblyDefinitionByName(QName name);
}
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamed.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamed.java
new file mode 100644
index 000000000..33b3eb8a7
--- /dev/null
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamed.java
@@ -0,0 +1,153 @@
+/*
+ * Portions of this software was developed by employees of the National Institute
+ * of Standards and Technology (NIST), an agency of the Federal Government and is
+ * being made available as a public service. Pursuant to title 17 United States
+ * Code Section 105, works of NIST employees are not subject to copyright
+ * protection in the United States. This software may be subject to foreign
+ * copyright. Permission in the United States and in foreign countries, to the
+ * extent that NIST may hold copyright, to use, copy, modify, create derivative
+ * works, and distribute this software and its documentation without fee is hereby
+ * granted on a non-exclusive basis, provided that this notice and disclaimer
+ * of warranty appears in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED 'AS IS' WITHOUT ANY WARRANTY OF ANY KIND, EITHER
+ * EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY
+ * THAT THE SOFTWARE WILL CONFORM TO SPECIFICATIONS, ANY IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND FREEDOM FROM
+ * INFRINGEMENT, AND ANY WARRANTY THAT THE DOCUMENTATION WILL CONFORM TO THE
+ * SOFTWARE, OR ANY WARRANTY THAT THE SOFTWARE WILL BE ERROR FREE. IN NO EVENT
+ * SHALL NIST BE LIABLE FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO, DIRECT,
+ * INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF, RESULTING FROM,
+ * OR IN ANY WAY CONNECTED WITH THIS SOFTWARE, WHETHER OR NOT BASED UPON WARRANTY,
+ * CONTRACT, TORT, OR OTHERWISE, WHETHER OR NOT INJURY WAS SUSTAINED BY PERSONS OR
+ * PROPERTY OR OTHERWISE, AND WHETHER OR NOT LOSS WAS SUSTAINED FROM, OR AROSE OUT
+ * OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER.
+ */
+
+package gov.nist.secauto.metaschema.core.model;
+
+import javax.xml.XMLConstants;
+import javax.xml.namespace.QName;
+
+import edu.umd.cs.findbugs.annotations.NonNull;
+import edu.umd.cs.findbugs.annotations.Nullable;
+
+public interface INamed {
+
+ /**
+ * Retrieve the name of the model element.
+ *
+ * @return the name
+ */
+ @NonNull
+ String getName();
+
+ /**
+ * Retrieve the name to use for the model element, instead of the name.
+ *
+ * @return the use name or {@code null} if no use name is defined
+ */
+ // from INamedModelElement
+ @Nullable
+ default String getUseName() {
+ // no use-name by default
+ return null;
+ }
+
+ /**
+ * Get the name to use based on the provided names. This method will return the
+ * use name provided by {@link #getUseName()} if the call is not {@code null},
+ * and fall back to the name provided by {@link #getName()} otherwise. This is
+ * the model name to use for the for an instance where the instance is
+ * referenced.
+ *
+ * @return the use name if available, or the name if not
+ *
+ * @see #getUseName()
+ * @see #getName()
+ */
+ // from INamedModelElement
+ @NonNull
+ default String getEffectiveName() {
+ @Nullable String useName = getUseName();
+ return useName == null ? getName() : useName;
+ }
+
+ /**
+ * Retrieve the XML namespace for this instance.
+ *
+ * Multiple calls to this method are expected to produce the same, deterministic
+ * return value.
+ *
+ * @return the XML namespace or {@code null} if no namespace is defined
+ */
+ @Nullable
+ default String getXmlNamespace() {
+ return getXmlQName().getNamespaceURI();
+ }
+
+ /**
+ * Get the unique XML qualified name for this model element.
+ *
+ * The qualified name is considered to be unique relative to all sibling
+ * elements. For a flag, this name will be unique among all flag instances on
+ * the same field or assembly definition. For a field or assembly, this name
+ * will be unique among all sibling field or assembly instances on the same
+ * assembly definition.
+ *
+ * Multiple calls to this method are expected to produce the same, deterministic
+ * return value.
+ *
+ * If {@link #getXmlNamespace()} is {@code null}, the the resulting QName will
+ * have the namespace {@link XMLConstants#NULL_NS_URI}.
+ *
+ * This implementation may be overridden by implementation that cache the QName
+ * or provide for a more efficient method for QName creation.
+ *
+ * @return the XML qualified name, or {@code null} if there isn't one
+ */
+ // REFACTOR: rename to getQName
+ @NonNull
+ QName getXmlQName();
+
+ /**
+ * Retrieve the index value to use for binary naming.
+ *
+ * @return the name index or {@code null} if no name index is defined
+ */
+ // from INamedModelElement
+ @Nullable
+ default Integer getIndex() {
+ // no index by default
+ return null;
+ }
+
+ /**
+ * Retrieve the index value to use for binary naming, instead of the name.
+ *
+ * @return the use name index or {@code null} if no use name index is defined
+ */
+ // from INamedModelElement
+ @Nullable
+ default Integer getUseIndex() {
+ // no use-name index by default
+ return null;
+ }
+
+ /**
+ * Get the index value to use for binary naming based on the provided index
+ * values.
+ *
+ * This method will return the use index value provided by
+ * {@link #getUseIndex()} if the call result is not {@code null}, and fall back
+ * to the index value provided by {@link #getIndex()} otherwise.
+ *
+ * @return the index value if available, or {@code null} otherwise
+ */
+ // from INamedModelElement
+ @Nullable
+ default Integer getEffectiveIndex() {
+ @Nullable Integer useIndex = getUseIndex();
+ return useIndex == null ? getIndex() : useIndex;
+ }
+}
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamedInstance.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamedInstance.java
index fac230666..bb695f1fa 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamedInstance.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamedInstance.java
@@ -26,6 +26,8 @@
package gov.nist.secauto.metaschema.core.model;
+import javax.xml.namespace.QName;
+
import edu.umd.cs.findbugs.annotations.NonNull;
/**
@@ -43,4 +45,12 @@ public interface INamedInstance extends INamedModelElement, IAttributable, IInst
@NonNull
IDefinition getDefinition();
+ /**
+ * This represents the qualified name of a referenced definition.
+ *
+ * @return the qualified name
+ * @see IDefinition#getDefinitionQName()
+ */
+ @NonNull
+ QName getReferencedDefinitionQName();
}
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamedModelElement.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamedModelElement.java
index cca624f0a..3871afb15 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamedModelElement.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamedModelElement.java
@@ -26,169 +26,15 @@
package gov.nist.secauto.metaschema.core.model;
-import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine;
-
-import javax.xml.XMLConstants;
-import javax.xml.namespace.QName;
-
import edu.umd.cs.findbugs.annotations.NonNull;
-import edu.umd.cs.findbugs.annotations.Nullable;
/**
* A marker interface for Metaschema constructs that can be members of a
* Metaschema module's model that have a name and other identifying
* characteristics.
*/
-public interface INamedModelElement extends IDescribable, IModelElement {
- /**
- * The resolved formal display name, which allows an instance to override a
- * definition's name.
- *
- * @return the formal name or {@code null} if not defined
- */
- // from INamedModelElement
- @Nullable
- default String getEffectiveFormalName() {
- return getFormalName();
- }
-
- /**
- * Get the text that describes the basic use of the element, which allows an
- * instance to override a definition's description.
- *
- * @return a line of markup text or {@code null} if not defined
- */
- // from INamedModelElement
- @Nullable
- default MarkupLine getEffectiveDescription() {
- return getDescription();
- }
-
- /**
- * Retrieve the name of the model element.
- *
- * @return the name
- */
- @NonNull
- String getName();
-
- /**
- * Retrieve the name to use for the model element, instead of the name.
- *
- * @return the use name or {@code null} if no use name is defined
- */
- // from INamedModelElement
- @Nullable
- default String getUseName() {
- // no use-name by default
- return null;
- }
-
- /**
- * Get the name to use based on the provided names. This method will return the
- * use name provided by {@link #getUseName()} if the call is not {@code null},
- * and fall back to the name provided by {@link #getName()} otherwise. This is
- * the model name to use for the for an instance where the instance is
- * referenced.
- *
- * @return the use name if available, or the name if not
- *
- * @see #getUseName()
- * @see #getName()
- */
- // from INamedModelElement
- @NonNull
- default String getEffectiveName() {
- @Nullable String useName = getUseName();
- return useName == null ? getName() : useName;
- }
-
- /**
- * Retrieve the XML namespace for this instance.
- *
- * Multiple calls to this method are expected to produce the same, deterministic
- * return value.
- *
- * @return the XML namespace or {@code null} if no namespace is defined
- */
- @Nullable
- default String getXmlNamespace() {
- return getContainingModule().getXmlNamespace().toASCIIString();
- }
-
- /**
- * Get the unique XML qualified name for this model element.
- *
- * The qualified name is considered to be unique relative to all sibling
- * elements. For a flag, this name will be unique among all flag instances on
- * the same field or assembly definition. For a field or assembly, this name
- * will be unique among all sibling field or assembly instances on the same
- * assembly definition.
- *
- * Multiple calls to this method are expected to produce the same, deterministic
- * return value.
- *
- * If {@link #getXmlNamespace()} is {@code null}, the the resulting QName will
- * have the namespace {@link XMLConstants#NULL_NS_URI}.
- *
- * This implementation may be overridden by implementation that cache the QName
- * or provide for a more efficient method for QName creation.
- *
- * @return the XML qualified name, or {@code null} if there isn't one
- */
- // REFACTOR: rename to getQName
- @NonNull
- default QName getXmlQName() {
- return new QName(getXmlNamespace(), getEffectiveName());
- }
-
- /**
- * Retrieve the index value to use for binary naming.
- *
- * @return the name index or {@code null} if no name index is defined
- */
- // from INamedModelElement
- @Nullable
- default Integer getIndex() {
- // no index by default
- return null;
- }
-
- /**
- * Retrieve the index value to use for binary naming, instead of the name.
- *
- * @return the use name index or {@code null} if no use name index is defined
- */
- // from INamedModelElement
- @Nullable
- default Integer getUseIndex() {
- // no use-name index by default
- return null;
- }
-
- /**
- * Get the index value to use for binary naming based on the provided index
- * values.
- *
- * This method will return the use index value provided by
- * {@link #getUseIndex()} if the call result is not {@code null}, and fall back
- * to the index value provided by {@link #getIndex()} otherwise.
- *
- * @return the index value if available, or {@code null} otherwise
- */
- // from INamedModelElement
- @Nullable
- default Integer getEffectiveIndex() {
- @Nullable Integer useIndex = getUseIndex();
- return useIndex == null ? getIndex() : useIndex;
- }
-
- /**
- * Get the name used for the associated property in JSON/YAML.
- *
- * @return the JSON property name
- */
- // from INamedModelElement
+public interface INamedModelElement extends IDescribable, IModelElement, IJsonNamed, INamed {
+ @Override
@NonNull
default String getJsonName() {
return getEffectiveName();
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamedModelInstance.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamedModelInstance.java
index b87337a72..47c14c813 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamedModelInstance.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamedModelInstance.java
@@ -26,10 +26,57 @@
package gov.nist.secauto.metaschema.core.model;
+import javax.xml.namespace.QName;
+
import edu.umd.cs.findbugs.annotations.NonNull;
+import edu.umd.cs.findbugs.annotations.Nullable;
-public interface INamedModelInstance extends IModelInstance, INamedInstance, IKeyed {
+public interface INamedModelInstance extends IModelInstance, INamedInstance {
@Override
@NonNull
IModelDefinition getDefinition();
+
+ /**
+ * Indicates if a flag's value can be used as a property name in the containing
+ * object in JSON who's value will be the object containing the flag. In such
+ * cases, the flag will not appear in the object. This is only allowed if the
+ * flag is required, as determined by a {@code true} result from
+ * {@link IFlagInstance#isRequired()}. The {@link IFlagInstance} can be
+ * retrieved using {@link #getEffectiveJsonKey()}.
+ *
+ * @return {@code true} if the flag's value can be used as a property name, or
+ * {@code false} otherwise
+ * @see #getEffectiveJsonKey()
+ */
+ // TODO: remove once moved to the instance side
+ default boolean hasJsonKey() {
+ return getEffectiveJsonKey() != null;
+ }
+
+ /**
+ * Get the JSON key flag instance for this model instance, if one is configured.
+ *
+ * @return the JSON key flag instance or {@code null} if a JSON key is
+ * configured
+ */
+ @Nullable
+ IFlagInstance getEffectiveJsonKey();
+
+ /**
+ * Get the JSON key associated with this instance.
+ *
+ * @return the configured JSON key or {@code null} if no JSON key is configured
+ */
+ @Nullable
+ IFlagInstance getJsonKey();
+
+ @Override
+ default QName getReferencedDefinitionQName() {
+ return getContainingModule().toModelQName(getName());
+ }
+
+ @Override
+ default QName getXmlQName() {
+ return getContainingModule().toModelQName(getEffectiveName());
+ }
}
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamedModelInstanceAbsolute.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamedModelInstanceAbsolute.java
index a80241dae..4e6a6b6cb 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamedModelInstanceAbsolute.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamedModelInstanceAbsolute.java
@@ -29,6 +29,7 @@
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
import edu.umd.cs.findbugs.annotations.NonNull;
+import edu.umd.cs.findbugs.annotations.Nullable;
public interface INamedModelInstanceAbsolute extends INamedModelInstance, IModelInstanceAbsolute {
@Override
@@ -48,14 +49,16 @@ default String getJsonName() {
}
@Override
- default String getJsonKeyFlagName() {
- String retval = null;
- if (JsonGroupAsBehavior.KEYED.equals(getJsonGroupAsBehavior())) {
- IFlagInstance jsonKeyFlag = getDefinition().getJsonKeyFlagInstance();
- if (jsonKeyFlag != null) {
- retval = jsonKeyFlag.getEffectiveName();
- }
- }
- return retval;
+ @Nullable
+ default IFlagInstance getEffectiveJsonKey() {
+ return JsonGroupAsBehavior.KEYED.equals(getJsonGroupAsBehavior())
+ ? getJsonKey()
+ : null;
+ }
+
+ @Override
+ @Nullable
+ default IFlagInstance getJsonKey() {
+ return getDefinition().getJsonKey();
}
}
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamedModelInstanceGrouped.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamedModelInstanceGrouped.java
index 9b4f06699..e5c23a8c6 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamedModelInstanceGrouped.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamedModelInstanceGrouped.java
@@ -69,10 +69,19 @@ default String getEffectiveDisciminatorValue() {
}
@Override
- default String getJsonKeyFlagName() {
- IChoiceGroupInstance choiceGroup = getParentContainer();
- return JsonGroupAsBehavior.KEYED.equals(choiceGroup.getJsonGroupAsBehavior())
- ? ObjectUtils.notNull(choiceGroup.getJsonKeyFlagName())
+ @Nullable
+ default IFlagInstance getEffectiveJsonKey() {
+ return JsonGroupAsBehavior.KEYED.equals(getParentContainer().getJsonGroupAsBehavior())
+ ? ObjectUtils.requireNonNull(getJsonKey())
: null;
}
+
+ @Override
+ @Nullable
+ default IFlagInstance getJsonKey() {
+ String name = getParentContainer().getJsonKeyFlagInstanceName();
+ return name == null
+ ? null
+ : ObjectUtils.requireNonNull(getDefinition().getFlagInstanceByName(getContainingModule().toFlagQName(name)));
+ }
}
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IValued.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IValued.java
index a86258466..643f7e582 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IValued.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IValued.java
@@ -45,5 +45,7 @@ public interface IValued extends IDefaultable {
*/
// from IInstanceAbsolute
@Nullable
- Object getValue(@NonNull Object parent);
+ default Object getValue(@NonNull Object parent) {
+ return getResolvedDefaultValue();
+ }
}
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/AbstractConstraintValidationHandler.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/AbstractConstraintValidationHandler.java
index 505dccaef..0307dad4e 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/AbstractConstraintValidationHandler.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/AbstractConstraintValidationHandler.java
@@ -295,7 +295,7 @@ protected CharSequence newAllowedValuesViolationMessage(
String allowedValues = constraints.stream()
.flatMap(constraint -> constraint.getAllowedValues().values().stream())
- .map(allowedValue -> allowedValue.getValue())
+ .map(IAllowedValue::getValue)
.sorted()
.distinct()
.collect(CustomCollectors.joiningWithOxfordComma("or"));
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/AssemblyTargetedConstraints.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/AssemblyTargetedConstraints.java
index 5595e0459..0822720e3 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/AssemblyTargetedConstraints.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/AssemblyTargetedConstraints.java
@@ -61,11 +61,10 @@ public void target(@NonNull IAssemblyDefinition definition) {
}
@Override
- @SuppressWarnings("null")
protected void applyTo(@NonNull IAssemblyDefinition definition) {
super.applyTo(definition);
- getIndexConstraints().forEach(constraint -> definition.addConstraint(constraint));
- getUniqueConstraints().forEach(constraint -> definition.addConstraint(constraint));
- getHasCardinalityConstraints().forEach(constraint -> definition.addConstraint(constraint));
+ getIndexConstraints().forEach(definition::addConstraint);
+ getUniqueConstraints().forEach(definition::addConstraint);
+ getHasCardinalityConstraints().forEach(definition::addConstraint);
}
}
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/DefaultConstraintValidator.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/DefaultConstraintValidator.java
index 4a45b9688..0b276281f 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/DefaultConstraintValidator.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/DefaultConstraintValidator.java
@@ -36,7 +36,6 @@
import gov.nist.secauto.metaschema.core.metapath.item.node.AbstractNodeItemVisitor;
import gov.nist.secauto.metaschema.core.metapath.item.node.IAssemblyNodeItem;
import gov.nist.secauto.metaschema.core.metapath.item.node.IDefinitionNodeItem;
-import gov.nist.secauto.metaschema.core.metapath.item.node.IDocumentNodeItem;
import gov.nist.secauto.metaschema.core.metapath.item.node.IFieldNodeItem;
import gov.nist.secauto.metaschema.core.metapath.item.node.IFlagNodeItem;
import gov.nist.secauto.metaschema.core.metapath.item.node.IModuleNodeItem;
@@ -794,11 +793,6 @@ private DynamicContext handleLetStatements(
return retval;
}
- @Override
- public Void visitDocument(@NonNull IDocumentNodeItem item, DynamicContext context) {
- return super.visitDocument(item, context);
- }
-
@Override
public Void visitFlag(@NonNull IFlagNodeItem item, DynamicContext context) {
assert context != null;
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/impl/AbstractDefinitionTargetedConstraints.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/impl/AbstractDefinitionTargetedConstraints.java
index 11dec4e6a..b38f5a36c 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/impl/AbstractDefinitionTargetedConstraints.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/impl/AbstractDefinitionTargetedConstraints.java
@@ -75,12 +75,11 @@ protected AbstractDefinitionTargetedConstraints(
* @param definition
* the definition to apply the constraints to.
*/
- @SuppressWarnings("null")
protected void applyTo(@NonNull T definition) {
- getAllowedValuesConstraints().forEach(constraint -> definition.addConstraint(constraint));
- getMatchesConstraints().forEach(constraint -> definition.addConstraint(constraint));
- getIndexHasKeyConstraints().forEach(constraint -> definition.addConstraint(constraint));
- getExpectConstraints().forEach(constraint -> definition.addConstraint(constraint));
+ getAllowedValuesConstraints().forEach(definition::addConstraint);
+ getMatchesConstraints().forEach(definition::addConstraint);
+ getIndexHasKeyConstraints().forEach(definition::addConstraint);
+ getExpectConstraints().forEach(definition::addConstraint);
}
@Override
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/DefaultContainerFlagSupport.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/impl/DefaultContainerFlagSupport.java
similarity index 97%
rename from core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/DefaultContainerFlagSupport.java
rename to core/src/main/java/gov/nist/secauto/metaschema/core/model/impl/DefaultContainerFlagSupport.java
index a15cbf6c7..4a70a2d45 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/DefaultContainerFlagSupport.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/impl/DefaultContainerFlagSupport.java
@@ -24,7 +24,7 @@
* OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER.
*/
-package gov.nist.secauto.metaschema.core.model.xml.impl;
+package gov.nist.secauto.metaschema.core.model.impl;
import gov.nist.secauto.metaschema.core.model.IContainerFlagSupport;
import gov.nist.secauto.metaschema.core.model.IFlagInstance;
@@ -70,6 +70,7 @@ public Map getFlagInstanceMap() {
* @return the flag instance if a JSON key is configured, or {@code null}
* otherwise
*/
+ @Override
public FI getJsonKeyFlagInstance() {
return jsonKey;
}
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/EmptyFlagContainer.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/impl/EmptyFlagContainer.java
similarity index 91%
rename from core/src/main/java/gov/nist/secauto/metaschema/core/model/EmptyFlagContainer.java
rename to core/src/main/java/gov/nist/secauto/metaschema/core/model/impl/EmptyFlagContainer.java
index ca8c4d904..d66a8e722 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/EmptyFlagContainer.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/impl/EmptyFlagContainer.java
@@ -59,8 +59,10 @@
* OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER.
*/
-package gov.nist.secauto.metaschema.core.model;
+package gov.nist.secauto.metaschema.core.model.impl;
+import gov.nist.secauto.metaschema.core.model.IContainerFlagSupport;
+import gov.nist.secauto.metaschema.core.model.IFlagInstance;
import gov.nist.secauto.metaschema.core.util.CollectionUtil;
import java.util.Map;
@@ -69,7 +71,7 @@
import edu.umd.cs.findbugs.annotations.NonNull;
-class EmptyFlagContainer implements IContainerFlagSupport {
+public class EmptyFlagContainer implements IContainerFlagSupport {
@NonNull
public static final EmptyFlagContainer> EMPTY = new EmptyFlagContainer<>();
@@ -77,4 +79,10 @@ class EmptyFlagContainer implements IContainerFlagSupp
public Map getFlagInstanceMap() {
return CollectionUtil.emptyMap();
}
+
+ @Override
+ public FI getJsonKeyFlagInstance() {
+ // no JSON key
+ return null;
+ }
}
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/util/JsonUtil.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/util/JsonUtil.java
index e25f62720..e4691f77d 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/util/JsonUtil.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/util/JsonUtil.java
@@ -257,7 +257,7 @@ public static String getAssertMessage(
JsonToken actual) {
return ObjectUtils.notNull(
String.format("Expected JsonToken(s) '%s', but found JsonToken '%s'%s.",
- expected.stream().map(token -> token.name()).collect(CustomCollectors.joiningWithOxfordComma("or")),
+ expected.stream().map(Enum::name).collect(CustomCollectors.joiningWithOxfordComma("or")),
actual,
generateLocationMessage(parser)));
}
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/util/XmlEventUtil.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/util/XmlEventUtil.java
index 4a49bf509..3ad22a6ce 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/util/XmlEventUtil.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/util/XmlEventUtil.java
@@ -81,7 +81,9 @@ private XmlEventUtil() {
@SuppressWarnings("null")
@NonNull
private static Object escape(@NonNull String data) {
- return data.chars().mapToObj(c -> (char) c).map(c -> escape(c)).collect(Collectors.joining());
+ return data.chars()
+ .mapToObj(c -> (char) c)
+ .map(XmlEventUtil::escape).collect(Collectors.joining());
}
@SuppressWarnings("null")
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/IXmlModule.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/IXmlModule.java
deleted file mode 100644
index d93b289ba..000000000
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/IXmlModule.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Portions of this software was developed by employees of the National Institute
- * of Standards and Technology (NIST), an agency of the Federal Government and is
- * being made available as a public service. Pursuant to title 17 United States
- * Code Section 105, works of NIST employees are not subject to copyright
- * protection in the United States. This software may be subject to foreign
- * copyright. Permission in the United States and in foreign countries, to the
- * extent that NIST may hold copyright, to use, copy, modify, create derivative
- * works, and distribute this software and its documentation without fee is hereby
- * granted on a non-exclusive basis, provided that this notice and disclaimer
- * of warranty appears in all copies.
- *
- * THE SOFTWARE IS PROVIDED 'AS IS' WITHOUT ANY WARRANTY OF ANY KIND, EITHER
- * EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY
- * THAT THE SOFTWARE WILL CONFORM TO SPECIFICATIONS, ANY IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND FREEDOM FROM
- * INFRINGEMENT, AND ANY WARRANTY THAT THE DOCUMENTATION WILL CONFORM TO THE
- * SOFTWARE, OR ANY WARRANTY THAT THE SOFTWARE WILL BE ERROR FREE. IN NO EVENT
- * SHALL NIST BE LIABLE FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO, DIRECT,
- * INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF, RESULTING FROM,
- * OR IN ANY WAY CONNECTED WITH THIS SOFTWARE, WHETHER OR NOT BASED UPON WARRANTY,
- * CONTRACT, TORT, OR OTHERWISE, WHETHER OR NOT INJURY WAS SUSTAINED BY PERSONS OR
- * PROPERTY OR OTHERWISE, AND WHETHER OR NOT LOSS WAS SUSTAINED FROM, OR AROSE OUT
- * OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER.
- */
-
-package gov.nist.secauto.metaschema.core.model.xml;
-
-import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition;
-import gov.nist.secauto.metaschema.core.model.IFieldDefinition;
-import gov.nist.secauto.metaschema.core.model.IFlagDefinition;
-import gov.nist.secauto.metaschema.core.model.IModelDefinition;
-import gov.nist.secauto.metaschema.core.model.IModuleExtended;
-
-public interface IXmlModule
- extends IModuleExtended<
- IXmlModule,
- IModelDefinition,
- IFlagDefinition,
- IFieldDefinition,
- IAssemblyDefinition> {
- // no additional methods
-}
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/ModuleLoader.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/ModuleLoader.java
index d966fee1e..7d2d75b3a 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/ModuleLoader.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/ModuleLoader.java
@@ -27,6 +27,7 @@
package gov.nist.secauto.metaschema.core.model.xml;
import gov.nist.secauto.metaschema.core.model.AbstractModuleLoader;
+import gov.nist.secauto.metaschema.core.model.IMetaschemaModule;
import gov.nist.secauto.metaschema.core.model.IModuleLoader;
import gov.nist.secauto.metaschema.core.model.MetaschemaException;
import gov.nist.secauto.metaschema.core.model.xml.impl.XmlModule;
@@ -60,7 +61,7 @@
* every use. Any Metaschema imported is also loaded and cached automatically.
*/
public class ModuleLoader
- extends AbstractModuleLoader {
+ extends AbstractModuleLoader {
private boolean resolveEntities; // = false;
/**
@@ -92,7 +93,8 @@ public void allowEntityResolution() {
}
@Override
- protected IXmlModule newModule(URI resource, METASCHEMADocument binding, List importedModules)
+ protected IMetaschemaModule newModule(URI resource, METASCHEMADocument binding,
+ List extends IMetaschemaModule> importedModules)
throws MetaschemaException {
return new XmlModule(resource, binding, importedModules);
}
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/XmlMetaConstraintLoader.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/XmlMetaConstraintLoader.java
index 98fa49bf2..11e0fae12 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/XmlMetaConstraintLoader.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/XmlMetaConstraintLoader.java
@@ -42,6 +42,7 @@
import gov.nist.secauto.metaschema.core.model.constraint.ITargetedConstraints;
import gov.nist.secauto.metaschema.core.model.xml.impl.ConstraintXmlSupport;
import gov.nist.secauto.metaschema.core.model.xml.xmlbeans.MetaschemaMetaConstraintsDocument;
+import gov.nist.secauto.metaschema.core.model.xml.xmlbeans.MetaschemaMetapathReferenceType;
import gov.nist.secauto.metaschema.core.model.xml.xmlbeans.ModelContextType;
import gov.nist.secauto.metaschema.core.util.CollectionUtil;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
@@ -89,13 +90,13 @@ private Context parseContext(
List metapaths;
if (parent == null) {
metapaths = ObjectUtils.notNull(contextObj.getMetapathList().stream()
- .map(metapath -> metapath.getTarget())
+ .map(MetaschemaMetapathReferenceType::getTarget)
.collect(Collectors.toList()));
} else {
List parentMetapaths = parent.getMetapaths().stream()
.collect(Collectors.toList());
metapaths = ObjectUtils.notNull(contextObj.getMetapathList().stream()
- .map(metapath -> metapath.getTarget())
+ .map(MetaschemaMetapathReferenceType::getTarget)
.flatMap(childPath -> {
return parentMetapaths.stream()
.map(parentPath -> parentPath + '/' + childPath);
@@ -190,20 +191,18 @@ protected MetaTargetedContraints(
* @param definition
* the definition to apply the constraints to.
*/
- @SuppressWarnings("null")
protected void applyTo(@NonNull IDefinition definition) {
- getAllowedValuesConstraints().forEach(constraint -> definition.addConstraint(constraint));
- getMatchesConstraints().forEach(constraint -> definition.addConstraint(constraint));
- getIndexHasKeyConstraints().forEach(constraint -> definition.addConstraint(constraint));
- getExpectConstraints().forEach(constraint -> definition.addConstraint(constraint));
+ getAllowedValuesConstraints().forEach(definition::addConstraint);
+ getMatchesConstraints().forEach(definition::addConstraint);
+ getIndexHasKeyConstraints().forEach(definition::addConstraint);
+ getExpectConstraints().forEach(definition::addConstraint);
}
- @SuppressWarnings("null")
protected void applyTo(@NonNull IAssemblyDefinition definition) {
applyTo((IDefinition) definition);
- getIndexConstraints().forEach(constraint -> definition.addConstraint(constraint));
- getUniqueConstraints().forEach(constraint -> definition.addConstraint(constraint));
- getHasCardinalityConstraints().forEach(constraint -> definition.addConstraint(constraint));
+ getIndexConstraints().forEach(definition::addConstraint);
+ getUniqueConstraints().forEach(definition::addConstraint);
+ getHasCardinalityConstraints().forEach(definition::addConstraint);
}
@Override
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlAssemblyInstance.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlAssemblyInstance.java
index 2bbad0e53..1795b7d44 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlAssemblyInstance.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlAssemblyInstance.java
@@ -28,19 +28,17 @@
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine;
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline;
-import gov.nist.secauto.metaschema.core.model.AbstractInstance;
+import gov.nist.secauto.metaschema.core.model.AbstractAssemblyInstance;
import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition;
import gov.nist.secauto.metaschema.core.model.IAssemblyInstanceAbsolute;
import gov.nist.secauto.metaschema.core.model.IAttributable;
import gov.nist.secauto.metaschema.core.model.IContainerModel;
-import gov.nist.secauto.metaschema.core.model.IFeatureDefinitionReferenceInstance;
import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior;
import gov.nist.secauto.metaschema.core.model.XmlGroupAsBehavior;
import gov.nist.secauto.metaschema.core.model.xml.xmlbeans.AssemblyReferenceType;
import gov.nist.secauto.metaschema.core.model.xml.xmlbeans.MarkupLineDatatype;
import gov.nist.secauto.metaschema.core.model.xml.xmlbeans.UseNameType;
import gov.nist.secauto.metaschema.core.util.CollectionUtil;
-import gov.nist.secauto.metaschema.core.util.ObjectUtils;
import java.util.Map;
import java.util.Set;
@@ -48,9 +46,13 @@
import edu.umd.cs.findbugs.annotations.NonNull;
class XmlAssemblyInstance
- extends AbstractInstance
- implements IAssemblyInstanceAbsolute,
- IFeatureDefinitionReferenceInstance {
+ extends AbstractAssemblyInstance<
+ IContainerModel,
+ IAssemblyDefinition,
+ IAssemblyInstanceAbsolute,
+ IAssemblyDefinition>
+ implements IAssemblyInstanceAbsolute {
+ @NonNull
private final AssemblyReferenceType xmlObject;
/**
@@ -69,13 +71,6 @@ public XmlAssemblyInstance(
this.xmlObject = xmlObject;
}
- @Override
- public IAssemblyDefinition getDefinition() {
- // This will always be not null
- return ObjectUtils.notNull(getContainingModule()
- .getScopedAssemblyDefinitionByName(getName()));
- }
-
// ----------------------------------------
// - Start XmlBeans driven code - CPD-OFF -
// ----------------------------------------
@@ -85,6 +80,7 @@ public IAssemblyDefinition getDefinition() {
*
* @return the underlying XML data
*/
+ @NonNull
protected AssemblyReferenceType getXmlObject() {
return xmlObject;
}
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlChoiceGroupInstance.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlChoiceGroupInstance.java
index 9a847300f..426f66f37 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlChoiceGroupInstance.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlChoiceGroupInstance.java
@@ -27,11 +27,10 @@
package gov.nist.secauto.metaschema.core.model.xml.impl;
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline;
-import gov.nist.secauto.metaschema.core.model.AbstractInstance;
+import gov.nist.secauto.metaschema.core.model.AbstractChoiceGroupInstance;
import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition;
import gov.nist.secauto.metaschema.core.model.IAssemblyInstanceGrouped;
import gov.nist.secauto.metaschema.core.model.IChoiceGroupInstance;
-import gov.nist.secauto.metaschema.core.model.IFeatureContainerModelGrouped;
import gov.nist.secauto.metaschema.core.model.IFieldInstanceGrouped;
import gov.nist.secauto.metaschema.core.model.IModule;
import gov.nist.secauto.metaschema.core.model.INamedModelInstanceGrouped;
@@ -56,9 +55,11 @@
import nl.talsmasoftware.lazy4j.Lazy;
class XmlChoiceGroupInstance
- extends AbstractInstance
- implements IChoiceGroupInstance,
- IFeatureContainerModelGrouped {
+ extends AbstractChoiceGroupInstance<
+ IAssemblyDefinition,
+ INamedModelInstanceGrouped,
+ IFieldInstanceGrouped,
+ IAssemblyInstanceGrouped> {
@NonNull
private final GroupedChoiceType xmlObject;
@NonNull
@@ -108,11 +109,11 @@ protected GroupedChoiceType getXmlObject() {
public String getJsonDiscriminatorProperty() {
return getXmlObject().isSetDiscriminator()
? ObjectUtils.requireNonNull(getXmlObject().getDiscriminator())
- : IChoiceGroupInstance.DEFAULT_JSON_DISCRIMINATOR_PROPERTY_NAME;
+ : DEFAULT_JSON_DISCRIMINATOR_PROPERTY_NAME;
}
@Override
- public String getJsonKeyFlagName() {
+ public String getJsonKeyFlagInstanceName() {
return getXmlObject().isSetJsonKey() ? getXmlObject().getJsonKey().getFlagRef() : null;
}
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlChoiceInstance.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlChoiceInstance.java
index 9c2d24ae0..e6a78645c 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlChoiceInstance.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlChoiceInstance.java
@@ -27,11 +27,10 @@
package gov.nist.secauto.metaschema.core.model.xml.impl;
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline;
-import gov.nist.secauto.metaschema.core.model.AbstractInstance;
+import gov.nist.secauto.metaschema.core.model.AbstractChoiceInstance;
import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition;
import gov.nist.secauto.metaschema.core.model.IAssemblyInstanceAbsolute;
import gov.nist.secauto.metaschema.core.model.IChoiceInstance;
-import gov.nist.secauto.metaschema.core.model.IFeatureContainerModelAbsolute;
import gov.nist.secauto.metaschema.core.model.IFieldInstanceAbsolute;
import gov.nist.secauto.metaschema.core.model.IModelInstanceAbsolute;
import gov.nist.secauto.metaschema.core.model.IModule;
@@ -55,9 +54,8 @@
import nl.talsmasoftware.lazy4j.Lazy;
class XmlChoiceInstance
- extends AbstractInstance
- implements IChoiceInstance,
- IFeatureContainerModelAbsolute<
+ extends AbstractChoiceInstance<
+ IAssemblyDefinition,
IModelInstanceAbsolute,
INamedModelInstanceAbsolute,
IFieldInstanceAbsolute,
@@ -88,23 +86,6 @@ public XmlModelContainer getModelContainer() {
return ObjectUtils.notNull(modelContainer.get());
}
- @Override
- public String getGroupAsName() {
- // a choice does not have a groups-as name
- return null;
- }
-
- @Override
- public String getJsonKeyFlagName() {
- // choices do not have a JSON key flag
- return null;
- }
-
- @Override
- public boolean hasChildren() {
- return !getModelContainer().getModelInstances().isEmpty();
- }
-
// ----------------------------------------
// - Start XmlBeans driven code - CPD-OFF -
// ----------------------------------------
@@ -131,36 +112,33 @@ public MarkupMultiline getRemarks() {
@SuppressWarnings("PMD.UseConcurrentHashMap")
@NonNull
- private static final XmlObjectParser> XML_MODEL_PARSER
- = new XmlObjectParser<>(ObjectUtils.notNull(
- Map.ofEntries(
- Map.entry(new QName(IModule.XML_NAMESPACE, "assembly"),
- XmlChoiceInstance::handleAssembly),
- Map.entry(new QName(IModule.XML_NAMESPACE, "define-assembly"),
- XmlChoiceInstance::handleDefineAssembly),
- Map.entry(new QName(IModule.XML_NAMESPACE, "field"),
- XmlChoiceInstance::handleField),
- Map.entry(new QName(IModule.XML_NAMESPACE, "define-field"),
- XmlChoiceInstance::handleDefineField)))) {
-
- @Override
- protected Handler>
- identifyHandler(XmlCursor cursor, XmlObject obj) {
- Handler> retval;
- if (obj instanceof FieldReferenceType) {
- retval = XmlChoiceInstance::handleField;
- } else if (obj instanceof InlineFieldDefinitionType) {
- retval = XmlChoiceInstance::handleDefineField;
- } else if (obj instanceof AssemblyReferenceType) {
- retval = XmlChoiceInstance::handleAssembly;
- } else if (obj instanceof InlineAssemblyDefinitionType) {
- retval = XmlChoiceInstance::handleDefineAssembly;
- } else {
- retval = super.identifyHandler(cursor, obj);
- }
- return retval;
- }
- };
+ private static final XmlObjectParser> XML_MODEL_PARSER
+ = new XmlObjectParser<>(ObjectUtils.notNull(
+ Map.ofEntries(Map.entry(new QName(IModule.XML_NAMESPACE, "assembly"), XmlChoiceInstance::handleAssembly),
+ Map.entry(new QName(IModule.XML_NAMESPACE, "define-assembly"),
+ XmlChoiceInstance::handleDefineAssembly),
+ Map.entry(new QName(IModule.XML_NAMESPACE, "field"), XmlChoiceInstance::handleField),
+ Map.entry(new QName(IModule.XML_NAMESPACE, "define-field"), XmlChoiceInstance::handleDefineField)))) {
+
+ @Override
+ protected Handler> identifyHandler(XmlCursor cursor,
+ XmlObject obj) {
+ Handler> retval;
+ if (obj instanceof FieldReferenceType) {
+ retval = XmlChoiceInstance::handleField;
+ } else if (obj instanceof InlineFieldDefinitionType) {
+ retval = XmlChoiceInstance::handleDefineField;
+ } else if (obj instanceof AssemblyReferenceType) {
+ retval = XmlChoiceInstance::handleAssembly;
+ } else if (obj instanceof InlineAssemblyDefinitionType) {
+ retval = XmlChoiceInstance::handleDefineAssembly;
+ } else {
+ retval = super.identifyHandler(cursor, obj);
+ }
+ return retval;
+ }
+ };
private static void handleField( // NOPMD false positive
@NonNull XmlObject obj,
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlFieldInstance.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlFieldInstance.java
index 4762fe67b..2db9e884c 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlFieldInstance.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlFieldInstance.java
@@ -28,11 +28,10 @@
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine;
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline;
-import gov.nist.secauto.metaschema.core.model.AbstractInstance;
+import gov.nist.secauto.metaschema.core.model.AbstractFieldInstance;
import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition;
import gov.nist.secauto.metaschema.core.model.IAttributable;
import gov.nist.secauto.metaschema.core.model.IContainerModel;
-import gov.nist.secauto.metaschema.core.model.IFeatureDefinitionReferenceInstance;
import gov.nist.secauto.metaschema.core.model.IFieldDefinition;
import gov.nist.secauto.metaschema.core.model.IFieldInstanceAbsolute;
import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior;
@@ -49,9 +48,8 @@
import edu.umd.cs.findbugs.annotations.Nullable;
class XmlFieldInstance
- extends AbstractInstance
- implements IFieldInstanceAbsolute,
- IFeatureDefinitionReferenceInstance {
+ extends AbstractFieldInstance
+ implements IFieldInstanceAbsolute {
@NonNull
private final FieldReferenceType xmlObject;
@Nullable
@@ -66,7 +64,7 @@ class XmlFieldInstance
* @param container
* the parent container, either a choice or assembly
*/
- @SuppressWarnings("PMD.NullAssignment")
+ @SuppressWarnings({ "PMD.NullAssignment", "PMD.ConstructorCallsOverridableMethod" })
public XmlFieldInstance(
@NonNull FieldReferenceType xmlObject,
@NonNull IContainerModel container) {
@@ -77,17 +75,6 @@ public XmlFieldInstance(
: null;
}
- @Override
- public final IFieldDefinition getDefinition() {
- // this will always be not null
- return ObjectUtils.notNull(getContainingModule().getScopedFieldDefinitionByName(getName()));
- }
-
- @Override
- public IAssemblyDefinition getContainingDefinition() {
- return getParentContainer().getOwningDefinition();
- }
-
// ----------------------------------------
// - Start XmlBeans driven code - CPD-OFF -
// ----------------------------------------
@@ -97,6 +84,7 @@ public IAssemblyDefinition getContainingDefinition() {
*
* @return the underlying XML data
*/
+ @NonNull
protected final FieldReferenceType getXmlObject() {
return xmlObject;
}
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlFlagContainerSupport.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlFlagContainerSupport.java
index 6a9ff11ca..5f3c64b7e 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlFlagContainerSupport.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlFlagContainerSupport.java
@@ -27,7 +27,9 @@
package gov.nist.secauto.metaschema.core.model.xml.impl;
import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition;
+import gov.nist.secauto.metaschema.core.model.IContainerFlagSupport;
import gov.nist.secauto.metaschema.core.model.IFieldDefinition;
+import gov.nist.secauto.metaschema.core.model.IFlagContainerBuilder;
import gov.nist.secauto.metaschema.core.model.IFlagInstance;
import gov.nist.secauto.metaschema.core.model.IModelDefinition;
import gov.nist.secauto.metaschema.core.model.IModule;
@@ -39,14 +41,12 @@
import gov.nist.secauto.metaschema.core.model.xml.xmlbeans.InlineAssemblyDefinitionType;
import gov.nist.secauto.metaschema.core.model.xml.xmlbeans.InlineFieldDefinitionType;
import gov.nist.secauto.metaschema.core.model.xml.xmlbeans.InlineFlagDefinitionType;
-import gov.nist.secauto.metaschema.core.util.CollectionUtil;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlObject;
-import java.util.LinkedHashMap;
import java.util.Map;
import javax.xml.namespace.QName;
@@ -54,12 +54,10 @@
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
-@SuppressWarnings("PMD.NullAssignment") // readability
-class XmlFlagContainerSupport
- extends DefaultContainerFlagSupport {
+final class XmlFlagContainerSupport {
@SuppressWarnings("PMD.UseConcurrentHashMap")
@NonNull
- private static final XmlObjectParser>> XML_MODEL_PARSER
+ private static final XmlObjectParser>> XML_MODEL_PARSER
= new XmlObjectParser<>(ObjectUtils.notNull(
Map.ofEntries(
Map.entry(new QName(IModule.XML_NAMESPACE, "flag"),
@@ -68,9 +66,10 @@ class XmlFlagContainerSupport
XmlFlagContainerSupport::handleDefineFlag)))) {
@Override
- protected Handler>> identifyHandler(XmlCursor cursor,
+ protected Handler>> identifyHandler(
+ XmlCursor cursor,
XmlObject obj) {
- Handler>> retval;
+ Handler>> retval;
if (obj instanceof FlagReferenceType) {
retval = XmlFlagContainerSupport::handleFlag;
} else if (obj instanceof InlineFlagDefinitionType) {
@@ -84,154 +83,163 @@ protected Handler>> identifyHan
private static void handleFlag( // NOPMD false positive
@NonNull XmlObject obj,
- Pair> state) {
+ Pair> state) {
XmlFlagInstance flagInstance = new XmlFlagInstance(
(FlagReferenceType) obj,
ObjectUtils.notNull(state.getLeft()));
- state.getRight().put(flagInstance.getXmlQName(), flagInstance);
+ state.getRight().flag(flagInstance);
}
private static void handleDefineFlag( // NOPMD false positive
@NonNull XmlObject obj,
- Pair> state) {
+ Pair> state) {
XmlInlineFlagDefinition flagInstance = new XmlInlineFlagDefinition(
(InlineFlagDefinitionType) obj,
ObjectUtils.notNull(state.getLeft()));
- state.getRight().put(flagInstance.getXmlQName(), flagInstance);
- }
-
- protected XmlFlagContainerSupport(
- @NonNull Map flagInstanceMap,
- @Nullable QName jsonKeyFlagName) {
- super(flagInstanceMap,
- jsonKeyFlagName == null ? null : ObjectUtils.requireNonNull(flagInstanceMap.get(jsonKeyFlagName)));
+ state.getRight().flag(flagInstance);
}
/**
- * Generate a set of constraints from the provided XMLBeans instance.
+ * Generate a flag container from the provided XMLBeans instance.
*
* @param xmlField
* the XMLBeans instance
* @param container
* the field containing the flag
*/
- public XmlFlagContainerSupport(
+ static IContainerFlagSupport newInstance(
@NonNull GlobalFieldDefinitionType xmlField,
@NonNull IFieldDefinition container) {
- this(
- xmlField.getFlagList().size() > 0 || xmlField.getDefineFlagList().size() > 0
- ? parseLocalFlags(xmlField, container)
- : CollectionUtil.emptyMap(),
- xmlField.isSetJsonKey()
- ? container.getContainingModule().toFlagQName(xmlField.getJsonKey().getFlagRef())
- : null);
+ if (!xmlField.getFlagList().isEmpty() || !xmlField.getDefineFlagList().isEmpty()) {
+ IFlagContainerBuilder builder = xmlField.isSetJsonKey()
+ ? IContainerFlagSupport.builder(container.getContainingModule().toFlagQName(
+ ObjectUtils.requireNonNull(xmlField.getJsonKey().getFlagRef())))
+ : IContainerFlagSupport.builder();
+ parseLocalFlags(xmlField, container, builder);
+ return builder.build();
+ }
+ return IContainerFlagSupport.empty();
}
/**
- * Generate a set of constraints from the provided XMLBeans instance.
+ * Generate a flag container from the provided XMLBeans instance.
*
* @param xmlField
* the XMLBeans instance
* @param container
* the field containing the flag
*/
- public XmlFlagContainerSupport(
+ static IContainerFlagSupport newInstance(
@NonNull InlineFieldDefinitionType xmlField,
@NonNull IFieldDefinition container) {
- this(
- xmlField.getFlagList().size() > 0 || xmlField.getDefineFlagList().size() > 0
- ? parseLocalFlags(xmlField, container)
- : CollectionUtil.emptyMap(),
- xmlField.isSetJsonKey()
- ? container.getContainingModule().toFlagQName(xmlField.getJsonKey().getFlagRef())
- : null);
+ if (!xmlField.getFlagList().isEmpty() || !xmlField.getDefineFlagList().isEmpty()) {
+ IFlagContainerBuilder builder = xmlField.isSetJsonKey()
+ ? IContainerFlagSupport.builder(container.getContainingModule().toFlagQName(
+ ObjectUtils.requireNonNull(xmlField.getJsonKey().getFlagRef())))
+ : IContainerFlagSupport.builder();
+ parseLocalFlags(xmlField, container, builder);
+ return builder.build();
+ }
+ return IContainerFlagSupport.empty();
}
/**
- * Generate a set of constraints from the provided XMLBeans instance.
+ * Generate a flag container from the provided XMLBeans instance.
*
* @param xmlField
* the XMLBeans instance
* @param container
* the field containing the flag
*/
- public XmlFlagContainerSupport(
+ static IContainerFlagSupport newInstance(
@NonNull GroupedInlineFieldDefinitionType xmlField,
- @NonNull IFieldDefinition container) {
- this(
- xmlField.getFlagList().size() > 0 || xmlField.getDefineFlagList().size() > 0
- ? parseLocalFlags(xmlField, container)
- : CollectionUtil.emptyMap(),
- null);
+ @NonNull IFieldDefinition container,
+ @Nullable String jsonKeyName) {
+ if (!xmlField.getFlagList().isEmpty() || !xmlField.getDefineFlagList().isEmpty()) {
+ IFlagContainerBuilder builder = jsonKeyName == null
+ ? IContainerFlagSupport.builder()
+ : IContainerFlagSupport.builder(container.getContainingModule().toFlagQName(jsonKeyName));
+ parseLocalFlags(xmlField, container, builder);
+ return builder.build();
+ }
+ return IContainerFlagSupport.empty();
}
/**
- * Generate a set of constraints from the provided XMLBeans instance.
+ * Generate a flag container from the provided XMLBeans instance.
*
- * @param xmlAssembly
+ * @param xmlField
* the XMLBeans instance
* @param container
- * the assembly containing the flag
+ * the field containing the flag
*/
- public XmlFlagContainerSupport(
+ static IContainerFlagSupport newInstance(
@NonNull GlobalAssemblyDefinitionType xmlAssembly,
@NonNull IAssemblyDefinition container) {
- this(
- xmlAssembly.getFlagList().size() > 0 || xmlAssembly.getDefineFlagList().size() > 0
- ? parseLocalFlags(xmlAssembly, container)
- : CollectionUtil.emptyMap(),
- xmlAssembly.isSetJsonKey()
- ? container.getContainingModule().toFlagQName(xmlAssembly.getJsonKey().getFlagRef())
- : null);
+ if (!xmlAssembly.getFlagList().isEmpty() || !xmlAssembly.getDefineFlagList().isEmpty()) {
+ IFlagContainerBuilder builder = xmlAssembly.isSetJsonKey()
+ ? IContainerFlagSupport.builder(container.getContainingModule().toFlagQName(
+ ObjectUtils.requireNonNull(xmlAssembly.getJsonKey().getFlagRef())))
+ : IContainerFlagSupport.builder();
+ parseLocalFlags(xmlAssembly, container, builder);
+ return builder.build();
+ }
+ return IContainerFlagSupport.empty();
}
/**
- * Generate a set of constraints from the provided XMLBeans instance.
+ * Generate a flag container from the provided XMLBeans instance.
*
- * @param xmlAssembly
+ * @param xmlField
* the XMLBeans instance
* @param container
- * the assembly containing the flag
+ * the field containing the flag
*/
- public XmlFlagContainerSupport(
+ static IContainerFlagSupport newInstance(
@NonNull InlineAssemblyDefinitionType xmlAssembly,
@NonNull IAssemblyDefinition container) {
- this(
- xmlAssembly.getFlagList().size() > 0 || xmlAssembly.getDefineFlagList().size() > 0
- ? parseLocalFlags(xmlAssembly, container)
- : CollectionUtil.emptyMap(),
- xmlAssembly.isSetJsonKey()
- ? container.getContainingModule().toFlagQName(xmlAssembly.getJsonKey().getFlagRef())
- : null);
+ if (!xmlAssembly.getFlagList().isEmpty() || !xmlAssembly.getDefineFlagList().isEmpty()) {
+ IFlagContainerBuilder builder = xmlAssembly.isSetJsonKey()
+ ? IContainerFlagSupport.builder(container.getContainingModule().toFlagQName(
+ ObjectUtils.requireNonNull(xmlAssembly.getJsonKey().getFlagRef())))
+ : IContainerFlagSupport.builder();
+ parseLocalFlags(xmlAssembly, container, builder);
+ return builder.build();
+ }
+ return IContainerFlagSupport.empty();
}
/**
- * Generate a set of constraints from the provided XMLBeans instance.
+ * Generate a flag container from the provided XMLBeans instance.
*
- * @param xmlAssembly
+ * @param xmlField
* the XMLBeans instance
* @param container
- * the assembly containing the flag
+ * the field containing the flag
*/
- public XmlFlagContainerSupport(
+ static IContainerFlagSupport newInstance(
@NonNull GroupedInlineAssemblyDefinitionType xmlAssembly,
- @NonNull IAssemblyDefinition container) {
- this(
- xmlAssembly.getFlagList().size() > 0 || xmlAssembly.getDefineFlagList().size() > 0
- ? parseLocalFlags(xmlAssembly, container)
- : CollectionUtil.emptyMap(),
- null);
+ @NonNull IAssemblyDefinition container,
+ @Nullable String jsonKeyName) {
+ if (!xmlAssembly.getFlagList().isEmpty() || !xmlAssembly.getDefineFlagList().isEmpty()) {
+ IFlagContainerBuilder builder = jsonKeyName == null
+ ? IContainerFlagSupport.builder()
+ : IContainerFlagSupport.builder(container.getContainingModule().toFlagQName(jsonKeyName));
+ parseLocalFlags(xmlAssembly, container, builder);
+ return builder.build();
+ }
+ return IContainerFlagSupport.empty();
}
- @NonNull
- private static Map parseLocalFlags(
+ private static void parseLocalFlags(
@NonNull XmlObject xmlObject,
- @NonNull IModelDefinition parent) {
+ @NonNull IModelDefinition parent,
+ @NonNull IFlagContainerBuilder builder) {
// handle flags
- Map flagInstances = new LinkedHashMap<>(); // NOPMD - intentional
-
- XML_MODEL_PARSER.parse(xmlObject, Pair.of(parent, flagInstances));
+ XML_MODEL_PARSER.parse(xmlObject, Pair.of(parent, builder));
+ }
- return flagInstances.isEmpty() ? CollectionUtil.emptyMap() : CollectionUtil.unmodifiableMap(flagInstances);
+ private XmlFlagContainerSupport() {
+ // disable construction
}
}
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlFlagInstance.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlFlagInstance.java
index ad8ba9511..895c3fe29 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlFlagInstance.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlFlagInstance.java
@@ -28,9 +28,8 @@
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine;
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline;
-import gov.nist.secauto.metaschema.core.model.AbstractInstance;
+import gov.nist.secauto.metaschema.core.model.AbstractFlagInstance;
import gov.nist.secauto.metaschema.core.model.IAttributable;
-import gov.nist.secauto.metaschema.core.model.IFeatureDefinitionReferenceInstance;
import gov.nist.secauto.metaschema.core.model.IFlagDefinition;
import gov.nist.secauto.metaschema.core.model.IFlagInstance;
import gov.nist.secauto.metaschema.core.model.IModelDefinition;
@@ -46,9 +45,7 @@
import edu.umd.cs.findbugs.annotations.Nullable;
class XmlFlagInstance
- extends AbstractInstance
- implements IFlagInstance,
- IFeatureDefinitionReferenceInstance {
+ extends AbstractFlagInstance {
@NonNull
private final FlagReferenceType xmlFlag;
@Nullable
@@ -63,6 +60,7 @@ class XmlFlagInstance
* @param parent
* the field definition this object is an instance of
*/
+ @SuppressWarnings("PMD.ConstructorCallsOverridableMethod")
public XmlFlagInstance(@NonNull FlagReferenceType xmlObject, @NonNull IModelDefinition parent) {
super(parent);
this.xmlFlag = xmlObject;
@@ -71,6 +69,10 @@ public XmlFlagInstance(@NonNull FlagReferenceType xmlObject, @NonNull IModelDefi
: null; // NOPMD needed for final variable
}
+ // ----------------------------------------
+ // - Start XmlBeans driven code - CPD-OFF -
+ // ----------------------------------------
+
/**
* Get the underlying XML data.
*
@@ -80,22 +82,6 @@ protected final FlagReferenceType getXmlObject() {
return xmlFlag;
}
- @Override
- public final IFlagDefinition getDefinition() {
- // this should always be not null
- return ObjectUtils.requireNonNull(
- getContainingDefinition().getContainingModule().getScopedFlagDefinitionByName(getName()));
- }
-
- @Override
- public final IModelDefinition getContainingDefinition() {
- return getParentContainer();
- }
-
- // ----------------------------------------
- // - Start XmlBeans driven code - CPD-OFF -
- // ----------------------------------------
-
@Override
public String getFormalName() {
return getXmlObject().isSetFormalName() ? getXmlObject().getFormalName() : null;
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGlobalAssemblyDefinition.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGlobalAssemblyDefinition.java
index 4e0aa165a..8959d04f3 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGlobalAssemblyDefinition.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGlobalAssemblyDefinition.java
@@ -28,15 +28,15 @@
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine;
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline;
-import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition;
+import gov.nist.secauto.metaschema.core.model.AbstractGlobalAssemblyDefinition;
+import gov.nist.secauto.metaschema.core.model.IAssemblyInstance;
import gov.nist.secauto.metaschema.core.model.IAssemblyInstanceAbsolute;
import gov.nist.secauto.metaschema.core.model.IAttributable;
import gov.nist.secauto.metaschema.core.model.IChoiceGroupInstance;
import gov.nist.secauto.metaschema.core.model.IChoiceInstance;
+import gov.nist.secauto.metaschema.core.model.IContainerFlagSupport;
import gov.nist.secauto.metaschema.core.model.IContainerModelAssemblySupport;
import gov.nist.secauto.metaschema.core.model.IDefinition;
-import gov.nist.secauto.metaschema.core.model.IFeatureContainerFlag;
-import gov.nist.secauto.metaschema.core.model.IFeatureContainerModelAssembly;
import gov.nist.secauto.metaschema.core.model.IFieldInstanceAbsolute;
import gov.nist.secauto.metaschema.core.model.IFlagInstance;
import gov.nist.secauto.metaschema.core.model.IModelInstanceAbsolute;
@@ -58,22 +58,21 @@
@SuppressWarnings("PMD.CouplingBetweenObjects")
class XmlGlobalAssemblyDefinition
- implements IAssemblyDefinition,
- IFeatureContainerModelAssembly<
+ extends AbstractGlobalAssemblyDefinition<
+ XmlModule,
+ IAssemblyInstance,
+ IFlagInstance,
IModelInstanceAbsolute,
INamedModelInstanceAbsolute,
IFieldInstanceAbsolute,
IAssemblyInstanceAbsolute,
IChoiceInstance,
- IChoiceGroupInstance>,
- IFeatureContainerFlag {
+ IChoiceGroupInstance> {
@NonNull
private final GlobalAssemblyDefinitionType xmlAssembly;
@NonNull
- private final XmlModule metaschema;
- @NonNull
- private final Lazy flagContainer;
+ private final Lazy> flagContainer;
@NonNull
private final Lazy new XmlFlagContainerSupport(xmlObject, this)));
+ this.flagContainer = ObjectUtils.notNull(Lazy.lazy(() -> XmlFlagContainerSupport.newInstance(xmlObject, this)));
this.modelContainer = ObjectUtils.notNull(
Lazy.lazy(() -> XmlAssemblyModelContainer.of(xmlObject.getModel(), this)));
this.constraints = ObjectUtils.notNull(Lazy.lazy(() -> {
@@ -113,7 +112,7 @@ public XmlGlobalAssemblyDefinition(
}
@Override
- public XmlFlagContainerSupport getFlagContainer() {
+ public IContainerFlagSupport getFlagContainer() {
return ObjectUtils.notNull(flagContainer.get());
}
@@ -133,16 +132,6 @@ public IModelConstrained getConstraintSupport() {
return ObjectUtils.notNull(constraints.get());
}
- @Override
- public XmlModule getContainingModule() {
- return metaschema;
- }
-
- @Override
- public IFlagInstance getJsonKeyFlagInstance() {
- return getFlagContainer().getJsonKeyFlagInstance();
- }
-
// ----------------------------------------
// - Start XmlBeans driven code - CPD-OFF -
// ----------------------------------------
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGlobalFieldDefinition.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGlobalFieldDefinition.java
index 2e5df30d5..299b0d86d 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGlobalFieldDefinition.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGlobalFieldDefinition.java
@@ -30,10 +30,11 @@
import gov.nist.secauto.metaschema.core.datatype.adapter.MetaschemaDataTypeProvider;
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine;
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline;
+import gov.nist.secauto.metaschema.core.model.AbstractGlobalFieldDefinition;
import gov.nist.secauto.metaschema.core.model.IAttributable;
+import gov.nist.secauto.metaschema.core.model.IContainerFlagSupport;
import gov.nist.secauto.metaschema.core.model.IDefinition;
-import gov.nist.secauto.metaschema.core.model.IFeatureContainerFlag;
-import gov.nist.secauto.metaschema.core.model.IFieldDefinition;
+import gov.nist.secauto.metaschema.core.model.IFieldInstance;
import gov.nist.secauto.metaschema.core.model.IFlagInstance;
import gov.nist.secauto.metaschema.core.model.ModuleScopeEnum;
import gov.nist.secauto.metaschema.core.model.constraint.ISource;
@@ -55,16 +56,13 @@
@SuppressWarnings({ "PMD.GodClass", "PMD.CouplingBetweenObjects" })
class XmlGlobalFieldDefinition
- implements IFieldDefinition,
- IFeatureContainerFlag {
+ extends AbstractGlobalFieldDefinition {
@NonNull
private final GlobalFieldDefinitionType xmlObject;
- @NonNull
- private final XmlModule module;
@Nullable
private final Object defaultValue;
@NonNull
- private final Lazy flagContainer;
+ private final Lazy> flagContainer;
@NonNull
private final Lazy constraints;
@@ -78,14 +76,14 @@ class XmlGlobalFieldDefinition
* the containing Metaschema module
*/
public XmlGlobalFieldDefinition(@NonNull GlobalFieldDefinitionType xmlObject, @NonNull XmlModule module) {
+ super(module);
this.xmlObject = xmlObject;
- this.module = module;
Object defaultValue = null;
if (xmlObject.isSetDefault()) {
defaultValue = getJavaTypeAdapter().parse(ObjectUtils.requireNonNull(xmlObject.getDefault()));
}
this.defaultValue = defaultValue;
- this.flagContainer = ObjectUtils.notNull(Lazy.lazy(() -> new XmlFlagContainerSupport(xmlObject, this)));
+ this.flagContainer = ObjectUtils.notNull(Lazy.lazy(() -> XmlFlagContainerSupport.newInstance(xmlObject, this)));
this.constraints = ObjectUtils.notNull(Lazy.lazy(() -> {
IValueConstrained retval = new ValueConstraintSet();
if (getXmlObject().isSetConstraint()) {
@@ -103,7 +101,7 @@ public XmlGlobalFieldDefinition(@NonNull GlobalFieldDefinitionType xmlObject, @N
*/
@SuppressWarnings("null")
@Override
- public XmlFlagContainerSupport getFlagContainer() {
+ public IContainerFlagSupport getFlagContainer() {
return flagContainer.get();
}
@@ -119,21 +117,11 @@ public IValueConstrained getConstraintSupport() {
return constraints.get();
}
- @Override
- public XmlModule getContainingModule() {
- return module;
- }
-
@Override
public Object getDefaultValue() {
return defaultValue;
}
- @Override
- public IFlagInstance getJsonKeyFlagInstance() {
- return getFlagContainer().getJsonKeyFlagInstance();
- }
-
// ----------------------------------------
// - Start XmlBeans driven code - CPD-OFF -
// ----------------------------------------
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGlobalFlagDefinition.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGlobalFlagDefinition.java
index a3b5555c2..a9e14eda2 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGlobalFlagDefinition.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGlobalFlagDefinition.java
@@ -30,9 +30,10 @@
import gov.nist.secauto.metaschema.core.datatype.adapter.MetaschemaDataTypeProvider;
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine;
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline;
+import gov.nist.secauto.metaschema.core.model.AbstractGlobalFlagDefinition;
import gov.nist.secauto.metaschema.core.model.IAttributable;
import gov.nist.secauto.metaschema.core.model.IDefinition;
-import gov.nist.secauto.metaschema.core.model.IFlagDefinition;
+import gov.nist.secauto.metaschema.core.model.IFlagInstance;
import gov.nist.secauto.metaschema.core.model.ModuleScopeEnum;
import gov.nist.secauto.metaschema.core.model.constraint.ISource;
import gov.nist.secauto.metaschema.core.model.constraint.IValueConstrained;
@@ -49,11 +50,10 @@
import edu.umd.cs.findbugs.annotations.Nullable;
import nl.talsmasoftware.lazy4j.Lazy;
-class XmlGlobalFlagDefinition implements IFlagDefinition {
+class XmlGlobalFlagDefinition
+ extends AbstractGlobalFlagDefinition {
@NonNull
private final GlobalFlagDefinitionType xmlFlag;
- @NonNull
- private final XmlModule module;
@Nullable
private final Object defaultValue;
private final Lazy constraints;
@@ -70,9 +70,8 @@ class XmlGlobalFlagDefinition implements IFlagDefinition {
public XmlGlobalFlagDefinition(
@NonNull GlobalFlagDefinitionType xmlFlag,
@NonNull XmlModule module) {
+ super(module);
this.xmlFlag = xmlFlag;
- this.module = module;
-
Object defaultValue = null;
if (xmlFlag.isSetDefault()) {
defaultValue = getJavaTypeAdapter().parse(ObjectUtils.requireNonNull(xmlFlag.getDefault()));
@@ -100,11 +99,6 @@ public IValueConstrained getConstraintSupport() {
return constraints.get();
}
- @Override
- public XmlModule getContainingModule() {
- return module;
- }
-
@Override
public Object getDefaultValue() {
return defaultValue;
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGroupedAssemblyInstance.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGroupedAssemblyInstance.java
index c40234c3a..9894df806 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGroupedAssemblyInstance.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGroupedAssemblyInstance.java
@@ -28,12 +28,11 @@
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine;
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline;
-import gov.nist.secauto.metaschema.core.model.AbstractNamedModelInstanceGrouped;
+import gov.nist.secauto.metaschema.core.model.AbstractAssemblyInstance;
import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition;
import gov.nist.secauto.metaschema.core.model.IAssemblyInstanceGrouped;
import gov.nist.secauto.metaschema.core.model.IAttributable;
import gov.nist.secauto.metaschema.core.model.IChoiceGroupInstance;
-import gov.nist.secauto.metaschema.core.model.IFeatureDefinitionReferenceInstance;
import gov.nist.secauto.metaschema.core.model.xml.xmlbeans.GroupedAssemblyReferenceType;
import gov.nist.secauto.metaschema.core.model.xml.xmlbeans.UseNameType;
import gov.nist.secauto.metaschema.core.util.CollectionUtil;
@@ -45,9 +44,12 @@
import edu.umd.cs.findbugs.annotations.NonNull;
public class XmlGroupedAssemblyInstance
- extends AbstractNamedModelInstanceGrouped
- implements IAssemblyInstanceGrouped,
- IFeatureDefinitionReferenceInstance {
+ extends AbstractAssemblyInstance<
+ IChoiceGroupInstance,
+ IAssemblyDefinition,
+ IAssemblyInstanceGrouped,
+ IAssemblyDefinition>
+ implements IAssemblyInstanceGrouped {
@NonNull
private final GroupedAssemblyReferenceType xmlObject;
@@ -72,16 +74,11 @@ public XmlGroupedAssemblyInstance(
*
* @return the underlying XML data
*/
+ @NonNull
protected GroupedAssemblyReferenceType getXmlObject() {
return xmlObject;
}
- @Override
- public IAssemblyDefinition getDefinition() {
- // this will always be not null
- return ObjectUtils.notNull(getContainingModule().getScopedAssemblyDefinitionByName(getName()));
- }
-
// ----------------------------------------
// - Start XmlBeans driven code - CPD-OFF -
// ----------------------------------------
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGroupedFieldInstance.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGroupedFieldInstance.java
index 32471a5ea..d73189fb3 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGroupedFieldInstance.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGroupedFieldInstance.java
@@ -28,10 +28,10 @@
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine;
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline;
-import gov.nist.secauto.metaschema.core.model.AbstractNamedModelInstanceGrouped;
+import gov.nist.secauto.metaschema.core.model.AbstractFieldInstance;
+import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition;
import gov.nist.secauto.metaschema.core.model.IAttributable;
import gov.nist.secauto.metaschema.core.model.IChoiceGroupInstance;
-import gov.nist.secauto.metaschema.core.model.IFeatureDefinitionReferenceInstance;
import gov.nist.secauto.metaschema.core.model.IFieldDefinition;
import gov.nist.secauto.metaschema.core.model.IFieldInstanceGrouped;
import gov.nist.secauto.metaschema.core.model.xml.xmlbeans.GroupedFieldReferenceType;
@@ -45,9 +45,8 @@
import edu.umd.cs.findbugs.annotations.NonNull;
public class XmlGroupedFieldInstance
- extends AbstractNamedModelInstanceGrouped
- implements IFieldInstanceGrouped,
- IFeatureDefinitionReferenceInstance {
+ extends AbstractFieldInstance
+ implements IFieldInstanceGrouped {
@NonNull
private final GroupedFieldReferenceType xmlObject;
@@ -68,12 +67,6 @@ public XmlGroupedFieldInstance(
this.xmlObject = xmlObject;
}
- @Override
- public IFieldDefinition getDefinition() {
- // this will always be not null
- return ObjectUtils.notNull(getContainingModule().getScopedFieldDefinitionByName(getName()));
- }
-
// ----------------------------------------
// - Start XmlBeans driven code - CPD-OFF -
// ----------------------------------------
@@ -83,6 +76,7 @@ public IFieldDefinition getDefinition() {
*
* @return the underlying XML data
*/
+ @NonNull
protected GroupedFieldReferenceType getXmlObject() {
return xmlObject;
}
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGroupedInlineAssemblyDefinition.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGroupedInlineAssemblyDefinition.java
index e0241ef54..43a25750c 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGroupedInlineAssemblyDefinition.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGroupedInlineAssemblyDefinition.java
@@ -28,17 +28,15 @@
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine;
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline;
-import gov.nist.secauto.metaschema.core.model.AbstractNamedModelInstanceGrouped;
+import gov.nist.secauto.metaschema.core.model.AbstractInlineAssemblyDefinition;
import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition;
import gov.nist.secauto.metaschema.core.model.IAssemblyInstanceAbsolute;
import gov.nist.secauto.metaschema.core.model.IAssemblyInstanceGrouped;
import gov.nist.secauto.metaschema.core.model.IAttributable;
import gov.nist.secauto.metaschema.core.model.IChoiceGroupInstance;
import gov.nist.secauto.metaschema.core.model.IChoiceInstance;
+import gov.nist.secauto.metaschema.core.model.IContainerFlagSupport;
import gov.nist.secauto.metaschema.core.model.IContainerModelAssemblySupport;
-import gov.nist.secauto.metaschema.core.model.IFeatureContainerFlag;
-import gov.nist.secauto.metaschema.core.model.IFeatureContainerModelAssembly;
-import gov.nist.secauto.metaschema.core.model.IFeatureDefinitionInstanceInlined;
import gov.nist.secauto.metaschema.core.model.IFieldInstanceAbsolute;
import gov.nist.secauto.metaschema.core.model.IFlagInstance;
import gov.nist.secauto.metaschema.core.model.IModelInstanceAbsolute;
@@ -57,22 +55,28 @@
import nl.talsmasoftware.lazy4j.Lazy;
public class XmlGroupedInlineAssemblyDefinition
- extends AbstractNamedModelInstanceGrouped
- implements IAssemblyInstanceGrouped, IAssemblyDefinition,
- IFeatureContainerModelAssembly<
+ extends AbstractInlineAssemblyDefinition<
+ IChoiceGroupInstance,
+ IAssemblyDefinition,
+ IAssemblyInstanceGrouped,
+ IAssemblyDefinition,
+ IFlagInstance,
IModelInstanceAbsolute,
INamedModelInstanceAbsolute,
IFieldInstanceAbsolute,
IAssemblyInstanceAbsolute,
IChoiceInstance,
- IChoiceGroupInstance>,
- IFeatureContainerFlag,
- IFeatureDefinitionInstanceInlined {
+ IChoiceGroupInstance>
+ implements IAssemblyInstanceGrouped {
+
+ // ----------------------------------------
+ // - Start XmlBeans driven code - CPD-OFF -
+ // ----------------------------------------
@NonNull
private final GroupedInlineAssemblyDefinitionType xmlObject;
@NonNull
- private final Lazy flagContainer;
+ private final Lazy> flagContainer;
@NonNull
private final Lazy new XmlFlagContainerSupport(xmlObject, this)));
+ this.flagContainer = ObjectUtils.notNull(Lazy.lazy(() -> XmlFlagContainerSupport.newInstance(
+ xmlObject,
+ this,
+ parent.getJsonKeyFlagInstanceName())));
this.modelContainer = ObjectUtils.notNull(
Lazy.lazy(() -> XmlAssemblyModelContainer.of(xmlObject.getModel(), this)));
this.constraints = ObjectUtils.notNull(Lazy.lazy(() -> {
@@ -113,17 +120,7 @@ public XmlGroupedInlineAssemblyDefinition(
}
@Override
- public IAssemblyDefinition getDefinition() {
- return this;
- }
-
- @Override
- public IAssemblyInstanceGrouped getInlineInstance() {
- return this;
- }
-
- @Override
- public XmlFlagContainerSupport getFlagContainer() {
+ public IContainerFlagSupport getFlagContainer() {
return ObjectUtils.notNull(flagContainer.get());
}
@@ -144,15 +141,6 @@ public IModelConstrained getConstraintSupport() {
return ObjectUtils.notNull(constraints.get());
}
- @Override
- public IFlagInstance getJsonKeyFlagInstance() {
- return getFlagContainer().getJsonKeyFlagInstance();
- }
-
- // ----------------------------------------
- // - Start XmlBeans driven code - CPD-OFF -
- // ----------------------------------------
-
/**
* Get the underlying XML model.
*
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGroupedInlineFieldDefinition.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGroupedInlineFieldDefinition.java
index 99ed78671..739e2d619 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGroupedInlineFieldDefinition.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGroupedInlineFieldDefinition.java
@@ -30,11 +30,11 @@
import gov.nist.secauto.metaschema.core.datatype.adapter.MetaschemaDataTypeProvider;
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine;
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline;
-import gov.nist.secauto.metaschema.core.model.AbstractNamedModelInstanceGrouped;
+import gov.nist.secauto.metaschema.core.model.AbstractInlineFieldDefinition;
+import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition;
import gov.nist.secauto.metaschema.core.model.IAttributable;
import gov.nist.secauto.metaschema.core.model.IChoiceGroupInstance;
-import gov.nist.secauto.metaschema.core.model.IFeatureContainerFlag;
-import gov.nist.secauto.metaschema.core.model.IFeatureDefinitionInstanceInlined;
+import gov.nist.secauto.metaschema.core.model.IContainerFlagSupport;
import gov.nist.secauto.metaschema.core.model.IFieldDefinition;
import gov.nist.secauto.metaschema.core.model.IFieldInstanceGrouped;
import gov.nist.secauto.metaschema.core.model.IFlagInstance;
@@ -54,15 +54,18 @@
import nl.talsmasoftware.lazy4j.Lazy;
public class XmlGroupedInlineFieldDefinition
- extends AbstractNamedModelInstanceGrouped
- implements IFieldInstanceGrouped, IFieldDefinition,
- IFeatureDefinitionInstanceInlined,
- IFeatureContainerFlag {
+ extends AbstractInlineFieldDefinition<
+ IChoiceGroupInstance,
+ IFieldDefinition,
+ IFieldInstanceGrouped,
+ IAssemblyDefinition,
+ IFlagInstance>
+ implements IFieldInstanceGrouped {
@NonNull
private final GroupedInlineFieldDefinitionType xmlObject;
@NonNull
- private final Lazy flagContainer;
+ private final Lazy> flagContainer;
@NonNull
private final Lazy constraints;
@@ -81,7 +84,10 @@ public XmlGroupedInlineFieldDefinition(
@NonNull IChoiceGroupInstance parent) {
super(parent);
this.xmlObject = xmlObject;
- this.flagContainer = ObjectUtils.notNull(Lazy.lazy(() -> new XmlFlagContainerSupport(xmlObject, this)));
+ this.flagContainer = ObjectUtils.notNull(Lazy.lazy(() -> XmlFlagContainerSupport.newInstance(
+ xmlObject,
+ this,
+ parent.getJsonKeyFlagInstanceName())));
this.constraints = ObjectUtils.notNull(Lazy.lazy(() -> {
IValueConstrained retval = new ValueConstraintSet();
if (getXmlObject().isSetConstraint()) {
@@ -93,17 +99,7 @@ public XmlGroupedInlineFieldDefinition(
}
@Override
- public IFieldDefinition getDefinition() {
- return this;
- }
-
- @Override
- public XmlGroupedInlineFieldDefinition getInlineInstance() {
- return this;
- }
-
- @Override
- public XmlFlagContainerSupport getFlagContainer() {
+ public IContainerFlagSupport getFlagContainer() {
return ObjectUtils.notNull(flagContainer.get());
}
@@ -112,10 +108,6 @@ public IValueConstrained getConstraintSupport() {
return ObjectUtils.notNull(constraints.get());
}
- @Override
- public IFlagInstance getJsonKeyFlagInstance() {
- return getFlagContainer().getJsonKeyFlagInstance();
- }
// ----------------------------------------
// - Start XmlBeans driven code - CPD-OFF -
// ----------------------------------------
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlInlineAssemblyDefinition.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlInlineAssemblyDefinition.java
index c7ea0532d..af3d1fd92 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlInlineAssemblyDefinition.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlInlineAssemblyDefinition.java
@@ -28,17 +28,15 @@
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine;
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline;
-import gov.nist.secauto.metaschema.core.model.AbstractInstance;
+import gov.nist.secauto.metaschema.core.model.AbstractInlineAssemblyDefinition;
import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition;
import gov.nist.secauto.metaschema.core.model.IAssemblyInstanceAbsolute;
import gov.nist.secauto.metaschema.core.model.IAttributable;
import gov.nist.secauto.metaschema.core.model.IChoiceGroupInstance;
import gov.nist.secauto.metaschema.core.model.IChoiceInstance;
+import gov.nist.secauto.metaschema.core.model.IContainerFlagSupport;
import gov.nist.secauto.metaschema.core.model.IContainerModel;
import gov.nist.secauto.metaschema.core.model.IContainerModelAssemblySupport;
-import gov.nist.secauto.metaschema.core.model.IFeatureContainerFlag;
-import gov.nist.secauto.metaschema.core.model.IFeatureContainerModelAssembly;
-import gov.nist.secauto.metaschema.core.model.IFeatureDefinitionInstanceInlined;
import gov.nist.secauto.metaschema.core.model.IFieldInstanceAbsolute;
import gov.nist.secauto.metaschema.core.model.IFlagInstance;
import gov.nist.secauto.metaschema.core.model.IModelInstanceAbsolute;
@@ -62,21 +60,28 @@
* Represents a Metaschema assembly definition declared locally as an instance.
*/
class XmlInlineAssemblyDefinition
- extends AbstractInstance
- implements IAssemblyInstanceAbsolute, IAssemblyDefinition,
- IFeatureContainerModelAssembly<
+ extends AbstractInlineAssemblyDefinition<
+ IContainerModel,
+ IAssemblyDefinition,
+ IAssemblyInstanceAbsolute,
+ IAssemblyDefinition,
+ IFlagInstance,
IModelInstanceAbsolute,
INamedModelInstanceAbsolute,
IFieldInstanceAbsolute,
IAssemblyInstanceAbsolute,
IChoiceInstance,
- IChoiceGroupInstance>,
- IFeatureContainerFlag,
- IFeatureDefinitionInstanceInlined {
+ IChoiceGroupInstance>
+ implements IAssemblyInstanceAbsolute {
+
+ // ----------------------------------------
+ // - Start XmlBeans driven code - CPD-OFF -
+ // ----------------------------------------
+
@NonNull
private final InlineAssemblyDefinitionType xmlObject;
@NonNull
- private final Lazy flagContainer;
+ private final Lazy> flagContainer;
@NonNull
private final Lazy new XmlFlagContainerSupport(xmlObject, this)));
+ this.flagContainer = ObjectUtils.notNull(Lazy.lazy(() -> XmlFlagContainerSupport.newInstance(xmlObject, this)));
this.modelContainer
= ObjectUtils.notNull(Lazy.lazy(() -> XmlAssemblyModelContainer.of(xmlObject.getModel(), this)));
this.constraints = ObjectUtils.notNull(Lazy.lazy(() -> {
@@ -115,20 +120,9 @@ public XmlInlineAssemblyDefinition(
}));
}
- @Override
- public IAssemblyDefinition getDefinition() {
- return this;
- }
-
- @Override
- @NonNull
- public IAssemblyInstanceAbsolute getInlineInstance() {
- return this;
- }
-
@SuppressWarnings("null")
@Override
- public XmlFlagContainerSupport getFlagContainer() {
+ public IContainerFlagSupport getFlagContainer() {
return flagContainer.get();
}
@@ -150,15 +144,6 @@ public IModelConstrained getConstraintSupport() {
return constraints.get();
}
- @Override
- public IFlagInstance getJsonKeyFlagInstance() {
- return getFlagContainer().getJsonKeyFlagInstance();
- }
-
- // ----------------------------------------
- // - Start XmlBeans driven code - CPD-OFF -
- // ----------------------------------------
-
/**
* Get the underlying XML model.
*
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlInlineFieldDefinition.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlInlineFieldDefinition.java
index 2cf746f64..a2029c40a 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlInlineFieldDefinition.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlInlineFieldDefinition.java
@@ -30,11 +30,11 @@
import gov.nist.secauto.metaschema.core.datatype.adapter.MetaschemaDataTypeProvider;
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine;
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline;
-import gov.nist.secauto.metaschema.core.model.AbstractInstance;
+import gov.nist.secauto.metaschema.core.model.AbstractInlineFieldDefinition;
+import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition;
import gov.nist.secauto.metaschema.core.model.IAttributable;
+import gov.nist.secauto.metaschema.core.model.IContainerFlagSupport;
import gov.nist.secauto.metaschema.core.model.IContainerModel;
-import gov.nist.secauto.metaschema.core.model.IFeatureContainerFlag;
-import gov.nist.secauto.metaschema.core.model.IFeatureDefinitionInstanceInlined;
import gov.nist.secauto.metaschema.core.model.IFieldDefinition;
import gov.nist.secauto.metaschema.core.model.IFieldInstanceAbsolute;
import gov.nist.secauto.metaschema.core.model.IFlagInstance;
@@ -57,16 +57,19 @@
import nl.talsmasoftware.lazy4j.Lazy;
class XmlInlineFieldDefinition
- extends AbstractInstance
- implements IFieldInstanceAbsolute, IFieldDefinition,
- IFeatureContainerFlag,
- IFeatureDefinitionInstanceInlined {
+ extends AbstractInlineFieldDefinition<
+ IContainerModel,
+ IFieldDefinition,
+ IFieldInstanceAbsolute,
+ IAssemblyDefinition,
+ IFlagInstance>
+ implements IFieldInstanceAbsolute {
@NonNull
private final InlineFieldDefinitionType xmlObject;
@Nullable
private final Object defaultValue;
@NonNull
- private final Lazy flagContainer;
+ private final Lazy> flagContainer;
@NonNull
private final Lazy constraints;
@@ -88,7 +91,7 @@ public XmlInlineFieldDefinition(
this.defaultValue = xmlObject.isSetDefault()
? getJavaTypeAdapter().parse(ObjectUtils.requireNonNull(xmlObject.getDefault()))
: null;
- this.flagContainer = ObjectUtils.notNull(Lazy.lazy(() -> new XmlFlagContainerSupport(xmlObject, this)));
+ this.flagContainer = ObjectUtils.notNull(Lazy.lazy(() -> XmlFlagContainerSupport.newInstance(xmlObject, this)));
this.constraints = ObjectUtils.notNull(Lazy.lazy(() -> {
IValueConstrained retval = new ValueConstraintSet();
if (getXmlObject().isSetConstraint()) {
@@ -113,28 +116,12 @@ protected final InlineFieldDefinitionType getXmlObject() {
return xmlObject;
}
- @Override
- public IFieldDefinition getDefinition() {
- return this;
- }
-
- @Override
- @NonNull
- public IFieldInstanceAbsolute getInlineInstance() {
- return this;
- }
-
@SuppressWarnings("null")
@Override
- public XmlFlagContainerSupport getFlagContainer() {
+ public IContainerFlagSupport getFlagContainer() {
return flagContainer.get();
}
- @Override
- public IFlagInstance getJsonKeyFlagInstance() {
- return getFlagContainer().getJsonKeyFlagInstance();
- }
-
/**
* Used to generate the instances for the constraints in a lazy fashion when the
* constraints are first accessed.
@@ -244,6 +231,11 @@ public String getJsonValueKeyName() {
return getXmlObject().getJsonValueKey();
}
+ // @Override
+ // public String getJsonKeyFlagInstanceName() {
+ // return IFeatureXmlContainerFlag.super.getJsonKeyFlagInstanceName();
+ // }
+
// -------------------------------------
// - End XmlBeans driven code - CPD-ON -
// -------------------------------------
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlInlineFlagDefinition.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlInlineFlagDefinition.java
index 00702587b..12a99b3de 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlInlineFlagDefinition.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlInlineFlagDefinition.java
@@ -30,9 +30,8 @@
import gov.nist.secauto.metaschema.core.datatype.adapter.MetaschemaDataTypeProvider;
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine;
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline;
-import gov.nist.secauto.metaschema.core.model.AbstractInstance;
+import gov.nist.secauto.metaschema.core.model.AbstractInlineFlagDefinition;
import gov.nist.secauto.metaschema.core.model.IAttributable;
-import gov.nist.secauto.metaschema.core.model.IFeatureDefinitionInstanceInlined;
import gov.nist.secauto.metaschema.core.model.IFlagDefinition;
import gov.nist.secauto.metaschema.core.model.IFlagInstance;
import gov.nist.secauto.metaschema.core.model.IModelDefinition;
@@ -51,9 +50,8 @@
import nl.talsmasoftware.lazy4j.Lazy;
class XmlInlineFlagDefinition
- extends AbstractInstance
- implements IFlagInstance, IFlagDefinition,
- IFeatureDefinitionInstanceInlined {
+ extends AbstractInlineFlagDefinition {
+
@NonNull
private final InlineFlagDefinitionType xmlFlag;
@Nullable
@@ -88,17 +86,6 @@ public XmlInlineFlagDefinition(@NonNull InlineFlagDefinitionType xmlObject, @Non
}));
}
- @Override
- public IFlagDefinition getDefinition() {
- return this;
- }
-
- @Override
- @NonNull
- public IFlagInstance getInlineInstance() {
- return this;
- }
-
/**
* Used to generate the instances for the constraints in a lazy fashion when the
* constraints are first accessed.
@@ -114,11 +101,6 @@ public Object getDefaultValue() {
return defaultValue;
}
- @Override
- public IModelDefinition getContainingDefinition() {
- return getParentContainer();
- }
-
// ----------------------------------------
// - Start XmlBeans driven code - CPD-OFF -
// ----------------------------------------
diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlModule.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlModule.java
index f5e791e8b..7efcb9750 100644
--- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlModule.java
+++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlModule.java
@@ -32,9 +32,9 @@
import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition;
import gov.nist.secauto.metaschema.core.model.IFieldDefinition;
import gov.nist.secauto.metaschema.core.model.IFlagDefinition;
+import gov.nist.secauto.metaschema.core.model.IMetaschemaModule;
import gov.nist.secauto.metaschema.core.model.IModelDefinition;
import gov.nist.secauto.metaschema.core.model.MetaschemaException;
-import gov.nist.secauto.metaschema.core.model.xml.IXmlModule;
import gov.nist.secauto.metaschema.core.model.xml.xmlbeans.GlobalAssemblyDefinitionType;
import gov.nist.secauto.metaschema.core.model.xml.xmlbeans.GlobalFieldDefinitionType;
import gov.nist.secauto.metaschema.core.model.xml.xmlbeans.GlobalFlagDefinitionType;
@@ -56,27 +56,27 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import javax.xml.namespace.QName;
+
import edu.umd.cs.findbugs.annotations.NonNull;
+import nl.talsmasoftware.lazy4j.Lazy;
@SuppressWarnings("PMD.CouplingBetweenObjects")
public class XmlModule
extends AbstractModule<
- IXmlModule,
+ IMetaschemaModule,
IModelDefinition,
IFlagDefinition,
IFieldDefinition,
IAssemblyDefinition>
- implements IXmlModule {
+ implements IMetaschemaModule {
private static final Logger LOGGER = LogManager.getLogger(XmlModule.class);
@NonNull
private final URI location;
@NonNull
private final METASCHEMADocument module;
- private final Map flagDefinitions;
- private final Map fieldDefinitions;
- private final Map assemblyDefinitions;
- private final Map rootAssemblyDefinitions;
+ private final Lazy definitions;
/**
* Constructs a new Metaschema instance.
@@ -93,81 +93,13 @@ public class XmlModule
public XmlModule( // NOPMD - unavoidable
@NonNull URI resource,
@NonNull METASCHEMADocument moduleXml,
- @NonNull List importedModules) throws MetaschemaException {
+ @NonNull List extends IMetaschemaModule> importedModules) throws MetaschemaException {
super(importedModules);
this.location = ObjectUtils.requireNonNull(resource, "resource");
Objects.requireNonNull(moduleXml.getMETASCHEMA());
this.module = moduleXml;
- METASCHEMA metaschemaNode = module.getMETASCHEMA();
-
- // handle definitions in this module
- // TODO: switch implementation to use the XmlObjectParser
- {
- // start with flag definitions
- try (XmlCursor cursor = metaschemaNode.newCursor()) {
- cursor.selectPath("declare namespace m='http://csrc.nist.gov/ns/oscal/metaschema/1.0';$this/m:define-flag");
-
- Map flagDefinitions = new LinkedHashMap<>(); // NOPMD - intentional
- while (cursor.toNextSelection()) {
- GlobalFlagDefinitionType obj = ObjectUtils.notNull((GlobalFlagDefinitionType) cursor.getObject());
- XmlGlobalFlagDefinition flag = new XmlGlobalFlagDefinition(obj, this); // NOPMD - intentional
- if (LOGGER.isTraceEnabled()) {
- LOGGER.trace("New flag definition '{}'", flag.toCoordinates());
- }
- flagDefinitions.put(flag.getName(), flag);
- }
- this.flagDefinitions
- = flagDefinitions.isEmpty() ? Collections.emptyMap() : Collections.unmodifiableMap(flagDefinitions);
- }
- }
-
- {
- // now field definitions
- try (XmlCursor cursor = metaschemaNode.newCursor()) {
- cursor.selectPath("declare namespace m='http://csrc.nist.gov/ns/oscal/metaschema/1.0';$this/m:define-field");
-
- Map fieldDefinitions = new LinkedHashMap<>(); // NOPMD - intentional
- while (cursor.toNextSelection()) {
- GlobalFieldDefinitionType obj = ObjectUtils.notNull((GlobalFieldDefinitionType) cursor.getObject());
- XmlGlobalFieldDefinition field = new XmlGlobalFieldDefinition(obj, this); // NOPMD - intentional
- if (LOGGER.isTraceEnabled()) {
- LOGGER.trace("New field definition '{}'", field.toCoordinates());
- }
- fieldDefinitions.put(field.getName(), field);
- }
- this.fieldDefinitions
- = fieldDefinitions.isEmpty() ? Collections.emptyMap() : Collections.unmodifiableMap(fieldDefinitions);
- }
- }
-
- {
- // finally assembly definitions
- Map assemblyDefinitions = new LinkedHashMap<>(); // NOPMD - intentional
- Map rootAssemblyDefinitions = new LinkedHashMap<>(); // NOPMD - intentional
-
- try (XmlCursor cursor = metaschemaNode.newCursor()) {
- cursor.selectPath(
- "declare namespace m='http://csrc.nist.gov/ns/oscal/metaschema/1.0';$this/m:define-assembly");
-
- while (cursor.toNextSelection()) {
- GlobalAssemblyDefinitionType obj = ObjectUtils.notNull((GlobalAssemblyDefinitionType) cursor.getObject());
- XmlGlobalAssemblyDefinition assembly = new XmlGlobalAssemblyDefinition(obj, this); // NOPMD - intentional
- if (LOGGER.isTraceEnabled()) {
- LOGGER.trace("New assembly definition '{}'", assembly.toCoordinates());
- }
- assemblyDefinitions.put(assembly.getName(), assembly);
- if (assembly.isRoot()) {
- rootAssemblyDefinitions.put(ObjectUtils.notNull(assembly.getRootName()), assembly);
- }
- }
-
- this.assemblyDefinitions
- = assemblyDefinitions.isEmpty() ? Collections.emptyMap() : Collections.unmodifiableMap(assemblyDefinitions);
- this.rootAssemblyDefinitions = rootAssemblyDefinitions.isEmpty() ? Collections.emptyMap()
- : Collections.unmodifiableMap(rootAssemblyDefinitions);
- }
- }
+ this.definitions = Lazy.lazy(() -> new Definitions(ObjectUtils.requireNonNull(module.getMETASCHEMA())));
}
@NonNull
@@ -223,34 +155,31 @@ public URI getJsonBaseUri() {
return URI.create(getXmlModule().getJsonBaseUri());
}
- private Map getAssemblyDefinitionMap() {
- return assemblyDefinitions;
+ @NonNull
+ private Definitions getDefinitions() {
+ return ObjectUtils.notNull(definitions.get());
}
@SuppressWarnings("null")
@Override
public Collection getAssemblyDefinitions() {
- return getAssemblyDefinitionMap().values();
+ return getDefinitions().getAssemblyDefinitionMap().values();
}
@Override
- public IAssemblyDefinition getAssemblyDefinitionByName(@NonNull String name) {
- return getAssemblyDefinitionMap().get(name);
- }
-
- private Map getFieldDefinitionMap() {
- return fieldDefinitions;
+ public IAssemblyDefinition getAssemblyDefinitionByName(@NonNull QName name) {
+ return getDefinitions().getAssemblyDefinitionMap().get(name);
}
@SuppressWarnings("null")
@Override
public Collection getFieldDefinitions() {
- return getFieldDefinitionMap().values();
+ return getDefinitions().getFieldDefinitionMap().values();
}
@Override
- public IFieldDefinition getFieldDefinitionByName(@NonNull String name) {
- return getFieldDefinitionMap().get(name);
+ public IFieldDefinition getFieldDefinitionByName(@NonNull QName name) {
+ return getDefinitions().getFieldDefinitionMap().get(name);
}
@SuppressWarnings("null")
@@ -260,28 +189,117 @@ public List getAssemblyAndFieldDefinitions() {
.collect(Collectors.toList());
}
- private Map