From 1e35c10f8ec28016e27e846b4376584eac232fc0 Mon Sep 17 00:00:00 2001 From: David Waltermire Date: Fri, 27 Sep 2024 10:49:12 -0400 Subject: [PATCH] Work in progress towards a better type system. --- core/src/main/antlr4/Metapath10.g4 | 47 ++++--- .../metaschema/core/metapath/EQNameUtils.java | 38 +++++- .../metaschema/core/metapath/ISequence.java | 2 + .../core/metapath/MetapathExpression.java | 2 + .../core/metapath/StaticContext.java | 10 +- .../core/metapath/cst/AbstractExpression.java | 2 +- .../core/metapath/cst/MapConstructor.java | 2 +- .../core/metapath/cst/math/Division.java | 2 +- .../metapath/cst/math/Multiplication.java | 2 +- .../core/metapath/cst/math/Subtraction.java | 2 +- .../core/metapath/function/ArgumentImpl.java | 2 + .../function/ComparisonFunctions.java | 2 +- .../metapath/function/DefaultFunction.java | 17 ++- .../core/metapath/function/FunctionUtils.java | 4 +- .../core/metapath/function/IArgument.java | 2 + .../core/metapath/function/IFunction.java | 4 +- .../metapath/function/OperationFunctions.java | 2 +- .../metapath/function/library/FnPath.java | 2 +- .../metapath/function/library/FnString.java | 2 +- .../core/metapath/impl/AbstractArrayItem.java | 4 +- .../metapath/impl/AbstractKeySpecifier.java | 2 +- .../core/metapath/impl/AbstractMapItem.java | 4 +- .../core/metapath/item/DefaultItemWriter.java | 11 ++ .../core/metapath/item/IItemVisitor.java | 9 ++ .../core/metapath/item/IItemWriter.java | 9 ++ .../core/metapath/item/ItemUtils.java | 2 +- .../metapath/item/atomic/IIntegerItem.java | 2 +- .../item/atomic/INonNegativeIntegerItem.java | 2 +- .../item/atomic/IPositiveIntegerItem.java | 2 +- .../metapath/item/function/IArrayItem.java | 2 +- .../core/metapath/item/function/IMapItem.java | 2 +- .../core/metapath/type/IArrayTest.java | 6 + .../metapath/type/IAtomicOrUnionType.java | 6 + .../core/metapath/type/IFunctionTest.java | 6 + .../core/metapath/type/IItemType.java | 60 +++++++++ .../core/metapath/type/IMapTest.java | 6 + .../{function => type}/ISequenceType.java | 11 +- .../InvalidTypeMetapathException.java | 2 +- .../{function => type}/Occurrence.java | 3 +- .../{ => type}/TypeMetapathException.java | 4 +- .../core/metapath/type/TypeSystem.java | 127 ++++++++++++++++++ .../metapath/type/impl/AbstractItemType.java | 26 ++++ .../type/impl/AbstractNodeItemType.java | 39 ++++++ .../core/metapath/type/impl/AnyItemType.java | 40 ++++++ .../metapath/type/impl/AnyRawItemType.java | 37 +++++ .../core/metapath/type/impl/ArrayTest.java | 45 +++++++ .../metapath/type/impl/DataTypeItemType.java | 41 ++++++ .../impl}/SequenceTypeImpl.java | 8 +- .../core/model/constraint/IIndex.java | 2 +- core/src/main/java/module-info.java | 1 + .../core/metapath/ISequenceTest.java | 2 + .../core/metapath/cst/EQNameUtilsTest.java | 4 +- 52 files changed, 605 insertions(+), 68 deletions(-) create mode 100644 core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/IArrayTest.java create mode 100644 core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/IAtomicOrUnionType.java create mode 100644 core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/IFunctionTest.java create mode 100644 core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/IItemType.java create mode 100644 core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/IMapTest.java rename core/src/main/java/gov/nist/secauto/metaschema/core/metapath/{function => type}/ISequenceType.java (84%) rename core/src/main/java/gov/nist/secauto/metaschema/core/metapath/{ => type}/InvalidTypeMetapathException.java (97%) rename core/src/main/java/gov/nist/secauto/metaschema/core/metapath/{function => type}/Occurrence.java (96%) rename core/src/main/java/gov/nist/secauto/metaschema/core/metapath/{ => type}/TypeMetapathException.java (95%) create mode 100644 core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/TypeSystem.java create mode 100644 core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/AbstractItemType.java create 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/AnyItemType.java create mode 100644 core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/AnyRawItemType.java create mode 100644 core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/ArrayTest.java create mode 100644 core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/DataTypeItemType.java rename core/src/main/java/gov/nist/secauto/metaschema/core/metapath/{function => type/impl}/SequenceTypeImpl.java (84%) diff --git a/core/src/main/antlr4/Metapath10.g4 b/core/src/main/antlr4/Metapath10.g4 index 6f2dfa541..d91693cf8 100644 --- a/core/src/main/antlr4/Metapath10.g4 +++ b/core/src/main/antlr4/Metapath10.g4 @@ -6,9 +6,9 @@ options { tokenVocab=Metapath10Lexer; superClass=Metapath10ParserBase; } // [1] metapath : expr EOF ; -// paramlist : param ( COMMA param)* ; -// param : DOLLAR eqname typedeclaration? ; -// functionbody : enclosedexpr ; +paramlist : param ( COMMA param)* ; +param : DOLLAR eqname typedeclaration? ; +functionbody : enclosedexpr ; // [5] enclosedexpr : OC expr? CC ; expr : exprsingle ( COMMA exprsingle)* ; @@ -74,10 +74,8 @@ predicate : OB expr CB ; lookup : QM keyspecifier ; keyspecifier : NCName | IntegerLiteral | parenthesizedexpr | STAR ; // [55] -//arrowfunctionspecifier : eqname | varref | parenthesizedexpr ; -arrowfunctionspecifier : eqname; -// primaryexpr : literal | varref | parenthesizedexpr | contextitemexpr | functioncall | functionitemexpr | mapconstructor | arrayconstructor | unarylookup ; -primaryexpr : literal | varref | parenthesizedexpr | contextitemexpr | functioncall | mapconstructor | arrayconstructor | unarylookup; +arrowfunctionspecifier : eqname | varref | parenthesizedexpr ; +primaryexpr : literal | varref | parenthesizedexpr | contextitemexpr | functioncall | functionitemexpr | mapconstructor | arrayconstructor | unarylookup ; literal : numericliteral | StringLiteral ; numericliteral : IntegerLiteral | DecimalLiteral | DoubleLiteral ; varref : DOLLAR varname ; @@ -90,9 +88,9 @@ functioncall : { this.isFuncCall() }? eqname argumentlist ; argument : exprsingle ; // [65] // argumentplaceholder : QM ; -// functionitemexpr : namedfunctionref | inlinefunctionexpr ; -// namedfunctionref : eqname POUND IntegerLiteral /* xgc: reserved-function-names */; -// inlinefunctionexpr : KW_FUNCTION OP paramlist? CP ( KW_AS sequencetype)? functionbody ; +functionitemexpr : namedfunctionref | inlinefunctionexpr ; +namedfunctionref : eqname POUND IntegerLiteral /* xgc: reserved-function-names */; +inlinefunctionexpr : KW_FUNCTION OP paramlist? CP ( KW_AS sequencetype)? functionbody ; mapconstructor : KW_MAP OC (mapconstructorentry ( COMMA mapconstructorentry)*)? CC ; // [70] mapconstructorentry : mapkeyexpr COLON mapvalueexpr ; @@ -104,12 +102,13 @@ squarearrayconstructor : OB (exprsingle ( COMMA exprsingle)*)? CB ; curlyarrayconstructor : KW_ARRAY enclosedexpr ; unarylookup : QM keyspecifier ; // singletype : simpletypename QM? ; -// typedeclaration : KW_AS sequencetype ; -// sequencetype : KW_EMPTY_SEQUENCE OP CP | itemtype occurrenceindicator? ; +typedeclaration : KW_AS sequencetype ; +sequencetype : KW_EMPTY_SEQUENCE OP CP | itemtype occurrenceindicator? ; // [80] -// occurrenceindicator : QM | STAR | PLUS ; +occurrenceindicator : QM | STAR | PLUS ; +itemtype : KW_ITEM OP CP | functiontest | maptest | arraytest | atomicoruniontype | parenthesizeditemtype ; // itemtype : kindtest | KW_ITEM OP CP | functiontest | maptest | arraytest | atomicoruniontype | parenthesizeditemtype ; -// atomicoruniontype : eqname ; +atomicoruniontype : eqname ; // kindtest : documenttest | elementtest | attributetest | schemaelementtest | schemaattributetest | pitest | commenttest | texttest | namespacenodetest | anykindtest ; // anykindtest : KW_NODE OP CP ; // [85] @@ -133,18 +132,18 @@ unarylookup : QM keyspecifier ; // [100] // simpletypename : typename_ ; // typename_ : eqname ; -// functiontest : anyfunctiontest | typedfunctiontest ; -// anyfunctiontest : KW_FUNCTION OP STAR CP ; -// typedfunctiontest : KW_FUNCTION OP (sequencetype ( COMMA sequencetype)*)? CP KW_AS sequencetype ; +functiontest : anyfunctiontest | typedfunctiontest ; +anyfunctiontest : KW_FUNCTION OP STAR CP ; +typedfunctiontest : KW_FUNCTION OP (sequencetype ( COMMA sequencetype)*)? CP KW_AS sequencetype ; // [105] -// maptest : anymaptest | typedmaptest ; -// anymaptest : KW_MAP OP STAR CP ; -// typedmaptest : KW_MAP OP atomicoruniontype COMMA sequencetype CP ; -// arraytest : anyarraytest | typedarraytest ; -// anyarraytest : KW_ARRAY OP STAR CP ; +maptest : anymaptest | typedmaptest ; +anymaptest : KW_MAP OP STAR CP ; +typedmaptest : KW_MAP OP atomicoruniontype COMMA sequencetype CP ; +arraytest : anyarraytest | typedarraytest ; +anyarraytest : KW_ARRAY OP STAR CP ; // [110] -// typedarraytest : KW_ARRAY OP sequencetype CP ; -// parenthesizeditemtype : OP itemtype CP ; +typedarraytest : KW_ARRAY OP sequencetype CP ; +parenthesizeditemtype : OP itemtype CP ; // Error in the spec. EQName also includes acceptable keywords. 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 e62fb0a00..34ed733e4 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,6 +5,8 @@ package gov.nist.secauto.metaschema.core.metapath; +import gov.nist.secauto.metaschema.core.util.ObjectUtils; + import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -12,6 +14,7 @@ import javax.xml.namespace.QName; import edu.umd.cs.findbugs.annotations.NonNull; +import edu.umd.cs.findbugs.annotations.Nullable; public final class EQNameUtils { private static final Pattern URI_QUALIFIED_NAME = Pattern.compile("^Q\\{([^{}]*)\\}(.+)$"); @@ -43,7 +46,7 @@ private EQNameUtils() { @NonNull public static QName parseName( @NonNull String name, - @NonNull IEQNamePrefixResolver resolver) { + @NonNull PrefixToNamespaceResolver resolver) { Matcher matcher = URI_QUALIFIED_NAME.matcher(name); return matcher.matches() ? newUriQualifiedName(matcher) @@ -92,7 +95,7 @@ private static QName newUriQualifiedName(@NonNull Matcher matcher) { @NonNull public static QName parseLexicalQName( @NonNull String name, - @NonNull IEQNamePrefixResolver resolver) { + @NonNull PrefixToNamespaceResolver resolver) { Matcher matcher = LEXICAL_NAME.matcher(name); if (!matcher.matches()) { throw new IllegalArgumentException( @@ -120,11 +123,24 @@ public static boolean isNcName(@NonNull String name) { return NCNAME.matcher(name).matches(); } + @NonNull + public static String toEQName( + @NonNull QName qname, + @Nullable NamespaceToPrefixResolver resolver) { + String namespace = qname.getNamespaceURI(); + 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(); + } + /** * Provides a callback for resolving namespace prefixes. */ @FunctionalInterface - public interface IEQNamePrefixResolver { + public interface PrefixToNamespaceResolver { /** * Get the URI string for the provided namespace prefix. * @@ -135,4 +151,20 @@ public interface IEQNamePrefixResolver { @NonNull String resolve(@NonNull String prefix); } + + /** + * Provides a callback for resolving namespace prefixes. + */ + @FunctionalInterface + public interface NamespaceToPrefixResolver { + /** + * Get the URI string for the provided namespace prefix. + * + * @param namespace + * the namespace URI + * @return the associated prefix or {@code null} if no prefix is associated + */ + @Nullable + String resolve(@NonNull String namespace); + } } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/ISequence.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/ISequence.java index 2c36a75d3..6c68f93bd 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/ISequence.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/ISequence.java @@ -11,6 +11,8 @@ import gov.nist.secauto.metaschema.core.metapath.impl.StreamSequence; 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.type.InvalidTypeMetapathException; +import gov.nist.secauto.metaschema.core.metapath.type.TypeMetapathException; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.util.ArrayList; diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/MetapathExpression.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/MetapathExpression.java index 2cdcfdaed..6fb174fbf 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/MetapathExpression.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/MetapathExpression.java @@ -20,6 +20,8 @@ import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyAtomicItem; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IDecimalItem; import gov.nist.secauto.metaschema.core.metapath.item.atomic.INumericItem; +import gov.nist.secauto.metaschema.core.metapath.type.InvalidTypeMetapathException; +import gov.nist.secauto.metaschema.core.metapath.type.TypeMetapathException; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import org.antlr.v4.runtime.CharStreams; 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 13bce12ee..95d51f935 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,7 +5,7 @@ package gov.nist.secauto.metaschema.core.metapath; -import gov.nist.secauto.metaschema.core.metapath.EQNameUtils.IEQNamePrefixResolver; +import gov.nist.secauto.metaschema.core.metapath.EQNameUtils.PrefixToNamespaceResolver; import gov.nist.secauto.metaschema.core.util.CollectionUtil; import gov.nist.secauto.metaschema.core.util.ObjectUtils; @@ -220,7 +220,7 @@ public URI getDefaultFunctionNamespace() { * @return the resolver */ @NonNull - public IEQNamePrefixResolver getFunctionPrefixResolver() { + public PrefixToNamespaceResolver getFunctionPrefixResolver() { return this::resolveFunctionPrefix; } @@ -251,7 +251,7 @@ private String resolveFunctionPrefix(@NonNull String prefix) { * @return the resolver */ @NonNull - public IEQNamePrefixResolver getFlagPrefixResolver() { + public PrefixToNamespaceResolver getFlagPrefixResolver() { return this::resolveFlagReferencePrefix; } @@ -278,7 +278,7 @@ private String resolveFlagReferencePrefix(@NonNull String prefix) { * @return the resolver */ @NonNull - public IEQNamePrefixResolver getModelPrefixResolver() { + public PrefixToNamespaceResolver getModelPrefixResolver() { return this::resolveModelReferencePrefix; } @@ -309,7 +309,7 @@ private String resolveModelReferencePrefix(@NonNull String prefix) { * @return the resolver */ @NonNull - public IEQNamePrefixResolver getVariablePrefixResolver() { + public PrefixToNamespaceResolver getVariablePrefixResolver() { return this::resolveVariablePrefix; } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AbstractExpression.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AbstractExpression.java index 5c06136a5..7b1be6026 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AbstractExpression.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AbstractExpression.java @@ -6,9 +6,9 @@ package gov.nist.secauto.metaschema.core.metapath.cst; import gov.nist.secauto.metaschema.core.metapath.ISequence; -import gov.nist.secauto.metaschema.core.metapath.TypeMetapathException; import gov.nist.secauto.metaschema.core.metapath.function.library.FnData; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyAtomicItem; +import gov.nist.secauto.metaschema.core.metapath.type.TypeMetapathException; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/MapConstructor.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/MapConstructor.java index 3b00caac3..ca2cfe428 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/MapConstructor.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/MapConstructor.java @@ -8,11 +8,11 @@ import gov.nist.secauto.metaschema.core.metapath.DynamicContext; import gov.nist.secauto.metaschema.core.metapath.ICollectionValue; import gov.nist.secauto.metaschema.core.metapath.ISequence; -import gov.nist.secauto.metaschema.core.metapath.InvalidTypeMetapathException; import gov.nist.secauto.metaschema.core.metapath.function.library.FnData; 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.function.IMapItem; +import gov.nist.secauto.metaschema.core.metapath.type.InvalidTypeMetapathException; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.util.List; diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/Division.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/Division.java index c666218a2..25075bcd8 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/Division.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/Division.java @@ -6,7 +6,6 @@ package gov.nist.secauto.metaschema.core.metapath.cst.math; import gov.nist.secauto.metaschema.core.metapath.ISequence; -import gov.nist.secauto.metaschema.core.metapath.InvalidTypeMetapathException; import gov.nist.secauto.metaschema.core.metapath.cst.IExpression; import gov.nist.secauto.metaschema.core.metapath.cst.IExpressionVisitor; import gov.nist.secauto.metaschema.core.metapath.function.FunctionUtils; @@ -15,6 +14,7 @@ import gov.nist.secauto.metaschema.core.metapath.item.atomic.IDayTimeDurationItem; import gov.nist.secauto.metaschema.core.metapath.item.atomic.INumericItem; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IYearMonthDurationItem; +import gov.nist.secauto.metaschema.core.metapath.type.InvalidTypeMetapathException; import edu.umd.cs.findbugs.annotations.NonNull; diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/Multiplication.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/Multiplication.java index 18a4d5272..24414866a 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/Multiplication.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/Multiplication.java @@ -6,7 +6,6 @@ package gov.nist.secauto.metaschema.core.metapath.cst.math; import gov.nist.secauto.metaschema.core.metapath.ISequence; -import gov.nist.secauto.metaschema.core.metapath.InvalidTypeMetapathException; import gov.nist.secauto.metaschema.core.metapath.cst.IExpression; import gov.nist.secauto.metaschema.core.metapath.cst.IExpressionVisitor; import gov.nist.secauto.metaschema.core.metapath.function.FunctionUtils; @@ -15,6 +14,7 @@ import gov.nist.secauto.metaschema.core.metapath.item.atomic.IDayTimeDurationItem; import gov.nist.secauto.metaschema.core.metapath.item.atomic.INumericItem; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IYearMonthDurationItem; +import gov.nist.secauto.metaschema.core.metapath.type.InvalidTypeMetapathException; import edu.umd.cs.findbugs.annotations.NonNull; diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/Subtraction.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/Subtraction.java index d0f3f7121..c42c9b32e 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/Subtraction.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/Subtraction.java @@ -6,7 +6,6 @@ package gov.nist.secauto.metaschema.core.metapath.cst.math; import gov.nist.secauto.metaschema.core.metapath.ISequence; -import gov.nist.secauto.metaschema.core.metapath.InvalidTypeMetapathException; import gov.nist.secauto.metaschema.core.metapath.cst.IExpression; import gov.nist.secauto.metaschema.core.metapath.cst.IExpressionVisitor; import gov.nist.secauto.metaschema.core.metapath.function.FunctionUtils; @@ -17,6 +16,7 @@ import gov.nist.secauto.metaschema.core.metapath.item.atomic.IDayTimeDurationItem; import gov.nist.secauto.metaschema.core.metapath.item.atomic.INumericItem; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IYearMonthDurationItem; +import gov.nist.secauto.metaschema.core.metapath.type.InvalidTypeMetapathException; import edu.umd.cs.findbugs.annotations.NonNull; diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/ArgumentImpl.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/ArgumentImpl.java index 19ff1efe7..227f84ca3 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/ArgumentImpl.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/ArgumentImpl.java @@ -5,6 +5,8 @@ package gov.nist.secauto.metaschema.core.metapath.function; +import gov.nist.secauto.metaschema.core.metapath.type.ISequenceType; + import java.util.Objects; import edu.umd.cs.findbugs.annotations.NonNull; diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/ComparisonFunctions.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/ComparisonFunctions.java index aab9f3737..54baa409f 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/ComparisonFunctions.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/ComparisonFunctions.java @@ -6,7 +6,6 @@ package gov.nist.secauto.metaschema.core.metapath.function; import gov.nist.secauto.metaschema.core.metapath.ISequence; -import gov.nist.secauto.metaschema.core.metapath.InvalidTypeMetapathException; import gov.nist.secauto.metaschema.core.metapath.function.library.FnNot; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyAtomicItem; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IBase64BinaryItem; @@ -21,6 +20,7 @@ import gov.nist.secauto.metaschema.core.metapath.item.atomic.IStringItem; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IUntypedAtomicItem; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IYearMonthDurationItem; +import gov.nist.secauto.metaschema.core.metapath.type.InvalidTypeMetapathException; import java.util.Locale; diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/DefaultFunction.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/DefaultFunction.java index 40752c640..757f75cf5 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/DefaultFunction.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/DefaultFunction.java @@ -8,14 +8,16 @@ import gov.nist.secauto.metaschema.core.metapath.DynamicContext; import gov.nist.secauto.metaschema.core.metapath.DynamicMetapathException; import gov.nist.secauto.metaschema.core.metapath.ISequence; -import gov.nist.secauto.metaschema.core.metapath.InvalidTypeMetapathException; import gov.nist.secauto.metaschema.core.metapath.MetapathException; import gov.nist.secauto.metaschema.core.metapath.function.library.FnData; import gov.nist.secauto.metaschema.core.metapath.item.IItem; -import gov.nist.secauto.metaschema.core.metapath.item.TypeSystem; +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.item.atomic.IAnyUriItem; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IStringItem; +import gov.nist.secauto.metaschema.core.metapath.type.ISequenceType; +import gov.nist.secauto.metaschema.core.metapath.type.InvalidTypeMetapathException; +import gov.nist.secauto.metaschema.core.metapath.type.TypeSystem; import java.util.ArrayList; import java.util.Collections; @@ -339,4 +341,15 @@ public boolean equals(Object obj) { return Objects.equals(arguments, other.arguments) && Objects.equals(contextItem, other.contextItem); } } + + @Override + public Object getValue() { + // never a value + return null; + } + + @Override + public void accept(IItemVisitor visitor) { + visitor.visit(this); + } } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/FunctionUtils.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/FunctionUtils.java index a968762bb..66f452814 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/FunctionUtils.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/FunctionUtils.java @@ -6,13 +6,13 @@ package gov.nist.secauto.metaschema.core.metapath.function; import gov.nist.secauto.metaschema.core.metapath.ISequence; -import gov.nist.secauto.metaschema.core.metapath.InvalidTypeMetapathException; -import gov.nist.secauto.metaschema.core.metapath.TypeMetapathException; import gov.nist.secauto.metaschema.core.metapath.function.library.FnData; 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.IDecimalItem; import gov.nist.secauto.metaschema.core.metapath.item.atomic.INumericItem; +import gov.nist.secauto.metaschema.core.metapath.type.InvalidTypeMetapathException; +import gov.nist.secauto.metaschema.core.metapath.type.TypeMetapathException; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.math.BigInteger; 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 706bcad7c..46b1ddc38 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 @@ -6,6 +6,8 @@ package gov.nist.secauto.metaschema.core.metapath.function; import gov.nist.secauto.metaschema.core.metapath.item.IItem; +import gov.nist.secauto.metaschema.core.metapath.type.ISequenceType; +import gov.nist.secauto.metaschema.core.metapath.type.Occurrence; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.util.Objects; 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 c2323547d..2f34c147a 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 @@ -9,6 +9,8 @@ import gov.nist.secauto.metaschema.core.metapath.ISequence; import gov.nist.secauto.metaschema.core.metapath.MetapathException; import gov.nist.secauto.metaschema.core.metapath.item.IItem; +import gov.nist.secauto.metaschema.core.metapath.type.ISequenceType; +import gov.nist.secauto.metaschema.core.metapath.type.Occurrence; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.net.URI; @@ -27,7 +29,7 @@ /** * A common interface for all Metapath functions. */ -public interface IFunction { +public interface IFunction extends IItem { /** * Details specific characteristics of a function. */ diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/OperationFunctions.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/OperationFunctions.java index dac656c15..03bff5be4 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/OperationFunctions.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/OperationFunctions.java @@ -5,7 +5,6 @@ package gov.nist.secauto.metaschema.core.metapath.function; // NOPMD - intentional -import gov.nist.secauto.metaschema.core.metapath.InvalidTypeMetapathException; 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.IBooleanItem; @@ -17,6 +16,7 @@ import gov.nist.secauto.metaschema.core.metapath.item.atomic.IIntegerItem; import gov.nist.secauto.metaschema.core.metapath.item.atomic.INumericItem; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IYearMonthDurationItem; +import gov.nist.secauto.metaschema.core.metapath.type.InvalidTypeMetapathException; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.math.BigDecimal; 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 ea850f3c5..bfec72df8 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 @@ -7,7 +7,6 @@ import gov.nist.secauto.metaschema.core.metapath.DynamicContext; import gov.nist.secauto.metaschema.core.metapath.ISequence; -import gov.nist.secauto.metaschema.core.metapath.InvalidTypeMetapathException; import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.format.IPathFormatter; import gov.nist.secauto.metaschema.core.metapath.function.FunctionUtils; @@ -16,6 +15,7 @@ import gov.nist.secauto.metaschema.core.metapath.item.IItem; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IStringItem; import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem; +import gov.nist.secauto.metaschema.core.metapath.type.InvalidTypeMetapathException; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.util.List; 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 892bab33f..accb38fd1 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 @@ -7,7 +7,6 @@ import gov.nist.secauto.metaschema.core.metapath.DynamicContext; import gov.nist.secauto.metaschema.core.metapath.ISequence; -import gov.nist.secauto.metaschema.core.metapath.InvalidTypeMetapathException; import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.function.FunctionUtils; import gov.nist.secauto.metaschema.core.metapath.function.IArgument; @@ -17,6 +16,7 @@ import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyAtomicItem; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IStringItem; import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem; +import gov.nist.secauto.metaschema.core.metapath.type.InvalidTypeMetapathException; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.util.List; 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 4ed123ca6..2f5e98041 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 @@ -10,11 +10,11 @@ import gov.nist.secauto.metaschema.core.metapath.ISequence; import gov.nist.secauto.metaschema.core.metapath.function.FunctionUtils; import gov.nist.secauto.metaschema.core.metapath.function.IArgument; -import gov.nist.secauto.metaschema.core.metapath.function.ISequenceType; -import gov.nist.secauto.metaschema.core.metapath.function.Occurrence; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyAtomicItem; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IIntegerItem; import gov.nist.secauto.metaschema.core.metapath.item.function.IArrayItem; +import gov.nist.secauto.metaschema.core.metapath.type.ISequenceType; +import gov.nist.secauto.metaschema.core.metapath.type.Occurrence; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.util.EnumSet; diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/impl/AbstractKeySpecifier.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/impl/AbstractKeySpecifier.java index 844b07394..6e3d0bb2a 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/impl/AbstractKeySpecifier.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/impl/AbstractKeySpecifier.java @@ -8,7 +8,6 @@ import gov.nist.secauto.metaschema.core.metapath.DynamicContext; import gov.nist.secauto.metaschema.core.metapath.ICollectionValue; import gov.nist.secauto.metaschema.core.metapath.ISequence; -import gov.nist.secauto.metaschema.core.metapath.InvalidTypeMetapathException; import gov.nist.secauto.metaschema.core.metapath.cst.IExpression; import gov.nist.secauto.metaschema.core.metapath.function.library.ArrayGet; import gov.nist.secauto.metaschema.core.metapath.function.library.FnData; @@ -21,6 +20,7 @@ import gov.nist.secauto.metaschema.core.metapath.item.function.IArrayItem; import gov.nist.secauto.metaschema.core.metapath.item.function.IKeySpecifier; import gov.nist.secauto.metaschema.core.metapath.item.function.IMapItem; +import gov.nist.secauto.metaschema.core.metapath.type.InvalidTypeMetapathException; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.util.stream.Stream; 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 20bcf6d3b..923b2c5b2 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 @@ -10,13 +10,13 @@ import gov.nist.secauto.metaschema.core.metapath.ISequence; import gov.nist.secauto.metaschema.core.metapath.function.FunctionUtils; import gov.nist.secauto.metaschema.core.metapath.function.IArgument; -import gov.nist.secauto.metaschema.core.metapath.function.ISequenceType; -import gov.nist.secauto.metaschema.core.metapath.function.Occurrence; import gov.nist.secauto.metaschema.core.metapath.function.library.MapGet; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyAtomicItem; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IIntegerItem; 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.ISequenceType; +import gov.nist.secauto.metaschema.core.metapath.type.Occurrence; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.util.EnumSet; diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/DefaultItemWriter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/DefaultItemWriter.java index 197102488..3e2cf85e0 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/DefaultItemWriter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/DefaultItemWriter.java @@ -7,6 +7,7 @@ import gov.nist.secauto.metaschema.core.metapath.ICollectionValue; import gov.nist.secauto.metaschema.core.metapath.ISequence; +import gov.nist.secauto.metaschema.core.metapath.function.IFunction; import gov.nist.secauto.metaschema.core.metapath.function.library.FnData; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyAtomicItem; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAtomicValuedItem; @@ -119,6 +120,11 @@ public void writeAtomicValue(IAnyAtomicItem node) { writer.append(node.asString()); } + @Override + public void writeFunction(IFunction function) { + writer.append(function.toSignature()); + } + /** * Write the provided collection value. * @@ -159,5 +165,10 @@ public void visit(INodeItem node) { public void visit(IAnyAtomicItem node) { writeAtomicValue(node); } + + @Override + public void visit(IFunction function) { + writeFunction(function); + } } } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/IItemVisitor.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/IItemVisitor.java index 31b5e3a0c..f30df63fa 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/IItemVisitor.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/IItemVisitor.java @@ -5,6 +5,7 @@ package gov.nist.secauto.metaschema.core.metapath.item; +import gov.nist.secauto.metaschema.core.metapath.function.IFunction; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyAtomicItem; import gov.nist.secauto.metaschema.core.metapath.item.function.IArrayItem; import gov.nist.secauto.metaschema.core.metapath.item.function.IMapItem; @@ -44,4 +45,12 @@ public interface IItemVisitor { * the instance to visit */ void visit(@NonNull IAnyAtomicItem item); + + /** + * Visit the function item instance. + * + * @param function + * the instance to visit + */ + void visit(IFunction function); } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/IItemWriter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/IItemWriter.java index 54a416a3b..90253dbe6 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/IItemWriter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/IItemWriter.java @@ -6,6 +6,7 @@ package gov.nist.secauto.metaschema.core.metapath.item; import gov.nist.secauto.metaschema.core.metapath.ISequence; +import gov.nist.secauto.metaschema.core.metapath.function.IFunction; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyAtomicItem; import gov.nist.secauto.metaschema.core.metapath.item.function.IArrayItem; import gov.nist.secauto.metaschema.core.metapath.item.function.IMapItem; @@ -53,4 +54,12 @@ public interface IItemWriter extends AutoCloseable { * the instance to write */ void writeAtomicValue(@NonNull IAnyAtomicItem item); + + /** + * Write the provided function item instance. + * + * @param function + * the instance to write + */ + void writeFunction(@NonNull IFunction function); } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/ItemUtils.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/ItemUtils.java index aa7eb25de..660260f97 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/ItemUtils.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/ItemUtils.java @@ -5,8 +5,8 @@ package gov.nist.secauto.metaschema.core.metapath.item; -import gov.nist.secauto.metaschema.core.metapath.TypeMetapathException; import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem; +import gov.nist.secauto.metaschema.core.metapath.type.TypeMetapathException; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; 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 db6b14002..dc1823d90 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 @@ -6,8 +6,8 @@ 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.type.InvalidTypeMetapathException; import java.math.BigInteger; 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 b346796e9..4bcd46884 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 @@ -6,8 +6,8 @@ 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.type.InvalidTypeMetapathException; import java.math.BigInteger; 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 7eff6798c..8cca39323 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 @@ -6,8 +6,8 @@ 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.type.InvalidTypeMetapathException; import java.math.BigInteger; 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 b819540b7..40f9d5445 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 @@ -11,11 +11,11 @@ import gov.nist.secauto.metaschema.core.metapath.ISequence; import gov.nist.secauto.metaschema.core.metapath.function.IArgument; import gov.nist.secauto.metaschema.core.metapath.function.IFunction; -import gov.nist.secauto.metaschema.core.metapath.function.ISequenceType; import gov.nist.secauto.metaschema.core.metapath.impl.AbstractArrayItem; 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.ISequenceType; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.util.ArrayList; 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 725e61925..c091f5b87 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 @@ -11,12 +11,12 @@ import gov.nist.secauto.metaschema.core.metapath.ISequence; import gov.nist.secauto.metaschema.core.metapath.function.IArgument; import gov.nist.secauto.metaschema.core.metapath.function.IFunction; -import gov.nist.secauto.metaschema.core.metapath.function.ISequenceType; import gov.nist.secauto.metaschema.core.metapath.impl.AbstractMapItem; import gov.nist.secauto.metaschema.core.metapath.impl.MapItemN; 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.ISequenceType; import java.util.LinkedHashMap; import java.util.List; diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/IArrayTest.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/IArrayTest.java new file mode 100644 index 000000000..a8c9dbaaf --- /dev/null +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/IArrayTest.java @@ -0,0 +1,6 @@ + +package gov.nist.secauto.metaschema.core.metapath.type; + +public interface IArrayTest 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 new file mode 100644 index 000000000..4ff2c17c0 --- /dev/null +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/IAtomicOrUnionType.java @@ -0,0 +1,6 @@ + +package gov.nist.secauto.metaschema.core.metapath.type; + +public interface IAtomicOrUnionType extends IItemType { + +} diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/IFunctionTest.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/IFunctionTest.java new file mode 100644 index 000000000..812c31b77 --- /dev/null +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/IFunctionTest.java @@ -0,0 +1,6 @@ + +package gov.nist.secauto.metaschema.core.metapath.type; + +public interface IFunctionTest extends IItemType { + +} 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 new file mode 100644 index 000000000..2e260c618 --- /dev/null +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/IItemType.java @@ -0,0 +1,60 @@ + +package gov.nist.secauto.metaschema.core.metapath.type; + +import gov.nist.secauto.metaschema.core.datatype.IDataTypeAdapter; +import gov.nist.secauto.metaschema.core.metapath.item.IItem; +import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem; +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.ArrayTest; +import gov.nist.secauto.metaschema.core.metapath.type.impl.DataTypeItemType; + +import edu.umd.cs.findbugs.annotations.NonNull; + +public interface IItemType { + @NonNull + static IItemType item() { + return AnyItemType.instance(); + } + + static IItemType function() { + return AnyRawItemType.ANY_FUNCTION; + } + + // static IFunctionTest function(@NonNull ISequenceType result, @NonNull + // ISequenceType... args) { + // + // } + + static IItemType map() { + return AnyRawItemType.ANY_MAP; + } + + // static IMapTest map(@NonNull IAtomicOrUnionType key, @NonNull ISequenceType + // value) { + // + // } + + static IItemType array() { + return AnyRawItemType.ANY_ARRAY; + } + + static IArrayTest array(@NonNull ISequenceType value) { + return new ArrayTest(value); + } + + static IItemType type(@NonNull IDataTypeAdapter adapter) { + return new DataTypeItemType(adapter); + } + + boolean matches(@NonNull IItem item); + + @NonNull + Class getItemClass(); + + @NonNull + String toSignature(); + + static IItemType node(Class itemClass, String nodeName) { + } +} 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 new file mode 100644 index 000000000..e014a63b8 --- /dev/null +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/IMapTest.java @@ -0,0 +1,6 @@ + +package gov.nist.secauto.metaschema.core.metapath.type; + +public interface IMapTest extends IItemType { + +} diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/ISequenceType.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/ISequenceType.java similarity index 84% rename from core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/ISequenceType.java rename to core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/ISequenceType.java index 72cb23a14..b990e0195 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/ISequenceType.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/ISequenceType.java @@ -3,9 +3,11 @@ * SPDX-License-Identifier: CC0-1.0 */ -package gov.nist.secauto.metaschema.core.metapath.function; +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; @@ -31,6 +33,11 @@ public Occurrence getOccurrence() { public String toSignature() { return "()"; } + + @Override + public boolean matches(ICollectionValue item) { + return false; + } }; /** @@ -79,4 +86,6 @@ static ISequenceType of(@NonNull Class type, @NonNull Occurrenc */ @NonNull String toSignature(); + + boolean matches(@NonNull ICollectionValue item); } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/InvalidTypeMetapathException.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/InvalidTypeMetapathException.java similarity index 97% rename from core/src/main/java/gov/nist/secauto/metaschema/core/metapath/InvalidTypeMetapathException.java rename to core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/InvalidTypeMetapathException.java index b89ed9057..96a61f4e3 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/InvalidTypeMetapathException.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/InvalidTypeMetapathException.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: CC0-1.0 */ -package gov.nist.secauto.metaschema.core.metapath; +package gov.nist.secauto.metaschema.core.metapath.type; import gov.nist.secauto.metaschema.core.metapath.item.IItem; diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/Occurrence.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/Occurrence.java similarity index 96% rename from core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/Occurrence.java rename to core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/Occurrence.java index bc52948c4..c1f7e2e87 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/Occurrence.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/Occurrence.java @@ -3,10 +3,9 @@ * SPDX-License-Identifier: CC0-1.0 */ -package gov.nist.secauto.metaschema.core.metapath.function; +package gov.nist.secauto.metaschema.core.metapath.type; import gov.nist.secauto.metaschema.core.metapath.ISequence; -import gov.nist.secauto.metaschema.core.metapath.InvalidTypeMetapathException; import gov.nist.secauto.metaschema.core.metapath.item.IItem; import java.util.Objects; diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/TypeMetapathException.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/TypeMetapathException.java similarity index 95% rename from core/src/main/java/gov/nist/secauto/metaschema/core/metapath/TypeMetapathException.java rename to core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/TypeMetapathException.java index 0e7434bed..aed0b5b81 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/TypeMetapathException.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/TypeMetapathException.java @@ -3,7 +3,9 @@ * SPDX-License-Identifier: CC0-1.0 */ -package gov.nist.secauto.metaschema.core.metapath; +package gov.nist.secauto.metaschema.core.metapath.type; + +import gov.nist.secauto.metaschema.core.metapath.AbstractCodedMetapathException; /** * MPTY: Exceptions related to Metapath type errors. 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 new file mode 100644 index 000000000..31d156e55 --- /dev/null +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/TypeSystem.java @@ -0,0 +1,127 @@ +/* + * SPDX-FileCopyrightText: none + * SPDX-License-Identifier: CC0-1.0 + */ + +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.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.IDurationItem; +import gov.nist.secauto.metaschema.core.metapath.item.atomic.INumericItem; +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") +public final class TypeSystem { + private static final Map, IItemType> ITEM_CLASS_TO_TYPE_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(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))); + + } + + private static Map.Entry, IItemType> register( + @NonNull IItemType type) { + return Map.entry(type.getItemClass(), type); + } + + private static Map.Entry, IItemType> register( + @NonNull IDataTypeAdapter adapter) { + 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") 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/type/impl/AbstractItemType.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/AbstractItemType.java new file mode 100644 index 000000000..b8f968b20 --- /dev/null +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/AbstractItemType.java @@ -0,0 +1,26 @@ + +package gov.nist.secauto.metaschema.core.metapath.type.impl; + +import gov.nist.secauto.metaschema.core.metapath.item.IItem; +import gov.nist.secauto.metaschema.core.metapath.type.IItemType; + +import edu.umd.cs.findbugs.annotations.NonNull; + +public abstract class AbstractItemType implements IItemType { + @NonNull + private final Class itemClass; + + 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 new file mode 100644 index 000000000..2ee94ad0d --- /dev/null +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/AbstractNodeItemType.java @@ -0,0 +1,39 @@ + +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/AnyItemType.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/AnyItemType.java new file mode 100644 index 000000000..3f9e1d767 --- /dev/null +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/AnyItemType.java @@ -0,0 +1,40 @@ + +package gov.nist.secauto.metaschema.core.metapath.type.impl; + +import gov.nist.secauto.metaschema.core.metapath.item.IItem; +import gov.nist.secauto.metaschema.core.metapath.type.IItemType; + +import edu.umd.cs.findbugs.annotations.NonNull; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + +@SuppressFBWarnings(value = "SING_SINGLETON_GETTER_NOT_SYNCHRONIZED", justification = "false positive") +public final class AnyItemType + implements IItemType { + @NonNull + private static final AnyItemType INSTANCE = new AnyItemType(); + + @NonNull + public static AnyItemType instance() { + return INSTANCE; + } + + @Override + public boolean matches(IItem item) { + // any item type always matches + return true; + } + + @Override + public Class getItemClass() { + return IItem.class; + } + + @Override + public String toSignature() { + return "item()"; + } + + private AnyItemType() { + // disable construction + } +} 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 new file mode 100644 index 000000000..521467be6 --- /dev/null +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/AnyRawItemType.java @@ -0,0 +1,37 @@ + +package gov.nist.secauto.metaschema.core.metapath.type.impl; + +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 edu.umd.cs.findbugs.annotations.NonNull; + +public final class AnyRawItemType + extends AbstractItemType { + public static final AnyRawItemType ANY_FUNCTION = new AnyRawItemType<>( + IFunction.class, + "function(*)"); + public static final AnyRawItemType> ANY_MAP = new AnyRawItemType<>( + IMapItem.class, + "map(*)"); + public static final AnyRawItemType> ANY_ARRAY = new AnyRawItemType<>( + IArrayItem.class, + "array(*)"); + + @NonNull + private String signature; + + private AnyRawItemType( + @NonNull Class itemClass, + @NonNull String signature) { + super(itemClass); + this.signature = signature; + } + + @Override + public String toSignature() { + return signature; + } +} diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/ArrayTest.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/ArrayTest.java new file mode 100644 index 000000000..83b0bc432 --- /dev/null +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/ArrayTest.java @@ -0,0 +1,45 @@ + +package gov.nist.secauto.metaschema.core.metapath.type.impl; + +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.type.IArrayTest; +import gov.nist.secauto.metaschema.core.metapath.type.ISequenceType; +import gov.nist.secauto.metaschema.core.util.ObjectUtils; + +import edu.umd.cs.findbugs.annotations.NonNull; + +public class ArrayTest implements IArrayTest { + @NonNull + private final ISequenceType valueType; + + public ArrayTest(@NonNull ISequenceType valueType) { + this.valueType = valueType; + } + + public ISequenceType getValueType() { + return valueType; + } + + @Override + public boolean matches(IItem item) { + return item instanceof IArrayItem + ? ((IArrayItem) item).stream().allMatch(valueType::matches) + : false; + } + + @Override + public Class getItemClass() { + return IArrayItem.class; + } + + @Override + public String toSignature() { + return ObjectUtils.notNull( + new StringBuilder() + .append("array(") + .append(getValueType().toSignature()) + .append(')') + .toString()); + } +} 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 new file mode 100644 index 000000000..fa0a182f2 --- /dev/null +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/DataTypeItemType.java @@ -0,0 +1,41 @@ + +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 edu.umd.cs.findbugs.annotations.NonNull; + +public class DataTypeItemType + implements IItemType { + + @NonNull + private final IDataTypeAdapter adapter; + + public DataTypeItemType(@NonNull IDataTypeAdapter adapter) { + this.adapter = adapter; + } + + @NonNull + public IDataTypeAdapter getAdapter() { + return adapter; + } + + @Override + public Class getItemClass() { + return getAdapter().getItemClass(); + } + + @Override + public boolean matches(IItem item) { + return getItemClass().isInstance(item); + } + + @Override + public String toSignature() { + return EQNameUtils.toEQName(getAdapter().getPreferredName(), null); + } +} diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/SequenceTypeImpl.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/SequenceTypeImpl.java similarity index 84% rename from core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/SequenceTypeImpl.java rename to core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/SequenceTypeImpl.java index 79fb297c0..c92b17cc6 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/SequenceTypeImpl.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/type/impl/SequenceTypeImpl.java @@ -3,17 +3,19 @@ * SPDX-License-Identifier: CC0-1.0 */ -package gov.nist.secauto.metaschema.core.metapath.function; +package gov.nist.secauto.metaschema.core.metapath.type.impl; import gov.nist.secauto.metaschema.core.metapath.item.IItem; -import gov.nist.secauto.metaschema.core.metapath.item.TypeSystem; +import gov.nist.secauto.metaschema.core.metapath.type.ISequenceType; +import gov.nist.secauto.metaschema.core.metapath.type.Occurrence; +import gov.nist.secauto.metaschema.core.metapath.type.TypeSystem; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.util.Objects; import edu.umd.cs.findbugs.annotations.NonNull; -class SequenceTypeImpl implements ISequenceType { +public class SequenceTypeImpl implements ISequenceType { private final Class type; private final Occurrence occurrence; diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IIndex.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IIndex.java index f801588ee..4b51f58cf 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IIndex.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IIndex.java @@ -6,13 +6,13 @@ package gov.nist.secauto.metaschema.core.model.constraint; import gov.nist.secauto.metaschema.core.metapath.DynamicContext; -import gov.nist.secauto.metaschema.core.metapath.InvalidTypeMetapathException; import gov.nist.secauto.metaschema.core.metapath.MetapathException; import gov.nist.secauto.metaschema.core.metapath.MetapathExpression; import gov.nist.secauto.metaschema.core.metapath.MetapathExpression.ResultType; import gov.nist.secauto.metaschema.core.metapath.function.library.FnData; import gov.nist.secauto.metaschema.core.metapath.item.IItem; import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem; +import gov.nist.secauto.metaschema.core.metapath.type.InvalidTypeMetapathException; import gov.nist.secauto.metaschema.core.model.constraint.impl.DefaultIndex; import gov.nist.secauto.metaschema.core.util.CollectionUtil; import gov.nist.secauto.metaschema.core.util.ObjectUtils; diff --git a/core/src/main/java/module-info.java b/core/src/main/java/module-info.java index 61b0705e8..28dfecb30 100644 --- a/core/src/main/java/module-info.java +++ b/core/src/main/java/module-info.java @@ -78,6 +78,7 @@ exports gov.nist.secauto.metaschema.core.metapath.item.atomic; exports gov.nist.secauto.metaschema.core.metapath.item.function; exports gov.nist.secauto.metaschema.core.metapath.item.node; + exports gov.nist.secauto.metaschema.core.metapath.type; exports gov.nist.secauto.metaschema.core.model; exports gov.nist.secauto.metaschema.core.model.constraint; exports gov.nist.secauto.metaschema.core.model.util; diff --git a/core/src/test/java/gov/nist/secauto/metaschema/core/metapath/ISequenceTest.java b/core/src/test/java/gov/nist/secauto/metaschema/core/metapath/ISequenceTest.java index b3f077302..f640da8e2 100644 --- a/core/src/test/java/gov/nist/secauto/metaschema/core/metapath/ISequenceTest.java +++ b/core/src/test/java/gov/nist/secauto/metaschema/core/metapath/ISequenceTest.java @@ -11,6 +11,8 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; +import gov.nist.secauto.metaschema.core.metapath.type.InvalidTypeMetapathException; + import org.junit.jupiter.api.Test; class ISequenceTest { diff --git a/core/src/test/java/gov/nist/secauto/metaschema/core/metapath/cst/EQNameUtilsTest.java b/core/src/test/java/gov/nist/secauto/metaschema/core/metapath/cst/EQNameUtilsTest.java index 408779c9c..0c199011b 100644 --- a/core/src/test/java/gov/nist/secauto/metaschema/core/metapath/cst/EQNameUtilsTest.java +++ b/core/src/test/java/gov/nist/secauto/metaschema/core/metapath/cst/EQNameUtilsTest.java @@ -8,7 +8,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import gov.nist.secauto.metaschema.core.metapath.EQNameUtils; -import gov.nist.secauto.metaschema.core.metapath.EQNameUtils.IEQNamePrefixResolver; +import gov.nist.secauto.metaschema.core.metapath.EQNameUtils.PrefixToNamespaceResolver; import gov.nist.secauto.metaschema.core.metapath.StaticContext; import org.junit.jupiter.params.ParameterizedTest; @@ -81,7 +81,7 @@ static Stream provideValues() { void test( @NonNull String eqname, @NonNull QName expected, - @NonNull IEQNamePrefixResolver resolver) { + @NonNull PrefixToNamespaceResolver resolver) { QName actual = EQNameUtils.parseName(eqname, resolver); assertEquals(expected, actual);