From 098448a6fd246de395f24c26dc698d78ed8c3e20 Mon Sep 17 00:00:00 2001 From: David Waltermire Date: Wed, 1 May 2024 19:20:49 -0400 Subject: [PATCH] Reworked definition and instance model classes to reduce extra interfaces and to simplify and align implementations. --- core/pom.xml | 5 +- .../datatype/AbstractDataTypeProvider.java | 2 +- .../flexmark/HtmlQuoteTagExtension.java | 1 + .../metaschema/core/metapath/ISequence.java | 4 +- .../core/metapath/cst/BuildCSTVisitor.java | 137 ++++--- .../core/metapath/cst/ExpressionUtils.java | 2 +- .../metapath/cst/PredicateExpression.java | 3 +- .../cst/path/AbstractPathExpression.java | 2 +- .../core/metapath/cst/path/Axis.java | 4 +- .../core/metapath/cst/path/Flag.java | 2 +- .../core/metapath/cst/path/ModelInstance.java | 2 +- .../core/metapath/cst/path/NameTest.java | 2 +- .../metapath/cst/path/RootSlashOnlyPath.java | 2 +- .../core/metapath/cst/path/RootSlashPath.java | 2 +- .../core/metapath/cst/path/Wildcard.java | 7 +- .../metapath/function/DefaultFunction.java | 2 +- .../metapath/function/FunctionLibrary.java | 7 +- .../metapath/function/FunctionService.java | 4 +- .../core/metapath/function/FunctionUtils.java | 2 +- .../core/metapath/function/library/FnAvg.java | 2 +- .../metapath/function/library/FnMinMax.java | 4 +- .../core/metapath/function/library/FnSum.java | 2 +- .../item/node/FlagInstanceNodeItemImpl.java | 2 +- .../item/node/IFeatureFlagContainerItem.java | 5 +- .../core/metapath/item/node/INodeItem.java | 2 +- .../core/model/AbstractAssemblyInstance.java | 69 ++++ ....java => AbstractChoiceGroupInstance.java} | 25 +- .../core/model/AbstractChoiceInstance.java | 49 +++ ...ainerFlag.java => AbstractDefinition.java} | 56 ++- .../core/model/AbstractFieldInstance.java | 57 +-- .../core/model/AbstractFlagInstance.java | 73 ++++ .../AbstractGlobalAssemblyDefinition.java | 53 +++ .../core/model/AbstractGlobalDefinition.java | 33 +- .../model/AbstractGlobalFieldDefinition.java | 25 +- .../model/AbstractGlobalFlagDefinition.java | 16 +- .../AbstractInlineAssemblyDefinition.java | 60 +-- .../model/AbstractInlineFieldDefinition.java | 43 +-- .../model/AbstractInlineFlagDefinition.java | 38 +- .../core/model/AbstractInstance.java | 11 +- .../metaschema/core/model/AbstractLoader.java | 2 +- .../metaschema/core/model/AbstractModule.java | 57 ++- .../core/model/AbstractModuleLoader.java | 2 +- .../core/model/AbstractNamedInstance.java | 53 +-- .../model/AbstractNamedModelInstance.java | 47 +++ .../core/model/FlagContainerBuilder.java | 102 +++++ .../core/model/IAssemblyDefinition.java | 6 + .../core/model/IChoiceGroupInstance.java | 13 + .../core/model/IContainerFlagSupport.java | 18 +- .../metaschema/core/model/IDefinition.java | 19 +- .../metaschema/core/model/IDescribable.java | 24 ++ .../core/model/IFeatureContainerFlag.java | 7 +- .../model/IFeatureContainerModelAbsolute.java | 3 +- .../IFeatureDefinitionInstanceInlined.java | 20 +- .../IFeatureDefinitionReferenceInstance.java | 30 -- .../core/model}/IFeatureValueless.java | 5 +- .../secauto/metaschema/core/model/IFlag.java | 10 - .../core/model/IFlagContainerBuilder.java | 10 +- .../core/model/IFlagDefinition.java | 5 +- .../metaschema/core/model/IFlagInstance.java | 20 +- .../metaschema/core/model/IGroupable.java | 2 +- .../model/{IKeyed.java => IJsonNamed.java} | 14 +- .../core/model/IMetapathQueryable.java | 21 +- .../core/model/IMetaschemaModule.java | 12 +- .../core/model/IModelDefinition.java | 45 ++- .../metaschema/core/model/IModelElement.java | 2 +- .../metaschema/core/model/IModelInstance.java | 4 +- .../metaschema/core/model/IModule.java | 82 +++-- .../core/model/IModuleExtended.java | 26 +- .../secauto/metaschema/core/model/INamed.java | 153 ++++++++ .../metaschema/core/model/INamedInstance.java | 10 + .../core/model/INamedModelElement.java | 158 +------- .../core/model/INamedModelInstance.java | 49 ++- .../model/INamedModelInstanceAbsolute.java | 21 +- .../model/INamedModelInstanceGrouped.java | 17 +- .../metaschema/core/model/IValued.java | 4 +- .../AbstractConstraintValidationHandler.java | 2 +- .../AssemblyTargetedConstraints.java | 7 +- .../DefaultConstraintValidator.java | 6 - ...AbstractDefinitionTargetedConstraints.java | 9 +- .../impl/DefaultContainerFlagSupport.java | 3 +- .../model/{ => impl}/EmptyFlagContainer.java | 12 +- .../metaschema/core/model/util/JsonUtil.java | 2 +- .../core/model/util/XmlEventUtil.java | 4 +- .../metaschema/core/model/xml/IXmlModule.java | 43 --- .../core/model/xml/ModuleLoader.java | 6 +- .../model/xml/XmlMetaConstraintLoader.java | 21 +- .../model/xml/impl/XmlAssemblyInstance.java | 22 +- .../xml/impl/XmlChoiceGroupInstance.java | 15 +- .../model/xml/impl/XmlChoiceInstance.java | 82 ++--- .../core/model/xml/impl/XmlFieldInstance.java | 22 +- .../xml/impl/XmlFlagContainerSupport.java | 176 ++++----- .../core/model/xml/impl/XmlFlagInstance.java | 28 +- .../xml/impl/XmlGlobalAssemblyDefinition.java | 35 +- .../xml/impl/XmlGlobalFieldDefinition.java | 28 +- .../xml/impl/XmlGlobalFlagDefinition.java | 16 +- .../xml/impl/XmlGroupedAssemblyInstance.java | 19 +- .../xml/impl/XmlGroupedFieldInstance.java | 16 +- .../XmlGroupedInlineAssemblyDefinition.java | 52 +-- .../impl/XmlGroupedInlineFieldDefinition.java | 40 +- .../xml/impl/XmlInlineAssemblyDefinition.java | 51 +-- .../xml/impl/XmlInlineFieldDefinition.java | 44 +-- .../xml/impl/XmlInlineFlagDefinition.java | 24 +- .../core/model/xml/impl/XmlModule.java | 220 ++++++----- .../core/model/xml/impl/XmlObjectParser.java | 2 +- .../model/xml/impl/XmlbeansMarkupVisitor.java | 14 +- .../metapath/cst/BuildCstVisitorTest.java | 2 +- .../core/metapath/cst/EQNameUtilsTest.java | 6 - ...Test.java => PredicateExpressionTest.java} | 0 .../core/model/xml/ExamplesTest.java | 10 +- .../model/xml/MetaConstraintLoaderTest.java | 3 +- .../core/model/xml/MetaschemaModuleTest.java | 3 +- .../core/model/xml/ModuleLoaderTest.java | 24 +- .../xml/UsedDefinitionModelWalkerTest.java | 3 +- .../core/testing/AbstractModelBuilder.java | 2 +- .../metaschema/core/testing/FlagBuilder.java | 7 - databind/pom.xml | 4 +- .../databind/DefaultBindingContext.java | 11 +- .../metaschema/databind/IBindingContext.java | 2 + .../PostProcessingModuleLoaderStrategy.java | 8 +- .../databind/SimpleModuleLoaderStrategy.java | 4 +- .../databind/codegen/ClassUtils.java | 17 +- .../codegen/IGeneratedDefinitionClass.java | 4 +- .../impl/DefaultGeneratedDefinitionClass.java | 8 +- .../impl/DefaultGeneratedModuleClass.java | 6 +- .../databind/codegen/impl/NameConverter.java | 281 -------------- .../databind/codegen/impl/NameUtil.java | 348 ------------------ .../AbstractModelInstanceTypeInfo.java | 9 +- .../AbstractNamedModelInstanceTypeInfo.java | 2 +- .../typeinfo/ChoiceGroupTypeInfoImpl.java | 2 +- .../DefaultMetaschemaClassFactory.java | 180 +-------- .../typeinfo/FlagInstanceTypeInfoImpl.java | 12 +- .../codegen/typeinfo/TypeInfoUtils.java | 38 +- .../def/AbstractModelDefinitionTypeInfo.java | 5 +- .../def/AssemblyDefinitionTypeInfoImpl.java | 9 +- .../def/FieldDefinitionTypeInfoImpl.java | 10 +- .../metaschema/databind/io/Format.java | 20 +- .../io/json/MetaschemaJsonReader.java | 15 +- .../databind/io/json/MetaschemaJsonUtil.java | 4 +- .../io/xml/DefaultXmlDeserializer.java | 28 +- .../databind/io/xml/MetaschemaXmlWriter.java | 4 +- .../databind/metapath/function/Model.java | 17 +- .../databind/model/AbstractBoundModule.java | 20 +- .../databind/model/IBoundContainerFlag.java | 44 --- .../model/IBoundContainerModelAssembly.java | 3 +- .../IBoundContainerModelChoiceGroup.java | 8 +- .../databind/model/IBoundDefinition.java | 51 --- .../databind/model/IBoundDefinitionFlag.java | 2 +- .../databind/model/IBoundDefinitionModel.java | 23 +- .../model/IBoundDefinitionModelAssembly.java | 10 +- .../model/IBoundDefinitionModelComplex.java | 107 +++++- .../IBoundDefinitionModelFieldComplex.java | 12 +- .../databind/model/IBoundFieldValue.java | 29 -- .../databind/model/IBoundInstance.java | 19 +- .../databind/model/IBoundInstanceFlag.java | 47 +-- .../databind/model/IBoundInstanceModel.java | 19 - .../model/IBoundInstanceModelAssembly.java | 14 +- .../model/IBoundInstanceModelChoiceGroup.java | 12 +- .../model/IBoundInstanceModelField.java | 4 +- .../IBoundInstanceModelFieldComplex.java | 12 +- .../model/IBoundInstanceModelFieldScalar.java | 68 +--- .../IBoundInstanceModelGroupedNamed.java | 46 ++- .../model/IBoundInstanceModelNamed.java | 31 +- .../IBoundInstanceModelNamedComplex.java | 35 -- .../databind/model/IBoundModule.java | 6 +- .../databind/model/IBoundModuleElement.java | 11 - .../databind/model/IBoundProperty.java | 35 +- .../model/IFeatureBoundDefinitionInline.java | 70 ---- .../metaschema/databind/model/IGroupAs.java | 22 +- .../model/annotations/BoundAssembly.java | 14 +- .../model/annotations/BoundField.java | 13 +- .../databind/model/annotations/BoundFlag.java | 12 - .../annotations/BoundGroupedAssembly.java | 14 +- .../model/annotations/BoundGroupedField.java | 13 +- .../databind/model/annotations/GroupAs.java | 11 - .../model/annotations/MetaschemaAssembly.java | 11 - .../databind/model/annotations/ModelUtil.java | 43 +-- .../impl/AbstractBoundAnnotatedJavaField.java | 78 ---- .../AbstractBoundDefinitionModelComplex.java | 115 ++---- .../impl/AbstractBoundInstanceField.java | 140 ------- .../impl/AbstractBoundInstanceJavaField.java | 60 --- ...bstractBoundInstanceModelGroupedNamed.java | 93 ----- .../AbstractBoundInstanceModelJavaField.java | 85 ----- .../impl/AssemblyModelContainerSupport.java | 30 +- .../model/impl/ConstraintSupport.java | 16 +- .../databind/model/impl/DefaultGroupAs.java | 38 +- .../model/impl/DefinitionAssembly.java | 55 ++- .../databind/model/impl/DefinitionField.java | 82 +++-- .../model/impl/FlagContainerSupport.java | 25 +- .../IFeatureBoundContainerModelAssembly.java | 15 +- ...FeatureBoundContainerModelChoiceGroup.java | 23 +- .../impl/IFeatureInstanceModelGroupAs.java | 10 + .../model/impl/InstanceFlagInline.java | 46 ++- .../impl/InstanceModelAssemblyComplex.java | 94 +++-- .../model/impl/InstanceModelChoiceGroup.java | 112 ++++-- .../model/impl/InstanceModelFieldComplex.java | 174 +++++++-- .../model/impl/InstanceModelFieldScalar.java | 167 +++++++-- .../impl/InstanceModelGroupedAssembly.java | 50 +-- .../InstanceModelGroupedFieldComplex.java | 46 ++- .../databind/model/impl/package-info.java | 4 +- .../AbstractModelInstanceReadHandler.java | 16 +- .../info/IFeatureComplexItemValueHandler.java | 6 + .../info/IFeatureScalarItemValueHandler.java | 8 +- .../metaschema/BindingConstraintLoader.java | 30 +- .../model/metaschema/BindingModuleLoader.java | 11 +- .../IBindingContainerModelAbsolute.java | 60 --- .../IBindingContainerModelAssembly.java | 44 --- .../IBindingContainerModelGrouped.java | 62 ---- .../model/metaschema/IBindingDefinition.java | 34 -- .../IBindingDefinitionAssembly.java | 38 -- .../IBindingDefinitionModelField.java | 33 -- .../metaschema/IBindingInstanceFlag.java | 33 -- .../metaschema/IBindingInstanceModel.java | 35 -- .../IBindingInstanceModelAssembly.java | 34 -- ...IBindingInstanceModelAssemblyAbsolute.java | 34 -- .../IBindingInstanceModelAssemblyGrouped.java | 34 -- .../IBindingInstanceModelField.java | 33 -- .../IBindingInstanceModelFieldAbsolute.java | 34 -- .../IBindingInstanceModelFieldGrouped.java | 34 -- .../IBindingInstanceModelNamed.java | 33 -- .../IBindingInstanceModelNamedAbsolute.java | 34 -- .../IBindingInstanceModelNamedGrouped.java | 34 -- .../metaschema/IBindingModelElement.java | 34 -- .../model/metaschema/IBindingModule.java | 43 --- .../IInstanceModelChoiceBinding.java | 39 -- .../IInstanceModelChoiceGroupBinding.java | 38 -- .../binding/AssemblyConstraints.java | 4 +- .../metaschema/binding/AssemblyModel.java | 22 +- .../metaschema/binding/AssemblyReference.java | 10 +- .../metaschema/binding/FieldConstraints.java | 4 +- .../metaschema/binding/FieldReference.java | 10 +- .../metaschema/binding/FlagAllowedValues.java | 4 +- .../metaschema/binding/FlagConstraints.java | 4 +- .../model/metaschema/binding/FlagExpect.java | 2 +- .../metaschema/binding/FlagIndexHasKey.java | 4 +- .../model/metaschema/binding/FlagMatches.java | 2 +- .../metaschema/binding/FlagReference.java | 10 +- .../binding/InlineDefineAssembly.java | 15 +- .../metaschema/binding/InlineDefineField.java | 15 +- .../metaschema/binding/InlineDefineFlag.java | 12 +- .../model/metaschema/binding/METASCHEMA.java | 29 +- .../metaschema/binding/MetapathContext.java | 4 +- .../binding/MetaschemaMetaConstraints.java | 4 +- .../binding/MetaschemaModuleConstraints.java | 12 +- .../TargetedAllowedValuesConstraint.java | 4 +- .../binding/TargetedExpectConstraint.java | 2 +- .../TargetedHasCardinalityConstraint.java | 2 +- .../binding/TargetedIndexConstraint.java | 4 +- .../TargetedIndexHasKeyConstraint.java | 4 +- .../binding/TargetedIsUniqueConstraint.java | 4 +- .../binding/TargetedMatchesConstraint.java | 2 +- .../metaschema/binding/package-info.java | 5 + .../AbstractBindingModelContainerSupport.java | 73 ++-- ...stractGroupedAssemblyInstanceNodeItem.java | 51 --- .../AbstractGroupedModelInstanceNodeItem.java | 71 ---- .../impl/AbstractInstanceModel.java | 64 ---- .../impl/AbstractInstanceModelGrouped.java | 104 ------ .../impl/AbstractInstanceModelNamed.java | 118 ------ .../AbstractInstanceModelNamedInline.java | 71 ---- .../AbstractInstanceModelNamedReference.java | 107 ------ .../impl/AssemblyModelContainerSupport.java | 112 +++--- .../model/metaschema/impl/BindingModule.java | 90 ++--- .../ChoiceGroupModelContainerSupport.java | 114 +++--- .../impl/ChoiceModelContainerSupport.java | 76 ++-- .../impl/DefinitionAssemblyGlobal.java | 110 +++--- .../impl/DefinitionFieldGlobal.java | 77 ++-- .../metaschema/impl/DefinitionFlagGlobal.java | 65 ++-- .../metaschema/impl/FlagContainerSupport.java | 117 ++---- .../model/metaschema/impl/GroupAsImpl.java | 22 +- .../impl/IFeatureBindingContainerModel.java | 47 +-- ...IFeatureBindingContainerModelAssembly.java | 65 ++-- .../impl/IFeatureInstanceModelGroupAs.java | 4 +- .../metaschema/impl/InstanceFlagInline.java | 53 ++- .../impl/InstanceFlagReference.java | 46 ++- .../impl/InstanceModelAssemblyInline.java | 155 ++++---- .../impl/InstanceModelAssemblyReference.java | 98 +++-- .../metaschema/impl/InstanceModelChoice.java | 63 ++-- .../impl/InstanceModelChoiceGroup.java | 80 ++-- .../impl/InstanceModelFieldInline.java | 116 +++--- .../impl/InstanceModelFieldReference.java | 96 +++-- .../InstanceModelGroupedAssemblyInline.java | 115 +++--- ...InstanceModelGroupedAssemblyReference.java | 64 +++- .../impl/InstanceModelGroupedFieldInline.java | 92 +++-- .../InstanceModelGroupedFieldReference.java | 65 +++- .../model/metaschema/impl/ModelSupport.java | 23 +- ...gDefinitionFlag.java => package-info.java} | 13 +- .../databind/model/package-info.java | 6 +- .../metaschema/databind/package-info.java | 18 +- .../databind/DefaultBindingContextTest.java | 8 +- .../codegen/AbstractMetaschemaTest.java | 9 +- .../databind/codegen/GenerationTest.java | 4 +- .../MetaschemaModuleMetaschemaTest.java | 9 +- .../databind/io/json/JsonParserTest.java | 7 +- .../DefaultAssemblyClassBindingTest.java | 3 +- .../databind/model/JsonKeyTest.java | 4 +- .../databind/model/test/SimpleAssembly.java | 3 +- .../databind/testing/model/ModelTestBase.java | 22 +- .../nist/secauto/metaschema/cli/CLITest.java | 3 +- .../metaschema/schemagen/ModuleIndex.java | 6 +- .../json/impl/FieldDefinitionJsonSchema.java | 4 +- .../builder/AbstractCollectionBuilder.java | 19 +- .../metaschema/schemagen/JsonSuiteTest.java | 5 +- .../schemagen/MetaschemaModuleTest.java | 19 +- .../metaschema/schemagen/XmlSuiteTest.java | 5 +- src/site/site.xml | 3 +- 304 files changed, 4169 insertions(+), 6155 deletions(-) create mode 100644 core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractAssemblyInstance.java rename core/src/main/java/gov/nist/secauto/metaschema/core/model/{AbstractNamedModelInstanceGrouped.java => AbstractChoiceGroupInstance.java} (78%) create mode 100644 core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractChoiceInstance.java rename core/src/main/java/gov/nist/secauto/metaschema/core/model/{IContainerFlag.java => AbstractDefinition.java} (68%) rename databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/IFeatureBoundContainerFlag.java => core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractFieldInstance.java (60%) create mode 100644 core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractFlagInstance.java create mode 100644 core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractGlobalAssemblyDefinition.java rename databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AbstractDefinition.java => core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractGlobalDefinition.java (76%) rename databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AbstractBinding.java => core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractGlobalFieldDefinition.java (79%) rename databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstance.java => core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractGlobalFlagDefinition.java (81%) rename databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/IFeatureBindingDefinitionInline.java => core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractInlineAssemblyDefinition.java (59%) rename databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AbstractInstance.java => core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractInlineFieldDefinition.java (66%) rename databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingDefinitionModel.java => core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractInlineFlagDefinition.java (69%) rename databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/IFeatureBindingContainerFlag.java => core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractNamedInstance.java (63%) create mode 100644 core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractNamedModelInstance.java create mode 100644 core/src/main/java/gov/nist/secauto/metaschema/core/model/FlagContainerBuilder.java rename {databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl => core/src/main/java/gov/nist/secauto/metaschema/core/model}/IFeatureValueless.java (93%) rename databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBinding.java => core/src/main/java/gov/nist/secauto/metaschema/core/model/IFlagContainerBuilder.java (89%) rename core/src/main/java/gov/nist/secauto/metaschema/core/model/{IKeyed.java => IJsonNamed.java} (86%) rename databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceNamed.java => core/src/main/java/gov/nist/secauto/metaschema/core/model/IMetapathQueryable.java (77%) rename databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModelAbsolute.java => core/src/main/java/gov/nist/secauto/metaschema/core/model/IMetaschemaModule.java (87%) create mode 100644 core/src/main/java/gov/nist/secauto/metaschema/core/model/INamed.java rename core/src/main/java/gov/nist/secauto/metaschema/core/model/{xml => }/impl/DefaultContainerFlagSupport.java (97%) rename core/src/main/java/gov/nist/secauto/metaschema/core/model/{ => impl}/EmptyFlagContainer.java (91%) delete mode 100644 core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/IXmlModule.java rename core/src/test/java/gov/nist/secauto/metaschema/core/metapath/cst/{PredicateTest.java => PredicateExpressionTest.java} (100%) delete mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/impl/NameConverter.java delete mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/impl/NameUtil.java delete mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundContainerFlag.java delete mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundDefinition.java delete mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceModelNamedComplex.java delete mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IFeatureBoundDefinitionInline.java delete mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/AbstractBoundAnnotatedJavaField.java delete mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/AbstractBoundInstanceField.java delete mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/AbstractBoundInstanceJavaField.java delete mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/AbstractBoundInstanceModelGroupedNamed.java delete mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/AbstractBoundInstanceModelJavaField.java delete mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingContainerModelAbsolute.java delete mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingContainerModelAssembly.java delete mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingContainerModelGrouped.java delete mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingDefinition.java delete mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingDefinitionAssembly.java delete mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingDefinitionModelField.java delete mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceFlag.java delete mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModel.java delete mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModelAssembly.java delete mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModelAssemblyAbsolute.java delete mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModelAssemblyGrouped.java delete mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModelField.java delete mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModelFieldAbsolute.java delete mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModelFieldGrouped.java delete mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModelNamed.java delete mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModelNamedAbsolute.java delete mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModelNamedGrouped.java delete mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingModelElement.java delete mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingModule.java delete mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IInstanceModelChoiceBinding.java delete mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IInstanceModelChoiceGroupBinding.java delete mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AbstractGroupedAssemblyInstanceNodeItem.java delete mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AbstractGroupedModelInstanceNodeItem.java delete mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AbstractInstanceModel.java delete mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AbstractInstanceModelGrouped.java delete mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AbstractInstanceModelNamed.java delete mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AbstractInstanceModelNamedInline.java delete mode 100644 databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AbstractInstanceModelNamedReference.java rename databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/{IBindingDefinitionFlag.java => package-info.java} (87%) diff --git a/core/pom.xml b/core/pom.xml index 6e8baf269..e4fabc367 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -169,9 +169,10 @@ jacoco-maven-plugin - - gov/nist/secauto/metaschema/core/model/xml/xmlbeans/**/* + + gov/nist/secauto/metaschema/core/model/xml/xmlbeans/**/* org/apache/xmlbeans/**/* + gov/nist/secauto/metaschema/core/metapath/antlr/* diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/AbstractDataTypeProvider.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/AbstractDataTypeProvider.java index 256bb755a..9fac25c1a 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/AbstractDataTypeProvider.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/AbstractDataTypeProvider.java @@ -61,7 +61,7 @@ public List> getJavaTypeAdapters() { * if another type adapter has no name */ protected void registerDatatype(@NonNull IDataTypeAdapter adapter) { - if (adapter.getNames().size() == 0) { + if (adapter.getNames().isEmpty()) { throw new IllegalArgumentException("The adapter has no name: " + adapter.getClass().getName()); } synchronized (this) { diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/markup/flexmark/HtmlQuoteTagExtension.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/markup/flexmark/HtmlQuoteTagExtension.java index e5cc2434a..894eb506f 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/markup/flexmark/HtmlQuoteTagExtension.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/markup/flexmark/HtmlQuoteTagExtension.java @@ -172,6 +172,7 @@ public HtmlNodeRenderer apply(DataHolder options) { public static class DoubleQuoteNode extends TypographicQuotes { + @SuppressWarnings("PMD.ConstructorCallsOverridableMethod") public DoubleQuoteNode(TypographicQuotes node) { super(node.getOpeningMarker(), node.getText(), node.getClosingMarker()); setTypographicOpening(node.getTypographicOpening()); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/ISequence.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/ISequence.java index 569f3ccac..229b65f6e 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/ISequence.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/ISequence.java @@ -240,7 +240,7 @@ public Supplier> supplier() { @Override public BiConsumer, ITEM_TYPE> accumulator() { - return (list, value) -> list.add(value); + return List::add; } @Override @@ -280,7 +280,7 @@ static ISequence map( @NonNull Function mapFunction, @NonNull ISequence seq) { return seq.safeStream() - .map(item -> mapFunction.apply(item)) + .map(mapFunction::apply) .collect(toSequence()); } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/BuildCSTVisitor.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/BuildCSTVisitor.java index 3cd8b46f8..471d2acd1 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/BuildCSTVisitor.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/BuildCSTVisitor.java @@ -138,8 +138,9 @@ public BuildCSTVisitor(@NonNull StaticContext context) { this.context = context; } - /* ============================================================ - * Expressions - https://www.w3.org/TR/xpath-31/#id-expressions + /* + * ============================================================ Expressions - + * https://www.w3.org/TR/xpath-31/#id-expressions * ============================================================ */ @NonNull @@ -155,8 +156,9 @@ protected IExpression handleExpr(ExprContext ctx) { }); } - /* ================================================================= - * Literal Expressions - https://www.w3.org/TR/xpath-31/#id-literals + /* + * ================================================================= Literal + * Expressions - https://www.w3.org/TR/xpath-31/#id-literals * ================================================================= */ @@ -185,8 +187,9 @@ protected IExpression handleNumericLiteral(NumericliteralContext ctx) { return retval; } - /* ================================================================== - * Variable References - https://www.w3.org/TR/xpath-31/#id-variables + /* + * ================================================================== Variable + * References - https://www.w3.org/TR/xpath-31/#id-variables * ================================================================== */ @@ -198,8 +201,9 @@ protected IExpression handleVarref(VarrefContext ctx) { getContext().getVariablePrefixResolver())); } - /* ==================================================================== - * For Expressions - https://www.w3.org/TR/xpath-31/#id-for-expressions + /* + * ==================================================================== For + * Expressions - https://www.w3.org/TR/xpath-31/#id-for-expressions * ==================================================================== */ @@ -234,8 +238,9 @@ protected IExpression handleForexpr(ForexprContext ctx) { return retval; } - /* ==================================================================== - * Let Expressions - https://www.w3.org/TR/xpath-31/#id-let-expressions + /* + * ==================================================================== Let + * Expressions - https://www.w3.org/TR/xpath-31/#id-let-expressions * ==================================================================== */ @@ -262,9 +267,12 @@ protected IExpression handleLet(LetexprContext context) { return retval; } - /* ================================================================================== - * Quantified Expressions - https://www.w3.org/TR/xpath-31/#id-quantified-expressions - * ================================================================================== + /* + * ============================================================================= + * ===== Quantified Expressions - + * https://www.w3.org/TR/xpath-31/#id-quantified-expressions + * ============================================================================= + * ===== */ @Override @@ -302,8 +310,9 @@ protected IExpression handleQuantifiedexpr(QuantifiedexprContext ctx) { return new Quantified(quantifier, vars, satisfies); } - /* ======================================================================= - * Arrow operator (=>) - https://www.w3.org/TR/xpath-31/#id-arrow-operator + /* + * ======================================================================= Arrow + * operator (=>) - https://www.w3.org/TR/xpath-31/#id-arrow-operator * ======================================================================= */ @@ -333,9 +342,12 @@ protected IExpression handleArrowexpr(ArrowexprContext context) { }); } - /* ================================================================================= - * Parenthesized Expressions - https://www.w3.org/TR/xpath-31/#id-paren-expressions - * ================================================================================= + /* + * ============================================================================= + * ==== Parenthesized Expressions - + * https://www.w3.org/TR/xpath-31/#id-paren-expressions + * ============================================================================= + * ==== */ @Override @@ -343,9 +355,12 @@ protected IExpression handleEmptyParenthesizedexpr(ParenthesizedexprContext ctx) return EmptySequence.instance(); } - /* ===================================================================================== - * Context Item Expression - https://www.w3.org/TR/xpath-31/#id-context-item-expression - * ===================================================================================== + /* + * ============================================================================= + * ======== Context Item Expression - + * https://www.w3.org/TR/xpath-31/#id-context-item-expression + * ============================================================================= + * ======== */ @Override @@ -353,7 +368,8 @@ protected IExpression handleContextitemexpr(ContextitemexprContext ctx) { return ContextItem.instance(); } - /* ========================================================================= + /* + * ========================================================================= * Static Function Calls - https://www.w3.org/TR/xpath-31/#id-function-calls * ========================================================================= */ @@ -396,7 +412,8 @@ protected IExpression handleFunctioncall(FunctioncallContext ctx) { .collect(Collectors.toUnmodifiableList()))); } - /* ========================================================================= + /* + * ========================================================================= * Filter Expressions - https://www.w3.org/TR/xpath-31/#id-filter-expression * ========================================================================= */ @@ -461,8 +478,9 @@ protected IExpression handlePostfixexpr(PostfixexprContext ctx) { } return retval; } - /* ====================================================================== - * Path Expressions - https://www.w3.org/TR/xpath-31/#id-path-expressions + /* + * ====================================================================== Path + * Expressions - https://www.w3.org/TR/xpath-31/#id-path-expressions * ====================================================================== */ @@ -498,9 +516,12 @@ protected IExpression handlePathexpr(PathexprContext ctx) { return retval; } - /* ======================================================================================= - * RelativePath Expressions - https://www.w3.org/TR/xpath-31/#id-relative-path-expressions - * ======================================================================================= + /* + * ============================================================================= + * ========== RelativePath Expressions - + * https://www.w3.org/TR/xpath-31/#id-relative-path-expressions + * ============================================================================= + * ========== */ @Override @@ -528,8 +549,9 @@ protected IExpression handleRelativepathexpr(RelativepathexprContext context) { }); } - /* ================================================ - * Steps - https://www.w3.org/TR/xpath-31/#id-steps + /* + * ================================================ Steps - + * https://www.w3.org/TR/xpath-31/#id-steps * ================================================ */ @@ -594,13 +616,15 @@ protected IExpression handleReversestep(ReversestepContext ctx) { return new Step(axis, parseNodeTest(ctx.nodetest(), false)); } - /* ======================================================= - * Node Tests - https://www.w3.org/TR/xpath-31/#node-tests + /* + * ======================================================= Node Tests - + * https://www.w3.org/TR/xpath-31/#node-tests * ======================================================= */ - /* ======================================================= - * Node Tests - https://www.w3.org/TR/xpath-31/#node-tests + /* + * ======================================================= Node Tests - + * https://www.w3.org/TR/xpath-31/#node-tests * ======================================================= */ @@ -627,9 +651,8 @@ protected INameTestExpression parseNameTest(NametestContext ctx, boolean flag) { @Override protected Wildcard handleWildcard(WildcardContext ctx) { Predicate> matcher = null; - TerminalNode node; - if ((node = ctx.STAR()) == null) { - if ((node = ctx.CS()) != null) { + if (ctx.STAR() == null) { + if (ctx.CS() != null) { // specified prefix, any local-name String prefix = ctx.NCName().getText(); String namespace = getContext().lookupNamespaceForPrefix(prefix); @@ -637,7 +660,7 @@ protected Wildcard handleWildcard(WildcardContext ctx) { throw new IllegalStateException(String.format("Prefix '%s' did not map to a namespace.", prefix)); } matcher = new Wildcard.MatchAnyLocalName(namespace); - } else if ((node = ctx.SC()) != null) { + } else if (ctx.SC() != null) { // any prefix, specified local-name matcher = new Wildcard.MatchAnyNamespace(ctx.NCName().getText()); } else { @@ -651,7 +674,8 @@ protected Wildcard handleWildcard(WildcardContext ctx) { return new Wildcard(matcher); } - /* ====================================================================== + /* + * ====================================================================== * Predicates within Steps - https://www.w3.org/TR/xpath-31/#id-predicate * ====================================================================== */ @@ -667,8 +691,9 @@ protected IExpression handleAxisstep(AxisstepContext ctx) { return predicates.isEmpty() ? step : new PredicateExpression(step, predicates); } - /* =========================================================== - * Abbreviated Syntax - https://www.w3.org/TR/xpath-31/#abbrev + /* + * =========================================================== Abbreviated + * Syntax - https://www.w3.org/TR/xpath-31/#abbrev * =========================================================== */ @@ -691,7 +716,8 @@ protected IExpression handleAbbrevreversestep(AbbrevreversestepContext ctx) { return Axis.PARENT; } - /* ====================================================================== + /* + * ====================================================================== * Constructing Sequences - https://www.w3.org/TR/xpath-31/#construct_seq * ====================================================================== */ @@ -706,7 +732,8 @@ protected IExpression handleRangeexpr(RangeexprContext ctx) { return new Range(left, right); } - /* ======================================================================== + /* + * ======================================================================== * Combining Node Sequences - https://www.w3.org/TR/xpath-31/#combining_seq * ======================================================================== */ @@ -744,7 +771,8 @@ protected IExpression handleIntersectexceptexpr(IntersectexceptexprContext conte }); } - /* ====================================================================== + /* + * ====================================================================== * Arithmetic Expressions - https://www.w3.org/TR/xpath-31/#id-arithmetic * ====================================================================== */ @@ -835,9 +863,12 @@ protected IExpression handleUnaryexpr(UnaryexprContext ctx) { return retval; } - /* ======================================================================================== - * String Concatenation Expressions - https://www.w3.org/TR/xpath-31/#id-string-concat-expr - * ======================================================================================== + /* + * ============================================================================= + * =========== String Concatenation Expressions - + * https://www.w3.org/TR/xpath-31/#id-string-concat-expr + * ============================================================================= + * =========== */ @Override @@ -848,7 +879,8 @@ protected IExpression handleStringconcatexpr(StringconcatexprContext ctx) { }); } - /* ======================================================================= + /* + * ======================================================================= * Comparison Expressions - https://www.w3.org/TR/xpath-31/#id-comparisons * ======================================================================= */ @@ -924,7 +956,8 @@ protected IExpression handleComparisonexpr(ComparisonexprContext ctx) { // NOPMD return retval; } - /* ============================================================================ + /* + * ============================================================================ * Logical Expressions - https://www.w3.org/TR/xpath-31/#id-logical-expressions * ============================================================================ */ @@ -945,7 +978,8 @@ protected IExpression handleAndexpr(AndexprContext ctx) { }); } - /* ========================================================================= + /* + * ========================================================================= * Conditional Expressions - https://www.w3.org/TR/xpath-31/#id-conditionals * ========================================================================= */ @@ -959,7 +993,8 @@ protected IExpression handleIfexpr(IfexprContext ctx) { return new If(testExpr, thenExpr, elseExpr); } - /* ========================================================================= + /* + * ========================================================================= * Simple map operator (!) - https://www.w3.org/TR/xpath-31/#id-map-operator * ========================================================================= */ diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/ExpressionUtils.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/ExpressionUtils.java index 5fc6ec69f..d900ed4ae 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/ExpressionUtils.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/ExpressionUtils.java @@ -61,7 +61,7 @@ public static Class analyzeStaticResultType retval = baseType; } else { List> expressionClasses = ObjectUtils.notNull(expressions.stream() - .map(expr -> expr.getStaticResultType()).collect(Collectors.toList())); + .map(IExpression::getStaticResultType).collect(Collectors.toList())); // check if the expression classes, are derived from the base type if (checkDerivedFrom(baseType, expressionClasses)) { diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/PredicateExpression.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/PredicateExpression.java index b51633ba2..8e33e838b 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/PredicateExpression.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/PredicateExpression.java @@ -36,6 +36,7 @@ import java.math.BigInteger; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -125,7 +126,7 @@ public List getChildren() { } return bool; }).anyMatch(x -> !x); - }).map(entry -> entry.getValue())); + }).map(Entry::getValue)); retval = ISequence.of(stream); } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/AbstractPathExpression.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/AbstractPathExpression.java index 410e900f0..a381d9419 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/AbstractPathExpression.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/AbstractPathExpression.java @@ -76,7 +76,7 @@ protected Stream searchExpression( = (Stream) expression.accept(dynamicContext, outerFocus).asStream(); Stream childMatches = outerFocus.asStream() - .map(item -> ItemUtils.checkItemIsNodeItemForStep(item)) + .map(ItemUtils::checkItemIsNodeItemForStep) .flatMap(focusedNode -> { Stream matches; diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/Axis.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/Axis.java index 1895941a9..8965ee515 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/Axis.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/Axis.java @@ -43,7 +43,7 @@ @SuppressWarnings("PMD.ShortClassName") // intentional public enum Axis implements IExpression { - SELF(focus -> Stream.of(focus)), + SELF(Stream::of), PARENT(focus -> Stream.ofNullable(focus.getParentNodeItem())), ANCESTOR(INodeItem::ancestor), ANCESTOR_OR_SELF(INodeItem::ancestorOrSelf), @@ -99,7 +99,7 @@ public ISequence accept( retval = ISequence.empty(); } else { retval = ISequence.of(outerFocus.asStream() - .map(item -> ItemUtils.checkItemIsNodeItemForStep(item)) + .map(ItemUtils::checkItemIsNodeItemForStep) .flatMap(item -> { assert item != null; return execute(item); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/Flag.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/Flag.java index 8772aaa78..9dd6b5fea 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/Flag.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/Flag.java @@ -70,7 +70,7 @@ public ISequence accept( DynamicContext dynamicContext, ISequence focus) { return ISequence.of(focus.asStream() - .map(item -> ItemUtils.checkItemIsNodeItemForStep(item)) + .map(ItemUtils::checkItemIsNodeItemForStep) .flatMap(item -> { assert item != null; return match(item); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/ModelInstance.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/ModelInstance.java index 4ae747583..4b17abc81 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/ModelInstance.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/ModelInstance.java @@ -72,7 +72,7 @@ public RESULT accept(IExpressionVisitor visit DynamicContext dynamicContext, ISequence focus) { return ISequence.of(focus.asStream() - .map(item -> ItemUtils.checkItemIsNodeItemForStep(item)) + .map(ItemUtils::checkItemIsNodeItemForStep) .flatMap(item -> { assert item != null; return match(item); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/NameTest.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/NameTest.java index 8b0d4f5c7..d23d39582 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/NameTest.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/NameTest.java @@ -78,7 +78,7 @@ public ISequence accept( DynamicContext dynamicContext, ISequence focus) { return ISequence.of(focus.asStream() - .map(item -> ItemUtils.checkItemIsNodeItemForStep(item)) + .map(ItemUtils::checkItemIsNodeItemForStep) .filter(this::match)); } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/RootSlashOnlyPath.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/RootSlashOnlyPath.java index c5e5902ea..a83c31a4b 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/RootSlashOnlyPath.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/RootSlashOnlyPath.java @@ -61,7 +61,7 @@ public ISequence accept( ISequence focus) { return ObjectUtils.notNull(focus.asStream() - .map(item -> ItemUtils.checkItemIsNodeItemForStep(item)) + .map(ItemUtils::checkItemIsNodeItemForStep) .map(item -> Axis.ANCESTOR_OR_SELF.execute(ObjectUtils.notNull(item)).findFirst().get()) .collect(ISequence.toSequence())); } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/RootSlashPath.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/RootSlashPath.java index c33b16189..df4a9a98d 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/RootSlashPath.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/RootSlashPath.java @@ -60,7 +60,7 @@ public ISequence accept( ISequence focus) { ISequence roots = ObjectUtils.notNull(focus.asStream() - .map(item -> ItemUtils.checkItemIsNodeItemForStep(item)) + .map(ItemUtils::checkItemIsNodeItemForStep) .map(item -> Axis.ANCESTOR_OR_SELF.execute(ObjectUtils.notNull(item)).findFirst().get()) .collect(ISequence.toSequence())); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/Wildcard.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/Wildcard.java index 3ac26f514..12174dfa8 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/Wildcard.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/Wildcard.java @@ -60,8 +60,7 @@ public RESULT accept(IExpressionVisitor visit @Override public ISequence accept( DynamicContext dynamicContext, ISequence focus) { - Stream nodes = focus.asStream() - .map(item -> ItemUtils.checkItemIsNodeItemForStep(item)); + Stream nodes = focus.asStream().map(ItemUtils::checkItemIsNodeItemForStep); if (matcher != null) { Predicate> test = matcher; nodes = nodes.filter(item -> { @@ -75,7 +74,7 @@ public ISequence accept( public static class MatchAnyNamespace implements Predicate> { @NonNull - private String localName; + private final String localName; public MatchAnyNamespace(@NonNull String localName) { this.localName = localName; @@ -89,7 +88,7 @@ public boolean test(IDefinitionNodeItem item) { public static class MatchAnyLocalName implements Predicate> { @NonNull - private String namespace; + private final String namespace; public MatchAnyLocalName(@NonNull String namespace) { this.namespace = namespace; diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/DefaultFunction.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/DefaultFunction.java index 8907d8d66..2540ce4e5 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/DefaultFunction.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/DefaultFunction.java @@ -394,7 +394,7 @@ public String toSignature() { if (arguments.isEmpty()) { builder.append("()"); } else { - builder.append(arguments.stream().map(argument -> argument.toSignature()).collect(Collectors.joining(","))); + builder.append(arguments.stream().map(IArgument::toSignature).collect(Collectors.joining(","))); if (isArityUnbounded()) { builder.append(", ..."); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/FunctionLibrary.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/FunctionLibrary.java index 739059485..a568c8451 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/FunctionLibrary.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/FunctionLibrary.java @@ -53,7 +53,7 @@ public class FunctionLibrary implements IFunctionLibrary { * if the provided function has the same arity as a previously * registered function with the same name */ - public void registerFunction(@NonNull IFunction function) { + public final void registerFunction(@NonNull IFunction function) { registerFunctionByQName(function); registerFunctionByName(function); } @@ -91,10 +91,7 @@ private void registerFunctionByName(@NonNull IFunction function) { @Override public Stream getFunctionsAsStream() { synchronized (this) { - return ObjectUtils.notNull( - libraryByQName.values().stream().flatMap(set -> { - return set.getFunctionsAsStream(); - })); + return ObjectUtils.notNull(libraryByQName.values().stream().flatMap(NamedFunctionSet::getFunctionsAsStream)); } } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/FunctionService.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/FunctionService.java index 07c94382e..22b456138 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/FunctionService.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/FunctionService.java @@ -74,9 +74,7 @@ public IFunctionLibrary load() { FunctionLibrary functionLibrary = new FunctionLibrary(); loader.stream() .map(Provider::get) - .flatMap(library -> { - return library.getFunctionsAsStream(); - }) + .flatMap(IFunctionLibrary::getFunctionsAsStream) .forEachOrdered(function -> functionLibrary.registerFunction(ObjectUtils.notNull(function))); synchronized (this) { diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/FunctionUtils.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/FunctionUtils.java index 3a9790afe..567f95257 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/FunctionUtils.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/FunctionUtils.java @@ -373,7 +373,7 @@ public static TYPE requireTypeOrNull(Class clazz, @Nu */ @NonNull public static Stream> getTypes(@NonNull Stream items) { - return ObjectUtils.notNull(items.map(item -> item.getClass())); + return ObjectUtils.notNull(items.map(Object::getClass)); } /** diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnAvg.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnAvg.java index 2f829a3c5..07fb5b0a0 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnAvg.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnAvg.java @@ -163,7 +163,7 @@ public static IAnyAtomicItem average(@NonNull Collection type.getName()) + .map(Class::getName) .collect(CustomCollectors.joiningWithOxfordComma(",")))); } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnMinMax.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnMinMax.java index 0035a917e..12c6043a2 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnMinMax.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnMinMax.java @@ -179,7 +179,7 @@ private static Stream normalize( int size = resultingItems.size(); if (counts.getOrDefault(IStringItem.class, 0) + counts.getOrDefault(IAnyUriItem.class, 0) == size) { stream = resultingItems.stream() - .map(item -> item.asStringItem()); + .map(IAnyAtomicItem::asStringItem); } else if (counts.getOrDefault(IDecimalItem.class, 0) == size) { stream = resultingItems.stream() .map(item -> (IDecimalItem) item); @@ -191,7 +191,7 @@ private static Stream normalize( InvalidArgumentFunctionException.INVALID_ARGUMENT_TYPE, String.format("Values must all be of a single atomic type. Their types are '%s'.", FunctionUtils.getTypes(resultingItems).stream() - .map(clazz -> clazz.getName()) + .map(Class::getName) .collect(Collectors.joining(",")))); } return stream; diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnSum.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnSum.java index 93c418e83..538969662 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnSum.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnSum.java @@ -208,7 +208,7 @@ public static IAnyAtomicItem sum( InvalidArgumentFunctionException.INVALID_ARGUMENT_TYPE, String.format("Values must all be of type '%s'.", OperationFunctions.AGGREGATE_MATH_TYPES.stream() - .map(type -> type.getName()) + .map(Class::getName) .collect(CustomCollectors.joiningWithOxfordComma(",")))); } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/FlagInstanceNodeItemImpl.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/FlagInstanceNodeItemImpl.java index bc251175b..2dcae87ce 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/FlagInstanceNodeItemImpl.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/FlagInstanceNodeItemImpl.java @@ -56,7 +56,7 @@ public FlagInstanceNodeItemImpl( @NonNull Object value) { super(instance, parent); this.value = value; - this.atomicItem = ObjectUtils.notNull(Lazy.lazy(() -> newAtomicItem())); + this.atomicItem = ObjectUtils.notNull(Lazy.lazy(this::newAtomicItem)); } @Override diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/IFeatureFlagContainerItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/IFeatureFlagContainerItem.java index 324ade525..a3e1de7a1 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/IFeatureFlagContainerItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/IFeatureFlagContainerItem.java @@ -26,7 +26,7 @@ package gov.nist.secauto.metaschema.core.metapath.item.node; -import gov.nist.secauto.metaschema.core.model.IContainerFlag; +import gov.nist.secauto.metaschema.core.model.IModelDefinition; import gov.nist.secauto.metaschema.core.util.CollectionUtil; import java.util.Collection; @@ -40,7 +40,8 @@ /** * This mixin interface indicates that the implementation is a {@link INodeItem} - * that is based on an {@link IContainerFlag}. This means it has flag children. + * that is based on an {@link IModelDefinition}. This means it has flag + * children. *

* If an implementation may have flag and model children, or model children * only, then the {@link IFeatureModelContainerItem} should be used instead. diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/INodeItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/INodeItem.java index a7811e867..e22c4aa4d 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/INodeItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/INodeItem.java @@ -298,6 +298,6 @@ default Stream flags() { @SuppressWarnings("null") @NonNull default Stream> modelItems() { - return getModelItems().stream().flatMap(list -> list.stream()); + return getModelItems().stream().flatMap(Collection::stream); } } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractAssemblyInstance.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractAssemblyInstance.java new file mode 100644 index 000000000..640761284 --- /dev/null +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractAssemblyInstance.java @@ -0,0 +1,69 @@ +/* + * Portions of this software was developed by employees of the National Institute + * of Standards and Technology (NIST), an agency of the Federal Government and is + * being made available as a public service. Pursuant to title 17 United States + * Code Section 105, works of NIST employees are not subject to copyright + * protection in the United States. This software may be subject to foreign + * copyright. Permission in the United States and in foreign countries, to the + * extent that NIST may hold copyright, to use, copy, modify, create derivative + * works, and distribute this software and its documentation without fee is hereby + * granted on a non-exclusive basis, provided that this notice and disclaimer + * of warranty appears in all copies. + * + * THE SOFTWARE IS PROVIDED 'AS IS' WITHOUT ANY WARRANTY OF ANY KIND, EITHER + * EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY + * THAT THE SOFTWARE WILL CONFORM TO SPECIFICATIONS, ANY IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND FREEDOM FROM + * INFRINGEMENT, AND ANY WARRANTY THAT THE DOCUMENTATION WILL CONFORM TO THE + * SOFTWARE, OR ANY WARRANTY THAT THE SOFTWARE WILL BE ERROR FREE. IN NO EVENT + * SHALL NIST BE LIABLE FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO, DIRECT, + * INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF, RESULTING FROM, + * OR IN ANY WAY CONNECTED WITH THIS SOFTWARE, WHETHER OR NOT BASED UPON WARRANTY, + * CONTRACT, TORT, OR OTHERWISE, WHETHER OR NOT INJURY WAS SUSTAINED BY PERSONS OR + * PROPERTY OR OTHERWISE, AND WHETHER OR NOT LOSS WAS SUSTAINED FROM, OR AROSE OUT + * OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER. + */ + +package gov.nist.secauto.metaschema.core.model; + +import gov.nist.secauto.metaschema.core.util.ObjectUtils; + +import edu.umd.cs.findbugs.annotations.NonNull; + +public abstract class AbstractAssemblyInstance< + PARENT extends IContainerModel, + DEFINITION extends IAssemblyDefinition, + INSTANCE extends IAssemblyInstance, + PARENT_DEFINITION extends IAssemblyDefinition> + extends AbstractNamedModelInstance + implements IAssemblyInstance, IFeatureDefinitionReferenceInstance { + + protected AbstractAssemblyInstance(@NonNull PARENT parent) { + super(parent); + } + + @Override + public DEFINITION getDefinition() { + // this should always be not null + return ObjectUtils.asType(ObjectUtils.requireNonNull( + getContainingModule() + .getScopedAssemblyDefinitionByName(getReferencedDefinitionQName()))); + } + + /** + * Generates a "coordinate" string for the assembly instance. + * + * @return the coordinate + */ + @SuppressWarnings("null") + @Override + public String toCoordinates() { + IDefinition definition = getDefinition(); + return String.format("assembly instance %s -> %s in module %s (@%d(%d)", + getXmlQName(), + definition.getDefinitionQName(), + getContainingDefinition().getContainingModule().getShortName(), + hashCode(), + definition.hashCode()); + } +} diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractNamedModelInstanceGrouped.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractChoiceGroupInstance.java similarity index 78% rename from core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractNamedModelInstanceGrouped.java rename to core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractChoiceGroupInstance.java index bc526b861..fc91042b0 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractNamedModelInstanceGrouped.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractChoiceGroupInstance.java @@ -28,22 +28,15 @@ import edu.umd.cs.findbugs.annotations.NonNull; -public abstract class AbstractNamedModelInstanceGrouped implements INamedModelInstanceGrouped { - @NonNull - private final IChoiceGroupInstance parent; +public abstract class AbstractChoiceGroupInstance< + PARENT extends IAssemblyDefinition, + NAMED_MODEL extends INamedModelInstanceGrouped, + FIELD extends IFieldInstanceGrouped, + ASSEMBLY extends IAssemblyInstanceGrouped> + extends AbstractInstance + implements IChoiceGroupInstance, IFeatureContainerModelGrouped { - /** - * Construct a new named model instance that is part of a choice group. - * - * @param parent - * the containing choice group - */ - protected AbstractNamedModelInstanceGrouped(@NonNull IChoiceGroupInstance parent) { - this.parent = parent; - } - - @Override - public IChoiceGroupInstance getParentContainer() { - return parent; + protected AbstractChoiceGroupInstance(@NonNull PARENT parent) { + super(parent); } } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractChoiceInstance.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractChoiceInstance.java new file mode 100644 index 000000000..4d3eaa901 --- /dev/null +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractChoiceInstance.java @@ -0,0 +1,49 @@ +/* + * Portions of this software was developed by employees of the National Institute + * of Standards and Technology (NIST), an agency of the Federal Government and is + * being made available as a public service. Pursuant to title 17 United States + * Code Section 105, works of NIST employees are not subject to copyright + * protection in the United States. This software may be subject to foreign + * copyright. Permission in the United States and in foreign countries, to the + * extent that NIST may hold copyright, to use, copy, modify, create derivative + * works, and distribute this software and its documentation without fee is hereby + * granted on a non-exclusive basis, provided that this notice and disclaimer + * of warranty appears in all copies. + * + * THE SOFTWARE IS PROVIDED 'AS IS' WITHOUT ANY WARRANTY OF ANY KIND, EITHER + * EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY + * THAT THE SOFTWARE WILL CONFORM TO SPECIFICATIONS, ANY IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND FREEDOM FROM + * INFRINGEMENT, AND ANY WARRANTY THAT THE DOCUMENTATION WILL CONFORM TO THE + * SOFTWARE, OR ANY WARRANTY THAT THE SOFTWARE WILL BE ERROR FREE. IN NO EVENT + * SHALL NIST BE LIABLE FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO, DIRECT, + * INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF, RESULTING FROM, + * OR IN ANY WAY CONNECTED WITH THIS SOFTWARE, WHETHER OR NOT BASED UPON WARRANTY, + * CONTRACT, TORT, OR OTHERWISE, WHETHER OR NOT INJURY WAS SUSTAINED BY PERSONS OR + * PROPERTY OR OTHERWISE, AND WHETHER OR NOT LOSS WAS SUSTAINED FROM, OR AROSE OUT + * OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER. + */ + +package gov.nist.secauto.metaschema.core.model; + +import edu.umd.cs.findbugs.annotations.NonNull; + +public abstract class AbstractChoiceInstance< + PARENT extends IAssemblyDefinition, + MODEL extends IModelInstanceAbsolute, + NAMED_MODEL extends INamedModelInstanceAbsolute, + FIELD extends IFieldInstanceAbsolute, + ASSEMBLY extends IAssemblyInstanceAbsolute> + extends AbstractInstance + implements IChoiceInstance, IFeatureContainerModelAbsolute { + + protected AbstractChoiceInstance(@NonNull PARENT parent) { + super(parent); + } + + @Override + public String getGroupAsName() { + // a choice does not have a groups-as name + return null; + } +} diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IContainerFlag.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractDefinition.java similarity index 68% rename from core/src/main/java/gov/nist/secauto/metaschema/core/model/IContainerFlag.java rename to core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractDefinition.java index 599a2f122..4d974917f 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IContainerFlag.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractDefinition.java @@ -26,42 +26,40 @@ package gov.nist.secauto.metaschema.core.model; -import java.util.Collection; +import gov.nist.secauto.metaschema.core.util.ObjectUtils; import javax.xml.namespace.QName; import edu.umd.cs.findbugs.annotations.NonNull; -import edu.umd.cs.findbugs.annotations.Nullable; +import nl.talsmasoftware.lazy4j.Lazy; -/** - * This marker interface identifies a type of definition that contains flags, - * either a field or assembly. - * - */ -public interface IContainerFlag extends IContainer { +public abstract class AbstractDefinition + implements IDefinition { + @NonNull + private final Lazy qname; + @NonNull + private final Lazy definitionQName; + + protected AbstractDefinition(@NonNull NameInitializer initializer) { + this.qname = ObjectUtils.notNull(Lazy.lazy(() -> initializer.apply(getEffectiveName()))); + this.definitionQName = ObjectUtils.notNull(Lazy.lazy(() -> initializer.apply(getName()))); + } + + @SuppressWarnings("null") @Override - default boolean hasChildren() { - return !getFlagInstances().isEmpty(); + public final QName getXmlQName() { + return qname.get(); } - /** - * Retrieves a flag instance, by the flag's effective name, that is defined on - * the containing definition. - * - * @param name - * the flag's name - * @return the matching flag instance, or {@code null} if there is no flag - * matching the specified name - */ - @Nullable - IFlagInstance getFlagInstanceByName(@NonNull QName name); + @SuppressWarnings("null") + @Override + public final QName getDefinitionQName() { + return definitionQName.get(); + } - /** - * Retrieves the flag instances for all flags defined on the containing - * definition. - * - * @return the flags - */ - @NonNull - Collection getFlagInstances(); + @FunctionalInterface + public interface NameInitializer { + @NonNull + QName apply(@NonNull String name); + } } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/IFeatureBoundContainerFlag.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractFieldInstance.java similarity index 60% rename from databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/IFeatureBoundContainerFlag.java rename to core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractFieldInstance.java index 189a0e381..630a336e4 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/IFeatureBoundContainerFlag.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractFieldInstance.java @@ -24,41 +24,46 @@ * OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER. */ -package gov.nist.secauto.metaschema.databind.model.impl; +package gov.nist.secauto.metaschema.core.model; -import java.util.Collection; - -import javax.xml.namespace.QName; +import gov.nist.secauto.metaschema.core.util.ObjectUtils; import edu.umd.cs.findbugs.annotations.NonNull; -import edu.umd.cs.findbugs.annotations.Nullable; -import gov.nist.secauto.metaschema.core.model.IContainerFlagSupport; -import gov.nist.secauto.metaschema.core.model.IFeatureContainerFlag; -import gov.nist.secauto.metaschema.core.util.ObjectUtils; -import gov.nist.secauto.metaschema.databind.model.IBoundContainerFlag; -import gov.nist.secauto.metaschema.databind.model.IBoundInstanceFlag; -/** - * Provides default implementations based on a supporting glag container - * implementation. - */ -public interface IFeatureBoundContainerFlag - extends IBoundContainerFlag, - IFeatureContainerFlag { +public abstract class AbstractFieldInstance< + PARENT extends IContainerModel, + DEFINITION extends IFieldDefinition, + INSTANCE extends IFieldInstance, + PARENT_DEFINITION extends IAssemblyDefinition> + extends AbstractNamedModelInstance + implements IFieldInstance, IFeatureDefinitionReferenceInstance { - @Override - @NonNull - IContainerFlagSupport getFlagContainer(); + protected AbstractFieldInstance(@NonNull PARENT parent) { + super(parent); + } @Override - @Nullable - default IBoundInstanceFlag getFlagInstanceByName(QName name) { - return getFlagContainer().getFlagInstanceMap().get(name); + public DEFINITION getDefinition() { + // this should always be not null + return ObjectUtils.asType(ObjectUtils.requireNonNull( + getContainingModule() + .getScopedFieldDefinitionByName(getReferencedDefinitionQName()))); } + /** + * Generates a "coordinate" string for the assembly instance. + * + * @return the coordinate + */ + @SuppressWarnings("null") @Override - @NonNull - default Collection getFlagInstances() { - return ObjectUtils.notNull(getFlagContainer().getFlagInstanceMap().values()); + public String toCoordinates() { + IDefinition definition = getDefinition(); + return String.format("field instance %s -> %s in module %s (@%d(%d)", + getXmlQName(), + definition.getDefinitionQName(), + getContainingDefinition().getContainingModule().getShortName(), + hashCode(), + definition.hashCode()); } } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractFlagInstance.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractFlagInstance.java new file mode 100644 index 000000000..82ca43adb --- /dev/null +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractFlagInstance.java @@ -0,0 +1,73 @@ +/* + * Portions of this software was developed by employees of the National Institute + * of Standards and Technology (NIST), an agency of the Federal Government and is + * being made available as a public service. Pursuant to title 17 United States + * Code Section 105, works of NIST employees are not subject to copyright + * protection in the United States. This software may be subject to foreign + * copyright. Permission in the United States and in foreign countries, to the + * extent that NIST may hold copyright, to use, copy, modify, create derivative + * works, and distribute this software and its documentation without fee is hereby + * granted on a non-exclusive basis, provided that this notice and disclaimer + * of warranty appears in all copies. + * + * THE SOFTWARE IS PROVIDED 'AS IS' WITHOUT ANY WARRANTY OF ANY KIND, EITHER + * EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY + * THAT THE SOFTWARE WILL CONFORM TO SPECIFICATIONS, ANY IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND FREEDOM FROM + * INFRINGEMENT, AND ANY WARRANTY THAT THE DOCUMENTATION WILL CONFORM TO THE + * SOFTWARE, OR ANY WARRANTY THAT THE SOFTWARE WILL BE ERROR FREE. IN NO EVENT + * SHALL NIST BE LIABLE FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO, DIRECT, + * INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF, RESULTING FROM, + * OR IN ANY WAY CONNECTED WITH THIS SOFTWARE, WHETHER OR NOT BASED UPON WARRANTY, + * CONTRACT, TORT, OR OTHERWISE, WHETHER OR NOT INJURY WAS SUSTAINED BY PERSONS OR + * PROPERTY OR OTHERWISE, AND WHETHER OR NOT LOSS WAS SUSTAINED FROM, OR AROSE OUT + * OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER. + */ + +package gov.nist.secauto.metaschema.core.model; + +import gov.nist.secauto.metaschema.core.util.ObjectUtils; + +import edu.umd.cs.findbugs.annotations.NonNull; + +public abstract class AbstractFlagInstance< + PARENT extends IModelDefinition, + DEFINITION extends IFlagDefinition, + INSTANCE extends IFlagInstance> + extends AbstractNamedInstance + implements IFlagInstance, IFeatureDefinitionReferenceInstance { + + protected AbstractFlagInstance(@NonNull PARENT parent) { + super(parent, name -> parent.getContainingModule().toFlagQName(name)); + } + + @Override + public DEFINITION getDefinition() { + // this should always be not null + return ObjectUtils.asType(ObjectUtils.requireNonNull( + getContainingModule() + .getScopedFlagDefinitionByName(getReferencedDefinitionQName()))); + } + + @Override + public final PARENT getContainingDefinition() { + return getParentContainer(); + } + + /** + * Generates a "coordinate" string for the assembly instance. + * + * @return the coordinate + */ + @SuppressWarnings("null") + @Override + public String toCoordinates() { + IDefinition definition = getDefinition(); + return String.format("flag instance %s -> %s in module %s (@%d(%d)", + getXmlQName(), + definition.getDefinitionQName(), + getContainingDefinition().getContainingModule().getShortName(), + hashCode(), + definition.hashCode()); + } +} diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractGlobalAssemblyDefinition.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractGlobalAssemblyDefinition.java new file mode 100644 index 000000000..b36c09198 --- /dev/null +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractGlobalAssemblyDefinition.java @@ -0,0 +1,53 @@ +/* + * Portions of this software was developed by employees of the National Institute + * of Standards and Technology (NIST), an agency of the Federal Government and is + * being made available as a public service. Pursuant to title 17 United States + * Code Section 105, works of NIST employees are not subject to copyright + * protection in the United States. This software may be subject to foreign + * copyright. Permission in the United States and in foreign countries, to the + * extent that NIST may hold copyright, to use, copy, modify, create derivative + * works, and distribute this software and its documentation without fee is hereby + * granted on a non-exclusive basis, provided that this notice and disclaimer + * of warranty appears in all copies. + * + * THE SOFTWARE IS PROVIDED 'AS IS' WITHOUT ANY WARRANTY OF ANY KIND, EITHER + * EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY + * THAT THE SOFTWARE WILL CONFORM TO SPECIFICATIONS, ANY IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND FREEDOM FROM + * INFRINGEMENT, AND ANY WARRANTY THAT THE DOCUMENTATION WILL CONFORM TO THE + * SOFTWARE, OR ANY WARRANTY THAT THE SOFTWARE WILL BE ERROR FREE. IN NO EVENT + * SHALL NIST BE LIABLE FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO, DIRECT, + * INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF, RESULTING FROM, + * OR IN ANY WAY CONNECTED WITH THIS SOFTWARE, WHETHER OR NOT BASED UPON WARRANTY, + * CONTRACT, TORT, OR OTHERWISE, WHETHER OR NOT INJURY WAS SUSTAINED BY PERSONS OR + * PROPERTY OR OTHERWISE, AND WHETHER OR NOT LOSS WAS SUSTAINED FROM, OR AROSE OUT + * OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER. + */ + +package gov.nist.secauto.metaschema.core.model; + +import edu.umd.cs.findbugs.annotations.NonNull; + +public abstract class AbstractGlobalAssemblyDefinition< + MODULE extends IModule, + INSTANCE extends IAssemblyInstance, + FLAG extends IFlagInstance, + MODEL extends IModelInstanceAbsolute, + NAMED_MODEL extends INamedModelInstanceAbsolute, + FIELD extends IFieldInstanceAbsolute, + ASSEMBLY extends IAssemblyInstanceAbsolute, + CHOICE extends IChoiceInstance, + CHOICE_GROUP extends IChoiceGroupInstance> + extends AbstractGlobalDefinition + implements IAssemblyDefinition, IFeatureContainerFlag, IFeatureContainerModelAssembly< + MODEL, + NAMED_MODEL, + FIELD, + ASSEMBLY, + CHOICE, + CHOICE_GROUP> { + + protected AbstractGlobalAssemblyDefinition(@NonNull MODULE module) { + super(module, name -> module.toModelQName(name)); + } +} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AbstractDefinition.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractGlobalDefinition.java similarity index 76% rename from databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AbstractDefinition.java rename to core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractGlobalDefinition.java index 1af2b5dda..aec1bc70c 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AbstractDefinition.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractGlobalDefinition.java @@ -24,29 +24,34 @@ * OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER. */ -package gov.nist.secauto.metaschema.databind.model.metaschema.impl; - -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingModule; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingDefinition; +package gov.nist.secauto.metaschema.core.model; import edu.umd.cs.findbugs.annotations.NonNull; -public abstract class AbstractDefinition - extends AbstractBinding - implements IBindingDefinition { +public abstract class AbstractGlobalDefinition + extends AbstractDefinition { @NonNull - private final IBindingModule module; + private final MODULE module; - protected AbstractDefinition( - @NonNull BINDING binding, - @NonNull IBindingModule module) { - super(binding); + protected AbstractGlobalDefinition(@NonNull MODULE module, @NonNull NameInitializer initializer) { + super(initializer); this.module = module; - } @Override - public IBindingModule getContainingModule() { + public final MODULE getContainingModule() { return module; } + + @Override + public final boolean isInline() { + // never inline + return false; + } + + @Override + public final INSTANCE getInlineInstance() { + // never inline + return null; + } } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AbstractBinding.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractGlobalFieldDefinition.java similarity index 79% rename from databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AbstractBinding.java rename to core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractGlobalFieldDefinition.java index 2a60a5bbb..f5466ad4d 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AbstractBinding.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractGlobalFieldDefinition.java @@ -24,25 +24,18 @@ * OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER. */ -package gov.nist.secauto.metaschema.databind.model.metaschema.impl; - -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingModelElement; +package gov.nist.secauto.metaschema.core.model; import edu.umd.cs.findbugs.annotations.NonNull; -public abstract class AbstractBinding implements IBindingModelElement { - @NonNull - private final BINDING binding; - - protected AbstractBinding( - @NonNull BINDING binding) { - this.binding = binding; - } +public abstract class AbstractGlobalFieldDefinition< + MODULE extends IModule, + INSTANCE extends IFieldInstance, + FLAG extends IFlagInstance> + extends AbstractGlobalDefinition + implements IFieldDefinition, IFeatureContainerFlag { - @Override - @NonNull - public BINDING getBinding() { - return binding; + protected AbstractGlobalFieldDefinition(@NonNull MODULE module) { + super(module, name -> module.toModelQName(name)); } - } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstance.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractGlobalFlagDefinition.java similarity index 81% rename from databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstance.java rename to core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractGlobalFlagDefinition.java index 0c626c4eb..4748c2327 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstance.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractGlobalFlagDefinition.java @@ -24,19 +24,15 @@ * OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER. */ -package gov.nist.secauto.metaschema.databind.model.metaschema; - -import gov.nist.secauto.metaschema.core.model.IInstance; +package gov.nist.secauto.metaschema.core.model; import edu.umd.cs.findbugs.annotations.NonNull; -public interface IBindingInstance extends IInstance, IBindingModelElement { - @Override - @NonNull - IBindingDefinitionModel getContainingDefinition(); +public abstract class AbstractGlobalFlagDefinition + extends AbstractGlobalDefinition + implements IFlagDefinition { - @Override - default IBindingModule getContainingModule() { - return getContainingDefinition().getContainingModule(); + protected AbstractGlobalFlagDefinition(@NonNull MODULE module) { + super(module, name -> module.toFlagQName(name)); } } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/IFeatureBindingDefinitionInline.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractInlineAssemblyDefinition.java similarity index 59% rename from databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/IFeatureBindingDefinitionInline.java rename to core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractInlineAssemblyDefinition.java index 51726dd86..563bed25d 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/IFeatureBindingDefinitionInline.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractInlineAssemblyDefinition.java @@ -24,40 +24,52 @@ * OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER. */ -package gov.nist.secauto.metaschema.databind.model.metaschema.impl; +package gov.nist.secauto.metaschema.core.model; -import gov.nist.secauto.metaschema.core.model.IFeatureDefinitionInstanceInlined; -import gov.nist.secauto.metaschema.core.model.INamedInstance; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingDefinition; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstance; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingModule; +import gov.nist.secauto.metaschema.core.util.ObjectUtils; import edu.umd.cs.findbugs.annotations.NonNull; -// REFACTOR: Try to eliminate this interface in favor of IFeatureInlinedDefinitionInstance -public interface IFeatureBindingDefinitionInline< - DEFINITION extends IBindingDefinition, - INSTANCE extends IBindingInstance & INamedInstance> - extends IBindingDefinition, IBindingInstance, +public abstract class AbstractInlineAssemblyDefinition< + PARENT extends IContainerModel, + DEFINITION extends IAssemblyDefinition, + INSTANCE extends IAssemblyInstance, + PARENT_DEFINITION extends IAssemblyDefinition, + FLAG extends IFlagInstance, + MODEL extends IModelInstanceAbsolute, + NAMED_MODEL extends INamedModelInstanceAbsolute, + FIELD extends IFieldInstanceAbsolute, + ASSEMBLY extends IAssemblyInstanceAbsolute, + CHOICE extends IChoiceInstance, + CHOICE_GROUP extends IChoiceGroupInstance> + extends AbstractNamedModelInstance + implements IAssemblyInstance, IAssemblyDefinition, IFeatureContainerFlag, + IFeatureContainerModelAssembly< + MODEL, + NAMED_MODEL, + FIELD, + ASSEMBLY, + CHOICE, + CHOICE_GROUP>, IFeatureDefinitionInstanceInlined { + protected AbstractInlineAssemblyDefinition(@NonNull PARENT parent) { + super(parent); + } + + @Override + public final DEFINITION getDefinition() { + return ObjectUtils.asType(this); + } + @Override @NonNull - default IBindingModule getContainingModule() { - // this is the same as IBoundInstance, but is needed since IBoundDefinition - // and IBoundInstance both declare it - return getContainingDefinition().getContainingModule(); + public final INSTANCE getInlineInstance() { + return ObjectUtils.asType(this); } - /** - * {@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(); + public final FLAG getJsonKey() { + return IFeatureContainerFlag.super.getJsonKey(); } } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AbstractInstance.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractInlineFieldDefinition.java similarity index 66% rename from databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AbstractInstance.java rename to core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractInlineFieldDefinition.java index fea395302..17ea2e6ea 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AbstractInstance.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractInlineFieldDefinition.java @@ -24,39 +24,40 @@ * OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER. */ -package gov.nist.secauto.metaschema.databind.model.metaschema.impl; +package gov.nist.secauto.metaschema.core.model; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingDefinitionModel; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstance; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingModule; +import gov.nist.secauto.metaschema.core.util.ObjectUtils; import edu.umd.cs.findbugs.annotations.NonNull; -public abstract class AbstractInstance - extends AbstractBinding - implements IBindingInstance, IFeatureValueless { - @NonNull - private final IBindingDefinitionModel parent; - - protected AbstractInstance( - @NonNull BINDING binding, - @NonNull IBindingDefinitionModel parent) { - super(binding); - this.parent = parent; +public abstract class AbstractInlineFieldDefinition< + PARENT extends IContainerModel, + DEFINITION extends IFieldDefinition, + INSTANCE extends IFieldInstance, + PARENT_DEFINITION extends IAssemblyDefinition, + FLAG extends IFlagInstance> + extends AbstractNamedModelInstance + implements IFieldInstance, IFieldDefinition, + IFeatureContainerFlag, + IFeatureDefinitionInstanceInlined { + + protected AbstractInlineFieldDefinition(@NonNull PARENT parent) { + super(parent); } @Override - public IBindingDefinitionModel getParentContainer() { - return parent; + public final DEFINITION getDefinition() { + return ObjectUtils.asType(this); } @Override - public IBindingDefinitionModel getContainingDefinition() { - return parent; + @NonNull + public final INSTANCE getInlineInstance() { + return ObjectUtils.asType(this); } @Override - public IBindingModule getContainingModule() { - return getContainingDefinition().getContainingModule(); + public final FLAG getJsonKey() { + return IFeatureContainerFlag.super.getJsonKey(); } } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingDefinitionModel.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractInlineFlagDefinition.java similarity index 69% rename from databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingDefinitionModel.java rename to core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractInlineFlagDefinition.java index a660cadb6..927efc077 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingDefinitionModel.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractInlineFlagDefinition.java @@ -24,33 +24,37 @@ * OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER. */ -package gov.nist.secauto.metaschema.databind.model.metaschema; +package gov.nist.secauto.metaschema.core.model; -import gov.nist.secauto.metaschema.core.model.IModelDefinition; import gov.nist.secauto.metaschema.core.util.ObjectUtils; -import java.util.Collection; +import edu.umd.cs.findbugs.annotations.NonNull; -import javax.xml.namespace.QName; +public abstract class AbstractInlineFlagDefinition< + PARENT extends IModelDefinition, + DEFINITION extends IFlagDefinition, + INSTANCE extends IFlagInstance> + extends AbstractNamedInstance + implements IFlagInstance, IFlagDefinition, + IFeatureDefinitionInstanceInlined { -import edu.umd.cs.findbugs.annotations.Nullable; + protected AbstractInlineFlagDefinition(@NonNull PARENT parent) { + super(parent, name -> parent.getContainingModule().toFlagQName(name)); + } -public interface IBindingDefinitionModel - extends IBindingDefinition, IModelDefinition { @Override - IBindingInstanceFlag getFlagInstanceByName(QName name); + public final DEFINITION getDefinition() { + return ObjectUtils.asType(this); + } @Override - Collection getFlagInstances(); - - @Nullable - String getJsonKeyFlagName(); + @NonNull + public final INSTANCE getInlineInstance() { + return ObjectUtils.asType(this); + } @Override - default IBindingInstanceFlag getJsonKeyFlagInstance() { - String name = getJsonKeyFlagName(); - return name == null ? null - : ObjectUtils.requireNonNull(getFlagInstanceByName( - getContainingModule().toFlagQName(name))); + public PARENT getContainingDefinition() { + return getParentContainer(); } } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractInstance.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractInstance.java index 03154c372..e451ba5e0 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractInstance.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractInstance.java @@ -27,9 +27,8 @@ package gov.nist.secauto.metaschema.core.model; import edu.umd.cs.findbugs.annotations.NonNull; -import edu.umd.cs.findbugs.annotations.Nullable; -public abstract class AbstractInstance

implements IInstanceAbsolute { +public abstract class AbstractInstance

implements IInstance { @NonNull private final P parent; @@ -45,13 +44,7 @@ protected AbstractInstance(@NonNull P parent) { @Override @NonNull - public P getParentContainer() { + public final P getParentContainer() { return parent; } - - @Override - @Nullable - public Object getValue(Object parent) { - return getResolvedDefaultValue(); - } } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractLoader.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractLoader.java index dbdd06faf..e69eeaf76 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractLoader.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractLoader.java @@ -148,7 +148,7 @@ protected T loadInternal(@NonNull URI resource, @NonNull Deque visitedResou // first check if the current resource has been visited to prevent cycles if (visitedResources.contains(resource)) { throw new MetaschemaException("Cycle detected in metaschema includes for '" + resource + "'. Call stack: '" - + visitedResources.stream().map(n -> n.toString()).collect(Collectors.joining(","))); + + visitedResources.stream().map(URI::toString).collect(Collectors.joining(","))); } T retval = cache.get(resource); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractModule.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractModule.java index 8ee1c2cc6..515387585 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractModule.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractModule.java @@ -42,6 +42,8 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import javax.xml.namespace.QName; + import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import nl.talsmasoftware.lazy4j.Lazy; @@ -116,7 +118,7 @@ public Collection getExportedFlagDefinitions() { } @Override - public FL getExportedFlagDefinitionByName(String name) { + public FL getExportedFlagDefinitionByName(QName name) { return getExports().getExportedFlagDefinitionMap().get(name); } @@ -127,7 +129,7 @@ public Collection getExportedFieldDefinitions() { } @Override - public FI getExportedFieldDefinitionByName(String name) { + public FI getExportedFieldDefinitionByName(QName name) { return getExports().getExportedFieldDefinitionMap().get(name); } @@ -138,13 +140,20 @@ public Collection getExportedAssemblyDefinitions() { } @Override - public A getExportedAssemblyDefinitionByName(String name) { + public A getExportedAssemblyDefinitionByName(QName name) { return getExports().getExportedAssemblyDefinitionMap().get(name); } + @Override + public A getExportedRootAssemblyDefinitionByName(QName name) { + return getExports().getExportedRootAssemblyDefinitionMap().get(name); + } + @SuppressWarnings({ "unused", "PMD.UnusedPrivateMethod" }) // used by lambda private static DEF handleShadowedDefinitions( - @SuppressWarnings("unused") @NonNull String key, @NonNull DEF oldDef, @NonNull DEF newDef) { + @SuppressWarnings("unused") @NonNull QName key, + @NonNull DEF oldDef, + @NonNull DEF newDef) { if (!oldDef.equals(newDef) && LOGGER.isWarnEnabled()) { LOGGER.warn("The {} '{}' from metaschema '{}' is shadowing '{}' from metaschema '{}'", newDef.getModelType().name().toLowerCase(Locale.ROOT), @@ -158,11 +167,13 @@ private static DEF handleShadowedDefinitions( private class Exports { @NonNull - private final Map exportedFlagDefinitions; + private final Map exportedFlagDefinitions; + @NonNull + private final Map exportedFieldDefinitions; @NonNull - private final Map exportedFieldDefinitions; + private final Map exportedAssemblyDefinitions; @NonNull - private final Map exportedAssemblyDefinitions; + private final Map exportedRootAssemblyDefinitions; @SuppressWarnings("PMD.ConstructorCallsOverridableMethod") public Exports(@NonNull List importedModules) { @@ -196,19 +207,19 @@ public Exports(@NonNull List importedModules) { // Build the maps. Definitions from this module will take priority, with // shadowing being reported when a definition from this module has the same name // as an imported one - Map exportedFlagDefinitions = flags.collect( + Map exportedFlagDefinitions = flags.collect( CustomCollectors.toMap( - IFlagDefinition::getName, + IFlagDefinition::getDefinitionQName, CustomCollectors.identity(), AbstractModule::handleShadowedDefinitions)); - Map exportedFieldDefinitions = fields.collect( + Map exportedFieldDefinitions = fields.collect( CustomCollectors.toMap( - IFieldDefinition::getName, + IFieldDefinition::getDefinitionQName, CustomCollectors.identity(), AbstractModule::handleShadowedDefinitions)); - Map exportedAssemblyDefinitions = assemblies.collect( + Map exportedAssemblyDefinitions = assemblies.collect( CustomCollectors.toMap( - IAssemblyDefinition::getName, + IAssemblyDefinition::getDefinitionQName, CustomCollectors.identity(), AbstractModule::handleShadowedDefinitions)); @@ -221,22 +232,34 @@ public Exports(@NonNull List importedModules) { this.exportedAssemblyDefinitions = exportedAssemblyDefinitions.isEmpty() ? CollectionUtil.emptyMap() : CollectionUtil.unmodifiableMap(exportedAssemblyDefinitions); - + this.exportedRootAssemblyDefinitions = exportedAssemblyDefinitions.isEmpty() + ? CollectionUtil.emptyMap() + : CollectionUtil.unmodifiableMap(ObjectUtils.notNull(exportedAssemblyDefinitions.values().stream() + .filter(IAssemblyDefinition::isRoot) + .collect(CustomCollectors.toMap( + IAssemblyDefinition::getRootXmlQName, + CustomCollectors.identity(), + AbstractModule::handleShadowedDefinitions)))); } @NonNull - public Map getExportedFlagDefinitionMap() { + public Map getExportedFlagDefinitionMap() { return this.exportedFlagDefinitions; } @NonNull - public Map getExportedFieldDefinitionMap() { + public Map getExportedFieldDefinitionMap() { return this.exportedFieldDefinitions; } @NonNull - public Map getExportedAssemblyDefinitionMap() { + public Map getExportedAssemblyDefinitionMap() { return this.exportedAssemblyDefinitions; } + + @NonNull + public Map getExportedRootAssemblyDefinitionMap() { + return this.exportedRootAssemblyDefinitions; + } } } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractModuleLoader.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractModuleLoader.java index a89cf7c50..d3685383b 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractModuleLoader.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractModuleLoader.java @@ -98,7 +98,7 @@ protected List getModulePostProcessors() { protected abstract M newModule( @NonNull URI resource, @NonNull T binding, - @NonNull List importedModules) throws MetaschemaException; + @NonNull List importedModules) throws MetaschemaException; /** * Get the list of Metaschema module URIs associated with the provided binding. diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/IFeatureBindingContainerFlag.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractNamedInstance.java similarity index 63% rename from databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/IFeatureBindingContainerFlag.java rename to core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractNamedInstance.java index 2661e5898..e651b9ee9 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/IFeatureBindingContainerFlag.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractNamedInstance.java @@ -24,39 +24,48 @@ * OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER. */ -package gov.nist.secauto.metaschema.databind.model.metaschema.impl; +package gov.nist.secauto.metaschema.core.model; -import java.util.Collection; +import gov.nist.secauto.metaschema.core.model.AbstractDefinition.NameInitializer; +import gov.nist.secauto.metaschema.core.util.ObjectUtils; import javax.xml.namespace.QName; import edu.umd.cs.findbugs.annotations.NonNull; -import edu.umd.cs.findbugs.annotations.Nullable; -import gov.nist.secauto.metaschema.core.model.IContainerFlagSupport; -import gov.nist.secauto.metaschema.core.model.IFeatureContainerFlag; -import gov.nist.secauto.metaschema.core.util.ObjectUtils; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingDefinitionModel; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceFlag; +import nl.talsmasoftware.lazy4j.Lazy; -/** - * Represents a definition that may contain flags. - */ -public interface IFeatureBindingContainerFlag - extends IFeatureContainerFlag, IBindingDefinitionModel { - - @Override +public abstract class AbstractNamedInstance< + PARENT extends IContainer> + extends AbstractInstance + implements INamedInstance { @NonNull - IContainerFlagSupport getFlagContainer(); + private final Lazy qname; + @NonNull + private final Lazy definitionQName; + + /** + * Construct a new instance. + * + * @param parent + * the parent containing the instance + * @param initializer + * used to generate the instance qualified name + */ + protected AbstractNamedInstance(@NonNull PARENT parent, @NonNull NameInitializer initializer) { + super(parent); + this.qname = ObjectUtils.notNull(Lazy.lazy(() -> initializer.apply(getEffectiveName()))); + this.definitionQName = ObjectUtils.notNull(Lazy.lazy(() -> initializer.apply(getName()))); + } + @SuppressWarnings("null") @Override - @Nullable - default IBindingInstanceFlag getFlagInstanceByName(QName name) { - return getFlagContainer().getFlagInstanceMap().get(name); + public final QName getXmlQName() { + return qname.get(); } + @SuppressWarnings("null") @Override - @NonNull - default Collection getFlagInstances() { - return ObjectUtils.notNull(getFlagContainer().getFlagInstanceMap().values()); + public final QName getReferencedDefinitionQName() { + return definitionQName.get(); } } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractNamedModelInstance.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractNamedModelInstance.java new file mode 100644 index 000000000..b5d7a8ba2 --- /dev/null +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/AbstractNamedModelInstance.java @@ -0,0 +1,47 @@ +/* + * Portions of this software was developed by employees of the National Institute + * of Standards and Technology (NIST), an agency of the Federal Government and is + * being made available as a public service. Pursuant to title 17 United States + * Code Section 105, works of NIST employees are not subject to copyright + * protection in the United States. This software may be subject to foreign + * copyright. Permission in the United States and in foreign countries, to the + * extent that NIST may hold copyright, to use, copy, modify, create derivative + * works, and distribute this software and its documentation without fee is hereby + * granted on a non-exclusive basis, provided that this notice and disclaimer + * of warranty appears in all copies. + * + * THE SOFTWARE IS PROVIDED 'AS IS' WITHOUT ANY WARRANTY OF ANY KIND, EITHER + * EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY + * THAT THE SOFTWARE WILL CONFORM TO SPECIFICATIONS, ANY IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND FREEDOM FROM + * INFRINGEMENT, AND ANY WARRANTY THAT THE DOCUMENTATION WILL CONFORM TO THE + * SOFTWARE, OR ANY WARRANTY THAT THE SOFTWARE WILL BE ERROR FREE. IN NO EVENT + * SHALL NIST BE LIABLE FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO, DIRECT, + * INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF, RESULTING FROM, + * OR IN ANY WAY CONNECTED WITH THIS SOFTWARE, WHETHER OR NOT BASED UPON WARRANTY, + * CONTRACT, TORT, OR OTHERWISE, WHETHER OR NOT INJURY WAS SUSTAINED BY PERSONS OR + * PROPERTY OR OTHERWISE, AND WHETHER OR NOT LOSS WAS SUSTAINED FROM, OR AROSE OUT + * OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER. + */ + +package gov.nist.secauto.metaschema.core.model; + +import gov.nist.secauto.metaschema.core.util.ObjectUtils; + +import edu.umd.cs.findbugs.annotations.NonNull; + +public abstract class AbstractNamedModelInstance< + PARENT extends IContainerModel, + PARENT_DEFINITION extends IAssemblyDefinition> + extends AbstractNamedInstance + implements INamedModelInstance { + + protected AbstractNamedModelInstance(@NonNull PARENT parent) { + super(parent, name -> parent.getOwningDefinition().getContainingModule().toModelQName(name)); + } + + @Override + public final PARENT_DEFINITION getContainingDefinition() { + return ObjectUtils.asType(getParentContainer().getOwningDefinition()); + } +} 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 new file mode 100644 index 000000000..b702706e8 --- /dev/null +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/FlagContainerBuilder.java @@ -0,0 +1,102 @@ +/* + * Portions of this software was developed by employees of the National Institute + * of Standards and Technology (NIST), an agency of the Federal Government and is + * being made available as a public service. Pursuant to title 17 United States + * Code Section 105, works of NIST employees are not subject to copyright + * protection in the United States. This software may be subject to foreign + * copyright. Permission in the United States and in foreign countries, to the + * extent that NIST may hold copyright, to use, copy, modify, create derivative + * works, and distribute this software and its documentation without fee is hereby + * granted on a non-exclusive basis, provided that this notice and disclaimer + * of warranty appears in all copies. + * + * THE SOFTWARE IS PROVIDED 'AS IS' WITHOUT ANY WARRANTY OF ANY KIND, EITHER + * EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY + * THAT THE SOFTWARE WILL CONFORM TO SPECIFICATIONS, ANY IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND FREEDOM FROM + * INFRINGEMENT, AND ANY WARRANTY THAT THE DOCUMENTATION WILL CONFORM TO THE + * SOFTWARE, OR ANY WARRANTY THAT THE SOFTWARE WILL BE ERROR FREE. IN NO EVENT + * SHALL NIST BE LIABLE FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO, DIRECT, + * INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF, RESULTING FROM, + * OR IN ANY WAY CONNECTED WITH THIS SOFTWARE, WHETHER OR NOT BASED UPON WARRANTY, + * CONTRACT, TORT, OR OTHERWISE, WHETHER OR NOT INJURY WAS SUSTAINED BY PERSONS OR + * PROPERTY OR OTHERWISE, AND WHETHER OR NOT LOSS WAS SUSTAINED FROM, OR AROSE OUT + * OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER. + */ + +package gov.nist.secauto.metaschema.core.model; + +import gov.nist.secauto.metaschema.core.model.impl.DefaultContainerFlagSupport; +import gov.nist.secauto.metaschema.core.util.CollectionUtil; +import gov.nist.secauto.metaschema.core.util.CustomCollectors; +import gov.nist.secauto.metaschema.core.util.ObjectUtils; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import javax.xml.namespace.QName; + +import edu.umd.cs.findbugs.annotations.NonNull; +import edu.umd.cs.findbugs.annotations.Nullable; + +public class FlagContainerBuilder implements IFlagContainerBuilder { + private static final Logger LOGGER = LogManager.getLogger(FlagContainerBuilder.class); + + @Nullable + private final QName jsonKeyName; + @NonNull + private final List flags; + + public FlagContainerBuilder(@Nullable QName jsonKeyName) { + this.jsonKeyName = jsonKeyName; + this.flags = new LinkedList<>(); + } + + @Override + @NonNull + public IFlagContainerBuilder flag(@NonNull T instance) { + flags.add(instance); + return this; + } + + @Override + public IContainerFlagSupport build() { + IContainerFlagSupport retval = null; + if (flags.isEmpty()) { + retval = IContainerFlagSupport.empty(); + } else { + Map flagMap = CollectionUtil.unmodifiableMap(ObjectUtils.notNull(flags.stream() + .collect( + CustomCollectors.toMap( + INamed::getXmlQName, + CustomCollectors.identity(), + FlagContainerBuilder::handleShadowedInstances, + LinkedHashMap::new)))); + + T jsonKey = jsonKeyName == null ? null : flagMap.get(jsonKeyName); + retval = new DefaultContainerFlagSupport<>(flagMap, jsonKey); + } + return retval; + } + + private static INSTANCE handleShadowedInstances( + @NonNull QName key, + @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, + owningDefinition.getDefinitionQName(), + module.getShortName(), + module.getLocation()); + } + return shadowing; + } +} diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IAssemblyDefinition.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IAssemblyDefinition.java index ec9bfbc96..a204152cf 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IAssemblyDefinition.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IAssemblyDefinition.java @@ -26,6 +26,7 @@ package gov.nist.secauto.metaschema.core.model; +import gov.nist.secauto.metaschema.core.metapath.item.node.IAssemblyNodeItem; import gov.nist.secauto.metaschema.core.model.constraint.IFeatureModelConstrained; import javax.xml.namespace.QName; @@ -108,6 +109,11 @@ default IAssemblyDefinition getOwningDefinition() { return this; } + @Override + default IAssemblyNodeItem getNodeItem() { + return null; + } + @Override default boolean hasChildren() { return IModelDefinition.super.hasChildren() || IContainerModelAssembly.super.hasChildren(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IChoiceGroupInstance.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IChoiceGroupInstance.java index 727e000f9..4a43cea19 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IChoiceGroupInstance.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IChoiceGroupInstance.java @@ -31,6 +31,7 @@ import java.util.Locale; import edu.umd.cs.findbugs.annotations.NonNull; +import edu.umd.cs.findbugs.annotations.Nullable; public interface IChoiceGroupInstance extends IModelInstanceAbsolute, IContainerModelGrouped { @@ -84,6 +85,18 @@ default boolean isEffectiveValueWrappedInXml() { return true; } + /** + * Get the effective name of the JSON key flag, if a JSON key is configured. + *

+ * This name is expected to be in the same namespace as the containing model + * element (i.e. choice group, assembly, field). + * + * @return the name of the JSON key flag if configured, or {@code null} + * otherwise + */ + @Nullable + String getJsonKeyFlagInstanceName(); + /** * Get the named model instance for the provided choice group item. * 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 24ef98b9e..112c0031b 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 @@ -26,11 +26,14 @@ package gov.nist.secauto.metaschema.core.model; +import gov.nist.secauto.metaschema.core.model.impl.EmptyFlagContainer; + import java.util.Map; import javax.xml.namespace.QName; import edu.umd.cs.findbugs.annotations.NonNull; +import edu.umd.cs.findbugs.annotations.Nullable; public interface IContainerFlagSupport { /** @@ -46,6 +49,16 @@ static IContainerFlagSupport empty() { return (IContainerFlagSupport) EmptyFlagContainer.EMPTY; } + @NonNull + static IFlagContainerBuilder builder() { + return new FlagContainerBuilder<>(null); + } + + @NonNull + static IFlagContainerBuilder builder(@NonNull QName jsonKey) { + return new FlagContainerBuilder<>(jsonKey); + } + /** * Get a mapping of flag effective name to flag instance. * @@ -53,6 +66,7 @@ static IContainerFlagSupport empty() { */ @NonNull Map getFlagInstanceMap(); - // @Nullable - // FI getJsonKeyFlagInstance(); + + @Nullable + FI getJsonKeyFlagInstance(); } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IDefinition.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IDefinition.java index e6a367f3b..b4f6c1131 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IDefinition.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IDefinition.java @@ -30,6 +30,8 @@ import java.util.Locale; +import javax.xml.namespace.QName; + import edu.umd.cs.findbugs.annotations.NonNull; public interface IDefinition extends INamedModelElement, IAttributable, IFeatureValueConstrained { @@ -47,6 +49,21 @@ default ModuleScopeEnum getModuleScope() { return ModuleScopeEnum.LOCAL; } + /** + * The qualified name for the definition. + *

+ * This name is the combination of the definition's namespace, which is the + * module's namespace, and the definition's name. + * + * @return the definition's qualified name + */ + @NonNull + default QName getDefinitionQName() { + return new QName( + getContainingModule().getXmlNamespace().toASCIIString(), + getName()); + } + /** * Determine if the definition is defined inline, meaning the definition is * declared where it is used. @@ -55,7 +72,7 @@ default ModuleScopeEnum getModuleScope() { * the definition is able to be globally referenced */ default boolean isInline() { - return false; + return getInlineInstance() != null; } /** 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/IFeatureContainerFlag.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFeatureContainerFlag.java index 72ee85aba..51ac31b1a 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 @@ -41,7 +41,7 @@ * @param * the flag instance Java type */ -public interface IFeatureContainerFlag extends IContainerFlag { +public interface IFeatureContainerFlag extends IModelDefinition { /** * Lazy initialize the flag instances associated with this definition. * @@ -61,4 +61,9 @@ default FI getFlagInstanceByName(QName name) { default Collection getFlagInstances() { return ObjectUtils.notNull(getFlagContainer().getFlagInstanceMap().values()); } + + @Override + default FI getJsonKey() { + return getFlagContainer().getJsonKeyFlagInstance(); + } } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFeatureContainerModelAbsolute.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFeatureContainerModelAbsolute.java index 4d3fddc78..03d6e5cd2 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFeatureContainerModelAbsolute.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFeatureContainerModelAbsolute.java @@ -46,7 +46,8 @@ public interface IFeatureContainerModelAbsolute< MI extends IModelInstanceAbsolute, NMI extends INamedModelInstanceAbsolute, FI extends IFieldInstanceAbsolute, - AI extends IAssemblyInstanceAbsolute> extends IContainerModelAbsolute, IFeatureContainerModel { + AI extends IAssemblyInstanceAbsolute> + extends IContainerModelAbsolute, IFeatureContainerModel { @Override default Collection getModelInstances() { return getModelContainer().getModelInstances(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFeatureDefinitionInstanceInlined.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFeatureDefinitionInstanceInlined.java index 15c748dbb..11b3f48ea 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFeatureDefinitionInstanceInlined.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFeatureDefinitionInstanceInlined.java @@ -27,9 +27,12 @@ package gov.nist.secauto.metaschema.core.model; import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine; +import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.util.Locale; +import javax.xml.namespace.QName; + import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; @@ -42,7 +45,9 @@ * @param * the associated instance Java type */ -public interface IFeatureDefinitionInstanceInlined +public interface IFeatureDefinitionInstanceInlined< + DEFINITION extends IDefinition, + INSTANCE extends INamedInstance> extends IDefinition, INamedInstance { @Override default boolean isInline() { @@ -51,11 +56,20 @@ default boolean isInline() { } @Override - DEFINITION getDefinition(); + default QName getDefinitionQName() { + return getReferencedDefinitionQName(); + } + + @Override + default DEFINITION getDefinition() { + return ObjectUtils.asType(this); + } @Override @NonNull - INSTANCE getInlineInstance(); + default INSTANCE getInlineInstance() { + return ObjectUtils.asType(this); + } @Override default String getEffectiveFormalName() { diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFeatureDefinitionReferenceInstance.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFeatureDefinitionReferenceInstance.java index 16e54f0ff..e4fc03b98 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFeatureDefinitionReferenceInstance.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFeatureDefinitionReferenceInstance.java @@ -28,8 +28,6 @@ import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine; -import java.util.Locale; - import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; @@ -103,32 +101,4 @@ default Object getEffectiveDefaultValue() { } return retval; } - - /** - * Generates a "coordinate" string for the provided information element - * instance. - * - * A coordinate consists of the element's: - *

- * - * @return the coordinate - */ - @SuppressWarnings("null") - @Override - default String toCoordinates() { - IDefinition definition = getDefinition(); - return String.format("%s-instance:%s:%s/%s@%d(%d)", - getModelType().toString().toLowerCase(Locale.ROOT), - getContainingDefinition().getContainingModule().getShortName(), - definition.getName(), - getName(), - hashCode(), - definition.hashCode()); - } } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/IFeatureValueless.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFeatureValueless.java similarity index 93% rename from databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/IFeatureValueless.java rename to core/src/main/java/gov/nist/secauto/metaschema/core/model/IFeatureValueless.java index cfbcae651..59f0b9527 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/IFeatureValueless.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFeatureValueless.java @@ -24,10 +24,9 @@ * OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER. */ -package gov.nist.secauto.metaschema.databind.model.metaschema.impl; - -import gov.nist.secauto.metaschema.core.model.IInstanceAbsolute; +package gov.nist.secauto.metaschema.core.model; +// REFACTOR: rename to IFeatureValuelessInstance public interface IFeatureValueless extends IInstanceAbsolute { @Override default Object getValue(Object parent) { diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFlag.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFlag.java index 9e08aed4a..a76a352f3 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFlag.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFlag.java @@ -40,14 +40,4 @@ public interface IFlag extends INamedModelElement, IAttributable { default ModelType getModelType() { return ModelType.FLAG; } - - /** - * {@inheritDoc} - *

- * Flags by default do not have namespaces. - */ - @Override - default String getXmlNamespace() { - return null; - } } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBinding.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFlagContainerBuilder.java similarity index 89% rename from databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBinding.java rename to core/src/main/java/gov/nist/secauto/metaschema/core/model/IFlagContainerBuilder.java index fffff52dd..59ffae730 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBinding.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFlagContainerBuilder.java @@ -24,16 +24,14 @@ * OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER. */ -package gov.nist.secauto.metaschema.databind.model.metaschema; - -import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem; +package gov.nist.secauto.metaschema.core.model; import edu.umd.cs.findbugs.annotations.NonNull; -public interface IBinding { +public interface IFlagContainerBuilder { @NonNull - Object getBinding(); + IFlagContainerBuilder flag(@NonNull T instance); @NonNull - INodeItem getBoundNodeItem(); + IContainerFlagSupport build(); } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFlagDefinition.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFlagDefinition.java index 7aa06994e..727a7fd69 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFlagDefinition.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFlagDefinition.java @@ -28,8 +28,5 @@ public interface IFlagDefinition extends IValuedDefinition, IFlag { @Override - default IFlagInstance getInlineInstance() { - // not inline by default - return null; - } + IFlagInstance getInlineInstance(); } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFlagInstance.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFlagInstance.java index f927a2965..3b6038ea9 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFlagInstance.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IFlagInstance.java @@ -26,16 +26,23 @@ package gov.nist.secauto.metaschema.core.model; +import javax.xml.namespace.QName; + public interface IFlagInstance extends IFlag, IValuedInstance, IInstanceAbsolute { boolean DEFAULT_FLAG_REQUIRED = false; @Override - IContainerFlag getParentContainer(); + IModelDefinition getParentContainer(); @Override IFlagDefinition getDefinition(); + @Override + default IModelDefinition getContainingDefinition() { + return getParentContainer(); + } + /** * Determines if a flag value is required to be provided. * @@ -45,4 +52,15 @@ public interface IFlagInstance extends IFlag, IValuedInstance, IInstanceAbsolute default boolean isRequired() { return DEFAULT_FLAG_REQUIRED; } + + @Override + default QName getReferencedDefinitionQName() { + return getContainingModule().toFlagQName(getName()); + } + + @Override + default QName getXmlQName() { + // flags do not have a namespace by default + return getContainingModule().toFlagQName(getEffectiveName()); + } } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IGroupable.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IGroupable.java index 6cbb04920..e06412a16 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IGroupable.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IGroupable.java @@ -36,7 +36,7 @@ import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; -public interface IGroupable extends IInstanceAbsolute, IKeyed { +public interface IGroupable extends IInstanceAbsolute { int DEFAULT_GROUP_AS_MIN_OCCURS = 0; int DEFAULT_GROUP_AS_MAX_OCCURS = 1; diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IKeyed.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IJsonNamed.java similarity index 86% rename from core/src/main/java/gov/nist/secauto/metaschema/core/model/IKeyed.java rename to core/src/main/java/gov/nist/secauto/metaschema/core/model/IJsonNamed.java index 88df9aae9..0b1ed76e2 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IKeyed.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IJsonNamed.java @@ -26,16 +26,16 @@ package gov.nist.secauto.metaschema.core.model; -import edu.umd.cs.findbugs.annotations.Nullable; +import edu.umd.cs.findbugs.annotations.NonNull; -public interface IKeyed { +public interface IJsonNamed { /** - * Get the name of the JSON key, if a JSON key is configured. + * Get the name used for the associated property in JSON/YAML + * serialization-related operations. * - * @return the name of the JSON key flag if configured, or {@code null} - * otherwise + * @return the JSON property name */ - @Nullable - String getJsonKeyFlagName(); + @NonNull + String getJsonName(); } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceNamed.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IMetapathQueryable.java similarity index 77% rename from databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceNamed.java rename to core/src/main/java/gov/nist/secauto/metaschema/core/model/IMetapathQueryable.java index e90e5ebc6..ac8f757a8 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceNamed.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IMetapathQueryable.java @@ -24,15 +24,22 @@ * OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER. */ -package gov.nist.secauto.metaschema.databind.model; +package gov.nist.secauto.metaschema.core.model; -import gov.nist.secauto.metaschema.core.model.INamedInstance; +import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem; -public interface IBoundInstanceNamed extends IBoundInstance, INamedInstance { +import edu.umd.cs.findbugs.annotations.Nullable; - @Override - default String getJsonName() { - // needed to avoid conflict between IBoundInstance and INamedInstance - return INamedInstance.super.getJsonName(); +public interface IMetapathQueryable { + /** + * Get the Metapath node item for this Metaschema module construct, which can be + * used to query it. + * + * @return the node item if the implementation can be queried by a Metapath or + * {@code null} otherwise + */ + @Nullable + default INodeItem getNodeItem() { + return null; } } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModelAbsolute.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IMetaschemaModule.java similarity index 87% rename from databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModelAbsolute.java rename to core/src/main/java/gov/nist/secauto/metaschema/core/model/IMetaschemaModule.java index 28c6a7601..8400ef50a 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModelAbsolute.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IMetaschemaModule.java @@ -24,10 +24,14 @@ * OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER. */ -package gov.nist.secauto.metaschema.databind.model.metaschema; +package gov.nist.secauto.metaschema.core.model; -import gov.nist.secauto.metaschema.core.model.IModelInstanceAbsolute; - -public interface IBindingInstanceModelAbsolute extends IModelInstanceAbsolute, IBindingInstanceModel { +public interface IMetaschemaModule + extends IModuleExtended< + IMetaschemaModule, + IModelDefinition, + IFlagDefinition, + IFieldDefinition, + IAssemblyDefinition> { // no additional methods } 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 8f6fd06dd..2d8317dda 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 @@ -26,26 +26,39 @@ package gov.nist.secauto.metaschema.core.model; +import java.util.Collection; + +import javax.xml.namespace.QName; + +import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; -public interface IModelDefinition extends IDefinition, IContainerFlag { +public interface IModelDefinition extends IDefinition, IContainer { + @Override + default boolean hasChildren() { + return !getFlagInstances().isEmpty(); + } /** - * Indicates if a flag's value can be used as a property name in the containing - * object in JSON who's value will be the object containing the flag. In such - * cases, the flag will not appear in the object. This is only allowed if the - * flag is required, as determined by a {@code true} result from - * {@link IFlagInstance#isRequired()}. The {@link IFlagInstance} can be - * retrieved using {@link #getJsonKeyFlagInstance()}. + * Retrieves a flag instance, by the flag's effective name, that is defined on + * the containing definition. * - * @return {@code true} if the flag's value can be used as a property name, or - * {@code false} otherwise - * @see #getJsonKeyFlagInstance() + * @param name + * the flag's name + * @return the matching flag instance, or {@code null} if there is no flag + * matching the specified name */ - // TODO: remove once moved to the instance side - default boolean hasJsonKey() { - return getJsonKeyFlagInstance() != null; - } + @Nullable + IFlagInstance getFlagInstanceByName(@NonNull QName name); + + /** + * Retrieves the flag instances for all flags defined on the containing + * definition. + * + * @return the flags + */ + @NonNull + Collection getFlagInstances(); /** * Retrieves the flag instance to use as as the property name for the containing @@ -53,9 +66,9 @@ default boolean hasJsonKey() { * * @return the flag instance if a JSON key is configured, or {@code null} * otherwise - * @see #hasJsonKey() */ // TODO: remove once moved to the instance side + // TODO: Reconsider using toFlagName in favor of getReferencedDefinitionQName @Nullable - IFlagInstance getJsonKeyFlagInstance(); + IFlagInstance getJsonKey(); } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IModelElement.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IModelElement.java index b6411e27b..b4da4e52d 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IModelElement.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IModelElement.java @@ -35,7 +35,7 @@ * A marker interface for Metaschema constructs that can be members of a * Metaschema definition's model. */ -public interface IModelElement extends IDefaultable { +public interface IModelElement extends IDefaultable, IMetapathQueryable { /** * Get the Metaschema model type of the information element. diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IModelInstance.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IModelInstance.java index f525d5c4b..d2e222590 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IModelInstance.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IModelInstance.java @@ -35,9 +35,7 @@ public interface IModelInstance extends IInstance { IContainerModel getParentContainer(); @Override - default IAssemblyDefinition getContainingDefinition() { - return getParentContainer().getOwningDefinition(); - } + IAssemblyDefinition getContainingDefinition(); /** * Indicate if the instance allows values without an XML element wrapper. diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IModule.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IModule.java index bb44743e3..02aae7400 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IModule.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IModule.java @@ -28,6 +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.metapath.item.node.IDocumentNodeItem; import java.net.URI; import java.util.Collection; @@ -38,7 +39,7 @@ import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; -public interface IModule { +public interface IModule extends IMetapathQueryable { String XML_NAMESPACE = "http://csrc.nist.gov/ns/oscal/metaschema/1.0"; @@ -144,7 +145,7 @@ default QName getQName() { * @return the matching assembly definition, or {@code null} if none match */ @Nullable - IAssemblyDefinition getAssemblyDefinitionByName(@NonNull String name); + IAssemblyDefinition getAssemblyDefinitionByName(@NonNull QName name); /** * Retrieves the top-level field definitions in this Metaschema module. @@ -164,7 +165,7 @@ default QName getQName() { * @return the matching field definition, or {@code null} if none match */ @Nullable - IFieldDefinition getFieldDefinitionByName(@NonNull String name); + IFieldDefinition getFieldDefinitionByName(@NonNull QName name); /** * Retrieves the top-level assembly and field definitions in this Metaschema @@ -194,7 +195,7 @@ default QName getQName() { * @return the matching flag definition, or {@code null} if none match */ @Nullable - IFlagDefinition getFlagDefinitionByName(@NonNull String name); + IFlagDefinition getFlagDefinitionByName(@NonNull QName name); /** * Retrieves the assembly definition with a matching name from either: 1) the @@ -207,7 +208,7 @@ default QName getQName() { * @return the assembly definition */ @Nullable - IAssemblyDefinition getScopedAssemblyDefinitionByName(@NonNull String name); + IAssemblyDefinition getScopedAssemblyDefinitionByName(@NonNull QName name); /** * Retrieves the field definition with a matching name from either: 1) the @@ -219,7 +220,7 @@ default QName getQName() { * @return the field definition */ @Nullable - IFieldDefinition getScopedFieldDefinitionByName(@NonNull String name); + IFieldDefinition getScopedFieldDefinitionByName(@NonNull QName name); /** * Retrieves the flag definition with a matching name from either: 1) the @@ -231,16 +232,7 @@ default QName getQName() { * @return the flag definition */ @Nullable - IFlagDefinition getScopedFlagDefinitionByName(@NonNull String name); - - /** - * Retrieves the top-level assembly definitions that are marked as roots from - * the current Metaschema module and any imported Metaschema modules. - * - * @return a listing of assembly definitions marked as root - */ - @NonNull - Collection getExportedRootAssemblyDefinitions(); + IFlagDefinition getScopedFlagDefinitionByName(@NonNull QName name); /** * Retrieves the top-level assembly definitions that are marked as roots from @@ -276,7 +268,7 @@ default QName getQName() { * @return the flag definition, or {@code null} if it doesn't exist. */ @Nullable - IFlagDefinition getExportedFlagDefinitionByName(String name); + IFlagDefinition getExportedFlagDefinitionByName(@NonNull QName name); /** * Retrieve the top-level field definitions that are marked global in this @@ -303,7 +295,7 @@ default QName getQName() { * @return the field definition, or {@code null} if it doesn't exist. */ @Nullable - IFieldDefinition getExportedFieldDefinitionByName(String name); + IFieldDefinition getExportedFieldDefinitionByName(@NonNull QName name); /** * Retrieve the top-level assembly definitions that are marked global in this @@ -323,14 +315,36 @@ default QName getQName() { * Retrieves the exported named assembly definition, if it exists. *

* For information about how assembly definitions are exported see - * {@link #getExportedFieldDefinitions()}. + * {@link #getExportedAssemblyDefinitions()}. * * @param name * the definition name * @return the assembly definition, or {@code null} if it doesn't exist. */ @Nullable - IAssemblyDefinition getExportedAssemblyDefinitionByName(String name); + IAssemblyDefinition getExportedAssemblyDefinitionByName(@NonNull QName name); + + /** + * Retrieves the top-level assembly definitions that are marked as roots from + * the current Metaschema module and any imported Metaschema modules. + * + * @return a listing of assembly definitions marked as root + */ + @NonNull + Collection getExportedRootAssemblyDefinitions(); + + /** + * Retrieves the exported named root assembly definition, if it exists. + *

+ * For information about how assembly definitions are exported see + * {@link #getExportedAssemblyDefinitions()}. + * + * @param name + * the root name + * @return the assembly definition, or {@code null} if it doesn't exist. + */ + @Nullable + IAssemblyDefinition getExportedRootAssemblyDefinitionByName(QName name); @NonNull default QName toFlagQName(@NonNull String nameRef) { @@ -338,9 +352,35 @@ default QName toFlagQName(@NonNull String nameRef) { return new QName(nameRef); } + @NonNull + default QName toFlagQName(@Nullable String modelNamespace, @NonNull String nameRef) { + // TODO: handle namespace prefix + return modelNamespace == null + ? new QName(nameRef) + : new QName(modelNamespace, nameRef); + } + @NonNull default QName toModelQName(@NonNull String nameRef) { + return toModelQName(null, nameRef); + } + + @NonNull + default QName toModelQName(@Nullable String modelNamespace, @NonNull String nameRef) { // TODO: handle namespace prefix - return new QName(getXmlNamespace().toASCIIString(), nameRef); + String namespace = modelNamespace == null ? getXmlNamespace().toASCIIString() : modelNamespace; + return new QName(namespace, nameRef); + } + + /** + * If this module is supported by an underlying Metaschema module + * representation, this method retrieves that representation. + * + * @return the underlying document as a Metapath node item or {@code null} + */ + @Override + @Nullable + default IDocumentNodeItem getNodeItem() { + return null; } } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IModuleExtended.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IModuleExtended.java index fa0afbf91..8e259c499 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IModuleExtended.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IModuleExtended.java @@ -34,6 +34,8 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import javax.xml.namespace.QName; + import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; @@ -44,9 +46,9 @@ * can be accessed using {@link #getImportedModules()}. *

* Global scoped Metaschema definitions can be accessed using - * {@link #getScopedAssemblyDefinitionByName(String)}, - * {@link #getScopedFieldDefinitionByName(String)}, and - * {@link #getScopedFlagDefinitionByName(String)}. These methods take into + * {@link #getScopedAssemblyDefinitionByName(QName)}, + * {@link #getScopedFieldDefinitionByName(QName)}, and + * {@link #getScopedFlagDefinitionByName(QName)}. These methods take into * consideration the import order to provide the global definitions that are in * scope within the given Metschema module. *

@@ -120,7 +122,7 @@ static Predicate allRootAssemblyDefinitions() { @Override @Nullable - FL getFlagDefinitionByName(@NonNull String name); + FL getFlagDefinitionByName(@NonNull QName name); @Override @NonNull @@ -128,7 +130,7 @@ static Predicate allRootAssemblyDefinitions() { @Override @Nullable - A getAssemblyDefinitionByName(@NonNull String name); + A getAssemblyDefinitionByName(@NonNull QName name); @Override @NonNull @@ -136,7 +138,7 @@ static Predicate allRootAssemblyDefinitions() { @Override @Nullable - FI getFieldDefinitionByName(@NonNull String name); + FI getFieldDefinitionByName(@NonNull QName name); @Override @SuppressWarnings("unchecked") @@ -151,7 +153,7 @@ default List getAssemblyAndFieldDefinitions() { @Override @Nullable - default A getScopedAssemblyDefinitionByName(@NonNull String name) { + default A getScopedAssemblyDefinitionByName(@NonNull QName name) { // first try local/global top-level definitions from current metaschema module A retval = getAssemblyDefinitionByName(name); if (retval == null) { @@ -163,7 +165,7 @@ default A getScopedAssemblyDefinitionByName(@NonNull String name) { @Override @Nullable - default FI getScopedFieldDefinitionByName(@NonNull String name) { + default FI getScopedFieldDefinitionByName(@NonNull QName name) { // first try local/global top-level definitions from current metaschema module FI retval = getFieldDefinitionByName(name); if (retval == null) { @@ -175,7 +177,7 @@ default FI getScopedFieldDefinitionByName(@NonNull String name) { @Override @Nullable - default FL getScopedFlagDefinitionByName(@NonNull String name) { + default FL getScopedFlagDefinitionByName(@NonNull QName name) { // first try local/global top-level definitions from current metaschema module FL retval = getFlagDefinitionByName(name); if (retval == null) { @@ -207,7 +209,7 @@ default Collection getRootAssemblyDefinitions() { @Override @Nullable - FL getExportedFlagDefinitionByName(String name); + FL getExportedFlagDefinitionByName(QName name); @Override @NonNull @@ -215,7 +217,7 @@ default Collection getRootAssemblyDefinitions() { @Override @Nullable - FI getExportedFieldDefinitionByName(String name); + FI getExportedFieldDefinitionByName(QName name); @Override @NonNull @@ -223,5 +225,5 @@ default Collection getRootAssemblyDefinitions() { @Override @Nullable - A getExportedAssemblyDefinitionByName(String name); + A getExportedAssemblyDefinitionByName(QName name); } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamed.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamed.java new file mode 100644 index 000000000..33b3eb8a7 --- /dev/null +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamed.java @@ -0,0 +1,153 @@ +/* + * Portions of this software was developed by employees of the National Institute + * of Standards and Technology (NIST), an agency of the Federal Government and is + * being made available as a public service. Pursuant to title 17 United States + * Code Section 105, works of NIST employees are not subject to copyright + * protection in the United States. This software may be subject to foreign + * copyright. Permission in the United States and in foreign countries, to the + * extent that NIST may hold copyright, to use, copy, modify, create derivative + * works, and distribute this software and its documentation without fee is hereby + * granted on a non-exclusive basis, provided that this notice and disclaimer + * of warranty appears in all copies. + * + * THE SOFTWARE IS PROVIDED 'AS IS' WITHOUT ANY WARRANTY OF ANY KIND, EITHER + * EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY + * THAT THE SOFTWARE WILL CONFORM TO SPECIFICATIONS, ANY IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND FREEDOM FROM + * INFRINGEMENT, AND ANY WARRANTY THAT THE DOCUMENTATION WILL CONFORM TO THE + * SOFTWARE, OR ANY WARRANTY THAT THE SOFTWARE WILL BE ERROR FREE. IN NO EVENT + * SHALL NIST BE LIABLE FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO, DIRECT, + * INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF, RESULTING FROM, + * OR IN ANY WAY CONNECTED WITH THIS SOFTWARE, WHETHER OR NOT BASED UPON WARRANTY, + * CONTRACT, TORT, OR OTHERWISE, WHETHER OR NOT INJURY WAS SUSTAINED BY PERSONS OR + * PROPERTY OR OTHERWISE, AND WHETHER OR NOT LOSS WAS SUSTAINED FROM, OR AROSE OUT + * OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER. + */ + +package gov.nist.secauto.metaschema.core.model; + +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; + +import edu.umd.cs.findbugs.annotations.NonNull; +import edu.umd.cs.findbugs.annotations.Nullable; + +public interface INamed { + + /** + * 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; + } +} diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamedInstance.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamedInstance.java index fac230666..bb695f1fa 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamedInstance.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamedInstance.java @@ -26,6 +26,8 @@ package gov.nist.secauto.metaschema.core.model; +import javax.xml.namespace.QName; + import edu.umd.cs.findbugs.annotations.NonNull; /** @@ -43,4 +45,12 @@ public interface INamedInstance extends INamedModelElement, IAttributable, IInst @NonNull IDefinition getDefinition(); + /** + * This represents the qualified name of a referenced definition. + * + * @return the qualified name + * @see IDefinition#getDefinitionQName() + */ + @NonNull + QName getReferencedDefinitionQName(); } 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 cca624f0a..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,169 +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 getContainingModule().getXmlNamespace().toASCIIString(); - } - - /** - * 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 - default QName getXmlQName() { - return new QName(getXmlNamespace(), getEffectiveName()); - } - - /** - * 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/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamedModelInstance.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamedModelInstance.java index b87337a72..47c14c813 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamedModelInstance.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamedModelInstance.java @@ -26,10 +26,57 @@ package gov.nist.secauto.metaschema.core.model; +import javax.xml.namespace.QName; + import edu.umd.cs.findbugs.annotations.NonNull; +import edu.umd.cs.findbugs.annotations.Nullable; -public interface INamedModelInstance extends IModelInstance, INamedInstance, IKeyed { +public interface INamedModelInstance extends IModelInstance, INamedInstance { @Override @NonNull IModelDefinition getDefinition(); + + /** + * Indicates if a flag's value can be used as a property name in the containing + * object in JSON who's value will be the object containing the flag. In such + * cases, the flag will not appear in the object. This is only allowed if the + * flag is required, as determined by a {@code true} result from + * {@link IFlagInstance#isRequired()}. The {@link IFlagInstance} can be + * retrieved using {@link #getEffectiveJsonKey()}. + * + * @return {@code true} if the flag's value can be used as a property name, or + * {@code false} otherwise + * @see #getEffectiveJsonKey() + */ + // TODO: remove once moved to the instance side + default boolean hasJsonKey() { + return getEffectiveJsonKey() != null; + } + + /** + * Get the JSON key flag instance for this model instance, if one is configured. + * + * @return the JSON key flag instance or {@code null} if a JSON key is + * configured + */ + @Nullable + IFlagInstance getEffectiveJsonKey(); + + /** + * Get the JSON key associated with this instance. + * + * @return the configured JSON key or {@code null} if no JSON key is configured + */ + @Nullable + IFlagInstance getJsonKey(); + + @Override + default QName getReferencedDefinitionQName() { + return getContainingModule().toModelQName(getName()); + } + + @Override + default QName getXmlQName() { + return getContainingModule().toModelQName(getEffectiveName()); + } } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamedModelInstanceAbsolute.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamedModelInstanceAbsolute.java index a80241dae..4e6a6b6cb 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamedModelInstanceAbsolute.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/INamedModelInstanceAbsolute.java @@ -29,6 +29,7 @@ import gov.nist.secauto.metaschema.core.util.ObjectUtils; import edu.umd.cs.findbugs.annotations.NonNull; +import edu.umd.cs.findbugs.annotations.Nullable; public interface INamedModelInstanceAbsolute extends INamedModelInstance, IModelInstanceAbsolute { @Override @@ -48,14 +49,16 @@ default String getJsonName() { } @Override - default String getJsonKeyFlagName() { - String retval = null; - if (JsonGroupAsBehavior.KEYED.equals(getJsonGroupAsBehavior())) { - IFlagInstance jsonKeyFlag = getDefinition().getJsonKeyFlagInstance(); - if (jsonKeyFlag != null) { - retval = jsonKeyFlag.getEffectiveName(); - } - } - return retval; + @Nullable + default IFlagInstance getEffectiveJsonKey() { + return JsonGroupAsBehavior.KEYED.equals(getJsonGroupAsBehavior()) + ? getJsonKey() + : null; + } + + @Override + @Nullable + default IFlagInstance getJsonKey() { + return getDefinition().getJsonKey(); } } 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 9b4f06699..e5c23a8c6 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 @@ -69,10 +69,19 @@ default String getEffectiveDisciminatorValue() { } @Override - default String getJsonKeyFlagName() { - IChoiceGroupInstance choiceGroup = getParentContainer(); - return JsonGroupAsBehavior.KEYED.equals(choiceGroup.getJsonGroupAsBehavior()) - ? ObjectUtils.notNull(choiceGroup.getJsonKeyFlagName()) + @Nullable + default IFlagInstance getEffectiveJsonKey() { + return JsonGroupAsBehavior.KEYED.equals(getParentContainer().getJsonGroupAsBehavior()) + ? ObjectUtils.requireNonNull(getJsonKey()) : null; } + + @Override + @Nullable + default IFlagInstance getJsonKey() { + String name = getParentContainer().getJsonKeyFlagInstanceName(); + return name == null + ? null + : ObjectUtils.requireNonNull(getDefinition().getFlagInstanceByName(getContainingModule().toFlagQName(name))); + } } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IValued.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IValued.java index a86258466..643f7e582 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/IValued.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/IValued.java @@ -45,5 +45,7 @@ public interface IValued extends IDefaultable { */ // from IInstanceAbsolute @Nullable - Object getValue(@NonNull Object parent); + default Object getValue(@NonNull Object parent) { + return getResolvedDefaultValue(); + } } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/AbstractConstraintValidationHandler.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/AbstractConstraintValidationHandler.java index 505dccaef..0307dad4e 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/AbstractConstraintValidationHandler.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/AbstractConstraintValidationHandler.java @@ -295,7 +295,7 @@ protected CharSequence newAllowedValuesViolationMessage( String allowedValues = constraints.stream() .flatMap(constraint -> constraint.getAllowedValues().values().stream()) - .map(allowedValue -> allowedValue.getValue()) + .map(IAllowedValue::getValue) .sorted() .distinct() .collect(CustomCollectors.joiningWithOxfordComma("or")); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/AssemblyTargetedConstraints.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/AssemblyTargetedConstraints.java index 5595e0459..0822720e3 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/AssemblyTargetedConstraints.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/AssemblyTargetedConstraints.java @@ -61,11 +61,10 @@ public void target(@NonNull IAssemblyDefinition definition) { } @Override - @SuppressWarnings("null") protected void applyTo(@NonNull IAssemblyDefinition definition) { super.applyTo(definition); - getIndexConstraints().forEach(constraint -> definition.addConstraint(constraint)); - getUniqueConstraints().forEach(constraint -> definition.addConstraint(constraint)); - getHasCardinalityConstraints().forEach(constraint -> definition.addConstraint(constraint)); + getIndexConstraints().forEach(definition::addConstraint); + getUniqueConstraints().forEach(definition::addConstraint); + getHasCardinalityConstraints().forEach(definition::addConstraint); } } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/DefaultConstraintValidator.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/DefaultConstraintValidator.java index 4a45b9688..0b276281f 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/DefaultConstraintValidator.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/DefaultConstraintValidator.java @@ -36,7 +36,6 @@ import gov.nist.secauto.metaschema.core.metapath.item.node.AbstractNodeItemVisitor; import gov.nist.secauto.metaschema.core.metapath.item.node.IAssemblyNodeItem; import gov.nist.secauto.metaschema.core.metapath.item.node.IDefinitionNodeItem; -import gov.nist.secauto.metaschema.core.metapath.item.node.IDocumentNodeItem; import gov.nist.secauto.metaschema.core.metapath.item.node.IFieldNodeItem; import gov.nist.secauto.metaschema.core.metapath.item.node.IFlagNodeItem; import gov.nist.secauto.metaschema.core.metapath.item.node.IModuleNodeItem; @@ -794,11 +793,6 @@ private DynamicContext handleLetStatements( return retval; } - @Override - public Void visitDocument(@NonNull IDocumentNodeItem item, DynamicContext context) { - return super.visitDocument(item, context); - } - @Override public Void visitFlag(@NonNull IFlagNodeItem item, DynamicContext context) { assert context != null; diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/impl/AbstractDefinitionTargetedConstraints.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/impl/AbstractDefinitionTargetedConstraints.java index 11dec4e6a..b38f5a36c 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/impl/AbstractDefinitionTargetedConstraints.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/impl/AbstractDefinitionTargetedConstraints.java @@ -75,12 +75,11 @@ protected AbstractDefinitionTargetedConstraints( * @param definition * the definition to apply the constraints to. */ - @SuppressWarnings("null") protected void applyTo(@NonNull T definition) { - getAllowedValuesConstraints().forEach(constraint -> definition.addConstraint(constraint)); - getMatchesConstraints().forEach(constraint -> definition.addConstraint(constraint)); - getIndexHasKeyConstraints().forEach(constraint -> definition.addConstraint(constraint)); - getExpectConstraints().forEach(constraint -> definition.addConstraint(constraint)); + getAllowedValuesConstraints().forEach(definition::addConstraint); + getMatchesConstraints().forEach(definition::addConstraint); + getIndexHasKeyConstraints().forEach(definition::addConstraint); + getExpectConstraints().forEach(definition::addConstraint); } @Override diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/DefaultContainerFlagSupport.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/impl/DefaultContainerFlagSupport.java similarity index 97% rename from core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/DefaultContainerFlagSupport.java rename to core/src/main/java/gov/nist/secauto/metaschema/core/model/impl/DefaultContainerFlagSupport.java index a15cbf6c7..4a70a2d45 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/DefaultContainerFlagSupport.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/impl/DefaultContainerFlagSupport.java @@ -24,7 +24,7 @@ * OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER. */ -package gov.nist.secauto.metaschema.core.model.xml.impl; +package gov.nist.secauto.metaschema.core.model.impl; import gov.nist.secauto.metaschema.core.model.IContainerFlagSupport; import gov.nist.secauto.metaschema.core.model.IFlagInstance; @@ -70,6 +70,7 @@ public Map getFlagInstanceMap() { * @return the flag instance if a JSON key is configured, or {@code null} * otherwise */ + @Override public FI getJsonKeyFlagInstance() { return jsonKey; } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/EmptyFlagContainer.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/impl/EmptyFlagContainer.java similarity index 91% rename from core/src/main/java/gov/nist/secauto/metaschema/core/model/EmptyFlagContainer.java rename to core/src/main/java/gov/nist/secauto/metaschema/core/model/impl/EmptyFlagContainer.java index ca8c4d904..d66a8e722 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/EmptyFlagContainer.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/impl/EmptyFlagContainer.java @@ -59,8 +59,10 @@ * OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER. */ -package gov.nist.secauto.metaschema.core.model; +package gov.nist.secauto.metaschema.core.model.impl; +import gov.nist.secauto.metaschema.core.model.IContainerFlagSupport; +import gov.nist.secauto.metaschema.core.model.IFlagInstance; import gov.nist.secauto.metaschema.core.util.CollectionUtil; import java.util.Map; @@ -69,7 +71,7 @@ import edu.umd.cs.findbugs.annotations.NonNull; -class EmptyFlagContainer implements IContainerFlagSupport { +public class EmptyFlagContainer implements IContainerFlagSupport { @NonNull public static final EmptyFlagContainer EMPTY = new EmptyFlagContainer<>(); @@ -77,4 +79,10 @@ class EmptyFlagContainer implements IContainerFlagSupp public Map getFlagInstanceMap() { return CollectionUtil.emptyMap(); } + + @Override + public FI getJsonKeyFlagInstance() { + // no JSON key + return null; + } } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/util/JsonUtil.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/util/JsonUtil.java index e25f62720..e4691f77d 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/util/JsonUtil.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/util/JsonUtil.java @@ -257,7 +257,7 @@ public static String getAssertMessage( JsonToken actual) { return ObjectUtils.notNull( String.format("Expected JsonToken(s) '%s', but found JsonToken '%s'%s.", - expected.stream().map(token -> token.name()).collect(CustomCollectors.joiningWithOxfordComma("or")), + expected.stream().map(Enum::name).collect(CustomCollectors.joiningWithOxfordComma("or")), actual, generateLocationMessage(parser))); } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/util/XmlEventUtil.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/util/XmlEventUtil.java index 4a49bf509..3ad22a6ce 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/util/XmlEventUtil.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/util/XmlEventUtil.java @@ -81,7 +81,9 @@ private XmlEventUtil() { @SuppressWarnings("null") @NonNull private static Object escape(@NonNull String data) { - return data.chars().mapToObj(c -> (char) c).map(c -> escape(c)).collect(Collectors.joining()); + return data.chars() + .mapToObj(c -> (char) c) + .map(XmlEventUtil::escape).collect(Collectors.joining()); } @SuppressWarnings("null") diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/IXmlModule.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/IXmlModule.java deleted file mode 100644 index d93b289ba..000000000 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/IXmlModule.java +++ /dev/null @@ -1,43 +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.core.model.xml; - -import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition; -import gov.nist.secauto.metaschema.core.model.IFieldDefinition; -import gov.nist.secauto.metaschema.core.model.IFlagDefinition; -import gov.nist.secauto.metaschema.core.model.IModelDefinition; -import gov.nist.secauto.metaschema.core.model.IModuleExtended; - -public interface IXmlModule - extends IModuleExtended< - IXmlModule, - IModelDefinition, - IFlagDefinition, - IFieldDefinition, - IAssemblyDefinition> { - // no additional methods -} diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/ModuleLoader.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/ModuleLoader.java index d966fee1e..7d2d75b3a 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/ModuleLoader.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/ModuleLoader.java @@ -27,6 +27,7 @@ package gov.nist.secauto.metaschema.core.model.xml; import gov.nist.secauto.metaschema.core.model.AbstractModuleLoader; +import gov.nist.secauto.metaschema.core.model.IMetaschemaModule; import gov.nist.secauto.metaschema.core.model.IModuleLoader; import gov.nist.secauto.metaschema.core.model.MetaschemaException; import gov.nist.secauto.metaschema.core.model.xml.impl.XmlModule; @@ -60,7 +61,7 @@ * every use. Any Metaschema imported is also loaded and cached automatically. */ public class ModuleLoader - extends AbstractModuleLoader { + extends AbstractModuleLoader { private boolean resolveEntities; // = false; /** @@ -92,7 +93,8 @@ public void allowEntityResolution() { } @Override - protected IXmlModule newModule(URI resource, METASCHEMADocument binding, List importedModules) + protected IMetaschemaModule newModule(URI resource, METASCHEMADocument binding, + List importedModules) throws MetaschemaException { return new XmlModule(resource, binding, importedModules); } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/XmlMetaConstraintLoader.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/XmlMetaConstraintLoader.java index 98fa49bf2..11e0fae12 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/XmlMetaConstraintLoader.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/XmlMetaConstraintLoader.java @@ -42,6 +42,7 @@ import gov.nist.secauto.metaschema.core.model.constraint.ITargetedConstraints; import gov.nist.secauto.metaschema.core.model.xml.impl.ConstraintXmlSupport; import gov.nist.secauto.metaschema.core.model.xml.xmlbeans.MetaschemaMetaConstraintsDocument; +import gov.nist.secauto.metaschema.core.model.xml.xmlbeans.MetaschemaMetapathReferenceType; import gov.nist.secauto.metaschema.core.model.xml.xmlbeans.ModelContextType; import gov.nist.secauto.metaschema.core.util.CollectionUtil; import gov.nist.secauto.metaschema.core.util.ObjectUtils; @@ -89,13 +90,13 @@ private Context parseContext( List metapaths; if (parent == null) { metapaths = ObjectUtils.notNull(contextObj.getMetapathList().stream() - .map(metapath -> metapath.getTarget()) + .map(MetaschemaMetapathReferenceType::getTarget) .collect(Collectors.toList())); } else { List parentMetapaths = parent.getMetapaths().stream() .collect(Collectors.toList()); metapaths = ObjectUtils.notNull(contextObj.getMetapathList().stream() - .map(metapath -> metapath.getTarget()) + .map(MetaschemaMetapathReferenceType::getTarget) .flatMap(childPath -> { return parentMetapaths.stream() .map(parentPath -> parentPath + '/' + childPath); @@ -190,20 +191,18 @@ protected MetaTargetedContraints( * @param definition * the definition to apply the constraints to. */ - @SuppressWarnings("null") protected void applyTo(@NonNull IDefinition definition) { - getAllowedValuesConstraints().forEach(constraint -> definition.addConstraint(constraint)); - getMatchesConstraints().forEach(constraint -> definition.addConstraint(constraint)); - getIndexHasKeyConstraints().forEach(constraint -> definition.addConstraint(constraint)); - getExpectConstraints().forEach(constraint -> definition.addConstraint(constraint)); + getAllowedValuesConstraints().forEach(definition::addConstraint); + getMatchesConstraints().forEach(definition::addConstraint); + getIndexHasKeyConstraints().forEach(definition::addConstraint); + getExpectConstraints().forEach(definition::addConstraint); } - @SuppressWarnings("null") protected void applyTo(@NonNull IAssemblyDefinition definition) { applyTo((IDefinition) definition); - getIndexConstraints().forEach(constraint -> definition.addConstraint(constraint)); - getUniqueConstraints().forEach(constraint -> definition.addConstraint(constraint)); - getHasCardinalityConstraints().forEach(constraint -> definition.addConstraint(constraint)); + getIndexConstraints().forEach(definition::addConstraint); + getUniqueConstraints().forEach(definition::addConstraint); + getHasCardinalityConstraints().forEach(definition::addConstraint); } @Override diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlAssemblyInstance.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlAssemblyInstance.java index 2bbad0e53..1795b7d44 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlAssemblyInstance.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlAssemblyInstance.java @@ -28,19 +28,17 @@ 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.AbstractInstance; +import gov.nist.secauto.metaschema.core.model.AbstractAssemblyInstance; import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition; import gov.nist.secauto.metaschema.core.model.IAssemblyInstanceAbsolute; import gov.nist.secauto.metaschema.core.model.IAttributable; import gov.nist.secauto.metaschema.core.model.IContainerModel; -import gov.nist.secauto.metaschema.core.model.IFeatureDefinitionReferenceInstance; import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior; import gov.nist.secauto.metaschema.core.model.XmlGroupAsBehavior; import gov.nist.secauto.metaschema.core.model.xml.xmlbeans.AssemblyReferenceType; import gov.nist.secauto.metaschema.core.model.xml.xmlbeans.MarkupLineDatatype; import gov.nist.secauto.metaschema.core.model.xml.xmlbeans.UseNameType; import gov.nist.secauto.metaschema.core.util.CollectionUtil; -import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.util.Map; import java.util.Set; @@ -48,9 +46,13 @@ import edu.umd.cs.findbugs.annotations.NonNull; class XmlAssemblyInstance - extends AbstractInstance - implements IAssemblyInstanceAbsolute, - IFeatureDefinitionReferenceInstance { + extends AbstractAssemblyInstance< + IContainerModel, + IAssemblyDefinition, + IAssemblyInstanceAbsolute, + IAssemblyDefinition> + implements IAssemblyInstanceAbsolute { + @NonNull private final AssemblyReferenceType xmlObject; /** @@ -69,13 +71,6 @@ public XmlAssemblyInstance( this.xmlObject = xmlObject; } - @Override - public IAssemblyDefinition getDefinition() { - // This will always be not null - return ObjectUtils.notNull(getContainingModule() - .getScopedAssemblyDefinitionByName(getName())); - } - // ---------------------------------------- // - Start XmlBeans driven code - CPD-OFF - // ---------------------------------------- @@ -85,6 +80,7 @@ public IAssemblyDefinition getDefinition() { * * @return the underlying XML data */ + @NonNull protected AssemblyReferenceType getXmlObject() { return xmlObject; } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlChoiceGroupInstance.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlChoiceGroupInstance.java index 9a847300f..426f66f37 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlChoiceGroupInstance.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlChoiceGroupInstance.java @@ -27,11 +27,10 @@ package gov.nist.secauto.metaschema.core.model.xml.impl; import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline; -import gov.nist.secauto.metaschema.core.model.AbstractInstance; +import gov.nist.secauto.metaschema.core.model.AbstractChoiceGroupInstance; import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition; import gov.nist.secauto.metaschema.core.model.IAssemblyInstanceGrouped; import gov.nist.secauto.metaschema.core.model.IChoiceGroupInstance; -import gov.nist.secauto.metaschema.core.model.IFeatureContainerModelGrouped; import gov.nist.secauto.metaschema.core.model.IFieldInstanceGrouped; import gov.nist.secauto.metaschema.core.model.IModule; import gov.nist.secauto.metaschema.core.model.INamedModelInstanceGrouped; @@ -56,9 +55,11 @@ import nl.talsmasoftware.lazy4j.Lazy; class XmlChoiceGroupInstance - extends AbstractInstance - implements IChoiceGroupInstance, - IFeatureContainerModelGrouped { + extends AbstractChoiceGroupInstance< + IAssemblyDefinition, + INamedModelInstanceGrouped, + IFieldInstanceGrouped, + IAssemblyInstanceGrouped> { @NonNull private final GroupedChoiceType xmlObject; @NonNull @@ -108,11 +109,11 @@ protected GroupedChoiceType getXmlObject() { public String getJsonDiscriminatorProperty() { return getXmlObject().isSetDiscriminator() ? ObjectUtils.requireNonNull(getXmlObject().getDiscriminator()) - : IChoiceGroupInstance.DEFAULT_JSON_DISCRIMINATOR_PROPERTY_NAME; + : DEFAULT_JSON_DISCRIMINATOR_PROPERTY_NAME; } @Override - public String getJsonKeyFlagName() { + public String getJsonKeyFlagInstanceName() { return getXmlObject().isSetJsonKey() ? getXmlObject().getJsonKey().getFlagRef() : null; } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlChoiceInstance.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlChoiceInstance.java index 9c2d24ae0..e6a78645c 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlChoiceInstance.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlChoiceInstance.java @@ -27,11 +27,10 @@ package gov.nist.secauto.metaschema.core.model.xml.impl; import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline; -import gov.nist.secauto.metaschema.core.model.AbstractInstance; +import gov.nist.secauto.metaschema.core.model.AbstractChoiceInstance; import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition; import gov.nist.secauto.metaschema.core.model.IAssemblyInstanceAbsolute; import gov.nist.secauto.metaschema.core.model.IChoiceInstance; -import gov.nist.secauto.metaschema.core.model.IFeatureContainerModelAbsolute; import gov.nist.secauto.metaschema.core.model.IFieldInstanceAbsolute; import gov.nist.secauto.metaschema.core.model.IModelInstanceAbsolute; import gov.nist.secauto.metaschema.core.model.IModule; @@ -55,9 +54,8 @@ import nl.talsmasoftware.lazy4j.Lazy; class XmlChoiceInstance - extends AbstractInstance - implements IChoiceInstance, - IFeatureContainerModelAbsolute< + extends AbstractChoiceInstance< + IAssemblyDefinition, IModelInstanceAbsolute, INamedModelInstanceAbsolute, IFieldInstanceAbsolute, @@ -88,23 +86,6 @@ public XmlModelContainer getModelContainer() { return ObjectUtils.notNull(modelContainer.get()); } - @Override - public String getGroupAsName() { - // a choice does not have a groups-as name - return null; - } - - @Override - public String getJsonKeyFlagName() { - // choices do not have a JSON key flag - return null; - } - - @Override - public boolean hasChildren() { - return !getModelContainer().getModelInstances().isEmpty(); - } - // ---------------------------------------- // - Start XmlBeans driven code - CPD-OFF - // ---------------------------------------- @@ -131,36 +112,33 @@ public MarkupMultiline getRemarks() { @SuppressWarnings("PMD.UseConcurrentHashMap") @NonNull - private static final XmlObjectParser> XML_MODEL_PARSER - = new XmlObjectParser<>(ObjectUtils.notNull( - Map.ofEntries( - Map.entry(new QName(IModule.XML_NAMESPACE, "assembly"), - XmlChoiceInstance::handleAssembly), - Map.entry(new QName(IModule.XML_NAMESPACE, "define-assembly"), - XmlChoiceInstance::handleDefineAssembly), - Map.entry(new QName(IModule.XML_NAMESPACE, "field"), - XmlChoiceInstance::handleField), - Map.entry(new QName(IModule.XML_NAMESPACE, "define-field"), - XmlChoiceInstance::handleDefineField)))) { - - @Override - protected Handler> - identifyHandler(XmlCursor cursor, XmlObject obj) { - Handler> retval; - if (obj instanceof FieldReferenceType) { - retval = XmlChoiceInstance::handleField; - } else if (obj instanceof InlineFieldDefinitionType) { - retval = XmlChoiceInstance::handleDefineField; - } else if (obj instanceof AssemblyReferenceType) { - retval = XmlChoiceInstance::handleAssembly; - } else if (obj instanceof InlineAssemblyDefinitionType) { - retval = XmlChoiceInstance::handleDefineAssembly; - } else { - retval = super.identifyHandler(cursor, obj); - } - return retval; - } - }; + private static final XmlObjectParser> XML_MODEL_PARSER + = new XmlObjectParser<>(ObjectUtils.notNull( + Map.ofEntries(Map.entry(new QName(IModule.XML_NAMESPACE, "assembly"), XmlChoiceInstance::handleAssembly), + Map.entry(new QName(IModule.XML_NAMESPACE, "define-assembly"), + XmlChoiceInstance::handleDefineAssembly), + Map.entry(new QName(IModule.XML_NAMESPACE, "field"), XmlChoiceInstance::handleField), + Map.entry(new QName(IModule.XML_NAMESPACE, "define-field"), XmlChoiceInstance::handleDefineField)))) { + + @Override + protected Handler> identifyHandler(XmlCursor cursor, + XmlObject obj) { + Handler> retval; + if (obj instanceof FieldReferenceType) { + retval = XmlChoiceInstance::handleField; + } else if (obj instanceof InlineFieldDefinitionType) { + retval = XmlChoiceInstance::handleDefineField; + } else if (obj instanceof AssemblyReferenceType) { + retval = XmlChoiceInstance::handleAssembly; + } else if (obj instanceof InlineAssemblyDefinitionType) { + retval = XmlChoiceInstance::handleDefineAssembly; + } else { + retval = super.identifyHandler(cursor, obj); + } + return retval; + } + }; private static void handleField( // NOPMD false positive @NonNull XmlObject obj, diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlFieldInstance.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlFieldInstance.java index 4762fe67b..2db9e884c 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlFieldInstance.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlFieldInstance.java @@ -28,11 +28,10 @@ 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.AbstractInstance; +import gov.nist.secauto.metaschema.core.model.AbstractFieldInstance; import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition; import gov.nist.secauto.metaschema.core.model.IAttributable; import gov.nist.secauto.metaschema.core.model.IContainerModel; -import gov.nist.secauto.metaschema.core.model.IFeatureDefinitionReferenceInstance; import gov.nist.secauto.metaschema.core.model.IFieldDefinition; import gov.nist.secauto.metaschema.core.model.IFieldInstanceAbsolute; import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior; @@ -49,9 +48,8 @@ import edu.umd.cs.findbugs.annotations.Nullable; class XmlFieldInstance - extends AbstractInstance - implements IFieldInstanceAbsolute, - IFeatureDefinitionReferenceInstance { + extends AbstractFieldInstance + implements IFieldInstanceAbsolute { @NonNull private final FieldReferenceType xmlObject; @Nullable @@ -66,7 +64,7 @@ class XmlFieldInstance * @param container * the parent container, either a choice or assembly */ - @SuppressWarnings("PMD.NullAssignment") + @SuppressWarnings({ "PMD.NullAssignment", "PMD.ConstructorCallsOverridableMethod" }) public XmlFieldInstance( @NonNull FieldReferenceType xmlObject, @NonNull IContainerModel container) { @@ -77,17 +75,6 @@ public XmlFieldInstance( : null; } - @Override - public final IFieldDefinition getDefinition() { - // this will always be not null - return ObjectUtils.notNull(getContainingModule().getScopedFieldDefinitionByName(getName())); - } - - @Override - public IAssemblyDefinition getContainingDefinition() { - return getParentContainer().getOwningDefinition(); - } - // ---------------------------------------- // - Start XmlBeans driven code - CPD-OFF - // ---------------------------------------- @@ -97,6 +84,7 @@ public IAssemblyDefinition getContainingDefinition() { * * @return the underlying XML data */ + @NonNull protected final FieldReferenceType getXmlObject() { return xmlObject; } 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 6a9ff11ca..5f3c64b7e 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 @@ -27,7 +27,9 @@ package gov.nist.secauto.metaschema.core.model.xml.impl; import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition; +import gov.nist.secauto.metaschema.core.model.IContainerFlagSupport; import gov.nist.secauto.metaschema.core.model.IFieldDefinition; +import gov.nist.secauto.metaschema.core.model.IFlagContainerBuilder; import gov.nist.secauto.metaschema.core.model.IFlagInstance; import gov.nist.secauto.metaschema.core.model.IModelDefinition; import gov.nist.secauto.metaschema.core.model.IModule; @@ -39,14 +41,12 @@ import gov.nist.secauto.metaschema.core.model.xml.xmlbeans.InlineAssemblyDefinitionType; import gov.nist.secauto.metaschema.core.model.xml.xmlbeans.InlineFieldDefinitionType; import gov.nist.secauto.metaschema.core.model.xml.xmlbeans.InlineFlagDefinitionType; -import gov.nist.secauto.metaschema.core.util.CollectionUtil; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import org.apache.commons.lang3.tuple.Pair; import org.apache.xmlbeans.XmlCursor; import org.apache.xmlbeans.XmlObject; -import java.util.LinkedHashMap; import java.util.Map; import javax.xml.namespace.QName; @@ -54,12 +54,10 @@ import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; -@SuppressWarnings("PMD.NullAssignment") // readability -class XmlFlagContainerSupport - extends DefaultContainerFlagSupport { +final class XmlFlagContainerSupport { @SuppressWarnings("PMD.UseConcurrentHashMap") @NonNull - private static final XmlObjectParser>> XML_MODEL_PARSER + private static final XmlObjectParser>> XML_MODEL_PARSER = new XmlObjectParser<>(ObjectUtils.notNull( Map.ofEntries( Map.entry(new QName(IModule.XML_NAMESPACE, "flag"), @@ -68,9 +66,10 @@ class XmlFlagContainerSupport XmlFlagContainerSupport::handleDefineFlag)))) { @Override - protected Handler>> identifyHandler(XmlCursor cursor, + protected Handler>> identifyHandler( + XmlCursor cursor, XmlObject obj) { - Handler>> retval; + Handler>> retval; if (obj instanceof FlagReferenceType) { retval = XmlFlagContainerSupport::handleFlag; } else if (obj instanceof InlineFlagDefinitionType) { @@ -84,154 +83,163 @@ protected Handler>> identifyHan private static void handleFlag( // NOPMD false positive @NonNull XmlObject obj, - Pair> state) { + Pair> state) { XmlFlagInstance flagInstance = new XmlFlagInstance( (FlagReferenceType) obj, ObjectUtils.notNull(state.getLeft())); - state.getRight().put(flagInstance.getXmlQName(), flagInstance); + state.getRight().flag(flagInstance); } private static void handleDefineFlag( // NOPMD false positive @NonNull XmlObject obj, - Pair> state) { + Pair> state) { XmlInlineFlagDefinition flagInstance = new XmlInlineFlagDefinition( (InlineFlagDefinitionType) obj, ObjectUtils.notNull(state.getLeft())); - state.getRight().put(flagInstance.getXmlQName(), flagInstance); - } - - protected XmlFlagContainerSupport( - @NonNull Map flagInstanceMap, - @Nullable QName jsonKeyFlagName) { - super(flagInstanceMap, - jsonKeyFlagName == null ? null : ObjectUtils.requireNonNull(flagInstanceMap.get(jsonKeyFlagName))); + state.getRight().flag(flagInstance); } /** - * Generate a set of constraints from the provided XMLBeans instance. + * Generate a flag container from the provided XMLBeans instance. * * @param xmlField * the XMLBeans instance * @param container * the field containing the flag */ - public XmlFlagContainerSupport( + static IContainerFlagSupport newInstance( @NonNull GlobalFieldDefinitionType xmlField, @NonNull IFieldDefinition container) { - this( - xmlField.getFlagList().size() > 0 || xmlField.getDefineFlagList().size() > 0 - ? parseLocalFlags(xmlField, container) - : CollectionUtil.emptyMap(), - xmlField.isSetJsonKey() - ? container.getContainingModule().toFlagQName(xmlField.getJsonKey().getFlagRef()) - : null); + if (!xmlField.getFlagList().isEmpty() || !xmlField.getDefineFlagList().isEmpty()) { + IFlagContainerBuilder builder = xmlField.isSetJsonKey() + ? IContainerFlagSupport.builder(container.getContainingModule().toFlagQName( + ObjectUtils.requireNonNull(xmlField.getJsonKey().getFlagRef()))) + : IContainerFlagSupport.builder(); + parseLocalFlags(xmlField, container, builder); + return builder.build(); + } + return IContainerFlagSupport.empty(); } /** - * Generate a set of constraints from the provided XMLBeans instance. + * Generate a flag container from the provided XMLBeans instance. * * @param xmlField * the XMLBeans instance * @param container * the field containing the flag */ - public XmlFlagContainerSupport( + static IContainerFlagSupport newInstance( @NonNull InlineFieldDefinitionType xmlField, @NonNull IFieldDefinition container) { - this( - xmlField.getFlagList().size() > 0 || xmlField.getDefineFlagList().size() > 0 - ? parseLocalFlags(xmlField, container) - : CollectionUtil.emptyMap(), - xmlField.isSetJsonKey() - ? container.getContainingModule().toFlagQName(xmlField.getJsonKey().getFlagRef()) - : null); + if (!xmlField.getFlagList().isEmpty() || !xmlField.getDefineFlagList().isEmpty()) { + IFlagContainerBuilder builder = xmlField.isSetJsonKey() + ? IContainerFlagSupport.builder(container.getContainingModule().toFlagQName( + ObjectUtils.requireNonNull(xmlField.getJsonKey().getFlagRef()))) + : IContainerFlagSupport.builder(); + parseLocalFlags(xmlField, container, builder); + return builder.build(); + } + return IContainerFlagSupport.empty(); } /** - * Generate a set of constraints from the provided XMLBeans instance. + * Generate a flag container from the provided XMLBeans instance. * * @param xmlField * the XMLBeans instance * @param container * the field containing the flag */ - public XmlFlagContainerSupport( + static IContainerFlagSupport newInstance( @NonNull GroupedInlineFieldDefinitionType xmlField, - @NonNull IFieldDefinition container) { - this( - xmlField.getFlagList().size() > 0 || xmlField.getDefineFlagList().size() > 0 - ? parseLocalFlags(xmlField, container) - : CollectionUtil.emptyMap(), - null); + @NonNull IFieldDefinition container, + @Nullable String jsonKeyName) { + if (!xmlField.getFlagList().isEmpty() || !xmlField.getDefineFlagList().isEmpty()) { + IFlagContainerBuilder builder = jsonKeyName == null + ? IContainerFlagSupport.builder() + : IContainerFlagSupport.builder(container.getContainingModule().toFlagQName(jsonKeyName)); + parseLocalFlags(xmlField, container, builder); + return builder.build(); + } + return IContainerFlagSupport.empty(); } /** - * Generate a set of constraints from the provided XMLBeans instance. + * Generate a flag container from the provided XMLBeans instance. * - * @param xmlAssembly + * @param xmlField * the XMLBeans instance * @param container - * the assembly containing the flag + * the field containing the flag */ - public XmlFlagContainerSupport( + static IContainerFlagSupport newInstance( @NonNull GlobalAssemblyDefinitionType xmlAssembly, @NonNull IAssemblyDefinition container) { - this( - xmlAssembly.getFlagList().size() > 0 || xmlAssembly.getDefineFlagList().size() > 0 - ? parseLocalFlags(xmlAssembly, container) - : CollectionUtil.emptyMap(), - xmlAssembly.isSetJsonKey() - ? container.getContainingModule().toFlagQName(xmlAssembly.getJsonKey().getFlagRef()) - : null); + if (!xmlAssembly.getFlagList().isEmpty() || !xmlAssembly.getDefineFlagList().isEmpty()) { + IFlagContainerBuilder builder = xmlAssembly.isSetJsonKey() + ? IContainerFlagSupport.builder(container.getContainingModule().toFlagQName( + ObjectUtils.requireNonNull(xmlAssembly.getJsonKey().getFlagRef()))) + : IContainerFlagSupport.builder(); + parseLocalFlags(xmlAssembly, container, builder); + return builder.build(); + } + return IContainerFlagSupport.empty(); } /** - * Generate a set of constraints from the provided XMLBeans instance. + * Generate a flag container from the provided XMLBeans instance. * - * @param xmlAssembly + * @param xmlField * the XMLBeans instance * @param container - * the assembly containing the flag + * the field containing the flag */ - public XmlFlagContainerSupport( + static IContainerFlagSupport newInstance( @NonNull InlineAssemblyDefinitionType xmlAssembly, @NonNull IAssemblyDefinition container) { - this( - xmlAssembly.getFlagList().size() > 0 || xmlAssembly.getDefineFlagList().size() > 0 - ? parseLocalFlags(xmlAssembly, container) - : CollectionUtil.emptyMap(), - xmlAssembly.isSetJsonKey() - ? container.getContainingModule().toFlagQName(xmlAssembly.getJsonKey().getFlagRef()) - : null); + if (!xmlAssembly.getFlagList().isEmpty() || !xmlAssembly.getDefineFlagList().isEmpty()) { + IFlagContainerBuilder builder = xmlAssembly.isSetJsonKey() + ? IContainerFlagSupport.builder(container.getContainingModule().toFlagQName( + ObjectUtils.requireNonNull(xmlAssembly.getJsonKey().getFlagRef()))) + : IContainerFlagSupport.builder(); + parseLocalFlags(xmlAssembly, container, builder); + return builder.build(); + } + return IContainerFlagSupport.empty(); } /** - * Generate a set of constraints from the provided XMLBeans instance. + * Generate a flag container from the provided XMLBeans instance. * - * @param xmlAssembly + * @param xmlField * the XMLBeans instance * @param container - * the assembly containing the flag + * the field containing the flag */ - public XmlFlagContainerSupport( + static IContainerFlagSupport newInstance( @NonNull GroupedInlineAssemblyDefinitionType xmlAssembly, - @NonNull IAssemblyDefinition container) { - this( - xmlAssembly.getFlagList().size() > 0 || xmlAssembly.getDefineFlagList().size() > 0 - ? parseLocalFlags(xmlAssembly, container) - : CollectionUtil.emptyMap(), - null); + @NonNull IAssemblyDefinition container, + @Nullable String jsonKeyName) { + if (!xmlAssembly.getFlagList().isEmpty() || !xmlAssembly.getDefineFlagList().isEmpty()) { + IFlagContainerBuilder builder = jsonKeyName == null + ? IContainerFlagSupport.builder() + : IContainerFlagSupport.builder(container.getContainingModule().toFlagQName(jsonKeyName)); + parseLocalFlags(xmlAssembly, container, builder); + return builder.build(); + } + return IContainerFlagSupport.empty(); } - @NonNull - private static Map parseLocalFlags( + private static void parseLocalFlags( @NonNull XmlObject xmlObject, - @NonNull IModelDefinition parent) { + @NonNull IModelDefinition parent, + @NonNull IFlagContainerBuilder builder) { // handle flags - Map flagInstances = new LinkedHashMap<>(); // NOPMD - intentional - - XML_MODEL_PARSER.parse(xmlObject, Pair.of(parent, flagInstances)); + XML_MODEL_PARSER.parse(xmlObject, Pair.of(parent, builder)); + } - return flagInstances.isEmpty() ? CollectionUtil.emptyMap() : CollectionUtil.unmodifiableMap(flagInstances); + private XmlFlagContainerSupport() { + // disable construction } } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlFlagInstance.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlFlagInstance.java index ad8ba9511..895c3fe29 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlFlagInstance.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlFlagInstance.java @@ -28,9 +28,8 @@ 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.AbstractInstance; +import gov.nist.secauto.metaschema.core.model.AbstractFlagInstance; import gov.nist.secauto.metaschema.core.model.IAttributable; -import gov.nist.secauto.metaschema.core.model.IFeatureDefinitionReferenceInstance; import gov.nist.secauto.metaschema.core.model.IFlagDefinition; import gov.nist.secauto.metaschema.core.model.IFlagInstance; import gov.nist.secauto.metaschema.core.model.IModelDefinition; @@ -46,9 +45,7 @@ import edu.umd.cs.findbugs.annotations.Nullable; class XmlFlagInstance - extends AbstractInstance - implements IFlagInstance, - IFeatureDefinitionReferenceInstance { + extends AbstractFlagInstance { @NonNull private final FlagReferenceType xmlFlag; @Nullable @@ -63,6 +60,7 @@ class XmlFlagInstance * @param parent * the field definition this object is an instance of */ + @SuppressWarnings("PMD.ConstructorCallsOverridableMethod") public XmlFlagInstance(@NonNull FlagReferenceType xmlObject, @NonNull IModelDefinition parent) { super(parent); this.xmlFlag = xmlObject; @@ -71,6 +69,10 @@ public XmlFlagInstance(@NonNull FlagReferenceType xmlObject, @NonNull IModelDefi : null; // NOPMD needed for final variable } + // ---------------------------------------- + // - Start XmlBeans driven code - CPD-OFF - + // ---------------------------------------- + /** * Get the underlying XML data. * @@ -80,22 +82,6 @@ protected final FlagReferenceType getXmlObject() { return xmlFlag; } - @Override - public final IFlagDefinition getDefinition() { - // this should always be not null - return ObjectUtils.requireNonNull( - getContainingDefinition().getContainingModule().getScopedFlagDefinitionByName(getName())); - } - - @Override - public final IModelDefinition getContainingDefinition() { - return getParentContainer(); - } - - // ---------------------------------------- - // - Start XmlBeans driven code - CPD-OFF - - // ---------------------------------------- - @Override public String getFormalName() { return getXmlObject().isSetFormalName() ? getXmlObject().getFormalName() : null; diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGlobalAssemblyDefinition.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGlobalAssemblyDefinition.java index 4e0aa165a..8959d04f3 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGlobalAssemblyDefinition.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGlobalAssemblyDefinition.java @@ -28,15 +28,15 @@ 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.IAssemblyDefinition; +import gov.nist.secauto.metaschema.core.model.AbstractGlobalAssemblyDefinition; +import gov.nist.secauto.metaschema.core.model.IAssemblyInstance; import gov.nist.secauto.metaschema.core.model.IAssemblyInstanceAbsolute; import gov.nist.secauto.metaschema.core.model.IAttributable; import gov.nist.secauto.metaschema.core.model.IChoiceGroupInstance; import gov.nist.secauto.metaschema.core.model.IChoiceInstance; +import gov.nist.secauto.metaschema.core.model.IContainerFlagSupport; import gov.nist.secauto.metaschema.core.model.IContainerModelAssemblySupport; import gov.nist.secauto.metaschema.core.model.IDefinition; -import gov.nist.secauto.metaschema.core.model.IFeatureContainerFlag; -import gov.nist.secauto.metaschema.core.model.IFeatureContainerModelAssembly; import gov.nist.secauto.metaschema.core.model.IFieldInstanceAbsolute; import gov.nist.secauto.metaschema.core.model.IFlagInstance; import gov.nist.secauto.metaschema.core.model.IModelInstanceAbsolute; @@ -58,22 +58,21 @@ @SuppressWarnings("PMD.CouplingBetweenObjects") class XmlGlobalAssemblyDefinition - implements IAssemblyDefinition, - IFeatureContainerModelAssembly< + extends AbstractGlobalAssemblyDefinition< + XmlModule, + IAssemblyInstance, + IFlagInstance, IModelInstanceAbsolute, INamedModelInstanceAbsolute, IFieldInstanceAbsolute, IAssemblyInstanceAbsolute, IChoiceInstance, - IChoiceGroupInstance>, - IFeatureContainerFlag { + IChoiceGroupInstance> { @NonNull private final GlobalAssemblyDefinitionType xmlAssembly; @NonNull - private final XmlModule metaschema; - @NonNull - private final Lazy flagContainer; + private final Lazy> flagContainer; @NonNull private final Lazy new XmlFlagContainerSupport(xmlObject, this))); + this.flagContainer = ObjectUtils.notNull(Lazy.lazy(() -> XmlFlagContainerSupport.newInstance(xmlObject, this))); this.modelContainer = ObjectUtils.notNull( Lazy.lazy(() -> XmlAssemblyModelContainer.of(xmlObject.getModel(), this))); this.constraints = ObjectUtils.notNull(Lazy.lazy(() -> { @@ -113,7 +112,7 @@ public XmlGlobalAssemblyDefinition( } @Override - public XmlFlagContainerSupport getFlagContainer() { + public IContainerFlagSupport getFlagContainer() { return ObjectUtils.notNull(flagContainer.get()); } @@ -133,16 +132,6 @@ public IModelConstrained getConstraintSupport() { return ObjectUtils.notNull(constraints.get()); } - @Override - public XmlModule getContainingModule() { - return metaschema; - } - - @Override - public IFlagInstance getJsonKeyFlagInstance() { - return getFlagContainer().getJsonKeyFlagInstance(); - } - // ---------------------------------------- // - Start XmlBeans driven code - CPD-OFF - // ---------------------------------------- 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 2e5df30d5..299b0d86d 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 @@ -30,10 +30,11 @@ 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.AbstractGlobalFieldDefinition; import gov.nist.secauto.metaschema.core.model.IAttributable; +import gov.nist.secauto.metaschema.core.model.IContainerFlagSupport; import gov.nist.secauto.metaschema.core.model.IDefinition; -import gov.nist.secauto.metaschema.core.model.IFeatureContainerFlag; -import gov.nist.secauto.metaschema.core.model.IFieldDefinition; +import gov.nist.secauto.metaschema.core.model.IFieldInstance; import gov.nist.secauto.metaschema.core.model.IFlagInstance; import gov.nist.secauto.metaschema.core.model.ModuleScopeEnum; import gov.nist.secauto.metaschema.core.model.constraint.ISource; @@ -55,16 +56,13 @@ @SuppressWarnings({ "PMD.GodClass", "PMD.CouplingBetweenObjects" }) class XmlGlobalFieldDefinition - implements IFieldDefinition, - IFeatureContainerFlag { + extends AbstractGlobalFieldDefinition { @NonNull private final GlobalFieldDefinitionType xmlObject; - @NonNull - private final XmlModule module; @Nullable private final Object defaultValue; @NonNull - private final Lazy flagContainer; + private final Lazy> flagContainer; @NonNull private final Lazy constraints; @@ -78,14 +76,14 @@ class XmlGlobalFieldDefinition * the containing Metaschema module */ public XmlGlobalFieldDefinition(@NonNull GlobalFieldDefinitionType xmlObject, @NonNull XmlModule module) { + super(module); this.xmlObject = xmlObject; - this.module = module; Object defaultValue = null; if (xmlObject.isSetDefault()) { defaultValue = getJavaTypeAdapter().parse(ObjectUtils.requireNonNull(xmlObject.getDefault())); } this.defaultValue = defaultValue; - this.flagContainer = ObjectUtils.notNull(Lazy.lazy(() -> new XmlFlagContainerSupport(xmlObject, this))); + this.flagContainer = ObjectUtils.notNull(Lazy.lazy(() -> XmlFlagContainerSupport.newInstance(xmlObject, this))); this.constraints = ObjectUtils.notNull(Lazy.lazy(() -> { IValueConstrained retval = new ValueConstraintSet(); if (getXmlObject().isSetConstraint()) { @@ -103,7 +101,7 @@ public XmlGlobalFieldDefinition(@NonNull GlobalFieldDefinitionType xmlObject, @N */ @SuppressWarnings("null") @Override - public XmlFlagContainerSupport getFlagContainer() { + public IContainerFlagSupport getFlagContainer() { return flagContainer.get(); } @@ -119,21 +117,11 @@ public IValueConstrained getConstraintSupport() { return constraints.get(); } - @Override - public XmlModule getContainingModule() { - return module; - } - @Override public Object getDefaultValue() { return defaultValue; } - @Override - public IFlagInstance getJsonKeyFlagInstance() { - return getFlagContainer().getJsonKeyFlagInstance(); - } - // ---------------------------------------- // - Start XmlBeans driven code - CPD-OFF - // ---------------------------------------- diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGlobalFlagDefinition.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGlobalFlagDefinition.java index a3b5555c2..a9e14eda2 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGlobalFlagDefinition.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGlobalFlagDefinition.java @@ -30,9 +30,10 @@ 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.AbstractGlobalFlagDefinition; import gov.nist.secauto.metaschema.core.model.IAttributable; import gov.nist.secauto.metaschema.core.model.IDefinition; -import gov.nist.secauto.metaschema.core.model.IFlagDefinition; +import gov.nist.secauto.metaschema.core.model.IFlagInstance; import gov.nist.secauto.metaschema.core.model.ModuleScopeEnum; import gov.nist.secauto.metaschema.core.model.constraint.ISource; import gov.nist.secauto.metaschema.core.model.constraint.IValueConstrained; @@ -49,11 +50,10 @@ import edu.umd.cs.findbugs.annotations.Nullable; import nl.talsmasoftware.lazy4j.Lazy; -class XmlGlobalFlagDefinition implements IFlagDefinition { +class XmlGlobalFlagDefinition + extends AbstractGlobalFlagDefinition { @NonNull private final GlobalFlagDefinitionType xmlFlag; - @NonNull - private final XmlModule module; @Nullable private final Object defaultValue; private final Lazy constraints; @@ -70,9 +70,8 @@ class XmlGlobalFlagDefinition implements IFlagDefinition { public XmlGlobalFlagDefinition( @NonNull GlobalFlagDefinitionType xmlFlag, @NonNull XmlModule module) { + super(module); this.xmlFlag = xmlFlag; - this.module = module; - Object defaultValue = null; if (xmlFlag.isSetDefault()) { defaultValue = getJavaTypeAdapter().parse(ObjectUtils.requireNonNull(xmlFlag.getDefault())); @@ -100,11 +99,6 @@ public IValueConstrained getConstraintSupport() { return constraints.get(); } - @Override - public XmlModule getContainingModule() { - return module; - } - @Override public Object getDefaultValue() { return defaultValue; diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGroupedAssemblyInstance.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGroupedAssemblyInstance.java index c40234c3a..9894df806 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGroupedAssemblyInstance.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGroupedAssemblyInstance.java @@ -28,12 +28,11 @@ 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.AbstractNamedModelInstanceGrouped; +import gov.nist.secauto.metaschema.core.model.AbstractAssemblyInstance; import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition; import gov.nist.secauto.metaschema.core.model.IAssemblyInstanceGrouped; import gov.nist.secauto.metaschema.core.model.IAttributable; import gov.nist.secauto.metaschema.core.model.IChoiceGroupInstance; -import gov.nist.secauto.metaschema.core.model.IFeatureDefinitionReferenceInstance; import gov.nist.secauto.metaschema.core.model.xml.xmlbeans.GroupedAssemblyReferenceType; import gov.nist.secauto.metaschema.core.model.xml.xmlbeans.UseNameType; import gov.nist.secauto.metaschema.core.util.CollectionUtil; @@ -45,9 +44,12 @@ import edu.umd.cs.findbugs.annotations.NonNull; public class XmlGroupedAssemblyInstance - extends AbstractNamedModelInstanceGrouped - implements IAssemblyInstanceGrouped, - IFeatureDefinitionReferenceInstance { + extends AbstractAssemblyInstance< + IChoiceGroupInstance, + IAssemblyDefinition, + IAssemblyInstanceGrouped, + IAssemblyDefinition> + implements IAssemblyInstanceGrouped { @NonNull private final GroupedAssemblyReferenceType xmlObject; @@ -72,16 +74,11 @@ public XmlGroupedAssemblyInstance( * * @return the underlying XML data */ + @NonNull protected GroupedAssemblyReferenceType getXmlObject() { return xmlObject; } - @Override - public IAssemblyDefinition getDefinition() { - // this will always be not null - return ObjectUtils.notNull(getContainingModule().getScopedAssemblyDefinitionByName(getName())); - } - // ---------------------------------------- // - Start XmlBeans driven code - CPD-OFF - // ---------------------------------------- diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGroupedFieldInstance.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGroupedFieldInstance.java index 32471a5ea..d73189fb3 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGroupedFieldInstance.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGroupedFieldInstance.java @@ -28,10 +28,10 @@ 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.AbstractNamedModelInstanceGrouped; +import gov.nist.secauto.metaschema.core.model.AbstractFieldInstance; +import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition; import gov.nist.secauto.metaschema.core.model.IAttributable; import gov.nist.secauto.metaschema.core.model.IChoiceGroupInstance; -import gov.nist.secauto.metaschema.core.model.IFeatureDefinitionReferenceInstance; import gov.nist.secauto.metaschema.core.model.IFieldDefinition; import gov.nist.secauto.metaschema.core.model.IFieldInstanceGrouped; import gov.nist.secauto.metaschema.core.model.xml.xmlbeans.GroupedFieldReferenceType; @@ -45,9 +45,8 @@ import edu.umd.cs.findbugs.annotations.NonNull; public class XmlGroupedFieldInstance - extends AbstractNamedModelInstanceGrouped - implements IFieldInstanceGrouped, - IFeatureDefinitionReferenceInstance { + extends AbstractFieldInstance + implements IFieldInstanceGrouped { @NonNull private final GroupedFieldReferenceType xmlObject; @@ -68,12 +67,6 @@ public XmlGroupedFieldInstance( this.xmlObject = xmlObject; } - @Override - public IFieldDefinition getDefinition() { - // this will always be not null - return ObjectUtils.notNull(getContainingModule().getScopedFieldDefinitionByName(getName())); - } - // ---------------------------------------- // - Start XmlBeans driven code - CPD-OFF - // ---------------------------------------- @@ -83,6 +76,7 @@ public IFieldDefinition getDefinition() { * * @return the underlying XML data */ + @NonNull protected GroupedFieldReferenceType getXmlObject() { return xmlObject; } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGroupedInlineAssemblyDefinition.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGroupedInlineAssemblyDefinition.java index e0241ef54..43a25750c 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGroupedInlineAssemblyDefinition.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlGroupedInlineAssemblyDefinition.java @@ -28,17 +28,15 @@ 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.AbstractNamedModelInstanceGrouped; +import gov.nist.secauto.metaschema.core.model.AbstractInlineAssemblyDefinition; import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition; import gov.nist.secauto.metaschema.core.model.IAssemblyInstanceAbsolute; import gov.nist.secauto.metaschema.core.model.IAssemblyInstanceGrouped; import gov.nist.secauto.metaschema.core.model.IAttributable; import gov.nist.secauto.metaschema.core.model.IChoiceGroupInstance; import gov.nist.secauto.metaschema.core.model.IChoiceInstance; +import gov.nist.secauto.metaschema.core.model.IContainerFlagSupport; import gov.nist.secauto.metaschema.core.model.IContainerModelAssemblySupport; -import gov.nist.secauto.metaschema.core.model.IFeatureContainerFlag; -import gov.nist.secauto.metaschema.core.model.IFeatureContainerModelAssembly; -import gov.nist.secauto.metaschema.core.model.IFeatureDefinitionInstanceInlined; import gov.nist.secauto.metaschema.core.model.IFieldInstanceAbsolute; import gov.nist.secauto.metaschema.core.model.IFlagInstance; import gov.nist.secauto.metaschema.core.model.IModelInstanceAbsolute; @@ -57,22 +55,28 @@ import nl.talsmasoftware.lazy4j.Lazy; public class XmlGroupedInlineAssemblyDefinition - extends AbstractNamedModelInstanceGrouped - implements IAssemblyInstanceGrouped, IAssemblyDefinition, - IFeatureContainerModelAssembly< + extends AbstractInlineAssemblyDefinition< + IChoiceGroupInstance, + IAssemblyDefinition, + IAssemblyInstanceGrouped, + IAssemblyDefinition, + IFlagInstance, IModelInstanceAbsolute, INamedModelInstanceAbsolute, IFieldInstanceAbsolute, IAssemblyInstanceAbsolute, IChoiceInstance, - IChoiceGroupInstance>, - IFeatureContainerFlag, - IFeatureDefinitionInstanceInlined { + IChoiceGroupInstance> + implements IAssemblyInstanceGrouped { + + // ---------------------------------------- + // - Start XmlBeans driven code - CPD-OFF - + // ---------------------------------------- @NonNull private final GroupedInlineAssemblyDefinitionType xmlObject; @NonNull - private final Lazy flagContainer; + private final Lazy> flagContainer; @NonNull private final Lazy new XmlFlagContainerSupport(xmlObject, this))); + this.flagContainer = ObjectUtils.notNull(Lazy.lazy(() -> XmlFlagContainerSupport.newInstance( + xmlObject, + this, + parent.getJsonKeyFlagInstanceName()))); this.modelContainer = ObjectUtils.notNull( Lazy.lazy(() -> XmlAssemblyModelContainer.of(xmlObject.getModel(), this))); this.constraints = ObjectUtils.notNull(Lazy.lazy(() -> { @@ -113,17 +120,7 @@ public XmlGroupedInlineAssemblyDefinition( } @Override - public IAssemblyDefinition getDefinition() { - return this; - } - - @Override - public IAssemblyInstanceGrouped getInlineInstance() { - return this; - } - - @Override - public XmlFlagContainerSupport getFlagContainer() { + public IContainerFlagSupport getFlagContainer() { return ObjectUtils.notNull(flagContainer.get()); } @@ -144,15 +141,6 @@ public IModelConstrained getConstraintSupport() { return ObjectUtils.notNull(constraints.get()); } - @Override - public IFlagInstance getJsonKeyFlagInstance() { - return getFlagContainer().getJsonKeyFlagInstance(); - } - - // ---------------------------------------- - // - Start XmlBeans driven code - CPD-OFF - - // ---------------------------------------- - /** * Get the underlying XML model. * 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 99ed78671..739e2d619 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 @@ -30,11 +30,11 @@ 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.AbstractNamedModelInstanceGrouped; +import gov.nist.secauto.metaschema.core.model.AbstractInlineFieldDefinition; +import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition; import gov.nist.secauto.metaschema.core.model.IAttributable; import gov.nist.secauto.metaschema.core.model.IChoiceGroupInstance; -import gov.nist.secauto.metaschema.core.model.IFeatureContainerFlag; -import gov.nist.secauto.metaschema.core.model.IFeatureDefinitionInstanceInlined; +import gov.nist.secauto.metaschema.core.model.IContainerFlagSupport; import gov.nist.secauto.metaschema.core.model.IFieldDefinition; import gov.nist.secauto.metaschema.core.model.IFieldInstanceGrouped; import gov.nist.secauto.metaschema.core.model.IFlagInstance; @@ -54,15 +54,18 @@ import nl.talsmasoftware.lazy4j.Lazy; public class XmlGroupedInlineFieldDefinition - extends AbstractNamedModelInstanceGrouped - implements IFieldInstanceGrouped, IFieldDefinition, - IFeatureDefinitionInstanceInlined, - IFeatureContainerFlag { + extends AbstractInlineFieldDefinition< + IChoiceGroupInstance, + IFieldDefinition, + IFieldInstanceGrouped, + IAssemblyDefinition, + IFlagInstance> + implements IFieldInstanceGrouped { @NonNull private final GroupedInlineFieldDefinitionType xmlObject; @NonNull - private final Lazy flagContainer; + private final Lazy> flagContainer; @NonNull private final Lazy constraints; @@ -81,7 +84,10 @@ public XmlGroupedInlineFieldDefinition( @NonNull IChoiceGroupInstance parent) { super(parent); this.xmlObject = xmlObject; - this.flagContainer = ObjectUtils.notNull(Lazy.lazy(() -> new XmlFlagContainerSupport(xmlObject, this))); + this.flagContainer = ObjectUtils.notNull(Lazy.lazy(() -> XmlFlagContainerSupport.newInstance( + xmlObject, + this, + parent.getJsonKeyFlagInstanceName()))); this.constraints = ObjectUtils.notNull(Lazy.lazy(() -> { IValueConstrained retval = new ValueConstraintSet(); if (getXmlObject().isSetConstraint()) { @@ -93,17 +99,7 @@ public XmlGroupedInlineFieldDefinition( } @Override - public IFieldDefinition getDefinition() { - return this; - } - - @Override - public XmlGroupedInlineFieldDefinition getInlineInstance() { - return this; - } - - @Override - public XmlFlagContainerSupport getFlagContainer() { + public IContainerFlagSupport getFlagContainer() { return ObjectUtils.notNull(flagContainer.get()); } @@ -112,10 +108,6 @@ public IValueConstrained getConstraintSupport() { return ObjectUtils.notNull(constraints.get()); } - @Override - public IFlagInstance getJsonKeyFlagInstance() { - return getFlagContainer().getJsonKeyFlagInstance(); - } // ---------------------------------------- // - Start XmlBeans driven code - CPD-OFF - // ---------------------------------------- diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlInlineAssemblyDefinition.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlInlineAssemblyDefinition.java index c7ea0532d..af3d1fd92 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlInlineAssemblyDefinition.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlInlineAssemblyDefinition.java @@ -28,17 +28,15 @@ 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.AbstractInstance; +import gov.nist.secauto.metaschema.core.model.AbstractInlineAssemblyDefinition; import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition; import gov.nist.secauto.metaschema.core.model.IAssemblyInstanceAbsolute; import gov.nist.secauto.metaschema.core.model.IAttributable; import gov.nist.secauto.metaschema.core.model.IChoiceGroupInstance; import gov.nist.secauto.metaschema.core.model.IChoiceInstance; +import gov.nist.secauto.metaschema.core.model.IContainerFlagSupport; import gov.nist.secauto.metaschema.core.model.IContainerModel; import gov.nist.secauto.metaschema.core.model.IContainerModelAssemblySupport; -import gov.nist.secauto.metaschema.core.model.IFeatureContainerFlag; -import gov.nist.secauto.metaschema.core.model.IFeatureContainerModelAssembly; -import gov.nist.secauto.metaschema.core.model.IFeatureDefinitionInstanceInlined; import gov.nist.secauto.metaschema.core.model.IFieldInstanceAbsolute; import gov.nist.secauto.metaschema.core.model.IFlagInstance; import gov.nist.secauto.metaschema.core.model.IModelInstanceAbsolute; @@ -62,21 +60,28 @@ * Represents a Metaschema assembly definition declared locally as an instance. */ class XmlInlineAssemblyDefinition - extends AbstractInstance - implements IAssemblyInstanceAbsolute, IAssemblyDefinition, - IFeatureContainerModelAssembly< + extends AbstractInlineAssemblyDefinition< + IContainerModel, + IAssemblyDefinition, + IAssemblyInstanceAbsolute, + IAssemblyDefinition, + IFlagInstance, IModelInstanceAbsolute, INamedModelInstanceAbsolute, IFieldInstanceAbsolute, IAssemblyInstanceAbsolute, IChoiceInstance, - IChoiceGroupInstance>, - IFeatureContainerFlag, - IFeatureDefinitionInstanceInlined { + IChoiceGroupInstance> + implements IAssemblyInstanceAbsolute { + + // ---------------------------------------- + // - Start XmlBeans driven code - CPD-OFF - + // ---------------------------------------- + @NonNull private final InlineAssemblyDefinitionType xmlObject; @NonNull - private final Lazy flagContainer; + private final Lazy> flagContainer; @NonNull private final Lazy new XmlFlagContainerSupport(xmlObject, this))); + this.flagContainer = ObjectUtils.notNull(Lazy.lazy(() -> XmlFlagContainerSupport.newInstance(xmlObject, this))); this.modelContainer = ObjectUtils.notNull(Lazy.lazy(() -> XmlAssemblyModelContainer.of(xmlObject.getModel(), this))); this.constraints = ObjectUtils.notNull(Lazy.lazy(() -> { @@ -115,20 +120,9 @@ public XmlInlineAssemblyDefinition( })); } - @Override - public IAssemblyDefinition getDefinition() { - return this; - } - - @Override - @NonNull - public IAssemblyInstanceAbsolute getInlineInstance() { - return this; - } - @SuppressWarnings("null") @Override - public XmlFlagContainerSupport getFlagContainer() { + public IContainerFlagSupport getFlagContainer() { return flagContainer.get(); } @@ -150,15 +144,6 @@ public IModelConstrained getConstraintSupport() { return constraints.get(); } - @Override - public IFlagInstance getJsonKeyFlagInstance() { - return getFlagContainer().getJsonKeyFlagInstance(); - } - - // ---------------------------------------- - // - Start XmlBeans driven code - CPD-OFF - - // ---------------------------------------- - /** * Get the underlying XML model. * 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 2cf746f64..a2029c40a 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 @@ -30,11 +30,11 @@ 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.AbstractInstance; +import gov.nist.secauto.metaschema.core.model.AbstractInlineFieldDefinition; +import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition; import gov.nist.secauto.metaschema.core.model.IAttributable; +import gov.nist.secauto.metaschema.core.model.IContainerFlagSupport; import gov.nist.secauto.metaschema.core.model.IContainerModel; -import gov.nist.secauto.metaschema.core.model.IFeatureContainerFlag; -import gov.nist.secauto.metaschema.core.model.IFeatureDefinitionInstanceInlined; import gov.nist.secauto.metaschema.core.model.IFieldDefinition; import gov.nist.secauto.metaschema.core.model.IFieldInstanceAbsolute; import gov.nist.secauto.metaschema.core.model.IFlagInstance; @@ -57,16 +57,19 @@ import nl.talsmasoftware.lazy4j.Lazy; class XmlInlineFieldDefinition - extends AbstractInstance - implements IFieldInstanceAbsolute, IFieldDefinition, - IFeatureContainerFlag, - IFeatureDefinitionInstanceInlined { + extends AbstractInlineFieldDefinition< + IContainerModel, + IFieldDefinition, + IFieldInstanceAbsolute, + IAssemblyDefinition, + IFlagInstance> + implements IFieldInstanceAbsolute { @NonNull private final InlineFieldDefinitionType xmlObject; @Nullable private final Object defaultValue; @NonNull - private final Lazy flagContainer; + private final Lazy> flagContainer; @NonNull private final Lazy constraints; @@ -88,7 +91,7 @@ public XmlInlineFieldDefinition( this.defaultValue = xmlObject.isSetDefault() ? getJavaTypeAdapter().parse(ObjectUtils.requireNonNull(xmlObject.getDefault())) : null; - this.flagContainer = ObjectUtils.notNull(Lazy.lazy(() -> new XmlFlagContainerSupport(xmlObject, this))); + this.flagContainer = ObjectUtils.notNull(Lazy.lazy(() -> XmlFlagContainerSupport.newInstance(xmlObject, this))); this.constraints = ObjectUtils.notNull(Lazy.lazy(() -> { IValueConstrained retval = new ValueConstraintSet(); if (getXmlObject().isSetConstraint()) { @@ -113,28 +116,12 @@ protected final InlineFieldDefinitionType getXmlObject() { return xmlObject; } - @Override - public IFieldDefinition getDefinition() { - return this; - } - - @Override - @NonNull - public IFieldInstanceAbsolute getInlineInstance() { - return this; - } - @SuppressWarnings("null") @Override - public XmlFlagContainerSupport getFlagContainer() { + public IContainerFlagSupport getFlagContainer() { return flagContainer.get(); } - @Override - public IFlagInstance getJsonKeyFlagInstance() { - return getFlagContainer().getJsonKeyFlagInstance(); - } - /** * Used to generate the instances for the constraints in a lazy fashion when the * constraints are first accessed. @@ -244,6 +231,11 @@ public String getJsonValueKeyName() { return getXmlObject().getJsonValueKey(); } + // @Override + // public String getJsonKeyFlagInstanceName() { + // return IFeatureXmlContainerFlag.super.getJsonKeyFlagInstanceName(); + // } + // ------------------------------------- // - End XmlBeans driven code - CPD-ON - // ------------------------------------- diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlInlineFlagDefinition.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlInlineFlagDefinition.java index 00702587b..12a99b3de 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlInlineFlagDefinition.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlInlineFlagDefinition.java @@ -30,9 +30,8 @@ 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.AbstractInstance; +import gov.nist.secauto.metaschema.core.model.AbstractInlineFlagDefinition; import gov.nist.secauto.metaschema.core.model.IAttributable; -import gov.nist.secauto.metaschema.core.model.IFeatureDefinitionInstanceInlined; import gov.nist.secauto.metaschema.core.model.IFlagDefinition; import gov.nist.secauto.metaschema.core.model.IFlagInstance; import gov.nist.secauto.metaschema.core.model.IModelDefinition; @@ -51,9 +50,8 @@ import nl.talsmasoftware.lazy4j.Lazy; class XmlInlineFlagDefinition - extends AbstractInstance - implements IFlagInstance, IFlagDefinition, - IFeatureDefinitionInstanceInlined { + extends AbstractInlineFlagDefinition { + @NonNull private final InlineFlagDefinitionType xmlFlag; @Nullable @@ -88,17 +86,6 @@ public XmlInlineFlagDefinition(@NonNull InlineFlagDefinitionType xmlObject, @Non })); } - @Override - public IFlagDefinition getDefinition() { - return this; - } - - @Override - @NonNull - public IFlagInstance getInlineInstance() { - return this; - } - /** * Used to generate the instances for the constraints in a lazy fashion when the * constraints are first accessed. @@ -114,11 +101,6 @@ public Object getDefaultValue() { return defaultValue; } - @Override - public IModelDefinition getContainingDefinition() { - return getParentContainer(); - } - // ---------------------------------------- // - Start XmlBeans driven code - CPD-OFF - // ---------------------------------------- diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlModule.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlModule.java index f5e791e8b..7efcb9750 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlModule.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlModule.java @@ -32,9 +32,9 @@ import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition; import gov.nist.secauto.metaschema.core.model.IFieldDefinition; import gov.nist.secauto.metaschema.core.model.IFlagDefinition; +import gov.nist.secauto.metaschema.core.model.IMetaschemaModule; import gov.nist.secauto.metaschema.core.model.IModelDefinition; import gov.nist.secauto.metaschema.core.model.MetaschemaException; -import gov.nist.secauto.metaschema.core.model.xml.IXmlModule; import gov.nist.secauto.metaschema.core.model.xml.xmlbeans.GlobalAssemblyDefinitionType; import gov.nist.secauto.metaschema.core.model.xml.xmlbeans.GlobalFieldDefinitionType; import gov.nist.secauto.metaschema.core.model.xml.xmlbeans.GlobalFlagDefinitionType; @@ -56,27 +56,27 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import javax.xml.namespace.QName; + import edu.umd.cs.findbugs.annotations.NonNull; +import nl.talsmasoftware.lazy4j.Lazy; @SuppressWarnings("PMD.CouplingBetweenObjects") public class XmlModule extends AbstractModule< - IXmlModule, + IMetaschemaModule, IModelDefinition, IFlagDefinition, IFieldDefinition, IAssemblyDefinition> - implements IXmlModule { + implements IMetaschemaModule { private static final Logger LOGGER = LogManager.getLogger(XmlModule.class); @NonNull private final URI location; @NonNull private final METASCHEMADocument module; - private final Map flagDefinitions; - private final Map fieldDefinitions; - private final Map assemblyDefinitions; - private final Map rootAssemblyDefinitions; + private final Lazy definitions; /** * Constructs a new Metaschema instance. @@ -93,81 +93,13 @@ public class XmlModule public XmlModule( // NOPMD - unavoidable @NonNull URI resource, @NonNull METASCHEMADocument moduleXml, - @NonNull List importedModules) throws MetaschemaException { + @NonNull List importedModules) throws MetaschemaException { super(importedModules); this.location = ObjectUtils.requireNonNull(resource, "resource"); Objects.requireNonNull(moduleXml.getMETASCHEMA()); this.module = moduleXml; - METASCHEMA metaschemaNode = module.getMETASCHEMA(); - - // handle definitions in this module - // TODO: switch implementation to use the XmlObjectParser - { - // start with flag definitions - try (XmlCursor cursor = metaschemaNode.newCursor()) { - cursor.selectPath("declare namespace m='http://csrc.nist.gov/ns/oscal/metaschema/1.0';$this/m:define-flag"); - - Map flagDefinitions = new LinkedHashMap<>(); // NOPMD - intentional - while (cursor.toNextSelection()) { - GlobalFlagDefinitionType obj = ObjectUtils.notNull((GlobalFlagDefinitionType) cursor.getObject()); - XmlGlobalFlagDefinition flag = new XmlGlobalFlagDefinition(obj, this); // NOPMD - intentional - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("New flag definition '{}'", flag.toCoordinates()); - } - flagDefinitions.put(flag.getName(), flag); - } - this.flagDefinitions - = flagDefinitions.isEmpty() ? Collections.emptyMap() : Collections.unmodifiableMap(flagDefinitions); - } - } - - { - // now field definitions - try (XmlCursor cursor = metaschemaNode.newCursor()) { - cursor.selectPath("declare namespace m='http://csrc.nist.gov/ns/oscal/metaschema/1.0';$this/m:define-field"); - - Map fieldDefinitions = new LinkedHashMap<>(); // NOPMD - intentional - while (cursor.toNextSelection()) { - GlobalFieldDefinitionType obj = ObjectUtils.notNull((GlobalFieldDefinitionType) cursor.getObject()); - XmlGlobalFieldDefinition field = new XmlGlobalFieldDefinition(obj, this); // NOPMD - intentional - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("New field definition '{}'", field.toCoordinates()); - } - fieldDefinitions.put(field.getName(), field); - } - this.fieldDefinitions - = fieldDefinitions.isEmpty() ? Collections.emptyMap() : Collections.unmodifiableMap(fieldDefinitions); - } - } - - { - // finally assembly definitions - Map assemblyDefinitions = new LinkedHashMap<>(); // NOPMD - intentional - Map rootAssemblyDefinitions = new LinkedHashMap<>(); // NOPMD - intentional - - try (XmlCursor cursor = metaschemaNode.newCursor()) { - cursor.selectPath( - "declare namespace m='http://csrc.nist.gov/ns/oscal/metaschema/1.0';$this/m:define-assembly"); - - while (cursor.toNextSelection()) { - GlobalAssemblyDefinitionType obj = ObjectUtils.notNull((GlobalAssemblyDefinitionType) cursor.getObject()); - XmlGlobalAssemblyDefinition assembly = new XmlGlobalAssemblyDefinition(obj, this); // NOPMD - intentional - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("New assembly definition '{}'", assembly.toCoordinates()); - } - assemblyDefinitions.put(assembly.getName(), assembly); - if (assembly.isRoot()) { - rootAssemblyDefinitions.put(ObjectUtils.notNull(assembly.getRootName()), assembly); - } - } - - this.assemblyDefinitions - = assemblyDefinitions.isEmpty() ? Collections.emptyMap() : Collections.unmodifiableMap(assemblyDefinitions); - this.rootAssemblyDefinitions = rootAssemblyDefinitions.isEmpty() ? Collections.emptyMap() - : Collections.unmodifiableMap(rootAssemblyDefinitions); - } - } + this.definitions = Lazy.lazy(() -> new Definitions(ObjectUtils.requireNonNull(module.getMETASCHEMA()))); } @NonNull @@ -223,34 +155,31 @@ public URI getJsonBaseUri() { return URI.create(getXmlModule().getJsonBaseUri()); } - private Map getAssemblyDefinitionMap() { - return assemblyDefinitions; + @NonNull + private Definitions getDefinitions() { + return ObjectUtils.notNull(definitions.get()); } @SuppressWarnings("null") @Override public Collection getAssemblyDefinitions() { - return getAssemblyDefinitionMap().values(); + return getDefinitions().getAssemblyDefinitionMap().values(); } @Override - public IAssemblyDefinition getAssemblyDefinitionByName(@NonNull String name) { - return getAssemblyDefinitionMap().get(name); - } - - private Map getFieldDefinitionMap() { - return fieldDefinitions; + public IAssemblyDefinition getAssemblyDefinitionByName(@NonNull QName name) { + return getDefinitions().getAssemblyDefinitionMap().get(name); } @SuppressWarnings("null") @Override public Collection getFieldDefinitions() { - return getFieldDefinitionMap().values(); + return getDefinitions().getFieldDefinitionMap().values(); } @Override - public IFieldDefinition getFieldDefinitionByName(@NonNull String name) { - return getFieldDefinitionMap().get(name); + public IFieldDefinition getFieldDefinitionByName(@NonNull QName name) { + return getDefinitions().getFieldDefinitionMap().get(name); } @SuppressWarnings("null") @@ -260,28 +189,117 @@ public List getAssemblyAndFieldDefinitions() { .collect(Collectors.toList()); } - private Map getFlagDefinitionMap() { - return flagDefinitions; - } - @SuppressWarnings("null") @Override public Collection getFlagDefinitions() { - return getFlagDefinitionMap().values(); + return getDefinitions().getFlagDefinitionMap().values(); } @Override - public IFlagDefinition getFlagDefinitionByName(@NonNull String name) { - return getFlagDefinitionMap().get(name); - } - - private Map getRootAssemblyDefinitionMap() { - return rootAssemblyDefinitions; + public IFlagDefinition getFlagDefinitionByName(@NonNull QName name) { + return getDefinitions().getFlagDefinitionMap().get(name); } @SuppressWarnings("null") @Override public Collection getRootAssemblyDefinitions() { - return getRootAssemblyDefinitionMap().values(); + return getDefinitions().getRootAssemblyDefinitionMap().values(); + } + + private final class Definitions { + private final Map flagDefinitions; + private final Map fieldDefinitions; + private final Map assemblyDefinitions; + private final Map rootAssemblyDefinitions; + + @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") + private Definitions(@NonNull METASCHEMA metaschemaNode) { + + // handle definitions in this module + // TODO: switch implementation to use the XmlObjectParser + { + // start with flag definitions + try (XmlCursor cursor = metaschemaNode.newCursor()) { + cursor.selectPath("declare namespace m='http://csrc.nist.gov/ns/oscal/metaschema/1.0';$this/m:define-flag"); + + Map flagDefinitions = new LinkedHashMap<>(); // NOPMD - intentional + while (cursor.toNextSelection()) { + GlobalFlagDefinitionType obj = ObjectUtils.notNull((GlobalFlagDefinitionType) cursor.getObject()); + XmlGlobalFlagDefinition flag = new XmlGlobalFlagDefinition(obj, XmlModule.this); // NOPMD - intentional + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("New flag definition '{}'", flag.toCoordinates()); + } + flagDefinitions.put(flag.getDefinitionQName(), flag); + } + this.flagDefinitions + = flagDefinitions.isEmpty() ? Collections.emptyMap() : Collections.unmodifiableMap(flagDefinitions); + } + } + + { + // now field definitions + try (XmlCursor cursor = metaschemaNode.newCursor()) { + cursor.selectPath("declare namespace m='http://csrc.nist.gov/ns/oscal/metaschema/1.0';$this/m:define-field"); + + Map fieldDefinitions = new LinkedHashMap<>(); // NOPMD - intentional + while (cursor.toNextSelection()) { + GlobalFieldDefinitionType obj = ObjectUtils.notNull((GlobalFieldDefinitionType) cursor.getObject()); + XmlGlobalFieldDefinition field = new XmlGlobalFieldDefinition(obj, XmlModule.this); // NOPMD - intentional + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("New field definition '{}'", field.toCoordinates()); + } + fieldDefinitions.put(field.getDefinitionQName(), field); + } + this.fieldDefinitions + = fieldDefinitions.isEmpty() ? Collections.emptyMap() : Collections.unmodifiableMap(fieldDefinitions); + } + } + + { + // finally assembly definitions + Map assemblyDefinitions = new LinkedHashMap<>(); // NOPMD - intentional + Map rootAssemblyDefinitions = new LinkedHashMap<>(); // NOPMD - intentional + + try (XmlCursor cursor = metaschemaNode.newCursor()) { + cursor.selectPath( + "declare namespace m='http://csrc.nist.gov/ns/oscal/metaschema/1.0';$this/m:define-assembly"); + + while (cursor.toNextSelection()) { + GlobalAssemblyDefinitionType obj = ObjectUtils.notNull((GlobalAssemblyDefinitionType) cursor.getObject()); + XmlGlobalAssemblyDefinition assembly = new XmlGlobalAssemblyDefinition(obj, XmlModule.this); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("New assembly definition '{}'", assembly.toCoordinates()); + } + assemblyDefinitions.put(assembly.getDefinitionQName(), assembly); + if (assembly.isRoot()) { + rootAssemblyDefinitions.put(ObjectUtils.notNull(assembly.getRootXmlQName()), assembly); + } + } + + this.assemblyDefinitions + = assemblyDefinitions.isEmpty() ? Collections.emptyMap() + : Collections.unmodifiableMap(assemblyDefinitions); + this.rootAssemblyDefinitions = rootAssemblyDefinitions.isEmpty() ? Collections.emptyMap() + : Collections.unmodifiableMap(rootAssemblyDefinitions); + } + } + } + + public Map getFlagDefinitionMap() { + return flagDefinitions; + } + + public Map getFieldDefinitionMap() { + return fieldDefinitions; + } + + public Map getAssemblyDefinitionMap() { + return assemblyDefinitions; + } + + public Map getRootAssemblyDefinitionMap() { + return rootAssemblyDefinitions; + } + } } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlObjectParser.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlObjectParser.java index 6dc871b1d..878e179db 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlObjectParser.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlObjectParser.java @@ -55,7 +55,7 @@ private static String generatePath(@NonNull Collection nodes) { // build a mapping of namespace prefix to namespace AtomicInteger count = new AtomicInteger(); Map namespaceToPrefixMap = nodes.stream() - .map(qname -> qname.getNamespaceURI()) + .map(QName::getNamespaceURI) .distinct() .map(ns -> Pair.of(ns, "m" + count.getAndIncrement())) .collect(Collectors.toMap( diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlbeansMarkupVisitor.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlbeansMarkupVisitor.java index 010844bec..6ecac5ffe 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlbeansMarkupVisitor.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/impl/XmlbeansMarkupVisitor.java @@ -106,11 +106,11 @@ protected XmlbeansMarkupVisitor( @Override public void writeEmptyElement(QName qname, Map attributes) throws IllegalArgumentException { - @SuppressWarnings("resource") // not owned + @SuppressWarnings({ "resource", "PMD.CloseResource" }) // not owned XmlCursor cursor = getStream(); cursor.beginElement(qname); - attributes.forEach((name, value) -> cursor.insertAttributeWithValue(name, value)); + attributes.forEach(cursor::insertAttributeWithValue); // go to the end of the new element cursor.toEndToken(); @@ -122,11 +122,11 @@ public void writeEmptyElement(QName qname, Map attributes) @Override public void writeElementStart(QName qname, Map attributes) throws IllegalArgumentException { - @SuppressWarnings("resource") // not owned + @SuppressWarnings({ "resource", "PMD.CloseResource" }) // not owned XmlCursor cursor = getStream(); cursor.beginElement(qname); - attributes.forEach((name, value) -> cursor.insertAttributeWithValue(name, value)); + attributes.forEach(cursor::insertAttributeWithValue); // save the current location state cursor.push(); @@ -134,7 +134,7 @@ public void writeElementStart(QName qname, Map attributes) @Override public void writeElementEnd(QName qname) throws IllegalArgumentException { - @SuppressWarnings("resource") // not owned + @SuppressWarnings({ "resource", "PMD.CloseResource" }) // not owned XmlCursor cursor = getStream(); // restore location to end of start element @@ -149,14 +149,14 @@ public void writeElementEnd(QName qname) throws IllegalArgumentException { @Override public void writeText(CharSequence text) throws IllegalArgumentException { - @SuppressWarnings("resource") // not owned + @SuppressWarnings({ "resource", "PMD.CloseResource" }) // not owned XmlCursor cursor = getStream(); cursor.insertChars(text.toString()); } @Override protected void writeComment(CharSequence text) throws IllegalArgumentException { - @SuppressWarnings("resource") // not owned + @SuppressWarnings({ "resource", "PMD.CloseResource" }) // not owned XmlCursor cursor = getStream(); cursor.insertComment(text.toString()); } diff --git a/core/src/test/java/gov/nist/secauto/metaschema/core/metapath/cst/BuildCstVisitorTest.java b/core/src/test/java/gov/nist/secauto/metaschema/core/metapath/cst/BuildCstVisitorTest.java index 494fb5f0a..f1b8d1cde 100644 --- a/core/src/test/java/gov/nist/secauto/metaschema/core/metapath/cst/BuildCstVisitorTest.java +++ b/core/src/test/java/gov/nist/secauto/metaschema/core/metapath/cst/BuildCstVisitorTest.java @@ -112,7 +112,7 @@ private IDocumentNodeItem newTestDocument() { } @NonNull - private StaticContext newStaticContext() { + private static StaticContext newStaticContext() { return StaticContext.builder() .defaultModelNamespace(NS_URI) .build(); diff --git a/core/src/test/java/gov/nist/secauto/metaschema/core/metapath/cst/EQNameUtilsTest.java b/core/src/test/java/gov/nist/secauto/metaschema/core/metapath/cst/EQNameUtilsTest.java index 64678e516..357417b34 100644 --- a/core/src/test/java/gov/nist/secauto/metaschema/core/metapath/cst/EQNameUtilsTest.java +++ b/core/src/test/java/gov/nist/secauto/metaschema/core/metapath/cst/EQNameUtilsTest.java @@ -49,12 +49,6 @@ class EQNameUtilsTest { .defaultModelNamespace("http://example.com/ns/model") .build(); - private enum NameType { - FUNCTION, - FLAG, - MODEL; - } - static Stream provideValues() { return Stream.of( Arguments.of( diff --git a/core/src/test/java/gov/nist/secauto/metaschema/core/metapath/cst/PredicateTest.java b/core/src/test/java/gov/nist/secauto/metaschema/core/metapath/cst/PredicateExpressionTest.java similarity index 100% rename from core/src/test/java/gov/nist/secauto/metaschema/core/metapath/cst/PredicateTest.java rename to core/src/test/java/gov/nist/secauto/metaschema/core/metapath/cst/PredicateExpressionTest.java diff --git a/core/src/test/java/gov/nist/secauto/metaschema/core/model/xml/ExamplesTest.java b/core/src/test/java/gov/nist/secauto/metaschema/core/model/xml/ExamplesTest.java index 447aa30ad..dad9cc9dc 100644 --- a/core/src/test/java/gov/nist/secauto/metaschema/core/model/xml/ExamplesTest.java +++ b/core/src/test/java/gov/nist/secauto/metaschema/core/model/xml/ExamplesTest.java @@ -29,6 +29,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition; +import gov.nist.secauto.metaschema.core.model.IMetaschemaModule; import gov.nist.secauto.metaschema.core.model.MetaschemaException; import gov.nist.secauto.metaschema.core.util.ObjectUtils; @@ -37,6 +38,8 @@ import java.io.IOException; import java.net.URI; +import javax.xml.namespace.QName; + class ExamplesTest { @Test @@ -46,7 +49,7 @@ void testLoadMetaschema() throws MetaschemaException, IOException { URI moduleUri = ObjectUtils.notNull(URI.create( "https://raw.githubusercontent.com/usnistgov/OSCAL/v1.0.0/src/metaschema/oscal_complete_metaschema.xml")); - IXmlModule module = loader.load(moduleUri); + IMetaschemaModule module = loader.load(moduleUri); assertNotNull(module, "metaschema not found"); } @@ -56,9 +59,10 @@ void testExamineAssemblyDefinitionByName() throws MetaschemaException, IOExcepti loader.allowEntityResolution(); URI moduleUri = ObjectUtils.notNull(URI.create( "https://raw.githubusercontent.com/usnistgov/OSCAL/v1.0.0/src/metaschema/oscal_complete_metaschema.xml")); - IXmlModule module = loader.load(moduleUri); + IMetaschemaModule module = loader.load(moduleUri); - IAssemblyDefinition definition = module.getScopedAssemblyDefinitionByName("property"); + IAssemblyDefinition definition = module.getScopedAssemblyDefinitionByName( + new QName("http://csrc.nist.gov/ns/oscal/1.0", "property")); assertNotNull(definition, "definition not found"); } diff --git a/core/src/test/java/gov/nist/secauto/metaschema/core/model/xml/MetaConstraintLoaderTest.java b/core/src/test/java/gov/nist/secauto/metaschema/core/model/xml/MetaConstraintLoaderTest.java index 209399641..f16fc2a1d 100644 --- a/core/src/test/java/gov/nist/secauto/metaschema/core/model/xml/MetaConstraintLoaderTest.java +++ b/core/src/test/java/gov/nist/secauto/metaschema/core/model/xml/MetaConstraintLoaderTest.java @@ -36,6 +36,7 @@ import gov.nist.secauto.metaschema.core.metapath.item.node.IDefinitionNodeItem; import gov.nist.secauto.metaschema.core.metapath.item.node.IModuleNodeItem; import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItemFactory; +import gov.nist.secauto.metaschema.core.model.IMetaschemaModule; import gov.nist.secauto.metaschema.core.model.MetaschemaException; import gov.nist.secauto.metaschema.core.model.constraint.IConstraintSet; import gov.nist.secauto.metaschema.core.util.CollectionUtil; @@ -60,7 +61,7 @@ void test() throws MetaschemaException, IOException { ModuleLoader loader = new ModuleLoader(CollectionUtil.singletonList(postProcessor)); URI moduleUri = ObjectUtils.notNull( Paths.get("metaschema/examples/computer-example.xml").toUri()); - IXmlModule module = loader.load(moduleUri); + IMetaschemaModule module = loader.load(moduleUri); StaticContext staticContext = StaticContext.builder() .defaultModelNamespace(module.getXmlNamespace()) diff --git a/core/src/test/java/gov/nist/secauto/metaschema/core/model/xml/MetaschemaModuleTest.java b/core/src/test/java/gov/nist/secauto/metaschema/core/model/xml/MetaschemaModuleTest.java index cb2635089..0eb130b3b 100644 --- a/core/src/test/java/gov/nist/secauto/metaschema/core/model/xml/MetaschemaModuleTest.java +++ b/core/src/test/java/gov/nist/secauto/metaschema/core/model/xml/MetaschemaModuleTest.java @@ -28,6 +28,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; +import gov.nist.secauto.metaschema.core.model.IMetaschemaModule; import gov.nist.secauto.metaschema.core.model.MetaschemaException; import gov.nist.secauto.metaschema.core.util.ObjectUtils; @@ -44,7 +45,7 @@ void testFile() throws MetaschemaException, IOException { ModuleLoader loader = new ModuleLoader(); URI moduleUri = ObjectUtils.notNull( Paths.get("metaschema/schema/metaschema/metaschema-module-metaschema.xml").toUri()); - IXmlModule module = loader.load(moduleUri); + IMetaschemaModule module = loader.load(moduleUri); assertFalse(module.getExportedRootAssemblyDefinitions().isEmpty(), "no roots found"); } } diff --git a/core/src/test/java/gov/nist/secauto/metaschema/core/model/xml/ModuleLoaderTest.java b/core/src/test/java/gov/nist/secauto/metaschema/core/model/xml/ModuleLoaderTest.java index b39071c2c..0c1ea4c65 100644 --- a/core/src/test/java/gov/nist/secauto/metaschema/core/model/xml/ModuleLoaderTest.java +++ b/core/src/test/java/gov/nist/secauto/metaschema/core/model/xml/ModuleLoaderTest.java @@ -34,6 +34,7 @@ import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition; import gov.nist.secauto.metaschema.core.model.IConstraintLoader; import gov.nist.secauto.metaschema.core.model.IFlagDefinition; +import gov.nist.secauto.metaschema.core.model.IMetaschemaModule; import gov.nist.secauto.metaschema.core.model.MetaschemaException; import gov.nist.secauto.metaschema.core.model.constraint.IAllowedValuesConstraint; import gov.nist.secauto.metaschema.core.model.constraint.IConstraint; @@ -48,6 +49,8 @@ import java.nio.file.Paths; import java.util.List; +import javax.xml.namespace.QName; + class ModuleLoaderTest { @Test @@ -56,13 +59,14 @@ void testUrl() throws MetaschemaException, IOException { // NOPMD - intentional loader.allowEntityResolution(); URI moduleUri = ObjectUtils.notNull(URI.create( "https://raw.githubusercontent.com/usnistgov/OSCAL/v1.0.0/src/metaschema/oscal_complete_metaschema.xml")); - IXmlModule module = loader.load(moduleUri); + IMetaschemaModule module = loader.load(moduleUri); - IXmlModule oscalCatalogModule = module.getImportedModuleByShortName("oscal-catalog"); + IMetaschemaModule oscalCatalogModule = module.getImportedModuleByShortName("oscal-catalog"); assertNotNull(oscalCatalogModule, "catalog metaschema not found"); - IXmlModule metadataModule = oscalCatalogModule.getImportedModuleByShortName("oscal-metadata"); + IMetaschemaModule metadataModule = oscalCatalogModule.getImportedModuleByShortName("oscal-metadata"); assertNotNull(metadataModule, "metadata metaschema not found"); - IFlagDefinition flag = metadataModule.getScopedFlagDefinitionByName("location-type"); + IFlagDefinition flag + = metadataModule.getScopedFlagDefinitionByName(new QName("location-type")); assertNotNull(flag, "flag not found"); List constraints = flag.getConstraints(); assertFalse(constraints.isEmpty(), "a constraint was expected"); @@ -73,7 +77,7 @@ void testFile() throws MetaschemaException, IOException { ModuleLoader loader = new ModuleLoader(); URI moduleUri = ObjectUtils.notNull( Paths.get("src/test/resources/content/custom-entity-metaschema.xml").toUri()); - IXmlModule module = loader.load(moduleUri); + IMetaschemaModule module = loader.load(moduleUri); assertFalse(module.getExportedRootAssemblyDefinitions().isEmpty(), "no roots found"); } @@ -89,8 +93,9 @@ void testConstraints() throws MetaschemaException, IOException { // NOPMD - inte loader.allowEntityResolution(); URI moduleUri = ObjectUtils.notNull(URI.create( "https://raw.githubusercontent.com/usnistgov/OSCAL/v1.0.0/src/metaschema/oscal_complete_metaschema.xml")); - IXmlModule module = loader.load(moduleUri); - IAssemblyDefinition catalog = module.getExportedAssemblyDefinitionByName("catalog"); + IMetaschemaModule module = loader.load(moduleUri); + IAssemblyDefinition catalog + = module.getExportedAssemblyDefinitionByName(new QName("http://csrc.nist.gov/ns/oscal/1.0", "catalog")); assertNotNull(catalog, "catalog not found"); List constraints = catalog.getConstraints(); @@ -101,10 +106,11 @@ void testConstraints() throws MetaschemaException, IOException { // NOPMD - inte void testLoadMetaschemaWithExternalEntity() throws MetaschemaException, IOException { ModuleLoader loader = new ModuleLoader(); loader.allowEntityResolution(); - IXmlModule module + IMetaschemaModule module = loader.load(ObjectUtils.notNull(Paths.get("src/test/resources/content/custom-entity-metaschema.xml"))); - IAssemblyDefinition root = module.getAssemblyDefinitionByName("root"); + IAssemblyDefinition root = module.getExportedRootAssemblyDefinitionByName( + new QName("http://csrc.nist.gov/ns/test/metaschema/entity", "root")); assert root != null; List allowedValues = root.getAllowedValuesConstraints(); diff --git a/core/src/test/java/gov/nist/secauto/metaschema/core/model/xml/UsedDefinitionModelWalkerTest.java b/core/src/test/java/gov/nist/secauto/metaschema/core/model/xml/UsedDefinitionModelWalkerTest.java index 1e2029bb1..9cf2e544e 100644 --- a/core/src/test/java/gov/nist/secauto/metaschema/core/model/xml/UsedDefinitionModelWalkerTest.java +++ b/core/src/test/java/gov/nist/secauto/metaschema/core/model/xml/UsedDefinitionModelWalkerTest.java @@ -29,6 +29,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import gov.nist.secauto.metaschema.core.model.IDefinition; +import gov.nist.secauto.metaschema.core.model.IMetaschemaModule; import gov.nist.secauto.metaschema.core.model.MetaschemaException; import gov.nist.secauto.metaschema.core.model.UsedDefinitionModelWalker; @@ -50,7 +51,7 @@ void test() throws MetaschemaException, IOException { ModuleLoader loader = new ModuleLoader(); loader.allowEntityResolution(); - IXmlModule module = loader.load(new URL( + IMetaschemaModule module = loader.load(new URL( "https://raw.githubusercontent.com/usnistgov/OSCAL/v1.0.0/src/metaschema/oscal_complete_metaschema.xml")); Collection definitions 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 85ee822e1..dec8b1726 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 @@ -30,8 +30,8 @@ import gov.nist.secauto.metaschema.core.model.IDefinition; import gov.nist.secauto.metaschema.core.model.IModelDefinition; import gov.nist.secauto.metaschema.core.model.IModelElement; -import gov.nist.secauto.metaschema.core.model.INamedModelElement; import gov.nist.secauto.metaschema.core.model.INamedInstance; +import gov.nist.secauto.metaschema.core.model.INamedModelElement; import gov.nist.secauto.metaschema.core.util.CollectionUtil; import org.apache.commons.lang3.ObjectUtils; diff --git a/core/src/test/java/gov/nist/secauto/metaschema/core/testing/FlagBuilder.java b/core/src/test/java/gov/nist/secauto/metaschema/core/testing/FlagBuilder.java index 6a3326f2c..35053427d 100644 --- a/core/src/test/java/gov/nist/secauto/metaschema/core/testing/FlagBuilder.java +++ b/core/src/test/java/gov/nist/secauto/metaschema/core/testing/FlagBuilder.java @@ -103,11 +103,4 @@ public IFlagDefinition toDefinition() { }); return retval; } - - // @Override - // public Object getValue(Object parentInstance) { - // // TODO Auto-generated method stub - // return null; - // } - // } } diff --git a/databind/pom.xml b/databind/pom.xml index 5810ed93a..0e64f3e69 100644 --- a/databind/pom.xml +++ b/databind/pom.xml @@ -101,7 +101,7 @@ target/generated-sources/xmlbeans - **/gov/nist/secauto/metaschema/databind/model/metaschema/*.java + gov/nist/secauto/metaschema/databind/model/metaschema/binding/*.java @@ -117,8 +117,10 @@ jacoco-maven-plugin + gov/nist/secauto/metaschema/databind/codegen/xmlbeans/**/* org/apache/xmlbeans/**/* + gov/nist/secauto/metaschema/databind/model/metaschema/binding/* 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 aafb556b6..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 @@ -138,12 +138,12 @@ protected Collection getBindingMatchers() { @Override @NonNull - public IBindingMatcher registerBindingMatcher(@NonNull IBoundDefinitionModelAssembly definition) { - return ObjectUtils.notNull(bindingMatchers.computeIfAbsent(definition, (key) -> IBindingMatcher.of(definition))); + public final IBindingMatcher registerBindingMatcher(@NonNull IBoundDefinitionModelAssembly definition) { + return ObjectUtils.notNull(bindingMatchers.computeIfAbsent(definition, key -> IBindingMatcher.of(definition))); } @Override - public IBindingMatcher registerBindingMatcher(@NonNull Class clazz) { + public final IBindingMatcher registerBindingMatcher(@NonNull Class clazz) { IBoundDefinitionModelComplex definition = getBoundDefinitionForClass(clazz); if (definition == null) { throw new IllegalArgumentException(String.format("Unable to find bound definition for class '%s'.", @@ -160,7 +160,7 @@ public IBindingMatcher registerBindingMatcher(@NonNull Class clazz) { } @Override - public IBoundDefinitionModelComplex registerClassBinding(IBoundDefinitionModelComplex definition) { + public final IBoundDefinitionModelComplex registerClassBinding(IBoundDefinitionModelComplex definition) { Class clazz = definition.getBoundClass(); return boundClassToStrategyMap.computeIfAbsent(clazz, k -> definition); } @@ -322,7 +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())); } - @SuppressWarnings("unchecked") CLASS retval = (CLASS) definition.deepCopyItem(other, parentInstance); - return retval; + return ObjectUtils.asType(definition.deepCopyItem(other, parentInstance)); } } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/IBindingContext.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/IBindingContext.java index 642f26f63..c7b5ca36c 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/IBindingContext.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/IBindingContext.java @@ -316,6 +316,8 @@ default IConstraintValidator newValidator(@NonNull IConstraintValidationHandler * * @param nodeItem * the node item to validate + * @param loader + * a module loader used to load and resolve referenced resources * @return the validation result * @throws IllegalArgumentException * if the provided class is not bound to a Module assembly or field 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/SimpleModuleLoaderStrategy.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/SimpleModuleLoaderStrategy.java index 9399542da..f65409e0f 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/SimpleModuleLoaderStrategy.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/SimpleModuleLoaderStrategy.java @@ -90,9 +90,9 @@ public IBoundDefinitionModelComplex getBoundDefinitionForClass(@NonNull Class private IBoundDefinitionModelComplex newBoundDefinition(@NonNull Class clazz) { IBoundDefinitionModelComplex retval = null; if (clazz.isAnnotationPresent(MetaschemaAssembly.class)) { - retval = new DefinitionAssembly(clazz, getBindingContext()); + retval = DefinitionAssembly.newInstance(clazz, getBindingContext()); } else if (clazz.isAnnotationPresent(MetaschemaField.class)) { - retval = new DefinitionField(clazz, getBindingContext()); + retval = DefinitionField.newInstance(clazz, getBindingContext()); } return retval; } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/ClassUtils.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/ClassUtils.java index 6953cc97d..be18276b6 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/ClassUtils.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/ClassUtils.java @@ -26,7 +26,9 @@ package gov.nist.secauto.metaschema.databind.codegen; -import gov.nist.secauto.metaschema.databind.codegen.impl.NameConverter; +import org.apache.xmlbeans.impl.common.NameUtil; + +import java.util.Map; import edu.umd.cs.findbugs.annotations.NonNull; @@ -34,6 +36,9 @@ * A variety of utility methods for normalizing Java class related names. */ public final class ClassUtils { + private static final Map JAVA_NAME_MAPPER = Map.ofEntries( + Map.entry("Class", "Clazz")); + private ClassUtils() { // disable construction } @@ -49,7 +54,8 @@ private ClassUtils() { @SuppressWarnings("null") @NonNull public static String toPropertyName(@NonNull String name) { - return NameConverter.STANDARD.toPropertyName(name); + String property = NameUtil.upperCamelCase(name); + return JAVA_NAME_MAPPER.getOrDefault(property, property); } /** @@ -63,7 +69,7 @@ public static String toPropertyName(@NonNull String name) { @SuppressWarnings("null") @NonNull public static String toVariableName(@NonNull String name) { - return NameConverter.STANDARD.toVariableName(name); + return NameUtil.lowerCamelCase(name); } /** @@ -77,7 +83,7 @@ public static String toVariableName(@NonNull String name) { @SuppressWarnings("null") @NonNull public static String toClassName(@NonNull String name) { - return NameConverter.STANDARD.toClassName(name); + return NameUtil.upperCamelCase(name, false); } /** @@ -91,7 +97,6 @@ public static String toClassName(@NonNull String name) { @SuppressWarnings("null") @NonNull public static String toPackageName(@NonNull String name) { - return NameConverter.STANDARD.toPackageName(name); + return NameUtil.getPackageFromNamespace(name, false); } - } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/IGeneratedDefinitionClass.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/IGeneratedDefinitionClass.java index c84080227..3fee0a0e8 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/IGeneratedDefinitionClass.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/IGeneratedDefinitionClass.java @@ -26,7 +26,7 @@ package gov.nist.secauto.metaschema.databind.codegen; -import gov.nist.secauto.metaschema.core.model.IContainerFlag; +import gov.nist.secauto.metaschema.core.model.IModelDefinition; import edu.umd.cs.findbugs.annotations.NonNull; @@ -38,7 +38,7 @@ public interface IGeneratedDefinitionClass extends IGeneratedClass { * @return the definition */ @NonNull - IContainerFlag getDefinition(); + IModelDefinition getDefinition(); /** * Indicates if the class represents a root Module assembly which can be the diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/impl/DefaultGeneratedDefinitionClass.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/impl/DefaultGeneratedDefinitionClass.java index 5493a2dbe..00ae607ec 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/impl/DefaultGeneratedDefinitionClass.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/impl/DefaultGeneratedDefinitionClass.java @@ -29,7 +29,7 @@ import com.squareup.javapoet.ClassName; import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition; -import gov.nist.secauto.metaschema.core.model.IContainerFlag; +import gov.nist.secauto.metaschema.core.model.IModelDefinition; import gov.nist.secauto.metaschema.databind.codegen.IGeneratedDefinitionClass; import java.nio.file.Path; @@ -44,7 +44,7 @@ public class DefaultGeneratedDefinitionClass extends DefaultGeneratedClass implements IGeneratedDefinitionClass { @NonNull - private final IContainerFlag definition; + private final IModelDefinition definition; /** * Construct a new class information object for a generated class. @@ -57,13 +57,13 @@ public class DefaultGeneratedDefinitionClass * the definition on which the class was based */ public DefaultGeneratedDefinitionClass(@NonNull Path classFile, @NonNull ClassName className, - @NonNull IContainerFlag definition) { + @NonNull IModelDefinition definition) { super(classFile, className); this.definition = definition; } @Override - public IContainerFlag getDefinition() { + public IModelDefinition getDefinition() { return definition; } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/impl/DefaultGeneratedModuleClass.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/impl/DefaultGeneratedModuleClass.java index e6b06e38a..36a3e581a 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/impl/DefaultGeneratedModuleClass.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/impl/DefaultGeneratedModuleClass.java @@ -28,7 +28,7 @@ import com.squareup.javapoet.ClassName; -import gov.nist.secauto.metaschema.core.model.IContainerFlag; +import gov.nist.secauto.metaschema.core.model.IModelDefinition; import gov.nist.secauto.metaschema.core.model.IModule; import gov.nist.secauto.metaschema.core.util.CollectionUtil; import gov.nist.secauto.metaschema.core.util.ObjectUtils; @@ -47,7 +47,7 @@ public class DefaultGeneratedModuleClass @NonNull private final IModule module; @NonNull - private final Map definitionClassMap; + private final Map definitionClassMap; @NonNull private final String packageName; @@ -55,7 +55,7 @@ public DefaultGeneratedModuleClass( @NonNull IModule module, @NonNull ClassName className, @NonNull Path classFile, - @NonNull Map definitionClassMap, + @NonNull Map definitionClassMap, @NonNull String packageName) { super(classFile, className); this.module = module; diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/impl/NameConverter.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/impl/NameConverter.java deleted file mode 100644 index 709db26f5..000000000 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/impl/NameConverter.java +++ /dev/null @@ -1,281 +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. - */ -/* - * Copyright (c) 1997, 2022 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Distribution License v. 1.0, which is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -package gov.nist.secauto.metaschema.databind.codegen.impl; - -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; -import java.util.StringTokenizer; - -import javax.lang.model.SourceVersion; - -/** - * Converts aribitrary strings into Java identifiers. - * - * @author Kohsuke KAWAGUCHI - */ -public interface NameConverter { - /** - * The name converter implemented by Code Model. - * - * This is the standard name conversion for JAXB. - */ - NameConverter STANDARD = new Standard(); - - /** - * converts a string into an identifier suitable for classes. - * - * In general, this operation should generate "NamesLikeThis". - * - * @param token - * the string to convert - * @return the equivalent class name - */ - String toClassName(String token); - - /** - * converts a string into an identifier suitable for interfaces. - * - * In general, this operation should generate "NamesLikeThis". But for example, - * it can prepend every interface with 'I'. - * - * @param token - * the string to convert - * @return the equivalent interface name - */ - String toInterfaceName(String token); - - /** - * Converts a string into an identifier suitable for Java properties. - *

- * In general, this operation should generate upper camel case "NamesLikeThis", - * which will be used with known prefixes like "get" or "set". - * - * @param token - * the string to convert - * @return the equivalent Java property name - */ - String toPropertyName(String token); - - /** - * converts a string into an identifier suitable for constants. - *

- * In the standard Java naming convention, this operation should generate upper - * case "NAMES_LIKE_THIS". - * - * @param token - * the string to convert - * @return the equivalent constant name - */ - String toConstantName(String token); - - /** - * Converts a string into an identifier suitable for variables. - *

- * In general it should generate lower camel case "namesLikeThis". - * - * @param token - * the string to convert - * @return the equivalent variable name - */ - String toVariableName(String token); - - /** - * Converts a namespace URI into a package name. This method should expect - * strings like "http://foo.bar.zot/org", "urn:abc:def:ghi" "", or even "###" - * (basically anything) and expected to return a package name, like - * "org.acme.foo". - * - * @param namespaceUri - * the string to convert - * @return the equivalent package name - */ - String toPackageName(String namespaceUri); - - class Standard - extends NameUtil - implements NameConverter { - - @Override - public String toClassName(String token) { - return toMixedCaseName(toWordList(token), true); - } - - @Override - public String toVariableName(String token) { - return toMixedCaseName(toWordList(token), false); - } - - @Override - public String toInterfaceName(String token) { - return toClassName(token); - } - - @Override - public String toPropertyName(String token) { - String prop = toClassName(token); - // property name "Class" with collide with Object.getClass, - // so escape this. - if ("Class".equals(prop)) { - prop = "Clazz"; - } - return prop; - } - - /** - * Computes a Java package name from a namespace URI, as specified in the spec. - * - * @return {@code null} if it fails to derive a package name. - */ - @SuppressWarnings({ - "PMD.CyclomaticComplexity", "PMD.NPathComplexity", // acceptable - "PMD.OnlyOneReturn", // readability - "PMD.UseStringBufferForStringAppends" // ok - }) - @Override - public String toPackageName(String uri) { - String nsUri = uri; - // remove scheme and :, if present - // spec only requires us to remove 'http' and 'urn'... - int idx = nsUri.indexOf(':'); - String scheme = ""; - if (idx >= 0) { - scheme = nsUri.substring(0, idx); - if ("http".equalsIgnoreCase(scheme) || "urn".equalsIgnoreCase(scheme)) { - nsUri = nsUri.substring(idx + 1); - } - } - - // tokenize string - List tokens = tokenize(nsUri, "/: "); - if (tokens.isEmpty()) { - return null; - } - - // remove trailing file type, if necessary - if (tokens.size() > 1) { - // for uri's like "www.foo.com" and "foo.com", there is no trailing - // file, so there's no need to look at the last '.' and substring - // otherwise, we loose the "com" (which would be wrong) - String lastToken = tokens.get(tokens.size() - 1); - idx = lastToken.lastIndexOf('.'); - if (idx > 0) { - lastToken = lastToken.substring(0, idx); - tokens.set(tokens.size() - 1, lastToken); - } - } - - // tokenize domain name and reverse. Also remove :port if it exists - String domain = tokens.get(0); - idx = domain.indexOf(':'); - if (idx >= 0) { - domain = domain.substring(0, idx); - } - List rev = reverse(tokenize(domain, "urn".equals(scheme) ? ".-" : ".")); - if ("www".equalsIgnoreCase(rev.get(rev.size() - 1))) { - // remove leading www - rev.remove(rev.size() - 1); - } - - // replace the domain name with tokenized items - tokens.addAll(1, rev); - tokens.remove(0); - - // iterate through the tokens and apply xml->java name algorithm - for (int i = 0; i < tokens.size(); i++) { - - // get the token and remove illegal chars - String token = tokens.get(i); - token = removeIllegalIdentifierChars(token); - - // this will check for reserved keywords - if (SourceVersion.isKeyword(token.toLowerCase(Locale.ENGLISH))) { - token = '_' + token; - } - - tokens.set(i, token.toLowerCase(Locale.ENGLISH)); - } - - // concat all the pieces and return it - return combine(tokens, '.'); - } - - private static String removeIllegalIdentifierChars(String token) { - StringBuilder newToken = new StringBuilder(token.length() * 2); // max expected length - for (int i = 0; i < token.length(); i++) { - char ch = token.charAt(i); - if (i == 0 && !Character.isJavaIdentifierStart(ch)) { // ch can't be used as FIRST char - newToken.append('_'); - } - if (Character.isJavaIdentifierPart(ch)) { - newToken.append(ch); // ch is valid - } else { - newToken.append('_'); // ch can't be used - } - } - return newToken.toString(); - } - - private static List tokenize(String str, String sep) { - StringTokenizer tokens = new StringTokenizer(str, sep); - List retval = new ArrayList<>(); - - while (tokens.hasMoreTokens()) { - retval.add(tokens.nextToken()); - } - return retval; - } - - private static List reverse(List list) { - List rev = new ArrayList<>(list.size()); - - for (int i = list.size() - 1; i >= 0; i--) { - rev.add(list.get(i)); - } - return rev; - } - - private static String combine(List tokens, char sep) { - StringBuilder buf = new StringBuilder(tokens.get(0)); - - for (int i = 1; i < tokens.size(); i++) { - buf.append(sep) - .append(tokens.get(i)); - } - return buf.toString(); - } - } -} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/impl/NameUtil.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/impl/NameUtil.java deleted file mode 100644 index c54f0d736..000000000 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/impl/NameUtil.java +++ /dev/null @@ -1,348 +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. - */ - -/* - * This code is based on https://github.com/eclipse-ee4j/jaxb-ri/blob/master/jaxb-ri/core/src/main/java/org/glassfish/jaxb/core/api/impl/NameUtil.java - * - * Copyright (c) 1997, 2022 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Distribution License v. 1.0, which is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -package gov.nist.secauto.metaschema.databind.codegen.impl; - -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; - -/** - * Methods that convert strings into various formats. - */ -@SuppressWarnings("PMD") -class NameUtil { - protected static boolean isPunct(char ch) { - return ch == '-' || ch == '.' || ch == ':' || ch == '_' || ch == '·' || ch == '·' || ch == '۝' || ch == '۞'; - } - - /** - * Capitalizes the first character of the specified string, and de-capitalize - * the rest of characters. - * - * @param str - * the string to capitalize - * @return the capitalized string - */ - public static String capitalize(String str) { - if (!Character.isLowerCase(str.charAt(0))) { - return str; - } - StringBuilder sb = new StringBuilder(str.length()); - sb.append(String.valueOf(str.charAt(0)).toUpperCase(Locale.ENGLISH)); - sb.append(str.substring(1).toLowerCase(Locale.ENGLISH)); - return sb.toString(); - } - - // Precondition: s[start] is not punctuation - @SuppressWarnings({ - "checkstyle:MissingSwitchDefaultCheck", // intentional - }) - private static int nextBreak(String str, int start) { - int len = str.length(); - - char c1 = str.charAt(start); - int t1 = classify(c1); - - for (int i = start + 1; i < len; i++) { - // shift (c1,t1) into (c0,t0) - // char c0 = c1; --- conceptually, but c0 won't be used - int t0 = t1; - - c1 = str.charAt(i); - t1 = classify(c1); - - switch (actionTable[t0 * 5 + t1]) { - case ACTION_CHECK_PUNCT: - if (isPunct(c1)) { - return i; - } - break; - case ACTION_CHECK_C2: - if (i < len - 1) { - char c2 = str.charAt(i + 1); - if (Character.isLowerCase(c2)) { - return i; - } - } - break; - case ACTION_BREAK: - return i; - } - } - return -1; - } - - // the 5-category classification that we use in this code - // to find work breaks - protected static final int UPPER_LETTER = 0; - protected static final int LOWER_LETTER = 1; - protected static final int OTHER_LETTER = 2; - protected static final int DIGIT = 3; - protected static final int OTHER = 4; - - /** - * Look up table for actions. type0*5+type1 would yield the action to be taken. - */ - private static final byte[] actionTable = new byte[5 * 5]; - - // action constants. see nextBreak for the meaning - private static final byte ACTION_CHECK_PUNCT = 0; - private static final byte ACTION_CHECK_C2 = 1; - private static final byte ACTION_BREAK = 2; - private static final byte ACTION_NOBREAK = 3; - - /** - * Decide the action to be taken given the classification of the preceding - * character 't0' and the classification of the next character 't1'. - */ - private static byte decideAction(int t0, int t1) { - if (t0 == OTHER && t1 == OTHER) { - return ACTION_CHECK_PUNCT; - } - if ((t0 == DIGIT) ^ (t1 == DIGIT)) { - return ACTION_BREAK; - } - if (t0 == LOWER_LETTER && t1 != LOWER_LETTER) { - return ACTION_BREAK; - } - if ((t0 <= OTHER_LETTER) ^ (t1 <= OTHER_LETTER)) { - return ACTION_BREAK; - } - if ((t0 == OTHER_LETTER) ^ (t1 == OTHER_LETTER)) { - return ACTION_BREAK; - } - if (t0 == UPPER_LETTER && t1 == UPPER_LETTER) { - return ACTION_CHECK_C2; - } - - return ACTION_NOBREAK; - } - - static { - // initialize the action table - for (int t0 = 0; t0 < 5; t0++) { - for (int t1 = 0; t1 < 5; t1++) { - actionTable[t0 * 5 + t1] = decideAction(t0, t1); - } - } - } - - /** - * Classify a character into 5 categories that determine the word break. - * - * @param ch - * the character - * @return the categorization - */ - protected static int classify(char ch) { - switch (Character.getType(ch)) { - case Character.UPPERCASE_LETTER: - return UPPER_LETTER; - case Character.LOWERCASE_LETTER: - return LOWER_LETTER; - case Character.TITLECASE_LETTER: - case Character.MODIFIER_LETTER: - case Character.OTHER_LETTER: - return OTHER_LETTER; - case Character.DECIMAL_DIGIT_NUMBER: - return DIGIT; - default: - return OTHER; - } - } - - /** - * Tokenizes a string into words and capitalizes the first character of each - * word. - *

- * This method uses a change in character type as a splitter of two words. For - * example, "abc100ghi" will be splitted into {"Abc", "100","Ghi"}. - * - * @param str - * the string to split into a word list - * @return the word list - */ - public static List toWordList(String str) { - ArrayList retval = new ArrayList<>(); - int len = str.length(); - for (int i = 0; i < len;) { - - // Skip punctuation - while (i < len) { - if (!isPunct(str.charAt(i))) { - break; - } - i++; - } - if (i >= len) { - break; - } - - // Find next break and collect word - int breakPos = nextBreak(str, i); - String word = (breakPos == -1) ? str.substring(i) : str.substring(i, breakPos); - retval.add(escape(capitalize(word))); - if (breakPos == -1) { - break; - } - i = breakPos; - } - - // we can't guarantee a valid Java identifier anyway, - // so there's not much point in rejecting things in this way. - // if (ss.size() == 0) - // throw new IllegalArgumentException("Zero-length identifier"); - return retval; - } - - protected static String toMixedCaseName(List ss, boolean startUpper) { - StringBuilder sb = new StringBuilder(); - if (!ss.isEmpty()) { - sb.append(startUpper ? ss.get(0) : ss.get(0).toLowerCase(Locale.ENGLISH)); - for (int i = 1; i < ss.size(); i++) { - sb.append(ss.get(i)); - } - } - return sb.toString(); - } - - protected static String toMixedCaseVariableName(String[] ss, - boolean startUpper, - boolean cdrUpper) { - if (cdrUpper) { - for (int i = 1; i < ss.length; i++) { - ss[i] = capitalize(ss[i]); - } - } - StringBuilder sb = new StringBuilder(); - if (ss.length > 0) { - sb.append(startUpper ? ss[0] : ss[0].toLowerCase(Locale.ENGLISH)); - for (int i = 1; i < ss.length; i++) { - sb.append(ss[i]); - } - } - return sb.toString(); - } - - /** - * Formats a string into "THIS_KIND_OF_FORMAT_ABC_DEF". - * - * @param str - * the string to format - * @return Always return a string but there's no guarantee that the generated - * code is a valid Java identifier. - */ - public String toConstantName(String str) { - return toConstantName(toWordList(str)); - } - - /** - * Formats a string into "THIS_KIND_OF_FORMAT_ABC_DEF". - * - * @param ss - * a list of words - * @return Always return a string but there's no guarantee that the generated - * code is a valid Java identifier. - */ - public String toConstantName(List ss) { - StringBuilder sb = new StringBuilder(); - if (!ss.isEmpty()) { - sb.append(ss.get(0).toUpperCase(Locale.ENGLISH)); - for (int i = 1; i < ss.size(); i++) { - sb.append('_'); - sb.append(ss.get(i).toUpperCase(Locale.ENGLISH)); - } - } - return sb.toString(); - } - - /** - * Escapes characters is the given string so that they can be printed by only - * using US-ASCII characters. - * - * The escaped characters will be appended to the given StringBuffer. - * - * @param sb - * StringBuffer that receives escaped string. - * @param str - * String to be escaped. s.substring(start) will be - * escaped and copied to the string buffer. - * @param start - * the starting position in the string - */ - @SuppressWarnings({ - "checkstyle:MissingSwitchDefaultCheck", // intentional - "checkstyle:AvoidEscapedUnicodeCharactersCheck" // ok - }) - public static void escape(StringBuilder sb, String str, int start) { - int len = str.length(); - for (int i = start; i < len; i++) { - char ch = str.charAt(i); - if (Character.isJavaIdentifierPart(ch)) { - sb.append(ch); - } else { - sb.append('_'); - if (ch <= '\u000f') { - sb.append("000"); - } else if (ch <= '\u00ff') { - sb.append("00"); - } else if (ch <= '\u0fff') { - sb.append('0'); - } - sb.append(Integer.toString(ch, 16)); - } - } - } - - /** - * Escapes characters that are unusable as Java identifiers by replacing unsafe - * characters with safe characters. - */ - private static String escape(String str) { - int len = str.length(); - for (int i = 0; i < len; i++) { - if (!Character.isJavaIdentifierPart(str.charAt(i))) { - StringBuilder sb = new StringBuilder(str.substring(0, i)); - escape(sb, str, i); - return sb.toString(); - } - } - return str; - } -} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/typeinfo/AbstractModelInstanceTypeInfo.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/typeinfo/AbstractModelInstanceTypeInfo.java index 2a01fcb81..b9bf12544 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/typeinfo/AbstractModelInstanceTypeInfo.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/typeinfo/AbstractModelInstanceTypeInfo.java @@ -41,7 +41,6 @@ import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.metaschema.databind.codegen.typeinfo.def.IAssemblyDefinitionTypeInfo; import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs; -import gov.nist.secauto.metaschema.databind.model.annotations.ModelUtil; import java.util.HashSet; import java.util.List; @@ -121,13 +120,7 @@ protected AnnotationSpec.Builder generateGroupAsAnnotation() { groupAsAnnoation.addMember("name", "$S", ObjectUtils.requireNonNull(modelInstance.getGroupAsName(), "The grouping name must be non-null")); - TypeInfoUtils.buildNamespaceBindingAnnotation( - groupAsAnnoation, - "namespace", - modelInstance.getGroupAsXmlNamespace(), - () -> modelInstance.getContainingModule().getXmlNamespace().toASCIIString(), - ModelUtil.DEFAULT_STRING_VALUE, - false); + // TODO: handle group-as namespace as a prefix JsonGroupAsBehavior jsonGroupAsBehavior = modelInstance.getJsonGroupAsBehavior(); assert jsonGroupAsBehavior != null; diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/typeinfo/AbstractNamedModelInstanceTypeInfo.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/typeinfo/AbstractNamedModelInstanceTypeInfo.java index de2a8f621..5aed79a10 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/typeinfo/AbstractNamedModelInstanceTypeInfo.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/typeinfo/AbstractNamedModelInstanceTypeInfo.java @@ -141,7 +141,7 @@ protected void buildExtraMethods(TypeSpec.Builder builder, FieldSpec valueField) String itemPropertyName = ClassUtils.toPropertyName(getItemBaseName()); if (JsonGroupAsBehavior.KEYED.equals(instance.getJsonGroupAsBehavior())) { - IFlagInstance jsonKey = instance.getDefinition().getJsonKeyFlagInstance(); + IFlagInstance jsonKey = instance.getDefinition().getJsonKey(); if (jsonKey == null) { throw new IllegalStateException( String.format("JSON key not defined for property: %s", instance.toCoordinates())); diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/typeinfo/ChoiceGroupTypeInfoImpl.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/typeinfo/ChoiceGroupTypeInfoImpl.java index c859504ff..e89911045 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/typeinfo/ChoiceGroupTypeInfoImpl.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/typeinfo/ChoiceGroupTypeInfoImpl.java @@ -93,7 +93,7 @@ public Set buildBindingAnnotation( annotation.addMember("maxOccurs", "$L", maxOccurs); } - String jsonKeyName = choiceGroup.getJsonKeyFlagName(); + String jsonKeyName = choiceGroup.getJsonKeyFlagInstanceName(); if (jsonKeyName != null) { annotation.addMember("jsonKey", "$S", jsonKeyName); } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/typeinfo/DefaultMetaschemaClassFactory.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/typeinfo/DefaultMetaschemaClassFactory.java index 21e719c99..f7dbbd415 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/typeinfo/DefaultMetaschemaClassFactory.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/typeinfo/DefaultMetaschemaClassFactory.java @@ -31,28 +31,20 @@ import com.squareup.javapoet.FieldSpec; import com.squareup.javapoet.JavaFile; import com.squareup.javapoet.MethodSpec; -import com.squareup.javapoet.ParameterSpec; import com.squareup.javapoet.ParameterizedTypeName; -import com.squareup.javapoet.TypeName; import com.squareup.javapoet.TypeSpec; import com.squareup.javapoet.WildcardTypeName; 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.IAssemblyDefinition; -import gov.nist.secauto.metaschema.core.model.IContainerFlag; import gov.nist.secauto.metaschema.core.model.IDefinition; import gov.nist.secauto.metaschema.core.model.IFieldDefinition; -import gov.nist.secauto.metaschema.core.model.IFlagInstance; import gov.nist.secauto.metaschema.core.model.IModelDefinition; -import gov.nist.secauto.metaschema.core.model.IModelInstanceAbsolute; import gov.nist.secauto.metaschema.core.model.IModule; -import gov.nist.secauto.metaschema.core.model.INamedModelInstance; -import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior; import gov.nist.secauto.metaschema.core.util.CollectionUtil; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.metaschema.databind.IBindingContext; -import gov.nist.secauto.metaschema.databind.codegen.ClassUtils; import gov.nist.secauto.metaschema.databind.codegen.IGeneratedClass; import gov.nist.secauto.metaschema.databind.codegen.IGeneratedDefinitionClass; import gov.nist.secauto.metaschema.databind.codegen.IGeneratedModuleClass; @@ -84,8 +76,6 @@ import java.nio.file.StandardOpenOption; import java.util.Collection; import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; @@ -152,14 +142,14 @@ public IGeneratedModuleClass generateClass( Path classFile = ObjectUtils.notNull(javaFile.writeToPath(targetDirectory)); // now generate all related definition classes - Stream globalDefinitions = Stream.concat( + Stream globalDefinitions = Stream.concat( module.getAssemblyDefinitions().stream(), module.getFieldDefinitions().stream()); Set classNames = new HashSet<>(); @SuppressWarnings("PMD.UseConcurrentHashMap") // map is unmodifiable - Map definitionProductions + Map definitionProductions = ObjectUtils.notNull(globalDefinitions // Get type information for assembly and field definitions. // Avoid field definitions without flags that don't require a generated class @@ -474,9 +464,7 @@ protected TypeSpec.Builder newClassBuilder( protected Set buildClass( @NonNull IAssemblyDefinitionTypeInfo typeInfo, @NonNull TypeSpec.Builder builder) { - Set retval = new HashSet<>(); - - retval.addAll(buildClass((IModelDefinitionTypeInfo) typeInfo, builder)); + Set retval = new HashSet<>(buildClass((IModelDefinitionTypeInfo) typeInfo, builder)); AnnotationSpec.Builder metaschemaAssembly = ObjectUtils.notNull(AnnotationSpec.builder(MetaschemaAssembly.class)); @@ -513,9 +501,7 @@ protected Set buildClass( protected Set buildClass( @NonNull IFieldDefinitionTypeInfo typeInfo, @NonNull TypeSpec.Builder builder) { - Set retval = new HashSet<>(); - retval.addAll(buildClass((IModelDefinitionTypeInfo) typeInfo, builder)); - + Set retval = new HashSet<>(buildClass((IModelDefinitionTypeInfo) typeInfo, builder)); AnnotationSpec.Builder metaschemaField = ObjectUtils.notNull(AnnotationSpec.builder(MetaschemaField.class)); buildCommonProperties(typeInfo, metaschemaField); @@ -604,162 +590,4 @@ protected void buildCommonProperties( IModule module = definition.getContainingModule(); builder.addMember("moduleClass", "$T.class", getTypeResolver().getClassName(module)); } - - /* - protected void buildFieldForFieldValue( - @NonNull IFieldValueTypeInfo typeInfo, - @NonNull FieldSpec.Builder builder) { - IFieldDefinition definition = typeInfo.getParentDefinitionTypeInfo().getDefinition(); - AnnotationSpec.Builder fieldValue = AnnotationSpec.builder(BoundFieldValue.class); - - IDataTypeAdapter valueDataType = definition.getJavaTypeAdapter(); - - // a field object always has a single value - if (!definition.hasJsonValueKeyFlagInstance()) { - fieldValue.addMember("valueKeyName", "$S", definition.getJsonValueKeyName()); - } // else do nothing, the annotation will be on the flag - - if (!MetaschemaDataTypeProvider.DEFAULT_DATA_TYPE.equals(valueDataType)) { - fieldValue.addMember("typeAdapter", "$T.class", valueDataType.getClass()); - } - - Object defaultValue = definition.getDefaultValue(); - if (defaultValue != null) { - fieldValue.addMember("defaultValue", "$S", valueDataType.asString(defaultValue)); - } - - builder.addAnnotation(fieldValue.build()); - } - */ - /** - * This method can be implemented by subclasses to create additional methods. - * - * @param typeInfo - * the type information for the Java property to build - * @param builder - * the class builder - * @param valueField - * the field corresponding to this property - */ - @SuppressWarnings("PMD.LooseCoupling") // need implementation classes - protected void buildExtraMethods( // NOPMD - intentional - @NonNull IModelInstanceTypeInfo typeInfo, - @NonNull TypeSpec.Builder builder, - @NonNull FieldSpec valueField) { - IModelInstanceAbsolute instance = typeInfo.getInstance(); - int maxOccurance = instance.getMaxOccurs(); - if (maxOccurance == -1 || maxOccurance > 1) { - TypeName itemType = typeInfo.getJavaItemType(); - ParameterSpec valueParam = ObjectUtils.notNull(ParameterSpec.builder(itemType, "item").build()); - - String itemPropertyName = ClassUtils.toPropertyName(typeInfo.getItemBaseName()); - - if (JsonGroupAsBehavior.KEYED.equals(instance.getJsonGroupAsBehavior())) { - if (instance instanceof INamedModelInstance) { - buildKeyedMethods((INamedModelInstance) instance, builder, itemType, itemPropertyName, valueParam, - valueField); - } else { - // FIXME: implement choice group - throw new UnsupportedOperationException("implement"); - } - } else { - { - // create add method - MethodSpec.Builder method = MethodSpec.methodBuilder("add" + itemPropertyName) - .addParameter(valueParam) - .returns(TypeName.BOOLEAN) - .addModifiers(Modifier.PUBLIC) - .addJavadoc("Add a new {@link $T} item to the underlying collection.\n", itemType) - .addJavadoc("@param item the item to add\n") - .addJavadoc("@return {@code true}\n") - .addStatement("$T value = $T.requireNonNull($N,\"$N cannot be null\")", - itemType, ObjectUtils.class, valueParam, valueParam) - .beginControlFlow("if ($N == null)", valueField) - .addStatement("$N = new $T<>()", valueField, LinkedList.class) - .endControlFlow() - .addStatement("return $N.add(value)", valueField); - - builder.addMethod(method.build()); - } - - { - // create remove method - MethodSpec.Builder method = MethodSpec.methodBuilder("remove" + itemPropertyName) - .addParameter(valueParam) - .returns(TypeName.BOOLEAN) - .addModifiers(Modifier.PUBLIC) - .addJavadoc("Remove the first matching {@link $T} item from the underlying collection.\n", itemType) - .addJavadoc("@param item the item to remove\n") - .addJavadoc("@return {@code true} if the item was removed or {@code false} otherwise\n") - .addStatement("$T value = $T.requireNonNull($N,\"$N cannot be null\")", - itemType, ObjectUtils.class, valueParam, valueParam) - .addStatement("return $1N != null && $1N.remove(value)", valueField); - builder.addMethod(method.build()); - } - } - } - } - - private void buildKeyedMethods( - @NonNull INamedModelInstance instance, - @NonNull TypeSpec.Builder builder, - @NonNull TypeName itemType, - @NonNull String itemPropertyName, - @NonNull ParameterSpec valueParam, - @NonNull FieldSpec valueField) { - - IFlagInstance jsonKey = instance.getDefinition().getJsonKeyFlagInstance(); - if (jsonKey == null) { - throw new IllegalStateException( - String.format("JSON key not defined for property: %s", instance.toCoordinates())); - } - - // get the json key property on the instance's definition - IModelDefinitionTypeInfo instanceTypeInfo = typeResolver.getTypeInfo(instance.getDefinition()); - IFlagInstanceTypeInfo jsonKeyTypeInfo = instanceTypeInfo.getFlagInstanceTypeInfo(jsonKey); - - if (jsonKeyTypeInfo == null) { - throw new IllegalStateException( - String.format("Unable to identify JSON key for property: %s", instance.toCoordinates())); - } - - { - // create add method - MethodSpec.Builder method = MethodSpec.methodBuilder("add" + itemPropertyName) - .addParameter(valueParam) - .returns(itemType) - .addModifiers(Modifier.PUBLIC) - .addJavadoc("Add a new {@link $T} item to the underlying collection.\n", itemType) - .addJavadoc("@param item the item to add\n") - .addJavadoc("@return the existing {@link $T} item in the collection or {@code null} if not item exists\n", - itemType) - .addStatement("$1T value = $2T.requireNonNull($3N,\"$3N value cannot be null\")", - itemType, ObjectUtils.class, valueParam) - .addStatement("$1T key = $2T.requireNonNull($3N.$4N(),\"$3N key cannot be null\")", - String.class, ObjectUtils.class, valueParam, "get" + jsonKeyTypeInfo.getPropertyName()) - .beginControlFlow("if ($N == null)", valueField) - .addStatement("$N = new $T<>()", valueField, LinkedHashMap.class) // NOPMD required - .endControlFlow() - .addStatement("return $N.put(key, value)", valueField); - - builder.addMethod(method.build()); - } - { - // create remove method - MethodSpec.Builder method = MethodSpec.methodBuilder("remove" + itemPropertyName) - .addParameter(valueParam) - .returns(TypeName.BOOLEAN) - .addModifiers(Modifier.PUBLIC) - .addJavadoc("Remove the {@link $T} item from the underlying collection.\n", itemType) - .addJavadoc("@param item the item to remove\n") - .addJavadoc("@return {@code true} if the item was removed or {@code false} otherwise\n") - .addStatement("$1T value = $2T.requireNonNull($3N,\"$3N value cannot be null\")", - itemType, ObjectUtils.class, valueParam) - .addStatement("$1T key = $2T.requireNonNull($3N.$4N(),\"$3N key cannot be null\")", - String.class, ObjectUtils.class, valueParam, "get" + jsonKeyTypeInfo.getPropertyName()) - .addStatement("return $1N != null && $1N.remove(key, value)", valueField); - builder.addMethod(method.build()); - } - - } } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/typeinfo/FlagInstanceTypeInfoImpl.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/typeinfo/FlagInstanceTypeInfoImpl.java index 2348691c5..1896bc37d 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/typeinfo/FlagInstanceTypeInfoImpl.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/typeinfo/FlagInstanceTypeInfoImpl.java @@ -46,7 +46,6 @@ import gov.nist.secauto.metaschema.databind.model.annotations.BoundFlag; import gov.nist.secauto.metaschema.databind.model.annotations.JsonFieldValueKeyFlag; import gov.nist.secauto.metaschema.databind.model.annotations.JsonKey; -import gov.nist.secauto.metaschema.databind.model.annotations.ModelUtil; import java.util.Set; @@ -97,13 +96,7 @@ public Set buildField( annotation.addMember("useIndex", "$L", index); } - TypeInfoUtils.buildNamespaceBindingAnnotation( - annotation, - "namespace", - instance.getXmlNamespace(), - () -> instance.getContainingModule().getXmlNamespace().toASCIIString(), - ModelUtil.NO_STRING_VALUE, - true); + // TODO: handle flag namespace as a prefix IFlagDefinition definition = instance.getDefinition(); @@ -128,7 +121,8 @@ public Set buildField( fieldBuilder.addAnnotation(annotation.build()); IModelDefinition parent = instance.getContainingDefinition(); - if (parent.hasJsonKey() && instance.equals(parent.getJsonKeyFlagInstance())) { + IFlagInstance jsonKey = parent.getJsonKey(); + if (instance.equals(jsonKey)) { fieldBuilder.addAnnotation(JsonKey.class); } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/typeinfo/TypeInfoUtils.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/typeinfo/TypeInfoUtils.java index ae0d875a1..5a3f9491c 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/typeinfo/TypeInfoUtils.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/typeinfo/TypeInfoUtils.java @@ -30,14 +30,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.INamedInstance; import gov.nist.secauto.metaschema.core.model.INamedModelInstance; -import gov.nist.secauto.metaschema.databind.model.annotations.ModelUtil; - -import java.util.function.Supplier; import edu.umd.cs.findbugs.annotations.NonNull; -import edu.umd.cs.findbugs.annotations.Nullable; public final class TypeInfoUtils { private TypeInfoUtils() { @@ -65,42 +60,11 @@ public static void buildCommonBindingAnnotationValues( annotation.addMember("useIndex", "$L", index); } - buildNamespaceBindingAnnotation( - annotation, - "namespace", - instance.getXmlNamespace(), - () -> instance.getContainingModule().getXmlNamespace().toASCIIString(), - ModelUtil.DEFAULT_STRING_VALUE, - false); + // TODO: handle instance namespace as a prefix MarkupMultiline remarks = instance.getRemarks(); if (remarks != null) { annotation.addMember("remarks", "$S", remarks.toMarkdown()); } } - - public static void buildNamespaceBindingAnnotation( - @NonNull AnnotationSpec.Builder annotation, - @NonNull String annotationMember, - @Nullable String namespaceUri, - @NonNull Supplier defaultSupplier, - @NonNull String annotationDefault, - boolean allowNone) { - String value; - if (namespaceUri == null) { - if (allowNone) { - value = ModelUtil.NO_STRING_VALUE; - } else { - throw new IllegalStateException("Expected non-null namespace"); - } - } else if (namespaceUri.equals(defaultSupplier.get())) { - value = ModelUtil.DEFAULT_STRING_VALUE; - } else { - value = namespaceUri; - } - - if (!annotationDefault.equals(value)) { - annotation.addMember(annotationMember, "$S", value); - } - } } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/typeinfo/def/AbstractModelDefinitionTypeInfo.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/typeinfo/def/AbstractModelDefinitionTypeInfo.java index c820d07ca..1dd1a0af1 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/typeinfo/def/AbstractModelDefinitionTypeInfo.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/typeinfo/def/AbstractModelDefinitionTypeInfo.java @@ -37,6 +37,7 @@ import gov.nist.secauto.metaschema.databind.codegen.typeinfo.IFlagInstanceTypeInfo; import gov.nist.secauto.metaschema.databind.codegen.typeinfo.IInstanceTypeInfo; import gov.nist.secauto.metaschema.databind.codegen.typeinfo.IPropertyTypeInfo; +import gov.nist.secauto.metaschema.databind.codegen.typeinfo.ITypeInfo; import gov.nist.secauto.metaschema.databind.codegen.typeinfo.ITypeResolver; import org.apache.logging.log4j.LogManager; @@ -73,8 +74,8 @@ public AbstractModelDefinitionTypeInfo( this.baseClassName = typeResolver.getBaseClassName(definition); this.flagTypeInfos = ObjectUtils.notNull(Lazy.lazy(() -> flags() .collect(CustomCollectors.toMap( - (typeInfo) -> typeInfo.getPropertyName(), - (typeInfo) -> typeInfo, + ITypeInfo::getPropertyName, + CustomCollectors.identity(), (key, v1, v2) -> { if (LOGGER.isErrorEnabled()) { LOGGER.error(String.format("Unexpected duplicate flag property name '%s'", key)); diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/typeinfo/def/AssemblyDefinitionTypeInfoImpl.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/typeinfo/def/AssemblyDefinitionTypeInfoImpl.java index 1ff07d649..77a361849 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/typeinfo/def/AssemblyDefinitionTypeInfoImpl.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/typeinfo/def/AssemblyDefinitionTypeInfoImpl.java @@ -45,6 +45,7 @@ import java.util.LinkedHashMap; import java.util.Map; +import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -67,8 +68,8 @@ public AssemblyDefinitionTypeInfoImpl(@NonNull IAssemblyDefinition definition, @ getFlagInstanceTypeInfos().stream(), processModel(definition)) .collect(CustomCollectors.toMap( - (typeInfo) -> typeInfo.getInstance(), - (typeInfo) -> typeInfo, + IInstanceTypeInfo::getInstance, + CustomCollectors.identity(), (key, v1, v2) -> { if (LOGGER.isErrorEnabled()) { LOGGER.error(String.format("Unexpected duplicate property name '%s'", key)); @@ -78,8 +79,8 @@ public AssemblyDefinitionTypeInfoImpl(@NonNull IAssemblyDefinition definition, @ LinkedHashMap::new)))); this.propertyNameToTypeInfoMap = ObjectUtils.notNull(Lazy.lazy(() -> getInstanceTypeInfoMap().values().stream() .collect(Collectors.toMap( - (typeInfo) -> typeInfo.getPropertyName(), - (typeInfo) -> typeInfo, + IInstanceTypeInfo::getPropertyName, + Function.identity(), (v1, v2) -> v2, LinkedHashMap::new)))); } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/typeinfo/def/FieldDefinitionTypeInfoImpl.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/typeinfo/def/FieldDefinitionTypeInfoImpl.java index 04573b260..078c00ac3 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/typeinfo/def/FieldDefinitionTypeInfoImpl.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/typeinfo/def/FieldDefinitionTypeInfoImpl.java @@ -31,6 +31,7 @@ import gov.nist.secauto.metaschema.core.util.CustomCollectors; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.metaschema.databind.codegen.typeinfo.IFieldValueTypeInfo; +import gov.nist.secauto.metaschema.databind.codegen.typeinfo.IFlagInstanceTypeInfo; import gov.nist.secauto.metaschema.databind.codegen.typeinfo.IInstanceTypeInfo; import gov.nist.secauto.metaschema.databind.codegen.typeinfo.IPropertyTypeInfo; import gov.nist.secauto.metaschema.databind.codegen.typeinfo.ITypeResolver; @@ -40,6 +41,7 @@ import java.util.LinkedHashMap; import java.util.Map; +import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -60,8 +62,8 @@ public FieldDefinitionTypeInfoImpl(@NonNull IFieldDefinition definition, @NonNul super(definition, typeResolver); this.instanceToTypeInfoMap = ObjectUtils.notNull(Lazy.lazy(() -> getFlagInstanceTypeInfos().stream() .collect(CustomCollectors.toMap( - (typeInfo) -> typeInfo.getInstance(), - (typeInfo) -> typeInfo, + IFlagInstanceTypeInfo::getInstance, + CustomCollectors.identity(), (key, v1, v2) -> { if (LOGGER.isErrorEnabled()) { LOGGER.error(String.format("Unexpected duplicate property name '%s'", key)); @@ -73,8 +75,8 @@ public FieldDefinitionTypeInfoImpl(@NonNull IFieldDefinition definition, @NonNul getInstanceTypeInfoMap().values().stream(), Stream.of((IPropertyTypeInfo) IFieldValueTypeInfo.newTypeInfo(this))) .collect(Collectors.toMap( - (typeInfo) -> typeInfo.getPropertyName(), - (typeInfo) -> typeInfo, + IPropertyTypeInfo::getPropertyName, + Function.identity(), (v1, v2) -> v2, LinkedHashMap::new)))); } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/io/Format.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/io/Format.java index 566f5a3eb..ec3d67b4b 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/io/Format.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/io/Format.java @@ -26,9 +26,13 @@ package gov.nist.secauto.metaschema.databind.io; +import gov.nist.secauto.metaschema.core.util.CollectionUtil; +import gov.nist.secauto.metaschema.core.util.ObjectUtils; + import java.util.Arrays; import java.util.List; import java.util.Locale; +import java.util.Set; import java.util.stream.Collectors; import edu.umd.cs.findbugs.annotations.NonNull; @@ -41,20 +45,20 @@ public enum Format { /** * The Extensible Markup Language format. */ - XML(".xml"), + XML(Set.of(".xml")), /** * The JavaScript Object Notation format. */ - JSON(".json"), + JSON(Set.of(".json")), /** * The YAML Ain't Markup Language format. */ - YAML(".yml"); + YAML(Set.of(".yml", ".yaml")); private static final List NAMES; @NonNull - private final String defaultExtension; + private final Set defaultExtensions; static { NAMES = Arrays.stream(values()) @@ -72,8 +76,8 @@ public static List names() { return NAMES; } - Format(@NonNull String defaultExtension) { - this.defaultExtension = defaultExtension; + Format(Set defaultExtensions) { + this.defaultExtensions = CollectionUtil.unmodifiableSet(ObjectUtils.requireNonNull(defaultExtensions)); } /** @@ -82,7 +86,7 @@ public static List names() { * @return the default extension */ @NonNull - public String getDefaultExtension() { - return defaultExtension; + public Set getDefaultExtension() { + return defaultExtensions; } } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/io/json/MetaschemaJsonReader.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/io/json/MetaschemaJsonReader.java index a033a95d6..fd208175c 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/io/json/MetaschemaJsonReader.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/io/json/MetaschemaJsonReader.java @@ -117,7 +117,7 @@ public MetaschemaJsonReader( @NonNull JsonParser parser, @NonNull IJsonProblemHandler problemHandler) throws IOException { this.problemHandler = problemHandler; - this.objectMapper = ObjectUtils.notNull(Lazy.lazy(() -> new ObjectMapper())); + this.objectMapper = ObjectUtils.notNull(Lazy.lazy(ObjectMapper::new)); push(parser); } @@ -278,7 +278,7 @@ public Object readItemField(Object parentItem, IBoundInstanceModelFieldComplex i parentItem, instance.getDefinition(), instance.getJsonProperties(), - instance.getJsonKey(), + instance.getEffectiveJsonKey(), getProblemHandler()); } @@ -295,7 +295,7 @@ public Object readItemField(Object parentItem, IBoundInstanceModelGroupedField i return readComplexDefinitionObject( parentItem, definition, - instance.getJsonKey(), + instance.getEffectiveJsonKey(), new PropertyBodyHandler(instance.getJsonProperties()), actualProblemHandler); } @@ -333,7 +333,7 @@ public Object readItemAssembly(Object parentItem, IBoundInstanceModelGroupedAsse return readComplexDefinitionObject( parentItem, instance.getDefinition(), - instance.getJsonKey(), + instance.getEffectiveJsonKey(), new PropertyBodyHandler(instance.getJsonProperties()), new GroupedInstanceProblemHandler(instance, getProblemHandler())); } @@ -511,11 +511,11 @@ public void accept( handled = true; } - if (!(handled || problemHandler.handleUnknownProperty( + if (!handled && !problemHandler.handleUnknownProperty( definition, parentItem, propertyName, - getInstanceReader()))) { + getInstanceReader())) { if (LOGGER.isWarnEnabled()) { LOGGER.warn("Skipping unhandled JSON field '{}' {}.", propertyName, JsonUtil.toString(parser)); } @@ -747,7 +747,6 @@ public Object readItem() throws IOException { IBoundInstanceModel instance = getCollectionInfo().getInstance(); return instance.readItem(getParentObject(), getItemReader()); } - } @SuppressWarnings("unchecked") @@ -771,7 +770,7 @@ public T readProperty( T retval = null; JsonToken token; - while (!(JsonToken.END_OBJECT.equals(token = parser.currentToken()) || token == null)) { + while (!JsonToken.END_OBJECT.equals(token = parser.currentToken()) && token != null) { if (!JsonToken.FIELD_NAME.equals(token)) { throw new IOException(String.format("Expected FIELD_NAME token, found '%s'", token.toString())); } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/io/json/MetaschemaJsonUtil.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/io/json/MetaschemaJsonUtil.java index 0d9a3ff62..dae2222fe 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/io/json/MetaschemaJsonUtil.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/io/json/MetaschemaJsonUtil.java @@ -76,7 +76,7 @@ private MetaschemaJsonUtil() { Collection flags = targetDefinition.getFlagInstances(); int flagCount = flags.size() - (jsonKey == null ? 0 : 1); - @SuppressWarnings("resource") Stream instanceStream; + Stream instanceStream; if (targetDefinition instanceof IBoundDefinitionModelAssembly) { // use all child instances instanceStream = ((IBoundDefinitionModelAssembly) targetDefinition).getModelInstances().stream() @@ -100,7 +100,7 @@ private MetaschemaJsonUtil() { if (jsonKey != null) { instanceStream = Stream.concat( - flags.stream().filter((flag) -> !jsonKey.equals(flag)), + flags.stream().filter(flag -> !jsonKey.equals(flag)), instanceStream); } else { instanceStream = Stream.concat( diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/io/xml/DefaultXmlDeserializer.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/io/xml/DefaultXmlDeserializer.java index 35c07b78b..4c4da37e9 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/io/xml/DefaultXmlDeserializer.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/io/xml/DefaultXmlDeserializer.java @@ -44,6 +44,7 @@ import java.net.URI; import javax.xml.stream.EventFilter; +import javax.xml.stream.XMLEventReader; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLResolver; import javax.xml.stream.XMLStreamException; @@ -99,21 +100,16 @@ private XMLInputFactory2 getXMLInputFactory() { xmlInputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, true); xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, true); xmlInputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, true); - xmlInputFactory.setProperty(XMLInputFactory.RESOLVER, new XMLResolver() { - - @Override - public Object resolveEntity(String publicID, String systemID, String baseURI, String namespace) - throws XMLStreamException { - URI base = URI.create(baseURI); - URI resource = base.resolve(systemID); - try { - return resource.toURL().openStream(); - } catch (IOException ex) { - throw new XMLStreamException(ex); - } - } - - }); + xmlInputFactory.setProperty(XMLInputFactory.RESOLVER, + (XMLResolver) (publicID, systemID, baseURI, namespace) -> { + URI base = URI.create(baseURI); + URI resource = base.resolve(systemID); + try { + return resource.toURL().openStream(); + } catch (IOException ex) { + throw new XMLStreamException(ex); + } + }); } } return ObjectUtils.notNull(xmlInputFactory); @@ -153,7 +149,7 @@ protected final IDocumentNodeItem deserializeToNodeItemInternal(Reader reader, U public final CLASS deserializeToValue(Reader reader, URI documentUri) throws IOException { // doesn't auto close the underlying reader try (AutoCloser closer = new AutoCloser<>( - newXMLEventReader2(documentUri, reader), event -> event.close())) { + newXMLEventReader2(documentUri, reader), XMLEventReader::close)) { return parseXmlInternal(closer.getResource()); } catch (XMLStreamException ex) { throw new IOException("Unable to create a new XMLEventReader2 instance.", ex); diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/io/xml/MetaschemaXmlWriter.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/io/xml/MetaschemaXmlWriter.java index 1ca2f3ca9..c3d71c366 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/io/xml/MetaschemaXmlWriter.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/io/xml/MetaschemaXmlWriter.java @@ -442,7 +442,9 @@ protected AbstractItemWriter(@NonNull QName parentQName) { } /** - * @return the startElement + * Get the qualified name of the item's parent. + * + * @return the qualified name */ @NonNull protected QName getParentQName() { diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/metapath/function/Model.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/metapath/function/Model.java index 176f4b6c4..e676430a3 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/metapath/function/Model.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/metapath/function/Model.java @@ -34,11 +34,9 @@ import gov.nist.secauto.metaschema.core.metapath.item.IItem; import gov.nist.secauto.metaschema.core.metapath.item.node.IDefinitionNodeItem; import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem; -import gov.nist.secauto.metaschema.core.model.IDefinition; import gov.nist.secauto.metaschema.core.model.INamedInstance; import gov.nist.secauto.metaschema.core.model.MetaschemaModelConstants; import gov.nist.secauto.metaschema.core.util.ObjectUtils; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBinding; import java.util.List; @@ -58,7 +56,7 @@ public final class Model { .focusIndependent() .contextIndependent() .deterministic() - .returnOne() + .returnZeroOrOne() .functionHandler(Model::execute) .build(); @@ -96,15 +94,8 @@ public static ISequence execute( public static INodeItem getModel(@NonNull IDefinitionNodeItem definitionNodeItem) { INamedInstance instance = definitionNodeItem.getInstance(); - INodeItem retval = null; - if (instance instanceof IBinding) { - retval = ((IBinding) instance).getBoundNodeItem(); - } else { - IDefinition definition = definitionNodeItem.getDefinition(); - if (definition instanceof IBinding) { - retval = ((IBinding) definition).getBoundNodeItem(); - } - } - return retval; + return instance != null + ? instance.getNodeItem() + : definitionNodeItem.getDefinition().getNodeItem(); } } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/AbstractBoundModule.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/AbstractBoundModule.java index 8929a7856..280e85d67 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/AbstractBoundModule.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/AbstractBoundModule.java @@ -43,6 +43,8 @@ import java.util.function.Function; import java.util.stream.Collectors; +import javax.xml.namespace.QName; + import edu.umd.cs.findbugs.annotations.NonNull; import nl.talsmasoftware.lazy4j.Lazy; @@ -57,9 +59,9 @@ public abstract class AbstractBoundModule @NonNull private final IBindingContext bindingContext; @NonNull - private final Lazy> assemblyDefinitions; + private final Lazy> assemblyDefinitions; @NonNull - private final Lazy> fieldDefinitions; + private final Lazy> fieldDefinitions; /** * Create a new Module instance for a given class annotated by the @@ -140,7 +142,7 @@ protected AbstractBoundModule( .requireNonNull(bindingContext.getBoundDefinitionForClass(clazz)); }) .collect(Collectors.toUnmodifiableMap( - IBoundDefinitionModelAssembly::getName, + IBoundDefinitionModelAssembly::getDefinitionQName, Function.identity())))); this.fieldDefinitions = ObjectUtils.notNull(Lazy.lazy(() -> Arrays.stream(getFieldClasses()) .map(clazz -> { @@ -149,7 +151,7 @@ protected AbstractBoundModule( .requireNonNull(bindingContext.getBoundDefinitionForClass(clazz)); }) .collect(Collectors.toUnmodifiableMap( - IBoundDefinitionModelField::getName, + IBoundDefinitionModelField::getDefinitionQName, Function.identity())))); } @@ -199,7 +201,7 @@ protected Class[] getFieldClasses() { * * @return the mapping */ - protected Map getAssemblyDefinitionMap() { + protected Map getAssemblyDefinitionMap() { return assemblyDefinitions.get(); } @@ -210,7 +212,7 @@ public Collection getAssemblyDefinitions() { } @Override - public IBoundDefinitionModelAssembly getAssemblyDefinitionByName(@NonNull String name) { + public IBoundDefinitionModelAssembly getAssemblyDefinitionByName(@NonNull QName name) { return getAssemblyDefinitionMap().get(name); } @@ -219,7 +221,7 @@ public IBoundDefinitionModelAssembly getAssemblyDefinitionByName(@NonNull String * * @return the mapping */ - protected Map getFieldDefinitionMap() { + protected Map getFieldDefinitionMap() { return fieldDefinitions.get(); } @@ -230,7 +232,7 @@ public Collection getFieldDefinitions() { } @Override - public IBoundDefinitionModelField getFieldDefinitionByName(@NonNull String name) { + public IBoundDefinitionModelField getFieldDefinitionByName(@NonNull QName name) { return getFieldDefinitionMap().get(name); } @@ -242,7 +244,7 @@ public Collection getFlagDefinitions() { } @Override - public IBoundDefinitionFlag getFlagDefinitionByName(@NonNull String name) { + public IBoundDefinitionFlag getFlagDefinitionByName(@NonNull QName name) { // Flags are always inline, so they do not have separate definitions return null; } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundContainerFlag.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundContainerFlag.java deleted file mode 100644 index 2f488944c..000000000 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundContainerFlag.java +++ /dev/null @@ -1,44 +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 java.util.Collection; - -import javax.xml.namespace.QName; - -import gov.nist.secauto.metaschema.core.model.IContainerFlag; - -public interface IBoundContainerFlag extends IContainerFlag { - @Override - IBoundInstanceFlag getFlagInstanceByName(QName name); - - @Override - Collection getFlagInstances(); - // - // @Override - // IBoundInstanceFlag getJsonKeyFlagInstance(); -} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundContainerModelAssembly.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundContainerModelAssembly.java index 6592eb78a..abbdbe15d 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundContainerModelAssembly.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundContainerModelAssembly.java @@ -26,6 +26,8 @@ package gov.nist.secauto.metaschema.databind.model; +import gov.nist.secauto.metaschema.core.model.IContainerModelAssembly; + import java.util.Collection; import java.util.Map; @@ -33,7 +35,6 @@ import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; -import gov.nist.secauto.metaschema.core.model.IContainerModelAssembly; public interface IBoundContainerModelAssembly extends IContainerModelAssembly { @Override diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundContainerModelChoiceGroup.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundContainerModelChoiceGroup.java index 640f6cc20..c8523e9f1 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundContainerModelChoiceGroup.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundContainerModelChoiceGroup.java @@ -26,20 +26,20 @@ package gov.nist.secauto.metaschema.databind.model; +import gov.nist.secauto.metaschema.core.model.IContainerModelGrouped; + import java.util.Collection; import javax.xml.namespace.QName; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; -import gov.nist.secauto.metaschema.core.model.IContainerModelGrouped; public interface IBoundContainerModelChoiceGroup extends IContainerModelGrouped { @Override - default Collection getModelInstances() { - return getNamedModelInstances(); - } + @NonNull + Collection getModelInstances(); @Override @NonNull 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 4ec46346e..e19dfebca 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 @@ -26,20 +26,29 @@ package gov.nist.secauto.metaschema.databind.model; -import gov.nist.secauto.metaschema.core.model.IModelDefinition; +import gov.nist.secauto.metaschema.core.model.IFeatureContainerFlag; +import gov.nist.secauto.metaschema.databind.IBindingContext; + +import edu.umd.cs.findbugs.annotations.NonNull; /** * Represents a field or assembly instance bound to Java data. */ -// REFACTOR: rename to IBoundDefinitionModelNamed +// REFACTOR: rename to IBoundDefinitionModel public interface IBoundDefinitionModel - extends IBoundDefinition, IBoundContainerFlag, IModelDefinition { - // @NonNull - // Class getBoundClass(); + extends IBoundModuleElement, IFeatureContainerFlag { + /** + * Get the binding context used for the definition. + * + * @return the binding context + */ + @NonNull + IBindingContext getBindingContext(); @Override IBoundInstanceModelNamed getInlineInstance(); - @Override - IBoundInstanceFlag getJsonKeyFlagInstance(); + // + // @Override + // IBoundInstanceFlag getJsonKeyFlagInstance(); } 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 58746ae9e..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 @@ -33,6 +33,7 @@ import java.io.IOException; import java.util.Map; +import java.util.function.Function; import java.util.function.Predicate; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -50,7 +51,6 @@ public interface IBoundDefinitionModelAssembly // Assembly Definition Features // ============================ - @Override @NonNull default IBoundDefinitionModelAssembly getOwningDefinition() { @@ -86,8 +86,7 @@ default Map getJsonProperties(@Nullable Predicate p.getJsonName(), (p) -> p))); + .collect(Collectors.toUnmodifiableMap(IBoundProperty::getJsonName, Function.identity()))); } @Override @@ -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/IBoundDefinitionModelComplex.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundDefinitionModelComplex.java index b629c9b44..ef39ace33 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundDefinitionModelComplex.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundDefinitionModelComplex.java @@ -27,13 +27,15 @@ package gov.nist.secauto.metaschema.databind.model; 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 java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.Map; import java.util.function.Predicate; -import javax.xml.namespace.QName; - import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; @@ -42,10 +44,105 @@ */ public interface IBoundDefinitionModelComplex extends IBoundDefinitionModel, IFeatureComplexItemValueHandler { - @Override - @NonNull - Class getBoundClass(); @NonNull Map getJsonProperties(@Nullable Predicate flagFilter); + + @Override + default boolean isInline() { + return getBoundClass().getEnclosingClass() != null; + } + + /** + * Gets a new instance of the bound class. + * + * @param + * the type of the bound class + * @return a Java object for the class + * @throws RuntimeException + * if the instance cannot be created due to a binding error + */ + @SuppressWarnings("PMD.AvoidThrowingRawExceptionTypes") + @Override + @NonNull + default CLASS newInstance() { + Class clazz = getBoundClass(); + try { + @SuppressWarnings("unchecked") Constructor constructor + = (Constructor) clazz.getDeclaredConstructor(); + return ObjectUtils.notNull(constructor.newInstance()); + } catch (NoSuchMethodException ex) { + String msg = String.format("Class '%s' does not have a required no-arg constructor.", clazz.getName()); + throw new RuntimeException(msg, ex); + } catch (InstantiationException | IllegalAccessException | InvocationTargetException ex) { + throw new RuntimeException(ex); + } + } + + @Nullable + Method getBeforeDeserializeMethod(); + + /** + * Calls the method named "beforeDeserialize" on each class in the object's + * hierarchy if the method exists on the class. + *

+ * These methods can be used to set the initial state of the target bound object + * before data is read and applied during deserialization. + * + * @param targetObject + * the data object target to call the method(s) on + * @param parentObject + * the object target's parent object, which is used as the method + * argument + * @throws BindingException + * if an error occurs while calling the method + */ + @Override + default void callBeforeDeserialize(Object targetObject, Object parentObject) throws BindingException { + Method beforeDeserializeMethod = getBeforeDeserializeMethod(); + if (beforeDeserializeMethod != null) { + try { + beforeDeserializeMethod.invoke(targetObject, parentObject); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { + throw new BindingException(ex); + } + } + } + + @Nullable + Method getAfterDeserializeMethod(); + + /** + * Calls the method named "afterDeserialize" on each class in the object's + * hierarchy if the method exists. + *

+ * These methods can be used to modify the state of the target bound object + * after data is read and applied during deserialization. + * + * @param targetObject + * the data object target to call the method(s) on + * @param parentObject + * the object target's parent object, which is used as the method + * argument + * @throws BindingException + * if an error occurs while calling the method + */ + @Override + default void callAfterDeserialize(Object targetObject, Object parentObject) throws BindingException { + Method afterDeserializeMethod = getAfterDeserializeMethod(); + if (afterDeserializeMethod != null) { + try { + afterDeserializeMethod.invoke(targetObject, parentObject); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { + throw new BindingException(ex); + } + } + } + + // @Override + // public String getJsonKeyFlagName() { + // // definition items never have a JSON key + // return null; + // } + } 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 5bd17bd3f..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 @@ -34,6 +34,7 @@ import java.io.IOException; import java.util.Collection; import java.util.Map; +import java.util.function.Function; import java.util.function.Predicate; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -116,7 +117,7 @@ default Map getJsonProperties(@Nullable Predicate jsonValueKeyFilter = (flag) -> !flag.equals(jsonValueKey); + Predicate jsonValueKeyFilter = flag -> !flag.equals(jsonValueKey); actualFlagFilter = actualFlagFilter == null ? jsonValueKeyFilter : actualFlagFilter.and(jsonValueKeyFilter); // ensure the field value is omitted too! fieldValue = null; @@ -144,8 +145,7 @@ default Map getJsonProperties(@Nullable Predicate p.getJsonName(), (p) -> p))); + .collect(Collectors.toUnmodifiableMap(IBoundProperty::getJsonName, Function.identity()))); } @Override @@ -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 06f17f442..25b4e017c 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 @@ -26,7 +26,6 @@ package gov.nist.secauto.metaschema.databind.model; -import gov.nist.secauto.metaschema.core.util.CollectionUtil; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.metaschema.databind.io.BindingException; import gov.nist.secauto.metaschema.databind.model.info.IFeatureScalarItemValueHandler; @@ -34,7 +33,6 @@ import gov.nist.secauto.metaschema.databind.model.info.IItemWriteHandler; import java.io.IOException; -import java.util.Collection; import javax.xml.namespace.QName; @@ -42,12 +40,6 @@ import edu.umd.cs.findbugs.annotations.Nullable; public interface IBoundFieldValue extends IFeatureScalarItemValueHandler, IBoundProperty { - - @Override - default IBoundFieldValue getInstance() { - return this; - } - @Override @Nullable Object getDefaultValue(); @@ -89,21 +81,6 @@ default Object getEffectiveDefaultValue() { return getDefaultValue(); } - @Override - default Object getValue(Object parent) { - return IBoundProperty.super.getValue(parent); - } - - @Override - default void setValue(Object parentObject, Object value) { - IBoundProperty.super.setValue(parentObject, value); - } - - @Override - default Collection getItemValues(Object value) { - return value == null ? CollectionUtil.emptyList() : CollectionUtil.singleton(value); - } - @Override default Object readItem(Object parent, IItemReadHandler handler) throws IOException { return handler.readItemFieldValue(ObjectUtils.requireNonNull(parent, "parent"), this); @@ -120,12 +97,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/IBoundInstance.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstance.java index 91884cce0..1f99e1306 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstance.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstance.java @@ -28,6 +28,9 @@ import gov.nist.secauto.metaschema.core.model.IInstance; +import edu.umd.cs.findbugs.annotations.NonNull; +import edu.umd.cs.findbugs.annotations.Nullable; + /** * Represents a Metaschema module instance bound to Java data. */ @@ -38,15 +41,21 @@ public interface IBoundInstance extends IBoundProperty, IInstance { /** * {@inheritDoc} *

- * An instance is contained in the parent definition's module. + * Always bound to a field. */ @Override - default IBoundModule getContainingModule() { - return getContainingDefinition().getContainingModule(); + @Nullable + default Object getValue(@NonNull Object parent) { + return IBoundProperty.super.getValue(parent); } + /** + * {@inheritDoc} + *

+ * Always bound to a field. + */ @Override - default Object getValue(Object parent) { - return IBoundProperty.super.getValue(parent); + default void setValue(@NonNull Object parentObject, @Nullable Object value) { + IBoundProperty.super.setValue(parentObject, value); } } 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 f04701ccf..7f0b8daa3 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,8 +26,8 @@ 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.CollectionUtil; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.metaschema.databind.io.BindingException; import gov.nist.secauto.metaschema.databind.model.impl.InstanceFlagInline; @@ -37,12 +37,10 @@ import java.io.IOException; import java.lang.reflect.Field; -import java.util.Collection; import javax.xml.namespace.QName; import edu.umd.cs.findbugs.annotations.NonNull; -import edu.umd.cs.findbugs.annotations.Nullable; /** * Represents a flag instance bound to Java data. @@ -50,7 +48,7 @@ public interface IBoundInstanceFlag extends IFlagInstance, IBoundDefinitionFlag, IFeatureScalarItemValueHandler, - IFeatureBoundDefinitionInline { + IBoundInstance, IFeatureDefinitionInstanceInlined { /** * Create a new bound flag instance. @@ -101,12 +99,6 @@ default IBoundDefinitionModel getParentContainer() { return getContainingDefinition(); } - @Override - @NonNull - default IBoundInstanceFlag getInstance() { - return this; - } - /** * {@inheritDoc} *

@@ -114,9 +106,7 @@ default IBoundInstanceFlag getInstance() { */ @Override @NonNull - default IBoundInstanceFlag getDefinition() { - return this; - } + IBoundDefinitionFlag getDefinition(); @Override @NonNull @@ -125,32 +115,6 @@ default IBoundInstanceFlag getInlineInstance() { return this; } - @Override - default Collection getItemValues(Object value) { - return value == null ? CollectionUtil.emptyList() : CollectionUtil.singleton(value); - } - - /** - * {@inheritDoc} - *

- * Always bound to a field. - */ - @Override - @Nullable - default Object getValue(@NonNull Object parent) { - return IFeatureBoundDefinitionInline.super.getValue(parent); - } - - /** - * {@inheritDoc} - *

- * Always bound to a field. - */ - @Override - default void setValue(@NonNull Object parentObject, @Nullable Object value) { - IFeatureBoundDefinitionInline.super.setValue(parentObject, value); - } - @Override default void deepCopy(@NonNull Object fromInstance, @NonNull Object toInstance) throws BindingException { Object value = getValue(fromInstance); @@ -170,11 +134,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/IBoundInstanceModel.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceModel.java index e8a3945b9..29839a477 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceModel.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceModel.java @@ -114,23 +114,4 @@ default Collection getItemValues(Object value) { @Nullable IBoundInstanceFlag getItemJsonKey(@NonNull Object item); - /** - * {@inheritDoc} - *

- * Always bound to a field. - */ - @Override - default Object getValue(Object parent) { - return IBoundInstance.super.getValue(parent); - } - - /** - * {@inheritDoc} - *

- * Always bound to a field. - */ - @Override - default void setValue(Object parentObject, Object value) { - IBoundInstance.super.setValue(parentObject, value); - } } 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 4321e0943..7a7dd64c3 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 @@ -31,6 +31,7 @@ import gov.nist.secauto.metaschema.databind.IBindingContext; import gov.nist.secauto.metaschema.databind.io.BindingException; import gov.nist.secauto.metaschema.databind.model.impl.InstanceModelAssemblyComplex; +import gov.nist.secauto.metaschema.databind.model.info.IFeatureComplexItemValueHandler; import gov.nist.secauto.metaschema.databind.model.info.IItemReadHandler; import gov.nist.secauto.metaschema.databind.model.info.IItemWriteHandler; @@ -43,8 +44,7 @@ * Represents an assembly instance bound to Java field. */ public interface IBoundInstanceModelAssembly - extends IBoundInstanceModelNamedComplex, IAssemblyInstanceAbsolute { - + extends IBoundInstanceModelNamed, IAssemblyInstanceAbsolute, IFeatureComplexItemValueHandler { /** * Create a new bound assembly instance. * @@ -62,7 +62,10 @@ static IBoundInstanceModelAssembly newInstance( IBindingContext bindingContext = containingDefinition.getBindingContext(); IBoundDefinitionModel definition = bindingContext.getBoundDefinitionForClass(itemType); if (definition instanceof IBoundDefinitionModelAssembly) { - return new InstanceModelAssemblyComplex(field, (IBoundDefinitionModelAssembly) definition, containingDefinition); + return InstanceModelAssemblyComplex.newInstance( + field, + (IBoundDefinitionModelAssembly) definition, + containingDefinition); } throw new IllegalStateException(String.format( @@ -71,11 +74,6 @@ static IBoundInstanceModelAssembly newInstance( field.getDeclaringClass().getName())); } - @Override - default IBoundInstanceModelAssembly getInstance() { - return this; - } - @Override @NonNull IBoundDefinitionModelAssembly getDefinition(); 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 5465937a6..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 @@ -60,12 +60,7 @@ public interface IBoundInstanceModelChoiceGroup static IBoundInstanceModelChoiceGroup newInstance( @NonNull Field field, @NonNull IBoundDefinitionModelAssembly containingDefinition) { - return new InstanceModelChoiceGroup(field, containingDefinition); - } - - @Override - default IBoundInstanceModelChoiceGroup getInstance() { - return this; + return InstanceModelChoiceGroup.newInstance(field, containingDefinition); } @Override @@ -150,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/IBoundInstanceModelField.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceModelField.java index 2208c2a7b..d3307841f 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceModelField.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceModelField.java @@ -63,9 +63,9 @@ static IBoundInstanceModelField newInstance( IBoundInstanceModelField retval; if (definition == null) { - retval = new InstanceModelFieldScalar(field, containingDefinition); + retval = InstanceModelFieldScalar.newInstance(field, containingDefinition); } else if (definition instanceof DefinitionField) { - retval = new InstanceModelFieldComplex(field, (DefinitionField) definition, containingDefinition); + retval = InstanceModelFieldComplex.newInstance(field, (DefinitionField) definition, containingDefinition); } else { throw new IllegalStateException(String.format( "The field '%s' on class '%s' is not bound to a Metaschema field", diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceModelFieldComplex.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceModelFieldComplex.java index 4a83597f4..1616f8e41 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceModelFieldComplex.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceModelFieldComplex.java @@ -28,22 +28,14 @@ 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 gov.nist.secauto.metaschema.databind.model.info.IItemReadHandler; import gov.nist.secauto.metaschema.databind.model.info.IItemWriteHandler; import java.io.IOException; -import javax.xml.namespace.QName; - -import edu.umd.cs.findbugs.annotations.NonNull; - public interface IBoundInstanceModelFieldComplex - extends IBoundInstanceModelField, IBoundInstanceModelNamedComplex { - - @Override - default IBoundInstanceModelFieldComplex getInstance() { - return this; - } + extends IBoundInstanceModelField, IFeatureComplexItemValueHandler { @Override IBoundDefinitionModelFieldComplex getDefinition(); 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 ae319a54d..6d3b8f09b 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 @@ -26,65 +26,44 @@ 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.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; import java.io.IOException; -import edu.umd.cs.findbugs.annotations.NonNull; - public interface IBoundInstanceModelFieldScalar extends IBoundInstanceModelField, IBoundDefinitionModelField, IFeatureScalarItemValueHandler, - IFeatureBoundDefinitionInline { + IFeatureDefinitionInstanceInlined { // integrate above - - @Override - IBoundDefinitionModelAssembly getContainingDefinition(); - @Override - default IBoundInstanceModelFieldScalar getInstance() { - return this; - } - - /** - * {@inheritDoc} - *

- * For an inline instance, this instance is the definition. - */ - @Override - default IBoundInstanceModelFieldScalar getDefinition() { - return this; + default IBoundDefinitionModelField getDefinition() { + return IFeatureDefinitionInstanceInlined.super.getDefinition(); } @Override default IBoundInstanceModelFieldScalar getInlineInstance() { - // always inline - return this; + return IFeatureDefinitionInstanceInlined.super.getInlineInstance(); } @Override - default IBindingContext getBindingContext() { - return getContainingDefinition().getBindingContext(); - } + IBoundDefinitionModelAssembly getContainingDefinition(); - /** - * {@inheritDoc} - *

- * Use the effective name of the instance. - */ @Override - @NonNull - default String getJsonName() { - return IBoundInstanceModelField.super.getJsonName(); + default IContainerFlagSupport getFlagContainer() { + return IContainerFlagSupport.empty(); } @Override - IBoundInstanceFlag getJsonKeyFlagInstance(); + default IBoundInstanceFlag getJsonKey() { + // no flags + return null; + } @Override default IBoundInstanceFlag getItemJsonKey(Object item) { @@ -110,26 +89,6 @@ default IBoundInstanceFlag getJsonValueKeyFlagInstance() { return null; } - /** - * {@inheritDoc} - *

- * Always bound to a field. - */ - @Override - default Object getValue(Object parent) { - return IBoundInstanceModelField.super.getValue(parent); - } - - /** - * {@inheritDoc} - *

- * Always bound to a field. - */ - @Override - default void setValue(Object parentObject, Object value) { - IBoundInstanceModelField.super.setValue(parentObject, value); - } - @Override default Object readItem(Object parent, IItemReadHandler handler) throws IOException { return handler.readItemField(ObjectUtils.requireNonNull(parent, "parent"), this); @@ -139,5 +98,4 @@ default Object readItem(Object parent, IItemReadHandler handler) throws IOExcept default void writeItem(Object item, IItemWriteHandler handler) throws IOException { handler.writeItemField(item, this); } - } 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 b3c824ef6..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 @@ -26,14 +26,14 @@ package gov.nist.secauto.metaschema.databind.model; -import javax.xml.namespace.QName; - -import edu.umd.cs.findbugs.annotations.Nullable; 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; + /** * Represents a model instance that is a member of a choice group instance. */ @@ -45,12 +45,44 @@ public interface IBoundInstanceModelGroupedNamed @Override IBoundDefinitionModelComplex getDefinition(); + @Override @Nullable - default IBoundInstanceFlag getJsonKey() { - String jsonKeyName = getJsonKeyFlagName(); + default IBoundInstanceFlag getEffectiveJsonKey() { return JsonGroupAsBehavior.KEYED.equals(getParentContainer().getJsonGroupAsBehavior()) - ? ObjectUtils.requireNonNull(getDefinition().getFlagInstanceByName( - new QName(getXmlNamespace(), ObjectUtils.requireNonNull(jsonKeyName)))) + ? getJsonKey() : null; } + + @Override + default IBoundInstanceFlag getJsonKey() { + String name = getParentContainer().getJsonKeyFlagInstanceName(); + return name == null + ? 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 9136e50f1..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 @@ -26,17 +26,18 @@ package gov.nist.secauto.metaschema.databind.model; +import gov.nist.secauto.metaschema.core.model.INamedModelInstanceAbsolute; +import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior; + import java.util.Collection; import javax.xml.namespace.QName; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; -import gov.nist.secauto.metaschema.core.model.INamedModelInstanceAbsolute; -import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior; -import gov.nist.secauto.metaschema.core.util.ObjectUtils; -public interface IBoundInstanceModelNamed extends IBoundInstanceModel, INamedModelInstanceAbsolute { +public interface IBoundInstanceModelNamed + extends IBoundInstanceModel, INamedModelInstanceAbsolute { @Override @NonNull @@ -55,22 +56,21 @@ default Integer getIndex() { } @Override - default String getJsonName() { - return INamedModelInstanceAbsolute.super.getJsonName(); - } - @Nullable - default IBoundInstanceFlag getJsonKey() { - String jsonKeyName = getJsonKeyFlagName(); + default IBoundInstanceFlag getEffectiveJsonKey() { return JsonGroupAsBehavior.KEYED.equals(getJsonGroupAsBehavior()) - ? ObjectUtils.requireNonNull(getDefinition().getFlagInstanceByName( - getContainingModule().toFlagQName(ObjectUtils.requireNonNull(jsonKeyName)))) + ? getJsonKey() : null; } + @Override + default IBoundInstanceFlag getJsonKey() { + return getDefinition().getJsonKey(); + } + @Override default IBoundInstanceFlag getItemJsonKey(Object item) { - return getJsonKey(); + return getEffectiveJsonKey(); } @Override @@ -82,9 +82,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/IBoundInstanceModelNamedComplex.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceModelNamedComplex.java deleted file mode 100644 index f995a568d..000000000 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundInstanceModelNamedComplex.java +++ /dev/null @@ -1,35 +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.databind.model.info.IFeatureComplexItemValueHandler; - -public interface IBoundInstanceModelNamedComplex extends IBoundInstanceModelNamed, IFeatureComplexItemValueHandler { - - @Override - IBoundDefinitionModelComplex getDefinition(); -} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundModule.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundModule.java index 6b9f07381..ddad425e9 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundModule.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundModule.java @@ -32,6 +32,8 @@ import java.net.URI; import java.util.Collection; +import javax.xml.namespace.QName; + import edu.umd.cs.findbugs.annotations.NonNull; public interface IBoundModule @@ -60,11 +62,11 @@ default URI getLocation() { // NOPMD - intentional Collection getAssemblyDefinitions(); @Override - IBoundDefinitionModelAssembly getAssemblyDefinitionByName(@NonNull String name); + IBoundDefinitionModelAssembly getAssemblyDefinitionByName(@NonNull QName name); @Override Collection getFieldDefinitions(); @Override - IBoundDefinitionModelField getFieldDefinitionByName(@NonNull String name); + IBoundDefinitionModelField getFieldDefinitionByName(@NonNull QName name); } 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/IBoundProperty.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IBoundProperty.java index 1cb0b7e93..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,43 +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 java.util.Collection; - import edu.umd.cs.findbugs.annotations.NonNull; -public interface IBoundProperty extends IBoundModuleElement, IFeatureJavaField { - /** - * Get the Metaschema module instance associated with this binding. - * - * @return the instance - */ - @NonNull - IBoundProperty getInstance(); - - /** - * Get the JSON/YAML property/key name to use for serialization-related - * operations. - * - * @return the JSON name - */ - // REFACTOR: rename to getEffectiveJsonName - @NonNull - String getJsonName(); - - /** - * Get the individual item values for this property. - *

- * A property can be single- or multi-valued. This method gets each value in - * either case. - * - * @param propertyValue - * the value for the property, which can be multi-valued - * @return the item values - */ - Collection getItemValues(Object propertyValue); - +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 9f0f55962..000000000 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/IFeatureBoundDefinitionInline.java +++ /dev/null @@ -1,70 +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.IFeatureDefinitionInstanceInlined; - -import edu.umd.cs.findbugs.annotations.NonNull; - -// REFACTOR: Try to eliminate this interface in favor of IFeatureInlinedDefinitionInstance -public interface IFeatureBoundDefinitionInline< - DEFINITION extends IBoundDefinition, - INSTANCE extends IBoundInstanceNamed> - extends IBoundDefinition, 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 IBoundModule 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/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/BoundAssembly.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/annotations/BoundAssembly.java index 3e4cf04c8..24336d38b 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/annotations/BoundAssembly.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/annotations/BoundAssembly.java @@ -44,8 +44,7 @@ * Module assembly. *

* For XML serialization, the {@link #useName()} identifies the name of the - * element to use and the {@link #namespace()} identifies the namespace of this - * element. + * element to use for this element. *

* For JSON and YAML serializations, the {@link #useName()} identifies the * property/item name to use. @@ -97,17 +96,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; - /** * A non-negative number that indicates the minimum occurrence of the model * instance. diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/annotations/BoundField.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/annotations/BoundField.java index 21db7dfd4..a286fe730 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/annotations/BoundField.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/annotations/BoundField.java @@ -45,8 +45,7 @@ * Module field. *

* For XML serialization, the {@link #useName()} identifies the name of the - * element to use and the {@link #namespace()} identifies the namespace of this - * element. + * element to use for this element. *

* For JSON and YAML serializations, the {@link #useName()} identifies the * property/item name to use. @@ -127,16 +126,6 @@ @NonNull String defaultValue() default ModelUtil.NULL_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 - */ - String namespace() default ModelUtil.DEFAULT_STRING_VALUE; - /** * If the data type allows it, determines if the field's value must be wrapped * with an XML element. diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/annotations/BoundFlag.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/annotations/BoundFlag.java index 061188c30..d7bcdc12f 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/annotations/BoundFlag.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/annotations/BoundFlag.java @@ -89,18 +89,6 @@ */ int useIndex() default Integer.MIN_VALUE; - /** - * XML target namespace of the XML Schema element. - *

- * If the value is "##default", then namespace is derived from the namespace - * provided in the package-info. If the value is "##none", the namespace will be - * {@code null}. - * - * @return the namespace - */ - @NonNull - String namespace() default ModelUtil.NO_STRING_VALUE; - /** * The default value of the flag represented as a string. *

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..972c0cfca 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 @@ -42,8 +42,7 @@ * Module assembly. *

* For XML serialization, the {@link #useName()} identifies the name of the - * element to use and the {@link #namespace()} identifies the namespace of this - * element. + * element to use for this element. *

* For JSON and YAML serializations, the {@link #useName()} identifies the * property/item name to use. @@ -95,17 +94,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..b66939dff 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 @@ -43,8 +43,7 @@ * Module field. *

* For XML serialization, the {@link #useName()} identifies the name of the - * element to use and the {@link #namespace()} identifies the namespace of this - * element. + * element to use for this element. *

* For JSON and YAML serializations, the {@link #useName()} identifies the * property/item name to use. @@ -114,16 +113,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/AbstractBoundAnnotatedJavaField.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/AbstractBoundAnnotatedJavaField.java deleted file mode 100644 index b5a38f1da..000000000 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/AbstractBoundAnnotatedJavaField.java +++ /dev/null @@ -1,78 +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.model.IFeatureJavaField; -import gov.nist.secauto.metaschema.databind.model.annotations.ModelUtil; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Field; - -import edu.umd.cs.findbugs.annotations.NonNull; - -public abstract class AbstractBoundAnnotatedJavaField implements IFeatureJavaField { - @NonNull - private final Field javaField; - @NonNull - private final A annotation; - - /** - * Construct a new binding between a Java field and a binding Java annotation. - * - * @param javaField - * the bound Java field - * @param annotationClass - * the binding annotation Java class - */ - protected AbstractBoundAnnotatedJavaField( - @NonNull Field javaField, - @NonNull Class annotationClass) { - this.javaField = javaField; - this.annotation = ModelUtil.getAnnotation(javaField, annotationClass); - } - - /** - * Get the bound Java field. - * - * @return the bound Java field - */ - @Override - @NonNull - public Field getField() { - return javaField; - } - - /** - * Get the binding Java annotation. - * - * @return the binding Java annotation - */ - @NonNull - public A getAnnotation() { - return annotation; - } -} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/AbstractBoundDefinitionModelComplex.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/AbstractBoundDefinitionModelComplex.java index 64d613e47..830efe92a 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/AbstractBoundDefinitionModelComplex.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/AbstractBoundDefinitionModelComplex.java @@ -32,19 +32,18 @@ import gov.nist.secauto.metaschema.databind.model.IBoundDefinitionModelComplex; import gov.nist.secauto.metaschema.databind.model.IBoundInstanceFlag; import gov.nist.secauto.metaschema.databind.model.IBoundModule; -import gov.nist.secauto.metaschema.databind.model.annotations.ModelUtil; import java.lang.annotation.Annotation; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import javax.xml.namespace.QName; + import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; import nl.talsmasoftware.lazy4j.Lazy; public abstract class AbstractBoundDefinitionModelComplex - implements IFeatureBoundContainerFlag, IBoundDefinitionModelComplex { + implements IBoundDefinitionModelComplex { @NonNull private final Class clazz; @NonNull @@ -53,6 +52,10 @@ public abstract class AbstractBoundDefinitionModelComplex private final IBindingContext bindingContext; @NonNull private final Lazy module; + @NonNull + private final Lazy qname; + @NonNull + private final Lazy definitionQName; @Nullable private final Method beforeDeserializeMethod; @Nullable @@ -60,12 +63,15 @@ public abstract class AbstractBoundDefinitionModelComplex protected AbstractBoundDefinitionModelComplex( @NonNull Class clazz, - @NonNull Class annotationClass, + @NonNull A annotation, + @NonNull Class moduleClass, @NonNull IBindingContext bindingContext) { this.clazz = clazz; - this.annotation = ModelUtil.getAnnotation(clazz, annotationClass); + this.annotation = annotation; this.bindingContext = bindingContext; - this.module = ObjectUtils.notNull(Lazy.lazy(() -> bindingContext.registerModule(getModuleClass()))); + this.module = ObjectUtils.notNull(Lazy.lazy(() -> bindingContext.registerModule(moduleClass))); + this.qname = ObjectUtils.notNull(Lazy.lazy(() -> getContainingModule().toModelQName(getEffectiveName()))); + this.definitionQName = ObjectUtils.notNull(Lazy.lazy(() -> getContainingModule().toModelQName(getName()))); this.beforeDeserializeMethod = ClassIntrospector.getMatchingMethod( clazz, "beforeDeserialize", @@ -76,9 +82,6 @@ protected AbstractBoundDefinitionModelComplex( Object.class); } - @NonNull - protected abstract Class getModuleClass(); - @Override public Class getBoundClass() { return clazz; @@ -88,11 +91,6 @@ public A getAnnotation() { return annotation; } - @Override - public boolean isInline() { - return getBoundClass().getEnclosingClass() != null; - } - @Override @NonNull public IBoundModule getContainingModule() { @@ -105,82 +103,31 @@ public IBindingContext getBindingContext() { return bindingContext; } - /** - * Gets a new instance of the bound class. - * - * @param - * the type of the bound class - * @return a Java object for the class - * @throws RuntimeException - * if the instance cannot be created due to a binding error - */ - @SuppressWarnings("PMD.AvoidThrowingRawExceptionTypes") + @SuppressWarnings("null") @Override - @NonNull - public CLASS newInstance() { - Class clazz = getBoundClass(); - try { - @SuppressWarnings("unchecked") Constructor constructor - = (Constructor) clazz.getDeclaredConstructor(); - return ObjectUtils.notNull(constructor.newInstance()); - } catch (NoSuchMethodException ex) { - String msg = String.format("Class '%s' does not have a required no-arg constructor.", clazz.getName()); - throw new RuntimeException(msg, ex); - } catch (InstantiationException | IllegalAccessException | InvocationTargetException ex) { - throw new RuntimeException(ex); - } + public final QName getXmlQName() { + return qname.get(); } - /** - * Calls the method named "beforeDeserialize" on each class in the object's - * hierarchy if the method exists on the class. - *

- * These methods can be used to set the initial state of the target bound object - * before data is read and applied during deserialization. - * - * @param targetObject - * the data object target to call the method(s) on - * @param parentObject - * the object target's parent object, which is used as the method - * argument - * @throws BindingException - * if an error occurs while calling the method - */ + @SuppressWarnings("null") @Override - public void callBeforeDeserialize(Object targetObject, Object parentObject) throws BindingException { - if (beforeDeserializeMethod != null) { - try { - beforeDeserializeMethod.invoke(targetObject, parentObject); - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { - throw new BindingException(ex); - } - } + public final QName getDefinitionQName() { + return definitionQName.get(); } - /** - * Calls the method named "afterDeserialize" on each class in the object's - * hierarchy if the method exists. - *

- * These methods can be used to modify the state of the target bound object - * after data is read and applied during deserialization. - * - * @param targetObject - * the data object target to call the method(s) on - * @param parentObject - * the object target's parent object, which is used as the method - * argument - * @throws BindingException - * if an error occurs while calling the method - */ @Override - public void callAfterDeserialize(Object targetObject, Object parentObject) throws BindingException { - if (afterDeserializeMethod != null) { - try { - afterDeserializeMethod.invoke(targetObject, parentObject); - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { - throw new BindingException(ex); - } - } + public boolean isInline() { + return getBoundClass().getEnclosingClass() != null; + } + + @Override + public Method getBeforeDeserializeMethod() { + return beforeDeserializeMethod; + } + + @Override + public Method getAfterDeserializeMethod() { + return afterDeserializeMethod; } // @Override diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/AbstractBoundInstanceField.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/AbstractBoundInstanceField.java deleted file mode 100644 index 36d3e82ea..000000000 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/AbstractBoundInstanceField.java +++ /dev/null @@ -1,140 +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.core.datatype.markup.MarkupLine; -import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline; -import gov.nist.secauto.metaschema.databind.model.IBoundDefinitionModelAssembly; -import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelField; -import gov.nist.secauto.metaschema.databind.model.IGroupAs; -import gov.nist.secauto.metaschema.databind.model.annotations.BoundField; -import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs; -import gov.nist.secauto.metaschema.databind.model.annotations.ModelUtil; - -import java.lang.reflect.Field; - -import edu.umd.cs.findbugs.annotations.NonNull; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; - -// TODO: implement getProperties() -public abstract class AbstractBoundInstanceField - extends AbstractBoundInstanceModelJavaField - implements IBoundInstanceModelField { - @NonNull - private final IGroupAs groupAs; - - /** - * Construct a new field instance bound to a Java field. - * - * @param javaField - * the Java field bound to this instance - * @param containingDefinition - * the definition containing this instance - */ - @SuppressFBWarnings(value = "CT_CONSTRUCTOR_THROW", justification = "Use of final fields") - protected AbstractBoundInstanceField( - @NonNull Field javaField, - @NonNull IBoundDefinitionModelAssembly containingDefinition) { - super(javaField, BoundField.class, containingDefinition); - this.groupAs = ModelUtil.groupAs( - getAnnotation().groupAs(), - () -> containingDefinition.getXmlNamespace()); - 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.", - javaField.getName(), - javaField.getDeclaringClass().getName(), - GroupAs.class.getName())); // NOPMD false positive - } - } else if (!IGroupAs.SINGLETON_GROUP_AS.equals(this.groupAs)) { - // max is 1 and a groupAs is set - throw new IllegalStateException( - String.format( - "Field '%s' on class '%s' has the '%s' annotation, but maxOccurs=1. A groupAs must not be specfied.", - javaField.getName(), - javaField.getDeclaringClass().getName(), - GroupAs.class.getName())); // NOPMD false positive - } - } - - // ------------------------------------------ - // - Start annotation driven code - CPD-OFF - - // ------------------------------------------ - - @Override - public IGroupAs getGroupAs() { - return groupAs; - } - - @Override - public String getFormalName() { - return ModelUtil.resolveNoneOrValue(getAnnotation().formalName()); - } - - @Override - public MarkupLine getDescription() { - return ModelUtil.resolveToMarkupLine(getAnnotation().description()); - } - - @Override - public Integer getUseIndex() { - int value = getAnnotation().useIndex(); - return value == Integer.MIN_VALUE ? null : value; - } - - @Override - public String getXmlNamespace() { - return ModelUtil.resolveOptionalNamespace( - getAnnotation().namespace(), - () -> getContainingDefinition().getXmlNamespace()); - } - - @Override - public boolean isInXmlWrapped() { - return getAnnotation().inXmlWrapped(); - } - - @Override - public final int getMinOccurs() { - return getAnnotation().minOccurs(); - } - - @Override - public final int getMaxOccurs() { - return getAnnotation().maxOccurs(); - } - - @Override - public MarkupMultiline getRemarks() { - return ModelUtil.resolveToMarkupMultiline(getAnnotation().remarks()); - } - - // @Override - // public String getJsonKeyFlagName() { - // return IBoundInstanceModelField.super.getJsonKeyFlagName(); - // } -} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/AbstractBoundInstanceJavaField.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/AbstractBoundInstanceJavaField.java deleted file mode 100644 index 0778d737a..000000000 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/AbstractBoundInstanceJavaField.java +++ /dev/null @@ -1,60 +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.model.IBoundDefinitionModel; -import gov.nist.secauto.metaschema.databind.model.IBoundInstance; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Field; - -import edu.umd.cs.findbugs.annotations.NonNull; - -public abstract class AbstractBoundInstanceJavaField - extends AbstractBoundAnnotatedJavaField - implements IBoundInstance { - @NonNull - private final P containingDefinition; - - protected AbstractBoundInstanceJavaField( - @NonNull Field javaField, - @NonNull Class annotationClass, - @NonNull P containingDefinition) { - super(javaField, annotationClass); - this.containingDefinition = containingDefinition; - } - - @Override - public P getContainingDefinition() { - return containingDefinition; - } - - @Override - public P getParentContainer() { - return containingDefinition; - } -} 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 980e4b371..000000000 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/AbstractBoundInstanceModelGroupedNamed.java +++ /dev/null @@ -1,93 +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 getJsonKeyFlagName() { - return getParentContainer().getJsonKeyFlagName(); - } - - @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/AbstractBoundInstanceModelJavaField.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/AbstractBoundInstanceModelJavaField.java deleted file mode 100644 index f3b639c9a..000000000 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/AbstractBoundInstanceModelJavaField.java +++ /dev/null @@ -1,85 +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.core.util.ObjectUtils; -import gov.nist.secauto.metaschema.databind.io.BindingException; -import gov.nist.secauto.metaschema.databind.model.IBoundDefinitionModelAssembly; -import gov.nist.secauto.metaschema.databind.model.info.IModelInstanceCollectionInfo; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Field; - -import edu.umd.cs.findbugs.annotations.NonNull; -import nl.talsmasoftware.lazy4j.Lazy; - -public abstract class AbstractBoundInstanceModelJavaField - extends AbstractBoundInstanceJavaField - implements IFeatureInstanceModelGroupAs { - - @NonNull - private final Lazy collectionInfo; - - public AbstractBoundInstanceModelJavaField( - @NonNull Field javaField, - @NonNull Class annotationClass, - @NonNull IBoundDefinitionModelAssembly containingDefinition) { - super(javaField, annotationClass, containingDefinition); - this.collectionInfo = ObjectUtils.notNull(Lazy.lazy(() -> IModelInstanceCollectionInfo.of(this))); - } - - /** - * Gets information about the bound property. - * - * @return the collection information for the bound property - */ - @SuppressWarnings("null") - @Override - @NonNull - public IModelInstanceCollectionInfo getCollectionInfo() { - return collectionInfo.get(); - } - // - // @Override - // public Object getValue(Object parent) { - // return IFeatureInstanceModelGroupAs.super.getValue(parent); - // } - - @Override - public void setValue(Object parentObject, Object value) { - IFeatureInstanceModelGroupAs.super.setValue(parentObject, value); - } - - @Override - public void deepCopy(@NonNull Object fromInstance, @NonNull Object toInstance) throws BindingException { - Object value = getValue(fromInstance); - if (value != null) { - value = getCollectionInfo().deepCopyItems(fromInstance, toInstance); - } - setValue(toInstance, value); - } -} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/AssemblyModelContainerSupport.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/AssemblyModelContainerSupport.java index f3b0f09e8..650580461 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/AssemblyModelContainerSupport.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/AssemblyModelContainerSupport.java @@ -26,21 +26,6 @@ package gov.nist.secauto.metaschema.databind.model.impl; -import java.lang.reflect.Field; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import javax.xml.namespace.QName; - -import edu.umd.cs.findbugs.annotations.NonNull; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; - import gov.nist.secauto.metaschema.core.model.IChoiceInstance; import gov.nist.secauto.metaschema.core.model.IContainerModelAssemblySupport; import gov.nist.secauto.metaschema.core.util.CollectionUtil; @@ -56,6 +41,21 @@ import gov.nist.secauto.metaschema.databind.model.annotations.BoundField; import gov.nist.secauto.metaschema.databind.model.annotations.Ignore; +import java.lang.reflect.Field; +import java.util.Arrays; +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import javax.xml.namespace.QName; + +import edu.umd.cs.findbugs.annotations.NonNull; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + class AssemblyModelContainerSupport implements IContainerModelAssemblySupport< IBoundInstanceModel, diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/ConstraintSupport.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/ConstraintSupport.java index fad12f9f4..eb69d743a 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/ConstraintSupport.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/ConstraintSupport.java @@ -63,19 +63,19 @@ public static void parse( // NOPMD - intentional try { Arrays.stream(valueAnnotation.lets()) .map(annotation -> ConstraintFactory.newLetExpression(annotation, source)) - .forEachOrdered(let -> set.addLetExpression(let)); + .forEachOrdered(set::addLetExpression); Arrays.stream(valueAnnotation.allowedValues()) .map(annotation -> ConstraintFactory.newAllowedValuesConstraint(annotation, source)) - .forEachOrdered(constraint -> set.addConstraint(constraint)); + .forEachOrdered(set::addConstraint); Arrays.stream(valueAnnotation.matches()) .map(annotation -> ConstraintFactory.newMatchesConstraint(annotation, source)) - .forEachOrdered(constraint -> set.addConstraint(constraint)); + .forEachOrdered(set::addConstraint); Arrays.stream(valueAnnotation.indexHasKey()) .map(annotation -> ConstraintFactory.newIndexHasKeyConstraint(annotation, source)) - .forEachOrdered(constraint -> set.addConstraint(constraint)); + .forEachOrdered(set::addConstraint); Arrays.stream(valueAnnotation.expect()) .map(annotation -> ConstraintFactory.newExpectConstraint(annotation, source)) - .forEachOrdered(constraint -> set.addConstraint(constraint)); + .forEachOrdered(set::addConstraint); } catch (MetapathException ex) { throw new MetapathException( String.format("Unable to compile a Metapath in '%s'. %s", source.getSource(), ex.getLocalizedMessage()), @@ -104,15 +104,15 @@ public static void parse( // NOPMD - intentional try { Arrays.stream(assemblyAnnotation.index()) .map(annotation -> ConstraintFactory.newIndexConstraint(annotation, source)) - .forEachOrdered(constraint -> set.addConstraint(constraint)); + .forEachOrdered(set::addConstraint); Arrays.stream(assemblyAnnotation.unique()) .map(annotation -> ConstraintFactory.newUniqueConstraint(annotation, source)) - .forEachOrdered(constraint -> set.addConstraint(constraint)); + .forEachOrdered(set::addConstraint); Arrays.stream(assemblyAnnotation.cardinality()) .map(annotation -> ConstraintFactory.newCardinalityConstraint(annotation, source)) - .forEachOrdered(constraint -> set.addConstraint(constraint)); + .forEachOrdered(set::addConstraint); } catch (MetapathException ex) { throw new MetapathException( String.format("Unable to compile a Metapath in '%s'. %s", source.getSource(), ex.getLocalizedMessage()), 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/DefinitionAssembly.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/DefinitionAssembly.java index 0e19ded94..6ae6a8e4c 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/DefinitionAssembly.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/DefinitionAssembly.java @@ -35,7 +35,6 @@ import gov.nist.secauto.metaschema.databind.IBindingContext; import gov.nist.secauto.metaschema.databind.io.BindingException; import gov.nist.secauto.metaschema.databind.model.IBoundDefinitionModelAssembly; -import gov.nist.secauto.metaschema.databind.model.IBoundInstanceFlag; import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModel; import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelAssembly; import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelChoiceGroup; @@ -57,7 +56,7 @@ import nl.talsmasoftware.lazy4j.Lazy; //TODO: implement getProperties() -public class DefinitionAssembly +public final class DefinitionAssembly extends AbstractBoundDefinitionModelComplex implements IBoundDefinitionModelAssembly, IFeatureBoundContainerModelAssembly< @@ -66,6 +65,7 @@ public class DefinitionAssembly IBoundInstanceModelField, IBoundInstanceModelAssembly, IBoundInstanceModelChoiceGroup> { + @NonNull private final Lazy flagContainer; @NonNull @@ -77,25 +77,25 @@ public class DefinitionAssembly @NonNull private final Lazy> jsonProperties; - public DefinitionAssembly( + public static DefinitionAssembly newInstance( + @NonNull Class clazz, + @NonNull IBindingContext bindingContext) { + MetaschemaAssembly annotation = ModelUtil.getAnnotation(clazz, MetaschemaAssembly.class); + Class moduleClass = annotation.moduleClass(); + return new DefinitionAssembly(clazz, annotation, moduleClass, bindingContext); + } + + private DefinitionAssembly( @NonNull Class clazz, + @NonNull MetaschemaAssembly annotation, + @NonNull Class moduleClass, @NonNull IBindingContext bindingContext) { - super(clazz, MetaschemaAssembly.class, bindingContext); + super(clazz, annotation, moduleClass, bindingContext); String rootLocalName = ModelUtil.resolveNoneOrDefault(getAnnotation().rootName(), null); - this.xmlRootQName = ObjectUtils.notNull(Lazy.lazy(() -> { - QName retval = null; - if (rootLocalName != null) { - String namespace = ModelUtil.resolveOptionalNamespace( - getAnnotation().rootNamespace(), - () -> getContainingModule().getXmlNamespace().toASCIIString()); - if (namespace == null) { - namespace = getXmlNamespace(); - } - retval = new QName(namespace, rootLocalName); - } - return retval; - })); + this.xmlRootQName = ObjectUtils.notNull(Lazy.lazy(() -> rootLocalName == null + ? null + : getContainingModule().toModelQName(rootLocalName))); this.flagContainer = ObjectUtils.notNull(Lazy.lazy(() -> new FlagContainerSupport(this, null))); this.modelContainer = ObjectUtils.notNull(Lazy.lazy(() -> new AssemblyModelContainerSupport(this))); this.constraints = ObjectUtils.notNull(Lazy.lazy(() -> { @@ -124,6 +124,11 @@ protected void deepCopyItemInternal(Object fromObject, Object toObject) throws B } } + @Override + public Map getJsonProperties() { + return ObjectUtils.notNull(jsonProperties.get()); + } + // ------------------------------------------ // - Start annotation driven code - CPD-OFF - // ------------------------------------------ @@ -135,11 +140,6 @@ public FlagContainerSupport getFlagContainer() { return flagContainer.get(); } - @Override - public IBoundInstanceFlag getJsonKeyFlagInstance() { - return getFlagContainer().getJsonKeyFlagInstance(); - } - @Override @SuppressWarnings("null") @NonNull @@ -153,11 +153,6 @@ public IModelConstrained getConstraintSupport() { return ObjectUtils.notNull(constraints.get()); } - @Override - public Map getJsonProperties() { - return ObjectUtils.notNull(jsonProperties.get()); - } - @Override @Nullable public String getFormalName() { @@ -188,12 +183,6 @@ public MarkupMultiline getRemarks() { return ModelUtil.resolveToMarkupMultiline(getAnnotation().description()); } - @Override - @NonNull - protected Class getModuleClass() { - return getAnnotation().moduleClass(); - } - @Override @Nullable public QName getRootXmlQName() { diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/DefinitionField.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/DefinitionField.java index b4d7ab2f3..a66ff1bde 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/DefinitionField.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/DefinitionField.java @@ -53,11 +53,10 @@ import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import nl.talsmasoftware.lazy4j.Lazy; //TODO: implement getProperties() -public class DefinitionField +public final class DefinitionField extends AbstractBoundDefinitionModelComplex implements IBoundDefinitionModelFieldComplex { @NonNull @@ -84,12 +83,7 @@ private static Field getFieldValueField(Class clazz) { Field retval = null; for (Field field : fields) { - if (!field.isAnnotationPresent(BoundFieldValue.class)) { - // skip fields that aren't a field or assembly instance - continue; - } - - if (field.isAnnotationPresent(Ignore.class)) { + if (!field.isAnnotationPresent(BoundFieldValue.class) || field.isAnnotationPresent(Ignore.class)) { // skip this field, since it is ignored continue; } @@ -113,12 +107,23 @@ private static Field getFieldValueField(Class clazz) { * the Java class the definition is bound to * @param bindingContext * the Metaschema binding context managing this class + * @return the instance */ - @SuppressFBWarnings(value = "CT_CONSTRUCTOR_THROW", justification = "Use of final fields, except JSON key") - public DefinitionField( + @NonNull + public static DefinitionField newInstance( + @NonNull Class clazz, + @NonNull IBindingContext bindingContext) { + MetaschemaField annotation = ModelUtil.getAnnotation(clazz, MetaschemaField.class); + Class moduleClass = annotation.moduleClass(); + return new DefinitionField(clazz, annotation, moduleClass, bindingContext); + } + + private DefinitionField( @NonNull Class clazz, + @NonNull MetaschemaField annotation, + @NonNull Class moduleClass, @NonNull IBindingContext bindingContext) { - super(clazz, MetaschemaField.class, bindingContext); + super(clazz, annotation, moduleClass, bindingContext); Field field = getFieldValueField(getBoundClass()); if (field == null) { throw new IllegalArgumentException( @@ -126,7 +131,7 @@ public DefinitionField( clazz.getName(), BoundFieldValue.class.getName())); // NOPMD false positive } - this.fieldValue = new FieldValue(field, BoundFieldValue.class); + this.fieldValue = new FieldValue(field, BoundFieldValue.class, bindingContext); this.flagContainer = ObjectUtils.notNull(Lazy.lazy(() -> new FlagContainerSupport(this, this::handleFlagInstance))); this.constraints = ObjectUtils.notNull(Lazy.lazy(() -> { IModelConstrained retval = new AssemblyConstraintSet(); @@ -136,7 +141,7 @@ public DefinitionField( })); this.jsonProperties = ObjectUtils.notNull(Lazy.lazy(() -> { IBoundInstanceFlag jsonValueKey = getJsonValueKeyFlagInstance(); - Predicate flagFilter = jsonValueKey == null ? null : (flag) -> !flag.equals(jsonValueKey); + Predicate flagFilter = jsonValueKey == null ? null : flag -> !flag.equals(jsonValueKey); return getJsonProperties(flagFilter); })); } @@ -185,11 +190,6 @@ public FlagContainerSupport getFlagContainer() { return flagContainer.get(); } - @Override - public IBoundInstanceFlag getJsonKeyFlagInstance() { - return getFlagContainer().getJsonKeyFlagInstance(); - } - @Override @NonNull public IValueConstrained getConstraintSupport() { @@ -231,16 +231,13 @@ public MarkupMultiline getRemarks() { return ModelUtil.resolveToMarkupMultiline(getAnnotation().description()); } - @Override - @NonNull - protected Class getModuleClass() { - return getAnnotation().moduleClass(); - } - protected class FieldValue - extends AbstractBoundAnnotatedJavaField implements IBoundFieldValue { @NonNull + private final Field javaField; + @NonNull + private final BoundFieldValue annotation; + @NonNull private final IDataTypeAdapter javaTypeAdapter; @Nullable private final Object defaultValue; @@ -252,15 +249,40 @@ protected class FieldValue * the Java field the field value is bound to * @param annotationClass * the field value binding annotation Java class + * @param bindingContext + * the Metaschema binding context managing this class */ protected FieldValue( @NonNull Field javaField, - @NonNull Class annotationClass) { - super(javaField, annotationClass); + @NonNull Class annotationClass, + @NonNull IBindingContext bindingContext) { + this.javaField = javaField; + this.annotation = ModelUtil.getAnnotation(javaField, annotationClass); this.javaTypeAdapter = ModelUtil.getDataTypeAdapter( - getAnnotation().typeAdapter(), - getBindingContext()); - this.defaultValue = ModelUtil.resolveNullOrValue(getAnnotation().defaultValue(), this.javaTypeAdapter); + this.annotation.typeAdapter(), + bindingContext); + this.defaultValue = ModelUtil.resolveNullOrValue(this.annotation.defaultValue(), this.javaTypeAdapter); + } + + /** + * Get the bound Java field. + * + * @return the bound Java field + */ + @Override + @NonNull + public Field getField() { + return javaField; + } + + /** + * Get the binding Java annotation. + * + * @return the binding Java annotation + */ + @NonNull + public BoundFieldValue getAnnotation() { + return annotation; } @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 d88292805..e6cdc5bea 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 @@ -26,6 +26,14 @@ package gov.nist.secauto.metaschema.databind.model.impl; +import gov.nist.secauto.metaschema.core.model.IContainerFlagSupport; +import gov.nist.secauto.metaschema.core.util.CollectionUtil; +import gov.nist.secauto.metaschema.core.util.ObjectUtils; +import gov.nist.secauto.metaschema.databind.model.IBoundDefinitionModelComplex; +import gov.nist.secauto.metaschema.databind.model.IBoundInstanceFlag; +import gov.nist.secauto.metaschema.databind.model.annotations.BoundFlag; +import gov.nist.secauto.metaschema.databind.model.annotations.Ignore; + import java.lang.reflect.Field; import java.util.Collection; import java.util.Collections; @@ -44,13 +52,6 @@ import edu.umd.cs.findbugs.annotations.Nullable; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import gov.nist.secauto.metaschema.core.model.IContainerFlagSupport; -import gov.nist.secauto.metaschema.core.util.CollectionUtil; -import gov.nist.secauto.metaschema.core.util.ObjectUtils; -import gov.nist.secauto.metaschema.databind.model.IBoundInstanceFlag; -import gov.nist.secauto.metaschema.databind.model.annotations.BoundFlag; -import gov.nist.secauto.metaschema.databind.model.annotations.Ignore; - public class FlagContainerSupport implements IContainerFlagSupport { @NonNull private final Map flagInstances; @@ -60,7 +61,7 @@ public class FlagContainerSupport implements IContainerFlagSupport definition, + @NonNull IBoundDefinitionModelComplex definition, @Nullable Consumer peeker) { Class clazz = definition.getBoundClass(); @@ -111,12 +112,7 @@ protected static Collection getFlagInstanceFields(Class clazz) { } for (Field field : fields) { - if (!field.isAnnotationPresent(BoundFlag.class)) { - // skip non-flag fields - continue; - } - - if (field.isAnnotationPresent(Ignore.class)) { + if (!field.isAnnotationPresent(BoundFlag.class) || field.isAnnotationPresent(Ignore.class)) { // skip this field, since it is ignored continue; } @@ -144,6 +140,7 @@ public Map getFlagInstanceMap() { return flagInstances; } + @Override public IBoundInstanceFlag getJsonKeyFlagInstance() { return jsonKeyFlag; } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/IFeatureBoundContainerModelAssembly.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/IFeatureBoundContainerModelAssembly.java index e64c9148b..abded64be 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/IFeatureBoundContainerModelAssembly.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/IFeatureBoundContainerModelAssembly.java @@ -26,13 +26,6 @@ package gov.nist.secauto.metaschema.databind.model.impl; -import java.util.Collection; -import java.util.List; -import java.util.Map; - -import javax.xml.namespace.QName; - -import edu.umd.cs.findbugs.annotations.NonNull; import gov.nist.secauto.metaschema.core.model.IChoiceInstance; import gov.nist.secauto.metaschema.core.model.IContainerModelAssemblySupport; import gov.nist.secauto.metaschema.core.model.IFeatureContainerModelAssembly; @@ -44,6 +37,14 @@ import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelField; import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelNamed; +import java.util.Collection; +import java.util.List; +import java.util.Map; + +import javax.xml.namespace.QName; + +import edu.umd.cs.findbugs.annotations.NonNull; + public interface IFeatureBoundContainerModelAssembly< MI extends IBoundInstanceModel, NMI extends IBoundInstanceModelNamed, diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/IFeatureBoundContainerModelChoiceGroup.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/IFeatureBoundContainerModelChoiceGroup.java index b4b03d538..a707fa3a9 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/IFeatureBoundContainerModelChoiceGroup.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/IFeatureBoundContainerModelChoiceGroup.java @@ -26,20 +26,26 @@ package gov.nist.secauto.metaschema.databind.model.impl; -import java.util.Collection; - -import javax.xml.namespace.QName; - -import edu.umd.cs.findbugs.annotations.NonNull; import gov.nist.secauto.metaschema.core.model.IContainerModelSupport; +import gov.nist.secauto.metaschema.core.model.IFeatureContainerModelGrouped; import gov.nist.secauto.metaschema.databind.model.IBoundContainerModelChoiceGroup; import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelGroupedAssembly; import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelGroupedField; import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelGroupedNamed; +import java.util.Collection; + +import javax.xml.namespace.QName; + +import edu.umd.cs.findbugs.annotations.NonNull; + public interface IFeatureBoundContainerModelChoiceGroup - extends IBoundContainerModelChoiceGroup { + extends IBoundContainerModelChoiceGroup, IFeatureContainerModelGrouped< + IBoundInstanceModelGroupedNamed, + IBoundInstanceModelGroupedField, + IBoundInstanceModelGroupedAssembly> { + @Override @NonNull IContainerModelSupport< IBoundInstanceModelGroupedNamed, @@ -47,6 +53,11 @@ public interface IFeatureBoundContainerModelChoiceGroup IBoundInstanceModelGroupedField, IBoundInstanceModelGroupedAssembly> getModelContainer(); + @Override + default Collection getModelInstances() { + return getModelContainer().getModelInstances(); + } + @Override default IBoundInstanceModelGroupedNamed getNamedModelInstanceByName(QName name) { return getModelContainer().getNamedModelInstanceMap().get(name); diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/IFeatureInstanceModelGroupAs.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/IFeatureInstanceModelGroupAs.java index 1b41acae5..cc2ee1b59 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/IFeatureInstanceModelGroupAs.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/IFeatureInstanceModelGroupAs.java @@ -28,6 +28,7 @@ import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior; import gov.nist.secauto.metaschema.core.model.XmlGroupAsBehavior; +import gov.nist.secauto.metaschema.databind.io.BindingException; import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModel; import gov.nist.secauto.metaschema.databind.model.IGroupAs; @@ -56,4 +57,13 @@ default JsonGroupAsBehavior getJsonGroupAsBehavior() { default XmlGroupAsBehavior getXmlGroupAsBehavior() { return getGroupAs().getXmlGroupAsBehavior(); } + + @Override + default void deepCopy(@NonNull Object fromInstance, @NonNull Object toInstance) throws BindingException { + Object value = getValue(fromInstance); + if (value != null) { + value = getCollectionInfo().deepCopyItems(fromInstance, toInstance); + } + setValue(toInstance, value); + } } 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 39a812c32..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 @@ -29,11 +29,12 @@ 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.AbstractInlineFlagDefinition; 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.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; import gov.nist.secauto.metaschema.databind.model.annotations.BoundFlag; @@ -55,9 +56,14 @@ */ // TODO: implement getProperties() public class InstanceFlagInline - extends AbstractBoundInstanceJavaField + extends AbstractInlineFlagDefinition + // extends AbstractBoundInstanceJavaField implements IBoundInstanceFlag { @NonNull + private final Field javaField; + @NonNull + private final BoundFlag annotation; + @NonNull private final IDataTypeAdapter javaTypeAdapter; @Nullable private final Object defaultValue; @@ -75,7 +81,9 @@ public class InstanceFlagInline public InstanceFlagInline( @NonNull Field javaField, @NonNull IBoundDefinitionModel containingDefinition) { - super(javaField, BoundFlag.class, containingDefinition); + super(containingDefinition); + this.javaField = javaField; + this.annotation = ModelUtil.getAnnotation(javaField, BoundFlag.class); Class> adapterClass = ObjectUtils.notNull(getAnnotation().typeAdapter()); this.javaTypeAdapter = ModelUtil.getDataTypeAdapter( adapterClass, @@ -90,6 +98,26 @@ public InstanceFlagInline( })); } + /** + * Get the bound Java field. + * + * @return the bound Java field + */ + @Override + @NonNull + public Field getField() { + return javaField; + } + + /** + * Get the binding Java annotation. + * + * @return the binding Java annotation + */ + @NonNull + private BoundFlag getAnnotation() { + return annotation; + } // ------------------------------------------ // - Start annotation driven code - CPD-OFF - // ------------------------------------------ @@ -149,24 +177,12 @@ public Integer getUseIndex() { return getAnnotation().useIndex(); } - @Override - public String getXmlNamespace() { - return ModelUtil.resolveOptionalNamespace( - getAnnotation().namespace(), - () -> getContainingDefinition().getXmlNamespace()); - } - @Override @Nullable 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/InstanceModelAssemblyComplex.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/InstanceModelAssemblyComplex.java index 9dd778047..d7fe1f13f 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 @@ -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.IBoundInstanceFlag; @@ -38,6 +38,7 @@ import gov.nist.secauto.metaschema.databind.model.annotations.BoundAssembly; import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs; import gov.nist.secauto.metaschema.databind.model.annotations.ModelUtil; +import gov.nist.secauto.metaschema.databind.model.info.IModelInstanceCollectionInfo; import java.lang.reflect.Field; import java.util.Map; @@ -52,10 +53,19 @@ * supported by a bound definition class. */ // TODO: implement getProperties() -public class InstanceModelAssemblyComplex - extends AbstractBoundInstanceModelJavaField - implements IBoundInstanceModelAssembly, - IFeatureDefinitionReferenceInstance { +public final class InstanceModelAssemblyComplex + extends AbstractAssemblyInstance< + IBoundDefinitionModelAssembly, + IBoundDefinitionModelAssembly, + IBoundInstanceModelAssembly, + IBoundDefinitionModelAssembly> + implements IBoundInstanceModelAssembly, IFeatureInstanceModelGroupAs { + @NonNull + private final Field javaField; + @NonNull + private final BoundAssembly annotation; + @NonNull + private final Lazy collectionInfo; @NonNull private final IBoundDefinitionModelAssembly definition; @NonNull @@ -73,40 +83,75 @@ public class InstanceModelAssemblyComplex * the assembly definition this instance is bound to * @param containingDefinition * the definition containing this instance + * @return the instance */ - @SuppressFBWarnings(value = "CT_CONSTRUCTOR_THROW", justification = "Use of final fields") - public InstanceModelAssemblyComplex( + @NonNull + public static InstanceModelAssemblyComplex newInstance( @NonNull Field javaField, @NonNull IBoundDefinitionModelAssembly definition, @NonNull IBoundDefinitionModelAssembly containingDefinition) { - super(javaField, BoundAssembly.class, containingDefinition); - this.definition = definition; - this.groupAs = ModelUtil.groupAs( - getAnnotation().groupAs(), - () -> containingDefinition.getXmlNamespace()); - if (getMaxOccurs() == -1 || getMaxOccurs() > 1) { - if (IGroupAs.SINGLETON_GROUP_AS.equals(this.groupAs)) { + BoundAssembly annotation = ModelUtil.getAnnotation(javaField, BoundAssembly.class); + IGroupAs groupAs = ModelUtil.groupAs(annotation.groupAs(), containingDefinition.getContainingModule()); + if (annotation.maxOccurs() == -1 || annotation.maxOccurs() > 1) { + if (IGroupAs.SINGLETON_GROUP_AS.equals(groupAs)) { throw new IllegalStateException(String.format("Field '%s' on class '%s' is missing the '%s' annotation.", - getField().getName(), + javaField.getName(), containingDefinition.getBoundClass().getName(), GroupAs.class.getName())); } - } else if (!IGroupAs.SINGLETON_GROUP_AS.equals(this.groupAs)) { + } else if (!IGroupAs.SINGLETON_GROUP_AS.equals(groupAs)) { // max is 1 and a groupAs is set throw new IllegalStateException( String.format( "Field '%s' on class '%s' has the '%s' annotation, but maxOccurs=1. A groupAs must not be specfied.", - getField().getName(), + javaField.getName(), containingDefinition.getBoundClass().getName(), GroupAs.class.getName())); } + return new InstanceModelAssemblyComplex(javaField, annotation, groupAs, definition, containingDefinition); + } + + @SuppressFBWarnings(value = "CT_CONSTRUCTOR_THROW", justification = "Use of final fields") + private InstanceModelAssemblyComplex( + @NonNull Field javaField, + @NonNull BoundAssembly annotation, + @NonNull IGroupAs groupAs, + @NonNull IBoundDefinitionModelAssembly definition, + @NonNull IBoundDefinitionModelAssembly containingDefinition) { + super(containingDefinition); + this.javaField = javaField; + this.annotation = annotation; + this.groupAs = groupAs; + this.collectionInfo = ObjectUtils.notNull(Lazy.lazy(() -> IModelInstanceCollectionInfo.of(this))); + this.definition = definition; this.jsonProperties = ObjectUtils.notNull(Lazy.lazy(() -> { - IBoundInstanceFlag jsonKey = getJsonKey(); - Predicate flagFilter = jsonKey == null ? null : (flag) -> !jsonKey.equals(flag); + IBoundInstanceFlag jsonKey = getEffectiveJsonKey(); + Predicate flagFilter = jsonKey == null ? null : flag -> !jsonKey.equals(flag); return getDefinition().getJsonProperties(flagFilter); })); } + @Override + public Field getField() { + return javaField; + } + + /** + * Get the binding Java annotation. + * + * @return the binding Java annotation + */ + @NonNull + public BoundAssembly getAnnotation() { + return annotation; + } + + @SuppressWarnings("null") + @Override + public IModelInstanceCollectionInfo getCollectionInfo() { + return collectionInfo.get(); + } + // ------------------------------------------ // - Start annotation driven code - CPD-OFF - // ------------------------------------------ @@ -148,19 +193,12 @@ public Integer getUseIndex() { } @Override - public String getXmlNamespace() { - return ModelUtil.resolveOptionalNamespace( - getAnnotation().namespace(), - () -> getContainingDefinition().getXmlNamespace()); - } - - @Override - public final int getMinOccurs() { + public int getMinOccurs() { return getAnnotation().minOccurs(); } @Override - public final int getMaxOccurs() { + public int getMaxOccurs() { return getAnnotation().maxOccurs(); } 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 4a0eb0cea..f8c31c75e 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 @@ -26,6 +26,7 @@ package gov.nist.secauto.metaschema.databind.model.impl; +import gov.nist.secauto.metaschema.core.model.AbstractChoiceGroupInstance; import gov.nist.secauto.metaschema.core.model.IContainerModelSupport; import gov.nist.secauto.metaschema.core.util.CollectionUtil; import gov.nist.secauto.metaschema.core.util.CustomCollectors; @@ -42,6 +43,7 @@ import gov.nist.secauto.metaschema.databind.model.annotations.BoundGroupedField; import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs; import gov.nist.secauto.metaschema.databind.model.annotations.ModelUtil; +import gov.nist.secauto.metaschema.databind.model.info.IModelInstanceCollectionInfo; import java.lang.reflect.Field; import java.util.Arrays; @@ -49,6 +51,7 @@ import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; +import java.util.Map.Entry; import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -63,10 +66,21 @@ /** * Implements a Metaschema module choice group instance bound to a Java field. */ -public class InstanceModelChoiceGroup - extends AbstractBoundInstanceModelJavaField +public final class InstanceModelChoiceGroup + extends AbstractChoiceGroupInstance< + IBoundDefinitionModelAssembly, + IBoundInstanceModelGroupedNamed, + IBoundInstanceModelGroupedField, + IBoundInstanceModelGroupedAssembly> + // extends AbstractBoundInstanceModelJavaField implements IBoundInstanceModelChoiceGroup, - IFeatureBoundContainerModelChoiceGroup { + IFeatureBoundContainerModelChoiceGroup, IFeatureInstanceModelGroupAs { + @NonNull + private final Field javaField; + @NonNull + private final BoundChoiceGroup annotation; + @NonNull + private final Lazy collectionInfo; @NonNull private final IGroupAs groupAs; @NonNull @@ -83,55 +97,89 @@ public class InstanceModelChoiceGroup * * @param javaField * the Java field bound to this instance - * @param containingDefinition + * @param parent * the definition containing this instance + * @return the instance */ - @SuppressFBWarnings(value = "CT_CONSTRUCTOR_THROW", justification = "Use of final fields") - public InstanceModelChoiceGroup( + @NonNull + public static InstanceModelChoiceGroup newInstance( @NonNull Field javaField, - @NonNull IBoundDefinitionModelAssembly containingDefinition) { - super(javaField, BoundChoiceGroup.class, containingDefinition); - this.groupAs = ModelUtil.groupAs( - getAnnotation().groupAs(), - () -> containingDefinition.getXmlNamespace()); - if (getMaxOccurs() == -1 || getMaxOccurs() > 1) { - if (IGroupAs.SINGLETON_GROUP_AS.equals(this.groupAs)) { + @NonNull IBoundDefinitionModelAssembly parent) { + BoundChoiceGroup annotation = ModelUtil.getAnnotation(javaField, BoundChoiceGroup.class); + IGroupAs groupAs = ModelUtil.groupAs(annotation.groupAs(), parent.getContainingModule()); + if (annotation.maxOccurs() == -1 || annotation.maxOccurs() > 1) { + if (IGroupAs.SINGLETON_GROUP_AS.equals(groupAs)) { throw new IllegalStateException(String.format("Field '%s' on class '%s' is missing the '%s' annotation.", - getField().getName(), - containingDefinition.getBoundClass().getName(), + javaField.getName(), + parent.getBoundClass().getName(), GroupAs.class.getName())); } - } else if (!IGroupAs.SINGLETON_GROUP_AS.equals(this.groupAs)) { + } else if (!IGroupAs.SINGLETON_GROUP_AS.equals(groupAs)) { // max is 1 and a groupAs is set throw new IllegalStateException( String.format( "Field '%s' on class '%s' has the '%s' annotation, but maxOccurs=1. A groupAs must not be specfied.", - getField().getName(), - containingDefinition.getBoundClass().getName(), + javaField.getName(), + parent.getBoundClass().getName(), GroupAs.class.getName())); } + return new InstanceModelChoiceGroup(javaField, annotation, groupAs, parent); + } + + @SuppressFBWarnings(value = "CT_CONSTRUCTOR_THROW", justification = "Use of final fields") + private InstanceModelChoiceGroup( + @NonNull Field javaField, + @NonNull BoundChoiceGroup annotation, + @NonNull IGroupAs groupAs, + @NonNull IBoundDefinitionModelAssembly parent) { + super(parent); + this.javaField = javaField; + this.annotation = annotation; + this.groupAs = groupAs; + this.collectionInfo = ObjectUtils.notNull(Lazy.lazy(() -> IModelInstanceCollectionInfo.of(this))); this.modelContainer = ObjectUtils.notNull(Lazy.lazy(() -> new ChoiceGroupModelContainerSupport( - getAnnotation().assemblies(), - getAnnotation().fields(), + this.annotation.assemblies(), + this.annotation.fields(), this))); this.classToInstanceMap = ObjectUtils.notNull(Lazy.lazy(() -> Collections.unmodifiableMap( getNamedModelInstances().stream() .map(instance -> instance) .collect(Collectors.toMap( - item -> (Class) item.getDefinition().getBoundClass(), + item -> item.getDefinition().getBoundClass(), CustomCollectors.identity()))))); this.qnameToInstanceMap = ObjectUtils.notNull(Lazy.lazy(() -> Collections.unmodifiableMap( getNamedModelInstances().stream() .collect(Collectors.toMap( - item -> item.getXmlQName(), + IBoundInstanceModelGroupedNamed::getXmlQName, CustomCollectors.identity()))))); this.discriminatorToInstanceMap = ObjectUtils.notNull(Lazy.lazy(() -> Collections.unmodifiableMap( getNamedModelInstances().stream() .collect(Collectors.toMap( - item -> item.getEffectiveDisciminatorValue(), + IBoundInstanceModelGroupedNamed::getEffectiveDisciminatorValue, CustomCollectors.identity()))))); } + @Override + public Field getField() { + return javaField; + } + + /** + * Get the binding Java annotation. + * + * @return the binding Java annotation + */ + @NonNull + public BoundChoiceGroup getAnnotation() { + return annotation; + } + + @SuppressWarnings("null") + @Override + public IModelInstanceCollectionInfo getCollectionInfo() { + return collectionInfo.get(); + } + // ------------------------------------------ // - Start annotation driven code - CPD-OFF - // ------------------------------------------ @@ -201,16 +249,16 @@ public ChoiceGroupModelContainerSupport getModelContainer() { @Override public IBoundDefinitionModelAssembly getOwningDefinition() { - return getContainingDefinition(); + return getParentContainer(); } @Override - public final int getMinOccurs() { + public int getMinOccurs() { return getAnnotation().minOccurs(); } @Override - public final int getMaxOccurs() { + public int getMaxOccurs() { return getAnnotation().maxOccurs(); } @@ -220,13 +268,13 @@ public String getJsonDiscriminatorProperty() { } @Override - public String getJsonKeyFlagName() { + public String getJsonKeyFlagInstanceName() { return getAnnotation().jsonKey(); } @Override public IBoundInstanceFlag getItemJsonKey(Object item) { - String jsonKeyFlagName = getJsonKeyFlagName(); + String jsonKeyFlagName = getJsonKeyFlagInstanceName(); IBoundInstanceFlag retval = null; if (jsonKeyFlagName != null) { @@ -264,7 +312,7 @@ public ChoiceGroupModelContainerSupport( container); }) .collect(Collectors.toMap( - instance -> instance.getXmlQName(), + IBoundInstanceModelGroupedAssembly::getXmlQName, Function.identity(), CustomCollectors.useLastMapper(), LinkedHashMap::new)))); @@ -274,7 +322,7 @@ public ChoiceGroupModelContainerSupport( return IBoundInstanceModelGroupedField.newInstance(instance, container); }) .collect(Collectors.toMap( - instance -> instance.getXmlQName(), + IBoundInstanceModelGroupedField::getXmlQName, Function.identity(), CustomCollectors.useLastMapper(), LinkedHashMap::new)))); @@ -282,8 +330,8 @@ public ChoiceGroupModelContainerSupport( this.assemblyInstances.entrySet().stream(), this.fieldInstances.entrySet().stream()) .collect(Collectors.toMap( - entry -> entry.getKey(), - entry -> entry.getValue(), + Entry::getKey, + Entry::getValue, CustomCollectors.useLastMapper(), LinkedHashMap::new)))); } 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 9f3734450..b400efdde 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 @@ -26,7 +26,9 @@ package gov.nist.secauto.metaschema.databind.model.impl; -import gov.nist.secauto.metaschema.core.model.IFeatureDefinitionReferenceInstance; +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.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; @@ -34,7 +36,11 @@ import gov.nist.secauto.metaschema.databind.model.IBoundInstanceFlag; import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelFieldComplex; import gov.nist.secauto.metaschema.databind.model.IBoundProperty; +import gov.nist.secauto.metaschema.databind.model.IGroupAs; +import gov.nist.secauto.metaschema.databind.model.annotations.BoundField; +import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs; import gov.nist.secauto.metaschema.databind.model.annotations.ModelUtil; +import gov.nist.secauto.metaschema.databind.model.info.IModelInstanceCollectionInfo; import java.lang.reflect.Field; import java.util.Map; @@ -48,10 +54,21 @@ * Implements a Metaschema module field instance bound to a Java field, * supported by a bound definition class. */ -public class InstanceModelFieldComplex - extends AbstractBoundInstanceField - implements IBoundInstanceModelFieldComplex, - IFeatureDefinitionReferenceInstance { +public final class InstanceModelFieldComplex + extends AbstractFieldInstance< + IBoundDefinitionModelAssembly, + IBoundDefinitionModelFieldComplex, + IBoundInstanceModelFieldComplex, + IBoundDefinitionModelAssembly> + implements IBoundInstanceModelFieldComplex, IFeatureInstanceModelGroupAs { + @NonNull + private final Field javaField; + @NonNull + private final BoundField annotation; + @NonNull + private final Lazy collectionInfo; + @NonNull + private final IGroupAs groupAs; @NonNull private final DefinitionField definition; @NonNull @@ -59,6 +76,50 @@ public class InstanceModelFieldComplex @NonNull private final Lazy> jsonProperties; + public static InstanceModelFieldComplex newInstance( + @NonNull Field javaField, + @NonNull DefinitionField definition, + @NonNull IBoundDefinitionModelAssembly parent) { + BoundField annotation = ModelUtil.getAnnotation(javaField, BoundField.class); + if (!annotation.inXmlWrapped()) { + if (definition.hasChildren()) { // NOPMD efficiency + throw new IllegalStateException( + String.format("Field '%s' on class '%s' is requested to be unwrapped, but it has flags preventing this.", + javaField.getName(), + parent.getBoundClass().getName())); + } + if (!definition.getJavaTypeAdapter().isUnrappedValueAllowedInXml()) { + throw new IllegalStateException( + String.format( + "Field '%s' on class '%s' is requested to be unwrapped, but its data type '%s' does not allow this.", + javaField.getName(), + parent.getBoundClass().getName(), + definition.getJavaTypeAdapter().getPreferredName())); + } + } + + IGroupAs groupAs = ModelUtil.groupAs( + annotation.groupAs(), + parent.getContainingModule()); + if (annotation.maxOccurs() == -1 || annotation.maxOccurs() > 1) { + if (IGroupAs.SINGLETON_GROUP_AS.equals(groupAs)) { + throw new IllegalStateException(String.format("Field '%s' on class '%s' is missing the '%s' annotation.", + javaField.getName(), + javaField.getDeclaringClass().getName(), + GroupAs.class.getName())); // NOPMD false positive + } + } else if (!IGroupAs.SINGLETON_GROUP_AS.equals(groupAs)) { + // max is 1 and a groupAs is set + throw new IllegalStateException( + String.format( + "Field '%s' on class '%s' has the '%s' annotation, but maxOccurs=1. A groupAs must not be specfied.", + javaField.getName(), + javaField.getDeclaringClass().getName(), + GroupAs.class.getName())); // NOPMD false positive + } + return new InstanceModelFieldComplex(javaField, annotation, groupAs, definition, parent); + } + /** * Construct a new field instance bound to a Java field, supported by a bound * definition class. @@ -67,32 +128,23 @@ public class InstanceModelFieldComplex * the Java field bound to this instance * @param definition * the assembly definition this instance is bound to - * @param containingDefinition + * @param parent * the definition containing this instance */ @SuppressFBWarnings(value = "CT_CONSTRUCTOR_THROW", justification = "Use of final fields") - public InstanceModelFieldComplex( + private InstanceModelFieldComplex( @NonNull Field javaField, + @NonNull BoundField annotation, + @NonNull IGroupAs groupAs, @NonNull DefinitionField definition, - @NonNull IBoundDefinitionModelAssembly containingDefinition) { - super(javaField, containingDefinition); + @NonNull IBoundDefinitionModelAssembly parent) { + super(parent); + this.javaField = javaField; + this.annotation = annotation; + this.collectionInfo = ObjectUtils.notNull(Lazy.lazy(() -> IModelInstanceCollectionInfo.of(this))); + this.groupAs = groupAs; this.definition = definition; - if (!isEffectiveValueWrappedInXml()) { - if (definition.hasChildren()) { // NOPMD efficiency - throw new IllegalStateException( - String.format("Field '%s' on class '%s' is requested to be unwrapped, but it has flags preventing this.", - javaField.getName(), - containingDefinition.getBoundClass().getName())); - } else if (!getDefinition().getJavaTypeAdapter().isUnrappedValueAllowedInXml()) { - throw new IllegalStateException( - String.format( - "Field '%s' on class '%s' is requested to be unwrapped, but its data type '%s' does not allow this.", - javaField.getName(), - containingDefinition.getBoundClass().getName(), - getDefinition().getJavaTypeAdapter().getPreferredName())); - } - } this.defaultValue = ObjectUtils.notNull(Lazy.lazy(() -> { Object retval = null; if (getMaxOccurs() == 1) { @@ -115,20 +167,37 @@ public InstanceModelFieldComplex( })); this.jsonProperties = ObjectUtils.notNull(Lazy.lazy(() -> { Predicate flagFilter = null; - IBoundInstanceFlag jsonKey = getJsonKey(); + IBoundInstanceFlag jsonKey = getEffectiveJsonKey(); if (jsonKey != null) { - flagFilter = (flag) -> !jsonKey.equals(flag); + flagFilter = flag -> !jsonKey.equals(flag); } return getDefinition().getJsonProperties(flagFilter); })); } - // ------------------------------------------ - // - Start annotation driven code - CPD-OFF - - // ------------------------------------------ + @Override + public Field getField() { + return javaField; + } + /** + * Get the binding Java annotation. + * + * @return the binding Java annotation + */ + @NonNull + public BoundField getAnnotation() { + return annotation; + } + + @SuppressWarnings("null") @Override - public final DefinitionField getDefinition() { + public IModelInstanceCollectionInfo getCollectionInfo() { + return collectionInfo.get(); + } + + @Override + public DefinitionField getDefinition() { return definition; } @@ -142,8 +211,53 @@ public Map getJsonProperties() { return ObjectUtils.notNull(jsonProperties.get()); } + // ------------------------------------------ + // - Start annotation driven code - CPD-OFF - + // ------------------------------------------ + + @Override + public IGroupAs getGroupAs() { + return groupAs; + } + + @Override + public String getFormalName() { + return ModelUtil.resolveNoneOrValue(getAnnotation().formalName()); + } + + @Override + public MarkupLine getDescription() { + return ModelUtil.resolveToMarkupLine(getAnnotation().description()); + } + @Override public String getUseName() { return ModelUtil.resolveNoneOrValue(getAnnotation().useName()); } + + @Override + public Integer getUseIndex() { + int value = getAnnotation().useIndex(); + return value == Integer.MIN_VALUE ? null : value; + } + + @Override + public boolean isInXmlWrapped() { + return getAnnotation().inXmlWrapped(); + } + + @Override + public int getMinOccurs() { + return getAnnotation().minOccurs(); + } + + @Override + public int getMaxOccurs() { + return getAnnotation().maxOccurs(); + } + + @Override + public MarkupMultiline getRemarks() { + return ModelUtil.resolveToMarkupMultiline(getAnnotation().remarks()); + } } 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 214447623..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 @@ -27,16 +27,24 @@ package gov.nist.secauto.metaschema.databind.model.impl; import gov.nist.secauto.metaschema.core.datatype.IDataTypeAdapter; -import gov.nist.secauto.metaschema.core.model.IContainerFlagSupport; +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.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.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; 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; +import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs; import gov.nist.secauto.metaschema.databind.model.annotations.ModelUtil; import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints; +import gov.nist.secauto.metaschema.databind.model.info.IModelInstanceCollectionInfo; import java.lang.reflect.Field; import java.util.Optional; @@ -45,10 +53,22 @@ import edu.umd.cs.findbugs.annotations.Nullable; import nl.talsmasoftware.lazy4j.Lazy; -public class InstanceModelFieldScalar - extends AbstractBoundInstanceField - implements IBoundInstanceModelFieldScalar, - IFeatureBoundContainerFlag { +public final class InstanceModelFieldScalar + extends AbstractInlineFieldDefinition< + IBoundDefinitionModelAssembly, + IBoundDefinitionModelField, + IBoundInstanceModelFieldScalar, + IBoundDefinitionModelAssembly, + IBoundInstanceFlag> + implements IBoundInstanceModelFieldScalar, IFeatureInstanceModelGroupAs { + @NonNull + private final Field javaField; + @NonNull + private final BoundField annotation; + @NonNull + private final Lazy collectionInfo; + @NonNull + private final IGroupAs groupAs; @NonNull private final IDataTypeAdapter javaTypeAdapter; @Nullable @@ -61,39 +81,93 @@ public class InstanceModelFieldScalar * * @param javaField * the Java field bound to this instance + * @param annotation + * the field binding annotation + * @param groupAs + * the grouping info for the model instance * @param containingDefinition * the definition containing this instance + * @return the instance */ - public InstanceModelFieldScalar( + @NonNull + public static InstanceModelFieldScalar newInstance( + @NonNull Field javaField, + @NonNull IBoundDefinitionModelAssembly containingDefinition) { + BoundField annotation = ModelUtil.getAnnotation(javaField, BoundField.class); + IGroupAs groupAs = ModelUtil.groupAs( + annotation.groupAs(), + containingDefinition.getContainingModule()); + + if (annotation.maxOccurs() == -1 || annotation.maxOccurs() > 1) { + if (IGroupAs.SINGLETON_GROUP_AS.equals(groupAs)) { + throw new IllegalStateException(String.format("Field '%s' on class '%s' is missing the '%s' annotation.", + javaField.getName(), + javaField.getDeclaringClass().getName(), + GroupAs.class.getName())); // NOPMD false positive + } + } else if (!IGroupAs.SINGLETON_GROUP_AS.equals(groupAs)) { + // max is 1 and a groupAs is set + throw new IllegalStateException( + String.format( + "Field '%s' on class '%s' has the '%s' annotation, but maxOccurs=1. A groupAs must not be specfied.", + javaField.getName(), + javaField.getDeclaringClass().getName(), + GroupAs.class.getName())); // NOPMD false positive + } + + return new InstanceModelFieldScalar( + javaField, + annotation, + groupAs, + containingDefinition); + } + + private InstanceModelFieldScalar( @NonNull Field javaField, + @NonNull BoundField annotation, + @NonNull IGroupAs groupAs, @NonNull IBoundDefinitionModelAssembly containingDefinition) { - super(javaField, containingDefinition); + super(containingDefinition); + this.javaField = javaField; + this.annotation = annotation; + this.collectionInfo = ObjectUtils.notNull(Lazy.lazy(() -> IModelInstanceCollectionInfo.of(this))); + this.groupAs = groupAs; this.javaTypeAdapter = ModelUtil.getDataTypeAdapter( - getAnnotation().typeAdapter(), + annotation.typeAdapter(), containingDefinition.getBindingContext()); - this.defaultValue = ModelUtil.resolveDefaultValue(getAnnotation().defaultValue(), this.javaTypeAdapter); - + this.defaultValue = ModelUtil.resolveDefaultValue(annotation.defaultValue(), this.javaTypeAdapter); this.constraints = ObjectUtils.notNull(Lazy.lazy(() -> { IValueConstrained retval = new ValueConstraintSet(); - ValueConstraints valueAnnotation = getAnnotation().valueConstraints(); + ValueConstraints valueAnnotation = annotation.valueConstraints(); ConstraintSupport.parse(valueAnnotation, ISource.modelSource(), retval); return retval; })); } @Override - public IBoundInstanceFlag getJsonKeyFlagInstance() { - // no flags - return null; + public IBindingContext getBindingContext() { + return getContainingDefinition().getBindingContext(); } - // ------------------------------------------ - // - Start annotation driven code - CPD-OFF - - // ------------------------------------------ + @Override + public Field getField() { + return javaField; + } + + /** + * Get the binding Java annotation. + * + * @return the binding Java annotation + */ + @NonNull + public BoundField getAnnotation() { + return annotation; + } + @SuppressWarnings("null") @Override - public IContainerFlagSupport getFlagContainer() { - return IContainerFlagSupport.empty(); + public IModelInstanceCollectionInfo getCollectionInfo() { + return collectionInfo.get(); } @SuppressWarnings("null") @@ -108,6 +182,56 @@ public IDataTypeAdapter getJavaTypeAdapter() { return javaTypeAdapter; } + @Override + public Object getDefaultValue() { + return defaultValue; + } + + @Override + public IGroupAs getGroupAs() { + return groupAs; + } + + // ------------------------------------------ + // - Start annotation driven code - CPD-OFF - + // ------------------------------------------ + + @Override + public String getFormalName() { + return ModelUtil.resolveNoneOrValue(getAnnotation().formalName()); + } + + @Override + public MarkupLine getDescription() { + return ModelUtil.resolveToMarkupLine(getAnnotation().description()); + } + + @Override + public Integer getUseIndex() { + int value = getAnnotation().useIndex(); + return value == Integer.MIN_VALUE ? null : value; + } + + @Override + public boolean isInXmlWrapped() { + return getAnnotation().inXmlWrapped(); + } + + @Override + public int getMinOccurs() { + return getAnnotation().minOccurs(); + } + + @Override + public int getMaxOccurs() { + return getAnnotation().maxOccurs(); + } + + @Override + public MarkupMultiline getRemarks() { + return ModelUtil.resolveToMarkupMultiline(getAnnotation().remarks()); + } + @Override public String getName() { // the name is stored as a usename to remain consistent with non-scalar valued @@ -116,11 +240,6 @@ public String getName() { Optional.ofNullable(ModelUtil.resolveNoneOrValue(getAnnotation().useName())).orElse(getField().getName())); } - @Override - public Object getDefaultValue() { - return defaultValue; - } - // ---------------------------------------- // - End annotation driven code - CPD-OFF - // ---------------------------------------- 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 dfdc2e2ad..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,10 +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.AbstractAssemblyInstance; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.metaschema.databind.model.IBoundDefinitionModelAssembly; -import gov.nist.secauto.metaschema.databind.model.IBoundInstanceFlag; import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelChoiceGroup; import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelGroupedAssembly; import gov.nist.secauto.metaschema.databind.model.IBoundProperty; @@ -39,7 +38,6 @@ import gov.nist.secauto.metaschema.databind.model.annotations.ModelUtil; import java.util.Map; -import java.util.function.Predicate; import edu.umd.cs.findbugs.annotations.NonNull; import nl.talsmasoftware.lazy4j.Lazy; @@ -49,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 @@ -72,19 +76,29 @@ public InstanceModelGroupedAssembly( @NonNull BoundGroupedAssembly annotation, @NonNull IBoundDefinitionModelAssembly definition, @NonNull IBoundInstanceModelChoiceGroup container) { - super(annotation, container); + super(container); + this.annotation = annotation; this.definition = definition; - this.jsonProperties = ObjectUtils.notNull(Lazy.lazy(() -> { - IBoundInstanceFlag jsonKey = getJsonKey(); - Predicate flagFilter = jsonKey == null ? null : (flag) -> !jsonKey.equals(flag); - return getDefinition().getJsonProperties(flagFilter); - })); + // IBoundInstanceFlag jsonKey = getEffectiveJsonKey(); + // Predicate flagFilter = jsonKey == null ? null : (flag) -> + // !jsonKey.equals(flag); + // return getDefinition().getJsonProperties(flagFilter); + 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()); @@ -124,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 c58ee02f8..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,28 +65,38 @@ 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 = getJsonKey(); + IBoundInstanceFlag jsonKey = getEffectiveJsonKey(); if (jsonKey != null) { - flagFilter = (flag) -> !jsonKey.equals(flag); + flagFilter = flag -> !jsonKey.equals(flag); } IBoundInstanceFlag jsonValueKey = getDefinition().getJsonValueKeyFlagInstance(); if (jsonValueKey != null) { - Predicate jsonValueKeyFilter = (flag) -> !flag.equals(jsonValueKey); + Predicate jsonValueKeyFilter = flag -> !flag.equals(jsonValueKey); flagFilter = flagFilter == null ? jsonValueKeyFilter : flagFilter.and(jsonValueKeyFilter); } return getDefinition().getJsonProperties(flagFilter); })); } + 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/main/java/gov/nist/secauto/metaschema/databind/model/impl/package-info.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/package-info.java index 1316bbc9e..9c4d1cf32 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/package-info.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/package-info.java @@ -26,8 +26,8 @@ /** * Provides an implementation of the Module model - * ({@link gov.nist.secauto.metaschema.core.model}) representing module - * constructs as bound Java class annotations + * ({@link gov.nist.secauto.metaschema.core.model}) represented by bound Java + * class annotations * ({@link gov.nist.secauto.metaschema.databind.model.annotations}). */ diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/info/AbstractModelInstanceReadHandler.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/info/AbstractModelInstanceReadHandler.java index 21fc109c0..36b7e7b95 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/info/AbstractModelInstanceReadHandler.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/info/AbstractModelInstanceReadHandler.java @@ -26,10 +26,11 @@ package gov.nist.secauto.metaschema.databind.model.info; +import gov.nist.secauto.metaschema.databind.model.IBoundInstanceFlag; import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModel; +import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelNamed; import edu.umd.cs.findbugs.annotations.NonNull; -import edu.umd.cs.findbugs.annotations.Nullable; public abstract class AbstractModelInstanceReadHandler implements IModelInstanceReadHandler { @NonNull @@ -65,6 +66,8 @@ public IModelInstanceCollectionInfo getCollectionInfo() { } /** + * Get the object onto which parsed data will be stored. + * * @return the parentObject */ @NonNull @@ -73,8 +76,15 @@ public Object getParentObject() { } @Override - @Nullable public String getJsonKeyFlagName() { - return getCollectionInfo().getInstance().getJsonKeyFlagName(); + IBoundInstanceModel instance = getInstance(); + String retval = null; + if (instance instanceof IBoundInstanceModelNamed) { + IBoundInstanceFlag jsonKey = ((IBoundInstanceModelNamed) instance).getEffectiveJsonKey(); + if (jsonKey != null) { + retval = jsonKey.getEffectiveName(); + } + } + return retval; } } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/info/IFeatureComplexItemValueHandler.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/info/IFeatureComplexItemValueHandler.java index 58d6f9293..8e317dd8e 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/info/IFeatureComplexItemValueHandler.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/info/IFeatureComplexItemValueHandler.java @@ -56,6 +56,12 @@ public interface IFeatureComplexItemValueHandler extends IItemValueHandler { // @Nullable // String getJsonKeyFlagName(); + /** + * Get the mapping of JSON property names to property bindings. + * + * @return the mapping + */ + // REFACTOR: move JSON-specific methods to a binding cache implementation @NonNull Map getJsonProperties(); diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/info/IFeatureScalarItemValueHandler.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/info/IFeatureScalarItemValueHandler.java index d62b4763d..e1bd55c39 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/info/IFeatureScalarItemValueHandler.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/info/IFeatureScalarItemValueHandler.java @@ -28,17 +28,13 @@ import gov.nist.secauto.metaschema.core.datatype.IDataTypeAdapter; import gov.nist.secauto.metaschema.databind.io.BindingException; +import gov.nist.secauto.metaschema.databind.model.IValuedMutable; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; public interface IFeatureScalarItemValueHandler - extends IItemValueHandler { - - @Nullable - Object getValue(@NonNull Object parent); - - void setValue(@NonNull Object parent, Object value); + extends IItemValueHandler, IValuedMutable { default void setValue(@NonNull Object parent, @NonNull String text) { Object item = getValueFromString(text); diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/BindingConstraintLoader.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/BindingConstraintLoader.java index ee3d1899f..1fd75a523 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/BindingConstraintLoader.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/BindingConstraintLoader.java @@ -57,6 +57,7 @@ import gov.nist.secauto.metaschema.databind.io.IBoundLoader; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.MetapathContext; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.MetaschemaMetaConstraints; +import gov.nist.secauto.metaschema.databind.model.metaschema.binding.MetaschemaMetapath; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.MetaschemaModuleConstraints; import gov.nist.secauto.metaschema.databind.model.metaschema.impl.ConstraintBindingSupport; @@ -250,17 +251,15 @@ private Context parseContext( List metapaths; if (parent == null) { metapaths = CollectionUtil.listOrEmpty(contextObj.getMetapaths()).stream() - .map(metapath -> metapath.getTarget()) + .map(MetaschemaMetapath::getTarget) .collect(Collectors.toList()); } else { List parentMetapaths = parent.getMetapaths().stream() .collect(Collectors.toList()); metapaths = CollectionUtil.listOrEmpty(contextObj.getMetapaths()).stream() - .map(metapath -> metapath.getTarget()) - .flatMap(childPath -> { - return parentMetapaths.stream() - .map(parentPath -> parentPath + '/' + childPath); - }) + .map(MetaschemaMetapath::getTarget) + .flatMap(childPath -> parentMetapaths.stream() + .map(parentPath -> parentPath + '/' + childPath)) .collect(Collectors.toList()); } @@ -281,8 +280,6 @@ private static class Context { @NonNull private final List metapaths; @NonNull - private final IModelConstrained constraints; - @NonNull private final List childContexts = new LinkedList<>(); @NonNull private final Lazy> targetedConstraints; @@ -291,7 +288,6 @@ public Context( @NonNull List metapaths, @NonNull IModelConstrained constraints) { this.metapaths = metapaths; - this.constraints = constraints; this.targetedConstraints = ObjectUtils.notNull(Lazy.lazy(() -> { Stream paths = getMetapaths().stream() @@ -338,20 +334,18 @@ protected MetaTargetedContraints( * @param definition * the definition to apply the constraints to. */ - @SuppressWarnings("null") protected void applyTo(@NonNull IDefinition definition) { - getAllowedValuesConstraints().forEach(constraint -> definition.addConstraint(constraint)); - getMatchesConstraints().forEach(constraint -> definition.addConstraint(constraint)); - getIndexHasKeyConstraints().forEach(constraint -> definition.addConstraint(constraint)); - getExpectConstraints().forEach(constraint -> definition.addConstraint(constraint)); + getAllowedValuesConstraints().forEach(definition::addConstraint); + getMatchesConstraints().forEach(definition::addConstraint); + getIndexHasKeyConstraints().forEach(definition::addConstraint); + getExpectConstraints().forEach(definition::addConstraint); } - @SuppressWarnings("null") protected void applyTo(@NonNull IAssemblyDefinition definition) { applyTo((IDefinition) definition); - getIndexConstraints().forEach(constraint -> definition.addConstraint(constraint)); - getUniqueConstraints().forEach(constraint -> definition.addConstraint(constraint)); - getHasCardinalityConstraints().forEach(constraint -> definition.addConstraint(constraint)); + getIndexConstraints().forEach(definition::addConstraint); + getUniqueConstraints().forEach(definition::addConstraint); + getHasCardinalityConstraints().forEach(definition::addConstraint); } @Override diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/BindingModuleLoader.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/BindingModuleLoader.java index 7b45aa481..675aecaf5 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/BindingModuleLoader.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/BindingModuleLoader.java @@ -29,6 +29,7 @@ import gov.nist.secauto.metaschema.core.configuration.IConfiguration; import gov.nist.secauto.metaschema.core.configuration.IMutableConfiguration; import gov.nist.secauto.metaschema.core.model.AbstractModuleLoader; +import gov.nist.secauto.metaschema.core.model.IMetaschemaModule; import gov.nist.secauto.metaschema.core.model.IModuleLoader; import gov.nist.secauto.metaschema.core.model.MetaschemaException; import gov.nist.secauto.metaschema.core.util.CollectionUtil; @@ -38,6 +39,7 @@ import gov.nist.secauto.metaschema.databind.io.IBoundLoader; import gov.nist.secauto.metaschema.databind.model.IBoundDefinitionModelAssembly; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.METASCHEMA; +import gov.nist.secauto.metaschema.databind.model.metaschema.binding.METASCHEMA.Import; import gov.nist.secauto.metaschema.databind.model.metaschema.impl.BindingModule; import java.io.IOException; @@ -49,7 +51,7 @@ import edu.umd.cs.findbugs.annotations.NonNull; public class BindingModuleLoader - extends AbstractModuleLoader + extends AbstractModuleLoader implements IMutableConfiguration> { @NonNull private final IBoundLoader loader; @@ -78,7 +80,10 @@ public BindingModuleLoader(@NonNull List mod } @Override - protected IBindingModule newModule(URI resource, METASCHEMA binding, List importedModules) + protected IMetaschemaModule newModule( + URI resource, + METASCHEMA binding, + List importedModules) throws MetaschemaException { return new BindingModule( resource, @@ -92,7 +97,7 @@ protected IBindingModule newModule(URI resource, METASCHEMA binding, List getImports(METASCHEMA binding) { return ObjectUtils.notNull(binding.getImports().stream() - .map(imported -> imported.getHref()) + .map(Import::getHref) .collect(Collectors.toUnmodifiableList())); } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingContainerModelAbsolute.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingContainerModelAbsolute.java deleted file mode 100644 index d77d7cbfe..000000000 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingContainerModelAbsolute.java +++ /dev/null @@ -1,60 +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.metaschema; - -import java.util.Collection; - -import javax.xml.namespace.QName; - -import gov.nist.secauto.metaschema.core.model.IContainerModelAbsolute; - -public interface IBindingContainerModelAbsolute extends IContainerModelAbsolute { - - @Override - IBindingDefinitionAssembly getOwningDefinition(); - - @Override - Collection getModelInstances(); - - @Override - Collection getNamedModelInstances(); - - @Override - IBindingInstanceModelNamedAbsolute getNamedModelInstanceByName(QName name); - - @Override - Collection getFieldInstances(); - - @Override - IBindingInstanceModelFieldAbsolute getFieldInstanceByName(QName name); - - @Override - Collection getAssemblyInstances(); - - @Override - IBindingInstanceModelAssemblyAbsolute getAssemblyInstanceByName(QName name); -} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingContainerModelAssembly.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingContainerModelAssembly.java deleted file mode 100644 index 47f9d2144..000000000 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingContainerModelAssembly.java +++ /dev/null @@ -1,44 +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.metaschema; - -import gov.nist.secauto.metaschema.core.model.IContainerModelAssembly; - -import java.util.List; -import java.util.Map; - -public interface IBindingContainerModelAssembly extends IContainerModelAssembly, IBindingContainerModelAbsolute { - - @Override - List getChoiceInstances(); - - @Override - IInstanceModelChoiceGroupBinding getChoiceGroupInstanceByName(String name); - - @Override - Map getChoiceGroupInstances(); -} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingContainerModelGrouped.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingContainerModelGrouped.java deleted file mode 100644 index 1641c4e29..000000000 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingContainerModelGrouped.java +++ /dev/null @@ -1,62 +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.metaschema; - -import java.util.Collection; - -import javax.xml.namespace.QName; - -import gov.nist.secauto.metaschema.core.model.IContainerModelGrouped; - -public interface IBindingContainerModelGrouped extends IContainerModelGrouped { - - @Override - IBindingDefinitionAssembly getOwningDefinition(); - - @Override - default Collection getModelInstances() { - return getNamedModelInstances(); - } - - @Override - Collection getNamedModelInstances(); - - @Override - IBindingInstanceModelNamedGrouped getNamedModelInstanceByName(QName name); - - @Override - Collection getFieldInstances(); - - @Override - IBindingInstanceModelFieldGrouped getFieldInstanceByName(QName name); - - @Override - Collection getAssemblyInstances(); - - @Override - IBindingInstanceModelAssemblyGrouped getAssemblyInstanceByName(QName name); -} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingDefinition.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingDefinition.java deleted file mode 100644 index 1265b71e3..000000000 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingDefinition.java +++ /dev/null @@ -1,34 +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.metaschema; - -import gov.nist.secauto.metaschema.core.model.IDefinition; - -public interface IBindingDefinition extends IBindingModelElement, IDefinition { - @Override - IBindingModule getContainingModule(); -} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingDefinitionAssembly.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingDefinitionAssembly.java deleted file mode 100644 index c2f90fe47..000000000 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingDefinitionAssembly.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.metaschema; - -import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition; - -public interface IBindingDefinitionAssembly - extends IAssemblyDefinition, IBindingDefinitionModel, IBindingContainerModelAssembly { - - @Override - default IBindingDefinitionAssembly getOwningDefinition() { - return this; - } -} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingDefinitionModelField.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingDefinitionModelField.java deleted file mode 100644 index cc9ce7433..000000000 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingDefinitionModelField.java +++ /dev/null @@ -1,33 +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.metaschema; - -import gov.nist.secauto.metaschema.core.model.IFieldDefinition; - -public interface IBindingDefinitionModelField extends IFieldDefinition, IBindingDefinitionModel { - // no additional methods -} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceFlag.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceFlag.java deleted file mode 100644 index 6c127ea7b..000000000 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceFlag.java +++ /dev/null @@ -1,33 +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.metaschema; - -import gov.nist.secauto.metaschema.core.model.IFlagInstance; - -public interface IBindingInstanceFlag extends IFlagInstance, IBindingInstance { - // no additional methods -} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModel.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModel.java deleted file mode 100644 index 7f300b290..000000000 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModel.java +++ /dev/null @@ -1,35 +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.metaschema; - -import gov.nist.secauto.metaschema.core.model.IModelInstance; - -public interface IBindingInstanceModel extends IModelInstance, IBindingInstance { - - @Override - IBindingDefinitionAssembly getContainingDefinition(); -} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModelAssembly.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModelAssembly.java deleted file mode 100644 index d117a0af3..000000000 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModelAssembly.java +++ /dev/null @@ -1,34 +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.metaschema; - -import gov.nist.secauto.metaschema.core.model.IAssemblyInstance; - -public interface IBindingInstanceModelAssembly - extends IAssemblyInstance, IBindingInstanceModelNamed { - // no additional methods -} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModelAssemblyAbsolute.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModelAssemblyAbsolute.java deleted file mode 100644 index 0beeec970..000000000 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModelAssemblyAbsolute.java +++ /dev/null @@ -1,34 +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.metaschema; - -import gov.nist.secauto.metaschema.core.model.IAssemblyInstanceAbsolute; - -public interface IBindingInstanceModelAssemblyAbsolute - extends IBindingInstanceModelAssembly, IAssemblyInstanceAbsolute, IBindingInstanceModelNamedAbsolute { - // no additional methods -} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModelAssemblyGrouped.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModelAssemblyGrouped.java deleted file mode 100644 index 76d3c8747..000000000 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModelAssemblyGrouped.java +++ /dev/null @@ -1,34 +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.metaschema; - -import gov.nist.secauto.metaschema.core.model.IAssemblyInstanceGrouped; - -public interface IBindingInstanceModelAssemblyGrouped - extends IBindingInstanceModelAssembly, IAssemblyInstanceGrouped, IBindingInstanceModelNamedGrouped { - // no additional methods -} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModelField.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModelField.java deleted file mode 100644 index 028c29aa0..000000000 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModelField.java +++ /dev/null @@ -1,33 +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.metaschema; - -import gov.nist.secauto.metaschema.core.model.IFieldInstance; - -public interface IBindingInstanceModelField extends IFieldInstance, IBindingInstanceModelNamed { - // no additional methods -} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModelFieldAbsolute.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModelFieldAbsolute.java deleted file mode 100644 index 9377a27c8..000000000 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModelFieldAbsolute.java +++ /dev/null @@ -1,34 +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.metaschema; - -import gov.nist.secauto.metaschema.core.model.IFieldInstanceAbsolute; - -public interface IBindingInstanceModelFieldAbsolute - extends IBindingInstanceModelField, IFieldInstanceAbsolute, IBindingInstanceModelNamedAbsolute { - // no additional methods -} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModelFieldGrouped.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModelFieldGrouped.java deleted file mode 100644 index b1885edd4..000000000 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModelFieldGrouped.java +++ /dev/null @@ -1,34 +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.metaschema; - -import gov.nist.secauto.metaschema.core.model.IFieldInstanceGrouped; - -public interface IBindingInstanceModelFieldGrouped - extends IBindingInstanceModelField, IFieldInstanceGrouped, IBindingInstanceModelNamedGrouped { - // no additional methods -} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModelNamed.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModelNamed.java deleted file mode 100644 index 0705527a7..000000000 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModelNamed.java +++ /dev/null @@ -1,33 +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.metaschema; - -import gov.nist.secauto.metaschema.core.model.INamedModelInstance; - -public interface IBindingInstanceModelNamed extends IBindingInstanceModel, INamedModelInstance { - // no additional methods -} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModelNamedAbsolute.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModelNamedAbsolute.java deleted file mode 100644 index eef878a43..000000000 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModelNamedAbsolute.java +++ /dev/null @@ -1,34 +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.metaschema; - -import gov.nist.secauto.metaschema.core.model.INamedModelInstanceAbsolute; - -public interface IBindingInstanceModelNamedAbsolute - extends IBindingInstanceModelNamed, IBindingInstanceModelAbsolute, INamedModelInstanceAbsolute { - // no additional methods -} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModelNamedGrouped.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModelNamedGrouped.java deleted file mode 100644 index 19182e389..000000000 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingInstanceModelNamedGrouped.java +++ /dev/null @@ -1,34 +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.metaschema; - -import gov.nist.secauto.metaschema.core.model.INamedModelInstanceGrouped; - -public interface IBindingInstanceModelNamedGrouped extends IBindingInstanceModelNamed, INamedModelInstanceGrouped { - @Override - IBindingDefinitionAssembly getContainingDefinition(); -} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingModelElement.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingModelElement.java deleted file mode 100644 index 742350aff..000000000 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingModelElement.java +++ /dev/null @@ -1,34 +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.metaschema; - -import gov.nist.secauto.metaschema.core.model.IModelElement; - -public interface IBindingModelElement extends IBinding, IModelElement { - @Override - IBindingModule getContainingModule(); -} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingModule.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingModule.java deleted file mode 100644 index ed2b1baea..000000000 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingModule.java +++ /dev/null @@ -1,43 +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.metaschema; - -import gov.nist.secauto.metaschema.core.metapath.item.node.IDocumentNodeItem; -import gov.nist.secauto.metaschema.core.model.IModuleExtended; - -public interface IBindingModule - extends IModuleExtended< - IBindingModule, - IBindingDefinitionModel, - IBindingDefinitionFlag, - IBindingDefinitionModelField, - IBindingDefinitionAssembly>, - IBinding { - - @Override - IDocumentNodeItem getBoundNodeItem(); -} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IInstanceModelChoiceBinding.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IInstanceModelChoiceBinding.java deleted file mode 100644 index 7eeb41687..000000000 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IInstanceModelChoiceBinding.java +++ /dev/null @@ -1,39 +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.metaschema; - -import gov.nist.secauto.metaschema.core.model.IChoiceInstance; - -public interface IInstanceModelChoiceBinding - extends IBindingInstanceModelAbsolute, IChoiceInstance, IBindingContainerModelAbsolute { - - @Override - IBindingDefinitionAssembly getOwningDefinition(); - - @Override - IBindingDefinitionAssembly getContainingDefinition(); -} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IInstanceModelChoiceGroupBinding.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IInstanceModelChoiceGroupBinding.java deleted file mode 100644 index e441b0776..000000000 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IInstanceModelChoiceGroupBinding.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.metaschema; - -import gov.nist.secauto.metaschema.core.model.IChoiceGroupInstance; - -public interface IInstanceModelChoiceGroupBinding extends IBindingInstanceModelAbsolute, IChoiceGroupInstance { - - @Override - IBindingDefinitionAssembly getOwningDefinition(); - - @Override - IBindingDefinitionAssembly getContainingDefinition(); -} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/AssemblyConstraints.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/AssemblyConstraints.java index 47cf9db51..f51a776c3 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/AssemblyConstraints.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/AssemblyConstraints.java @@ -55,7 +55,7 @@ public class AssemblyConstraints implements IModelConstraintsBase { formalName = "Constraint Let Expression", useName = "let", maxOccurs = -1, - groupAs = @GroupAs(name = "lets", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "lets", inJson = JsonGroupAsBehavior.LIST)) private List _lets; @BoundChoiceGroup( @@ -77,7 +77,7 @@ public class AssemblyConstraints implements IModelConstraintsBase { @BoundGroupedAssembly(formalName = "Targeted Cardinality Constraint", useName = "has-cardinality", binding = TargetedHasCardinalityConstraint.class) }, - groupAs = @GroupAs(name = "rules", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "rules", inJson = JsonGroupAsBehavior.LIST)) private List _rules; @Override diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/AssemblyModel.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/AssemblyModel.java index c1f4df539..7e793c778 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/AssemblyModel.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/AssemblyModel.java @@ -77,7 +77,7 @@ public class AssemblyModel { @BoundGroupedAssembly(formalName = "Choice Grouping", useName = "choice-group", binding = ChoiceGroup.class) }, groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "instances", - namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + inJson = JsonGroupAsBehavior.LIST)) private List _instances; @BoundAssembly( @@ -159,7 +159,7 @@ public static class ChoiceGroup { binding = DefineField.class) }, groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "choices", - namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + inJson = JsonGroupAsBehavior.LIST)) private List _choices; @BoundField( @@ -271,7 +271,7 @@ public static class Assembly { useName = "prop", maxOccurs = -1, groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "props", - namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + inJson = JsonGroupAsBehavior.LIST)) private List _props; @BoundField( @@ -440,7 +440,7 @@ public static class DefineAssembly { useName = "prop", maxOccurs = -1, groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "props", - namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + inJson = JsonGroupAsBehavior.LIST)) private List _props; @BoundField( @@ -457,7 +457,7 @@ public static class DefineAssembly { @BoundGroupedAssembly(formalName = "Flag Reference", useName = "flag", binding = FlagReference.class) }, groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "flags", - namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + inJson = JsonGroupAsBehavior.LIST)) private List _flags; @BoundAssembly( @@ -479,7 +479,7 @@ public static class DefineAssembly { useName = "example", maxOccurs = -1, groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "examples", - namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + inJson = JsonGroupAsBehavior.LIST)) private List _examples; public String getName() { @@ -701,7 +701,7 @@ public static class Field { useName = "prop", maxOccurs = -1, groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "props", - namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + inJson = JsonGroupAsBehavior.LIST)) private List _props; @BoundField( @@ -920,7 +920,7 @@ public static class DefineField { useName = "prop", maxOccurs = -1, groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "props", - namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + inJson = JsonGroupAsBehavior.LIST)) private List _props; @BoundField( @@ -948,7 +948,7 @@ public static class DefineField { @BoundGroupedAssembly(formalName = "Flag Reference", useName = "flag", binding = FlagReference.class) }, groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "flags", - namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + inJson = JsonGroupAsBehavior.LIST)) private List _flags; @BoundAssembly( @@ -966,7 +966,7 @@ public static class DefineField { useName = "example", maxOccurs = -1, groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "examples", - namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + inJson = JsonGroupAsBehavior.LIST)) private List _examples; public String getName() { @@ -1170,7 +1170,7 @@ public static class Choice { binding = InlineDefineField.class) }, groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "choices", - namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + inJson = JsonGroupAsBehavior.LIST)) private List _choices; @BoundAssembly( diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/AssemblyReference.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/AssemblyReference.java index 5b1acc190..870118793 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/AssemblyReference.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/AssemblyReference.java @@ -41,13 +41,13 @@ import gov.nist.secauto.metaschema.databind.model.annotations.Matches; import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints; -import java.lang.Override; -import java.lang.String; + +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + import java.math.BigInteger; import java.util.LinkedList; import java.util.List; -import org.apache.commons.lang3.builder.ReflectionToStringBuilder; -import org.apache.commons.lang3.builder.ToStringStyle; @SuppressWarnings({ "PMD.DataClass", @@ -110,7 +110,7 @@ public class AssemblyReference { formalName = "Property", useName = "prop", maxOccurs = -1, - groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "props", namespace = "##default", + groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "props", inJson = JsonGroupAsBehavior.LIST)) private List _props; diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FieldConstraints.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FieldConstraints.java index 469a616e9..a4d5f1f9d 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FieldConstraints.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FieldConstraints.java @@ -54,7 +54,7 @@ public class FieldConstraints implements IValueConstraintsBase { formalName = "Constraint Let Expression", useName = "let", maxOccurs = -1, - groupAs = @GroupAs(name = "lets", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "lets", inJson = JsonGroupAsBehavior.LIST)) private List _lets; @BoundChoiceGroup( @@ -70,7 +70,7 @@ public class FieldConstraints implements IValueConstraintsBase { @BoundGroupedAssembly(formalName = "Value Matches Constraint", useName = "matches", binding = TargetedMatchesConstraint.class) }, - groupAs = @GroupAs(name = "rules", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "rules", inJson = JsonGroupAsBehavior.LIST)) private List _rules; @Override diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FieldReference.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FieldReference.java index 0cbff61d7..a5688ec66 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FieldReference.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FieldReference.java @@ -43,13 +43,13 @@ import gov.nist.secauto.metaschema.databind.model.annotations.Matches; import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints; -import java.lang.Override; -import java.lang.String; + +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + import java.math.BigInteger; import java.util.LinkedList; import java.util.List; -import org.apache.commons.lang3.builder.ReflectionToStringBuilder; -import org.apache.commons.lang3.builder.ToStringStyle; @SuppressWarnings({ "PMD.DataClass", @@ -131,7 +131,7 @@ public class FieldReference { formalName = "Property", useName = "prop", maxOccurs = -1, - groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "props", namespace = "##default", + groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "props", inJson = JsonGroupAsBehavior.LIST)) private List _props; diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagAllowedValues.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagAllowedValues.java index c1091c614..85fb6111c 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagAllowedValues.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagAllowedValues.java @@ -122,7 +122,7 @@ public class FlagAllowedValues implements IConstraintBase { formalName = "Property", useName = "prop", maxOccurs = -1, - groupAs = @GroupAs(name = "props", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "props", inJson = JsonGroupAsBehavior.LIST)) private List _props; @BoundField( @@ -130,7 +130,7 @@ public class FlagAllowedValues implements IConstraintBase { useName = "enum", minOccurs = 1, maxOccurs = -1, - groupAs = @GroupAs(name = "enums", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "enums", inJson = JsonGroupAsBehavior.LIST)) private List _enums; @BoundField( diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagConstraints.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagConstraints.java index 6f6db71a9..3ed9b9082 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagConstraints.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagConstraints.java @@ -55,7 +55,7 @@ public class FlagConstraints implements IValueConstraintsBase { formalName = "Constraint Let Expression", useName = "let", maxOccurs = -1, - groupAs = @GroupAs(name = "lets", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "lets", inJson = JsonGroupAsBehavior.LIST)) private List _lets; @BoundChoiceGroup( @@ -71,7 +71,7 @@ public class FlagConstraints implements IValueConstraintsBase { @BoundGroupedAssembly(formalName = "Value Matches Constraint", useName = "matches", binding = FlagMatches.class) }, - groupAs = @GroupAs(name = "rules", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "rules", inJson = JsonGroupAsBehavior.LIST)) private List _rules; @Override diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagExpect.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagExpect.java index f609191c7..3b2c87921 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagExpect.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagExpect.java @@ -104,7 +104,7 @@ public class FlagExpect implements IConstraintBase { formalName = "Property", useName = "prop", maxOccurs = -1, - groupAs = @GroupAs(name = "props", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "props", inJson = JsonGroupAsBehavior.LIST)) private List _props; @BoundField( diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagIndexHasKey.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagIndexHasKey.java index 53fb36ed1..7707bf98c 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagIndexHasKey.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagIndexHasKey.java @@ -103,7 +103,7 @@ public class FlagIndexHasKey implements IConstraintBase { formalName = "Property", useName = "prop", maxOccurs = -1, - groupAs = @GroupAs(name = "props", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "props", inJson = JsonGroupAsBehavior.LIST)) private List _props; @BoundAssembly( @@ -111,7 +111,7 @@ public class FlagIndexHasKey implements IConstraintBase { useName = "key-field", minOccurs = 1, maxOccurs = -1, - groupAs = @GroupAs(name = "key-fields", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "key-fields", inJson = JsonGroupAsBehavior.LIST)) private List _keyFields; @BoundField( diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagMatches.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagMatches.java index dedba477e..52efdaddd 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagMatches.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagMatches.java @@ -127,7 +127,7 @@ public class FlagMatches implements IConstraintBase { formalName = "Property", useName = "prop", maxOccurs = -1, - groupAs = @GroupAs(name = "props", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "props", inJson = JsonGroupAsBehavior.LIST)) private List _props; @BoundField( diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagReference.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagReference.java index e0f529c33..8e507ccac 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagReference.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/FlagReference.java @@ -42,13 +42,13 @@ import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs; import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints; -import java.lang.Override; -import java.lang.String; + +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + import java.math.BigInteger; import java.util.LinkedList; import java.util.List; -import org.apache.commons.lang3.builder.ReflectionToStringBuilder; -import org.apache.commons.lang3.builder.ToStringStyle; @SuppressWarnings({ "PMD.DataClass", @@ -110,7 +110,7 @@ public class FlagReference { formalName = "Property", useName = "prop", maxOccurs = -1, - groupAs = @GroupAs(name = "props", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "props", inJson = JsonGroupAsBehavior.LIST)) private List _props; @BoundField( diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/InlineDefineAssembly.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/InlineDefineAssembly.java index 8be25ca5f..c6dad361f 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/InlineDefineAssembly.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/InlineDefineAssembly.java @@ -43,14 +43,13 @@ import gov.nist.secauto.metaschema.databind.model.annotations.Matches; import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints; -import java.lang.Object; -import java.lang.Override; -import java.lang.String; + +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + import java.math.BigInteger; import java.util.LinkedList; import java.util.List; -import org.apache.commons.lang3.builder.ReflectionToStringBuilder; -import org.apache.commons.lang3.builder.ToStringStyle; @SuppressWarnings({ "PMD.DataClass", @@ -113,7 +112,7 @@ public class InlineDefineAssembly { formalName = "Property", useName = "prop", maxOccurs = -1, - groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "props", namespace = "##default", + groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "props", inJson = JsonGroupAsBehavior.LIST)) private List _props; @@ -135,7 +134,7 @@ public class InlineDefineAssembly { binding = InlineDefineFlag.class), @BoundGroupedAssembly(formalName = "Flag Reference", useName = "flag", binding = FlagReference.class) }, - groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "flags", namespace = "##default", + groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "flags", inJson = JsonGroupAsBehavior.LIST)) private List _flags; @@ -158,7 +157,7 @@ public class InlineDefineAssembly { useName = "example", maxOccurs = -1, groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "examples", - namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + inJson = JsonGroupAsBehavior.LIST)) private List _examples; public String getName() { diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/InlineDefineField.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/InlineDefineField.java index 5ed0f442d..b13ae5daf 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/InlineDefineField.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/InlineDefineField.java @@ -45,14 +45,13 @@ import gov.nist.secauto.metaschema.databind.model.annotations.Matches; import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints; -import java.lang.Object; -import java.lang.Override; -import java.lang.String; + +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + import java.math.BigInteger; import java.util.LinkedList; import java.util.List; -import org.apache.commons.lang3.builder.ReflectionToStringBuilder; -import org.apache.commons.lang3.builder.ToStringStyle; @SuppressWarnings({ "PMD.DataClass", @@ -161,7 +160,7 @@ public class InlineDefineField { formalName = "Property", useName = "prop", maxOccurs = -1, - groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "props", namespace = "##default", + groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "props", inJson = JsonGroupAsBehavior.LIST)) private List _props; @@ -194,7 +193,7 @@ public class InlineDefineField { binding = InlineDefineFlag.class), @BoundGroupedAssembly(formalName = "Flag Reference", useName = "flag", binding = FlagReference.class) }, - groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "flags", namespace = "##default", + groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "flags", inJson = JsonGroupAsBehavior.LIST)) private List _flags; @@ -213,7 +212,7 @@ public class InlineDefineField { useName = "example", maxOccurs = -1, groupAs = @gov.nist.secauto.metaschema.databind.model.annotations.GroupAs(name = "examples", - namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + inJson = JsonGroupAsBehavior.LIST)) private List _examples; public String getName() { diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/InlineDefineFlag.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/InlineDefineFlag.java index 048be4ea8..b14dab385 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/InlineDefineFlag.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/InlineDefineFlag.java @@ -42,13 +42,13 @@ import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs; import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints; -import java.lang.Override; -import java.lang.String; + +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + import java.math.BigInteger; import java.util.LinkedList; import java.util.List; -import org.apache.commons.lang3.builder.ReflectionToStringBuilder; -import org.apache.commons.lang3.builder.ToStringStyle; @SuppressWarnings({ "PMD.DataClass", @@ -135,7 +135,7 @@ public class InlineDefineFlag { formalName = "Property", useName = "prop", maxOccurs = -1, - groupAs = @GroupAs(name = "props", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "props", inJson = JsonGroupAsBehavior.LIST)) private List _props; @BoundAssembly( @@ -152,7 +152,7 @@ public class InlineDefineFlag { formalName = "Example", useName = "example", maxOccurs = -1, - groupAs = @GroupAs(name = "examples", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "examples", inJson = JsonGroupAsBehavior.LIST)) private List _examples; public String getName() { diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/METASCHEMA.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/METASCHEMA.java index 94f036f94..4a2e711e4 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/METASCHEMA.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/METASCHEMA.java @@ -49,15 +49,14 @@ import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaField; import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints; -import java.lang.Object; -import java.lang.Override; -import java.lang.String; + +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + import java.math.BigInteger; import java.net.URI; import java.util.LinkedList; import java.util.List; -import org.apache.commons.lang3.builder.ReflectionToStringBuilder; -import org.apache.commons.lang3.builder.ToStringStyle; /** * A declaration of the Metaschema module. @@ -139,7 +138,7 @@ public class METASCHEMA { description = "Imports a set of Metaschema modules contained in another resource. Imports support the reuse of common information structures.", useName = "import", maxOccurs = -1, - groupAs = @GroupAs(name = "imports", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "imports", inJson = JsonGroupAsBehavior.LIST)) private List _imports; @BoundChoiceGroup( @@ -153,7 +152,7 @@ public class METASCHEMA { @BoundGroupedAssembly(formalName = "Global Flag Definition", useName = "define-flag", binding = DefineFlag.class) }, - groupAs = @GroupAs(name = "definitions", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "definitions", inJson = JsonGroupAsBehavior.LIST)) private List _definitions; public String getAbstract() { @@ -346,7 +345,7 @@ public static class DefineField { formalName = "Property", useName = "prop", maxOccurs = -1, - groupAs = @GroupAs(name = "props", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "props", inJson = JsonGroupAsBehavior.LIST)) private List _props; @BoundField( @@ -379,7 +378,7 @@ public static class DefineField { binding = InlineDefineFlag.class), @BoundGroupedAssembly(formalName = "Flag Reference", useName = "flag", binding = FlagReference.class) }, - groupAs = @GroupAs(name = "flags", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "flags", inJson = JsonGroupAsBehavior.LIST)) private List _flags; @BoundAssembly( @@ -396,7 +395,7 @@ public static class DefineField { formalName = "Example", useName = "example", maxOccurs = -1, - groupAs = @GroupAs(name = "examples", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "examples", inJson = JsonGroupAsBehavior.LIST)) private List _examples; public String getName() { @@ -682,7 +681,7 @@ public static class DefineFlag { formalName = "Property", useName = "prop", maxOccurs = -1, - groupAs = @GroupAs(name = "props", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "props", inJson = JsonGroupAsBehavior.LIST)) private List _props; @BoundField( @@ -705,7 +704,7 @@ public static class DefineFlag { formalName = "Example", useName = "example", maxOccurs = -1, - groupAs = @GroupAs(name = "examples", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "examples", inJson = JsonGroupAsBehavior.LIST)) private List _examples; public String getName() { @@ -970,7 +969,7 @@ public static class DefineAssembly { formalName = "Property", useName = "prop", maxOccurs = -1, - groupAs = @GroupAs(name = "props", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "props", inJson = JsonGroupAsBehavior.LIST)) private List _props; @BoundField( @@ -999,7 +998,7 @@ public static class DefineAssembly { binding = InlineDefineFlag.class), @BoundGroupedAssembly(formalName = "Flag Reference", useName = "flag", binding = FlagReference.class) }, - groupAs = @GroupAs(name = "flags", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "flags", inJson = JsonGroupAsBehavior.LIST)) private List _flags; @BoundAssembly( @@ -1020,7 +1019,7 @@ public static class DefineAssembly { formalName = "Example", useName = "example", maxOccurs = -1, - groupAs = @GroupAs(name = "examples", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "examples", inJson = JsonGroupAsBehavior.LIST)) private List _examples; public String getName() { diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/MetapathContext.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/MetapathContext.java index 6edea95c9..98ea9635a 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/MetapathContext.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/MetapathContext.java @@ -52,7 +52,7 @@ public class MetapathContext { useName = "metapath", minOccurs = 1, maxOccurs = -1, - groupAs = @GroupAs(name = "metapaths", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "metapaths", inJson = JsonGroupAsBehavior.LIST)) private List _metapaths; @BoundAssembly( @@ -62,7 +62,7 @@ public class MetapathContext { @BoundAssembly( useName = "metapath-context", maxOccurs = -1, - groupAs = @GroupAs(name = "metapath-contexts", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "metapath-contexts", inJson = JsonGroupAsBehavior.LIST)) private List _metapathContexts; @BoundField( diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/MetaschemaMetaConstraints.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/MetaschemaMetaConstraints.java index 364eaaa60..057591ef7 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/MetaschemaMetaConstraints.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/MetaschemaMetaConstraints.java @@ -63,7 +63,7 @@ public class MetaschemaMetaConstraints { description = "Declares a set of Metaschema constraints from an out-of-line resource to import, supporting composition of constraint sets.", useName = "import", maxOccurs = -1, - groupAs = @GroupAs(name = "imports", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "imports", inJson = JsonGroupAsBehavior.LIST)) private List _imports; @BoundAssembly( @@ -74,7 +74,7 @@ public class MetaschemaMetaConstraints { useName = "metapath-context", minOccurs = 1, maxOccurs = -1, - groupAs = @GroupAs(name = "metapath-contexts", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "metapath-contexts", inJson = JsonGroupAsBehavior.LIST)) private List _metapathContexts; public List getImports() { diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/MetaschemaModuleConstraints.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/MetaschemaModuleConstraints.java index e40f725aa..1fb17e0fd 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/MetaschemaModuleConstraints.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/MetaschemaModuleConstraints.java @@ -83,14 +83,14 @@ public class MetaschemaModuleConstraints { description = "Declares a set of Metaschema constraints from an out-of-line resource to import, supporting composition of constraint sets.", useName = "import", maxOccurs = -1, - groupAs = @GroupAs(name = "imports", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "imports", inJson = JsonGroupAsBehavior.LIST)) private List _imports; @BoundAssembly( useName = "scope", minOccurs = 1, maxOccurs = -1, - groupAs = @GroupAs(name = "scopes", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "scopes", inJson = JsonGroupAsBehavior.LIST)) private List _scopes; public String getName() { @@ -208,7 +208,7 @@ public static class Scope { @BoundGroupedAssembly(useName = "field", binding = Field.class), @BoundGroupedAssembly(useName = "flag", binding = Flag.class) }, - groupAs = @GroupAs(name = "constraints", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "constraints", inJson = JsonGroupAsBehavior.LIST)) private List _constraints; @BoundField( @@ -278,7 +278,7 @@ public static class Flag implements IValueConstraintsBase { @BoundGroupedAssembly(formalName = "Value Matches Constraint", useName = "matches", binding = FlagMatches.class) }, - groupAs = @GroupAs(name = "rules", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "rules", inJson = JsonGroupAsBehavior.LIST)) private List _rules; @Override @@ -333,7 +333,7 @@ public static class Field implements IValueConstraintsBase { @BoundGroupedAssembly(formalName = "Value Matches Constraint", useName = "matches", binding = TargetedMatchesConstraint.class) }, - groupAs = @GroupAs(name = "rules", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "rules", inJson = JsonGroupAsBehavior.LIST)) private List _rules; public String getTarget() { @@ -394,7 +394,7 @@ public static class Assembly implements IModelConstraintsBase { @BoundGroupedAssembly(formalName = "Targeted Cardinality Constraint", useName = "has-cardinality", binding = TargetedHasCardinalityConstraint.class) }, - groupAs = @GroupAs(name = "rules", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "rules", inJson = JsonGroupAsBehavior.LIST)) private List _rules; public String getTarget() { diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedAllowedValuesConstraint.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedAllowedValuesConstraint.java index 971151767..edf02a210 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedAllowedValuesConstraint.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedAllowedValuesConstraint.java @@ -130,7 +130,7 @@ public class TargetedAllowedValuesConstraint implements ITargetedConstraintBase formalName = "Property", useName = "prop", maxOccurs = -1, - groupAs = @GroupAs(name = "props", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "props", inJson = JsonGroupAsBehavior.LIST)) private List _props; @BoundField( @@ -138,7 +138,7 @@ public class TargetedAllowedValuesConstraint implements ITargetedConstraintBase useName = "enum", minOccurs = 1, maxOccurs = -1, - groupAs = @GroupAs(name = "enums", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "enums", inJson = JsonGroupAsBehavior.LIST)) private List _enums; @BoundField( diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedExpectConstraint.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedExpectConstraint.java index ddd306fa6..de17f639e 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedExpectConstraint.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedExpectConstraint.java @@ -111,7 +111,7 @@ public class TargetedExpectConstraint implements ITargetedConstraintBase { formalName = "Property", useName = "prop", maxOccurs = -1, - groupAs = @GroupAs(name = "props", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "props", inJson = JsonGroupAsBehavior.LIST)) private List _props; @BoundField( diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedHasCardinalityConstraint.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedHasCardinalityConstraint.java index c20099b25..b6a09bf8f 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedHasCardinalityConstraint.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedHasCardinalityConstraint.java @@ -121,7 +121,7 @@ public class TargetedHasCardinalityConstraint implements ITargetedConstraintBase formalName = "Property", useName = "prop", maxOccurs = -1, - groupAs = @GroupAs(name = "props", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "props", inJson = JsonGroupAsBehavior.LIST)) private List _props; @BoundField( diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedIndexConstraint.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedIndexConstraint.java index 58d63835c..6051f9e97 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedIndexConstraint.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedIndexConstraint.java @@ -111,7 +111,7 @@ public class TargetedIndexConstraint implements ITargetedConstraintBase { formalName = "Property", useName = "prop", maxOccurs = -1, - groupAs = @GroupAs(name = "props", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "props", inJson = JsonGroupAsBehavior.LIST)) private List _props; @BoundAssembly( @@ -119,7 +119,7 @@ public class TargetedIndexConstraint implements ITargetedConstraintBase { useName = "key-field", minOccurs = 1, maxOccurs = -1, - groupAs = @GroupAs(name = "key-fields", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "key-fields", inJson = JsonGroupAsBehavior.LIST)) private List _keyFields; @BoundField( diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedIndexHasKeyConstraint.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedIndexHasKeyConstraint.java index 8dd650d3d..d9aedbb56 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedIndexHasKeyConstraint.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedIndexHasKeyConstraint.java @@ -111,7 +111,7 @@ public class TargetedIndexHasKeyConstraint implements ITargetedConstraintBase { formalName = "Property", useName = "prop", maxOccurs = -1, - groupAs = @GroupAs(name = "props", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "props", inJson = JsonGroupAsBehavior.LIST)) private List _props; @BoundAssembly( @@ -119,7 +119,7 @@ public class TargetedIndexHasKeyConstraint implements ITargetedConstraintBase { useName = "key-field", minOccurs = 1, maxOccurs = -1, - groupAs = @GroupAs(name = "key-fields", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "key-fields", inJson = JsonGroupAsBehavior.LIST)) private List _keyFields; @BoundField( diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedIsUniqueConstraint.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedIsUniqueConstraint.java index c4cc2e4b9..e8eedd6d6 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedIsUniqueConstraint.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedIsUniqueConstraint.java @@ -104,7 +104,7 @@ public class TargetedIsUniqueConstraint implements ITargetedConstraintBase { formalName = "Property", useName = "prop", maxOccurs = -1, - groupAs = @GroupAs(name = "props", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "props", inJson = JsonGroupAsBehavior.LIST)) private List _props; @BoundAssembly( @@ -112,7 +112,7 @@ public class TargetedIsUniqueConstraint implements ITargetedConstraintBase { useName = "key-field", minOccurs = 1, maxOccurs = -1, - groupAs = @GroupAs(name = "key-fields", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "key-fields", inJson = JsonGroupAsBehavior.LIST)) private List _keyFields; @BoundField( diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedMatchesConstraint.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedMatchesConstraint.java index 3eaa1a743..25ce66f60 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedMatchesConstraint.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/TargetedMatchesConstraint.java @@ -134,7 +134,7 @@ public class TargetedMatchesConstraint implements ITargetedConstraintBase { formalName = "Property", useName = "prop", maxOccurs = -1, - groupAs = @GroupAs(name = "props", namespace = "##default", inJson = JsonGroupAsBehavior.LIST)) + groupAs = @GroupAs(name = "props", inJson = JsonGroupAsBehavior.LIST)) private List _props; @BoundField( diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/package-info.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/package-info.java index f0b9eef72..93c990d9a 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/package-info.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/package-info.java @@ -24,6 +24,11 @@ * 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. */ + +/** + * A Metaschema module represented as a set of Metaschema module bindings. + */ + @gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaPackage(moduleClass = { MetaschemaModelModule.class }) @gov.nist.secauto.metaschema.databind.model.annotations.XmlSchema( namespace = "http://csrc.nist.gov/ns/oscal/metaschema/1.0", diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AbstractBindingModelContainerSupport.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AbstractBindingModelContainerSupport.java index 2675858b7..c44e029e5 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AbstractBindingModelContainerSupport.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AbstractBindingModelContainerSupport.java @@ -26,38 +26,39 @@ package gov.nist.secauto.metaschema.databind.model.metaschema.impl; +import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition; +import gov.nist.secauto.metaschema.core.model.IAssemblyInstanceAbsolute; +import gov.nist.secauto.metaschema.core.model.IContainerModelAbsolute; +import gov.nist.secauto.metaschema.core.model.IContainerModelSupport; +import gov.nist.secauto.metaschema.core.model.IFieldDefinition; +import gov.nist.secauto.metaschema.core.model.IFieldInstanceAbsolute; +import gov.nist.secauto.metaschema.core.model.IModelInstanceAbsolute; +import gov.nist.secauto.metaschema.core.model.IModule; +import gov.nist.secauto.metaschema.core.model.INamedModelInstanceAbsolute; +import gov.nist.secauto.metaschema.core.util.ObjectUtils; +import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelGroupedAssembly; +import gov.nist.secauto.metaschema.databind.model.metaschema.binding.AssemblyReference; +import gov.nist.secauto.metaschema.databind.model.metaschema.binding.FieldReference; + import java.util.List; import java.util.Map; import javax.xml.namespace.QName; import edu.umd.cs.findbugs.annotations.NonNull; -import gov.nist.secauto.metaschema.core.model.IContainerModelSupport; -import gov.nist.secauto.metaschema.core.util.ObjectUtils; -import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelGroupedAssembly; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingContainerModelAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingDefinitionAssembly; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingDefinitionModelField; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelAssemblyAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelFieldAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelNamedAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingModule; -import gov.nist.secauto.metaschema.databind.model.metaschema.binding.AssemblyReference; -import gov.nist.secauto.metaschema.databind.model.metaschema.binding.FieldReference; public abstract class AbstractBindingModelContainerSupport implements IContainerModelSupport< - IBindingInstanceModelAbsolute, - IBindingInstanceModelNamedAbsolute, - IBindingInstanceModelFieldAbsolute, - IBindingInstanceModelAssemblyAbsolute> { + IModelInstanceAbsolute, + INamedModelInstanceAbsolute, + IFieldInstanceAbsolute, + IAssemblyInstanceAbsolute> { protected static void addInstance( - @NonNull IBindingInstanceModelAssemblyAbsolute assembly, - @NonNull List modelInstances, - @NonNull Map namedModelInstances, - @NonNull Map assemblyInstances) { + @NonNull IAssemblyInstanceAbsolute assembly, + @NonNull List modelInstances, + @NonNull Map namedModelInstances, + @NonNull Map assemblyInstances) { QName effectiveName = assembly.getXmlQName(); modelInstances.add(assembly); namedModelInstances.put(effectiveName, assembly); @@ -65,10 +66,10 @@ protected static void addInstance( } protected static void addInstance( - @NonNull IBindingInstanceModelFieldAbsolute field, - @NonNull List modelInstances, - @NonNull Map namedModelInstances, - @NonNull Map fieldInstances) { + @NonNull IFieldInstanceAbsolute field, + @NonNull List modelInstances, + @NonNull Map namedModelInstances, + @NonNull Map fieldInstances) { QName effectiveName = field.getXmlQName(); modelInstances.add(field); namedModelInstances.put(effectiveName, field); @@ -76,16 +77,17 @@ protected static void addInstance( } @NonNull - protected static IBindingInstanceModelAssemblyAbsolute newInstance( + protected static IAssemblyInstanceAbsolute newInstance( @NonNull AssemblyReference obj, @NonNull IBoundInstanceModelGroupedAssembly objInstance, int position, - @NonNull IBindingContainerModelAbsolute parent) { - IBindingDefinitionAssembly owningDefinition = parent.getOwningDefinition(); - IBindingModule module = owningDefinition.getContainingModule(); + @NonNull IContainerModelAbsolute parent) { + IAssemblyDefinition owningDefinition = parent.getOwningDefinition(); + IModule module = owningDefinition.getContainingModule(); String name = ObjectUtils.requireNonNull(obj.getRef()); - IBindingDefinitionAssembly definition = module.getScopedAssemblyDefinitionByName(name); + IAssemblyDefinition definition = module.getScopedAssemblyDefinitionByName( + module.toModelQName(name)); if (definition == null) { throw new IllegalStateException( @@ -98,16 +100,17 @@ protected static IBindingInstanceModelAssemblyAbsolute newInstance( } @NonNull - protected static IBindingInstanceModelFieldAbsolute newInstance( + protected static IFieldInstanceAbsolute newInstance( @NonNull FieldReference obj, @NonNull IBoundInstanceModelGroupedAssembly objInstance, int position, - @NonNull IBindingContainerModelAbsolute parent) { - IBindingDefinitionAssembly owningDefinition = parent.getOwningDefinition(); - IBindingModule module = owningDefinition.getContainingModule(); + @NonNull IContainerModelAbsolute parent) { + IAssemblyDefinition owningDefinition = parent.getOwningDefinition(); + IModule module = owningDefinition.getContainingModule(); String name = ObjectUtils.requireNonNull(obj.getRef()); - IBindingDefinitionModelField definition = module.getScopedFieldDefinitionByName(name); + IFieldDefinition definition = module.getScopedFieldDefinitionByName( + module.toModelQName(name)); if (definition == null) { throw new IllegalStateException( String.format("Unable to resolve field reference '%s' in definition '%s' in module '%s'", diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AbstractGroupedAssemblyInstanceNodeItem.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AbstractGroupedAssemblyInstanceNodeItem.java deleted file mode 100644 index 621e2e9b9..000000000 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AbstractGroupedAssemblyInstanceNodeItem.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.metaschema.impl; - -// REFACTOR: Check if this is used, delete? -// public abstract class AbstractGroupedAssemblyInstanceNodeItem -// extends AbstractGroupedModelInstanceNodeItem -// implements IAssemblyInstanceGroupedNodeItem, IFeatureModelContainerItem { -// protected AbstractGroupedAssemblyInstanceNodeItem( -// @NonNull IAssemblyInstanceGrouped instance, -// int position, -// @NonNull INodeItemGenerator generator) { -// super(instance, position); -// this.model = -// ObjectUtils.notNull(Lazy.lazy(generator.newDataModelSupplier(this))); -// } -// -// @NonNull -// private final Lazy model; -// -// @SuppressWarnings("null") -// @Override -// public ModelContainer getModel() { -// return model.get(); -// } -// } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AbstractGroupedModelInstanceNodeItem.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AbstractGroupedModelInstanceNodeItem.java deleted file mode 100644 index 2ce1c6a01..000000000 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AbstractGroupedModelInstanceNodeItem.java +++ /dev/null @@ -1,71 +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.metaschema.impl; - -// REFACTOR: Check if this is used, delete? -// public abstract class AbstractGroupedModelInstanceNodeItem< -// D extends IModelDefinition, -// I extends INamedModelInstance, -// T> -// implements IModelNodeItem { -// private final int position; -// @NonNull -// private final I instance; -// @NonNull -// private final T value; -// -// protected AbstractGroupedModelInstanceNodeItem( -// @NonNull I instance, -// int position, -// @NonNull T value) { -// this.position = position; -// this.instance = instance; -// this.value = value; -// } -// -// @Override -// public int getPosition() { -// return position; -// } -// -// @SuppressWarnings("unchecked") -// @Override -// public D getDefinition() { -// return (D) getInstance().getDefinition(); -// } -// -// @Override -// public I getInstance() { -// return instance; -// } -// -// @Override -// @NonNull -// public Object getValue() { -// return value; -// } -// } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AbstractInstanceModel.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AbstractInstanceModel.java deleted file mode 100644 index 59ac912aa..000000000 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AbstractInstanceModel.java +++ /dev/null @@ -1,64 +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.metaschema.impl; - -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingContainerModelAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingDefinitionAssembly; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingModule; - -import edu.umd.cs.findbugs.annotations.NonNull; - -public abstract class AbstractInstanceModel - extends AbstractBinding - implements IBindingInstanceModelAbsolute, - IFeatureValueless { - @NonNull - private final PARENT parent; - - protected AbstractInstanceModel( - @NonNull BINDING binding, - @NonNull PARENT parent) { - super(binding); - this.parent = parent; - } - - @Override - public PARENT getParentContainer() { - return parent; - } - - @Override - public IBindingDefinitionAssembly getContainingDefinition() { - return getParentContainer().getOwningDefinition(); - } - - @Override - public IBindingModule getContainingModule() { - return getContainingDefinition().getContainingModule(); - } -} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AbstractInstanceModelGrouped.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AbstractInstanceModelGrouped.java deleted file mode 100644 index f905dca4f..000000000 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AbstractInstanceModelGrouped.java +++ /dev/null @@ -1,104 +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.metaschema.impl; - -import gov.nist.secauto.metaschema.core.metapath.item.node.IAssemblyNodeItem; -import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem; -import gov.nist.secauto.metaschema.core.model.IAttributable; -import gov.nist.secauto.metaschema.core.util.ObjectUtils; -import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelGroupedAssembly; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingDefinitionAssembly; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelNamedGrouped; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingModule; -import gov.nist.secauto.metaschema.databind.model.metaschema.IInstanceModelChoiceGroupBinding; -import gov.nist.secauto.metaschema.databind.model.metaschema.binding.Property; - -import java.util.List; -import java.util.Map; -import java.util.Set; - -import edu.umd.cs.findbugs.annotations.NonNull; -import nl.talsmasoftware.lazy4j.Lazy; - -public abstract class AbstractInstanceModelGrouped< - BINDING> - extends AbstractBinding - implements IBindingInstanceModelNamedGrouped, - IFeatureValueless { - @NonNull - private final IInstanceModelChoiceGroupBinding parent; - @NonNull - private final Map> properties; - @NonNull - private final Lazy boundNodeItem; - - protected AbstractInstanceModelGrouped( - @NonNull BINDING binding, - @NonNull IBoundInstanceModelGroupedAssembly bindingInstance, - int position, - @NonNull IInstanceModelChoiceGroupBinding parent, - @NonNull List properties) { - super(binding); - this.parent = parent; - this.properties = ModelSupport.parseProperties(properties); - this.boundNodeItem = ObjectUtils.notNull( - Lazy.lazy(() -> (IAssemblyNodeItem) getContainingDefinition().getBoundNodeItem() - .getModelItemsByName(bindingInstance.getXmlQName()) - .get(position))); - } - - @Override - public IInstanceModelChoiceGroupBinding getParentContainer() { - return parent; - } - - @Override - public Map> getProperties() { - return properties; - } - - @SuppressWarnings("null") - @Override - public INodeItem getBoundNodeItem() { - return boundNodeItem.get(); - } - - @Override - public IBindingDefinitionAssembly getContainingDefinition() { - return getParentContainer().getOwningDefinition(); - } - - @Override - public String getJsonKeyFlagName() { - return getParentContainer().getJsonKeyFlagName(); - } - - @Override - public IBindingModule getContainingModule() { - return getContainingDefinition().getContainingModule(); - } -} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AbstractInstanceModelNamed.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AbstractInstanceModelNamed.java deleted file mode 100644 index 95c2bd3c8..000000000 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AbstractInstanceModelNamed.java +++ /dev/null @@ -1,118 +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.metaschema.impl; - -import gov.nist.secauto.metaschema.core.metapath.item.node.IAssemblyNodeItem; -import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem; -import gov.nist.secauto.metaschema.core.model.IAttributable; -import gov.nist.secauto.metaschema.core.util.ObjectUtils; -import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelGroupedAssembly; -import gov.nist.secauto.metaschema.databind.model.IGroupAs; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingContainerModelAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelNamedAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.binding.GroupAs; -import gov.nist.secauto.metaschema.databind.model.metaschema.binding.Property; - -import java.util.List; -import java.util.Map; -import java.util.Set; - -import edu.umd.cs.findbugs.annotations.NonNull; -import edu.umd.cs.findbugs.annotations.Nullable; -import nl.talsmasoftware.lazy4j.Lazy; - -/** - * Implements a named model instance associated with a Java object binding. - * - * @param - * the Java type of the associated object binding - * @param - * the Java type of the parent container - */ -public abstract class AbstractInstanceModelNamed< - BINDING, - PARENT extends IBindingContainerModelAbsolute> - extends AbstractInstanceModel - implements IBindingInstanceModelNamedAbsolute, - IFeatureInstanceModelGroupAs { - @NonNull - private final Map> properties; - @NonNull - private final IGroupAs groupAs; - @NonNull - private final Lazy boundNodeItem; - - /** - * Construct a new bound named instance. - * - * @param binding - * the instance object bound to a Java class - * @param bindingInstance - * the Metaschema module instance for the bound object - * @param position - * the zero-based position of this bound object relative to its bound - * object siblings - * @param parent - * the container containing this binding - * @param properties - * the collection of properties associated with this instance, which - * may be empty - * @param groupAs - * the instance grouping information - */ - protected AbstractInstanceModelNamed( - @NonNull BINDING binding, - @NonNull IBoundInstanceModelGroupedAssembly bindingInstance, - int position, - @NonNull PARENT parent, - @NonNull List properties, - @Nullable GroupAs groupAs) { - super(binding, parent); - this.properties = ModelSupport.parseProperties(properties); - this.groupAs = ModelSupport.groupAs(groupAs, parent.getOwningDefinition().getXmlNamespace()); - this.boundNodeItem = ObjectUtils.notNull( - Lazy.lazy(() -> (IAssemblyNodeItem) getContainingDefinition().getBoundNodeItem() - .getModelItemsByName(bindingInstance.getXmlQName()) - .get(position))); - } - - @Override - public Map> getProperties() { - return properties; - } - - @Override - public IGroupAs getGroupAs() { - return groupAs; - } - - @SuppressWarnings("null") - @Override - public INodeItem getBoundNodeItem() { - return boundNodeItem.get(); - } -} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AbstractInstanceModelNamedInline.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AbstractInstanceModelNamedInline.java deleted file mode 100644 index 8d378865e..000000000 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AbstractInstanceModelNamedInline.java +++ /dev/null @@ -1,71 +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.metaschema.impl; - -import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelGroupedAssembly; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingContainerModelAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.binding.GroupAs; -import gov.nist.secauto.metaschema.databind.model.metaschema.binding.Property; - -import java.util.List; - -import edu.umd.cs.findbugs.annotations.NonNull; -import edu.umd.cs.findbugs.annotations.Nullable; - -public abstract class AbstractInstanceModelNamedInline< - BINDING, - PARENT extends IBindingContainerModelAbsolute> - extends AbstractInstanceModelNamed { - - /** - * Construct a new bound named instance that represents an inline definition. - * - * @param binding - * the instance object bound to a Java class - * @param bindingInstance - * the Metaschema module instance for the bound object - * @param position - * the zero-based position of this bound object relative to its bound - * object siblings - * @param parent - * the container containing this binding - * @param properties - * the collection of properties associated with this instance, which - * may be empty - * @param groupAs - * the instance grouping information - */ - protected AbstractInstanceModelNamedInline( - @NonNull BINDING binding, - @NonNull IBoundInstanceModelGroupedAssembly bindingInstance, - int position, - @NonNull PARENT parent, - @NonNull List properties, - @Nullable GroupAs groupAs) { - super(binding, bindingInstance, position, parent, properties, groupAs); - } -} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AbstractInstanceModelNamedReference.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AbstractInstanceModelNamedReference.java deleted file mode 100644 index 94dbd12e2..000000000 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AbstractInstanceModelNamedReference.java +++ /dev/null @@ -1,107 +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.metaschema.impl; - -import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelGroupedAssembly; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingContainerModelAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingDefinitionModel; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceFlag; -import gov.nist.secauto.metaschema.databind.model.metaschema.binding.GroupAs; -import gov.nist.secauto.metaschema.databind.model.metaschema.binding.Property; - -import java.util.List; - -import edu.umd.cs.findbugs.annotations.NonNull; -import edu.umd.cs.findbugs.annotations.Nullable; - -/** - * Implements a named model instance, referencing a global definition, - * associated with a Java object binding. - * - * @param - * the Java type of the associated object binding - * @param - * the Java type of the referenced definition - * @param - * the Java type of the parent container - */ -public abstract class AbstractInstanceModelNamedReference< - BINDING, - DEF extends IBindingDefinitionModel, - PARENT extends IBindingContainerModelAbsolute> - extends AbstractInstanceModelNamed { - @NonNull - private final DEF definition; - - /** - * Construct a new bound named instance that references a global definition. - * - * @param binding - * the instance object bound to a Java class - * @param bindingInstance - * the Metaschema module instance for the bound object - * @param position - * the zero-based position of this bound object relative to its bound - * object siblings - * @param definition - * the referenced global definition - * @param parent - * the container containing this binding - * @param properties - * the collection of properties associated with this instance, which - * may be empty - * @param groupAs - * the instance grouping information - */ - protected AbstractInstanceModelNamedReference( - @NonNull BINDING binding, - @NonNull IBoundInstanceModelGroupedAssembly bindingInstance, - int position, - @NonNull DEF definition, - @NonNull PARENT parent, - @NonNull List properties, - @Nullable GroupAs groupAs) { - super(binding, bindingInstance, position, parent, properties, groupAs); - this.definition = definition; - } - - @Override - public DEF getDefinition() { - return definition; - } - - @Override - public String getName() { - return getDefinition().getName(); - } - - @Override - public String getJsonKeyFlagName() { - IBindingInstanceFlag instance = getDefinition().getJsonKeyFlagInstance(); - return instance == null ? null : instance.getName(); - } -} diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AssemblyModelContainerSupport.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AssemblyModelContainerSupport.java index 6584aac0e..9fd089a1a 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AssemblyModelContainerSupport.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/AssemblyModelContainerSupport.java @@ -26,31 +26,20 @@ package gov.nist.secauto.metaschema.databind.model.metaschema.impl; -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -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; - import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItemFactory; +import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition; +import gov.nist.secauto.metaschema.core.model.IAssemblyInstanceAbsolute; +import gov.nist.secauto.metaschema.core.model.IChoiceGroupInstance; +import gov.nist.secauto.metaschema.core.model.IChoiceInstance; import gov.nist.secauto.metaschema.core.model.IContainerModelAssemblySupport; +import gov.nist.secauto.metaschema.core.model.IFieldInstanceAbsolute; +import gov.nist.secauto.metaschema.core.model.IModelInstanceAbsolute; +import gov.nist.secauto.metaschema.core.model.INamedModelInstanceAbsolute; import gov.nist.secauto.metaschema.core.util.CollectionUtil; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelAssembly; import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelChoiceGroup; import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelGroupedAssembly; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingDefinitionAssembly; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelAssemblyAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelFieldAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelNamedAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IInstanceModelChoiceBinding; -import gov.nist.secauto.metaschema.databind.model.metaschema.IInstanceModelChoiceGroupBinding; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.AssemblyModel; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.AssemblyModel.Choice; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.AssemblyModel.ChoiceGroup; @@ -59,40 +48,51 @@ import gov.nist.secauto.metaschema.databind.model.metaschema.binding.InlineDefineAssembly; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.InlineDefineField; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +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; + class AssemblyModelContainerSupport extends AbstractBindingModelContainerSupport implements IContainerModelAssemblySupport< - IBindingInstanceModelAbsolute, - IBindingInstanceModelNamedAbsolute, - IBindingInstanceModelFieldAbsolute, - IBindingInstanceModelAssemblyAbsolute, - IInstanceModelChoiceBinding, - IInstanceModelChoiceGroupBinding> { + IModelInstanceAbsolute, + INamedModelInstanceAbsolute, + IFieldInstanceAbsolute, + IAssemblyInstanceAbsolute, + IChoiceInstance, + IChoiceGroupInstance> { @NonNull - private final List modelInstances; + private final List modelInstances; @NonNull - private final Map namedModelInstances; + private final Map namedModelInstances; @NonNull - private final Map fieldInstances; + private final Map fieldInstances; @NonNull - private final Map assemblyInstances; + private final Map assemblyInstances; @NonNull - private final List choiceInstances; + private final List choiceInstances; @NonNull - private final Map choiceGroupInstances; + private final Map choiceGroupInstances; @SuppressWarnings("PMD.ShortMethodName") @SuppressFBWarnings(value = "CT_CONSTRUCTOR_THROW", justification = "Use of final fields") public static IContainerModelAssemblySupport< - IBindingInstanceModelAbsolute, - IBindingInstanceModelNamedAbsolute, - IBindingInstanceModelFieldAbsolute, - IBindingInstanceModelAssemblyAbsolute, - IInstanceModelChoiceBinding, - IInstanceModelChoiceGroupBinding> of( + IModelInstanceAbsolute, + INamedModelInstanceAbsolute, + IFieldInstanceAbsolute, + IAssemblyInstanceAbsolute, + IChoiceInstance, + IChoiceGroupInstance> of( @Nullable AssemblyModel binding, @NonNull IBoundInstanceModelAssembly bindingInstance, - @NonNull IBindingDefinitionAssembly parent, + @NonNull IAssemblyDefinition parent, @NonNull INodeItemFactory nodeItemFactory) { List instances; return binding == null || (instances = binding.getInstances()) == null || instances.isEmpty() @@ -121,16 +121,16 @@ IInstanceModelChoiceGroupBinding> of( protected AssemblyModelContainerSupport( @NonNull AssemblyModel model, @NonNull IBoundInstanceModelAssembly modelInstance, - @NonNull IBindingDefinitionAssembly parent, + @NonNull IAssemblyDefinition parent, @NonNull INodeItemFactory nodeItemFactory) { // create temporary collections to store the child binding objects - final List modelInstances = new LinkedList<>(); - final Map namedModelInstances = new LinkedHashMap<>(); - final Map fieldInstances = new LinkedHashMap<>(); - final Map assemblyInstances = new LinkedHashMap<>(); - final List choiceInstances = new LinkedList<>(); - final Map choiceGroupInstances = new LinkedHashMap<>(); + final List modelInstances = new LinkedList<>(); + final Map namedModelInstances = new LinkedHashMap<>(); + final Map fieldInstances = new LinkedHashMap<>(); + final Map assemblyInstances = new LinkedHashMap<>(); + final List choiceInstances = new LinkedList<>(); + final Map choiceGroupInstances = new LinkedHashMap<>(); // create counters to track child positions int assemblyReferencePosition = 0; @@ -148,14 +148,14 @@ protected AssemblyModelContainerSupport( = (IBoundInstanceModelGroupedAssembly) instance.getItemInstance(obj); if (obj instanceof AssemblyReference) { - IBindingInstanceModelAssemblyAbsolute assembly = newInstance( + IAssemblyInstanceAbsolute assembly = newInstance( (AssemblyReference) obj, objInstance, assemblyReferencePosition++, parent); addInstance(assembly, modelInstances, namedModelInstances, assemblyInstances); } else if (obj instanceof InlineDefineAssembly) { - IBindingInstanceModelAssemblyAbsolute assembly = new InstanceModelAssemblyInline( + IAssemblyInstanceAbsolute assembly = new InstanceModelAssemblyInline( (InlineDefineAssembly) obj, objInstance, assemblyInlineDefinitionPosition++, @@ -163,21 +163,21 @@ protected AssemblyModelContainerSupport( nodeItemFactory); addInstance(assembly, modelInstances, namedModelInstances, assemblyInstances); } else if (obj instanceof FieldReference) { - IBindingInstanceModelFieldAbsolute field = newInstance( + IFieldInstanceAbsolute field = newInstance( (FieldReference) obj, objInstance, fieldReferencePosition++, parent); addInstance(field, modelInstances, namedModelInstances, fieldInstances); } else if (obj instanceof InlineDefineField) { - IBindingInstanceModelFieldAbsolute field = new InstanceModelFieldInline( + IFieldInstanceAbsolute field = new InstanceModelFieldInline( (InlineDefineField) obj, objInstance, fieldInlineDefinitionPosition++, parent); addInstance(field, modelInstances, namedModelInstances, fieldInstances); } else if (obj instanceof AssemblyModel.Choice) { - IInstanceModelChoiceBinding choice = new InstanceModelChoice( + IChoiceInstance choice = new InstanceModelChoice( (Choice) obj, objInstance, choicePosition++, @@ -186,7 +186,7 @@ protected AssemblyModelContainerSupport( modelInstances.add(choice); choiceInstances.add(choice); } else if (obj instanceof AssemblyModel.ChoiceGroup) { - IInstanceModelChoiceGroupBinding choiceGroup = new InstanceModelChoiceGroup( + IChoiceGroupInstance choiceGroup = new InstanceModelChoiceGroup( (ChoiceGroup) obj, objInstance, choiceGroupPosition++, @@ -220,32 +220,32 @@ protected AssemblyModelContainerSupport( } @Override - public List getModelInstances() { + public List getModelInstances() { return modelInstances; } @Override - public Map getNamedModelInstanceMap() { + public Map getNamedModelInstanceMap() { return namedModelInstances; } @Override - public Map getFieldInstanceMap() { + public Map getFieldInstanceMap() { return fieldInstances; } @Override - public Map getAssemblyInstanceMap() { + public Map getAssemblyInstanceMap() { return assemblyInstances; } @Override - public List getChoiceInstances() { + public List getChoiceInstances() { return choiceInstances; } @Override - public Map getChoiceGroupInstanceMap() { + public Map getChoiceGroupInstanceMap() { return choiceGroupInstances; } } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/BindingModule.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/BindingModule.java index dbf625f31..3c9b5cbb4 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/BindingModule.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/BindingModule.java @@ -31,17 +31,16 @@ import gov.nist.secauto.metaschema.core.metapath.item.node.IDocumentNodeItem; import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItemFactory; import gov.nist.secauto.metaschema.core.model.AbstractModule; -import gov.nist.secauto.metaschema.core.model.IDefinition; +import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition; +import gov.nist.secauto.metaschema.core.model.IFieldDefinition; +import gov.nist.secauto.metaschema.core.model.IFlagDefinition; +import gov.nist.secauto.metaschema.core.model.IMetaschemaModule; +import gov.nist.secauto.metaschema.core.model.IModelDefinition; import gov.nist.secauto.metaschema.core.model.MetaschemaException; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.metaschema.databind.model.IBoundDefinitionModelAssembly; import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelChoiceGroup; import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelGroupedAssembly; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingDefinitionAssembly; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingDefinitionFlag; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingDefinitionModel; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingDefinitionModelField; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingModule; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.METASCHEMA; import java.net.URI; @@ -52,18 +51,20 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import javax.xml.namespace.QName; + import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import nl.talsmasoftware.lazy4j.Lazy; public class BindingModule extends AbstractModule< - IBindingModule, - IBindingDefinitionModel, - IBindingDefinitionFlag, - IBindingDefinitionModelField, - IBindingDefinitionAssembly> - implements IBindingModule { + IMetaschemaModule, + IModelDefinition, + IFlagDefinition, + IFieldDefinition, + IAssemblyDefinition> + implements IMetaschemaModule { @NonNull private final URI location; @NonNull @@ -71,15 +72,13 @@ public class BindingModule @NonNull private final Lazy nodeItem; @NonNull - private final Map definitions; - @NonNull - private final Map flagDefinitions; + private final Map flagDefinitions; @NonNull - private final Map fieldDefinitions; + private final Map fieldDefinitions; @NonNull - private final Map assemblyDefinitions; + private final Map assemblyDefinitions; @NonNull - private final Map rootAssemblyDefinitions; + private final Map rootAssemblyDefinitions; /** * Constructs a new Metaschema instance. @@ -101,11 +100,10 @@ public BindingModule( // NOPMD - unavoidable @NonNull URI resource, @NonNull IBoundDefinitionModelAssembly rootDefinition, @NonNull METASCHEMA binding, - @NonNull List importedModules) throws MetaschemaException { + @NonNull List importedModules) throws MetaschemaException { super(importedModules); this.location = ObjectUtils.requireNonNull(resource, "resource"); this.binding = binding; - this.definitions = new LinkedHashMap<>(); this.flagDefinitions = new LinkedHashMap<>(); this.fieldDefinitions = new LinkedHashMap<>(); this.assemblyDefinitions = new LinkedHashMap<>(); @@ -124,35 +122,32 @@ public BindingModule( // NOPMD - unavoidable = (IBoundInstanceModelGroupedAssembly) instance.getItemInstance(obj); if (obj instanceof METASCHEMA.DefineAssembly) { - IBindingDefinitionAssembly definition = new DefinitionAssemblyGlobal( + IAssemblyDefinition definition = new DefinitionAssemblyGlobal( (METASCHEMA.DefineAssembly) obj, objInstance, globalAssemblyPosition++, this, nodeItemFactory); - String name = definition.getName(); - definitions.put(name, definition); + QName name = definition.getDefinitionQName(); assemblyDefinitions.put(name, definition); if (definition.isRoot()) { rootAssemblyDefinitions.put(name, definition); } } else if (obj instanceof METASCHEMA.DefineField) { - IBindingDefinitionModelField definition = new DefinitionFieldGlobal( + IFieldDefinition definition = new DefinitionFieldGlobal( (METASCHEMA.DefineField) obj, objInstance, globalFieldPosition++, this); - String name = definition.getName(); - definitions.put(name, definition); + QName name = definition.getDefinitionQName(); fieldDefinitions.put(name, definition); } else if (obj instanceof METASCHEMA.DefineFlag) { - IBindingDefinitionFlag definition = new DefinitionFlagGlobal( + IFlagDefinition definition = new DefinitionFlagGlobal( (METASCHEMA.DefineFlag) obj, objInstance, globalFlagPosition++, this); - String name = definition.getName(); - definitions.put(name, definition); + QName name = definition.getDefinitionQName(); flagDefinitions.put(name, definition); } else { throw new IllegalStateException( @@ -161,19 +156,17 @@ public BindingModule( // NOPMD - unavoidable resource.toASCIIString())); } } - this.nodeItem = ObjectUtils.notNull(Lazy.lazy(() -> { - return nodeItemFactory.newDocumentNodeItem(rootDefinition, resource, binding); - })); + this.nodeItem + = ObjectUtils.notNull(Lazy.lazy(() -> nodeItemFactory.newDocumentNodeItem(rootDefinition, resource, binding))); } - @Override @NonNull public METASCHEMA getBinding() { return binding; } @Override - public IDocumentNodeItem getBoundNodeItem() { + public IDocumentNodeItem getNodeItem() { return ObjectUtils.notNull(nodeItem.get()); } @@ -234,69 +227,64 @@ public URI getJsonBaseUri() { return retval; } - @NonNull - public Collection getDefinitions() { - return ObjectUtils.notNull(definitions.values()); - } - - private Map getAssemblyDefinitionMap() { + private Map getAssemblyDefinitionMap() { return assemblyDefinitions; } @Override - public Collection getAssemblyDefinitions() { + public Collection getAssemblyDefinitions() { return ObjectUtils.notNull(getAssemblyDefinitionMap().values()); } @Override - public IBindingDefinitionAssembly getAssemblyDefinitionByName(@NonNull String name) { + public IAssemblyDefinition getAssemblyDefinitionByName(@NonNull QName name) { return getAssemblyDefinitionMap().get(name); } - private Map getFieldDefinitionMap() { + private Map getFieldDefinitionMap() { return fieldDefinitions; } @SuppressWarnings("null") @Override - public Collection getFieldDefinitions() { + public Collection getFieldDefinitions() { return getFieldDefinitionMap().values(); } @Override - public IBindingDefinitionModelField getFieldDefinitionByName(@NonNull String name) { + public IFieldDefinition getFieldDefinitionByName(@NonNull QName name) { return getFieldDefinitionMap().get(name); } @SuppressWarnings("null") @Override - public List getAssemblyAndFieldDefinitions() { + public List getAssemblyAndFieldDefinitions() { return Stream.concat(getAssemblyDefinitions().stream(), getFieldDefinitions().stream()) .collect(Collectors.toList()); } - private Map getFlagDefinitionMap() { + private Map getFlagDefinitionMap() { return flagDefinitions; } @SuppressWarnings("null") @Override - public Collection getFlagDefinitions() { + public Collection getFlagDefinitions() { return getFlagDefinitionMap().values(); } @Override - public IBindingDefinitionFlag getFlagDefinitionByName(@NonNull String name) { + public IFlagDefinition getFlagDefinitionByName(@NonNull QName name) { return getFlagDefinitionMap().get(name); } - private Map getRootAssemblyDefinitionMap() { + private Map getRootAssemblyDefinitionMap() { return rootAssemblyDefinitions; } @SuppressWarnings("null") @Override - public Collection getRootAssemblyDefinitions() { + public Collection getRootAssemblyDefinitions() { return getRootAssemblyDefinitionMap().values(); } } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/ChoiceGroupModelContainerSupport.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/ChoiceGroupModelContainerSupport.java index ac214e16a..9fa52a738 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/ChoiceGroupModelContainerSupport.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/ChoiceGroupModelContainerSupport.java @@ -26,6 +26,21 @@ package gov.nist.secauto.metaschema.databind.model.metaschema.impl; +import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItemFactory; +import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition; +import gov.nist.secauto.metaschema.core.model.IAssemblyInstanceGrouped; +import gov.nist.secauto.metaschema.core.model.IChoiceGroupInstance; +import gov.nist.secauto.metaschema.core.model.IContainerModelSupport; +import gov.nist.secauto.metaschema.core.model.IFieldDefinition; +import gov.nist.secauto.metaschema.core.model.IFieldInstanceGrouped; +import gov.nist.secauto.metaschema.core.model.IModule; +import gov.nist.secauto.metaschema.core.model.INamedModelInstanceGrouped; +import gov.nist.secauto.metaschema.core.util.CollectionUtil; +import gov.nist.secauto.metaschema.core.util.ObjectUtils; +import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelChoiceGroup; +import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelGroupedAssembly; +import gov.nist.secauto.metaschema.databind.model.metaschema.binding.AssemblyModel; + import java.util.Collection; import java.util.LinkedHashMap; import java.util.List; @@ -37,43 +52,28 @@ import edu.umd.cs.findbugs.annotations.Nullable; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItemFactory; -import gov.nist.secauto.metaschema.core.model.IContainerModelSupport; -import gov.nist.secauto.metaschema.core.util.CollectionUtil; -import gov.nist.secauto.metaschema.core.util.ObjectUtils; -import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelChoiceGroup; -import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelGroupedAssembly; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingDefinitionAssembly; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingDefinitionModelField; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelAssemblyGrouped; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelFieldGrouped; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelNamedGrouped; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingModule; -import gov.nist.secauto.metaschema.databind.model.metaschema.IInstanceModelChoiceGroupBinding; -import gov.nist.secauto.metaschema.databind.model.metaschema.binding.AssemblyModel; - class ChoiceGroupModelContainerSupport implements IContainerModelSupport< - IBindingInstanceModelNamedGrouped, - IBindingInstanceModelNamedGrouped, - IBindingInstanceModelFieldGrouped, - IBindingInstanceModelAssemblyGrouped> { + INamedModelInstanceGrouped, + INamedModelInstanceGrouped, + IFieldInstanceGrouped, + IAssemblyInstanceGrouped> { @NonNull - private final Map namedModelInstances; + private final Map namedModelInstances; @NonNull - private final Map fieldInstances; + private final Map fieldInstances; @NonNull - private final Map assemblyInstances; + private final Map assemblyInstances; @SuppressWarnings("PMD.ShortMethodName") public static IContainerModelSupport< - IBindingInstanceModelNamedGrouped, - IBindingInstanceModelNamedGrouped, - IBindingInstanceModelFieldGrouped, - IBindingInstanceModelAssemblyGrouped> of( + INamedModelInstanceGrouped, + INamedModelInstanceGrouped, + IFieldInstanceGrouped, + IAssemblyInstanceGrouped> of( @Nullable AssemblyModel.ChoiceGroup binding, @NonNull IBoundInstanceModelGroupedAssembly bindingInstance, - @NonNull IInstanceModelChoiceGroupBinding parent, + @NonNull IChoiceGroupInstance parent, @NonNull INodeItemFactory nodeItemFactory) { List instances; return binding == null || (instances = binding.getChoices()) == null || instances.isEmpty() @@ -102,13 +102,13 @@ IBindingInstanceModelAssemblyGrouped> of( public ChoiceGroupModelContainerSupport( @NonNull AssemblyModel.ChoiceGroup binding, @NonNull IBoundInstanceModelGroupedAssembly bindingInstance, - @NonNull IInstanceModelChoiceGroupBinding parent, + @NonNull IChoiceGroupInstance parent, @NonNull INodeItemFactory nodeItemFactory) { // create temporary collections to store the child binding objects - final Map namedModelInstances = new LinkedHashMap<>(); - final Map fieldInstances = new LinkedHashMap<>(); - final Map assemblyInstances = new LinkedHashMap<>(); + final Map namedModelInstances = new LinkedHashMap<>(); + final Map fieldInstances = new LinkedHashMap<>(); + final Map assemblyInstances = new LinkedHashMap<>(); // create counters to track child positions int assemblyReferencePosition = 0; @@ -124,14 +124,14 @@ public ChoiceGroupModelContainerSupport( = (IBoundInstanceModelGroupedAssembly) instance.getItemInstance(obj); if (obj instanceof AssemblyModel.ChoiceGroup.Assembly) { - IBindingInstanceModelAssemblyGrouped assembly = newInstance( + IAssemblyInstanceGrouped assembly = newInstance( (AssemblyModel.ChoiceGroup.Assembly) obj, objInstance, assemblyReferencePosition++, parent); addInstance(assembly, namedModelInstances, assemblyInstances); } else if (obj instanceof AssemblyModel.ChoiceGroup.DefineAssembly) { - IBindingInstanceModelAssemblyGrouped assembly = new InstanceModelGroupedAssemblyInline( + IAssemblyInstanceGrouped assembly = new InstanceModelGroupedAssemblyInline( (AssemblyModel.ChoiceGroup.DefineAssembly) obj, objInstance, assemblyInlineDefinitionPosition++, @@ -139,14 +139,14 @@ public ChoiceGroupModelContainerSupport( nodeItemFactory); addInstance(assembly, namedModelInstances, assemblyInstances); } else if (obj instanceof AssemblyModel.ChoiceGroup.Field) { - IBindingInstanceModelFieldGrouped field = newInstance( + IFieldInstanceGrouped field = newInstance( (AssemblyModel.ChoiceGroup.Field) obj, objInstance, fieldReferencePosition++, parent); addInstance(field, namedModelInstances, fieldInstances); } else if (obj instanceof AssemblyModel.ChoiceGroup.DefineField) { - IBindingInstanceModelFieldGrouped field = new InstanceModelGroupedFieldInline( + IFieldInstanceGrouped field = new InstanceModelGroupedFieldInline( (AssemblyModel.ChoiceGroup.DefineField) obj, objInstance, fieldInlineDefinitionPosition++, @@ -170,34 +170,34 @@ public ChoiceGroupModelContainerSupport( } protected static void addInstance( - @NonNull IBindingInstanceModelAssemblyGrouped assembly, - @NonNull Map namedModelInstances, - @NonNull Map assemblyInstances) { + @NonNull IAssemblyInstanceGrouped assembly, + @NonNull Map namedModelInstances, + @NonNull Map assemblyInstances) { QName effectiveName = assembly.getXmlQName(); namedModelInstances.put(effectiveName, assembly); assemblyInstances.put(effectiveName, assembly); } protected static void addInstance( - @NonNull IBindingInstanceModelFieldGrouped field, - @NonNull Map namedModelInstances, - @NonNull Map fieldInstances) { + @NonNull IFieldInstanceGrouped field, + @NonNull Map namedModelInstances, + @NonNull Map fieldInstances) { QName effectiveName = field.getXmlQName(); namedModelInstances.put(effectiveName, field); fieldInstances.put(effectiveName, field); } @NonNull - protected static IBindingInstanceModelAssemblyGrouped newInstance( + protected static IAssemblyInstanceGrouped newInstance( @NonNull AssemblyModel.ChoiceGroup.Assembly obj, @NonNull IBoundInstanceModelGroupedAssembly objInstance, int position, - @NonNull IInstanceModelChoiceGroupBinding parent) { - IBindingDefinitionAssembly owningDefinition = parent.getOwningDefinition(); - IBindingModule module = owningDefinition.getContainingModule(); + @NonNull IChoiceGroupInstance parent) { + IAssemblyDefinition owningDefinition = parent.getOwningDefinition(); + IModule module = owningDefinition.getContainingModule(); - String name = ObjectUtils.requireNonNull(obj.getRef()); - IBindingDefinitionAssembly definition = module.getScopedAssemblyDefinitionByName(name); + QName name = parent.getContainingModule().toModelQName(ObjectUtils.requireNonNull(obj.getRef())); + IAssemblyDefinition definition = module.getScopedAssemblyDefinitionByName(name); if (definition == null) { throw new IllegalStateException( @@ -210,16 +210,16 @@ protected static IBindingInstanceModelAssemblyGrouped newInstance( } @NonNull - protected static IBindingInstanceModelFieldGrouped newInstance( + protected static IFieldInstanceGrouped newInstance( @NonNull AssemblyModel.ChoiceGroup.Field obj, @NonNull IBoundInstanceModelGroupedAssembly objInstance, int position, - @NonNull IInstanceModelChoiceGroupBinding parent) { - IBindingDefinitionAssembly owningDefinition = parent.getOwningDefinition(); - IBindingModule module = owningDefinition.getContainingModule(); + @NonNull IChoiceGroupInstance parent) { + IAssemblyDefinition owningDefinition = parent.getOwningDefinition(); + IModule module = owningDefinition.getContainingModule(); - String name = ObjectUtils.requireNonNull(obj.getRef()); - IBindingDefinitionModelField definition = module.getScopedFieldDefinitionByName(name); + QName name = parent.getContainingModule().toModelQName(ObjectUtils.requireNonNull(obj.getRef())); + IFieldDefinition definition = module.getScopedFieldDefinitionByName(name); if (definition == null) { throw new IllegalStateException( String.format("Unable to resolve field reference '%s' in definition '%s' in module '%s'", @@ -232,22 +232,22 @@ protected static IBindingInstanceModelFieldGrouped newInstance( @SuppressWarnings("null") @Override - public Collection getModelInstances() { + public Collection getModelInstances() { return namedModelInstances.values(); } @Override - public Map getNamedModelInstanceMap() { + public Map getNamedModelInstanceMap() { return namedModelInstances; } @Override - public Map getFieldInstanceMap() { + public Map getFieldInstanceMap() { return fieldInstances; } @Override - public Map getAssemblyInstanceMap() { + public Map getAssemblyInstanceMap() { return assemblyInstances; } } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/ChoiceModelContainerSupport.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/ChoiceModelContainerSupport.java index 2becf1dc6..cdb9bd0f8 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/ChoiceModelContainerSupport.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/ChoiceModelContainerSupport.java @@ -26,54 +26,54 @@ package gov.nist.secauto.metaschema.databind.model.metaschema.impl; -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -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; - import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItemFactory; +import gov.nist.secauto.metaschema.core.model.IAssemblyInstanceAbsolute; +import gov.nist.secauto.metaschema.core.model.IChoiceInstance; import gov.nist.secauto.metaschema.core.model.IContainerModelSupport; +import gov.nist.secauto.metaschema.core.model.IFieldInstanceAbsolute; +import gov.nist.secauto.metaschema.core.model.IModelInstanceAbsolute; +import gov.nist.secauto.metaschema.core.model.INamedModelInstanceAbsolute; import gov.nist.secauto.metaschema.core.util.CollectionUtil; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelChoiceGroup; import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelGroupedAssembly; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelAssemblyAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelFieldAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelNamedAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IInstanceModelChoiceBinding; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.AssemblyModel.Choice; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.AssemblyReference; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.FieldReference; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.InlineDefineAssembly; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.InlineDefineField; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +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; + class ChoiceModelContainerSupport extends AbstractBindingModelContainerSupport { @NonNull - private final List modelInstances; + private final List modelInstances; @NonNull - private final Map namedModelInstances; + private final Map namedModelInstances; @NonNull - private final Map fieldInstances; + private final Map fieldInstances; @NonNull - private final Map assemblyInstances; + private final Map assemblyInstances; @SuppressWarnings("PMD.ShortMethodName") public static IContainerModelSupport< - IBindingInstanceModelAbsolute, - IBindingInstanceModelNamedAbsolute, - IBindingInstanceModelFieldAbsolute, - IBindingInstanceModelAssemblyAbsolute> of( + IModelInstanceAbsolute, + INamedModelInstanceAbsolute, + IFieldInstanceAbsolute, + IAssemblyInstanceAbsolute> of( @Nullable Choice binding, @NonNull IBoundInstanceModelGroupedAssembly bindingInstance, - @NonNull IInstanceModelChoiceBinding parent, + @NonNull IChoiceInstance parent, @NonNull INodeItemFactory nodeItemFactory) { List instances; return binding == null || (instances = binding.getChoices()) == null || instances.isEmpty() @@ -102,14 +102,14 @@ IBindingInstanceModelAssemblyAbsolute> of( public ChoiceModelContainerSupport( @NonNull Choice binding, @NonNull IBoundInstanceModelGroupedAssembly bindingInstance, - @NonNull IInstanceModelChoiceBinding parent, + @NonNull IChoiceInstance parent, @NonNull INodeItemFactory nodeItemFactory) { // create temporary collections to store the child binding objects - final List modelInstances = new LinkedList<>(); - final Map namedModelInstances = new LinkedHashMap<>(); - final Map fieldInstances = new LinkedHashMap<>(); - final Map assemblyInstances = new LinkedHashMap<>(); + final List modelInstances = new LinkedList<>(); + final Map namedModelInstances = new LinkedHashMap<>(); + final Map fieldInstances = new LinkedHashMap<>(); + final Map assemblyInstances = new LinkedHashMap<>(); // create counters to track child positions int assemblyReferencePosition = 0; @@ -125,14 +125,14 @@ public ChoiceModelContainerSupport( = (IBoundInstanceModelGroupedAssembly) instance.getItemInstance(obj); if (obj instanceof AssemblyReference) { - IBindingInstanceModelAssemblyAbsolute assembly = newInstance( + IAssemblyInstanceAbsolute assembly = newInstance( (AssemblyReference) obj, objInstance, assemblyReferencePosition++, parent); addInstance(assembly, modelInstances, namedModelInstances, assemblyInstances); } else if (obj instanceof InlineDefineAssembly) { - IBindingInstanceModelAssemblyAbsolute assembly = new InstanceModelAssemblyInline( + IAssemblyInstanceAbsolute assembly = new InstanceModelAssemblyInline( (InlineDefineAssembly) obj, objInstance, assemblyInlineDefinitionPosition++, @@ -140,14 +140,14 @@ public ChoiceModelContainerSupport( nodeItemFactory); addInstance(assembly, modelInstances, namedModelInstances, assemblyInstances); } else if (obj instanceof FieldReference) { - IBindingInstanceModelFieldAbsolute field = newInstance( + IFieldInstanceAbsolute field = newInstance( (FieldReference) obj, objInstance, fieldReferencePosition++, parent); addInstance(field, modelInstances, namedModelInstances, fieldInstances); } else if (obj instanceof InlineDefineField) { - IBindingInstanceModelFieldAbsolute field = new InstanceModelFieldInline( + IFieldInstanceAbsolute field = new InstanceModelFieldInline( (InlineDefineField) obj, objInstance, fieldInlineDefinitionPosition++, @@ -173,22 +173,22 @@ public ChoiceModelContainerSupport( } @Override - public List getModelInstances() { + public List getModelInstances() { return modelInstances; } @Override - public Map getNamedModelInstanceMap() { + public Map getNamedModelInstanceMap() { return namedModelInstances; } @Override - public Map getFieldInstanceMap() { + public Map getFieldInstanceMap() { return fieldInstances; } @Override - public Map getAssemblyInstanceMap() { + public Map getAssemblyInstanceMap() { return assemblyInstances; } } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/DefinitionAssemblyGlobal.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/DefinitionAssemblyGlobal.java index da31161bc..c17f462d5 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/DefinitionAssemblyGlobal.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/DefinitionAssemblyGlobal.java @@ -29,27 +29,26 @@ import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine; import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline; import gov.nist.secauto.metaschema.core.metapath.item.node.IAssemblyNodeItem; -import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem; import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItemFactory; -import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition; +import gov.nist.secauto.metaschema.core.model.AbstractGlobalAssemblyDefinition; +import gov.nist.secauto.metaschema.core.model.IAssemblyInstance; +import gov.nist.secauto.metaschema.core.model.IAssemblyInstanceAbsolute; import gov.nist.secauto.metaschema.core.model.IAttributable; +import gov.nist.secauto.metaschema.core.model.IChoiceGroupInstance; +import gov.nist.secauto.metaschema.core.model.IChoiceInstance; import gov.nist.secauto.metaschema.core.model.IContainerFlagSupport; import gov.nist.secauto.metaschema.core.model.IContainerModelAssemblySupport; +import gov.nist.secauto.metaschema.core.model.IFieldInstanceAbsolute; +import gov.nist.secauto.metaschema.core.model.IFlagInstance; +import gov.nist.secauto.metaschema.core.model.IMetaschemaModule; +import gov.nist.secauto.metaschema.core.model.IModelInstanceAbsolute; +import gov.nist.secauto.metaschema.core.model.INamedModelInstanceAbsolute; import gov.nist.secauto.metaschema.core.model.ModuleScopeEnum; import gov.nist.secauto.metaschema.core.model.constraint.AssemblyConstraintSet; import gov.nist.secauto.metaschema.core.model.constraint.IModelConstrained; import gov.nist.secauto.metaschema.core.model.constraint.ISource; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelGroupedAssembly; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingDefinitionAssembly; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceFlag; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelAssemblyAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelFieldAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelNamedAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingModule; -import gov.nist.secauto.metaschema.databind.model.metaschema.IInstanceModelChoiceBinding; -import gov.nist.secauto.metaschema.databind.model.metaschema.IInstanceModelChoiceGroupBinding; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.AssemblyConstraints; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.JsonKey; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.METASCHEMA; @@ -61,23 +60,30 @@ import nl.talsmasoftware.lazy4j.Lazy; public class DefinitionAssemblyGlobal - extends AbstractDefinition - implements IBindingDefinitionAssembly, - IFeatureBindingContainerFlag, - IFeatureBindingContainerModelAssembly { - + extends AbstractGlobalAssemblyDefinition< + IMetaschemaModule, + IAssemblyInstance, + IFlagInstance, + IModelInstanceAbsolute, + INamedModelInstanceAbsolute, + IFieldInstanceAbsolute, + IAssemblyInstanceAbsolute, + IChoiceInstance, + IChoiceGroupInstance> { + @NonNull + private final METASCHEMA.DefineAssembly binding; @NonNull private final Map> properties; @NonNull - private final Lazy> flagContainer; + private final Lazy> flagContainer; @NonNull private final Lazy> modelContainer; + IModelInstanceAbsolute, + INamedModelInstanceAbsolute, + IFieldInstanceAbsolute, + IAssemblyInstanceAbsolute, + IChoiceInstance, + IChoiceGroupInstance>> modelContainer; @NonNull private final Lazy modelConstraints; @NonNull @@ -103,18 +109,23 @@ public DefinitionAssemblyGlobal( @NonNull METASCHEMA.DefineAssembly binding, @NonNull IBoundInstanceModelGroupedAssembly bindingInstance, int position, - @NonNull IBindingModule module, + @NonNull IMetaschemaModule module, @NonNull INodeItemFactory nodeItemFactory) { - super(binding, module); + super(module); + this.binding = binding; this.properties = ModelSupport.parseProperties(ObjectUtils.requireNonNull(binding.getProps())); - this.flagContainer = ObjectUtils.notNull(Lazy.lazy(() -> FlagContainerSupport.of( - binding.getFlags(), - bindingInstance, - this))); + this.flagContainer = ObjectUtils.notNull(Lazy.lazy(() -> { + JsonKey jsonKey = getBinding().getJsonKey(); + return FlagContainerSupport.newFlagContainer( + binding.getFlags(), + bindingInstance, + this, + jsonKey == null ? null : jsonKey.getFlagRef()); + })); this.modelContainer = ObjectUtils.notNull(Lazy.lazy(() -> AssemblyModelContainerSupport.of( binding.getModel(), ObjectUtils - .requireNonNull(bindingInstance.getDefinition().getAssemblyInstanceByName(IAssemblyDefinition.MODEL_QNAME)), + .requireNonNull(bindingInstance.getDefinition().getAssemblyInstanceByName(MODEL_QNAME)), this, nodeItemFactory))); this.modelConstraints = ObjectUtils.notNull(Lazy.lazy(() -> @@ -127,26 +138,30 @@ public DefinitionAssemblyGlobal( } return retval; })); - this.boundNodeItem = ObjectUtils.notNull(Lazy.lazy(() -> (IAssemblyNodeItem) + this.boundNodeItem = ObjectUtils.notNull(Lazy.lazy(() -> ObjectUtils.requireNonNull(ModelSupport.toNodeItem( + module, + bindingInstance.getXmlQName(), + position)))); + } - getContainingModule().getBoundNodeItem() - .getModelItemsByName(bindingInstance.getXmlQName()) - .get(position))); + @NonNull + protected METASCHEMA.DefineAssembly getBinding() { + return binding; } @Override - public IContainerFlagSupport getFlagContainer() { + public IContainerFlagSupport getFlagContainer() { return ObjectUtils.notNull(flagContainer.get()); } @Override public IContainerModelAssemblySupport< - IBindingInstanceModelAbsolute, - IBindingInstanceModelNamedAbsolute, - IBindingInstanceModelFieldAbsolute, - IBindingInstanceModelAssemblyAbsolute, - IInstanceModelChoiceBinding, - IInstanceModelChoiceGroupBinding> getModelContainer() { + IModelInstanceAbsolute, + INamedModelInstanceAbsolute, + IFieldInstanceAbsolute, + IAssemblyInstanceAbsolute, + IChoiceInstance, + IChoiceGroupInstance> getModelContainer() { return ObjectUtils.notNull(modelContainer.get()); } @@ -155,9 +170,8 @@ public IModelConstrained getConstraintSupport() { return ObjectUtils.notNull(modelConstraints.get()); } - @SuppressWarnings("null") @Override - public INodeItem getBoundNodeItem() { + public IAssemblyNodeItem getNodeItem() { return boundNodeItem.get(); } @@ -166,6 +180,10 @@ public Map> getProperties() { return properties; } + // --------------------------------------- + // - Start binding driven code - CPD-OFF - + // --------------------------------------- + @Override public String getFormalName() { return getBinding().getFormalName(); @@ -206,12 +224,6 @@ public MarkupMultiline getRemarks() { return ModelSupport.remarks(getBinding().getRemarks()); } - @Override - public String getJsonKeyFlagName() { - JsonKey jsonKey = getBinding().getJsonKey(); - return jsonKey == null ? null : jsonKey.getFlagRef(); - } - @Override public boolean isRoot() { return getRootName() != null || getRootIndex() != null; 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 7911f1fcb..0d17f5acb 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 @@ -30,19 +30,18 @@ import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine; import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline; import gov.nist.secauto.metaschema.core.metapath.item.node.IAssemblyNodeItem; -import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem; +import gov.nist.secauto.metaschema.core.model.AbstractGlobalFieldDefinition; import gov.nist.secauto.metaschema.core.model.IAttributable; import gov.nist.secauto.metaschema.core.model.IContainerFlagSupport; +import gov.nist.secauto.metaschema.core.model.IFieldInstance; import gov.nist.secauto.metaschema.core.model.IFlagInstance; +import gov.nist.secauto.metaschema.core.model.IMetaschemaModule; import gov.nist.secauto.metaschema.core.model.ModuleScopeEnum; 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.IBoundInstanceModelGroupedAssembly; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingDefinitionModelField; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceFlag; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingModule; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.FieldConstraints; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.JsonKey; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.JsonValueKeyFlag; @@ -51,16 +50,14 @@ import java.util.Map; import java.util.Set; -import javax.xml.namespace.QName; - import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; import nl.talsmasoftware.lazy4j.Lazy; public class DefinitionFieldGlobal - extends AbstractDefinition - implements IBindingDefinitionModelField, - IFeatureBindingContainerFlag { + extends AbstractGlobalFieldDefinition { + @NonNull + private final METASCHEMA.DefineField binding; @NonNull private final Map> properties; @NonNull @@ -68,7 +65,7 @@ public class DefinitionFieldGlobal @Nullable private final Object defaultValue; @NonNull - private final Lazy> flagContainer; + private final Lazy> flagContainer; @NonNull private final Lazy valueConstraints; @NonNull @@ -78,31 +75,41 @@ public DefinitionFieldGlobal( @NonNull METASCHEMA.DefineField binding, @NonNull IBoundInstanceModelGroupedAssembly bindingInstance, int position, - @NonNull IBindingModule module) { - super(binding, module); - this.properties = ModelSupport.parseProperties(ObjectUtils.requireNonNull(getBinding().getProps())); - this.javaTypeAdapter = ModelSupport.dataType(getBinding().getAsType()); - this.defaultValue = ModelSupport.defaultValue(getBinding().getDefault(), this.javaTypeAdapter); - this.flagContainer = ObjectUtils.notNull(Lazy.lazy(() -> FlagContainerSupport.of( - binding.getFlags(), - bindingInstance, - this))); + @NonNull IMetaschemaModule module) { + super(module); + this.binding = binding; + this.properties = ModelSupport.parseProperties(ObjectUtils.requireNonNull(binding.getProps())); + this.javaTypeAdapter = ModelSupport.dataType(binding.getAsType()); + this.defaultValue = ModelSupport.defaultValue(binding.getDefault(), this.javaTypeAdapter); + this.flagContainer = ObjectUtils.notNull(Lazy.lazy(() -> { + JsonKey jsonKey = binding.getJsonKey(); + return FlagContainerSupport.newFlagContainer( + binding.getFlags(), + bindingInstance, + this, + jsonKey == null ? null : jsonKey.getFlagRef()); + })); this.valueConstraints = ObjectUtils.notNull(Lazy.lazy(() -> { IValueConstrained retval = new ValueConstraintSet(); - FieldConstraints constraints = getBinding().getConstraint(); + FieldConstraints constraints = binding.getConstraint(); if (constraints != null) { ConstraintBindingSupport.parse(retval, constraints, ISource.modelSource(module.getLocation())); } return retval; })); - this.boundNodeItem = ObjectUtils.notNull( - Lazy.lazy(() -> (IAssemblyNodeItem) getContainingModule().getBoundNodeItem() - .getModelItemsByName(bindingInstance.getXmlQName()) - .get(position))); + this.boundNodeItem = ObjectUtils.notNull(Lazy.lazy(() -> ObjectUtils.requireNonNull(ModelSupport.toNodeItem( + module, + bindingInstance.getXmlQName(), + position)))); + } + + @NonNull + protected METASCHEMA.DefineField getBinding() { + return binding; } @Override - public IContainerFlagSupport getFlagContainer() { + public IContainerFlagSupport getFlagContainer() { return ObjectUtils.notNull(flagContainer.get()); } @@ -126,6 +133,15 @@ public Object getDefaultValue() { return defaultValue; } + @Override + public IAssemblyNodeItem getNodeItem() { + return boundNodeItem.get(); + } + + // --------------------------------------- + // - Start binding driven code - CPD-OFF - + // --------------------------------------- + @Override public String getFormalName() { return getBinding().getFormalName(); @@ -166,12 +182,6 @@ public MarkupMultiline getRemarks() { return ModelSupport.remarks(getBinding().getRemarks()); } - @Override - public String getJsonKeyFlagName() { - JsonKey jsonKey = getBinding().getJsonKey(); - return jsonKey == null ? null : jsonKey.getFlagRef(); - } - @Override public IFlagInstance getJsonValueKeyFlagInstance() { JsonValueKeyFlag obj = getBinding().getJsonValueKeyFlag(); @@ -186,9 +196,4 @@ public String getJsonValueKeyName() { return getBinding().getJsonValueKey(); } - @SuppressWarnings("null") - @Override - public INodeItem getBoundNodeItem() { - return boundNodeItem.get(); - } } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/DefinitionFlagGlobal.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/DefinitionFlagGlobal.java index e506fe03d..1b272180b 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/DefinitionFlagGlobal.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/DefinitionFlagGlobal.java @@ -31,15 +31,16 @@ import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline; import gov.nist.secauto.metaschema.core.metapath.item.node.IAssemblyNodeItem; import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem; +import gov.nist.secauto.metaschema.core.model.AbstractGlobalFlagDefinition; import gov.nist.secauto.metaschema.core.model.IAttributable; +import gov.nist.secauto.metaschema.core.model.IFlagInstance; +import gov.nist.secauto.metaschema.core.model.IMetaschemaModule; import gov.nist.secauto.metaschema.core.model.ModuleScopeEnum; 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.IBoundInstanceModelGroupedAssembly; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingDefinitionFlag; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingModule; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.FlagConstraints; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.METASCHEMA; @@ -51,8 +52,9 @@ import nl.talsmasoftware.lazy4j.Lazy; public class DefinitionFlagGlobal - extends AbstractDefinition - implements IBindingDefinitionFlag { + extends AbstractGlobalFlagDefinition { + @NonNull + private final METASCHEMA.DefineFlag binding; @NonNull private final Map> properties; @NonNull @@ -82,24 +84,29 @@ public DefinitionFlagGlobal( @NonNull METASCHEMA.DefineFlag binding, @NonNull IBoundInstanceModelGroupedAssembly bindingInstance, int position, - @NonNull IBindingModule module) { - super(binding, module); - this.properties = ModelSupport.parseProperties(ObjectUtils.requireNonNull(getBinding().getProps())); - this.javaTypeAdapter = ModelSupport.dataType(getBinding().getAsType()); - this.defaultValue = ModelSupport.defaultValue(getBinding().getDefault(), this.javaTypeAdapter); + @NonNull IMetaschemaModule module) { + super(module); + this.binding = binding; + this.properties = ModelSupport.parseProperties(ObjectUtils.requireNonNull(binding.getProps())); + this.javaTypeAdapter = ModelSupport.dataType(binding.getAsType()); + this.defaultValue = ModelSupport.defaultValue(binding.getDefault(), this.javaTypeAdapter); this.valueConstraints = ObjectUtils.notNull(Lazy.lazy(() -> { IValueConstrained retval = new ValueConstraintSet(); - FlagConstraints constraints = getBinding().getConstraint(); + FlagConstraints constraints = binding.getConstraint(); if (constraints != null) { ConstraintBindingSupport.parse(retval, constraints, ISource.modelSource(module.getLocation())); } return retval; })); - this.boundNodeItem = ObjectUtils.notNull( - Lazy.lazy(() -> (IAssemblyNodeItem) getContainingModule().getBoundNodeItem() - .getModelItemsByName(bindingInstance.getXmlQName()) - .get(position))); - // new NodeItem(bindingInstance, position, generator) + this.boundNodeItem = ObjectUtils.notNull(Lazy.lazy(() -> ObjectUtils.requireNonNull(ModelSupport.toNodeItem( + module, + bindingInstance.getXmlQName(), + position)))); + } + + @NonNull + protected METASCHEMA.DefineFlag getBinding() { + return binding; } @Override @@ -162,34 +169,8 @@ public MarkupMultiline getRemarks() { return ModelSupport.remarks(getBinding().getRemarks()); } - @SuppressWarnings("null") @Override - public INodeItem getBoundNodeItem() { + public INodeItem getNodeItem() { return boundNodeItem.get(); } - - // private class NodeItem - // extends AbstractGroupedAssemblyInstanceNodeItem { - // private NodeItem( - // @NonNull IAssemblyInstanceGrouped instance, - // int position, - // @NonNull INodeItemGenerator generator) { - // super(instance, position, generator); - // } - // - // @Override - // public IAssemblyNodeItem getParentNodeItem() { - // return getContainingModule().getBoundNodeItem(); - // } - // - // @Override - // public IAssemblyNodeItem getParentContentNodeItem() { - // return getParentNodeItem(); - // } - // - // @Override - // public METASCHEMA.DefineFlag getValue() { - // return getBinding(); - // } - // } } 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 653b6f51e..84b5c6a89 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 @@ -26,59 +26,42 @@ package gov.nist.secauto.metaschema.databind.model.metaschema.impl; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import javax.xml.namespace.QName; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import edu.umd.cs.findbugs.annotations.NonNull; -import edu.umd.cs.findbugs.annotations.Nullable; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; - import gov.nist.secauto.metaschema.core.model.IContainerFlagSupport; +import gov.nist.secauto.metaschema.core.model.IFlagContainerBuilder; +import gov.nist.secauto.metaschema.core.model.IFlagDefinition; +import gov.nist.secauto.metaschema.core.model.IFlagInstance; import gov.nist.secauto.metaschema.core.model.IModelDefinition; import gov.nist.secauto.metaschema.core.model.IModule; -import gov.nist.secauto.metaschema.core.util.CollectionUtil; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelChoiceGroup; import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelGroupedAssembly; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingDefinitionFlag; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingDefinitionModel; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceFlag; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingModule; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.FlagReference; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.InlineDefineFlag; -public class FlagContainerSupport implements IContainerFlagSupport { - private static final Logger LOGGER = LogManager.getLogger(FlagContainerSupport.class); - @NonNull - private final Map flagInstances; +import java.util.List; - @SuppressWarnings("PMD.ShortMethodName") - public static IContainerFlagSupport of( - @Nullable List flags, - @NonNull IBoundInstanceModelGroupedAssembly bindingInstance, - @NonNull IBindingDefinitionModel parent) { - return flags == null || flags.isEmpty() - ? IContainerFlagSupport.empty() - : new FlagContainerSupport( - flags, - bindingInstance, - parent); - } +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; - @SuppressWarnings("PMD.UseConcurrentHashMap") +public final class FlagContainerSupport { @SuppressFBWarnings(value = "CT_CONSTRUCTOR_THROW", justification = "Use of final fields") - public FlagContainerSupport( - @NonNull List flags, + @NonNull + public static IContainerFlagSupport newFlagContainer( + @Nullable List flags, @NonNull IBoundInstanceModelGroupedAssembly bindingInstance, - @NonNull IBindingDefinitionModel parent) { + @NonNull IModelDefinition parent, + @Nullable String jsonKeyName) { + if (flags == null || flags.isEmpty()) { + return IContainerFlagSupport.empty(); + } + // create temporary collections to store the child binding objects - final Map flagInstances = new LinkedHashMap<>(); + IFlagContainerBuilder builder = jsonKeyName == null + ? IContainerFlagSupport.builder() + : IContainerFlagSupport.builder(parent.getContainingModule().toFlagQName(jsonKeyName)); // create counter to track child positions int flagReferencePosition = 0; @@ -90,9 +73,9 @@ public FlagContainerSupport( IBoundInstanceModelGroupedAssembly objInstance = (IBoundInstanceModelGroupedAssembly) instance.getItemInstance(obj); - IBindingInstanceFlag flag; + IFlagInstance flag; if (obj instanceof InlineDefineFlag) { - flag = newFlagInstance( + flag = new InstanceFlagInline( (InlineDefineFlag) obj, objInstance, flagInlineDefinitionPosition++, @@ -107,56 +90,34 @@ public FlagContainerSupport( throw new UnsupportedOperationException(String.format("Unknown flag instance class: %s", obj.getClass())); } - String key = flag.getEffectiveName(); - flagInstances.merge(flag.getXmlQName(), flag, (v1, v2) -> { - if (LOGGER.isErrorEnabled()) { - IModelDefinition owningDefinition = v1.getContainingDefinition(); - IModule module = owningDefinition.getContainingModule(); - LOGGER.error( - String.format( - "Unexpected duplicate flag instance name '%s' in definition '%s' in module name '%s' at '%s'", - key, - owningDefinition.getName(), - module.getShortName(), - module.getLocation())); - } - return ObjectUtils.notNull(v2); - }); + builder.flag(flag); } - this.flagInstances = flagInstances.isEmpty() - ? CollectionUtil.emptyMap() - : CollectionUtil.unmodifiableMap(flagInstances); - } - - @Override - public Map getFlagInstanceMap() { - return flagInstances; + return builder.build(); } - protected static final IBindingInstanceFlag newFlagInstance( - @NonNull InlineDefineFlag obj, - @NonNull IBoundInstanceModelGroupedAssembly objInstance, - int position, - @NonNull IBindingDefinitionModel parent) { - return new InstanceFlagInline(obj, objInstance, position, parent); - } - - protected static final IBindingInstanceFlag newFlagInstance( + @NonNull + private static IFlagInstance newFlagInstance( @NonNull FlagReference obj, @NonNull IBoundInstanceModelGroupedAssembly objInstance, int position, - @NonNull IBindingDefinitionModel parent) { - String flagName = ObjectUtils.requireNonNull(obj.getRef()); - IBindingModule module = parent.getContainingModule(); - IBindingDefinitionFlag definition = module.getScopedFlagDefinitionByName(flagName); + @NonNull IModelDefinition parent) { + IModule module = parent.getContainingModule(); + + QName qname = module.toFlagQName(ObjectUtils.requireNonNull(obj.getRef())); + IFlagDefinition definition = module.getScopedFlagDefinitionByName(qname); if (definition == null) { throw new IllegalStateException( String.format("Unable to resolve flag reference '%s' in definition '%s' in module '%s'", - flagName, + qname, parent.getName(), module.getShortName())); } return new InstanceFlagReference(obj, objInstance, position, definition, parent); } + + private FlagContainerSupport() { + // disable construction + } + } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/GroupAsImpl.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/GroupAsImpl.java index d3ce622cc..0538373bb 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/GroupAsImpl.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/GroupAsImpl.java @@ -26,40 +26,34 @@ package gov.nist.secauto.metaschema.databind.model.metaschema.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.core.util.ObjectUtils; import gov.nist.secauto.metaschema.databind.model.IGroupAs; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.GroupAs; +import javax.xml.namespace.QName; + import edu.umd.cs.findbugs.annotations.NonNull; -import edu.umd.cs.findbugs.annotations.Nullable; class GroupAsImpl implements IGroupAs { @NonNull - private final String name; - @Nullable - private final String namespace; + private final QName qname; @NonNull private final JsonGroupAsBehavior jsonBehavior; @NonNull private final XmlGroupAsBehavior xmlBehavior; - public GroupAsImpl(@NonNull GroupAs groupAs, @Nullable String namespace) { - this.name = ObjectUtils.requireNonNull(groupAs.getName()); - this.namespace = namespace; + public GroupAsImpl(@NonNull GroupAs groupAs, @NonNull IModule module) { + this.qname = module.toModelQName(ObjectUtils.requireNonNull(groupAs.getName())); this.jsonBehavior = ModelSupport.groupAsJsonBehavior(groupAs.getInJson()); this.xmlBehavior = ModelSupport.groupAsXmlBehavior(groupAs.getInXml()); } @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/metaschema/impl/IFeatureBindingContainerModel.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/IFeatureBindingContainerModel.java index 63be50118..cf44f4ada 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/IFeatureBindingContainerModel.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/IFeatureBindingContainerModel.java @@ -26,68 +26,69 @@ package gov.nist.secauto.metaschema.databind.model.metaschema.impl; +import gov.nist.secauto.metaschema.core.model.IAssemblyInstanceAbsolute; +import gov.nist.secauto.metaschema.core.model.IContainerModelAbsolute; +import gov.nist.secauto.metaschema.core.model.IContainerModelSupport; +import gov.nist.secauto.metaschema.core.model.IFeatureContainerModel; +import gov.nist.secauto.metaschema.core.model.IFieldInstanceAbsolute; +import gov.nist.secauto.metaschema.core.model.IModelInstanceAbsolute; +import gov.nist.secauto.metaschema.core.model.INamedModelInstanceAbsolute; + import java.util.Collection; import javax.xml.namespace.QName; import edu.umd.cs.findbugs.annotations.NonNull; -import gov.nist.secauto.metaschema.core.model.IContainerModelSupport; -import gov.nist.secauto.metaschema.core.model.IFeatureContainerModel; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingContainerModelAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelAssemblyAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelFieldAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelNamedAbsolute; public interface IFeatureBindingContainerModel - extends IBindingContainerModelAbsolute, IFeatureContainerModel< - IBindingInstanceModelAbsolute, - IBindingInstanceModelNamedAbsolute, - IBindingInstanceModelFieldAbsolute, - IBindingInstanceModelAssemblyAbsolute> { + extends IContainerModelAbsolute, IFeatureContainerModel< + IModelInstanceAbsolute, + INamedModelInstanceAbsolute, + IFieldInstanceAbsolute, + IAssemblyInstanceAbsolute> { @Override @NonNull IContainerModelSupport< - IBindingInstanceModelAbsolute, - IBindingInstanceModelNamedAbsolute, - IBindingInstanceModelFieldAbsolute, - IBindingInstanceModelAssemblyAbsolute> getModelContainer(); + IModelInstanceAbsolute, + INamedModelInstanceAbsolute, + IFieldInstanceAbsolute, + IAssemblyInstanceAbsolute> getModelContainer(); @Override - default Collection getModelInstances() { + default Collection getModelInstances() { return getModelContainer().getModelInstances(); } @Override - default IBindingInstanceModelNamedAbsolute getNamedModelInstanceByName(QName name) { + default INamedModelInstanceAbsolute getNamedModelInstanceByName(QName name) { return getModelContainer().getNamedModelInstanceMap().get(name); } @SuppressWarnings("null") @Override - default Collection getNamedModelInstances() { + default Collection getNamedModelInstances() { return getModelContainer().getNamedModelInstanceMap().values(); } @Override - default IBindingInstanceModelFieldAbsolute getFieldInstanceByName(QName name) { + default IFieldInstanceAbsolute getFieldInstanceByName(QName name) { return getModelContainer().getFieldInstanceMap().get(name); } @SuppressWarnings("null") @Override - default Collection getFieldInstances() { + default Collection getFieldInstances() { return getModelContainer().getFieldInstanceMap().values(); } @Override - default IBindingInstanceModelAssemblyAbsolute getAssemblyInstanceByName(QName name) { + default IAssemblyInstanceAbsolute getAssemblyInstanceByName(QName name) { return getModelContainer().getAssemblyInstanceMap().get(name); } @SuppressWarnings("null") @Override - default Collection getAssemblyInstances() { + default Collection getAssemblyInstances() { return getModelContainer().getAssemblyInstanceMap().values(); } } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/IFeatureBindingContainerModelAssembly.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/IFeatureBindingContainerModelAssembly.java index 96a682e3d..cb2074d2e 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/IFeatureBindingContainerModelAssembly.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/IFeatureBindingContainerModelAssembly.java @@ -26,6 +26,15 @@ package gov.nist.secauto.metaschema.databind.model.metaschema.impl; +import gov.nist.secauto.metaschema.core.model.IAssemblyInstanceAbsolute; +import gov.nist.secauto.metaschema.core.model.IChoiceGroupInstance; +import gov.nist.secauto.metaschema.core.model.IChoiceInstance; +import gov.nist.secauto.metaschema.core.model.IContainerModelAssemblySupport; +import gov.nist.secauto.metaschema.core.model.IFeatureContainerModelAssembly; +import gov.nist.secauto.metaschema.core.model.IFieldInstanceAbsolute; +import gov.nist.secauto.metaschema.core.model.IModelInstanceAbsolute; +import gov.nist.secauto.metaschema.core.model.INamedModelInstanceAbsolute; + import java.util.Collection; import java.util.List; import java.util.Map; @@ -33,86 +42,76 @@ import javax.xml.namespace.QName; import edu.umd.cs.findbugs.annotations.NonNull; -import gov.nist.secauto.metaschema.core.model.IContainerModelAssemblySupport; -import gov.nist.secauto.metaschema.core.model.IFeatureContainerModelAssembly; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingContainerModelAssembly; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelAssemblyAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelFieldAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelNamedAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IInstanceModelChoiceBinding; -import gov.nist.secauto.metaschema.databind.model.metaschema.IInstanceModelChoiceGroupBinding; public interface IFeatureBindingContainerModelAssembly - extends IBindingContainerModelAssembly, - IFeatureBindingContainerModel, + extends IFeatureBindingContainerModel, IFeatureContainerModelAssembly< - IBindingInstanceModelAbsolute, - IBindingInstanceModelNamedAbsolute, - IBindingInstanceModelFieldAbsolute, - IBindingInstanceModelAssemblyAbsolute, - IInstanceModelChoiceBinding, - IInstanceModelChoiceGroupBinding> { + IModelInstanceAbsolute, + INamedModelInstanceAbsolute, + IFieldInstanceAbsolute, + IAssemblyInstanceAbsolute, + IChoiceInstance, + IChoiceGroupInstance> { @Override @NonNull IContainerModelAssemblySupport< - IBindingInstanceModelAbsolute, - IBindingInstanceModelNamedAbsolute, - IBindingInstanceModelFieldAbsolute, - IBindingInstanceModelAssemblyAbsolute, - IInstanceModelChoiceBinding, - IInstanceModelChoiceGroupBinding> getModelContainer(); + IModelInstanceAbsolute, + INamedModelInstanceAbsolute, + IFieldInstanceAbsolute, + IAssemblyInstanceAbsolute, + IChoiceInstance, + IChoiceGroupInstance> getModelContainer(); @Override - default Collection getModelInstances() { + default Collection getModelInstances() { return getModelContainer().getModelInstances(); } @Override - default IBindingInstanceModelNamedAbsolute getNamedModelInstanceByName(QName name) { + default INamedModelInstanceAbsolute getNamedModelInstanceByName(QName name) { return getModelContainer().getNamedModelInstanceMap().get(name); } @SuppressWarnings("null") @Override - default Collection getNamedModelInstances() { + default Collection getNamedModelInstances() { return getModelContainer().getNamedModelInstanceMap().values(); } @Override - default IBindingInstanceModelFieldAbsolute getFieldInstanceByName(QName name) { + default IFieldInstanceAbsolute getFieldInstanceByName(QName name) { return getModelContainer().getFieldInstanceMap().get(name); } @SuppressWarnings("null") @Override - default Collection getFieldInstances() { + default Collection getFieldInstances() { return getModelContainer().getFieldInstanceMap().values(); } @Override - default IBindingInstanceModelAssemblyAbsolute getAssemblyInstanceByName(QName name) { + default IAssemblyInstanceAbsolute getAssemblyInstanceByName(QName name) { return getModelContainer().getAssemblyInstanceMap().get(name); } @SuppressWarnings("null") @Override - default Collection getAssemblyInstances() { + default Collection getAssemblyInstances() { return getModelContainer().getAssemblyInstanceMap().values(); } @Override - default List getChoiceInstances() { + default List getChoiceInstances() { return getModelContainer().getChoiceInstances(); } @Override - default IInstanceModelChoiceGroupBinding getChoiceGroupInstanceByName(String name) { + default IChoiceGroupInstance getChoiceGroupInstanceByName(String name) { return getModelContainer().getChoiceGroupInstanceMap().get(name); } @Override - default Map getChoiceGroupInstances() { + default Map getChoiceGroupInstances() { return getModelContainer().getChoiceGroupInstanceMap(); } } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/IFeatureInstanceModelGroupAs.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/IFeatureInstanceModelGroupAs.java index b724b7825..3e98330c2 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/IFeatureInstanceModelGroupAs.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/IFeatureInstanceModelGroupAs.java @@ -26,14 +26,14 @@ package gov.nist.secauto.metaschema.databind.model.metaschema.impl; +import gov.nist.secauto.metaschema.core.model.IModelInstanceAbsolute; 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.metaschema.IBindingInstanceModelAbsolute; import edu.umd.cs.findbugs.annotations.NonNull; -public interface IFeatureInstanceModelGroupAs extends IBindingInstanceModelAbsolute { +public interface IFeatureInstanceModelGroupAs extends IModelInstanceAbsolute { @NonNull IGroupAs getGroupAs(); diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceFlagInline.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceFlagInline.java index afac75db4..7eef0377f 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceFlagInline.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceFlagInline.java @@ -30,17 +30,17 @@ import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine; import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline; import gov.nist.secauto.metaschema.core.metapath.item.node.IAssemblyNodeItem; -import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem; +import gov.nist.secauto.metaschema.core.model.AbstractInlineFlagDefinition; import gov.nist.secauto.metaschema.core.model.IAttributable; -import gov.nist.secauto.metaschema.core.model.IFeatureDefinitionInstanceInlined; +import gov.nist.secauto.metaschema.core.model.IFeatureValueless; +import gov.nist.secauto.metaschema.core.model.IFlagDefinition; +import gov.nist.secauto.metaschema.core.model.IFlagInstance; +import gov.nist.secauto.metaschema.core.model.IModelDefinition; 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.IBoundInstanceModelGroupedAssembly; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingDefinitionFlag; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingDefinitionModel; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceFlag; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.FlagConstraints; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.InlineDefineFlag; @@ -52,9 +52,13 @@ import nl.talsmasoftware.lazy4j.Lazy; public class InstanceFlagInline - extends AbstractInstance - implements IBindingInstanceFlag, IBindingDefinitionFlag, - IFeatureDefinitionInstanceInlined { + extends AbstractInlineFlagDefinition< + IModelDefinition, + IFlagDefinition, + IFlagInstance> + implements IFeatureValueless { + @NonNull + private final InlineDefineFlag binding; @NonNull private final Map> properties; @NonNull @@ -70,34 +74,39 @@ public InstanceFlagInline( @NonNull InlineDefineFlag binding, @NonNull IBoundInstanceModelGroupedAssembly bindingInstance, int position, - @NonNull IBindingDefinitionModel parent) { - super(binding, parent); - this.properties = ModelSupport.parseProperties(ObjectUtils.requireNonNull(getBinding().getProps())); - this.javaTypeAdapter = ModelSupport.dataType(getBinding().getAsType()); - this.defaultValue = ModelSupport.defaultValue(getBinding().getDefault(), this.javaTypeAdapter); + @NonNull IModelDefinition parent) { + super(parent); + this.binding = binding; + this.properties = ModelSupport.parseProperties(ObjectUtils.requireNonNull(binding.getProps())); + this.javaTypeAdapter = ModelSupport.dataType(binding.getAsType()); + this.defaultValue = ModelSupport.defaultValue(binding.getDefault(), this.javaTypeAdapter); this.valueConstraints = ObjectUtils.notNull(Lazy.lazy(() -> { IValueConstrained retval = new ValueConstraintSet(); - FlagConstraints constraints = getBinding().getConstraint(); + FlagConstraints constraints = binding.getConstraint(); if (constraints != null) { ConstraintBindingSupport.parse(retval, constraints, ISource.modelSource()); } return retval; })); this.boundNodeItem = ObjectUtils.notNull( - Lazy.lazy(() -> (IAssemblyNodeItem) getContainingModule().getBoundNodeItem() + Lazy.lazy(() -> (IAssemblyNodeItem) ObjectUtils.notNull(getContainingModule().getNodeItem()) .getModelItemsByName(bindingInstance.getXmlQName()) .get(position))); } + @NonNull + protected InlineDefineFlag getBinding() { + return binding; + } + @SuppressWarnings("null") @Override public IValueConstrained getConstraintSupport() { return valueConstraints.get(); } - @SuppressWarnings("null") @Override - public INodeItem getBoundNodeItem() { + public IAssemblyNodeItem getNodeItem() { return boundNodeItem.get(); } @@ -116,16 +125,6 @@ public Object getDefaultValue() { return defaultValue; } - @Override - public IBindingInstanceFlag getInlineInstance() { - return this; - } - - @Override - public IBindingDefinitionFlag getDefinition() { - return this; - } - @Override public String getName() { return ObjectUtils.notNull(getBinding().getName()); diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceFlagReference.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceFlagReference.java index 7710abebe..e63d35245 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceFlagReference.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceFlagReference.java @@ -29,14 +29,14 @@ import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine; import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline; import gov.nist.secauto.metaschema.core.metapath.item.node.IAssemblyNodeItem; -import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem; +import gov.nist.secauto.metaschema.core.model.AbstractFlagInstance; import gov.nist.secauto.metaschema.core.model.IAttributable; -import gov.nist.secauto.metaschema.core.model.IFeatureDefinitionReferenceInstance; +import gov.nist.secauto.metaschema.core.model.IFeatureValueless; +import gov.nist.secauto.metaschema.core.model.IFlagDefinition; +import gov.nist.secauto.metaschema.core.model.IFlagInstance; +import gov.nist.secauto.metaschema.core.model.IModelDefinition; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelGroupedAssembly; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingDefinitionFlag; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingDefinitionModel; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceFlag; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.FlagReference; import java.util.Map; @@ -47,11 +47,14 @@ import nl.talsmasoftware.lazy4j.Lazy; public class InstanceFlagReference - extends AbstractInstance - implements IBindingInstanceFlag, - IFeatureDefinitionReferenceInstance { + extends AbstractFlagInstance< + IModelDefinition, + IFlagDefinition, IFlagInstance> + implements IFeatureValueless { @NonNull - private final IBindingDefinitionFlag definition; + private final FlagReference binding; + @NonNull + private final IFlagDefinition definition; @NonNull private final Map> properties; @Nullable @@ -60,29 +63,34 @@ public class InstanceFlagReference private final Lazy boundNodeItem; public InstanceFlagReference( - @NonNull FlagReference obj, + @NonNull FlagReference binding, @NonNull IBoundInstanceModelGroupedAssembly bindingInstance, int position, - @NonNull IBindingDefinitionFlag definition, - @NonNull IBindingDefinitionModel parent) { - super(obj, parent); + @NonNull IFlagDefinition definition, + @NonNull IModelDefinition parent) { + super(parent); + this.binding = binding; this.definition = definition; - this.properties = ModelSupport.parseProperties(ObjectUtils.requireNonNull(getBinding().getProps())); - this.defaultValue = ModelSupport.defaultValue(getBinding().getDefault(), definition.getJavaTypeAdapter()); + this.properties = ModelSupport.parseProperties(ObjectUtils.requireNonNull(binding.getProps())); + this.defaultValue = ModelSupport.defaultValue(binding.getDefault(), definition.getJavaTypeAdapter()); this.boundNodeItem = ObjectUtils.notNull( - Lazy.lazy(() -> (IAssemblyNodeItem) getContainingModule().getBoundNodeItem() + Lazy.lazy(() -> (IAssemblyNodeItem) ObjectUtils.notNull(getContainingModule().getNodeItem()) .getModelItemsByName(bindingInstance.getXmlQName()) .get(position))); } - @SuppressWarnings("null") + @NonNull + protected FlagReference getBinding() { + return binding; + } + @Override - public INodeItem getBoundNodeItem() { + public IAssemblyNodeItem getNodeItem() { return boundNodeItem.get(); } @Override - public IBindingDefinitionFlag getDefinition() { + public IFlagDefinition getDefinition() { return definition; } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceModelAssemblyInline.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceModelAssemblyInline.java index 9cc18c5c9..357f25762 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceModelAssemblyInline.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceModelAssemblyInline.java @@ -28,53 +28,71 @@ import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine; import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline; +import gov.nist.secauto.metaschema.core.metapath.item.node.IAssemblyNodeItem; import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItemFactory; +import gov.nist.secauto.metaschema.core.model.AbstractInlineAssemblyDefinition; import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition; +import gov.nist.secauto.metaschema.core.model.IAssemblyInstanceAbsolute; +import gov.nist.secauto.metaschema.core.model.IAttributable; +import gov.nist.secauto.metaschema.core.model.IChoiceGroupInstance; +import gov.nist.secauto.metaschema.core.model.IChoiceInstance; import gov.nist.secauto.metaschema.core.model.IContainerFlagSupport; +import gov.nist.secauto.metaschema.core.model.IContainerModelAbsolute; import gov.nist.secauto.metaschema.core.model.IContainerModelAssemblySupport; -import gov.nist.secauto.metaschema.core.model.IFeatureDefinitionInstanceInlined; -import gov.nist.secauto.metaschema.core.model.IGroupable; +import gov.nist.secauto.metaschema.core.model.IFieldInstanceAbsolute; +import gov.nist.secauto.metaschema.core.model.IFlagInstance; +import gov.nist.secauto.metaschema.core.model.IModelInstanceAbsolute; +import gov.nist.secauto.metaschema.core.model.INamedModelInstanceAbsolute; import gov.nist.secauto.metaschema.core.model.constraint.AssemblyConstraintSet; import gov.nist.secauto.metaschema.core.model.constraint.IModelConstrained; import gov.nist.secauto.metaschema.core.model.constraint.ISource; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelGroupedAssembly; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingContainerModelAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingDefinitionAssembly; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceFlag; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelAssemblyAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelFieldAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelNamedAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IInstanceModelChoiceBinding; -import gov.nist.secauto.metaschema.databind.model.metaschema.IInstanceModelChoiceGroupBinding; +import gov.nist.secauto.metaschema.databind.model.IGroupAs; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.AssemblyConstraints; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.InlineDefineAssembly; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.JsonKey; import java.math.BigInteger; +import java.util.Map; +import java.util.Set; import edu.umd.cs.findbugs.annotations.NonNull; import nl.talsmasoftware.lazy4j.Lazy; public class InstanceModelAssemblyInline - extends AbstractInstanceModelNamedInline< - InlineDefineAssembly, - IBindingContainerModelAbsolute> - implements IBindingInstanceModelAssemblyAbsolute, IBindingDefinitionAssembly, - IFeatureDefinitionInstanceInlined, - IFeatureBindingContainerFlag, + extends AbstractInlineAssemblyDefinition< + IContainerModelAbsolute, + IAssemblyDefinition, + IAssemblyInstanceAbsolute, + IAssemblyDefinition, + IFlagInstance, + IModelInstanceAbsolute, + INamedModelInstanceAbsolute, + IFieldInstanceAbsolute, + IAssemblyInstanceAbsolute, + IChoiceInstance, + IChoiceGroupInstance> + implements IAssemblyInstanceAbsolute, IFeatureInstanceModelGroupAs, IFeatureBindingContainerModelAssembly { @NonNull - private final Lazy> flagContainer; + private final InlineDefineAssembly binding; + @NonNull + private final Map> properties; + @NonNull + private final IGroupAs groupAs; + @NonNull + private final Lazy boundNodeItem; + @NonNull + private final Lazy> flagContainer; @NonNull private final Lazy> modelContainer; + IModelInstanceAbsolute, + INamedModelInstanceAbsolute, + IFieldInstanceAbsolute, + IAssemblyInstanceAbsolute, + IChoiceInstance, + IChoiceGroupInstance>> modelContainer; @NonNull private final Lazy modelConstraints; @@ -97,22 +115,28 @@ public InstanceModelAssemblyInline( @NonNull InlineDefineAssembly binding, @NonNull IBoundInstanceModelGroupedAssembly bindingInstance, int position, - @NonNull IBindingContainerModelAbsolute parent, + @NonNull IContainerModelAbsolute parent, @NonNull INodeItemFactory nodeItemFactory) { - super(binding, - bindingInstance, - position, - parent, - ObjectUtils.requireNonNull(binding.getProps()), - binding.getGroupAs()); - this.flagContainer = ObjectUtils.notNull(Lazy.lazy(() -> FlagContainerSupport.of( - binding.getFlags(), - bindingInstance, - this))); + super(parent); + this.binding = binding; + this.properties = ModelSupport.parseProperties(ObjectUtils.requireNonNull(binding.getProps())); + this.groupAs = ModelSupport.groupAs(binding.getGroupAs(), parent.getOwningDefinition().getContainingModule()); + this.boundNodeItem = ObjectUtils.notNull( + Lazy.lazy(() -> (IAssemblyNodeItem) ObjectUtils.notNull(getContainingDefinition().getNodeItem()) + .getModelItemsByName(bindingInstance.getXmlQName()) + .get(position))); + this.flagContainer = ObjectUtils.notNull(Lazy.lazy(() -> { + JsonKey jsonKey = getBinding().getJsonKey(); + return FlagContainerSupport.newFlagContainer( + binding.getFlags(), + bindingInstance, + this, + jsonKey == null ? null : jsonKey.getFlagRef()); + })); this.modelContainer = ObjectUtils.notNull(Lazy.lazy(() -> AssemblyModelContainerSupport.of( binding.getModel(), ObjectUtils - .requireNonNull(bindingInstance.getDefinition().getAssemblyInstanceByName(IAssemblyDefinition.MODEL_QNAME)), + .requireNonNull(bindingInstance.getDefinition().getAssemblyInstanceByName(MODEL_QNAME)), this, nodeItemFactory))); this.modelConstraints = ObjectUtils.notNull(Lazy.lazy(() -> { @@ -128,20 +152,41 @@ public InstanceModelAssemblyInline( })); } + @NonNull + protected InlineDefineAssembly getBinding() { + getContainingDefinition(); + return binding; + } + + @Override + public Map> getProperties() { + return properties; + } + + @Override + public IGroupAs getGroupAs() { + return groupAs; + } + + @Override + public IAssemblyNodeItem getNodeItem() { + return boundNodeItem.get(); + } + @SuppressWarnings("null") @Override - public IContainerFlagSupport getFlagContainer() { + public IContainerFlagSupport getFlagContainer() { return flagContainer.get(); } @Override public IContainerModelAssemblySupport< - IBindingInstanceModelAbsolute, - IBindingInstanceModelNamedAbsolute, - IBindingInstanceModelFieldAbsolute, - IBindingInstanceModelAssemblyAbsolute, - IInstanceModelChoiceBinding, - IInstanceModelChoiceGroupBinding> getModelContainer() { + IModelInstanceAbsolute, + INamedModelInstanceAbsolute, + IFieldInstanceAbsolute, + IAssemblyInstanceAbsolute, + IChoiceInstance, + IChoiceGroupInstance> getModelContainer() { return ObjectUtils.notNull(modelContainer.get()); } @@ -150,15 +195,9 @@ public IModelConstrained getConstraintSupport() { return ObjectUtils.notNull(modelConstraints.get()); } - @Override - public InstanceModelAssemblyInline getDefinition() { - return this; - } - - @Override - public IBindingInstanceModelAssemblyAbsolute getInlineInstance() { - return this; - } + // --------------------------------------- + // - Start binding driven code - CPD-OFF - + // --------------------------------------- @Override public String getName() { @@ -185,23 +224,15 @@ public MarkupMultiline getRemarks() { return ModelSupport.remarks(getBinding().getRemarks()); } - @Override - public String getJsonKeyFlagName() { - JsonKey jsonKey = getBinding().getJsonKey(); - return jsonKey == null ? null : jsonKey.getFlagRef(); - } - @Override public int getMinOccurs() { BigInteger min = getBinding().getMinOccurs(); - return min == null ? IGroupable.DEFAULT_GROUP_AS_MIN_OCCURS : min.intValueExact(); + return min == null ? DEFAULT_GROUP_AS_MIN_OCCURS : min.intValueExact(); } @Override public int getMaxOccurs() { String max = getBinding().getMaxOccurs(); - return max == null - ? IGroupable.DEFAULT_GROUP_AS_MIN_OCCURS - : ModelSupport.maxOccurs(max); + return max == null ? DEFAULT_GROUP_AS_MAX_OCCURS : ModelSupport.maxOccurs(max); } } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceModelAssemblyReference.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceModelAssemblyReference.java index 710edcb55..62980c39d 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceModelAssemblyReference.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceModelAssemblyReference.java @@ -28,26 +28,42 @@ 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.IGroupable; +import gov.nist.secauto.metaschema.core.metapath.item.node.IAssemblyNodeItem; +import gov.nist.secauto.metaschema.core.model.AbstractAssemblyInstance; +import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition; +import gov.nist.secauto.metaschema.core.model.IAssemblyInstanceAbsolute; +import gov.nist.secauto.metaschema.core.model.IAttributable; +import gov.nist.secauto.metaschema.core.model.IContainerModelAbsolute; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelGroupedAssembly; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingContainerModelAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingDefinitionAssembly; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelAssemblyAbsolute; +import gov.nist.secauto.metaschema.databind.model.IGroupAs; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.AssemblyReference; import java.math.BigInteger; +import java.util.Map; +import java.util.Set; import edu.umd.cs.findbugs.annotations.NonNull; +import nl.talsmasoftware.lazy4j.Lazy; public class InstanceModelAssemblyReference - extends AbstractInstanceModelNamedReference< - AssemblyReference, - IBindingDefinitionAssembly, - IBindingContainerModelAbsolute> - implements IBindingInstanceModelAssemblyAbsolute, - IFeatureDefinitionReferenceInstance { + extends AbstractAssemblyInstance< + IContainerModelAbsolute, + IAssemblyDefinition, + IAssemblyInstanceAbsolute, + IAssemblyDefinition> + implements IAssemblyInstanceAbsolute, IFeatureInstanceModelGroupAs { + @NonNull + private final AssemblyReference binding; + @NonNull + private final IAssemblyDefinition definition; + @NonNull + private final Map> properties; + @NonNull + private final IGroupAs groupAs; + @NonNull + private final Lazy boundNodeItem; + /** * Construct a new assembly reference. * @@ -67,15 +83,51 @@ public InstanceModelAssemblyReference( @NonNull AssemblyReference binding, @NonNull IBoundInstanceModelGroupedAssembly bindingInstance, int position, - @NonNull IBindingDefinitionAssembly definition, - @NonNull IBindingContainerModelAbsolute parent) { - super(binding, - bindingInstance, - position, - definition, - parent, - ObjectUtils.requireNonNull(binding.getProps()), - binding.getGroupAs()); + @NonNull IAssemblyDefinition definition, + @NonNull IContainerModelAbsolute parent) { + super(parent); + this.binding = binding; + this.definition = definition; + this.properties = ModelSupport.parseProperties(ObjectUtils.requireNonNull(binding.getProps())); + this.groupAs = ModelSupport.groupAs(binding.getGroupAs(), parent.getOwningDefinition().getContainingModule()); + this.boundNodeItem = ObjectUtils.notNull( + Lazy.lazy(() -> (IAssemblyNodeItem) ObjectUtils.notNull(getContainingDefinition().getNodeItem()) + .getModelItemsByName(bindingInstance.getXmlQName()) + .get(position))); + } + + @Override + public IAssemblyDefinition getDefinition() { + return definition; + } + + @NonNull + protected AssemblyReference getBinding() { + return binding; + } + + @Override + public Map> getProperties() { + return properties; + } + + @Override + public IGroupAs getGroupAs() { + return groupAs; + } + + @Override + public IAssemblyNodeItem getNodeItem() { + return boundNodeItem.get(); + } + + // --------------------------------------- + // - Start binding driven code - CPD-OFF - + // --------------------------------------- + + @Override + public String getName() { + return getDefinition().getName(); } @Override @@ -111,14 +163,12 @@ public MarkupMultiline getRemarks() { @Override public int getMinOccurs() { BigInteger min = getBinding().getMinOccurs(); - return min == null ? IGroupable.DEFAULT_GROUP_AS_MIN_OCCURS : min.intValueExact(); + return min == null ? DEFAULT_GROUP_AS_MIN_OCCURS : min.intValueExact(); } @Override public int getMaxOccurs() { String max = getBinding().getMaxOccurs(); - return max == null - ? IGroupable.DEFAULT_GROUP_AS_MIN_OCCURS - : ModelSupport.maxOccurs(max); + return max == null ? DEFAULT_GROUP_AS_MAX_OCCURS : ModelSupport.maxOccurs(max); } } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceModelChoice.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceModelChoice.java index 387e0388c..1c17ec0d9 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceModelChoice.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceModelChoice.java @@ -28,32 +28,37 @@ import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline; import gov.nist.secauto.metaschema.core.metapath.item.node.IAssemblyNodeItem; -import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem; import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItemFactory; +import gov.nist.secauto.metaschema.core.model.AbstractChoiceInstance; +import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition; +import gov.nist.secauto.metaschema.core.model.IAssemblyInstanceAbsolute; import gov.nist.secauto.metaschema.core.model.IContainerModelSupport; +import gov.nist.secauto.metaschema.core.model.IFieldInstanceAbsolute; +import gov.nist.secauto.metaschema.core.model.IModelInstanceAbsolute; +import gov.nist.secauto.metaschema.core.model.INamedModelInstanceAbsolute; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelGroupedAssembly; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingDefinitionAssembly; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelAssemblyAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelFieldAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelNamedAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IInstanceModelChoiceBinding; +import gov.nist.secauto.metaschema.databind.model.metaschema.binding.AssemblyModel; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.AssemblyModel.Choice; import edu.umd.cs.findbugs.annotations.NonNull; import nl.talsmasoftware.lazy4j.Lazy; public class InstanceModelChoice - extends AbstractInstanceModel - implements IInstanceModelChoiceBinding, - IFeatureBindingContainerModel { + extends AbstractChoiceInstance< + IAssemblyDefinition, + IModelInstanceAbsolute, + INamedModelInstanceAbsolute, + IFieldInstanceAbsolute, + IAssemblyInstanceAbsolute> { + @NonNull + private final AssemblyModel.Choice binding; @NonNull private final Lazy> modelContainer; + IModelInstanceAbsolute, + INamedModelInstanceAbsolute, + IFieldInstanceAbsolute, + IAssemblyInstanceAbsolute>> modelContainer; @NonNull private final Lazy boundNodeItem; @@ -61,45 +66,45 @@ public InstanceModelChoice( @NonNull Choice binding, @NonNull IBoundInstanceModelGroupedAssembly bindingInstance, int position, - @NonNull IBindingDefinitionAssembly parent, + @NonNull IAssemblyDefinition parent, @NonNull INodeItemFactory nodeItemFactory) { - super(binding, parent); + super(parent); + this.binding = binding; this.modelContainer = ObjectUtils.notNull(Lazy.lazy(() -> ChoiceModelContainerSupport.of( binding, bindingInstance, this, nodeItemFactory))); this.boundNodeItem = ObjectUtils.notNull( - Lazy.lazy(() -> (IAssemblyNodeItem) getContainingDefinition().getBoundNodeItem() + Lazy.lazy(() -> (IAssemblyNodeItem) ObjectUtils.notNull(getContainingDefinition().getNodeItem()) .getModelItemsByName(bindingInstance.getXmlQName()) .get(position))); } + @NonNull + protected AssemblyModel.Choice getBinding() { + return binding; + } + @Override public IContainerModelSupport< - IBindingInstanceModelAbsolute, - IBindingInstanceModelNamedAbsolute, - IBindingInstanceModelFieldAbsolute, - IBindingInstanceModelAssemblyAbsolute> getModelContainer() { + IModelInstanceAbsolute, + INamedModelInstanceAbsolute, + IFieldInstanceAbsolute, + IAssemblyInstanceAbsolute> getModelContainer() { return ObjectUtils.notNull(modelContainer.get()); } - @SuppressWarnings("null") @Override - public INodeItem getBoundNodeItem() { + public IAssemblyNodeItem getNodeItem() { return boundNodeItem.get(); } @Override - public IBindingDefinitionAssembly getOwningDefinition() { + public IAssemblyDefinition getOwningDefinition() { return getContainingDefinition(); } - @Override - public String getJsonKeyFlagName() { - return null; - } - @Override public MarkupMultiline getRemarks() { // no remarks diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceModelChoiceGroup.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceModelChoiceGroup.java index 6d4a6dd1d..647cfd946 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceModelChoiceGroup.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceModelChoiceGroup.java @@ -27,20 +27,16 @@ package gov.nist.secauto.metaschema.databind.model.metaschema.impl; import gov.nist.secauto.metaschema.core.metapath.item.node.IAssemblyNodeItem; -import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem; import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItemFactory; -import gov.nist.secauto.metaschema.core.model.IChoiceGroupInstance; +import gov.nist.secauto.metaschema.core.model.AbstractChoiceGroupInstance; +import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition; +import gov.nist.secauto.metaschema.core.model.IAssemblyInstanceGrouped; import gov.nist.secauto.metaschema.core.model.IContainerModelSupport; -import gov.nist.secauto.metaschema.core.model.IFeatureContainerModelGrouped; -import gov.nist.secauto.metaschema.core.model.IGroupable; +import gov.nist.secauto.metaschema.core.model.IFieldInstanceGrouped; +import gov.nist.secauto.metaschema.core.model.INamedModelInstanceGrouped; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelGroupedAssembly; import gov.nist.secauto.metaschema.databind.model.IGroupAs; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingDefinitionAssembly; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelAssemblyGrouped; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelFieldGrouped; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelNamedGrouped; -import gov.nist.secauto.metaschema.databind.model.metaschema.IInstanceModelChoiceGroupBinding; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.AssemblyModel; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.JsonKey; @@ -50,21 +46,22 @@ import nl.talsmasoftware.lazy4j.Lazy; public class InstanceModelChoiceGroup - extends AbstractInstanceModel - implements IInstanceModelChoiceGroupBinding, - IFeatureContainerModelGrouped< - IBindingInstanceModelNamedGrouped, - IBindingInstanceModelFieldGrouped, - IBindingInstanceModelAssemblyGrouped>, - IFeatureInstanceModelGroupAs { + extends AbstractChoiceGroupInstance< + IAssemblyDefinition, + INamedModelInstanceGrouped, + IFieldInstanceGrouped, + IAssemblyInstanceGrouped> + implements IFeatureInstanceModelGroupAs { + @NonNull + private final AssemblyModel.ChoiceGroup binding; @NonNull private final IGroupAs groupAs; @NonNull private final Lazy> modelContainer; + INamedModelInstanceGrouped, + INamedModelInstanceGrouped, + IFieldInstanceGrouped, + IAssemblyInstanceGrouped>> modelContainer; @NonNull private final Lazy boundNodeItem; @@ -72,27 +69,33 @@ public InstanceModelChoiceGroup( @NonNull AssemblyModel.ChoiceGroup binding, @NonNull IBoundInstanceModelGroupedAssembly bindingInstance, int position, - @NonNull IBindingDefinitionAssembly parent, + @NonNull IAssemblyDefinition parent, @NonNull INodeItemFactory nodeItemFactory) { - super(binding, parent); - this.groupAs = ModelSupport.groupAs(binding.getGroupAs(), parent.getXmlNamespace()); + super(parent); + this.binding = binding; + this.groupAs = ModelSupport.groupAs(binding.getGroupAs(), parent.getContainingModule()); this.modelContainer = ObjectUtils.notNull(Lazy.lazy(() -> ChoiceGroupModelContainerSupport.of( binding, bindingInstance, this, nodeItemFactory))); this.boundNodeItem = ObjectUtils.notNull( - Lazy.lazy(() -> (IAssemblyNodeItem) getContainingDefinition().getBoundNodeItem() + Lazy.lazy(() -> (IAssemblyNodeItem) ObjectUtils.notNull(getContainingDefinition().getNodeItem()) .getModelItemsByName(bindingInstance.getXmlQName()) .get(position))); } + @NonNull + protected AssemblyModel.ChoiceGroup getBinding() { + return binding; + } + @Override public IContainerModelSupport< - IBindingInstanceModelNamedGrouped, - IBindingInstanceModelNamedGrouped, - IBindingInstanceModelFieldGrouped, - IBindingInstanceModelAssemblyGrouped> getModelContainer() { + INamedModelInstanceGrouped, + INamedModelInstanceGrouped, + IFieldInstanceGrouped, + IAssemblyInstanceGrouped> getModelContainer() { return ObjectUtils.notNull(modelContainer.get()); } @@ -101,39 +104,40 @@ public IGroupAs getGroupAs() { return groupAs; } - @SuppressWarnings("null") @Override - public INodeItem getBoundNodeItem() { + public IAssemblyNodeItem getNodeItem() { return boundNodeItem.get(); } + // --------------------------------------- + // - Start binding driven code - CPD-OFF - + // --------------------------------------- + @Override public int getMinOccurs() { BigInteger min = getBinding().getMinOccurs(); - return min == null ? IGroupable.DEFAULT_GROUP_AS_MIN_OCCURS : min.intValueExact(); + return min == null ? DEFAULT_GROUP_AS_MIN_OCCURS : min.intValueExact(); } @Override public int getMaxOccurs() { String max = getBinding().getMaxOccurs(); - return max == null - ? IGroupable.DEFAULT_GROUP_AS_MIN_OCCURS - : ModelSupport.maxOccurs(max); + return max == null ? DEFAULT_GROUP_AS_MAX_OCCURS : ModelSupport.maxOccurs(max); } @Override - public IBindingDefinitionAssembly getOwningDefinition() { - return getContainingDefinition(); + public IAssemblyDefinition getOwningDefinition() { + return getParentContainer(); } @Override public String getJsonDiscriminatorProperty() { String discriminator = getBinding().getDiscriminator(); - return discriminator == null ? IChoiceGroupInstance.DEFAULT_JSON_DISCRIMINATOR_PROPERTY_NAME : discriminator; + return discriminator == null ? DEFAULT_JSON_DISCRIMINATOR_PROPERTY_NAME : discriminator; } @Override - public String getJsonKeyFlagName() { + public String getJsonKeyFlagInstanceName() { JsonKey jsonKey = getBinding().getJsonKey(); return jsonKey == null ? null : jsonKey.getFlagRef(); } 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 3de41f937..6275dc1fd 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 @@ -29,25 +29,29 @@ 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.metapath.item.node.IAssemblyNodeItem; +import gov.nist.secauto.metaschema.core.model.AbstractInlineFieldDefinition; +import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition; +import gov.nist.secauto.metaschema.core.model.IAttributable; import gov.nist.secauto.metaschema.core.model.IContainerFlagSupport; -import gov.nist.secauto.metaschema.core.model.IFeatureDefinitionInstanceInlined; +import gov.nist.secauto.metaschema.core.model.IContainerModelAbsolute; +import gov.nist.secauto.metaschema.core.model.IFieldDefinition; +import gov.nist.secauto.metaschema.core.model.IFieldInstanceAbsolute; import gov.nist.secauto.metaschema.core.model.IFlagInstance; -import gov.nist.secauto.metaschema.core.model.IGroupable; 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.IBoundInstanceModelGroupedAssembly; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingContainerModelAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingDefinitionModelField; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceFlag; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelFieldAbsolute; +import gov.nist.secauto.metaschema.databind.model.IGroupAs; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.FieldConstraints; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.InlineDefineField; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.JsonKey; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.JsonValueKeyFlag; import java.math.BigInteger; +import java.util.Map; +import java.util.Set; import javax.xml.namespace.QName; @@ -56,17 +60,27 @@ import nl.talsmasoftware.lazy4j.Lazy; public class InstanceModelFieldInline - extends AbstractInstanceModelNamedInline - implements IBindingInstanceModelFieldAbsolute, IBindingDefinitionModelField, - IFeatureDefinitionInstanceInlined, - IFeatureBindingContainerFlag { + extends AbstractInlineFieldDefinition< + IContainerModelAbsolute, + IFieldDefinition, + IFieldInstanceAbsolute, + IAssemblyDefinition, + IFlagInstance> + implements IFieldInstanceAbsolute, IFeatureInstanceModelGroupAs { + @NonNull + private final InlineDefineField binding; + @NonNull + private final Map> properties; + @NonNull + private final IGroupAs groupAs; + @NonNull + private final Lazy boundNodeItem; @NonNull private final IDataTypeAdapter javaTypeAdapter; @Nullable private final Object defaultValue; @NonNull - private final Lazy> flagContainer; + private final Lazy> flagContainer; @NonNull private final Lazy valueConstraints; @@ -74,22 +88,28 @@ public InstanceModelFieldInline( @NonNull InlineDefineField binding, @NonNull IBoundInstanceModelGroupedAssembly bindingInstance, int position, - @NonNull IBindingContainerModelAbsolute parent) { - super(binding, - bindingInstance, - position, - parent, - ObjectUtils.requireNonNull(binding.getProps()), - binding.getGroupAs()); - this.javaTypeAdapter = ModelSupport.dataType(getBinding().getAsType()); - this.defaultValue = ModelSupport.defaultValue(getBinding().getDefault(), this.javaTypeAdapter); - this.flagContainer = ObjectUtils.notNull(Lazy.lazy(() -> FlagContainerSupport.of( - binding.getFlags(), - bindingInstance, - this))); + @NonNull IContainerModelAbsolute parent) { + super(parent); + this.binding = binding; + this.properties = ModelSupport.parseProperties(ObjectUtils.requireNonNull(binding.getProps())); + this.groupAs = ModelSupport.groupAs(binding.getGroupAs(), parent.getOwningDefinition().getContainingModule()); + this.boundNodeItem = ObjectUtils.notNull( + Lazy.lazy(() -> (IAssemblyNodeItem) ObjectUtils.notNull(getContainingDefinition().getNodeItem()) + .getModelItemsByName(bindingInstance.getXmlQName()) + .get(position))); + this.javaTypeAdapter = ModelSupport.dataType(binding.getAsType()); + this.defaultValue = ModelSupport.defaultValue(binding.getDefault(), this.javaTypeAdapter); + this.flagContainer = ObjectUtils.notNull(Lazy.lazy(() -> { + JsonKey jsonKey = binding.getJsonKey(); + return FlagContainerSupport.newFlagContainer( + binding.getFlags(), + bindingInstance, + this, + jsonKey == null ? null : jsonKey.getFlagRef()); + })); this.valueConstraints = ObjectUtils.notNull(Lazy.lazy(() -> { IValueConstrained retval = new ValueConstraintSet(); - FieldConstraints constraints = getBinding().getConstraint(); + FieldConstraints constraints = binding.getConstraint(); if (constraints != null) { ConstraintBindingSupport.parse( retval, @@ -100,13 +120,23 @@ public InstanceModelFieldInline( })); } + @NonNull + protected InlineDefineField getBinding() { + return binding; + } + @Override - public boolean isInXmlWrapped() { - return ModelSupport.fieldInXml(getBinding().getInXml()); + public Map> getProperties() { + return properties; } @Override - public IContainerFlagSupport getFlagContainer() { + public IGroupAs getGroupAs() { + return groupAs; + } + + @Override + public IContainerFlagSupport getFlagContainer() { return ObjectUtils.notNull(flagContainer.get()); } @@ -121,18 +151,22 @@ public IDataTypeAdapter getJavaTypeAdapter() { } @Override - public InstanceModelFieldInline getDefinition() { - return this; + public Object getDefaultValue() { + return defaultValue; } @Override - public IBindingInstanceModelFieldAbsolute getInlineInstance() { - return this; + public IAssemblyNodeItem getNodeItem() { + return boundNodeItem.get(); } + // --------------------------------------- + // - Start binding driven code - CPD-OFF - + // --------------------------------------- + @Override - public Object getDefaultValue() { - return defaultValue; + public boolean isInXmlWrapped() { + return ModelSupport.fieldInXml(getBinding().getInXml()); } @Override @@ -160,24 +194,16 @@ public MarkupMultiline getRemarks() { return ModelSupport.remarks(getBinding().getRemarks()); } - @Override - public String getJsonKeyFlagName() { - JsonKey jsonKey = getBinding().getJsonKey(); - return jsonKey == null ? null : jsonKey.getFlagRef(); - } - @Override public int getMinOccurs() { BigInteger min = getBinding().getMinOccurs(); - return min == null ? IGroupable.DEFAULT_GROUP_AS_MIN_OCCURS : min.intValueExact(); + return min == null ? DEFAULT_GROUP_AS_MIN_OCCURS : min.intValueExact(); } @Override public int getMaxOccurs() { String max = getBinding().getMaxOccurs(); - return max == null - ? IGroupable.DEFAULT_GROUP_AS_MIN_OCCURS - : ModelSupport.maxOccurs(max); + return max == null ? DEFAULT_GROUP_AS_MAX_OCCURS : ModelSupport.maxOccurs(max); } @Override diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceModelFieldReference.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceModelFieldReference.java index c16c9c76e..88d6ac709 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceModelFieldReference.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceModelFieldReference.java @@ -28,27 +28,43 @@ 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.IGroupable; +import gov.nist.secauto.metaschema.core.metapath.item.node.IAssemblyNodeItem; +import gov.nist.secauto.metaschema.core.model.AbstractFieldInstance; +import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition; +import gov.nist.secauto.metaschema.core.model.IAttributable; +import gov.nist.secauto.metaschema.core.model.IContainerModelAbsolute; +import gov.nist.secauto.metaschema.core.model.IFieldDefinition; +import gov.nist.secauto.metaschema.core.model.IFieldInstanceAbsolute; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelGroupedAssembly; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingContainerModelAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingDefinitionModelField; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelFieldAbsolute; +import gov.nist.secauto.metaschema.databind.model.IGroupAs; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.FieldReference; import java.math.BigInteger; +import java.util.Map; +import java.util.Set; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; +import nl.talsmasoftware.lazy4j.Lazy; public class InstanceModelFieldReference - extends AbstractInstanceModelNamedReference< - FieldReference, - IBindingDefinitionModelField, - IBindingContainerModelAbsolute> - implements IBindingInstanceModelFieldAbsolute, - IFeatureDefinitionReferenceInstance { + extends AbstractFieldInstance< + IContainerModelAbsolute, + IFieldDefinition, + IFieldInstanceAbsolute, + IAssemblyDefinition> + implements IFieldInstanceAbsolute, IFeatureInstanceModelGroupAs { + @NonNull + private final FieldReference binding; + @NonNull + private final IFieldDefinition definition; + @NonNull + private final Map> properties; + @NonNull + private final IGroupAs groupAs; + @NonNull + private final Lazy boundNodeItem; @Nullable private final Object defaultValue; @@ -56,19 +72,49 @@ public InstanceModelFieldReference( @NonNull FieldReference binding, @NonNull IBoundInstanceModelGroupedAssembly bindingInstance, int position, - @NonNull IBindingDefinitionModelField definition, - @NonNull IBindingContainerModelAbsolute parent) { - super( - binding, - bindingInstance, - position, - definition, - parent, - ObjectUtils.requireNonNull(binding.getProps()), - binding.getGroupAs()); - this.defaultValue = ModelSupport.defaultValue(getBinding().getDefault(), definition.getJavaTypeAdapter()); + @NonNull IFieldDefinition definition, + @NonNull IContainerModelAbsolute parent) { + super(parent); + this.binding = binding; + this.definition = definition; + this.properties = ModelSupport.parseProperties(ObjectUtils.requireNonNull(binding.getProps())); + this.groupAs = ModelSupport.groupAs(binding.getGroupAs(), parent.getOwningDefinition().getContainingModule()); + this.boundNodeItem = ObjectUtils.notNull( + Lazy.lazy(() -> (IAssemblyNodeItem) ObjectUtils.notNull(getContainingDefinition().getNodeItem()) + .getModelItemsByName(bindingInstance.getXmlQName()) + .get(position))); + this.defaultValue = ModelSupport.defaultValue(binding.getDefault(), definition.getJavaTypeAdapter()); } + @Override + public IFieldDefinition getDefinition() { + return definition; + } + + @NonNull + protected FieldReference getBinding() { + return binding; + } + + @Override + public Map> getProperties() { + return properties; + } + + @Override + public IGroupAs getGroupAs() { + return groupAs; + } + + @Override + public IAssemblyNodeItem getNodeItem() { + return boundNodeItem.get(); + } + + // --------------------------------------- + // - Start binding driven code - CPD-OFF - + // --------------------------------------- + @Override public boolean isInXmlWrapped() { return ModelSupport.fieldInXml(getBinding().getInXml()); @@ -117,14 +163,12 @@ public MarkupMultiline getRemarks() { @Override public int getMinOccurs() { BigInteger min = getBinding().getMinOccurs(); - return min == null ? IGroupable.DEFAULT_GROUP_AS_MIN_OCCURS : min.intValueExact(); + return min == null ? DEFAULT_GROUP_AS_MIN_OCCURS : min.intValueExact(); } @Override public int getMaxOccurs() { String max = getBinding().getMaxOccurs(); - return max == null - ? IGroupable.DEFAULT_GROUP_AS_MIN_OCCURS - : ModelSupport.maxOccurs(max); + return max == null ? DEFAULT_GROUP_AS_MAX_OCCURS : ModelSupport.maxOccurs(max); } } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceModelGroupedAssemblyInline.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceModelGroupedAssemblyInline.java index 034d116cd..67404960c 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceModelGroupedAssemblyInline.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceModelGroupedAssemblyInline.java @@ -29,49 +29,62 @@ import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine; import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline; import gov.nist.secauto.metaschema.core.metapath.item.node.IAssemblyNodeItem; -import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem; import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItemFactory; +import gov.nist.secauto.metaschema.core.model.AbstractInlineAssemblyDefinition; import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition; +import gov.nist.secauto.metaschema.core.model.IAssemblyInstanceAbsolute; import gov.nist.secauto.metaschema.core.model.IAssemblyInstanceGrouped; +import gov.nist.secauto.metaschema.core.model.IAttributable; +import gov.nist.secauto.metaschema.core.model.IChoiceGroupInstance; +import gov.nist.secauto.metaschema.core.model.IChoiceInstance; import gov.nist.secauto.metaschema.core.model.IContainerFlagSupport; import gov.nist.secauto.metaschema.core.model.IContainerModelAssemblySupport; -import gov.nist.secauto.metaschema.core.model.IFeatureDefinitionInstanceInlined; +import gov.nist.secauto.metaschema.core.model.IFieldInstanceAbsolute; +import gov.nist.secauto.metaschema.core.model.IFlagInstance; +import gov.nist.secauto.metaschema.core.model.IModelInstanceAbsolute; +import gov.nist.secauto.metaschema.core.model.INamedModelInstanceAbsolute; import gov.nist.secauto.metaschema.core.model.constraint.AssemblyConstraintSet; import gov.nist.secauto.metaschema.core.model.constraint.IModelConstrained; import gov.nist.secauto.metaschema.core.model.constraint.ISource; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelGroupedAssembly; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingDefinitionAssembly; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceFlag; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelAssemblyAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelAssemblyGrouped; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelFieldAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelNamedAbsolute; -import gov.nist.secauto.metaschema.databind.model.metaschema.IInstanceModelChoiceBinding; -import gov.nist.secauto.metaschema.databind.model.metaschema.IInstanceModelChoiceGroupBinding; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.AssemblyConstraints; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.AssemblyModel; +import java.util.Map; +import java.util.Set; + import edu.umd.cs.findbugs.annotations.NonNull; import nl.talsmasoftware.lazy4j.Lazy; public class InstanceModelGroupedAssemblyInline - extends AbstractInstanceModelGrouped - implements IBindingInstanceModelAssemblyGrouped, IBindingDefinitionAssembly, - IFeatureDefinitionInstanceInlined, - IFeatureBindingContainerModelAssembly, - IFeatureBindingContainerFlag { + extends AbstractInlineAssemblyDefinition< + IChoiceGroupInstance, + IAssemblyDefinition, + IAssemblyInstanceGrouped, + IAssemblyDefinition, + IFlagInstance, + IModelInstanceAbsolute, + INamedModelInstanceAbsolute, + IFieldInstanceAbsolute, + IAssemblyInstanceAbsolute, + IChoiceInstance, + IChoiceGroupInstance> + implements IAssemblyInstanceGrouped, IFeatureBindingContainerModelAssembly { + @NonNull + private final AssemblyModel.ChoiceGroup.DefineAssembly binding; @NonNull - private final Lazy> flagContainer; + private final Map> properties; + @NonNull + private final Lazy> flagContainer; @NonNull private final Lazy> modelContainer; + IModelInstanceAbsolute, + INamedModelInstanceAbsolute, + IFieldInstanceAbsolute, + IAssemblyInstanceAbsolute, + IChoiceInstance, + IChoiceGroupInstance>> modelContainer; @NonNull private final Lazy modelConstraints; @NonNull @@ -81,22 +94,25 @@ public InstanceModelGroupedAssemblyInline( @NonNull AssemblyModel.ChoiceGroup.DefineAssembly binding, @NonNull IBoundInstanceModelGroupedAssembly bindingInstance, int position, - @NonNull IInstanceModelChoiceGroupBinding parent, + @NonNull IChoiceGroupInstance parent, @NonNull INodeItemFactory nodeItemFactory) { - super(binding, bindingInstance, position, parent, ObjectUtils.requireNonNull(binding.getProps())); - this.flagContainer = ObjectUtils.notNull(Lazy.lazy(() -> FlagContainerSupport.of( + super(parent); + this.binding = binding; + this.properties = ModelSupport.parseProperties(ObjectUtils.requireNonNull(binding.getProps())); + this.flagContainer = ObjectUtils.notNull(Lazy.lazy(() -> FlagContainerSupport.newFlagContainer( binding.getFlags(), bindingInstance, - this))); + this, + getParentContainer().getJsonKeyFlagInstanceName()))); this.modelContainer = ObjectUtils.notNull(Lazy.lazy(() -> AssemblyModelContainerSupport.of( binding.getModel(), ObjectUtils - .requireNonNull(bindingInstance.getDefinition().getAssemblyInstanceByName(IAssemblyDefinition.MODEL_QNAME)), + .requireNonNull(bindingInstance.getDefinition().getAssemblyInstanceByName(MODEL_QNAME)), this, nodeItemFactory))); this.modelConstraints = ObjectUtils.notNull(Lazy.lazy(() -> { IModelConstrained retval = new AssemblyConstraintSet(); - AssemblyConstraints constraints = getBinding().getConstraint(); + AssemblyConstraints constraints = binding.getConstraint(); if (constraints != null) { ConstraintBindingSupport.parse( retval, @@ -106,24 +122,34 @@ public InstanceModelGroupedAssemblyInline( return retval; })); this.boundNodeItem = ObjectUtils.notNull( - Lazy.lazy(() -> (IAssemblyNodeItem) getContainingDefinition().getBoundNodeItem() + Lazy.lazy(() -> (IAssemblyNodeItem) ObjectUtils.notNull(getContainingDefinition().getNodeItem()) .getModelItemsByName(bindingInstance.getXmlQName()) .get(position))); } + @NonNull + protected AssemblyModel.ChoiceGroup.DefineAssembly getBinding() { + return binding; + } + @Override - public IContainerFlagSupport getFlagContainer() { + public Map> getProperties() { + return properties; + } + + @Override + public IContainerFlagSupport getFlagContainer() { return ObjectUtils.notNull(flagContainer.get()); } @Override public IContainerModelAssemblySupport< - IBindingInstanceModelAbsolute, - IBindingInstanceModelNamedAbsolute, - IBindingInstanceModelFieldAbsolute, - IBindingInstanceModelAssemblyAbsolute, - IInstanceModelChoiceBinding, - IInstanceModelChoiceGroupBinding> getModelContainer() { + IModelInstanceAbsolute, + INamedModelInstanceAbsolute, + IFieldInstanceAbsolute, + IAssemblyInstanceAbsolute, + IChoiceInstance, + IChoiceGroupInstance> getModelContainer() { return ObjectUtils.notNull(modelContainer.get()); } @@ -132,21 +158,14 @@ public IModelConstrained getConstraintSupport() { return ObjectUtils.notNull(modelConstraints.get()); } - @SuppressWarnings("null") @Override - public INodeItem getBoundNodeItem() { + public IAssemblyNodeItem getNodeItem() { return boundNodeItem.get(); } - @Override - public IBindingDefinitionAssembly getDefinition() { - return this; - } - - @Override - public IAssemblyInstanceGrouped getInlineInstance() { - return this; - } + // --------------------------------------- + // - Start binding driven code - CPD-OFF - + // --------------------------------------- @Override public String getName() { diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceModelGroupedAssemblyReference.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceModelGroupedAssemblyReference.java index 44f70a156..f86357e7b 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceModelGroupedAssemblyReference.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceModelGroupedAssemblyReference.java @@ -28,43 +28,83 @@ 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.metapath.item.node.IAssemblyNodeItem; +import gov.nist.secauto.metaschema.core.model.AbstractAssemblyInstance; +import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition; +import gov.nist.secauto.metaschema.core.model.IAssemblyInstanceGrouped; +import gov.nist.secauto.metaschema.core.model.IAttributable; +import gov.nist.secauto.metaschema.core.model.IChoiceGroupInstance; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelGroupedAssembly; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingDefinitionAssembly; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelAssemblyGrouped; -import gov.nist.secauto.metaschema.databind.model.metaschema.IInstanceModelChoiceGroupBinding; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.AssemblyModel; +import java.util.Map; +import java.util.Set; + import edu.umd.cs.findbugs.annotations.NonNull; +import nl.talsmasoftware.lazy4j.Lazy; public class InstanceModelGroupedAssemblyReference - extends AbstractInstanceModelGrouped - implements IBindingInstanceModelAssemblyGrouped, - IFeatureDefinitionReferenceInstance { + extends AbstractAssemblyInstance< + IChoiceGroupInstance, + IAssemblyDefinition, + IAssemblyInstanceGrouped, + IAssemblyDefinition> + implements IAssemblyInstanceGrouped { + @NonNull + private final AssemblyModel.ChoiceGroup.Assembly binding; + @NonNull + private final IAssemblyDefinition definition; + @NonNull + private final Map> properties; @NonNull - private final IBindingDefinitionAssembly definition; + private final Lazy boundNodeItem; public InstanceModelGroupedAssemblyReference( @NonNull AssemblyModel.ChoiceGroup.Assembly binding, @NonNull IBoundInstanceModelGroupedAssembly bindingInstance, int position, - @NonNull IBindingDefinitionAssembly definition, - @NonNull IInstanceModelChoiceGroupBinding parent) { - super(binding, bindingInstance, position, parent, ObjectUtils.requireNonNull(binding.getProps())); + @NonNull IAssemblyDefinition definition, + @NonNull IChoiceGroupInstance parent) { + super(parent); + this.binding = binding; this.definition = definition; + this.properties = ModelSupport.parseProperties(ObjectUtils.requireNonNull(binding.getProps())); + this.boundNodeItem = ObjectUtils.notNull( + Lazy.lazy(() -> (IAssemblyNodeItem) ObjectUtils.notNull(getContainingDefinition().getNodeItem()) + .getModelItemsByName(bindingInstance.getXmlQName()) + .get(position))); } @Override - public IBindingDefinitionAssembly getDefinition() { + public IAssemblyDefinition getDefinition() { return definition; } + @NonNull + protected AssemblyModel.ChoiceGroup.Assembly getBinding() { + return binding; + } + + @Override + public Map> getProperties() { + return properties; + } + + @Override + public IAssemblyNodeItem getNodeItem() { + return boundNodeItem.get(); + } + @Override public String getName() { return getDefinition().getName(); } + // --------------------------------------- + // - Start binding driven code - CPD-OFF - + // --------------------------------------- + @Override public String getUseName() { return ModelSupport.useName(getBinding().getUseName()); 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 237dce80b..54e7220b7 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 @@ -26,15 +26,16 @@ package gov.nist.secauto.metaschema.databind.model.metaschema.impl; -import javax.xml.namespace.QName; - -import edu.umd.cs.findbugs.annotations.NonNull; -import edu.umd.cs.findbugs.annotations.Nullable; 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.metapath.item.node.IFieldNodeItem; +import gov.nist.secauto.metaschema.core.model.AbstractInlineFieldDefinition; +import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition; +import gov.nist.secauto.metaschema.core.model.IAttributable; +import gov.nist.secauto.metaschema.core.model.IChoiceGroupInstance; import gov.nist.secauto.metaschema.core.model.IContainerFlagSupport; -import gov.nist.secauto.metaschema.core.model.IFeatureDefinitionInstanceInlined; +import gov.nist.secauto.metaschema.core.model.IFieldDefinition; import gov.nist.secauto.metaschema.core.model.IFieldInstanceGrouped; import gov.nist.secauto.metaschema.core.model.IFlagInstance; import gov.nist.secauto.metaschema.core.model.constraint.ISource; @@ -42,44 +43,60 @@ import gov.nist.secauto.metaschema.core.model.constraint.ValueConstraintSet; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelGroupedAssembly; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingDefinitionModelField; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceFlag; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelFieldGrouped; -import gov.nist.secauto.metaschema.databind.model.metaschema.IInstanceModelChoiceGroupBinding; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.AssemblyModel; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.FieldConstraints; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.JsonValueKeyFlag; + +import java.util.Map; +import java.util.Set; + +import javax.xml.namespace.QName; + +import edu.umd.cs.findbugs.annotations.NonNull; +import edu.umd.cs.findbugs.annotations.Nullable; import nl.talsmasoftware.lazy4j.Lazy; public class InstanceModelGroupedFieldInline - extends AbstractInstanceModelGrouped - implements IBindingInstanceModelFieldGrouped, IBindingDefinitionModelField, - IFeatureDefinitionInstanceInlined, - IFeatureBindingContainerFlag { + extends AbstractInlineFieldDefinition< + IChoiceGroupInstance, + IFieldDefinition, + IFieldInstanceGrouped, + IAssemblyDefinition, + IFlagInstance> + implements IFieldInstanceGrouped { + @NonNull + private final AssemblyModel.ChoiceGroup.DefineField binding; + @NonNull + private final Map> properties; @NonNull private final IDataTypeAdapter javaTypeAdapter; @Nullable private final Object defaultValue; @NonNull - private final Lazy> flagContainer; + private final Lazy> flagContainer; @NonNull private final Lazy valueConstraints; + @NonNull + private final Lazy boundNodeItem; public InstanceModelGroupedFieldInline( @NonNull AssemblyModel.ChoiceGroup.DefineField binding, @NonNull IBoundInstanceModelGroupedAssembly bindingInstance, int position, - @NonNull IInstanceModelChoiceGroupBinding parent) { - super(binding, bindingInstance, position, parent, ObjectUtils.requireNonNull(binding.getProps())); - this.javaTypeAdapter = ModelSupport.dataType(getBinding().getAsType()); - this.defaultValue = ModelSupport.defaultValue(getBinding().getDefault(), this.javaTypeAdapter); - this.flagContainer = ObjectUtils.notNull(Lazy.lazy(() -> FlagContainerSupport.of( + @NonNull IChoiceGroupInstance parent) { + super(parent); + this.binding = binding; + this.properties = ModelSupport.parseProperties(ObjectUtils.requireNonNull(binding.getProps())); + this.javaTypeAdapter = ModelSupport.dataType(binding.getAsType()); + this.defaultValue = ModelSupport.defaultValue(binding.getDefault(), this.javaTypeAdapter); + this.flagContainer = ObjectUtils.notNull(Lazy.lazy(() -> FlagContainerSupport.newFlagContainer( binding.getFlags(), bindingInstance, - this))); + this, + getParentContainer().getJsonKeyFlagInstanceName()))); this.valueConstraints = ObjectUtils.notNull(Lazy.lazy(() -> { IValueConstrained retval = new ValueConstraintSet(); - FieldConstraints constraints = getBinding().getConstraint(); + FieldConstraints constraints = binding.getConstraint(); if (constraints != null) { ConstraintBindingSupport.parse( retval, @@ -88,31 +105,40 @@ public InstanceModelGroupedFieldInline( } return retval; })); + this.boundNodeItem = ObjectUtils.notNull( + Lazy.lazy(() -> (IFieldNodeItem) ObjectUtils.notNull(getContainingDefinition().getNodeItem()) + .getModelItemsByName(bindingInstance.getXmlQName()) + .get(position))); + } + + @NonNull + protected AssemblyModel.ChoiceGroup.DefineField getBinding() { + return binding; } @Override - public IContainerFlagSupport getFlagContainer() { - return ObjectUtils.notNull(flagContainer.get()); + public Map> getProperties() { + return properties; } @Override - public IValueConstrained getConstraintSupport() { - return ObjectUtils.notNull(valueConstraints.get()); + public IContainerFlagSupport getFlagContainer() { + return ObjectUtils.notNull(flagContainer.get()); } @Override - public IDataTypeAdapter getJavaTypeAdapter() { - return javaTypeAdapter; + public IValueConstrained getConstraintSupport() { + return ObjectUtils.notNull(valueConstraints.get()); } @Override - public IBindingDefinitionModelField getDefinition() { - return this; + public IFieldNodeItem getNodeItem() { + return boundNodeItem.get(); } @Override - public IFieldInstanceGrouped getInlineInstance() { - return this; + public IDataTypeAdapter getJavaTypeAdapter() { + return javaTypeAdapter; } @Override @@ -120,6 +146,10 @@ public Object getDefaultValue() { return defaultValue; } + // --------------------------------------- + // - Start binding driven code - CPD-OFF - + // --------------------------------------- + @Override public String getName() { return ObjectUtils.notNull(getBinding().getName()); diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceModelGroupedFieldReference.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceModelGroupedFieldReference.java index 5ab347f65..20b4560cb 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceModelGroupedFieldReference.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/InstanceModelGroupedFieldReference.java @@ -28,43 +28,84 @@ 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.metapath.item.node.IAssemblyNodeItem; +import gov.nist.secauto.metaschema.core.model.AbstractFieldInstance; +import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition; +import gov.nist.secauto.metaschema.core.model.IAttributable; +import gov.nist.secauto.metaschema.core.model.IChoiceGroupInstance; +import gov.nist.secauto.metaschema.core.model.IFieldDefinition; +import gov.nist.secauto.metaschema.core.model.IFieldInstanceGrouped; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelGroupedAssembly; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingDefinitionModelField; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstanceModelFieldGrouped; -import gov.nist.secauto.metaschema.databind.model.metaschema.IInstanceModelChoiceGroupBinding; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.AssemblyModel; +import java.util.Map; +import java.util.Set; + import edu.umd.cs.findbugs.annotations.NonNull; +import nl.talsmasoftware.lazy4j.Lazy; public class InstanceModelGroupedFieldReference - extends AbstractInstanceModelGrouped - implements IBindingInstanceModelFieldGrouped, - IFeatureDefinitionReferenceInstance { + extends AbstractFieldInstance< + IChoiceGroupInstance, + IFieldDefinition, + IFieldInstanceGrouped, + IAssemblyDefinition> + implements IFieldInstanceGrouped { + @NonNull + private final AssemblyModel.ChoiceGroup.Field binding; + @NonNull + private final IFieldDefinition definition; + @NonNull + private final Map> properties; @NonNull - private final IBindingDefinitionModelField definition; + private final Lazy boundNodeItem; protected InstanceModelGroupedFieldReference( @NonNull AssemblyModel.ChoiceGroup.Field binding, @NonNull IBoundInstanceModelGroupedAssembly bindingInstance, int position, - @NonNull IBindingDefinitionModelField definition, - @NonNull IInstanceModelChoiceGroupBinding parent) { - super(binding, bindingInstance, position, parent, ObjectUtils.requireNonNull(binding.getProps())); + @NonNull IFieldDefinition definition, + @NonNull IChoiceGroupInstance parent) { + super(parent); + this.binding = binding; this.definition = definition; + this.properties = ModelSupport.parseProperties(ObjectUtils.requireNonNull(binding.getProps())); + this.boundNodeItem = ObjectUtils.notNull( + Lazy.lazy(() -> (IAssemblyNodeItem) ObjectUtils.notNull(getContainingDefinition().getNodeItem()) + .getModelItemsByName(bindingInstance.getXmlQName()) + .get(position))); } @Override - public IBindingDefinitionModelField getDefinition() { + public IFieldDefinition getDefinition() { return definition; } + @NonNull + protected AssemblyModel.ChoiceGroup.Field getBinding() { + return binding; + } + + @Override + public Map> getProperties() { + return properties; + } + + @Override + public IAssemblyNodeItem getNodeItem() { + return boundNodeItem.get(); + } + @Override public String getName() { return getDefinition().getName(); } + // --------------------------------------- + // - Start binding driven code - CPD-OFF - + // --------------------------------------- + @Override public String getUseName() { return ModelSupport.useName(getBinding().getUseName()); diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/ModelSupport.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/ModelSupport.java index caee807b3..e3e277784 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/ModelSupport.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/ModelSupport.java @@ -30,9 +30,12 @@ import gov.nist.secauto.metaschema.core.datatype.IDataTypeAdapter; import gov.nist.secauto.metaschema.core.datatype.adapter.MetaschemaDataTypeProvider; import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline; +import gov.nist.secauto.metaschema.core.metapath.item.node.IAssemblyNodeItem; +import gov.nist.secauto.metaschema.core.metapath.item.node.IDocumentNodeItem; import gov.nist.secauto.metaschema.core.model.IAttributable; import gov.nist.secauto.metaschema.core.model.IFieldInstance; import gov.nist.secauto.metaschema.core.model.IGroupable; +import gov.nist.secauto.metaschema.core.model.IModule; import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior; import gov.nist.secauto.metaschema.core.model.ModuleScopeEnum; import gov.nist.secauto.metaschema.core.model.XmlGroupAsBehavior; @@ -54,6 +57,8 @@ import java.util.Set; import java.util.stream.Collectors; +import javax.xml.namespace.QName; + import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; @@ -67,14 +72,14 @@ public static Map> parseProperties(@NonNull List< return CollectionUtil.unmodifiableMap(ObjectUtils.notNull(props.stream() .collect( Collectors.groupingBy( - (prop) -> { + prop -> { String name = ObjectUtils.requireNonNull(prop.getName()); URI namespace = prop.getNamespace(); return namespace == null ? IAttributable.key(name) : IAttributable.key(name, ObjectUtils.notNull(namespace.toASCIIString())); }, Collectors.mapping( - (prop) -> ObjectUtils.requireNonNull(prop.getValue()), + prop -> ObjectUtils.requireNonNull(prop.getValue()), Collectors.toCollection(LinkedHashSet::new)))))); } @@ -183,10 +188,10 @@ public static boolean fieldInXml(@Nullable String inXml) { @NonNull public static IGroupAs groupAs( @Nullable GroupAs groupAs, - @Nullable String groupAsNamespace) { + @NonNull IModule module) { return groupAs == null ? IGroupAs.SINGLETON_GROUP_AS - : new GroupAsImpl(groupAs, groupAsNamespace); + : new GroupAsImpl(groupAs, module); } @NonNull @@ -229,4 +234,14 @@ public static XmlGroupAsBehavior groupAsXmlBehavior(@Nullable String inXml) { } return retval; } + + @SuppressWarnings("unchecked") + @Nullable + public static NODE toNodeItem( + @NonNull IModule module, + @NonNull QName qname, + int position) { + IDocumentNodeItem moduleNodeItem = module.getNodeItem(); + return moduleNodeItem == null ? null : (NODE) moduleNodeItem.getModelItemsByName(qname).get(position); + } } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingDefinitionFlag.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/package-info.java similarity index 87% rename from databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingDefinitionFlag.java rename to databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/package-info.java index ee6f5e956..bcb6f2a2a 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/IBindingDefinitionFlag.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/package-info.java @@ -24,10 +24,11 @@ * OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER. */ -package gov.nist.secauto.metaschema.databind.model.metaschema; - -import gov.nist.secauto.metaschema.core.model.IFlagDefinition; +/** + * Provides an implementation of the Module model + * ({@link gov.nist.secauto.metaschema.core.model}) represented by a + * module-specific set of bound Java classes + * ({@link gov.nist.secauto.metaschema.databind.model.metaschema.binding}). + */ -public interface IBindingDefinitionFlag extends IFlagDefinition, IBindingDefinition { - // no additional methods -} +package gov.nist.secauto.metaschema.databind.model.metaschema; diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/package-info.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/package-info.java index 4cabc3660..b92bac6ff 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/package-info.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/package-info.java @@ -26,9 +26,9 @@ /** * Provides an overlay of the Metaschema module model - * ({@link gov.nist.secauto.metaschema.core.model}) representing module - * constructs as bound Java class annotations - * ({@link gov.nist.secauto.metaschema.databind.model.annotations}). + * ({@link gov.nist.secauto.metaschema.core.model}) using bound Java class + * annotations ({@link gov.nist.secauto.metaschema.databind.model.annotations}) + * to represent module constructs annotated on Java classes. */ package gov.nist.secauto.metaschema.databind.model; diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/package-info.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/package-info.java index 64de47654..ee1782849 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/package-info.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/package-info.java @@ -24,7 +24,23 @@ * OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER. */ /** - * The core implementation of the metaschema binding framework. + * Support for parsing Metaschema module-based data using Java class bindings. + *

+ * Two methods are supported + *

    + *
  1. A Java annotation based approach + * ({@link gov.nist.secauto.metaschema.databind.model}) using annotations + * ({@link gov.nist.secauto.metaschema.databind.model.annotations}). The + * {@link gov.nist.secauto.metaschema.databind.DefaultBindingContext} is used to + * load a bound Java class.
  2. + *
  3. A metaschema-specific binding, based on the first method, that is capable + * of representing a Metaschema module + * ({@link gov.nist.secauto.metaschema.databind.model.metaschema.binding}). The + * {@link gov.nist.secauto.metaschema.databind.model.metaschema.BindingConstraintLoader} + * can be used to load any Metaschema module using this method. Once loaded, the + * module can be registered with the binding context using + * {@link gov.nist.secauto.metaschema.databind.IBindingContext#registerModule(gov.nist.secauto.metaschema.core.model.IModule, java.nio.file.Path)}. + *
*/ package gov.nist.secauto.metaschema.databind; diff --git a/databind/src/test/java/gov/nist/secauto/metaschema/databind/DefaultBindingContextTest.java b/databind/src/test/java/gov/nist/secauto/metaschema/databind/DefaultBindingContextTest.java index 431600079..66d952708 100644 --- a/databind/src/test/java/gov/nist/secauto/metaschema/databind/DefaultBindingContextTest.java +++ b/databind/src/test/java/gov/nist/secauto/metaschema/databind/DefaultBindingContextTest.java @@ -48,6 +48,8 @@ import java.nio.file.Paths; import java.util.List; +import javax.xml.namespace.QName; + class DefaultBindingContextTest { @Test @@ -61,7 +63,8 @@ void testConstraints() throws MetaschemaException, IOException { // NOPMD - inte IBindingContext bindingContext = new DefaultBindingContext(CollectionUtil.singletonList(postProcessor)); IBoundModule module = bindingContext.registerModule(TestMetaschema.class); - IAssemblyDefinition root = module.getExportedAssemblyDefinitionByName("root"); + IAssemblyDefinition root + = module.getExportedAssemblyDefinitionByName(new QName("https://csrc.nist.gov/ns/test/xml", "root")); assertNotNull(root, "root not found"); List constraints = root.getConstraints(); @@ -79,7 +82,8 @@ void testConstraintsUsingBinding() throws MetaschemaException, IOException { // IBindingContext bindingContext = new DefaultBindingContext(CollectionUtil.singletonList(postProcessor)); IBoundModule module = bindingContext.registerModule(TestMetaschema.class); - IAssemblyDefinition root = module.getExportedAssemblyDefinitionByName("root"); + IAssemblyDefinition root + = module.getExportedAssemblyDefinitionByName(new QName("https://csrc.nist.gov/ns/test/xml", "root")); assertNotNull(root, "root not found"); List constraints = root.getConstraints(); diff --git a/databind/src/test/java/gov/nist/secauto/metaschema/databind/codegen/AbstractMetaschemaTest.java b/databind/src/test/java/gov/nist/secauto/metaschema/databind/codegen/AbstractMetaschemaTest.java index c83c80fa9..3b77b3e82 100644 --- a/databind/src/test/java/gov/nist/secauto/metaschema/databind/codegen/AbstractMetaschemaTest.java +++ b/databind/src/test/java/gov/nist/secauto/metaschema/databind/codegen/AbstractMetaschemaTest.java @@ -28,6 +28,7 @@ import static org.junit.jupiter.api.Assertions.assertAll; +import gov.nist.secauto.metaschema.core.model.IMetaschemaModule; import gov.nist.secauto.metaschema.core.model.MetaschemaException; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.metaschema.databind.DefaultBindingContext; @@ -37,7 +38,6 @@ import gov.nist.secauto.metaschema.databind.io.Format; import gov.nist.secauto.metaschema.databind.io.IDeserializer; import gov.nist.secauto.metaschema.databind.model.metaschema.BindingModuleLoader; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingModule; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -62,14 +62,14 @@ abstract class AbstractMetaschemaTest { Path generationDir = ObjectUtils.notNull(Paths.get("target/generated-test-sources/metaschema")); @NonNull - private static IBindingModule loadModule(@NonNull Path moduleFile) throws MetaschemaException, IOException { + private static IMetaschemaModule loadModule(@NonNull Path moduleFile) throws MetaschemaException, IOException { return LOADER.load(moduleFile); } public static Class compileModule(@NonNull Path moduleFile, @Nullable Path bindingFile, @NonNull String rootClassName, @NonNull Path classDir) throws IOException, ClassNotFoundException, MetaschemaException { - IBindingModule module = loadModule(moduleFile); + IMetaschemaModule module = loadModule(moduleFile); DefaultBindingConfiguration bindingConfiguration = new DefaultBindingConfiguration(); if (bindingFile != null && Files.exists(bindingFile) && Files.isRegularFile(bindingFile)) { @@ -93,8 +93,7 @@ private static Object read( throws IOException { IDeserializer deserializer = context.newDeserializer(format, rootClass); LOGGER.info("Reading content: {}", file); - Object value = deserializer.deserialize(file); - return value; + return deserializer.deserialize(file); } private static void write( diff --git a/databind/src/test/java/gov/nist/secauto/metaschema/databind/codegen/GenerationTest.java b/databind/src/test/java/gov/nist/secauto/metaschema/databind/codegen/GenerationTest.java index a46737557..13b42fb2b 100644 --- a/databind/src/test/java/gov/nist/secauto/metaschema/databind/codegen/GenerationTest.java +++ b/databind/src/test/java/gov/nist/secauto/metaschema/databind/codegen/GenerationTest.java @@ -29,12 +29,12 @@ import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertNotNull; +import gov.nist.secauto.metaschema.core.model.IMetaschemaModule; import gov.nist.secauto.metaschema.core.model.MetaschemaException; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.metaschema.databind.IBindingContext; import gov.nist.secauto.metaschema.databind.io.DeserializationFeature; import gov.nist.secauto.metaschema.databind.model.metaschema.BindingModuleLoader; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingModule; import org.junit.jupiter.api.Test; @@ -48,7 +48,7 @@ public class GenerationTest { void testOscalBindingModuleLoader() throws MetaschemaException, IOException { BindingModuleLoader loader = new BindingModuleLoader(); loader.set(DeserializationFeature.DESERIALIZE_XML_ALLOW_ENTITY_RESOLUTION, true); - IBindingModule module = loader.load(ObjectUtils.notNull(URI.create( + IMetaschemaModule module = loader.load(ObjectUtils.notNull(URI.create( "https://raw.githubusercontent.com/usnistgov/OSCAL/main/src/metaschema/oscal_complete_metaschema.xml"))); IBindingContext context = IBindingContext.instance().registerModule(module, Paths.get("target/oscal-classes")); assertAll( diff --git a/databind/src/test/java/gov/nist/secauto/metaschema/databind/codegen/MetaschemaModuleMetaschemaTest.java b/databind/src/test/java/gov/nist/secauto/metaschema/databind/codegen/MetaschemaModuleMetaschemaTest.java index ba661572e..14260382a 100644 --- a/databind/src/test/java/gov/nist/secauto/metaschema/databind/codegen/MetaschemaModuleMetaschemaTest.java +++ b/databind/src/test/java/gov/nist/secauto/metaschema/databind/codegen/MetaschemaModuleMetaschemaTest.java @@ -28,8 +28,8 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; +import gov.nist.secauto.metaschema.core.model.IMetaschemaModule; import gov.nist.secauto.metaschema.core.model.MetaschemaException; -import gov.nist.secauto.metaschema.core.model.xml.IXmlModule; import gov.nist.secauto.metaschema.core.model.xml.ModuleLoader; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.metaschema.databind.IBindingContext; @@ -39,7 +39,6 @@ import gov.nist.secauto.metaschema.databind.io.IDeserializer; import gov.nist.secauto.metaschema.databind.io.ISerializer; import gov.nist.secauto.metaschema.databind.model.metaschema.BindingModuleLoader; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingModule; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.METASCHEMA; import org.junit.jupiter.api.Test; @@ -112,7 +111,7 @@ void testReadMetaschemaAsXml() throws IOException { @Test void testModuleLoader() throws MetaschemaException, IOException { BindingModuleLoader loader = new BindingModuleLoader(); - IBindingModule module = loader.load(METASCHEMA_FILE); + IMetaschemaModule module = loader.load(METASCHEMA_FILE); assertNotNull(module); } @@ -120,7 +119,7 @@ void testModuleLoader() throws MetaschemaException, IOException { void testOscalBindingModuleLoader() throws MetaschemaException, IOException { BindingModuleLoader loader = new BindingModuleLoader(); loader.set(DeserializationFeature.DESERIALIZE_XML_ALLOW_ENTITY_RESOLUTION, true); - IBindingModule module = loader.load(ObjectUtils.notNull(URI.create( + IMetaschemaModule module = loader.load(ObjectUtils.notNull(URI.create( "https://raw.githubusercontent.com/usnistgov/OSCAL/main/src/metaschema/oscal_complete_metaschema.xml"))); assertNotNull(module); } @@ -130,7 +129,7 @@ void testOscalXmlModuleLoader() throws MetaschemaException, IOException { ModuleLoader loader = new ModuleLoader(); // loader.set(DeserializationFeature.DESERIALIZE_XML_ALLOW_ENTITY_RESOLUTION, // true); - IXmlModule module = loader.load(ObjectUtils.notNull(URI.create( + IMetaschemaModule module = loader.load(ObjectUtils.notNull(URI.create( "https://raw.githubusercontent.com/usnistgov/OSCAL/main/src/metaschema/oscal_complete_metaschema.xml"))); assertNotNull(module); } diff --git a/databind/src/test/java/gov/nist/secauto/metaschema/databind/io/json/JsonParserTest.java b/databind/src/test/java/gov/nist/secauto/metaschema/databind/io/json/JsonParserTest.java index 74687c984..12a42a603 100644 --- a/databind/src/test/java/gov/nist/secauto/metaschema/databind/io/json/JsonParserTest.java +++ b/databind/src/test/java/gov/nist/secauto/metaschema/databind/io/json/JsonParserTest.java @@ -28,20 +28,17 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; +import gov.nist.secauto.metaschema.core.model.IMetaschemaModule; import gov.nist.secauto.metaschema.core.model.MetaschemaException; -import gov.nist.secauto.metaschema.core.model.xml.IXmlModule; import gov.nist.secauto.metaschema.core.model.xml.ModuleLoader; import gov.nist.secauto.metaschema.databind.IBindingContext; import gov.nist.secauto.metaschema.databind.io.DeserializationFeature; import gov.nist.secauto.metaschema.databind.io.IBoundLoader; import gov.nist.secauto.metaschema.databind.model.AbstractBoundModelTestSupport; -import gov.nist.secauto.metaschema.databind.model.metaschema.BindingModuleLoader; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingModule; import org.junit.jupiter.api.Test; import java.io.IOException; -import java.net.URI; import java.nio.file.Paths; class JsonParserTest @@ -49,7 +46,7 @@ class JsonParserTest @Test void testIssue308Regression() throws IOException, MetaschemaException { ModuleLoader moduleLoader = new ModuleLoader(); - IXmlModule module + IMetaschemaModule module = moduleLoader.load(Paths.get("src/test/resources/metaschema/308-choice-regression/metaschema.xml")); IBindingContext context = IBindingContext.instance(); 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"); } diff --git a/databind/src/test/java/gov/nist/secauto/metaschema/databind/model/JsonKeyTest.java b/databind/src/test/java/gov/nist/secauto/metaschema/databind/model/JsonKeyTest.java index 685a51ccc..e0aae3b2e 100644 --- a/databind/src/test/java/gov/nist/secauto/metaschema/databind/model/JsonKeyTest.java +++ b/databind/src/test/java/gov/nist/secauto/metaschema/databind/model/JsonKeyTest.java @@ -28,11 +28,11 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; +import gov.nist.secauto.metaschema.core.model.IMetaschemaModule; import gov.nist.secauto.metaschema.core.model.MetaschemaException; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.metaschema.databind.IBindingContext; import gov.nist.secauto.metaschema.databind.model.metaschema.BindingModuleLoader; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingModule; import org.junit.jupiter.api.Test; @@ -51,7 +51,7 @@ class JsonKeyTest @Test void testJsonKey() throws IOException, MetaschemaException { - IBindingModule module = new BindingModuleLoader().load(ObjectUtils.requireNonNull( + IMetaschemaModule module = new BindingModuleLoader().load(ObjectUtils.requireNonNull( Paths.get("src/test/resources/metaschema/json-key/metaschema.xml"))); IBindingContext bindingContext = IBindingContext.instance(); 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 } diff --git a/metaschema-cli/src/test/java/gov/nist/secauto/metaschema/cli/CLITest.java b/metaschema-cli/src/test/java/gov/nist/secauto/metaschema/cli/CLITest.java index 97c44158f..554a01be1 100644 --- a/metaschema-cli/src/test/java/gov/nist/secauto/metaschema/cli/CLITest.java +++ b/metaschema-cli/src/test/java/gov/nist/secauto/metaschema/cli/CLITest.java @@ -47,7 +47,7 @@ * Unit test for simple CLI. */ public class CLITest { - private static final ExitCode NO_EXPECTION_CLASS = null; + private static final ExitCode NO_EXCEPTION_CLASS = null; void evaluateResult(@NonNull ExitStatus status, @NonNull ExitCode expectedCode) { status.generateMessage(true); @@ -65,7 +65,6 @@ void evaluateResult(@NonNull ExitStatus status, @NonNull ExitCode expectedCode, } private static Stream providesValues() { - ExitCode NO_EXCEPTION_CLASS = null; List values = new LinkedList<>() { { add(Arguments.of(new String[] {}, ExitCode.INVALID_COMMAND, NO_EXCEPTION_CLASS)); diff --git a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/ModuleIndex.java b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/ModuleIndex.java index 3a6cb48cc..5a28346fe 100644 --- a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/ModuleIndex.java +++ b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/ModuleIndex.java @@ -269,7 +269,7 @@ public boolean isChoiceSibling() { public boolean isUsedAsJsonKey() { return references.stream() .anyMatch(ref -> ref instanceof INamedModelInstance - && ((INamedModelInstance) ref).getJsonKeyFlagName() != null); + && ((INamedModelInstance) ref).hasJsonKey()); } public boolean isUsedWithoutJsonKey() { @@ -277,12 +277,12 @@ public boolean isUsedWithoutJsonKey() { || references.isEmpty() || references.stream() .anyMatch(ref -> ref instanceof INamedModelInstance - && ((INamedModelInstance) ref).getJsonKeyFlagName() == null); + && !((INamedModelInstance) ref).hasJsonKey()); } public boolean isChoiceGroupMember() { return references.stream() - .anyMatch(ref -> ref instanceof INamedModelInstanceGrouped); + .anyMatch(INamedModelInstanceGrouped.class::isInstance); } } } diff --git a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/json/impl/FieldDefinitionJsonSchema.java b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/json/impl/FieldDefinitionJsonSchema.java index 4ecbc7759..b660f3bd0 100644 --- a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/json/impl/FieldDefinitionJsonSchema.java +++ b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/json/impl/FieldDefinitionJsonSchema.java @@ -69,9 +69,9 @@ protected void generateBody( Collection flags = definition.getFlagInstances(); String discriminatorProperty = getDiscriminatorProperty(); - IFlagInstance jsonKeyFlag = definition.getJsonKeyFlagInstance(); + IFlagInstance jsonKeyFlag = definition.getJsonKey(); if (discriminatorProperty == null - && (flags.isEmpty() || (jsonKeyFlag != null && flags.size() == 1))) { // NOPMD readability + && (flags.isEmpty() || jsonKeyFlag != null && flags.size() == 1)) { // NOPMD readability // field is a simple data type value if there are no flags or if the only flag // is a JSON key IDataTypeJsonSchema schema = state.getDataTypeSchemaForDefinition(definition); diff --git a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/json/impl/builder/AbstractCollectionBuilder.java b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/json/impl/builder/AbstractCollectionBuilder.java index f1e859b97..118e4bf24 100644 --- a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/json/impl/builder/AbstractCollectionBuilder.java +++ b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/json/impl/builder/AbstractCollectionBuilder.java @@ -144,18 +144,7 @@ private abstract static class Type implements IMo protected Type(@NonNull T instance) { this.namedModelInstance = instance; - String jsonKeyFlagName = instance.getJsonKeyFlagName(); - IFlagInstance jsonKey = null; - if (jsonKeyFlagName != null) { - IModelDefinition definition = instance.getDefinition(); - jsonKey = definition.getFlagInstanceByName( - definition.getContainingModule().toFlagQName(jsonKeyFlagName)); - - if (jsonKey == null) { - throw new IllegalStateException(String.format("No JSON key flag named '%s.", jsonKeyFlagName)); - } - } - this.jsonKeyFlag = jsonKey; + this.jsonKeyFlag = instance.getEffectiveJsonKey(); if (instance instanceof INamedModelInstanceGrouped) { INamedModelInstanceGrouped grouped = (INamedModelInstanceGrouped) instance; @@ -166,7 +155,11 @@ protected Type(@NonNull T instance) { this.discriminatorValue = null; } this.key - = IKey.of(instance.getDefinition(), jsonKeyFlagName, this.discriminatorProperty, this.discriminatorValue); + = IKey.of( + instance.getDefinition(), + jsonKeyFlag == null ? null : jsonKeyFlag.getName(), + this.discriminatorProperty, + this.discriminatorValue); } @NonNull diff --git a/schemagen/src/test/java/gov/nist/secauto/metaschema/schemagen/JsonSuiteTest.java b/schemagen/src/test/java/gov/nist/secauto/metaschema/schemagen/JsonSuiteTest.java index 2d27f243a..cfd08e8e4 100644 --- a/schemagen/src/test/java/gov/nist/secauto/metaschema/schemagen/JsonSuiteTest.java +++ b/schemagen/src/test/java/gov/nist/secauto/metaschema/schemagen/JsonSuiteTest.java @@ -34,7 +34,6 @@ import gov.nist.secauto.metaschema.core.model.validation.JsonSchemaContentValidator; import gov.nist.secauto.metaschema.databind.io.Format; import gov.nist.secauto.metaschema.databind.model.metaschema.BindingModuleLoader; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingModule; import gov.nist.secauto.metaschema.schemagen.json.JsonSchemaGenerator; import org.junit.jupiter.api.Disabled; @@ -135,7 +134,7 @@ void testOscalComplete() throws IOException, MetaschemaException { // NOPMD - de BindingModuleLoader loader = new BindingModuleLoader(); loader.allowEntityResolution(); - IBindingModule module = loader.load(new URL( + IModule module = loader.load(new URL( "https://raw.githubusercontent.com/usnistgov/OSCAL/develop/src/metaschema/oscal_complete_metaschema.xml")); ISchemaGenerator schemaGenerator = new JsonSchemaGenerator(); IMutableConfiguration> features @@ -156,7 +155,7 @@ void testTestMetaschema() throws IOException, MetaschemaException { // NOPMD - d BindingModuleLoader loader = new BindingModuleLoader(); loader.allowEntityResolution(); - IBindingModule module = loader.load(new URL( + IModule module = loader.load(new URL( "https://raw.githubusercontent.com/usnistgov/metaschema/71233f4eb6854e820c7949144e86afa4d7981b22/test-suite/metaschema-xspec/json-schema-gen/json-value-testing-mini-metaschema.xml")); ISchemaGenerator schemaGenerator = new JsonSchemaGenerator(); IMutableConfiguration> features = new DefaultConfiguration<>(); diff --git a/schemagen/src/test/java/gov/nist/secauto/metaschema/schemagen/MetaschemaModuleTest.java b/schemagen/src/test/java/gov/nist/secauto/metaschema/schemagen/MetaschemaModuleTest.java index 5f57d26c1..4fae0da85 100644 --- a/schemagen/src/test/java/gov/nist/secauto/metaschema/schemagen/MetaschemaModuleTest.java +++ b/schemagen/src/test/java/gov/nist/secauto/metaschema/schemagen/MetaschemaModuleTest.java @@ -28,10 +28,10 @@ import gov.nist.secauto.metaschema.core.configuration.DefaultConfiguration; import gov.nist.secauto.metaschema.core.configuration.IMutableConfiguration; +import gov.nist.secauto.metaschema.core.model.IModule; import gov.nist.secauto.metaschema.core.model.MetaschemaException; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.metaschema.databind.model.metaschema.BindingModuleLoader; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingModule; import gov.nist.secauto.metaschema.schemagen.json.JsonSchemaGenerator; import gov.nist.secauto.metaschema.schemagen.xml.XmlSchemaGenerator; @@ -41,7 +41,6 @@ import java.io.Writer; import java.nio.charset.StandardCharsets; import java.nio.file.Files; -import java.nio.file.OpenOption; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardOpenOption; @@ -57,7 +56,7 @@ class MetaschemaModuleTest { void testGenerateMetaschemaModuleJson() throws MetaschemaException, IOException { BindingModuleLoader loader = new BindingModuleLoader(); - IBindingModule module = loader.load(METASCHEMA_FILE); + IModule module = loader.load(METASCHEMA_FILE); IMutableConfiguration> features = new DefaultConfiguration<>(); @@ -67,11 +66,7 @@ void testGenerateMetaschemaModuleJson() throws MetaschemaException, IOException try (Writer writer = Files.newBufferedWriter( Path.of("target/metaschema-schema.json"), StandardCharsets.UTF_8, - new OpenOption[] { - StandardOpenOption.CREATE, - StandardOpenOption.WRITE, - StandardOpenOption.TRUNCATE_EXISTING - })) { + StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING)) { assert writer != null; ISchemaGenerator schemaGenerator = new JsonSchemaGenerator(); schemaGenerator.generateFromModule(module, writer, features); @@ -82,7 +77,7 @@ void testGenerateMetaschemaModuleJson() throws MetaschemaException, IOException void testGenerateMetaschemaModuleXml() throws MetaschemaException, IOException { BindingModuleLoader loader = new BindingModuleLoader(); - IBindingModule module = loader.load(METASCHEMA_FILE); + IModule module = loader.load(METASCHEMA_FILE); IMutableConfiguration> features = new DefaultConfiguration<>(); @@ -92,11 +87,7 @@ void testGenerateMetaschemaModuleXml() throws MetaschemaException, IOException { try (Writer writer = Files.newBufferedWriter( Path.of("target/metaschema-schema.xsd"), StandardCharsets.UTF_8, - new OpenOption[] { - StandardOpenOption.CREATE, - StandardOpenOption.WRITE, - StandardOpenOption.TRUNCATE_EXISTING - })) { + StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING)) { assert writer != null; ISchemaGenerator schemaGenerator = new XmlSchemaGenerator(); schemaGenerator.generateFromModule(module, writer, features); diff --git a/schemagen/src/test/java/gov/nist/secauto/metaschema/schemagen/XmlSuiteTest.java b/schemagen/src/test/java/gov/nist/secauto/metaschema/schemagen/XmlSuiteTest.java index ac7b439ec..580793793 100644 --- a/schemagen/src/test/java/gov/nist/secauto/metaschema/schemagen/XmlSuiteTest.java +++ b/schemagen/src/test/java/gov/nist/secauto/metaschema/schemagen/XmlSuiteTest.java @@ -36,7 +36,6 @@ import gov.nist.secauto.metaschema.core.model.validation.XmlSchemaContentValidator; import gov.nist.secauto.metaschema.databind.io.Format; import gov.nist.secauto.metaschema.databind.model.metaschema.BindingModuleLoader; -import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingModule; import gov.nist.secauto.metaschema.schemagen.xml.XmlSchemaGenerator; import org.jdom2.Document; @@ -176,7 +175,7 @@ void testliboscalJavaIssue181() throws IOException, MetaschemaException, XMLStre BindingModuleLoader loader = new BindingModuleLoader(); loader.allowEntityResolution(); - IBindingModule module = loader.load(new URL( + IModule module = loader.load(new URL( // "https://raw.githubusercontent.com/usnistgov/OSCAL/develop/src/metaschema/oscal_complete_metaschema.xml")); "https://raw.githubusercontent.com/usnistgov/OSCAL/v1.1.1/src/metaschema/oscal_catalog_metaschema.xml")); ISchemaGenerator schemaGenerator = new XmlSchemaGenerator(); @@ -213,7 +212,7 @@ void testLiboscalJavaIssue181() throws IOException, MetaschemaException, XMLStre BindingModuleLoader loader = new BindingModuleLoader(); loader.allowEntityResolution(); - IBindingModule module = loader.load(new URL( + IModule module = loader.load(new URL( "https://raw.githubusercontent.com/usnistgov/OSCAL/v1.1.1/src/metaschema/oscal_catalog_metaschema.xml")); ISchemaGenerator schemaGenerator = new XmlSchemaGenerator(); IMutableConfiguration> features = new DefaultConfiguration<>(); diff --git a/src/site/site.xml b/src/site/site.xml index 643b3c61b..f5dc38049 100644 --- a/src/site/site.xml +++ b/src/site/site.xml @@ -12,7 +12,7 @@ - + io.github.devacfr.maven.skins @@ -115,5 +115,6 @@ + \ No newline at end of file