From ece3b634df2e623270a688ef5681712efd6d726e Mon Sep 17 00:00:00 2001 From: David Waltermire Date: Mon, 18 Nov 2024 09:29:48 -0500 Subject: [PATCH] WIP --- .../AbstractCustomJavaDataTypeAdapter.java | 10 +- .../datatype/AbstractDataTypeAdapter.java | 29 ++- .../core/datatype/DataTypeService.java | 89 ++++----- .../core/datatype/IDataTypeAdapter.java | 13 +- .../adapter/AbstractIntegerAdapter.java | 10 +- .../adapter/AbstractStringAdapter.java | 9 +- .../core/datatype/adapter/Base64Adapter.java | 19 +- .../core/datatype/adapter/BooleanAdapter.java | 17 +- .../core/datatype/adapter/DateAdapter.java | 17 +- .../datatype/adapter/DateTimeAdapter.java | 19 +- .../adapter/DateTimeWithTZAdapter.java | 19 +- .../datatype/adapter/DateWithTZAdapter.java | 18 +- .../core/datatype/adapter/DayTimeAdapter.java | 17 +- .../core/datatype/adapter/DecimalAdapter.java | 17 +- .../datatype/adapter/EmailAddressAdapter.java | 20 +- .../datatype/adapter/HostnameAdapter.java | 17 +- .../datatype/adapter/IPv4AddressAdapter.java | 17 +- .../datatype/adapter/IPv6AddressAdapter.java | 17 +- .../core/datatype/adapter/IntegerAdapter.java | 17 +- .../core/datatype/adapter/NcNameAdapter.java | 19 +- .../adapter/NonNegativeIntegerAdapter.java | 18 +- .../adapter/PositiveIntegerAdapter.java | 18 +- .../core/datatype/adapter/StringAdapter.java | 16 +- .../core/datatype/adapter/TokenAdapter.java | 16 +- .../core/datatype/adapter/UriAdapter.java | 17 +- .../datatype/adapter/UriReferenceAdapter.java | 17 +- .../core/datatype/adapter/UuidAdapter.java | 17 +- .../datatype/adapter/YearMonthAdapter.java | 17 +- .../markup/AbstractMarkupAdapter.java | 9 +- .../datatype/markup/MarkupLineAdapter.java | 14 +- .../markup/MarkupMultilineAdapter.java | 13 +- .../metaschema/core/metapath/EQNameUtils.java | 29 ++- .../core/metapath/StaticContext.java | 35 +++- .../metapath/cst/ICstExpressionFactory.java | 145 +++++++++++++++ .../metapath/cst/impl/TypeTestSupport.java | 2 +- .../core/metapath/function/IArgument.java | 41 +++- .../core/metapath/function/IFunction.java | 39 +++- .../InvalidTypeFunctionException.java | 2 +- .../function/library/ArrayAppend.java | 6 +- .../function/library/ArrayFlatten.java | 4 +- .../metapath/function/library/ArrayGet.java | 6 +- .../metapath/function/library/ArrayHead.java | 4 +- .../function/library/ArrayInsertBefore.java | 8 +- .../metapath/function/library/ArrayJoin.java | 4 +- .../metapath/function/library/ArrayPut.java | 8 +- .../function/library/ArrayRemove.java | 6 +- .../function/library/ArrayReverse.java | 4 +- .../metapath/function/library/ArraySize.java | 4 +- .../function/library/ArraySubarray.java | 14 +- .../metapath/function/library/ArrayTail.java | 4 +- .../function/library/CastFunction.java | 7 +- .../library/DefaultFunctionLibrary.java | 27 ++- .../core/metapath/function/library/FnAbs.java | 4 +- .../core/metapath/function/library/FnAvg.java | 4 +- .../metapath/function/library/FnBaseUri.java | 6 +- .../metapath/function/library/FnBoolean.java | 4 +- .../metapath/function/library/FnCeiling.java | 4 +- .../metapath/function/library/FnCompare.java | 6 +- .../metapath/function/library/FnConcat.java | 6 +- .../metapath/function/library/FnContains.java | 7 +- .../metapath/function/library/FnCount.java | 4 +- .../function/library/FnCurrentDateTime.java | 2 +- .../metapath/function/library/FnData.java | 6 +- .../core/metapath/function/library/FnDoc.java | 4 +- .../function/library/FnDocumentAvailable.java | 4 +- .../function/library/FnDocumentUri.java | 6 +- .../metapath/function/library/FnEmpty.java | 4 +- .../metapath/function/library/FnEndsWith.java | 7 +- .../metapath/function/library/FnExists.java | 4 +- .../metapath/function/library/FnFalse.java | 2 +- .../metapath/function/library/FnHead.java | 4 +- .../function/library/FnInsertBefore.java | 8 +- .../function/library/FnLowerCase.java | 4 +- .../metapath/function/library/FnMatches.java | 14 +- .../metapath/function/library/FnMinMax.java | 8 +- .../function/library/FnNormalizeSpace.java | 6 +- .../core/metapath/function/library/FnNot.java | 4 +- .../metapath/function/library/FnPath.java | 6 +- .../metapath/function/library/FnRemove.java | 6 +- .../function/library/FnResolveUri.java | 10 +- .../metapath/function/library/FnReverse.java | 4 +- .../metapath/function/library/FnRound.java | 10 +- .../function/library/FnStartsWith.java | 7 +- .../function/library/FnStaticBaseUri.java | 4 +- .../metapath/function/library/FnString.java | 6 +- .../function/library/FnStringLength.java | 6 +- .../function/library/FnSubstring.java | 14 +- .../function/library/FnSubstringAfter.java | 6 +- .../function/library/FnSubstringBefore.java | 6 +- .../core/metapath/function/library/FnSum.java | 10 +- .../metapath/function/library/FnTail.java | 4 +- .../metapath/function/library/FnTokenize.java | 18 +- .../metapath/function/library/FnTrue.java | 2 +- .../function/library/FnUpperCase.java | 4 +- .../function/library/MapContains.java | 6 +- .../metapath/function/library/MapEntry.java | 6 +- .../metapath/function/library/MapFind.java | 6 +- .../metapath/function/library/MapGet.java | 6 +- .../metapath/function/library/MapKeys.java | 4 +- .../metapath/function/library/MapMerge.java | 10 +- .../metapath/function/library/MapPut.java | 8 +- .../metapath/function/library/MapRemove.java | 6 +- .../metapath/function/library/MapSize.java | 4 +- .../function/library/MpRecurseDepth.java | 10 +- .../function/library/NumericFunction.java | 4 +- .../core/metapath/impl/AbstractArrayItem.java | 5 +- .../core/metapath/impl/AbstractMapItem.java | 5 +- .../metaschema/core/metapath/item/IItem.java | 5 + .../core/metapath/item/TypeSystem.java | 144 -------------- .../metapath/item/atomic/IAnyAtomicItem.java | 6 + .../metapath/item/atomic/IAnyUriItem.java | 8 +- .../item/atomic/IBase64BinaryItem.java | 7 +- .../metapath/item/atomic/IBooleanItem.java | 8 +- .../core/metapath/item/atomic/IDateItem.java | 8 +- .../metapath/item/atomic/IDateTimeItem.java | 8 +- .../item/atomic/IDayTimeDurationItem.java | 8 +- .../metapath/item/atomic/IDecimalItem.java | 8 +- .../metapath/item/atomic/IDurationItem.java | 7 + .../item/atomic/IEmailAddressItem.java | 11 +- .../metapath/item/atomic/IHostnameItem.java | 8 +- .../metapath/item/atomic/IIPAddressItem.java | 7 + .../item/atomic/IIPv4AddressItem.java | 7 +- .../item/atomic/IIPv6AddressItem.java | 7 +- .../metapath/item/atomic/IIntegerItem.java | 9 +- .../metapath/item/atomic/IMarkupItem.java | 9 +- .../metapath/item/atomic/INcNameItem.java | 8 +- .../item/atomic/INonNegativeIntegerItem.java | 6 + .../metapath/item/atomic/INumericItem.java | 8 +- .../item/atomic/IPositiveIntegerItem.java | 9 +- .../metapath/item/atomic/IStringItem.java | 8 +- .../metapath/item/atomic/ITemporalItem.java | 8 + .../core/metapath/item/atomic/ITokenItem.java | 8 +- .../item/atomic/IUriReferenceItem.java | 8 +- .../core/metapath/item/atomic/IUuidItem.java | 8 +- .../item/atomic/IYearMonthDurationItem.java | 8 +- .../item/atomic/impl/AtomicItemConstants.java | 42 +++++ .../item/atomic/impl/IPv4AddressItemImpl.java | 1 - .../item/atomic/impl/IPv6AddressItemImpl.java | 1 - .../item/atomic/impl/StringItemImpl.java | 1 - .../metapath/item/function/IArrayItem.java | 6 + .../core/metapath/item/function/IMapItem.java | 6 + .../metapath/item/node/IAssemblyNodeItem.java | 4 +- .../metapath/item/node/IDocumentNodeItem.java | 10 +- .../metapath/item/node/IFieldNodeItem.java | 6 +- .../metapath/item/node/IFlagNodeItem.java | 10 +- .../metapath/item/node/IModuleNodeItem.java | 4 +- .../core/metapath/item/node/INodeItem.java | 12 +- .../{NodeItemType.java => NodeItemKind.java} | 4 +- .../core/metapath/type/IArrayType.java | 5 +- .../metapath/type/IAtomicOrUnionType.java | 20 +- .../core/metapath/type/IItemType.java | 50 +++-- .../core/metapath/type/IMapTest.java | 5 +- .../core/metapath/type/ISequenceType.java | 16 +- .../core/metapath/type/TypeSystem.java | 114 +++++------- .../metapath/type/impl/AbstractItemType.java | 5 - .../type/impl/AbstractNodeItemType.java | 39 ---- .../metapath/type/impl/AnyAtomicItemType.java | 27 +++ .../core/metapath/type/impl/AnyItemType.java | 2 +- .../metapath/type/impl/AnyRawItemType.java | 6 +- .../metapath/type/impl/ArrayTypeImpl.java | 25 +-- .../metapath/type/impl/DataTypeItemType.java | 29 ++- .../core/metapath/type/impl/NodeItemType.java | 51 +++++ .../type/impl/NonAdapterAtomicItemType.java | 32 ++++ .../metapath/type/impl/SequenceTypeImpl.java | 19 +- .../model/util/MermaidErDiagramGenerator.java | 5 +- .../xmlbeans/handler/DatatypesHandler.java | 8 +- .../metaschema/core/qname/IEnhancedQName.java | 39 ++++ .../metaschema/core/qname/NamespaceCache.java | 74 ++++++++ .../metaschema/core/qname/QNameCache.java | 175 ++++++++++++++++++ core/src/main/java/module-info.java | 1 + .../MetaschemaDataTypeProviderTest.java | 6 +- .../core/metapath/cst/FlagTest.java | 6 +- .../core/metapath/type/ISequenceTypeTest.java | 2 +- .../metaschema/core/qname/QNameCacheTest.java | 36 ++++ .../metaschema/databind/IBindingContext.java | 2 +- .../model/impl/ConstraintFactory.java | 2 +- .../model/metaschema/impl/ModelSupport.java | 4 +- 177 files changed, 1639 insertions(+), 943 deletions(-) create mode 100644 core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/ICstExpressionFactory.java delete mode 100644 core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/TypeSystem.java create mode 100644 core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/AtomicItemConstants.java rename core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/{NodeItemType.java => NodeItemKind.java} (81%) delete mode 100644 core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/AbstractNodeItemType.java create mode 100644 core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/AnyAtomicItemType.java create mode 100644 core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/NodeItemType.java create mode 100644 core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/NonAdapterAtomicItemType.java create mode 100644 core/src/main/java/gov/nist/secauto/metaschema/core/qname/IEnhancedQName.java create mode 100644 core/src/main/java/gov/nist/secauto/metaschema/core/qname/NamespaceCache.java create mode 100644 core/src/main/java/gov/nist/secauto/metaschema/core/qname/QNameCache.java create mode 100644 core/src/test/java/gov/nist/secauto/metaschema/core/qname/QNameCacheTest.java diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/AbstractCustomJavaDataTypeAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/AbstractCustomJavaDataTypeAdapter.java index b5e81cdc9..e2fd9d3d4 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/AbstractCustomJavaDataTypeAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/AbstractCustomJavaDataTypeAdapter.java @@ -29,11 +29,15 @@ public abstract class AbstractCustomJavaDataTypeAdapter< * Construct a new Java type adapter for the class based on * {@link ICustomJavaDataType}. * - * @param clazz + * @param valueClass * a data type class based on {@link ICustomJavaDataType} + * @param itemClass + * the Java type of the Matepath item this adapter supports */ - public AbstractCustomJavaDataTypeAdapter(@NonNull Class clazz) { - super(clazz); + public AbstractCustomJavaDataTypeAdapter( + @NonNull Class valueClass, + @NonNull Class itemClass) { + super(valueClass, itemClass); } @SuppressWarnings("unchecked") diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/AbstractDataTypeAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/AbstractDataTypeAdapter.java index 25f306bfc..a3b99f96e 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/AbstractDataTypeAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/AbstractDataTypeAdapter.java @@ -9,6 +9,8 @@ import com.fasterxml.jackson.core.JsonParser; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyAtomicItem; +import gov.nist.secauto.metaschema.core.metapath.type.IAtomicOrUnionType; +import gov.nist.secauto.metaschema.core.metapath.type.impl.DataTypeItemType; import gov.nist.secauto.metaschema.core.model.util.JsonUtil; import gov.nist.secauto.metaschema.core.model.util.XmlEventUtil; import gov.nist.secauto.metaschema.core.util.ObjectUtils; @@ -47,16 +49,23 @@ public abstract class AbstractDataTypeAdapter clazz; + private final Class valueClass; + @NonNull + private final IAtomicOrUnionType itemType; /** * Construct a new Java type adapter for a provided class. * - * @param clazz - * the Java type this adapter supports + * @param valueClass + * the Java value object type this adapter supports + * @param itemClass + * the Java type of the Matepath item this adapter supports */ - protected AbstractDataTypeAdapter(@NonNull Class clazz) { - this.clazz = clazz; + protected AbstractDataTypeAdapter( + @NonNull Class valueClass, + @NonNull Class itemClass) { + this.valueClass = valueClass; + this.itemType = new DataTypeItemType<>(this, itemClass); } @Override @@ -67,7 +76,12 @@ public TYPE toValue(Object value) { @Override public Class getJavaClass() { - return clazz; + return valueClass; + } + + @Override + public IAtomicOrUnionType getItemType() { + return itemType; } @Override @@ -191,9 +205,6 @@ public void writeJsonValue(Object value, JsonGenerator generator) throws IOExcep } } - @Override - public abstract Class getItemClass(); - @Override public abstract ITEM_TYPE newItem(Object value); } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/DataTypeService.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/DataTypeService.java index 264b4d62b..b564436aa 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/DataTypeService.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/DataTypeService.java @@ -5,7 +5,11 @@ package gov.nist.secauto.metaschema.core.datatype; +import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyAtomicItem; +import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; +import gov.nist.secauto.metaschema.core.qname.QNameCache; import gov.nist.secauto.metaschema.core.util.CustomCollectors; +import gov.nist.secauto.metaschema.core.util.ObjectUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -15,7 +19,6 @@ import java.util.ServiceLoader; import java.util.ServiceLoader.Provider; import java.util.concurrent.ConcurrentHashMap; -import java.util.function.Function; import java.util.stream.Collectors; import javax.xml.namespace.QName; @@ -30,11 +33,11 @@ */ public final class DataTypeService { private static final Logger LOGGER = LogManager.getLogger(DataTypeService.class); - private static final Lazy INSTANCE = Lazy.lazy(() -> new DataTypeService()); + private static final Lazy INSTANCE = Lazy.lazy(DataTypeService::new); - private final Map> typeByName; - private final Map> typeByQName; - private final Map>, IDataTypeAdapter> typeByClass; + private final Map> typeByQNameIndex; + private final Map>, IDataTypeAdapter> typeByAdapterClass; + private final Map, IDataTypeAdapter> typeByItemClass; /** * Get the singleton service instance, which will be lazy constructed on first @@ -44,21 +47,20 @@ public final class DataTypeService { */ @SuppressWarnings("null") @NonNull - public static DataTypeService getInstance() { + public static DataTypeService instance() { return INSTANCE.get(); } private DataTypeService() { - ServiceLoader loader = ServiceLoader.load(IDataTypeProvider.class); List> dataTypes = loader.stream() .map(Provider::get) .flatMap(provider -> provider.getJavaTypeAdapters().stream()) .collect(Collectors.toList()); - Map> typeByName = dataTypes.stream() + this.typeByQNameIndex = dataTypes.stream() .flatMap(dataType -> dataType.getNames().stream() - .map(qname -> Map.entry(qname.getLocalPart(), dataType))) + .map(qname -> Map.entry(qname.getIndexPosition(), dataType))) .collect(CustomCollectors.toMap( Map.Entry::getKey, Map.Entry::getValue, @@ -73,44 +75,37 @@ private DataTypeService() { }, ConcurrentHashMap::new)); - Map> typeByQName = dataTypes.stream() - .flatMap(dataType -> dataType.getNames().stream() - .map(qname -> Map.entry(qname, dataType))) + this.typeByAdapterClass = dataTypes.stream() .collect(CustomCollectors.toMap( - Map.Entry::getKey, - Map.Entry::getValue, + dataType -> ObjectUtils.asNullableType(dataType.getClass()), + CustomCollectors.identity(), (key, v1, v2) -> { if (LOGGER.isWarnEnabled()) { - LOGGER.warn("Data types '{}' and '{}' have duplicate name '{}'. Using the first.", - v1.getClass().getName(), - v2.getClass().getName(), - key); + LOGGER.warn("Duplicate data type class '{}'. Using the first.", + key.getClass().getName()); } return v1; }, ConcurrentHashMap::new)); - @SuppressWarnings({ "unchecked", "null" }) - Map>, - IDataTypeAdapter> typeByClass = dataTypes.stream() - .collect(CustomCollectors.toMap( - dataType -> (Class>) dataType.getClass(), - Function.identity(), - (key, v1, v2) -> { - if (LOGGER.isWarnEnabled()) { - LOGGER.warn("Duplicate data type class '{}'. Using the first.", - key.getClass().getName()); - } - return v1; - }, - ConcurrentHashMap::new)); - this.typeByName = typeByName; - this.typeByQName = typeByQName; - this.typeByClass = typeByClass; + this.typeByItemClass = dataTypes.stream() + .collect(CustomCollectors.toMap( + dataType -> ObjectUtils.asNullableType(dataType.getItemType().getItemClass()), + CustomCollectors.identity(), + (key, v1, v2) -> { + if (LOGGER.isWarnEnabled()) { + LOGGER.warn("Duplicate item class '{}' declared by adapters '%s' and '%s'. Using the first.", + key.getClass().getName(), + v1.getClass().getName(), + v2.getClass().getName()); + } + return v1; + }, + ConcurrentHashMap::new)); } /** - * Lookup a specific {@link IDataTypeAdapter} instance by its name. + * Lookup a specific {@link IDataTypeAdapter} instance by its QName. * * @param qname * the qualified name of data type adapter to get the instance for @@ -119,20 +114,23 @@ private DataTypeService() { */ @Nullable public IDataTypeAdapter getJavaTypeAdapterByQName(@NonNull QName qname) { - return typeByQName.get(qname); + IEnhancedQName result = QNameCache.instance().get(qname); + return result == null ? null : getJavaTypeAdapterByQNameIndex(result.getIndexPosition()); } /** - * Lookup a specific {@link IDataTypeAdapter} instance by its name. + * Lookup a specific {@link IDataTypeAdapter} instance by its QName index + * position. * - * @param name - * the name of data type adapter to get the instance for + * @param qnameIndexPosition + * the position in the global QName index for the qualified name of + * data type adapter to get the instance for * @return the instance or {@code null} if the instance is unknown to the type * system */ @Nullable - public IDataTypeAdapter getJavaTypeAdapterByName(@NonNull String name) { - return typeByName.get(name); + public IDataTypeAdapter getJavaTypeAdapterByQNameIndex(int qnameIndexPosition) { + return typeByQNameIndex.get(qnameIndexPosition); } /** @@ -148,6 +146,11 @@ public IDataTypeAdapter getJavaTypeAdapterByName(@NonNull String name) { @SuppressWarnings("unchecked") @Nullable public > TYPE getJavaTypeAdapterByClass(@NonNull Class clazz) { - return (TYPE) typeByClass.get(clazz); + return (TYPE) typeByAdapterClass.get(clazz); + } + + @Nullable + public IDataTypeAdapter getJavaTypeAdapterByItemClass(Class clazz) { + return typeByItemClass.get(clazz); } } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/IDataTypeAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/IDataTypeAdapter.java index 2fb732997..dfd7f6fb9 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/IDataTypeAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/IDataTypeAdapter.java @@ -10,6 +10,8 @@ import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyAtomicItem; +import gov.nist.secauto.metaschema.core.metapath.type.IAtomicOrUnionType; +import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import org.codehaus.stax2.XMLEventReader2; @@ -46,7 +48,7 @@ public interface IDataTypeAdapter { * @return the name */ @NonNull - List getNames(); + List getNames(); /** * Get the most preferred name for this data type. @@ -54,7 +56,7 @@ public interface IDataTypeAdapter { * @return the name */ @NonNull - default QName getPreferredName() { + default IEnhancedQName getPreferredName() { return ObjectUtils.notNull(getNames().iterator().next()); } @@ -121,13 +123,12 @@ default boolean isAtomic() { } /** - * Get the java type of the associated item. + * Get the item type information of the associated item. * - * @return the java associated item type + * @return the item type information */ - // TODO: move to IAnyAtomicItem @NonNull - Class getItemClass(); + IAtomicOrUnionType getItemType(); /** * Construct a new item of this type using the provided value. diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/AbstractIntegerAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/AbstractIntegerAdapter.java index 721fcfadc..1a12d75ec 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/AbstractIntegerAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/AbstractIntegerAdapter.java @@ -14,6 +14,8 @@ import java.io.IOException; import java.math.BigInteger; +import edu.umd.cs.findbugs.annotations.NonNull; + /** * Provides a common base class for integer-based data types. *

@@ -27,9 +29,13 @@ public abstract class AbstractIntegerAdapter /** * Construct a new integer-based adapter. + * + * @param itemClass + * the Java type of the Matepath item this adapter supports */ - protected AbstractIntegerAdapter() { - super(BigInteger.class); + protected AbstractIntegerAdapter( + @NonNull Class itemClass) { + super(BigInteger.class, itemClass); } @Override diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/AbstractStringAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/AbstractStringAdapter.java index b3e399628..0de70598c 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/AbstractStringAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/AbstractStringAdapter.java @@ -10,6 +10,8 @@ import gov.nist.secauto.metaschema.core.datatype.AbstractDataTypeAdapter; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IStringItem; +import edu.umd.cs.findbugs.annotations.NonNull; + /** * Provides a common base class for string-based data types. * @@ -21,9 +23,12 @@ public abstract class AbstractStringAdapter /** * Construct a new string-based adapter. + * + * @param itemClass + * the Java type of the Matepath item this adapter supports */ - protected AbstractStringAdapter() { - super(String.class); + protected AbstractStringAdapter(@NonNull Class itemClass) { + super(String.class, itemClass); } @Override diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/Base64Adapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/Base64Adapter.java index 8c4772744..935ef4f6f 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/Base64Adapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/Base64Adapter.java @@ -10,14 +10,14 @@ import gov.nist.secauto.metaschema.core.datatype.AbstractDataTypeAdapter; import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IBase64BinaryItem; +import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; +import gov.nist.secauto.metaschema.core.qname.QNameCache; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.nio.ByteBuffer; import java.util.Base64; import java.util.List; -import javax.xml.namespace.QName; - import edu.umd.cs.findbugs.annotations.NonNull; /** @@ -28,18 +28,18 @@ public class Base64Adapter extends AbstractDataTypeAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( + private static final List NAMES = ObjectUtils.notNull( List.of( - new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "base64"), + QNameCache.instance().of(MetapathConstants.NS_METAPATH, "base64"), // for backwards compatibility with original type name - new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "base64Binary"))); + QNameCache.instance().of(MetapathConstants.NS_METAPATH, "base64Binary"))); Base64Adapter() { - super(ByteBuffer.class); + super(ByteBuffer.class, IBase64BinaryItem.class); } @Override - public List getNames() { + public List getNames() { return NAMES; } @@ -83,11 +83,6 @@ public String asString(Object value) { return ObjectUtils.notNull(encoder.encodeToString(array)); } - @Override - public Class getItemClass() { - return IBase64BinaryItem.class; - } - @Override public IBase64BinaryItem newItem(Object value) { ByteBuffer item = toValue(value); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/BooleanAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/BooleanAdapter.java index f39cd0363..5ae51c26c 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/BooleanAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/BooleanAdapter.java @@ -12,14 +12,14 @@ import gov.nist.secauto.metaschema.core.datatype.AbstractDataTypeAdapter; import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IBooleanItem; +import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; +import gov.nist.secauto.metaschema.core.qname.QNameCache; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.io.IOException; import java.net.URI; import java.util.List; -import javax.xml.namespace.QName; - import edu.umd.cs.findbugs.annotations.NonNull; /** @@ -30,15 +30,15 @@ public class BooleanAdapter extends AbstractDataTypeAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( - List.of(new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "boolean"))); + private static final List NAMES = ObjectUtils.notNull( + List.of(QNameCache.instance().of(MetapathConstants.NS_METAPATH, "boolean"))); BooleanAdapter() { - super(Boolean.class); + super(Boolean.class, IBooleanItem.class); } @Override - public List getNames() { + public List getNames() { return NAMES; } @@ -77,11 +77,6 @@ public Boolean copy(Object obj) { return (Boolean) obj; } - @Override - public Class getItemClass() { - return IBooleanItem.class; - } - @Override public IBooleanItem newItem(Object value) { Boolean item = toValue(value); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DateAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DateAdapter.java index ab2c79799..ecc6c6639 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DateAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DateAdapter.java @@ -11,6 +11,8 @@ import gov.nist.secauto.metaschema.core.datatype.object.AmbiguousDate; import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IDateItem; +import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; +import gov.nist.secauto.metaschema.core.qname.QNameCache; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.time.LocalDate; @@ -23,8 +25,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import javax.xml.namespace.QName; - import edu.umd.cs.findbugs.annotations.NonNull; /** @@ -35,8 +35,8 @@ public class DateAdapter extends AbstractCustomJavaDataTypeAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( - List.of(new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "date"))); + private static final List NAMES = ObjectUtils.notNull( + List.of(QNameCache.instance().of(MetapathConstants.NS_METAPATH, "date"))); @NonNull private static final Pattern DATE_TIMEZONE = ObjectUtils.notNull( Pattern.compile("^(" @@ -48,11 +48,11 @@ public class DateAdapter + "(Z|[+-][0-9]{2}:[0-9]{2})?$")); DateAdapter() { - super(AmbiguousDate.class); + super(AmbiguousDate.class, IDateItem.class); } @Override - public List getNames() { + public List getNames() { return NAMES; } @@ -94,11 +94,6 @@ public String asString(Object obj) { : DateFormats.DATE_WITHOUT_TZ.format(value.getValue())); } - @Override - public Class getItemClass() { - return IDateItem.class; - } - @Override public IDateItem newItem(Object value) { AmbiguousDate item = toValue(value); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DateTimeAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DateTimeAdapter.java index 6d61a4e55..7b412217e 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DateTimeAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DateTimeAdapter.java @@ -11,6 +11,8 @@ import gov.nist.secauto.metaschema.core.datatype.object.AmbiguousDateTime; import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IDateTimeItem; +import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; +import gov.nist.secauto.metaschema.core.qname.QNameCache; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.time.LocalDateTime; @@ -19,8 +21,6 @@ import java.time.format.DateTimeParseException; import java.util.List; -import javax.xml.namespace.QName; - import edu.umd.cs.findbugs.annotations.NonNull; /** @@ -31,18 +31,18 @@ public class DateTimeAdapter extends AbstractCustomJavaDataTypeAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( + private static final List NAMES = ObjectUtils.notNull( List.of( - new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "date-time"), + QNameCache.instance().of(MetapathConstants.NS_METAPATH, "date-time"), // for backwards compatibility with original type name - new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "dateTime"))); + QNameCache.instance().of(MetapathConstants.NS_METAPATH, "dateTime"))); DateTimeAdapter() { - super(AmbiguousDateTime.class); + super(AmbiguousDateTime.class, IDateTimeItem.class); } @Override - public List getNames() { + public List getNames() { return NAMES; } @@ -91,11 +91,6 @@ public String asString(Object obj) { : DateFormats.DATE_TIME_WITHOUT_TZ.format(value.getValue())); } - @Override - public Class getItemClass() { - return IDateTimeItem.class; - } - @Override public IDateTimeItem newItem(Object value) { AmbiguousDateTime item = toValue(value); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DateTimeWithTZAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DateTimeWithTZAdapter.java index 3c1c0f4d9..d34f2b8d1 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DateTimeWithTZAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DateTimeWithTZAdapter.java @@ -10,6 +10,8 @@ import gov.nist.secauto.metaschema.core.datatype.AbstractDataTypeAdapter; import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IDateTimeItem; +import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; +import gov.nist.secauto.metaschema.core.qname.QNameCache; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.time.DateTimeException; @@ -17,8 +19,6 @@ import java.time.format.DateTimeParseException; import java.util.List; -import javax.xml.namespace.QName; - import edu.umd.cs.findbugs.annotations.NonNull; /** @@ -29,18 +29,18 @@ public class DateTimeWithTZAdapter extends AbstractDataTypeAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( + private static final List NAMES = ObjectUtils.notNull( List.of( - new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "date-time-with-timezone"), + QNameCache.instance().of(MetapathConstants.NS_METAPATH, "date-time-with-timezone"), // for backwards compatibility with original type name - new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "dateTime-with-timezone"))); + QNameCache.instance().of(MetapathConstants.NS_METAPATH, "dateTime-with-timezone"))); DateTimeWithTZAdapter() { - super(ZonedDateTime.class); + super(ZonedDateTime.class, IDateTimeItem.class); } @Override - public List getNames() { + public List getNames() { return NAMES; } @@ -79,11 +79,6 @@ public ZonedDateTime copy(Object obj) { return ZonedDateTime.from((ZonedDateTime) obj); } - @Override - public Class getItemClass() { - return IDateTimeItem.class; - } - @Override public IDateTimeItem newItem(Object value) { ZonedDateTime item = toValue(value); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DateWithTZAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DateWithTZAdapter.java index f309d20d7..b1220c994 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DateWithTZAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DateWithTZAdapter.java @@ -10,6 +10,8 @@ import gov.nist.secauto.metaschema.core.datatype.AbstractDataTypeAdapter; import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IDateItem; +import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; +import gov.nist.secauto.metaschema.core.qname.QNameCache; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.time.DateTimeException; @@ -19,8 +21,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import javax.xml.namespace.QName; - import edu.umd.cs.findbugs.annotations.NonNull; /** @@ -31,9 +31,8 @@ public class DateWithTZAdapter extends AbstractDataTypeAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( - List.of( - new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "date-with-timezone"))); + private static final List NAMES = ObjectUtils.notNull( + List.of(QNameCache.instance().of(MetapathConstants.NS_METAPATH, "date-with-timezone"))); private static final Pattern DATE_TIMEZONE = Pattern.compile("^(" + "^(?:(?:2000|2400|2800|(?:19|2[0-9](?:0[48]|[2468][048]|[13579][26])))-02-29)" + "|(?:(?:(?:19|2[0-9])[0-9]{2})-02-(?:0[1-9]|1[0-9]|2[0-8]))" @@ -43,11 +42,11 @@ public class DateWithTZAdapter + "(Z|[+-][0-9]{2}:[0-9]{2})$"); DateWithTZAdapter() { - super(ZonedDateTime.class); + super(ZonedDateTime.class, IDateItem.class); } @Override - public List getNames() { + public List getNames() { return NAMES; } @@ -91,11 +90,6 @@ public ZonedDateTime copy(Object obj) { return ZonedDateTime.from((ZonedDateTime) obj); } - @Override - public Class getItemClass() { - return IDateItem.class; - } - @Override public IDateItem newItem(Object value) { ZonedDateTime item = toValue(value); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DayTimeAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DayTimeAdapter.java index 6632ab70b..6a14a9045 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DayTimeAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DayTimeAdapter.java @@ -10,14 +10,14 @@ import gov.nist.secauto.metaschema.core.datatype.AbstractDataTypeAdapter; import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IDayTimeDurationItem; +import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; +import gov.nist.secauto.metaschema.core.qname.QNameCache; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.time.Duration; import java.time.format.DateTimeParseException; import java.util.List; -import javax.xml.namespace.QName; - import edu.umd.cs.findbugs.annotations.NonNull; /** @@ -28,15 +28,15 @@ public class DayTimeAdapter extends AbstractDataTypeAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( - List.of(new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "day-time-duration"))); + private static final List NAMES = ObjectUtils.notNull( + List.of(QNameCache.instance().of(MetapathConstants.NS_METAPATH, "day-time-duration"))); DayTimeAdapter() { - super(Duration.class); + super(Duration.class, IDayTimeDurationItem.class); } @Override - public List getNames() { + public List getNames() { return NAMES; } @@ -61,11 +61,6 @@ public Duration parse(String value) { } } - @Override - public Class getItemClass() { - return IDayTimeDurationItem.class; - } - @Override public IDayTimeDurationItem newItem(Object value) { Duration item = toValue(value); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DecimalAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DecimalAdapter.java index 25667eb66..3f9a0d3fe 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DecimalAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DecimalAdapter.java @@ -11,6 +11,8 @@ import gov.nist.secauto.metaschema.core.datatype.AbstractDataTypeAdapter; import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IDecimalItem; +import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; +import gov.nist.secauto.metaschema.core.qname.QNameCache; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.io.IOException; @@ -18,8 +20,6 @@ import java.math.MathContext; import java.util.List; -import javax.xml.namespace.QName; - import edu.umd.cs.findbugs.annotations.NonNull; /** @@ -31,15 +31,15 @@ public class DecimalAdapter extends AbstractDataTypeAdapter { private static final MathContext MATH_CONTEXT = MathContext.DECIMAL64; @NonNull - private static final List NAMES = ObjectUtils.notNull( - List.of(new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "decimal"))); + private static final List NAMES = ObjectUtils.notNull( + List.of(QNameCache.instance().of(MetapathConstants.NS_METAPATH, "decimal"))); DecimalAdapter() { - super(BigDecimal.class); + super(BigDecimal.class, IDecimalItem.class); } @Override - public List getNames() { + public List getNames() { return NAMES; } @@ -68,11 +68,6 @@ public BigDecimal copy(Object obj) { return (BigDecimal) obj; } - @Override - public Class getItemClass() { - return IDecimalItem.class; - } - @Override public IDecimalItem newItem(Object value) { BigDecimal item = toValue(value); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/EmailAddressAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/EmailAddressAdapter.java index 35b128459..f390997f0 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/EmailAddressAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/EmailAddressAdapter.java @@ -7,12 +7,12 @@ import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IEmailAddressItem; +import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; +import gov.nist.secauto.metaschema.core.qname.QNameCache; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.util.List; -import javax.xml.namespace.QName; - import edu.umd.cs.findbugs.annotations.NonNull; /** @@ -23,27 +23,21 @@ public class EmailAddressAdapter extends AbstractStringAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( + private static final List NAMES = ObjectUtils.notNull( List.of( - new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "email-address"), + QNameCache.instance().of(MetapathConstants.NS_METAPATH, "email-address"), // for backwards compatibility with original type name - new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "email"))); + QNameCache.instance().of(MetapathConstants.NS_METAPATH, "email"))); EmailAddressAdapter() { - // avoid general construction + super(IEmailAddressItem.class); } @Override - public List getNames() { + public List getNames() { return NAMES; } - @Override - @NonNull - public Class getItemClass() { - return IEmailAddressItem.class; - } - @Override public IEmailAddressItem newItem(Object value) { String item = asString(value); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/HostnameAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/HostnameAdapter.java index ab79caf20..ad30646bc 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/HostnameAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/HostnameAdapter.java @@ -7,12 +7,12 @@ import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IHostnameItem; +import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; +import gov.nist.secauto.metaschema.core.qname.QNameCache; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.util.List; -import javax.xml.namespace.QName; - import edu.umd.cs.findbugs.annotations.NonNull; /** @@ -23,24 +23,19 @@ public class HostnameAdapter extends AbstractStringAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( - List.of(new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "hostname"))); + private static final List NAMES = ObjectUtils.notNull( + List.of(QNameCache.instance().of(MetapathConstants.NS_METAPATH, "hostname"))); HostnameAdapter() { + super(IHostnameItem.class); // avoid general construction } @Override - public List getNames() { + public List getNames() { return NAMES; } - @Override - public @NonNull - Class getItemClass() { - return IHostnameItem.class; - } - @Override public IHostnameItem newItem(Object value) { String item = asString(value); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/IPv4AddressAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/IPv4AddressAdapter.java index d62023fe5..267fe11ba 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/IPv4AddressAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/IPv4AddressAdapter.java @@ -10,12 +10,12 @@ import gov.nist.secauto.metaschema.core.datatype.AbstractDataTypeAdapter; import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IIPv4AddressItem; +import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; +import gov.nist.secauto.metaschema.core.qname.QNameCache; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.util.List; -import javax.xml.namespace.QName; - import edu.umd.cs.findbugs.annotations.NonNull; import inet.ipaddr.AddressStringException; import inet.ipaddr.IPAddressString; @@ -31,8 +31,8 @@ public class IPv4AddressAdapter extends AbstractDataTypeAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( - List.of(new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "ip-v4-address"))); + private static final List NAMES = ObjectUtils.notNull( + List.of(QNameCache.instance().of(MetapathConstants.NS_METAPATH, "ip-v4-address"))); private static final IPAddressStringParameters IP_V_4; static { @@ -50,11 +50,11 @@ public class IPv4AddressAdapter } IPv4AddressAdapter() { - super(IPv4Address.class); + super(IPv4Address.class, IIPv4AddressItem.class); } @Override - public List getNames() { + public List getNames() { return NAMES; } @@ -79,11 +79,6 @@ public IPv4Address copy(Object obj) { return (IPv4Address) obj; } - @Override - public Class getItemClass() { - return IIPv4AddressItem.class; - } - @Override public IIPv4AddressItem newItem(Object value) { IPv4Address item = toValue(value); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/IPv6AddressAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/IPv6AddressAdapter.java index d7642d6cd..bcf0804c5 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/IPv6AddressAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/IPv6AddressAdapter.java @@ -10,12 +10,12 @@ import gov.nist.secauto.metaschema.core.datatype.AbstractDataTypeAdapter; import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IIPv6AddressItem; +import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; +import gov.nist.secauto.metaschema.core.qname.QNameCache; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.util.List; -import javax.xml.namespace.QName; - import edu.umd.cs.findbugs.annotations.NonNull; import inet.ipaddr.AddressStringException; import inet.ipaddr.IPAddressString; @@ -31,8 +31,8 @@ public class IPv6AddressAdapter extends AbstractDataTypeAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( - List.of(new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "ip-v6-address"))); + private static final List NAMES = ObjectUtils.notNull( + List.of(QNameCache.instance().of(MetapathConstants.NS_METAPATH, "ip-v6-address"))); private static final IPAddressStringParameters IP_V_6; static { @@ -42,11 +42,11 @@ public class IPv6AddressAdapter } IPv6AddressAdapter() { - super(IPv6Address.class); + super(IPv6Address.class, IIPv6AddressItem.class); } @Override - public List getNames() { + public List getNames() { return NAMES; } @@ -71,11 +71,6 @@ public IPv6Address copy(Object obj) { return (IPv6Address) obj; } - @Override - public Class getItemClass() { - return IIPv6AddressItem.class; - } - @Override public IIPv6AddressItem newItem(Object value) { IPv6Address item = toValue(value); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/IntegerAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/IntegerAdapter.java index b6634c120..e112594b3 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/IntegerAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/IntegerAdapter.java @@ -7,13 +7,13 @@ import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IIntegerItem; +import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; +import gov.nist.secauto.metaschema.core.qname.QNameCache; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.math.BigInteger; import java.util.List; -import javax.xml.namespace.QName; - import edu.umd.cs.findbugs.annotations.NonNull; /** @@ -24,24 +24,19 @@ public class IntegerAdapter extends AbstractIntegerAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( - List.of(new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "integer"))); + private static final List NAMES = ObjectUtils.notNull( + List.of(QNameCache.instance().of(MetapathConstants.NS_METAPATH, "integer"))); IntegerAdapter() { + super(IIntegerItem.class); // avoid general construction } @Override - public List getNames() { + public List getNames() { return NAMES; } - @Override - @NonNull - public Class getItemClass() { - return IIntegerItem.class; - } - @Override public IIntegerItem newItem(Object value) { BigInteger item = toValue(value); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/NcNameAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/NcNameAdapter.java index 143c98077..9854cf74f 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/NcNameAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/NcNameAdapter.java @@ -7,12 +7,12 @@ import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.INcNameItem; +import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; +import gov.nist.secauto.metaschema.core.qname.QNameCache; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.util.List; -import javax.xml.namespace.QName; - import edu.umd.cs.findbugs.annotations.NonNull; /** @@ -24,25 +24,22 @@ public class NcNameAdapter extends AbstractStringAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( - List.of(new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "ncname"), + private static final List NAMES = ObjectUtils.notNull( + List.of( + QNameCache.instance().of(MetapathConstants.NS_METAPATH, "ncname"), // for backwards compatibility with original type name - new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "NCName"))); + QNameCache.instance().of(MetapathConstants.NS_METAPATH, "NCName"))); NcNameAdapter() { + super(INcNameItem.class); // avoid general construction } @Override - public List getNames() { + public List getNames() { return NAMES; } - @Override - public Class getItemClass() { - return INcNameItem.class; - } - @Override public INcNameItem newItem(Object value) { String item = asString(value); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/NonNegativeIntegerAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/NonNegativeIntegerAdapter.java index 9063bb00a..ddab30a2c 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/NonNegativeIntegerAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/NonNegativeIntegerAdapter.java @@ -7,13 +7,13 @@ import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.INonNegativeIntegerItem; +import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; +import gov.nist.secauto.metaschema.core.qname.QNameCache; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.math.BigInteger; import java.util.List; -import javax.xml.namespace.QName; - import edu.umd.cs.findbugs.annotations.NonNull; /** @@ -24,26 +24,22 @@ public class NonNegativeIntegerAdapter extends AbstractIntegerAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( + private static final List NAMES = ObjectUtils.notNull( List.of( - new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "non-negative-integer"), + QNameCache.instance().of(MetapathConstants.NS_METAPATH, "non-negative-integer"), // for backwards compatibility with original type name - new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "nonNegativeInteger"))); + QNameCache.instance().of(MetapathConstants.NS_METAPATH, "nonNegativeInteger"))); NonNegativeIntegerAdapter() { + super(INonNegativeIntegerItem.class); // avoid general construction } @Override - public List getNames() { + public List getNames() { return NAMES; } - @Override - public Class getItemClass() { - return INonNegativeIntegerItem.class; - } - @Override public INonNegativeIntegerItem newItem(Object value) { BigInteger item = toValue(value); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/PositiveIntegerAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/PositiveIntegerAdapter.java index a78141ed7..c237324ec 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/PositiveIntegerAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/PositiveIntegerAdapter.java @@ -7,13 +7,13 @@ import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IPositiveIntegerItem; +import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; +import gov.nist.secauto.metaschema.core.qname.QNameCache; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.math.BigInteger; import java.util.List; -import javax.xml.namespace.QName; - import edu.umd.cs.findbugs.annotations.NonNull; /** @@ -24,26 +24,22 @@ public class PositiveIntegerAdapter extends AbstractIntegerAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( + private static final List NAMES = ObjectUtils.notNull( List.of( - new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "positive-integer"), + QNameCache.instance().of(MetapathConstants.NS_METAPATH, "positive-integer"), // for backwards compatibility with original type name - new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "positiveInteger"))); + QNameCache.instance().of(MetapathConstants.NS_METAPATH, "positiveInteger"))); PositiveIntegerAdapter() { + super(IPositiveIntegerItem.class); // avoid general construction } @Override - public List getNames() { + public List getNames() { return NAMES; } - @Override - public Class getItemClass() { - return IPositiveIntegerItem.class; - } - @Override public IPositiveIntegerItem newItem(Object value) { BigInteger item = toValue(value); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/StringAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/StringAdapter.java index 8c5373d74..be13e97f6 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/StringAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/StringAdapter.java @@ -7,12 +7,12 @@ import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IStringItem; +import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; +import gov.nist.secauto.metaschema.core.qname.QNameCache; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.util.List; -import javax.xml.namespace.QName; - import edu.umd.cs.findbugs.annotations.NonNull; /** @@ -23,23 +23,19 @@ public class StringAdapter extends AbstractStringAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( - List.of(new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "string"))); + private static final List NAMES = ObjectUtils.notNull( + List.of(QNameCache.instance().of(MetapathConstants.NS_METAPATH, "string"))); StringAdapter() { + super(IStringItem.class); // avoid general construction } @Override - public List getNames() { + public List getNames() { return NAMES; } - @Override - public Class getItemClass() { - return IStringItem.class; - } - @Override @NonNull public IStringItem newItem(@NonNull Object value) { diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/TokenAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/TokenAdapter.java index f7d9d42a6..5c9b7669e 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/TokenAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/TokenAdapter.java @@ -7,12 +7,12 @@ import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.ITokenItem; +import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; +import gov.nist.secauto.metaschema.core.qname.QNameCache; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.util.List; -import javax.xml.namespace.QName; - import edu.umd.cs.findbugs.annotations.NonNull; /** @@ -23,23 +23,19 @@ public class TokenAdapter extends AbstractStringAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( - List.of(new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "token"))); + private static final List NAMES = ObjectUtils.notNull( + List.of(QNameCache.instance().of(MetapathConstants.NS_METAPATH, "token"))); TokenAdapter() { + super(ITokenItem.class); // avoid general construction } @Override - public List getNames() { + public List getNames() { return NAMES; } - @Override - public Class getItemClass() { - return ITokenItem.class; - } - @Override public ITokenItem newItem(Object value) { String item = asString(value); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/UriAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/UriAdapter.java index fbeaa5137..1a3561df7 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/UriAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/UriAdapter.java @@ -10,13 +10,13 @@ import gov.nist.secauto.metaschema.core.datatype.AbstractDataTypeAdapter; import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyUriItem; +import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; +import gov.nist.secauto.metaschema.core.qname.QNameCache; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.net.URI; import java.util.List; -import javax.xml.namespace.QName; - import edu.umd.cs.findbugs.annotations.NonNull; /** @@ -27,15 +27,15 @@ public class UriAdapter extends AbstractDataTypeAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( - List.of(new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "uri"))); + private static final List NAMES = ObjectUtils.notNull( + List.of(QNameCache.instance().of(MetapathConstants.NS_METAPATH, "uri"))); UriAdapter() { - super(URI.class); + super(URI.class, IAnyUriItem.class); } @Override - public List getNames() { + public List getNames() { return NAMES; } @@ -56,11 +56,6 @@ public URI copy(Object obj) { return (URI) obj; } - @Override - public Class getItemClass() { - return IAnyUriItem.class; - } - @Override public IAnyUriItem newItem(Object value) { URI item = toValue(value); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/UriReferenceAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/UriReferenceAdapter.java index 92587d733..30de89b43 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/UriReferenceAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/UriReferenceAdapter.java @@ -10,13 +10,13 @@ import gov.nist.secauto.metaschema.core.datatype.AbstractDataTypeAdapter; import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IUriReferenceItem; +import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; +import gov.nist.secauto.metaschema.core.qname.QNameCache; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.net.URI; import java.util.List; -import javax.xml.namespace.QName; - import edu.umd.cs.findbugs.annotations.NonNull; /** @@ -27,15 +27,15 @@ public class UriReferenceAdapter extends AbstractDataTypeAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( - List.of(new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "uri-reference"))); + private static final List NAMES = ObjectUtils.notNull( + List.of(QNameCache.instance().of(MetapathConstants.NS_METAPATH, "uri-reference"))); UriReferenceAdapter() { - super(URI.class); + super(URI.class, IUriReferenceItem.class); } @Override - public List getNames() { + public List getNames() { return NAMES; } @@ -56,11 +56,6 @@ public URI copy(Object obj) { return (URI) obj; } - @Override - public Class getItemClass() { - return IUriReferenceItem.class; - } - @Override public IUriReferenceItem newItem(Object value) { URI item = toValue(value); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/UuidAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/UuidAdapter.java index 33313265b..7e90e79e5 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/UuidAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/UuidAdapter.java @@ -10,14 +10,14 @@ import gov.nist.secauto.metaschema.core.datatype.AbstractDataTypeAdapter; import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IUuidItem; +import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; +import gov.nist.secauto.metaschema.core.qname.QNameCache; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.util.List; import java.util.UUID; import java.util.regex.Pattern; -import javax.xml.namespace.QName; - import edu.umd.cs.findbugs.annotations.NonNull; /** @@ -28,8 +28,8 @@ public class UuidAdapter extends AbstractDataTypeAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( - List.of(new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "uuid"))); + private static final List NAMES = ObjectUtils.notNull( + List.of(QNameCache.instance().of(MetapathConstants.NS_METAPATH, "uuid"))); /** * A regular expression that matches a valid UUID. @@ -38,11 +38,11 @@ public class UuidAdapter = Pattern.compile("^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"); UuidAdapter() { - super(UUID.class); + super(UUID.class, IUuidItem.class); } @Override - public List getNames() { + public List getNames() { return NAMES; } @@ -69,11 +69,6 @@ public UUID copy(Object obj) { return (UUID) obj; } - @Override - public Class getItemClass() { - return IUuidItem.class; - } - @Override public IUuidItem newItem(Object value) { UUID item = toValue(value); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/YearMonthAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/YearMonthAdapter.java index 7f1511adf..e5aec27ca 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/YearMonthAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/YearMonthAdapter.java @@ -10,14 +10,14 @@ import gov.nist.secauto.metaschema.core.datatype.AbstractDataTypeAdapter; import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IYearMonthDurationItem; +import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; +import gov.nist.secauto.metaschema.core.qname.QNameCache; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.time.Period; import java.time.format.DateTimeParseException; import java.util.List; -import javax.xml.namespace.QName; - import edu.umd.cs.findbugs.annotations.NonNull; /** @@ -28,15 +28,15 @@ public class YearMonthAdapter extends AbstractDataTypeAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( - List.of(new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "year-month-duration"))); + private static final List NAMES = ObjectUtils.notNull( + List.of(QNameCache.instance().of(MetapathConstants.NS_METAPATH, "year-month-duration"))); YearMonthAdapter() { - super(Period.class); + super(Period.class, IYearMonthDurationItem.class); } @Override - public List getNames() { + public List getNames() { return NAMES; } @@ -61,11 +61,6 @@ public Period parse(String value) { } } - @Override - public Class getItemClass() { - return IYearMonthDurationItem.class; - } - @Override public IYearMonthDurationItem newItem(Object value) { Period item = toValue(value); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/markup/AbstractMarkupAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/markup/AbstractMarkupAdapter.java index b4f63bd14..844bb8ea9 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/markup/AbstractMarkupAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/markup/AbstractMarkupAdapter.java @@ -35,11 +35,12 @@ abstract class AbstractMarkupAdapter> /** * Construct a new adapter. * - * @param clazz - * the markup type class + * @param valueClass + * the Java value object type this adapter supports */ - protected AbstractMarkupAdapter(@NonNull Class clazz) { - super(clazz); + protected AbstractMarkupAdapter( + @NonNull Class valueClass) { + super(valueClass, IMarkupItem.class); } @Override diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/markup/MarkupLineAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/markup/MarkupLineAdapter.java index 6bf2c2452..23ba20892 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/markup/MarkupLineAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/markup/MarkupLineAdapter.java @@ -9,6 +9,8 @@ import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IMarkupItem; +import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; +import gov.nist.secauto.metaschema.core.qname.QNameCache; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import org.codehaus.stax2.XMLEventReader2; @@ -17,7 +19,6 @@ import java.net.URI; import java.util.List; -import javax.xml.namespace.QName; import javax.xml.stream.XMLStreamException; import edu.umd.cs.findbugs.annotations.NonNull; @@ -30,15 +31,15 @@ public class MarkupLineAdapter extends AbstractMarkupAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( - List.of(new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "markup-line"))); + private static final List NAMES = ObjectUtils.notNull( + List.of(QNameCache.instance().of(MetapathConstants.NS_METAPATH, "markup-line"))); MarkupLineAdapter() { super(MarkupLine.class); } @Override - public List getNames() { + public List getNames() { return NAMES; } @@ -74,11 +75,6 @@ public String getDefaultJsonValueKey() { return "RICHTEXT"; } - @Override - public Class getItemClass() { - return IMarkupItem.class; - } - @Override public IMarkupItem newItem(Object value) { MarkupLine item = toValue(value); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/markup/MarkupMultilineAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/markup/MarkupMultilineAdapter.java index 08850f89b..09e0e7ea6 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/markup/MarkupMultilineAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/markup/MarkupMultilineAdapter.java @@ -9,6 +9,8 @@ import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IMarkupItem; +import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; +import gov.nist.secauto.metaschema.core.qname.QNameCache; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import org.codehaus.stax2.XMLEventReader2; @@ -30,15 +32,15 @@ public class MarkupMultilineAdapter extends AbstractMarkupAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( - List.of(new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "markup-multiline"))); + private static final List NAMES = ObjectUtils.notNull( + List.of(QNameCache.instance().of(MetapathConstants.NS_METAPATH, "markup-multiline"))); MarkupMultilineAdapter() { super(MarkupMultiline.class); } @Override - public List getNames() { + public List getNames() { return NAMES; } @@ -84,11 +86,6 @@ public String getDefaultJsonValueKey() { return "PROSE"; } - @Override - public Class getItemClass() { - return IMarkupItem.class; - } - @Override public IMarkupItem newItem(Object value) { MarkupMultiline item = toValue(value); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/EQNameUtils.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/EQNameUtils.java index 482b84ee7..c5f5d022a 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/EQNameUtils.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/EQNameUtils.java @@ -5,7 +5,7 @@ package gov.nist.secauto.metaschema.core.metapath; -import gov.nist.secauto.metaschema.core.util.ObjectUtils; +import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -126,17 +126,38 @@ public static boolean isNcName(@NonNull String name) { return NCNAME.matcher(name).matches(); } + /** + * Generate a qualified name, use a prefix provided by the resolve or by + * prepending the namespace. + * + * @param qname + * the qualified name to generate the EQName for + * @param resolver + * the resolver to use to lookup the prefix + * @return the extended qualified-name + */ + // FIXME: move utility methods to IEnhancedQName @NonNull public static String toEQName( - @NonNull QName qname, + @NonNull IEnhancedQName qname, @Nullable NamespaceToPrefixResolver resolver) { - String namespace = qname.getNamespaceURI(); + String namespace = qname.getNamespace(); String prefix = namespace.isEmpty() ? null : StaticContext.getWellKnownPrefixForUri(namespace); if (prefix == null && resolver != null) { prefix = resolver.resolve(namespace); } - return prefix == null ? ObjectUtils.notNull(qname.toString()) : prefix + ":" + qname.getLocalPart(); + String preamble; + if (prefix == null) { + if (namespace.isEmpty()) { + preamble = ""; + } else { + preamble = "{" + namespace + "}"; + } + } else { + preamble = prefix + ":"; + } + return preamble + qname.getLocalName(); } /** diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/StaticContext.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/StaticContext.java index 77c7063f3..bb239cac7 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/StaticContext.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/StaticContext.java @@ -5,9 +5,13 @@ package gov.nist.secauto.metaschema.core.metapath; +import gov.nist.secauto.metaschema.core.datatype.DataTypeService; +import gov.nist.secauto.metaschema.core.datatype.IDataTypeAdapter; import gov.nist.secauto.metaschema.core.metapath.EQNameUtils.PrefixToNamespaceResolver; -import gov.nist.secauto.metaschema.core.metapath.item.IItem; +import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyAtomicItem; import gov.nist.secauto.metaschema.core.metapath.type.IItemType; +import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; +import gov.nist.secauto.metaschema.core.qname.NamespaceCache; import gov.nist.secauto.metaschema.core.util.CollectionUtil; import gov.nist.secauto.metaschema.core.util.ObjectUtils; @@ -17,7 +21,6 @@ import java.util.stream.Collectors; import javax.xml.XMLConstants; -import javax.xml.namespace.QName; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; @@ -53,6 +56,9 @@ public final class StaticContext { MetapathConstants.NS_METAPATH_FUNCTIONS_MAP); WELL_KNOWN_NAMESPACES = CollectionUtil.unmodifiableMap(knownNamespaces); + WELL_KNOWN_NAMESPACES.forEach( + (prefix, namespace) -> NamespaceCache.instance().of(ObjectUtils.notNull(namespace))); + WELL_KNOWN_URI_TO_PREFIX = ObjectUtils.notNull(WELL_KNOWN_NAMESPACES.entrySet().stream() .collect(Collectors.toUnmodifiableMap( entry -> entry.getValue().toASCIIString(), @@ -414,6 +420,7 @@ public Builder baseUri(@NonNull URI uri) { @NonNull public Builder namespace(@NonNull String prefix, @NonNull URI uri) { this.namespaces.put(prefix, uri); + NamespaceCache.instance().of(uri); return this; } @@ -448,6 +455,7 @@ public Builder namespace(@NonNull String prefix, @NonNull String uri) { @NonNull public Builder defaultModelNamespace(@NonNull URI uri) { this.defaultModelNamespace = uri; + NamespaceCache.instance().of(uri); return this; } @@ -478,6 +486,7 @@ public Builder defaultModelNamespace(@NonNull String uri) { @NonNull public Builder defaultFunctionNamespace(@NonNull URI uri) { this.defaultFunctionNamespace = uri; + NamespaceCache.instance().of(uri); return this; } @@ -519,11 +528,25 @@ public StaticContext build() { } } - @NonNull - public IItemType lookupDataType(QName name) { + @Nullable + public IItemType lookupDataTypeItemType(@NonNull IEnhancedQName qname) { + IDataTypeAdapter adapter = DataTypeService.instance() + .getJavaTypeAdapterByQNameIndex(qname.getIndexPosition()); + + IItemType retval = null; + + // Expected a non-null adapter result, since the QName was found + // if an adapter is not found, this is likely because someone is squating on + // the namespace + if (adapter != null) { + retval = adapter.getItemType(); + } + return retval; } - @NonNull - public IItemType lookupDataType(Class clazz) { + @Nullable + public IItemType lookupDataTypeItemType(Class clazz) { + IDataTypeAdapter adapter = DataTypeService.instance().getJavaTypeAdapterByItemClass(clazz); + return adapter == null ? null : adapter.getItemType(); } } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/ICstExpressionFactory.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/ICstExpressionFactory.java new file mode 100644 index 000000000..578c41aa0 --- /dev/null +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/ICstExpressionFactory.java @@ -0,0 +1,145 @@ +/* + * SPDX-FileCopyrightText: none + * SPDX-License-Identifier: CC0-1.0 + */ + +package gov.nist.secauto.metaschema.core.metapath.cst; + +import gov.nist.secauto.metaschema.core.metapath.cst.Let.VariableDeclaration; +import gov.nist.secauto.metaschema.core.metapath.cst.math.Addition; +import gov.nist.secauto.metaschema.core.metapath.item.IItem; + +import java.math.BigDecimal; +import java.util.List; + +import edu.umd.cs.findbugs.annotations.NonNull; +import edu.umd.cs.findbugs.annotations.Nullable; + +/** + * A factory interface that supports creating new Metapath CST nodes. + */ +public interface ICstExpressionFactory { + /** + * Construct an "and" logical expression. + * + * @param expressions + * the expressions to evaluate + * @return the expression + */ + @NonNull + And newAnd(@NonNull List expressions); + + /** + * Construct an array constructor expression that uses the provided expression + * to initialize the array. + * + * @param expression + * the expression used to produce the array members + * @return the expression + */ + @NonNull + ArraySequenceConstructor newArraySequenceConstructor(@Nullable IExpression expression); + + /** + * Construct an array constructor expression that uses the provided expression + * to initialize the array. + *

+ * Each resulting array member contains the value of the corresponding argument + * expression. + * + * @param children + * the expressions used to produce the array members + * @return the expression + */ + @NonNull + ArraySquareConstructor newArraySquareConstructor(@NonNull List children); + + /** + * Construct an expression that always returns the same decimal value. + * + * @param value + * the literal value + * @return the expression + */ + @NonNull + DecimalLiteral newDecimalLiteral(@NonNull BigDecimal value); + + /** + * Construct an expression that returns an empty sequence. + * + * @param + * the Java type of the resulting empty sequence + * @return the expression + */ + @NonNull + EmptySequence newEmptySequence(); + + /** + * Construct a except filter expression, which removes the items resulting from + * the filter expression from the items expression. + * + * @param itemsExpression + * an expression indicating the items to filter + * @param filterExpression + * an expression indicating the items to omit + * @return the expression + */ + @NonNull + Except newExcept(@NonNull IExpression itemsExpression, @NonNull IExpression filterExpression); + + /** + * Construct a new let expression using the provided variable and return clause. + * + * @param variable + * the variable declaration + * @param returnExpr + * the return clause that makes use of variables for evaluation + * @return the expression + */ + @NonNull + For newFor(@NonNull VariableDeclaration variable, @NonNull IExpression returnExpr); + + /** + * Construct a new functional call accessor. + * + * @param base + * the expression whose result is used as the map or array to perform + * the lookup on + * @param keyOrIndex + * the value to find, which will be the key for a map or the index for + * an array + * @return the expression + */ + @NonNull + FunctionCallAccessor newFunctionCallAccessor(@NonNull IExpression base, @NonNull IExpression keyOrIndex); + + /** + * Construct a new conditional expression. + * + * @param testExpression + * the first expression to evaluate + * @param thenExpression + * the expression to evaluate if the test is {@code true} + * @param elseExpression + * the expression to evaluate if the test is {@code false} + * @return the expression + */ + @NonNull + If newIf( + @NonNull IExpression testExpression, + @NonNull IExpression thenExpression, + @NonNull IExpression elseExpression); + + /** + * Construct a new additive expression that sums two atomic data items. + * + * @param left + * an expression whose result is summed + * @param right + * an expression whose result is summed + * @return the expression + */ + Addition newAddition( + @NonNull IExpression left, + @NonNull IExpression right); +} diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/impl/TypeTestSupport.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/impl/TypeTestSupport.java index 0e9fd8ea1..1602dec28 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/impl/TypeTestSupport.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/impl/TypeTestSupport.java @@ -23,7 +23,7 @@ import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; -public class TypeTestSupport { +public final class TypeTestSupport { private static final Map< Class, diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/IArgument.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/IArgument.java index 4894589bf..635ba2042 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/IArgument.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/IArgument.java @@ -10,6 +10,8 @@ import gov.nist.secauto.metaschema.core.metapath.type.IItemType; import gov.nist.secauto.metaschema.core.metapath.type.ISequenceType; import gov.nist.secauto.metaschema.core.metapath.type.Occurrence; +import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; +import gov.nist.secauto.metaschema.core.qname.QNameCache; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.util.Objects; @@ -83,10 +85,10 @@ final class Builder { private Builder(@NonNull StaticContext staticContext) { // construct a new non-initialized builder this.staticContext = staticContext; - this.type = staticContext.lookupDataType(IItem.class); + this.type = IItem.type(); } - protected StaticContext getStaticContext() { + private StaticContext getStaticContext() { return staticContext; } @@ -112,15 +114,40 @@ public Builder name(@NonNull String name) { * By default an argument has the type {@link IItem}. * * @param type - * the argument's type + * the qualified name of the argument's type * @return this builder */ @NonNull - public Builder type(@NonNull QName name) { - this.type = getStaticContext().lookupDataType(name); + public Builder type(@NonNull IEnhancedQName name) { + IItemType result = getStaticContext().lookupDataTypeItemType(name); + if (result == null) { + throw new IllegalArgumentException( + String.format("No data type with the name '%s'.", name)); + } + this.type = result; return this; } + /** + * Define the type of the function argument. + *

+ * By default an argument has the type {@link IItem}. + * + * @param name + * the qualified name of the argument's type + * @return this builder + */ + @NonNull + public Builder type(@NonNull QName name) { + IEnhancedQName result = QNameCache.instance().get(name); + if (result == null) { + throw new IllegalArgumentException( + String.format("A data type with the qname '%s' was not found.", + name)); + } + return type(result); + } + /** * Define the type of the function argument. *

@@ -131,8 +158,8 @@ public Builder type(@NonNull QName name) { * @return this builder */ @NonNull - public Builder type(@NonNull Class type) { - this.type = getStaticContext().lookupDataType(type); + public Builder type(@NonNull IItemType type) { + this.type = type; return this; } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/IFunction.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/IFunction.java index 0ffe78253..e33bee855 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/IFunction.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/IFunction.java @@ -13,6 +13,8 @@ import gov.nist.secauto.metaschema.core.metapath.type.IItemType; import gov.nist.secauto.metaschema.core.metapath.type.ISequenceType; import gov.nist.secauto.metaschema.core.metapath.type.Occurrence; +import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; +import gov.nist.secauto.metaschema.core.qname.QNameCache; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.net.URI; @@ -255,10 +257,10 @@ final class Builder { private Builder(@NonNull StaticContext staticContext) { this.staticContext = staticContext; - returnType = staticContext.lookupDataType(IItem.class); + returnType = IItem.type(); } - protected StaticContext getStaticContext() { + private StaticContext getStaticContext() { return staticContext; } @@ -406,11 +408,36 @@ public Builder allowUnboundedArity(boolean allow) { * @return this builder */ @NonNull - public Builder returnType(@NonNull QName name) { - this.returnType = getStaticContext().lookupDataType(name); + public Builder returnType(@NonNull IEnhancedQName name) { + IItemType result = getStaticContext().lookupDataTypeItemType(name); + if (result == null) { + throw new IllegalArgumentException( + String.format("No data type with the name '%s'.", name)); + } + this.returnType = result; return this; } + /** + * Define the type of the function argument. + *

+ * By default an argument has the type {@link IItem}. + * + * @param type + * the qualified name of the function's return data type + * @return this builder + */ + @NonNull + public Builder returnType(@NonNull QName name) { + IEnhancedQName result = QNameCache.instance().get(name); + if (result == null) { + throw new IllegalArgumentException( + String.format("A data type with the qname '%s' was not found.", + name)); + } + return returnType(result); + } + /** * Define the return sequence Java type of the function. * @@ -419,8 +446,8 @@ public Builder returnType(@NonNull QName name) { * @return this builder */ @NonNull - public Builder returnType(@NonNull Class type) { - this.returnType = getStaticContext().lookupDataType(type); + public Builder returnType(@NonNull IItemType type) { + this.returnType = type; return this; } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/InvalidTypeFunctionException.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/InvalidTypeFunctionException.java index d5573aa3c..b73aebf4a 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/InvalidTypeFunctionException.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/InvalidTypeFunctionException.java @@ -73,7 +73,7 @@ private static String generateMessage(@NonNull IItem item) { if (item instanceof INodeItem) { INodeItem nodeItem = (INodeItem) item; retval = String.format("The %s node item at path '%s' has no typed value", - nodeItem.getNodeItemType().name().toLowerCase(Locale.ROOT), + nodeItem.getNodeItemKind().name().toLowerCase(Locale.ROOT), nodeItem.getMetapath()); } else { retval = String.format("Item '%s' has no typed value", item.getClass().getName()); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayAppend.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayAppend.java index 5b44d6cff..28b907e67 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayAppend.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayAppend.java @@ -37,15 +37,15 @@ public final class ArrayAppend { .focusIndependent() .argument(IArgument.builder() .name("array") - .type(IArrayItem.class) + .type(IArrayItem.type()) .one() .build()) .argument(IArgument.builder() .name("appendage") - .type(IItem.class) + .type(IItem.type()) .zeroOrMore() .build()) - .returnType(IArrayItem.class) + .returnType(IArrayItem.type()) .returnOne() .functionHandler(ArrayAppend::execute) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayFlatten.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayFlatten.java index cc2d4ef23..afcc0ba3c 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayFlatten.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayFlatten.java @@ -35,10 +35,10 @@ public final class ArrayFlatten { .focusIndependent() .argument(IArgument.builder() .name("input") - .type(IItem.class) + .type(IItem.type()) .zeroOrMore() .build()) - .returnType(IItem.class) + .returnType(IItem.type()) .returnZeroOrMore() .functionHandler(ArrayFlatten::execute) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayGet.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayGet.java index 10804d40e..3a23d6fd8 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayGet.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayGet.java @@ -38,15 +38,15 @@ public final class ArrayGet { .focusIndependent() .argument(IArgument.builder() .name("array") - .type(IArrayItem.class) + .type(IArrayItem.type()) .one() .build()) .argument(IArgument.builder() .name("position") - .type(IIntegerItem.class) + .type(IIntegerItem.type()) .one() .build()) - .returnType(IItem.class) + .returnType(IItem.type()) .returnZeroOrOne() .functionHandler(ArrayGet::execute) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayHead.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayHead.java index 145af11d6..f895021f5 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayHead.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayHead.java @@ -37,10 +37,10 @@ public final class ArrayHead { .focusIndependent() .argument(IArgument.builder() .name("array") - .type(IArrayItem.class) + .type(IArrayItem.type()) .one() .build()) - .returnType(IItem.class) + .returnType(IItem.type()) .returnZeroOrOne() .functionHandler(ArrayHead::execute) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayInsertBefore.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayInsertBefore.java index 5df8c77de..d9c77c94a 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayInsertBefore.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayInsertBefore.java @@ -40,20 +40,20 @@ public final class ArrayInsertBefore { .focusIndependent() .argument(IArgument.builder() .name("array") - .type(IArrayItem.class) + .type(IArrayItem.type()) .one() .build()) .argument(IArgument.builder() .name("position") - .type(IIntegerItem.class) + .type(IIntegerItem.type()) .one() .build()) .argument(IArgument.builder() .name("member") - .type(IItem.class) + .type(IItem.type()) .zeroOrMore() .build()) - .returnType(IArrayItem.class) + .returnType(IArrayItem.type()) .returnOne() .functionHandler(ArrayInsertBefore::execute) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayJoin.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayJoin.java index ab769f6e1..14d304303 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayJoin.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayJoin.java @@ -38,10 +38,10 @@ public final class ArrayJoin { .focusIndependent() .argument(IArgument.builder() .name("array") - .type(IArrayItem.class) + .type(IArrayItem.type()) .zeroOrMore() .build()) - .returnType(IItem.class) + .returnType(IItem.type()) .returnZeroOrOne() .functionHandler(ArrayJoin::execute) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayPut.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayPut.java index bc3769a77..4f199b6cb 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayPut.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayPut.java @@ -41,20 +41,20 @@ public final class ArrayPut { .focusIndependent() .argument(IArgument.builder() .name("array") - .type(IArrayItem.class) + .type(IArrayItem.type()) .one() .build()) .argument(IArgument.builder() .name("position") - .type(IIntegerItem.class) + .type(IIntegerItem.type()) .one() .build()) .argument(IArgument.builder() .name("member") - .type(IItem.class) + .type(IItem.type()) .zeroOrMore() .build()) - .returnType(IArrayItem.class) + .returnType(IArrayItem.type()) .returnOne() .functionHandler(ArrayPut::execute) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayRemove.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayRemove.java index 498445586..f1d57afd7 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayRemove.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayRemove.java @@ -42,15 +42,15 @@ public final class ArrayRemove { .focusIndependent() .argument(IArgument.builder() .name("array") - .type(IArrayItem.class) + .type(IArrayItem.type()) .one() .build()) .argument(IArgument.builder() .name("positions") - .type(IIntegerItem.class) + .type(IIntegerItem.type()) .zeroOrMore() .build()) - .returnType(IArrayItem.class) + .returnType(IArrayItem.type()) .returnOne() .functionHandler(ArrayRemove::execute) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayReverse.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayReverse.java index 621fa4e15..653342838 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayReverse.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayReverse.java @@ -38,10 +38,10 @@ public final class ArrayReverse { .focusIndependent() .argument(IArgument.builder() .name("array") - .type(IArrayItem.class) + .type(IArrayItem.type()) .one() .build()) - .returnType(IArrayItem.class) + .returnType(IArrayItem.type()) .returnOne() .functionHandler(ArrayReverse::execute) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArraySize.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArraySize.java index 21b018f94..9cd0805a5 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArraySize.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArraySize.java @@ -36,10 +36,10 @@ public final class ArraySize { .focusIndependent() .argument(IArgument.builder() .name("array") - .type(IArrayItem.class) + .type(IArrayItem.type()) .one() .build()) - .returnType(IIntegerItem.class) + .returnType(IIntegerItem.type()) .returnOne() .functionHandler(ArraySize::execute) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArraySubarray.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArraySubarray.java index a614ceaa8..1f26b06a2 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArraySubarray.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArraySubarray.java @@ -39,15 +39,15 @@ public final class ArraySubarray { .focusIndependent() .argument(IArgument.builder() .name("array") - .type(IArrayItem.class) + .type(IArrayItem.type()) .one() .build()) .argument(IArgument.builder() .name("start") - .type(IIntegerItem.class) + .type(IIntegerItem.type()) .one() .build()) - .returnType(IArrayItem.class) + .returnType(IArrayItem.type()) .returnOne() .functionHandler(ArraySubarray::executeTwoArg) .build(); @@ -60,20 +60,20 @@ public final class ArraySubarray { .focusIndependent() .argument(IArgument.builder() .name("array") - .type(IArrayItem.class) + .type(IArrayItem.type()) .one() .build()) .argument(IArgument.builder() .name("start") - .type(IIntegerItem.class) + .type(IIntegerItem.type()) .one() .build()) .argument(IArgument.builder() .name("length") - .type(IIntegerItem.class) + .type(IIntegerItem.type()) .one() .build()) - .returnType(IArrayItem.class) + .returnType(IArrayItem.type()) .returnOne() .functionHandler(ArraySubarray::executeThreeArg) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayTail.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayTail.java index 1bb9c72e8..1c521d2d3 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayTail.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayTail.java @@ -36,10 +36,10 @@ public final class ArrayTail { .focusIndependent() .argument(IArgument.builder() .name("array") - .type(IArrayItem.class) + .type(IArrayItem.type()) .one() .build()) - .returnType(IItem.class) + .returnType(IItem.type()) .returnZeroOrOne() .functionHandler(ArrayTail::execute) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/CastFunction.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/CastFunction.java index 3ee86412b..76df31621 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/CastFunction.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/CastFunction.java @@ -13,6 +13,7 @@ import gov.nist.secauto.metaschema.core.metapath.function.IFunctionExecutor; import gov.nist.secauto.metaschema.core.metapath.item.IItem; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyAtomicItem; +import gov.nist.secauto.metaschema.core.metapath.type.IAtomicOrUnionType; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.net.URI; @@ -36,7 +37,7 @@ public final class CastFunction implements IFunctio static IFunction signature( @NonNull URI namespace, @NonNull String name, - @NonNull Class resultingAtomicType, + @NonNull IAtomicOrUnionType resultingAtomicType, @NonNull ICastExecutor executor) { return signature( ObjectUtils.notNull(namespace.toASCIIString()), @@ -49,7 +50,7 @@ static IFunction signature( static IFunction signature( @NonNull String namespace, @NonNull String name, - @NonNull Class resulingAtomicType, + @NonNull IAtomicOrUnionType resulingAtomicType, @NonNull ICastExecutor executor) { return IFunction.builder() .name(name) @@ -59,7 +60,7 @@ static IFunction signature( .focusIndependent() .argument(IArgument.builder() .name("arg1") - .type(IAnyAtomicItem.class) + .type(IAnyAtomicItem.type()) .zeroOrOne() .build()) .returnType(resulingAtomicType) diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/DefaultFunctionLibrary.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/DefaultFunctionLibrary.java index d5b984abf..85078a1c7 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/DefaultFunctionLibrary.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/DefaultFunctionLibrary.java @@ -286,27 +286,34 @@ public DefaultFunctionLibrary() { // NOPMD - intentional // metapath casting functions registerFunction(CastFunction.signature( - MetapathConstants.NS_METAPATH, "boolean", IBooleanItem.class, IBooleanItem::cast)); + MetapathConstants.NS_METAPATH, "boolean", IBooleanItem.type(), IBooleanItem::cast)); registerFunction(CastFunction.signature( - MetapathConstants.NS_METAPATH, "date", IDateItem.class, IDateItem::cast)); + MetapathConstants.NS_METAPATH, "date", IDateItem.type(), IDateItem::cast)); registerFunction(CastFunction.signature( - MetapathConstants.NS_METAPATH, "date-time", IDateTimeItem.class, IDateTimeItem::cast)); + MetapathConstants.NS_METAPATH, "date-time", IDateTimeItem.type(), IDateTimeItem::cast)); registerFunction(CastFunction.signature( - MetapathConstants.NS_METAPATH, "decimal", IDecimalItem.class, IDecimalItem::cast)); + MetapathConstants.NS_METAPATH, "decimal", IDecimalItem.type(), IDecimalItem::cast)); registerFunction(CastFunction.signature( - MetapathConstants.NS_METAPATH, "duration", IDurationItem.class, IDurationItem::cast)); + MetapathConstants.NS_METAPATH, "duration", IDurationItem.type(), IDurationItem::cast)); registerFunction(CastFunction.signature( - MetapathConstants.NS_METAPATH, "integer", IIntegerItem.class, IIntegerItem::cast)); + MetapathConstants.NS_METAPATH, "integer", IIntegerItem.type(), IIntegerItem::cast)); registerFunction(CastFunction.signature( - MetapathConstants.NS_METAPATH, "ncname", INcNameItem.class, INcNameItem::cast)); + MetapathConstants.NS_METAPATH, "ncname", INcNameItem.type(), INcNameItem::cast)); registerFunction(CastFunction.signature( - MetapathConstants.NS_METAPATH, "non-negative-integer", INonNegativeIntegerItem.class, + MetapathConstants.NS_METAPATH, + "non-negative-integer", + INonNegativeIntegerItem.type(), INonNegativeIntegerItem::cast)); registerFunction(CastFunction.signature( - MetapathConstants.NS_METAPATH, "positive-integer", IPositiveIntegerItem.class, + MetapathConstants.NS_METAPATH, + "positive-integer", + IPositiveIntegerItem.type(), IPositiveIntegerItem::cast)); registerFunction(CastFunction.signature( - MetapathConstants.NS_METAPATH, "string", IStringItem.class, IStringItem::cast)); + MetapathConstants.NS_METAPATH, + "string", + IStringItem.type(), + IStringItem::cast)); // extra functions registerFunction(MpRecurseDepth.SIGNATURE_ONE_ARG); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnAbs.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnAbs.java index d6c6c052c..28079300e 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnAbs.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnAbs.java @@ -36,10 +36,10 @@ public final class FnAbs { .focusIndependent() .argument(IArgument.builder() .name("arg") - .type(INumericItem.class) + .type(INumericItem.type()) .zeroOrOne() .build()) - .returnType(INumericItem.class) + .returnType(INumericItem.type()) .returnZeroOrOne() .functionHandler(FnAbs::execute) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnAvg.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnAvg.java index 034ce6be4..299182971 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnAvg.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnAvg.java @@ -51,10 +51,10 @@ public final class FnAvg { .focusIndependent() .argument(IArgument.builder() .name("arg") - .type(IAnyAtomicItem.class) + .type(IAnyAtomicItem.type()) .zeroOrMore() .build()) - .returnType(IAnyAtomicItem.class) + .returnType(IAnyAtomicItem.type()) .returnZeroOrOne() .functionHandler(FnAvg::execute) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnBaseUri.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnBaseUri.java index 116fd0f91..135068b43 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnBaseUri.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnBaseUri.java @@ -40,7 +40,7 @@ public final class FnBaseUri { .deterministic() .contextDependent() .focusDependent() - .returnType(IAnyUriItem.class) + .returnType(IAnyUriItem.type()) .returnOne() .functionHandler(FnBaseUri::executeNoArg) .build(); @@ -54,10 +54,10 @@ public final class FnBaseUri { .focusIndependent() .argument(IArgument.builder() .name("arg1") - .type(INodeItem.class) + .type(INodeItem.type()) .zeroOrOne() .build()) - .returnType(IAnyUriItem.class) + .returnType(IAnyUriItem.type()) .returnOne() .functionHandler(FnBaseUri::executeOneArg) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnBoolean.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnBoolean.java index c7c653a59..b4a80816c 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnBoolean.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnBoolean.java @@ -41,10 +41,10 @@ public final class FnBoolean { .focusIndependent() .argument(IArgument.builder() .name("arg") - .type(IItem.class) + .type(IItem.type()) .zeroOrMore() .build()) - .returnType(IBooleanItem.class) + .returnType(IBooleanItem.type()) .returnOne() .functionHandler(FnBoolean::execute) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnCeiling.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnCeiling.java index 99626871e..38d040a53 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnCeiling.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnCeiling.java @@ -36,10 +36,10 @@ public final class FnCeiling { .focusIndependent() .argument(IArgument.builder() .name("arg") - .type(INumericItem.class) + .type(INumericItem.type()) .zeroOrOne() .build()) - .returnType(INumericItem.class) + .returnType(INumericItem.type()) .returnZeroOrOne() .functionHandler(FnCeiling::execute) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnCompare.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnCompare.java index b691d760d..c5bb1f6fa 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnCompare.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnCompare.java @@ -35,15 +35,15 @@ public final class FnCompare { .focusIndependent() .argument(IArgument.builder() .name("comparand1") - .type(IStringItem.class) + .type(IStringItem.type()) .zeroOrOne() .build()) .argument(IArgument.builder() .name("comparand2") - .type(IStringItem.class) + .type(IStringItem.type()) .zeroOrOne() .build()) - .returnType(IIntegerItem.class) + .returnType(IIntegerItem.type()) .returnZeroOrOne() .functionHandler(FnCompare::execute) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnConcat.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnConcat.java index 3a040f513..2561414a1 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnConcat.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnConcat.java @@ -38,16 +38,16 @@ public final class FnConcat { .focusIndependent() .argument(IArgument.builder() .name("arg1") - .type(IAnyAtomicItem.class) + .type(IAnyAtomicItem.type()) .zeroOrOne() .build()) .argument(IArgument.builder() .name("arg2") - .type(IAnyAtomicItem.class) + .type(IAnyAtomicItem.type()) .zeroOrOne() .build()) .allowUnboundedArity(true) - .returnType(IStringItem.class) + .returnType(IStringItem.type()) .returnOne() .functionHandler(FnConcat::execute) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnContains.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnContains.java index a8f4e739a..75697dad0 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnContains.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnContains.java @@ -36,15 +36,16 @@ public final class FnContains { .contextDependent() .focusIndependent() .argument(IArgument.builder() - .name("arg1").type(IStringItem.class) + .name("arg1") + .type(IStringItem.type()) .zeroOrOne() .build()) .argument(IArgument.builder() .name("arg2") - .type(IStringItem.class) + .type(IStringItem.type()) .zeroOrOne() .build()) - .returnType(IBooleanItem.class) + .returnType(IBooleanItem.type()) .returnOne() .functionHandler(FnContains::execute) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnCount.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnCount.java index b5be3eb6c..4316e5988 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnCount.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnCount.java @@ -36,10 +36,10 @@ public final class FnCount { .focusIndependent() .argument(IArgument.builder() .name("arg") - .type(IItem.class) + .type(IItem.type()) .zeroOrMore() .build()) - .returnType(IIntegerItem.class) + .returnType(IIntegerItem.type()) .returnOne() .functionHandler(FnCount::execute) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnCurrentDateTime.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnCurrentDateTime.java index fa5143d96..d2504d59e 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnCurrentDateTime.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnCurrentDateTime.java @@ -29,7 +29,7 @@ public final class FnCurrentDateTime { .deterministic() .contextDependent() .focusIndependent() - .returnType(IDateTimeItem.class) + .returnType(IDateTimeItem.type()) .returnOne() .functionHandler(FnCurrentDateTime::execute) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnData.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnData.java index 6e2f21144..057d9478a 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnData.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnData.java @@ -38,7 +38,7 @@ public final class FnData { .deterministic() .contextDependent() .focusDependent() - .returnType(IAnyAtomicItem.class) + .returnType(IAnyAtomicItem.type()) .returnOne() .functionHandler(FnData::executeNoArg) .build(); @@ -52,10 +52,10 @@ public final class FnData { .focusIndependent() .argument(IArgument.builder() .name("arg1") - .type(IItem.class) + .type(IItem.type()) .zeroOrMore() .build()) - .returnType(IAnyAtomicItem.class) + .returnType(IAnyAtomicItem.type()) .returnOne() .functionHandler(FnData::executeOneArg) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnDoc.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnDoc.java index 5cff3b8fa..9a32fa797 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnDoc.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnDoc.java @@ -40,10 +40,10 @@ public final class FnDoc { .focusIndependent() .argument(IArgument.builder() .name("arg1") - .type(IStringItem.class) + .type(IStringItem.type()) .zeroOrOne() .build()) - .returnType(IDocumentNodeItem.class) + .returnType(IDocumentNodeItem.type()) .returnOne() .functionHandler(FnDoc::execute) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnDocumentAvailable.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnDocumentAvailable.java index a8ec32a93..61279b88b 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnDocumentAvailable.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnDocumentAvailable.java @@ -43,10 +43,10 @@ public final class FnDocumentAvailable { .focusIndependent() .argument(IArgument.builder() .name("arg1") - .type(IStringItem.class) + .type(IStringItem.type()) .zeroOrOne() .build()) - .returnType(IBooleanItem.class) + .returnType(IBooleanItem.type()) .returnOne() .functionHandler(FnDocumentAvailable::execute) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnDocumentUri.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnDocumentUri.java index 8a165e075..2098573e9 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnDocumentUri.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnDocumentUri.java @@ -37,7 +37,7 @@ public final class FnDocumentUri { .deterministic() .contextDependent() .focusDependent() - .returnType(IAnyUriItem.class) + .returnType(IAnyUriItem.type()) .returnOne() .functionHandler(FnDocumentUri::executeNoArg) .build(); @@ -51,10 +51,10 @@ public final class FnDocumentUri { .focusIndependent() .argument(IArgument.builder() .name("arg1") - .type(IDocumentNodeItem.class) + .type(IDocumentNodeItem.type()) .zeroOrOne() .build()) - .returnType(IAnyUriItem.class) + .returnType(IAnyUriItem.type()) .returnOne() .functionHandler(FnDocumentUri::executeOneArg) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnEmpty.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnEmpty.java index dd4794a11..505cd2e51 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnEmpty.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnEmpty.java @@ -36,10 +36,10 @@ public final class FnEmpty { .focusIndependent() .argument(IArgument.builder() .name("arg") - .type(IItem.class) + .type(IItem.type()) .zeroOrMore() .build()) - .returnType(IBooleanItem.class) + .returnType(IBooleanItem.type()) .returnOne() .functionHandler(FnEmpty::execute) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnEndsWith.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnEndsWith.java index 112ca514b..313afc9b6 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnEndsWith.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnEndsWith.java @@ -36,15 +36,16 @@ public final class FnEndsWith { .contextDependent() .focusIndependent() .argument(IArgument.builder() - .name("arg1").type(IStringItem.class) + .name("arg1") + .type(IStringItem.type()) .zeroOrOne() .build()) .argument(IArgument.builder() .name("arg2") - .type(IStringItem.class) + .type(IStringItem.type()) .zeroOrOne() .build()) - .returnType(IBooleanItem.class) + .returnType(IBooleanItem.type()) .returnOne() .functionHandler(FnEndsWith::execute) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnExists.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnExists.java index b91402450..222220e59 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnExists.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnExists.java @@ -35,10 +35,10 @@ public final class FnExists { .focusIndependent() .argument(IArgument.builder() .name("arg") - .type(IItem.class) + .type(IItem.type()) .zeroOrMore() .build()) - .returnType(IBooleanItem.class) + .returnType(IBooleanItem.type()) .returnOne() .functionHandler(FnExists::execute) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnFalse.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnFalse.java index f69ba4eac..cba9c5f9b 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnFalse.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnFalse.java @@ -30,7 +30,7 @@ public final class FnFalse { .deterministic() .contextIndependent() .focusIndependent() - .returnType(IBooleanItem.class) + .returnType(IBooleanItem.type()) .returnOne() .functionHandler(FnFalse::execute) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnHead.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnHead.java index 8b9d5300c..a1e1e028c 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnHead.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnHead.java @@ -34,10 +34,10 @@ public final class FnHead { .focusIndependent() .argument(IArgument.builder() .name("arg") - .type(IItem.class) + .type(IItem.type()) .zeroOrMore() .build()) - .returnType(IItem.class) + .returnType(IItem.type()) .returnZeroOrOne() .functionHandler(FnHead::execute) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnInsertBefore.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnInsertBefore.java index 342e163e3..ccded7a96 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnInsertBefore.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnInsertBefore.java @@ -36,20 +36,20 @@ public final class FnInsertBefore { .focusIndependent() .argument(IArgument.builder() .name("target") - .type(IItem.class) + .type(IItem.type()) .zeroOrMore() .build()) .argument(IArgument.builder() .name("position") - .type(IIntegerItem.class) + .type(IIntegerItem.type()) .one() .build()) .argument(IArgument.builder() .name("inserts") - .type(IItem.class) + .type(IItem.type()) .zeroOrMore() .build()) - .returnType(IItem.class) + .returnType(IItem.type()) .returnZeroOrMore() .functionHandler(FnInsertBefore::execute) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnLowerCase.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnLowerCase.java index 487c6bc11..6493cecfa 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnLowerCase.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnLowerCase.java @@ -37,10 +37,10 @@ public final class FnLowerCase { .focusIndependent() .argument(IArgument.builder() .name("arg") - .type(IStringItem.class) + .type(IStringItem.type()) .zeroOrOne() .build()) - .returnType(IStringItem.class) + .returnType(IStringItem.type()) .returnOne() .functionHandler(FnLowerCase::executeOneArg) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnMatches.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnMatches.java index b918ed050..1fe0a95c8 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnMatches.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnMatches.java @@ -43,15 +43,15 @@ public final class FnMatches { .focusIndependent() .argument(IArgument.builder() .name("input") - .type(IStringItem.class) + .type(IStringItem.type()) .zeroOrOne() .build()) .argument(IArgument.builder() .name("pattern") - .type(IStringItem.class) + .type(IStringItem.type()) .one() .build()) - .returnType(IBooleanItem.class) + .returnType(IBooleanItem.type()) .returnOne() .functionHandler(FnMatches::executeTwoArg) .build(); @@ -65,20 +65,20 @@ public final class FnMatches { .focusIndependent() .argument(IArgument.builder() .name("input") - .type(IStringItem.class) + .type(IStringItem.type()) .zeroOrOne() .build()) .argument(IArgument.builder() .name("pattern") - .type(IStringItem.class) + .type(IStringItem.type()) .one() .build()) .argument(IArgument.builder() .name("flags") - .type(IStringItem.class) + .type(IStringItem.type()) .one() .build()) - .returnType(IBooleanItem.class) + .returnType(IBooleanItem.type()) .returnOne() .functionHandler(FnMatches::executeThreeArg) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnMinMax.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnMinMax.java index afca2be5d..62c2a9a6b 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnMinMax.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnMinMax.java @@ -67,10 +67,10 @@ public final class FnMinMax { .focusIndependent() .argument(IArgument.builder() .name("arg") - .type(IAnyAtomicItem.class) + .type(IAnyAtomicItem.type()) .zeroOrMore() .build()) - .returnType(IAnyAtomicItem.class) + .returnType(IAnyAtomicItem.type()) .returnZeroOrOne() .functionHandler(FnMinMax::executeMin) .build(); @@ -84,10 +84,10 @@ public final class FnMinMax { .focusIndependent() .argument(IArgument.builder() .name("arg") - .type(IAnyAtomicItem.class) + .type(IAnyAtomicItem.type()) .zeroOrMore() .build()) - .returnType(IAnyAtomicItem.class) + .returnType(IAnyAtomicItem.type()) .returnZeroOrOne() .functionHandler(FnMinMax::executeMax) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnNormalizeSpace.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnNormalizeSpace.java index 27755e3da..f3c3dc199 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnNormalizeSpace.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnNormalizeSpace.java @@ -33,7 +33,7 @@ public final class FnNormalizeSpace { .deterministic() .contextDependent() .focusDependent() - .returnType(IStringItem.class) + .returnType(IStringItem.type()) .returnOne() .functionHandler(FnNormalizeSpace::executeNoArg) .build(); @@ -47,10 +47,10 @@ public final class FnNormalizeSpace { .focusIndependent() .argument(IArgument.builder() .name("arg") - .type(IStringItem.class) + .type(IStringItem.type()) .zeroOrOne() .build()) - .returnType(IStringItem.class) + .returnType(IStringItem.type()) .returnOne() .functionHandler(FnNormalizeSpace::executeOneArg) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnNot.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnNot.java index 51c745474..afc7d1180 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnNot.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnNot.java @@ -34,10 +34,10 @@ public final class FnNot { .focusIndependent() .argument(IArgument.builder() .name("arg") - .type(IItem.class) + .type(IItem.type()) .zeroOrMore() .build()) - .returnType(IBooleanItem.class) + .returnType(IBooleanItem.type()) .returnOne() .functionHandler(FnNot::execute) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnPath.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnPath.java index bfec72df8..e305b90b4 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnPath.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnPath.java @@ -40,7 +40,7 @@ public final class FnPath { .deterministic() .contextDependent() .focusDependent() - .returnType(IStringItem.class) + .returnType(IStringItem.type()) .returnZeroOrOne() .functionHandler(FnPath::executeNoArg) .build(); @@ -54,10 +54,10 @@ public final class FnPath { .focusIndependent() .argument(IArgument.builder() .name("arg1") - .type(INodeItem.class) + .type(INodeItem.type()) .zeroOrOne() .build()) - .returnType(IStringItem.class) + .returnType(IStringItem.type()) .returnZeroOrOne() .functionHandler(FnPath::executeOneArg) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnRemove.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnRemove.java index 158557c2d..a5a1ed10c 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnRemove.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnRemove.java @@ -36,15 +36,15 @@ public final class FnRemove { .focusIndependent() .argument(IArgument.builder() .name("target") - .type(IItem.class) + .type(IItem.type()) .zeroOrMore() .build()) .argument(IArgument.builder() .name("position") - .type(IIntegerItem.class) + .type(IIntegerItem.type()) .one() .build()) - .returnType(IItem.class) + .returnType(IItem.type()) .returnZeroOrMore() .functionHandler(FnRemove::execute) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnResolveUri.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnResolveUri.java index 124e66549..e9b504915 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnResolveUri.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnResolveUri.java @@ -39,10 +39,10 @@ public final class FnResolveUri { .focusIndependent() .argument(IArgument.builder() .name("relative") - .type(IStringItem.class) + .type(IStringItem.type()) .zeroOrOne() .build()) - .returnType(IAnyUriItem.class) + .returnType(IAnyUriItem.type()) .returnZeroOrOne() .functionHandler(FnResolveUri::executeOneArg) .build(); @@ -56,15 +56,15 @@ public final class FnResolveUri { .focusIndependent() .argument(IArgument.builder() .name("relative") - .type(IStringItem.class) + .type(IStringItem.type()) .zeroOrOne() .build()) .argument(IArgument.builder() .name("base") - .type(IStringItem.class) + .type(IStringItem.type()) .one() .build()) - .returnType(IAnyUriItem.class) + .returnType(IAnyUriItem.type()) .returnZeroOrOne() .functionHandler(FnResolveUri::executeTwoArg) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnReverse.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnReverse.java index 64eca5265..61e08b598 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnReverse.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnReverse.java @@ -36,10 +36,10 @@ public final class FnReverse { .focusIndependent() .argument(IArgument.builder() .name("target") - .type(IItem.class) + .type(IItem.type()) .zeroOrMore() .build()) - .returnType(IItem.class) + .returnType(IItem.type()) .returnZeroOrMore() .functionHandler(FnReverse::execute) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnRound.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnRound.java index 3ae34b270..163ff1791 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnRound.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnRound.java @@ -36,10 +36,10 @@ public final class FnRound { .focusIndependent() .argument(IArgument.builder() .name("arg") - .type(INumericItem.class) + .type(INumericItem.type()) .zeroOrOne() .build()) - .returnType(INumericItem.class) + .returnType(INumericItem.type()) .returnZeroOrOne() .functionHandler(FnRound::executeOneArg) .build(); @@ -53,15 +53,15 @@ public final class FnRound { .focusIndependent() .argument(IArgument.builder() .name("arg1") - .type(INumericItem.class) + .type(INumericItem.type()) .zeroOrOne() .build()) .argument(IArgument.builder() .name("precision") - .type(IIntegerItem.class) + .type(IIntegerItem.type()) .one() .build()) - .returnType(INumericItem.class) + .returnType(INumericItem.type()) .returnZeroOrOne() .functionHandler(FnRound::executeTwoArg) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnStartsWith.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnStartsWith.java index a666f4d28..1bdf83175 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnStartsWith.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnStartsWith.java @@ -36,15 +36,16 @@ public final class FnStartsWith { .contextDependent() .focusIndependent() .argument(IArgument.builder() - .name("arg1").type(IStringItem.class) + .name("arg1") + .type(IStringItem.type()) .zeroOrOne() .build()) .argument(IArgument.builder() .name("arg2") - .type(IStringItem.class) + .type(IStringItem.type()) .zeroOrOne() .build()) - .returnType(IBooleanItem.class) + .returnType(IBooleanItem.type()) .returnOne() .functionHandler(FnStartsWith::execute) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnStaticBaseUri.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnStaticBaseUri.java index 930e34413..d2950068d 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnStaticBaseUri.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnStaticBaseUri.java @@ -36,10 +36,10 @@ public final class FnStaticBaseUri { .focusIndependent() .argument(IArgument.builder() .name("arg1") - .type(IStringItem.class) + .type(IStringItem.type()) .zeroOrOne() .build()) - .returnType(IAnyUriItem.class) + .returnType(IAnyUriItem.type()) .returnOne() .functionHandler(FnStaticBaseUri::execute) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnString.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnString.java index accb38fd1..4b6ffd19d 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnString.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnString.java @@ -37,7 +37,7 @@ public final class FnString { .deterministic() .contextDependent() .focusDependent() - .returnType(IStringItem.class) + .returnType(IStringItem.type()) .returnOne() .functionHandler(FnString::executeNoArg) .build(); @@ -51,10 +51,10 @@ public final class FnString { .focusIndependent() .argument(IArgument.builder() .name("arg1") - .type(IItem.class) + .type(IItem.type()) .zeroOrOne() .build()) - .returnType(IStringItem.class) + .returnType(IStringItem.type()) .returnOne() .functionHandler(FnString::executeOneArg) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnStringLength.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnStringLength.java index ff64e91e6..1bd2f1cf9 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnStringLength.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnStringLength.java @@ -34,7 +34,7 @@ public final class FnStringLength { .deterministic() .contextDependent() .focusDependent() - .returnType(IIntegerItem.class) + .returnType(IIntegerItem.type()) .returnOne() .functionHandler(FnStringLength::executeNoArg) .build(); @@ -48,10 +48,10 @@ public final class FnStringLength { .focusIndependent() .argument(IArgument.builder() .name("arg1") - .type(IStringItem.class) + .type(IStringItem.type()) .zeroOrOne() .build()) - .returnType(IIntegerItem.class) + .returnType(IIntegerItem.type()) .returnOne() .functionHandler(FnStringLength::executeOneArg) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnSubstring.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnSubstring.java index 1c74f4d87..319fbe21b 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnSubstring.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnSubstring.java @@ -36,15 +36,15 @@ public final class FnSubstring { .focusIndependent() .argument(IArgument.builder() .name("sourceString") - .type(IStringItem.class) + .type(IStringItem.type()) .zeroOrOne() .build()) .argument(IArgument.builder() .name("start") - .type(IDecimalItem.class) + .type(IDecimalItem.type()) .one() .build()) - .returnType(IStringItem.class) + .returnType(IStringItem.type()) .returnOne() .functionHandler(FnSubstring::executeTwoArg) .build(); @@ -58,20 +58,20 @@ public final class FnSubstring { .focusIndependent() .argument(IArgument.builder() .name("sourceString") - .type(IStringItem.class) + .type(IStringItem.type()) .zeroOrOne() .build()) .argument(IArgument.builder() .name("start") - .type(IDecimalItem.class) + .type(IDecimalItem.type()) .one() .build()) .argument(IArgument.builder() .name("length") - .type(IDecimalItem.class) + .type(IDecimalItem.type()) .one() .build()) - .returnType(IStringItem.class) + .returnType(IStringItem.type()) .returnOne() .functionHandler(FnSubstring::executeThreeArg) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnSubstringAfter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnSubstringAfter.java index 4b20ced11..27e20c64b 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnSubstringAfter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnSubstringAfter.java @@ -38,15 +38,15 @@ public final class FnSubstringAfter { .focusIndependent() .argument(IArgument.builder() .name("arg1") - .type(IStringItem.class) + .type(IStringItem.type()) .zeroOrOne() .build()) .argument(IArgument.builder() .name("arg2") - .type(IStringItem.class) + .type(IStringItem.type()) .zeroOrOne() .build()) - .returnType(IStringItem.class) + .returnType(IStringItem.type()) .returnOne() .functionHandler(FnSubstringAfter::executeTwoArg) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnSubstringBefore.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnSubstringBefore.java index 687b5bd22..7ba0e8c73 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnSubstringBefore.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnSubstringBefore.java @@ -38,15 +38,15 @@ public final class FnSubstringBefore { .focusIndependent() .argument(IArgument.builder() .name("arg1") - .type(IStringItem.class) + .type(IStringItem.type()) .zeroOrOne() .build()) .argument(IArgument.builder() .name("arg2") - .type(IStringItem.class) + .type(IStringItem.type()) .zeroOrOne() .build()) - .returnType(IStringItem.class) + .returnType(IStringItem.type()) .returnOne() .functionHandler(FnSubstringBefore::executeTwoArg) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnSum.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnSum.java index e50ccc95b..cd7c98c5d 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnSum.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnSum.java @@ -45,10 +45,10 @@ public final class FnSum { .focusIndependent() .argument(IArgument.builder() .name("arg") - .type(IAnyAtomicItem.class) + .type(IAnyAtomicItem.type()) .zeroOrMore() .build()) - .returnType(IAnyAtomicItem.class) + .returnType(IAnyAtomicItem.type()) .returnOne() .functionHandler(FnSum::executeOneArg) .build(); @@ -62,15 +62,15 @@ public final class FnSum { .focusIndependent() .argument(IArgument.builder() .name("arg") - .type(IAnyAtomicItem.class) + .type(IAnyAtomicItem.type()) .zeroOrMore() .build()) .argument(IArgument.builder() .name("zero") - .type(IAnyAtomicItem.class) + .type(IAnyAtomicItem.type()) .zeroOrOne() .build()) - .returnType(IAnyAtomicItem.class) + .returnType(IAnyAtomicItem.type()) .returnZeroOrOne() .functionHandler(FnSum::executeTwoArg) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnTail.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnTail.java index 99384eb5f..c44b46818 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnTail.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnTail.java @@ -35,10 +35,10 @@ public final class FnTail { .focusIndependent() .argument(IArgument.builder() .name("arg") - .type(IItem.class) + .type(IItem.type()) .zeroOrMore() .build()) - .returnType(IItem.class) + .returnType(IItem.type()) .returnZeroOrMore() .functionHandler(FnTail::execute) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnTokenize.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnTokenize.java index ade0735d2..32159e51a 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnTokenize.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnTokenize.java @@ -45,10 +45,10 @@ public final class FnTokenize { .focusIndependent() .argument(IArgument.builder() .name("input") - .type(IStringItem.class) + .type(IStringItem.type()) .zeroOrOne() .build()) - .returnType(IStringItem.class) + .returnType(IStringItem.type()) .returnZeroOrMore() .functionHandler(FnTokenize::executeOneArg) .build(); @@ -61,15 +61,15 @@ public final class FnTokenize { .focusIndependent() .argument(IArgument.builder() .name("input") - .type(IStringItem.class) + .type(IStringItem.type()) .zeroOrOne() .build()) .argument(IArgument.builder() .name("pattern") - .type(IStringItem.class) + .type(IStringItem.type()) .one() .build()) - .returnType(IStringItem.class) + .returnType(IStringItem.type()) .returnZeroOrMore() .functionHandler(FnTokenize::executeTwoArg) .build(); @@ -83,20 +83,20 @@ public final class FnTokenize { .focusIndependent() .argument(IArgument.builder() .name("input") - .type(IStringItem.class) + .type(IStringItem.type()) .zeroOrOne() .build()) .argument(IArgument.builder() .name("pattern") - .type(IStringItem.class) + .type(IStringItem.type()) .one() .build()) .argument(IArgument.builder() .name("flags") - .type(IStringItem.class) + .type(IStringItem.type()) .one() .build()) - .returnType(IStringItem.class) + .returnType(IStringItem.type()) .returnZeroOrMore() .functionHandler(FnTokenize::executeThreeArg) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnTrue.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnTrue.java index 43017ac51..16a8f0329 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnTrue.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnTrue.java @@ -30,7 +30,7 @@ public final class FnTrue { .deterministic() .contextIndependent() .focusIndependent() - .returnType(IBooleanItem.class) + .returnType(IBooleanItem.type()) .returnOne() .functionHandler(FnTrue::execute) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnUpperCase.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnUpperCase.java index 9e199156f..48b98aaff 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnUpperCase.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnUpperCase.java @@ -37,10 +37,10 @@ public final class FnUpperCase { .focusIndependent() .argument(IArgument.builder() .name("arg") - .type(IStringItem.class) + .type(IStringItem.type()) .zeroOrOne() .build()) - .returnType(IStringItem.class) + .returnType(IStringItem.type()) .returnOne() .functionHandler(FnUpperCase::executeOneArg) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/MapContains.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/MapContains.java index ea4bcd5fe..0e4b7b37a 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/MapContains.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/MapContains.java @@ -38,15 +38,15 @@ public final class MapContains { .focusIndependent() .argument(IArgument.builder() .name("map") - .type(IMapItem.class) + .type(IMapItem.type()) .one() .build()) .argument(IArgument.builder() .name("key") - .type(IAnyAtomicItem.class) + .type(IAnyAtomicItem.type()) .one() .build()) - .returnType(IBooleanItem.class) + .returnType(IBooleanItem.type()) .returnOne() .functionHandler(MapContains::execute) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/MapEntry.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/MapEntry.java index 9500d8bb2..281ac7643 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/MapEntry.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/MapEntry.java @@ -37,15 +37,15 @@ public final class MapEntry { .focusIndependent() .argument(IArgument.builder() .name("key") - .type(IAnyAtomicItem.class) + .type(IAnyAtomicItem.type()) .one() .build()) .argument(IArgument.builder() .name("item") - .type(IItem.class) + .type(IItem.type()) .zeroOrMore() .build()) - .returnType(IItem.class) + .returnType(IItem.type()) .returnOne() .functionHandler(MapEntry::execute) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/MapFind.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/MapFind.java index 7eaaa10f3..77a7403e7 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/MapFind.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/MapFind.java @@ -41,15 +41,15 @@ public final class MapFind { .focusIndependent() .argument(IArgument.builder() .name("input") - .type(IItem.class) + .type(IItem.type()) .zeroOrMore() .build()) .argument(IArgument.builder() .name("key") - .type(IAnyAtomicItem.class) + .type(IAnyAtomicItem.type()) .one() .build()) - .returnType(IArrayItem.class) + .returnType(IArrayItem.type()) .returnOne() .functionHandler(MapFind::execute) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/MapGet.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/MapGet.java index 29051c6e0..3744d4e04 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/MapGet.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/MapGet.java @@ -38,15 +38,15 @@ public final class MapGet { .focusIndependent() .argument(IArgument.builder() .name("map") - .type(IMapItem.class) + .type(IMapItem.type()) .one() .build()) .argument(IArgument.builder() .name("key") - .type(IAnyAtomicItem.class) + .type(IAnyAtomicItem.type()) .one() .build()) - .returnType(IItem.class) + .returnType(IItem.type()) .returnZeroOrOne() .functionHandler(MapGet::execute) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/MapKeys.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/MapKeys.java index 76cb8f8d1..0783b0f83 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/MapKeys.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/MapKeys.java @@ -39,10 +39,10 @@ public final class MapKeys { .focusIndependent() .argument(IArgument.builder() .name("map") - .type(IMapItem.class) + .type(IMapItem.type()) .one() .build()) - .returnType(IAnyAtomicItem.class) + .returnType(IAnyAtomicItem.type()) .returnZeroOrMore() .functionHandler(MapKeys::execute) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/MapMerge.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/MapMerge.java index 593adc7e3..a1274578c 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/MapMerge.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/MapMerge.java @@ -52,10 +52,10 @@ public final class MapMerge { .focusIndependent() .argument(IArgument.builder() .name("maps") - .type(IMapItem.class) + .type(IMapItem.type()) .zeroOrMore() .build()) - .returnType(IMapItem.class) + .returnType(IMapItem.type()) .returnOne() .functionHandler(MapMerge::executeOneArg) .build(); @@ -69,15 +69,15 @@ public final class MapMerge { .focusIndependent() .argument(IArgument.builder() .name("maps") - .type(IMapItem.class) + .type(IMapItem.type()) .zeroOrMore() .build()) .argument(IArgument.builder() .name("options") - .type(IMapItem.class) + .type(IMapItem.type()) .one() .build()) - .returnType(IMapItem.class) + .returnType(IMapItem.type()) .returnOne() .functionHandler(MapMerge::executeTwoArg) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/MapPut.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/MapPut.java index eb6dbef22..0ce943bf4 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/MapPut.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/MapPut.java @@ -40,20 +40,20 @@ public final class MapPut { .focusIndependent() .argument(IArgument.builder() .name("map") - .type(IMapItem.class) + .type(IMapItem.type()) .one() .build()) .argument(IArgument.builder() .name("key") - .type(IAnyAtomicItem.class) + .type(IAnyAtomicItem.type()) .one() .build()) .argument(IArgument.builder() .name("value") - .type(IItem.class) + .type(IItem.type()) .zeroOrMore() .build()) - .returnType(IMapItem.class) + .returnType(IMapItem.type()) .returnOne() .functionHandler(MapPut::execute) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/MapRemove.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/MapRemove.java index ac0549d74..cf7b0bf11 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/MapRemove.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/MapRemove.java @@ -42,15 +42,15 @@ public final class MapRemove { .focusIndependent() .argument(IArgument.builder() .name("map") - .type(IMapItem.class) + .type(IMapItem.type()) .one() .build()) .argument(IArgument.builder() .name("keys") - .type(IAnyAtomicItem.class) + .type(IAnyAtomicItem.type()) .zeroOrMore() .build()) - .returnType(IMapItem.class) + .returnType(IMapItem.type()) .returnOne() .functionHandler(MapRemove::execute) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/MapSize.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/MapSize.java index a8b43db10..903f3b257 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/MapSize.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/MapSize.java @@ -36,10 +36,10 @@ public final class MapSize { .focusIndependent() .argument(IArgument.builder() .name("map") - .type(IMapItem.class) + .type(IMapItem.type()) .one() .build()) - .returnType(IIntegerItem.class) + .returnType(IIntegerItem.type()) .returnOne() .functionHandler(MapSize::execute) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/MpRecurseDepth.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/MpRecurseDepth.java index a4791858b..05280867d 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/MpRecurseDepth.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/MpRecurseDepth.java @@ -40,10 +40,10 @@ public final class MpRecurseDepth { .focusDependent() .argument(IArgument.builder() .name("recursePath") - .type(IStringItem.class) + .type(IStringItem.type()) .one() .build()) - .returnType(INodeItem.class) + .returnType(INodeItem.type()) .returnZeroOrMore() .functionHandler(MpRecurseDepth::executeOneArg) .build(); @@ -57,15 +57,15 @@ public final class MpRecurseDepth { .focusIndependent() .argument(IArgument.builder() .name("context") - .type(INodeItem.class) + .type(INodeItem.type()) .zeroOrMore() .build()) .argument(IArgument.builder() .name("recursePath") - .type(IStringItem.class) + .type(IStringItem.type()) .one() .build()) - .returnType(INodeItem.class) + .returnType(INodeItem.type()) .returnZeroOrMore() .functionHandler(MpRecurseDepth::executeTwoArg) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/NumericFunction.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/NumericFunction.java index ac3753edd..4a6f45696 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/NumericFunction.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/NumericFunction.java @@ -47,10 +47,10 @@ static IFunction signature(@NonNull String namespace, @NonNull String name, @Non .focusIndependent() .argument(IArgument.builder() .name("arg1") - .type(INumericItem.class) + .type(INumericItem.type()) .zeroOrOne() .build()) - .returnType(INumericItem.class) + .returnType(INumericItem.type()) .returnZeroOrOne() .functionHandler(newFunctionHandler(executor)) .build(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/impl/AbstractArrayItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/impl/AbstractArrayItem.java index 2f5e98041..14913301d 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/impl/AbstractArrayItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/impl/AbstractArrayItem.java @@ -36,9 +36,10 @@ public abstract class AbstractArrayItem EnumSet.of(FunctionProperty.DETERMINISTIC)); @NonNull public static final List ARGUMENTS = ObjectUtils.notNull(List.of( - IArgument.builder().name("position").type(IIntegerItem.class).one().build())); + IArgument.builder().name("position").type(IIntegerItem.type()).one().build())); @NonNull - public static final ISequenceType RESULT = ISequenceType.of(IAnyAtomicItem.class, Occurrence.ZERO_OR_ONE); + public static final ISequenceType RESULT = ISequenceType.of( + IAnyAtomicItem.type(), Occurrence.ZERO_OR_ONE); @NonNull private static final IArrayItem EMPTY = new ArrayItemN<>(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/impl/AbstractMapItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/impl/AbstractMapItem.java index 923b2c5b2..9f27f377c 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/impl/AbstractMapItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/impl/AbstractMapItem.java @@ -38,9 +38,10 @@ public abstract class AbstractMapItem EnumSet.of(FunctionProperty.DETERMINISTIC)); @NonNull public static final List ARGUMENTS = ObjectUtils.notNull(List.of( - IArgument.builder().name("key").type(IAnyAtomicItem.class).one().build())); + IArgument.builder().name("key").type(IAnyAtomicItem.type()).one().build())); @NonNull - public static final ISequenceType RESULT = ISequenceType.of(IAnyAtomicItem.class, Occurrence.ZERO_OR_ONE); + public static final ISequenceType RESULT = ISequenceType.of( + IAnyAtomicItem.type(), Occurrence.ZERO_OR_ONE); @NonNull private static final IMapItem EMPTY = new MapItemN<>(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/IItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/IItem.java index 378fe5a40..0659ab686 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/IItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/IItem.java @@ -8,12 +8,17 @@ import gov.nist.secauto.metaschema.core.datatype.IDataTypeAdapter; import gov.nist.secauto.metaschema.core.metapath.ICollectionValue; import gov.nist.secauto.metaschema.core.metapath.ISequence; +import gov.nist.secauto.metaschema.core.metapath.type.IItemType; import java.util.stream.Stream; import edu.umd.cs.findbugs.annotations.NonNull; public interface IItem extends ICollectionValue { + @NonNull + static IItemType type() { + return IItemType.item(); + } /** * Get the item's "wrapped" value. This "wrapped" value may be: diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/TypeSystem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/TypeSystem.java deleted file mode 100644 index d8017e3d2..000000000 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/TypeSystem.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * SPDX-FileCopyrightText: none - * SPDX-License-Identifier: CC0-1.0 - */ - -package gov.nist.secauto.metaschema.core.metapath.item; - -import gov.nist.secauto.metaschema.core.datatype.IDataTypeAdapter; -import gov.nist.secauto.metaschema.core.datatype.adapter.MetaschemaDataTypeProvider; -import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; -import gov.nist.secauto.metaschema.core.metapath.StaticContext; -import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyAtomicItem; -import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyUriItem; -import gov.nist.secauto.metaschema.core.metapath.item.atomic.IBase64BinaryItem; -import gov.nist.secauto.metaschema.core.metapath.item.atomic.IBooleanItem; -import gov.nist.secauto.metaschema.core.metapath.item.atomic.IDateItem; -import gov.nist.secauto.metaschema.core.metapath.item.atomic.IDateTimeItem; -import gov.nist.secauto.metaschema.core.metapath.item.atomic.IDayTimeDurationItem; -import gov.nist.secauto.metaschema.core.metapath.item.atomic.IDecimalItem; -import gov.nist.secauto.metaschema.core.metapath.item.atomic.IDurationItem; -import gov.nist.secauto.metaschema.core.metapath.item.atomic.IEmailAddressItem; -import gov.nist.secauto.metaschema.core.metapath.item.atomic.IHostnameItem; -import gov.nist.secauto.metaschema.core.metapath.item.atomic.IIPv4AddressItem; -import gov.nist.secauto.metaschema.core.metapath.item.atomic.IIPv6AddressItem; -import gov.nist.secauto.metaschema.core.metapath.item.atomic.IIntegerItem; -import gov.nist.secauto.metaschema.core.metapath.item.atomic.INcNameItem; -import gov.nist.secauto.metaschema.core.metapath.item.atomic.INonNegativeIntegerItem; -import gov.nist.secauto.metaschema.core.metapath.item.atomic.INumericItem; -import gov.nist.secauto.metaschema.core.metapath.item.atomic.IPositiveIntegerItem; -import gov.nist.secauto.metaschema.core.metapath.item.atomic.IStringItem; -import gov.nist.secauto.metaschema.core.metapath.item.atomic.ITokenItem; -import gov.nist.secauto.metaschema.core.metapath.item.atomic.IUriReferenceItem; -import gov.nist.secauto.metaschema.core.metapath.item.atomic.IUuidItem; -import gov.nist.secauto.metaschema.core.metapath.item.atomic.IYearMonthDurationItem; -import gov.nist.secauto.metaschema.core.metapath.item.function.IArrayItem; -import gov.nist.secauto.metaschema.core.metapath.item.function.IMapItem; -import gov.nist.secauto.metaschema.core.metapath.item.node.IAssemblyNodeItem; -import gov.nist.secauto.metaschema.core.metapath.item.node.IDocumentNodeItem; -import gov.nist.secauto.metaschema.core.metapath.item.node.IFieldNodeItem; -import gov.nist.secauto.metaschema.core.metapath.item.node.IFlagNodeItem; -import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem; -import gov.nist.secauto.metaschema.core.util.ObjectUtils; - -import java.util.Arrays; -import java.util.Collections; -import java.util.Map; -import java.util.stream.Stream; - -import javax.xml.namespace.QName; - -import edu.umd.cs.findbugs.annotations.NonNull; - -@SuppressWarnings({ "removal", "deprecation" }) -public final class TypeSystem { - private static final Map, QName> ITEM_CLASS_TO_QNAME_MAP; - - static { - ITEM_CLASS_TO_QNAME_MAP = Collections.unmodifiableMap(Map.ofEntries( - register(IItem.class, "item"), - register(INodeItem.class, "node"), - register(IDocumentNodeItem.class, "document-node"), - register(IAssemblyNodeItem.class, "assembly-node"), - register(IFieldNodeItem.class, "field-node"), - register(IFlagNodeItem.class, "flag-node"), - register(IArrayItem.class, "array"), - register(IMapItem.class, "map"), - register(IAnyAtomicItem.class, "any-atomic-type"), - register(INumericItem.class, "numeric"), - register(IDurationItem.class, "duration"), - register(IBase64BinaryItem.class, MetaschemaDataTypeProvider.BASE64), - register(IBooleanItem.class, MetaschemaDataTypeProvider.BOOLEAN), - register(IDateItem.class, MetaschemaDataTypeProvider.DATE), - // register(IDate.class, MetaschemaDataTypeProvider.DATE_WITH_TZ), - register(IDateTimeItem.class, MetaschemaDataTypeProvider.DATE_TIME), - // register(IBooleanItem.class, MetaschemaDataTypeProvider.DATE_TIME_WITH_TZ), - register(IIPv4AddressItem.class, MetaschemaDataTypeProvider.IP_V4_ADDRESS), - register(IIPv6AddressItem.class, MetaschemaDataTypeProvider.IP_V6_ADDRESS), - register(IAnyUriItem.class, MetaschemaDataTypeProvider.URI), - register(IUriReferenceItem.class, MetaschemaDataTypeProvider.URI_REFERENCE), - register(IUuidItem.class, MetaschemaDataTypeProvider.UUID), - register(IDayTimeDurationItem.class, MetaschemaDataTypeProvider.DAY_TIME_DURATION), - register(IYearMonthDurationItem.class, MetaschemaDataTypeProvider.YEAR_MONTH_DURATION), - register(IDecimalItem.class, MetaschemaDataTypeProvider.DECIMAL), - register(IIntegerItem.class, MetaschemaDataTypeProvider.INTEGER), - register(INonNegativeIntegerItem.class, MetaschemaDataTypeProvider.NON_NEGATIVE_INTEGER), - register(IPositiveIntegerItem.class, MetaschemaDataTypeProvider.POSITIVE_INTEGER), - register(IEmailAddressItem.class, MetaschemaDataTypeProvider.EMAIL_ADDRESS), - register(IHostnameItem.class, MetaschemaDataTypeProvider.HOSTNAME), - register(INcNameItem.class, MetaschemaDataTypeProvider.NCNAME), - register(IStringItem.class, MetaschemaDataTypeProvider.STRING), - register(ITokenItem.class, MetaschemaDataTypeProvider.TOKEN))); - } - - private static Map.Entry, QName> register( - @NonNull Class clazz, - @NonNull IDataTypeAdapter adapter) { - return Map.entry(clazz, adapter.getPreferredName()); - } - - private static Map.Entry, QName> register( - @NonNull Class clazz, - @NonNull String typeName) { - return Map.entry(clazz, new QName(MetapathConstants.NS_METAPATH.toASCIIString(), typeName)); - } - - @NonNull - private static Stream> getItemInterfaces(@NonNull Class clazz) { - @SuppressWarnings("unchecked") - Stream> retval = IItem.class.isAssignableFrom(clazz) - ? Stream.of((Class) clazz) - : Stream.empty(); - - Class[] interfaces = clazz.getInterfaces(); - if (interfaces.length > 0) { - retval = Stream.concat(retval, Arrays.stream(interfaces).flatMap(TypeSystem::getItemInterfaces)); - } - - return ObjectUtils.notNull(retval); - } - - /** - * Get the human-friendly data type name for the provided Metapath item class. - * - * @param clazz - * the Metapath item class to get the name for - * @return the name or {@code null} if no name is registered for the item class - */ - public static String getName(@NonNull Class clazz) { - Class itemClass = getItemInterfaces(clazz).findFirst().orElse(null); - - QName qname = ITEM_CLASS_TO_QNAME_MAP.get(itemClass); - return qname == null ? clazz.getName() : asPrefixedName(qname); - } - - private static String asPrefixedName(@NonNull QName qname) { - String namespace = qname.getNamespaceURI(); - String prefix = namespace.isEmpty() ? null : StaticContext.getWellKnownPrefixForUri(namespace); - return prefix == null ? qname.toString() : prefix + ":" + qname.getLocalPart(); - } - - private TypeSystem() { - // disable construction - } -} diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IAnyAtomicItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IAnyAtomicItem.java index fef08f6fe..54b27a792 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IAnyAtomicItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IAnyAtomicItem.java @@ -11,6 +11,8 @@ import gov.nist.secauto.metaschema.core.metapath.item.IItemVisitor; import gov.nist.secauto.metaschema.core.metapath.item.function.IMapItem; import gov.nist.secauto.metaschema.core.metapath.item.function.IMapKey; +import gov.nist.secauto.metaschema.core.metapath.type.IAtomicOrUnionType; +import gov.nist.secauto.metaschema.core.metapath.type.IItemType; import edu.umd.cs.findbugs.annotations.NonNull; @@ -20,6 +22,10 @@ * structures in the Metaschema framework. */ public interface IAnyAtomicItem extends IAtomicValuedItem, IPrintable { + @NonNull + static IAtomicOrUnionType type() { + return IItemType.anyAtomic(); + } @Override @NonNull diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IAnyUriItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IAnyUriItem.java index 2521e5bdf..bda7bc35b 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IAnyUriItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IAnyUriItem.java @@ -6,9 +6,10 @@ package gov.nist.secauto.metaschema.core.metapath.item.atomic; import gov.nist.secauto.metaschema.core.datatype.adapter.MetaschemaDataTypeProvider; -import gov.nist.secauto.metaschema.core.metapath.InvalidTypeMetapathException; import gov.nist.secauto.metaschema.core.metapath.function.InvalidValueForCastFunctionException; import gov.nist.secauto.metaschema.core.metapath.item.atomic.impl.AnyUriItemImpl; +import gov.nist.secauto.metaschema.core.metapath.type.IAtomicOrUnionType; +import gov.nist.secauto.metaschema.core.metapath.type.InvalidTypeMetapathException; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.net.URI; @@ -19,6 +20,11 @@ * An atomic Metapath item containing a URI data value. */ public interface IAnyUriItem extends IAnyAtomicItem { + @NonNull + static IAtomicOrUnionType type() { + return MetaschemaDataTypeProvider.URI.getItemType(); + } + /** * Construct a new URI item using the provided string {@code value}. * diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IBase64BinaryItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IBase64BinaryItem.java index 82a912079..c36663332 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IBase64BinaryItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IBase64BinaryItem.java @@ -6,9 +6,10 @@ package gov.nist.secauto.metaschema.core.metapath.item.atomic; import gov.nist.secauto.metaschema.core.datatype.adapter.MetaschemaDataTypeProvider; -import gov.nist.secauto.metaschema.core.metapath.InvalidTypeMetapathException; import gov.nist.secauto.metaschema.core.metapath.function.InvalidValueForCastFunctionException; import gov.nist.secauto.metaschema.core.metapath.item.atomic.impl.Base64BinaryItemImpl; +import gov.nist.secauto.metaschema.core.metapath.type.IAtomicOrUnionType; +import gov.nist.secauto.metaschema.core.metapath.type.InvalidTypeMetapathException; import java.nio.ByteBuffer; @@ -18,6 +19,10 @@ * An atomic Metapath item containing a Base64 encoded data value. */ public interface IBase64BinaryItem extends IAnyAtomicItem { + @NonNull + static IAtomicOrUnionType type() { + return MetaschemaDataTypeProvider.BASE64.getItemType(); + } /** * Construct a new base64 encoded byte sequence item using the provided string diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IBooleanItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IBooleanItem.java index 20016c0ed..acc9b6dee 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IBooleanItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IBooleanItem.java @@ -6,9 +6,10 @@ package gov.nist.secauto.metaschema.core.metapath.item.atomic; import gov.nist.secauto.metaschema.core.datatype.adapter.MetaschemaDataTypeProvider; -import gov.nist.secauto.metaschema.core.metapath.InvalidTypeMetapathException; import gov.nist.secauto.metaschema.core.metapath.function.InvalidValueForCastFunctionException; import gov.nist.secauto.metaschema.core.metapath.item.atomic.impl.BooleanItemImpl; +import gov.nist.secauto.metaschema.core.metapath.type.IAtomicOrUnionType; +import gov.nist.secauto.metaschema.core.metapath.type.InvalidTypeMetapathException; import edu.umd.cs.findbugs.annotations.NonNull; @@ -27,6 +28,11 @@ public interface IBooleanItem extends IAnyAtomicItem { @NonNull IBooleanItem FALSE = new BooleanItemImpl(false); + @NonNull + static IAtomicOrUnionType type() { + return MetaschemaDataTypeProvider.BOOLEAN.getItemType(); + } + /** * Construct a new boolean item using the provided string {@code value}. *

diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IDateItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IDateItem.java index c29e38f66..b0b29d1df 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IDateItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IDateItem.java @@ -8,10 +8,11 @@ import gov.nist.secauto.metaschema.core.datatype.adapter.MetaschemaDataTypeProvider; import gov.nist.secauto.metaschema.core.datatype.object.AmbiguousDate; import gov.nist.secauto.metaschema.core.datatype.object.AmbiguousDateTime; -import gov.nist.secauto.metaschema.core.metapath.InvalidTypeMetapathException; import gov.nist.secauto.metaschema.core.metapath.function.InvalidValueForCastFunctionException; import gov.nist.secauto.metaschema.core.metapath.item.atomic.impl.DateWithTimeZoneItemImpl; import gov.nist.secauto.metaschema.core.metapath.item.atomic.impl.DateWithoutTimeZoneItemImpl; +import gov.nist.secauto.metaschema.core.metapath.type.IAtomicOrUnionType; +import gov.nist.secauto.metaschema.core.metapath.type.InvalidTypeMetapathException; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.time.LocalDate; @@ -26,6 +27,11 @@ */ public interface IDateItem extends ITemporalItem { + @NonNull + static IAtomicOrUnionType type() { + return MetaschemaDataTypeProvider.DATE.getItemType(); + } + /** * Construct a new date item using the provided string {@code value}. * diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IDateTimeItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IDateTimeItem.java index 83292573d..13b5af857 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IDateTimeItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IDateTimeItem.java @@ -7,10 +7,11 @@ import gov.nist.secauto.metaschema.core.datatype.adapter.MetaschemaDataTypeProvider; import gov.nist.secauto.metaschema.core.datatype.object.AmbiguousDateTime; -import gov.nist.secauto.metaschema.core.metapath.InvalidTypeMetapathException; import gov.nist.secauto.metaschema.core.metapath.function.InvalidValueForCastFunctionException; import gov.nist.secauto.metaschema.core.metapath.item.atomic.impl.DateTimeWithTimeZoneItemImpl; import gov.nist.secauto.metaschema.core.metapath.item.atomic.impl.DateTimeWithoutTimeZoneItemImpl; +import gov.nist.secauto.metaschema.core.metapath.type.IAtomicOrUnionType; +import gov.nist.secauto.metaschema.core.metapath.type.InvalidTypeMetapathException; import java.time.ZonedDateTime; @@ -26,6 +27,11 @@ * properly handle time zone ambiguity. */ public interface IDateTimeItem extends ITemporalItem { + @NonNull + static IAtomicOrUnionType type() { + return MetaschemaDataTypeProvider.DATE_TIME.getItemType(); + } + /** * Construct a new date/time item using the provided string {@code value}. * diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IDayTimeDurationItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IDayTimeDurationItem.java index 42a28ecb2..31e655053 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IDayTimeDurationItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IDayTimeDurationItem.java @@ -6,9 +6,10 @@ package gov.nist.secauto.metaschema.core.metapath.item.atomic; import gov.nist.secauto.metaschema.core.datatype.adapter.MetaschemaDataTypeProvider; -import gov.nist.secauto.metaschema.core.metapath.InvalidTypeMetapathException; import gov.nist.secauto.metaschema.core.metapath.function.InvalidValueForCastFunctionException; import gov.nist.secauto.metaschema.core.metapath.item.atomic.impl.DayTimeDurationItemImpl; +import gov.nist.secauto.metaschema.core.metapath.type.IAtomicOrUnionType; +import gov.nist.secauto.metaschema.core.metapath.type.InvalidTypeMetapathException; import java.time.Duration; @@ -19,6 +20,11 @@ * seconds. */ public interface IDayTimeDurationItem extends IDurationItem { + @NonNull + static IAtomicOrUnionType type() { + return MetaschemaDataTypeProvider.DAY_TIME_DURATION.getItemType(); + } + /** * Construct a new day time duration item using the provided string * {@code value}. diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IDecimalItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IDecimalItem.java index a6900b323..d30ab4ced 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IDecimalItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IDecimalItem.java @@ -6,9 +6,10 @@ package gov.nist.secauto.metaschema.core.metapath.item.atomic; import gov.nist.secauto.metaschema.core.datatype.adapter.MetaschemaDataTypeProvider; -import gov.nist.secauto.metaschema.core.metapath.InvalidTypeMetapathException; import gov.nist.secauto.metaschema.core.metapath.function.InvalidValueForCastFunctionException; import gov.nist.secauto.metaschema.core.metapath.item.atomic.impl.DecimalItemImpl; +import gov.nist.secauto.metaschema.core.metapath.type.IAtomicOrUnionType; +import gov.nist.secauto.metaschema.core.metapath.type.InvalidTypeMetapathException; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.math.BigDecimal; @@ -26,6 +27,11 @@ public interface IDecimalItem extends INumericItem { @NonNull IDecimalItem ZERO = valueOf(ObjectUtils.notNull(BigDecimal.ZERO)); + @NonNull + static IAtomicOrUnionType type() { + return MetaschemaDataTypeProvider.DECIMAL.getItemType(); + } + /** * Construct a new decimal item using the provided string {@code value}. * diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IDurationItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IDurationItem.java index 6b0b7fc7d..ccac0f873 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IDurationItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IDurationItem.java @@ -6,6 +6,8 @@ package gov.nist.secauto.metaschema.core.metapath.item.atomic; import gov.nist.secauto.metaschema.core.metapath.function.InvalidValueForCastFunctionException; +import gov.nist.secauto.metaschema.core.metapath.item.atomic.impl.AtomicItemConstants; +import gov.nist.secauto.metaschema.core.metapath.type.IAtomicOrUnionType; import java.time.temporal.TemporalAmount; @@ -25,6 +27,11 @@ * @see IYearMonthDurationItem */ public interface IDurationItem extends IAnyAtomicItem { + @NonNull + static IAtomicOrUnionType type() { + return AtomicItemConstants.DURATION_ITEM_TYPE; + } + /** * Cast the provided type to this item type. * diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IEmailAddressItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IEmailAddressItem.java index bc54171fc..237a966fd 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IEmailAddressItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IEmailAddressItem.java @@ -6,9 +6,10 @@ package gov.nist.secauto.metaschema.core.metapath.item.atomic; import gov.nist.secauto.metaschema.core.datatype.adapter.MetaschemaDataTypeProvider; -import gov.nist.secauto.metaschema.core.metapath.InvalidTypeMetapathException; import gov.nist.secauto.metaschema.core.metapath.function.InvalidValueForCastFunctionException; import gov.nist.secauto.metaschema.core.metapath.item.atomic.impl.EmailAddressItemImpl; +import gov.nist.secauto.metaschema.core.metapath.type.IAtomicOrUnionType; +import gov.nist.secauto.metaschema.core.metapath.type.InvalidTypeMetapathException; import edu.umd.cs.findbugs.annotations.NonNull; @@ -16,8 +17,14 @@ * An atomic Metapath item containing an email address data value. */ public interface IEmailAddressItem extends IStringItem { + @NonNull + static IAtomicOrUnionType type() { + return MetaschemaDataTypeProvider.EMAIL_ADDRESS.getItemType(); + } + /** - * Construct a new email address item using the provided string {@code value}. + * /** Construct a new email address item using the provided string + * {@code value}. * * @param value * a string representing an email address value diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IHostnameItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IHostnameItem.java index 001f1bfc4..a6930fc93 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IHostnameItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IHostnameItem.java @@ -6,9 +6,10 @@ package gov.nist.secauto.metaschema.core.metapath.item.atomic; import gov.nist.secauto.metaschema.core.datatype.adapter.MetaschemaDataTypeProvider; -import gov.nist.secauto.metaschema.core.metapath.InvalidTypeMetapathException; import gov.nist.secauto.metaschema.core.metapath.function.InvalidValueForCastFunctionException; import gov.nist.secauto.metaschema.core.metapath.item.atomic.impl.HostnameItemImpl; +import gov.nist.secauto.metaschema.core.metapath.type.IAtomicOrUnionType; +import gov.nist.secauto.metaschema.core.metapath.type.InvalidTypeMetapathException; import edu.umd.cs.findbugs.annotations.NonNull; @@ -16,6 +17,11 @@ * An atomic Metapath item containing a hostname data value. */ public interface IHostnameItem extends IStringItem { + @NonNull + static IAtomicOrUnionType type() { + return MetaschemaDataTypeProvider.HOSTNAME.getItemType(); + } + /** * Construct a new host name item using the provided string {@code value}. * diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IIPAddressItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IIPAddressItem.java index 59dd04a23..3fe28d24a 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IIPAddressItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IIPAddressItem.java @@ -6,6 +6,8 @@ package gov.nist.secauto.metaschema.core.metapath.item.atomic; import gov.nist.secauto.metaschema.core.metapath.function.InvalidValueForCastFunctionException; +import gov.nist.secauto.metaschema.core.metapath.item.atomic.impl.AtomicItemConstants; +import gov.nist.secauto.metaschema.core.metapath.type.IAtomicOrUnionType; import edu.umd.cs.findbugs.annotations.NonNull; import inet.ipaddr.IPAddress; @@ -14,6 +16,11 @@ * An atomic Metapath item representing an IP address data value. */ public interface IIPAddressItem extends IUntypedAtomicItem { + @NonNull + static IAtomicOrUnionType type() { + return AtomicItemConstants.IP_ADDRESS_ITEM_TYPE; + } + /** * Get the "wrapped" IP address value. * diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IIPv4AddressItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IIPv4AddressItem.java index 7de02e6f5..55346d0de 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IIPv4AddressItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IIPv4AddressItem.java @@ -6,9 +6,10 @@ package gov.nist.secauto.metaschema.core.metapath.item.atomic; import gov.nist.secauto.metaschema.core.datatype.adapter.MetaschemaDataTypeProvider; -import gov.nist.secauto.metaschema.core.metapath.InvalidTypeMetapathException; import gov.nist.secauto.metaschema.core.metapath.function.InvalidValueForCastFunctionException; import gov.nist.secauto.metaschema.core.metapath.item.atomic.impl.IPv4AddressItemImpl; +import gov.nist.secauto.metaschema.core.metapath.type.IAtomicOrUnionType; +import gov.nist.secauto.metaschema.core.metapath.type.InvalidTypeMetapathException; import edu.umd.cs.findbugs.annotations.NonNull; import inet.ipaddr.ipv4.IPv4Address; @@ -17,6 +18,10 @@ * An atomic Metapath item containing an IPv4 address data value. */ public interface IIPv4AddressItem extends IIPAddressItem { + @NonNull + static IAtomicOrUnionType type() { + return MetaschemaDataTypeProvider.IP_V4_ADDRESS.getItemType(); + } /** * Construct a new IPv4 item using the provided {@code value}. diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IIPv6AddressItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IIPv6AddressItem.java index 82c3234a8..93b68fda8 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IIPv6AddressItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IIPv6AddressItem.java @@ -6,9 +6,10 @@ package gov.nist.secauto.metaschema.core.metapath.item.atomic; import gov.nist.secauto.metaschema.core.datatype.adapter.MetaschemaDataTypeProvider; -import gov.nist.secauto.metaschema.core.metapath.InvalidTypeMetapathException; import gov.nist.secauto.metaschema.core.metapath.function.InvalidValueForCastFunctionException; import gov.nist.secauto.metaschema.core.metapath.item.atomic.impl.IPv6AddressItemImpl; +import gov.nist.secauto.metaschema.core.metapath.type.IAtomicOrUnionType; +import gov.nist.secauto.metaschema.core.metapath.type.InvalidTypeMetapathException; import edu.umd.cs.findbugs.annotations.NonNull; import inet.ipaddr.ipv6.IPv6Address; @@ -17,6 +18,10 @@ * An atomic Metapath item containing an IPv6 address data value. */ public interface IIPv6AddressItem extends IIPAddressItem { + @NonNull + static IAtomicOrUnionType type() { + return MetaschemaDataTypeProvider.IP_V6_ADDRESS.getItemType(); + } /** * Construct a new IPv6 item using the provided {@code value}. diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IIntegerItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IIntegerItem.java index 738205771..f591ac1a5 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IIntegerItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IIntegerItem.java @@ -5,8 +5,10 @@ package gov.nist.secauto.metaschema.core.metapath.item.atomic; +import gov.nist.secauto.metaschema.core.datatype.adapter.MetaschemaDataTypeProvider; import gov.nist.secauto.metaschema.core.metapath.function.InvalidValueForCastFunctionException; import gov.nist.secauto.metaschema.core.metapath.item.atomic.impl.IntegerItemImpl; +import gov.nist.secauto.metaschema.core.metapath.type.IAtomicOrUnionType; import gov.nist.secauto.metaschema.core.metapath.type.InvalidTypeMetapathException; import gov.nist.secauto.metaschema.core.util.ObjectUtils; @@ -34,6 +36,11 @@ public interface IIntegerItem extends IDecimalItem { @NonNull IIntegerItem NEGATIVE_ONE = valueOf(ObjectUtils.notNull(BigInteger.ONE.negate())); + @NonNull + static IAtomicOrUnionType type() { + return MetaschemaDataTypeProvider.INTEGER.getItemType(); + } + /** * Create an item from an existing integer value. * @@ -46,7 +53,7 @@ public interface IIntegerItem extends IDecimalItem { @NonNull static IIntegerItem valueOf(@NonNull String value) { try { - return valueOf(new BigInteger(value)); + return valueOf(MetaschemaDataTypeProvider.INTEGER.parse(value)); } catch (NumberFormatException ex) { throw new InvalidTypeMetapathException(null, ex.getMessage(), diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IMarkupItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IMarkupItem.java index c6bbc0e17..f74cfe096 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IMarkupItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IMarkupItem.java @@ -9,10 +9,12 @@ import gov.nist.secauto.metaschema.core.datatype.markup.MarkupDataTypeProvider; import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine; import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline; -import gov.nist.secauto.metaschema.core.metapath.InvalidTypeMetapathException; import gov.nist.secauto.metaschema.core.metapath.function.InvalidValueForCastFunctionException; +import gov.nist.secauto.metaschema.core.metapath.item.atomic.impl.AtomicItemConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.impl.MarkupLineItemImpl; import gov.nist.secauto.metaschema.core.metapath.item.atomic.impl.MarkupMultiLineItemImpl; +import gov.nist.secauto.metaschema.core.metapath.type.IAtomicOrUnionType; +import gov.nist.secauto.metaschema.core.metapath.type.InvalidTypeMetapathException; import edu.umd.cs.findbugs.annotations.NonNull; @@ -20,6 +22,11 @@ * An atomic Metapath item representing a Markup data value. */ public interface IMarkupItem extends IUntypedAtomicItem { + @NonNull + static IAtomicOrUnionType type() { + return AtomicItemConstants.MARKUP_ITEM_TYPE; + } + /** * Construct a new item using the provided {@code value}. * diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/INcNameItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/INcNameItem.java index 3253d8d2d..7cf3cc753 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/INcNameItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/INcNameItem.java @@ -6,9 +6,10 @@ package gov.nist.secauto.metaschema.core.metapath.item.atomic; import gov.nist.secauto.metaschema.core.datatype.adapter.MetaschemaDataTypeProvider; -import gov.nist.secauto.metaschema.core.metapath.InvalidTypeMetapathException; import gov.nist.secauto.metaschema.core.metapath.function.InvalidValueForCastFunctionException; import gov.nist.secauto.metaschema.core.metapath.item.atomic.impl.NcNameItemImpl; +import gov.nist.secauto.metaschema.core.metapath.type.IAtomicOrUnionType; +import gov.nist.secauto.metaschema.core.metapath.type.InvalidTypeMetapathException; import edu.umd.cs.findbugs.annotations.NonNull; @@ -17,6 +18,11 @@ */ @Deprecated(forRemoval = true, since = "0.7.0") public interface INcNameItem extends IStringItem { + @NonNull + static IAtomicOrUnionType type() { + return MetaschemaDataTypeProvider.NCNAME.getItemType(); + } + /** * Construct a new item using the provided string {@code value}. * diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/INonNegativeIntegerItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/INonNegativeIntegerItem.java index 7c843c5ce..2057afab6 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/INonNegativeIntegerItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/INonNegativeIntegerItem.java @@ -8,6 +8,7 @@ import gov.nist.secauto.metaschema.core.datatype.adapter.MetaschemaDataTypeProvider; import gov.nist.secauto.metaschema.core.metapath.function.InvalidValueForCastFunctionException; import gov.nist.secauto.metaschema.core.metapath.item.atomic.impl.NonNegativeIntegerItemImpl; +import gov.nist.secauto.metaschema.core.metapath.type.IAtomicOrUnionType; import gov.nist.secauto.metaschema.core.metapath.type.InvalidTypeMetapathException; import gov.nist.secauto.metaschema.core.util.ObjectUtils; @@ -30,6 +31,11 @@ public interface INonNegativeIntegerItem extends IIntegerItem { @NonNull INonNegativeIntegerItem ZERO = valueOf(ObjectUtils.notNull(BigInteger.ZERO)); + @NonNull + static IAtomicOrUnionType type() { + return MetaschemaDataTypeProvider.NON_NEGATIVE_INTEGER.getItemType(); + } + /** * Create an item from an existing integer value. * diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/INumericItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/INumericItem.java index 2ea3b0f10..1e8d7ab88 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/INumericItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/INumericItem.java @@ -5,10 +5,12 @@ package gov.nist.secauto.metaschema.core.metapath.item.atomic; -import gov.nist.secauto.metaschema.core.metapath.InvalidTypeMetapathException; import gov.nist.secauto.metaschema.core.metapath.function.ArithmeticFunctionException; import gov.nist.secauto.metaschema.core.metapath.function.FunctionUtils; import gov.nist.secauto.metaschema.core.metapath.function.InvalidValueForCastFunctionException; +import gov.nist.secauto.metaschema.core.metapath.item.atomic.impl.AtomicItemConstants; +import gov.nist.secauto.metaschema.core.metapath.type.IAtomicOrUnionType; +import gov.nist.secauto.metaschema.core.metapath.type.InvalidTypeMetapathException; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.math.BigDecimal; @@ -28,6 +30,10 @@ * @see IDecimalItem */ public interface INumericItem extends IAnyAtomicItem { + @NonNull + static IAtomicOrUnionType type() { + return AtomicItemConstants.NUMERIC_ITEM_TYPE; + } /** * Cast the provided type to this item type. diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IPositiveIntegerItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IPositiveIntegerItem.java index ffd244582..5ac44d9e8 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IPositiveIntegerItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IPositiveIntegerItem.java @@ -5,8 +5,10 @@ package gov.nist.secauto.metaschema.core.metapath.item.atomic; +import gov.nist.secauto.metaschema.core.datatype.adapter.MetaschemaDataTypeProvider; import gov.nist.secauto.metaschema.core.metapath.function.InvalidValueForCastFunctionException; import gov.nist.secauto.metaschema.core.metapath.item.atomic.impl.PositiveIntegerItemImpl; +import gov.nist.secauto.metaschema.core.metapath.type.IAtomicOrUnionType; import gov.nist.secauto.metaschema.core.metapath.type.InvalidTypeMetapathException; import java.math.BigInteger; @@ -24,6 +26,11 @@ public interface IPositiveIntegerItem extends INonNegativeIntegerItem { @NonNull IPositiveIntegerItem ONE = valueOf(BigInteger.ONE); + @NonNull + static IAtomicOrUnionType type() { + return MetaschemaDataTypeProvider.POSITIVE_INTEGER.getItemType(); + } + /** * Create an item from an existing integer value. * @@ -36,7 +43,7 @@ public interface IPositiveIntegerItem extends INonNegativeIntegerItem { @NonNull static IPositiveIntegerItem valueOf(@NonNull String value) { try { - return valueOf(new BigInteger(value)); + return valueOf(MetaschemaDataTypeProvider.POSITIVE_INTEGER.parse(value)); } catch (IllegalArgumentException ex) { throw new InvalidTypeMetapathException( null, diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IStringItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IStringItem.java index 3742a9414..ad41c9a77 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IStringItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IStringItem.java @@ -6,9 +6,10 @@ package gov.nist.secauto.metaschema.core.metapath.item.atomic; import gov.nist.secauto.metaschema.core.datatype.adapter.MetaschemaDataTypeProvider; -import gov.nist.secauto.metaschema.core.metapath.InvalidTypeMetapathException; import gov.nist.secauto.metaschema.core.metapath.function.InvalidValueForCastFunctionException; import gov.nist.secauto.metaschema.core.metapath.item.atomic.impl.StringItemImpl; +import gov.nist.secauto.metaschema.core.metapath.type.IAtomicOrUnionType; +import gov.nist.secauto.metaschema.core.metapath.type.InvalidTypeMetapathException; import edu.umd.cs.findbugs.annotations.NonNull; @@ -16,6 +17,11 @@ * An atomic Metapath item containing a text data value. */ public interface IStringItem extends IAnyAtomicItem { + @NonNull + static IAtomicOrUnionType type() { + return MetaschemaDataTypeProvider.STRING.getItemType(); + } + /** * Construct a new item using the provided string {@code value}. * diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/ITemporalItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/ITemporalItem.java index f60a6e16a..3acee0f5a 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/ITemporalItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/ITemporalItem.java @@ -5,6 +5,9 @@ package gov.nist.secauto.metaschema.core.metapath.item.atomic; +import gov.nist.secauto.metaschema.core.metapath.item.atomic.impl.AtomicItemConstants; +import gov.nist.secauto.metaschema.core.metapath.type.IAtomicOrUnionType; + import java.time.ZonedDateTime; import edu.umd.cs.findbugs.annotations.NonNull; @@ -13,6 +16,11 @@ * An atomic Metapath item containing a temporal data value. */ public interface ITemporalItem extends IAnyAtomicItem { + @NonNull + static IAtomicOrUnionType type() { + return AtomicItemConstants.TEMPORAL_ITEM_TYPE; + } + /** * Determine if the temporal item has a timezone. * diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/ITokenItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/ITokenItem.java index 9dacff82e..6529c362a 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/ITokenItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/ITokenItem.java @@ -6,9 +6,10 @@ package gov.nist.secauto.metaschema.core.metapath.item.atomic; import gov.nist.secauto.metaschema.core.datatype.adapter.MetaschemaDataTypeProvider; -import gov.nist.secauto.metaschema.core.metapath.InvalidTypeMetapathException; import gov.nist.secauto.metaschema.core.metapath.function.InvalidValueForCastFunctionException; import gov.nist.secauto.metaschema.core.metapath.item.atomic.impl.TokenItemImpl; +import gov.nist.secauto.metaschema.core.metapath.type.IAtomicOrUnionType; +import gov.nist.secauto.metaschema.core.metapath.type.InvalidTypeMetapathException; import edu.umd.cs.findbugs.annotations.NonNull; @@ -16,6 +17,11 @@ * An atomic Metapath item containing a text token data value. */ public interface ITokenItem extends IStringItem { + @NonNull + static IAtomicOrUnionType type() { + return MetaschemaDataTypeProvider.TOKEN.getItemType(); + } + /** * Construct a new item using the provided string {@code value}. * diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IUriReferenceItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IUriReferenceItem.java index ef17d7001..6727a178d 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IUriReferenceItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IUriReferenceItem.java @@ -6,9 +6,10 @@ package gov.nist.secauto.metaschema.core.metapath.item.atomic; import gov.nist.secauto.metaschema.core.datatype.adapter.MetaschemaDataTypeProvider; -import gov.nist.secauto.metaschema.core.metapath.InvalidTypeMetapathException; import gov.nist.secauto.metaschema.core.metapath.function.InvalidValueForCastFunctionException; import gov.nist.secauto.metaschema.core.metapath.item.atomic.impl.UriReferenceItemImpl; +import gov.nist.secauto.metaschema.core.metapath.type.IAtomicOrUnionType; +import gov.nist.secauto.metaschema.core.metapath.type.InvalidTypeMetapathException; import java.net.URI; @@ -23,6 +24,11 @@ * @see RFC2396 */ public interface IUriReferenceItem extends IAnyUriItem { + @NonNull + static IAtomicOrUnionType type() { + return MetaschemaDataTypeProvider.URI_REFERENCE.getItemType(); + } + /** * Construct a new URI item using the provided string {@code value}. * diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IUuidItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IUuidItem.java index 134a84d69..af4ae5a51 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IUuidItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IUuidItem.java @@ -6,9 +6,10 @@ package gov.nist.secauto.metaschema.core.metapath.item.atomic; import gov.nist.secauto.metaschema.core.datatype.adapter.MetaschemaDataTypeProvider; -import gov.nist.secauto.metaschema.core.metapath.InvalidTypeMetapathException; import gov.nist.secauto.metaschema.core.metapath.function.InvalidValueForCastFunctionException; import gov.nist.secauto.metaschema.core.metapath.item.atomic.impl.UuidItemImpl; +import gov.nist.secauto.metaschema.core.metapath.type.IAtomicOrUnionType; +import gov.nist.secauto.metaschema.core.metapath.type.InvalidTypeMetapathException; import java.util.UUID; @@ -18,6 +19,11 @@ * An atomic Metapath item containing a UUID data value. */ public interface IUuidItem extends IStringItem { + @NonNull + static IAtomicOrUnionType type() { + return MetaschemaDataTypeProvider.UUID.getItemType(); + } + /** * Construct a new UUID item using the provided string {@code value}. * diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IYearMonthDurationItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IYearMonthDurationItem.java index 3cffc2934..dd64dd35d 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IYearMonthDurationItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IYearMonthDurationItem.java @@ -6,9 +6,10 @@ package gov.nist.secauto.metaschema.core.metapath.item.atomic; import gov.nist.secauto.metaschema.core.datatype.adapter.MetaschemaDataTypeProvider; -import gov.nist.secauto.metaschema.core.metapath.InvalidTypeMetapathException; import gov.nist.secauto.metaschema.core.metapath.function.InvalidValueForCastFunctionException; import gov.nist.secauto.metaschema.core.metapath.item.atomic.impl.YearMonthDurationItemImpl; +import gov.nist.secauto.metaschema.core.metapath.type.IAtomicOrUnionType; +import gov.nist.secauto.metaschema.core.metapath.type.InvalidTypeMetapathException; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.time.Period; @@ -19,6 +20,11 @@ * An atomic Metapath item containing a duration data value in years and months. */ public interface IYearMonthDurationItem extends IDurationItem { + @NonNull + static IAtomicOrUnionType type() { + return MetaschemaDataTypeProvider.YEAR_MONTH_DURATION.getItemType(); + } + /** * Construct a new year month day duration item using the provided string * {@code value}. diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/AtomicItemConstants.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/AtomicItemConstants.java new file mode 100644 index 000000000..36f1b5b78 --- /dev/null +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/AtomicItemConstants.java @@ -0,0 +1,42 @@ + +package gov.nist.secauto.metaschema.core.metapath.item.atomic.impl; + +import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; +import gov.nist.secauto.metaschema.core.metapath.item.atomic.IDurationItem; +import gov.nist.secauto.metaschema.core.metapath.item.atomic.IIPAddressItem; +import gov.nist.secauto.metaschema.core.metapath.item.atomic.IMarkupItem; +import gov.nist.secauto.metaschema.core.metapath.item.atomic.INumericItem; +import gov.nist.secauto.metaschema.core.metapath.type.IAtomicOrUnionType; +import gov.nist.secauto.metaschema.core.metapath.type.impl.NonAdapterAtomicItemType; +import gov.nist.secauto.metaschema.core.qname.QNameCache; + +import edu.umd.cs.findbugs.annotations.NonNull; + +public final class AtomicItemConstants { + + @NonNull + public static final IAtomicOrUnionType DURATION_ITEM_TYPE = new NonAdapterAtomicItemType<>( + IDurationItem.class, + QNameCache.instance().of(MetapathConstants.NS_METAPATH, "duration")); + @NonNull + public static final IAtomicOrUnionType IP_ADDRESS_ITEM_TYPE = new NonAdapterAtomicItemType<>( + IIPAddressItem.class, + QNameCache.instance().of(MetapathConstants.NS_METAPATH, "ip-address")); + @NonNull + public static final IAtomicOrUnionType MARKUP_ITEM_TYPE = new NonAdapterAtomicItemType<>( + IMarkupItem.class, + QNameCache.instance().of(MetapathConstants.NS_METAPATH, "markup")); + @NonNull + public static final IAtomicOrUnionType NUMERIC_ITEM_TYPE = new NonAdapterAtomicItemType<>( + INumericItem.class, + QNameCache.instance().of(MetapathConstants.NS_METAPATH, "numeric")); + @NonNull + public static final IAtomicOrUnionType TEMPORAL_ITEM_TYPE = new NonAdapterAtomicItemType<>( + INumericItem.class, + QNameCache.instance().of(MetapathConstants.NS_METAPATH, "temporal")); + + private AtomicItemConstants() { + // prevent construction + } + +} diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/IPv4AddressItemImpl.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/IPv4AddressItemImpl.java index a650364e6..756a88a77 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/IPv4AddressItemImpl.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/IPv4AddressItemImpl.java @@ -20,7 +20,6 @@ public class IPv4AddressItemImpl extends AbstractUntypedAtomicItem implements IIPv4AddressItem { - /** * Construct a new item with the provided {@code value}. * diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/IPv6AddressItemImpl.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/IPv6AddressItemImpl.java index e72eb917e..492f56da0 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/IPv6AddressItemImpl.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/IPv6AddressItemImpl.java @@ -20,7 +20,6 @@ public class IPv6AddressItemImpl extends AbstractUntypedAtomicItem implements IIPv6AddressItem { - /** * Construct a new item with the provided {@code value}. * diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/StringItemImpl.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/StringItemImpl.java index 2794093df..e8bdc1962 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/StringItemImpl.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/StringItemImpl.java @@ -15,7 +15,6 @@ */ public class StringItemImpl extends AbstractStringItem { - /** * Construct a new item with the provided {@code value}. * diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/function/IArrayItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/function/IArrayItem.java index 40f9d5445..1b7104225 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/function/IArrayItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/function/IArrayItem.java @@ -15,6 +15,7 @@ import gov.nist.secauto.metaschema.core.metapath.impl.ArrayItemN; import gov.nist.secauto.metaschema.core.metapath.item.IItem; import gov.nist.secauto.metaschema.core.metapath.item.IItemVisitor; +import gov.nist.secauto.metaschema.core.metapath.type.IItemType; import gov.nist.secauto.metaschema.core.metapath.type.ISequenceType; import gov.nist.secauto.metaschema.core.util.ObjectUtils; @@ -46,6 +47,11 @@ */ @SuppressWarnings("PMD.ShortMethodName") public interface IArrayItem extends IFunction, IItem, List, IPrintable { + @NonNull + static IItemType type() { + return IItemType.array(); + } + /** * Get an empty, immutable array item. * diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/function/IMapItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/function/IMapItem.java index c091f5b87..7707b71a7 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/function/IMapItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/function/IMapItem.java @@ -16,6 +16,7 @@ import gov.nist.secauto.metaschema.core.metapath.item.IItem; import gov.nist.secauto.metaschema.core.metapath.item.IItemVisitor; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyAtomicItem; +import gov.nist.secauto.metaschema.core.metapath.type.IItemType; import gov.nist.secauto.metaschema.core.metapath.type.ISequenceType; import java.util.LinkedHashMap; @@ -35,6 +36,11 @@ */ public interface IMapItem extends IFunction, IItem, Map, IPrintable { + @NonNull + static IItemType type() { + return IItemType.map(); + } + /** * Get an empty, immutable map item. * diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/IAssemblyNodeItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/IAssemblyNodeItem.java index 1ecdde273..7791ab581 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/IAssemblyNodeItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/IAssemblyNodeItem.java @@ -15,8 +15,8 @@ */ public interface IAssemblyNodeItem extends IModelNodeItem { @Override - default NodeItemType getNodeItemType() { - return NodeItemType.ASSEMBLY; + default NodeItemKind getNodeItemKind() { + return NodeItemKind.ASSEMBLY; } @Override diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/IDocumentNodeItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/IDocumentNodeItem.java index 9b0190392..55b89fe5e 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/IDocumentNodeItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/IDocumentNodeItem.java @@ -2,13 +2,19 @@ package gov.nist.secauto.metaschema.core.metapath.item.node; import gov.nist.secauto.metaschema.core.metapath.format.IPathFormatter; +import gov.nist.secauto.metaschema.core.metapath.type.IItemType; import edu.umd.cs.findbugs.annotations.NonNull; public interface IDocumentNodeItem extends IDocumentBasedNodeItem { + @NonNull + static IItemType type() { + return IItemType.document(); + } + @Override - default NodeItemType getNodeItemType() { - return NodeItemType.DOCUMENT; + default NodeItemKind getNodeItemKind() { + return NodeItemKind.DOCUMENT; } @Override diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/IFieldNodeItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/IFieldNodeItem.java index c0f7bbabf..a92b6957e 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/IFieldNodeItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/IFieldNodeItem.java @@ -18,8 +18,8 @@ public interface IFieldNodeItem extends IModelNodeItem, IAtomicValuedItem { @Override - default NodeItemType getNodeItemType() { - return NodeItemType.FIELD; + default NodeItemKind getNodeItemKind() { + return NodeItemKind.FIELD; } @Override @@ -36,7 +36,7 @@ default URI getBaseUri() { @Override default @NonNull - String format(@NonNull IPathFormatter formatter) { + String format(@NonNull IPathFormatter formatter) { return formatter.formatField(this); } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/IFlagNodeItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/IFlagNodeItem.java index 099173c82..741157dcb 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/IFlagNodeItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/IFlagNodeItem.java @@ -24,8 +24,8 @@ public interface IFlagNodeItem extends IDefinitionNodeItem, IAtomicValuedItem { @Override - default NodeItemType getNodeItemType() { - return NodeItemType.FLAG; + default NodeItemKind getNodeItemKind() { + return NodeItemKind.FLAG; } @Override @@ -73,7 +73,7 @@ default IFlagNodeItem getFlagByName(@NonNull QName name) { @SuppressWarnings("null") @Override default @NonNull - Stream flags() { + Stream flags() { // a flag does not have flags return Stream.empty(); } @@ -85,7 +85,7 @@ Stream flags() { @SuppressWarnings("null") @Override default @NonNull - Collection>> getModelItems() { + Collection>> getModelItems() { // a flag does not have model items return Collections.emptyList(); } @@ -114,7 +114,7 @@ Stream flags() { @Override default @NonNull - String format(@NonNull IPathFormatter formatter) { + String format(@NonNull IPathFormatter formatter) { return formatter.formatFlag(this); } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/IModuleNodeItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/IModuleNodeItem.java index b89982961..d692fe7d1 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/IModuleNodeItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/IModuleNodeItem.java @@ -34,8 +34,8 @@ default URI getDocumentUri() { } @Override - default NodeItemType getNodeItemType() { - return NodeItemType.METASCHEMA; + default NodeItemKind getNodeItemKind() { + return NodeItemKind.METASCHEMA; } @Override diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/INodeItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/INodeItem.java index 846a4b0a3..009fa95e5 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/INodeItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/INodeItem.java @@ -6,6 +6,7 @@ import gov.nist.secauto.metaschema.core.metapath.format.IPathSegment; import gov.nist.secauto.metaschema.core.metapath.item.IItem; import gov.nist.secauto.metaschema.core.metapath.item.IItemVisitor; +import gov.nist.secauto.metaschema.core.metapath.type.IItemType; import gov.nist.secauto.metaschema.core.model.IResourceLocation; import gov.nist.secauto.metaschema.core.util.ObjectUtils; @@ -23,6 +24,11 @@ * Represents a queryable Metapath model node. */ public interface INodeItem extends IItem, IPathSegment, INodeItemVisitable { + @NonNull + static IItemType type() { + return IItemType.node(); + } + /** * Retrieve the relative position of this node relative to sibling nodes. *

@@ -91,12 +97,12 @@ static CLASS toValue(@NonNull INodeItem item) { IModelNodeItem getParentContentNodeItem(); /** - * Get the type of node item this is. + * Get the kind of node item this is. * - * @return the node item's type + * @return the node item's kind */ @NonNull - NodeItemType getNodeItemType(); + NodeItemKind getNodeItemKind(); /** * Retrieve the base URI of this node. diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/NodeItemType.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/NodeItemKind.java similarity index 81% rename from core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/NodeItemType.java rename to core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/NodeItemKind.java index 756c641f7..64e56643e 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/NodeItemType.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/NodeItemKind.java @@ -2,10 +2,10 @@ package gov.nist.secauto.metaschema.core.metapath.item.node; /** - * This enumeration provides a listing of the available types of + * This enumeration provides a listing of the available kinds of * {@link INodeItem} implementations. */ -public enum NodeItemType { +public enum NodeItemKind { /** * An {@link INodeItem} based on a Metaschema (@link {@link IModuleNodeItem}}). */ diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/IArrayType.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/IArrayType.java index 28a0b667b..fa4f09e72 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/IArrayType.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/IArrayType.java @@ -1,6 +1,9 @@ package gov.nist.secauto.metaschema.core.metapath.type; -public interface IArrayType extends IItemType { +import gov.nist.secauto.metaschema.core.metapath.ICollectionValue; +import gov.nist.secauto.metaschema.core.metapath.item.function.IArrayItem; + +public interface IArrayType extends IItemType> { } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/IAtomicOrUnionType.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/IAtomicOrUnionType.java index 4ff2c17c0..7c822210b 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/IAtomicOrUnionType.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/IAtomicOrUnionType.java @@ -1,6 +1,24 @@ package gov.nist.secauto.metaschema.core.metapath.type; -public interface IAtomicOrUnionType extends IItemType { +import gov.nist.secauto.metaschema.core.metapath.EQNameUtils; +import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyAtomicItem; +import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; + +import edu.umd.cs.findbugs.annotations.NonNull; + +public interface IAtomicOrUnionType extends IItemType { + + @NonNull + IEnhancedQName getQName(); + + @Override + @NonNull + Class getItemClass(); + + @Override + default String toSignature() { + return EQNameUtils.toEQName(getQName(), null); + } } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/IItemType.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/IItemType.java index e58a674d2..0155c2dab 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/IItemType.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/IItemType.java @@ -1,22 +1,26 @@ package gov.nist.secauto.metaschema.core.metapath.type; -import gov.nist.secauto.metaschema.core.datatype.IDataTypeAdapter; +import gov.nist.secauto.metaschema.core.metapath.ICollectionValue; +import gov.nist.secauto.metaschema.core.metapath.function.IFunction; import gov.nist.secauto.metaschema.core.metapath.item.IItem; +import gov.nist.secauto.metaschema.core.metapath.item.function.IArrayItem; +import gov.nist.secauto.metaschema.core.metapath.item.function.IMapItem; +import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem; +import gov.nist.secauto.metaschema.core.metapath.type.impl.AnyAtomicItemType; import gov.nist.secauto.metaschema.core.metapath.type.impl.AnyItemType; import gov.nist.secauto.metaschema.core.metapath.type.impl.AnyRawItemType; -import gov.nist.secauto.metaschema.core.metapath.type.impl.ArrayTypeImpl; -import gov.nist.secauto.metaschema.core.metapath.type.impl.DataTypeItemType; +import gov.nist.secauto.metaschema.core.metapath.type.impl.NodeItemType; import edu.umd.cs.findbugs.annotations.NonNull; -public interface IItemType { +public interface IItemType { @NonNull - static IItemType item() { + static IItemType item() { return AnyItemType.instance(); } - static IItemType function() { + static IItemType function() { return AnyRawItemType.ANY_FUNCTION; } @@ -25,7 +29,9 @@ static IItemType function() { // // } - static IItemType map() { + @SuppressWarnings("unchecked") + @NonNull + static IItemType> map() { return AnyRawItemType.ANY_MAP; } @@ -34,30 +40,40 @@ static IItemType map() { // // } + @SuppressWarnings("unchecked") @NonNull - static IItemType array() { + static IItemType> array() { return AnyRawItemType.ANY_ARRAY; } + // @NonNull + // static IArrayType array(@NonNull ISequenceType value) + // { + // return new ArrayTypeImpl(value); + // } + @NonNull - static IArrayType array(@NonNull ISequenceType value) { - return new ArrayTypeImpl(value); + static IAtomicOrUnionType anyAtomic() { + return AnyAtomicItemType.instance(); } + @SuppressWarnings("unchecked") @NonNull - static IItemType type(@NonNull IDataTypeAdapter adapter) { - return new DataTypeItemType(adapter); + static IItemType node() { + return NodeItemType.ANY_NODE; } - boolean matches(@NonNull IItem item); + default boolean isInstance(IItem item) { + return getItemClass().isInstance(item); + } @NonNull - Class getItemClass(); + Class getItemClass(); @NonNull String toSignature(); - // static IItemType node(Class itemClass, String nodeName) - // { - // } + static IItemType document() { + return NodeItemType.ANY_DOCUMENT; + } } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/IMapTest.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/IMapTest.java index e014a63b8..ec547399a 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/IMapTest.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/IMapTest.java @@ -1,6 +1,9 @@ package gov.nist.secauto.metaschema.core.metapath.type; -public interface IMapTest extends IItemType { +import gov.nist.secauto.metaschema.core.metapath.ICollectionValue; +import gov.nist.secauto.metaschema.core.metapath.item.function.IMapItem; + +public interface IMapTest extends IItemType> { } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/ISequenceType.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/ISequenceType.java index ae04cd061..09d55f327 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/ISequenceType.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/ISequenceType.java @@ -6,16 +6,18 @@ package gov.nist.secauto.metaschema.core.metapath.type; import gov.nist.secauto.metaschema.core.metapath.ICollectionValue; +import gov.nist.secauto.metaschema.core.metapath.item.IItem; import gov.nist.secauto.metaschema.core.metapath.type.impl.SequenceTypeImpl; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; -public interface ISequenceType { +public interface ISequenceType { + @SuppressWarnings("unchecked") @NonNull - static ISequenceType empty() { - return SequenceTypeImpl.EMPTY; + static ISequenceType empty() { + return (ISequenceType) SequenceTypeImpl.EMPTY; } /** @@ -29,12 +31,12 @@ static ISequenceType empty() { */ @SuppressWarnings("PMD.ShortMethodName") @NonNull - static ISequenceType of( - @NonNull IItemType type, + static ISequenceType of( + @NonNull IItemType type, @NonNull Occurrence occurrence) { return Occurrence.ZERO.equals(occurrence) ? empty() - : new SequenceTypeImpl(type, occurrence); + : new SequenceTypeImpl<>(type, occurrence); } /** @@ -50,7 +52,7 @@ static ISequenceType of( * @return the type of the sequence or {@code null} if the sequence is empty */ @Nullable - IItemType getType(); + IItemType getType(); /** * Get the occurrence of the sequence. diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/TypeSystem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/TypeSystem.java index 616301f74..756655520 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/TypeSystem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/TypeSystem.java @@ -5,14 +5,19 @@ package gov.nist.secauto.metaschema.core.metapath.type; -import gov.nist.secauto.metaschema.core.datatype.IDataTypeAdapter; import gov.nist.secauto.metaschema.core.datatype.adapter.MetaschemaDataTypeProvider; import gov.nist.secauto.metaschema.core.datatype.markup.MarkupDataTypeProvider; -import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; -import gov.nist.secauto.metaschema.core.metapath.StaticContext; import gov.nist.secauto.metaschema.core.metapath.item.IItem; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyAtomicItem; +import gov.nist.secauto.metaschema.core.metapath.item.atomic.IBase64BinaryItem; +import gov.nist.secauto.metaschema.core.metapath.item.atomic.IDurationItem; +import gov.nist.secauto.metaschema.core.metapath.item.atomic.INumericItem; +import gov.nist.secauto.metaschema.core.metapath.item.atomic.ITokenItem; +import gov.nist.secauto.metaschema.core.metapath.item.function.IArrayItem; +import gov.nist.secauto.metaschema.core.metapath.item.function.IMapItem; +import gov.nist.secauto.metaschema.core.metapath.item.node.IDocumentNodeItem; import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem; +import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; import gov.nist.secauto.metaschema.core.util.CollectionUtil; import gov.nist.secauto.metaschema.core.util.ObjectUtils; @@ -23,77 +28,64 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import javax.xml.namespace.QName; - import edu.umd.cs.findbugs.annotations.NonNull; @SuppressWarnings("removal") public final class TypeSystem { - private static final Map, IItemType> ITEM_CLASS_TO_TYPE_MAP; - private static final Map, QName> ITEM_CLASS_TO_QNAME_MAP; + private static final Map, IItemType> ITEM_CLASS_TO_TYPE_MAP; + private static final Map, IEnhancedQName> ITEM_CLASS_TO_QNAME_MAP; static { ITEM_CLASS_TO_TYPE_MAP = Collections.unmodifiableMap(Map.ofEntries( - register(IItemType.item()), - // register(IItemType.node(INodeItem.class, "node")), - // register(IItemType.node(IDocumentNodeItem.class, "document-node")), + register(IItem.type()), + register(INodeItem.type()), + register(IDocumentNodeItem.type()), // register(IItemType.node(IAssemblyNodeItem.class, "assembly-node")), // register(IItemType.node(IFieldNodeItem.class, "field-node")), // register(IItemType.node(IFlagNodeItem.class, "flag-node")), - // register(IArrayItem.class, "array"), - // register(IMapItem.class, "map"), - // register(IAnyAtomicItem.class, "any-atomic-type"), - // register(INumericItem.class, "numeric"), - // register(IDurationItem.class, "duration"), - register(MetaschemaDataTypeProvider.BASE64), - register(MetaschemaDataTypeProvider.BOOLEAN), - register(MetaschemaDataTypeProvider.DATE), - register(MetaschemaDataTypeProvider.DATE_TIME), - register(MetaschemaDataTypeProvider.IP_V4_ADDRESS), - register(MetaschemaDataTypeProvider.IP_V6_ADDRESS), - register(MetaschemaDataTypeProvider.URI), - register(MetaschemaDataTypeProvider.URI_REFERENCE), - register(MetaschemaDataTypeProvider.UUID), - register(MetaschemaDataTypeProvider.DAY_TIME_DURATION), - register(MetaschemaDataTypeProvider.YEAR_MONTH_DURATION), - register(MetaschemaDataTypeProvider.DECIMAL), - register(MetaschemaDataTypeProvider.INTEGER), - register(MetaschemaDataTypeProvider.NON_NEGATIVE_INTEGER), - register(MetaschemaDataTypeProvider.POSITIVE_INTEGER), - register(MetaschemaDataTypeProvider.EMAIL_ADDRESS), - register(MetaschemaDataTypeProvider.HOSTNAME), - register(MetaschemaDataTypeProvider.NCNAME), - register(MetaschemaDataTypeProvider.STRING), - register(MetaschemaDataTypeProvider.TOKEN))); - - Stream, QName>> basicAdapterStream + register(IArrayItem.type()), + register(IMapItem.type()), + register(IAnyAtomicItem.type()), + register(INumericItem.type()), + register(IDurationItem.type()), + register(IBase64BinaryItem.type()), + // register(MetaschemaDataTypeProvider.BOOLEAN), + // register(MetaschemaDataTypeProvider.DATE), + // register(MetaschemaDataTypeProvider.DATE_TIME), + // register(MetaschemaDataTypeProvider.IP_V4_ADDRESS), + // register(MetaschemaDataTypeProvider.IP_V6_ADDRESS), + // register(MetaschemaDataTypeProvider.URI), + // register(MetaschemaDataTypeProvider.URI_REFERENCE), + // register(MetaschemaDataTypeProvider.UUID), + // register(MetaschemaDataTypeProvider.DAY_TIME_DURATION), + // register(MetaschemaDataTypeProvider.YEAR_MONTH_DURATION), + // register(MetaschemaDataTypeProvider.DECIMAL), + // register(MetaschemaDataTypeProvider.INTEGER), + // register(MetaschemaDataTypeProvider.NON_NEGATIVE_INTEGER), + // register(MetaschemaDataTypeProvider.POSITIVE_INTEGER), + // register(MetaschemaDataTypeProvider.EMAIL_ADDRESS), + // register(MetaschemaDataTypeProvider.HOSTNAME), + // register(MetaschemaDataTypeProvider.NCNAME), + // register(MetaschemaDataTypeProvider.STRING), + register(ITokenItem.type()))); + + Stream, IEnhancedQName>> basicAdapterStream = new MetaschemaDataTypeProvider().getJavaTypeAdapters().stream() - .map(adapter -> Map.entry(adapter.getItemClass(), adapter.getPreferredName())); - Stream, QName>> markupAdapterStream + .map(adapter -> Map.entry(adapter.getItemType().getItemClass(), adapter.getPreferredName())); + Stream, IEnhancedQName>> markupAdapterStream = new MarkupDataTypeProvider().getJavaTypeAdapters().stream() - .map(adapter -> Map.entry(adapter.getItemClass(), adapter.getPreferredName())); + .map(adapter -> Map.entry(adapter.getItemType().getItemClass(), adapter.getPreferredName())); ITEM_CLASS_TO_QNAME_MAP = CollectionUtil.unmodifiableMap( Stream.concat(basicAdapterStream, markupAdapterStream) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (v1, v2) -> v2, LinkedHashMap::new))); } - private static Map.Entry, IItemType> register( - @NonNull IItemType type) { + private static , I extends IItem> Map.Entry, T> + register(@NonNull T type) { return Map.entry(type.getItemClass(), type); } - private static Map.Entry, IItemType> register( - @NonNull IDataTypeAdapter adapter) { - return register(IItemType.type(adapter)); - } - - private static Map.Entry, QName> register( - @NonNull Class clazz, - @NonNull String typeName) { - return Map.entry(clazz, new QName(MetapathConstants.NS_METAPATH.toASCIIString(), typeName)); - } - @NonNull private static Stream> getItemInterfaces(@NonNull Class clazz) { @SuppressWarnings("unchecked") @@ -112,21 +104,15 @@ private static Stream> getItemInterfaces(@NonNull Class clazz) { - Class itemClass = getItemInterfaces(clazz).findFirst().orElse(null); - - QName qname = ITEM_CLASS_TO_QNAME_MAP.get(itemClass); - return qname == null ? clazz.getName() : asPrefixedName(qname); - } + public static String getName(@NonNull Class itemClass) { + Class supportedItemClass = getItemInterfaces(itemClass).findFirst().orElse(null); - private static String asPrefixedName(@NonNull QName qname) { - String namespace = qname.getNamespaceURI(); - String prefix = namespace.isEmpty() ? null : StaticContext.getWellKnownPrefixForUri(namespace); - return prefix == null ? qname.toString() : prefix + ":" + qname.getLocalPart(); + IEnhancedQName qname = ITEM_CLASS_TO_QNAME_MAP.get(supportedItemClass); + return qname == null ? supportedItemClass.getName() : qname.toEQName(null); } private TypeSystem() { diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/AbstractItemType.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/AbstractItemType.java index b8f968b20..003206552 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/AbstractItemType.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/AbstractItemType.java @@ -14,11 +14,6 @@ protected AbstractItemType(@NonNull Class itemClass) { this.itemClass = itemClass; } - @Override - public boolean matches(IItem item) { - return getItemClass().isInstance(item); - } - @Override public Class getItemClass() { return itemClass; diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/AbstractNodeItemType.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/AbstractNodeItemType.java deleted file mode 100644 index 2ee94ad0d..000000000 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/AbstractNodeItemType.java +++ /dev/null @@ -1,39 +0,0 @@ - -package gov.nist.secauto.metaschema.core.metapath.type.impl; - -import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem; -import gov.nist.secauto.metaschema.core.util.ObjectUtils; - -import edu.umd.cs.findbugs.annotations.NonNull; - -public abstract class AbstractNodeItemType - extends AbstractItemType { - @NonNull - private final String nodeName; - - protected AbstractNodeItemType( - @NonNull String name, - @NonNull Class itemClass) { - super(itemClass); - this.nodeName = name; - } - - @NonNull - public String getNodeName() { - return nodeName; - } - - @NonNull - protected abstract String getTest(); - - @Override - public String toSignature() { - return ObjectUtils.notNull(new StringBuilder() - .append(getNodeName()) - .append('(') - .append(getTest()) - .append(')') - .toString()); - } - -} diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/AnyAtomicItemType.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/AnyAtomicItemType.java new file mode 100644 index 000000000..3778292fc --- /dev/null +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/AnyAtomicItemType.java @@ -0,0 +1,27 @@ + +package gov.nist.secauto.metaschema.core.metapath.type.impl; + +import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; +import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyAtomicItem; +import gov.nist.secauto.metaschema.core.metapath.type.IAtomicOrUnionType; +import gov.nist.secauto.metaschema.core.qname.QNameCache; + +import edu.umd.cs.findbugs.annotations.NonNull; + +public final class AnyAtomicItemType + extends NonAdapterAtomicItemType + implements IAtomicOrUnionType { + @NonNull + private static final AnyAtomicItemType INSTANCE = new AnyAtomicItemType(); + + @NonNull + public static AnyAtomicItemType instance() { + return INSTANCE; + } + + private AnyAtomicItemType() { + super( + IAnyAtomicItem.class, + QNameCache.instance().of(MetapathConstants.NS_METAPATH, "any-atomic-type")); + } +} diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/AnyItemType.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/AnyItemType.java index 3f9e1d767..7f8d42127 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/AnyItemType.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/AnyItemType.java @@ -19,7 +19,7 @@ public static AnyItemType instance() { } @Override - public boolean matches(IItem item) { + public boolean isInstance(IItem item) { // any item type always matches return true; } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/AnyRawItemType.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/AnyRawItemType.java index 521467be6..eb0d3f890 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/AnyRawItemType.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/AnyRawItemType.java @@ -10,18 +10,22 @@ public final class AnyRawItemType extends AbstractItemType { + @NonNull public static final AnyRawItemType ANY_FUNCTION = new AnyRawItemType<>( IFunction.class, "function(*)"); + + @NonNull public static final AnyRawItemType> ANY_MAP = new AnyRawItemType<>( IMapItem.class, "map(*)"); + @NonNull public static final AnyRawItemType> ANY_ARRAY = new AnyRawItemType<>( IArrayItem.class, "array(*)"); @NonNull - private String signature; + private final String signature; private AnyRawItemType( @NonNull Class itemClass, diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/ArrayTypeImpl.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/ArrayTypeImpl.java index d818e2080..46151e778 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/ArrayTypeImpl.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/ArrayTypeImpl.java @@ -9,28 +9,29 @@ import edu.umd.cs.findbugs.annotations.NonNull; -public class ArrayTypeImpl implements IArrayType { +public class ArrayTypeImpl> implements IArrayType { @NonNull - private final ISequenceType valueType; + private final ISequenceType valueType; - public ArrayTypeImpl(@NonNull ISequenceType valueType) { + public ArrayTypeImpl(@NonNull ISequenceType valueType) { this.valueType = valueType; } - public ISequenceType getValueType() { + public ISequenceType getValueType() { return valueType; } - @Override - public boolean matches(IItem item) { - return item instanceof IArrayItem - ? ((IArrayItem) item).stream().allMatch(valueType::matches) - : false; - } + // @Override + // public boolean matches(IItem item) { + // return item instanceof IArrayItem + // ? ((IArrayItem) item).stream().allMatch(valueType::matches) + // : false; + // } + @SuppressWarnings("unchecked") @Override - public Class getItemClass() { - return IArrayItem.class; + public Class getItemClass() { + return (Class) IArrayItem.class; } @Override diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/DataTypeItemType.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/DataTypeItemType.java index fa0a182f2..9ab1bd847 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/DataTypeItemType.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/DataTypeItemType.java @@ -2,21 +2,25 @@ package gov.nist.secauto.metaschema.core.metapath.type.impl; import gov.nist.secauto.metaschema.core.datatype.IDataTypeAdapter; -import gov.nist.secauto.metaschema.core.metapath.EQNameUtils; -import gov.nist.secauto.metaschema.core.metapath.item.IItem; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyAtomicItem; -import gov.nist.secauto.metaschema.core.metapath.type.IItemType; +import gov.nist.secauto.metaschema.core.metapath.type.IAtomicOrUnionType; +import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; import edu.umd.cs.findbugs.annotations.NonNull; -public class DataTypeItemType - implements IItemType { +public class DataTypeItemType + implements IAtomicOrUnionType { @NonNull private final IDataTypeAdapter adapter; + @NonNull + private final Class itemClass; - public DataTypeItemType(@NonNull IDataTypeAdapter adapter) { + public DataTypeItemType( + @NonNull IDataTypeAdapter adapter, + @NonNull Class itemClass) { this.adapter = adapter; + this.itemClass = itemClass; } @NonNull @@ -25,17 +29,12 @@ public IDataTypeAdapter getAdapter() { } @Override - public Class getItemClass() { - return getAdapter().getItemClass(); - } - - @Override - public boolean matches(IItem item) { - return getItemClass().isInstance(item); + public IEnhancedQName getQName() { + return getAdapter().getPreferredName(); } @Override - public String toSignature() { - return EQNameUtils.toEQName(getAdapter().getPreferredName(), null); + public Class getItemClass() { + return itemClass; } } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/NodeItemType.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/NodeItemType.java new file mode 100644 index 000000000..8e4154669 --- /dev/null +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/NodeItemType.java @@ -0,0 +1,51 @@ + +package gov.nist.secauto.metaschema.core.metapath.type.impl; + +import gov.nist.secauto.metaschema.core.metapath.item.node.IDocumentNodeItem; +import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem; +import gov.nist.secauto.metaschema.core.util.ObjectUtils; + +import edu.umd.cs.findbugs.annotations.NonNull; + +public class NodeItemType + extends AbstractItemType { + @NonNull + public static final NodeItemType ANY_NODE = new NodeItemType<>( + "node", + INodeItem.class, + ""); + @NonNull + public static final NodeItemType ANY_DOCUMENT = new NodeItemType<>( + "document", + IDocumentNodeItem.class, + ""); + @NonNull + private final String nodeName; + @NonNull + private final String signature; + + protected NodeItemType( + @NonNull String name, + @NonNull Class itemClass, + @NonNull String test) { + super(itemClass); + this.nodeName = name; + this.signature = ObjectUtils.notNull(new StringBuilder() + .append(name) + .append('(') + .append(test) + .append(')') + .toString()); + } + + @NonNull + public String getNodeName() { + return nodeName; + } + + @Override + public String toSignature() { + return signature; + } + +} diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/NonAdapterAtomicItemType.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/NonAdapterAtomicItemType.java new file mode 100644 index 000000000..cdbf6bb36 --- /dev/null +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/NonAdapterAtomicItemType.java @@ -0,0 +1,32 @@ + +package gov.nist.secauto.metaschema.core.metapath.type.impl; + +import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyAtomicItem; +import gov.nist.secauto.metaschema.core.metapath.type.IAtomicOrUnionType; +import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; + +import edu.umd.cs.findbugs.annotations.NonNull; + +public class NonAdapterAtomicItemType implements IAtomicOrUnionType { + @NonNull + private final Class itemClass; + @NonNull + private final IEnhancedQName qname; + + public NonAdapterAtomicItemType( + @NonNull Class itemClass, + @NonNull IEnhancedQName qname) { + this.itemClass = itemClass; + this.qname = qname; + } + + @Override + public Class getItemClass() { + return itemClass; + } + + @Override + public IEnhancedQName getQName() { + return qname; + } +} diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/SequenceTypeImpl.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/SequenceTypeImpl.java index f79b0252e..1c5d68bfb 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/SequenceTypeImpl.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/SequenceTypeImpl.java @@ -6,6 +6,7 @@ package gov.nist.secauto.metaschema.core.metapath.type.impl; import gov.nist.secauto.metaschema.core.metapath.ICollectionValue; +import gov.nist.secauto.metaschema.core.metapath.item.IItem; import gov.nist.secauto.metaschema.core.metapath.type.IItemType; import gov.nist.secauto.metaschema.core.metapath.type.ISequenceType; import gov.nist.secauto.metaschema.core.metapath.type.Occurrence; @@ -15,16 +16,16 @@ import edu.umd.cs.findbugs.annotations.NonNull; -public class SequenceTypeImpl implements ISequenceType { +public class SequenceTypeImpl implements ISequenceType { @NonNull - public static final ISequenceType EMPTY = new ISequenceType() { + public static final ISequenceType EMPTY = new ISequenceType() { @Override public boolean isEmpty() { return true; } @Override - public IItemType getType() { + public IItemType getType() { return null; } @@ -44,10 +45,12 @@ public boolean matches(ICollectionValue item) { } }; - private final IItemType type; + @NonNull + private final IItemType type; + @NonNull private final Occurrence occurrence; - public SequenceTypeImpl(@NonNull IItemType type, @NonNull Occurrence occurrence) { + public SequenceTypeImpl(@NonNull IItemType type, @NonNull Occurrence occurrence) { Objects.requireNonNull(type, "type"); Objects.requireNonNull(occurrence, "occurrence"); this.type = type; @@ -60,7 +63,7 @@ public boolean isEmpty() { } @Override - public IItemType getType() { + public IItemType getType() { return type; } @@ -78,7 +81,7 @@ public String toString() { public String toSignature() { StringBuilder builder = new StringBuilder(); - IItemType type = getType(); + IItemType type = getType(); // name builder.append(type == null ? "" @@ -102,7 +105,7 @@ public boolean equals(Object obj) { if (obj == null || getClass() != obj.getClass()) { return false; // NOPMD - readability } - ISequenceType other = (ISequenceType) obj; + ISequenceType other = (ISequenceType) obj; return Objects.equals(occurrence, other.getOccurrence()) && Objects.equals(type, other.getType()); } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/util/MermaidErDiagramGenerator.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/util/MermaidErDiagramGenerator.java index c4d5d1564..0edd3c483 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/util/MermaidErDiagramGenerator.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/util/MermaidErDiagramGenerator.java @@ -29,6 +29,9 @@ import edu.umd.cs.findbugs.annotations.Nullable; import nl.talsmasoftware.lazy4j.Lazy; +/** + * Generates a mermaid diagram from a Metaschema {@link IModule}. + */ @SuppressWarnings({ "PMD.CouplingBetweenObjects", "PMD.UseConcurrentHashMap" }) public final class MermaidErDiagramGenerator { @NonNull @@ -74,7 +77,7 @@ public static void generate(@NonNull IModule module, @NonNull PrintWriter writer for (IDiagramNode.IAttribute attribute : node.getAttributes()) { writer.format(" %s %s%n", - attribute.getDataType().getPreferredName().getLocalPart(), + attribute.getDataType().getPreferredName().getLocalName(), attribute.getLabel()); } writer.format(" }%n"); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/xmlbeans/handler/DatatypesHandler.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/xmlbeans/handler/DatatypesHandler.java index abf809150..e62fc443f 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/xmlbeans/handler/DatatypesHandler.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/xmlbeans/handler/DatatypesHandler.java @@ -7,10 +7,13 @@ import gov.nist.secauto.metaschema.core.datatype.DataTypeService; import gov.nist.secauto.metaschema.core.datatype.IDataTypeAdapter; +import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import org.apache.xmlbeans.SimpleValue; +import javax.xml.namespace.QName; + public final class DatatypesHandler { private DatatypesHandler() { // disable construction @@ -72,7 +75,8 @@ public static void encodeSimpleDatatypesType(IDataTypeAdapter datatype, Simpl private static IDataTypeAdapter decode(SimpleValue target) { String name = ObjectUtils.requireNonNull(target.getStringValue()); - IDataTypeAdapter retval = DataTypeService.getInstance().getJavaTypeAdapterByName(name); + IDataTypeAdapter retval = DataTypeService.instance() + .getJavaTypeAdapterByQName(new QName(MetapathConstants.NS_METAPATH.toASCIIString(), name)); if (retval == null) { throw new IllegalStateException("Unrecognized data type: " + name); } @@ -81,7 +85,7 @@ private static IDataTypeAdapter decode(SimpleValue target) { private static void encode(IDataTypeAdapter datatype, SimpleValue target) { if (datatype != null) { - target.setStringValue(datatype.getPreferredName().getLocalPart()); + target.setStringValue(datatype.getItemType().getQName().getLocalName()); } } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/qname/IEnhancedQName.java b/core/src/main/java/gov/nist/secauto/metaschema/core/qname/IEnhancedQName.java new file mode 100644 index 000000000..807a6d735 --- /dev/null +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/qname/IEnhancedQName.java @@ -0,0 +1,39 @@ + +package gov.nist.secauto.metaschema.core.qname; + +import gov.nist.secauto.metaschema.core.metapath.EQNameUtils; +import gov.nist.secauto.metaschema.core.metapath.EQNameUtils.NamespaceToPrefixResolver; + +import java.net.URI; + +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; + +import edu.umd.cs.findbugs.annotations.NonNull; +import edu.umd.cs.findbugs.annotations.Nullable; + +public interface IEnhancedQName { + int getIndexPosition(); + + @NonNull + String getNamespace(); + + @NonNull + URI getNamespaceAsUri(); + + @NonNull + String getLocalName(); + + @NonNull + default String toEQName(@Nullable NamespaceToPrefixResolver resolver) { + return EQNameUtils.toEQName(this, resolver); + } + + @NonNull + default QName toQName() { + return toQName(XMLConstants.DEFAULT_NS_PREFIX); + } + + @NonNull + QName toQName(@NonNull String prefix); +} diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/qname/NamespaceCache.java b/core/src/main/java/gov/nist/secauto/metaschema/core/qname/NamespaceCache.java new file mode 100644 index 000000000..5bc148238 --- /dev/null +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/qname/NamespaceCache.java @@ -0,0 +1,74 @@ + +package gov.nist.secauto.metaschema.core.qname; + +import gov.nist.secauto.metaschema.core.util.ObjectUtils; + +import java.net.URI; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicInteger; + +import edu.umd.cs.findbugs.annotations.NonNull; +import nl.talsmasoftware.lazy4j.Lazy; + +public final class NamespaceCache { + @NonNull + private static final Lazy INSTANCE = ObjectUtils.notNull(Lazy.lazy(NamespaceCache::new)); + + private final Map nsToIndex = new ConcurrentHashMap<>(); + private final Map indexToNs = new ConcurrentHashMap<>(); + private final Map indexToNsUri = new ConcurrentHashMap<>(); + /** + * The next available namespace index position. + *

+ * This value starts at 1, since the "" no namspace has the zero position. + */ + private final AtomicInteger indexCounter = new AtomicInteger(); + + @NonNull + public static NamespaceCache instance() { + return ObjectUtils.notNull(INSTANCE.get()); + } + + public NamespaceCache() { + // claim the "0" position + int noNamespaceIndex = of(""); + assert noNamespaceIndex == 0; + } + + public int of(@NonNull URI namespace) { + return of(namespace.toASCIIString()); + } + + public int of(@NonNull String namespace) { + return nsToIndex.computeIfAbsent(namespace, key -> { + int nextIndex = indexCounter.getAndIncrement(); + indexToNs.put(nextIndex, namespace); + return nextIndex; + }); + } + + @NonNull + public Optional get(@NonNull String namespace) { + return ObjectUtils.notNull(Optional.ofNullable(nsToIndex.get(namespace))); + } + + @NonNull + public Optional get(int index) { + return ObjectUtils.notNull(Optional.ofNullable(indexToNs.get(index))); + } + + @NonNull + public Optional getAsURI(int index) { + return ObjectUtils.notNull(Optional.ofNullable(indexToNsUri.computeIfAbsent(index, key -> { + Optional namespace = get(key); + URI nsUri = null; + if (namespace.isPresent()) { + nsUri = URI.create(namespace.get()); + indexToNsUri.put(key, nsUri); + } + return nsUri; + }))); + } +} diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/qname/QNameCache.java b/core/src/main/java/gov/nist/secauto/metaschema/core/qname/QNameCache.java new file mode 100644 index 000000000..a410de9d2 --- /dev/null +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/qname/QNameCache.java @@ -0,0 +1,175 @@ + +package gov.nist.secauto.metaschema.core.qname; + +import gov.nist.secauto.metaschema.core.util.ObjectUtils; + +import java.net.URI; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicInteger; + +import javax.xml.namespace.QName; + +import edu.umd.cs.findbugs.annotations.NonNull; +import edu.umd.cs.findbugs.annotations.Nullable; +import nl.talsmasoftware.lazy4j.Lazy; + +public class QNameCache { + @NonNull + private static final Lazy INSTANCE = ObjectUtils.notNull(Lazy.lazy(QNameCache::new)); + + @NonNull + private final NamespaceCache namespaceCache; + + private final Map indexToQName = new ConcurrentHashMap<>(); + private final Map> nsIndexToLocalNameToIndex = new ConcurrentHashMap<>(); + /** + * The next available qualified-name index position. + */ + private final AtomicInteger indexCounter = new AtomicInteger(); + + @NonNull + public static QNameCache instance() { + return ObjectUtils.notNull(INSTANCE.get()); + } + + private QNameCache() { + this(NamespaceCache.instance()); + } + + public QNameCache(@NonNull NamespaceCache nsCache) { + this.namespaceCache = nsCache; + } + + @NonNull + public NamespaceCache getNamespaceCache() { + return namespaceCache; + } + + @SuppressWarnings("PMD.ShortMethodName") + @NonNull + public IEnhancedQName of(@NonNull URI namespace, @NonNull String name) { + return of( + ObjectUtils.notNull(namespace.toASCIIString()), + name); + } + + @SuppressWarnings("PMD.ShortMethodName") + @NonNull + public IEnhancedQName of(@NonNull QName qname) { + return of( + ObjectUtils.notNull(qname.getNamespaceURI()), + ObjectUtils.notNull(qname.getLocalPart())); + } + + @SuppressWarnings("PMD.ShortMethodName") + @NonNull + public IEnhancedQName of(@NonNull String namespace, @NonNull String name) { + + int namespacePosition = namespaceCache.of(namespace); + + Map namespaceNames = nsIndexToLocalNameToIndex + .computeIfAbsent(namespacePosition, key -> new ConcurrentHashMap<>()); + + return ObjectUtils.notNull(namespaceNames.computeIfAbsent(name, key -> { + QNameRecord record = new QNameRecord(namespacePosition, namespace, key); + indexToQName.put(record.getIndexPosition(), record); + return record; + })); + } + + @Nullable + public IEnhancedQName get(@NonNull QName qname) { + return get( + ObjectUtils.notNull(qname.getNamespaceURI()), + ObjectUtils.notNull(qname.getLocalPart())); + } + + @Nullable + public IEnhancedQName get(@NonNull String namespace, @NonNull String name) { + Optional nsPosition = namespaceCache.get(namespace); + if (!nsPosition.isPresent()) { + throw new IllegalArgumentException( + String.format("The namespace '%s' is not recognized.", namespace)); + } + + Map namespaceNames = nsIndexToLocalNameToIndex.get(nsPosition.get()); + return namespaceNames == null + ? null + : namespaceNames.get(name); + } + + @Nullable + public IEnhancedQName get(int index) { + return indexToQName.get(index); + } + + private final class QNameRecord implements IEnhancedQName { + private final int qnameIndexPosition; + private final int namespaceIndexPosition; + @NonNull + private final String namespace; + @NonNull + private final String localName; + + public QNameRecord( + int namespaceIndexPosition, + @NonNull String namespace, + @NonNull String localName) { + this.qnameIndexPosition = indexCounter.getAndIncrement(); + this.namespaceIndexPosition = namespaceIndexPosition; + this.namespace = namespace; + this.localName = localName; + } + + @Override + public int getIndexPosition() { + return qnameIndexPosition; + } + + @Override + public URI getNamespaceAsUri() { + return ObjectUtils.notNull(getNamespaceCache().getAsURI(namespaceIndexPosition).get()); + } + + @Override + public String getNamespace() { + return namespace; + } + + @Override + public String getLocalName() { + return localName; + } + + @Override + public QName toQName(@NonNull String prefix) { + return new QName(getNamespace(), getLocalName(), prefix); + } + + @Override + public int hashCode() { + return Objects.hashCode(qnameIndexPosition); + } + + @SuppressWarnings("PMD.OnlyOneReturn") + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; + } + QNameRecord other = (QNameRecord) obj; + return Objects.equals(qnameIndexPosition, other.getIndexPosition()); + } + + @Override + public String toString() { + return toEQName(null); + } + } +} diff --git a/core/src/main/java/module-info.java b/core/src/main/java/module-info.java index 28dfecb30..c69b5f2b0 100644 --- a/core/src/main/java/module-info.java +++ b/core/src/main/java/module-info.java @@ -84,6 +84,7 @@ exports gov.nist.secauto.metaschema.core.model.util; exports gov.nist.secauto.metaschema.core.model.validation; exports gov.nist.secauto.metaschema.core.model.xml; + exports gov.nist.secauto.metaschema.core.qname; exports gov.nist.secauto.metaschema.core.util; exports gov.nist.secauto.metaschema.core.datatype.markup.flexmark diff --git a/core/src/test/java/gov/nist/secauto/metaschema/core/datatype/adapter/MetaschemaDataTypeProviderTest.java b/core/src/test/java/gov/nist/secauto/metaschema/core/datatype/adapter/MetaschemaDataTypeProviderTest.java index e8e4824e2..f4fdedd99 100644 --- a/core/src/test/java/gov/nist/secauto/metaschema/core/datatype/adapter/MetaschemaDataTypeProviderTest.java +++ b/core/src/test/java/gov/nist/secauto/metaschema/core/datatype/adapter/MetaschemaDataTypeProviderTest.java @@ -8,14 +8,18 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import gov.nist.secauto.metaschema.core.datatype.DataTypeService; +import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import org.junit.jupiter.api.Test; +import javax.xml.namespace.QName; + class MetaschemaDataTypeProviderTest { @Test void test() { - assertNotNull(DataTypeService.getInstance().getJavaTypeAdapterByName("uuid")); + assertNotNull(DataTypeService.instance() + .getJavaTypeAdapterByQName(new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "uuid"))); } } diff --git a/core/src/test/java/gov/nist/secauto/metaschema/core/metapath/cst/FlagTest.java b/core/src/test/java/gov/nist/secauto/metaschema/core/metapath/cst/FlagTest.java index b52cef02f..260988eaa 100644 --- a/core/src/test/java/gov/nist/secauto/metaschema/core/metapath/cst/FlagTest.java +++ b/core/src/test/java/gov/nist/secauto/metaschema/core/metapath/cst/FlagTest.java @@ -14,7 +14,7 @@ import gov.nist.secauto.metaschema.core.metapath.cst.path.NameTest; import gov.nist.secauto.metaschema.core.metapath.item.node.IFlagNodeItem; import gov.nist.secauto.metaschema.core.metapath.item.node.IModelNodeItem; -import gov.nist.secauto.metaschema.core.metapath.item.node.NodeItemType; +import gov.nist.secauto.metaschema.core.metapath.item.node.NodeItemKind; import gov.nist.secauto.metaschema.core.model.IFlagInstance; import org.jmock.Expectations; @@ -46,8 +46,8 @@ void testFlagWithName() { { // NOPMD - intentional allowing(focusItem).getNodeItem(); will(returnValue(focusItem)); - allowing(focusItem).getNodeItemType(); - will(returnValue(NodeItemType.ASSEMBLY)); + allowing(focusItem).getNodeItemKind(); + will(returnValue(NodeItemKind.ASSEMBLY)); allowing(focusItem).getFlagByName(flagName); will(returnValue(flagNode)); diff --git a/core/src/test/java/gov/nist/secauto/metaschema/core/metapath/type/ISequenceTypeTest.java b/core/src/test/java/gov/nist/secauto/metaschema/core/metapath/type/ISequenceTypeTest.java index f7cd70f01..7e8e58342 100644 --- a/core/src/test/java/gov/nist/secauto/metaschema/core/metapath/type/ISequenceTypeTest.java +++ b/core/src/test/java/gov/nist/secauto/metaschema/core/metapath/type/ISequenceTypeTest.java @@ -33,7 +33,7 @@ private static Stream provideValues() { // NOPMD - false positive @MethodSource("provideValues") void testMatch(@NonNull IItem actual, @NonNull Map testToExpectedMap) { for (Map.Entry entry : testToExpectedMap.entrySet()) { - String test = ". instanceof " + entry.getKey(); + String test = ". instance of " + entry.getKey(); MetapathExpression expression = MetapathExpression.compile(test); Boolean result = expression.evaluateAs(actual, MetapathExpression.ResultType.BOOLEAN); diff --git a/core/src/test/java/gov/nist/secauto/metaschema/core/qname/QNameCacheTest.java b/core/src/test/java/gov/nist/secauto/metaschema/core/qname/QNameCacheTest.java new file mode 100644 index 000000000..d41437161 --- /dev/null +++ b/core/src/test/java/gov/nist/secauto/metaschema/core/qname/QNameCacheTest.java @@ -0,0 +1,36 @@ + +package gov.nist.secauto.metaschema.core.qname; + +import static org.junit.jupiter.api.Assertions.assertAll; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import java.util.stream.Stream; + +import edu.umd.cs.findbugs.annotations.NonNull; + +class QNameCacheTest { + private static Stream provideValues() { + return Stream.of( + Arguments.of("", "name1", 0), + Arguments.of("https://example.com/ns", "name1", 1), + Arguments.of("https://example.com/ns", "name2", 2), + Arguments.of("", "name2", 3)); + } + + @ParameterizedTest + @MethodSource("provideValues") + void test(@NonNull String namespace, @NonNull String localName, int position) { + QNameCache cache = QNameCache.instance(); + + IEnhancedQName qname = cache.of(namespace, localName); + assertAll( + () -> assertEquals(position, qname.getIndexPosition()), + () -> assertEquals(namespace, qname.getNamespace()), + () -> assertEquals(localName, qname.getLocalName())); + } + +} 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 890092d85..d037e65f6 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 @@ -334,7 +334,7 @@ default IBoundModule registerModule(@NonNull IModule module) { */ @Nullable default > TYPE getJavaTypeAdapterInstance(@NonNull Class clazz) { - return DataTypeService.getInstance().getJavaTypeAdapterByClass(clazz); + return DataTypeService.instance().getJavaTypeAdapterByClass(clazz); } /** diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/ConstraintFactory.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/ConstraintFactory.java index 59c06bbee..0ce930d3e 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/ConstraintFactory.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/impl/ConstraintFactory.java @@ -154,7 +154,7 @@ static String toMessage(@NonNull String message) { @Nullable static IDataTypeAdapter toDataType(@NonNull Class> adapterClass) { return adapterClass.isAssignableFrom(NullJavaTypeAdapter.class) ? null - : DataTypeService.getInstance().getJavaTypeAdapterByClass(adapterClass); + : DataTypeService.instance().getJavaTypeAdapterByClass(adapterClass); } @NonNull diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/ModelSupport.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/ModelSupport.java index 70a3418a4..37abf5df8 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/ModelSupport.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/impl/ModelSupport.java @@ -24,10 +24,10 @@ import gov.nist.secauto.metaschema.databind.model.annotations.ModelUtil; import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingMetaschemaModule; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.GroupingAs; +import gov.nist.secauto.metaschema.databind.model.metaschema.binding.METASCHEMA.DefineAssembly.RootName; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.Property; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.Remarks; import gov.nist.secauto.metaschema.databind.model.metaschema.binding.UseName; -import gov.nist.secauto.metaschema.databind.model.metaschema.binding.METASCHEMA.DefineAssembly.RootName; import java.math.BigInteger; import java.net.URI; @@ -122,7 +122,7 @@ public static IDataTypeAdapter dataType(@Nullable String dataType) { if (dataType == null) { retval = MetaschemaDataTypeProvider.DEFAULT_DATA_TYPE; } else { - retval = DataTypeService.getInstance().getJavaTypeAdapterByName(dataType); + retval = DataTypeService.instance().getJavaTypeAdapterByName(dataType); if (retval == null) { throw new IllegalStateException("Unrecognized data type: " + dataType); }