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 2918db8 commit e867ad2
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 300 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public IContainerFlagSupport<T> build() {
Map<QName, T> flagMap = CollectionUtil.unmodifiableMap(ObjectUtils.notNull(flags.stream()
.collect(
CustomCollectors.toMap(
INamedModelElement::getXmlQName,
INamed::getXmlQName,
CustomCollectors.identity(),
FlagContainerBuilder::handleShadowedInstances,
LinkedHashMap::new))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,28 @@ public interface IDescribable {
// from INamedModelElement
@Nullable
MarkupLine getDescription();

/**
* The resolved formal display name, which allows an instance to override a
* definition's name.
*
* @return the formal name or {@code null} if not defined
*/
// from INamedModelElement
@Nullable
default String getEffectiveFormalName() {
return getFormalName();
}

/**
* Get the text that describes the basic use of the element, which allows an
* instance to override a definition's description.
*
* @return a line of markup text or {@code null} if not defined
*/
// from INamedModelElement
@Nullable
default MarkupLine getEffectiveDescription() {
return getDescription();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,167 +26,15 @@

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

import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine;

import javax.xml.XMLConstants;
import javax.xml.namespace.QName;

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

/**
* A marker interface for Metaschema constructs that can be members of a
* Metaschema module's model that have a name and other identifying
* characteristics.
*/
public interface INamedModelElement extends IDescribable, IModelElement {
/**
* The resolved formal display name, which allows an instance to override a
* definition's name.
*
* @return the formal name or {@code null} if not defined
*/
// from INamedModelElement
@Nullable
default String getEffectiveFormalName() {
return getFormalName();
}

/**
* Get the text that describes the basic use of the element, which allows an
* instance to override a definition's description.
*
* @return a line of markup text or {@code null} if not defined
*/
// from INamedModelElement
@Nullable
default MarkupLine getEffectiveDescription() {
return getDescription();
}

/**
* Retrieve the name of the model element.
*
* @return the name
*/
@NonNull
String getName();

/**
* Retrieve the name to use for the model element, instead of the name.
*
* @return the use name or {@code null} if no use name is defined
*/
// from INamedModelElement
@Nullable
default String getUseName() {
// no use-name by default
return null;
}

/**
* Get the name to use based on the provided names. This method will return the
* use name provided by {@link #getUseName()} if the call is not {@code null},
* and fall back to the name provided by {@link #getName()} otherwise. This is
* the model name to use for the for an instance where the instance is
* referenced.
*
* @return the use name if available, or the name if not
*
* @see #getUseName()
* @see #getName()
*/
// from INamedModelElement
@NonNull
default String getEffectiveName() {
@Nullable String useName = getUseName();
return useName == null ? getName() : useName;
}

/**
* Retrieve the XML namespace for this instance.
* <p>
* Multiple calls to this method are expected to produce the same, deterministic
* return value.
*
* @return the XML namespace or {@code null} if no namespace is defined
*/
@Nullable
default String getXmlNamespace() {
return getXmlQName().getNamespaceURI();
}

/**
* Get the unique XML qualified name for this model element.
* <p>
* The qualified name is considered to be unique relative to all sibling
* elements. For a flag, this name will be unique among all flag instances on
* the same field or assembly definition. For a field or assembly, this name
* will be unique among all sibling field or assembly instances on the same
* assembly definition.
* <p>
* Multiple calls to this method are expected to produce the same, deterministic
* return value.
* <p>
* If {@link #getXmlNamespace()} is {@code null}, the the resulting QName will
* have the namespace {@link XMLConstants#NULL_NS_URI}.
* <p>
* This implementation may be overridden by implementation that cache the QName
* or provide for a more efficient method for QName creation.
*
* @return the XML qualified name, or {@code null} if there isn't one
*/
// REFACTOR: rename to getQName
@NonNull
QName getXmlQName();

/**
* Retrieve the index value to use for binary naming.
*
* @return the name index or {@code null} if no name index is defined
*/
// from INamedModelElement
@Nullable
default Integer getIndex() {
// no index by default
return null;
}

/**
* Retrieve the index value to use for binary naming, instead of the name.
*
* @return the use name index or {@code null} if no use name index is defined
*/
// from INamedModelElement
@Nullable
default Integer getUseIndex() {
// no use-name index by default
return null;
}

/**
* Get the index value to use for binary naming based on the provided index
* values.
* <p>
* This method will return the use index value provided by
* {@link #getUseIndex()} if the call result is not {@code null}, and fall back
* to the index value provided by {@link #getIndex()} otherwise.
*
* @return the index value if available, or {@code null} otherwise
*/
// from INamedModelElement
@Nullable
default Integer getEffectiveIndex() {
@Nullable Integer useIndex = getUseIndex();
return useIndex == null ? getIndex() : useIndex;
}

/**
* Get the name used for the associated property in JSON/YAML.
*
* @return the JSON property name
*/
// from INamedModelElement
public interface INamedModelElement extends IDescribable, IModelElement, IJsonNamed, INamed {
@Override
@NonNull
default String getJsonName() {
return getEffectiveName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,6 @@ public <CLASS> CLASS deepCopy(@NonNull CLASS other, Object parentInstance) throw
if (definition == null) {
throw new IllegalStateException(String.format("Class '%s' is not bound", other.getClass().getName()));
}
return (CLASS) definition.deepCopyItem(other, parentInstance);
return ObjectUtils.asType(definition.deepCopyItem(other, parentInstance));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

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

import gov.nist.secauto.metaschema.core.model.IFeatureDefinitionInstanceInlined;
import gov.nist.secauto.metaschema.core.model.IFlagInstance;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
import gov.nist.secauto.metaschema.databind.io.BindingException;
Expand All @@ -48,7 +49,7 @@
public interface IBoundInstanceFlag
extends IFlagInstance, IBoundDefinitionFlag,
IFeatureScalarItemValueHandler,
IFeatureBoundDefinitionInline<IBoundDefinitionFlag, IBoundInstanceFlag> {
IBoundInstance, IFeatureDefinitionInstanceInlined<IBoundDefinitionFlag, IBoundInstanceFlag> {

/**
* Create a new bound flag instance.
Expand Down Expand Up @@ -123,7 +124,7 @@ default IBoundInstanceFlag getInlineInstance() {
@Override
@Nullable
default Object getValue(@NonNull Object parent) {
return IFeatureBoundDefinitionInline.super.getValue(parent);
return IBoundInstance.super.getValue(parent);
}

/**
Expand All @@ -133,7 +134,7 @@ default Object getValue(@NonNull Object parent) {
*/
@Override
default void setValue(@NonNull Object parentObject, @Nullable Object value) {
IFeatureBoundDefinitionInline.super.setValue(parentObject, value);
IBoundInstance.super.setValue(parentObject, value);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
package gov.nist.secauto.metaschema.databind.model;

import gov.nist.secauto.metaschema.core.model.IContainerFlagSupport;
import gov.nist.secauto.metaschema.core.model.IFeatureDefinitionInstanceInlined;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
import gov.nist.secauto.metaschema.databind.model.info.IFeatureScalarItemValueHandler;
import gov.nist.secauto.metaschema.databind.model.info.IItemReadHandler;
Expand All @@ -37,28 +38,25 @@
public interface IBoundInstanceModelFieldScalar
extends IBoundInstanceModelField,
IBoundDefinitionModelField, IFeatureScalarItemValueHandler,
IFeatureBoundDefinitionInline<IBoundDefinitionModelField, IBoundInstanceModelFieldScalar>,
IFeatureDefinitionInstanceInlined<IBoundDefinitionModelField, IBoundInstanceModelFieldScalar>,
IFeatureBoundContainerFlag {

// integrate above

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

@Override
IBoundDefinitionModelAssembly getContainingDefinition();

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

@Override
IBoundDefinitionModelAssembly getContainingDefinition();

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import edu.umd.cs.findbugs.annotations.Nullable;

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

@Override
@NonNull
Expand All @@ -55,11 +55,6 @@ default Integer getIndex() {
return getDefinition().getIndex();
}

@Override
default String getJsonName() {
return INamedModelInstanceAbsolute.super.getJsonName();
}

@Override
@Nullable
default IBoundInstanceFlag getEffectiveJsonKey() {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,12 @@

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

import gov.nist.secauto.metaschema.core.model.IJsonNamed;
import gov.nist.secauto.metaschema.databind.io.BindingException;

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

public interface IBoundProperty extends IBoundModuleElement, IFeatureJavaField {
/**
* Get the JSON/YAML property/key name to use for serialization-related
* operations.
*
* @return the JSON name
*/
// REFACTOR: rename to getEffectiveJsonName
@NonNull
String getJsonName();

public interface IBoundProperty extends IBoundModuleElement, IFeatureJavaField, IJsonNamed {
/**
* Copy this instance from one parent object to another.
*
Expand Down
Loading

0 comments on commit e867ad2

Please sign in to comment.