From dad334e9976d04441c412bca5ee6fc67aec3b96d Mon Sep 17 00:00:00 2001 From: David Waltermire Date: Tue, 26 Nov 2024 02:41:12 -0500 Subject: [PATCH] Added support for 'treat as' Metapath expressions. Refactored IItem and ICollectionValue types to have a tighter integration with the data type system. Added support for full signature generation for these implementations. --- .github/workflows/build.yml | 2 +- .../metapath/DynamicMetapathException.java | 2 +- .../core/metapath/ICollectionValue.java | 8 ++ .../metaschema/core/metapath/ISequence.java | 2 +- .../core/metapath/MetapathExpression.java | 81 +++++++++++-------- .../core/metapath/StaticContext.java | 44 ++++++++-- .../cst/AbstractExpressionVisitor.java | 6 ++ .../core/metapath/cst/BuildCSTVisitor.java | 9 ++- .../core/metapath/cst/CSTPrinter.java | 6 ++ .../core/metapath/cst/IExpressionVisitor.java | 12 +++ .../core/metapath/cst/type/Treat.java | 79 ++++++++++++++++++ .../core/metapath/function/IFunction.java | 7 ++ .../function/library/FnLowerCase.java | 2 +- .../function/library/FnSubstring.java | 2 +- .../function/library/FnUpperCase.java | 2 +- .../core/metapath/impl/AbstractArrayItem.java | 12 ++- .../core/metapath/impl/AbstractMapItem.java | 12 ++- .../core/metapath/impl/AbstractSequence.java | 10 +-- .../metaschema/core/metapath/item/IItem.java | 8 ++ .../item/atomic/AbstractAnyAtomicItem.java | 1 - .../item/atomic/AbstractAtomicItemBase.java | 17 +++- .../metapath/item/atomic/IAnyAtomicItem.java | 27 +++---- .../metapath/item/atomic/IAnyUriItem.java | 5 ++ .../item/atomic/IBase64BinaryItem.java | 5 ++ .../metapath/item/atomic/IBooleanItem.java | 5 ++ .../core/metapath/item/atomic/IDateItem.java | 5 ++ .../metapath/item/atomic/IDateTimeItem.java | 5 ++ .../atomic/IDateTimeWithTimeZoneItem.java | 5 ++ .../item/atomic/IDateWithTimeZoneItem.java | 5 ++ .../item/atomic/IDayTimeDurationItem.java | 5 ++ .../metapath/item/atomic/IDecimalItem.java | 5 ++ .../item/atomic/IEmailAddressItem.java | 5 ++ .../metapath/item/atomic/IHostnameItem.java | 5 ++ .../metapath/item/atomic/IIPAddressItem.java | 5 ++ .../item/atomic/IIPv4AddressItem.java | 5 ++ .../item/atomic/IIPv6AddressItem.java | 5 ++ .../metapath/item/atomic/IIntegerItem.java | 5 ++ .../metapath/item/atomic/IMarkupItem.java | 5 ++ .../metapath/item/atomic/IMarkupLineItem.java | 5 ++ .../item/atomic/IMarkupMultilineItem.java | 5 ++ .../metapath/item/atomic/INcNameItem.java | 5 ++ .../item/atomic/INonNegativeIntegerItem.java | 5 ++ .../item/atomic/IPositiveIntegerItem.java | 5 ++ .../metapath/item/atomic/IStringItem.java | 5 ++ .../core/metapath/item/atomic/ITokenItem.java | 5 ++ .../item/atomic/IUriReferenceItem.java | 5 ++ .../core/metapath/item/atomic/IUuidItem.java | 5 ++ .../item/atomic/IYearMonthDurationItem.java | 5 ++ .../item/atomic/impl/AbstractDecimalItem.java | 5 ++ .../atomic/impl/AbstractIPAddressItem.java | 5 ++ .../item/atomic/impl/AbstractMarkupItem.java | 5 ++ .../item/atomic/impl/AbstractStringItem.java | 4 + .../atomic/impl/AbstractTemporalItem.java | 5 ++ .../item/atomic/impl/AbstractUriItem.java | 5 ++ .../item/atomic/impl/AnyUriItemImpl.java | 1 + .../atomic/impl/Base64BinaryItemImpl.java | 5 ++ .../item/atomic/impl/BooleanItemImpl.java | 2 +- .../atomic/impl/DayTimeDurationItemImpl.java | 15 ++-- .../item/atomic/impl/UuidItemImpl.java | 21 +++-- .../impl/YearMonthDurationItemImpl.java | 15 ++-- .../metapath/item/function/IArrayItem.java | 8 +- .../core/metapath/item/function/IMapItem.java | 8 +- .../item/node/AbstractDefinitionNodeItem.java | 1 + .../node/AbstractFlagInstanceNodeItem.java | 14 +--- .../AbstractGlobalDefinitionNodeItem.java | 10 +++ .../item/node/AbstractInstanceNodeItem.java | 1 + .../metapath/item/node/AbstractNodeItem.java | 33 ++++++++ .../AbstractOrphanedDefinitionNodeItem.java | 5 ++ .../AssemblyGlobalDefinitionNodeItemImpl.java | 4 - .../AssemblyInstanceNoValueNodeItemImpl.java | 5 ++ .../node/AssemblyInstanceNodeItemImpl.java | 5 ++ ...ssemblyOrphanedDefinitionNodeItemImpl.java | 1 + .../CycledAssemblyInstanceNodeItemImpl.java | 6 ++ .../item/node/DocumentNodeItemImpl.java | 5 ++ .../FieldGlobalDefinitionNodeItemImpl.java | 5 -- .../FieldInstanceNoValueNodeItemImpl.java | 5 ++ .../item/node/FieldInstanceNodeItemImpl.java | 5 ++ .../FlagGlobalDefinitionNodeItemImpl.java | 5 -- .../metapath/item/node/IAssemblyNodeItem.java | 11 +++ .../metapath/item/node/IDocumentNodeItem.java | 7 ++ .../metapath/item/node/IFieldNodeItem.java | 12 +++ .../metapath/item/node/IFlagNodeItem.java | 12 +++ .../metapath/item/node/IModuleNodeItem.java | 10 +++ .../item/node/ModuleNodeItemImpl.java | 6 ++ .../node/RootAssemblyValuedNodeItemImpl.java | 6 ++ .../metapath/type/IAtomicOrUnionType.java | 2 +- .../core/metapath/type/IItemType.java | 1 + .../metaschema/core/qname/IEnhancedQName.java | 30 ++++++- .../metaschema/core/qname/QNameCache.java | 7 +- .../annotations/NullJavaTypeAdapter.java | 11 +++ pom.xml | 3 +- 91 files changed, 675 insertions(+), 138 deletions(-) create mode 100644 core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/type/Treat.java create mode 100644 core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/AbstractNodeItem.java diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f0f72d9f7..a8b18ba8b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -128,7 +128,7 @@ jobs: # ------------------------- - name: Build and Test Website run: | - mvn -B -e -Prelease install site site:stage -Dmaven.test.skip=true + mvn -B -e -PCI -Prelease install site site:stage -Dmaven.test.skip=true - name: Zip Artifacts for Upload run: | zip ${{ runner.temp }}/website.zip -r target/staging diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/DynamicMetapathException.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/DynamicMetapathException.java index 12ba1849b..95d8512b7 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/DynamicMetapathException.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/DynamicMetapathException.java @@ -40,7 +40,7 @@ public class DynamicMetapathException * "/" or "//" in a path expression is an abbreviation for an initial step that * includes the clause treat as document-node(). */ - public static final int CONTEXT_NODE_NOT_A_DOCUMENT_NODE = 50; + public static final int TREAT_DOES_NOT_MATCH_TYPE = 50; /** * Constructs a new exception with the provided {@code code}, {@code message}, diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/ICollectionValue.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/ICollectionValue.java index 2ee886688..8b5292a22 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/ICollectionValue.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/ICollectionValue.java @@ -95,4 +95,12 @@ static Stream normalizeAsItems(@NonNull ICollectionValue value) */ @NonNull Stream flatten(); + + /** + * Get a representation of the value based on its type signature. + * + * @return the signature + */ + @NonNull + String toSignature(); } 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 4b4c951f6..a640b269e 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 @@ -37,7 +37,7 @@ * the Java type of the items in a sequence */ @SuppressWarnings("PMD.ShortMethodName") -public interface ISequence extends List, IPrintable, ICollectionValue { +public interface ISequence extends List, ICollectionValue { /** * Get an empty sequence. * 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 b0d033dbb..a8792b363 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 @@ -173,48 +173,18 @@ public static MetapathExpression compile(@NonNull String path, @NonNull StaticCo retval = CONTEXT_NODE; } else { try { - Metapath10Lexer lexer = new Metapath10Lexer(CharStreams.fromString(path)); - lexer.removeErrorListeners(); - lexer.addErrorListener(new FailingErrorListener()); - - CommonTokenStream tokens = new CommonTokenStream(lexer); - Metapath10 parser = new Metapath10(tokens); - parser.removeErrorListeners(); - parser.addErrorListener(new FailingErrorListener()); - parser.setErrorHandler(new DefaultErrorStrategy() { - - @Override - public void sync(Parser recognizer) { - // disable - } - }); - + Metapath10 parser = newParser(path); ParseTree tree = ObjectUtils.notNull(parser.metapath()); - - if (LOGGER.isDebugEnabled()) { - try (ByteArrayOutputStream os = new ByteArrayOutputStream()) { - try (PrintStream ps = new PrintStream(os, true, StandardCharsets.UTF_8)) { - ParseTreePrinter printer = new ParseTreePrinter(ps); - printer.print(tree, Metapath10.ruleNames); - ps.flush(); - } - LOGGER.atDebug().log(String.format("Metapath AST:%n%s", os.toString(StandardCharsets.UTF_8))); - } catch (IOException ex) { - LOGGER.atError().withThrowable(ex).log("An unexpected error occurred while closing the steam."); - } - } - + logAst(tree); IExpression expr = new BuildCSTVisitor(context).visit(tree); - - if (LOGGER.isDebugEnabled()) { - LOGGER.atDebug().log(String.format("Metapath CST:%n%s", CSTPrinter.toString(expr))); - } + logCst(expr); retval = new MetapathExpression(path, expr, context); } catch (StaticMetapathException ex) { String message = ex.getMessageText(); throw new StaticMetapathException( ex.getCode(), - String.format("Unable to compile path '%s'.%s", path, message == null ? "" : " " + message)); + String.format("Unable to compile path '%s'.%s", path, message == null ? "" : " " + message), + ex); } catch (MetapathException | ParseCancellationException ex) { String msg = String.format("Unable to compile Metapath '%s'", path); LOGGER.atError().withThrowable(ex).log(msg); @@ -224,6 +194,47 @@ public void sync(Parser recognizer) { return retval; } + private static void logCst(@NonNull IExpression expr) { + if (LOGGER.isDebugEnabled()) { + LOGGER.atDebug().log(String.format("Metapath CST:%n%s", CSTPrinter.toString(expr))); + } + } + + private static void logAst(@NonNull ParseTree tree) { + if (LOGGER.isDebugEnabled()) { + try (ByteArrayOutputStream os = new ByteArrayOutputStream()) { + try (PrintStream ps = new PrintStream(os, true, StandardCharsets.UTF_8)) { + ParseTreePrinter printer = new ParseTreePrinter(ps); + printer.print(tree, Metapath10.ruleNames); + ps.flush(); + } + LOGGER.atDebug().log(String.format("Metapath AST:%n%s", os.toString(StandardCharsets.UTF_8))); + } catch (IOException ex) { + LOGGER.atError().withThrowable(ex).log("An unexpected error occurred while closing the steam."); + } + } + } + + @NonNull + private static Metapath10 newParser(@NonNull String path) { + Metapath10Lexer lexer = new Metapath10Lexer(CharStreams.fromString(path)); + lexer.removeErrorListeners(); + lexer.addErrorListener(new FailingErrorListener()); + + CommonTokenStream tokens = new CommonTokenStream(lexer); + Metapath10 parser = new Metapath10(tokens); + parser.removeErrorListeners(); + parser.addErrorListener(new FailingErrorListener()); + parser.setErrorHandler(new DefaultErrorStrategy() { + + @Override + public void sync(Parser recognizer) { + // disable + } + }); + return parser; + } + /** * Construct a new Metapath expression. * 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 d7e4d89a0..c49412a3b 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 @@ -16,6 +16,7 @@ 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.CustomCollectors; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.net.URI; @@ -70,13 +71,15 @@ public final class StaticContext { .collect(Collectors.toUnmodifiableMap( (Function, ? extends String>) Entry::getValue, Map.Entry::getKey, - (v1, v2) -> v2))); + (v1, v2) -> v1))); } @Nullable private final URI baseUri; @NonNull - private final Map knownNamespaces; + private final Map knownPrefixToNamespace; + @NonNull + private final Map knownNamespacesToPrefix; @Nullable private final String defaultModelNamespace; @Nullable @@ -133,7 +136,13 @@ public static StaticContext instance() { private StaticContext(Builder builder) { this.baseUri = builder.baseUri; - this.knownNamespaces = CollectionUtil.unmodifiableMap(ObjectUtils.notNull(Map.copyOf(builder.namespaces))); + this.knownPrefixToNamespace = CollectionUtil.unmodifiableMap(ObjectUtils.notNull(Map.copyOf(builder.namespaces))); + this.knownNamespacesToPrefix = ObjectUtils.notNull(builder.namespaces.entrySet().stream() + .map(entry -> Map.entry(entry.getValue(), entry.getKey())) + .collect(Collectors.toUnmodifiableMap( + Map.Entry::getKey, + Map.Entry::getValue, + CustomCollectors.useFirstMapper()))); this.defaultModelNamespace = builder.defaultModelNamespace; this.defaultFunctionNamespace = builder.defaultFunctionNamespace; this.useWildcardWhenNamespaceNotDefaulted = builder.useWildcardWhenNamespaceNotDefaulted; @@ -171,7 +180,7 @@ public URI getBaseUri() { */ @Nullable private String lookupNamespaceURIForPrefix(@NonNull String prefix) { - String retval = knownNamespaces.get(prefix); + String retval = knownPrefixToNamespace.get(prefix); if (retval == null) { // fall back to well-known namespaces retval = WELL_KNOWN_NAMESPACES.get(prefix); @@ -179,6 +188,16 @@ private String lookupNamespaceURIForPrefix(@NonNull String prefix) { return retval; } + @Nullable + private String lookupPrefixForNamespaceURI(@NonNull String namespace) { + String retval = knownNamespacesToPrefix.get(namespace); + if (retval == null) { + // fall back to well-known namespaces + retval = WELL_KNOWN_URI_TO_PREFIX.get(namespace); + } + return retval; + } + /** * Get the namespace associated with the provided {@code prefix} as a string, if * any is bound. @@ -194,6 +213,21 @@ public String lookupNamespaceForPrefix(@NonNull String prefix) { return result == null ? null : result; } + /** + * Get the prefix associated with the provided {@code namespace} as a string, if + * any is bound. + * + * @param namespace + * the namespace + * @return the prefix string bound to the prefix, or {@code null} if no prefix + * is bound to the namespace + */ + @Nullable + public String lookupPrefixForNamespace(@NonNull String namespace) { + String result = lookupPrefixForNamespaceURI(namespace); + return result == null ? XMLConstants.DEFAULT_NS_PREFIX : result; + } + /** * Get the default namespace for assembly, field, or flag references that have * no namespace prefix. @@ -551,7 +585,7 @@ public IEnhancedQName parseVariableName(@NonNull String name) { public Builder buildFrom() { Builder builder = builder(); builder.baseUri = this.baseUri; - builder.namespaces.putAll(this.knownNamespaces); + builder.namespaces.putAll(this.knownPrefixToNamespace); builder.defaultModelNamespace = this.defaultModelNamespace; builder.defaultFunctionNamespace = this.defaultFunctionNamespace; return builder; diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AbstractExpressionVisitor.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AbstractExpressionVisitor.java index 4169e2cc9..43a21acce 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AbstractExpressionVisitor.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AbstractExpressionVisitor.java @@ -50,6 +50,7 @@ import gov.nist.secauto.metaschema.core.metapath.cst.type.Cast; import gov.nist.secauto.metaschema.core.metapath.cst.type.Castable; import gov.nist.secauto.metaschema.core.metapath.cst.type.InstanceOf; +import gov.nist.secauto.metaschema.core.metapath.cst.type.Treat; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; @@ -407,4 +408,9 @@ public RESULT visitCast(Cast expr, CONTEXT context) { public RESULT visitCastable(Castable expr, CONTEXT context) { return visitChildren(expr, context); } + + @Override + public RESULT visitTreat(Treat expr, CONTEXT context) { + return visitChildren(expr, context); + } } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/BuildCSTVisitor.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/BuildCSTVisitor.java index b251c9b5b..304d61246 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/BuildCSTVisitor.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/BuildCSTVisitor.java @@ -58,6 +58,7 @@ import gov.nist.secauto.metaschema.core.metapath.cst.type.Cast; import gov.nist.secauto.metaschema.core.metapath.cst.type.Castable; import gov.nist.secauto.metaschema.core.metapath.cst.type.InstanceOf; +import gov.nist.secauto.metaschema.core.metapath.cst.type.Treat; import gov.nist.secauto.metaschema.core.metapath.cst.type.TypeTestSupport; import gov.nist.secauto.metaschema.core.metapath.function.ComparisonFunctions; import gov.nist.secauto.metaschema.core.metapath.impl.AbstractKeySpecifier; @@ -1121,7 +1122,13 @@ protected IExpression handleCastableexpr(Metapath10.CastableexprContext ctx) { @Override protected IExpression handleTreatexpr(Metapath10.TreatexprContext ctx) { - throw new UnsupportedOperationException("expression not supported"); + IExpression left = visit(ctx.castableexpr()); + + ISequenceType sequenceType = TypeTestSupport.parseSequenceType( + ObjectUtils.notNull(ctx.sequencetype()), + getContext()); + + return new Treat(left, sequenceType); } // ========================================================================= diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/CSTPrinter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/CSTPrinter.java index 4b15bf084..e4ec93920 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/CSTPrinter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/CSTPrinter.java @@ -50,6 +50,7 @@ import gov.nist.secauto.metaschema.core.metapath.cst.type.Cast; import gov.nist.secauto.metaschema.core.metapath.cst.type.Castable; import gov.nist.secauto.metaschema.core.metapath.cst.type.InstanceOf; +import gov.nist.secauto.metaschema.core.metapath.cst.type.Treat; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; @@ -394,6 +395,11 @@ public String visitCast(Cast expr, State context) { public String visitCastable(Castable expr, State context) { return appendNode(expr, super.visitCastable(expr, context), context); } + + @Override + public String visitTreat(Treat expr, State context) { + return appendNode(expr, super.visitTreat(expr, context), context); + } } static class State { diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/IExpressionVisitor.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/IExpressionVisitor.java index f81c15835..e8bbe6243 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/IExpressionVisitor.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/IExpressionVisitor.java @@ -50,6 +50,7 @@ import gov.nist.secauto.metaschema.core.metapath.cst.type.Cast; import gov.nist.secauto.metaschema.core.metapath.cst.type.Castable; import gov.nist.secauto.metaschema.core.metapath.cst.type.InstanceOf; +import gov.nist.secauto.metaschema.core.metapath.cst.type.Treat; import edu.umd.cs.findbugs.annotations.NonNull; @@ -626,4 +627,15 @@ public interface IExpressionVisitor { * @return the visitation result or {@code null} if no result was produced */ RESULT visitCastable(@NonNull Castable expr, @NonNull CONTEXT context); + + /** + * Visit the CST node. + * + * @param expr + * the CST node to visit + * @param context + * the processing context + * @return the visitation result or {@code null} if no result was produced + */ + RESULT visitTreat(@NonNull Treat expr, @NonNull CONTEXT context); } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/type/Treat.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/type/Treat.java new file mode 100644 index 000000000..171a13fec --- /dev/null +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/type/Treat.java @@ -0,0 +1,79 @@ +/* + * SPDX-FileCopyrightText: none + * SPDX-License-Identifier: CC0-1.0 + */ + +package gov.nist.secauto.metaschema.core.metapath.cst.type; + +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.cst.IExpression; +import gov.nist.secauto.metaschema.core.metapath.cst.IExpressionVisitor; +import gov.nist.secauto.metaschema.core.metapath.item.IItem; +import gov.nist.secauto.metaschema.core.metapath.type.ISequenceType; +import gov.nist.secauto.metaschema.core.util.ObjectUtils; + +import java.util.List; + +import edu.umd.cs.findbugs.annotations.NonNull; + +/** + * A compact syntax tree node that supports the Metapath + * "cast as" operator. + */ +@SuppressWarnings("PMD.ShortClassName") +public class Treat implements IExpression { + @NonNull + private final IExpression value; + @NonNull + private final ISequenceType type; + + /** + * Construct a new cast expression. + * + * @param value + * the expression that will produce the item to cast + * @param type + * the sequence type to treat the expression type as + */ + public Treat( + @NonNull IExpression value, + @NonNull ISequenceType type) { + this.value = value; + this.type = type; + } + + @Override + public Class getBaseResultType() { + return type.getType().getItemClass(); + } + + @Override + public List getChildren() { + return ObjectUtils.notNull(List.of(value)); + } + + @Override + public ISequence accept(DynamicContext dynamicContext, ISequence focus) { + ISequence retval = value.accept(dynamicContext, focus); + if (!type.matches(retval)) { + throw new DynamicMetapathException( + DynamicMetapathException.TREAT_DOES_NOT_MATCH_TYPE, + String.format("The sequence '%s' does not match the sequence type '%s'.", retval, type.toSignature())); + } + return retval; + } + + @Override + public RESULT accept(IExpressionVisitor visitor, CONTEXT context) { + return visitor.visitTreat(this, context); + } + + @Override + public String toASTString() { + return ObjectUtils.notNull(String.format("%s[type=%s]", + getClass().getName(), + type.toSignature())); + } +} 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 311673276..6343516f7 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 @@ -69,6 +69,12 @@ enum FunctionProperty { UNBOUNDED_ARITY; } + @Override + default IItemType getType() { + // TODO: implement this based on the signature + return IItemType.function(); + } + /** * Retrieve the name of the function. * @@ -204,6 +210,7 @@ default IAnyAtomicItem toAtomicItem() { * * @return the signature */ + @Override @NonNull default String toSignature() { return ObjectUtils.notNull(String.format("%s(%s) as %s", 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 6493cecfa..8e095ca0b 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 @@ -72,6 +72,6 @@ private static ISequence executeOneArg(@NonNull IFunction function, */ @NonNull public static IStringItem fnLowerCase(@NonNull IStringItem arg) { - return IStringItem.valueOf(ObjectUtils.notNull(arg.toString().toLowerCase(Locale.ROOT))); + return IStringItem.valueOf(ObjectUtils.notNull(arg.asString().toLowerCase(Locale.ROOT))); } } 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 319fbe21b..af80cb840 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 @@ -102,7 +102,7 @@ private static ISequence executeTwoArg( fnSubstring( sourceString.asString(), startIndex, - sourceString.toString().length() - Math.max(startIndex, 1) + 1))); + sourceString.asString().length() - Math.max(startIndex, 1) + 1))); } @SuppressWarnings({ "unused", "PMD.OnlyOneReturn" }) 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 48b98aaff..e2b14bfe1 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 @@ -72,6 +72,6 @@ private static ISequence executeOneArg(@NonNull IFunction function, */ @NonNull public static IStringItem fnUpperCase(@NonNull IStringItem arg) { - return IStringItem.valueOf(ObjectUtils.notNull(arg.toString().toUpperCase(Locale.ROOT))); + return IStringItem.valueOf(ObjectUtils.notNull(arg.asString().toUpperCase(Locale.ROOT))); } } 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 5c3ee17c4..b221bf593 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 @@ -22,6 +22,7 @@ import java.util.List; import java.util.Objects; import java.util.Set; +import java.util.stream.Collectors; import edu.umd.cs.findbugs.annotations.NonNull; @@ -136,7 +137,14 @@ public boolean equals(Object other) { } @Override - public String asString() { - return ObjectUtils.notNull(toString()); + public String toSignature() { + return ObjectUtils.notNull(stream() + .map(ICollectionValue::toSignature) + .collect(Collectors.joining(",", "[", "]"))); + } + + @Override + public String toString() { + return toSignature(); } } 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 840b8f373..1cd3aa13e 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 @@ -24,6 +24,7 @@ import java.util.List; import java.util.Objects; import java.util.Set; +import java.util.stream.Collectors; import edu.umd.cs.findbugs.annotations.NonNull; @@ -147,7 +148,14 @@ public boolean equals(Object other) { } @Override - public String asString() { - return ObjectUtils.notNull(toString()); + public String toSignature() { + return ObjectUtils.notNull(entrySet().stream() + .map(entry -> entry.getKey().getKey().toSignature() + "=" + entry.getValue().toSignature()) + .collect(Collectors.joining(",", "[", "]"))); + } + + @Override + public String toString() { + return toSignature(); } } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/impl/AbstractSequence.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/impl/AbstractSequence.java index f67d81791..c1cfb384b 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/impl/AbstractSequence.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/impl/AbstractSequence.java @@ -53,14 +53,14 @@ public int hashCode() { } @Override - public String asString() { - return ObjectUtils.notNull(toString()); + public String toSignature() { + return ObjectUtils.notNull(safeStream() + .map(IItem::toSignature) + .collect(Collectors.joining(",", "(", ")"))); } @Override public String toString() { - return safeStream() - .map(Object::toString) - .collect(Collectors.joining(",", "(", ")")); + return toSignature(); } } 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 cda08b168..9fb5e4c2f 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 @@ -31,6 +31,14 @@ static IItemType type() { return IItemType.item(); } + /** + * Get the type information for the item. + * + * @return the item's type information + */ + @NonNull + IItemType getType(); + /** * 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/atomic/AbstractAnyAtomicItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/AbstractAnyAtomicItem.java index c12c9d4d2..56b71a24a 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/AbstractAnyAtomicItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/AbstractAnyAtomicItem.java @@ -36,5 +36,4 @@ protected AbstractAnyAtomicItem(@NonNull TYPE value) { public TYPE getValue() { return value; } - } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/AbstractAtomicItemBase.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/AbstractAtomicItemBase.java index c3c3c6a92..3333dc640 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/AbstractAtomicItemBase.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/AbstractAtomicItemBase.java @@ -6,6 +6,7 @@ package gov.nist.secauto.metaschema.core.metapath.item.atomic; import gov.nist.secauto.metaschema.core.datatype.IDataTypeAdapter; +import gov.nist.secauto.metaschema.core.util.ObjectUtils; import edu.umd.cs.findbugs.annotations.NonNull; @@ -26,8 +27,22 @@ public String asString() { return getJavaTypeAdapter().asString(getValue()); } + @Override + public String toSignature() { + return ObjectUtils.notNull(new StringBuilder() + .append(getType().toSignature()) + .append("(") + .append(getValueSignature()) + .append(")") + .toString()); + } + + @NonNull + protected abstract String getValueSignature(); + + @NonNull @Override public String toString() { - return asString(); + return toSignature(); } } 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 4728d2d0a..219e080a3 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 @@ -6,7 +6,6 @@ package gov.nist.secauto.metaschema.core.metapath.item.atomic; import gov.nist.secauto.metaschema.core.datatype.IDataTypeAdapter; -import gov.nist.secauto.metaschema.core.metapath.IPrintable; import gov.nist.secauto.metaschema.core.metapath.function.InvalidValueForCastFunctionException; import gov.nist.secauto.metaschema.core.metapath.item.IItemVisitor; import gov.nist.secauto.metaschema.core.metapath.item.function.IMapItem; @@ -24,7 +23,7 @@ * values that serve as the fundamental building blocks for complex data * structures in the Metaschema framework. */ -public interface IAnyAtomicItem extends IAtomicValuedItem, IPrintable { +public interface IAnyAtomicItem extends IAtomicValuedItem { /** * Get the type information for this item. * @@ -50,16 +49,21 @@ default IAnyAtomicItem toAtomicItem() { @NonNull Object getValue(); - @Override - @NonNull - String toString(); + /** + * Get a new {@link IStringItem} based on the the textual value of the item's + * "wrapped" value. + * + * @return a new string item + */ + default IStringItem asStringItem() { + return IStringItem.valueOf(asString()); + } /** * Get the item's string value. * * @return the string value value of the item */ - @Override @NonNull String asString(); @@ -76,17 +80,6 @@ default Stream atomize() { @NonNull IMapKey asMapKey(); - /** - * Get a new {@link IStringItem} based on the the textual value of the item's - * "wrapped" value. - * - * @return a new string item - */ - @NonNull - default IStringItem asStringItem() { - return IStringItem.valueOf(asString()); - } - /** * Get the item's type adapter. * 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 b09a56f4a..5ad81642b 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 @@ -30,6 +30,11 @@ static IAtomicOrUnionType type() { return MetaschemaDataTypeProvider.URI.getItemType(); } + @Override + default IAtomicOrUnionType getType() { + return type(); + } + /** * 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 324e2c199..29c050ef1 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 @@ -29,6 +29,11 @@ static IAtomicOrUnionType type() { return MetaschemaDataTypeProvider.BASE64.getItemType(); } + @Override + default IAtomicOrUnionType getType() { + return type(); + } + /** * Construct a new base64 encoded byte sequence item using the provided string * {@code value}. 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 9c8a5bc54..db37c7ab9 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 @@ -38,6 +38,11 @@ static IAtomicOrUnionType type() { return MetaschemaDataTypeProvider.BOOLEAN.getItemType(); } + @Override + default IAtomicOrUnionType getType() { + return type(); + } + /** * 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 34711ad86..8668ec4c1 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 @@ -41,6 +41,11 @@ static IAtomicOrUnionType type() { return MetaschemaDataTypeProvider.DATE.getItemType(); } + @Override + default IAtomicOrUnionType getType() { + return type(); + } + /** * 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 d52a22a5b..307d99c1b 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 @@ -38,6 +38,11 @@ static IAtomicOrUnionType type() { return MetaschemaDataTypeProvider.DATE_TIME.getItemType(); } + @Override + default IAtomicOrUnionType getType() { + return type(); + } + /** * 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/IDateTimeWithTimeZoneItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IDateTimeWithTimeZoneItem.java index 9db1c545c..ddfe164a7 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IDateTimeWithTimeZoneItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IDateTimeWithTimeZoneItem.java @@ -35,6 +35,11 @@ static IAtomicOrUnionType type() { return MetaschemaDataTypeProvider.DATE_TIME_WITH_TZ.getItemType(); } + @Override + default IAtomicOrUnionType getType() { + return type(); + } + /** * 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/IDateWithTimeZoneItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IDateWithTimeZoneItem.java index 3cc5bb1a6..5d12eca2b 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IDateWithTimeZoneItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IDateWithTimeZoneItem.java @@ -32,6 +32,11 @@ static IAtomicOrUnionType type() { return MetaschemaDataTypeProvider.DATE_WITH_TZ.getItemType(); } + @Override + default IAtomicOrUnionType getType() { + return type(); + } + /** * 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/IDayTimeDurationItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IDayTimeDurationItem.java index 5999da1dc..a4791548e 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 @@ -30,6 +30,11 @@ static IAtomicOrUnionType type() { return MetaschemaDataTypeProvider.DAY_TIME_DURATION.getItemType(); } + @Override + default IAtomicOrUnionType getType() { + return type(); + } + /** * 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 296fff957..f1c9c652f 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 @@ -37,6 +37,11 @@ static IAtomicOrUnionType type() { return MetaschemaDataTypeProvider.DECIMAL.getItemType(); } + @Override + default IAtomicOrUnionType getType() { + return type(); + } + /** * 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/IEmailAddressItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IEmailAddressItem.java index 1d7faf125..66f99007f 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 @@ -27,6 +27,11 @@ static IAtomicOrUnionType type() { return MetaschemaDataTypeProvider.EMAIL_ADDRESS.getItemType(); } + @Override + default IAtomicOrUnionType getType() { + return type(); + } + /** * /** Construct a new email address item using the provided string * {@code 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 fce3d2dd8..51b1aa1cf 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 @@ -27,6 +27,11 @@ static IAtomicOrUnionType type() { return MetaschemaDataTypeProvider.HOSTNAME.getItemType(); } + @Override + default IAtomicOrUnionType getType() { + return type(); + } + /** * 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 40a58b1eb..e11550ffa 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 @@ -27,6 +27,11 @@ static IAtomicOrUnionType type() { return TypeConstants.IP_ADDRESS_TYPE; } + @Override + default IAtomicOrUnionType getType() { + return 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 0f84b74b6..251423e29 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 @@ -28,6 +28,11 @@ static IAtomicOrUnionType type() { return MetaschemaDataTypeProvider.IP_V4_ADDRESS.getItemType(); } + @Override + default IAtomicOrUnionType getType() { + return type(); + } + /** * 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 297405555..85f155541 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 @@ -28,6 +28,11 @@ static IAtomicOrUnionType type() { return MetaschemaDataTypeProvider.IP_V6_ADDRESS.getItemType(); } + @Override + default IAtomicOrUnionType getType() { + return type(); + } + /** * 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 1887538a4..bbc958726 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 @@ -46,6 +46,11 @@ static IAtomicOrUnionType type() { return MetaschemaDataTypeProvider.INTEGER.getItemType(); } + @Override + default IAtomicOrUnionType getType() { + return type(); + } + /** * Create an item from an existing integer value. * 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 c68a88888..521fadfc6 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 @@ -27,6 +27,11 @@ static IAtomicOrUnionType type() { return MarkupDataTypeProvider.MARKUP_TYPE; } + @Override + default IAtomicOrUnionType getType() { + return type(); + } + /** * Cast the provided type to this item type. * diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IMarkupLineItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IMarkupLineItem.java index 81cd83c3e..587aac901 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IMarkupLineItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IMarkupLineItem.java @@ -28,6 +28,11 @@ static IAtomicOrUnionType type() { return MarkupDataTypeProvider.MARKUP_LINE.getItemType(); } + @Override + default IAtomicOrUnionType getType() { + return 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/IMarkupMultilineItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IMarkupMultilineItem.java index c8d3b408e..0d39b4b58 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IMarkupMultilineItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IMarkupMultilineItem.java @@ -28,6 +28,11 @@ static IAtomicOrUnionType type() { return MarkupDataTypeProvider.MARKUP_MULTILINE.getItemType(); } + @Override + default IAtomicOrUnionType getType() { + return 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 e50e42a9c..0bf70c40c 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 @@ -28,6 +28,11 @@ static IAtomicOrUnionType type() { return MetaschemaDataTypeProvider.NCNAME.getItemType(); } + @Override + default IAtomicOrUnionType getType() { + return type(); + } + /** * 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 e4e0f99e1..6ca793ad9 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 @@ -41,6 +41,11 @@ static IAtomicOrUnionType type() { return MetaschemaDataTypeProvider.NON_NEGATIVE_INTEGER.getItemType(); } + @Override + default IAtomicOrUnionType getType() { + return type(); + } + /** * Create an item from an existing integer value. * 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 4028d9023..204f427cc 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 @@ -36,6 +36,11 @@ static IAtomicOrUnionType type() { return MetaschemaDataTypeProvider.POSITIVE_INTEGER.getItemType(); } + @Override + default IAtomicOrUnionType getType() { + return type(); + } + /** * Create an item from an existing integer value. * 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 cea636459..e6a67866e 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 @@ -27,6 +27,11 @@ static IAtomicOrUnionType type() { return MetaschemaDataTypeProvider.STRING.getItemType(); } + @Override + default IAtomicOrUnionType getType() { + return type(); + } + /** * 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/ITokenItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/ITokenItem.java index 3a88c6651..79fb74651 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 @@ -27,6 +27,11 @@ static IAtomicOrUnionType type() { return MetaschemaDataTypeProvider.TOKEN.getItemType(); } + @Override + default IAtomicOrUnionType getType() { + return type(); + } + /** * 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 d2306cda3..c0a5a160f 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 @@ -34,6 +34,11 @@ static IAtomicOrUnionType type() { return MetaschemaDataTypeProvider.URI_REFERENCE.getItemType(); } + @Override + default IAtomicOrUnionType getType() { + return type(); + } + /** * 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 8267f657d..5e588e396 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 @@ -29,6 +29,11 @@ static IAtomicOrUnionType type() { return MetaschemaDataTypeProvider.UUID.getItemType(); } + @Override + default IAtomicOrUnionType getType() { + return type(); + } + /** * 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 bfa6d08c8..aa56b3315 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 @@ -31,6 +31,11 @@ static IAtomicOrUnionType type() { return MetaschemaDataTypeProvider.YEAR_MONTH_DURATION.getItemType(); } + @Override + default IAtomicOrUnionType getType() { + return type(); + } + /** * 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/AbstractDecimalItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/AbstractDecimalItem.java index 0d026d9f5..f7823aa2e 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/AbstractDecimalItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/AbstractDecimalItem.java @@ -32,6 +32,11 @@ protected AbstractDecimalItem(@NonNull TYPE value) { super(value); } + @Override + protected String getValueSignature() { + return asString(); + } + @Override public IMapKey asMapKey() { return new MapKey(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/AbstractIPAddressItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/AbstractIPAddressItem.java index 7bca4b6ce..6ae06e009 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/AbstractIPAddressItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/AbstractIPAddressItem.java @@ -50,6 +50,11 @@ public boolean equals(Object obj) { || obj instanceof IIPAddressItem && compareTo((IIPAddressItem) obj) == 0; } + @Override + protected String getValueSignature() { + return "'" + asString() + "'"; + } + @Override public IMapKey asMapKey() { return new MapKey(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/AbstractMarkupItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/AbstractMarkupItem.java index 0487571b1..ecf5daea2 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/AbstractMarkupItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/AbstractMarkupItem.java @@ -43,6 +43,11 @@ public int hashCode() { return asMarkup().hashCode(); } + @Override + protected String getValueSignature() { + return "'" + asString() + "'"; + } + @SuppressWarnings("PMD.OnlyOneReturn") @Override public boolean equals(Object obj) { diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/AbstractStringItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/AbstractStringItem.java index a4e61b21d..19008fe78 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/AbstractStringItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/AbstractStringItem.java @@ -86,4 +86,8 @@ public IStringItem normalizeSpace() { return IStringItem.valueOf(value); } + @Override + protected String getValueSignature() { + return "'" + getValue() + "'"; + } } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/AbstractTemporalItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/AbstractTemporalItem.java index 108d927be..19f9fabf7 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/AbstractTemporalItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/AbstractTemporalItem.java @@ -31,6 +31,11 @@ protected AbstractTemporalItem(@NonNull TYPE value) { super(value); } + @Override + protected String getValueSignature() { + return "'" + asString() + "'"; + } + @Override public IMapKey asMapKey() { return new MapKey(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/AbstractUriItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/AbstractUriItem.java index 3f8c49d2c..eaea731f1 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/AbstractUriItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/AbstractUriItem.java @@ -48,6 +48,11 @@ public int hashCode() { return asUri().hashCode(); } + @Override + protected String getValueSignature() { + return "'" + asString() + "'"; + } + @SuppressWarnings("PMD.OnlyOneReturn") @Override public boolean equals(Object obj) { diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/AnyUriItemImpl.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/AnyUriItemImpl.java index 7df2600cb..5e24ee30e 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/AnyUriItemImpl.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/AnyUriItemImpl.java @@ -32,4 +32,5 @@ public AnyUriItemImpl(@NonNull URI value) { public UriAdapter getJavaTypeAdapter() { return MetaschemaDataTypeProvider.URI; } + } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/Base64BinaryItemImpl.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/Base64BinaryItemImpl.java index 4ec1450b6..8191c74af 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/Base64BinaryItemImpl.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/Base64BinaryItemImpl.java @@ -43,6 +43,11 @@ public ByteBuffer asByteBuffer() { return getValue(); } + @Override + protected String getValueSignature() { + return "'" + asString() + "'"; + } + @Override public IMapKey asMapKey() { return new MapKey(); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/BooleanItemImpl.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/BooleanItemImpl.java index 09522bc68..ec5b184a1 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/BooleanItemImpl.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/BooleanItemImpl.java @@ -67,7 +67,7 @@ public IDataTypeAdapter getJavaTypeAdapter() { } @Override - public String toString() { + protected String getValueSignature() { return asString(); } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/DayTimeDurationItemImpl.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/DayTimeDurationItemImpl.java index 40dfa04af..8d04c7818 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/DayTimeDurationItemImpl.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/DayTimeDurationItemImpl.java @@ -43,11 +43,6 @@ public DayTimeAdapter getJavaTypeAdapter() { return MetaschemaDataTypeProvider.DAY_TIME_DURATION; } - @Override - public IMapKey asMapKey() { - return new MapKey(); - } - @Override public int hashCode() { return asDuration().hashCode(); @@ -60,6 +55,16 @@ public boolean equals(Object obj) { || obj instanceof IDayTimeDurationItem && compareTo((IDayTimeDurationItem) obj) == 0; } + @Override + protected String getValueSignature() { + return "'" + asString() + "'"; + } + + @Override + public IMapKey asMapKey() { + return new MapKey(); + } + private final class MapKey implements IMapKey { @Override public IDayTimeDurationItem getKey() { diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/UuidItemImpl.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/UuidItemImpl.java index 94c914961..e4176f65d 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/UuidItemImpl.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/UuidItemImpl.java @@ -11,7 +11,6 @@ import gov.nist.secauto.metaschema.core.metapath.item.atomic.IStringItem; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IUuidItem; import gov.nist.secauto.metaschema.core.metapath.item.function.IMapKey; -import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.util.UUID; @@ -44,16 +43,6 @@ public UuidAdapter getJavaTypeAdapter() { return MetaschemaDataTypeProvider.UUID; } - @Override - public IMapKey asMapKey() { - return new MapKey(); - } - - @Override - public String asString() { - return ObjectUtils.notNull(asUuid().toString()); - } - @Override public int hashCode() { return asString().hashCode(); @@ -72,6 +61,16 @@ public IStringItem normalizeSpace() { return this; } + @Override + protected String getValueSignature() { + return "'" + asString() + "'"; + } + + @Override + public IMapKey asMapKey() { + return new MapKey(); + } + private final class MapKey implements IMapKey { @Override public IUuidItem getKey() { diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/YearMonthDurationItemImpl.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/YearMonthDurationItemImpl.java index f572a2281..f4e60476c 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/YearMonthDurationItemImpl.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/impl/YearMonthDurationItemImpl.java @@ -44,11 +44,6 @@ public YearMonthAdapter getJavaTypeAdapter() { return MetaschemaDataTypeProvider.YEAR_MONTH_DURATION; } - @Override - public IMapKey asMapKey() { - return new MapKey(); - } - @Override public int hashCode() { return Objects.hash(asPeriod()); @@ -61,6 +56,16 @@ public boolean equals(Object obj) { || obj instanceof IYearMonthDurationItem && compareTo((IYearMonthDurationItem) obj) == 0; } + @Override + protected String getValueSignature() { + return "'" + asString() + "'"; + } + + @Override + public IMapKey asMapKey() { + return new MapKey(); + } + private final class MapKey implements IMapKey { @Override public IYearMonthDurationItem getKey() { 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 06bc63ccf..45f6b9998 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 @@ -6,7 +6,6 @@ package gov.nist.secauto.metaschema.core.metapath.item.function; import gov.nist.secauto.metaschema.core.metapath.ICollectionValue; -import gov.nist.secauto.metaschema.core.metapath.IPrintable; import gov.nist.secauto.metaschema.core.metapath.ISequence; import gov.nist.secauto.metaschema.core.metapath.function.IFunction; import gov.nist.secauto.metaschema.core.metapath.impl.AbstractArrayItem; @@ -42,7 +41,7 @@ * the Metapath item type of array members */ @SuppressWarnings({ "PMD.ShortMethodName", "PMD.ExcessivePublicCount" }) -public interface IArrayItem extends IFunction, IItem, List, IPrintable { +public interface IArrayItem extends IFunction, IItem, List { /** * Get the type information for this item. * @@ -53,6 +52,11 @@ static IItemType type() { return IItemType.array(); } + @Override + default IItemType getType() { + return type(); + } + /** * 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 eeb0be561..c4e13acf8 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 @@ -6,7 +6,6 @@ package gov.nist.secauto.metaschema.core.metapath.item.function; import gov.nist.secauto.metaschema.core.metapath.ICollectionValue; -import gov.nist.secauto.metaschema.core.metapath.IPrintable; import gov.nist.secauto.metaschema.core.metapath.ISequence; import gov.nist.secauto.metaschema.core.metapath.function.IFunction; import gov.nist.secauto.metaschema.core.metapath.impl.AbstractMapItem; @@ -29,7 +28,7 @@ * the value type */ public interface IMapItem - extends IFunction, IItem, Map, IPrintable { + extends IFunction, IItem, Map { /** * Get the type information for this item. * @@ -40,6 +39,11 @@ static IItemType type() { return IItemType.map(); } + @Override + default IItemType getType() { + return type(); + } + /** * Get an empty, immutable map item. * diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/AbstractDefinitionNodeItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/AbstractDefinitionNodeItem.java index 9c68b0e6b..53b445b70 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/AbstractDefinitionNodeItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/AbstractDefinitionNodeItem.java @@ -7,6 +7,7 @@ import edu.umd.cs.findbugs.annotations.NonNull; abstract class AbstractDefinitionNodeItem + extends AbstractNodeItem implements IFeatureOrhpanedDefinitionNodeItem { @NonNull diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/AbstractFlagInstanceNodeItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/AbstractFlagInstanceNodeItem.java index 10444779a..dd7203c60 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/AbstractFlagInstanceNodeItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/AbstractFlagInstanceNodeItem.java @@ -1,7 +1,6 @@ package gov.nist.secauto.metaschema.core.metapath.item.node; -import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyAtomicItem; import gov.nist.secauto.metaschema.core.model.IFlagDefinition; import gov.nist.secauto.metaschema.core.model.IFlagInstance; @@ -19,16 +18,7 @@ public AbstractFlagInstanceNodeItem(@NonNull IFlagInstance instance, @NonNull IM } @Override - public String toString() { - StringBuilder builder = new StringBuilder() - .append(getInstance().getQName().toString()); - IAnyAtomicItem value = toAtomicItem(); - if (value != null) { - builder - .append('(') - .append(value.asString()) - .append(')'); - } - return builder.toString(); + protected String getValueSignature() { + return toAtomicItem().toSignature(); } } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/AbstractGlobalDefinitionNodeItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/AbstractGlobalDefinitionNodeItem.java index a988bfa0e..4734fb40c 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/AbstractGlobalDefinitionNodeItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/AbstractGlobalDefinitionNodeItem.java @@ -47,4 +47,14 @@ public URI getBaseUri() { public StaticContext getStaticContext() { return getMetaschemaNodeItem().getStaticContext(); } + + @Override + public String stringValue() { + return ""; + } + + @Override + protected String getValueSignature() { + return null; + } } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/AbstractInstanceNodeItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/AbstractInstanceNodeItem.java index 2b011903f..db0d6074b 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/AbstractInstanceNodeItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/AbstractInstanceNodeItem.java @@ -11,6 +11,7 @@ abstract class AbstractInstanceNodeItem< D extends IDefinition, I extends INamedInstance, P extends IModelNodeItem> + extends AbstractNodeItem implements IDefinitionNodeItem { @NonNull diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/AbstractNodeItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/AbstractNodeItem.java new file mode 100644 index 000000000..7d6043af6 --- /dev/null +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/AbstractNodeItem.java @@ -0,0 +1,33 @@ + +package gov.nist.secauto.metaschema.core.metapath.item.node; + +import gov.nist.secauto.metaschema.core.util.ObjectUtils; + +import edu.umd.cs.findbugs.annotations.Nullable; + +public abstract class AbstractNodeItem implements INodeItem { + + @Override + public final String toSignature() { + StringBuilder builder = new StringBuilder() + .append(getType().toSignature()) + .append("⪻") + .append(getMetapath()) + .append("⪼"); + String value = getValueSignature(); + if (value != null) { + builder.append("("); + builder.append(value); + builder.append(")"); + } + return ObjectUtils.notNull(builder.toString()); + } + + @Nullable + protected abstract String getValueSignature(); + + @Override + public final String toString() { + return toSignature(); + } +} diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/AbstractOrphanedDefinitionNodeItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/AbstractOrphanedDefinitionNodeItem.java index d21de5b3a..a35267aa1 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/AbstractOrphanedDefinitionNodeItem.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/AbstractOrphanedDefinitionNodeItem.java @@ -50,4 +50,9 @@ public URI getBaseUri() { public StaticContext getStaticContext() { return staticContext; } + + @Override + protected String getValueSignature() { + return null; + } } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/AssemblyGlobalDefinitionNodeItemImpl.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/AssemblyGlobalDefinitionNodeItemImpl.java index 6d8f260f9..44f4aca49 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/AssemblyGlobalDefinitionNodeItemImpl.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/AssemblyGlobalDefinitionNodeItemImpl.java @@ -31,8 +31,4 @@ public ModelContainer getModel() { return model.get(); } - @Override - public String stringValue() { - return ""; - } } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/AssemblyInstanceNoValueNodeItemImpl.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/AssemblyInstanceNoValueNodeItemImpl.java index d2e25c67a..3c4d40fe8 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/AssemblyInstanceNoValueNodeItemImpl.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/AssemblyInstanceNoValueNodeItemImpl.java @@ -41,4 +41,9 @@ public int getPosition() { public String stringValue() { return ""; } + + @Override + protected String getValueSignature() { + return null; + } } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/AssemblyInstanceNodeItemImpl.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/AssemblyInstanceNodeItemImpl.java index d3658af28..6951b8801 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/AssemblyInstanceNodeItemImpl.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/AssemblyInstanceNodeItemImpl.java @@ -60,4 +60,9 @@ public String stringValue() { .map(INodeItem::stringValue) .collect(Collectors.joining())); } + + @Override + protected String getValueSignature() { + return null; + } } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/AssemblyOrphanedDefinitionNodeItemImpl.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/AssemblyOrphanedDefinitionNodeItemImpl.java index d50e87ceb..233a2e887 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/AssemblyOrphanedDefinitionNodeItemImpl.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/AssemblyOrphanedDefinitionNodeItemImpl.java @@ -37,4 +37,5 @@ public ModelContainer getModel() { public String stringValue() { return ""; } + } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/CycledAssemblyInstanceNodeItemImpl.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/CycledAssemblyInstanceNodeItemImpl.java index 7e8272e29..e23c44654 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/CycledAssemblyInstanceNodeItemImpl.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/CycledAssemblyInstanceNodeItemImpl.java @@ -71,4 +71,10 @@ public int getPosition() { public String stringValue() { return ""; } + + @Override + protected String getValueSignature() { + return null; + } + } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/DocumentNodeItemImpl.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/DocumentNodeItemImpl.java index 1c378b727..48806da74 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/DocumentNodeItemImpl.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/DocumentNodeItemImpl.java @@ -12,6 +12,7 @@ import nl.talsmasoftware.lazy4j.Lazy; class DocumentNodeItemImpl + extends AbstractNodeItem implements IDocumentNodeItem, IFeatureModelContainerItem { @NonNull private final IRootAssemblyNodeItem root; @@ -81,4 +82,8 @@ public String stringValue() { return getRootAssemblyNodeItem().stringValue(); } + @Override + protected String getValueSignature() { + return null; + } } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/FieldGlobalDefinitionNodeItemImpl.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/FieldGlobalDefinitionNodeItemImpl.java index 37144e057..36ce7c758 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/FieldGlobalDefinitionNodeItemImpl.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/FieldGlobalDefinitionNodeItemImpl.java @@ -29,9 +29,4 @@ protected FieldGlobalDefinitionNodeItemImpl( public FlagContainer getModel() { return model.get(); } - - @Override - public String stringValue() { - return ""; - } } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/FieldInstanceNoValueNodeItemImpl.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/FieldInstanceNoValueNodeItemImpl.java index 451a329e1..4dc4697b6 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/FieldInstanceNoValueNodeItemImpl.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/FieldInstanceNoValueNodeItemImpl.java @@ -41,4 +41,9 @@ public int getPosition() { public String stringValue() { return ""; } + + @Override + protected String getValueSignature() { + return null; + } } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/FieldInstanceNodeItemImpl.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/FieldInstanceNodeItemImpl.java index 10ccdfb34..202a68592 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/FieldInstanceNodeItemImpl.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/FieldInstanceNodeItemImpl.java @@ -77,4 +77,9 @@ public IAnyAtomicItem toAtomicItem() { public String stringValue() { return toAtomicItem().asString(); } + + @Override + protected String getValueSignature() { + return toAtomicItem().toSignature(); + } } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/FlagGlobalDefinitionNodeItemImpl.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/FlagGlobalDefinitionNodeItemImpl.java index 4957aa755..05276795c 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/FlagGlobalDefinitionNodeItemImpl.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/FlagGlobalDefinitionNodeItemImpl.java @@ -33,9 +33,4 @@ public FlagGlobalDefinitionNodeItemImpl( public IFlagInstance getInstance() { return null; } - - @Override - public String stringValue() { - return ""; - } } 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 7b844950f..0ebdb645d 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 @@ -1,10 +1,12 @@ package gov.nist.secauto.metaschema.core.metapath.item.node; +import gov.nist.secauto.metaschema.core.metapath.StaticContext; import gov.nist.secauto.metaschema.core.metapath.format.IPathFormatter; import gov.nist.secauto.metaschema.core.metapath.function.InvalidTypeFunctionException; 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.IKindTest; import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition; import gov.nist.secauto.metaschema.core.model.IAssemblyInstance; @@ -22,6 +24,15 @@ static IItemType type() { return IItemType.assembly(); } + @Override + default IKindTest getType() { + StaticContext staticContext = getStaticContext(); + return IItemType.assembly( + getQName(), + getDefinition().getDefinitionQName().toEQName(staticContext), + staticContext); + } + @Override default NodeItemKind getNodeItemKind() { return NodeItemKind.ASSEMBLY; 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 55b89fe5e..f80d75c1d 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 @@ -3,6 +3,7 @@ import gov.nist.secauto.metaschema.core.metapath.format.IPathFormatter; import gov.nist.secauto.metaschema.core.metapath.type.IItemType; +import gov.nist.secauto.metaschema.core.metapath.type.IKindTest; import edu.umd.cs.findbugs.annotations.NonNull; @@ -12,6 +13,12 @@ static IItemType type() { return IItemType.document(); } + @Override + default IKindTest getType() { + return IItemType.document( + getRootAssemblyNodeItem().getType()); + } + @Override default NodeItemKind getNodeItemKind() { return NodeItemKind.DOCUMENT; 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 ec9832808..0e5aacfaa 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 @@ -1,8 +1,11 @@ package gov.nist.secauto.metaschema.core.metapath.item.node; +import gov.nist.secauto.metaschema.core.metapath.StaticContext; import gov.nist.secauto.metaschema.core.metapath.format.IPathFormatter; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAtomicValuedItem; +import gov.nist.secauto.metaschema.core.metapath.type.IItemType; +import gov.nist.secauto.metaschema.core.metapath.type.IKindTest; import gov.nist.secauto.metaschema.core.model.IFieldDefinition; import gov.nist.secauto.metaschema.core.model.IFieldInstance; @@ -27,6 +30,15 @@ default IFieldNodeItem getNodeItem() { return this; } + @Override + default IKindTest getType() { + StaticContext staticContext = getStaticContext(); + return IItemType.field( + getQName(), + getDefinition().getDefinitionQName().toEQName(staticContext), + staticContext); + } + @Override @Nullable default URI getBaseUri() { 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 5d9472c15..325147e41 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 @@ -1,8 +1,11 @@ package gov.nist.secauto.metaschema.core.metapath.item.node; +import gov.nist.secauto.metaschema.core.metapath.StaticContext; import gov.nist.secauto.metaschema.core.metapath.format.IPathFormatter; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAtomicValuedItem; +import gov.nist.secauto.metaschema.core.metapath.type.IItemType; +import gov.nist.secauto.metaschema.core.metapath.type.IKindTest; import gov.nist.secauto.metaschema.core.model.IFlagDefinition; import gov.nist.secauto.metaschema.core.model.IFlagInstance; import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; @@ -38,6 +41,15 @@ default IFlagNodeItem getNodeItem() { @Override IFlagInstance getInstance(); + @Override + default IKindTest getType() { + StaticContext staticContext = getStaticContext(); + return IItemType.flag( + getQName(), + getDefinition().getDefinitionQName().toEQName(staticContext), + staticContext); + } + @Override @Nullable default URI getBaseUri() { 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 d692fe7d1..af4e033bf 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 @@ -3,6 +3,7 @@ import gov.nist.secauto.metaschema.core.metapath.StaticContext; import gov.nist.secauto.metaschema.core.metapath.format.IPathFormatter; +import gov.nist.secauto.metaschema.core.metapath.type.IItemType; import gov.nist.secauto.metaschema.core.model.IModule; import java.net.URI; @@ -19,6 +20,15 @@ * be queried. */ public interface IModuleNodeItem extends IDocumentBasedNodeItem, IFeatureNoDataValuedItem { + @NonNull + static IItemType type() { + return IItemType.document(); + } + + @Override + default IItemType getType() { + return type(); + } /** * The Metaschema module this item is based on. diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/ModuleNodeItemImpl.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/ModuleNodeItemImpl.java index 93406a57c..9a877a507 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/ModuleNodeItemImpl.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/ModuleNodeItemImpl.java @@ -11,6 +11,7 @@ import nl.talsmasoftware.lazy4j.Lazy; class ModuleNodeItemImpl + extends AbstractNodeItem implements IModuleNodeItem, IFeatureModelContainerItem { @NonNull private final IModule module; @@ -51,4 +52,9 @@ public IResourceLocation getLocation() { public String stringValue() { return ""; } + + @Override + protected String getValueSignature() { + return null; + } } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/RootAssemblyValuedNodeItemImpl.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/RootAssemblyValuedNodeItemImpl.java index ee31ef71c..f3ad57209 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/RootAssemblyValuedNodeItemImpl.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/RootAssemblyValuedNodeItemImpl.java @@ -10,6 +10,7 @@ import nl.talsmasoftware.lazy4j.Lazy; class RootAssemblyValuedNodeItemImpl + extends AbstractNodeItem implements IRootAssemblyNodeItem, IFeatureModelContainerItem { @NonNull private final IAssemblyDefinition definition; @@ -66,4 +67,9 @@ public String stringValue() { .map(INodeItem::stringValue) .collect(Collectors.joining())); } + + @Override + protected String getValueSignature() { + return null; + } } 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 a5d9478d4..d445fab1e 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 @@ -72,7 +72,7 @@ static IAtomicOrUnionType of( @Override default String toSignature() { - return getQName().toEQName(null); + return getQName().toEQName(); } /** 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 6ba9de111..6798f5552 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 @@ -51,6 +51,7 @@ static IItemType item() { * * @return the function test */ + @NonNull static IItemType function() { return AnyFunctionItemType.ANY_FUNCTION; } 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 index 39ab98b0b..968749035 100644 --- 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 @@ -83,7 +83,9 @@ static Optional of(int index) { @SuppressWarnings("PMD.ShortMethodName") @NonNull static IEnhancedQName of(@NonNull QName qname) { - return of(ObjectUtils.notNull(qname.getNamespaceURI()), ObjectUtils.notNull(qname.getLocalPart())); + return of( + ObjectUtils.notNull(qname.getNamespaceURI()), + ObjectUtils.notNull(qname.getLocalPart())); } /** @@ -129,6 +131,11 @@ static IEnhancedQName of(@NonNull String namespace, @NonNull String localName) { return EQNameFactory.instance().newQName(namespace, localName); } + @NonNull + default String toEQName() { + return toEQName((NamespaceToPrefixResolver) null); + } + /** * Generate a qualified name for this QName, use a prefix provided by the * resolver, or by prepending the namespace if no prefix can be resolved. @@ -144,6 +151,21 @@ default String toEQName(@Nullable NamespaceToPrefixResolver resolver) { if (prefix == null && resolver != null) { prefix = resolver.resolve(namespace); } + return toEQName(namespace, getLocalName(), prefix); + } + + @NonNull + default String toEQName(@NonNull StaticContext staticContext) { + String namespace = getNamespace(); + String prefix = namespace.isEmpty() ? null : staticContext.lookupPrefixForNamespace(namespace); + return toEQName(namespace, getLocalName(), prefix); + } + + @NonNull + private static String toEQName( + @NonNull String namespace, + @NonNull String localName, + @Nullable String prefix) { StringBuilder builder = new StringBuilder(); if (prefix == null) { @@ -156,7 +178,7 @@ default String toEQName(@Nullable NamespaceToPrefixResolver resolver) { builder.append(prefix) .append(':'); } - return ObjectUtils.notNull(builder.append(getLocalName()) + return ObjectUtils.notNull(builder.append(localName) .toString()); } @@ -178,7 +200,9 @@ default QName toQName() { * @return the name */ @NonNull - QName toQName(@NonNull String prefix); + default QName toQName(@NonNull String prefix) { + return new QName(getNamespace(), getLocalName(), prefix); + } /** * Provides a callback for resolving namespace prefixes. 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 index e12114070..8e2823743 100644 --- 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 @@ -139,11 +139,6 @@ 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); @@ -164,7 +159,7 @@ public boolean equals(Object obj) { @Override public String toString() { - return toEQName(null); + return toEQName(); } } } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/annotations/NullJavaTypeAdapter.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/annotations/NullJavaTypeAdapter.java index f30723682..92175540b 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/annotations/NullJavaTypeAdapter.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/model/annotations/NullJavaTypeAdapter.java @@ -11,6 +11,7 @@ import gov.nist.secauto.metaschema.core.datatype.IDataTypeAdapter; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyAtomicItem; import gov.nist.secauto.metaschema.core.metapath.item.function.IMapKey; +import gov.nist.secauto.metaschema.core.metapath.type.IItemType; import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; import gov.nist.secauto.metaschema.databind.model.annotations.NullJavaTypeAdapter.VoidItem; @@ -104,5 +105,15 @@ public int compareTo(IAnyAtomicItem item) { public IMapKey asMapKey() { throw new UnsupportedOperationException(NOT_VALID); } + + @Override + public IItemType getType() { + throw new UnsupportedOperationException(NOT_VALID); + } + + @Override + public String toSignature() { + throw new UnsupportedOperationException(NOT_VALID); + } } } diff --git a/pom.xml b/pom.xml index ac9b6b90b..3b3b28b66 100644 --- a/pom.xml +++ b/pom.xml @@ -688,6 +688,7 @@ false + true @@ -734,7 +735,7 @@ maven-jxr-plugin - default + default false