From 585ff2f49b23207ef5be395980f2bfe1c564f17a Mon Sep 17 00:00:00 2001 From: David Waltermire Date: Fri, 22 Nov 2024 13:46:27 -0500 Subject: [PATCH] Switched flag retrieval to using Integer indexes instead of qnames. --- .../core/model/FlagContainerBuilder.java | 26 +++++++++---------- .../core/model/IContainerFlagSupport.java | 15 ++++++++--- .../core/model/IFeatureContainerFlag.java | 3 +-- .../core/model/IModelDefinition.java | 8 +++--- .../model/INamedModelInstanceGrouped.java | 3 ++- .../impl/DefaultContainerFlagSupport.java | 7 +++-- .../core/model/impl/EmptyFlagContainer.java | 3 +-- .../xml/impl/XmlFlagContainerSupport.java | 4 ++- .../xml/impl/XmlGlobalFieldDefinition.java | 5 +--- .../impl/XmlGroupedInlineFieldDefinition.java | 5 +--- .../xml/impl/XmlInlineFieldDefinition.java | 5 +--- .../metaschema/core/qname/IEnhancedQName.java | 4 ++- .../item/node/DefaultNodeItemFactoryTest.java | 5 ++-- .../core/testing/AbstractModelBuilder.java | 10 +++---- .../core/testing/AssemblyBuilder.java | 2 +- .../metaschema/core/testing/FieldBuilder.java | 3 +-- .../IBoundInstanceModelGroupedNamed.java | 3 ++- .../model/impl/FlagContainerSupport.java | 7 +++-- .../model/impl/InstanceModelChoiceGroup.java | 6 ++--- .../impl/DefinitionFieldGlobal.java | 3 ++- .../metaschema/impl/FlagContainerSupport.java | 3 ++- .../impl/InstanceModelFieldInline.java | 2 +- .../impl/InstanceModelGroupedFieldInline.java | 5 +--- .../databind/io/xml/XmlParserTest.java | 2 +- .../databind/testing/model/ModelTest.java | 6 ++--- .../AbstractModelDefinitionJsonSchema.java | 2 +- 26 files changed, 72 insertions(+), 75 deletions(-) diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/FlagContainerBuilder.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/FlagContainerBuilder.java index 31625d691..5876545d3 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/FlagContainerBuilder.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/FlagContainerBuilder.java @@ -6,7 +6,7 @@ package gov.nist.secauto.metaschema.core.model; import gov.nist.secauto.metaschema.core.model.impl.DefaultContainerFlagSupport; -import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; +import gov.nist.secauto.metaschema.core.qname.EQNameFactory; import gov.nist.secauto.metaschema.core.util.CollectionUtil; import gov.nist.secauto.metaschema.core.util.CustomCollectors; import gov.nist.secauto.metaschema.core.util.ObjectUtils; @@ -26,7 +26,7 @@ public class FlagContainerBuilder implements IFlagConta private static final Logger LOGGER = LogManager.getLogger(FlagContainerBuilder.class); @Nullable - private final IEnhancedQName jsonKeyName; + private final Integer jsonKeyIndex; @NonNull private final List flags; @@ -34,12 +34,12 @@ public class FlagContainerBuilder implements IFlagConta * Construct a new flag container using the provided flag qualified name as the * JSON key. * - * @param jsonKeyName - * the qualified name of the JSON key or {@code null} if no JSON key is - * configured + * @param jsonKeyIndex + * the qualified name index of the JSON key or {@code null} if no JSON + * key is configured */ - public FlagContainerBuilder(@Nullable IEnhancedQName jsonKeyName) { - this.jsonKeyName = jsonKeyName; + public FlagContainerBuilder(@Nullable Integer jsonKeyIndex) { + this.jsonKeyIndex = jsonKeyIndex; this.flags = new LinkedList<>(); } @@ -56,29 +56,29 @@ public IContainerFlagSupport build() { if (flags.isEmpty()) { retval = IContainerFlagSupport.empty(); } else { - Map flagMap = CollectionUtil.unmodifiableMap(ObjectUtils.notNull(flags.stream() + Map flagMap = CollectionUtil.unmodifiableMap(ObjectUtils.notNull(flags.stream() .collect( CustomCollectors.toMap( - INamed::getQName, + flag -> flag.getQName().getIndexPosition(), CustomCollectors.identity(), FlagContainerBuilder::handleShadowedInstances, LinkedHashMap::new)))); - T jsonKey = jsonKeyName == null ? null : flagMap.get(jsonKeyName); + T jsonKey = jsonKeyIndex == null ? null : flagMap.get(jsonKeyIndex); retval = new DefaultContainerFlagSupport<>(flagMap, jsonKey); } return retval; } private static INSTANCE handleShadowedInstances( - @NonNull IEnhancedQName key, + @NonNull Integer keyIndex, @NonNull INSTANCE shadowed, @NonNull INSTANCE shadowing) { if (!shadowed.equals(shadowing) && LOGGER.isErrorEnabled()) { IModelDefinition owningDefinition = shadowing.getContainingDefinition(); IModule module = owningDefinition.getContainingModule(); - LOGGER.error("Unexpected duplicate flag instance named '%s' in definition '%s' in module name '%s' at '%s'", - key, + LOGGER.error("Unexpected duplicate flag instance name '%s' in definition '%s' in module name '%s' at '%s'", + EQNameFactory.instance().get(keyIndex), owningDefinition.getDefinitionQName(), module.getShortName(), module.getLocation()); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IContainerFlagSupport.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IContainerFlagSupport.java index 52815c549..c758e2218 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IContainerFlagSupport.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IContainerFlagSupport.java @@ -6,13 +6,22 @@ package gov.nist.secauto.metaschema.core.model; import gov.nist.secauto.metaschema.core.model.impl.EmptyFlagContainer; -import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; import java.util.Map; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; +/** + * Provides support for managing the flag contents of a + * {@link IModelDefinition}. + *

+ * This interface provides the underlying data used by + * {@link IFeatureContainerFlag}. + * + * @param + * the Java type of the managed flag instance data + */ public interface IContainerFlagSupport { /** * Provides an empty instance. @@ -50,7 +59,7 @@ static IFlagContainerBuilder builder() { * @return the flag container */ @NonNull - static IFlagContainerBuilder builder(@NonNull IEnhancedQName jsonKey) { + static IFlagContainerBuilder builder(@NonNull Integer jsonKey) { return new FlagContainerBuilder<>(jsonKey); } @@ -60,7 +69,7 @@ static IFlagContainerBuilder builder(@NonNull IEnha * @return the mapping of flag effective name to flag instance */ @NonNull - Map getFlagInstanceMap(); + Map getFlagInstanceMap(); /** * Get the JSON key flag instance. diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFeatureContainerFlag.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFeatureContainerFlag.java index f0f54a075..c5a4ce1bc 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFeatureContainerFlag.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFeatureContainerFlag.java @@ -5,7 +5,6 @@ package gov.nist.secauto.metaschema.core.model; -import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.util.Collection; @@ -30,7 +29,7 @@ public interface IFeatureContainerFlag extends IModelD @Override @Nullable - default FI getFlagInstanceByName(IEnhancedQName name) { + default FI getFlagInstanceByName(Integer name) { return getFlagContainer().getFlagInstanceMap().get(name); } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IModelDefinition.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IModelDefinition.java index 768a29e70..c36d6935b 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IModelDefinition.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IModelDefinition.java @@ -5,14 +5,16 @@ package gov.nist.secauto.metaschema.core.model; -import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; - import java.util.Collection; import java.util.function.Predicate; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; +/** + * Represents a Metaschema definition for a complex object that may contain + * flags. + */ public interface IModelDefinition extends IDefinition, IContainer { /** * Tests if the provided definition represents complex data. The data is complex @@ -52,7 +54,7 @@ default boolean hasChildren() { * matching the specified name */ @Nullable - IFlagInstance getFlagInstanceByName(@NonNull IEnhancedQName index); + IFlagInstance getFlagInstanceByName(@NonNull Integer index); /** * Retrieves the flag instances for all flags defined on the containing diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamedModelInstanceGrouped.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamedModelInstanceGrouped.java index b2761993c..10e551edc 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamedModelInstanceGrouped.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamedModelInstanceGrouped.java @@ -63,7 +63,8 @@ default IFlagInstance getJsonKey() { return name == null ? null : ObjectUtils.requireNonNull( - getDefinition().getFlagInstanceByName(ModuleUtils.parseFlagName(getContainingModule(), name))); + getDefinition().getFlagInstanceByName( + ModuleUtils.parseFlagName(getContainingModule(), name).getIndexPosition())); } @Override diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/impl/DefaultContainerFlagSupport.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/impl/DefaultContainerFlagSupport.java index 92e4c899c..ebeb462b8 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/impl/DefaultContainerFlagSupport.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/impl/DefaultContainerFlagSupport.java @@ -7,7 +7,6 @@ import gov.nist.secauto.metaschema.core.model.IContainerFlagSupport; import gov.nist.secauto.metaschema.core.model.IFlagInstance; -import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; import java.util.Map; @@ -16,7 +15,7 @@ public class DefaultContainerFlagSupport implements IContainerFlagSupport { @NonNull - private final Map instances; + private final Map instances; @Nullable private final FI jsonKey; @@ -30,14 +29,14 @@ public class DefaultContainerFlagSupport implements IC * configured */ public DefaultContainerFlagSupport( - @NonNull Map instances, + @NonNull Map instances, @Nullable FI jsonKey) { this.instances = instances; this.jsonKey = jsonKey; } @Override - public Map getFlagInstanceMap() { + public Map getFlagInstanceMap() { return instances; } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/impl/EmptyFlagContainer.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/impl/EmptyFlagContainer.java index a73dd31b1..742f6756a 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/impl/EmptyFlagContainer.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/impl/EmptyFlagContainer.java @@ -7,7 +7,6 @@ import gov.nist.secauto.metaschema.core.model.IContainerFlagSupport; import gov.nist.secauto.metaschema.core.model.IFlagInstance; -import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; import gov.nist.secauto.metaschema.core.util.CollectionUtil; import java.util.Map; @@ -19,7 +18,7 @@ public class EmptyFlagContainer implements IContainerF public static final EmptyFlagContainer EMPTY = new EmptyFlagContainer<>(); @Override - public Map getFlagInstanceMap() { + public Map getFlagInstanceMap() { return CollectionUtil.emptyMap(); } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlFlagContainerSupport.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlFlagContainerSupport.java index 704c1204f..5c09afaee 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlFlagContainerSupport.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlFlagContainerSupport.java @@ -216,7 +216,9 @@ private static IContainerFlagSupport buildFlagContainer( @NonNull IModelDefinition parent) { IFlagContainerBuilder builder = jsonKeyFlagRef == null ? IContainerFlagSupport.builder() - : IContainerFlagSupport.builder(ModuleUtils.parseFlagName(parent.getContainingModule(), jsonKeyFlagRef)); + : IContainerFlagSupport.builder(ModuleUtils.parseFlagName( + parent.getContainingModule(), + jsonKeyFlagRef).getIndexPosition()); // handle flags XML_MODEL_PARSER.parse( parent.getContainingModule().getSource(), diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGlobalFieldDefinition.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGlobalFieldDefinition.java index 2bdf5183b..a570ac679 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGlobalFieldDefinition.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGlobalFieldDefinition.java @@ -175,10 +175,7 @@ public IFlagInstance getJsonValueKeyFlagInstance() { String namespace = getQName().getNamespace(); String name = ObjectUtils.notNull(getXmlObject().getJsonValueKeyFlag().getFlagRef()); - retval = getFlagInstanceByName( - namespace.isEmpty() - ? IEnhancedQName.of(name) - : IEnhancedQName.of(namespace, name)); + retval = getFlagInstanceByName(IEnhancedQName.of(namespace, name).getIndexPosition()); } return retval; } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGroupedInlineFieldDefinition.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGroupedInlineFieldDefinition.java index c5d65300c..cf623f8bd 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGroupedInlineFieldDefinition.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGroupedInlineFieldDefinition.java @@ -162,10 +162,7 @@ public IFlagInstance getJsonValueKeyFlagInstance() { String namespace = getQName().getNamespace(); String name = ObjectUtils.notNull(getXmlObject().getJsonValueKeyFlag().getFlagRef()); - retval = getFlagInstanceByName( - namespace.isEmpty() - ? IEnhancedQName.of(name) - : IEnhancedQName.of(namespace, name)); + retval = getFlagInstanceByName(IEnhancedQName.of(namespace, name).getIndexPosition()); } return retval; } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlInlineFieldDefinition.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlInlineFieldDefinition.java index 775ef585a..6dacbfe03 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlInlineFieldDefinition.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlInlineFieldDefinition.java @@ -201,10 +201,7 @@ public IFlagInstance getJsonValueKeyFlagInstance() { String namespace = getQName().getNamespace(); String name = ObjectUtils.notNull(getXmlObject().getJsonValueKeyFlag().getFlagRef()); - retval = getFlagInstanceByName( - namespace.isEmpty() - ? IEnhancedQName.of(name) - : IEnhancedQName.of(namespace, name)); + retval = getFlagInstanceByName(IEnhancedQName.of(namespace, name).getIndexPosition()); } return retval; } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/qname/IEnhancedQName.java b/core/src/main/java/gov/nist/secauto/metaschema/core/qname/IEnhancedQName.java index 48886b194..811c14436 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/qname/IEnhancedQName.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/qname/IEnhancedQName.java @@ -49,7 +49,9 @@ static IEnhancedQName of(@NonNull String localName) { @SuppressWarnings("PMD.ShortMethodName") @NonNull static IEnhancedQName of(@NonNull String namespace, @NonNull String localName) { - return EQNameFactory.instance().newQName(namespace, localName); + return namespace.isEmpty() + ? EQNameFactory.instance().newQName(localName) + : EQNameFactory.instance().newQName(namespace, localName); } @SuppressWarnings("PMD.ShortMethodName") diff --git a/core/src/test/java/gov/nist/secauto/metaschema/core/metapath/item/node/DefaultNodeItemFactoryTest.java b/core/src/test/java/gov/nist/secauto/metaschema/core/metapath/item/node/DefaultNodeItemFactoryTest.java index 6b4415f24..bd81cfab3 100644 --- a/core/src/test/java/gov/nist/secauto/metaschema/core/metapath/item/node/DefaultNodeItemFactoryTest.java +++ b/core/src/test/java/gov/nist/secauto/metaschema/core/metapath/item/node/DefaultNodeItemFactoryTest.java @@ -54,7 +54,7 @@ void testGenerateFlags() { // setup the value calls getContext().checking(new Expectations() { { // NOPMD - intentional - allowing(fieldInstance.getDefinition().getFlagInstanceByName(IEnhancedQName.of(NS, "flag1"))) + allowing(fieldInstance.getDefinition().getFlagInstanceByName(IEnhancedQName.of(NS, "flag1").getIndexPosition())) .getValue(fieldValue); will(returnValue("flag1 value")); } @@ -88,7 +88,8 @@ void testGenerateModelItems() { // Setup the value calls getContext().checking(new Expectations() { { // NOPMD - intentional - allowing(assembly.getFlagInstanceByName(IEnhancedQName.of(NS, "flag1"))).getValue(assemblyValue); + allowing(assembly.getFlagInstanceByName(IEnhancedQName.of(NS, "flag1").getIndexPosition())) + .getValue(assemblyValue); will(returnValue(flagValue)); allowing(assembly.getNamedModelInstanceByName(IEnhancedQName.of(NS, "field1").getIndexPosition())) .getValue(assemblyValue); diff --git a/core/src/test/java/gov/nist/secauto/metaschema/core/testing/AbstractModelBuilder.java b/core/src/test/java/gov/nist/secauto/metaschema/core/testing/AbstractModelBuilder.java index 3c5db0758..85c758a59 100644 --- a/core/src/test/java/gov/nist/secauto/metaschema/core/testing/AbstractModelBuilder.java +++ b/core/src/test/java/gov/nist/secauto/metaschema/core/testing/AbstractModelBuilder.java @@ -25,7 +25,7 @@ public abstract class AbstractModelBuilder> extends MockFactory { - private String namespace; + private String namespace = ""; private String name; /** @@ -136,9 +136,7 @@ protected void applyNamedInstance( getContext().checking(new Expectations() { { allowing(instance).getQName(); - will(returnValue(namespace == null - ? IEnhancedQName.of(ObjectUtils.notNull(name)) - : IEnhancedQName.of(ObjectUtils.notNull(namespace), ObjectUtils.notNull(name)))); + will(returnValue(IEnhancedQName.of(ObjectUtils.notNull(namespace), ObjectUtils.notNull(name)))); allowing(instance).getDefinition(); will(returnValue(definition)); allowing(instance).getContainingDefinition(); @@ -164,9 +162,7 @@ protected void applyNamed(@NonNull INamedModelElement element) { allowing(element).getUseName(); will(returnValue(null)); allowing(element).getQName(); - will(returnValue(namespace == null - ? IEnhancedQName.of(ObjectUtils.notNull(name)) - : IEnhancedQName.of(ObjectUtils.notNull(namespace), ObjectUtils.notNull(name)))); + will(returnValue(IEnhancedQName.of(ObjectUtils.notNull(namespace), ObjectUtils.notNull(name)))); allowing(element).getEffectiveName(); will(returnValue(name)); allowing(element).getFormalName(); diff --git a/core/src/test/java/gov/nist/secauto/metaschema/core/testing/AssemblyBuilder.java b/core/src/test/java/gov/nist/secauto/metaschema/core/testing/AssemblyBuilder.java index 6d710d59b..27799e234 100644 --- a/core/src/test/java/gov/nist/secauto/metaschema/core/testing/AssemblyBuilder.java +++ b/core/src/test/java/gov/nist/secauto/metaschema/core/testing/AssemblyBuilder.java @@ -136,7 +136,7 @@ public IAssemblyDefinition toDefinition() { allowing(retval).getFlagInstances(); will(returnValue(flags.values())); flags.forEach((key, value) -> { - allowing(retval).getFlagInstanceByName(with(key)); + allowing(retval).getFlagInstanceByName(with(key.getIndexPosition())); will(returnValue(value)); }); allowing(retval).getModelInstances(); diff --git a/core/src/test/java/gov/nist/secauto/metaschema/core/testing/FieldBuilder.java b/core/src/test/java/gov/nist/secauto/metaschema/core/testing/FieldBuilder.java index 3a9503bea..25adead9f 100644 --- a/core/src/test/java/gov/nist/secauto/metaschema/core/testing/FieldBuilder.java +++ b/core/src/test/java/gov/nist/secauto/metaschema/core/testing/FieldBuilder.java @@ -135,7 +135,6 @@ public IFieldInstanceAbsolute toInstance( * * @return the new mocked definition */ - @SuppressWarnings("null") @NonNull public IFieldDefinition toDefinition() { validate(); @@ -158,7 +157,7 @@ public IFieldDefinition toDefinition() { allowing(retval).getFlagInstances(); will(returnValue(flags.values())); flags.forEach((key, value) -> { - allowing(retval).getFlagInstanceByName(with(key)); + allowing(retval).getFlagInstanceByName(with(key.getIndexPosition())); will(returnValue(value)); }); } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceModelGroupedNamed.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceModelGroupedNamed.java index e4338aac2..fbb5e00bd 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceModelGroupedNamed.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceModelGroupedNamed.java @@ -40,7 +40,8 @@ default IBoundInstanceFlag getJsonKey() { return name == null ? null : ObjectUtils.requireNonNull( - getDefinition().getFlagInstanceByName(ModuleUtils.parseFlagName(getContainingModule(), name))); + getDefinition().getFlagInstanceByName( + ModuleUtils.parseFlagName(getContainingModule(), name).getIndexPosition())); } @Override diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/FlagContainerSupport.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/FlagContainerSupport.java index 7d60a7225..cef9c316f 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/FlagContainerSupport.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/FlagContainerSupport.java @@ -6,7 +6,6 @@ package gov.nist.secauto.metaschema.databind.model.impl; import gov.nist.secauto.metaschema.core.model.IContainerFlagSupport; -import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; import gov.nist.secauto.metaschema.core.util.CollectionUtil; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.metaschema.databind.model.IBoundDefinitionModelComplex; @@ -32,7 +31,7 @@ public class FlagContainerSupport implements IContainerFlagSupport { @NonNull - private final Map flagInstances; + private final Map flagInstances; @Nullable private IBoundInstanceFlag jsonKeyFlag; @@ -63,7 +62,7 @@ public FlagContainerSupport( this.flagInstances = CollectionUtil.unmodifiableMap(ObjectUtils.notNull(instances .peek(intermediate) .collect(Collectors.toMap( - IBoundInstanceFlag::getQName, + flag -> flag.getQName().getIndexPosition(), Function.identity(), (v1, v2) -> v2, LinkedHashMap::new)))); @@ -114,7 +113,7 @@ protected void handleFlagInstance(IBoundInstanceFlag instance) { @Override @NonNull - public Map getFlagInstanceMap() { + public Map getFlagInstanceMap() { return flagInstances; } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/InstanceModelChoiceGroup.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/InstanceModelChoiceGroup.java index 4472b5696..4e3116e4c 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/InstanceModelChoiceGroup.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/InstanceModelChoiceGroup.java @@ -297,10 +297,8 @@ public IBoundInstanceFlag getItemJsonKey(Object item) { IBoundInstanceModelGroupedNamed itemInstance = getClassToInstanceMap().get(clazz); String namespace = itemInstance.getQName().getNamespace(); - retval = itemInstance.getDefinition().getFlagInstanceByName( - namespace.isEmpty() - ? IEnhancedQName.of(jsonKeyFlagName) - : IEnhancedQName.of(namespace, jsonKeyFlagName)); + retval = itemInstance.getDefinition().getFlagInstanceByName(IEnhancedQName.of(namespace, jsonKeyFlagName) + .getIndexPosition()); } return retval; } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/DefinitionFieldGlobal.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/DefinitionFieldGlobal.java index 819297ee7..b746ebcbe 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/DefinitionFieldGlobal.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/DefinitionFieldGlobal.java @@ -173,7 +173,8 @@ public IFlagInstance getJsonValueKeyFlagInstance() { JsonValueKeyFlag obj = getBinding().getJsonValueKeyFlag(); String name = obj == null ? null : obj.getFlagRef(); return name == null ? null - : ObjectUtils.requireNonNull(getFlagInstanceByName(ModuleUtils.parseFlagName(getContainingModule(), name))); + : ObjectUtils.requireNonNull(getFlagInstanceByName( + ModuleUtils.parseFlagName(getContainingModule(), name).getIndexPosition())); } @Override diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/FlagContainerSupport.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/FlagContainerSupport.java index df173559e..97545c6ea 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/FlagContainerSupport.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/FlagContainerSupport.java @@ -42,7 +42,8 @@ public static IContainerFlagSupport newFlagContainer( // create temporary collections to store the child binding objects IFlagContainerBuilder builder = jsonKeyName == null ? IContainerFlagSupport.builder() - : IContainerFlagSupport.builder(ModuleUtils.parseFlagName(parent.getContainingModule(), jsonKeyName)); + : IContainerFlagSupport.builder( + ModuleUtils.parseFlagName(parent.getContainingModule(), jsonKeyName).getIndexPosition()); // create counter to track child positions AtomicInteger flagReferencePosition = new AtomicInteger(); diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceModelFieldInline.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceModelFieldInline.java index f69315420..98d2b00fd 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceModelFieldInline.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceModelFieldInline.java @@ -206,7 +206,7 @@ public IFlagInstance getJsonValueKeyFlagInstance() { String namespace = getContainingModule().getXmlNamespace().toASCIIString(); return name == null ? null : ObjectUtils.requireNonNull(getFlagInstanceByName( - IEnhancedQName.of(namespace, name))); + IEnhancedQName.of(namespace, name).getIndexPosition())); } @Override diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceModelGroupedFieldInline.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceModelGroupedFieldInline.java index 3c5fcd375..986758239 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceModelGroupedFieldInline.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceModelGroupedFieldInline.java @@ -180,10 +180,7 @@ public IFlagInstance getJsonValueKeyFlagInstance() { String flagName = obj.getFlagRef(); if (flagName != null) { String namespace = getQName().getNamespace(); - retval = getFlagInstanceByName( - namespace.isEmpty() - ? IEnhancedQName.of(flagName) - : IEnhancedQName.of(namespace, flagName)); + retval = getFlagInstanceByName(IEnhancedQName.of(namespace, flagName).getIndexPosition()); } } return retval; diff --git a/databind/src/test/java/gov/nist/secauto/metaschema/databind/io/xml/XmlParserTest.java b/databind/src/test/java/gov/nist/secauto/metaschema/databind/io/xml/XmlParserTest.java index 8ed68f19d..b1335765c 100644 --- a/databind/src/test/java/gov/nist/secauto/metaschema/databind/io/xml/XmlParserTest.java +++ b/databind/src/test/java/gov/nist/secauto/metaschema/databind/io/xml/XmlParserTest.java @@ -101,7 +101,7 @@ void testXmlReadFlagProperty() throws JsonParseException, IOException, .requireNonNull( (IBoundDefinitionModelAssembly) bindingContext.getBoundDefinitionForClass(FlaggedAssembly.class)); - IBoundInstanceFlag idProperty = assembly.getFlagInstanceByName(IEnhancedQName.of("id")); + IBoundInstanceFlag idProperty = assembly.getFlagInstanceByName(IEnhancedQName.of("id").getIndexPosition()); assert idProperty != null; assertEquals(XMLStreamConstants.START_DOCUMENT, eventReader.nextEvent().getEventType()); diff --git a/databind/src/test/java/gov/nist/secauto/metaschema/databind/testing/model/ModelTest.java b/databind/src/test/java/gov/nist/secauto/metaschema/databind/testing/model/ModelTest.java index 637fbb767..ffec6820e 100644 --- a/databind/src/test/java/gov/nist/secauto/metaschema/databind/testing/model/ModelTest.java +++ b/databind/src/test/java/gov/nist/secauto/metaschema/databind/testing/model/ModelTest.java @@ -50,11 +50,11 @@ void testRootAssemblyWithFlags() { context.getBoundDefinitionForClass(RootAssemblyWithFlags.class)); IBoundInstanceFlag idFlag = ObjectUtils.requireNonNull(definition.getFlagInstanceByName( - IEnhancedQName.of("id"))); + IEnhancedQName.of("id").getIndexPosition())); IBoundInstanceFlag defaultFlag = ObjectUtils.requireNonNull(definition.getFlagInstanceByName( - IEnhancedQName.of("defaultFlag"))); + IEnhancedQName.of("defaultFlag").getIndexPosition())); IBoundInstanceFlag numberFlag = ObjectUtils.requireNonNull(definition.getFlagInstanceByName( - IEnhancedQName.of("number"))); + IEnhancedQName.of("number").getIndexPosition())); assertAll( "root assembly", diff --git a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/json/impl/AbstractModelDefinitionJsonSchema.java b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/json/impl/AbstractModelDefinitionJsonSchema.java index d904e1cb4..79bf3b121 100644 --- a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/json/impl/AbstractModelDefinitionJsonSchema.java +++ b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/json/impl/AbstractModelDefinitionJsonSchema.java @@ -57,7 +57,7 @@ protected AbstractModelDefinitionJsonSchema( IFlagInstance jsonKeyFlag; try { jsonKeyFlag = definition.getFlagInstanceByName( - ModuleUtils.parseFlagName(definition.getContainingModule(), jsonKeyFlagName)); + ModuleUtils.parseFlagName(definition.getContainingModule(), jsonKeyFlagName).getIndexPosition()); } catch (StaticMetapathException ex) { throw new IllegalArgumentException(ex); }