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 f599a42bc..6bacb56b6 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 @@ -35,8 +35,6 @@ import java.io.IOException; -import edu.umd.cs.findbugs.annotations.NonNull; - public interface IBoundInstanceModelFieldScalar extends IBoundInstanceModelField, IBoundDefinitionModelField, IFeatureScalarItemValueHandler, @@ -46,27 +44,22 @@ public interface IBoundInstanceModelFieldScalar // integrate above @Override - IBoundDefinitionModelAssembly getContainingDefinition(); + default IBoundDefinitionModelField getDefinition() { + return IFeatureBoundDefinitionInline.super.getDefinition(); + } @Override - default IBoundInstanceModelFieldScalar getInstance() { - return this; - } + IBoundDefinitionModelAssembly getContainingDefinition(); - /** - * {@inheritDoc} - *

- * For an inline instance, this instance is the definition. - */ @Override - default IBoundInstanceModelFieldScalar getDefinition() { + default IBoundInstanceModelFieldScalar getInstance() { return this; } @Override default IBoundInstanceModelFieldScalar getInlineInstance() { - // always inline - return this; + // TODO Auto-generated method stub + return IFeatureBoundDefinitionInline.super.getInlineInstance(); } @Override @@ -74,19 +67,9 @@ default IBindingContext getBindingContext() { return getContainingDefinition().getBindingContext(); } - /** - * {@inheritDoc} - *

- * Use the effective name of the instance. - */ - @Override - @NonNull - default String getJsonName() { - return IBoundInstanceModelField.super.getJsonName(); - } - @Override default IContainerFlagSupport getFlagContainer() { + getJsonName(); return IContainerFlagSupport.empty(); } 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 49626da9d..b661992ea 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 @@ -29,6 +29,7 @@ import gov.nist.secauto.metaschema.core.model.INamedModelInstanceGrouped; import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior; import gov.nist.secauto.metaschema.core.util.ObjectUtils; +import gov.nist.secauto.metaschema.databind.io.BindingException; import gov.nist.secauto.metaschema.databind.model.info.IFeatureComplexItemValueHandler; import edu.umd.cs.findbugs.annotations.Nullable; @@ -59,4 +60,29 @@ default IBoundInstanceFlag getJsonKey() { ? null : ObjectUtils.requireNonNull(getDefinition().getFlagInstanceByName(getContainingModule().toFlagQName(name))); } + + @Override + default IBoundDefinitionModelAssembly getContainingDefinition() { + return getParentContainer().getContainingDefinition(); + } + + @Override + default String getName() { + return getDefinition().getName(); + } + + @Override + default Object deepCopyItem(Object item, Object parentInstance) throws BindingException { + return getDefinition().deepCopyItem(item, parentInstance); + } + + @Override + default void callBeforeDeserialize(Object targetObject, Object parentObject) throws BindingException { + getDefinition().callBeforeDeserialize(targetObject, parentObject); + } + + @Override + default void callAfterDeserialize(Object targetObject, Object parentObject) throws BindingException { + getDefinition().callAfterDeserialize(targetObject, parentObject); + } } 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 3b454ca48..bbc624244 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 @@ -36,7 +36,8 @@ import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; -public interface IBoundInstanceModelNamed extends IBoundInstanceModel, INamedModelInstanceAbsolute { +public interface IBoundInstanceModelNamed + extends IBoundInstanceModel, IBoundInstanceNamed, INamedModelInstanceAbsolute { @Override @NonNull 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 9f0f55962..219f6ba8e 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 @@ -55,16 +55,16 @@ default IBoundModule getContainingModule() { // 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(); - } + // + // /** + // * {@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/IGroupAs.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IGroupAs.java index 64e9d318e..2b140f364 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IGroupAs.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IGroupAs.java @@ -29,6 +29,8 @@ import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior; import gov.nist.secauto.metaschema.core.model.XmlGroupAsBehavior; +import javax.xml.namespace.QName; + import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; @@ -39,12 +41,7 @@ public interface IGroupAs { @NonNull IGroupAs SINGLETON_GROUP_AS = new IGroupAs() { @Override - public String getGroupAsName() { - return null; - } - - @Override - public String getGroupAsXmlNamespace() { + public QName getGroupAsQName() { return null; } @@ -60,10 +57,19 @@ public XmlGroupAsBehavior getXmlGroupAsBehavior() { }; @Nullable - String getGroupAsName(); + QName getGroupAsQName(); + + @Nullable + default String getGroupAsName() { + QName qname = getGroupAsQName(); + return qname == null ? null : qname.getLocalPart(); + } @Nullable - String getGroupAsXmlNamespace(); + default String getGroupAsXmlNamespace() { + QName qname = getGroupAsQName(); + return qname == null ? null : qname.getNamespaceURI(); + } @NonNull JsonGroupAsBehavior getJsonGroupAsBehavior(); diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/annotations/BoundGroupedAssembly.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/annotations/BoundGroupedAssembly.java index 0182629e3..bb6ab878c 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/annotations/BoundGroupedAssembly.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/annotations/BoundGroupedAssembly.java @@ -95,17 +95,6 @@ */ int useIndex() default Integer.MIN_VALUE; - /** - * The namespace to use for associated XML elements. - *

- * If the value is "##default", then element name is derived from the namespace - * provided in the package-info. - * - * @return the namespace - */ - @NonNull - String namespace() default ModelUtil.DEFAULT_STRING_VALUE; - /** * Get any remarks for this field. * diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/annotations/BoundGroupedField.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/annotations/BoundGroupedField.java index d0f414c9b..a337096a6 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/annotations/BoundGroupedField.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/annotations/BoundGroupedField.java @@ -114,16 +114,6 @@ @NonNull Class> typeAdapter() default NullJavaTypeAdapter.class; - /** - * The namespace to use for associated XML elements. - *

- * If the value is "##default", then element name is derived from the namespace - * provided in the package-info. - * - * @return the namespace - */ - String namespace() default ModelUtil.DEFAULT_STRING_VALUE; - /** * Get any remarks for this field. * diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/annotations/GroupAs.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/annotations/GroupAs.java index 1978957f2..d7ddd08a2 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/annotations/GroupAs.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/annotations/GroupAs.java @@ -51,17 +51,6 @@ @NonNull String name(); - /** - * XML target namespace of the XML grouping element. - *

- * If the value is "##default", then element name is derived from the namespace - * provided in the package-info. - * - * @return the namespace - */ - @NonNull - String namespace() default ModelUtil.DEFAULT_STRING_VALUE; - /** * Describes how to handle collections in JSON/YAML. * diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/annotations/MetaschemaAssembly.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/annotations/MetaschemaAssembly.java index 848e9cdad..5781f9fe0 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/annotations/MetaschemaAssembly.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/annotations/MetaschemaAssembly.java @@ -111,17 +111,6 @@ */ int rootIndex() default Integer.MIN_VALUE; - /** - * XML target namespace of the XML element. - *

- * If the value is "##default", then namespace is derived from the namespace - * provided in the package-info. - * - * @return the namespace - */ - @NonNull - String rootNamespace() default ModelUtil.DEFAULT_STRING_VALUE; - /** * Get any remarks for this assembly. * diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/annotations/ModelUtil.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/annotations/ModelUtil.java index c3af610e3..c611b4d07 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/annotations/ModelUtil.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/annotations/ModelUtil.java @@ -30,6 +30,7 @@ import gov.nist.secauto.metaschema.core.datatype.adapter.MetaschemaDataTypeProvider; import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine; import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline; +import gov.nist.secauto.metaschema.core.model.IModule; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.metaschema.databind.IBindingContext; import gov.nist.secauto.metaschema.databind.model.IGroupAs; @@ -37,7 +38,6 @@ import java.lang.annotation.Annotation; import java.lang.reflect.Field; -import java.util.function.Supplier; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; @@ -112,43 +112,6 @@ public static String resolveNoneOrDefault(@Nullable String value, @Nullable Stri return retval; } - @Nullable - public static String resolveOptionalNamespace( - @Nullable String annotationValue, - @NonNull Supplier defaultSupplier) { - return resolveNamespace(annotationValue, true, defaultSupplier); - } - - /** - * Resolves a provided namespace value. If the value is {@code null} or - * "##default", then the provided default value will be used instead. If the - * value is "##none" and {@code allowNone} is {@code true}, then an empty string - * value will be used. Otherwise, the value is returned. - * - * @param value - * the requested value - * @param definition - * a class with the {@link XmlSchema} annotation - * @param allowNone - * if the "##none" value is honored - * @return the resolved value or {@code null} if no namespace is defined - */ - private static String resolveNamespace( - @Nullable String value, - boolean allowNone, - @NonNull Supplier defaultSupplier) { - String retval; - if (value == null || DEFAULT_STRING_VALUE.equals(value)) { - // get namespace from the metaschema - retval = defaultSupplier.get(); - } else if (allowNone && NO_STRING_VALUE.equals(value)) { - retval = ""; // NOPMD - intentional - } else { - retval = value; - } - return retval; - } - /** * Get the processed value of a string. If the value is "##none", then the value * will be {@code null}. Otherwise the value is returned. @@ -225,9 +188,9 @@ public static Object resolveNullOrValue( @NonNull public static IGroupAs groupAs( @NonNull GroupAs groupAs, - @NonNull Supplier defaultSupplier) { + @NonNull IModule module) { return NULL_VALUE.equals(groupAs.name()) ? IGroupAs.SINGLETON_GROUP_AS - : new DefaultGroupAs(groupAs, defaultSupplier); + : new DefaultGroupAs(groupAs, module); } } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/AbstractBoundInstanceModelGroupedNamed.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/AbstractBoundInstanceModelGroupedNamed.java deleted file mode 100644 index dda2192a8..000000000 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/AbstractBoundInstanceModelGroupedNamed.java +++ /dev/null @@ -1,87 +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.impl; - -import gov.nist.secauto.metaschema.databind.io.BindingException; -import gov.nist.secauto.metaschema.databind.model.IBoundDefinitionModelAssembly; -import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelChoiceGroup; -import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelGroupedNamed; - -import java.lang.annotation.Annotation; - -import edu.umd.cs.findbugs.annotations.NonNull; - -//TODO: implement getProperties() -public abstract class AbstractBoundInstanceModelGroupedNamed< - A extends Annotation> - implements IBoundInstanceModelGroupedNamed { - @NonNull - private final A annotation; - @NonNull - private final IBoundInstanceModelChoiceGroup choiceGroupInstance; - - protected AbstractBoundInstanceModelGroupedNamed( - @NonNull A annotation, - @NonNull IBoundInstanceModelChoiceGroup choiceGroupInstance) { - this.annotation = annotation; - this.choiceGroupInstance = choiceGroupInstance; - } - - public A getAnnotation() { - return annotation; - } - - @Override - public IBoundInstanceModelChoiceGroup getParentContainer() { - return choiceGroupInstance; - } - - @Override - public IBoundDefinitionModelAssembly getContainingDefinition() { - return getParentContainer().getContainingDefinition(); - } - - @Override - public String getName() { - return getDefinition().getName(); - } - - @Override - public Object deepCopyItem(Object item, Object parentInstance) throws BindingException { - return getDefinition().deepCopyItem(item, parentInstance); - } - - @Override - public void callBeforeDeserialize(Object targetObject, Object parentObject) throws BindingException { - getDefinition().callBeforeDeserialize(targetObject, parentObject); - } - - @Override - public void callAfterDeserialize(Object targetObject, Object parentObject) throws BindingException { - getDefinition().callAfterDeserialize(targetObject, parentObject); - } -} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/DefaultGroupAs.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/DefaultGroupAs.java index 261869ca6..185f2dc00 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/DefaultGroupAs.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/DefaultGroupAs.java @@ -26,54 +26,42 @@ package gov.nist.secauto.metaschema.databind.model.impl; +import gov.nist.secauto.metaschema.core.model.IModule; import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior; import gov.nist.secauto.metaschema.core.model.XmlGroupAsBehavior; import gov.nist.secauto.metaschema.databind.model.IGroupAs; import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs; import gov.nist.secauto.metaschema.databind.model.annotations.ModelUtil; -import java.util.function.Supplier; +import javax.xml.namespace.QName; import edu.umd.cs.findbugs.annotations.NonNull; -import edu.umd.cs.findbugs.annotations.Nullable; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; public class DefaultGroupAs implements IGroupAs { @NonNull - private final String name; - @Nullable - private final String namespace; + private final QName qname; @NonNull private final GroupAs annotation; @SuppressFBWarnings(value = "CT_CONSTRUCTOR_THROW", justification = "Use of final fields") public DefaultGroupAs( @NonNull GroupAs annotation, - @NonNull Supplier defaultSupplier) { + @NonNull IModule module) { this.annotation = annotation; - { - String value = ModelUtil.resolveNoneOrDefault(annotation.name(), null); - if (value == null) { - throw new IllegalStateException( - String.format("The %s#groupName value '%s' resulted in an invalid null value", - GroupAs.class.getName(), - annotation.name())); - } - this.name = value; + String value = ModelUtil.resolveNoneOrDefault(annotation.name(), null); + if (value == null) { + throw new IllegalStateException( + String.format("The %s#groupName value '%s' resulted in an invalid null value", + GroupAs.class.getName(), + annotation.name())); } - this.namespace = ModelUtil.resolveOptionalNamespace( - annotation.namespace(), - defaultSupplier); + this.qname = module.toModelQName(value); } @Override - public String getGroupAsName() { - return name; - } - - @Override - public String getGroupAsXmlNamespace() { - return namespace; + public QName getGroupAsQName() { + return qname; } @Override 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 a81b180e2..95d952e6f 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 @@ -116,7 +116,7 @@ public Field getField() { * @return the binding Java annotation */ @NonNull - public BoundFlag getAnnotation() { + private BoundFlag getAnnotation() { return annotation; } // ------------------------------------------ diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/InstanceModelAssemblyComplex.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/InstanceModelAssemblyComplex.java index 3e76320f9..6ce11ed17 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/InstanceModelAssemblyComplex.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/InstanceModelAssemblyComplex.java @@ -94,7 +94,7 @@ public InstanceModelAssemblyComplex( this.annotation = ModelUtil.getAnnotation(javaField, BoundAssembly.class); this.collectionInfo = ObjectUtils.notNull(Lazy.lazy(() -> IModelInstanceCollectionInfo.of(this))); this.definition = definition; - this.groupAs = ModelUtil.groupAs(this.annotation.groupAs(), () -> containingDefinition.getXmlNamespace()); + this.groupAs = ModelUtil.groupAs(this.annotation.groupAs(), containingDefinition.getContainingModule()); if (getMaxOccurs() == -1 || getMaxOccurs() > 1) { if (IGroupAs.SINGLETON_GROUP_AS.equals(this.groupAs)) { throw new IllegalStateException(String.format("Field '%s' on class '%s' is missing the '%s' annotation.", 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 ea681689a..5ef766288 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 @@ -108,7 +108,7 @@ public InstanceModelChoiceGroup( this.javaField = javaField; this.annotation = ModelUtil.getAnnotation(javaField, BoundChoiceGroup.class); this.collectionInfo = ObjectUtils.notNull(Lazy.lazy(() -> IModelInstanceCollectionInfo.of(this))); - this.groupAs = ModelUtil.groupAs(this.annotation.groupAs(), () -> containingDefinition.getXmlNamespace()); + this.groupAs = ModelUtil.groupAs(this.annotation.groupAs(), containingDefinition.getContainingModule()); if (getMaxOccurs() == -1 || getMaxOccurs() > 1) { if (IGroupAs.SINGLETON_GROUP_AS.equals(this.groupAs)) { throw new IllegalStateException(String.format("Field '%s' on class '%s' is missing the '%s' annotation.", diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/InstanceModelFieldComplex.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/InstanceModelFieldComplex.java index c273f709f..7a19f88cd 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/InstanceModelFieldComplex.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/InstanceModelFieldComplex.java @@ -98,7 +98,7 @@ public InstanceModelFieldComplex( this.collectionInfo = ObjectUtils.notNull(Lazy.lazy(() -> IModelInstanceCollectionInfo.of(this))); this.groupAs = ModelUtil.groupAs( this.annotation.groupAs(), - () -> containingDefinition.getXmlNamespace()); + containingDefinition.getContainingModule()); if (getMaxOccurs() == -1 || getMaxOccurs() > 1) { if (IGroupAs.SINGLETON_GROUP_AS.equals(this.groupAs)) { throw new IllegalStateException(String.format("Field '%s' on class '%s' is missing the '%s' annotation.", 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 08e56758b..16253161e 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 @@ -29,12 +29,14 @@ import gov.nist.secauto.metaschema.core.datatype.IDataTypeAdapter; import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine; import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline; -import gov.nist.secauto.metaschema.core.model.AbstractNamedModelInstance; +import gov.nist.secauto.metaschema.core.model.AbstractInlineFieldDefinition; import gov.nist.secauto.metaschema.core.model.constraint.ISource; 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.model.IBoundDefinitionModelAssembly; +import gov.nist.secauto.metaschema.databind.model.IBoundDefinitionModelField; +import gov.nist.secauto.metaschema.databind.model.IBoundInstanceFlag; import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelFieldScalar; import gov.nist.secauto.metaschema.databind.model.IGroupAs; import gov.nist.secauto.metaschema.databind.model.annotations.BoundField; @@ -51,7 +53,12 @@ import nl.talsmasoftware.lazy4j.Lazy; public class InstanceModelFieldScalar - extends AbstractNamedModelInstance + extends AbstractInlineFieldDefinition< + IBoundDefinitionModelAssembly, + IBoundDefinitionModelField, + IBoundInstanceModelFieldScalar, + IBoundDefinitionModelAssembly, + IBoundInstanceFlag> implements IBoundInstanceModelFieldScalar, IFeatureInstanceModelGroupAs { @NonNull private final Field javaField; @@ -85,7 +92,7 @@ public InstanceModelFieldScalar( this.collectionInfo = ObjectUtils.notNull(Lazy.lazy(() -> IModelInstanceCollectionInfo.of(this))); this.groupAs = ModelUtil.groupAs( this.annotation.groupAs(), - () -> containingDefinition.getXmlNamespace()); + containingDefinition.getContainingModule()); if (getMaxOccurs() == -1 || getMaxOccurs() > 1) { if (IGroupAs.SINGLETON_GROUP_AS.equals(this.groupAs)) { throw new IllegalStateException(String.format("Field '%s' on class '%s' is missing the '%s' annotation.", @@ -118,6 +125,7 @@ public InstanceModelFieldScalar( @Override public Field getField() { + getJsonName(); return javaField; } @@ -154,15 +162,20 @@ public Object getDefaultValue() { return defaultValue; } - // ------------------------------------------ - // - Start annotation driven code - CPD-OFF - - // ------------------------------------------ - @Override public IGroupAs getGroupAs() { return groupAs; } + @Override + public String getJsonName() { + return IBoundInstanceModelFieldScalar.super.getJsonName(); + } + + // ------------------------------------------ + // - Start annotation driven code - CPD-OFF - + // ------------------------------------------ + @Override public String getFormalName() { return ModelUtil.resolveNoneOrValue(getAnnotation().formalName()); diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/InstanceModelGroupedAssembly.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/InstanceModelGroupedAssembly.java index 179bda851..e14447684 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/InstanceModelGroupedAssembly.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/InstanceModelGroupedAssembly.java @@ -28,7 +28,7 @@ import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine; import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline; -import gov.nist.secauto.metaschema.core.model.IFeatureDefinitionReferenceInstance; +import gov.nist.secauto.metaschema.core.model.AbstractAssemblyInstance; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.metaschema.databind.model.IBoundDefinitionModelAssembly; import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelChoiceGroup; @@ -47,9 +47,15 @@ * instance. */ public class InstanceModelGroupedAssembly - extends AbstractBoundInstanceModelGroupedNamed - implements IBoundInstanceModelGroupedAssembly, - IFeatureDefinitionReferenceInstance { + extends AbstractAssemblyInstance< + IBoundInstanceModelChoiceGroup, + IBoundDefinitionModelAssembly, + IBoundInstanceModelGroupedAssembly, + IBoundDefinitionModelAssembly> + // extends AbstractBoundInstanceModelGroupedNamed + implements IBoundInstanceModelGroupedAssembly { + @NonNull + private final BoundGroupedAssembly annotation; @NonNull private final IBoundDefinitionModelAssembly definition; @NonNull @@ -70,7 +76,8 @@ public InstanceModelGroupedAssembly( @NonNull BoundGroupedAssembly annotation, @NonNull IBoundDefinitionModelAssembly definition, @NonNull IBoundInstanceModelChoiceGroup container) { - super(annotation, container); + super(container); + this.annotation = annotation; this.definition = definition; // IBoundInstanceFlag jsonKey = getEffectiveJsonKey(); // Predicate flagFilter = jsonKey == null ? null : (flag) -> @@ -79,10 +86,19 @@ public InstanceModelGroupedAssembly( this.jsonProperties = ObjectUtils.notNull(Lazy.lazy(() -> getDefinition().getJsonProperties(null))); } + private BoundGroupedAssembly getAnnotation() { + return annotation; + } + // ------------------------------------------ // - Start annotation driven code - CPD-OFF - // ------------------------------------------ + @Override + public Class getBoundClass() { + return getAnnotation().binding(); + } + @Override public Map getJsonProperties() { return ObjectUtils.notNull(jsonProperties.get()); @@ -122,16 +138,4 @@ public String getUseName() { public Integer getUseIndex() { return ModelUtil.resolveNullOrInteger(getAnnotation().useIndex()); } - - @Override - public String getXmlNamespace() { - return ModelUtil.resolveOptionalNamespace( - getAnnotation().namespace(), - () -> getContainingDefinition().getXmlNamespace()); - } - - @Override - public Class getBoundClass() { - return getAnnotation().binding(); - } } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/InstanceModelGroupedFieldComplex.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/InstanceModelGroupedFieldComplex.java index f74fb05c8..6f8c6dab8 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/InstanceModelGroupedFieldComplex.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/InstanceModelGroupedFieldComplex.java @@ -28,8 +28,9 @@ import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine; import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline; -import gov.nist.secauto.metaschema.core.model.IFeatureDefinitionReferenceInstance; +import gov.nist.secauto.metaschema.core.model.AbstractFieldInstance; import gov.nist.secauto.metaschema.core.util.ObjectUtils; +import gov.nist.secauto.metaschema.databind.model.IBoundDefinitionModelAssembly; import gov.nist.secauto.metaschema.databind.model.IBoundDefinitionModelFieldComplex; import gov.nist.secauto.metaschema.databind.model.IBoundInstanceFlag; import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelChoiceGroup; @@ -45,9 +46,16 @@ import nl.talsmasoftware.lazy4j.Lazy; public class InstanceModelGroupedFieldComplex - extends AbstractBoundInstanceModelGroupedNamed - implements IBoundInstanceModelGroupedField, - IFeatureDefinitionReferenceInstance { + extends AbstractFieldInstance< + IBoundInstanceModelChoiceGroup, + IBoundDefinitionModelFieldComplex, + IBoundInstanceModelGroupedField, + IBoundDefinitionModelAssembly> + + // extends AbstractBoundInstanceModelGroupedNamed + implements IBoundInstanceModelGroupedField { + @NonNull + private final BoundGroupedField annotation; @NonNull private final DefinitionField definition; @NonNull @@ -57,14 +65,15 @@ public InstanceModelGroupedFieldComplex( @NonNull BoundGroupedField annotation, @NonNull DefinitionField definition, @NonNull IBoundInstanceModelChoiceGroup container) { - super(annotation, container); + super(container); + this.annotation = annotation; this.definition = definition; this.jsonProperties = ObjectUtils.notNull(Lazy.lazy(() -> { Predicate flagFilter = null; - // IBoundInstanceFlag jsonKey = getEffectiveJsonKey(); - // if (jsonKey != null) { - // flagFilter = (flag) -> !jsonKey.equals(flag); - // } + IBoundInstanceFlag jsonKey = getEffectiveJsonKey(); + if (jsonKey != null) { + flagFilter = flag -> !jsonKey.equals(flag); + } IBoundInstanceFlag jsonValueKey = getDefinition().getJsonValueKeyFlagInstance(); if (jsonValueKey != null) { @@ -75,10 +84,19 @@ public InstanceModelGroupedFieldComplex( })); } + private BoundGroupedField getAnnotation() { + return annotation; + } + // ------------------------------------------ // - Start annotation driven code - CPD-OFF - // ------------------------------------------ + @Override + public Class getBoundClass() { + return getAnnotation().binding(); + } + @Override public Map getJsonProperties() { return ObjectUtils.notNull(jsonProperties.get()); @@ -119,18 +137,6 @@ public Integer getUseIndex() { return ModelUtil.resolveNullOrInteger(getAnnotation().useIndex()); } - @Override - public String getXmlNamespace() { - return ModelUtil.resolveOptionalNamespace( - getAnnotation().namespace(), - () -> getContainingDefinition().getXmlNamespace()); - } - - @Override - public Class getBoundClass() { - return getAnnotation().binding(); - } - // ---------------------------------------- // - End annotation driven code - CPD-OFF - // ---------------------------------------- diff --git a/databind/src/test/java/gov/nist/secauto/metaschema/databind/model/test/SimpleAssembly.java b/databind/src/test/java/gov/nist/secauto/metaschema/databind/model/test/SimpleAssembly.java index 985a4485f..b9cc11213 100644 --- a/databind/src/test/java/gov/nist/secauto/metaschema/databind/model/test/SimpleAssembly.java +++ b/databind/src/test/java/gov/nist/secauto/metaschema/databind/model/test/SimpleAssembly.java @@ -33,8 +33,7 @@ import java.math.BigInteger; @SuppressWarnings("PMD") -@MetaschemaAssembly(name = "simple-assembly", rootName = "test", moduleClass = TestMetaschema.class, - rootNamespace = "http://example.com/ns") +@MetaschemaAssembly(name = "simple-assembly", rootName = "test", moduleClass = TestMetaschema.class) public class SimpleAssembly { @BoundFlag(name = "id") private String _id; diff --git a/databind/src/test/java/gov/nist/secauto/metaschema/databind/testing/model/ModelTestBase.java b/databind/src/test/java/gov/nist/secauto/metaschema/databind/testing/model/ModelTestBase.java index 4128e3722..d10e4a6e9 100644 --- a/databind/src/test/java/gov/nist/secauto/metaschema/databind/testing/model/ModelTestBase.java +++ b/databind/src/test/java/gov/nist/secauto/metaschema/databind/testing/model/ModelTestBase.java @@ -32,6 +32,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import gov.nist.secauto.metaschema.core.datatype.IDataTypeAdapter; +import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine; +import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline; import gov.nist.secauto.metaschema.databind.IBindingContext; import gov.nist.secauto.metaschema.databind.model.IBoundDefinitionModelAssembly; import gov.nist.secauto.metaschema.databind.model.IBoundInstanceFlag; @@ -69,11 +71,11 @@ public static void assertAssemblyDefinition( "formalName"), () -> assertEquals( ModelUtil.resolveNoneOrValue(annotation.description()), - Optional.ofNullable(assembly.getDescription()).map(value -> value.toMarkdown()).orElse(null), + Optional.ofNullable(assembly.getDescription()).map(MarkupLine::toMarkdown).orElse(null), "description"), () -> assertEquals( ModelUtil.resolveNoneOrValue(annotation.remarks()), - Optional.ofNullable(assembly.getRemarks()).map(value -> value.toMarkdown()).orElse(null), + Optional.ofNullable(assembly.getRemarks()).map(MarkupMultiline::toMarkdown).orElse(null), "remarks"), () -> { String rootName = ModelUtil.resolveNoneOrValue(annotation.rootName()); @@ -84,9 +86,7 @@ public static void assertAssemblyDefinition( assembly.getRootName(), "rootName"), () -> assertEquals( - ModelUtil.resolveOptionalNamespace( - annotation.rootNamespace(), - () -> assembly.getContainingModule().getXmlNamespace().toASCIIString()), + assembly.getContainingModule().getXmlNamespace().toASCIIString(), assembly.getRootXmlQName().getNamespaceURI(), "rootNamespace"), () -> assertTrue(true)); @@ -138,11 +138,11 @@ public static void assertFlagInstance( "formalName"), () -> assertEquals( ModelUtil.resolveNoneOrValue(annotation.description()), - Optional.ofNullable(flag.getDescription()).map(value -> value.toMarkdown()).orElse(null), + Optional.ofNullable(flag.getDescription()).map(MarkupLine::toMarkdown).orElse(null), "description"), () -> assertEquals( ModelUtil.resolveNoneOrValue(annotation.remarks()), - Optional.ofNullable(flag.getRemarks()).map(value -> value.toMarkdown()).orElse(null), + Optional.ofNullable(flag.getRemarks()).map(MarkupMultiline::toMarkdown).orElse(null), "remarks")); } @@ -185,9 +185,7 @@ public static void assertFieldInstance( field.getDefaultValue(), "defaultValue"), () -> assertEquals( - ModelUtil.resolveOptionalNamespace( - annotation.namespace(), - () -> field.getContainingModule().getXmlNamespace().toASCIIString()), + field.getContainingModule().getXmlNamespace().toASCIIString(), field.getXmlNamespace(), "namespace"), () -> assertEquals( @@ -208,11 +206,11 @@ public static void assertFieldInstance( "formalName"), () -> assertEquals( ModelUtil.resolveNoneOrValue(annotation.description()), - Optional.ofNullable(field.getDescription()).map(value -> value.toMarkdown()).orElse(null), + Optional.ofNullable(field.getDescription()).map(MarkupLine::toMarkdown).orElse(null), "description"), () -> assertEquals( ModelUtil.resolveNoneOrValue(annotation.remarks()), - Optional.ofNullable(field.getRemarks()).map(value -> value.toMarkdown()).orElse(null), + Optional.ofNullable(field.getRemarks()).map(MarkupMultiline::toMarkdown).orElse(null), "remarks")); // groupAs }