From fd8f3331872e843f2f79e392741fc9bd0b18651a Mon Sep 17 00:00:00 2001 From: David Waltermire Date: Tue, 13 Feb 2024 16:54:16 -0500 Subject: [PATCH 1/5] Added bindings for the legacy and new external constraint models. --- .../core/model/IChoiceGroupInstance.java | 4 +- .../core/model/IChoiceInstance.java | 4 +- .../IFeatureDefinitionInstanceInlined.java | 5 +- .../IFeatureDefinitionReferenceInstance.java | 5 +- .../AbstractModelInstanceTypeInfo.java | 10 +- .../model/metaschema/binding/Any.java | 2 +- .../binding/AssemblyConstraints.java | 633 +------------- .../metaschema/binding/AssemblyModel.java | 440 +++++----- .../metaschema/binding/AssemblyReference.java | 12 +- .../binding/ConstraintLetExpression.java | 5 +- .../binding/ConstraintValueEnum.java | 2 +- .../model/metaschema/binding/Example.java | 8 +- .../metaschema/binding/FieldConstraints.java | 6 +- .../metaschema/binding/FieldReference.java | 12 +- .../metaschema/binding/FlagAllowedValues.java | 280 ++++++ .../metaschema/binding/FlagConstraints.java | 824 +----------------- .../model/metaschema/binding/FlagExpect.java | 223 +++++ .../metaschema/binding/FlagIndexHasKey.java | 253 ++++++ .../model/metaschema/binding/FlagMatches.java | 241 +++++ .../metaschema/binding/FlagReference.java | 12 +- .../model/metaschema/binding/GroupAs.java | 5 +- .../binding/InlineDefineAssembly.java | 17 +- .../metaschema/binding/InlineDefineField.java | 17 +- .../metaschema/binding/InlineDefineFlag.java | 14 +- .../model/metaschema/binding/JsonKey.java | 5 +- .../metaschema/binding/JsonValueKeyFlag.java | 5 +- .../binding/KeyConstraintField.java | 5 +- .../model/metaschema/binding/METASCHEMA.java | 385 ++++---- .../metaschema/binding/MetapathContext.java | 135 +++ .../binding/MetaschemaMetaConstraints.java | 262 ++++++ ...Module.java => MetaschemaModelModule.java} | 33 +- .../binding/MetaschemaModuleConstraints.java | 440 ++++++++++ .../model/metaschema/binding/Property.java | 8 +- .../model/metaschema/binding/Remarks.java | 5 +- .../TargetedAllowedValuesConstraint.java | 6 +- .../binding/TargetedExpectConstraint.java | 4 +- .../TargetedHasCardinalityConstraint.java | 244 ++++++ .../binding/TargetedIndexConstraint.java | 270 ++++++ .../TargetedIndexHasKeyConstraint.java | 6 +- .../binding/TargetedIsUniqueConstraint.java | 255 ++++++ .../binding/TargetedMatchesConstraint.java | 4 +- .../model/metaschema/binding/UseName.java | 8 +- .../metaschema/binding/package-info.java | 14 +- .../impl/ConstraintBindingSupport.java | 51 +- 44 files changed, 3188 insertions(+), 1991 deletions(-) create mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagAllowedValues.java create mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagExpect.java create mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagIndexHasKey.java create mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagMatches.java create mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/MetapathContext.java create mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/MetaschemaMetaConstraints.java rename databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/{MetaschemaModule.java => MetaschemaModelModule.java} (81%) create mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/MetaschemaModuleConstraints.java create mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedHasCardinalityConstraint.java create mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedIndexConstraint.java create mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedIsUniqueConstraint.java 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 7e40a1f67..ecc44b7fd 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 @@ -93,9 +93,9 @@ default MarkupMultiline getRemarks() { @SuppressWarnings("null") @Override default String toCoordinates() { - return String.format("%s:%s-instance:%s/%s@%d", - getContainingDefinition().getContainingModule().getShortName(), + return String.format("%s-instance:%s:%s/%s@%d", getModelType().toString().toLowerCase(Locale.ROOT), + getContainingDefinition().getContainingModule().getShortName(), getContainingDefinition().getName(), getGroupAsName(), hashCode()); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IChoiceInstance.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IChoiceInstance.java index a095a2934..f46e09096 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IChoiceInstance.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IChoiceInstance.java @@ -77,9 +77,9 @@ default boolean isEffectiveValueWrappedInXml() { @SuppressWarnings("null") @Override default String toCoordinates() { - return String.format("%s:%s-instance:%s@%d", - getContainingDefinition().getContainingModule().getShortName(), + return String.format("%s-instance:%s:%s@%d", getModelType().toString().toLowerCase(Locale.ROOT), + getContainingDefinition().getContainingModule().getShortName(), getContainingDefinition().getName(), hashCode()); } 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 838d5054b..15c748dbb 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 @@ -103,10 +103,11 @@ default Object getEffectiveDefaultValue() { @Override default String toCoordinates() { IModule module = getContainingModule(); - return String.format("%s:%s-inline-definition:%s@%d", - module.getShortName(), + return String.format("%s-inline-definition:%s:%s/%s@%d", getModelType().toString().toLowerCase(Locale.ROOT), + module.getShortName(), getContainingDefinition().getName(), + getName(), hashCode()); } } 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 21b0bc166..16e54f0ff 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 @@ -123,10 +123,11 @@ default Object getEffectiveDefaultValue() { @Override default String toCoordinates() { IDefinition definition = getDefinition(); - return String.format("%s:%s-instance:%s@%d(%d)", - getContainingDefinition().getContainingModule().getShortName(), + 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/codegen/typeinfo/AbstractModelInstanceTypeInfo.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/typeinfo/AbstractModelInstanceTypeInfo.java index e08830cd6..dfeb9b82c 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/typeinfo/AbstractModelInstanceTypeInfo.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/typeinfo/AbstractModelInstanceTypeInfo.java @@ -61,7 +61,15 @@ protected AbstractModelInstanceTypeInfo( @Override public String getBaseName() { - return ObjectUtils.requireNonNull(getInstance().getGroupAsName()); + INSTANCE instance = getInstance(); + String baseName = getInstance().getGroupAsName(); + if (baseName == null) { + throw new IllegalStateException(String.format( + "Unable to derive the property name, due to missing group as name, for '%s' in the module '%s'.", + instance.toCoordinates(), + instance.getContainingModule().getLocation())); + } + return baseName; } @Override diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/Any.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/Any.java index 84f038c30..981f33c8d 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/Any.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/Any.java @@ -36,7 +36,7 @@ @MetaschemaAssembly( formalName = "Any Additional Content", name = "any", - moduleClass = MetaschemaModule.class) + moduleClass = MetaschemaModelModule.class) public class Any { @Override public String toString() { diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/AssemblyConstraints.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/AssemblyConstraints.java index 2a0d0aaf9..47cf9db51 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/AssemblyConstraints.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/AssemblyConstraints.java @@ -26,32 +26,19 @@ package gov.nist.secauto.metaschema.databind.model.metaschema.binding; -import gov.nist.secauto.metaschema.core.datatype.adapter.NonNegativeIntegerAdapter; -import gov.nist.secauto.metaschema.core.datatype.adapter.StringAdapter; -import gov.nist.secauto.metaschema.core.datatype.adapter.TokenAdapter; -import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine; -import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLineAdapter; import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior; -import gov.nist.secauto.metaschema.core.model.constraint.IConstraint; import gov.nist.secauto.metaschema.core.util.ObjectUtils; -import gov.nist.secauto.metaschema.databind.model.annotations.AllowedValue; -import gov.nist.secauto.metaschema.databind.model.annotations.AllowedValues; import gov.nist.secauto.metaschema.databind.model.annotations.BoundAssembly; import gov.nist.secauto.metaschema.databind.model.annotations.BoundChoiceGroup; -import gov.nist.secauto.metaschema.databind.model.annotations.BoundField; -import gov.nist.secauto.metaschema.databind.model.annotations.BoundFlag; import gov.nist.secauto.metaschema.databind.model.annotations.BoundGroupedAssembly; import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs; -import gov.nist.secauto.metaschema.databind.model.annotations.Matches; import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; -import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints; import gov.nist.secauto.metaschema.databind.model.metaschema.IModelConstraintsBase; import gov.nist.secauto.metaschema.databind.model.metaschema.ITargetedConstraintBase; import org.apache.commons.lang3.builder.ReflectionToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; -import java.math.BigInteger; import java.util.LinkedList; import java.util.List; @@ -62,13 +49,13 @@ }) @MetaschemaAssembly( name = "assembly-constraints", - moduleClass = MetaschemaModule.class) + moduleClass = MetaschemaModelModule.class) public class AssemblyConstraints implements IModelConstraintsBase { @BoundAssembly( formalName = "Constraint Let Expression", useName = "let", maxOccurs = -1, - groupAs = @GroupAs(name = "lets", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "lets", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) private List _lets; @BoundChoiceGroup( @@ -84,12 +71,13 @@ public class AssemblyConstraints implements IModelConstraintsBase { @BoundGroupedAssembly(formalName = "Value Matches Constraint", useName = "matches", binding = TargetedMatchesConstraint.class), @BoundGroupedAssembly(formalName = "Targeted Unique Constraint", useName = "is-unique", - binding = Unique.class), - @BoundGroupedAssembly(formalName = "Targeted Index Constraint", useName = "index", binding = Index.class), + binding = TargetedIsUniqueConstraint.class), + @BoundGroupedAssembly(formalName = "Targeted Index Constraint", useName = "index", + binding = TargetedIndexConstraint.class), @BoundGroupedAssembly(formalName = "Targeted Cardinality Constraint", useName = "has-cardinality", - binding = HasCardinality.class) + binding = TargetedHasCardinalityConstraint.class) }, - groupAs = @GroupAs(name = "rules", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "rules", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) private List _rules; @Override @@ -142,611 +130,4 @@ public void setRules(List value) { public String toString() { return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); } - - @MetaschemaAssembly( - formalName = "Targeted Cardinality Constraint", - name = "has-cardinality", - moduleClass = MetaschemaModule.class) - public static class HasCardinality - implements ITargetedConstraintBase { - @BoundFlag( - formalName = "Constraint Identifier", - name = "id", - typeAdapter = TokenAdapter.class) - private String _id; - - @BoundFlag( - formalName = "Constraint Severity Level", - name = "level", - defaultValue = "ERROR", - typeAdapter = TokenAdapter.class, - valueConstraints = @ValueConstraints(allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, values = { - @AllowedValue(value = "CRITICAL", - description = "A violation of the constraint represents a serious fault in the content that will prevent typical use of the content."), - @AllowedValue(value = "ERROR", - description = "A violation of the constraint represents a fault in the content. This may include issues around compatibility, integrity, consistency, etc."), - @AllowedValue(value = "WARNING", - description = "A violation of the constraint represents a potential issue with the content."), - @AllowedValue(value = "INFORMATIONAL", - description = "A violation of the constraint represents a point of interest.") }))) - private String _level; - - @BoundFlag( - formalName = "Minimum Occurrence", - name = "min-occurs", - typeAdapter = NonNegativeIntegerAdapter.class) - private BigInteger _minOccurs; - - @BoundFlag( - formalName = "Maximum Occurrence", - name = "max-occurs", - typeAdapter = StringAdapter.class, - valueConstraints = @ValueConstraints( - matches = @Matches(level = IConstraint.Level.ERROR, pattern = "^[1-9][0-9]*|unbounded$"))) - private String _maxOccurs; - - @BoundFlag( - formalName = "Constraint Target Metapath Expression", - name = "target", - required = true, - typeAdapter = StringAdapter.class) - private String _target; - - @BoundField( - formalName = "Formal Name", - description = "A formal name for the data construct, to be presented in documentation.", - useName = "formal-name") - private String _formalName; - - @BoundField( - formalName = "Description", - description = "A short description of the data construct's purpose, describing the constructs semantics.", - useName = "description", - typeAdapter = MarkupLineAdapter.class) - private MarkupLine _description; - - @BoundAssembly( - formalName = "Property", - useName = "prop", - maxOccurs = -1, - groupAs = @GroupAs(name = "props", inJson = JsonGroupAsBehavior.LIST)) - private List _props; - - @BoundField( - formalName = "Remarks", - description = "Any explanatory or helpful information to be provided about the remarks parent.", - useName = "remarks") - private Remarks _remarks; - - @Override - public String getId() { - return _id; - } - - public void setId(String value) { - _id = value; - } - - @Override - public String getLevel() { - return _level; - } - - public void setLevel(String value) { - _level = value; - } - - public BigInteger getMinOccurs() { - return _minOccurs; - } - - public void setMinOccurs(BigInteger value) { - _minOccurs = value; - } - - public String getMaxOccurs() { - return _maxOccurs; - } - - public void setMaxOccurs(String value) { - _maxOccurs = value; - } - - @Override - public String getTarget() { - return _target; - } - - public void setTarget(String value) { - _target = value; - } - - @Override - public String getFormalName() { - return _formalName; - } - - public void setFormalName(String value) { - _formalName = value; - } - - @Override - public MarkupLine getDescription() { - return _description; - } - - public void setDescription(MarkupLine value) { - _description = value; - } - - @Override - public List getProps() { - return _props; - } - - public void setProps(List value) { - _props = value; - } - - /** - * Add a new {@link Property} item to the underlying collection. - * - * @param item - * the item to add - * @return {@code true} - */ - public boolean addProp(Property item) { - Property value = ObjectUtils.requireNonNull(item, "item cannot be null"); - if (_props == null) { - _props = new LinkedList<>(); - } - return _props.add(value); - } - - /** - * Remove the first matching {@link Property} item from the underlying - * collection. - * - * @param item - * the item to remove - * @return {@code true} if the item was removed or {@code false} otherwise - */ - public boolean removeProp(Property item) { - Property value = ObjectUtils.requireNonNull(item, "item cannot be null"); - return _props != null && _props.remove(value); - } - - @Override - public Remarks getRemarks() { - return _remarks; - } - - public void setRemarks(Remarks value) { - _remarks = value; - } - - @Override - public String toString() { - return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); - } - } - - @MetaschemaAssembly( - formalName = "Targeted Index Constraint", - name = "index", - moduleClass = MetaschemaModule.class) - public static class Index - implements ITargetedConstraintBase { - @BoundFlag( - formalName = "Constraint Identifier", - name = "id", - typeAdapter = TokenAdapter.class) - private String _id; - - @BoundFlag( - formalName = "Constraint Severity Level", - name = "level", - defaultValue = "ERROR", - typeAdapter = TokenAdapter.class, - valueConstraints = @ValueConstraints(allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, values = { - @AllowedValue(value = "CRITICAL", - description = "A violation of the constraint represents a serious fault in the content that will prevent typical use of the content."), - @AllowedValue(value = "ERROR", - description = "A violation of the constraint represents a fault in the content. This may include issues around compatibility, integrity, consistency, etc."), - @AllowedValue(value = "WARNING", - description = "A violation of the constraint represents a potential issue with the content."), - @AllowedValue(value = "INFORMATIONAL", - description = "A violation of the constraint represents a point of interest.") }))) - private String _level; - - @BoundFlag( - formalName = "Index Name", - name = "name", - required = true, - typeAdapter = TokenAdapter.class) - private String _name; - - @BoundFlag( - formalName = "Constraint Target Metapath Expression", - name = "target", - required = true, - typeAdapter = StringAdapter.class) - private String _target; - - @BoundField( - formalName = "Formal Name", - description = "A formal name for the data construct, to be presented in documentation.", - useName = "formal-name") - private String _formalName; - - @BoundField( - formalName = "Description", - description = "A short description of the data construct's purpose, describing the constructs semantics.", - useName = "description", - typeAdapter = MarkupLineAdapter.class) - private MarkupLine _description; - - @BoundAssembly( - formalName = "Property", - useName = "prop", - maxOccurs = -1, - groupAs = @GroupAs(name = "props", inJson = JsonGroupAsBehavior.LIST)) - private List _props; - - @BoundAssembly( - formalName = "Key Constraint Field", - useName = "key-field", - minOccurs = 1, - maxOccurs = -1, - groupAs = @GroupAs(name = "key-fields", inJson = JsonGroupAsBehavior.LIST)) - private List _keyFields; - - @BoundField( - formalName = "Remarks", - description = "Any explanatory or helpful information to be provided about the remarks parent.", - useName = "remarks") - private Remarks _remarks; - - @Override - public String getId() { - return _id; - } - - public void setId(String value) { - _id = value; - } - - @Override - public String getLevel() { - return _level; - } - - public void setLevel(String value) { - _level = value; - } - - public String getName() { - return _name; - } - - public void setName(String value) { - _name = value; - } - - @Override - public String getTarget() { - return _target; - } - - public void setTarget(String value) { - _target = value; - } - - @Override - public String getFormalName() { - return _formalName; - } - - public void setFormalName(String value) { - _formalName = value; - } - - @Override - public MarkupLine getDescription() { - return _description; - } - - public void setDescription(MarkupLine value) { - _description = value; - } - - @Override - public List getProps() { - return _props; - } - - public void setProps(List value) { - _props = value; - } - - /** - * Add a new {@link Property} item to the underlying collection. - * - * @param item - * the item to add - * @return {@code true} - */ - public boolean addProp(Property item) { - Property value = ObjectUtils.requireNonNull(item, "item cannot be null"); - if (_props == null) { - _props = new LinkedList<>(); - } - return _props.add(value); - } - - /** - * Remove the first matching {@link Property} item from the underlying - * collection. - * - * @param item - * the item to remove - * @return {@code true} if the item was removed or {@code false} otherwise - */ - public boolean removeProp(Property item) { - Property value = ObjectUtils.requireNonNull(item, "item cannot be null"); - return _props != null && _props.remove(value); - } - - public List getKeyFields() { - return _keyFields; - } - - public void setKeyFields(List value) { - _keyFields = value; - } - - /** - * Add a new {@link KeyConstraintField} item to the underlying collection. - * - * @param item - * the item to add - * @return {@code true} - */ - public boolean addKeyField(KeyConstraintField item) { - KeyConstraintField value = ObjectUtils.requireNonNull(item, "item cannot be null"); - if (_keyFields == null) { - _keyFields = new LinkedList<>(); - } - return _keyFields.add(value); - } - - /** - * Remove the first matching {@link KeyConstraintField} item from the underlying - * collection. - * - * @param item - * the item to remove - * @return {@code true} if the item was removed or {@code false} otherwise - */ - public boolean removeKeyField(KeyConstraintField item) { - KeyConstraintField value = ObjectUtils.requireNonNull(item, "item cannot be null"); - return _keyFields != null && _keyFields.remove(value); - } - - @Override - public Remarks getRemarks() { - return _remarks; - } - - public void setRemarks(Remarks value) { - _remarks = value; - } - - @Override - public String toString() { - return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); - } - } - - @MetaschemaAssembly( - formalName = "Targeted Unique Constraint", - name = "unique", - moduleClass = MetaschemaModule.class) - public static class Unique - implements ITargetedConstraintBase { - @BoundFlag( - formalName = "Constraint Identifier", - name = "id", - typeAdapter = TokenAdapter.class) - private String _id; - - @BoundFlag( - formalName = "Constraint Severity Level", - name = "level", - defaultValue = "ERROR", - typeAdapter = TokenAdapter.class, - valueConstraints = @ValueConstraints(allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, values = { - @AllowedValue(value = "CRITICAL", - description = "A violation of the constraint represents a serious fault in the content that will prevent typical use of the content."), - @AllowedValue(value = "ERROR", - description = "A violation of the constraint represents a fault in the content. This may include issues around compatibility, integrity, consistency, etc."), - @AllowedValue(value = "WARNING", - description = "A violation of the constraint represents a potential issue with the content."), - @AllowedValue(value = "INFORMATIONAL", - description = "A violation of the constraint represents a point of interest.") }))) - private String _level; - - @BoundFlag( - formalName = "Constraint Target Metapath Expression", - name = "target", - required = true, - typeAdapter = StringAdapter.class) - private String _target; - - @BoundField( - formalName = "Formal Name", - description = "A formal name for the data construct, to be presented in documentation.", - useName = "formal-name") - private String _formalName; - - @BoundField( - formalName = "Description", - description = "A short description of the data construct's purpose, describing the constructs semantics.", - useName = "description", - typeAdapter = MarkupLineAdapter.class) - private MarkupLine _description; - - @BoundAssembly( - formalName = "Property", - useName = "prop", - maxOccurs = -1, - groupAs = @GroupAs(name = "props", inJson = JsonGroupAsBehavior.LIST)) - private List _props; - - @BoundAssembly( - formalName = "Key Constraint Field", - useName = "key-field", - minOccurs = 1, - maxOccurs = -1, - groupAs = @GroupAs(name = "key-fields", inJson = JsonGroupAsBehavior.LIST)) - private List _keyFields; - - @BoundField( - formalName = "Remarks", - description = "Any explanatory or helpful information to be provided about the remarks parent.", - useName = "remarks") - private Remarks _remarks; - - @Override - public String getId() { - return _id; - } - - public void setId(String value) { - _id = value; - } - - @Override - public String getLevel() { - return _level; - } - - public void setLevel(String value) { - _level = value; - } - - @Override - public String getTarget() { - return _target; - } - - public void setTarget(String value) { - _target = value; - } - - @Override - public String getFormalName() { - return _formalName; - } - - public void setFormalName(String value) { - _formalName = value; - } - - @Override - public MarkupLine getDescription() { - return _description; - } - - public void setDescription(MarkupLine value) { - _description = value; - } - - @Override - public List getProps() { - return _props; - } - - public void setProps(List value) { - _props = value; - } - - /** - * Add a new {@link Property} item to the underlying collection. - * - * @param item - * the item to add - * @return {@code true} - */ - public boolean addProp(Property item) { - Property value = ObjectUtils.requireNonNull(item, "item cannot be null"); - if (_props == null) { - _props = new LinkedList<>(); - } - return _props.add(value); - } - - /** - * Remove the first matching {@link Property} item from the underlying - * collection. - * - * @param item - * the item to remove - * @return {@code true} if the item was removed or {@code false} otherwise - */ - public boolean removeProp(Property item) { - Property value = ObjectUtils.requireNonNull(item, "item cannot be null"); - return _props != null && _props.remove(value); - } - - public List getKeyFields() { - return _keyFields; - } - - public void setKeyFields(List value) { - _keyFields = value; - } - - /** - * Add a new {@link KeyConstraintField} item to the underlying collection. - * - * @param item - * the item to add - * @return {@code true} - */ - public boolean addKeyField(KeyConstraintField item) { - KeyConstraintField value = ObjectUtils.requireNonNull(item, "item cannot be null"); - if (_keyFields == null) { - _keyFields = new LinkedList<>(); - } - return _keyFields.add(value); - } - - /** - * Remove the first matching {@link KeyConstraintField} item from the underlying - * collection. - * - * @param item - * the item to remove - * @return {@code true} if the item was removed or {@code false} otherwise - */ - public boolean removeKeyField(KeyConstraintField item) { - KeyConstraintField value = ObjectUtils.requireNonNull(item, "item cannot be null"); - return _keyFields != null && _keyFields.remove(value); - } - - @Override - public Remarks getRemarks() { - return _remarks; - } - - public void setRemarks(Remarks value) { - _remarks = value; - } - - @Override - public String toString() { - return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); - } - } } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/AssemblyModel.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/AssemblyModel.java index b812c7994..c1f4df539 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/AssemblyModel.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/AssemblyModel.java @@ -61,7 +61,7 @@ }) @MetaschemaAssembly( name = "assembly-model", - moduleClass = MetaschemaModule.class) + moduleClass = MetaschemaModelModule.class) public class AssemblyModel { @BoundChoiceGroup( maxOccurs = -1, @@ -77,7 +77,7 @@ public class AssemblyModel { @BoundGroupedAssembly(formalName = "Choice Grouping", useName = "choice-group", binding = ChoiceGroup.class) }, groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "instances", - inJson = JsonGroupAsBehavior.LIST)) + namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) private List _instances; @BoundAssembly( @@ -106,58 +106,10 @@ public String toString() { return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); } - @MetaschemaAssembly( - formalName = "Choice", - name = "choice", - moduleClass = MetaschemaModule.class) - public static class Choice { - @BoundChoiceGroup( - minOccurs = 1, - maxOccurs = -1, - assemblies = { - @BoundGroupedAssembly(formalName = "Assembly Reference", useName = "assembly", - binding = AssemblyReference.class), - @BoundGroupedAssembly(formalName = "Inline Assembly Definition", useName = "define-assembly", - binding = InlineDefineAssembly.class), - @BoundGroupedAssembly(formalName = "Field Reference", useName = "field", binding = FieldReference.class), - @BoundGroupedAssembly(formalName = "Inline Field Definition", useName = "define-field", - binding = InlineDefineField.class) - }, - groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "choices", - inJson = JsonGroupAsBehavior.LIST)) - private List _choices; - - @BoundAssembly( - formalName = "Any Additional Content", - useName = "any") - private Any _any; - - public List getChoices() { - return _choices; - } - - public void setChoices(List value) { - _choices = value; - } - - public Any getAny() { - return _any; - } - - public void setAny(Any value) { - _any = value; - } - - @Override - public String toString() { - return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); - } - } - @MetaschemaAssembly( formalName = "Choice Grouping", name = "choice-group", - moduleClass = MetaschemaModule.class) + moduleClass = MetaschemaModelModule.class) public static class ChoiceGroup { @BoundFlag( formalName = "Minimum Occurrence", @@ -207,7 +159,7 @@ public static class ChoiceGroup { binding = DefineField.class) }, groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "choices", - inJson = JsonGroupAsBehavior.LIST)) + namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) private List _choices; @BoundField( @@ -280,7 +232,7 @@ public String toString() { @MetaschemaAssembly( formalName = "Grouping Assembly Reference", name = "assembly", - moduleClass = MetaschemaModule.class) + moduleClass = MetaschemaModelModule.class) public static class Assembly { @BoundFlag( formalName = "Global Assembly Reference", @@ -319,7 +271,7 @@ public static class Assembly { useName = "prop", maxOccurs = -1, groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "props", - inJson = JsonGroupAsBehavior.LIST)) + namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) private List _props; @BoundField( @@ -447,19 +399,19 @@ public String toString() { } @MetaschemaAssembly( - formalName = "Grouping Field Reference", - name = "field", - moduleClass = MetaschemaModule.class) - public static class Field { + formalName = "Inline Assembly Definition", + name = "define-assembly", + moduleClass = MetaschemaModelModule.class) + public static class DefineAssembly { @BoundFlag( - formalName = "Global Field Reference", - name = "ref", + formalName = "Inline Assembly Name", + name = "name", required = true, typeAdapter = TokenAdapter.class) - private String _ref; + private String _name; @BoundFlag( - formalName = "Field Reference Binary Name", + formalName = "Inline Assembly Binary Name", name = "index", typeAdapter = PositiveIntegerAdapter.class) private BigInteger _index; @@ -470,25 +422,6 @@ public static class Field { typeAdapter = StringAdapter.class) private String _deprecated; - @BoundFlag( - formalName = "Default Field Value", - name = "default", - typeAdapter = StringAdapter.class) - private String _default; - - @BoundFlag( - formalName = "Field In XML", - name = "in-xml", - defaultValue = "WRAPPED", - typeAdapter = TokenAdapter.class, - valueConstraints = @ValueConstraints(allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, - values = { @AllowedValue(value = "WRAPPED", - description = "Block contents of a markup-multiline field will be represented with a containing (wrapper) element in the XML."), - @AllowedValue(value = "UNWRAPPED", - description = "Block contents of a markup-multiline will be represented in the XML with no wrapper, making the field implicit. Among sibling fields in a given model, only one of them may be designated as UNWRAPPED."), - @AllowedValue(value = "WITH_WRAPPER", description = "Alias for WRAPPED.") }))) - private String _inXml; - @BoundField( formalName = "Formal Name", description = "A formal name for the data construct, to be presented in documentation.", @@ -507,33 +440,54 @@ public static class Field { useName = "prop", maxOccurs = -1, groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "props", - inJson = JsonGroupAsBehavior.LIST)) + namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) private List _props; - @BoundField( - formalName = "Use Name", - description = "Allows the name of the definition to be overridden.", - useName = "use-name") - private UseName _useName; - @BoundField( formalName = "Grouping Discriminator Value", useName = "discriminator-value", typeAdapter = TokenAdapter.class) private String _discriminatorValue; + @BoundChoiceGroup( + maxOccurs = -1, + assemblies = { + @BoundGroupedAssembly(formalName = "Inline Flag Definition", useName = "define-flag", + binding = InlineDefineFlag.class), + @BoundGroupedAssembly(formalName = "Flag Reference", useName = "flag", binding = FlagReference.class) + }, + groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "flags", + namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + private List _flags; + + @BoundAssembly( + useName = "model") + private AssemblyModel _model; + + @BoundAssembly( + useName = "constraint") + private AssemblyConstraints _constraint; + @BoundField( formalName = "Remarks", description = "Any explanatory or helpful information to be provided about the remarks parent.", useName = "remarks") private Remarks _remarks; - public String getRef() { - return _ref; + @BoundAssembly( + formalName = "Example", + useName = "example", + maxOccurs = -1, + groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "examples", + namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + private List _examples; + + public String getName() { + return _name; } - public void setRef(String value) { - _ref = value; + public void setName(String value) { + _name = value; } public BigInteger getIndex() { @@ -552,22 +506,6 @@ public void setDeprecated(String value) { _deprecated = value; } - public String getDefault() { - return _default; - } - - public void setDefault(String value) { - _default = value; - } - - public String getInXml() { - return _inXml; - } - - public void setInXml(String value) { - _inXml = value; - } - public String getFormalName() { return _formalName; } @@ -620,14 +558,6 @@ public boolean removeProp(Property item) { return _props != null && _props.remove(value); } - public UseName getUseName() { - return _useName; - } - - public void setUseName(UseName value) { - _useName = value; - } - public String getDiscriminatorValue() { return _discriminatorValue; } @@ -636,6 +566,30 @@ public void setDiscriminatorValue(String value) { _discriminatorValue = value; } + public List getFlags() { + return _flags; + } + + public void setFlags(List value) { + _flags = value; + } + + public AssemblyModel getModel() { + return _model; + } + + public void setModel(AssemblyModel value) { + _model = value; + } + + public AssemblyConstraints getConstraint() { + return _constraint; + } + + public void setConstraint(AssemblyConstraints value) { + _constraint = value; + } + public Remarks getRemarks() { return _remarks; } @@ -644,6 +598,42 @@ public void setRemarks(Remarks value) { _remarks = value; } + public List getExamples() { + return _examples; + } + + public void setExamples(List value) { + _examples = value; + } + + /** + * Add a new {@link Example} item to the underlying collection. + * + * @param item + * the item to add + * @return {@code true} + */ + public boolean addExample(Example item) { + Example value = ObjectUtils.requireNonNull(item, "item cannot be null"); + if (_examples == null) { + _examples = new LinkedList<>(); + } + return _examples.add(value); + } + + /** + * Remove the first matching {@link Example} item from the underlying + * collection. + * + * @param item + * the item to remove + * @return {@code true} if the item was removed or {@code false} otherwise + */ + public boolean removeExample(Example item) { + Example value = ObjectUtils.requireNonNull(item, "item cannot be null"); + return _examples != null && _examples.remove(value); + } + @Override public String toString() { return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); @@ -651,19 +641,19 @@ public String toString() { } @MetaschemaAssembly( - formalName = "Inline Assembly Definition", - name = "define-assembly", - moduleClass = MetaschemaModule.class) - public static class DefineAssembly { + formalName = "Grouping Field Reference", + name = "field", + moduleClass = MetaschemaModelModule.class) + public static class Field { @BoundFlag( - formalName = "Inline Assembly Name", - name = "name", + formalName = "Global Field Reference", + name = "ref", required = true, typeAdapter = TokenAdapter.class) - private String _name; + private String _ref; @BoundFlag( - formalName = "Inline Assembly Binary Name", + formalName = "Field Reference Binary Name", name = "index", typeAdapter = PositiveIntegerAdapter.class) private BigInteger _index; @@ -674,6 +664,25 @@ public static class DefineAssembly { typeAdapter = StringAdapter.class) private String _deprecated; + @BoundFlag( + formalName = "Default Field Value", + name = "default", + typeAdapter = StringAdapter.class) + private String _default; + + @BoundFlag( + formalName = "Field In XML", + name = "in-xml", + defaultValue = "WRAPPED", + typeAdapter = TokenAdapter.class, + valueConstraints = @ValueConstraints(allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, + values = { @AllowedValue(value = "WRAPPED", + description = "Block contents of a markup-multiline field will be represented with a containing (wrapper) element in the XML."), + @AllowedValue(value = "UNWRAPPED", + description = "Block contents of a markup-multiline will be represented in the XML with no wrapper, making the field implicit. Among sibling fields in a given model, only one of them may be designated as UNWRAPPED."), + @AllowedValue(value = "WITH_WRAPPER", description = "Alias for WRAPPED.") }))) + private String _inXml; + @BoundField( formalName = "Formal Name", description = "A formal name for the data construct, to be presented in documentation.", @@ -692,54 +701,33 @@ public static class DefineAssembly { useName = "prop", maxOccurs = -1, groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "props", - inJson = JsonGroupAsBehavior.LIST)) + namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) private List _props; + @BoundField( + formalName = "Use Name", + description = "Allows the name of the definition to be overridden.", + useName = "use-name") + private UseName _useName; + @BoundField( formalName = "Grouping Discriminator Value", useName = "discriminator-value", typeAdapter = TokenAdapter.class) private String _discriminatorValue; - @BoundChoiceGroup( - maxOccurs = -1, - assemblies = { - @BoundGroupedAssembly(formalName = "Inline Flag Definition", useName = "define-flag", - binding = InlineDefineFlag.class), - @BoundGroupedAssembly(formalName = "Flag Reference", useName = "flag", binding = FlagReference.class) - }, - groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "flags", - inJson = JsonGroupAsBehavior.LIST)) - private List _flags; - - @BoundAssembly( - useName = "model") - private AssemblyModel _model; - - @BoundAssembly( - useName = "constraint") - private AssemblyConstraints _constraint; - @BoundField( formalName = "Remarks", description = "Any explanatory or helpful information to be provided about the remarks parent.", useName = "remarks") private Remarks _remarks; - @BoundAssembly( - formalName = "Example", - useName = "example", - maxOccurs = -1, - groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "examples", - inJson = JsonGroupAsBehavior.LIST)) - private List _examples; - - public String getName() { - return _name; + public String getRef() { + return _ref; } - public void setName(String value) { - _name = value; + public void setRef(String value) { + _ref = value; } public BigInteger getIndex() { @@ -758,6 +746,22 @@ public void setDeprecated(String value) { _deprecated = value; } + public String getDefault() { + return _default; + } + + public void setDefault(String value) { + _default = value; + } + + public String getInXml() { + return _inXml; + } + + public void setInXml(String value) { + _inXml = value; + } + public String getFormalName() { return _formalName; } @@ -810,36 +814,20 @@ public boolean removeProp(Property item) { return _props != null && _props.remove(value); } - public String getDiscriminatorValue() { - return _discriminatorValue; - } - - public void setDiscriminatorValue(String value) { - _discriminatorValue = value; - } - - public List getFlags() { - return _flags; - } - - public void setFlags(List value) { - _flags = value; - } - - public AssemblyModel getModel() { - return _model; + public UseName getUseName() { + return _useName; } - public void setModel(AssemblyModel value) { - _model = value; + public void setUseName(UseName value) { + _useName = value; } - public AssemblyConstraints getConstraint() { - return _constraint; + public String getDiscriminatorValue() { + return _discriminatorValue; } - public void setConstraint(AssemblyConstraints value) { - _constraint = value; + public void setDiscriminatorValue(String value) { + _discriminatorValue = value; } public Remarks getRemarks() { @@ -850,42 +838,6 @@ public void setRemarks(Remarks value) { _remarks = value; } - public List getExamples() { - return _examples; - } - - public void setExamples(List value) { - _examples = value; - } - - /** - * Add a new {@link Example} item to the underlying collection. - * - * @param item - * the item to add - * @return {@code true} - */ - public boolean addExample(Example item) { - Example value = ObjectUtils.requireNonNull(item, "item cannot be null"); - if (_examples == null) { - _examples = new LinkedList<>(); - } - return _examples.add(value); - } - - /** - * Remove the first matching {@link Example} item from the underlying - * collection. - * - * @param item - * the item to remove - * @return {@code true} if the item was removed or {@code false} otherwise - */ - public boolean removeExample(Example item) { - Example value = ObjectUtils.requireNonNull(item, "item cannot be null"); - return _examples != null && _examples.remove(value); - } - @Override public String toString() { return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); @@ -895,7 +847,7 @@ public String toString() { @MetaschemaAssembly( formalName = "Inline Field Definition", name = "define-field", - moduleClass = MetaschemaModule.class) + moduleClass = MetaschemaModelModule.class) public static class DefineField { @BoundFlag( formalName = "Inline Field Name", @@ -968,7 +920,7 @@ public static class DefineField { useName = "prop", maxOccurs = -1, groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "props", - inJson = JsonGroupAsBehavior.LIST)) + namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) private List _props; @BoundField( @@ -996,7 +948,7 @@ public static class DefineField { @BoundGroupedAssembly(formalName = "Flag Reference", useName = "flag", binding = FlagReference.class) }, groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "flags", - inJson = JsonGroupAsBehavior.LIST)) + namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) private List _flags; @BoundAssembly( @@ -1014,7 +966,7 @@ public static class DefineField { useName = "example", maxOccurs = -1, groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "examples", - inJson = JsonGroupAsBehavior.LIST)) + namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) private List _examples; public String getName() { @@ -1199,4 +1151,52 @@ public String toString() { } } } + + @MetaschemaAssembly( + formalName = "Choice", + name = "choice", + moduleClass = MetaschemaModelModule.class) + public static class Choice { + @BoundChoiceGroup( + minOccurs = 1, + maxOccurs = -1, + assemblies = { + @BoundGroupedAssembly(formalName = "Assembly Reference", useName = "assembly", + binding = AssemblyReference.class), + @BoundGroupedAssembly(formalName = "Inline Assembly Definition", useName = "define-assembly", + binding = InlineDefineAssembly.class), + @BoundGroupedAssembly(formalName = "Field Reference", useName = "field", binding = FieldReference.class), + @BoundGroupedAssembly(formalName = "Inline Field Definition", useName = "define-field", + binding = InlineDefineField.class) + }, + groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "choices", + namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + private List _choices; + + @BoundAssembly( + formalName = "Any Additional Content", + useName = "any") + private Any _any; + + public List getChoices() { + return _choices; + } + + public void setChoices(List value) { + _choices = value; + } + + public Any getAny() { + return _any; + } + + public void setAny(Any value) { + _any = value; + } + + @Override + public String toString() { + return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); + } + } } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/AssemblyReference.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/AssemblyReference.java index ad0efd510..5b1acc190 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/AssemblyReference.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/AssemblyReference.java @@ -41,13 +41,13 @@ import gov.nist.secauto.metaschema.databind.model.annotations.Matches; import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints; - -import org.apache.commons.lang3.builder.ReflectionToStringBuilder; -import org.apache.commons.lang3.builder.ToStringStyle; - +import java.lang.Override; +import java.lang.String; import java.math.BigInteger; import java.util.LinkedList; import java.util.List; +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; @SuppressWarnings({ "PMD.DataClass", @@ -56,7 +56,7 @@ @MetaschemaAssembly( formalName = "Assembly Reference", name = "assembly-reference", - moduleClass = MetaschemaModule.class) + moduleClass = MetaschemaModelModule.class) public class AssemblyReference { @BoundFlag( formalName = "Global Assembly Reference", @@ -110,7 +110,7 @@ public class AssemblyReference { formalName = "Property", useName = "prop", maxOccurs = -1, - groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "props", + groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "props", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) private List _props; diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/ConstraintLetExpression.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/ConstraintLetExpression.java index 5720d73a3..b003a8f0d 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/ConstraintLetExpression.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/ConstraintLetExpression.java @@ -31,7 +31,8 @@ import gov.nist.secauto.metaschema.databind.model.annotations.BoundField; import gov.nist.secauto.metaschema.databind.model.annotations.BoundFlag; import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; - +import java.lang.Override; +import java.lang.String; import org.apache.commons.lang3.builder.ReflectionToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; @@ -42,7 +43,7 @@ @MetaschemaAssembly( formalName = "Constraint Let Expression", name = "constraint-let-expression", - moduleClass = MetaschemaModule.class) + moduleClass = MetaschemaModelModule.class) public class ConstraintLetExpression { @BoundFlag( formalName = "Let Variable Name", diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/ConstraintValueEnum.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/ConstraintValueEnum.java index 19d75e01d..fdc41079e 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/ConstraintValueEnum.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/ConstraintValueEnum.java @@ -45,7 +45,7 @@ @MetaschemaField( formalName = "Allowed Value Enumeration", name = "constraint-value-enum", - moduleClass = MetaschemaModule.class) + moduleClass = MetaschemaModelModule.class) public class ConstraintValueEnum extends AbstractAllowedValue { @BoundFlag( diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/Example.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/Example.java index 432bb0c53..0d5c9567e 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/Example.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/Example.java @@ -33,12 +33,12 @@ import gov.nist.secauto.metaschema.databind.model.annotations.BoundField; import gov.nist.secauto.metaschema.databind.model.annotations.BoundFlag; import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; - +import java.lang.Override; +import java.lang.String; +import java.net.URI; import org.apache.commons.lang3.builder.ReflectionToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; -import java.net.URI; - @SuppressWarnings({ "PMD.DataClass", "PMD.FieldNamingConventions" @@ -46,7 +46,7 @@ @MetaschemaAssembly( formalName = "Example", name = "example", - moduleClass = MetaschemaModule.class) + moduleClass = MetaschemaModelModule.class) public class Example { @BoundFlag( formalName = "Example Reference", diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FieldConstraints.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FieldConstraints.java index 9359aa57c..469a616e9 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FieldConstraints.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FieldConstraints.java @@ -48,13 +48,13 @@ }) @MetaschemaAssembly( name = "field-constraints", - moduleClass = MetaschemaModule.class) + moduleClass = MetaschemaModelModule.class) public class FieldConstraints implements IValueConstraintsBase { @BoundAssembly( formalName = "Constraint Let Expression", useName = "let", maxOccurs = -1, - groupAs = @GroupAs(name = "lets", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "lets", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) private List _lets; @BoundChoiceGroup( @@ -70,7 +70,7 @@ public class FieldConstraints implements IValueConstraintsBase { @BoundGroupedAssembly(formalName = "Value Matches Constraint", useName = "matches", binding = TargetedMatchesConstraint.class) }, - groupAs = @GroupAs(name = "rules", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "rules", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) private List _rules; @Override diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FieldReference.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FieldReference.java index 64e075269..0cbff61d7 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FieldReference.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FieldReference.java @@ -43,13 +43,13 @@ import gov.nist.secauto.metaschema.databind.model.annotations.Matches; import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints; - -import org.apache.commons.lang3.builder.ReflectionToStringBuilder; -import org.apache.commons.lang3.builder.ToStringStyle; - +import java.lang.Override; +import java.lang.String; import java.math.BigInteger; import java.util.LinkedList; import java.util.List; +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; @SuppressWarnings({ "PMD.DataClass", @@ -58,7 +58,7 @@ @MetaschemaAssembly( formalName = "Field Reference", name = "field-reference", - moduleClass = MetaschemaModule.class) + moduleClass = MetaschemaModelModule.class) public class FieldReference { @BoundFlag( formalName = "Global Field Reference", @@ -131,7 +131,7 @@ public class FieldReference { formalName = "Property", useName = "prop", maxOccurs = -1, - groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "props", + groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "props", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) private List _props; diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagAllowedValues.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagAllowedValues.java new file mode 100644 index 000000000..c1091c614 --- /dev/null +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagAllowedValues.java @@ -0,0 +1,280 @@ +/* + * 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.databind.model.metaschema.binding; + +import gov.nist.secauto.metaschema.core.datatype.adapter.TokenAdapter; +import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine; +import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLineAdapter; +import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior; +import gov.nist.secauto.metaschema.core.model.constraint.IConstraint; +import gov.nist.secauto.metaschema.core.util.ObjectUtils; +import gov.nist.secauto.metaschema.databind.model.annotations.AllowedValue; +import gov.nist.secauto.metaschema.databind.model.annotations.AllowedValues; +import gov.nist.secauto.metaschema.databind.model.annotations.BoundAssembly; +import gov.nist.secauto.metaschema.databind.model.annotations.BoundField; +import gov.nist.secauto.metaschema.databind.model.annotations.BoundFlag; +import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs; +import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; +import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints; +import gov.nist.secauto.metaschema.databind.model.metaschema.IConstraintBase; + +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import java.util.LinkedList; +import java.util.List; + +@SuppressWarnings({ + "PMD.DataClass", + "PMD.FieldNamingConventions" +}) +@MetaschemaAssembly( + formalName = "Allowed Values Constraint", + name = "flag-allowed-values", + moduleClass = MetaschemaModelModule.class) +public class FlagAllowedValues implements IConstraintBase { + @BoundFlag( + formalName = "Constraint Identifier", + name = "id", + typeAdapter = TokenAdapter.class) + private String _id; + + @BoundFlag( + formalName = "Constraint Severity Level", + name = "level", + defaultValue = "ERROR", + typeAdapter = TokenAdapter.class, + valueConstraints = @ValueConstraints(allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, values = { + @AllowedValue(value = "CRITICAL", + description = "A violation of the constraint represents a serious fault in the content that will prevent typical use of the content."), + @AllowedValue(value = "ERROR", + description = "A violation of the constraint represents a fault in the content. This may include issues around compatibility, integrity, consistency, etc."), + @AllowedValue(value = "WARNING", + description = "A violation of the constraint represents a potential issue with the content."), + @AllowedValue(value = "INFORMATIONAL", + description = "A violation of the constraint represents a point of interest.") }))) + private String _level; + + @BoundFlag( + formalName = "Allow Non-Enumerated Values?", + name = "allow-other", + defaultValue = "no", + typeAdapter = TokenAdapter.class, + valueConstraints = @ValueConstraints(allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, + values = { @AllowedValue(value = "no", description = ""), @AllowedValue(value = "yes", description = "") }))) + private String _allowOther; + + /** + * "Determines if the given enumerated values may be extended by other allowed + * value constraints." + */ + @BoundFlag( + formalName = "Allow Extension?", + description = "Determines if the given enumerated values may be extended by other allowed value constraints.", + name = "extensible", + defaultValue = "external", + typeAdapter = TokenAdapter.class, + valueConstraints = @ValueConstraints(allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, + values = { + @AllowedValue(value = "model", description = "Can be extended by constraints within the same module."), + @AllowedValue(value = "external", description = "Can be extended by external constraints."), + @AllowedValue(value = "none", description = "Cannot be extended.") }))) + private String _extensible; + + @BoundField( + formalName = "Formal Name", + description = "A formal name for the data construct, to be presented in documentation.", + useName = "formal-name") + private String _formalName; + + @BoundField( + formalName = "Description", + description = "A short description of the data construct's purpose, describing the constructs semantics.", + useName = "description", + typeAdapter = MarkupLineAdapter.class) + private MarkupLine _description; + + @BoundAssembly( + formalName = "Property", + useName = "prop", + maxOccurs = -1, + groupAs = @GroupAs(name = "props", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + private List _props; + + @BoundField( + formalName = "Allowed Value Enumeration", + useName = "enum", + minOccurs = 1, + maxOccurs = -1, + groupAs = @GroupAs(name = "enums", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + private List _enums; + + @BoundField( + formalName = "Remarks", + description = "Any explanatory or helpful information to be provided about the remarks parent.", + useName = "remarks") + private Remarks _remarks; + + @Override + public String getId() { + return _id; + } + + public void setId(String value) { + _id = value; + } + + @Override + public String getLevel() { + return _level; + } + + public void setLevel(String value) { + _level = value; + } + + public String getAllowOther() { + return _allowOther; + } + + public void setAllowOther(String value) { + _allowOther = value; + } + + public String getExtensible() { + return _extensible; + } + + public void setExtensible(String value) { + _extensible = value; + } + + @Override + public String getFormalName() { + return _formalName; + } + + public void setFormalName(String value) { + _formalName = value; + } + + @Override + public MarkupLine getDescription() { + return _description; + } + + public void setDescription(MarkupLine value) { + _description = value; + } + + @Override + public List getProps() { + return _props; + } + + public void setProps(List value) { + _props = value; + } + + /** + * Add a new {@link Property} item to the underlying collection. + * + * @param item + * the item to add + * @return {@code true} + */ + public boolean addProp(Property item) { + Property value = ObjectUtils.requireNonNull(item, "item cannot be null"); + if (_props == null) { + _props = new LinkedList<>(); + } + return _props.add(value); + } + + /** + * Remove the first matching {@link Property} item from the underlying + * collection. + * + * @param item + * the item to remove + * @return {@code true} if the item was removed or {@code false} otherwise + */ + public boolean removeProp(Property item) { + Property value = ObjectUtils.requireNonNull(item, "item cannot be null"); + return _props != null && _props.remove(value); + } + + public List getEnums() { + return _enums; + } + + public void setEnums(List value) { + _enums = value; + } + + /** + * Add a new {@link ConstraintValueEnum} item to the underlying collection. + * + * @param item + * the item to add + * @return {@code true} + */ + public boolean addEnum(ConstraintValueEnum item) { + ConstraintValueEnum value = ObjectUtils.requireNonNull(item, "item cannot be null"); + if (_enums == null) { + _enums = new LinkedList<>(); + } + return _enums.add(value); + } + + /** + * Remove the first matching {@link ConstraintValueEnum} item from the + * underlying collection. + * + * @param item + * the item to remove + * @return {@code true} if the item was removed or {@code false} otherwise + */ + public boolean removeEnum(ConstraintValueEnum item) { + ConstraintValueEnum value = ObjectUtils.requireNonNull(item, "item cannot be null"); + return _enums != null && _enums.remove(value); + } + + @Override + public Remarks getRemarks() { + return _remarks; + } + + public void setRemarks(Remarks value) { + _remarks = value; + } + + @Override + public String toString() { + return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); + } +} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagConstraints.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagConstraints.java index 18333c50e..6f6db71a9 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagConstraints.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagConstraints.java @@ -26,22 +26,13 @@ package gov.nist.secauto.metaschema.databind.model.metaschema.binding; -import gov.nist.secauto.metaschema.core.datatype.adapter.StringAdapter; -import gov.nist.secauto.metaschema.core.datatype.adapter.TokenAdapter; -import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine; -import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLineAdapter; import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior; -import gov.nist.secauto.metaschema.core.model.constraint.IConstraint; import gov.nist.secauto.metaschema.core.util.ObjectUtils; -import gov.nist.secauto.metaschema.databind.model.annotations.AllowedValue; import gov.nist.secauto.metaschema.databind.model.annotations.BoundAssembly; import gov.nist.secauto.metaschema.databind.model.annotations.BoundChoiceGroup; -import gov.nist.secauto.metaschema.databind.model.annotations.BoundField; -import gov.nist.secauto.metaschema.databind.model.annotations.BoundFlag; import gov.nist.secauto.metaschema.databind.model.annotations.BoundGroupedAssembly; import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs; import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; -import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints; import gov.nist.secauto.metaschema.databind.model.metaschema.IConstraintBase; import gov.nist.secauto.metaschema.databind.model.metaschema.IValueConstraintsBase; @@ -58,13 +49,13 @@ }) @MetaschemaAssembly( name = "flag-constraints", - moduleClass = MetaschemaModule.class) + moduleClass = MetaschemaModelModule.class) public class FlagConstraints implements IValueConstraintsBase { @BoundAssembly( formalName = "Constraint Let Expression", useName = "let", maxOccurs = -1, - groupAs = @GroupAs(name = "lets", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "lets", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) private List _lets; @BoundChoiceGroup( @@ -72,13 +63,15 @@ public class FlagConstraints implements IValueConstraintsBase { maxOccurs = -1, assemblies = { @BoundGroupedAssembly(formalName = "Allowed Values Constraint", useName = "allowed-values", - binding = AllowedValues.class), - @BoundGroupedAssembly(formalName = "Expect Condition Constraint", useName = "expect", binding = Expect.class), + binding = FlagAllowedValues.class), + @BoundGroupedAssembly(formalName = "Expect Condition Constraint", useName = "expect", + binding = FlagExpect.class), @BoundGroupedAssembly(formalName = "Index Has Key Constraint", useName = "index-has-key", - binding = IndexHasKey.class), - @BoundGroupedAssembly(formalName = "Value Matches Constraint", useName = "matches", binding = Matches.class) + binding = FlagIndexHasKey.class), + @BoundGroupedAssembly(formalName = "Value Matches Constraint", useName = "matches", + binding = FlagMatches.class) }, - groupAs = @GroupAs(name = "rules", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "rules", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) private List _rules; @Override @@ -131,803 +124,4 @@ public void setRules(List value) { public String toString() { return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); } - - @MetaschemaAssembly( - formalName = "Expect Condition Constraint", - name = "expect", - moduleClass = MetaschemaModule.class) - public static class Expect implements IConstraintBase { - @BoundFlag( - formalName = "Constraint Identifier", - name = "id", - typeAdapter = TokenAdapter.class) - private String _id; - - @BoundFlag( - formalName = "Constraint Severity Level", - name = "level", - defaultValue = "ERROR", - typeAdapter = TokenAdapter.class, - valueConstraints = @ValueConstraints( - allowedValues = @gov.nist.secauto.metaschema.databind.model.annotations.AllowedValues( - level = IConstraint.Level.ERROR, - values = { @AllowedValue(value = "CRITICAL", - description = "A violation of the constraint represents a serious fault in the content that will prevent typical use of the content."), - @AllowedValue(value = "ERROR", - description = "A violation of the constraint represents a fault in the content. This may include issues around compatibility, integrity, consistency, etc."), - @AllowedValue(value = "WARNING", - description = "A violation of the constraint represents a potential issue with the content."), - @AllowedValue(value = "INFORMATIONAL", - description = "A violation of the constraint represents a point of interest.") }))) - private String _level; - - @BoundFlag( - formalName = "Expect Test Condition", - name = "test", - required = true, - typeAdapter = StringAdapter.class) - private String _test; - - @BoundField( - formalName = "Formal Name", - description = "A formal name for the data construct, to be presented in documentation.", - useName = "formal-name") - private String _formalName; - - @BoundField( - formalName = "Description", - description = "A short description of the data construct's purpose, describing the constructs semantics.", - useName = "description", - typeAdapter = MarkupLineAdapter.class) - private MarkupLine _description; - - @BoundAssembly( - formalName = "Property", - useName = "prop", - maxOccurs = -1, - groupAs = @GroupAs(name = "props", inJson = JsonGroupAsBehavior.LIST)) - private List _props; - - @BoundField( - formalName = "Expect Condition Violation Message", - useName = "message") - private String _message; - - @BoundField( - formalName = "Remarks", - description = "Any explanatory or helpful information to be provided about the remarks parent.", - useName = "remarks") - private Remarks _remarks; - - @Override - public String getId() { - return _id; - } - - public void setId(String value) { - _id = value; - } - - @Override - public String getLevel() { - return _level; - } - - public void setLevel(String value) { - _level = value; - } - - public String getTest() { - return _test; - } - - public void setTest(String value) { - _test = value; - } - - @Override - public String getFormalName() { - return _formalName; - } - - public void setFormalName(String value) { - _formalName = value; - } - - @Override - public MarkupLine getDescription() { - return _description; - } - - public void setDescription(MarkupLine value) { - _description = value; - } - - @Override - public List getProps() { - return _props; - } - - public void setProps(List value) { - _props = value; - } - - /** - * Add a new {@link Property} item to the underlying collection. - * - * @param item - * the item to add - * @return {@code true} - */ - public boolean addProp(Property item) { - Property value = ObjectUtils.requireNonNull(item, "item cannot be null"); - if (_props == null) { - _props = new LinkedList<>(); - } - return _props.add(value); - } - - /** - * Remove the first matching {@link Property} item from the underlying - * collection. - * - * @param item - * the item to remove - * @return {@code true} if the item was removed or {@code false} otherwise - */ - public boolean removeProp(Property item) { - Property value = ObjectUtils.requireNonNull(item, "item cannot be null"); - return _props != null && _props.remove(value); - } - - public String getMessage() { - return _message; - } - - public void setMessage(String value) { - _message = value; - } - - @Override - public Remarks getRemarks() { - return _remarks; - } - - public void setRemarks(Remarks value) { - _remarks = value; - } - - @Override - public String toString() { - return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); - } - } - - @MetaschemaAssembly( - formalName = "Value Matches Constraint", - name = "matches", - moduleClass = MetaschemaModule.class) - public static class Matches implements IConstraintBase { - @BoundFlag( - formalName = "Constraint Identifier", - name = "id", - typeAdapter = TokenAdapter.class) - private String _id; - - @BoundFlag( - formalName = "Constraint Severity Level", - name = "level", - defaultValue = "ERROR", - typeAdapter = TokenAdapter.class, - valueConstraints = @ValueConstraints( - allowedValues = @gov.nist.secauto.metaschema.databind.model.annotations.AllowedValues( - level = IConstraint.Level.ERROR, - values = { @AllowedValue(value = "CRITICAL", - description = "A violation of the constraint represents a serious fault in the content that will prevent typical use of the content."), - @AllowedValue(value = "ERROR", - description = "A violation of the constraint represents a fault in the content. This may include issues around compatibility, integrity, consistency, etc."), - @AllowedValue(value = "WARNING", - description = "A violation of the constraint represents a potential issue with the content."), - @AllowedValue(value = "INFORMATIONAL", - description = "A violation of the constraint represents a point of interest.") }))) - private String _level; - - @BoundFlag( - formalName = "Matches Regular Expression", - name = "regex", - typeAdapter = StringAdapter.class) - private String _regex; - - @BoundFlag( - formalName = "Matches Data Type", - name = "datatype", - typeAdapter = TokenAdapter.class, - valueConstraints = @ValueConstraints( - allowedValues = @gov.nist.secauto.metaschema.databind.model.annotations.AllowedValues( - level = IConstraint.Level.ERROR, allowOthers = true, - values = { @AllowedValue(value = "base64", description = ""), - @AllowedValue(value = "boolean", description = ""), @AllowedValue(value = "date", description = ""), - @AllowedValue(value = "date-time", description = ""), - @AllowedValue(value = "date-time-with-timezone", description = ""), - @AllowedValue(value = "date-with-timezone", description = ""), - @AllowedValue(value = "day-time-duration", description = ""), - @AllowedValue(value = "decimal", description = ""), - @AllowedValue(value = "email-address", description = ""), - @AllowedValue(value = "hostname", description = ""), - @AllowedValue(value = "integer", description = ""), - @AllowedValue(value = "ip-v4-address", description = ""), - @AllowedValue(value = "ip-v6-address", description = ""), - @AllowedValue(value = "non-negative-integer", description = ""), - @AllowedValue(value = "positive-integer", description = ""), - @AllowedValue(value = "string", description = ""), @AllowedValue(value = "token", description = ""), - @AllowedValue(value = "uri", description = ""), - @AllowedValue(value = "uri-reference", description = ""), - @AllowedValue(value = "uuid", description = "") }))) - private String _datatype; - - @BoundField( - formalName = "Formal Name", - description = "A formal name for the data construct, to be presented in documentation.", - useName = "formal-name") - private String _formalName; - - @BoundField( - formalName = "Description", - description = "A short description of the data construct's purpose, describing the constructs semantics.", - useName = "description", - typeAdapter = MarkupLineAdapter.class) - private MarkupLine _description; - - @BoundAssembly( - formalName = "Property", - useName = "prop", - maxOccurs = -1, - groupAs = @GroupAs(name = "props", inJson = JsonGroupAsBehavior.LIST)) - private List _props; - - @BoundField( - formalName = "Remarks", - description = "Any explanatory or helpful information to be provided about the remarks parent.", - useName = "remarks") - private Remarks _remarks; - - @Override - public String getId() { - return _id; - } - - public void setId(String value) { - _id = value; - } - - @Override - public String getLevel() { - return _level; - } - - public void setLevel(String value) { - _level = value; - } - - public String getRegex() { - return _regex; - } - - public void setRegex(String value) { - _regex = value; - } - - public String getDatatype() { - return _datatype; - } - - public void setDatatype(String value) { - _datatype = value; - } - - @Override - public String getFormalName() { - return _formalName; - } - - public void setFormalName(String value) { - _formalName = value; - } - - @Override - public MarkupLine getDescription() { - return _description; - } - - public void setDescription(MarkupLine value) { - _description = value; - } - - @Override - public List getProps() { - return _props; - } - - public void setProps(List value) { - _props = value; - } - - /** - * Add a new {@link Property} item to the underlying collection. - * - * @param item - * the item to add - * @return {@code true} - */ - public boolean addProp(Property item) { - Property value = ObjectUtils.requireNonNull(item, "item cannot be null"); - if (_props == null) { - _props = new LinkedList<>(); - } - return _props.add(value); - } - - /** - * Remove the first matching {@link Property} item from the underlying - * collection. - * - * @param item - * the item to remove - * @return {@code true} if the item was removed or {@code false} otherwise - */ - public boolean removeProp(Property item) { - Property value = ObjectUtils.requireNonNull(item, "item cannot be null"); - return _props != null && _props.remove(value); - } - - @Override - public Remarks getRemarks() { - return _remarks; - } - - public void setRemarks(Remarks value) { - _remarks = value; - } - - @Override - public String toString() { - return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); - } - } - - @MetaschemaAssembly( - formalName = "Allowed Values Constraint", - name = "allowed-values", - moduleClass = MetaschemaModule.class) - public static class AllowedValues implements IConstraintBase { - @BoundFlag( - formalName = "Constraint Identifier", - name = "id", - typeAdapter = TokenAdapter.class) - private String _id; - - @BoundFlag( - formalName = "Constraint Severity Level", - name = "level", - defaultValue = "ERROR", - typeAdapter = TokenAdapter.class, - valueConstraints = @ValueConstraints( - allowedValues = @gov.nist.secauto.metaschema.databind.model.annotations.AllowedValues( - level = IConstraint.Level.ERROR, - values = { @AllowedValue(value = "CRITICAL", - description = "A violation of the constraint represents a serious fault in the content that will prevent typical use of the content."), - @AllowedValue(value = "ERROR", - description = "A violation of the constraint represents a fault in the content. This may include issues around compatibility, integrity, consistency, etc."), - @AllowedValue(value = "WARNING", - description = "A violation of the constraint represents a potential issue with the content."), - @AllowedValue(value = "INFORMATIONAL", - description = "A violation of the constraint represents a point of interest.") }))) - private String _level; - - @BoundFlag( - formalName = "Allow Non-Enumerated Values?", - name = "allow-other", - defaultValue = "no", - typeAdapter = TokenAdapter.class, - valueConstraints = @ValueConstraints( - allowedValues = @gov.nist.secauto.metaschema.databind.model.annotations.AllowedValues( - level = IConstraint.Level.ERROR, values = { @AllowedValue(value = "no", description = ""), - @AllowedValue(value = "yes", description = "") }))) - private String _allowOther; - - /** - * "Determines if the given enumerated values may be extended by other allowed - * value constraints." - */ - @BoundFlag( - formalName = "Allow Extension?", - description = "Determines if the given enumerated values may be extended by other allowed value constraints.", - name = "extensible", - defaultValue = "external", - typeAdapter = TokenAdapter.class, - valueConstraints = @ValueConstraints( - allowedValues = @gov.nist.secauto.metaschema.databind.model.annotations.AllowedValues( - level = IConstraint.Level.ERROR, - values = { - @AllowedValue(value = "model", - description = "Can be extended by constraints within the same module."), - @AllowedValue(value = "external", description = "Can be extended by external constraints."), - @AllowedValue(value = "none", description = "Cannot be extended.") }))) - private String _extensible; - - @BoundField( - formalName = "Formal Name", - description = "A formal name for the data construct, to be presented in documentation.", - useName = "formal-name") - private String _formalName; - - @BoundField( - formalName = "Description", - description = "A short description of the data construct's purpose, describing the constructs semantics.", - useName = "description", - typeAdapter = MarkupLineAdapter.class) - private MarkupLine _description; - - @BoundAssembly( - formalName = "Property", - useName = "prop", - maxOccurs = -1, - groupAs = @GroupAs(name = "props", inJson = JsonGroupAsBehavior.LIST)) - private List _props; - - @BoundField( - formalName = "Allowed Value Enumeration", - useName = "enum", - minOccurs = 1, - maxOccurs = -1, - groupAs = @GroupAs(name = "enums", inJson = JsonGroupAsBehavior.LIST)) - private List _enums; - - @BoundField( - formalName = "Remarks", - description = "Any explanatory or helpful information to be provided about the remarks parent.", - useName = "remarks") - private Remarks _remarks; - - @Override - public String getId() { - return _id; - } - - public void setId(String value) { - _id = value; - } - - @Override - public String getLevel() { - return _level; - } - - public void setLevel(String value) { - _level = value; - } - - public String getAllowOther() { - return _allowOther; - } - - public void setAllowOther(String value) { - _allowOther = value; - } - - public String getExtensible() { - return _extensible; - } - - public void setExtensible(String value) { - _extensible = value; - } - - @Override - public String getFormalName() { - return _formalName; - } - - public void setFormalName(String value) { - _formalName = value; - } - - @Override - public MarkupLine getDescription() { - return _description; - } - - public void setDescription(MarkupLine value) { - _description = value; - } - - @Override - public List getProps() { - return _props; - } - - public void setProps(List value) { - _props = value; - } - - /** - * Add a new {@link Property} item to the underlying collection. - * - * @param item - * the item to add - * @return {@code true} - */ - public boolean addProp(Property item) { - Property value = ObjectUtils.requireNonNull(item, "item cannot be null"); - if (_props == null) { - _props = new LinkedList<>(); - } - return _props.add(value); - } - - /** - * Remove the first matching {@link Property} item from the underlying - * collection. - * - * @param item - * the item to remove - * @return {@code true} if the item was removed or {@code false} otherwise - */ - public boolean removeProp(Property item) { - Property value = ObjectUtils.requireNonNull(item, "item cannot be null"); - return _props != null && _props.remove(value); - } - - public List getEnums() { - return _enums; - } - - public void setEnums(List value) { - _enums = value; - } - - /** - * Add a new {@link ConstraintValueEnum} item to the underlying collection. - * - * @param item - * the item to add - * @return {@code true} - */ - public boolean addEnum(ConstraintValueEnum item) { - ConstraintValueEnum value = ObjectUtils.requireNonNull(item, "item cannot be null"); - if (_enums == null) { - _enums = new LinkedList<>(); - } - return _enums.add(value); - } - - /** - * Remove the first matching {@link ConstraintValueEnum} item from the - * underlying collection. - * - * @param item - * the item to remove - * @return {@code true} if the item was removed or {@code false} otherwise - */ - public boolean removeEnum(ConstraintValueEnum item) { - ConstraintValueEnum value = ObjectUtils.requireNonNull(item, "item cannot be null"); - return _enums != null && _enums.remove(value); - } - - @Override - public Remarks getRemarks() { - return _remarks; - } - - public void setRemarks(Remarks value) { - _remarks = value; - } - - @Override - public String toString() { - return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); - } - } - - @MetaschemaAssembly( - formalName = "Index Has Key Constraint", - name = "index-has-key", - moduleClass = MetaschemaModule.class) - public static class IndexHasKey implements IConstraintBase { - @BoundFlag( - formalName = "Constraint Identifier", - name = "id", - typeAdapter = TokenAdapter.class) - private String _id; - - @BoundFlag( - formalName = "Constraint Severity Level", - name = "level", - defaultValue = "ERROR", - typeAdapter = TokenAdapter.class, - valueConstraints = @ValueConstraints( - allowedValues = @gov.nist.secauto.metaschema.databind.model.annotations.AllowedValues( - level = IConstraint.Level.ERROR, - values = { @AllowedValue(value = "CRITICAL", - description = "A violation of the constraint represents a serious fault in the content that will prevent typical use of the content."), - @AllowedValue(value = "ERROR", - description = "A violation of the constraint represents a fault in the content. This may include issues around compatibility, integrity, consistency, etc."), - @AllowedValue(value = "WARNING", - description = "A violation of the constraint represents a potential issue with the content."), - @AllowedValue(value = "INFORMATIONAL", - description = "A violation of the constraint represents a point of interest.") }))) - private String _level; - - @BoundFlag( - formalName = "Index Name", - name = "name", - required = true, - typeAdapter = TokenAdapter.class) - private String _name; - - @BoundField( - formalName = "Formal Name", - description = "A formal name for the data construct, to be presented in documentation.", - useName = "formal-name") - private String _formalName; - - @BoundField( - formalName = "Description", - description = "A short description of the data construct's purpose, describing the constructs semantics.", - useName = "description", - typeAdapter = MarkupLineAdapter.class) - private MarkupLine _description; - - @BoundAssembly( - formalName = "Property", - useName = "prop", - maxOccurs = -1, - groupAs = @GroupAs(name = "props", inJson = JsonGroupAsBehavior.LIST)) - private List _props; - - @BoundAssembly( - formalName = "Key Constraint Field", - useName = "key-field", - minOccurs = 1, - maxOccurs = -1, - groupAs = @GroupAs(name = "key-fields", inJson = JsonGroupAsBehavior.LIST)) - private List _keyFields; - - @BoundField( - formalName = "Remarks", - description = "Any explanatory or helpful information to be provided about the remarks parent.", - useName = "remarks") - private Remarks _remarks; - - @Override - public String getId() { - return _id; - } - - public void setId(String value) { - _id = value; - } - - @Override - public String getLevel() { - return _level; - } - - public void setLevel(String value) { - _level = value; - } - - public String getName() { - return _name; - } - - public void setName(String value) { - _name = value; - } - - @Override - public String getFormalName() { - return _formalName; - } - - public void setFormalName(String value) { - _formalName = value; - } - - @Override - public MarkupLine getDescription() { - return _description; - } - - public void setDescription(MarkupLine value) { - _description = value; - } - - @Override - public List getProps() { - return _props; - } - - public void setProps(List value) { - _props = value; - } - - /** - * Add a new {@link Property} item to the underlying collection. - * - * @param item - * the item to add - * @return {@code true} - */ - public boolean addProp(Property item) { - Property value = ObjectUtils.requireNonNull(item, "item cannot be null"); - if (_props == null) { - _props = new LinkedList<>(); - } - return _props.add(value); - } - - /** - * Remove the first matching {@link Property} item from the underlying - * collection. - * - * @param item - * the item to remove - * @return {@code true} if the item was removed or {@code false} otherwise - */ - public boolean removeProp(Property item) { - Property value = ObjectUtils.requireNonNull(item, "item cannot be null"); - return _props != null && _props.remove(value); - } - - public List getKeyFields() { - return _keyFields; - } - - public void setKeyFields(List value) { - _keyFields = value; - } - - /** - * Add a new {@link KeyConstraintField} item to the underlying collection. - * - * @param item - * the item to add - * @return {@code true} - */ - public boolean addKeyField(KeyConstraintField item) { - KeyConstraintField value = ObjectUtils.requireNonNull(item, "item cannot be null"); - if (_keyFields == null) { - _keyFields = new LinkedList<>(); - } - return _keyFields.add(value); - } - - /** - * Remove the first matching {@link KeyConstraintField} item from the underlying - * collection. - * - * @param item - * the item to remove - * @return {@code true} if the item was removed or {@code false} otherwise - */ - public boolean removeKeyField(KeyConstraintField item) { - KeyConstraintField value = ObjectUtils.requireNonNull(item, "item cannot be null"); - return _keyFields != null && _keyFields.remove(value); - } - - @Override - public Remarks getRemarks() { - return _remarks; - } - - public void setRemarks(Remarks value) { - _remarks = value; - } - - @Override - public String toString() { - return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); - } - } } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagExpect.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagExpect.java new file mode 100644 index 000000000..f609191c7 --- /dev/null +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagExpect.java @@ -0,0 +1,223 @@ +/* + * 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.databind.model.metaschema.binding; + +import gov.nist.secauto.metaschema.core.datatype.adapter.StringAdapter; +import gov.nist.secauto.metaschema.core.datatype.adapter.TokenAdapter; +import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine; +import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLineAdapter; +import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior; +import gov.nist.secauto.metaschema.core.model.constraint.IConstraint; +import gov.nist.secauto.metaschema.core.util.ObjectUtils; +import gov.nist.secauto.metaschema.databind.model.annotations.AllowedValue; +import gov.nist.secauto.metaschema.databind.model.annotations.AllowedValues; +import gov.nist.secauto.metaschema.databind.model.annotations.BoundAssembly; +import gov.nist.secauto.metaschema.databind.model.annotations.BoundField; +import gov.nist.secauto.metaschema.databind.model.annotations.BoundFlag; +import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs; +import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; +import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints; +import gov.nist.secauto.metaschema.databind.model.metaschema.IConstraintBase; + +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import java.util.LinkedList; +import java.util.List; + +@SuppressWarnings({ + "PMD.DataClass", + "PMD.FieldNamingConventions" +}) +@MetaschemaAssembly( + formalName = "Expect Condition Constraint", + name = "flag-expect", + moduleClass = MetaschemaModelModule.class) +public class FlagExpect implements IConstraintBase { + @BoundFlag( + formalName = "Constraint Identifier", + name = "id", + typeAdapter = TokenAdapter.class) + private String _id; + + @BoundFlag( + formalName = "Constraint Severity Level", + name = "level", + defaultValue = "ERROR", + typeAdapter = TokenAdapter.class, + valueConstraints = @ValueConstraints(allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, values = { + @AllowedValue(value = "CRITICAL", + description = "A violation of the constraint represents a serious fault in the content that will prevent typical use of the content."), + @AllowedValue(value = "ERROR", + description = "A violation of the constraint represents a fault in the content. This may include issues around compatibility, integrity, consistency, etc."), + @AllowedValue(value = "WARNING", + description = "A violation of the constraint represents a potential issue with the content."), + @AllowedValue(value = "INFORMATIONAL", + description = "A violation of the constraint represents a point of interest.") }))) + private String _level; + + @BoundFlag( + formalName = "Expect Test Condition", + name = "test", + required = true, + typeAdapter = StringAdapter.class) + private String _test; + + @BoundField( + formalName = "Formal Name", + description = "A formal name for the data construct, to be presented in documentation.", + useName = "formal-name") + private String _formalName; + + @BoundField( + formalName = "Description", + description = "A short description of the data construct's purpose, describing the constructs semantics.", + useName = "description", + typeAdapter = MarkupLineAdapter.class) + private MarkupLine _description; + + @BoundAssembly( + formalName = "Property", + useName = "prop", + maxOccurs = -1, + groupAs = @GroupAs(name = "props", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + private List _props; + + @BoundField( + formalName = "Expect Condition Violation Message", + useName = "message") + private String _message; + + @BoundField( + formalName = "Remarks", + description = "Any explanatory or helpful information to be provided about the remarks parent.", + useName = "remarks") + private Remarks _remarks; + + @Override + public String getId() { + return _id; + } + + public void setId(String value) { + _id = value; + } + + @Override + public String getLevel() { + return _level; + } + + public void setLevel(String value) { + _level = value; + } + + public String getTest() { + return _test; + } + + public void setTest(String value) { + _test = value; + } + + @Override + public String getFormalName() { + return _formalName; + } + + public void setFormalName(String value) { + _formalName = value; + } + + @Override + public MarkupLine getDescription() { + return _description; + } + + public void setDescription(MarkupLine value) { + _description = value; + } + + @Override + public List getProps() { + return _props; + } + + public void setProps(List value) { + _props = value; + } + + /** + * Add a new {@link Property} item to the underlying collection. + * + * @param item + * the item to add + * @return {@code true} + */ + public boolean addProp(Property item) { + Property value = ObjectUtils.requireNonNull(item, "item cannot be null"); + if (_props == null) { + _props = new LinkedList<>(); + } + return _props.add(value); + } + + /** + * Remove the first matching {@link Property} item from the underlying + * collection. + * + * @param item + * the item to remove + * @return {@code true} if the item was removed or {@code false} otherwise + */ + public boolean removeProp(Property item) { + Property value = ObjectUtils.requireNonNull(item, "item cannot be null"); + return _props != null && _props.remove(value); + } + + public String getMessage() { + return _message; + } + + public void setMessage(String value) { + _message = value; + } + + @Override + public Remarks getRemarks() { + return _remarks; + } + + public void setRemarks(Remarks value) { + _remarks = value; + } + + @Override + public String toString() { + return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); + } +} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagIndexHasKey.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagIndexHasKey.java new file mode 100644 index 000000000..53fb36ed1 --- /dev/null +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagIndexHasKey.java @@ -0,0 +1,253 @@ +/* + * 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.databind.model.metaschema.binding; + +import gov.nist.secauto.metaschema.core.datatype.adapter.TokenAdapter; +import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine; +import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLineAdapter; +import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior; +import gov.nist.secauto.metaschema.core.model.constraint.IConstraint; +import gov.nist.secauto.metaschema.core.util.ObjectUtils; +import gov.nist.secauto.metaschema.databind.model.annotations.AllowedValue; +import gov.nist.secauto.metaschema.databind.model.annotations.AllowedValues; +import gov.nist.secauto.metaschema.databind.model.annotations.BoundAssembly; +import gov.nist.secauto.metaschema.databind.model.annotations.BoundField; +import gov.nist.secauto.metaschema.databind.model.annotations.BoundFlag; +import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs; +import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; +import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints; +import gov.nist.secauto.metaschema.databind.model.metaschema.IConstraintBase; + +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import java.util.LinkedList; +import java.util.List; + +@SuppressWarnings({ + "PMD.DataClass", + "PMD.FieldNamingConventions" +}) +@MetaschemaAssembly( + formalName = "Index Has Key Constraint", + name = "flag-index-has-key", + moduleClass = MetaschemaModelModule.class) +public class FlagIndexHasKey implements IConstraintBase { + @BoundFlag( + formalName = "Constraint Identifier", + name = "id", + typeAdapter = TokenAdapter.class) + private String _id; + + @BoundFlag( + formalName = "Constraint Severity Level", + name = "level", + defaultValue = "ERROR", + typeAdapter = TokenAdapter.class, + valueConstraints = @ValueConstraints(allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, values = { + @AllowedValue(value = "CRITICAL", + description = "A violation of the constraint represents a serious fault in the content that will prevent typical use of the content."), + @AllowedValue(value = "ERROR", + description = "A violation of the constraint represents a fault in the content. This may include issues around compatibility, integrity, consistency, etc."), + @AllowedValue(value = "WARNING", + description = "A violation of the constraint represents a potential issue with the content."), + @AllowedValue(value = "INFORMATIONAL", + description = "A violation of the constraint represents a point of interest.") }))) + private String _level; + + @BoundFlag( + formalName = "Index Name", + name = "name", + required = true, + typeAdapter = TokenAdapter.class) + private String _name; + + @BoundField( + formalName = "Formal Name", + description = "A formal name for the data construct, to be presented in documentation.", + useName = "formal-name") + private String _formalName; + + @BoundField( + formalName = "Description", + description = "A short description of the data construct's purpose, describing the constructs semantics.", + useName = "description", + typeAdapter = MarkupLineAdapter.class) + private MarkupLine _description; + + @BoundAssembly( + formalName = "Property", + useName = "prop", + maxOccurs = -1, + groupAs = @GroupAs(name = "props", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + private List _props; + + @BoundAssembly( + formalName = "Key Constraint Field", + useName = "key-field", + minOccurs = 1, + maxOccurs = -1, + groupAs = @GroupAs(name = "key-fields", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + private List _keyFields; + + @BoundField( + formalName = "Remarks", + description = "Any explanatory or helpful information to be provided about the remarks parent.", + useName = "remarks") + private Remarks _remarks; + + @Override + public String getId() { + return _id; + } + + public void setId(String value) { + _id = value; + } + + @Override + public String getLevel() { + return _level; + } + + public void setLevel(String value) { + _level = value; + } + + public String getName() { + return _name; + } + + public void setName(String value) { + _name = value; + } + + @Override + public String getFormalName() { + return _formalName; + } + + public void setFormalName(String value) { + _formalName = value; + } + + @Override + public MarkupLine getDescription() { + return _description; + } + + public void setDescription(MarkupLine value) { + _description = value; + } + + @Override + public List getProps() { + return _props; + } + + public void setProps(List value) { + _props = value; + } + + /** + * Add a new {@link Property} item to the underlying collection. + * + * @param item + * the item to add + * @return {@code true} + */ + public boolean addProp(Property item) { + Property value = ObjectUtils.requireNonNull(item, "item cannot be null"); + if (_props == null) { + _props = new LinkedList<>(); + } + return _props.add(value); + } + + /** + * Remove the first matching {@link Property} item from the underlying + * collection. + * + * @param item + * the item to remove + * @return {@code true} if the item was removed or {@code false} otherwise + */ + public boolean removeProp(Property item) { + Property value = ObjectUtils.requireNonNull(item, "item cannot be null"); + return _props != null && _props.remove(value); + } + + public List getKeyFields() { + return _keyFields; + } + + public void setKeyFields(List value) { + _keyFields = value; + } + + /** + * Add a new {@link KeyConstraintField} item to the underlying collection. + * + * @param item + * the item to add + * @return {@code true} + */ + public boolean addKeyField(KeyConstraintField item) { + KeyConstraintField value = ObjectUtils.requireNonNull(item, "item cannot be null"); + if (_keyFields == null) { + _keyFields = new LinkedList<>(); + } + return _keyFields.add(value); + } + + /** + * Remove the first matching {@link KeyConstraintField} item from the underlying + * collection. + * + * @param item + * the item to remove + * @return {@code true} if the item was removed or {@code false} otherwise + */ + public boolean removeKeyField(KeyConstraintField item) { + KeyConstraintField value = ObjectUtils.requireNonNull(item, "item cannot be null"); + return _keyFields != null && _keyFields.remove(value); + } + + @Override + public Remarks getRemarks() { + return _remarks; + } + + public void setRemarks(Remarks value) { + _remarks = value; + } + + @Override + public String toString() { + return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); + } +} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagMatches.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagMatches.java new file mode 100644 index 000000000..dedba477e --- /dev/null +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagMatches.java @@ -0,0 +1,241 @@ +/* + * 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.databind.model.metaschema.binding; + +import gov.nist.secauto.metaschema.core.datatype.adapter.StringAdapter; +import gov.nist.secauto.metaschema.core.datatype.adapter.TokenAdapter; +import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine; +import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLineAdapter; +import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior; +import gov.nist.secauto.metaschema.core.model.constraint.IConstraint; +import gov.nist.secauto.metaschema.core.util.ObjectUtils; +import gov.nist.secauto.metaschema.databind.model.annotations.AllowedValue; +import gov.nist.secauto.metaschema.databind.model.annotations.AllowedValues; +import gov.nist.secauto.metaschema.databind.model.annotations.BoundAssembly; +import gov.nist.secauto.metaschema.databind.model.annotations.BoundField; +import gov.nist.secauto.metaschema.databind.model.annotations.BoundFlag; +import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs; +import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; +import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints; +import gov.nist.secauto.metaschema.databind.model.metaschema.IConstraintBase; + +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import java.util.LinkedList; +import java.util.List; + +@SuppressWarnings({ + "PMD.DataClass", + "PMD.FieldNamingConventions" +}) +@MetaschemaAssembly( + formalName = "Value Matches Constraint", + name = "flag-matches", + moduleClass = MetaschemaModelModule.class) +public class FlagMatches implements IConstraintBase { + @BoundFlag( + formalName = "Constraint Identifier", + name = "id", + typeAdapter = TokenAdapter.class) + private String _id; + + @BoundFlag( + formalName = "Constraint Severity Level", + name = "level", + defaultValue = "ERROR", + typeAdapter = TokenAdapter.class, + valueConstraints = @ValueConstraints(allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, values = { + @AllowedValue(value = "CRITICAL", + description = "A violation of the constraint represents a serious fault in the content that will prevent typical use of the content."), + @AllowedValue(value = "ERROR", + description = "A violation of the constraint represents a fault in the content. This may include issues around compatibility, integrity, consistency, etc."), + @AllowedValue(value = "WARNING", + description = "A violation of the constraint represents a potential issue with the content."), + @AllowedValue(value = "INFORMATIONAL", + description = "A violation of the constraint represents a point of interest.") }))) + private String _level; + + @BoundFlag( + formalName = "Matches Regular Expression", + name = "regex", + typeAdapter = StringAdapter.class) + private String _regex; + + @BoundFlag( + formalName = "Matches Data Type", + name = "datatype", + typeAdapter = TokenAdapter.class, + valueConstraints = @ValueConstraints(allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, + allowOthers = true, + values = { @AllowedValue(value = "base64", description = ""), + @AllowedValue(value = "boolean", description = ""), @AllowedValue(value = "date", description = ""), + @AllowedValue(value = "date-time", description = ""), + @AllowedValue(value = "date-time-with-timezone", description = ""), + @AllowedValue(value = "date-with-timezone", description = ""), + @AllowedValue(value = "day-time-duration", description = ""), + @AllowedValue(value = "decimal", description = ""), + @AllowedValue(value = "email-address", description = ""), + @AllowedValue(value = "hostname", description = ""), @AllowedValue(value = "integer", description = ""), + @AllowedValue(value = "ip-v4-address", description = ""), + @AllowedValue(value = "ip-v6-address", description = ""), + @AllowedValue(value = "non-negative-integer", description = ""), + @AllowedValue(value = "positive-integer", description = ""), + @AllowedValue(value = "string", description = ""), @AllowedValue(value = "token", description = ""), + @AllowedValue(value = "uri", description = ""), @AllowedValue(value = "uri-reference", description = ""), + @AllowedValue(value = "uuid", description = "") }))) + private String _datatype; + + @BoundField( + formalName = "Formal Name", + description = "A formal name for the data construct, to be presented in documentation.", + useName = "formal-name") + private String _formalName; + + @BoundField( + formalName = "Description", + description = "A short description of the data construct's purpose, describing the constructs semantics.", + useName = "description", + typeAdapter = MarkupLineAdapter.class) + private MarkupLine _description; + + @BoundAssembly( + formalName = "Property", + useName = "prop", + maxOccurs = -1, + groupAs = @GroupAs(name = "props", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + private List _props; + + @BoundField( + formalName = "Remarks", + description = "Any explanatory or helpful information to be provided about the remarks parent.", + useName = "remarks") + private Remarks _remarks; + + @Override + public String getId() { + return _id; + } + + public void setId(String value) { + _id = value; + } + + @Override + public String getLevel() { + return _level; + } + + public void setLevel(String value) { + _level = value; + } + + public String getRegex() { + return _regex; + } + + public void setRegex(String value) { + _regex = value; + } + + public String getDatatype() { + return _datatype; + } + + public void setDatatype(String value) { + _datatype = value; + } + + @Override + public String getFormalName() { + return _formalName; + } + + public void setFormalName(String value) { + _formalName = value; + } + + @Override + public MarkupLine getDescription() { + return _description; + } + + public void setDescription(MarkupLine value) { + _description = value; + } + + @Override + public List getProps() { + return _props; + } + + public void setProps(List value) { + _props = value; + } + + /** + * Add a new {@link Property} item to the underlying collection. + * + * @param item + * the item to add + * @return {@code true} + */ + public boolean addProp(Property item) { + Property value = ObjectUtils.requireNonNull(item, "item cannot be null"); + if (_props == null) { + _props = new LinkedList<>(); + } + return _props.add(value); + } + + /** + * Remove the first matching {@link Property} item from the underlying + * collection. + * + * @param item + * the item to remove + * @return {@code true} if the item was removed or {@code false} otherwise + */ + public boolean removeProp(Property item) { + Property value = ObjectUtils.requireNonNull(item, "item cannot be null"); + return _props != null && _props.remove(value); + } + + @Override + public Remarks getRemarks() { + return _remarks; + } + + public void setRemarks(Remarks value) { + _remarks = value; + } + + @Override + public String toString() { + return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); + } +} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagReference.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagReference.java index d040a8ebd..3ccb2dc49 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagReference.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagReference.java @@ -42,13 +42,13 @@ import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs; import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints; - -import org.apache.commons.lang3.builder.ReflectionToStringBuilder; -import org.apache.commons.lang3.builder.ToStringStyle; - +import java.lang.Override; +import java.lang.String; import java.math.BigInteger; import java.util.LinkedList; import java.util.List; +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; @SuppressWarnings({ "PMD.DataClass", @@ -57,7 +57,7 @@ @MetaschemaAssembly( formalName = "Flag Reference", name = "flag-reference", - moduleClass = MetaschemaModule.class) + moduleClass = MetaschemaModelModule.class) public class FlagReference { @BoundFlag( formalName = "Global Flag Reference", @@ -110,7 +110,7 @@ public class FlagReference { formalName = "Property", useName = "prop", maxOccurs = -1, - groupAs = @GroupAs(name = "props", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "props", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) private List _props; @BoundField( diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/GroupAs.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/GroupAs.java index a9c6b7d98..5ed6ed33f 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/GroupAs.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/GroupAs.java @@ -33,7 +33,8 @@ import gov.nist.secauto.metaschema.databind.model.annotations.BoundFlag; import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints; - +import java.lang.Override; +import java.lang.String; import org.apache.commons.lang3.builder.ReflectionToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; @@ -44,7 +45,7 @@ @MetaschemaAssembly( formalName = "Group As", name = "group-as", - moduleClass = MetaschemaModule.class) + moduleClass = MetaschemaModelModule.class) public class GroupAs { @BoundFlag( formalName = "Grouping Name", diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/InlineDefineAssembly.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/InlineDefineAssembly.java index 007b42c58..8be25ca5f 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/InlineDefineAssembly.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/InlineDefineAssembly.java @@ -43,13 +43,14 @@ import gov.nist.secauto.metaschema.databind.model.annotations.Matches; import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints; - -import org.apache.commons.lang3.builder.ReflectionToStringBuilder; -import org.apache.commons.lang3.builder.ToStringStyle; - +import java.lang.Object; +import java.lang.Override; +import java.lang.String; import java.math.BigInteger; import java.util.LinkedList; import java.util.List; +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; @SuppressWarnings({ "PMD.DataClass", @@ -58,7 +59,7 @@ @MetaschemaAssembly( formalName = "Inline Assembly Definition", name = "inline-define-assembly", - moduleClass = MetaschemaModule.class) + moduleClass = MetaschemaModelModule.class) public class InlineDefineAssembly { @BoundFlag( formalName = "Inline Assembly Name", @@ -112,7 +113,7 @@ public class InlineDefineAssembly { formalName = "Property", useName = "prop", maxOccurs = -1, - groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "props", + groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "props", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) private List _props; @@ -134,7 +135,7 @@ public class InlineDefineAssembly { binding = InlineDefineFlag.class), @BoundGroupedAssembly(formalName = "Flag Reference", useName = "flag", binding = FlagReference.class) }, - groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "flags", + groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "flags", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) private List _flags; @@ -157,7 +158,7 @@ public class InlineDefineAssembly { useName = "example", maxOccurs = -1, groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "examples", - inJson = JsonGroupAsBehavior.LIST)) + namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) private List _examples; public String getName() { diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/InlineDefineField.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/InlineDefineField.java index 37d20d5cc..5ed0f442d 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/InlineDefineField.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/InlineDefineField.java @@ -45,13 +45,14 @@ import gov.nist.secauto.metaschema.databind.model.annotations.Matches; import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints; - -import org.apache.commons.lang3.builder.ReflectionToStringBuilder; -import org.apache.commons.lang3.builder.ToStringStyle; - +import java.lang.Object; +import java.lang.Override; +import java.lang.String; import java.math.BigInteger; import java.util.LinkedList; import java.util.List; +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; @SuppressWarnings({ "PMD.DataClass", @@ -61,7 +62,7 @@ @MetaschemaAssembly( formalName = "Inline Field Definition", name = "inline-define-field", - moduleClass = MetaschemaModule.class) + moduleClass = MetaschemaModelModule.class) public class InlineDefineField { @BoundFlag( formalName = "Inline Field Name", @@ -160,7 +161,7 @@ public class InlineDefineField { formalName = "Property", useName = "prop", maxOccurs = -1, - groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "props", + groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "props", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) private List _props; @@ -193,7 +194,7 @@ public class InlineDefineField { binding = InlineDefineFlag.class), @BoundGroupedAssembly(formalName = "Flag Reference", useName = "flag", binding = FlagReference.class) }, - groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "flags", + groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "flags", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) private List _flags; @@ -212,7 +213,7 @@ public class InlineDefineField { useName = "example", maxOccurs = -1, groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "examples", - inJson = JsonGroupAsBehavior.LIST)) + namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) private List _examples; public String getName() { diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/InlineDefineFlag.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/InlineDefineFlag.java index 7d8e3200a..048be4ea8 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/InlineDefineFlag.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/InlineDefineFlag.java @@ -42,13 +42,13 @@ import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs; import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints; - -import org.apache.commons.lang3.builder.ReflectionToStringBuilder; -import org.apache.commons.lang3.builder.ToStringStyle; - +import java.lang.Override; +import java.lang.String; import java.math.BigInteger; import java.util.LinkedList; import java.util.List; +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; @SuppressWarnings({ "PMD.DataClass", @@ -57,7 +57,7 @@ @MetaschemaAssembly( formalName = "Inline Flag Definition", name = "inline-define-flag", - moduleClass = MetaschemaModule.class) + moduleClass = MetaschemaModelModule.class) public class InlineDefineFlag { @BoundFlag( formalName = "Inline Flag Name", @@ -135,7 +135,7 @@ public class InlineDefineFlag { formalName = "Property", useName = "prop", maxOccurs = -1, - groupAs = @GroupAs(name = "props", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "props", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) private List _props; @BoundAssembly( @@ -152,7 +152,7 @@ public class InlineDefineFlag { formalName = "Example", useName = "example", maxOccurs = -1, - groupAs = @GroupAs(name = "examples", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "examples", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) private List _examples; public String getName() { diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/JsonKey.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/JsonKey.java index 4626aa03e..fde5fee66 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/JsonKey.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/JsonKey.java @@ -29,7 +29,8 @@ import gov.nist.secauto.metaschema.core.datatype.adapter.TokenAdapter; import gov.nist.secauto.metaschema.databind.model.annotations.BoundFlag; import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; - +import java.lang.Override; +import java.lang.String; import org.apache.commons.lang3.builder.ReflectionToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; @@ -46,7 +47,7 @@ formalName = "JSON Key", description = "Used in JSON (and similar formats) to identify a flag that will be used as the property name in an object hold a collection of sibling objects. Requires that siblings must never share `json-key` values.", name = "json-key", - moduleClass = MetaschemaModule.class) + moduleClass = MetaschemaModelModule.class) public class JsonKey { /** * "References the flag that will serve as the JSON key." diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/JsonValueKeyFlag.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/JsonValueKeyFlag.java index 10014b563..639a83842 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/JsonValueKeyFlag.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/JsonValueKeyFlag.java @@ -29,7 +29,8 @@ import gov.nist.secauto.metaschema.core.datatype.adapter.TokenAdapter; import gov.nist.secauto.metaschema.databind.model.annotations.BoundFlag; import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; - +import java.lang.Override; +import java.lang.String; import org.apache.commons.lang3.builder.ReflectionToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; @@ -40,7 +41,7 @@ @MetaschemaAssembly( formalName = "Flag Used as the Field Value's JSON Property Name", name = "json-value-key-flag", - moduleClass = MetaschemaModule.class) + moduleClass = MetaschemaModelModule.class) public class JsonValueKeyFlag { @BoundFlag( formalName = "Flag Reference", diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/KeyConstraintField.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/KeyConstraintField.java index 002b1fa3f..7b4fd7c1a 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/KeyConstraintField.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/KeyConstraintField.java @@ -30,7 +30,8 @@ import gov.nist.secauto.metaschema.databind.model.annotations.BoundField; import gov.nist.secauto.metaschema.databind.model.annotations.BoundFlag; import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; - +import java.lang.Override; +import java.lang.String; import org.apache.commons.lang3.builder.ReflectionToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; @@ -41,7 +42,7 @@ @MetaschemaAssembly( formalName = "Key Constraint", name = "key-constraint-field", - moduleClass = MetaschemaModule.class) + moduleClass = MetaschemaModelModule.class) public class KeyConstraintField { @BoundFlag( formalName = "Key Field Value Target", diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/METASCHEMA.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/METASCHEMA.java index 8b682ce09..94f036f94 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/METASCHEMA.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/METASCHEMA.java @@ -49,14 +49,15 @@ import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaField; import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints; - -import org.apache.commons.lang3.builder.ReflectionToStringBuilder; -import org.apache.commons.lang3.builder.ToStringStyle; - +import java.lang.Object; +import java.lang.Override; +import java.lang.String; import java.math.BigInteger; import java.net.URI; import java.util.LinkedList; import java.util.List; +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; /** * A declaration of the Metaschema module. @@ -72,7 +73,7 @@ formalName = "Metaschema Module", description = "A declaration of the Metaschema module.", name = "METASCHEMA", - moduleClass = MetaschemaModule.class, + moduleClass = MetaschemaModelModule.class, rootName = "METASCHEMA") public class METASCHEMA { /** @@ -138,7 +139,7 @@ public class METASCHEMA { description = "Imports a set of Metaschema modules contained in another resource. Imports support the reuse of common information structures.", useName = "import", maxOccurs = -1, - groupAs = @GroupAs(name = "imports", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "imports", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) private List _imports; @BoundChoiceGroup( @@ -152,7 +153,7 @@ public class METASCHEMA { @BoundGroupedAssembly(formalName = "Global Flag Definition", useName = "define-flag", binding = DefineFlag.class) }, - groupAs = @GroupAs(name = "definitions", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "definitions", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) private List _definitions; public String getAbstract() { @@ -259,27 +260,20 @@ public String toString() { return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); } - /** - * In XML, an element with structured element content. In JSON, an object with - * properties. Defined globally, an assembly can be assigned to appear in the - * model of any assembly (another assembly type, or itself), by - * assembly reference. - */ @MetaschemaAssembly( - formalName = "Global Assembly Definition", - description = "In XML, an element with structured element content. In JSON, an object with properties. Defined globally, an assembly can be assigned to appear in the `model` of any assembly (another assembly type, or itself), by `assembly` reference.", - name = "define-assembly", - moduleClass = MetaschemaModule.class) - public static class DefineAssembly { + formalName = "Global Field Definition", + name = "define-field", + moduleClass = MetaschemaModelModule.class) + public static class DefineField { @BoundFlag( - formalName = "Global Assembly Name", + formalName = "Global Field Name", name = "name", required = true, typeAdapter = TokenAdapter.class) private String _name; @BoundFlag( - formalName = "Global Assembly Binary Name", + formalName = "Global Field Binary Name", name = "index", typeAdapter = PositiveIntegerAdapter.class) private BigInteger _index; @@ -302,6 +296,39 @@ public static class DefineAssembly { typeAdapter = StringAdapter.class) private String _deprecated; + @BoundFlag( + formalName = "Field Value Data Type", + name = "as-type", + defaultValue = "string", + typeAdapter = TokenAdapter.class, + valueConstraints = @ValueConstraints(allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, + allowOthers = true, + values = { @AllowedValue(value = "markup-line", description = ""), + @AllowedValue(value = "markup-multiline", description = ""), + @AllowedValue(value = "base64", description = ""), @AllowedValue(value = "boolean", description = ""), + @AllowedValue(value = "date", description = ""), @AllowedValue(value = "date-time", description = ""), + @AllowedValue(value = "date-time-with-timezone", description = ""), + @AllowedValue(value = "date-with-timezone", description = ""), + @AllowedValue(value = "day-time-duration", description = ""), + @AllowedValue(value = "decimal", description = ""), + @AllowedValue(value = "email-address", description = ""), + @AllowedValue(value = "hostname", description = ""), @AllowedValue(value = "integer", description = ""), + @AllowedValue(value = "ip-v4-address", description = ""), + @AllowedValue(value = "ip-v6-address", description = ""), + @AllowedValue(value = "non-negative-integer", description = ""), + @AllowedValue(value = "positive-integer", description = ""), + @AllowedValue(value = "string", description = ""), @AllowedValue(value = "token", description = ""), + @AllowedValue(value = "uri", description = ""), + @AllowedValue(value = "uri-reference", description = ""), + @AllowedValue(value = "uuid", description = "") }))) + private String _asType; + + @BoundFlag( + formalName = "Default Field Value", + name = "default", + typeAdapter = StringAdapter.class) + private String _default; + @BoundField( formalName = "Formal Name", description = "A formal name for the data construct, to be presented in documentation.", @@ -319,7 +346,7 @@ public static class DefineAssembly { formalName = "Property", useName = "prop", maxOccurs = -1, - groupAs = @GroupAs(name = "props", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "props", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) private List _props; @BoundField( @@ -328,19 +355,23 @@ public static class DefineAssembly { useName = "use-name") private UseName _useName; - @BoundField( - formalName = "Root Name", - description = "Provides a root name, for when the definition is used as the root of a node hierarchy.", - useName = "root-name", - minOccurs = 1) - private RootName _rootName; - @BoundAssembly( formalName = "JSON Key", description = "Used in JSON (and similar formats) to identify a flag that will be used as the property name in an object hold a collection of sibling objects. Requires that siblings must never share `json-key` values.", useName = "json-key") private JsonKey _jsonKey; + @BoundField( + formalName = "Field Value JSON Property Name", + useName = "json-value-key", + typeAdapter = TokenAdapter.class) + private String _jsonValueKey; + + @BoundAssembly( + formalName = "Flag Used as the Field Value's JSON Property Name", + useName = "json-value-key-flag") + private JsonValueKeyFlag _jsonValueKeyFlag; + @BoundChoiceGroup( maxOccurs = -1, assemblies = { @@ -348,16 +379,12 @@ public static class DefineAssembly { binding = InlineDefineFlag.class), @BoundGroupedAssembly(formalName = "Flag Reference", useName = "flag", binding = FlagReference.class) }, - groupAs = @GroupAs(name = "flags", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "flags", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) private List _flags; - @BoundAssembly( - useName = "model") - private AssemblyModel _model; - @BoundAssembly( useName = "constraint") - private AssemblyConstraints _constraint; + private FieldConstraints _constraint; @BoundField( formalName = "Remarks", @@ -369,7 +396,7 @@ public static class DefineAssembly { formalName = "Example", useName = "example", maxOccurs = -1, - groupAs = @GroupAs(name = "examples", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "examples", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) private List _examples; public String getName() { @@ -404,6 +431,22 @@ public void setDeprecated(String value) { _deprecated = value; } + public String getAsType() { + return _asType; + } + + public void setAsType(String value) { + _asType = value; + } + + public String getDefault() { + return _default; + } + + public void setDefault(String value) { + _default = value; + } + public String getFormalName() { return _formalName; } @@ -464,14 +507,6 @@ public void setUseName(UseName value) { _useName = value; } - public RootName getRootName() { - return _rootName; - } - - public void setRootName(RootName value) { - _rootName = value; - } - public JsonKey getJsonKey() { return _jsonKey; } @@ -480,27 +515,35 @@ public void setJsonKey(JsonKey value) { _jsonKey = value; } - public List getFlags() { - return _flags; + public String getJsonValueKey() { + return _jsonValueKey; } - public void setFlags(List value) { - _flags = value; + public void setJsonValueKey(String value) { + _jsonValueKey = value; } - public AssemblyModel getModel() { - return _model; + public JsonValueKeyFlag getJsonValueKeyFlag() { + return _jsonValueKeyFlag; } - public void setModel(AssemblyModel value) { - _model = value; + public void setJsonValueKeyFlag(JsonValueKeyFlag value) { + _jsonValueKeyFlag = value; } - public AssemblyConstraints getConstraint() { + public List getFlags() { + return _flags; + } + + public void setFlags(List value) { + _flags = value; + } + + public FieldConstraints getConstraint() { return _constraint; } - public void setConstraint(AssemblyConstraints value) { + public void setConstraint(FieldConstraints value) { _constraint = value; } @@ -552,59 +595,12 @@ public boolean removeExample(Example item) { public String toString() { return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); } - - /** - * Provides a root name, for when the definition is used as the root of a node - * hierarchy. - */ - @MetaschemaField( - formalName = "Root Name", - description = "Provides a root name, for when the definition is used as the root of a node hierarchy.", - name = "root-name", - moduleClass = MetaschemaModule.class) - public static class RootName { - /** - * "Used for binary formats instead of the textual name." - */ - @BoundFlag( - formalName = "Numeric Index", - description = "Used for binary formats instead of the textual name.", - name = "index", - typeAdapter = NonNegativeIntegerAdapter.class) - private BigInteger _index; - - @BoundFieldValue( - valueKeyName = "name", - typeAdapter = TokenAdapter.class) - private String _name; - - public BigInteger getIndex() { - return _index; - } - - public void setIndex(BigInteger value) { - _index = value; - } - - public String getName() { - return _name; - } - - public void setName(String value) { - _name = value; - } - - @Override - public String toString() { - return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); - } - } } @MetaschemaAssembly( formalName = "Global Flag Definition", name = "define-flag", - moduleClass = MetaschemaModule.class) + moduleClass = MetaschemaModelModule.class) public static class DefineFlag { @BoundFlag( formalName = "Global Flag Name", @@ -686,7 +682,7 @@ public static class DefineFlag { formalName = "Property", useName = "prop", maxOccurs = -1, - groupAs = @GroupAs(name = "props", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "props", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) private List _props; @BoundField( @@ -709,7 +705,7 @@ public static class DefineFlag { formalName = "Example", useName = "example", maxOccurs = -1, - groupAs = @GroupAs(name = "examples", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "examples", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) private List _examples; public String getName() { @@ -886,7 +882,7 @@ public String toString() { formalName = "Module Import", description = "Imports a set of Metaschema modules contained in another resource. Imports support the reuse of common information structures.", name = "import", - moduleClass = MetaschemaModule.class) + moduleClass = MetaschemaModelModule.class) public static class Import { /** * "A relative or absolute URI for retrieving an out-of-line Metaschema @@ -914,20 +910,27 @@ public String toString() { } } + /** + * In XML, an element with structured element content. In JSON, an object with + * properties. Defined globally, an assembly can be assigned to appear in the + * model of any assembly (another assembly type, or itself), by + * assembly reference. + */ @MetaschemaAssembly( - formalName = "Global Field Definition", - name = "define-field", - moduleClass = MetaschemaModule.class) - public static class DefineField { + formalName = "Global Assembly Definition", + description = "In XML, an element with structured element content. In JSON, an object with properties. Defined globally, an assembly can be assigned to appear in the `model` of any assembly (another assembly type, or itself), by `assembly` reference.", + name = "define-assembly", + moduleClass = MetaschemaModelModule.class) + public static class DefineAssembly { @BoundFlag( - formalName = "Global Field Name", + formalName = "Global Assembly Name", name = "name", required = true, typeAdapter = TokenAdapter.class) private String _name; @BoundFlag( - formalName = "Global Field Binary Name", + formalName = "Global Assembly Binary Name", name = "index", typeAdapter = PositiveIntegerAdapter.class) private BigInteger _index; @@ -950,39 +953,6 @@ public static class DefineField { typeAdapter = StringAdapter.class) private String _deprecated; - @BoundFlag( - formalName = "Field Value Data Type", - name = "as-type", - defaultValue = "string", - typeAdapter = TokenAdapter.class, - valueConstraints = @ValueConstraints(allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, - allowOthers = true, - values = { @AllowedValue(value = "markup-line", description = ""), - @AllowedValue(value = "markup-multiline", description = ""), - @AllowedValue(value = "base64", description = ""), @AllowedValue(value = "boolean", description = ""), - @AllowedValue(value = "date", description = ""), @AllowedValue(value = "date-time", description = ""), - @AllowedValue(value = "date-time-with-timezone", description = ""), - @AllowedValue(value = "date-with-timezone", description = ""), - @AllowedValue(value = "day-time-duration", description = ""), - @AllowedValue(value = "decimal", description = ""), - @AllowedValue(value = "email-address", description = ""), - @AllowedValue(value = "hostname", description = ""), @AllowedValue(value = "integer", description = ""), - @AllowedValue(value = "ip-v4-address", description = ""), - @AllowedValue(value = "ip-v6-address", description = ""), - @AllowedValue(value = "non-negative-integer", description = ""), - @AllowedValue(value = "positive-integer", description = ""), - @AllowedValue(value = "string", description = ""), @AllowedValue(value = "token", description = ""), - @AllowedValue(value = "uri", description = ""), - @AllowedValue(value = "uri-reference", description = ""), - @AllowedValue(value = "uuid", description = "") }))) - private String _asType; - - @BoundFlag( - formalName = "Default Field Value", - name = "default", - typeAdapter = StringAdapter.class) - private String _default; - @BoundField( formalName = "Formal Name", description = "A formal name for the data construct, to be presented in documentation.", @@ -1000,7 +970,7 @@ public static class DefineField { formalName = "Property", useName = "prop", maxOccurs = -1, - groupAs = @GroupAs(name = "props", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "props", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) private List _props; @BoundField( @@ -1009,23 +979,19 @@ public static class DefineField { useName = "use-name") private UseName _useName; + @BoundField( + formalName = "Root Name", + description = "Provides a root name, for when the definition is used as the root of a node hierarchy.", + useName = "root-name", + minOccurs = 1) + private RootName _rootName; + @BoundAssembly( formalName = "JSON Key", description = "Used in JSON (and similar formats) to identify a flag that will be used as the property name in an object hold a collection of sibling objects. Requires that siblings must never share `json-key` values.", useName = "json-key") private JsonKey _jsonKey; - @BoundField( - formalName = "Field Value JSON Property Name", - useName = "json-value-key", - typeAdapter = TokenAdapter.class) - private String _jsonValueKey; - - @BoundAssembly( - formalName = "Flag Used as the Field Value's JSON Property Name", - useName = "json-value-key-flag") - private JsonValueKeyFlag _jsonValueKeyFlag; - @BoundChoiceGroup( maxOccurs = -1, assemblies = { @@ -1033,12 +999,16 @@ public static class DefineField { binding = InlineDefineFlag.class), @BoundGroupedAssembly(formalName = "Flag Reference", useName = "flag", binding = FlagReference.class) }, - groupAs = @GroupAs(name = "flags", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "flags", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) private List _flags; + @BoundAssembly( + useName = "model") + private AssemblyModel _model; + @BoundAssembly( useName = "constraint") - private FieldConstraints _constraint; + private AssemblyConstraints _constraint; @BoundField( formalName = "Remarks", @@ -1050,7 +1020,7 @@ public static class DefineField { formalName = "Example", useName = "example", maxOccurs = -1, - groupAs = @GroupAs(name = "examples", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "examples", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) private List _examples; public String getName() { @@ -1085,22 +1055,6 @@ public void setDeprecated(String value) { _deprecated = value; } - public String getAsType() { - return _asType; - } - - public void setAsType(String value) { - _asType = value; - } - - public String getDefault() { - return _default; - } - - public void setDefault(String value) { - _default = value; - } - public String getFormalName() { return _formalName; } @@ -1161,28 +1115,20 @@ public void setUseName(UseName value) { _useName = value; } - public JsonKey getJsonKey() { - return _jsonKey; - } - - public void setJsonKey(JsonKey value) { - _jsonKey = value; - } - - public String getJsonValueKey() { - return _jsonValueKey; + public RootName getRootName() { + return _rootName; } - public void setJsonValueKey(String value) { - _jsonValueKey = value; + public void setRootName(RootName value) { + _rootName = value; } - public JsonValueKeyFlag getJsonValueKeyFlag() { - return _jsonValueKeyFlag; + public JsonKey getJsonKey() { + return _jsonKey; } - public void setJsonValueKeyFlag(JsonValueKeyFlag value) { - _jsonValueKeyFlag = value; + public void setJsonKey(JsonKey value) { + _jsonKey = value; } public List getFlags() { @@ -1193,11 +1139,19 @@ public void setFlags(List value) { _flags = value; } - public FieldConstraints getConstraint() { + public AssemblyModel getModel() { + return _model; + } + + public void setModel(AssemblyModel value) { + _model = value; + } + + public AssemblyConstraints getConstraint() { return _constraint; } - public void setConstraint(FieldConstraints value) { + public void setConstraint(AssemblyConstraints value) { _constraint = value; } @@ -1249,5 +1203,52 @@ public boolean removeExample(Example item) { public String toString() { return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); } + + /** + * Provides a root name, for when the definition is used as the root of a node + * hierarchy. + */ + @MetaschemaField( + formalName = "Root Name", + description = "Provides a root name, for when the definition is used as the root of a node hierarchy.", + name = "root-name", + moduleClass = MetaschemaModelModule.class) + public static class RootName { + /** + * "Used for binary formats instead of the textual name." + */ + @BoundFlag( + formalName = "Numeric Index", + description = "Used for binary formats instead of the textual name.", + name = "index", + typeAdapter = NonNegativeIntegerAdapter.class) + private BigInteger _index; + + @BoundFieldValue( + valueKeyName = "name", + typeAdapter = TokenAdapter.class) + private String _name; + + public BigInteger getIndex() { + return _index; + } + + public void setIndex(BigInteger value) { + _index = value; + } + + public String getName() { + return _name; + } + + public void setName(String value) { + _name = value; + } + + @Override + public String toString() { + return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); + } + } } } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/MetapathContext.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/MetapathContext.java new file mode 100644 index 000000000..8b45aac63 --- /dev/null +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/MetapathContext.java @@ -0,0 +1,135 @@ +/* + * 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.databind.model.metaschema.binding; + +import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior; +import gov.nist.secauto.metaschema.core.util.ObjectUtils; +import gov.nist.secauto.metaschema.databind.model.annotations.BoundAssembly; +import gov.nist.secauto.metaschema.databind.model.annotations.BoundField; +import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs; +import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; + +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import java.util.LinkedList; +import java.util.List; + +@SuppressWarnings({ + "PMD.DataClass", + "PMD.FieldNamingConventions", +}) +@MetaschemaAssembly( + name = "metapath-context", + moduleClass = MetaschemaModelModule.class) +public class MetapathContext { + @BoundField( + description = "A Metapath expression identifying the model node that the constraints will be applied to.", + useName = "metapath") + private String _metapath; + + @BoundAssembly( + useName = "constraints") + private AssemblyConstraints _constraints; + + @BoundAssembly( + useName = "metapath-context", + maxOccurs = -1, + groupAs = @GroupAs(name = "metapath-contexts", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + private List _metapathContexts; + + @BoundField( + formalName = "Remarks", + description = "Any explanatory or helpful information to be provided about the remarks parent.", + useName = "remarks") + private Remarks _remarks; + + public String getMetapath() { + return _metapath; + } + + public void setMetapath(String value) { + _metapath = value; + } + + public AssemblyConstraints getConstraints() { + return _constraints; + } + + public void setConstraints(AssemblyConstraints value) { + _constraints = value; + } + + public List getMetapathContexts() { + return _metapathContexts; + } + + public void setMetapathContexts(List value) { + _metapathContexts = value; + } + + /** + * Add a new {@link MetapathContext} item to the underlying collection. + * + * @param item + * the item to add + * @return {@code true} + */ + public boolean addMetapathContext(MetapathContext item) { + MetapathContext value = ObjectUtils.requireNonNull(item, "item cannot be null"); + if (_metapathContexts == null) { + _metapathContexts = new LinkedList<>(); + } + return _metapathContexts.add(value); + } + + /** + * Remove the first matching {@link MetapathContext} item from the underlying + * collection. + * + * @param item + * the item to remove + * @return {@code true} if the item was removed or {@code false} otherwise + */ + public boolean removeMetapathContext(MetapathContext item) { + MetapathContext value = ObjectUtils.requireNonNull(item, "item cannot be null"); + return _metapathContexts != null && _metapathContexts.remove(value); + } + + public Remarks getRemarks() { + return _remarks; + } + + public void setRemarks(Remarks value) { + _remarks = value; + } + + @Override + public String toString() { + return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); + } +} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/MetaschemaMetaConstraints.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/MetaschemaMetaConstraints.java new file mode 100644 index 000000000..364eaaa60 --- /dev/null +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/MetaschemaMetaConstraints.java @@ -0,0 +1,262 @@ +/* + * 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.databind.model.metaschema.binding; + +import gov.nist.secauto.metaschema.core.datatype.adapter.TokenAdapter; +import gov.nist.secauto.metaschema.core.datatype.adapter.UriAdapter; +import gov.nist.secauto.metaschema.core.datatype.adapter.UriReferenceAdapter; +import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior; +import gov.nist.secauto.metaschema.core.util.ObjectUtils; +import gov.nist.secauto.metaschema.databind.model.annotations.BoundAssembly; +import gov.nist.secauto.metaschema.databind.model.annotations.BoundField; +import gov.nist.secauto.metaschema.databind.model.annotations.BoundFlag; +import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs; +import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; + +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import java.net.URI; +import java.util.LinkedList; +import java.util.List; + +/** + * Defines constraint rules to be applied to an existing set of Metaschema + * module-based models. + */ +@SuppressWarnings({ + "PMD.DataClass", + "PMD.FieldNamingConventions", +}) +@MetaschemaAssembly( + formalName = "External Module Constraints", + description = "Defines constraint rules to be applied to an existing set of Metaschema module-based models.", + name = "metaschema-meta-constraints", + moduleClass = MetaschemaModelModule.class, + rootName = "metaschema-meta-constraints") +public class MetaschemaMetaConstraints { + @BoundAssembly( + description = "Declares a set of Metaschema constraints from an out-of-line resource to import, supporting composition of constraint sets.", + useName = "import", + maxOccurs = -1, + groupAs = @GroupAs(name = "imports", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + private List _imports; + + @BoundAssembly( + useName = "definition-context") + private DefinitionContext _definitionContext; + + @BoundAssembly( + useName = "metapath-context", + minOccurs = 1, + maxOccurs = -1, + groupAs = @GroupAs(name = "metapath-contexts", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + private List _metapathContexts; + + public List getImports() { + return _imports; + } + + public void setImports(List value) { + _imports = value; + } + + /** + * Add a new {@link Import} item to the underlying collection. + * + * @param item + * the item to add + * @return {@code true} + */ + public boolean addImport(Import item) { + Import value = ObjectUtils.requireNonNull(item, "item cannot be null"); + if (_imports == null) { + _imports = new LinkedList<>(); + } + return _imports.add(value); + } + + /** + * Remove the first matching {@link Import} item from the underlying collection. + * + * @param item + * the item to remove + * @return {@code true} if the item was removed or {@code false} otherwise + */ + public boolean removeImport(Import item) { + Import value = ObjectUtils.requireNonNull(item, "item cannot be null"); + return _imports != null && _imports.remove(value); + } + + public DefinitionContext getDefinitionContext() { + return _definitionContext; + } + + public void setDefinitionContext(DefinitionContext value) { + _definitionContext = value; + } + + public List getMetapathContexts() { + return _metapathContexts; + } + + public void setMetapathContexts(List value) { + _metapathContexts = value; + } + + /** + * Add a new {@link MetapathContext} item to the underlying collection. + * + * @param item + * the item to add + * @return {@code true} + */ + public boolean addMetapathContext(MetapathContext item) { + MetapathContext value = ObjectUtils.requireNonNull(item, "item cannot be null"); + if (_metapathContexts == null) { + _metapathContexts = new LinkedList<>(); + } + return _metapathContexts.add(value); + } + + /** + * Remove the first matching {@link MetapathContext} item from the underlying + * collection. + * + * @param item + * the item to remove + * @return {@code true} if the item was removed or {@code false} otherwise + */ + public boolean removeMetapathContext(MetapathContext item) { + MetapathContext value = ObjectUtils.requireNonNull(item, "item cannot be null"); + return _metapathContexts != null && _metapathContexts.remove(value); + } + + @Override + public String toString() { + return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); + } + + @MetaschemaAssembly( + name = "definition-context", + moduleClass = MetaschemaModelModule.class) + public static class DefinitionContext { + @BoundFlag( + name = "name", + required = true, + typeAdapter = TokenAdapter.class) + private String _name; + + @BoundFlag( + name = "namespace", + required = true, + typeAdapter = UriAdapter.class) + private URI _namespace; + + @BoundAssembly( + useName = "constraints", + minOccurs = 1) + private AssemblyConstraints _constraints; + + @BoundField( + formalName = "Remarks", + description = "Any explanatory or helpful information to be provided about the remarks parent.", + useName = "remarks") + private Remarks _remarks; + + public String getName() { + return _name; + } + + public void setName(String value) { + _name = value; + } + + public URI getNamespace() { + return _namespace; + } + + public void setNamespace(URI value) { + _namespace = value; + } + + public AssemblyConstraints getConstraints() { + return _constraints; + } + + public void setConstraints(AssemblyConstraints value) { + _constraints = value; + } + + public Remarks getRemarks() { + return _remarks; + } + + public void setRemarks(Remarks value) { + _remarks = value; + } + + @Override + public String toString() { + return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); + } + } + + /** + * Declares a set of Metaschema constraints from an out-of-line resource to + * import, supporting composition of constraint sets. + */ + @MetaschemaAssembly( + description = "Declares a set of Metaschema constraints from an out-of-line resource to import, supporting composition of constraint sets.", + name = "import", + moduleClass = MetaschemaModelModule.class) + public static class Import { + /** + * "A relative or absolute URI for retrieving an out-of-line Metaschema + * constraint definition." + */ + @BoundFlag( + description = "A relative or absolute URI for retrieving an out-of-line Metaschema constraint definition.", + name = "href", + required = true, + typeAdapter = UriReferenceAdapter.class) + private URI _href; + + public URI getHref() { + return _href; + } + + public void setHref(URI value) { + _href = value; + } + + @Override + public String toString() { + return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); + } + } +} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/MetaschemaModule.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/MetaschemaModelModule.java similarity index 81% rename from databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/MetaschemaModule.java rename to databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/MetaschemaModelModule.java index 98887b8c3..dc234b77a 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/MetaschemaModule.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/MetaschemaModelModule.java @@ -28,7 +28,6 @@ import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine; import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline; -import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.metaschema.databind.IBindingContext; import gov.nist.secauto.metaschema.databind.model.AbstractBoundModule; import gov.nist.secauto.metaschema.databind.model.IBoundModule; @@ -37,8 +36,6 @@ import java.net.URI; import java.util.List; -import edu.umd.cs.findbugs.annotations.NonNull; - @Module( fields = { UseName.class, @@ -64,32 +61,36 @@ FieldConstraints.class, FlagConstraints.class, ConstraintLetExpression.class, + FlagAllowedValues.class, + FlagExpect.class, + FlagIndexHasKey.class, + FlagMatches.class, TargetedAllowedValuesConstraint.class, TargetedMatchesConstraint.class, TargetedExpectConstraint.class, TargetedIndexHasKeyConstraint.class, - KeyConstraintField.class + KeyConstraintField.class, + TargetedIsUniqueConstraint.class, + TargetedIndexConstraint.class, + TargetedHasCardinalityConstraint.class, + MetaschemaModuleConstraints.class, + MetaschemaMetaConstraints.class, + MetapathContext.class }) -public final class MetaschemaModule +public final class MetaschemaModelModule extends AbstractBoundModule { - @NonNull private static final MarkupLine NAME = MarkupLine.fromMarkdown("Metaschema Model"); - private static final String SHORT_NAME = "metaschema"; + private static final String SHORT_NAME = "metaschema-model"; private static final String VERSION = "1.0.0-M2"; - @NonNull - private static final URI XML_NAMESPACE = ObjectUtils.notNull( - URI.create("http://csrc.nist.gov/ns/oscal/metaschema/1.0")); + private static final URI XML_NAMESPACE = URI.create("http://csrc.nist.gov/ns/oscal/metaschema/1.0"); - @NonNull - private static final URI JSON_BASE_URI = ObjectUtils.notNull( - URI.create("http://csrc.nist.gov/ns/oscal/metaschema/1.0")); + private static final URI JSON_BASE_URI = URI.create("http://csrc.nist.gov/ns/oscal/metaschema/1.0"); - public MetaschemaModule( - @NonNull List importedModules, - @NonNull IBindingContext bindingContext) { + public MetaschemaModelModule(List importedModules, + IBindingContext bindingContext) { super(importedModules, bindingContext); } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/MetaschemaModuleConstraints.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/MetaschemaModuleConstraints.java new file mode 100644 index 000000000..8cb06b839 --- /dev/null +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/MetaschemaModuleConstraints.java @@ -0,0 +1,440 @@ +/* + * 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.databind.model.metaschema.binding; + +import gov.nist.secauto.metaschema.core.datatype.adapter.StringAdapter; +import gov.nist.secauto.metaschema.core.datatype.adapter.TokenAdapter; +import gov.nist.secauto.metaschema.core.datatype.adapter.UriAdapter; +import gov.nist.secauto.metaschema.core.datatype.adapter.UriReferenceAdapter; +import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior; +import gov.nist.secauto.metaschema.core.util.ObjectUtils; +import gov.nist.secauto.metaschema.databind.model.annotations.BoundAssembly; +import gov.nist.secauto.metaschema.databind.model.annotations.BoundChoiceGroup; +import gov.nist.secauto.metaschema.databind.model.annotations.BoundField; +import gov.nist.secauto.metaschema.databind.model.annotations.BoundFlag; +import gov.nist.secauto.metaschema.databind.model.annotations.BoundGroupedAssembly; +import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs; +import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; + +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import java.net.URI; +import java.util.LinkedList; +import java.util.List; + +/** + * Defines constraint rules to be applied to an existing set of Metaschema + * module-based models. + */ +@SuppressWarnings({ + "PMD.DataClass", + "PMD.FieldNamingConventions", + "PMD.ShortClassName" +}) +@MetaschemaAssembly( + formalName = "External Module Constraints", + description = "Defines constraint rules to be applied to an existing set of Metaschema module-based models.", + name = "metaschema-module-constraints", + moduleClass = MetaschemaModelModule.class, + rootName = "METASCHEMA-CONSTRAINTS") +public class MetaschemaModuleConstraints { + @BoundField( + description = "The name of this constraint set.", + useName = "name", + minOccurs = 1) + private String _name; + + @BoundField( + description = "The version of this constraint set. A version string used to distinguish between multiple revisions of the same resource.", + useName = "version", + minOccurs = 1) + private String _version; + + @BoundAssembly( + description = "Declares a set of Metaschema constraints from an out-of-line resource to import, supporting composition of constraint sets.", + useName = "import", + maxOccurs = -1, + groupAs = @GroupAs(name = "imports", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + private List _imports; + + @BoundAssembly( + useName = "scope", + minOccurs = 1, + maxOccurs = -1, + groupAs = @GroupAs(name = "scopes", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + private List _scopes; + + public String getName() { + return _name; + } + + public void setName(String value) { + _name = value; + } + + public String getVersion() { + return _version; + } + + public void setVersion(String value) { + _version = value; + } + + public List getImports() { + return _imports; + } + + public void setImports(List value) { + _imports = value; + } + + /** + * Add a new {@link Import} item to the underlying collection. + * + * @param item + * the item to add + * @return {@code true} + */ + public boolean addImport(Import item) { + Import value = ObjectUtils.requireNonNull(item, "item cannot be null"); + if (_imports == null) { + _imports = new LinkedList<>(); + } + return _imports.add(value); + } + + /** + * Remove the first matching {@link Import} item from the underlying collection. + * + * @param item + * the item to remove + * @return {@code true} if the item was removed or {@code false} otherwise + */ + public boolean removeImport(Import item) { + Import value = ObjectUtils.requireNonNull(item, "item cannot be null"); + return _imports != null && _imports.remove(value); + } + + public List getScopes() { + return _scopes; + } + + public void setScopes(List value) { + _scopes = value; + } + + /** + * Add a new {@link Scope} item to the underlying collection. + * + * @param item + * the item to add + * @return {@code true} + */ + public boolean addScope(Scope item) { + Scope value = ObjectUtils.requireNonNull(item, "item cannot be null"); + if (_scopes == null) { + _scopes = new LinkedList<>(); + } + return _scopes.add(value); + } + + /** + * Remove the first matching {@link Scope} item from the underlying collection. + * + * @param item + * the item to remove + * @return {@code true} if the item was removed or {@code false} otherwise + */ + public boolean removeScope(Scope item) { + Scope value = ObjectUtils.requireNonNull(item, "item cannot be null"); + return _scopes != null && _scopes.remove(value); + } + + @Override + public String toString() { + return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); + } + + @MetaschemaAssembly( + name = "scope", + moduleClass = MetaschemaModelModule.class) + public static class Scope { + @BoundFlag( + name = "metaschema-namespace", + required = true, + typeAdapter = UriAdapter.class) + private URI _metaschemaNamespace; + + @BoundFlag( + name = "metaschema-short-name", + required = true, + typeAdapter = TokenAdapter.class) + private String _metaschemaShortName; + + @BoundChoiceGroup( + minOccurs = 1, + maxOccurs = -1, + assemblies = { + @BoundGroupedAssembly(useName = "assembly", binding = Assembly.class), + @BoundGroupedAssembly(useName = "field", binding = Field.class), + @BoundGroupedAssembly(useName = "flag", binding = Flag.class) + }, + groupAs = @GroupAs(name = "constraints", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + private List _constraints; + + @BoundField( + formalName = "Remarks", + description = "Any explanatory or helpful information to be provided about the remarks parent.", + useName = "remarks") + private Remarks _remarks; + + public URI getMetaschemaNamespace() { + return _metaschemaNamespace; + } + + public void setMetaschemaNamespace(URI value) { + _metaschemaNamespace = value; + } + + public String getMetaschemaShortName() { + return _metaschemaShortName; + } + + public void setMetaschemaShortName(String value) { + _metaschemaShortName = value; + } + + public List getConstraints() { + return _constraints; + } + + public void setConstraints(List value) { + _constraints = value; + } + + public Remarks getRemarks() { + return _remarks; + } + + public void setRemarks(Remarks value) { + _remarks = value; + } + + @Override + public String toString() { + return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); + } + + @MetaschemaAssembly( + name = "flag", + moduleClass = MetaschemaModelModule.class) + public static class Flag { + @BoundFlag( + formalName = "Constraint Target Metapath Expression", + name = "target", + required = true, + typeAdapter = StringAdapter.class) + private String _target; + + @BoundChoiceGroup( + minOccurs = 1, + maxOccurs = -1, + assemblies = { + @BoundGroupedAssembly(formalName = "Allowed Values Constraint", useName = "allowed-values", + binding = FlagAllowedValues.class), + @BoundGroupedAssembly(formalName = "Expect Condition Constraint", useName = "expect", + binding = FlagExpect.class), + @BoundGroupedAssembly(formalName = "Index Has Key Constraint", useName = "index-has-key", + binding = FlagIndexHasKey.class), + @BoundGroupedAssembly(formalName = "Value Matches Constraint", useName = "matches", + binding = FlagMatches.class) + }, + groupAs = @GroupAs(name = "rules", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + private List _rules; + + public String getTarget() { + return _target; + } + + public void setTarget(String value) { + _target = value; + } + + public List getRules() { + return _rules; + } + + public void setRules(List value) { + _rules = value; + } + + @Override + public String toString() { + return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); + } + } + + @MetaschemaAssembly( + name = "field", + moduleClass = MetaschemaModelModule.class) + public static class Field { + @BoundFlag( + formalName = "Constraint Target Metapath Expression", + name = "target", + required = true, + typeAdapter = StringAdapter.class) + private String _target; + + @BoundChoiceGroup( + minOccurs = 1, + maxOccurs = -1, + assemblies = { + @BoundGroupedAssembly(formalName = "Allowed Values Constraint", useName = "allowed-values", + binding = TargetedAllowedValuesConstraint.class), + @BoundGroupedAssembly(formalName = "Expect Condition Constraint", useName = "expect", + binding = TargetedExpectConstraint.class), + @BoundGroupedAssembly(formalName = "Targeted Index Has Key Constraint", useName = "index-has-key", + binding = TargetedIndexHasKeyConstraint.class), + @BoundGroupedAssembly(formalName = "Value Matches Constraint", useName = "matches", + binding = TargetedMatchesConstraint.class) + }, + groupAs = @GroupAs(name = "rules", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + private List _rules; + + public String getTarget() { + return _target; + } + + public void setTarget(String value) { + _target = value; + } + + public List getRules() { + return _rules; + } + + public void setRules(List value) { + _rules = value; + } + + @Override + public String toString() { + return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); + } + } + + @MetaschemaAssembly( + name = "assembly", + moduleClass = MetaschemaModelModule.class) + public static class Assembly { + @BoundFlag( + formalName = "Constraint Target Metapath Expression", + name = "target", + required = true, + typeAdapter = StringAdapter.class) + private String _target; + + @BoundChoiceGroup( + minOccurs = 1, + maxOccurs = -1, + assemblies = { + @BoundGroupedAssembly(formalName = "Allowed Values Constraint", useName = "allowed-values", + binding = TargetedAllowedValuesConstraint.class), + @BoundGroupedAssembly(formalName = "Expect Condition Constraint", useName = "expect", + binding = TargetedExpectConstraint.class), + @BoundGroupedAssembly(formalName = "Targeted Index Has Key Constraint", useName = "index-has-key", + binding = TargetedIndexHasKeyConstraint.class), + @BoundGroupedAssembly(formalName = "Value Matches Constraint", useName = "matches", + binding = TargetedMatchesConstraint.class), + @BoundGroupedAssembly(formalName = "Targeted Unique Constraint", useName = "is-unique", + binding = TargetedIsUniqueConstraint.class), + @BoundGroupedAssembly(formalName = "Targeted Index Constraint", useName = "index", + binding = TargetedIndexConstraint.class), + @BoundGroupedAssembly(formalName = "Targeted Cardinality Constraint", useName = "has-cardinality", + binding = TargetedHasCardinalityConstraint.class) + }, + groupAs = @GroupAs(name = "rules", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + private List _rules; + + public String getTarget() { + return _target; + } + + public void setTarget(String value) { + _target = value; + } + + public List getRules() { + return _rules; + } + + public void setRules(List value) { + _rules = value; + } + + @Override + public String toString() { + return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); + } + } + } + + /** + * Declares a set of Metaschema constraints from an out-of-line resource to + * import, supporting composition of constraint sets. + */ + @MetaschemaAssembly( + description = "Declares a set of Metaschema constraints from an out-of-line resource to import, supporting composition of constraint sets.", + name = "import", + moduleClass = MetaschemaModelModule.class) + public static class Import { + /** + * "A relative or absolute URI for retrieving an out-of-line Metaschema + * constraint definition." + */ + @BoundFlag( + description = "A relative or absolute URI for retrieving an out-of-line Metaschema constraint definition.", + name = "href", + required = true, + typeAdapter = UriReferenceAdapter.class) + private URI _href; + + public URI getHref() { + return _href; + } + + public void setHref(URI value) { + _href = value; + } + + @Override + public String toString() { + return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); + } + } +} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/Property.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/Property.java index 1a0c12b50..7db9f3ac5 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/Property.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/Property.java @@ -30,12 +30,12 @@ import gov.nist.secauto.metaschema.core.datatype.adapter.UriAdapter; import gov.nist.secauto.metaschema.databind.model.annotations.BoundFlag; import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; - +import java.lang.Override; +import java.lang.String; +import java.net.URI; import org.apache.commons.lang3.builder.ReflectionToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; -import java.net.URI; - @SuppressWarnings({ "PMD.DataClass", "PMD.FieldNamingConventions" @@ -43,7 +43,7 @@ @MetaschemaAssembly( formalName = "Property", name = "property", - moduleClass = MetaschemaModule.class) + moduleClass = MetaschemaModelModule.class) public class Property { @BoundFlag( formalName = "Property Name", diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/Remarks.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/Remarks.java index e29127a8a..96baa3998 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/Remarks.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/Remarks.java @@ -36,7 +36,8 @@ import gov.nist.secauto.metaschema.databind.model.annotations.BoundFlag; import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaField; import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints; - +import java.lang.Override; +import java.lang.String; import org.apache.commons.lang3.builder.ReflectionToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; @@ -52,7 +53,7 @@ formalName = "Remarks", description = "Any explanatory or helpful information to be provided about the remarks parent.", name = "remarks", - moduleClass = MetaschemaModule.class) + moduleClass = MetaschemaModelModule.class) public class Remarks { /** * "Mark as ‘XML’ for XML-only or ‘JSON’ for JSON-only diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedAllowedValuesConstraint.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedAllowedValuesConstraint.java index 5984af62e..971151767 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedAllowedValuesConstraint.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedAllowedValuesConstraint.java @@ -56,7 +56,7 @@ @MetaschemaAssembly( formalName = "Allowed Values Constraint", name = "targeted-allowed-values-constraint", - moduleClass = MetaschemaModule.class) + moduleClass = MetaschemaModelModule.class) public class TargetedAllowedValuesConstraint implements ITargetedConstraintBase { @BoundFlag( formalName = "Constraint Identifier", @@ -130,7 +130,7 @@ public class TargetedAllowedValuesConstraint implements ITargetedConstraintBase formalName = "Property", useName = "prop", maxOccurs = -1, - groupAs = @GroupAs(name = "props", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "props", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) private List _props; @BoundField( @@ -138,7 +138,7 @@ public class TargetedAllowedValuesConstraint implements ITargetedConstraintBase useName = "enum", minOccurs = 1, maxOccurs = -1, - groupAs = @GroupAs(name = "enums", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "enums", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) private List _enums; @BoundField( diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedExpectConstraint.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedExpectConstraint.java index 433d1b26c..ddd306fa6 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedExpectConstraint.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedExpectConstraint.java @@ -56,7 +56,7 @@ @MetaschemaAssembly( formalName = "Expect Condition Constraint", name = "targeted-expect-constraint", - moduleClass = MetaschemaModule.class) + moduleClass = MetaschemaModelModule.class) public class TargetedExpectConstraint implements ITargetedConstraintBase { @BoundFlag( formalName = "Constraint Identifier", @@ -111,7 +111,7 @@ public class TargetedExpectConstraint implements ITargetedConstraintBase { formalName = "Property", useName = "prop", maxOccurs = -1, - groupAs = @GroupAs(name = "props", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "props", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) private List _props; @BoundField( diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedHasCardinalityConstraint.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedHasCardinalityConstraint.java new file mode 100644 index 000000000..c20099b25 --- /dev/null +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedHasCardinalityConstraint.java @@ -0,0 +1,244 @@ +/* + * 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.databind.model.metaschema.binding; + +import gov.nist.secauto.metaschema.core.datatype.adapter.NonNegativeIntegerAdapter; +import gov.nist.secauto.metaschema.core.datatype.adapter.StringAdapter; +import gov.nist.secauto.metaschema.core.datatype.adapter.TokenAdapter; +import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine; +import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLineAdapter; +import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior; +import gov.nist.secauto.metaschema.core.model.constraint.IConstraint; +import gov.nist.secauto.metaschema.core.util.ObjectUtils; +import gov.nist.secauto.metaschema.databind.model.annotations.AllowedValue; +import gov.nist.secauto.metaschema.databind.model.annotations.AllowedValues; +import gov.nist.secauto.metaschema.databind.model.annotations.BoundAssembly; +import gov.nist.secauto.metaschema.databind.model.annotations.BoundField; +import gov.nist.secauto.metaschema.databind.model.annotations.BoundFlag; +import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs; +import gov.nist.secauto.metaschema.databind.model.annotations.Matches; +import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; +import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints; +import gov.nist.secauto.metaschema.databind.model.metaschema.ITargetedConstraintBase; + +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import java.math.BigInteger; +import java.util.LinkedList; +import java.util.List; + +@SuppressWarnings({ + "PMD.DataClass", + "PMD.FieldNamingConventions" +}) +@MetaschemaAssembly( + formalName = "Targeted Cardinality Constraint", + name = "targeted-has-cardinality-constraint", + moduleClass = MetaschemaModelModule.class) +public class TargetedHasCardinalityConstraint implements ITargetedConstraintBase { + @BoundFlag( + formalName = "Constraint Identifier", + name = "id", + typeAdapter = TokenAdapter.class) + private String _id; + + @BoundFlag( + formalName = "Constraint Severity Level", + name = "level", + defaultValue = "ERROR", + typeAdapter = TokenAdapter.class, + valueConstraints = @ValueConstraints(allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, values = { + @AllowedValue(value = "CRITICAL", + description = "A violation of the constraint represents a serious fault in the content that will prevent typical use of the content."), + @AllowedValue(value = "ERROR", + description = "A violation of the constraint represents a fault in the content. This may include issues around compatibility, integrity, consistency, etc."), + @AllowedValue(value = "WARNING", + description = "A violation of the constraint represents a potential issue with the content."), + @AllowedValue(value = "INFORMATIONAL", + description = "A violation of the constraint represents a point of interest.") }))) + private String _level; + + @BoundFlag( + formalName = "Minimum Occurrence", + name = "min-occurs", + typeAdapter = NonNegativeIntegerAdapter.class) + private BigInteger _minOccurs; + + @BoundFlag( + formalName = "Maximum Occurrence", + name = "max-occurs", + typeAdapter = StringAdapter.class, + valueConstraints = @ValueConstraints( + matches = @Matches(level = IConstraint.Level.ERROR, pattern = "^[1-9][0-9]*|unbounded$"))) + private String _maxOccurs; + + @BoundFlag( + formalName = "Constraint Target Metapath Expression", + name = "target", + required = true, + typeAdapter = StringAdapter.class) + private String _target; + + @BoundField( + formalName = "Formal Name", + description = "A formal name for the data construct, to be presented in documentation.", + useName = "formal-name") + private String _formalName; + + @BoundField( + formalName = "Description", + description = "A short description of the data construct's purpose, describing the constructs semantics.", + useName = "description", + typeAdapter = MarkupLineAdapter.class) + private MarkupLine _description; + + @BoundAssembly( + formalName = "Property", + useName = "prop", + maxOccurs = -1, + groupAs = @GroupAs(name = "props", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + private List _props; + + @BoundField( + formalName = "Remarks", + description = "Any explanatory or helpful information to be provided about the remarks parent.", + useName = "remarks") + private Remarks _remarks; + + @Override + public String getId() { + return _id; + } + + public void setId(String value) { + _id = value; + } + + @Override + public String getLevel() { + return _level; + } + + public void setLevel(String value) { + _level = value; + } + + public BigInteger getMinOccurs() { + return _minOccurs; + } + + public void setMinOccurs(BigInteger value) { + _minOccurs = value; + } + + public String getMaxOccurs() { + return _maxOccurs; + } + + public void setMaxOccurs(String value) { + _maxOccurs = value; + } + + @Override + public String getTarget() { + return _target; + } + + public void setTarget(String value) { + _target = value; + } + + @Override + public String getFormalName() { + return _formalName; + } + + public void setFormalName(String value) { + _formalName = value; + } + + @Override + public MarkupLine getDescription() { + return _description; + } + + public void setDescription(MarkupLine value) { + _description = value; + } + + @Override + public List getProps() { + return _props; + } + + public void setProps(List value) { + _props = value; + } + + /** + * Add a new {@link Property} item to the underlying collection. + * + * @param item + * the item to add + * @return {@code true} + */ + public boolean addProp(Property item) { + Property value = ObjectUtils.requireNonNull(item, "item cannot be null"); + if (_props == null) { + _props = new LinkedList<>(); + } + return _props.add(value); + } + + /** + * Remove the first matching {@link Property} item from the underlying + * collection. + * + * @param item + * the item to remove + * @return {@code true} if the item was removed or {@code false} otherwise + */ + public boolean removeProp(Property item) { + Property value = ObjectUtils.requireNonNull(item, "item cannot be null"); + return _props != null && _props.remove(value); + } + + @Override + public Remarks getRemarks() { + return _remarks; + } + + public void setRemarks(Remarks value) { + _remarks = value; + } + + @Override + public String toString() { + return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); + } +} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedIndexConstraint.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedIndexConstraint.java new file mode 100644 index 000000000..58d63835c --- /dev/null +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedIndexConstraint.java @@ -0,0 +1,270 @@ +/* + * 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.databind.model.metaschema.binding; + +import gov.nist.secauto.metaschema.core.datatype.adapter.StringAdapter; +import gov.nist.secauto.metaschema.core.datatype.adapter.TokenAdapter; +import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine; +import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLineAdapter; +import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior; +import gov.nist.secauto.metaschema.core.model.constraint.IConstraint; +import gov.nist.secauto.metaschema.core.util.ObjectUtils; +import gov.nist.secauto.metaschema.databind.model.annotations.AllowedValue; +import gov.nist.secauto.metaschema.databind.model.annotations.AllowedValues; +import gov.nist.secauto.metaschema.databind.model.annotations.BoundAssembly; +import gov.nist.secauto.metaschema.databind.model.annotations.BoundField; +import gov.nist.secauto.metaschema.databind.model.annotations.BoundFlag; +import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs; +import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; +import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints; +import gov.nist.secauto.metaschema.databind.model.metaschema.ITargetedConstraintBase; + +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import java.util.LinkedList; +import java.util.List; + +@SuppressWarnings({ + "PMD.DataClass", + "PMD.FieldNamingConventions" +}) +@MetaschemaAssembly( + formalName = "Targeted Index Constraint", + name = "targeted-index-constraint", + moduleClass = MetaschemaModelModule.class) +public class TargetedIndexConstraint implements ITargetedConstraintBase { + @BoundFlag( + formalName = "Constraint Identifier", + name = "id", + typeAdapter = TokenAdapter.class) + private String _id; + + @BoundFlag( + formalName = "Constraint Severity Level", + name = "level", + defaultValue = "ERROR", + typeAdapter = TokenAdapter.class, + valueConstraints = @ValueConstraints(allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, values = { + @AllowedValue(value = "CRITICAL", + description = "A violation of the constraint represents a serious fault in the content that will prevent typical use of the content."), + @AllowedValue(value = "ERROR", + description = "A violation of the constraint represents a fault in the content. This may include issues around compatibility, integrity, consistency, etc."), + @AllowedValue(value = "WARNING", + description = "A violation of the constraint represents a potential issue with the content."), + @AllowedValue(value = "INFORMATIONAL", + description = "A violation of the constraint represents a point of interest.") }))) + private String _level; + + @BoundFlag( + formalName = "Index Name", + name = "name", + required = true, + typeAdapter = TokenAdapter.class) + private String _name; + + @BoundFlag( + formalName = "Constraint Target Metapath Expression", + name = "target", + required = true, + typeAdapter = StringAdapter.class) + private String _target; + + @BoundField( + formalName = "Formal Name", + description = "A formal name for the data construct, to be presented in documentation.", + useName = "formal-name") + private String _formalName; + + @BoundField( + formalName = "Description", + description = "A short description of the data construct's purpose, describing the constructs semantics.", + useName = "description", + typeAdapter = MarkupLineAdapter.class) + private MarkupLine _description; + + @BoundAssembly( + formalName = "Property", + useName = "prop", + maxOccurs = -1, + groupAs = @GroupAs(name = "props", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + private List _props; + + @BoundAssembly( + formalName = "Key Constraint Field", + useName = "key-field", + minOccurs = 1, + maxOccurs = -1, + groupAs = @GroupAs(name = "key-fields", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + private List _keyFields; + + @BoundField( + formalName = "Remarks", + description = "Any explanatory or helpful information to be provided about the remarks parent.", + useName = "remarks") + private Remarks _remarks; + + @Override + public String getId() { + return _id; + } + + public void setId(String value) { + _id = value; + } + + @Override + public String getLevel() { + return _level; + } + + public void setLevel(String value) { + _level = value; + } + + public String getName() { + return _name; + } + + public void setName(String value) { + _name = value; + } + + @Override + public String getTarget() { + return _target; + } + + public void setTarget(String value) { + _target = value; + } + + @Override + public String getFormalName() { + return _formalName; + } + + public void setFormalName(String value) { + _formalName = value; + } + + @Override + public MarkupLine getDescription() { + return _description; + } + + public void setDescription(MarkupLine value) { + _description = value; + } + + @Override + public List getProps() { + return _props; + } + + public void setProps(List value) { + _props = value; + } + + /** + * Add a new {@link Property} item to the underlying collection. + * + * @param item + * the item to add + * @return {@code true} + */ + public boolean addProp(Property item) { + Property value = ObjectUtils.requireNonNull(item, "item cannot be null"); + if (_props == null) { + _props = new LinkedList<>(); + } + return _props.add(value); + } + + /** + * Remove the first matching {@link Property} item from the underlying + * collection. + * + * @param item + * the item to remove + * @return {@code true} if the item was removed or {@code false} otherwise + */ + public boolean removeProp(Property item) { + Property value = ObjectUtils.requireNonNull(item, "item cannot be null"); + return _props != null && _props.remove(value); + } + + public List getKeyFields() { + return _keyFields; + } + + public void setKeyFields(List value) { + _keyFields = value; + } + + /** + * Add a new {@link KeyConstraintField} item to the underlying collection. + * + * @param item + * the item to add + * @return {@code true} + */ + public boolean addKeyField(KeyConstraintField item) { + KeyConstraintField value = ObjectUtils.requireNonNull(item, "item cannot be null"); + if (_keyFields == null) { + _keyFields = new LinkedList<>(); + } + return _keyFields.add(value); + } + + /** + * Remove the first matching {@link KeyConstraintField} item from the underlying + * collection. + * + * @param item + * the item to remove + * @return {@code true} if the item was removed or {@code false} otherwise + */ + public boolean removeKeyField(KeyConstraintField item) { + KeyConstraintField value = ObjectUtils.requireNonNull(item, "item cannot be null"); + return _keyFields != null && _keyFields.remove(value); + } + + @Override + public Remarks getRemarks() { + return _remarks; + } + + public void setRemarks(Remarks value) { + _remarks = value; + } + + @Override + public String toString() { + return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); + } +} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedIndexHasKeyConstraint.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedIndexHasKeyConstraint.java index d3988b064..8dd650d3d 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedIndexHasKeyConstraint.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedIndexHasKeyConstraint.java @@ -56,7 +56,7 @@ @MetaschemaAssembly( formalName = "Targeted Index Has Key Constraint", name = "targeted-index-has-key-constraint", - moduleClass = MetaschemaModule.class) + moduleClass = MetaschemaModelModule.class) public class TargetedIndexHasKeyConstraint implements ITargetedConstraintBase { @BoundFlag( formalName = "Constraint Identifier", @@ -111,7 +111,7 @@ public class TargetedIndexHasKeyConstraint implements ITargetedConstraintBase { formalName = "Property", useName = "prop", maxOccurs = -1, - groupAs = @GroupAs(name = "props", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "props", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) private List _props; @BoundAssembly( @@ -119,7 +119,7 @@ public class TargetedIndexHasKeyConstraint implements ITargetedConstraintBase { useName = "key-field", minOccurs = 1, maxOccurs = -1, - groupAs = @GroupAs(name = "key-fields", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "key-fields", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) private List _keyFields; @BoundField( diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedIsUniqueConstraint.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedIsUniqueConstraint.java new file mode 100644 index 000000000..c4cc2e4b9 --- /dev/null +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedIsUniqueConstraint.java @@ -0,0 +1,255 @@ +/* + * 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.databind.model.metaschema.binding; + +import gov.nist.secauto.metaschema.core.datatype.adapter.StringAdapter; +import gov.nist.secauto.metaschema.core.datatype.adapter.TokenAdapter; +import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine; +import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLineAdapter; +import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior; +import gov.nist.secauto.metaschema.core.model.constraint.IConstraint; +import gov.nist.secauto.metaschema.core.util.ObjectUtils; +import gov.nist.secauto.metaschema.databind.model.annotations.AllowedValue; +import gov.nist.secauto.metaschema.databind.model.annotations.AllowedValues; +import gov.nist.secauto.metaschema.databind.model.annotations.BoundAssembly; +import gov.nist.secauto.metaschema.databind.model.annotations.BoundField; +import gov.nist.secauto.metaschema.databind.model.annotations.BoundFlag; +import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs; +import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; +import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints; +import gov.nist.secauto.metaschema.databind.model.metaschema.ITargetedConstraintBase; + +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import java.util.LinkedList; +import java.util.List; + +@SuppressWarnings({ + "PMD.DataClass", + "PMD.FieldNamingConventions" +}) +@MetaschemaAssembly( + formalName = "Targeted Unique Constraint", + name = "targeted-is-unique-constraint", + moduleClass = MetaschemaModelModule.class) +public class TargetedIsUniqueConstraint implements ITargetedConstraintBase { + @BoundFlag( + formalName = "Constraint Identifier", + name = "id", + typeAdapter = TokenAdapter.class) + private String _id; + + @BoundFlag( + formalName = "Constraint Severity Level", + name = "level", + defaultValue = "ERROR", + typeAdapter = TokenAdapter.class, + valueConstraints = @ValueConstraints(allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, values = { + @AllowedValue(value = "CRITICAL", + description = "A violation of the constraint represents a serious fault in the content that will prevent typical use of the content."), + @AllowedValue(value = "ERROR", + description = "A violation of the constraint represents a fault in the content. This may include issues around compatibility, integrity, consistency, etc."), + @AllowedValue(value = "WARNING", + description = "A violation of the constraint represents a potential issue with the content."), + @AllowedValue(value = "INFORMATIONAL", + description = "A violation of the constraint represents a point of interest.") }))) + private String _level; + + @BoundFlag( + formalName = "Constraint Target Metapath Expression", + name = "target", + required = true, + typeAdapter = StringAdapter.class) + private String _target; + + @BoundField( + formalName = "Formal Name", + description = "A formal name for the data construct, to be presented in documentation.", + useName = "formal-name") + private String _formalName; + + @BoundField( + formalName = "Description", + description = "A short description of the data construct's purpose, describing the constructs semantics.", + useName = "description", + typeAdapter = MarkupLineAdapter.class) + private MarkupLine _description; + + @BoundAssembly( + formalName = "Property", + useName = "prop", + maxOccurs = -1, + groupAs = @GroupAs(name = "props", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + private List _props; + + @BoundAssembly( + formalName = "Key Constraint Field", + useName = "key-field", + minOccurs = 1, + maxOccurs = -1, + groupAs = @GroupAs(name = "key-fields", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + private List _keyFields; + + @BoundField( + formalName = "Remarks", + description = "Any explanatory or helpful information to be provided about the remarks parent.", + useName = "remarks") + private Remarks _remarks; + + @Override + public String getId() { + return _id; + } + + public void setId(String value) { + _id = value; + } + + @Override + public String getLevel() { + return _level; + } + + public void setLevel(String value) { + _level = value; + } + + @Override + public String getTarget() { + return _target; + } + + public void setTarget(String value) { + _target = value; + } + + @Override + public String getFormalName() { + return _formalName; + } + + public void setFormalName(String value) { + _formalName = value; + } + + @Override + public MarkupLine getDescription() { + return _description; + } + + public void setDescription(MarkupLine value) { + _description = value; + } + + @Override + public List getProps() { + return _props; + } + + public void setProps(List value) { + _props = value; + } + + /** + * Add a new {@link Property} item to the underlying collection. + * + * @param item + * the item to add + * @return {@code true} + */ + public boolean addProp(Property item) { + Property value = ObjectUtils.requireNonNull(item, "item cannot be null"); + if (_props == null) { + _props = new LinkedList<>(); + } + return _props.add(value); + } + + /** + * Remove the first matching {@link Property} item from the underlying + * collection. + * + * @param item + * the item to remove + * @return {@code true} if the item was removed or {@code false} otherwise + */ + public boolean removeProp(Property item) { + Property value = ObjectUtils.requireNonNull(item, "item cannot be null"); + return _props != null && _props.remove(value); + } + + public List getKeyFields() { + return _keyFields; + } + + public void setKeyFields(List value) { + _keyFields = value; + } + + /** + * Add a new {@link KeyConstraintField} item to the underlying collection. + * + * @param item + * the item to add + * @return {@code true} + */ + public boolean addKeyField(KeyConstraintField item) { + KeyConstraintField value = ObjectUtils.requireNonNull(item, "item cannot be null"); + if (_keyFields == null) { + _keyFields = new LinkedList<>(); + } + return _keyFields.add(value); + } + + /** + * Remove the first matching {@link KeyConstraintField} item from the underlying + * collection. + * + * @param item + * the item to remove + * @return {@code true} if the item was removed or {@code false} otherwise + */ + public boolean removeKeyField(KeyConstraintField item) { + KeyConstraintField value = ObjectUtils.requireNonNull(item, "item cannot be null"); + return _keyFields != null && _keyFields.remove(value); + } + + @Override + public Remarks getRemarks() { + return _remarks; + } + + public void setRemarks(Remarks value) { + _remarks = value; + } + + @Override + public String toString() { + return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); + } +} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedMatchesConstraint.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedMatchesConstraint.java index edeba2b87..3eaa1a743 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedMatchesConstraint.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedMatchesConstraint.java @@ -56,7 +56,7 @@ @MetaschemaAssembly( formalName = "Value Matches Constraint", name = "targeted-matches-constraint", - moduleClass = MetaschemaModule.class) + moduleClass = MetaschemaModelModule.class) public class TargetedMatchesConstraint implements ITargetedConstraintBase { @BoundFlag( formalName = "Constraint Identifier", @@ -134,7 +134,7 @@ public class TargetedMatchesConstraint implements ITargetedConstraintBase { formalName = "Property", useName = "prop", maxOccurs = -1, - groupAs = @GroupAs(name = "props", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "props", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) private List _props; @BoundField( diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/UseName.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/UseName.java index 9168b59d9..9b78f0853 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/UseName.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/UseName.java @@ -31,12 +31,12 @@ import gov.nist.secauto.metaschema.databind.model.annotations.BoundFieldValue; import gov.nist.secauto.metaschema.databind.model.annotations.BoundFlag; import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaField; - +import java.lang.Override; +import java.lang.String; +import java.math.BigInteger; import org.apache.commons.lang3.builder.ReflectionToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; -import java.math.BigInteger; - /** * Allows the name of the definition to be overridden. */ @@ -48,7 +48,7 @@ formalName = "Use Name", description = "Allows the name of the definition to be overridden.", name = "use-name", - moduleClass = MetaschemaModule.class) + moduleClass = MetaschemaModelModule.class) public class UseName { /** * "Used for binary formats instead of the textual name." diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/package-info.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/package-info.java index ca9aa34f4..f0b9eef72 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/package-info.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/package-info.java @@ -24,16 +24,10 @@ * 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. */ -@MetaschemaPackage(moduleClass = { - MetaschemaModule.class }) -@XmlSchema( +@gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaPackage(moduleClass = { MetaschemaModelModule.class }) +@gov.nist.secauto.metaschema.databind.model.annotations.XmlSchema( namespace = "http://csrc.nist.gov/ns/oscal/metaschema/1.0", - xmlns = { @XmlNs(prefix = "", + xmlns = { @gov.nist.secauto.metaschema.databind.model.annotations.XmlNs(prefix = "", namespace = "http://csrc.nist.gov/ns/oscal/metaschema/1.0") }, - xmlElementFormDefault = XmlNsForm.QUALIFIED) + xmlElementFormDefault = gov.nist.secauto.metaschema.databind.model.annotations.XmlNsForm.QUALIFIED) package gov.nist.secauto.metaschema.databind.model.metaschema.binding; - -import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaPackage; -import gov.nist.secauto.metaschema.databind.model.annotations.XmlNs; -import gov.nist.secauto.metaschema.databind.model.annotations.XmlNsForm; -import gov.nist.secauto.metaschema.databind.model.annotations.XmlSchema; diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/ConstraintBindingSupport.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/ConstraintBindingSupport.java index 56c5e4d3b..4cea99860 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/ConstraintBindingSupport.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/ConstraintBindingSupport.java @@ -48,16 +48,21 @@ import gov.nist.secauto.metaschema.databind.model.metaschema.IConstraintBase; import gov.nist.secauto.metaschema.databind.model.metaschema.IModelConstraintsBase; import gov.nist.secauto.metaschema.databind.model.metaschema.IValueConstraintsBase; -import gov.nist.secauto.metaschema.databind.model.metaschema.binding.AssemblyConstraints; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.ConstraintLetExpression; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.ConstraintValueEnum; -import gov.nist.secauto.metaschema.databind.model.metaschema.binding.FlagConstraints; +import gov.nist.secauto.metaschema.databind.model.metaschema.binding.FlagAllowedValues; +import gov.nist.secauto.metaschema.databind.model.metaschema.binding.FlagExpect; +import gov.nist.secauto.metaschema.databind.model.metaschema.binding.FlagIndexHasKey; +import gov.nist.secauto.metaschema.databind.model.metaschema.binding.FlagMatches; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.KeyConstraintField; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.Property; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.Remarks; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.TargetedAllowedValuesConstraint; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.TargetedExpectConstraint; +import gov.nist.secauto.metaschema.databind.model.metaschema.binding.TargetedHasCardinalityConstraint; +import gov.nist.secauto.metaschema.databind.model.metaschema.binding.TargetedIndexConstraint; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.TargetedIndexHasKeyConstraint; +import gov.nist.secauto.metaschema.databind.model.metaschema.binding.TargetedIsUniqueConstraint; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.TargetedMatchesConstraint; import java.math.BigInteger; @@ -80,17 +85,17 @@ public static void parse( // parse rules for (IConstraintBase ruleObj : constraints.getRules()) { - if (ruleObj instanceof FlagConstraints.AllowedValues) { - IAllowedValuesConstraint constraint = newAllowedValues((FlagConstraints.AllowedValues) ruleObj, source); + if (ruleObj instanceof FlagAllowedValues) { + IAllowedValuesConstraint constraint = newAllowedValues((FlagAllowedValues) ruleObj, source); constraintSet.addConstraint(constraint); - } else if (ruleObj instanceof FlagConstraints.Expect) { - IExpectConstraint constraint = newExpect((FlagConstraints.Expect) ruleObj, source); + } else if (ruleObj instanceof FlagExpect) { + IExpectConstraint constraint = newExpect((FlagExpect) ruleObj, source); constraintSet.addConstraint(constraint); - } else if (ruleObj instanceof FlagConstraints.IndexHasKey) { - IIndexHasKeyConstraint constraint = newIndexHasKey((FlagConstraints.IndexHasKey) ruleObj, source); + } else if (ruleObj instanceof FlagIndexHasKey) { + IIndexHasKeyConstraint constraint = newIndexHasKey((FlagIndexHasKey) ruleObj, source); constraintSet.addConstraint(constraint); - } else if (ruleObj instanceof FlagConstraints.Matches) { - IMatchesConstraint constraint = newMatches((FlagConstraints.Matches) ruleObj, source); + } else if (ruleObj instanceof FlagMatches) { + IMatchesConstraint constraint = newMatches((FlagMatches) ruleObj, source); constraintSet.addConstraint(constraint); } } @@ -129,14 +134,14 @@ public static void parse( } else if (ruleObj instanceof TargetedMatchesConstraint) { IMatchesConstraint constraint = newMatches((TargetedMatchesConstraint) ruleObj, source); constraintSet.addConstraint(constraint); - } else if (ruleObj instanceof AssemblyConstraints.Index) { - IIndexConstraint constraint = newIndex((AssemblyConstraints.Index) ruleObj, source); + } else if (ruleObj instanceof TargetedIndexConstraint) { + IIndexConstraint constraint = newIndex((TargetedIndexConstraint) ruleObj, source); constraintSet.addConstraint(constraint); - } else if (ruleObj instanceof AssemblyConstraints.HasCardinality) { - ICardinalityConstraint constraint = newHasCardinality((AssemblyConstraints.HasCardinality) ruleObj, source); + } else if (ruleObj instanceof TargetedHasCardinalityConstraint) { + ICardinalityConstraint constraint = newHasCardinality((TargetedHasCardinalityConstraint) ruleObj, source); constraintSet.addConstraint(constraint); - } else if (ruleObj instanceof AssemblyConstraints.Unique) { - IUniqueConstraint constraint = newUnique((AssemblyConstraints.Unique) ruleObj, source); + } else if (ruleObj instanceof TargetedIsUniqueConstraint) { + IUniqueConstraint constraint = newUnique((TargetedIsUniqueConstraint) ruleObj, source); constraintSet.addConstraint(constraint); } } @@ -145,7 +150,7 @@ public static void parse( @NonNull private static IAllowedValuesConstraint newAllowedValues( - @NonNull FlagConstraints.AllowedValues obj, + @NonNull FlagAllowedValues obj, @NonNull ISource source) { IAllowedValuesConstraint.Builder builder = IAllowedValuesConstraint.builder() .allowedOther(ModelSupport.yesOrNo(obj.getAllowOther())) @@ -175,7 +180,7 @@ private static IAllowedValuesConstraint newAllowedValues( @NonNull private static IExpectConstraint newExpect( - @NonNull FlagConstraints.Expect obj, + @NonNull FlagExpect obj, @NonNull ISource source) { IExpectConstraint.Builder builder = IExpectConstraint.builder() .test(target(ObjectUtils.requireNonNull(obj.getTest()))); @@ -223,7 +228,7 @@ private static IExpectConstraint newExpect( @NonNull private static IIndexHasKeyConstraint newIndexHasKey( - @NonNull FlagConstraints.IndexHasKey obj, + @NonNull FlagIndexHasKey obj, @NonNull ISource source) { IIndexHasKeyConstraint.Builder builder = IIndexHasKeyConstraint.builder() .name(ObjectUtils.requireNonNull(obj.getName())); @@ -245,7 +250,7 @@ private static IIndexHasKeyConstraint newIndexHasKey( @NonNull private static IMatchesConstraint newMatches( - @NonNull FlagConstraints.Matches obj, + @NonNull FlagMatches obj, @NonNull ISource source) { IMatchesConstraint.Builder builder = IMatchesConstraint.builder(); applyCommonValues(obj, null, source, builder); @@ -287,7 +292,7 @@ private static IMatchesConstraint newMatches( @NonNull private static IIndexConstraint newIndex( - @NonNull AssemblyConstraints.Index obj, + @NonNull TargetedIndexConstraint obj, @NonNull ISource source) { IIndexConstraint.Builder builder = IIndexConstraint.builder() .name(ObjectUtils.requireNonNull(obj.getName())); @@ -299,7 +304,7 @@ private static IIndexConstraint newIndex( @NonNull private static ICardinalityConstraint newHasCardinality( - @NonNull AssemblyConstraints.HasCardinality obj, + @NonNull TargetedHasCardinalityConstraint obj, @NonNull ISource source) { ICardinalityConstraint.Builder builder = ICardinalityConstraint.builder(); applyCommonValues(obj, obj.getTarget(), source, builder); @@ -319,7 +324,7 @@ private static ICardinalityConstraint newHasCardinality( @NonNull private static IUniqueConstraint newUnique( - @NonNull AssemblyConstraints.Unique obj, + @NonNull TargetedIsUniqueConstraint obj, @NonNull ISource source) { IUniqueConstraint.Builder builder = IUniqueConstraint.builder(); applyCommonValues(obj, obj.getTarget(), source, builder); From 36f0d751f71a398865591df26192f44ed0b5e1c5 Mon Sep 17 00:00:00 2001 From: David Waltermire Date: Wed, 14 Feb 2024 11:08:17 -0500 Subject: [PATCH 2/5] Implemented a Metaschema module binding-based constraint loader: BindingConstraintLoader. This loader is capable of loading the legacy external constraint format and the new meta constraint format. --- core/metaschema | 2 +- .../item/node/AbstractNodeItemFactory.java | 35 +- .../item/node/DefaultNodeItemFactory.java | 59 ++- .../core/model/IAssemblyDefinition.java | 2 +- .../core/model/IChoiceGroupInstance.java | 12 + .../core/model/IConstraintLoader.java | 33 ++ .../metaschema/core/model/IDefinition.java | 2 +- .../AbstractTargetedConstraints.java | 6 +- .../AssemblyTargetedConstraints.java | 4 +- .../{impl => }/DefaultConstraintSet.java | 7 +- .../{impl => }/DefaultScopedContraints.java | 10 +- .../{impl => }/FieldTargetedConstraints.java | 4 +- .../{impl => }/FlagTargetedConstraints.java | 4 +- .../core/model/constraint/IConstraintSet.java | 2 +- .../{impl => }/IFeatureModelConstrained.java | 7 +- .../{impl => }/IFeatureValueConstrained.java | 10 +- .../model/constraint/IScopedContraints.java | 2 +- ...staints.java => ITargetedConstraints.java} | 2 +- ...AbstractDefinitionTargetedConstraints.java | 1 + .../impl/ConstraintComposingVisitor.java | 16 +- ...xternalConstraintsModulePostProcessor.java | 4 +- ...ntLoader.java => XmlConstraintLoader.java} | 46 +- ...ader.java => XmlMetaConstraintLoader.java} | 32 +- .../model/xml/MetaConstraintLoaderTest.java | 2 +- .../core/model/xml/ModuleLoaderTest.java | 3 +- .../computer-metaschema-meta-constraints.xml | 4 +- .../model/IBoundInstanceModelChoiceGroup.java | 1 + .../metaschema/BindingConstraintLoader.java | 395 ++++++++++++++++++ .../metaschema/binding/MetapathContext.java | 45 +- .../binding/MetaschemaMetapath.java | 67 +++ .../binding/MetaschemaModuleConstraints.java | 46 +- .../impl/ConstraintBindingSupport.java | 1 - .../databind/DefaultBindingContextTest.java | 24 +- .../test/resources/content/constraints.xml | 2 +- .../AbstractValidateContentCommand.java | 5 +- 35 files changed, 763 insertions(+), 134 deletions(-) create mode 100644 core/src/main/java/gov/nist/secauto/metaschema/core/model/IConstraintLoader.java rename core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/{impl => }/AbstractTargetedConstraints.java (90%) rename core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/{impl => }/AssemblyTargetedConstraints.java (95%) rename core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/{impl => }/DefaultConstraintSet.java (91%) rename core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/{impl => }/DefaultScopedContraints.java (87%) rename core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/{impl => }/FieldTargetedConstraints.java (94%) rename core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/{impl => }/FlagTargetedConstraints.java (94%) rename core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/{impl => }/IFeatureModelConstrained.java (88%) rename core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/{impl => }/IFeatureValueConstrained.java (85%) rename core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/{ITargetedConstaints.java => ITargetedConstraints.java} (97%) rename core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/{ConstraintLoader.java => XmlConstraintLoader.java} (86%) rename core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/{MetaConstraintLoader.java => XmlMetaConstraintLoader.java} (89%) create mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/BindingConstraintLoader.java create mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/MetaschemaMetapath.java diff --git a/core/metaschema b/core/metaschema index c114fc1b4..bb4f6396d 160000 --- a/core/metaschema +++ b/core/metaschema @@ -1 +1 @@ -Subproject commit c114fc1b48887e915742605c92df128ebf722017 +Subproject commit bb4f6396d6b2c15bec2a4e7255c34bd5f6925cf3 diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/AbstractNodeItemFactory.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/AbstractNodeItemFactory.java index 1f395b5e5..a77577f63 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/AbstractNodeItemFactory.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/AbstractNodeItemFactory.java @@ -35,6 +35,7 @@ import gov.nist.secauto.metaschema.core.model.IFieldDefinition; import gov.nist.secauto.metaschema.core.model.IFieldInstance; import gov.nist.secauto.metaschema.core.model.IFieldInstanceAbsolute; +import gov.nist.secauto.metaschema.core.model.IModelInstance; import gov.nist.secauto.metaschema.core.model.IModule; import gov.nist.secauto.metaschema.core.model.INamedModelInstance; import gov.nist.secauto.metaschema.core.model.INamedModelInstanceAbsolute; @@ -249,18 +250,44 @@ private IAssemblyNodeItem getCycledInstance( * @return the stream of descendant instances */ @NonNull - protected Stream getNamedModelInstances(@NonNull IContainerModelAbsolute container) { + protected Stream getNamedModelInstances(@NonNull IContainerModelAbsolute container) { return ObjectUtils.notNull(container.getModelInstances().stream() .flatMap(instance -> { - Stream retval; + Stream retval; if (instance instanceof IAssemblyInstanceAbsolute || instance instanceof IFieldInstanceAbsolute) { retval = Stream.of((INamedModelInstanceAbsolute) instance); } else if (instance instanceof IChoiceInstance) { // descend into the choice retval = getNamedModelInstances((IChoiceInstance) instance); } else if (instance instanceof IChoiceGroupInstance) { - throw new UnsupportedOperationException("implement"); - // retval = Stream.of(instance); + IChoiceGroupInstance choiceGroupInstance = (IChoiceGroupInstance) instance; + retval = choiceGroupInstance.getNamedModelInstances().stream(); + } else { + throw new UnsupportedOperationException("unsupported instance type: " + instance.getClass().getName()); + } + return retval; + })); + } + + /** + * Get the descendant model instances of the provided {@code container}. + * + * @param container + * the container to get descendant instances for + * @return the stream of descendant instances + */ + @NonNull + protected Stream getValuedModelInstances(@NonNull IContainerModelAbsolute container) { + return ObjectUtils.notNull(container.getModelInstances().stream() + .flatMap(instance -> { + Stream retval; + if (instance instanceof IAssemblyInstanceAbsolute || instance instanceof IFieldInstanceAbsolute) { + retval = Stream.of((INamedModelInstanceAbsolute) instance); + } else if (instance instanceof IChoiceInstance) { + // descend into the choice + retval = getNamedModelInstances((IChoiceInstance) instance); + } else if (instance instanceof IChoiceGroupInstance) { + retval = Stream.of((IChoiceGroupInstance) instance); } else { throw new UnsupportedOperationException("unsupported instance type: " + instance.getClass().getName()); } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/DefaultNodeItemFactory.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/DefaultNodeItemFactory.java index ac2755916..910cbb098 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/DefaultNodeItemFactory.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/DefaultNodeItemFactory.java @@ -29,11 +29,14 @@ import gov.nist.secauto.metaschema.core.metapath.item.node.IFeatureFlagContainerItem.FlagContainer; import gov.nist.secauto.metaschema.core.metapath.item.node.IFeatureModelContainerItem.ModelContainer; import gov.nist.secauto.metaschema.core.model.IAssemblyInstanceGrouped; +import gov.nist.secauto.metaschema.core.model.IChoiceGroupInstance; import gov.nist.secauto.metaschema.core.model.IFlagDefinition; import gov.nist.secauto.metaschema.core.model.IFlagInstance; +import gov.nist.secauto.metaschema.core.model.IModelInstance; import gov.nist.secauto.metaschema.core.model.IModule; import gov.nist.secauto.metaschema.core.model.INamedModelInstance; import gov.nist.secauto.metaschema.core.model.INamedModelInstanceAbsolute; +import gov.nist.secauto.metaschema.core.model.INamedModelInstanceGrouped; import gov.nist.secauto.metaschema.core.util.CollectionUtil; import gov.nist.secauto.metaschema.core.util.ObjectUtils; @@ -136,18 +139,50 @@ protected Map generateFlags(@NonNull IModelNodeItem Object parentValue = parent.getValue(); assert parentValue != null; - for (INamedModelInstanceAbsolute instance : CollectionUtil - .toIterable(getNamedModelInstances(parent.getDefinition()))) { - Object instanceValue = instance.getValue(parentValue); - - // the item values will be all non-null items - Stream itemValues = instance.getItemValues(instanceValue).stream(); - AtomicInteger index = new AtomicInteger(); // NOPMD - intentional - List> items = itemValues.map(itemValue -> { - assert itemValue != null; - return newModelItem(instance, parent, index.incrementAndGet(), itemValue); - }).collect(Collectors.toUnmodifiableList()); - retval.put(instance.getEffectiveName(), items); + for (IModelInstance instance : CollectionUtil.toIterable(getValuedModelInstances(parent.getDefinition()))) { + if (instance instanceof INamedModelInstanceAbsolute) { + INamedModelInstanceAbsolute namedInstance = (INamedModelInstanceAbsolute) instance; + + Object instanceValue = namedInstance.getValue(parentValue); + + // the item values will be all non-null items + Stream itemValues = namedInstance.getItemValues(instanceValue).stream(); + AtomicInteger index = new AtomicInteger(); // NOPMD - intentional + List> items = itemValues.map(itemValue -> { + assert itemValue != null; + return newModelItem(namedInstance, parent, index.incrementAndGet(), itemValue); + }).collect(Collectors.toUnmodifiableList()); + retval.put(namedInstance.getEffectiveName(), items); + } else if (instance instanceof IChoiceGroupInstance) { + IChoiceGroupInstance choiceInstance = (IChoiceGroupInstance) instance; + + Object instanceValue = choiceInstance.getValue(parentValue); + + Map> instanceMap = choiceInstance.getItemValues(instanceValue).stream() + .map(item -> { + assert item != null; + INamedModelInstanceGrouped itemInstance = choiceInstance.getItemInstance(item); + return Map.entry(itemInstance, item); + }) + .collect(Collectors.groupingBy( + entry -> entry.getKey(), + LinkedHashMap::new, + Collectors.mapping(entry -> entry.getValue(), Collectors.toUnmodifiableList()))); + + for (Map.Entry> entry : instanceMap.entrySet()) { + INamedModelInstanceGrouped namedInstance = entry.getKey(); + assert namedInstance != null; + + AtomicInteger index = new AtomicInteger(); // NOPMD - intentional + List> items = entry.getValue().stream() + .map(itemValue -> { + assert itemValue != null; + return newModelItem(namedInstance, parent, index.incrementAndGet(), itemValue); + }).collect(Collectors.toUnmodifiableList()); + retval.put(namedInstance.getEffectiveName(), items); + } + } + } return retval.isEmpty() ? CollectionUtil.emptyMap() : CollectionUtil.unmodifiableMap(retval); } 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 ce1843d58..a6297b133 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,7 +26,7 @@ package gov.nist.secauto.metaschema.core.model; -import gov.nist.secauto.metaschema.core.model.constraint.impl.IFeatureModelConstrained; +import gov.nist.secauto.metaschema.core.model.constraint.IFeatureModelConstrained; import javax.xml.namespace.QName; 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 ecc44b7fd..727e000f9 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 @@ -84,6 +84,18 @@ default boolean isEffectiveValueWrappedInXml() { return true; } + /** + * Get the named model instance for the provided choice group item. + * + * @param item + * the item to get the instance for + * @return the named model instance for the provided choice group item + */ + @NonNull + default INamedModelInstanceGrouped getItemInstance(@NonNull Object item) { + throw new UnsupportedOperationException("no value"); + } + @Override default MarkupMultiline getRemarks() { // no remarks diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IConstraintLoader.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IConstraintLoader.java new file mode 100644 index 000000000..f1154772c --- /dev/null +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IConstraintLoader.java @@ -0,0 +1,33 @@ +/* + * 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 gov.nist.secauto.metaschema.core.model.constraint.IConstraintSet; + +public interface IConstraintLoader extends ILoader { + // no additional methods +} 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 943b52704..50397822d 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 @@ -26,7 +26,7 @@ package gov.nist.secauto.metaschema.core.model; -import gov.nist.secauto.metaschema.core.model.constraint.impl.IFeatureValueConstrained; +import gov.nist.secauto.metaschema.core.model.constraint.IFeatureValueConstrained; import java.util.Locale; diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/impl/AbstractTargetedConstraints.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/AbstractTargetedConstraints.java similarity index 90% rename from core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/impl/AbstractTargetedConstraints.java rename to core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/AbstractTargetedConstraints.java index 69f32b42c..5f376a714 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/impl/AbstractTargetedConstraints.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/AbstractTargetedConstraints.java @@ -24,11 +24,9 @@ * OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER. */ -package gov.nist.secauto.metaschema.core.model.constraint.impl; +package gov.nist.secauto.metaschema.core.model.constraint; import gov.nist.secauto.metaschema.core.metapath.MetapathExpression; -import gov.nist.secauto.metaschema.core.model.constraint.ITargetedConstaints; -import gov.nist.secauto.metaschema.core.model.constraint.IValueConstrained; import edu.umd.cs.findbugs.annotations.NonNull; @@ -40,7 +38,7 @@ * the Java type of the constraint container */ public abstract class AbstractTargetedConstraints - implements ITargetedConstaints, IFeatureValueConstrained { + implements ITargetedConstraints, IFeatureValueConstrained { @NonNull private final MetapathExpression targetExpression; @NonNull diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/impl/AssemblyTargetedConstraints.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/AssemblyTargetedConstraints.java similarity index 95% rename from core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/impl/AssemblyTargetedConstraints.java rename to core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/AssemblyTargetedConstraints.java index 9f291b53c..59193ee9e 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/impl/AssemblyTargetedConstraints.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/AssemblyTargetedConstraints.java @@ -24,11 +24,11 @@ * OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER. */ -package gov.nist.secauto.metaschema.core.model.constraint.impl; +package gov.nist.secauto.metaschema.core.model.constraint; import gov.nist.secauto.metaschema.core.metapath.MetapathExpression; import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition; -import gov.nist.secauto.metaschema.core.model.constraint.IModelConstrained; +import gov.nist.secauto.metaschema.core.model.constraint.impl.AbstractDefinitionTargetedConstraints; import edu.umd.cs.findbugs.annotations.NonNull; diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/impl/DefaultConstraintSet.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/DefaultConstraintSet.java similarity index 91% rename from core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/impl/DefaultConstraintSet.java rename to core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/DefaultConstraintSet.java index f498bbd88..701da48eb 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/impl/DefaultConstraintSet.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/DefaultConstraintSet.java @@ -24,12 +24,9 @@ * OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER. */ -package gov.nist.secauto.metaschema.core.model.constraint.impl; +package gov.nist.secauto.metaschema.core.model.constraint; import gov.nist.secauto.metaschema.core.model.IModule; -import gov.nist.secauto.metaschema.core.model.constraint.IConstraintSet; -import gov.nist.secauto.metaschema.core.model.constraint.IScopedContraints; -import gov.nist.secauto.metaschema.core.model.constraint.ITargetedConstaints; import gov.nist.secauto.metaschema.core.util.CollectionUtil; import gov.nist.secauto.metaschema.core.util.ObjectUtils; @@ -105,7 +102,7 @@ public Set getImportedConstraintSets() { } @Override - public Iterable getTargetedConstraintsForModule(@NonNull IModule module) { + public Iterable getTargetedConstraintsForModule(@NonNull IModule module) { QName qname = module.getQName(); Map> map = getScopedContraints(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/impl/DefaultScopedContraints.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/DefaultScopedContraints.java similarity index 87% rename from core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/impl/DefaultScopedContraints.java rename to core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/DefaultScopedContraints.java index b0ea54f49..e259998f9 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/impl/DefaultScopedContraints.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/DefaultScopedContraints.java @@ -24,11 +24,9 @@ * OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER. */ -package gov.nist.secauto.metaschema.core.model.constraint.impl; +package gov.nist.secauto.metaschema.core.model.constraint; import gov.nist.secauto.metaschema.core.model.IModule; -import gov.nist.secauto.metaschema.core.model.constraint.IScopedContraints; -import gov.nist.secauto.metaschema.core.model.constraint.ITargetedConstaints; import java.net.URI; import java.util.List; @@ -41,7 +39,7 @@ public class DefaultScopedContraints implements IScopedContraints { @NonNull private final String shortName; @NonNull - private final List targetedConstraints; + private final List targetedConstraints; /** * Construct a new set of scoped constraints. @@ -58,7 +56,7 @@ public class DefaultScopedContraints implements IScopedContraints { public DefaultScopedContraints( @NonNull URI namespace, @NonNull String shortName, - @NonNull List targetedConstraints) { + @NonNull List targetedConstraints) { this.namespace = namespace; this.shortName = shortName; this.targetedConstraints = targetedConstraints; @@ -75,7 +73,7 @@ public String getModuleShortName() { } @Override - public List getTargetedContraints() { + public List getTargetedContraints() { return targetedConstraints; } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/impl/FieldTargetedConstraints.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/FieldTargetedConstraints.java similarity index 94% rename from core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/impl/FieldTargetedConstraints.java rename to core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/FieldTargetedConstraints.java index ee1baacbe..386f11095 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/impl/FieldTargetedConstraints.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/FieldTargetedConstraints.java @@ -24,11 +24,11 @@ * OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER. */ -package gov.nist.secauto.metaschema.core.model.constraint.impl; +package gov.nist.secauto.metaschema.core.model.constraint; import gov.nist.secauto.metaschema.core.metapath.MetapathExpression; import gov.nist.secauto.metaschema.core.model.IFieldDefinition; -import gov.nist.secauto.metaschema.core.model.constraint.IValueConstrained; +import gov.nist.secauto.metaschema.core.model.constraint.impl.AbstractDefinitionTargetedConstraints; import edu.umd.cs.findbugs.annotations.NonNull; diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/impl/FlagTargetedConstraints.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/FlagTargetedConstraints.java similarity index 94% rename from core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/impl/FlagTargetedConstraints.java rename to core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/FlagTargetedConstraints.java index cd0bbd600..d59269063 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/impl/FlagTargetedConstraints.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/FlagTargetedConstraints.java @@ -24,11 +24,11 @@ * OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER. */ -package gov.nist.secauto.metaschema.core.model.constraint.impl; +package gov.nist.secauto.metaschema.core.model.constraint; import gov.nist.secauto.metaschema.core.metapath.MetapathExpression; import gov.nist.secauto.metaschema.core.model.IFlagDefinition; -import gov.nist.secauto.metaschema.core.model.constraint.IValueConstrained; +import gov.nist.secauto.metaschema.core.model.constraint.impl.AbstractDefinitionTargetedConstraints; import edu.umd.cs.findbugs.annotations.NonNull; diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IConstraintSet.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IConstraintSet.java index 9f271142d..d2ffaef73 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IConstraintSet.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IConstraintSet.java @@ -34,7 +34,7 @@ public interface IConstraintSet { @NonNull - Iterable getTargetedConstraintsForModule(@NonNull IModule module); + Iterable getTargetedConstraintsForModule(@NonNull IModule module); @NonNull Collection getImportedConstraintSets(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/impl/IFeatureModelConstrained.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IFeatureModelConstrained.java similarity index 88% rename from core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/impl/IFeatureModelConstrained.java rename to core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IFeatureModelConstrained.java index 6384f05a7..86967bce2 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/impl/IFeatureModelConstrained.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IFeatureModelConstrained.java @@ -24,12 +24,7 @@ * OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER. */ -package gov.nist.secauto.metaschema.core.model.constraint.impl; - -import gov.nist.secauto.metaschema.core.model.constraint.ICardinalityConstraint; -import gov.nist.secauto.metaschema.core.model.constraint.IIndexConstraint; -import gov.nist.secauto.metaschema.core.model.constraint.IModelConstrained; -import gov.nist.secauto.metaschema.core.model.constraint.IUniqueConstraint; +package gov.nist.secauto.metaschema.core.model.constraint; import java.util.List; diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/impl/IFeatureValueConstrained.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IFeatureValueConstrained.java similarity index 85% rename from core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/impl/IFeatureValueConstrained.java rename to core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IFeatureValueConstrained.java index 33e47a819..0bb19ce12 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/impl/IFeatureValueConstrained.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IFeatureValueConstrained.java @@ -24,15 +24,7 @@ * OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER. */ -package gov.nist.secauto.metaschema.core.model.constraint.impl; - -import gov.nist.secauto.metaschema.core.model.constraint.IAllowedValuesConstraint; -import gov.nist.secauto.metaschema.core.model.constraint.IConstraint; -import gov.nist.secauto.metaschema.core.model.constraint.IExpectConstraint; -import gov.nist.secauto.metaschema.core.model.constraint.IIndexHasKeyConstraint; -import gov.nist.secauto.metaschema.core.model.constraint.ILet; -import gov.nist.secauto.metaschema.core.model.constraint.IMatchesConstraint; -import gov.nist.secauto.metaschema.core.model.constraint.IValueConstrained; +package gov.nist.secauto.metaschema.core.model.constraint; import java.util.List; import java.util.Map; diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IScopedContraints.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IScopedContraints.java index 1749dac04..f3848427e 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IScopedContraints.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IScopedContraints.java @@ -39,5 +39,5 @@ public interface IScopedContraints { String getModuleShortName(); @NonNull - List getTargetedContraints(); + List getTargetedContraints(); } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/ITargetedConstaints.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/ITargetedConstraints.java similarity index 97% rename from core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/ITargetedConstaints.java rename to core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/ITargetedConstraints.java index b1211fb12..b6adabed6 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/ITargetedConstaints.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/ITargetedConstraints.java @@ -37,7 +37,7 @@ * Represents a set of constraints that target a given definition using a target * Metapath expression. */ -public interface ITargetedConstaints extends IValueConstrained { +public interface ITargetedConstraints extends IValueConstrained { @NonNull MetapathExpression getTargetExpression(); 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 0e1528e82..4755aff5e 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 @@ -31,6 +31,7 @@ import gov.nist.secauto.metaschema.core.model.IDefinition; import gov.nist.secauto.metaschema.core.model.IFieldDefinition; import gov.nist.secauto.metaschema.core.model.IFlagDefinition; +import gov.nist.secauto.metaschema.core.model.constraint.AbstractTargetedConstraints; import gov.nist.secauto.metaschema.core.model.constraint.IValueConstrained; import java.util.Locale; diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/impl/ConstraintComposingVisitor.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/impl/ConstraintComposingVisitor.java index 5b00eeacf..10ba85bc2 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/impl/ConstraintComposingVisitor.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/impl/ConstraintComposingVisitor.java @@ -33,44 +33,44 @@ import gov.nist.secauto.metaschema.core.metapath.item.node.IFlagNodeItem; import gov.nist.secauto.metaschema.core.metapath.item.node.IModuleNodeItem; import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItemVisitor; -import gov.nist.secauto.metaschema.core.model.constraint.ITargetedConstaints; +import gov.nist.secauto.metaschema.core.model.constraint.ITargetedConstraints; import edu.umd.cs.findbugs.annotations.NonNull; public class ConstraintComposingVisitor - implements INodeItemVisitor { + implements INodeItemVisitor { @Override - public Void visitDocument(@NonNull IDocumentNodeItem item, ITargetedConstaints context) { + public Void visitDocument(@NonNull IDocumentNodeItem item, ITargetedConstraints context) { throw new UnsupportedOperationException("constraints can only apply to an assembly, field, or flag definition"); } @Override - public Void visitFlag(@NonNull IFlagNodeItem item, ITargetedConstaints context) { + public Void visitFlag(@NonNull IFlagNodeItem item, ITargetedConstraints context) { context.target(item.getDefinition()); return null; } @Override - public Void visitField(@NonNull IFieldNodeItem item, ITargetedConstaints context) { + public Void visitField(@NonNull IFieldNodeItem item, ITargetedConstraints context) { context.target(item.getDefinition()); return null; } @Override - public Void visitAssembly(@NonNull IAssemblyNodeItem item, ITargetedConstaints context) { + public Void visitAssembly(@NonNull IAssemblyNodeItem item, ITargetedConstraints context) { context.target(item.getDefinition()); return null; } @Override - public Void visitAssembly(IAssemblyInstanceGroupedNodeItem item, ITargetedConstaints context) { + public Void visitAssembly(IAssemblyInstanceGroupedNodeItem item, ITargetedConstraints context) { context.target(item.getDefinition()); return null; } @Override - public Void visitMetaschema(@NonNull IModuleNodeItem item, ITargetedConstaints context) { + public Void visitMetaschema(@NonNull IModuleNodeItem item, ITargetedConstraints context) { throw new UnsupportedOperationException("constraints can only apply to an assembly, field, or flag definition"); } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/ExternalConstraintsModulePostProcessor.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/ExternalConstraintsModulePostProcessor.java index d6d752a4d..6c54c10bc 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/ExternalConstraintsModulePostProcessor.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/ExternalConstraintsModulePostProcessor.java @@ -36,7 +36,7 @@ import gov.nist.secauto.metaschema.core.model.IModule; import gov.nist.secauto.metaschema.core.model.IModuleLoader; import gov.nist.secauto.metaschema.core.model.constraint.IConstraintSet; -import gov.nist.secauto.metaschema.core.model.constraint.ITargetedConstaints; +import gov.nist.secauto.metaschema.core.model.constraint.ITargetedConstraints; import gov.nist.secauto.metaschema.core.model.constraint.impl.ConstraintComposingVisitor; import gov.nist.secauto.metaschema.core.util.ObjectUtils; @@ -74,7 +74,7 @@ public void processModule(IModule module) { IModuleNodeItem moduleItem = INodeItemFactory.instance().newModuleNodeItem(module); for (IConstraintSet set : getRegisteredConstraintSets()) { - for (ITargetedConstaints targeted : set.getTargetedConstraintsForModule(module)) { + for (ITargetedConstraints targeted : set.getTargetedConstraintsForModule(module)) { // apply targeted constraints MetapathExpression targetExpression = targeted.getTargetExpression(); ISequence items = targetExpression.evaluateAs(moduleItem, ResultType.SEQUENCE); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/ConstraintLoader.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/XmlConstraintLoader.java similarity index 86% rename from core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/ConstraintLoader.java rename to core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/XmlConstraintLoader.java index 1b8ebc0e1..33b0ff0b1 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/ConstraintLoader.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/XmlConstraintLoader.java @@ -29,21 +29,22 @@ import gov.nist.secauto.metaschema.core.metapath.MetapathException; import gov.nist.secauto.metaschema.core.metapath.MetapathExpression; import gov.nist.secauto.metaschema.core.model.AbstractLoader; +import gov.nist.secauto.metaschema.core.model.IConstraintLoader; import gov.nist.secauto.metaschema.core.model.IModule; import gov.nist.secauto.metaschema.core.model.MetaschemaException; import gov.nist.secauto.metaschema.core.model.constraint.AssemblyConstraintSet; +import gov.nist.secauto.metaschema.core.model.constraint.AssemblyTargetedConstraints; +import gov.nist.secauto.metaschema.core.model.constraint.DefaultConstraintSet; +import gov.nist.secauto.metaschema.core.model.constraint.DefaultScopedContraints; +import gov.nist.secauto.metaschema.core.model.constraint.FieldTargetedConstraints; +import gov.nist.secauto.metaschema.core.model.constraint.FlagTargetedConstraints; import gov.nist.secauto.metaschema.core.model.constraint.IConstraintSet; import gov.nist.secauto.metaschema.core.model.constraint.IModelConstrained; import gov.nist.secauto.metaschema.core.model.constraint.IScopedContraints; import gov.nist.secauto.metaschema.core.model.constraint.ISource; -import gov.nist.secauto.metaschema.core.model.constraint.ITargetedConstaints; +import gov.nist.secauto.metaschema.core.model.constraint.ITargetedConstraints; import gov.nist.secauto.metaschema.core.model.constraint.IValueConstrained; import gov.nist.secauto.metaschema.core.model.constraint.ValueConstraintSet; -import gov.nist.secauto.metaschema.core.model.constraint.impl.AssemblyTargetedConstraints; -import gov.nist.secauto.metaschema.core.model.constraint.impl.DefaultConstraintSet; -import gov.nist.secauto.metaschema.core.model.constraint.impl.DefaultScopedContraints; -import gov.nist.secauto.metaschema.core.model.constraint.impl.FieldTargetedConstraints; -import gov.nist.secauto.metaschema.core.model.constraint.impl.FlagTargetedConstraints; import gov.nist.secauto.metaschema.core.model.xml.impl.ConstraintXmlSupport; import gov.nist.secauto.metaschema.core.model.xml.impl.XmlObjectParser; import gov.nist.secauto.metaschema.core.model.xml.impl.XmlObjectParser.Handler; @@ -81,34 +82,35 @@ * every use. Any constraint set imported is also loaded and cached * automatically. */ -public class ConstraintLoader - extends AbstractLoader { +public class XmlConstraintLoader + extends AbstractLoader + implements IConstraintLoader { @SuppressWarnings("PMD.UseConcurrentHashMap") @NonNull private static final Map>>> SCOPE_OBJECT_MAPPING = ObjectUtils.notNull( + Handler>>> SCOPE_OBJECT_MAPPING = ObjectUtils.notNull( Map.ofEntries( Map.entry(new QName(IModule.XML_NAMESPACE, "assembly"), - ConstraintLoader::handleScopedAssembly), + XmlConstraintLoader::handleScopedAssembly), Map.entry(new QName(IModule.XML_NAMESPACE, "field"), - ConstraintLoader::handleScopedField), + XmlConstraintLoader::handleScopedField), Map.entry(new QName(IModule.XML_NAMESPACE, "flag"), - ConstraintLoader::handleScopedFlag))); + XmlConstraintLoader::handleScopedFlag))); @NonNull - private static final XmlObjectParser>> SCOPE_PARSER + private static final XmlObjectParser>> SCOPE_PARSER = new XmlObjectParser<>(SCOPE_OBJECT_MAPPING) { @Override - protected Handler>> identifyHandler(XmlCursor cursor, XmlObject obj) { - Handler>> retval; + protected Handler>> identifyHandler(XmlCursor cursor, XmlObject obj) { + Handler>> retval; if (obj instanceof Scope.Assembly) { - retval = ConstraintLoader::handleScopedAssembly; + retval = XmlConstraintLoader::handleScopedAssembly; } else if (obj instanceof Scope.Field) { - retval = ConstraintLoader::handleScopedField; + retval = XmlConstraintLoader::handleScopedField; } else if (obj instanceof Scope.Flag) { - retval = ConstraintLoader::handleScopedFlag; + retval = XmlConstraintLoader::handleScopedFlag; } else { throw new IllegalStateException(String.format("Unhandled element type '%s'.", obj.getClass().getName())); } @@ -189,7 +191,7 @@ protected List parseScopedConstraints( for (Scope scope : xmlObject.getMETASCHEMACONSTRAINTS().getScopeList()) { assert scope != null; - List targetedConstraints = new LinkedList<>(); // NOPMD - intentional + List targetedConstraints = new LinkedList<>(); // NOPMD - intentional try { SCOPE_PARSER.parse(scope, Pair.of(constraintSource, targetedConstraints)); } catch (MetapathException | XmlValueNotSupportedException ex) { @@ -216,7 +218,7 @@ protected List parseScopedConstraints( private static void handleScopedAssembly( // NOPMD false positive @NonNull XmlObject obj, - Pair> state) { + Pair> state) { Scope.Assembly assembly = (Scope.Assembly) obj; MetapathExpression expression = ObjectUtils.requireNonNull(assembly.getTarget()); @@ -228,7 +230,7 @@ private static void handleScopedAssembly( // NOPMD false positive private static void handleScopedField( // NOPMD false positive @NonNull XmlObject obj, - Pair> state) { + Pair> state) { Scope.Field field = (Scope.Field) obj; MetapathExpression expression = ObjectUtils.requireNonNull(field.getTarget()); @@ -240,7 +242,7 @@ private static void handleScopedField( // NOPMD false positive private static void handleScopedFlag( // NOPMD false positive @NonNull XmlObject obj, - Pair> state) { + Pair> state) { Scope.Flag flag = (Scope.Flag) obj; MetapathExpression expression = ObjectUtils.requireNonNull(flag.getTarget()); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/MetaConstraintLoader.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/XmlMetaConstraintLoader.java similarity index 89% rename from core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/MetaConstraintLoader.java rename to core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/XmlMetaConstraintLoader.java index 6cd53631f..231120d1a 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/MetaConstraintLoader.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/XmlMetaConstraintLoader.java @@ -29,17 +29,18 @@ import gov.nist.secauto.metaschema.core.metapath.MetapathExpression; import gov.nist.secauto.metaschema.core.model.AbstractLoader; import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition; +import gov.nist.secauto.metaschema.core.model.IConstraintLoader; import gov.nist.secauto.metaschema.core.model.IDefinition; import gov.nist.secauto.metaschema.core.model.IFieldDefinition; import gov.nist.secauto.metaschema.core.model.IFlagDefinition; import gov.nist.secauto.metaschema.core.model.IModule; +import gov.nist.secauto.metaschema.core.model.constraint.AbstractTargetedConstraints; import gov.nist.secauto.metaschema.core.model.constraint.AssemblyConstraintSet; import gov.nist.secauto.metaschema.core.model.constraint.IConstraintSet; +import gov.nist.secauto.metaschema.core.model.constraint.IFeatureModelConstrained; import gov.nist.secauto.metaschema.core.model.constraint.IModelConstrained; import gov.nist.secauto.metaschema.core.model.constraint.ISource; -import gov.nist.secauto.metaschema.core.model.constraint.ITargetedConstaints; -import gov.nist.secauto.metaschema.core.model.constraint.impl.AbstractTargetedConstraints; -import gov.nist.secauto.metaschema.core.model.constraint.impl.IFeatureModelConstrained; +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.ModelContextType; @@ -61,10 +62,11 @@ import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; -public class MetaConstraintLoader - extends AbstractLoader { +public class XmlMetaConstraintLoader + extends AbstractLoader + implements IConstraintLoader { // private static final Logger LOGGER = - // LogManager.getLogger(MetaConstraintLoader.class); + // LogManager.getLogger(XmlMetaConstraintLoader.class); @Override protected IConstraintSet parseResource(URI resource, Deque visitedResources) throws IOException { @@ -76,7 +78,7 @@ protected IConstraintSet parseResource(URI resource, Deque visitedResources MetaschemaMetaConstraintsDocument.MetaschemaMetaConstraints constraints = xmlObject.getMetaschemaMetaConstraints(); - List targetedConstraints = ObjectUtils.notNull(constraints.getContextList().stream() + List targetedConstraints = ObjectUtils.notNull(constraints.getContextList().stream() .flatMap(context -> parseContext(ObjectUtils.notNull(context), null, source).getTargetedConstraints().stream()) .collect(Collectors.toList())); return new MetaConstraintSet(targetedConstraints); @@ -89,14 +91,14 @@ private Context parseContext( List metapaths; if (parent == null) { - metapaths = ObjectUtils.notNull(contextObj.getMetaschemaMetapathList().stream() - .map(path -> path.getTarget()) + metapaths = ObjectUtils.notNull(contextObj.getMetapathList().stream() + .map(metapath -> metapath.getTarget()) .collect(Collectors.toList())); } else { List parentMetapaths = parent.getMetapaths().stream() .collect(Collectors.toList()); - metapaths = ObjectUtils.notNull(contextObj.getMetaschemaMetapathList().stream() - .map(path -> path.getTarget()) + metapaths = ObjectUtils.notNull(contextObj.getMetapathList().stream() + .map(metapath -> metapath.getTarget()) .flatMap(childPath -> { return parentMetapaths.stream() .map(parentPath -> parentPath + '/' + childPath); @@ -154,7 +156,7 @@ public Context( this.constraints = constraints; } - public List getTargetedConstraints() { + public List getTargetedConstraints() { return Stream.concat( getMetapaths().stream() .map(metapath -> MetapathExpression.compile(ObjectUtils.notNull(metapath))) @@ -226,14 +228,14 @@ public void target(IAssemblyDefinition definition) { private static final class MetaConstraintSet implements IConstraintSet { @NonNull - private final List targetedConstraints; + private final List targetedConstraints; - private MetaConstraintSet(@NonNull List targetedConstraints) { + private MetaConstraintSet(@NonNull List targetedConstraints) { this.targetedConstraints = targetedConstraints; } @Override - public Iterable getTargetedConstraintsForModule(IModule module) { + public Iterable getTargetedConstraintsForModule(IModule module) { return targetedConstraints; } diff --git a/core/src/test/java/gov/nist/secauto/metaschema/core/model/xml/MetaConstraintLoaderTest.java b/core/src/test/java/gov/nist/secauto/metaschema/core/model/xml/MetaConstraintLoaderTest.java index ee10d2a10..0a2a24063 100644 --- a/core/src/test/java/gov/nist/secauto/metaschema/core/model/xml/MetaConstraintLoaderTest.java +++ b/core/src/test/java/gov/nist/secauto/metaschema/core/model/xml/MetaConstraintLoaderTest.java @@ -51,7 +51,7 @@ public class MetaConstraintLoaderTest { @Test void test() throws MetaschemaException, IOException { - IConstraintSet constraintSet = new MetaConstraintLoader() + IConstraintSet constraintSet = new XmlMetaConstraintLoader() .load(ObjectUtils.requireNonNull(Paths.get("src/test/resources/computer-metaschema-meta-constraints.xml"))); ExternalConstraintsModulePostProcessor postProcessor diff --git a/core/src/test/java/gov/nist/secauto/metaschema/core/model/xml/ModuleLoaderTest.java b/core/src/test/java/gov/nist/secauto/metaschema/core/model/xml/ModuleLoaderTest.java index bbad3b313..b39071c2c 100644 --- a/core/src/test/java/gov/nist/secauto/metaschema/core/model/xml/ModuleLoaderTest.java +++ b/core/src/test/java/gov/nist/secauto/metaschema/core/model/xml/ModuleLoaderTest.java @@ -32,6 +32,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition; +import gov.nist.secauto.metaschema.core.model.IConstraintLoader; import gov.nist.secauto.metaschema.core.model.IFlagDefinition; import gov.nist.secauto.metaschema.core.model.MetaschemaException; import gov.nist.secauto.metaschema.core.model.constraint.IAllowedValuesConstraint; @@ -78,7 +79,7 @@ void testFile() throws MetaschemaException, IOException { @Test void testConstraints() throws MetaschemaException, IOException { // NOPMD - intentional - ConstraintLoader constraintLoader = new ConstraintLoader(); + IConstraintLoader constraintLoader = new XmlConstraintLoader(); IConstraintSet constraintSet = constraintLoader.load( ObjectUtils.notNull(Paths.get("src/test/resources/content/oscal-constraints.xml"))); diff --git a/core/src/test/resources/computer-metaschema-meta-constraints.xml b/core/src/test/resources/computer-metaschema-meta-constraints.xml index 14a1a295b..3bd312ef3 100644 --- a/core/src/test/resources/computer-metaschema-meta-constraints.xml +++ b/core/src/test/resources/computer-metaschema-meta-constraints.xml @@ -1,11 +1,11 @@ + xsi:schemaLocation="http://csrc.nist.gov/ns/oscal/metaschema/1.0 ../../../../core/metaschema/schema/xml/metaschema-meta-constraints.xsd"> - + diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceModelChoiceGroup.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceModelChoiceGroup.java index 0178d6a3c..5465937a6 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceModelChoiceGroup.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceModelChoiceGroup.java @@ -128,6 +128,7 @@ default IBoundDefinitionModelAssembly getContainingDefinition() { * @return the grouped model instance or {code null} if no instance was bound to * the requested item */ + @Override @NonNull default IBoundInstanceModelGroupedNamed getItemInstance(Object item) { return ObjectUtils.requireNonNull(getGroupedModelInstance(item.getClass())); diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/BindingConstraintLoader.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/BindingConstraintLoader.java new file mode 100644 index 000000000..fd18c7d6c --- /dev/null +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/BindingConstraintLoader.java @@ -0,0 +1,395 @@ +/* + * 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.databind.model.metaschema; + +import gov.nist.secauto.metaschema.core.metapath.MetapathException; +import gov.nist.secauto.metaschema.core.metapath.MetapathExpression; +import gov.nist.secauto.metaschema.core.model.AbstractLoader; +import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition; +import gov.nist.secauto.metaschema.core.model.IConstraintLoader; +import gov.nist.secauto.metaschema.core.model.IDefinition; +import gov.nist.secauto.metaschema.core.model.IFieldDefinition; +import gov.nist.secauto.metaschema.core.model.IFlagDefinition; +import gov.nist.secauto.metaschema.core.model.IModule; +import gov.nist.secauto.metaschema.core.model.MetaschemaException; +import gov.nist.secauto.metaschema.core.model.constraint.AbstractTargetedConstraints; +import gov.nist.secauto.metaschema.core.model.constraint.AssemblyConstraintSet; +import gov.nist.secauto.metaschema.core.model.constraint.AssemblyTargetedConstraints; +import gov.nist.secauto.metaschema.core.model.constraint.DefaultConstraintSet; +import gov.nist.secauto.metaschema.core.model.constraint.DefaultScopedContraints; +import gov.nist.secauto.metaschema.core.model.constraint.FieldTargetedConstraints; +import gov.nist.secauto.metaschema.core.model.constraint.FlagTargetedConstraints; +import gov.nist.secauto.metaschema.core.model.constraint.IConstraintSet; +import gov.nist.secauto.metaschema.core.model.constraint.IFeatureModelConstrained; +import gov.nist.secauto.metaschema.core.model.constraint.IModelConstrained; +import gov.nist.secauto.metaschema.core.model.constraint.IScopedContraints; +import gov.nist.secauto.metaschema.core.model.constraint.ISource; +import gov.nist.secauto.metaschema.core.model.constraint.ITargetedConstraints; +import gov.nist.secauto.metaschema.core.model.constraint.IValueConstrained; +import gov.nist.secauto.metaschema.core.model.constraint.ValueConstraintSet; +import gov.nist.secauto.metaschema.core.util.CollectionUtil; +import gov.nist.secauto.metaschema.core.util.ObjectUtils; +import gov.nist.secauto.metaschema.databind.IBindingContext; +import gov.nist.secauto.metaschema.databind.io.DeserializationFeature; +import gov.nist.secauto.metaschema.databind.io.IBoundLoader; +import gov.nist.secauto.metaschema.databind.model.metaschema.binding.MetapathContext; +import gov.nist.secauto.metaschema.databind.model.metaschema.binding.MetaschemaMetaConstraints; +import gov.nist.secauto.metaschema.databind.model.metaschema.binding.MetaschemaModuleConstraints; +import gov.nist.secauto.metaschema.databind.model.metaschema.impl.ConstraintBindingSupport; + +import org.apache.xmlbeans.impl.values.XmlValueNotSupportedException; + +import java.io.IOException; +import java.net.URI; +import java.util.Collection; +import java.util.Collections; +import java.util.Deque; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import edu.umd.cs.findbugs.annotations.NonNull; +import edu.umd.cs.findbugs.annotations.Nullable; +import nl.talsmasoftware.lazy4j.Lazy; + +/** + * Provides methods to load a constraint set expressed in XML. + *

+ * Loaded constraint instances are cached to avoid the need to load them for + * every use. Any constraint set imported is also loaded and cached + * automatically. + */ +public class BindingConstraintLoader + extends AbstractLoader + implements IConstraintLoader { + + @NonNull + private final IBoundLoader loader; + + public BindingConstraintLoader() { + // ensure the bindings are registered + IBindingContext.instance().registerBindingMatcher(MetaschemaMetaConstraints.class); + IBindingContext.instance().registerBindingMatcher(MetaschemaModuleConstraints.class); + + this.loader = IBindingContext.instance().newBoundLoader(); + this.loader.enableFeature(DeserializationFeature.DESERIALIZE_VALIDATE_CONSTRAINTS); + } + + @Override + protected IConstraintSet parseResource(@NonNull URI resource, @NonNull Deque visitedResources) + throws IOException { + + Object constraintsDocument = loader.load(resource); + + ISource source = ISource.externalSource(resource); + + IConstraintSet retval; + if (constraintsDocument instanceof MetaschemaModuleConstraints) { + MetaschemaModuleConstraints obj = (MetaschemaModuleConstraints) constraintsDocument; + + // now check if this constraint set imports other constraint sets + List imports = CollectionUtil.listOrEmpty(obj.getImports()); + + @NonNull + Map importedConstraints; + if (imports.isEmpty()) { + importedConstraints = ObjectUtils.notNull(Collections.emptyMap()); + } else { + try { + importedConstraints = new LinkedHashMap<>(); + for (MetaschemaModuleConstraints.Import imported : imports) { + URI importedResource = imported.getHref(); + importedResource = ObjectUtils.notNull(resource.resolve(importedResource)); + importedConstraints.put(importedResource, loadInternal(importedResource, visitedResources)); + } + } catch (MetaschemaException ex) { + throw new IOException(ex); + } + } + + // now create this constraint set + retval = new DefaultConstraintSet( + resource, + parseScopedConstraints(obj, source), + new LinkedHashSet<>(importedConstraints.values())); + } else if (constraintsDocument instanceof MetaschemaMetaConstraints) { + MetaschemaMetaConstraints obj = (MetaschemaMetaConstraints) constraintsDocument; + + List targetedConstraints = CollectionUtil.listOrEmpty(obj.getMetapathContexts()).stream() + .flatMap(context -> parseContext(ObjectUtils.notNull(context), null, source) + .getTargetedConstraints().stream()) + .collect(Collectors.toList()); + retval = new MetaConstraintSet(targetedConstraints); + } else { + throw new UnsupportedOperationException(String.format("Unsupported constraint content '%s'.", resource)); + } + return retval; + } + + /** + * Parse individual constraint definitions from the provided XMLBeans object. + * + * @param obj + * the XMLBeans object + * @param source + * the source of the constraint content + * @return the scoped constraint definitions + */ + @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") // intentional + @NonNull + protected List parseScopedConstraints( + @NonNull MetaschemaModuleConstraints obj, + @NonNull ISource source) { + List scopedConstraints = new LinkedList<>(); + + for (MetaschemaModuleConstraints.Scope scope : CollectionUtil.listOrEmpty(obj.getScopes())) { + assert scope != null; + + List targetedConstraints = new LinkedList<>(); + try { + for (Object constraintsObj : CollectionUtil.listOrEmpty(scope.getConstraints())) { + if (constraintsObj instanceof MetaschemaModuleConstraints.Scope.Assembly) { + targetedConstraints.add(handleScopedAssembly( + (MetaschemaModuleConstraints.Scope.Assembly) constraintsObj, + source)); + } else if (constraintsObj instanceof MetaschemaModuleConstraints.Scope.Field) { + targetedConstraints.add(handleScopedField( + (MetaschemaModuleConstraints.Scope.Field) constraintsObj, + source)); + } else if (constraintsObj instanceof MetaschemaModuleConstraints.Scope.Flag) { + targetedConstraints.add(handleScopedFlag( + (MetaschemaModuleConstraints.Scope.Flag) constraintsObj, + source)); + } + } + } catch (MetapathException | XmlValueNotSupportedException ex) { + if (ex.getCause() instanceof MetapathException) { + throw new MetapathException( + String.format("Unable to compile a Metapath in '%s'. %s", + source.getSource(), + ex.getLocalizedMessage()), + ex); + } + throw ex; + } + + URI namespace = ObjectUtils.requireNonNull(scope.getMetaschemaNamespace()); + String shortName = ObjectUtils.requireNonNull(scope.getMetaschemaShortName()); + + scopedConstraints.add(new DefaultScopedContraints( + namespace, + shortName, + CollectionUtil.unmodifiableList(targetedConstraints))); + } + return CollectionUtil.unmodifiableList(scopedConstraints); + } + + private static AssemblyTargetedConstraints handleScopedAssembly( + @NonNull MetaschemaModuleConstraints.Scope.Assembly obj, + @NonNull ISource source) { + MetapathExpression expression = MetapathExpression.compile(ObjectUtils.requireNonNull(obj.getTarget())); + + IModelConstrained constraints = new AssemblyConstraintSet(); + ConstraintBindingSupport.parse(constraints, obj, source); + return new AssemblyTargetedConstraints(expression, constraints); + } + + private static FieldTargetedConstraints handleScopedField( + @NonNull MetaschemaModuleConstraints.Scope.Field obj, + @NonNull ISource source) { + MetapathExpression expression = MetapathExpression.compile(ObjectUtils.requireNonNull(obj.getTarget())); + + IValueConstrained constraints = new ValueConstraintSet(); + ConstraintBindingSupport.parse(constraints, obj, source); + + return new FieldTargetedConstraints(expression, constraints); + } + + private static FlagTargetedConstraints handleScopedFlag( + @NonNull MetaschemaModuleConstraints.Scope.Flag obj, + @NonNull ISource source) { + MetapathExpression expression = MetapathExpression.compile(ObjectUtils.requireNonNull(obj.getTarget())); + + IValueConstrained constraints = new ValueConstraintSet(); + ConstraintBindingSupport.parse(constraints, obj, source); + + return new FlagTargetedConstraints(expression, constraints); + } + + private Context parseContext( + @NonNull MetapathContext contextObj, + @Nullable Context parent, + @NonNull ISource source) { + + List metapaths; + if (parent == null) { + metapaths = CollectionUtil.listOrEmpty(contextObj.getMetapaths()).stream() + .map(metapath -> metapath.getTarget()) + .collect(Collectors.toList()); + } else { + List parentMetapaths = parent.getMetapaths().stream() + .collect(Collectors.toList()); + metapaths = CollectionUtil.listOrEmpty(contextObj.getMetapaths()).stream() + .map(metapath -> metapath.getTarget()) + .flatMap(childPath -> { + return parentMetapaths.stream() + .map(parentPath -> parentPath + '/' + childPath); + }) + .collect(Collectors.toList()); + } + + IModelConstrained constraints = new AssemblyConstraintSet(); + ConstraintBindingSupport.parse(constraints, ObjectUtils.notNull(contextObj.getConstraints()), source); + Context context = new Context(metapaths, constraints); + + List childContexts = CollectionUtil.listOrEmpty(contextObj.getMetapathContexts()).stream() + .map(childObj -> parseContext(ObjectUtils.notNull(childObj), context, source)) + .collect(Collectors.toList()); + + context.addAll(childContexts); + + return context; + } + + private static class Context { + @NonNull + private final List metapaths; + @NonNull + private final IModelConstrained constraints; + @NonNull + private final List childContexts = new LinkedList<>(); + @NonNull + private final Lazy> targetedConstraints; + + public Context( + @NonNull List metapaths, + @NonNull IModelConstrained constraints) { + this.metapaths = metapaths; + this.constraints = constraints; + this.targetedConstraints = Lazy.lazy(() -> { + + Stream paths = getMetapaths().stream() + .map(metapath -> MetapathExpression.compile(ObjectUtils.notNull(metapath))) + .map(compiledMetapath -> new MetaTargetedContraints(ObjectUtils.notNull(compiledMetapath), constraints)); + Stream childPaths = childContexts.stream() + .flatMap(child -> child.getTargetedConstraints().stream()); + + return Stream.concat(paths, childPaths) + .collect(Collectors.toUnmodifiableList()); + }); + } + + @NonNull + public List getTargetedConstraints() { + return targetedConstraints.get(); + } + + public void addAll(@NonNull Collection childContexts) { + childContexts.addAll(childContexts); + } + + @NonNull + public List getMetapaths() { + return metapaths; + } + } + + private static class MetaTargetedContraints + extends AbstractTargetedConstraints + implements IFeatureModelConstrained { + + protected MetaTargetedContraints( + @NonNull MetapathExpression target, + @NonNull IModelConstrained constraints) { + super(target, constraints); + } + + /** + * Apply the constraints to the provided {@code definition}. + *

+ * This will be called when a definition is found that matches the target + * expression. + * + * @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)); + } + + @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)); + } + + @Override + public void target(IFlagDefinition definition) { + applyTo(definition); + } + + @Override + public void target(IFieldDefinition definition) { + applyTo(definition); + } + + @Override + public void target(IAssemblyDefinition definition) { + applyTo(definition); + } + } + + private static final class MetaConstraintSet implements IConstraintSet { + @NonNull + private final List targetedConstraints; + + private MetaConstraintSet(@NonNull List targetedConstraints) { + this.targetedConstraints = targetedConstraints; + } + + @Override + public Iterable getTargetedConstraintsForModule(IModule module) { + return targetedConstraints; + } + + @Override + public Collection getImportedConstraintSets() { + return CollectionUtil.emptyList(); + } + + } +} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/MetapathContext.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/MetapathContext.java index 8b45aac63..6edea95c9 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/MetapathContext.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/MetapathContext.java @@ -47,10 +47,13 @@ name = "metapath-context", moduleClass = MetaschemaModelModule.class) public class MetapathContext { - @BoundField( + @BoundAssembly( description = "A Metapath expression identifying the model node that the constraints will be applied to.", - useName = "metapath") - private String _metapath; + useName = "metapath", + minOccurs = 1, + maxOccurs = -1, + groupAs = @GroupAs(name = "metapaths", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + private List _metapaths; @BoundAssembly( useName = "constraints") @@ -68,12 +71,40 @@ public class MetapathContext { useName = "remarks") private Remarks _remarks; - public String getMetapath() { - return _metapath; + public List getMetapaths() { + return _metapaths; } - public void setMetapath(String value) { - _metapath = value; + public void setMetapaths(List value) { + _metapaths = value; + } + + /** + * Add a new {@link MetaschemaMetapath} item to the underlying collection. + * + * @param item + * the item to add + * @return {@code true} + */ + public boolean addMetapath(MetaschemaMetapath item) { + MetaschemaMetapath value = ObjectUtils.requireNonNull(item, "item cannot be null"); + if (_metapaths == null) { + _metapaths = new LinkedList<>(); + } + return _metapaths.add(value); + } + + /** + * Remove the first matching {@link MetaschemaMetapath} item from the underlying + * collection. + * + * @param item + * the item to remove + * @return {@code true} if the item was removed or {@code false} otherwise + */ + public boolean removeMetapath(MetaschemaMetapath item) { + MetaschemaMetapath value = ObjectUtils.requireNonNull(item, "item cannot be null"); + return _metapaths != null && _metapaths.remove(value); } public AssemblyConstraints getConstraints() { diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/MetaschemaMetapath.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/MetaschemaMetapath.java new file mode 100644 index 000000000..878fd260d --- /dev/null +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/MetaschemaMetapath.java @@ -0,0 +1,67 @@ +/* + * 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.databind.model.metaschema.binding; + +import gov.nist.secauto.metaschema.core.datatype.adapter.StringAdapter; +import gov.nist.secauto.metaschema.databind.model.annotations.BoundFlag; +import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; + +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +/** + * A Metapath expression identifying the model node that the constraints will be + * applied to. + */ +@SuppressWarnings({ + "PMD.DataClass", + "PMD.FieldNamingConventions", +}) +@MetaschemaAssembly( + description = "A Metapath expression identifying the model node that the constraints will be applied to.", + name = "metaschema-metapath", + moduleClass = MetaschemaModelModule.class) +public class MetaschemaMetapath { + @BoundFlag( + name = "target", + required = true, + typeAdapter = StringAdapter.class) + private String _target; + + public String getTarget() { + return _target; + } + + public void setTarget(String value) { + _target = value; + } + + @Override + public String toString() { + return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); + } +} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/MetaschemaModuleConstraints.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/MetaschemaModuleConstraints.java index 8cb06b839..e40f725aa 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/MetaschemaModuleConstraints.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/MetaschemaModuleConstraints.java @@ -31,6 +31,7 @@ import gov.nist.secauto.metaschema.core.datatype.adapter.UriAdapter; import gov.nist.secauto.metaschema.core.datatype.adapter.UriReferenceAdapter; import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior; +import gov.nist.secauto.metaschema.core.util.CollectionUtil; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.metaschema.databind.model.annotations.BoundAssembly; import gov.nist.secauto.metaschema.databind.model.annotations.BoundChoiceGroup; @@ -39,6 +40,9 @@ import gov.nist.secauto.metaschema.databind.model.annotations.BoundGroupedAssembly; import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs; import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; +import gov.nist.secauto.metaschema.databind.model.metaschema.IModelConstraintsBase; +import gov.nist.secauto.metaschema.databind.model.metaschema.ITargetedConstraintBase; +import gov.nist.secauto.metaschema.databind.model.metaschema.IValueConstraintsBase; import org.apache.commons.lang3.builder.ReflectionToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; @@ -253,7 +257,7 @@ public String toString() { @MetaschemaAssembly( name = "flag", moduleClass = MetaschemaModelModule.class) - public static class Flag { + public static class Flag implements IValueConstraintsBase { @BoundFlag( formalName = "Constraint Target Metapath Expression", name = "target", @@ -275,7 +279,12 @@ public static class Flag { binding = FlagMatches.class) }, groupAs = @GroupAs(name = "rules", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) - private List _rules; + private List _rules; + + @Override + public List getLets() { + return CollectionUtil.emptyList(); + } public String getTarget() { return _target; @@ -285,11 +294,12 @@ public void setTarget(String value) { _target = value; } - public List getRules() { + @Override + public List getRules() { return _rules; } - public void setRules(List value) { + public void setRules(List value) { _rules = value; } @@ -302,7 +312,7 @@ public String toString() { @MetaschemaAssembly( name = "field", moduleClass = MetaschemaModelModule.class) - public static class Field { + public static class Field implements IValueConstraintsBase { @BoundFlag( formalName = "Constraint Target Metapath Expression", name = "target", @@ -324,7 +334,7 @@ public static class Field { binding = TargetedMatchesConstraint.class) }, groupAs = @GroupAs(name = "rules", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) - private List _rules; + private List _rules; public String getTarget() { return _target; @@ -334,11 +344,17 @@ public void setTarget(String value) { _target = value; } - public List getRules() { + @Override + public List getLets() { + return CollectionUtil.emptyList(); + } + + @Override + public List getRules() { return _rules; } - public void setRules(List value) { + public void setRules(List value) { _rules = value; } @@ -351,7 +367,7 @@ public String toString() { @MetaschemaAssembly( name = "assembly", moduleClass = MetaschemaModelModule.class) - public static class Assembly { + public static class Assembly implements IModelConstraintsBase { @BoundFlag( formalName = "Constraint Target Metapath Expression", name = "target", @@ -379,7 +395,7 @@ public static class Assembly { binding = TargetedHasCardinalityConstraint.class) }, groupAs = @GroupAs(name = "rules", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) - private List _rules; + private List _rules; public String getTarget() { return _target; @@ -389,11 +405,17 @@ public void setTarget(String value) { _target = value; } - public List getRules() { + @Override + public List getLets() { + return CollectionUtil.emptyList(); + } + + @Override + public List getRules() { return _rules; } - public void setRules(List value) { + public void setRules(List value) { _rules = value; } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/ConstraintBindingSupport.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/ConstraintBindingSupport.java index 4cea99860..63e10c9f4 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/ConstraintBindingSupport.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/ConstraintBindingSupport.java @@ -145,7 +145,6 @@ public static void parse( constraintSet.addConstraint(constraint); } } - } @NonNull diff --git a/databind/src/test/java/gov/nist/secauto/metaschema/databind/DefaultBindingContextTest.java b/databind/src/test/java/gov/nist/secauto/metaschema/databind/DefaultBindingContextTest.java index 3bf39ad75..431600079 100644 --- a/databind/src/test/java/gov/nist/secauto/metaschema/databind/DefaultBindingContextTest.java +++ b/databind/src/test/java/gov/nist/secauto/metaschema/databind/DefaultBindingContextTest.java @@ -30,14 +30,16 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition; +import gov.nist.secauto.metaschema.core.model.IConstraintLoader; import gov.nist.secauto.metaschema.core.model.MetaschemaException; import gov.nist.secauto.metaschema.core.model.constraint.IConstraint; import gov.nist.secauto.metaschema.core.model.constraint.IConstraintSet; -import gov.nist.secauto.metaschema.core.model.xml.ConstraintLoader; import gov.nist.secauto.metaschema.core.model.xml.ExternalConstraintsModulePostProcessor; +import gov.nist.secauto.metaschema.core.model.xml.XmlConstraintLoader; import gov.nist.secauto.metaschema.core.util.CollectionUtil; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.metaschema.databind.model.IBoundModule; +import gov.nist.secauto.metaschema.databind.model.metaschema.BindingConstraintLoader; import gov.nist.secauto.metaschema.databind.model.test.TestMetaschema; import org.junit.jupiter.api.Test; @@ -50,7 +52,25 @@ class DefaultBindingContextTest { @Test void testConstraints() throws MetaschemaException, IOException { // NOPMD - intentional - ConstraintLoader constraintLoader = new ConstraintLoader(); + IConstraintLoader constraintLoader = new XmlConstraintLoader(); + IConstraintSet constraintSet = constraintLoader.load( + ObjectUtils.notNull(Paths.get("src/test/resources/content/constraints.xml"))); + + ExternalConstraintsModulePostProcessor postProcessor + = new ExternalConstraintsModulePostProcessor(CollectionUtil.singleton(constraintSet)); + IBindingContext bindingContext = new DefaultBindingContext(CollectionUtil.singletonList(postProcessor)); + IBoundModule module = bindingContext.registerModule(TestMetaschema.class); + + IAssemblyDefinition root = module.getExportedAssemblyDefinitionByName("root"); + + assertNotNull(root, "root not found"); + List constraints = root.getConstraints(); + assertFalse(constraints.isEmpty(), "a constraint was expected"); + } + + @Test + void testConstraintsUsingBinding() throws MetaschemaException, IOException { // NOPMD - intentional + IConstraintLoader constraintLoader = new BindingConstraintLoader(); IConstraintSet constraintSet = constraintLoader.load( ObjectUtils.notNull(Paths.get("src/test/resources/content/constraints.xml"))); diff --git a/databind/src/test/resources/content/constraints.xml b/databind/src/test/resources/content/constraints.xml index 2074a12ef..272ba6745 100644 --- a/databind/src/test/resources/content/constraints.xml +++ b/databind/src/test/resources/content/constraints.xml @@ -1,7 +1,7 @@ + xsi:schemaLocation="http://csrc.nist.gov/ns/oscal/metaschema/1.0 ../../../../../core/metaschema/schema/xml/metaschema.xsd"> Test Constraints 1.0.4 diff --git a/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/commands/AbstractValidateContentCommand.java b/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/commands/AbstractValidateContentCommand.java index c7e4bda24..170e72d6e 100644 --- a/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/commands/AbstractValidateContentCommand.java +++ b/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/commands/AbstractValidateContentCommand.java @@ -37,10 +37,10 @@ import gov.nist.secauto.metaschema.cli.processor.command.DefaultExtraArgument; import gov.nist.secauto.metaschema.cli.processor.command.ExtraArgument; import gov.nist.secauto.metaschema.cli.util.LoggingValidationHandler; +import gov.nist.secauto.metaschema.core.model.IConstraintLoader; import gov.nist.secauto.metaschema.core.model.MetaschemaException; import gov.nist.secauto.metaschema.core.model.constraint.IConstraintSet; import gov.nist.secauto.metaschema.core.model.validation.IValidationResult; -import gov.nist.secauto.metaschema.core.model.xml.ConstraintLoader; import gov.nist.secauto.metaschema.core.util.CollectionUtil; import gov.nist.secauto.metaschema.core.util.CustomCollectors; import gov.nist.secauto.metaschema.core.util.ObjectUtils; @@ -50,6 +50,7 @@ import gov.nist.secauto.metaschema.databind.io.Format; import gov.nist.secauto.metaschema.databind.io.FormatDetector; import gov.nist.secauto.metaschema.databind.io.IBoundLoader; +import gov.nist.secauto.metaschema.databind.model.metaschema.BindingConstraintLoader; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.Option; @@ -162,7 +163,7 @@ public ExitStatus execute() { Set constraintSets; if (cmdLine.hasOption(CONSTRAINTS_OPTION)) { - ConstraintLoader constraintLoader = new ConstraintLoader(); + IConstraintLoader constraintLoader = new BindingConstraintLoader(); constraintSets = new LinkedHashSet<>(); String[] args = cmdLine.getOptionValues(CONSTRAINTS_OPTION); for (String arg : args) { From 36ee01bff46eae364ef3ca89a51d4d89c8688f25 Mon Sep 17 00:00:00 2001 From: David Waltermire Date: Wed, 21 Feb 2024 10:39:19 -0500 Subject: [PATCH 3/5] Added support for configuring external constraints in the maven plugin. --- core/metaschema | 2 +- ...xternalConstraintsModulePostProcessor.java | 4 +- .../metaschema/BindingConstraintLoader.java | 3 +- metaschema-maven-plugin/pom.xml | 376 +++++++++--------- .../src/it/generate-sources-test/pom.xml | 40 -- .../src/it/generate-sources/pom.xml | 52 +++ .../verify.groovy | 0 .../maven/plugin/AbstractMetaschemaMojo.java | 32 +- .../maven/plugin/GenerateSchemaMojo.java | 21 +- .../maven/plugin/GenerateSourcesMojo.java | 17 +- 10 files changed, 305 insertions(+), 242 deletions(-) delete mode 100644 metaschema-maven-plugin/src/it/generate-sources-test/pom.xml create mode 100644 metaschema-maven-plugin/src/it/generate-sources/pom.xml rename metaschema-maven-plugin/src/it/{generate-sources-test => generate-sources}/verify.groovy (100%) diff --git a/core/metaschema b/core/metaschema index bb4f6396d..e9c0a6c52 160000 --- a/core/metaschema +++ b/core/metaschema @@ -1 +1 @@ -Subproject commit bb4f6396d6b2c15bec2a4e7255c34bd5f6925cf3 +Subproject commit e9c0a6c525f28e2068300a7c645ddbf972c7e9e9 diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/ExternalConstraintsModulePostProcessor.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/ExternalConstraintsModulePostProcessor.java index 6c54c10bc..30bee9958 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/ExternalConstraintsModulePostProcessor.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/ExternalConstraintsModulePostProcessor.java @@ -43,8 +43,8 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import java.util.Collection; import java.util.List; -import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -55,7 +55,7 @@ public class ExternalConstraintsModulePostProcessor implements IModuleLoader.IMo @NonNull private final List registeredConstraintSets; - public ExternalConstraintsModulePostProcessor(@NonNull Set additionalConstraintSets) { + public ExternalConstraintsModulePostProcessor(@NonNull Collection additionalConstraintSets) { this.registeredConstraintSets = ObjectUtils.notNull(additionalConstraintSets.stream() .flatMap(set -> Stream.concat( Stream.of(set), diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/BindingConstraintLoader.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/BindingConstraintLoader.java index fd18c7d6c..d72d23c57 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/BindingConstraintLoader.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/BindingConstraintLoader.java @@ -118,8 +118,7 @@ protected IConstraintSet parseResource(@NonNull URI resource, @NonNull Deque imports = CollectionUtil.listOrEmpty(obj.getImports()); - @NonNull - Map importedConstraints; + @NonNull Map importedConstraints; if (imports.isEmpty()) { importedConstraints = ObjectUtils.notNull(Collections.emptyMap()); } else { diff --git a/metaschema-maven-plugin/pom.xml b/metaschema-maven-plugin/pom.xml index 0b841e774..3fde0af51 100644 --- a/metaschema-maven-plugin/pom.xml +++ b/metaschema-maven-plugin/pom.xml @@ -1,198 +1,198 @@ - - 4.0.0 - - gov.nist.secauto.metaschema - metaschema-framework - 1.0.0-M2-SNAPSHOT - + + 4.0.0 + + gov.nist.secauto.metaschema + metaschema-framework + 1.0.0-M2-SNAPSHOT + - metaschema-maven-plugin + metaschema-maven-plugin - maven-plugin + maven-plugin - Metaschema Maven Plugin + Metaschema Maven Plugin - ${site.url}${project.artifactId}/ - - - nist-pages - ${site.url}${project.artifactId}/ - - + ${site.url}${project.artifactId}/ + + + nist-pages + ${site.url}${project.artifactId}/ + + - - 1.1 - + + ${plugin.maven-plugin.version} + + + + ${project.parent.groupId} + metaschema-core + + + ${project.parent.groupId} + metaschema-databind + + + ${project.parent.groupId} + metaschema-schema-generator + + + org.apache.maven + maven-plugin-api + ${mojo.maven.version} + provided + + + org.apache.maven + maven-core + ${mojo.maven.version} + provided + + + org.apache.maven + maven-artifact + ${mojo.maven.version} + provided + + + org.apache.maven + maven-model + ${mojo.maven.version} + provided + - - ${plugin.maven-plugin.version} - - - - ${project.parent.groupId} - metaschema-core - - - ${project.parent.groupId} - metaschema-databind - - - ${project.parent.groupId} - metaschema-schema-generator - - - org.apache.maven - maven-plugin-api - ${mojo.maven.version} - provided - - - org.apache.maven - maven-core - ${mojo.maven.version} - provided - - - org.apache.maven - maven-artifact - ${mojo.maven.version} - provided - - - org.apache.maven - maven-model - ${mojo.maven.version} - provided - + + org.apache.maven.shared + file-management + 3.1.0 + - - org.apache.maven.plugin-tools - maven-plugin-annotations - provided - true - - - org.codehaus.plexus - plexus-utils - ${dependency.plexus-utils.version} - - - org.codehaus.plexus - plexus-build-api - ${dependency.plexus-build-api.version} - + + org.apache.maven.plugin-tools + maven-plugin-annotations + provided + true + + + org.codehaus.plexus + plexus-utils + ${dependency.plexus-utils.version} + + + org.codehaus.plexus + plexus-build-api + ${dependency.plexus-build-api.version} + + + org.apache.logging.log4j + log4j-core + + - - org.apache.logging.log4j - log4j-core - - - - - - - - - org.eclipse.m2e - lifecycle-mapping - 1.0.0 - - - - - - - org.apache.maven.plugins - - - maven-plugin-plugin - - - [3.6.0,) - - - descriptor - helpmojo - - - - - - - - - - - - - - - org.apache.maven.plugins - maven-plugin-plugin - - - default-addPluginArtifactMetadata - package - - addPluginArtifactMetadata - - - - default-descriptor - process-classes - - descriptor - - - metaschema - false - - - - help-mojo - - helpmojo - - - false - - - - - - - - - run-its - - - - org.apache.maven.plugins - maven-invoker-plugin - - true - ${project.build.directory}/it - - */pom.xml - - verify - ${project.build.directory}/local-repo - src/it/settings.xml - - - - integration-test - - install - integration-test - verify - - - - - - - - + + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + org.apache.maven.plugins + maven-plugin-plugin + [3.6.0,) + + descriptor + helpmojo + + + + + + + + + + + + + + + org.apache.maven.plugins + maven-plugin-plugin + + + default-addPluginArtifactMetadata + package + + addPluginArtifactMetadata + + + + default-descriptor + process-classes + + descriptor + + + metaschema + false + + + + help-mojo + + helpmojo + + + + + + + + + run-its + + true + + + + + org.apache.maven.plugins + maven-invoker-plugin + + true + ${project.build.directory}/it + + */pom.xml + + verify + ${project.build.directory}/local-repo + src/it/settings.xml + true + true + true + + + + default-cli + + install + integration-test + verify + + + + + + + + \ No newline at end of file diff --git a/metaschema-maven-plugin/src/it/generate-sources-test/pom.xml b/metaschema-maven-plugin/src/it/generate-sources-test/pom.xml deleted file mode 100644 index de32bc349..000000000 --- a/metaschema-maven-plugin/src/it/generate-sources-test/pom.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - 4.0.0 - - gov.nist.secauto.metaschema.it - generate-sources-test - 0.12.0-SNAPSHOT - - A simple IT verifying the basic use case. - - - UTF-8 - - - - - - @project.groupId@ - @project.artifactId@ - @project.version@ - - - generate-sources-test - validate - - generate-sources - - - ../../../../../../../OSCAL/src/metaschema - - oscal_*_metaschema.xml - - - - - - - - diff --git a/metaschema-maven-plugin/src/it/generate-sources/pom.xml b/metaschema-maven-plugin/src/it/generate-sources/pom.xml new file mode 100644 index 000000000..a2b607d30 --- /dev/null +++ b/metaschema-maven-plugin/src/it/generate-sources/pom.xml @@ -0,0 +1,52 @@ + + + 4.0.0 + + gov.nist.secauto.metaschema.it + generate-sources-test + @project.version@ + + A simple IT verifying the basic use case. + + + UTF-8 + + + + + @project.groupId@ + metaschema-databind + @project.version@ + + + + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + + generate-sources-test + generate-sources + + generate-sources + + + ../../../../core/metaschema/schema/metaschema + + *-metaschema.xml + + + ../../../../core/metaschema/schema/metaschema/metaschema-module-constraints.xml + + + + + + + + diff --git a/metaschema-maven-plugin/src/it/generate-sources-test/verify.groovy b/metaschema-maven-plugin/src/it/generate-sources/verify.groovy similarity index 100% rename from metaschema-maven-plugin/src/it/generate-sources-test/verify.groovy rename to metaschema-maven-plugin/src/it/generate-sources/verify.groovy diff --git a/metaschema-maven-plugin/src/main/java/gov/nist/secauto/metaschema/maven/plugin/AbstractMetaschemaMojo.java b/metaschema-maven-plugin/src/main/java/gov/nist/secauto/metaschema/maven/plugin/AbstractMetaschemaMojo.java index e8f3d5166..915476880 100644 --- a/metaschema-maven-plugin/src/main/java/gov/nist/secauto/metaschema/maven/plugin/AbstractMetaschemaMojo.java +++ b/metaschema-maven-plugin/src/main/java/gov/nist/secauto/metaschema/maven/plugin/AbstractMetaschemaMojo.java @@ -26,6 +26,13 @@ package gov.nist.secauto.metaschema.maven.plugin; +import gov.nist.secauto.metaschema.core.model.IConstraintLoader; +import gov.nist.secauto.metaschema.core.model.MetaschemaException; +import gov.nist.secauto.metaschema.core.model.constraint.IConstraintSet; +import gov.nist.secauto.metaschema.core.util.CollectionUtil; +import gov.nist.secauto.metaschema.core.util.ObjectUtils; +import gov.nist.secauto.metaschema.databind.model.metaschema.BindingConstraintLoader; + import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecution; import org.apache.maven.plugins.annotations.Component; @@ -35,7 +42,10 @@ import org.sonatype.plexus.build.incremental.BuildContext; import java.io.File; +import java.io.IOException; import java.net.URI; +import java.util.ArrayList; +import java.util.List; import java.util.Objects; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -119,9 +129,16 @@ public abstract class AbstractMetaschemaMojo private File metaschemaDir; /** - * A set of inclusion patterns used to select which metaschema are to be + * A list of files containing Metaschema module constraints files. + */ + @Parameter(property = "constraints") + private File[] constraints; + + /** + * A set of inclusion patterns used to select which Metaschema modules are to be * processed. By default, all files are processed. */ + @Parameter protected String[] includes; @@ -223,7 +240,7 @@ protected final String getEncoding() { * * @return the stream */ - protected Stream getSources() { + protected Stream getModuleSources() { DirectoryScanner ds = new DirectoryScanner(); ds.setBasedir(metaschemaDir); ds.setIncludes(includes != null && includes.length > 0 ? includes : DEFAULT_INCLUDES); @@ -235,6 +252,15 @@ protected Stream getSources() { return Stream.of(ds.getIncludedFiles()).map(filename -> new File(metaschemaDir, filename)).distinct(); } + protected List getConstraints() throws MetaschemaException, IOException { + IConstraintLoader loader = new BindingConstraintLoader(); + List constraintSets = new ArrayList<>(constraints.length); + for (File constraint : this.constraints) { + constraintSets.add(loader.load(ObjectUtils.notNull(constraint))); + } + return CollectionUtil.unmodifiableList(constraintSets); + } + /** * Determine if the execution of this mojo should be skipped. * @@ -294,7 +320,7 @@ protected boolean isGenerationRequired() { } if (!generate) { - for (File sourceFile : getSources().collect(Collectors.toList())) { + for (File sourceFile : getModuleSources().collect(Collectors.toList())) { getLog().info("Source file: " + sourceFile.getPath()); if (sourceFile.lastModified() > staleLastModified) { generate = true; diff --git a/metaschema-maven-plugin/src/main/java/gov/nist/secauto/metaschema/maven/plugin/GenerateSchemaMojo.java b/metaschema-maven-plugin/src/main/java/gov/nist/secauto/metaschema/maven/plugin/GenerateSchemaMojo.java index e0381ceda..076ea2170 100644 --- a/metaschema-maven-plugin/src/main/java/gov/nist/secauto/metaschema/maven/plugin/GenerateSchemaMojo.java +++ b/metaschema-maven-plugin/src/main/java/gov/nist/secauto/metaschema/maven/plugin/GenerateSchemaMojo.java @@ -31,8 +31,11 @@ import gov.nist.secauto.metaschema.core.configuration.IMutableConfiguration; import gov.nist.secauto.metaschema.core.model.IModule; import gov.nist.secauto.metaschema.core.model.MetaschemaException; -import gov.nist.secauto.metaschema.core.model.xml.ModuleLoader; +import gov.nist.secauto.metaschema.core.model.constraint.IConstraintSet; +import gov.nist.secauto.metaschema.core.model.xml.ExternalConstraintsModulePostProcessor; +import gov.nist.secauto.metaschema.core.util.CollectionUtil; import gov.nist.secauto.metaschema.core.util.ObjectUtils; +import gov.nist.secauto.metaschema.databind.model.metaschema.BindingModuleLoader; import gov.nist.secauto.metaschema.schemagen.ISchemaGenerator; import gov.nist.secauto.metaschema.schemagen.SchemaGenerationFeature; import gov.nist.secauto.metaschema.schemagen.json.JsonSchemaGenerator; @@ -271,11 +274,21 @@ public void execute() throws MojoExecutionException { throw new MojoExecutionException("Unable to create output directory: " + outputDir); } - // generate Java sources based on provided Module sources - final ModuleLoader loader = new ModuleLoader(); + List constraints; + try { + constraints = getConstraints(); + } catch (MetaschemaException | IOException ex) { + throw new MojoExecutionException("Unable to load external constraints.", ex); + } + + // generate Java sources based on provided metaschema sources + final BindingModuleLoader loader = constraints.isEmpty() + ? new BindingModuleLoader() + : new BindingModuleLoader( + CollectionUtil.singletonList(new ExternalConstraintsModulePostProcessor(constraints))); loader.allowEntityResolution(); final Set modules = new HashSet<>(); - for (File source : getSources().collect(Collectors.toList())) { + for (File source : getModuleSources().collect(Collectors.toList())) { getLog().info("Using metaschema source: " + source.getPath()); IModule module; try { diff --git a/metaschema-maven-plugin/src/main/java/gov/nist/secauto/metaschema/maven/plugin/GenerateSourcesMojo.java b/metaschema-maven-plugin/src/main/java/gov/nist/secauto/metaschema/maven/plugin/GenerateSourcesMojo.java index e4066743b..8f7661a71 100644 --- a/metaschema-maven-plugin/src/main/java/gov/nist/secauto/metaschema/maven/plugin/GenerateSourcesMojo.java +++ b/metaschema-maven-plugin/src/main/java/gov/nist/secauto/metaschema/maven/plugin/GenerateSourcesMojo.java @@ -28,6 +28,9 @@ import gov.nist.secauto.metaschema.core.model.IModule; import gov.nist.secauto.metaschema.core.model.MetaschemaException; +import gov.nist.secauto.metaschema.core.model.constraint.IConstraintSet; +import gov.nist.secauto.metaschema.core.model.xml.ExternalConstraintsModulePostProcessor; +import gov.nist.secauto.metaschema.core.util.CollectionUtil; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.metaschema.databind.codegen.JavaGenerator; import gov.nist.secauto.metaschema.databind.codegen.config.DefaultBindingConfiguration; @@ -156,11 +159,21 @@ public void execute() throws MojoExecutionException { } } + List constraints; + try { + constraints = getConstraints(); + } catch (MetaschemaException | IOException ex) { + throw new MojoExecutionException("Unable to load external constraints.", ex); + } + // generate Java sources based on provided metaschema sources - final BindingModuleLoader loader = new BindingModuleLoader(); + final BindingModuleLoader loader = constraints.isEmpty() + ? new BindingModuleLoader() + : new BindingModuleLoader( + CollectionUtil.singletonList(new ExternalConstraintsModulePostProcessor(constraints))); loader.allowEntityResolution(); final Set modules = new HashSet<>(); - for (File source : getSources().collect(Collectors.toList())) { + for (File source : getModuleSources().collect(Collectors.toList())) { getLog().info("Using metaschema source: " + source.getPath()); IModule module; try { From 2993e4cba24edcdc41173d07acf3cb54d7f05c96 Mon Sep 17 00:00:00 2001 From: David Waltermire Date: Wed, 21 Feb 2024 21:50:04 -0500 Subject: [PATCH 4/5] Updated to latest metaschema develop branch commit. --- core/metaschema | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/metaschema b/core/metaschema index e9c0a6c52..16919d512 160000 --- a/core/metaschema +++ b/core/metaschema @@ -1 +1 @@ -Subproject commit e9c0a6c525f28e2068300a7c645ddbf972c7e9e9 +Subproject commit 16919d512f96110c49fa2edcd3e6ee9a377c0b69 From 0782426c4421b63b542535bd72b6790c639c6ccd Mon Sep 17 00:00:00 2001 From: David Waltermire Date: Wed, 21 Feb 2024 22:27:02 -0500 Subject: [PATCH 5/5] Cleaned up commented code and a few PMD warnings. --- .../metaschema/core/metapath/cst/BuildCSTVisitor.java | 7 +++++-- .../metaschema/core/model/xml/XmlMetaConstraintLoader.java | 2 -- .../gov/nist/secauto/metaschema/core/util/UriUtils.java | 1 + 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/BuildCSTVisitor.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/BuildCSTVisitor.java index 4e18ed028..c80d39558 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/BuildCSTVisitor.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/BuildCSTVisitor.java @@ -745,6 +745,7 @@ protected IExpression handleAndexpr(AndexprContext ctx) { * ==================================================================== */ + @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") @Override protected IExpression handleForexpr(ForexprContext ctx) { SimpleforclauseContext simpleForClause = ctx.simpleforclause(); @@ -752,7 +753,8 @@ protected IExpression handleForexpr(ForexprContext ctx) { // for SimpleForBinding ("," SimpleForBinding)* int bindingCount = simpleForClause.getChildCount() / 2; - @NonNull IExpression retval = ObjectUtils.notNull(ctx.exprsingle().accept(this)); + @NonNull + IExpression retval = ObjectUtils.notNull(ctx.exprsingle().accept(this)); // step through in reverse for (int idx = bindingCount - 1; idx >= 0; idx--) { @@ -781,7 +783,8 @@ protected IExpression handleForexpr(ForexprContext ctx) { @Override protected IExpression handleLet(LetexprContext context) { - @NonNull IExpression retval = ObjectUtils.notNull(context.exprsingle().accept(this)); + @NonNull + IExpression retval = ObjectUtils.notNull(context.exprsingle().accept(this)); SimpleletclauseContext letClause = context.simpleletclause(); List clauses = letClause.simpleletbinding(); 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 231120d1a..016c3326e 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 @@ -65,8 +65,6 @@ public class XmlMetaConstraintLoader extends AbstractLoader implements IConstraintLoader { - // private static final Logger LOGGER = - // LogManager.getLogger(XmlMetaConstraintLoader.class); @Override protected IConstraintSet parseResource(URI resource, Deque visitedResources) throws IOException { diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/util/UriUtils.java b/core/src/main/java/gov/nist/secauto/metaschema/core/util/UriUtils.java index aafd054e8..60a99eb50 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/util/UriUtils.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/util/UriUtils.java @@ -53,6 +53,7 @@ private UriUtils() { * @throws URISyntaxException * an error if the location string is not convertible to URI */ + @SuppressWarnings("PMD.PreserveStackTrace") public static URI toUri(@NonNull String location, @NonNull URI baseUri) throws URISyntaxException { URI asUri; try {