Skip to content

Commit

Permalink
interim commit
Browse files Browse the repository at this point in the history
  • Loading branch information
david-waltermire committed May 6, 2024
1 parent 99df361 commit dd82fc7
Show file tree
Hide file tree
Showing 17 changed files with 29 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@

package gov.nist.secauto.metaschema.databind;

import gov.nist.secauto.metaschema.core.model.IModule;
import gov.nist.secauto.metaschema.core.model.IModuleLoader;
import gov.nist.secauto.metaschema.core.util.CollectionUtil;
import gov.nist.secauto.metaschema.databind.model.IBoundDefinitionModelComplex;
import gov.nist.secauto.metaschema.databind.model.IBoundModule;

import java.util.ArrayList;
import java.util.HashSet;
Expand All @@ -42,7 +42,7 @@ class PostProcessingModuleLoaderStrategy
extends SimpleModuleLoaderStrategy {
@NonNull
private final List<IModuleLoader.IModulePostProcessor> modulePostProcessors;
private final Set<IBoundModule> resolvedModules = new HashSet<>();
private final Set<IModule> resolvedModules = new HashSet<>();

protected PostProcessingModuleLoaderStrategy(
@NonNull IBindingContext bindingContext,
Expand All @@ -61,7 +61,7 @@ public IBoundDefinitionModelComplex getBoundDefinitionForClass(@NonNull Class<?>
IBoundDefinitionModelComplex retval = super.getBoundDefinitionForClass(clazz);
if (retval != null) {
// force loading of metaschema information to apply constraints
IBoundModule module = retval.getContainingModule();
IModule module = retval.getContainingModule();
synchronized (resolvedModules) {
if (!resolvedModules.contains(module)) {
// add first, to avoid loops
Expand All @@ -73,7 +73,7 @@ public IBoundDefinitionModelComplex getBoundDefinitionForClass(@NonNull Class<?>
return retval;
}

private void handleModule(@NonNull IBoundModule module) {
private void handleModule(@NonNull IModule module) {
for (IModuleLoader.IModulePostProcessor postProcessor : getModulePostProcessors()) {
postProcessor.processModule(module);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
* Represents a flag definition/instance bound to Java field.
*/
public interface IBoundDefinitionFlag
extends IFlagDefinition, IBoundDefinition {
extends IFlagDefinition, IBoundModuleElement {
// no additional methods
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,27 @@
package gov.nist.secauto.metaschema.databind.model;

import gov.nist.secauto.metaschema.core.model.IModelDefinition;
import gov.nist.secauto.metaschema.databind.IBindingContext;

import java.util.Collection;

import javax.xml.namespace.QName;

import edu.umd.cs.findbugs.annotations.NonNull;

/**
* Represents a field or assembly instance bound to Java data.
*/
// REFACTOR: rename to IBoundDefinitionModel
public interface IBoundDefinitionModel
extends IBoundDefinition, IModelDefinition {
extends IModelDefinition, IBoundModuleElement {
/**
* Get the binding context used for the definition.
*
* @return the binding context
*/
@NonNull
IBindingContext getBindingContext();

@Override
IBoundInstanceModelNamed getInlineInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public interface IBoundDefinitionModelAssembly

// Assembly Definition Features
// ============================

@Override
@NonNull
default IBoundDefinitionModelAssembly getOwningDefinition() {
Expand Down Expand Up @@ -101,11 +100,6 @@ default void writeItem(Object item, IItemWriteHandler handler) throws IOExceptio
handler.writeItemAssembly(item, this);
}

@Override
default boolean canHandleJsonPropertyName(@NonNull String name) {
return name.equals(getRootJsonName());
}

@Override
default boolean canHandleXmlQName(@NonNull QName qname) {
return qname.equals(getRootXmlQName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,6 @@ default void writeItem(Object item, IItemWriteHandler handler) throws IOExceptio
handler.writeItemField(item, this);
}

@Override
default boolean canHandleJsonPropertyName(String name) {
// not handled, since not root
return false;
}

@Override
default boolean canHandleXmlQName(QName qname) {
// not handled, since not root
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,6 @@ default void deepCopy(@NonNull Object fromInstance, @NonNull Object toInstance)
setValue(toInstance, value);
}

@Override
default boolean canHandleJsonPropertyName(String name) {
// REFACTOR: Is this correct?
return name.equals(getJsonValueKeyName());
}

@Override
default boolean canHandleXmlQName(QName qname) {
// REFACTOR: Is this correct?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,6 @@ default void writeItem(Object item, IItemWriteHandler handler) throws IOExceptio
handler.writeItemFlag(item, this);
}

@Override
default boolean canHandleJsonPropertyName(@NonNull String name) {
return name.equals(getJsonName());
}

@Override
default boolean canHandleXmlQName(@NonNull QName qname) {
return qname.equals(getXmlQName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
*/
public interface IBoundInstanceModelAssembly
extends IBoundInstanceModelNamedComplex, IAssemblyInstanceAbsolute {

/**
* Create a new bound assembly instance.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,6 @@ default Object deepCopyItem(Object item, Object parentInstance) throws BindingEx
return itemInstance.deepCopyItem(itemInstance, parentInstance);
}

@Override
default boolean canHandleJsonPropertyName(@NonNull String name) {
return name.equals(getJsonName());
}

@Override
default boolean canHandleXmlQName(@NonNull QName qname) {
return getGroupedModelInstance(qname) != null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

import gov.nist.secauto.metaschema.core.model.IContainerFlagSupport;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
import gov.nist.secauto.metaschema.databind.IBindingContext;
import gov.nist.secauto.metaschema.databind.model.info.IFeatureScalarItemValueHandler;
import gov.nist.secauto.metaschema.databind.model.info.IItemReadHandler;
import gov.nist.secauto.metaschema.databind.model.info.IItemWriteHandler;
Expand Down Expand Up @@ -57,11 +56,6 @@ default IBoundInstanceModelFieldScalar getInlineInstance() {
return IFeatureBoundDefinitionInline.super.getInlineInstance();
}

@Override
default IBindingContext getBindingContext() {
return getContainingDefinition().getBindingContext();
}

@Override
default IContainerFlagSupport<IBoundInstanceFlag> getFlagContainer() {
getJsonName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,4 @@ default Collection<? extends Object> getItemValues(Object value) {
default boolean canHandleXmlQName(QName qname) {
return qname.equals(getXmlQName());
}

@Override
default boolean canHandleJsonPropertyName(@NonNull String name) {
return name.equals(getJsonName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,6 @@
* definition, instance, field value.
*/
public interface IBoundModuleElement extends IItemValueHandler {
/**
* Determine if the provided JSON property or YAML key name is associated with
* this instance.
*
* @param name
* the name of the property/key being parsed
* @return {@code true} if the instance will handle this name, or {@code false}
* otherwise
*/
boolean canHandleJsonPropertyName(@NonNull String name);

/**
* Determine if the provided XML qualified name is associated with this
* property.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@

package gov.nist.secauto.metaschema.databind.model;

import gov.nist.secauto.metaschema.core.model.IDefinition;
import gov.nist.secauto.metaschema.core.model.IFeatureDefinitionInstanceInlined;
import gov.nist.secauto.metaschema.core.model.IModule;

import edu.umd.cs.findbugs.annotations.NonNull;

// REFACTOR: Try to eliminate this interface in favor of IFeatureInlinedDefinitionInstance
public interface IFeatureBoundDefinitionInline<
DEFINITION extends IBoundDefinition,
DEFINITION extends IDefinition & IBoundModuleElement,
INSTANCE extends IBoundInstanceNamed>
extends IBoundDefinition, IBoundInstanceNamed,
extends IBoundInstanceNamed,
IFeatureDefinitionInstanceInlined<DEFINITION, INSTANCE> {
//
// @Override
Expand All @@ -50,7 +52,7 @@ public interface IFeatureBoundDefinitionInline<
*/
@Override
@NonNull
default IBoundModule getContainingModule() {
default IModule getContainingModule() {
// this is the same as IBoundInstance, but is needed since IBoundDefinition
// and IBoundInstance both declare it
return getContainingDefinition().getContainingModule();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import gov.nist.secauto.metaschema.core.model.constraint.IValueConstrained;
import gov.nist.secauto.metaschema.core.model.constraint.ValueConstraintSet;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
import gov.nist.secauto.metaschema.databind.IBindingContext;
import gov.nist.secauto.metaschema.databind.model.IBoundDefinitionFlag;
import gov.nist.secauto.metaschema.databind.model.IBoundDefinitionModel;
import gov.nist.secauto.metaschema.databind.model.IBoundInstanceFlag;
Expand Down Expand Up @@ -184,11 +183,6 @@ public MarkupMultiline getRemarks() {
return ModelUtil.resolveToMarkupMultiline(getAnnotation().remarks());
}

@Override
public IBindingContext getBindingContext() {
return getContainingDefinition().getBindingContext();
}

// ----------------------------------------
// - End annotation driven code - CPD-OFF -
// ----------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import gov.nist.secauto.metaschema.core.model.constraint.IValueConstrained;
import gov.nist.secauto.metaschema.core.model.constraint.ValueConstraintSet;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
import gov.nist.secauto.metaschema.databind.IBindingContext;
import gov.nist.secauto.metaschema.databind.model.IBoundDefinitionModelAssembly;
import gov.nist.secauto.metaschema.databind.model.IBoundDefinitionModelField;
import gov.nist.secauto.metaschema.databind.model.IBoundInstanceFlag;
Expand Down Expand Up @@ -143,6 +144,11 @@ private InstanceModelFieldScalar(
}));
}

@Override
public IBindingContext getBindingContext() {
return getContainingDefinition().getBindingContext();
}

@Override
public Field getField() {
return javaField;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonParser;

import gov.nist.secauto.metaschema.core.model.IModule;
import gov.nist.secauto.metaschema.databind.io.json.MetaschemaJsonReader;

import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -61,7 +62,7 @@ void testMinimalJsonParse() throws JsonParseException, IOException {
@Test
void testModule() {
IBoundDefinitionModelAssembly definition = getRootAssemblyClassBinding();
IBoundModule module = definition.getContainingModule();
IModule module = definition.getContainingModule();
assertNotNull(module, "metaschema was null");
}

Expand Down

0 comments on commit dd82fc7

Please sign in to comment.