From dd82fc7a0b4f0f221b09c114ed0333e17687c08d Mon Sep 17 00:00:00 2001 From: David Waltermire Date: Mon, 6 May 2024 17:58:19 -0400 Subject: [PATCH] interim commit --- .../PostProcessingModuleLoaderStrategy.java | 8 +-- .../databind/model/IBoundDefinition.java | 51 ------------------- .../databind/model/IBoundDefinitionFlag.java | 2 +- .../databind/model/IBoundDefinitionModel.java | 12 ++++- .../model/IBoundDefinitionModelAssembly.java | 6 --- .../IBoundDefinitionModelFieldComplex.java | 6 --- .../databind/model/IBoundFieldValue.java | 6 --- .../databind/model/IBoundInstanceFlag.java | 5 -- .../model/IBoundInstanceModelAssembly.java | 1 - .../model/IBoundInstanceModelChoiceGroup.java | 5 -- .../model/IBoundInstanceModelFieldScalar.java | 6 --- .../model/IBoundInstanceModelNamed.java | 5 -- .../databind/model/IBoundModuleElement.java | 11 ---- .../model/IFeatureBoundDefinitionInline.java | 8 +-- .../model/impl/InstanceFlagInline.java | 6 --- .../model/impl/InstanceModelFieldScalar.java | 6 +++ .../DefaultAssemblyClassBindingTest.java | 3 +- 17 files changed, 29 insertions(+), 118 deletions(-) delete mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundDefinition.java diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/PostProcessingModuleLoaderStrategy.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/PostProcessingModuleLoaderStrategy.java index 438e8c1d0..2e61cfa54 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/PostProcessingModuleLoaderStrategy.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/PostProcessingModuleLoaderStrategy.java @@ -26,10 +26,10 @@ package gov.nist.secauto.metaschema.databind; +import gov.nist.secauto.metaschema.core.model.IModule; import gov.nist.secauto.metaschema.core.model.IModuleLoader; import gov.nist.secauto.metaschema.core.util.CollectionUtil; import gov.nist.secauto.metaschema.databind.model.IBoundDefinitionModelComplex; -import gov.nist.secauto.metaschema.databind.model.IBoundModule; import java.util.ArrayList; import java.util.HashSet; @@ -42,7 +42,7 @@ class PostProcessingModuleLoaderStrategy extends SimpleModuleLoaderStrategy { @NonNull private final List modulePostProcessors; - private final Set resolvedModules = new HashSet<>(); + private final Set resolvedModules = new HashSet<>(); protected PostProcessingModuleLoaderStrategy( @NonNull IBindingContext bindingContext, @@ -61,7 +61,7 @@ public IBoundDefinitionModelComplex getBoundDefinitionForClass(@NonNull Class IBoundDefinitionModelComplex retval = super.getBoundDefinitionForClass(clazz); if (retval != null) { // force loading of metaschema information to apply constraints - IBoundModule module = retval.getContainingModule(); + IModule module = retval.getContainingModule(); synchronized (resolvedModules) { if (!resolvedModules.contains(module)) { // add first, to avoid loops @@ -73,7 +73,7 @@ public IBoundDefinitionModelComplex getBoundDefinitionForClass(@NonNull Class return retval; } - private void handleModule(@NonNull IBoundModule module) { + private void handleModule(@NonNull IModule module) { for (IModuleLoader.IModulePostProcessor postProcessor : getModulePostProcessors()) { postProcessor.processModule(module); } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundDefinition.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundDefinition.java deleted file mode 100644 index 0720957c0..000000000 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundDefinition.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Portions of this software was developed by employees of the National Institute - * of Standards and Technology (NIST), an agency of the Federal Government and is - * being made available as a public service. Pursuant to title 17 United States - * Code Section 105, works of NIST employees are not subject to copyright - * protection in the United States. This software may be subject to foreign - * copyright. Permission in the United States and in foreign countries, to the - * extent that NIST may hold copyright, to use, copy, modify, create derivative - * works, and distribute this software and its documentation without fee is hereby - * granted on a non-exclusive basis, provided that this notice and disclaimer - * of warranty appears in all copies. - * - * THE SOFTWARE IS PROVIDED 'AS IS' WITHOUT ANY WARRANTY OF ANY KIND, EITHER - * EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY - * THAT THE SOFTWARE WILL CONFORM TO SPECIFICATIONS, ANY IMPLIED WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND FREEDOM FROM - * INFRINGEMENT, AND ANY WARRANTY THAT THE DOCUMENTATION WILL CONFORM TO THE - * SOFTWARE, OR ANY WARRANTY THAT THE SOFTWARE WILL BE ERROR FREE. IN NO EVENT - * SHALL NIST BE LIABLE FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO, DIRECT, - * INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF, RESULTING FROM, - * OR IN ANY WAY CONNECTED WITH THIS SOFTWARE, WHETHER OR NOT BASED UPON WARRANTY, - * CONTRACT, TORT, OR OTHERWISE, WHETHER OR NOT INJURY WAS SUSTAINED BY PERSONS OR - * PROPERTY OR OTHERWISE, AND WHETHER OR NOT LOSS WAS SUSTAINED FROM, OR AROSE OUT - * OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER. - */ - -package gov.nist.secauto.metaschema.databind.model; - -import gov.nist.secauto.metaschema.core.model.IDefinition; -import gov.nist.secauto.metaschema.databind.IBindingContext; - -import edu.umd.cs.findbugs.annotations.NonNull; - -/** - * Represents a Metaschema module definition bound to Java data. - */ -public interface IBoundDefinition extends IDefinition, IBoundModuleElement { - /** - * Get the binding context used for the definition. - * - * @return the binding context - */ - @NonNull - IBindingContext getBindingContext(); - - /** - * Get the Metaschema module containing this definition. - */ - @Override - IBoundModule getContainingModule(); -} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundDefinitionFlag.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundDefinitionFlag.java index 01ffec7ef..c4c622ff5 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundDefinitionFlag.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundDefinitionFlag.java @@ -32,6 +32,6 @@ * Represents a flag definition/instance bound to Java field. */ public interface IBoundDefinitionFlag - extends IFlagDefinition, IBoundDefinition { + extends IFlagDefinition, IBoundModuleElement { // no additional methods } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundDefinitionModel.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundDefinitionModel.java index 59ca1ce3e..87ae03176 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundDefinitionModel.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundDefinitionModel.java @@ -27,17 +27,27 @@ package gov.nist.secauto.metaschema.databind.model; import gov.nist.secauto.metaschema.core.model.IModelDefinition; +import gov.nist.secauto.metaschema.databind.IBindingContext; import java.util.Collection; import javax.xml.namespace.QName; +import edu.umd.cs.findbugs.annotations.NonNull; + /** * Represents a field or assembly instance bound to Java data. */ // REFACTOR: rename to IBoundDefinitionModel public interface IBoundDefinitionModel - extends IBoundDefinition, IModelDefinition { + extends IModelDefinition, IBoundModuleElement { + /** + * Get the binding context used for the definition. + * + * @return the binding context + */ + @NonNull + IBindingContext getBindingContext(); @Override IBoundInstanceModelNamed getInlineInstance(); diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundDefinitionModelAssembly.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundDefinitionModelAssembly.java index b45656537..0dba4b3ab 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundDefinitionModelAssembly.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundDefinitionModelAssembly.java @@ -51,7 +51,6 @@ public interface IBoundDefinitionModelAssembly // Assembly Definition Features // ============================ - @Override @NonNull default IBoundDefinitionModelAssembly getOwningDefinition() { @@ -101,11 +100,6 @@ default void writeItem(Object item, IItemWriteHandler handler) throws IOExceptio handler.writeItemAssembly(item, this); } - @Override - default boolean canHandleJsonPropertyName(@NonNull String name) { - return name.equals(getRootJsonName()); - } - @Override default boolean canHandleXmlQName(@NonNull QName qname) { return qname.equals(getRootXmlQName()); diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundDefinitionModelFieldComplex.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundDefinitionModelFieldComplex.java index ec4c42c5a..f8bee845e 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundDefinitionModelFieldComplex.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundDefinitionModelFieldComplex.java @@ -159,12 +159,6 @@ default void writeItem(Object item, IItemWriteHandler handler) throws IOExceptio handler.writeItemField(item, this); } - @Override - default boolean canHandleJsonPropertyName(String name) { - // not handled, since not root - return false; - } - @Override default boolean canHandleXmlQName(QName qname) { // not handled, since not root diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundFieldValue.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundFieldValue.java index 8b204d21b..bcfab0c3a 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundFieldValue.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundFieldValue.java @@ -107,12 +107,6 @@ default void deepCopy(@NonNull Object fromInstance, @NonNull Object toInstance) setValue(toInstance, value); } - @Override - default boolean canHandleJsonPropertyName(String name) { - // REFACTOR: Is this correct? - return name.equals(getJsonValueKeyName()); - } - @Override default boolean canHandleXmlQName(QName qname) { // REFACTOR: Is this correct? diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceFlag.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceFlag.java index a15dd1b5e..529e49638 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceFlag.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceFlag.java @@ -155,11 +155,6 @@ default void writeItem(Object item, IItemWriteHandler handler) throws IOExceptio handler.writeItemFlag(item, this); } - @Override - default boolean canHandleJsonPropertyName(@NonNull String name) { - return name.equals(getJsonName()); - } - @Override default boolean canHandleXmlQName(@NonNull QName qname) { return qname.equals(getXmlQName()); diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceModelAssembly.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceModelAssembly.java index 73ecefe90..261bfb239 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceModelAssembly.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceModelAssembly.java @@ -44,7 +44,6 @@ */ public interface IBoundInstanceModelAssembly extends IBoundInstanceModelNamedComplex, IAssemblyInstanceAbsolute { - /** * Create a new bound assembly instance. * 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 33444019c..1d90878e2 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 @@ -145,11 +145,6 @@ default Object deepCopyItem(Object item, Object parentInstance) throws BindingEx return itemInstance.deepCopyItem(itemInstance, parentInstance); } - @Override - default boolean canHandleJsonPropertyName(@NonNull String name) { - return name.equals(getJsonName()); - } - @Override default boolean canHandleXmlQName(@NonNull QName qname) { return getGroupedModelInstance(qname) != null; diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceModelFieldScalar.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceModelFieldScalar.java index bb67634e1..a8c6ff53a 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceModelFieldScalar.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceModelFieldScalar.java @@ -28,7 +28,6 @@ import gov.nist.secauto.metaschema.core.model.IContainerFlagSupport; import gov.nist.secauto.metaschema.core.util.ObjectUtils; -import gov.nist.secauto.metaschema.databind.IBindingContext; import gov.nist.secauto.metaschema.databind.model.info.IFeatureScalarItemValueHandler; import gov.nist.secauto.metaschema.databind.model.info.IItemReadHandler; import gov.nist.secauto.metaschema.databind.model.info.IItemWriteHandler; @@ -57,11 +56,6 @@ default IBoundInstanceModelFieldScalar getInlineInstance() { return IFeatureBoundDefinitionInline.super.getInlineInstance(); } - @Override - default IBindingContext getBindingContext() { - return getContainingDefinition().getBindingContext(); - } - @Override default IContainerFlagSupport getFlagContainer() { getJsonName(); diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceModelNamed.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceModelNamed.java index bbc624244..913098bc7 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceModelNamed.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceModelNamed.java @@ -87,9 +87,4 @@ default Collection getItemValues(Object value) { default boolean canHandleXmlQName(QName qname) { return qname.equals(getXmlQName()); } - - @Override - default boolean canHandleJsonPropertyName(@NonNull String name) { - return name.equals(getJsonName()); - } } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundModuleElement.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundModuleElement.java index 223f01e60..65bbcd925 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundModuleElement.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundModuleElement.java @@ -37,17 +37,6 @@ * definition, instance, field value. */ public interface IBoundModuleElement extends IItemValueHandler { - /** - * Determine if the provided JSON property or YAML key name is associated with - * this instance. - * - * @param name - * the name of the property/key being parsed - * @return {@code true} if the instance will handle this name, or {@code false} - * otherwise - */ - boolean canHandleJsonPropertyName(@NonNull String name); - /** * Determine if the provided XML qualified name is associated with this * property. diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IFeatureBoundDefinitionInline.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IFeatureBoundDefinitionInline.java index 219f6ba8e..7f6fdf7ef 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IFeatureBoundDefinitionInline.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IFeatureBoundDefinitionInline.java @@ -26,15 +26,17 @@ package gov.nist.secauto.metaschema.databind.model; +import gov.nist.secauto.metaschema.core.model.IDefinition; import gov.nist.secauto.metaschema.core.model.IFeatureDefinitionInstanceInlined; +import gov.nist.secauto.metaschema.core.model.IModule; import edu.umd.cs.findbugs.annotations.NonNull; // REFACTOR: Try to eliminate this interface in favor of IFeatureInlinedDefinitionInstance public interface IFeatureBoundDefinitionInline< - DEFINITION extends IBoundDefinition, + DEFINITION extends IDefinition & IBoundModuleElement, INSTANCE extends IBoundInstanceNamed> - extends IBoundDefinition, IBoundInstanceNamed, + extends IBoundInstanceNamed, IFeatureDefinitionInstanceInlined { // // @Override @@ -50,7 +52,7 @@ public interface IFeatureBoundDefinitionInline< */ @Override @NonNull - default IBoundModule getContainingModule() { + default IModule getContainingModule() { // this is the same as IBoundInstance, but is needed since IBoundDefinition // and IBoundInstance both declare it return getContainingDefinition().getContainingModule(); diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/InstanceFlagInline.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/InstanceFlagInline.java index 95d952e6f..8f19a4afa 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/InstanceFlagInline.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/InstanceFlagInline.java @@ -34,7 +34,6 @@ 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.ObjectUtils; -import gov.nist.secauto.metaschema.databind.IBindingContext; import gov.nist.secauto.metaschema.databind.model.IBoundDefinitionFlag; import gov.nist.secauto.metaschema.databind.model.IBoundDefinitionModel; import gov.nist.secauto.metaschema.databind.model.IBoundInstanceFlag; @@ -184,11 +183,6 @@ public MarkupMultiline getRemarks() { return ModelUtil.resolveToMarkupMultiline(getAnnotation().remarks()); } - @Override - public IBindingContext getBindingContext() { - return getContainingDefinition().getBindingContext(); - } - // ---------------------------------------- // - End annotation driven code - CPD-OFF - // ---------------------------------------- diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/InstanceModelFieldScalar.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/InstanceModelFieldScalar.java index 7dd205ab4..0577957d7 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/InstanceModelFieldScalar.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/InstanceModelFieldScalar.java @@ -34,6 +34,7 @@ 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.ObjectUtils; +import gov.nist.secauto.metaschema.databind.IBindingContext; import gov.nist.secauto.metaschema.databind.model.IBoundDefinitionModelAssembly; import gov.nist.secauto.metaschema.databind.model.IBoundDefinitionModelField; import gov.nist.secauto.metaschema.databind.model.IBoundInstanceFlag; @@ -143,6 +144,11 @@ private InstanceModelFieldScalar( })); } + @Override + public IBindingContext getBindingContext() { + return getContainingDefinition().getBindingContext(); + } + @Override public Field getField() { return javaField; diff --git a/databind/src/test/java/gov/nist/secauto/metaschema/databind/model/DefaultAssemblyClassBindingTest.java b/databind/src/test/java/gov/nist/secauto/metaschema/databind/model/DefaultAssemblyClassBindingTest.java index 72d19e0d9..4be2540a5 100644 --- a/databind/src/test/java/gov/nist/secauto/metaschema/databind/model/DefaultAssemblyClassBindingTest.java +++ b/databind/src/test/java/gov/nist/secauto/metaschema/databind/model/DefaultAssemblyClassBindingTest.java @@ -31,6 +31,7 @@ import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonParser; +import gov.nist.secauto.metaschema.core.model.IModule; import gov.nist.secauto.metaschema.databind.io.json.MetaschemaJsonReader; import org.junit.jupiter.api.Test; @@ -61,7 +62,7 @@ void testMinimalJsonParse() throws JsonParseException, IOException { @Test void testModule() { IBoundDefinitionModelAssembly definition = getRootAssemblyClassBinding(); - IBoundModule module = definition.getContainingModule(); + IModule module = definition.getContainingModule(); assertNotNull(module, "metaschema was null"); }