diff --git a/cli-processor/pom.xml b/cli-processor/pom.xml
index 8cf166e9d..0fe90e8ad 100644
--- a/cli-processor/pom.xml
+++ b/cli-processor/pom.xml
@@ -52,10 +52,6 @@
nl.talsmasoftwarelazy4j
-
- com.google.auto.service
- auto-service-annotations
- org.apache.logging.log4jlog4j-core
diff --git a/cli-processor/src/main/java/gov/nist/secauto/metaschema/cli/processor/CLIProcessor.java b/cli-processor/src/main/java/gov/nist/secauto/metaschema/cli/processor/CLIProcessor.java
index ff919cf54..104fb9018 100644
--- a/cli-processor/src/main/java/gov/nist/secauto/metaschema/cli/processor/CLIProcessor.java
+++ b/cli-processor/src/main/java/gov/nist/secauto/metaschema/cli/processor/CLIProcessor.java
@@ -7,10 +7,13 @@
import static org.fusesource.jansi.Ansi.ansi;
+import gov.nist.secauto.metaschema.cli.processor.command.CommandExecutionException;
import gov.nist.secauto.metaschema.cli.processor.command.CommandService;
import gov.nist.secauto.metaschema.cli.processor.command.ExtraArgument;
import gov.nist.secauto.metaschema.cli.processor.command.ICommand;
import gov.nist.secauto.metaschema.cli.processor.command.ICommandExecutor;
+import gov.nist.secauto.metaschema.core.util.AutoCloser;
+import gov.nist.secauto.metaschema.core.util.CollectionUtil;
import gov.nist.secauto.metaschema.core.util.IVersionInfo;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
@@ -35,11 +38,10 @@
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collection;
-import java.util.Collections;
-import java.util.Deque;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -164,6 +166,13 @@ private ExitStatus parseCommand(String... args) {
assert commandArgs != null;
CallingContext callingContext = new CallingContext(commandArgs);
+ if (LOGGER.isDebugEnabled()) {
+ String commandChain = callingContext.getCalledCommands().stream()
+ .map(ICommand::getName)
+ .collect(Collectors.joining(" -> "));
+ LOGGER.debug("Processing command chain: {}", commandChain);
+ }
+
ExitStatus status;
// the first two arguments should be the and , where
// is the object type
@@ -177,10 +186,16 @@ private ExitStatus parseCommand(String... args) {
return status;
}
+ @NonNull
protected final List getTopLevelCommands() {
- List retval = Collections.unmodifiableList(commands);
- assert retval != null;
- return retval;
+ return CollectionUtil.unmodifiableList(commands);
+ }
+
+ @NonNull
+ protected final Map getTopLevelCommandsByName() {
+ return ObjectUtils.notNull(getTopLevelCommands()
+ .stream()
+ .collect(Collectors.toUnmodifiableMap(ICommand::getName, Function.identity())));
}
private static void handleNoColor() {
@@ -200,7 +215,8 @@ public static void handleQuiet() {
}
protected void showVersion() {
- @SuppressWarnings("resource") PrintStream out = AnsiConsole.out(); // NOPMD - not owner
+ @SuppressWarnings("resource")
+ PrintStream out = AnsiConsole.out(); // NOPMD - not owner
getVersionInfos().values().stream().forEach(info -> {
out.println(ansi()
.bold().a(info.getName()).boldOff()
@@ -230,63 +246,44 @@ public class CallingContext {
@NonNull
private final List
-
- com.google.auto.service
- auto-service-annotations
-
-
com.github.spotbugsspotbugs-annotations
diff --git a/databind-metaschema/src/main/java/gov/nist/secauto/metaschema/modules/sarif/SarifValidationHandler.java b/databind-metaschema/src/main/java/gov/nist/secauto/metaschema/modules/sarif/SarifValidationHandler.java
index 3211cf8e7..31b4e779b 100644
--- a/databind-metaschema/src/main/java/gov/nist/secauto/metaschema/modules/sarif/SarifValidationHandler.java
+++ b/databind-metaschema/src/main/java/gov/nist/secauto/metaschema/modules/sarif/SarifValidationHandler.java
@@ -45,6 +45,7 @@
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
+import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
@@ -56,6 +57,10 @@
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
+/**
+ * Supports building a Static Analysis Results Interchange Format (SARIF)
+ * document based on a set of validation findings.
+ */
@SuppressWarnings("PMD.CouplingBetweenObjects")
public final class SarifValidationHandler {
private enum Kind {
@@ -99,15 +104,15 @@ public String getLabel() {
}
@NonNull
- public static final String SARIF_NS = "https://docs.oasis-open.org/sarif/sarif/v2.1.0";
+ static final String SARIF_NS = "https://docs.oasis-open.org/sarif/sarif/v2.1.0";
@NonNull
- public static final IAttributable.Key SARIF_HELP_URL_KEY
+ static final IAttributable.Key SARIF_HELP_URL_KEY
= IAttributable.key("help-url", SARIF_NS);
@NonNull
- public static final IAttributable.Key SARIF_HELP_TEXT_KEY
+ static final IAttributable.Key SARIF_HELP_TEXT_KEY
= IAttributable.key("help-text", SARIF_NS);
@NonNull
- public static final IAttributable.Key SARIF_HELP_MARKDOWN_KEY
+ static final IAttributable.Key SARIF_HELP_MARKDOWN_KEY
= IAttributable.key("help-markdown", SARIF_NS);
@NonNull
@@ -131,6 +136,15 @@ public String getLabel() {
private final SchemaRuleRecord schemaRule = new SchemaRuleRecord();
private boolean schemaValid = true;
+ /**
+ * Construct a new validation handler.
+ *
+ * @param source
+ * the URI of the content that was validated
+ * @param toolVersion
+ * the version information for the tool producing the validation
+ * results
+ */
public SarifValidationHandler(
@NonNull URI source,
@Nullable IVersionInfo toolVersion) {
@@ -147,17 +161,29 @@ private URI getSource() {
return source;
}
- public IVersionInfo getToolVersion() {
+ private IVersionInfo getToolVersion() {
return toolVersion;
}
- public void addFindings(@NonNull List extends IValidationFinding> findings) {
+ /**
+ * Register a collection of validation finding.
+ *
+ * @param findings
+ * the findings to register
+ */
+ public void addFindings(@NonNull Collection extends IValidationFinding> findings) {
for (IValidationFinding finding : findings) {
assert finding != null;
addFinding(finding);
}
}
+ /**
+ * Register a validation finding.
+ *
+ * @param finding
+ * the finding to register
+ */
public void addFinding(@NonNull IValidationFinding finding) {
if (finding instanceof JsonValidationFinding) {
addJsonValidationFinding((JsonValidationFinding) finding);
@@ -207,7 +233,20 @@ private void addConstraintValidationFinding(@NonNull ConstraintValidationFinding
results.add(new ConstraintResult(finding));
}
- public void write(@NonNull Path outputFile) throws IOException {
+ /**
+ * Write the collection of findings to the provided output file.
+ *
+ * @param outputFile
+ * the path to the output file to write to
+ * @param bindingContext
+ * the context used to access Metaschema module information based on
+ * Java class bindings
+ * @throws IOException
+ * if an error occurred while writing the SARIF file
+ */
+ public void write(
+ @NonNull Path outputFile,
+ @NonNull IBindingContext bindingContext) throws IOException {
URI output = ObjectUtils.notNull(outputFile.toUri());
@@ -246,7 +285,6 @@ public void write(@NonNull Path outputFile) throws IOException {
run.setTool(tool);
}
- IBindingContext bindingContext = IBindingContext.newInstance();
bindingContext.registerModule(SarifModule.class);
bindingContext.newSerializer(Format.JSON, Sarif.class)
.disableFeature(SerializationFeature.SERIALIZE_ROOT)
@@ -428,7 +466,8 @@ public List generateResults(@NonNull URI output) throws IOException {
assert constraint != null;
ConstraintRuleRecord rule = getRuleRecord(constraint);
- @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") Result result = new Result();
+ @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
+ Result result = new Result();
String id = constraint.getId();
if (id != null) {
diff --git a/databind-metaschema/src/test/java/gov/nist/secauto/metaschema/modules/sarif/SarifValidationHandlerTest.java b/databind-metaschema/src/test/java/gov/nist/secauto/metaschema/modules/sarif/SarifValidationHandlerTest.java
index 9dce9a8d1..76b3488ac 100644
--- a/databind-metaschema/src/test/java/gov/nist/secauto/metaschema/modules/sarif/SarifValidationHandlerTest.java
+++ b/databind-metaschema/src/test/java/gov/nist/secauto/metaschema/modules/sarif/SarifValidationHandlerTest.java
@@ -15,6 +15,7 @@
import gov.nist.secauto.metaschema.core.model.validation.IValidationFinding;
import gov.nist.secauto.metaschema.core.util.IVersionInfo;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
+import gov.nist.secauto.metaschema.databind.IBindingContext;
import org.jmock.Expectations;
import org.jmock.junit5.JUnit5Mockery;
@@ -110,7 +111,7 @@ void testValid() throws IOException {
// no need to cleanup this file, since it is created in the target directory
Path sarifFile = ObjectUtils.requireNonNull(Paths.get("target/test.sarif"));
- handler.write(sarifFile);
+ handler.write(sarifFile, IBindingContext.newInstance());
Path sarifSchema = Paths.get("modules/sarif/sarif-schema-2.1.0.json");
diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/AbstractModuleLoaderStrategy.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/AbstractModuleLoaderStrategy.java
index fe5ba18d2..148b067cb 100644
--- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/AbstractModuleLoaderStrategy.java
+++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/AbstractModuleLoaderStrategy.java
@@ -95,7 +95,7 @@ public IBoundModule registerModule(
}
@NonNull
- protected abstract Class extends IBoundModule> handleUnboundModule(IModule key);
+ protected abstract Class extends IBoundModule> handleUnboundModule(@NonNull IModule key);
/**
* Get the Module instance for a given class annotated by the
@@ -106,6 +106,8 @@ public IBoundModule registerModule(
*
* @param moduleClass
* the Module class
+ * @param bindingContext
+ * the Metaschema binding context used to lookup binding information
* @return the new Module instance
*/
@NonNull
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 4558b2a2d..d34994a07 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
@@ -125,8 +125,6 @@ public final IBoundModule registerModule(@NonNull Class extends IBoundModule>
* Get the binding matchers that are associated with this class.
*
* @return the list of matchers
- * @see #registerBindingMatcher(Class)
- * @see #registerBindingMatcher(IBoundDefinitionModelAssembly)
*/
@NonNull
protected Collection getBindingMatchers() {
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 5f1f0e631..890092d85 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
@@ -257,8 +257,6 @@ default IConstraintLoader newConstraintLoader() {
*
* @param module
* the Module module to generate classes for
- * @param compilePath
- * the path to the directory to generate classes in
* @return the registered module, which may be a different instance than what
* was provided if dynamic compilation was performed
* @throws UnsupportedOperationException
@@ -304,7 +302,6 @@ default IBoundModule registerModule(@NonNull IModule module) {
* @param rootQName
* the root XML element's QName
* @return the bound class or {@code null} if not recognized
- * @see IBindingContext#registerBindingMatcher(Class)
*/
@Nullable
Class extends IBoundObject> getBoundClassForRootXmlQName(@NonNull QName rootQName);
@@ -316,7 +313,6 @@ default IBoundModule registerModule(@NonNull IModule module) {
* @param rootName
* the JSON/YAML property/item name
* @return the bound class or {@code null} if not recognized
- * @see IBindingContext#registerBindingMatcher(Class)
*/
@Nullable
Class extends IBoundObject> getBoundClassForRootJsonName(@NonNull String rootName);
@@ -830,7 +826,8 @@ default IValidationResult validateWithSchema(
switch (asFormat) {
case JSON: {
JSONObject json;
- try (@SuppressWarnings("resource") InputStream is
+ try (@SuppressWarnings("resource")
+ InputStream is
= new BufferedInputStream(ObjectUtils.notNull(targetResource.openStream()))) {
json = new JSONObject(new JSONTokener(is));
}
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 8186e9075..b2d05c400 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
@@ -58,7 +58,7 @@ public IBoundModule loadModule(Class extends IBoundModule> clazz, IBindingCont
@Override
public void postProcessModule(IModule module, IBindingContext bindingContext) {
- processModule(module, bindingContext);
+ processModule(module);
delegate.postProcessModule(module, bindingContext);
}
@@ -68,7 +68,7 @@ public IBoundModule registerModule(IModule module, IBindingContext bindingContex
postProcessedModulesLock.lock();
try {
// process before registering
- processModule(module, bindingContext);
+ processModule(module);
boundModule = delegate.registerModule(module, bindingContext);
@@ -80,7 +80,7 @@ public IBoundModule registerModule(IModule module, IBindingContext bindingContex
return boundModule;
}
- protected void processModule(IModule module, IBindingContext bindingContext) {
+ private void processModule(@NonNull IModule module) {
postProcessedModulesLock.lock();
try {
if (!postProcessedModules.contains(module)) {
diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/RootAssemblyBindingMatcher.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/RootAssemblyBindingMatcher.java
index 40ab248f2..838da028c 100644
--- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/RootAssemblyBindingMatcher.java
+++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/RootAssemblyBindingMatcher.java
@@ -51,4 +51,9 @@ public Class extends IBoundObject> getBoundClassForXmlQName(QName rootQName) {
public Class extends IBoundObject> getBoundClassForJsonName(String rootName) {
return getRootJsonName().equals(rootName) ? getClazz() : null;
}
+
+ @Override
+ public String toString() {
+ return getDefinition().getRootXmlQName().toString();
+ }
}
diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/JavaCompilerSupport.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/JavaCompilerSupport.java
index fcf9e731a..ffce169e7 100644
--- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/JavaCompilerSupport.java
+++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/JavaCompilerSupport.java
@@ -94,8 +94,8 @@ protected List generateCompilerOptions() {
/**
* Generate and compile Java classes.
*
- * @param classDir
- * the directory to generate the classes in
+ * @param classFiles
+ * the files to compile
* @param compileOut
* a Writer for additional output from the compiler; use System.err if
* null
diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/ModuleCompilerHelper.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/ModuleCompilerHelper.java
index e9ee84b17..becb466b4 100644
--- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/ModuleCompilerHelper.java
+++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/ModuleCompilerHelper.java
@@ -116,9 +116,9 @@ public static IProduction compileModule(
IProduction production = JavaGenerator.generate(module, classDir, bindingConfiguration);
List classesToCompile = production.getGeneratedClasses().collect(Collectors.toList());
- List classes = classesToCompile.stream()
+ List classes = ObjectUtils.notNull(classesToCompile.stream()
.map(IGeneratedClass::getClassFile)
- .collect(Collectors.toUnmodifiableList());
+ .collect(Collectors.toUnmodifiableList()));
JavaCompilerSupport compiler = new JavaCompilerSupport(classDir);
@@ -128,7 +128,7 @@ public static IProduction compileModule(
ModuleDescriptor descriptor = databindModule.getDescriptor();
if (descriptor != null) {
// add the databind module to the task
- compiler.addRootModule(descriptor.name());
+ compiler.addRootModule(ObjectUtils.notNull(descriptor.name()));
usingModule = true;
}
}
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 faf19be57..9e4b0cfb8 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
@@ -231,8 +231,8 @@ public IGeneratedClass generatePackageInfoClass(
}
/**
- * Creates and configures a builder, for a Module module, that can be used to
- * generate a Java class.
+ * Creates and configures a builder for a module that can be used to generate a
+ * Java class.
*
* @param module
* a parsed Module module
@@ -251,51 +251,7 @@ protected TypeSpec.Builder newClassBuilder(
.addModifiers(Modifier.FINAL);
builder.superclass(AbstractBoundModule.class);
-
- AnnotationSpec.Builder moduleAnnotation = AnnotationSpec.builder(MetaschemaModule.class);
-
- ITypeResolver typeResolver = getTypeResolver();
- for (IFieldDefinition definition : module.getFieldDefinitions()) {
- if (definition.hasChildren()) {
- moduleAnnotation.addMember("fields", "$T.class", typeResolver.getClassName(definition));
- }
- }
-
- for (IAssemblyDefinition definition : module.getAssemblyDefinitions()) {
- moduleAnnotation.addMember(
- "assemblies",
- "$T.class",
- typeResolver.getClassName(ObjectUtils.notNull(definition)));
- }
-
- for (IModule moduleImport : module.getImportedModules()) {
- moduleAnnotation.addMember(
- "imports",
- "$T.class",
- typeResolver.getClassName(ObjectUtils.notNull(moduleImport)));
- }
-
- Map bindings = module.getNamespaceBindings();
- if (!bindings.isEmpty()) {
- for (Map.Entry binding : bindings.entrySet()) {
- moduleAnnotation.addMember(
- "nsBindings",
- "$L",
- AnnotationSpec.builder(NsBinding.class)
- .addMember("prefix", "$S", binding.getKey())
- .addMember("uri", "$S", binding.getValue())
- .build());
- }
- }
-
- {
- MarkupMultiline remarks = module.getRemarks();
- if (remarks != null) {
- moduleAnnotation.addMember("remarks", "$S", remarks.toMarkdown());
- }
- }
-
- builder.addAnnotation(moduleAnnotation.build());
+ builder.addAnnotation(buildModuleAnnotation(module).build());
builder.addField(
FieldSpec.builder(MarkupLine.class, "NAME", Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL)
@@ -477,6 +433,50 @@ protected TypeSpec.Builder newClassBuilder(
return ObjectUtils.notNull(builder);
}
+ private AnnotationSpec.Builder buildModuleAnnotation(@NonNull IModule module) {
+ AnnotationSpec.Builder retval = AnnotationSpec.builder(MetaschemaModule.class);
+
+ ITypeResolver typeResolver = getTypeResolver();
+ for (IFieldDefinition definition : module.getFieldDefinitions()) {
+ if (definition.hasChildren()) {
+ retval.addMember("fields", "$T.class", typeResolver.getClassName(definition));
+ }
+ }
+
+ for (IAssemblyDefinition definition : module.getAssemblyDefinitions()) {
+ retval.addMember(
+ "assemblies",
+ "$T.class",
+ typeResolver.getClassName(ObjectUtils.notNull(definition)));
+ }
+
+ for (IModule moduleImport : module.getImportedModules()) {
+ retval.addMember(
+ "imports",
+ "$T.class",
+ typeResolver.getClassName(ObjectUtils.notNull(moduleImport)));
+ }
+
+ Map bindings = module.getNamespaceBindings();
+ if (!bindings.isEmpty()) {
+ for (Map.Entry binding : bindings.entrySet()) {
+ retval.addMember(
+ "nsBindings",
+ "$L",
+ AnnotationSpec.builder(NsBinding.class)
+ .addMember("prefix", "$S", binding.getKey())
+ .addMember("uri", "$S", binding.getValue())
+ .build());
+ }
+ }
+
+ MarkupMultiline remarks = module.getRemarks();
+ if (remarks != null) {
+ retval.addMember("remarks", "$S", remarks.toMarkdown());
+ }
+ return retval;
+ }
+
/**
* Generate the contents of the class represented by the provided
* {@code builder}.
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 3d3972425..7f81c0b90 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
@@ -54,10 +54,29 @@ public Set buildField(
FieldSpec.Builder fieldBuilder) {
super.buildField(typeBuilder, fieldBuilder);
- AnnotationSpec.Builder annotation = AnnotationSpec.builder(BoundFlag.class);
-
IFlagInstance instance = getInstance();
+ fieldBuilder.addAnnotation(buildBoundFlagAnnotation(instance).build());
+
+ IModelDefinition parent = instance.getContainingDefinition();
+ IFlagInstance jsonKey = parent.getJsonKey();
+ if (instance.equals(jsonKey)) {
+ fieldBuilder.addAnnotation(JsonKey.class);
+ }
+
+ if (parent instanceof IFieldDefinition) {
+ IFieldDefinition parentField = (IFieldDefinition) parent;
+
+ if (parentField.hasJsonValueKeyFlagInstance() && instance.equals(parentField.getJsonValueKeyFlagInstance())) {
+ fieldBuilder.addAnnotation(JsonFieldValueKeyFlag.class);
+ }
+ }
+ return CollectionUtil.emptySet();
+ }
+
+ private static AnnotationSpec.Builder buildBoundFlagAnnotation(@NonNull IFlagInstance instance) {
+ AnnotationSpec.Builder annotation = AnnotationSpec.builder(BoundFlag.class);
+
String formalName = instance.getEffectiveFormalName();
if (formalName != null) {
annotation.addMember("formalName", "$S", formalName);
@@ -97,21 +116,6 @@ public Set buildField(
AnnotationGenerator.buildValueConstraints(annotation, definition);
- fieldBuilder.addAnnotation(annotation.build());
-
- IModelDefinition parent = instance.getContainingDefinition();
- IFlagInstance jsonKey = parent.getJsonKey();
- if (instance.equals(jsonKey)) {
- fieldBuilder.addAnnotation(JsonKey.class);
- }
-
- if (parent instanceof IFieldDefinition) {
- IFieldDefinition parentField = (IFieldDefinition) parent;
-
- if (parentField.hasJsonValueKeyFlagInstance() && instance.equals(parentField.getJsonValueKeyFlagInstance())) {
- fieldBuilder.addAnnotation(JsonFieldValueKeyFlag.class);
- }
- }
- return CollectionUtil.emptySet();
+ return annotation;
}
}
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 9a786cd3f..1efd9003f 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
@@ -431,7 +431,7 @@ private IBoundObject readComplexDefinitionObject(
IBoundObject item = definition.newInstance(
JsonLocation.NA.equals(location)
? null
- : () -> new MetaschemaData(location));
+ : () -> new MetaschemaData(ObjectUtils.requireNonNull(location)));
try {
// call pre-parse initialization hook
diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/io/xml/MetaschemaXmlReader.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/io/xml/MetaschemaXmlReader.java
index 39acfecba..ed3d15ec6 100644
--- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/io/xml/MetaschemaXmlReader.java
+++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/io/xml/MetaschemaXmlReader.java
@@ -146,8 +146,9 @@ public CLASS read(@NonNull IBoundDefinitionModelComplex definition) thro
ItemReadHandler handler = new ItemReadHandler(ObjectUtils.notNull(event.asStartElement()));
Object value = definition.readItem(null, handler);
if (value == null) {
- throw new IOException(String.format("Unable to read data%s",
- XmlEventUtil.generateLocationMessage(reader.peek())));
+ event = reader.peek();
+ throw new IOException(String.format("Unable to read data.%s",
+ event == null ? "" : XmlEventUtil.generateLocationMessage(event)));
}
return ObjectUtils.asType(value);
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 59036b177..3ae7306d0 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
@@ -26,11 +26,6 @@ public interface IBoundDefinitionModelComplex
@NonNull
Map> getJsonProperties(@Nullable Predicate flagFilter);
- @Override
- default boolean isInline() {
- return getBoundClass().getEnclosingClass() != null;
- }
-
@Nullable
Method getBeforeDeserializeMethod();
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 fa0d02f35..b2a36b9cf 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
@@ -8,6 +8,7 @@
import gov.nist.secauto.metaschema.core.datatype.IDataTypeAdapter;
import gov.nist.secauto.metaschema.core.model.IBoundObject;
import gov.nist.secauto.metaschema.core.model.IFieldInstanceAbsolute;
+import gov.nist.secauto.metaschema.core.util.ObjectUtils;
import gov.nist.secauto.metaschema.databind.IBindingContext;
import gov.nist.secauto.metaschema.databind.model.impl.DefinitionField;
import gov.nist.secauto.metaschema.databind.model.impl.InstanceModelFieldComplex;
@@ -42,8 +43,8 @@ static IBoundInstanceModelField> newInstance(
IBoundInstanceModelField> retval;
if (IBoundObject.class.isAssignableFrom(itemType)) {
IBindingContext bindingContext = containingDefinition.getBindingContext();
- IBoundDefinitionModel> definition
- = bindingContext.getBoundDefinitionForClass(itemType.asSubclass(IBoundObject.class));
+ IBoundDefinitionModel> definition = bindingContext.getBoundDefinitionForClass(
+ ObjectUtils.notNull(itemType.asSubclass(IBoundObject.class)));
if (definition == null) {
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/impl/AbstractBoundDefinitionModelComplex.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/AbstractBoundDefinitionModelComplex.java
index b05c8e1ca..e175ef956 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
@@ -96,11 +96,6 @@ public final QName getDefinitionQName() {
return definitionQName.get();
}
- @Override
- public boolean isInline() {
- return getBoundClass().getEnclosingClass() != null;
- }
-
@Override
public Method getBeforeDeserializeMethod() {
return beforeDeserializeMethod;
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 068ad33e2..436dbb775 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
@@ -74,6 +74,10 @@ public final class DefinitionAssembly
*
* @param clazz
* the class the assembly is bound to
+ * @param annotation
+ * the binding annotation associated with this class
+ * @param module
+ * the module containing this class
* @param bindingContext
* the Metaschema binding context managing this class used to lookup
* binding information
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 b9f3e2359..0c38d771d 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
@@ -95,6 +95,10 @@ private static Field getFieldValueField(Class> clazz) {
*
* @param clazz
* the Java class the definition is bound to
+ * @param annotation
+ * the binding annotation associated with this class
+ * @param module
+ * the module containing this class
* @param bindingContext
* the Metaschema binding context managing this class used to lookup
* binding information
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 caf09412b..fd60dc82e 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
@@ -153,10 +153,11 @@ protected List parseResource(@NonNull URI resource, @NonNull Deq
ISource source = ISource.externalSource(builder.build());
- List targetedConstraints = CollectionUtil.listOrEmpty(obj.getContexts()).stream()
+ List targetedConstraints = ObjectUtils.notNull(CollectionUtil.listOrEmpty(obj.getContexts())
+ .stream()
.flatMap(context -> parseContext(ObjectUtils.notNull(context), null, source)
.getTargetedConstraints().stream())
- .collect(Collectors.toList());
+ .collect(Collectors.toList()));
retval.add(new MetaConstraintSet(targetedConstraints));
retval = CollectionUtil.unmodifiableList(retval);
@@ -263,17 +264,17 @@ private Context parseContext(
List metapaths;
if (parent == null) {
- metapaths = CollectionUtil.listOrEmpty(contextObj.getMetapaths()).stream()
+ metapaths = ObjectUtils.notNull(CollectionUtil.listOrEmpty(contextObj.getMetapaths()).stream()
.map(MetaschemaMetapath::getTarget)
- .collect(Collectors.toList());
+ .collect(Collectors.toList()));
} else {
List parentMetapaths = parent.getMetapaths().stream()
.collect(Collectors.toList());
- metapaths = CollectionUtil.listOrEmpty(contextObj.getMetapaths()).stream()
+ metapaths = ObjectUtils.notNull(CollectionUtil.listOrEmpty(contextObj.getMetapaths()).stream()
.map(MetaschemaMetapath::getTarget)
.flatMap(childPath -> parentMetapaths.stream()
.map(parentPath -> parentPath + '/' + childPath))
- .collect(Collectors.toList());
+ .collect(Collectors.toList()));
}
AssemblyConstraints contextConstraints = contextObj.getConstraints();
@@ -283,9 +284,9 @@ private Context parseContext(
}
Context context = new Context(metapaths, constraints);
- List childContexts = CollectionUtil.listOrEmpty(contextObj.getContexts()).stream()
+ List childContexts = ObjectUtils.notNull(CollectionUtil.listOrEmpty(contextObj.getContexts()).stream()
.map(childObj -> parseContext(ObjectUtils.notNull(childObj), context, source))
- .collect(Collectors.toList());
+ .collect(Collectors.toList()));
context.addAll(childContexts);
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 dd0b35bd0..b6bcc7248 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
@@ -56,6 +56,8 @@ public class BindingModuleLoader
*
* @param bindingContext
* the Metaschema binding context used to load bound resources
+ * @param postProcessor
+ * the post processor to use when after loading a module
*/
public BindingModuleLoader(
@NonNull IBindingContext bindingContext,
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 0a6b457ba..c92d3fc6a 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
@@ -7,6 +7,8 @@
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.IContainerModelAbsolute;
import gov.nist.secauto.metaschema.core.model.IContainerModelSupport;
import gov.nist.secauto.metaschema.core.model.IFieldDefinition;
@@ -55,6 +57,22 @@ protected static void addInstance(
fieldInstances.put(effectiveName, field);
}
+ protected static void addInstance(
+ @NonNull IChoiceInstance choice,
+ @NonNull List modelInstances,
+ @NonNull List choiceInstances) {
+ modelInstances.add(choice);
+ choiceInstances.add(choice);
+ }
+
+ protected static void addInstance(
+ @NonNull IChoiceGroupInstance choiceGroup,
+ @NonNull List modelInstances,
+ @NonNull Map choiceGroupInstances) {
+ modelInstances.add(choiceGroup);
+ choiceGroupInstances.put(choiceGroup.getGroupAsName(), choiceGroup);
+ }
+
@NonNull
protected static IAssemblyInstanceAbsolute newInstance(
@NonNull AssemblyReference obj,
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 c995d6170..63bf64851 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
@@ -31,6 +31,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
import javax.xml.namespace.QName;
@@ -95,7 +96,11 @@ IChoiceGroupInstance> of(
* @param nodeItemFactory
* the node item factory used to generate child nodes
*/
- @SuppressWarnings({ "PMD.AvoidInstantiatingObjectsInLoops", "PMD.UseConcurrentHashMap", "PMD.PrematureDeclaration" })
+ @SuppressWarnings({
+ "PMD.AvoidInstantiatingObjectsInLoops",
+ "PMD.UseConcurrentHashMap",
+ "PMD.PrematureDeclaration",
+ "PMD.NPathComplexity" })
@SuppressFBWarnings(value = "CT_CONSTRUCTOR_THROW", justification = "Use of final fields")
protected AssemblyModelContainerSupport(
@NonNull AssemblyModel model,
@@ -112,17 +117,17 @@ protected AssemblyModelContainerSupport(
final Map choiceGroupInstances = new LinkedHashMap<>();
// create counters to track child positions
- int assemblyReferencePosition = 0;
- int assemblyInlineDefinitionPosition = 0;
- int fieldReferencePosition = 0;
- int fieldInlineDefinitionPosition = 0;
- int choicePosition = 0;
- int choiceGroupPosition = 0;
-
- // TODO: make "instances" a constant
+ AtomicInteger assemblyReferencePosition = new AtomicInteger();
+ AtomicInteger assemblyInlineDefinitionPosition = new AtomicInteger();
+ AtomicInteger fieldReferencePosition = new AtomicInteger();
+ AtomicInteger fieldInlineDefinitionPosition = new AtomicInteger();
+ AtomicInteger choicePosition = new AtomicInteger();
+ AtomicInteger choiceGroupPosition = new AtomicInteger();
+
IBoundInstanceModelChoiceGroup instance = ObjectUtils.requireNonNull(
- modelInstance.getDefinition().getChoiceGroupInstanceByName("instances"));
- for (Object obj : ObjectUtils.notNull(model.getInstances())) {
+ modelInstance.getDefinition()
+ .getChoiceGroupInstanceByName(BindingConstants.METASCHEMA_CHOICE_GROUP_GROUP_AS_NAME));
+ ObjectUtils.notNull(model.getInstances()).forEach(obj -> {
assert obj != null;
IBoundInstanceModelGroupedAssembly objInstance
@@ -132,14 +137,14 @@ protected AssemblyModelContainerSupport(
IAssemblyInstanceAbsolute assembly = newInstance(
(AssemblyReference) obj,
objInstance,
- assemblyReferencePosition++,
+ assemblyReferencePosition.getAndIncrement(),
parent);
addInstance(assembly, modelInstances, namedModelInstances, assemblyInstances);
} else if (obj instanceof InlineDefineAssembly) {
IAssemblyInstanceAbsolute assembly = new InstanceModelAssemblyInline(
(InlineDefineAssembly) obj,
objInstance,
- assemblyInlineDefinitionPosition++,
+ assemblyInlineDefinitionPosition.getAndIncrement(),
parent,
nodeItemFactory);
addInstance(assembly, modelInstances, namedModelInstances, assemblyInstances);
@@ -147,38 +152,36 @@ protected AssemblyModelContainerSupport(
IFieldInstanceAbsolute field = newInstance(
(FieldReference) obj,
objInstance,
- fieldReferencePosition++,
+ fieldReferencePosition.getAndIncrement(),
parent);
addInstance(field, modelInstances, namedModelInstances, fieldInstances);
} else if (obj instanceof InlineDefineField) {
IFieldInstanceAbsolute field = new InstanceModelFieldInline(
(InlineDefineField) obj,
objInstance,
- fieldInlineDefinitionPosition++,
+ fieldInlineDefinitionPosition.getAndIncrement(),
parent);
addInstance(field, modelInstances, namedModelInstances, fieldInstances);
} else if (obj instanceof AssemblyModel.Choice) {
IChoiceInstance choice = new InstanceModelChoice(
(Choice) obj,
objInstance,
- choicePosition++,
+ choicePosition.getAndIncrement(),
parent,
nodeItemFactory);
- modelInstances.add(choice);
- choiceInstances.add(choice);
+ addInstance(choice, modelInstances, choiceInstances);
} else if (obj instanceof AssemblyModel.ChoiceGroup) {
IChoiceGroupInstance choiceGroup = new InstanceModelChoiceGroup(
(ChoiceGroup) obj,
objInstance,
- choiceGroupPosition++,
+ choiceGroupPosition.getAndIncrement(),
parent,
nodeItemFactory);
- modelInstances.add(choiceGroup);
- choiceGroupInstances.put(choiceGroup.getGroupAsName(), choiceGroup);
+ addInstance(choiceGroup, modelInstances, choiceGroupInstances);
} else {
throw new UnsupportedOperationException(String.format("Unknown model instance class: %s", obj.getClass()));
}
- }
+ });
this.modelInstances = modelInstances.isEmpty()
? CollectionUtil.emptyList()
diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/BindingConstants.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/BindingConstants.java
index 8d257fdaf..7442e8991 100644
--- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/BindingConstants.java
+++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/BindingConstants.java
@@ -13,6 +13,7 @@ public final class BindingConstants {
public static final String METASCHEMA_FIELD_INLINE_DEFINTION_NAME = "define-field";
public static final String METASCHEMA_CHOICE_NAME = "choice";
public static final String METASCHEMA_CHOICE_GROUP_NAME = "choice-group";
+ public static final String METASCHEMA_CHOICE_GROUP_GROUP_AS_NAME = "instances";
private BindingConstants() {
// disable construction
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 ed3baa834..47ccfe812 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,6 +26,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
import javax.xml.namespace.QName;
@@ -91,31 +92,35 @@ public ChoiceModelContainerSupport(
final Map assemblyInstances = new LinkedHashMap<>();
// create counters to track child positions
- int assemblyReferencePosition = 0;
- int assemblyInlineDefinitionPosition = 0;
- int fieldReferencePosition = 0;
- int fieldInlineDefinitionPosition = 0;
+ AtomicInteger assemblyReferencePosition = new AtomicInteger();
+ AtomicInteger assemblyInlineDefinitionPosition = new AtomicInteger();
+ AtomicInteger fieldReferencePosition = new AtomicInteger();
+ AtomicInteger fieldInlineDefinitionPosition = new AtomicInteger();
// TODO: make "instances" a constant
IBoundInstanceModelChoiceGroup instance = ObjectUtils.requireNonNull(
bindingInstance.getDefinition().getChoiceGroupInstanceByName("choices"));
- for (Object obj : ObjectUtils.notNull(binding.getChoices())) {
+
+ ObjectUtils.notNull(binding.getChoices()).forEach(obj -> {
assert obj != null;
IBoundInstanceModelGroupedAssembly objInstance
= (IBoundInstanceModelGroupedAssembly) instance.getItemInstance(obj);
if (obj instanceof AssemblyReference) {
- IAssemblyInstanceAbsolute assembly = newInstance(
- (AssemblyReference) obj,
- objInstance,
- assemblyReferencePosition++,
- parent);
- addInstance(assembly, modelInstances, namedModelInstances, assemblyInstances);
+ addInstance(
+ newInstance(
+ (AssemblyReference) obj,
+ objInstance,
+ assemblyReferencePosition.getAndIncrement(),
+ parent),
+ modelInstances,
+ namedModelInstances,
+ assemblyInstances);
} else if (obj instanceof InlineDefineAssembly) {
IAssemblyInstanceAbsolute assembly = new InstanceModelAssemblyInline(
(InlineDefineAssembly) obj,
objInstance,
- assemblyInlineDefinitionPosition++,
+ assemblyInlineDefinitionPosition.getAndIncrement(),
parent,
nodeItemFactory);
addInstance(assembly, modelInstances, namedModelInstances, assemblyInstances);
@@ -123,20 +128,20 @@ public ChoiceModelContainerSupport(
IFieldInstanceAbsolute field = newInstance(
(FieldReference) obj,
objInstance,
- fieldReferencePosition++,
+ fieldReferencePosition.getAndIncrement(),
parent);
addInstance(field, modelInstances, namedModelInstances, fieldInstances);
} else if (obj instanceof InlineDefineField) {
IFieldInstanceAbsolute field = new InstanceModelFieldInline(
(InlineDefineField) obj,
objInstance,
- fieldInlineDefinitionPosition++,
+ fieldInlineDefinitionPosition.getAndIncrement(),
parent);
addInstance(field, modelInstances, namedModelInstances, fieldInstances);
} else {
throw new UnsupportedOperationException(String.format("Unknown model instance class: %s", obj.getClass()));
}
- }
+ });
this.modelInstances = modelInstances.isEmpty()
? CollectionUtil.emptyList()
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 775383e94..eb26ca01f 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
@@ -150,7 +150,7 @@ public IModelConstrained getConstraintSupport() {
@Override
public IAssemblyNodeItem getSourceNodeItem() {
- return boundNodeItem.get();
+ return ObjectUtils.notNull(boundNodeItem.get());
}
@Override
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 322e80d9b..4fd235277 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
@@ -114,7 +114,7 @@ public Object getDefaultValue() {
@Override
public IAssemblyNodeItem getSourceNodeItem() {
- return boundNodeItem.get();
+ return ObjectUtils.notNull(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 6ef747f97..1e39ef713 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
@@ -148,6 +148,6 @@ public MarkupMultiline getRemarks() {
@NonNull
public INodeItem getNodeItem() {
- return boundNodeItem.get();
+ return ObjectUtils.notNull(boundNodeItem.get());
}
}
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 7d74be671..1762c1989 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
@@ -96,7 +96,7 @@ public IValueConstrained getConstraintSupport() {
@Override
public IAssemblyNodeItem getSourceNodeItem() {
- return boundNodeItem.get();
+ return ObjectUtils.notNull(boundNodeItem.get());
}
@Override
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 503c8724b..17a8726e1 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
@@ -72,7 +72,7 @@ public IBindingMetaschemaModule getContainingModule() {
@Override
public IAssemblyNodeItem getSourceNodeItem() {
- return boundNodeItem.get();
+ return ObjectUtils.notNull(boundNodeItem.get());
}
@Override
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 20302e8a6..6fb4458c9 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
@@ -158,13 +158,12 @@ public IGroupAs getGroupAs() {
@Override
public IAssemblyNodeItem getSourceNodeItem() {
- return boundNodeItem.get();
+ return ObjectUtils.notNull(boundNodeItem.get());
}
- @SuppressWarnings("null")
@Override
public IContainerFlagSupport getFlagContainer() {
- return flagContainer.get();
+ return ObjectUtils.notNull(flagContainer.get());
}
@Override
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 6c78f3c91..3d4f748b1 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
@@ -106,7 +106,7 @@ public IGroupAs getGroupAs() {
@Override
public IAssemblyNodeItem getSourceNodeItem() {
- return boundNodeItem.get();
+ return ObjectUtils.notNull(boundNodeItem.get());
}
// ---------------------------------------
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 237bc22d1..9895d90c2 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
@@ -17,7 +17,6 @@
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.binding.metaschema.AssemblyModel;
import gov.nist.secauto.metaschema.databind.model.binding.metaschema.AssemblyModel.Choice;
import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingDefinitionModelAssembly;
import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstance;
@@ -35,8 +34,6 @@ public class InstanceModelChoice
IAssemblyInstanceAbsolute>
implements IBindingInstance {
@NonNull
- private final AssemblyModel.Choice binding;
- @NonNull
private final Lazy ChoiceModelContainerSupport.of(
binding,
bindingInstance,
@@ -64,11 +60,6 @@ public InstanceModelChoice(
.get(position)));
}
- @NonNull
- protected AssemblyModel.Choice getBinding() {
- return binding;
- }
-
@Override
public IBindingMetaschemaModule getContainingModule() {
return getContainingDefinition().getContainingModule();
@@ -85,7 +76,7 @@ IAssemblyInstanceAbsolute> getModelContainer() {
@Override
public IAssemblyNodeItem getSourceNodeItem() {
- return boundNodeItem.get();
+ return ObjectUtils.notNull(boundNodeItem.get());
}
@Override
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 471ee20d2..ba0cdb768 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
@@ -68,7 +68,7 @@ public InstanceModelChoiceGroup(
}
@NonNull
- protected AssemblyModel.ChoiceGroup getBinding() {
+ private AssemblyModel.ChoiceGroup getBinding() {
return binding;
}
@@ -93,7 +93,7 @@ public IGroupAs getGroupAs() {
@Override
public IAssemblyNodeItem getSourceNodeItem() {
- return boundNodeItem.get();
+ return ObjectUtils.notNull(boundNodeItem.get());
}
// ---------------------------------------
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 e0213d68d..1b2bf9c5b 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
@@ -103,7 +103,7 @@ public InstanceModelFieldInline(
}
@NonNull
- protected InlineDefineField getBinding() {
+ private InlineDefineField getBinding() {
return binding;
}
@@ -144,7 +144,7 @@ public Object getDefaultValue() {
@Override
public IAssemblyNodeItem getSourceNodeItem() {
- return boundNodeItem.get();
+ return ObjectUtils.notNull(boundNodeItem.get());
}
// ---------------------------------------
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 f5a6cb7c2..afe7c8ffa 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
@@ -74,7 +74,7 @@ public IFieldDefinition getDefinition() {
}
@NonNull
- protected FieldReference getBinding() {
+ private FieldReference getBinding() {
return binding;
}
@@ -95,7 +95,7 @@ public IGroupAs getGroupAs() {
@Override
public IAssemblyNodeItem getSourceNodeItem() {
- return boundNodeItem.get();
+ return ObjectUtils.notNull(boundNodeItem.get());
}
// ---------------------------------------
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 a3a681b40..4e2781bae 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
@@ -111,7 +111,7 @@ public InstanceModelGroupedAssemblyInline(
}
@NonNull
- protected AssemblyModel.ChoiceGroup.DefineAssembly getBinding() {
+ private AssemblyModel.ChoiceGroup.DefineAssembly getBinding() {
return binding;
}
@@ -148,7 +148,7 @@ public IModelConstrained getConstraintSupport() {
@Override
public IAssemblyNodeItem getSourceNodeItem() {
- return boundNodeItem.get();
+ return ObjectUtils.notNull(boundNodeItem.get());
}
// ---------------------------------------
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 15a8f74d7..6b1442884 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
@@ -64,7 +64,7 @@ public IAssemblyDefinition getDefinition() {
}
@NonNull
- protected AssemblyModel.ChoiceGroup.Assembly getBinding() {
+ private AssemblyModel.ChoiceGroup.Assembly getBinding() {
return binding;
}
@@ -80,7 +80,7 @@ public Map> getProperties() {
@Override
public IAssemblyNodeItem getSourceNodeItem() {
- return boundNodeItem.get();
+ return ObjectUtils.notNull(boundNodeItem.get());
}
@Override
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 acd87a65b..bb872723f 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
@@ -93,7 +93,7 @@ public InstanceModelGroupedFieldInline(
}
@NonNull
- protected AssemblyModel.ChoiceGroup.DefineField getBinding() {
+ private AssemblyModel.ChoiceGroup.DefineField getBinding() {
return binding;
}
@@ -119,7 +119,7 @@ public IValueConstrained getConstraintSupport() {
@Override
public IAssemblyNodeItem getSourceNodeItem() {
- return boundNodeItem.get();
+ return ObjectUtils.notNull(boundNodeItem.get());
}
@Override
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 08c68b82b..2b9903acc 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
@@ -64,7 +64,7 @@ public IFieldDefinition getDefinition() {
}
@NonNull
- protected AssemblyModel.ChoiceGroup.Field getBinding() {
+ private AssemblyModel.ChoiceGroup.Field getBinding() {
return binding;
}
@@ -80,7 +80,7 @@ public Map> getProperties() {
@Override
public IAssemblyNodeItem getSourceNodeItem() {
- return boundNodeItem.get();
+ return ObjectUtils.notNull(boundNodeItem.get());
}
@Override
diff --git a/metaschema-cli/pom.xml b/metaschema-cli/pom.xml
index 2c7a9286c..cd71d3fcc 100644
--- a/metaschema-cli/pom.xml
+++ b/metaschema-cli/pom.xml
@@ -44,16 +44,6 @@
${project.groupId}metaschema-databind-modules
-
-
- com.github.spotbugs
- spotbugs-annotations
- org.apache.logging.log4j
@@ -66,8 +56,7 @@
io.github.hakky54
- consolecaptor
- 1.0.3
+ logcaptortest
diff --git a/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/CLI.java b/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/CLI.java
index 0c57fb0a0..542b654d5 100644
--- a/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/CLI.java
+++ b/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/CLI.java
@@ -19,6 +19,9 @@
import edu.umd.cs.findbugs.annotations.NonNull;
+/**
+ * The main entry point for the CLI application.
+ */
@SuppressWarnings("PMD.ShortClassName")
public final class CLI {
/**
@@ -42,7 +45,7 @@ public static void main(String[] args) {
public static ExitStatus runCli(String... args) {
System.setProperty("java.util.logging.manager", "org.apache.logging.log4j.jul.LogManager");
- Map versions = new LinkedHashMap<>();
+ @SuppressWarnings("PMD.UseConcurrentHashMap") Map versions = new LinkedHashMap<>();
versions.put(CLIProcessor.COMMAND_VERSION, new MetaschemaJavaVersion());
versions.put(MetaschemaConstants.METASCHEMA_NAMESPACE, new MetaschemaVersion());
diff --git a/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/commands/AbstractConvertSubcommand.java b/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/commands/AbstractConvertSubcommand.java
index 2e435e588..5921f4d74 100644
--- a/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/commands/AbstractConvertSubcommand.java
+++ b/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/commands/AbstractConvertSubcommand.java
@@ -7,18 +7,13 @@
import gov.nist.secauto.metaschema.cli.processor.CLIProcessor.CallingContext;
import gov.nist.secauto.metaschema.cli.processor.ExitCode;
-import gov.nist.secauto.metaschema.cli.processor.ExitStatus;
-import gov.nist.secauto.metaschema.cli.processor.InvalidArgumentException;
-import gov.nist.secauto.metaschema.cli.processor.OptionUtils;
import gov.nist.secauto.metaschema.cli.processor.command.AbstractCommandExecutor;
import gov.nist.secauto.metaschema.cli.processor.command.AbstractTerminalCommand;
+import gov.nist.secauto.metaschema.cli.processor.command.CommandExecutionException;
import gov.nist.secauto.metaschema.cli.processor.command.DefaultExtraArgument;
import gov.nist.secauto.metaschema.cli.processor.command.ExtraArgument;
-import gov.nist.secauto.metaschema.core.model.MetaschemaException;
import gov.nist.secauto.metaschema.core.util.AutoCloser;
-import gov.nist.secauto.metaschema.core.util.CustomCollectors;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
-import gov.nist.secauto.metaschema.core.util.UriUtils;
import gov.nist.secauto.metaschema.databind.IBindingContext;
import gov.nist.secauto.metaschema.databind.io.Format;
import gov.nist.secauto.metaschema.databind.io.IBoundLoader;
@@ -33,20 +28,17 @@
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.net.URI;
-import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
-import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.Collection;
import java.util.List;
-import java.util.Locale;
import edu.umd.cs.findbugs.annotations.NonNull;
/**
- * Used by implementing classes to declare a content conversion command.
+ * Used by implementing classes to provide a content conversion command.
*/
public abstract class AbstractConvertSubcommand
extends AbstractTerminalCommand {
@@ -59,21 +51,6 @@ public abstract class AbstractConvertSubcommand
new DefaultExtraArgument("source-file-or-URL", true),
new DefaultExtraArgument("destination-file", false)));
- @NonNull
- private static final Option OVERWRITE_OPTION = ObjectUtils.notNull(
- Option.builder()
- .longOpt("overwrite")
- .desc("overwrite the destination if it exists")
- .build());
- @NonNull
- private static final Option TO_OPTION = ObjectUtils.notNull(
- Option.builder()
- .longOpt("to")
- .required()
- .hasArg().argName("FORMAT")
- .desc("convert to format: xml, json, or yaml")
- .build());
-
@Override
public String getName() {
return COMMAND;
@@ -82,8 +59,8 @@ public String getName() {
@Override
public Collection extends Option> gatherOptions() {
return ObjectUtils.notNull(List.of(
- OVERWRITE_OPTION,
- TO_OPTION));
+ MetaschemaCommands.OVERWRITE_OPTION,
+ MetaschemaCommands.TO_OPTION));
}
@Override
@@ -91,30 +68,6 @@ public List getExtraArguments() {
return EXTRA_ARGUMENTS;
}
- @SuppressWarnings("PMD.PreserveStackTrace") // intended
- @Override
- public void validateOptions(CallingContext callingContext, CommandLine cmdLine) throws InvalidArgumentException {
-
- try {
- String toFormatText = cmdLine.getOptionValue(TO_OPTION);
- Format.valueOf(toFormatText.toUpperCase(Locale.ROOT));
- } catch (IllegalArgumentException ex) {
- InvalidArgumentException newEx = new InvalidArgumentException(
- String.format("Invalid '%s' argument. The format must be one of: %s.",
- OptionUtils.toArgument(TO_OPTION),
- Format.names().stream()
- .collect(CustomCollectors.joiningWithOxfordComma("and"))));
- newEx.setOption(TO_OPTION);
- newEx.addSuppressed(ex);
- throw newEx;
- }
-
- List extraArgs = cmdLine.getArgList();
- if (extraArgs.isEmpty() || extraArgs.size() > 2) {
- throw new InvalidArgumentException("Illegal number of arguments.");
- }
- }
-
/**
* Used by implementing classes to provide for execution of a conversion
* command.
@@ -140,77 +93,35 @@ protected AbstractConversionCommandExecutor(
* Get the binding context to use for data processing.
*
* @return the context
- * @throws MetaschemaException
- * if a Metaschema error occurred
- * @throws IOException
- * if an error occurred while reading data
+ * @throws CommandExecutionException
+ * if an error occurred getting the binding context
*/
@NonNull
- protected abstract IBindingContext getBindingContext() throws MetaschemaException, IOException;
+ protected abstract IBindingContext getBindingContext() throws CommandExecutionException;
@SuppressWarnings({
"PMD.OnlyOneReturn", // readability
"PMD.CyclomaticComplexity", "PMD.CognitiveComplexity" // reasonable
})
@Override
- public ExitStatus execute() {
+ public void execute() throws CommandExecutionException {
CommandLine cmdLine = getCommandLine();
List extraArgs = cmdLine.getArgList();
Path destination = null;
if (extraArgs.size() > 1) {
- destination = Paths.get(extraArgs.get(1)).toAbsolutePath();
+ destination = MetaschemaCommands.handleDestination(ObjectUtils.requireNonNull(extraArgs.get(1)), cmdLine);
}
- if (destination != null) {
- if (Files.exists(destination)) {
- if (!cmdLine.hasOption(OVERWRITE_OPTION)) {
- return ExitCode.INVALID_ARGUMENTS.exitMessage(
- String.format("The provided destination '%s' already exists and the '%s' option was not provided.",
- destination,
- OptionUtils.toArgument(OVERWRITE_OPTION)));
- }
- if (!Files.isWritable(destination)) {
- return ExitCode.IO_ERROR.exitMessage(
- "The provided destination '" + destination + "' is not writable.");
- }
- } else {
- Path parent = destination.getParent();
- if (parent != null) {
- try {
- Files.createDirectories(parent);
- } catch (IOException ex) {
- return ExitCode.INVALID_TARGET.exit().withThrowable(ex); // NOPMD readability
- }
- }
- }
- }
+ URI source = MetaschemaCommands.handleSource(
+ ObjectUtils.requireNonNull(extraArgs.get(0)),
+ ObjectUtils.notNull(getCurrentWorkingDirectory().toUri()));
- String sourceName = ObjectUtils.notNull(extraArgs.get(0));
- URI cwd = ObjectUtils.notNull(Paths.get("").toAbsolutePath().toUri());
+ Format toFormat = MetaschemaCommands.getFormat(cmdLine, MetaschemaCommands.TO_OPTION);
- URI source;
- try {
- source = UriUtils.toUri(sourceName, cwd);
- } catch (URISyntaxException ex) {
- return ExitCode.IO_ERROR
- .exitMessage(String.format("Cannot load source '%s' as it is not a valid file or URI.", sourceName))
- .withThrowable(ex);
- }
- assert source != null;
-
- String toFormatText = cmdLine.getOptionValue(TO_OPTION);
- Format toFormat = Format.valueOf(toFormatText.toUpperCase(Locale.ROOT));
+ IBindingContext bindingContext = getBindingContext();
- IBindingContext bindingContext;
- try {
- bindingContext = getBindingContext();
- } catch (IOException | MetaschemaException ex) {
- return ExitCode.PROCESSING_ERROR
- .exitMessage(String.format("Unable to initialize the binding context. %s", ex.getLocalizedMessage()))
- .withThrowable(ex);
- }
try {
IBoundLoader loader = bindingContext.newBoundLoader();
if (LOGGER.isInfoEnabled()) {
@@ -235,12 +146,11 @@ public ExitStatus execute() {
}
}
} catch (IOException | IllegalArgumentException ex) {
- return ExitCode.PROCESSING_ERROR.exit().withThrowable(ex); // NOPMD readability
+ throw new CommandExecutionException(ExitCode.PROCESSING_ERROR, ex);
}
if (destination != null && LOGGER.isInfoEnabled()) {
LOGGER.info("Generated {} file: {}", toFormat.toString(), destination);
}
- return ExitCode.OK.exit();
}
/**
diff --git a/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/commands/AbstractValidateContentCommand.java b/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/commands/AbstractValidateContentCommand.java
index 3829bd66e..f854b42d6 100644
--- a/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/commands/AbstractValidateContentCommand.java
+++ b/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/commands/AbstractValidateContentCommand.java
@@ -8,29 +8,22 @@
import gov.nist.secauto.metaschema.cli.processor.CLIProcessor;
import gov.nist.secauto.metaschema.cli.processor.CLIProcessor.CallingContext;
import gov.nist.secauto.metaschema.cli.processor.ExitCode;
-import gov.nist.secauto.metaschema.cli.processor.ExitStatus;
-import gov.nist.secauto.metaschema.cli.processor.InvalidArgumentException;
-import gov.nist.secauto.metaschema.cli.processor.OptionUtils;
import gov.nist.secauto.metaschema.cli.processor.command.AbstractCommandExecutor;
import gov.nist.secauto.metaschema.cli.processor.command.AbstractTerminalCommand;
+import gov.nist.secauto.metaschema.cli.processor.command.CommandExecutionException;
import gov.nist.secauto.metaschema.cli.processor.command.DefaultExtraArgument;
import gov.nist.secauto.metaschema.cli.processor.command.ExtraArgument;
import gov.nist.secauto.metaschema.cli.util.LoggingValidationHandler;
import gov.nist.secauto.metaschema.core.configuration.DefaultConfiguration;
import gov.nist.secauto.metaschema.core.configuration.IMutableConfiguration;
import gov.nist.secauto.metaschema.core.metapath.MetapathException;
-import gov.nist.secauto.metaschema.core.model.IConstraintLoader;
import gov.nist.secauto.metaschema.core.model.IModule;
-import gov.nist.secauto.metaschema.core.model.MetaschemaException;
import gov.nist.secauto.metaschema.core.model.constraint.IConstraintSet;
import gov.nist.secauto.metaschema.core.model.constraint.ValidationFeature;
import gov.nist.secauto.metaschema.core.model.validation.AggregateValidationResult;
import gov.nist.secauto.metaschema.core.model.validation.IValidationResult;
-import gov.nist.secauto.metaschema.core.util.CollectionUtil;
-import gov.nist.secauto.metaschema.core.util.CustomCollectors;
import gov.nist.secauto.metaschema.core.util.IVersionInfo;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
-import gov.nist.secauto.metaschema.core.util.UriUtils;
import gov.nist.secauto.metaschema.databind.IBindingContext;
import gov.nist.secauto.metaschema.databind.IBindingContext.ISchemaValidationProvider;
import gov.nist.secauto.metaschema.databind.io.Format;
@@ -45,19 +38,19 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URI;
-import java.net.URISyntaxException;
import java.net.UnknownHostException;
import java.nio.file.Path;
import java.nio.file.Paths;
-import java.util.Arrays;
import java.util.Collection;
-import java.util.LinkedHashSet;
import java.util.List;
-import java.util.Locale;
import java.util.Set;
import edu.umd.cs.findbugs.annotations.NonNull;
+import edu.umd.cs.findbugs.annotations.Nullable;
+/**
+ * Used by implementing classes to provide a content validation command.
+ */
public abstract class AbstractValidateContentCommand
extends AbstractTerminalCommand {
private static final Logger LOGGER = LogManager.getLogger(AbstractValidateContentCommand.class);
@@ -68,15 +61,6 @@ public abstract class AbstractValidateContentCommand
new DefaultExtraArgument("file-or-URI-to-validate", true)));
@NonNull
- private static final Option AS_OPTION = ObjectUtils.notNull(
- Option.builder()
- .longOpt("as")
- .hasArg()
- .argName("FORMAT")
- .desc("source format: xml, json, or yaml")
- .numberOfArgs(1)
- .build());
- @NonNull
private static final Option CONSTRAINTS_OPTION = ObjectUtils.notNull(
Option.builder("c")
.hasArgs()
@@ -119,7 +103,7 @@ public String getName() {
@Override
public Collection extends Option> gatherOptions() {
return List.of(
- AS_OPTION,
+ MetaschemaCommands.AS_FORMAT_OPTION,
CONSTRAINTS_OPTION,
SARIF_OUTPUT_FILE_OPTION,
SARIF_INCLUDE_PASS_OPTION,
@@ -132,31 +116,9 @@ public List getExtraArguments() {
return EXTRA_ARGUMENTS;
}
- @SuppressWarnings("PMD.PreserveStackTrace") // intended
- @Override
- public void validateOptions(CallingContext callingContext, CommandLine cmdLine) throws InvalidArgumentException {
- List extraArgs = cmdLine.getArgList();
- if (extraArgs.size() != 1) {
- throw new InvalidArgumentException("The source to validate must be provided.");
- }
-
- if (cmdLine.hasOption(AS_OPTION)) {
- try {
- String toFormatText = cmdLine.getOptionValue(AS_OPTION);
- Format.valueOf(toFormatText.toUpperCase(Locale.ROOT));
- } catch (IllegalArgumentException ex) {
- InvalidArgumentException newEx = new InvalidArgumentException(
- String.format("Invalid '%s' argument. The format must be one of: %s.",
- OptionUtils.toArgument(AS_OPTION),
- Arrays.asList(Format.values()).stream()
- .map(Enum::name)
- .collect(CustomCollectors.joiningWithOxfordComma("and"))));
- newEx.addSuppressed(ex);
- throw newEx;
- }
- }
- }
-
+ /**
+ * Drives the validation execution.
+ */
protected abstract class AbstractValidationCommandExecutor
extends AbstractCommandExecutor {
@@ -180,124 +142,127 @@ public AbstractValidationCommandExecutor(
* @param constraintSets
* the constraints to configure in the resulting binding context
* @return the context
- * @throws MetaschemaException
- * if a Metaschema error occurred
- * @throws IOException
- * if an error occurred while reading data
+ * @throws CommandExecutionException
+ * if a error occurred while getting the binding context
*/
@NonNull
protected abstract IBindingContext getBindingContext(@NonNull Set constraintSets)
- throws MetaschemaException, IOException;
+ throws CommandExecutionException;
+ /**
+ * Get the module to use for validation.
+ *
+ * This module is used to generate schemas and as a source of built-in
+ * constraints.
+ *
+ * @param commandLine
+ * the provided command line argument information
+ * @param bindingContext
+ * the context used to access Metaschema module information based on
+ * Java class bindings
+ * @return the loaded Metaschema module
+ * @throws CommandExecutionException
+ * if an error occurred while loading the module
+ */
@NonNull
protected abstract IModule getModule(
@NonNull CommandLine commandLine,
- IBindingContext bindingContext)
- throws IOException, MetaschemaException;
+ @NonNull IBindingContext bindingContext)
+ throws CommandExecutionException;
+ /**
+ * Get the schema validation implementation requested based on the provided
+ * command line arguments.
+ *
+ * It is typical for this call to result in the dynamic generation of a schema
+ * to use for validation.
+ *
+ * @param module
+ * the Metaschema module to generate the schema from
+ * @param commandLine
+ * the provided command line argument information
+ * @param bindingContext
+ * the context used to access Metaschema module information based on
+ * Java class bindings
+ * @return the provider
+ */
@NonNull
protected abstract ISchemaValidationProvider getSchemaValidationProvider(
@NonNull IModule module,
@NonNull CommandLine commandLine,
@NonNull IBindingContext bindingContext);
+ /**
+ * Execute the validation operation.
+ */
@SuppressWarnings("PMD.OnlyOneReturn") // readability
@Override
- public ExitStatus execute() {
- URI cwd = ObjectUtils.notNull(Paths.get("").toAbsolutePath().toUri());
+ public void execute() throws CommandExecutionException {
CommandLine cmdLine = getCommandLine();
+ URI currentWorkingDirectory = ObjectUtils.notNull(getCurrentWorkingDirectory().toUri());
- Set constraintSets;
- if (cmdLine.hasOption(CONSTRAINTS_OPTION)) {
- IConstraintLoader constraintLoader = IBindingContext.getConstraintLoader();
- constraintSets = new LinkedHashSet<>();
- String[] args = cmdLine.getOptionValues(CONSTRAINTS_OPTION);
- for (String arg : args) {
- assert arg != null;
- try {
- URI constraintUri = ObjectUtils.requireNonNull(UriUtils.toUri(arg, cwd));
- constraintSets.addAll(constraintLoader.load(constraintUri));
- } catch (IOException | MetaschemaException | MetapathException | URISyntaxException ex) {
- return ExitCode.IO_ERROR.exitMessage("Unable to load constraint set '" + arg + "'.").withThrowable(ex);
- }
- }
- } else {
- constraintSets = CollectionUtil.emptySet();
- }
+ Set constraintSets = MetaschemaCommands.loadConstraintSets(
+ cmdLine,
+ CONSTRAINTS_OPTION,
+ currentWorkingDirectory);
- IBindingContext bindingContext;
- try {
- bindingContext = getBindingContext(constraintSets);
- } catch (IOException | MetaschemaException ex) {
- return ExitCode.PROCESSING_ERROR
- .exitMessage(String.format("Unable to initialize the binding context. %s", ex.getLocalizedMessage()))
- .withThrowable(ex);
- }
+ List extraArgs = cmdLine.getArgList();
- IBoundLoader loader = bindingContext.newBoundLoader();
+ URI source = MetaschemaCommands.handleSource(
+ ObjectUtils.requireNonNull(extraArgs.get(0)),
+ currentWorkingDirectory);
- List extraArgs = cmdLine.getArgList();
+ IBindingContext bindingContext = getBindingContext(constraintSets);
+ IBoundLoader loader = bindingContext.newBoundLoader();
+ Format asFormat = MetaschemaCommands.determineSourceFormat(
+ cmdLine,
+ MetaschemaCommands.AS_FORMAT_OPTION,
+ loader,
+ source);
- String sourceName = ObjectUtils.requireNonNull(extraArgs.get(0));
- URI source;
+ IValidationResult validationResult = validate(source, asFormat, cmdLine, bindingContext);
+ handleOutput(source, validationResult, cmdLine, bindingContext);
- try {
- source = UriUtils.toUri(sourceName, cwd);
- } catch (URISyntaxException ex) {
- return ExitCode.IO_ERROR.exitMessage("Cannot load source '%s' as it is not a valid file or URI.")
- .withThrowable(ex);
+ if (validationResult == null || validationResult.isPassing()) {
+ if (LOGGER.isInfoEnabled()) {
+ LOGGER.info("The file '{}' is valid.", source);
+ }
+ } else if (LOGGER.isErrorEnabled()) {
+ LOGGER.error("The file '{}' is invalid.", source);
}
- Format asFormat;
- if (cmdLine.hasOption(AS_OPTION)) {
- try {
- String toFormatText = cmdLine.getOptionValue(AS_OPTION);
- asFormat = Format.valueOf(toFormatText.toUpperCase(Locale.ROOT));
- } catch (IllegalArgumentException ex) {
- return ExitCode.IO_ERROR
- .exitMessage("Invalid '--as' argument. The format must be one of: "
- + Arrays.stream(Format.values())
- .map(Enum::name)
- .collect(CustomCollectors.joiningWithOxfordComma("or")))
- .withThrowable(ex);
- }
- } else {
- // attempt to determine the format
- try {
- asFormat = loader.detectFormat(source);
- } catch (FileNotFoundException ex) {
- // this case was already checked for
- return ExitCode.IO_ERROR.exitMessage("The provided source file '" + source + "' does not exist.");
- } catch (IOException ex) {
- return ExitCode.PROCESSING_ERROR.exit().withThrowable(ex);
- } catch (IllegalArgumentException ex) {
- return ExitCode.IO_ERROR.exitMessage(
- "Source file has unrecognizable format. Use '--as' to specify the format. The format must be one of: "
- + Arrays.stream(Format.values())
- .map(Enum::name)
- .collect(CustomCollectors.joiningWithOxfordComma("or")));
- }
+ if (validationResult != null && !validationResult.isPassing()) {
+ throw new CommandExecutionException(ExitCode.FAIL);
}
+ }
+
+ @SuppressWarnings("PMD.CyclomaticComplexity")
+ @Nullable
+ private IValidationResult validate(
+ @NonNull URI source,
+ @NonNull Format asFormat,
+ @NonNull CommandLine commandLine,
+ @NonNull IBindingContext bindingContext) throws CommandExecutionException {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Validating '{}' as {}.", source, asFormat.name());
}
- IMutableConfiguration> configuration = new DefaultConfiguration<>();
- if (cmdLine.hasOption(SARIF_OUTPUT_FILE_OPTION) && cmdLine.hasOption(SARIF_INCLUDE_PASS_OPTION)) {
- configuration.enableFeature(ValidationFeature.VALIDATE_GENERATE_PASS_FINDINGS);
- }
-
IValidationResult validationResult = null;
try {
- if (!cmdLine.hasOption(NO_SCHEMA_VALIDATION_OPTION)) {
- IModule module = getModule(getCommandLine(), bindingContext);
+ IModule module = bindingContext.registerModule(getModule(commandLine, bindingContext));
+ if (!commandLine.hasOption(NO_SCHEMA_VALIDATION_OPTION)) {
// perform schema validation
- validationResult = getSchemaValidationProvider(module, getCommandLine(), bindingContext)
+ validationResult = getSchemaValidationProvider(module, commandLine, bindingContext)
.validateWithSchema(source, asFormat, bindingContext);
}
- if (!cmdLine.hasOption(NO_CONSTRAINT_VALIDATION_OPTION)) {
+ if (!commandLine.hasOption(NO_CONSTRAINT_VALIDATION_OPTION)) {
+ IMutableConfiguration> configuration = new DefaultConfiguration<>();
+ if (commandLine.hasOption(SARIF_OUTPUT_FILE_OPTION) && commandLine.hasOption(SARIF_INCLUDE_PASS_OPTION)) {
+ configuration.enableFeature(ValidationFeature.VALIDATE_GENERATE_PASS_FINDINGS);
+ }
+
// perform constraint validation
IValidationResult constraintValidationResult = bindingContext.validateWithConstraints(source, configuration);
validationResult = validationResult == null
@@ -305,17 +270,30 @@ public ExitStatus execute() {
: AggregateValidationResult.aggregate(validationResult, constraintValidationResult);
}
} catch (FileNotFoundException ex) {
- return ExitCode.IO_ERROR.exitMessage(String.format("Resource not found at '%s'", source)).withThrowable(ex);
+ throw new CommandExecutionException(
+ ExitCode.IO_ERROR,
+ String.format("Resource not found at '%s'", source),
+ ex);
} catch (UnknownHostException ex) {
- return ExitCode.IO_ERROR.exitMessage(String.format("Unknown host for '%s'.", source)).withThrowable(ex);
+ throw new CommandExecutionException(
+ ExitCode.IO_ERROR,
+ String.format("Unknown host for '%s'.", source),
+ ex);
} catch (IOException ex) {
- return ExitCode.IO_ERROR.exit().withThrowable(ex);
- } catch (MetapathException | MetaschemaException ex) {
- return ExitCode.PROCESSING_ERROR.exit().withThrowable(ex);
+ throw new CommandExecutionException(ExitCode.IO_ERROR, ex.getLocalizedMessage(), ex);
+ } catch (MetapathException ex) {
+ throw new CommandExecutionException(ExitCode.PROCESSING_ERROR, ex.getLocalizedMessage(), ex);
}
+ return validationResult;
+ }
- if (cmdLine.hasOption(SARIF_OUTPUT_FILE_OPTION) && LOGGER.isInfoEnabled()) {
- Path sarifFile = ObjectUtils.notNull(Paths.get(cmdLine.getOptionValue(SARIF_OUTPUT_FILE_OPTION)));
+ private void handleOutput(
+ @NonNull URI source,
+ @Nullable IValidationResult validationResult,
+ @NonNull CommandLine commandLine,
+ @NonNull IBindingContext bindingContext) throws CommandExecutionException {
+ if (commandLine.hasOption(SARIF_OUTPUT_FILE_OPTION) && LOGGER.isInfoEnabled()) {
+ Path sarifFile = ObjectUtils.notNull(Paths.get(commandLine.getOptionValue(SARIF_OUTPUT_FILE_OPTION)));
IVersionInfo version
= getCallingContext().getCLIProcessor().getVersionInfos().get(CLIProcessor.COMMAND_VERSION);
@@ -325,24 +303,15 @@ public ExitStatus execute() {
if (validationResult != null) {
sarifHandler.addFindings(validationResult.getFindings());
}
- sarifHandler.write(sarifFile);
+ sarifHandler.write(sarifFile, bindingContext);
} catch (IOException ex) {
- return ExitCode.IO_ERROR.exit().withThrowable(ex);
+ throw new CommandExecutionException(ExitCode.IO_ERROR, ex.getLocalizedMessage(), ex);
}
} else if (validationResult != null && !validationResult.getFindings().isEmpty()) {
LOGGER.info("Validation identified the following issues:");
LoggingValidationHandler.instance().handleResults(validationResult);
}
- if (validationResult == null || validationResult.isPassing()) {
- if (LOGGER.isInfoEnabled()) {
- LOGGER.info("The file '{}' is valid.", source);
- }
- } else if (LOGGER.isErrorEnabled()) {
- LOGGER.error("The file '{}' is invalid.", source);
- }
-
- return (validationResult == null || validationResult.isPassing() ? ExitCode.OK : ExitCode.FAIL).exit();
}
}
}
diff --git a/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/commands/ConvertContentUsingModuleCommand.java b/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/commands/ConvertContentUsingModuleCommand.java
index 59f7f35e9..4b6bdc298 100644
--- a/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/commands/ConvertContentUsingModuleCommand.java
+++ b/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/commands/ConvertContentUsingModuleCommand.java
@@ -6,10 +6,10 @@
package gov.nist.secauto.metaschema.cli.commands;
import gov.nist.secauto.metaschema.cli.processor.CLIProcessor.CallingContext;
+import gov.nist.secauto.metaschema.cli.processor.command.CommandExecutionException;
import gov.nist.secauto.metaschema.cli.processor.command.ICommandExecutor;
import gov.nist.secauto.metaschema.core.model.IBoundObject;
import gov.nist.secauto.metaschema.core.model.IModule;
-import gov.nist.secauto.metaschema.core.model.MetaschemaException;
import gov.nist.secauto.metaschema.core.util.CollectionUtil;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
import gov.nist.secauto.metaschema.databind.IBindingContext;
@@ -28,16 +28,18 @@
import java.io.InputStream;
import java.io.Writer;
import java.net.URI;
-import java.net.URISyntaxException;
import java.net.URL;
-import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import edu.umd.cs.findbugs.annotations.NonNull;
-public class ConvertContentUsingModuleCommand
+/**
+ * This command implementation supports the conversion of a content instance
+ * between supported formats based on a provided Metaschema module.
+ */
+class ConvertContentUsingModuleCommand
extends AbstractConvertSubcommand {
@NonNull
private static final String COMMAND = "convert";
@@ -66,35 +68,27 @@ public Collection extends Option> gatherOptions() {
@Override
public ICommandExecutor newExecutor(CallingContext callingContext, CommandLine commandLine) {
- return new OscalCommandExecutor(callingContext, commandLine);
+ return new CommandExecutor(callingContext, commandLine);
}
- private final class OscalCommandExecutor
+ private final class CommandExecutor
extends AbstractConversionCommandExecutor {
- private OscalCommandExecutor(
+ private CommandExecutor(
@NonNull CallingContext callingContext,
@NonNull CommandLine commandLine) {
super(callingContext, commandLine);
}
@Override
- protected IBindingContext getBindingContext() throws IOException, MetaschemaException {
+ protected IBindingContext getBindingContext() throws CommandExecutionException {
IBindingContext retval = MetaschemaCommands.newBindingContextWithDynamicCompilation();
- URI cwd = ObjectUtils.notNull(Paths.get("").toAbsolutePath().toUri());
-
- IModule module;
- try {
- module = MetaschemaCommands.handleModule(
- getCommandLine(),
- MetaschemaCommands.METASCHEMA_REQUIRED_OPTION,
- cwd,
- retval);
- } catch (URISyntaxException ex) {
- throw new IOException(String.format("Cannot load module as '%s' is not a valid file or URL.", ex.getInput()),
- ex);
- }
+ IModule module = MetaschemaCommands.loadModule(
+ getCommandLine(),
+ MetaschemaCommands.METASCHEMA_REQUIRED_OPTION,
+ ObjectUtils.notNull(getCurrentWorkingDirectory().toUri()),
+ retval);
retval.registerModule(module);
return retval;
}
diff --git a/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/commands/GenerateDiagramCommand.java b/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/commands/GenerateDiagramCommand.java
index 2db03846d..513265be8 100644
--- a/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/commands/GenerateDiagramCommand.java
+++ b/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/commands/GenerateDiagramCommand.java
@@ -7,18 +7,14 @@
import gov.nist.secauto.metaschema.cli.processor.CLIProcessor.CallingContext;
import gov.nist.secauto.metaschema.cli.processor.ExitCode;
-import gov.nist.secauto.metaschema.cli.processor.ExitStatus;
-import gov.nist.secauto.metaschema.cli.processor.InvalidArgumentException;
-import gov.nist.secauto.metaschema.cli.processor.OptionUtils;
import gov.nist.secauto.metaschema.cli.processor.command.AbstractTerminalCommand;
+import gov.nist.secauto.metaschema.cli.processor.command.CommandExecutionException;
import gov.nist.secauto.metaschema.cli.processor.command.DefaultExtraArgument;
import gov.nist.secauto.metaschema.cli.processor.command.ExtraArgument;
import gov.nist.secauto.metaschema.cli.processor.command.ICommandExecutor;
import gov.nist.secauto.metaschema.core.model.IModule;
-import gov.nist.secauto.metaschema.core.model.MetaschemaException;
import gov.nist.secauto.metaschema.core.model.util.MermaidErDiagramGenerator;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
-import gov.nist.secauto.metaschema.core.util.UriUtils;
import gov.nist.secauto.metaschema.databind.IBindingContext;
import org.apache.commons.cli.CommandLine;
@@ -35,7 +31,6 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
-import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.Collection;
import java.util.List;
@@ -43,7 +38,11 @@
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
-public class GenerateDiagramCommand
+/**
+ * This command implementation supports generation of a diagram depicting the
+ * objects and relationships within a provided Metaschema module.
+ */
+class GenerateDiagramCommand
extends AbstractTerminalCommand {
private static final Logger LOGGER = LogManager.getLogger(GenerateDiagramCommand.class);
@@ -71,8 +70,7 @@ public String getDescription() {
@SuppressWarnings("null")
@Override
public Collection extends Option> gatherOptions() {
- return List.of(
- MetaschemaCommands.OVERWRITE_OPTION);
+ return List.of(MetaschemaCommands.OVERWRITE_OPTION);
}
@Override
@@ -80,14 +78,6 @@ public List getExtraArguments() {
return EXTRA_ARGUMENTS;
}
- @Override
- public void validateOptions(CallingContext callingContext, CommandLine cmdLine) throws InvalidArgumentException {
- List extraArgs = cmdLine.getArgList();
- if (extraArgs.isEmpty() || extraArgs.size() > 2) {
- throw new InvalidArgumentException("Illegal number of arguments.");
- }
- }
-
@Override
public ICommandExecutor newExecutor(CallingContext callingContext, CommandLine cmdLine) {
return ICommandExecutor.using(callingContext, cmdLine, this::executeCommand);
@@ -100,7 +90,8 @@ public ICommandExecutor newExecutor(CallingContext callingContext, CommandLine c
* information about the calling context
* @param cmdLine
* the parsed command line details
- * @return the execution result
+ * @throws CommandExecutionException
+ * if an error occurred while executing the command
*/
@SuppressWarnings({
"PMD.OnlyOneReturn", // readability
@@ -108,92 +99,55 @@ public ICommandExecutor newExecutor(CallingContext callingContext, CommandLine c
})
@SuppressFBWarnings(value = "REC_CATCH_EXCEPTION",
justification = "Catching generic exception for CLI error handling")
- protected ExitStatus executeCommand(
+ protected void executeCommand(
@NonNull CallingContext callingContext,
- @NonNull CommandLine cmdLine) {
+ @NonNull CommandLine cmdLine) throws CommandExecutionException {
List extraArgs = cmdLine.getArgList();
Path destination = null;
if (extraArgs.size() > 1) {
- destination = Paths.get(extraArgs.get(1)).toAbsolutePath();
+ destination = MetaschemaCommands.handleDestination(ObjectUtils.requireNonNull(extraArgs.get(1)), cmdLine);
}
- if (destination != null) {
- if (Files.exists(destination)) {
- if (!cmdLine.hasOption(MetaschemaCommands.OVERWRITE_OPTION)) {
- return ExitCode.INVALID_ARGUMENTS.exitMessage( // NOPMD readability
- String.format("The provided destination '%s' already exists and the '%s' option was not provided.",
- destination,
- OptionUtils.toArgument(MetaschemaCommands.OVERWRITE_OPTION)));
- }
- if (!Files.isWritable(destination)) {
- return ExitCode.IO_ERROR.exitMessage( // NOPMD readability
- "The provided destination '" + destination + "' is not writable.");
- }
- } else {
- Path parent = destination.getParent();
- if (parent != null) {
- try {
- Files.createDirectories(parent);
- } catch (IOException ex) {
- return ExitCode.INVALID_TARGET.exit().withThrowable(ex); // NOPMD readability
- }
- }
- }
- }
+ IBindingContext bindingContext = MetaschemaCommands.newBindingContextWithDynamicCompilation();
- IBindingContext bindingContext;
+ URI moduleUri;
try {
- bindingContext = MetaschemaCommands.newBindingContextWithDynamicCompilation();
- } catch (IOException ex) {
- return ExitCode.PROCESSING_ERROR
- .exitMessage(String.format("Unable to initialize the binding context. %s", ex.getLocalizedMessage()))
- .withThrowable(ex);
- }
-
- URI cwd = ObjectUtils.notNull(Paths.get("").toAbsolutePath().toUri());
-
- IModule module;
- try {
- URI moduleUri = UriUtils.toUri(ObjectUtils.requireNonNull(extraArgs.get(0)), cwd);
- module = MetaschemaCommands.handleModule(moduleUri, bindingContext);
+ moduleUri = resolveAgainstCWD(ObjectUtils.requireNonNull(extraArgs.get(0)));
} catch (URISyntaxException ex) {
- return ExitCode.INVALID_ARGUMENTS
- .exitMessage(
- String.format("Cannot load module as '%s' is not a valid file or URL.", ex.getInput()))
- .withThrowable(ex);
- } catch (IOException | MetaschemaException ex) {
- return ExitCode.PROCESSING_ERROR.exit().withThrowable(ex);
+ throw new CommandExecutionException(
+ ExitCode.INVALID_ARGUMENTS,
+ String.format("Cannot load module as '%s' is not a valid file or URL. %s",
+ extraArgs.get(0),
+ ex.getLocalizedMessage()),
+ ex);
}
+ IModule module = MetaschemaCommands.loadModule(moduleUri, bindingContext);
- try {
- if (destination == null) {
- Writer stringWriter = new StringWriter();
- try (PrintWriter writer = new PrintWriter(stringWriter)) {
- MermaidErDiagramGenerator.generate(module, writer);
- }
+ if (destination == null) {
+ Writer stringWriter = new StringWriter();
+ try (PrintWriter writer = new PrintWriter(stringWriter)) {
+ MermaidErDiagramGenerator.generate(module, writer);
+ }
- // Print the result
- if (LOGGER.isInfoEnabled()) {
- LOGGER.info(stringWriter.toString());
- }
- } else {
- try (Writer writer = Files.newBufferedWriter(
- destination,
- StandardCharsets.UTF_8,
- StandardOpenOption.CREATE,
- StandardOpenOption.WRITE,
- StandardOpenOption.TRUNCATE_EXISTING)) {
- try (PrintWriter printWriter = new PrintWriter(writer)) {
- MermaidErDiagramGenerator.generate(module, printWriter);
- }
+ // Print the result
+ if (LOGGER.isInfoEnabled()) {
+ LOGGER.info(stringWriter.toString());
+ }
+ } else {
+ try (Writer writer = Files.newBufferedWriter(
+ destination,
+ StandardCharsets.UTF_8,
+ StandardOpenOption.CREATE,
+ StandardOpenOption.WRITE,
+ StandardOpenOption.TRUNCATE_EXISTING)) {
+ try (PrintWriter printWriter = new PrintWriter(writer)) {
+ MermaidErDiagramGenerator.generate(module, printWriter);
}
+ } catch (IOException ex) {
+ throw new CommandExecutionException(ExitCode.IO_ERROR, ex);
}
-
- return ExitCode.OK.exit();
- } catch (Exception ex) {
- return ExitCode.PROCESSING_ERROR.exit().withThrowable(ex);
}
}
}
diff --git a/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/commands/GenerateSchemaCommand.java b/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/commands/GenerateSchemaCommand.java
index 31bea72c7..ba91e4b69 100644
--- a/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/commands/GenerateSchemaCommand.java
+++ b/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/commands/GenerateSchemaCommand.java
@@ -7,23 +7,17 @@
import gov.nist.secauto.metaschema.cli.processor.CLIProcessor.CallingContext;
import gov.nist.secauto.metaschema.cli.processor.ExitCode;
-import gov.nist.secauto.metaschema.cli.processor.ExitStatus;
-import gov.nist.secauto.metaschema.cli.processor.InvalidArgumentException;
-import gov.nist.secauto.metaschema.cli.processor.OptionUtils;
import gov.nist.secauto.metaschema.cli.processor.command.AbstractTerminalCommand;
+import gov.nist.secauto.metaschema.cli.processor.command.CommandExecutionException;
import gov.nist.secauto.metaschema.cli.processor.command.DefaultExtraArgument;
import gov.nist.secauto.metaschema.cli.processor.command.ExtraArgument;
import gov.nist.secauto.metaschema.cli.processor.command.ICommandExecutor;
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.model.xml.ModuleLoader;
import gov.nist.secauto.metaschema.core.util.AutoCloser;
-import gov.nist.secauto.metaschema.core.util.CustomCollectors;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
-import gov.nist.secauto.metaschema.core.util.UriUtils;
-import gov.nist.secauto.metaschema.databind.io.Format;
+import gov.nist.secauto.metaschema.databind.IBindingContext;
import gov.nist.secauto.metaschema.schemagen.ISchemaGenerator;
import gov.nist.secauto.metaschema.schemagen.ISchemaGenerator.SchemaFormat;
import gov.nist.secauto.metaschema.schemagen.SchemaGenerationFeature;
@@ -36,50 +30,34 @@
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
-import java.net.URI;
-import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.Arrays;
import java.util.Collection;
import java.util.List;
-import java.util.Locale;
import edu.umd.cs.findbugs.annotations.NonNull;
-public class GenerateSchemaCommand
+/**
+ * This command implementation supports generation of schemas in a variety of
+ * formats based on a provided Metaschema module.
+ */
+class GenerateSchemaCommand
extends AbstractTerminalCommand {
private static final Logger LOGGER = LogManager.getLogger(GenerateSchemaCommand.class);
@NonNull
private static final String COMMAND = "generate-schema";
@NonNull
- private static final List EXTRA_ARGUMENTS;
+ private static final List EXTRA_ARGUMENTS = ObjectUtils.notNull(List.of(
+ new DefaultExtraArgument("metaschema-module-file-or-URL", true),
+ new DefaultExtraArgument("destination-schema-file", false)));
- @NonNull
- private static final Option AS_OPTION = ObjectUtils.notNull(
- Option.builder()
- .longOpt("as")
- .required()
- .hasArg()
- .argName("FORMAT")
- .desc("source format: xml, json, or yaml")
- .build());
- @NonNull
private static final Option INLINE_TYPES_OPTION = ObjectUtils.notNull(
Option.builder()
.longOpt("inline-types")
.desc("definitions declared inline will be generated as inline types")
.build());
- static {
- EXTRA_ARGUMENTS = ObjectUtils.notNull(List.of(
- new DefaultExtraArgument("metaschema-module-file-or-URL", true),
- new DefaultExtraArgument("destination-schema-file", false)));
- }
-
@Override
public String getName() {
return COMMAND;
@@ -95,7 +73,7 @@ public String getDescription() {
public Collection extends Option> gatherOptions() {
return List.of(
MetaschemaCommands.OVERWRITE_OPTION,
- AS_OPTION,
+ MetaschemaCommands.AS_SCHEMA_FORMAT_OPTION,
INLINE_TYPES_OPTION);
}
@@ -104,85 +82,37 @@ public List getExtraArguments() {
return EXTRA_ARGUMENTS;
}
- @SuppressWarnings("PMD.PreserveStackTrace") // intended
- @Override
- public void validateOptions(CallingContext callingContext, CommandLine cmdLine) throws InvalidArgumentException {
- try {
- String asFormatText = cmdLine.getOptionValue(AS_OPTION);
- if (asFormatText != null) {
- SchemaFormat.valueOf(asFormatText.toUpperCase(Locale.ROOT));
- }
- } catch (IllegalArgumentException ex) {
- InvalidArgumentException newEx = new InvalidArgumentException( // NOPMD - intentional
- String.format("Invalid '%s' argument. The format must be one of: %s.",
- OptionUtils.toArgument(AS_OPTION),
- Arrays.asList(Format.values()).stream()
- .map(Enum::name)
- .collect(CustomCollectors.joiningWithOxfordComma("and"))));
- newEx.setOption(AS_OPTION);
- newEx.addSuppressed(ex);
- throw newEx;
- }
-
- List extraArgs = cmdLine.getArgList();
- if (extraArgs.isEmpty() || extraArgs.size() > 2) {
- throw new InvalidArgumentException("Illegal number of arguments.");
- }
- }
-
@Override
public ICommandExecutor newExecutor(CallingContext callingContext, CommandLine cmdLine) {
return ICommandExecutor.using(callingContext, cmdLine, this::executeCommand);
}
/**
- * Called to execute the schema generation.
+ * Execute the schema generation operation.
*
* @param callingContext
* the context information for the execution
* @param cmdLine
* the parsed command line details
- * @return the execution result
+ * @throws CommandExecutionException
+ * if an error occurred while determining the source format
*/
@SuppressWarnings({
- "PMD.OnlyOneReturn" // readability
+ "PMD.OnlyOneReturn", // readability
+ "PMD.CyclomaticComplexity"
})
- protected ExitStatus executeCommand(
+ protected void executeCommand(
@NonNull CallingContext callingContext,
- @NonNull CommandLine cmdLine) {
+ @NonNull CommandLine cmdLine) throws CommandExecutionException {
List extraArgs = cmdLine.getArgList();
- Path destination = null;
- if (extraArgs.size() > 1) {
- destination = Paths.get(extraArgs.get(1)).toAbsolutePath();
- }
-
- if (destination != null) {
- if (Files.exists(destination)) {
- if (!cmdLine.hasOption(MetaschemaCommands.OVERWRITE_OPTION)) {
- return ExitCode.INVALID_ARGUMENTS.exitMessage( // NOPMD readability
- String.format("The provided destination '%s' already exists and the '%s' option was not provided.",
- destination,
- OptionUtils.toArgument(MetaschemaCommands.OVERWRITE_OPTION)));
- }
- if (!Files.isWritable(destination)) {
- return ExitCode.IO_ERROR.exitMessage( // NOPMD readability
- "The provided destination '" + destination + "' is not writable.");
- }
- } else {
- Path parent = destination.getParent();
- if (parent != null) {
- try {
- Files.createDirectories(parent);
- } catch (IOException ex) {
- return ExitCode.INVALID_TARGET.exit().withThrowable(ex); // NOPMD readability
- }
- }
- }
- }
+ Path destination = extraArgs.size() > 1
+ ? MetaschemaCommands.handleDestination(
+ ObjectUtils.requireNonNull(extraArgs.get(1)),
+ cmdLine)
+ : null;
- String asFormatText = cmdLine.getOptionValue(AS_OPTION);
- SchemaFormat asFormat = SchemaFormat.valueOf(asFormatText.toUpperCase(Locale.ROOT));
+ SchemaFormat asFormat = MetaschemaCommands.getSchemaFormat(cmdLine, MetaschemaCommands.AS_SCHEMA_FORMAT_OPTION);
IMutableConfiguration> configuration = new DefaultConfiguration<>();
if (cmdLine.hasOption(INLINE_TYPES_OPTION)) {
@@ -194,24 +124,16 @@ protected ExitStatus executeCommand(
}
}
- String inputName = ObjectUtils.notNull(extraArgs.get(0));
- URI cwd = ObjectUtils.notNull(Paths.get("").toAbsolutePath().toUri());
+ IBindingContext bindingContext = MetaschemaCommands.newBindingContextWithDynamicCompilation();
+ IModule module = MetaschemaCommands.loadModule(
+ ObjectUtils.requireNonNull(extraArgs.get(0)),
+ ObjectUtils.notNull(getCurrentWorkingDirectory().toUri()),
+ bindingContext);
+ bindingContext.registerModule(module);
- URI input;
try {
- input = UriUtils.toUri(inputName, cwd);
- } catch (URISyntaxException ex) {
- return ExitCode.IO_ERROR.exitMessage(
- String.format("Unable to load '%s' as it is not a valid file or URI.", inputName)).withThrowable(ex);
- }
- assert input != null;
- try {
- ModuleLoader loader = new ModuleLoader();
- loader.allowEntityResolution();
- IModule module = loader.load(input);
-
if (LOGGER.isInfoEnabled()) {
- LOGGER.info("Generating {} schema for '{}'.", asFormat.name(), input);
+ LOGGER.info("Generating {} schema for '{}'.", asFormat.name(), extraArgs.get(0));
}
if (destination == null) {
@SuppressWarnings({ "resource", "PMD.CloseResource" }) // not owned
@@ -225,12 +147,11 @@ protected ExitStatus executeCommand(
} else {
ISchemaGenerator.generateSchema(module, destination, asFormat, configuration);
}
- } catch (IOException | MetaschemaException ex) {
- return ExitCode.PROCESSING_ERROR.exit().withThrowable(ex); // NOPMD readability
+ } catch (IOException ex) {
+ throw new CommandExecutionException(ExitCode.PROCESSING_ERROR, ex);
}
if (destination != null && LOGGER.isInfoEnabled()) {
LOGGER.info("Generated {} schema file: {}", asFormat.toString(), destination);
}
- return ExitCode.OK.exit();
}
}
diff --git a/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/commands/MetaschemaCommands.java b/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/commands/MetaschemaCommands.java
index 881bae0a9..f009ecf59 100644
--- a/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/commands/MetaschemaCommands.java
+++ b/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/commands/MetaschemaCommands.java
@@ -6,30 +6,59 @@
package gov.nist.secauto.metaschema.cli.commands;
import gov.nist.secauto.metaschema.cli.commands.metapath.MetapathCommand;
+import gov.nist.secauto.metaschema.cli.processor.ExitCode;
+import gov.nist.secauto.metaschema.cli.processor.OptionUtils;
+import gov.nist.secauto.metaschema.cli.processor.command.CommandExecutionException;
import gov.nist.secauto.metaschema.cli.processor.command.ICommand;
+import gov.nist.secauto.metaschema.core.metapath.MetapathException;
+import gov.nist.secauto.metaschema.core.model.IConstraintLoader;
import gov.nist.secauto.metaschema.core.model.IModule;
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;
+import gov.nist.secauto.metaschema.core.util.CustomCollectors;
+import gov.nist.secauto.metaschema.core.util.DeleteOnShutdown;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
import gov.nist.secauto.metaschema.core.util.UriUtils;
import gov.nist.secauto.metaschema.databind.IBindingContext;
+import gov.nist.secauto.metaschema.databind.io.Format;
+import gov.nist.secauto.metaschema.databind.io.IBoundLoader;
import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingModuleLoader;
+import gov.nist.secauto.metaschema.schemagen.ISchemaGenerator.SchemaFormat;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.LinkedHashSet;
import java.util.List;
+import java.util.Locale;
import java.util.Set;
import edu.umd.cs.findbugs.annotations.NonNull;
+/**
+ * This class provides a variety of utility methods for processing
+ * Metaschema-related commands.
+ *
+ * These methods handle the errors produced using the
+ * {@link CommandExecutionException}, which will return an exceptional result to
+ * the command line interface (CLI) processor. This approach keeps the command
+ * implementations fairly clean and simple.
+ */
+@SuppressWarnings("PMD.GodClass")
public final class MetaschemaCommands {
+ /**
+ * A list of the Metaschema-related command pathways, for reuse in this and
+ * other CLI applications.
+ */
@NonNull
public static final List COMMANDS = ObjectUtils.notNull(List.of(
new ValidateModuleCommand(),
@@ -39,6 +68,11 @@ public final class MetaschemaCommands {
new ConvertContentUsingModuleCommand(),
new MetapathCommand()));
+ /**
+ * Used by commands to declare a required Metaschema module for processing.
+ *
+ * @since 2.0.0
+ */
@NonNull
public static final Option METASCHEMA_REQUIRED_OPTION = ObjectUtils.notNull(
Option.builder("m")
@@ -46,75 +80,539 @@ public final class MetaschemaCommands {
.argName("FILE_OR_URL")
.required()
.desc("metaschema resource")
+ .numberOfArgs(1)
.build());
+ /**
+ * Used by commands to declare an optional Metaschema module for processing.
+ *
+ * @since 2.0.0
+ */
@NonNull
public static final Option METASCHEMA_OPTIONAL_OPTION = ObjectUtils.notNull(
Option.builder("m")
.hasArg()
.argName("FILE_OR_URL")
- .required()
.desc("metaschema resource")
+ .numberOfArgs(1)
.build());
+ /**
+ * Used by commands to protect existing files from being overwritten, unless
+ * this option is provided.
+ */
@NonNull
public static final Option OVERWRITE_OPTION = ObjectUtils.notNull(
Option.builder()
.longOpt("overwrite")
.desc("overwrite the destination if it exists")
.build());
+ /**
+ * Used by commands to identify the target format for a content conversion
+ * operation.
+ *
+ * @since 2.0.0
+ */
+ @NonNull
+ public static final Option TO_OPTION = ObjectUtils.notNull(
+ Option.builder()
+ .longOpt("to")
+ .required()
+ .hasArg().argName("FORMAT")
+ .desc("convert to format: " + Arrays.stream(Format.values())
+ .map(Enum::name)
+ .collect(CustomCollectors.joiningWithOxfordComma("or")))
+ .numberOfArgs(1)
+ .build());
+ /**
+ * Used by commands to identify the source format for a content-related
+ * operation.
+ *
+ * @since 2.0.0
+ */
+ @NonNull
+ public static final Option AS_FORMAT_OPTION = ObjectUtils.notNull(
+ Option.builder()
+ .longOpt("as")
+ .hasArg()
+ .argName("FORMAT")
+ .desc("source format: " + Arrays.stream(Format.values())
+ .map(Enum::name)
+ .collect(CustomCollectors.joiningWithOxfordComma("or")))
+ .numberOfArgs(1)
+ .build());
+ /**
+ * Used by commands that produce schemas to identify the schema format to
+ * produce.
+ *
+ * @since 2.0.0
+ */
+ @NonNull
+ public static final Option AS_SCHEMA_FORMAT_OPTION = ObjectUtils.notNull(
+ Option.builder()
+ .longOpt("as")
+ .required()
+ .hasArg()
+ .argName("FORMAT")
+ .desc("schema format: " + Arrays.stream(SchemaFormat.values())
+ .map(Enum::name)
+ .collect(CustomCollectors.joiningWithOxfordComma("or")))
+ .numberOfArgs(1)
+ .build());
+
+ /**
+ * Get the provided source path or URI string as an absolute {@link URI} for the
+ * resource.
+ *
+ * @param pathOrUri
+ * the resource
+ * @param currentWorkingDirectory
+ * the current working directory the URI will be resolved against to
+ * ensure it is absolute
+ * @return the absolute URI for the resource
+ * @throws CommandExecutionException
+ * if the resulting URI is not a well-formed URI
+ * @since 2.0.0
+ */
+ @NonNull
+ public static URI handleSource(
+ @NonNull String pathOrUri,
+ @NonNull URI currentWorkingDirectory) throws CommandExecutionException {
+ try {
+ return getResourceUri(pathOrUri, currentWorkingDirectory);
+ } catch (URISyntaxException ex) {
+ throw new CommandExecutionException(
+ ExitCode.INVALID_ARGUMENTS,
+ String.format(
+ "Cannot load source '%s' as it is not a valid file or URI.",
+ pathOrUri),
+ ex);
+ }
+ }
+
+ /**
+ * Get the provided destination path as an absolute {@link Path} for the
+ * resource.
+ *
+ * This method checks if the path exists and if so, if the overwrite option is
+ * set. The method also ensures that the parent directory is created, if it
+ * doesn't already exist.
+ *
+ * @param path
+ * the resource
+ * @param commandLine
+ * the provided command line argument information
+ * @return the absolute URI for the resource
+ * @throws CommandExecutionException
+ * if the path exists and cannot be overwritten or is not writable
+ * @since 2.0.0
+ */
+ public static Path handleDestination(
+ @NonNull String path,
+ @NonNull CommandLine commandLine) throws CommandExecutionException {
+ Path retval = Paths.get(path).toAbsolutePath();
+
+ if (Files.exists(retval)) {
+ if (!commandLine.hasOption(OVERWRITE_OPTION)) {
+ throw new CommandExecutionException(
+ ExitCode.INVALID_ARGUMENTS,
+ String.format("The provided destination '%s' already exists and the '%s' option was not provided.",
+ retval,
+ OptionUtils.toArgument(OVERWRITE_OPTION)));
+ }
+ if (!Files.isWritable(retval)) {
+ throw new CommandExecutionException(
+ ExitCode.IO_ERROR,
+ String.format(
+ "The provided destination '%s' is not writable.", retval));
+ }
+ } else {
+ Path parent = retval.getParent();
+ if (parent != null) {
+ try {
+ Files.createDirectories(parent);
+ } catch (IOException ex) {
+ throw new CommandExecutionException(
+ ExitCode.INVALID_TARGET,
+ ex);
+ }
+ }
+ }
+ return retval;
+ }
+
+ /**
+ * Parse the command line options to get the selected format.
+ *
+ * @param commandLine
+ * the provided command line argument information
+ * @param option
+ * the option specifying the format, which must be present on the
+ * command line
+ * @return the format
+ * @throws CommandExecutionException
+ * if the format option was not provided or was an invalid choice
+ * @since 2.0.0
+ */
+ @SuppressWarnings("PMD.PreserveStackTrace")
+ @NonNull
+ public static Format getFormat(
+ @NonNull CommandLine commandLine,
+ @NonNull Option option) throws CommandExecutionException {
+ // use the option
+ String toFormatText = commandLine.getOptionValue(option);
+ if (toFormatText == null) {
+ throw new CommandExecutionException(
+ ExitCode.INVALID_ARGUMENTS,
+ String.format("The '%s' argument was not provided.",
+ option.hasLongOpt()
+ ? "--" + option.getLongOpt()
+ : "-" + option.getOpt()));
+ }
+ try {
+ return Format.valueOf(toFormatText.toUpperCase(Locale.ROOT));
+ } catch (IllegalArgumentException ex) {
+ throw new CommandExecutionException(
+ ExitCode.INVALID_ARGUMENTS,
+ String.format("Invalid '%s' argument. The format must be one of: %s.",
+ option.hasLongOpt()
+ ? "--" + option.getLongOpt()
+ : "-" + option.getOpt(),
+ Arrays.stream(Format.values())
+ .map(Enum::name)
+ .collect(CustomCollectors.joiningWithOxfordComma("or"))));
+ }
+ }
+
+ /**
+ * Parse the command line options to get the selected schema format.
+ *
+ * @param commandLine
+ * the provided command line argument information
+ * @param option
+ * the option specifying the format, which must be present on the
+ * command line
+ * @return the format
+ * @throws CommandExecutionException
+ * if the format option was not provided or was an invalid choice
+ * @since 2.0.0
+ */
+ @SuppressWarnings("PMD.PreserveStackTrace")
+ @NonNull
+ public static SchemaFormat getSchemaFormat(
+ @NonNull CommandLine commandLine,
+ @NonNull Option option) throws CommandExecutionException {
+ // use the option
+ String toFormatText = commandLine.getOptionValue(option);
+ if (toFormatText == null) {
+ throw new CommandExecutionException(
+ ExitCode.INVALID_ARGUMENTS,
+ String.format("Option '%s' not provided.",
+ option.hasLongOpt()
+ ? "--" + option.getLongOpt()
+ : "-" + option.getOpt()));
+ }
+ try {
+ return SchemaFormat.valueOf(toFormatText.toUpperCase(Locale.ROOT));
+ } catch (IllegalArgumentException ex) {
+ throw new CommandExecutionException(
+ ExitCode.INVALID_ARGUMENTS,
+ String.format("Invalid '%s' argument. The schema format must be one of: %s.",
+ option.hasLongOpt()
+ ? "--" + option.getLongOpt()
+ : "-" + option.getOpt(),
+ Arrays.stream(SchemaFormat.values())
+ .map(Enum::name)
+ .collect(CustomCollectors.joiningWithOxfordComma("or"))),
+ ex);
+ }
+ }
+ /**
+ * Detect the source format for content identified using the provided option.
+ *
+ * This method will first check if the source format is explicitly declared on
+ * the command line. If so, this format will be returned.
+ *
+ * If not, then the content will be analyzed to determine the format.
+ *
+ * @param commandLine
+ * the provided command line argument information
+ * @param option
+ * the option specifying the format, which must be present on the
+ * command line
+ * @param loader
+ * the content loader to use to load the content instance
+ * @param resource
+ * the resource to load
+ * @return the identified content format
+ * @throws CommandExecutionException
+ * if an error occurred while determining the source format
+ * @since 2.0.0
+ */
+ @SuppressWarnings({ "PMD.PreserveStackTrace", "PMD.OnlyOneReturn" })
@NonNull
- public static IModule handleModule(
+ public static Format determineSourceFormat(
@NonNull CommandLine commandLine,
@NonNull Option option,
- @NonNull URI cwd,
- @NonNull IBindingContext bindingContext) throws URISyntaxException, IOException, MetaschemaException {
- String moduleName = ObjectUtils.requireNonNull(commandLine.getOptionValue(option));
- URI moduleUri = UriUtils.toUri(moduleName, cwd);
- return handleModule(moduleUri, bindingContext);
+ @NonNull IBoundLoader loader,
+ @NonNull URI resource) throws CommandExecutionException {
+ if (commandLine.hasOption(option)) {
+ // use the option
+ return getFormat(commandLine, option);
+ }
+
+ // attempt to determine the format
+ try {
+ return loader.detectFormat(resource);
+ } catch (FileNotFoundException ex) {
+ // this case was already checked for
+ throw new CommandExecutionException(
+ ExitCode.IO_ERROR,
+ String.format("The provided source '%s' does not exist.", resource),
+ ex);
+ } catch (IOException ex) {
+ throw new CommandExecutionException(
+ ExitCode.IO_ERROR,
+ String.format("Unable to determine source format. Use '%s' to specify the format. %s",
+ option.hasLongOpt()
+ ? "--" + option.getLongOpt()
+ : "-" + option.getOpt(),
+ ex.getLocalizedMessage()),
+ ex);
+ }
}
+ /**
+ * Load a Metaschema module based on the provided command line option.
+ *
+ * @param commandLine
+ * the provided command line argument information
+ * @param option
+ * the option specifying the module to load, which must be present on
+ * the command line
+ * @param currentWorkingDirectory
+ * the URI of the current working directory
+ * @param bindingContext
+ * the context used to access Metaschema module information based on
+ * Java class bindings
+ * @return the loaded module
+ * @throws CommandExecutionException
+ * if an error occurred while loading the module
+ * @since 2.0.0
+ */
@NonNull
- public static IModule handleModule(
- @NonNull URI moduleResource,
- @NonNull IBindingContext bindingContext) throws IOException, MetaschemaException {
- IBindingModuleLoader loader = bindingContext.newModuleLoader();
- loader.allowEntityResolution();
- return loader.load(moduleResource);
+ public static IModule loadModule(
+ @NonNull CommandLine commandLine,
+ @NonNull Option option,
+ @NonNull URI currentWorkingDirectory,
+ @NonNull IBindingContext bindingContext) throws CommandExecutionException {
+ String moduleName = commandLine.getOptionValue(option);
+ if (moduleName == null) {
+ throw new CommandExecutionException(
+ ExitCode.INVALID_ARGUMENTS,
+ String.format("Unable to determine the module to load. Use '%s' to specify the module.",
+ option.hasLongOpt()
+ ? "--" + option.getLongOpt()
+ : "-" + option.getOpt()));
+ }
+
+ URI moduleUri;
+ try {
+ moduleUri = UriUtils.toUri(moduleName, currentWorkingDirectory);
+ } catch (URISyntaxException ex) {
+ throw new CommandExecutionException(
+ ExitCode.INVALID_ARGUMENTS,
+ String.format("Cannot load module as '%s' is not a valid file or URL. %s",
+ ex.getInput(),
+ ex.getLocalizedMessage()),
+ ex);
+ }
+ return loadModule(moduleUri, bindingContext);
}
+ /**
+ * Load a Metaschema module from the provided relative resource path.
+ *
+ * This method will resolve the provided resource against the current working
+ * directory to create an absolute URI.
+ *
+ * @param moduleResource
+ * the relative path to the module resource to load
+ * @param currentWorkingDirectory
+ * the URI of the current working directory
+ * @param bindingContext
+ * the context used to access Metaschema module information based on
+ * Java class bindings
+ * @return the loaded module
+ * @throws CommandExecutionException
+ * if an error occurred while loading the module
+ * @since 2.0.0
+ */
@NonNull
- public static URI handleResource(
- @NonNull String location,
- @NonNull URI cwd) throws IOException {
+ public static IModule loadModule(
+ @NonNull String moduleResource,
+ @NonNull URI currentWorkingDirectory,
+ @NonNull IBindingContext bindingContext) throws CommandExecutionException {
try {
- return UriUtils.toUri(location, cwd);
+ URI moduleUri = getResourceUri(
+ moduleResource,
+ currentWorkingDirectory);
+ return loadModule(moduleUri, bindingContext);
} catch (URISyntaxException ex) {
- IOException newEx = new IOException( // NOPMD - intentional
- String.format("Cannot load module as '%s' is not a valid file or URL.", location));
- newEx.addSuppressed(ex);
- throw newEx;
+ throw new CommandExecutionException(
+ ExitCode.INVALID_ARGUMENTS,
+ String.format("Cannot load module as '%s' is not a valid file or URL. %s",
+ ex.getInput(),
+ ex.getLocalizedMessage()),
+ ex);
+ }
+ }
+
+ /**
+ * Load a Metaschema module from the provided resource path.
+ *
+ * @param moduleResource
+ * the absolute path to the module resource to load
+ * @param bindingContext
+ * the context used to access Metaschema module information based on
+ * Java class bindings
+ * @return the loaded module
+ * @throws CommandExecutionException
+ * if an error occurred while loading the module
+ * @since 2.0.0
+ */
+ @NonNull
+ public static IModule loadModule(
+ @NonNull URI moduleResource,
+ @NonNull IBindingContext bindingContext) throws CommandExecutionException {
+ // TODO: ensure the resource URI is absolute
+ try {
+ IBindingModuleLoader loader = bindingContext.newModuleLoader();
+ loader.allowEntityResolution();
+ return loader.load(moduleResource);
+ } catch (IOException | MetaschemaException ex) {
+ throw new CommandExecutionException(ExitCode.PROCESSING_ERROR, ex);
+ }
+ }
+
+ /**
+ * For a given resource location, resolve the location into an absolute URI.
+ *
+ * @param location
+ * the resource location
+ * @param currentWorkingDirectory
+ * the URI of the current working directory
+ * @return the resolved URI
+ * @throws URISyntaxException
+ * if the location is not a valid URI
+ */
+ @NonNull
+ public static URI getResourceUri(
+ @NonNull String location,
+ @NonNull URI currentWorkingDirectory) throws URISyntaxException {
+ return UriUtils.toUri(location, currentWorkingDirectory);
+ }
+
+ /**
+ * Load a set of external Metaschema module constraints based on the provided
+ * command line option.
+ *
+ * @param commandLine
+ * the provided command line argument information
+ * @param option
+ * the option specifying the constraints to load, which must be present
+ * on the command line
+ * @param currentWorkingDirectory
+ * the URI of the current working directory
+ * @return the set of loaded constraints
+ * @throws CommandExecutionException
+ * if an error occurred while loading the module
+ * @since 2.0.0
+ */
+ @NonNull
+ public static Set loadConstraintSets(
+ @NonNull CommandLine commandLine,
+ @NonNull Option option,
+ @NonNull URI currentWorkingDirectory) throws CommandExecutionException {
+ Set constraintSets;
+ if (commandLine.hasOption(option)) {
+ IConstraintLoader constraintLoader = IBindingContext.getConstraintLoader();
+ constraintSets = new LinkedHashSet<>();
+ String[] args = commandLine.getOptionValues(option);
+ for (String arg : args) {
+ assert arg != null;
+ try {
+ URI constraintUri = ObjectUtils.requireNonNull(UriUtils.toUri(arg, currentWorkingDirectory));
+ constraintSets.addAll(constraintLoader.load(constraintUri));
+ } catch (URISyntaxException | IOException | MetaschemaException | MetapathException ex) {
+ throw new CommandExecutionException(
+ ExitCode.IO_ERROR,
+ String.format("Unable to process constraint set '%s'. %s",
+ arg,
+ ex.getLocalizedMessage()),
+ ex);
+ }
+ }
+ } else {
+ constraintSets = CollectionUtil.emptySet();
}
+ return constraintSets;
}
+ /**
+ * Create a temporary directory for ephemeral files that will be deleted on
+ * shutdown.
+ *
+ * @return the temp directory path
+ * @throws IOException
+ * if an error occurred while creating the temporary directory
+ */
@NonNull
public static Path newTempDir() throws IOException {
Path retval = Files.createTempDirectory("metaschema-cli-");
- retval.toFile().deleteOnExit();
- return retval;
+ DeleteOnShutdown.register(retval);
+ return ObjectUtils.notNull(retval);
}
+ /**
+ * Create a new {@link IBindingContext} that is configured for dynamic
+ * compilation.
+ *
+ * @return the binding context
+ * @throws CommandExecutionException
+ * if an error occurred while creating the binding context
+ * @since 2.0.0
+ */
@NonNull
- public static IBindingContext newBindingContextWithDynamicCompilation() throws IOException {
+ public static IBindingContext newBindingContextWithDynamicCompilation() throws CommandExecutionException {
return newBindingContextWithDynamicCompilation(CollectionUtil.emptySet());
}
+ /**
+ * Create a new {@link IBindingContext} that is configured for dynamic
+ * compilation and to use the provided constraints.
+ *
+ * @param constraintSets
+ * the Metaschema module constraints to dynamicly bind to loaded
+ * modules
+ * @return the binding context
+ * @throws CommandExecutionException
+ * if an error occurred while creating the binding context
+ * @since 2.0.0
+ */
@NonNull
public static IBindingContext newBindingContextWithDynamicCompilation(@NonNull Set constraintSets)
- throws IOException {
- return IBindingContext.builder()
- .compilePath(newTempDir())
- .constraintSet(constraintSets)
- .build();
+ throws CommandExecutionException {
+ try {
+ Path tempDir = newTempDir();
+ return IBindingContext.builder()
+ .compilePath(tempDir)
+ .constraintSet(constraintSets)
+ .build();
+ } catch (IOException ex) {
+ throw new CommandExecutionException(ExitCode.RUNTIME_ERROR,
+ String.format("Unable to initialize the binding context. %s", ex.getLocalizedMessage()),
+ ex);
+ }
}
private MetaschemaCommands() {
diff --git a/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/commands/ValidateContentUsingModuleCommand.java b/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/commands/ValidateContentUsingModuleCommand.java
index 7e2eda757..300c3413d 100644
--- a/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/commands/ValidateContentUsingModuleCommand.java
+++ b/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/commands/ValidateContentUsingModuleCommand.java
@@ -6,11 +6,11 @@
package gov.nist.secauto.metaschema.cli.commands;
import gov.nist.secauto.metaschema.cli.processor.CLIProcessor.CallingContext;
+import gov.nist.secauto.metaschema.cli.processor.command.CommandExecutionException;
import gov.nist.secauto.metaschema.cli.processor.command.ICommandExecutor;
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.model.constraint.IConstraintSet;
import gov.nist.secauto.metaschema.core.model.validation.JsonSchemaContentValidator;
import gov.nist.secauto.metaschema.core.model.validation.XmlSchemaContentValidator;
@@ -32,10 +32,7 @@
import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
-import java.net.URI;
-import java.net.URISyntaxException;
import java.net.URL;
-import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -45,7 +42,11 @@
import edu.umd.cs.findbugs.annotations.NonNull;
-public class ValidateContentUsingModuleCommand
+/**
+ * This command implementation supports validation of a content instance based
+ * on a provided Metaschema module.
+ */
+class ValidateContentUsingModuleCommand
extends AbstractValidateContentCommand {
@NonNull
private static final String COMMAND = "validate-content";
@@ -73,13 +74,13 @@ public Collection extends Option> gatherOptions() {
@Override
public ICommandExecutor newExecutor(CallingContext callingContext, CommandLine commandLine) {
- return new OscalCommandExecutor(callingContext, commandLine);
+ return new CommandExecutor(callingContext, commandLine);
}
- private final class OscalCommandExecutor
+ private final class CommandExecutor
extends AbstractValidationCommandExecutor {
- private OscalCommandExecutor(
+ private CommandExecutor(
@NonNull CallingContext callingContext,
@NonNull CommandLine commandLine) {
super(callingContext, commandLine);
@@ -87,29 +88,19 @@ private OscalCommandExecutor(
@Override
protected IBindingContext getBindingContext(@NonNull Set constraintSets)
- throws MetaschemaException, IOException {
+ throws CommandExecutionException {
return MetaschemaCommands.newBindingContextWithDynamicCompilation(constraintSets);
}
@Override
protected IModule getModule(
CommandLine commandLine,
- IBindingContext bindingContext) throws IOException, MetaschemaException {
-
- URI cwd = ObjectUtils.notNull(Paths.get("").toAbsolutePath().toUri());
-
- IModule module;
- try {
- module = MetaschemaCommands.handleModule(
- commandLine,
- MetaschemaCommands.METASCHEMA_REQUIRED_OPTION,
- cwd,
- bindingContext);
- } catch (URISyntaxException ex) {
- throw new IOException(String.format("Cannot load module as '%s' is not a valid file or URL.", ex.getInput()),
- ex);
- }
- return module;
+ IBindingContext bindingContext) throws CommandExecutionException {
+ return MetaschemaCommands.loadModule(
+ commandLine,
+ MetaschemaCommands.METASCHEMA_REQUIRED_OPTION,
+ ObjectUtils.notNull(getCurrentWorkingDirectory().toUri()),
+ bindingContext);
}
@Override
diff --git a/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/commands/ValidateModuleCommand.java b/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/commands/ValidateModuleCommand.java
index d070890ab..22400c6bc 100644
--- a/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/commands/ValidateModuleCommand.java
+++ b/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/commands/ValidateModuleCommand.java
@@ -6,9 +6,9 @@
package gov.nist.secauto.metaschema.cli.commands;
import gov.nist.secauto.metaschema.cli.processor.CLIProcessor.CallingContext;
+import gov.nist.secauto.metaschema.cli.processor.command.CommandExecutionException;
import gov.nist.secauto.metaschema.cli.processor.command.ICommandExecutor;
import gov.nist.secauto.metaschema.core.model.IModule;
-import gov.nist.secauto.metaschema.core.model.MetaschemaException;
import gov.nist.secauto.metaschema.core.model.constraint.IConstraintSet;
import gov.nist.secauto.metaschema.core.model.util.JsonUtil;
import gov.nist.secauto.metaschema.core.model.validation.JsonSchemaContentValidator;
@@ -38,7 +38,10 @@
import edu.umd.cs.findbugs.annotations.NonNull;
import nl.talsmasoftware.lazy4j.Lazy;
-public class ValidateModuleCommand
+/**
+ * This command implementation supports validation a Metaschema module.
+ */
+class ValidateModuleCommand
extends AbstractValidateContentCommand {
@NonNull
private static final String COMMAND = "validate";
@@ -55,14 +58,14 @@ public String getDescription() {
@Override
public ICommandExecutor newExecutor(CallingContext callingContext, CommandLine commandLine) {
- return new ValidateModuleCommandExecutor(callingContext, commandLine);
+ return new CommandExecutor(callingContext, commandLine);
}
- private final class ValidateModuleCommandExecutor
+ private final class CommandExecutor
extends AbstractValidationCommandExecutor {
private final Lazy validationProvider = Lazy.lazy(ValidationProvider::new);
- private ValidateModuleCommandExecutor(
+ private CommandExecutor(
@NonNull CallingContext callingContext,
@NonNull CommandLine commandLine) {
super(callingContext, commandLine);
@@ -70,7 +73,7 @@ private ValidateModuleCommandExecutor(
@Override
protected IBindingContext getBindingContext(Set constraintSets)
- throws MetaschemaException, IOException {
+ throws CommandExecutionException {
return MetaschemaCommands.newBindingContextWithDynamicCompilation(constraintSets);
}
@@ -90,16 +93,17 @@ protected ISchemaValidationProvider getSchemaValidationProvider(
}
private static final class ValidationProvider implements ISchemaValidationProvider {
+ @SuppressWarnings("resource")
@Override
public XmlSchemaContentValidator getXmlSchemas(
@NonNull URL targetResource,
@NonNull IBindingContext bindingContext) throws IOException, SAXException {
try (InputStream is = this.getClass().getResourceAsStream("/schema/xml/metaschema-model_schema.xsd")) {
- List
-
- com.google.auto.service
- auto-service-annotations
- ${dependency.auto-service.version}
- provided
- org.apache.xmlbeansxmlbeans
@@ -515,24 +508,11 @@
org.apache.maven.pluginsmaven-compiler-plugin
-
-
-
- com.google.auto.service
- auto-service
- ${dependency.auto-service.version}
-
-
- org.apache.maven.pluginsmaven-dependency-plugin
-
-
- com.google.auto.service:auto-service
- org.apache.logging.log4j:log4j-core
diff --git a/schemagen/pom.xml b/schemagen/pom.xml
index 6c214762d..b309c88d8 100644
--- a/schemagen/pom.xml
+++ b/schemagen/pom.xml
@@ -32,11 +32,6 @@
${project.groupId}metaschema-databind
-
-
- com.google.auto.service
- auto-service-annotations
- ${project.groupId}metaschema-testing
diff --git a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/datatype/IDatatypeContent.java b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/datatype/IDatatypeContent.java
deleted file mode 100644
index 91b68ddf9..000000000
--- a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/datatype/IDatatypeContent.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * SPDX-FileCopyrightText: none
- * SPDX-License-Identifier: CC0-1.0
- */
-
-package gov.nist.secauto.metaschema.schemagen.datatype;
-
-import java.util.List;
-
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
-
-import edu.umd.cs.findbugs.annotations.NonNull;
-
-public interface IDatatypeContent {
- @NonNull
- String getTypeName();
-
- @NonNull
- List getDependencies();
-
- void write(@NonNull XMLStreamWriter writer) throws XMLStreamException;
-}
diff --git a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/json/impl/AssemblyDefinitionJsonSchema.java b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/json/impl/AssemblyDefinitionJsonSchema.java
index d357bffc4..0ff6169a1 100644
--- a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/json/impl/AssemblyDefinitionJsonSchema.java
+++ b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/json/impl/AssemblyDefinitionJsonSchema.java
@@ -78,7 +78,7 @@ private static Stream extends INamedModelInstanceAbsolute> explodeChoice(@NonN
@NonNull
protected List> getGroupableModelInstances() {
- return groupableModelInstances.get();
+ return ObjectUtils.notNull(groupableModelInstances.get());
}
@Override
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 1a033b174..46a974834 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
@@ -72,11 +72,10 @@ protected void generateBody(
}
// generate flag properties
- for (IFlagInstance flag : flags) {
+ flags.forEach(flag -> {
assert flag != null;
- new FlagInstanceJsonProperty(flag)
- .generateProperty(properties, state); // NOPMD unavoidable instantiation
- }
+ new FlagInstanceJsonProperty(flag).generateProperty(properties, state);
+ });
// generate value property
if (jsonValueKeyFlag == null) {
diff --git a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/datatype/XmlDatatypeManager.java b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/XmlDatatypeManager.java
similarity index 75%
rename from schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/datatype/XmlDatatypeManager.java
rename to schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/XmlDatatypeManager.java
index bbc9b0be2..319bd00b7 100644
--- a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/datatype/XmlDatatypeManager.java
+++ b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/XmlDatatypeManager.java
@@ -3,11 +3,15 @@
* SPDX-License-Identifier: CC0-1.0
*/
-package gov.nist.secauto.metaschema.schemagen.xml.datatype;
+package gov.nist.secauto.metaschema.schemagen.xml;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
import gov.nist.secauto.metaschema.schemagen.datatype.AbstractDatatypeManager;
-import gov.nist.secauto.metaschema.schemagen.datatype.IDatatypeProvider;
+import gov.nist.secauto.metaschema.schemagen.xml.impl.IDatatypeProvider;
+import gov.nist.secauto.metaschema.schemagen.xml.impl.XmlCoreDatatypeProvider;
+import gov.nist.secauto.metaschema.schemagen.xml.impl.XmlMarkupLineDatatypeProvider;
+import gov.nist.secauto.metaschema.schemagen.xml.impl.XmlMarkupMultilineDatatypeProvider;
+import gov.nist.secauto.metaschema.schemagen.xml.impl.XmlProseCompositDatatypeProvider;
import org.codehaus.stax2.XMLStreamWriter2;
@@ -21,6 +25,10 @@
import edu.umd.cs.findbugs.annotations.NonNull;
import nl.talsmasoftware.lazy4j.Lazy;
+/**
+ * Support for managing Module data type implementations aligned with the XML
+ * schema format for use in schema generation.
+ */
public class XmlDatatypeManager
extends AbstractDatatypeManager {
public static final String NS_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema";
diff --git a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/XmlSchemaGenerator.java b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/XmlSchemaGenerator.java
index c87dd4ccb..67dce18ad 100644
--- a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/XmlSchemaGenerator.java
+++ b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/XmlSchemaGenerator.java
@@ -16,9 +16,8 @@
import gov.nist.secauto.metaschema.schemagen.AbstractSchemaGenerator;
import gov.nist.secauto.metaschema.schemagen.SchemaGenerationException;
import gov.nist.secauto.metaschema.schemagen.SchemaGenerationFeature;
-import gov.nist.secauto.metaschema.schemagen.xml.datatype.XmlDatatypeManager;
import gov.nist.secauto.metaschema.schemagen.xml.impl.XmlGenerationState;
-import gov.nist.secauto.metaschema.schemagen.xml.schematype.IXmlType;
+import gov.nist.secauto.metaschema.schemagen.xml.impl.schematype.IXmlType;
import org.codehaus.stax2.XMLOutputFactory2;
import org.codehaus.stax2.XMLStreamWriter2;
diff --git a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/datatype/package-info.java b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/datatype/package-info.java
deleted file mode 100644
index 402dccc97..000000000
--- a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/datatype/package-info.java
+++ /dev/null
@@ -1,11 +0,0 @@
-/*
- * SPDX-FileCopyrightText: none
- * SPDX-License-Identifier: CC0-1.0
- */
-
-/**
- * Support for managing Module data type implementations aligned with the XML
- * schema format for use in schema generation.
- */
-
-package gov.nist.secauto.metaschema.schemagen.xml.datatype;
diff --git a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/datatype/AbstractDatatypeContent.java b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/AbstractDatatypeContent.java
similarity index 94%
rename from schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/datatype/AbstractDatatypeContent.java
rename to schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/AbstractDatatypeContent.java
index 6b3f7692d..f3ec0d79c 100644
--- a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/datatype/AbstractDatatypeContent.java
+++ b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/AbstractDatatypeContent.java
@@ -3,7 +3,7 @@
* SPDX-License-Identifier: CC0-1.0
*/
-package gov.nist.secauto.metaschema.schemagen.datatype;
+package gov.nist.secauto.metaschema.schemagen.xml.impl;
import gov.nist.secauto.metaschema.core.util.CollectionUtil;
diff --git a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/datatype/AbstractXmlDatatypeProvider.java b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/AbstractXmlDatatypeProvider.java
similarity index 92%
rename from schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/datatype/AbstractXmlDatatypeProvider.java
rename to schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/AbstractXmlDatatypeProvider.java
index d95c1e908..9a0b5681c 100644
--- a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/datatype/AbstractXmlDatatypeProvider.java
+++ b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/AbstractXmlDatatypeProvider.java
@@ -3,10 +3,7 @@
* SPDX-License-Identifier: CC0-1.0
*/
-package gov.nist.secauto.metaschema.schemagen.xml.datatype;
-
-import gov.nist.secauto.metaschema.schemagen.datatype.IDatatypeContent;
-import gov.nist.secauto.metaschema.schemagen.datatype.IDatatypeProvider;
+package gov.nist.secauto.metaschema.schemagen.xml.impl;
import org.codehaus.stax2.XMLStreamWriter2;
import org.eclipse.jdt.annotation.Owning;
diff --git a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/datatype/AbstractXmlMarkupDatatypeProvider.java b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/AbstractXmlMarkupDatatypeProvider.java
similarity index 92%
rename from schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/datatype/AbstractXmlMarkupDatatypeProvider.java
rename to schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/AbstractXmlMarkupDatatypeProvider.java
index eb847965d..f0eb5eb27 100644
--- a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/datatype/AbstractXmlMarkupDatatypeProvider.java
+++ b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/AbstractXmlMarkupDatatypeProvider.java
@@ -3,12 +3,11 @@
* SPDX-License-Identifier: CC0-1.0
*/
-package gov.nist.secauto.metaschema.schemagen.xml.datatype;
+package gov.nist.secauto.metaschema.schemagen.xml.impl;
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.schemagen.datatype.IDatatypeContent;
import org.eclipse.jdt.annotation.Owning;
import org.jdom2.Element;
diff --git a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/datatype/CompositeDatatypeProvider.java b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/CompositeDatatypeProvider.java
similarity index 96%
rename from schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/datatype/CompositeDatatypeProvider.java
rename to schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/CompositeDatatypeProvider.java
index 5f84881ac..271ef895d 100644
--- a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/datatype/CompositeDatatypeProvider.java
+++ b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/CompositeDatatypeProvider.java
@@ -3,7 +3,7 @@
* SPDX-License-Identifier: CC0-1.0
*/
-package gov.nist.secauto.metaschema.schemagen.datatype;
+package gov.nist.secauto.metaschema.schemagen.xml.impl;
import gov.nist.secauto.metaschema.core.util.CollectionUtil;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
diff --git a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/IDatatypeContent.java b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/IDatatypeContent.java
new file mode 100644
index 000000000..f75ab7096
--- /dev/null
+++ b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/IDatatypeContent.java
@@ -0,0 +1,41 @@
+/*
+ * SPDX-FileCopyrightText: none
+ * SPDX-License-Identifier: CC0-1.0
+ */
+
+package gov.nist.secauto.metaschema.schemagen.xml.impl;
+
+import java.util.List;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+import edu.umd.cs.findbugs.annotations.NonNull;
+
+public interface IDatatypeContent {
+ /**
+ * Get the name of the data type.
+ *
+ * @return the name
+ */
+ @NonNull
+ String getTypeName();
+
+ /**
+ * Get the data type names this type depends on.
+ *
+ * @return the names
+ */
+ @NonNull
+ List getDependencies();
+
+ /**
+ * Write the data type to the XML stream.
+ *
+ * @param writer
+ * the XML stream
+ * @throws XMLStreamException
+ * if an error occurred while writing to the XML stream
+ */
+ void write(@NonNull XMLStreamWriter writer) throws XMLStreamException;
+}
diff --git a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/datatype/IDatatypeProvider.java b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/IDatatypeProvider.java
similarity index 89%
rename from schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/datatype/IDatatypeProvider.java
rename to schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/IDatatypeProvider.java
index d2749bfee..76fc7a723 100644
--- a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/datatype/IDatatypeProvider.java
+++ b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/IDatatypeProvider.java
@@ -3,7 +3,7 @@
* SPDX-License-Identifier: CC0-1.0
*/
-package gov.nist.secauto.metaschema.schemagen.datatype;
+package gov.nist.secauto.metaschema.schemagen.xml.impl;
import org.codehaus.stax2.XMLStreamWriter2;
diff --git a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/datatype/JDom2DatatypeContent.java b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/JDom2DatatypeContent.java
similarity index 89%
rename from schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/datatype/JDom2DatatypeContent.java
rename to schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/JDom2DatatypeContent.java
index c55c0c330..008e9f151 100644
--- a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/datatype/JDom2DatatypeContent.java
+++ b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/JDom2DatatypeContent.java
@@ -3,10 +3,9 @@
* SPDX-License-Identifier: CC0-1.0
*/
-package gov.nist.secauto.metaschema.schemagen.xml.datatype;
+package gov.nist.secauto.metaschema.schemagen.xml.impl;
import gov.nist.secauto.metaschema.core.util.CollectionUtil;
-import gov.nist.secauto.metaschema.schemagen.datatype.AbstractDatatypeContent;
import org.jdom2.Element;
import org.jdom2.output.Format;
diff --git a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/datatype/JDom2XmlSchemaLoader.java b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/JDom2XmlSchemaLoader.java
similarity index 97%
rename from schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/datatype/JDom2XmlSchemaLoader.java
rename to schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/JDom2XmlSchemaLoader.java
index d4ff1f13f..98a0b5bb4 100644
--- a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/datatype/JDom2XmlSchemaLoader.java
+++ b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/JDom2XmlSchemaLoader.java
@@ -3,7 +3,7 @@
* SPDX-License-Identifier: CC0-1.0
*/
-package gov.nist.secauto.metaschema.schemagen.xml.datatype;
+package gov.nist.secauto.metaschema.schemagen.xml.impl;
import org.jdom2.Document;
import org.jdom2.Element;
diff --git a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/datatype/XmlCoreDatatypeProvider.java b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/XmlCoreDatatypeProvider.java
similarity index 94%
rename from schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/datatype/XmlCoreDatatypeProvider.java
rename to schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/XmlCoreDatatypeProvider.java
index 05755130b..b09b9f5fc 100644
--- a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/datatype/XmlCoreDatatypeProvider.java
+++ b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/XmlCoreDatatypeProvider.java
@@ -3,12 +3,11 @@
* SPDX-License-Identifier: CC0-1.0
*/
-package gov.nist.secauto.metaschema.schemagen.xml.datatype;
+package gov.nist.secauto.metaschema.schemagen.xml.impl;
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.schemagen.datatype.IDatatypeContent;
import org.jdom2.Attribute;
import org.jdom2.Element;
diff --git a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/XmlGenerationState.java b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/XmlGenerationState.java
index 14202214f..281997443 100644
--- a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/XmlGenerationState.java
+++ b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/XmlGenerationState.java
@@ -20,15 +20,15 @@
import gov.nist.secauto.metaschema.schemagen.AbstractGenerationState;
import gov.nist.secauto.metaschema.schemagen.SchemaGenerationException;
import gov.nist.secauto.metaschema.schemagen.SchemaGenerationFeature;
-import gov.nist.secauto.metaschema.schemagen.xml.datatype.XmlDatatypeManager;
-import gov.nist.secauto.metaschema.schemagen.xml.schematype.IXmlComplexType;
-import gov.nist.secauto.metaschema.schemagen.xml.schematype.IXmlSimpleType;
-import gov.nist.secauto.metaschema.schemagen.xml.schematype.IXmlType;
-import gov.nist.secauto.metaschema.schemagen.xml.schematype.XmlComplexTypeAssemblyDefinition;
-import gov.nist.secauto.metaschema.schemagen.xml.schematype.XmlComplexTypeFieldDefinition;
-import gov.nist.secauto.metaschema.schemagen.xml.schematype.XmlSimpleTypeDataTypeReference;
-import gov.nist.secauto.metaschema.schemagen.xml.schematype.XmlSimpleTypeDataTypeRestriction;
-import gov.nist.secauto.metaschema.schemagen.xml.schematype.XmlSimpleTypeUnion;
+import gov.nist.secauto.metaschema.schemagen.xml.XmlDatatypeManager;
+import gov.nist.secauto.metaschema.schemagen.xml.impl.schematype.IXmlComplexType;
+import gov.nist.secauto.metaschema.schemagen.xml.impl.schematype.IXmlSimpleType;
+import gov.nist.secauto.metaschema.schemagen.xml.impl.schematype.IXmlType;
+import gov.nist.secauto.metaschema.schemagen.xml.impl.schematype.XmlComplexTypeAssemblyDefinition;
+import gov.nist.secauto.metaschema.schemagen.xml.impl.schematype.XmlComplexTypeFieldDefinition;
+import gov.nist.secauto.metaschema.schemagen.xml.impl.schematype.XmlSimpleTypeDataTypeReference;
+import gov.nist.secauto.metaschema.schemagen.xml.impl.schematype.XmlSimpleTypeDataTypeRestriction;
+import gov.nist.secauto.metaschema.schemagen.xml.impl.schematype.XmlSimpleTypeUnion;
import org.codehaus.stax2.XMLStreamWriter2;
diff --git a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/datatype/XmlMarkupLineDatatypeProvider.java b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/XmlMarkupLineDatatypeProvider.java
similarity index 89%
rename from schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/datatype/XmlMarkupLineDatatypeProvider.java
rename to schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/XmlMarkupLineDatatypeProvider.java
index e69cc59ee..0c8ca2861 100644
--- a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/datatype/XmlMarkupLineDatatypeProvider.java
+++ b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/XmlMarkupLineDatatypeProvider.java
@@ -3,7 +3,7 @@
* SPDX-License-Identifier: CC0-1.0
*/
-package gov.nist.secauto.metaschema.schemagen.xml.datatype;
+package gov.nist.secauto.metaschema.schemagen.xml.impl;
public class XmlMarkupLineDatatypeProvider
extends AbstractXmlMarkupDatatypeProvider {
diff --git a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/datatype/XmlMarkupMultilineDatatypeProvider.java b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/XmlMarkupMultilineDatatypeProvider.java
similarity index 89%
rename from schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/datatype/XmlMarkupMultilineDatatypeProvider.java
rename to schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/XmlMarkupMultilineDatatypeProvider.java
index 8b8a16f85..4502d36fa 100644
--- a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/datatype/XmlMarkupMultilineDatatypeProvider.java
+++ b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/XmlMarkupMultilineDatatypeProvider.java
@@ -3,7 +3,7 @@
* SPDX-License-Identifier: CC0-1.0
*/
-package gov.nist.secauto.metaschema.schemagen.xml.datatype;
+package gov.nist.secauto.metaschema.schemagen.xml.impl;
public class XmlMarkupMultilineDatatypeProvider
extends AbstractXmlMarkupDatatypeProvider {
diff --git a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/datatype/XmlProseBaseDatatypeProvider.java b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/XmlProseBaseDatatypeProvider.java
similarity index 89%
rename from schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/datatype/XmlProseBaseDatatypeProvider.java
rename to schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/XmlProseBaseDatatypeProvider.java
index cfbc7f710..14cd3427e 100644
--- a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/datatype/XmlProseBaseDatatypeProvider.java
+++ b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/XmlProseBaseDatatypeProvider.java
@@ -3,11 +3,10 @@
* SPDX-License-Identifier: CC0-1.0
*/
-package gov.nist.secauto.metaschema.schemagen.xml.datatype;
+package gov.nist.secauto.metaschema.schemagen.xml.impl;
import gov.nist.secauto.metaschema.core.model.IModule;
import gov.nist.secauto.metaschema.core.util.CollectionUtil;
-import gov.nist.secauto.metaschema.schemagen.datatype.IDatatypeContent;
import org.jdom2.Element;
diff --git a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/datatype/XmlProseCompositDatatypeProvider.java b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/XmlProseCompositDatatypeProvider.java
similarity index 81%
rename from schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/datatype/XmlProseCompositDatatypeProvider.java
rename to schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/XmlProseCompositDatatypeProvider.java
index e11787667..394b68b4c 100644
--- a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/datatype/XmlProseCompositDatatypeProvider.java
+++ b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/XmlProseCompositDatatypeProvider.java
@@ -3,11 +3,7 @@
* SPDX-License-Identifier: CC0-1.0
*/
-package gov.nist.secauto.metaschema.schemagen.xml.datatype;
-
-import gov.nist.secauto.metaschema.schemagen.datatype.CompositeDatatypeProvider;
-import gov.nist.secauto.metaschema.schemagen.datatype.IDatatypeContent;
-import gov.nist.secauto.metaschema.schemagen.datatype.IDatatypeProvider;
+package gov.nist.secauto.metaschema.schemagen.xml.impl;
import org.codehaus.stax2.XMLStreamWriter2;
diff --git a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/schematype/AbstractXmlComplexType.java b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/schematype/AbstractXmlComplexType.java
similarity index 97%
rename from schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/schematype/AbstractXmlComplexType.java
rename to schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/schematype/AbstractXmlComplexType.java
index ea684d300..f543cb255 100644
--- a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/schematype/AbstractXmlComplexType.java
+++ b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/schematype/AbstractXmlComplexType.java
@@ -3,7 +3,7 @@
* SPDX-License-Identifier: CC0-1.0
*/
-package gov.nist.secauto.metaschema.schemagen.xml.schematype;
+package gov.nist.secauto.metaschema.schemagen.xml.impl.schematype;
import gov.nist.secauto.metaschema.core.model.IFlagInstance;
import gov.nist.secauto.metaschema.core.model.IModelDefinition;
diff --git a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/schematype/AbstractXmlSimpleType.java b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/schematype/AbstractXmlSimpleType.java
similarity index 94%
rename from schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/schematype/AbstractXmlSimpleType.java
rename to schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/schematype/AbstractXmlSimpleType.java
index c2346861f..108326d79 100644
--- a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/schematype/AbstractXmlSimpleType.java
+++ b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/schematype/AbstractXmlSimpleType.java
@@ -3,7 +3,7 @@
* SPDX-License-Identifier: CC0-1.0
*/
-package gov.nist.secauto.metaschema.schemagen.xml.schematype;
+package gov.nist.secauto.metaschema.schemagen.xml.impl.schematype;
import gov.nist.secauto.metaschema.core.datatype.IDataTypeAdapter;
import gov.nist.secauto.metaschema.core.model.IValuedDefinition;
diff --git a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/schematype/AbstractXmlType.java b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/schematype/AbstractXmlType.java
similarity index 86%
rename from schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/schematype/AbstractXmlType.java
rename to schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/schematype/AbstractXmlType.java
index 8e78c0172..a73ac16e5 100644
--- a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/schematype/AbstractXmlType.java
+++ b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/schematype/AbstractXmlType.java
@@ -3,7 +3,7 @@
* SPDX-License-Identifier: CC0-1.0
*/
-package gov.nist.secauto.metaschema.schemagen.xml.schematype;
+package gov.nist.secauto.metaschema.schemagen.xml.impl.schematype;
import javax.xml.namespace.QName;
diff --git a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/schematype/IXmlComplexType.java b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/schematype/IXmlComplexType.java
similarity index 91%
rename from schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/schematype/IXmlComplexType.java
rename to schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/schematype/IXmlComplexType.java
index 3c4c4ebb0..49cd8350a 100644
--- a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/schematype/IXmlComplexType.java
+++ b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/schematype/IXmlComplexType.java
@@ -3,7 +3,7 @@
* SPDX-License-Identifier: CC0-1.0
*/
-package gov.nist.secauto.metaschema.schemagen.xml.schematype;
+package gov.nist.secauto.metaschema.schemagen.xml.impl.schematype;
import gov.nist.secauto.metaschema.core.model.IDefinition;
import gov.nist.secauto.metaschema.schemagen.ModuleIndex.DefinitionEntry;
diff --git a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/schematype/IXmlSimpleType.java b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/schematype/IXmlSimpleType.java
similarity index 89%
rename from schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/schematype/IXmlSimpleType.java
rename to schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/schematype/IXmlSimpleType.java
index e1ee56fea..5380ce311 100644
--- a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/schematype/IXmlSimpleType.java
+++ b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/schematype/IXmlSimpleType.java
@@ -3,7 +3,7 @@
* SPDX-License-Identifier: CC0-1.0
*/
-package gov.nist.secauto.metaschema.schemagen.xml.schematype;
+package gov.nist.secauto.metaschema.schemagen.xml.impl.schematype;
import gov.nist.secauto.metaschema.core.datatype.IDataTypeAdapter;
import gov.nist.secauto.metaschema.schemagen.xml.impl.XmlGenerationState;
diff --git a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/schematype/IXmlType.java b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/schematype/IXmlType.java
similarity index 97%
rename from schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/schematype/IXmlType.java
rename to schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/schematype/IXmlType.java
index 45d931288..275995b07 100644
--- a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/schematype/IXmlType.java
+++ b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/schematype/IXmlType.java
@@ -3,7 +3,7 @@
* SPDX-License-Identifier: CC0-1.0
*/
-package gov.nist.secauto.metaschema.schemagen.xml.schematype;
+package gov.nist.secauto.metaschema.schemagen.xml.impl.schematype;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
import gov.nist.secauto.metaschema.schemagen.SchemaGenerationException;
diff --git a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/schematype/XmlComplexTypeAssemblyDefinition.java b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/schematype/XmlComplexTypeAssemblyDefinition.java
similarity index 99%
rename from schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/schematype/XmlComplexTypeAssemblyDefinition.java
rename to schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/schematype/XmlComplexTypeAssemblyDefinition.java
index b05c81b20..07aec466b 100644
--- a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/schematype/XmlComplexTypeAssemblyDefinition.java
+++ b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/schematype/XmlComplexTypeAssemblyDefinition.java
@@ -3,7 +3,7 @@
* SPDX-License-Identifier: CC0-1.0
*/
-package gov.nist.secauto.metaschema.schemagen.xml.schematype;
+package gov.nist.secauto.metaschema.schemagen.xml.impl.schematype;
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupDataTypeProvider;
import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition;
diff --git a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/schematype/XmlComplexTypeFieldDefinition.java b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/schematype/XmlComplexTypeFieldDefinition.java
similarity index 96%
rename from schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/schematype/XmlComplexTypeFieldDefinition.java
rename to schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/schematype/XmlComplexTypeFieldDefinition.java
index d504644ea..af6135911 100644
--- a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/schematype/XmlComplexTypeFieldDefinition.java
+++ b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/schematype/XmlComplexTypeFieldDefinition.java
@@ -3,7 +3,7 @@
* SPDX-License-Identifier: CC0-1.0
*/
-package gov.nist.secauto.metaschema.schemagen.xml.schematype;
+package gov.nist.secauto.metaschema.schemagen.xml.impl.schematype;
import gov.nist.secauto.metaschema.core.datatype.IDataTypeAdapter;
import gov.nist.secauto.metaschema.core.model.IFieldDefinition;
diff --git a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/schematype/XmlSimpleTypeDataTypeReference.java b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/schematype/XmlSimpleTypeDataTypeReference.java
similarity index 95%
rename from schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/schematype/XmlSimpleTypeDataTypeReference.java
rename to schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/schematype/XmlSimpleTypeDataTypeReference.java
index 0369002a7..e03590de9 100644
--- a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/schematype/XmlSimpleTypeDataTypeReference.java
+++ b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/schematype/XmlSimpleTypeDataTypeReference.java
@@ -3,7 +3,7 @@
* SPDX-License-Identifier: CC0-1.0
*/
-package gov.nist.secauto.metaschema.schemagen.xml.schematype;
+package gov.nist.secauto.metaschema.schemagen.xml.impl.schematype;
import gov.nist.secauto.metaschema.core.datatype.IDataTypeAdapter;
import gov.nist.secauto.metaschema.schemagen.xml.impl.XmlGenerationState;
diff --git a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/schematype/XmlSimpleTypeDataTypeRestriction.java b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/schematype/XmlSimpleTypeDataTypeRestriction.java
similarity index 98%
rename from schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/schematype/XmlSimpleTypeDataTypeRestriction.java
rename to schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/schematype/XmlSimpleTypeDataTypeRestriction.java
index 10b5de4f2..457d50305 100644
--- a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/schematype/XmlSimpleTypeDataTypeRestriction.java
+++ b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/schematype/XmlSimpleTypeDataTypeRestriction.java
@@ -3,7 +3,7 @@
* SPDX-License-Identifier: CC0-1.0
*/
-package gov.nist.secauto.metaschema.schemagen.xml.schematype;
+package gov.nist.secauto.metaschema.schemagen.xml.impl.schematype;
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine;
import gov.nist.secauto.metaschema.core.model.IValuedDefinition;
diff --git a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/schematype/XmlSimpleTypeUnion.java b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/schematype/XmlSimpleTypeUnion.java
similarity index 97%
rename from schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/schematype/XmlSimpleTypeUnion.java
rename to schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/schematype/XmlSimpleTypeUnion.java
index 71256a7af..34ad7f5ef 100644
--- a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/schematype/XmlSimpleTypeUnion.java
+++ b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/schematype/XmlSimpleTypeUnion.java
@@ -3,7 +3,7 @@
* SPDX-License-Identifier: CC0-1.0
*/
-package gov.nist.secauto.metaschema.schemagen.xml.schematype;
+package gov.nist.secauto.metaschema.schemagen.xml.impl.schematype;
import gov.nist.secauto.metaschema.core.model.IValuedDefinition;
import gov.nist.secauto.metaschema.core.util.CollectionUtil;
diff --git a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/schematype/package-info.java b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/schematype/package-info.java
similarity index 74%
rename from schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/schematype/package-info.java
rename to schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/schematype/package-info.java
index 5b776c06d..7ca818916 100644
--- a/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/schematype/package-info.java
+++ b/schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/xml/impl/schematype/package-info.java
@@ -8,4 +8,4 @@
* flags, fields, assemblies).
*/
-package gov.nist.secauto.metaschema.schemagen.xml.schematype;
+package gov.nist.secauto.metaschema.schemagen.xml.impl.schematype;