From b39ea7c5add1035ad719d72d1e843b5a3e46f401 Mon Sep 17 00:00:00 2001 From: David Waltermire Date: Sun, 27 Oct 2024 18:29:58 -0400 Subject: [PATCH] Cleaned up the ModuleScopeEnum use. It is now located in IDefinition and the values have been changed: LOCAL->PRIVATE and GLOBAL->PUBLIC. --- .../core/metapath/MetapathExpression.java | 3 +-- .../core/metapath/cst/math/Division.java | 2 +- .../metapath/function/DefaultFunction.java | 3 +-- .../metapath/item/node/IModuleNodeItem.java | 7 +++--- .../metaschema/core/model/IDefinition.java | 19 ++++++++++++--- .../core/model/IModuleExtended.java | 11 ++++----- .../core/model/ModuleScopeEnum.java | 18 -------------- .../xml/impl/XmlGlobalAssemblyDefinition.java | 5 ++-- .../xml/impl/XmlGlobalFieldDefinition.java | 5 ++-- .../xml/impl/XmlGlobalFlagDefinition.java | 5 ++-- .../model/xml/xmlbeans/handler/ScopeType.java | 24 +++++++++---------- core/src/schema/xmlconfig.xml | 2 +- .../impl/DefinitionAssemblyGlobal.java | 3 +-- .../impl/DefinitionFieldGlobal.java | 3 +-- .../metaschema/impl/DefinitionFlagGlobal.java | 3 +-- .../model/metaschema/impl/ModelSupport.java | 17 +++++++++---- 16 files changed, 61 insertions(+), 69 deletions(-) delete mode 100644 core/src/main/java/gov/nist/secauto/metaschema/core/model/ModuleScopeEnum.java diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/MetapathExpression.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/MetapathExpression.java index 9ba2b3cda..bbcc4d0bf 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/MetapathExpression.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/MetapathExpression.java @@ -111,8 +111,7 @@ public static MetapathExpression compile(@NonNull String path) { */ @NonNull public static MetapathExpression compile(@NonNull String path, @NonNull StaticContext context) { - @NonNull - MetapathExpression retval; + @NonNull MetapathExpression retval; if (".".equals(path)) { retval = CONTEXT_NODE; } else { diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/Division.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/Division.java index 50909bc78..c666218a2 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/Division.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/Division.java @@ -74,7 +74,7 @@ public static IAnyAtomicItem divide(@NonNull IAnyAtomicItem dividend, // NOPMD - retval = OperationFunctions.opDivideYearMonthDuration(left, (INumericItem) divisor); } else if (divisor instanceof IYearMonthDurationItem) { // TODO: find a way to support this - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException("year month division is not supported"); } } else if (dividend instanceof IDayTimeDurationItem) { IDayTimeDurationItem left = (IDayTimeDurationItem) dividend; 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 40752c640..b8e7f2c4f 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 @@ -95,8 +95,7 @@ public ISequenceType getResult() { public static List> convertArguments( @NonNull IFunction function, @NonNull List> parameters) { - @NonNull - List> retval = new ArrayList<>(parameters.size()); + @NonNull List> retval = new ArrayList<>(parameters.size()); Iterator argumentIterator = function.getArguments().iterator(); IArgument argument = null; diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/IModuleNodeItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/IModuleNodeItem.java index 602930f4d..b89982961 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/IModuleNodeItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/IModuleNodeItem.java @@ -4,7 +4,6 @@ import gov.nist.secauto.metaschema.core.metapath.StaticContext; import gov.nist.secauto.metaschema.core.metapath.format.IPathFormatter; import gov.nist.secauto.metaschema.core.model.IModule; -import gov.nist.secauto.metaschema.core.model.ModuleScopeEnum; import java.net.URI; @@ -14,8 +13,10 @@ * Supports querying of global definitions and associated instances in a * Metaschema module by effective name. *

- * All definitions in the {@link ModuleScopeEnum#INHERITED} scope. This allows - * the exported structure of the Metaschema module to be queried. + * All definitions in the + * {@link gov.nist.secauto.metaschema.core.model.IDefinition.ModuleScope#PUBLIC} + * are visible. This allows the exported structure of the Metaschema module to + * be queried. */ public interface IModuleNodeItem extends IDocumentBasedNodeItem, IFeatureNoDataValuedItem { 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 2232d063d..739c89c77 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 @@ -15,9 +15,22 @@ import edu.umd.cs.findbugs.annotations.Nullable; public interface IDefinition extends INamedModelElement, IAttributable, IFeatureValueConstrained { + /** + * Describes the visibility of a definition to other modules. + */ + enum ModuleScope { + /** + * The definition is scoped to only the defining module. + */ + PRIVATE, + /** + * The definition is scoped to its defining module and any importing module. + */ + PUBLIC; + } @NonNull - ModuleScopeEnum DEFAULT_DEFINITION_MODEL_SCOPE = ModuleScopeEnum.INHERITED; + ModuleScope DEFAULT_MODULE_SCOPE = ModuleScope.PUBLIC; /** * Retrieve the definition's scope within the context of its defining module. @@ -25,8 +38,8 @@ public interface IDefinition extends INamedModelElement, IAttributable, IFeature * @return the module scope */ @NonNull - default ModuleScopeEnum getModuleScope() { - return ModuleScopeEnum.LOCAL; + default ModuleScope getModuleScope() { + return ModuleScope.PRIVATE; } /** 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 0a0367d6c..eb8ddc0e4 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 @@ -68,10 +68,8 @@ public interface IModuleExtended< * @return a predicate implementing the filter */ static Predicate allNonLocalDefinitions() { - return definition -> { - return ModuleScopeEnum.INHERITED.equals(definition.getModuleScope()) - || ModelType.ASSEMBLY.equals(definition.getModelType()) && ((IAssemblyDefinition) definition).isRoot(); - }; + return definition -> (IDefinition.ModuleScope.PUBLIC.equals(definition.getModuleScope()) + || ModelType.ASSEMBLY.equals(definition.getModelType()) && ((IAssemblyDefinition) definition).isRoot()); } /** @@ -82,9 +80,8 @@ static Predicate allNonLocalDefinitions() { * @return a predicate implementing the filter */ static Predicate allRootAssemblyDefinitions() { - return definition -> { - return ModelType.ASSEMBLY.equals(definition.getModelType()) && ((IAssemblyDefinition) definition).isRoot(); - }; + return definition -> (ModelType.ASSEMBLY.equals(definition.getModelType()) + && ((IAssemblyDefinition) definition).isRoot()); } @Override diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/ModuleScopeEnum.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/ModuleScopeEnum.java deleted file mode 100644 index 629128417..000000000 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/ModuleScopeEnum.java +++ /dev/null @@ -1,18 +0,0 @@ -/* - * SPDX-FileCopyrightText: none - * SPDX-License-Identifier: CC0-1.0 - */ - -package gov.nist.secauto.metaschema.core.model; - -public enum ModuleScopeEnum { - // TODO: consider naming these PRIVATE and PUBLIC in a 2.0 - /** - * The definition is scoped to only the defining module. - */ - LOCAL, - /** - * The definition is scoped to its defining module and any importing module. - */ - INHERITED; -} 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 8973f2ab0..5c7349316 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 @@ -20,7 +20,6 @@ import gov.nist.secauto.metaschema.core.model.IModelInstanceAbsolute; import gov.nist.secauto.metaschema.core.model.INamedModelInstanceAbsolute; import gov.nist.secauto.metaschema.core.model.IResourceLocation; -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; @@ -200,8 +199,8 @@ public Integer getRootIndex() { @SuppressWarnings("null") @Override - public ModuleScopeEnum getModuleScope() { - return getXmlObject().isSetScope() ? getXmlObject().getScope() : DEFAULT_DEFINITION_MODEL_SCOPE; + public ModuleScope getModuleScope() { + return getXmlObject().isSetScope() ? getXmlObject().getScope() : DEFAULT_MODULE_SCOPE; } @SuppressWarnings("null") 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 016b90792..23203537a 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 @@ -14,7 +14,6 @@ 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.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; @@ -189,8 +188,8 @@ public String getJsonValueKeyName() { @SuppressWarnings("null") @Override - public ModuleScopeEnum getModuleScope() { - return getXmlObject().isSetScope() ? getXmlObject().getScope() : DEFAULT_DEFINITION_MODEL_SCOPE; + public ModuleScope getModuleScope() { + return getXmlObject().isSetScope() ? getXmlObject().getScope() : DEFAULT_MODULE_SCOPE; } @SuppressWarnings("null") 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 191c731f8..81ccc48d3 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 @@ -12,7 +12,6 @@ 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.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; @@ -97,8 +96,8 @@ protected final GlobalFlagDefinitionType getXmlFlag() { @SuppressWarnings("null") @Override - public ModuleScopeEnum getModuleScope() { - return getXmlFlag().isSetScope() ? getXmlFlag().getScope() : DEFAULT_DEFINITION_MODEL_SCOPE; + public ModuleScope getModuleScope() { + return getXmlFlag().isSetScope() ? getXmlFlag().getScope() : DEFAULT_MODULE_SCOPE; } @SuppressWarnings("null") diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/xmlbeans/handler/ScopeType.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/xmlbeans/handler/ScopeType.java index 7089c92a7..df40ae835 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/xmlbeans/handler/ScopeType.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/xmlbeans/handler/ScopeType.java @@ -5,7 +5,7 @@ package gov.nist.secauto.metaschema.core.model.xml.xmlbeans.handler; -import gov.nist.secauto.metaschema.core.model.ModuleScopeEnum; +import gov.nist.secauto.metaschema.core.model.IDefinition; public final class ScopeType { private ScopeType() { @@ -15,22 +15,22 @@ private ScopeType() { /** * Sets the value of obj onto the given simple value target. * - * @param obj + * @param value * the boolean value to set * @param target * the XML value to cast to a scope */ - public static void encodeScopeType(ModuleScopeEnum obj, org.apache.xmlbeans.SimpleValue target) { - if (obj != null) { - switch (obj) { - case INHERITED: + public static void encodeScopeType(IDefinition.ModuleScope value, org.apache.xmlbeans.SimpleValue target) { + if (value != null) { + switch (value) { + case PUBLIC: target.setStringValue("global"); break; - case LOCAL: + case PRIVATE: target.setStringValue("local"); break; default: - throw new UnsupportedOperationException(obj.toString()); + throw new UnsupportedOperationException(value.toString()); } } } @@ -42,15 +42,15 @@ public static void encodeScopeType(ModuleScopeEnum obj, org.apache.xmlbeans.Simp * the XML value to cast to a scope * @return the associated scope value */ - public static ModuleScopeEnum decodeScopeType(org.apache.xmlbeans.SimpleValue obj) { + public static IDefinition.ModuleScope decodeScopeType(org.apache.xmlbeans.SimpleValue obj) { String value = obj.getStringValue(); - ModuleScopeEnum retval; + IDefinition.ModuleScope retval; switch (value) { case "global": - retval = ModuleScopeEnum.INHERITED; + retval = IDefinition.ModuleScope.PUBLIC; break; case "local": - retval = ModuleScopeEnum.LOCAL; + retval = IDefinition.ModuleScope.PRIVATE; break; default: throw new UnsupportedOperationException(value); diff --git a/core/src/schema/xmlconfig.xml b/core/src/schema/xmlconfig.xml index 73d4d6534..c738525e5 100644 --- a/core/src/schema/xmlconfig.xml +++ b/core/src/schema/xmlconfig.xml @@ -27,7 +27,7 @@ gov.nist.secauto.metaschema.core.model.xml.xmlbeans.handler.XmlGroupAsBehaviorType + javaname="gov.nist.secauto.metaschema.core.model.IDefinition.ModuleScope"> gov.nist.secauto.metaschema.core.model.xml.xmlbeans.handler.ScopeType