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 1bc1ab39b..b702706e8 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 @@ -73,7 +73,7 @@ public IContainerFlagSupport build() { Map flagMap = CollectionUtil.unmodifiableMap(ObjectUtils.notNull(flags.stream() .collect( CustomCollectors.toMap( - INamedModelElement::getXmlQName, + INamed::getXmlQName, CustomCollectors.identity(), FlagContainerBuilder::handleShadowedInstances, LinkedHashMap::new)))); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IDescribable.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IDescribable.java index 5aed8308e..e9a2c4530 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IDescribable.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IDescribable.java @@ -48,4 +48,28 @@ public interface IDescribable { // from INamedModelElement @Nullable MarkupLine getDescription(); + + /** + * The resolved formal display name, which allows an instance to override a + * definition's name. + * + * @return the formal name or {@code null} if not defined + */ + // from INamedModelElement + @Nullable + default String getEffectiveFormalName() { + return getFormalName(); + } + + /** + * Get the text that describes the basic use of the element, which allows an + * instance to override a definition's description. + * + * @return a line of markup text or {@code null} if not defined + */ + // from INamedModelElement + @Nullable + default MarkupLine getEffectiveDescription() { + return getDescription(); + } } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamedModelElement.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamedModelElement.java index a92e5c1ef..3871afb15 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamedModelElement.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamedModelElement.java @@ -26,167 +26,15 @@ package gov.nist.secauto.metaschema.core.model; -import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine; - -import javax.xml.XMLConstants; -import javax.xml.namespace.QName; - import edu.umd.cs.findbugs.annotations.NonNull; -import edu.umd.cs.findbugs.annotations.Nullable; /** * A marker interface for Metaschema constructs that can be members of a * Metaschema module's model that have a name and other identifying * characteristics. */ -public interface INamedModelElement extends IDescribable, IModelElement { - /** - * The resolved formal display name, which allows an instance to override a - * definition's name. - * - * @return the formal name or {@code null} if not defined - */ - // from INamedModelElement - @Nullable - default String getEffectiveFormalName() { - return getFormalName(); - } - - /** - * Get the text that describes the basic use of the element, which allows an - * instance to override a definition's description. - * - * @return a line of markup text or {@code null} if not defined - */ - // from INamedModelElement - @Nullable - default MarkupLine getEffectiveDescription() { - return getDescription(); - } - - /** - * Retrieve the name of the model element. - * - * @return the name - */ - @NonNull - String getName(); - - /** - * Retrieve the name to use for the model element, instead of the name. - * - * @return the use name or {@code null} if no use name is defined - */ - // from INamedModelElement - @Nullable - default String getUseName() { - // no use-name by default - return null; - } - - /** - * Get the name to use based on the provided names. This method will return the - * use name provided by {@link #getUseName()} if the call is not {@code null}, - * and fall back to the name provided by {@link #getName()} otherwise. This is - * the model name to use for the for an instance where the instance is - * referenced. - * - * @return the use name if available, or the name if not - * - * @see #getUseName() - * @see #getName() - */ - // from INamedModelElement - @NonNull - default String getEffectiveName() { - @Nullable String useName = getUseName(); - return useName == null ? getName() : useName; - } - - /** - * Retrieve the XML namespace for this instance. - *

- * Multiple calls to this method are expected to produce the same, deterministic - * return value. - * - * @return the XML namespace or {@code null} if no namespace is defined - */ - @Nullable - default String getXmlNamespace() { - return getXmlQName().getNamespaceURI(); - } - - /** - * Get the unique XML qualified name for this model element. - *

- * The qualified name is considered to be unique relative to all sibling - * elements. For a flag, this name will be unique among all flag instances on - * the same field or assembly definition. For a field or assembly, this name - * will be unique among all sibling field or assembly instances on the same - * assembly definition. - *

- * Multiple calls to this method are expected to produce the same, deterministic - * return value. - *

- * If {@link #getXmlNamespace()} is {@code null}, the the resulting QName will - * have the namespace {@link XMLConstants#NULL_NS_URI}. - *

- * This implementation may be overridden by implementation that cache the QName - * or provide for a more efficient method for QName creation. - * - * @return the XML qualified name, or {@code null} if there isn't one - */ - // REFACTOR: rename to getQName - @NonNull - QName getXmlQName(); - - /** - * Retrieve the index value to use for binary naming. - * - * @return the name index or {@code null} if no name index is defined - */ - // from INamedModelElement - @Nullable - default Integer getIndex() { - // no index by default - return null; - } - - /** - * Retrieve the index value to use for binary naming, instead of the name. - * - * @return the use name index or {@code null} if no use name index is defined - */ - // from INamedModelElement - @Nullable - default Integer getUseIndex() { - // no use-name index by default - return null; - } - - /** - * Get the index value to use for binary naming based on the provided index - * values. - *

- * This method will return the use index value provided by - * {@link #getUseIndex()} if the call result is not {@code null}, and fall back - * to the index value provided by {@link #getIndex()} otherwise. - * - * @return the index value if available, or {@code null} otherwise - */ - // from INamedModelElement - @Nullable - default Integer getEffectiveIndex() { - @Nullable Integer useIndex = getUseIndex(); - return useIndex == null ? getIndex() : useIndex; - } - - /** - * Get the name used for the associated property in JSON/YAML. - * - * @return the JSON property name - */ - // from INamedModelElement +public interface INamedModelElement extends IDescribable, IModelElement, IJsonNamed, INamed { + @Override @NonNull default String getJsonName() { return getEffectiveName(); diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/DefaultBindingContext.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/DefaultBindingContext.java index a81ca7682..4989b6707 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/DefaultBindingContext.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/DefaultBindingContext.java @@ -322,6 +322,6 @@ public CLASS deepCopy(@NonNull CLASS other, Object parentInstance) throw if (definition == null) { throw new IllegalStateException(String.format("Class '%s' is not bound", other.getClass().getName())); } - return (CLASS) definition.deepCopyItem(other, parentInstance); + return ObjectUtils.asType(definition.deepCopyItem(other, parentInstance)); } } 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 529e49638..5f3dc64fc 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 @@ -26,6 +26,7 @@ package gov.nist.secauto.metaschema.databind.model; +import gov.nist.secauto.metaschema.core.model.IFeatureDefinitionInstanceInlined; import gov.nist.secauto.metaschema.core.model.IFlagInstance; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.metaschema.databind.io.BindingException; @@ -48,7 +49,7 @@ public interface IBoundInstanceFlag extends IFlagInstance, IBoundDefinitionFlag, IFeatureScalarItemValueHandler, - IFeatureBoundDefinitionInline { + IBoundInstance, IFeatureDefinitionInstanceInlined { /** * Create a new bound flag instance. @@ -123,7 +124,7 @@ default IBoundInstanceFlag getInlineInstance() { @Override @Nullable default Object getValue(@NonNull Object parent) { - return IFeatureBoundDefinitionInline.super.getValue(parent); + return IBoundInstance.super.getValue(parent); } /** @@ -133,7 +134,7 @@ default Object getValue(@NonNull Object parent) { */ @Override default void setValue(@NonNull Object parentObject, @Nullable Object value) { - IFeatureBoundDefinitionInline.super.setValue(parentObject, value); + IBoundInstance.super.setValue(parentObject, value); } @Override 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 a8c6ff53a..95a185227 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 @@ -27,6 +27,7 @@ package gov.nist.secauto.metaschema.databind.model; import gov.nist.secauto.metaschema.core.model.IContainerFlagSupport; +import gov.nist.secauto.metaschema.core.model.IFeatureDefinitionInstanceInlined; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.metaschema.databind.model.info.IFeatureScalarItemValueHandler; import gov.nist.secauto.metaschema.databind.model.info.IItemReadHandler; @@ -37,28 +38,25 @@ public interface IBoundInstanceModelFieldScalar extends IBoundInstanceModelField, IBoundDefinitionModelField, IFeatureScalarItemValueHandler, - IFeatureBoundDefinitionInline, + IFeatureDefinitionInstanceInlined, IFeatureBoundContainerFlag { // integrate above - @Override default IBoundDefinitionModelField getDefinition() { - return IFeatureBoundDefinitionInline.super.getDefinition(); + return IFeatureDefinitionInstanceInlined.super.getDefinition(); } - @Override - IBoundDefinitionModelAssembly getContainingDefinition(); - @Override default IBoundInstanceModelFieldScalar getInlineInstance() { - // TODO Auto-generated method stub - return IFeatureBoundDefinitionInline.super.getInlineInstance(); + return IFeatureDefinitionInstanceInlined.super.getInlineInstance(); } + @Override + IBoundDefinitionModelAssembly getContainingDefinition(); + @Override default IContainerFlagSupport getFlagContainer() { - getJsonName(); return IContainerFlagSupport.empty(); } 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 913098bc7..343e2f41d 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 @@ -37,7 +37,7 @@ import edu.umd.cs.findbugs.annotations.Nullable; public interface IBoundInstanceModelNamed - extends IBoundInstanceModel, IBoundInstanceNamed, INamedModelInstanceAbsolute { + extends IBoundInstanceModel, INamedModelInstanceAbsolute { @Override @NonNull @@ -55,11 +55,6 @@ default Integer getIndex() { return getDefinition().getIndex(); } - @Override - default String getJsonName() { - return INamedModelInstanceAbsolute.super.getJsonName(); - } - @Override @Nullable default IBoundInstanceFlag getEffectiveJsonKey() { diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceNamed.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceNamed.java deleted file mode 100644 index e90e5ebc6..000000000 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceNamed.java +++ /dev/null @@ -1,38 +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.INamedInstance; - -public interface IBoundInstanceNamed extends IBoundInstance, INamedInstance { - - @Override - default String getJsonName() { - // needed to avoid conflict between IBoundInstance and INamedInstance - return INamedInstance.super.getJsonName(); - } -} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundProperty.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundProperty.java index ad53eca16..ee032677c 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundProperty.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundProperty.java @@ -26,21 +26,12 @@ package gov.nist.secauto.metaschema.databind.model; +import gov.nist.secauto.metaschema.core.model.IJsonNamed; import gov.nist.secauto.metaschema.databind.io.BindingException; import edu.umd.cs.findbugs.annotations.NonNull; -public interface IBoundProperty extends IBoundModuleElement, IFeatureJavaField { - /** - * Get the JSON/YAML property/key name to use for serialization-related - * operations. - * - * @return the JSON name - */ - // REFACTOR: rename to getEffectiveJsonName - @NonNull - String getJsonName(); - +public interface IBoundProperty extends IBoundModuleElement, IFeatureJavaField, IJsonNamed { /** * Copy this instance from one parent object to another. * 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 deleted file mode 100644 index 7f6fdf7ef..000000000 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IFeatureBoundDefinitionInline.java +++ /dev/null @@ -1,72 +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.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 IDefinition & IBoundModuleElement, - INSTANCE extends IBoundInstanceNamed> - extends IBoundInstanceNamed, - IFeatureDefinitionInstanceInlined { - // - // @Override - // default Object getEffectiveDefaultValue() { - // // needed to avoid conflict between IBoundInstance and INamedInstance - // return IBoundInstanceNamed.super.getDefaultValue(); - // } - - /** - * {@inheritDoc} - *

- * Get the containing module from the definition this instance is declared on. - */ - @Override - @NonNull - default IModule getContainingModule() { - // this is the same as IBoundInstance, but is needed since IBoundDefinition - // and IBoundInstance both declare it - return getContainingDefinition().getContainingModule(); - } - // - // /** - // * {@inheritDoc} - // *

- // * Use the effective name of the instance. - // */ - // @Override - // default String getJsonName() { - // // this is the same as INamedModelElement, but is needed since IBoundProperty - // // also declares it - // return getEffectiveName(); - // } -} 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 0577957d7..ee2cc7b8f 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 @@ -192,11 +192,6 @@ public IGroupAs getGroupAs() { return groupAs; } - @Override - public String getJsonName() { - return IBoundInstanceModelFieldScalar.super.getJsonName(); - } - // ------------------------------------------ // - Start annotation driven code - CPD-OFF - // ------------------------------------------