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 4, 2024
1 parent bf717b5 commit 9673a7b
Show file tree
Hide file tree
Showing 21 changed files with 161 additions and 304 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@

import java.io.IOException;

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

public interface IBoundInstanceModelFieldScalar
extends IBoundInstanceModelField,
IBoundDefinitionModelField, IFeatureScalarItemValueHandler,
Expand All @@ -46,47 +44,32 @@ public interface IBoundInstanceModelFieldScalar
// integrate above

@Override
IBoundDefinitionModelAssembly getContainingDefinition();
default IBoundDefinitionModelField getDefinition() {
return IFeatureBoundDefinitionInline.super.getDefinition();
}

@Override
default IBoundInstanceModelFieldScalar getInstance() {
return this;
}
IBoundDefinitionModelAssembly getContainingDefinition();

/**
* {@inheritDoc}
* <p>
* For an inline instance, this instance is the definition.
*/
@Override
default IBoundInstanceModelFieldScalar getDefinition() {
default IBoundInstanceModelFieldScalar getInstance() {
return this;
}

@Override
default IBoundInstanceModelFieldScalar getInlineInstance() {
// always inline
return this;
// TODO Auto-generated method stub
return IFeatureBoundDefinitionInline.super.getInlineInstance();
}

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

/**
* {@inheritDoc}
* <p>
* Use the effective name of the instance.
*/
@Override
@NonNull
default String getJsonName() {
return IBoundInstanceModelField.super.getJsonName();
}

@Override
default IContainerFlagSupport<IBoundInstanceFlag> getFlagContainer() {
getJsonName();
return IContainerFlagSupport.empty();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import gov.nist.secauto.metaschema.core.model.INamedModelInstanceGrouped;
import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
import gov.nist.secauto.metaschema.databind.io.BindingException;
import gov.nist.secauto.metaschema.databind.model.info.IFeatureComplexItemValueHandler;

import edu.umd.cs.findbugs.annotations.Nullable;
Expand Down Expand Up @@ -59,4 +60,29 @@ default IBoundInstanceFlag getJsonKey() {
? null
: ObjectUtils.requireNonNull(getDefinition().getFlagInstanceByName(getContainingModule().toFlagQName(name)));
}

@Override
default IBoundDefinitionModelAssembly getContainingDefinition() {
return getParentContainer().getContainingDefinition();
}

@Override
default String getName() {
return getDefinition().getName();
}

@Override
default Object deepCopyItem(Object item, Object parentInstance) throws BindingException {
return getDefinition().deepCopyItem(item, parentInstance);
}

@Override
default void callBeforeDeserialize(Object targetObject, Object parentObject) throws BindingException {
getDefinition().callBeforeDeserialize(targetObject, parentObject);
}

@Override
default void callAfterDeserialize(Object targetObject, Object parentObject) throws BindingException {
getDefinition().callAfterDeserialize(targetObject, parentObject);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;

public interface IBoundInstanceModelNamed extends IBoundInstanceModel, INamedModelInstanceAbsolute {
public interface IBoundInstanceModelNamed
extends IBoundInstanceModel, IBoundInstanceNamed, INamedModelInstanceAbsolute {

@Override
@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@ default IBoundModule getContainingModule() {
// and IBoundInstance both declare it
return getContainingDefinition().getContainingModule();
}

/**
* {@inheritDoc}
* <p>
* Use the effective name of the instance.
*/
@Override
default String getJsonName() {
// this is the same as INamedModelElement, but is needed since IBoundProperty
// also declares it
return getEffectiveName();
}
//
// /**
// * {@inheritDoc}
// * <p>
// * Use the effective name of the instance.
// */
// @Override
// default String getJsonName() {
// // this is the same as INamedModelElement, but is needed since IBoundProperty
// // also declares it
// return getEffectiveName();
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior;
import gov.nist.secauto.metaschema.core.model.XmlGroupAsBehavior;

import javax.xml.namespace.QName;

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

Expand All @@ -39,12 +41,7 @@ public interface IGroupAs {
@NonNull
IGroupAs SINGLETON_GROUP_AS = new IGroupAs() {
@Override
public String getGroupAsName() {
return null;
}

@Override
public String getGroupAsXmlNamespace() {
public QName getGroupAsQName() {
return null;
}

Expand All @@ -60,10 +57,19 @@ public XmlGroupAsBehavior getXmlGroupAsBehavior() {
};

@Nullable
String getGroupAsName();
QName getGroupAsQName();

@Nullable
default String getGroupAsName() {
QName qname = getGroupAsQName();
return qname == null ? null : qname.getLocalPart();
}

@Nullable
String getGroupAsXmlNamespace();
default String getGroupAsXmlNamespace() {
QName qname = getGroupAsQName();
return qname == null ? null : qname.getNamespaceURI();
}

@NonNull
JsonGroupAsBehavior getJsonGroupAsBehavior();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,6 @@
*/
int useIndex() default Integer.MIN_VALUE;

/**
* The namespace to use for associated XML elements.
* <p>
* If the value is "##default", then element name is derived from the namespace
* provided in the package-info.
*
* @return the namespace
*/
@NonNull
String namespace() default ModelUtil.DEFAULT_STRING_VALUE;

/**
* Get any remarks for this field.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,6 @@
@NonNull
Class<? extends IDataTypeAdapter<?>> typeAdapter() default NullJavaTypeAdapter.class;

/**
* The namespace to use for associated XML elements.
* <p>
* If the value is "##default", then element name is derived from the namespace
* provided in the package-info.
*
* @return the namespace
*/
String namespace() default ModelUtil.DEFAULT_STRING_VALUE;

/**
* Get any remarks for this field.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,6 @@
@NonNull
String name();

/**
* XML target namespace of the XML grouping element.
* <p>
* If the value is "##default", then element name is derived from the namespace
* provided in the package-info.
*
* @return the namespace
*/
@NonNull
String namespace() default ModelUtil.DEFAULT_STRING_VALUE;

/**
* Describes how to handle collections in JSON/YAML.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,6 @@
*/
int rootIndex() default Integer.MIN_VALUE;

/**
* XML target namespace of the XML element.
* <p>
* If the value is "##default", then namespace is derived from the namespace
* provided in the package-info.
*
* @return the namespace
*/
@NonNull
String rootNamespace() default ModelUtil.DEFAULT_STRING_VALUE;

/**
* Get any remarks for this assembly.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
import gov.nist.secauto.metaschema.core.datatype.adapter.MetaschemaDataTypeProvider;
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine;
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline;
import gov.nist.secauto.metaschema.core.model.IModule;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
import gov.nist.secauto.metaschema.databind.IBindingContext;
import gov.nist.secauto.metaschema.databind.model.IGroupAs;
import gov.nist.secauto.metaschema.databind.model.impl.DefaultGroupAs;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.function.Supplier;

import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
Expand Down Expand Up @@ -112,43 +112,6 @@ public static String resolveNoneOrDefault(@Nullable String value, @Nullable Stri
return retval;
}

@Nullable
public static String resolveOptionalNamespace(
@Nullable String annotationValue,
@NonNull Supplier<String> defaultSupplier) {
return resolveNamespace(annotationValue, true, defaultSupplier);
}

/**
* Resolves a provided namespace value. If the value is {@code null} or
* "##default", then the provided default value will be used instead. If the
* value is "##none" and {@code allowNone} is {@code true}, then an empty string
* value will be used. Otherwise, the value is returned.
*
* @param value
* the requested value
* @param definition
* a class with the {@link XmlSchema} annotation
* @param allowNone
* if the "##none" value is honored
* @return the resolved value or {@code null} if no namespace is defined
*/
private static String resolveNamespace(
@Nullable String value,
boolean allowNone,
@NonNull Supplier<String> defaultSupplier) {
String retval;
if (value == null || DEFAULT_STRING_VALUE.equals(value)) {
// get namespace from the metaschema
retval = defaultSupplier.get();
} else if (allowNone && NO_STRING_VALUE.equals(value)) {
retval = ""; // NOPMD - intentional
} else {
retval = value;
}
return retval;
}

/**
* Get the processed value of a string. If the value is "##none", then the value
* will be {@code null}. Otherwise the value is returned.
Expand Down Expand Up @@ -225,9 +188,9 @@ public static Object resolveNullOrValue(
@NonNull
public static IGroupAs groupAs(
@NonNull GroupAs groupAs,
@NonNull Supplier<String> defaultSupplier) {
@NonNull IModule module) {
return NULL_VALUE.equals(groupAs.name())
? IGroupAs.SINGLETON_GROUP_AS
: new DefaultGroupAs(groupAs, defaultSupplier);
: new DefaultGroupAs(groupAs, module);
}
}
Loading

0 comments on commit 9673a7b

Please sign in to comment.