Skip to content

Commit

Permalink
Cleaned up the ModuleScopeEnum use. It is now located in IDefinition …
Browse files Browse the repository at this point in the history
…and the values have been changed: LOCAL->PRIVATE and GLOBAL->PUBLIC.
  • Loading branch information
david-waltermire committed Oct 27, 2024
1 parent beff4bc commit b39ea7c
Show file tree
Hide file tree
Showing 16 changed files with 61 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ public ISequenceType getResult() {
public static List<ISequence<?>> convertArguments(
@NonNull IFunction function,
@NonNull List<? extends ISequence<?>> parameters) {
@NonNull
List<ISequence<?>> retval = new ArrayList<>(parameters.size());
@NonNull List<ISequence<?>> retval = new ArrayList<>(parameters.size());

Iterator<IArgument> argumentIterator = function.getArguments().iterator();
IArgument argument = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -14,8 +13,10 @@
* Supports querying of global definitions and associated instances in a
* Metaschema module by effective name.
* <p>
* 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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,31 @@
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.
*
* @return the module scope
*/
@NonNull
default ModuleScopeEnum getModuleScope() {
return ModuleScopeEnum.LOCAL;
default ModuleScope getModuleScope() {
return ModuleScope.PRIVATE;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,8 @@ public interface IModuleExtended<
* @return a predicate implementing the filter
*/
static <DEF extends IDefinition> Predicate<DEF> 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());
}

/**
Expand All @@ -82,9 +80,8 @@ static <DEF extends IDefinition> Predicate<DEF> allNonLocalDefinitions() {
* @return a predicate implementing the filter
*/
static <DEF extends IDefinition> Predicate<DEF> allRootAssemblyDefinitions() {
return definition -> {
return ModelType.ASSEMBLY.equals(definition.getModelType()) && ((IAssemblyDefinition) definition).isRoot();
};
return definition -> (ModelType.ASSEMBLY.equals(definition.getModelType())
&& ((IAssemblyDefinition) definition).isRoot());
}

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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());
}
}
}
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion core/src/schema/xmlconfig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<xb:staticHandler>gov.nist.secauto.metaschema.core.model.xml.xmlbeans.handler.XmlGroupAsBehaviorType</xb:staticHandler>
</xb:usertype>
<xb:usertype name="meta:ScopeType"
javaname="gov.nist.secauto.metaschema.core.model.ModuleScopeEnum">
javaname="gov.nist.secauto.metaschema.core.model.IDefinition.ModuleScope">
<xb:staticHandler>gov.nist.secauto.metaschema.core.model.xml.xmlbeans.handler.ScopeType</xb:staticHandler>
</xb:usertype>
<xb:usertype name="meta:InXmlWrappedType"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
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.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;
Expand Down Expand Up @@ -178,7 +177,7 @@ public String getName() {
}

@Override
public ModuleScopeEnum getModuleScope() {
public ModuleScope getModuleScope() {
return ModelSupport.moduleScope(ObjectUtils.requireNonNull(getBinding().getScope()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -139,7 +138,7 @@ public String getName() {
}

@Override
public ModuleScopeEnum getModuleScope() {
public ModuleScope getModuleScope() {
return ModelSupport.moduleScope(ObjectUtils.requireNonNull(getBinding().getScope()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,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;
Expand Down Expand Up @@ -124,7 +123,7 @@ public MarkupLine getDescription() {
}

@Override
public ModuleScopeEnum getModuleScope() {
public ModuleScope getModuleScope() {
return ModelSupport.moduleScope(ObjectUtils.requireNonNull(getBinding().getScope()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
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.IDefinition;
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;
import gov.nist.secauto.metaschema.core.util.CollectionUtil;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
Expand Down Expand Up @@ -67,17 +67,24 @@ public static boolean yesOrNo(String allowOther) {
return "yes".equals(allowOther);
}

/**
* Translate a text scope value to the equivalent enumerated value.
*
* @param value
* the text scope value
* @return the enumerated value
*/
@SuppressWarnings("PMD.ImplicitSwitchFallThrough")
@NonNull
public static ModuleScopeEnum moduleScope(@NonNull String value) {
ModuleScopeEnum retval;
public static IDefinition.ModuleScope moduleScope(@NonNull String value) {
IDefinition.ModuleScope retval;
switch (value) {
case "local":
retval = ModuleScopeEnum.LOCAL;
retval = IDefinition.ModuleScope.PRIVATE;
break;
case "global":
default:
retval = ModuleScopeEnum.INHERITED;
retval = IDefinition.ModuleScope.PUBLIC;
}
return retval;
}
Expand Down

0 comments on commit b39ea7c

Please sign in to comment.