diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnDocumentUri.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnDocumentUri.java index ea447fcaf..c590b42a9 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnDocumentUri.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnDocumentUri.java @@ -17,7 +17,6 @@ import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem; import gov.nist.secauto.metaschema.core.util.ObjectUtils; -import java.net.URI; import java.util.List; import edu.umd.cs.findbugs.annotations.NonNull; @@ -106,7 +105,6 @@ private static ISequence executeOneArg(@NonNull IFunction function, */ @Nullable public static IAnyUriItem fnDocumentUri(@NonNull IDocumentNodeItem document) { - URI documentUri = document.getDocumentUri(); - return documentUri == null ? null : IAnyUriItem.valueOf(documentUri); + return IAnyUriItem.valueOf(document.getDocumentUri()); } } 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 f11aa38b3..e62aa4756 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 @@ -6,6 +6,8 @@ import gov.nist.secauto.metaschema.core.metapath.type.IItemType; import gov.nist.secauto.metaschema.core.metapath.type.IKindTest; +import java.net.URI; + import edu.umd.cs.findbugs.annotations.NonNull; /** @@ -44,6 +46,10 @@ default IDocumentNodeItem getNodeItem() { return this; } + @Override + @NonNull + URI getDocumentUri(); + /** * Get the node item for the document root element. * 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 9de685f98..503494598 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 @@ -64,7 +64,7 @@ default URI getBaseUri() { @Override default @NonNull - String format(@NonNull IPathFormatter formatter) { + String format(@NonNull IPathFormatter formatter) { return formatter.formatField(this); } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/IFlagNodeItem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/IFlagNodeItem.java index 1003db254..fbf8fce91 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 @@ -100,7 +100,7 @@ default IFlagNodeItem getFlagByName(@NonNull IEnhancedQName name) { @SuppressWarnings("null") @Override default @NonNull - Stream flags() { + Stream flags() { // a flag does not have flags return Stream.empty(); } @@ -112,7 +112,7 @@ Stream flags() { @SuppressWarnings("null") @Override default @NonNull - Collection>> getModelItems() { + Collection>> getModelItems() { // a flag does not have model items return Collections.emptyList(); } @@ -141,7 +141,7 @@ Stream flags() { @Override default @NonNull - String format(@NonNull IPathFormatter formatter) { + String format(@NonNull IPathFormatter formatter) { return formatter.formatFlag(this); } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/DefaultConstraintValidator.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/DefaultConstraintValidator.java index df08aab3a..63a22be4e 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/DefaultConstraintValidator.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/DefaultConstraintValidator.java @@ -386,7 +386,7 @@ private static String toErrorMessage( @NonNull Throwable ex) { StringBuilder builder = new StringBuilder(128); builder.append("A ") - .append(constraint.getClass().getName()) + .append(constraint.getType().getName()) .append(" constraint"); String id = constraint.getId(); @@ -402,7 +402,7 @@ private static String toErrorMessage( builder.append(", matching the item at path '") .append(item.getMetapath()) - .append("', resulted in an unexpected error. The error was: ") + .append("', resulted in an unexpected error. ") .append(ex.getLocalizedMessage()); return ObjectUtils.notNull(builder.toString()); } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IAllowedValuesConstraint.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IAllowedValuesConstraint.java index 5bc44b3c9..a819fa461 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IAllowedValuesConstraint.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IAllowedValuesConstraint.java @@ -47,6 +47,11 @@ enum Extensible { NONE; } + @Override + default Type getType() { + return Type.ALLOWED_VALUES; + } + /** * Get the collection allowed values associated with this constraint. * diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/ICardinalityConstraint.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/ICardinalityConstraint.java index 6c0d0ae29..bb267ccfc 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/ICardinalityConstraint.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/ICardinalityConstraint.java @@ -17,6 +17,11 @@ * elements with a minimum and/or maximum occurrence. */ public interface ICardinalityConstraint extends IConfigurableMessageConstraint { + @Override + default Type getType() { + return Type.CARDINALITY; + } + /** * Retrieve the required minimum occurrence of the target instance. If * specified, this value must be less than or equal to the value of diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IConstraint.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IConstraint.java index 7bf0abcbc..b70d13e57 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IConstraint.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IConstraint.java @@ -23,6 +23,31 @@ * flag. Provides a common interface for all constraint definitions. */ public interface IConstraint extends IAttributable, IDescribable { + /** + * The type of constraint. + */ + enum Type { + ALLOWED_VALUES("allowed-values"), + CARDINALITY("cardinality"), + EXPECT("expect"), + INDEX("index"), + UNIQUE("unique"), + INDEX_HAS_KEY("index-has-key"), + MATCHES("matches"); + + @NonNull + private final String name; + + Type(@NonNull String name) { + this.name = name; + } + + @NonNull + public String getName() { + return name; + } + } + /** * The degree to which a constraint violation is significant. *

@@ -91,6 +116,14 @@ static String getConstraintIdentity(@NonNull IConstraint constraint) { return ObjectUtils.notNull(identity); } + /** + * Get the constraint type. + * + * @return the constraint type + */ + @NonNull + Type getType(); + /** * Retrieve the unique identifier for the constraint. * diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IExpectConstraint.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IExpectConstraint.java index d1bf60ffb..16b9e563e 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IExpectConstraint.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IExpectConstraint.java @@ -17,6 +17,11 @@ * A custom message can be used to indicate what a test failure signifies. */ public interface IExpectConstraint extends IConfigurableMessageConstraint { + @Override + default Type getType() { + return Type.EXPECT; + } + /** * Get the test to use to validate selected nodes. * diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IIndexConstraint.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IIndexConstraint.java index cd69e81cf..fca95732f 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IIndexConstraint.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IIndexConstraint.java @@ -18,6 +18,11 @@ * data objects using the {@link IIndexHasKeyConstraint}. */ public interface IIndexConstraint extends IKeyConstraint { + @Override + default Type getType() { + return Type.INDEX; + } + /** * Get the name of the index, which is used to refer to the index by an * {@link IIndexHasKeyConstraint}. diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IIndexHasKeyConstraint.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IIndexHasKeyConstraint.java index 4deb59c49..639ddb5a3 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IIndexHasKeyConstraint.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IIndexHasKeyConstraint.java @@ -16,6 +16,11 @@ * {@link IIndexConstraint}. */ public interface IIndexHasKeyConstraint extends IKeyConstraint { + @Override + default Type getType() { + return Type.INDEX_HAS_KEY; + } + /** * The name of the index used to verify cross references. * diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IMatchesConstraint.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IMatchesConstraint.java index 6442de519..142a7f3d2 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IMatchesConstraint.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IMatchesConstraint.java @@ -19,6 +19,11 @@ * and/or conform to an identified data type. */ public interface IMatchesConstraint extends IConfigurableMessageConstraint { + @Override + default Type getType() { + return Type.MATCHES; + } + /** * Get the expected pattern. * diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IUniqueConstraint.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IUniqueConstraint.java index ad22d28a0..ef1b12e8b 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IUniqueConstraint.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/IUniqueConstraint.java @@ -18,6 +18,10 @@ * generated, but this constraint type does not persist a named index. */ public interface IUniqueConstraint extends IKeyConstraint { + @Override + default Type getType() { + return Type.UNIQUE; + } @Override default R accept(IConstraintVisitor visitor, T state) { diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/util/UriUtils.java b/core/src/main/java/gov/nist/secauto/metaschema/core/util/UriUtils.java index 861ce637f..72ecb371d 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/util/UriUtils.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/util/UriUtils.java @@ -72,10 +72,11 @@ public static URI toUri(@NonNull String location, @NonNull URI baseUri) throws U * @throws URISyntaxException * if any of the URIs are malformed */ + @NonNull public static URI relativize(URI base, URI other, boolean prepend) throws URISyntaxException { URI normBase = Objects.requireNonNull(base).normalize(); URI normOther = Objects.requireNonNull(other).normalize(); - URI retval = normBase.relativize(normOther); + URI retval = ObjectUtils.notNull(normBase.relativize(normOther)); if (prepend && !normBase.isOpaque() && !retval.isOpaque() && hasSameSchemeAndAuthority(normBase, retval)) { // the URIs are not opaque and they share the same scheme and authority @@ -85,7 +86,6 @@ public static URI relativize(URI base, URI other, boolean prepend) throws URISyn retval = new URI(null, null, newPath, normOther.getQuery(), normOther.getFragment()); } - return retval; }