diff --git a/cli-processor/src/main/resources/log4j2.xml b/cli-processor/src/main/resources/log4j2.xml index b174b3f80..758bf2a4c 100644 --- a/cli-processor/src/main/resources/log4j2.xml +++ b/cli-processor/src/main/resources/log4j2.xml @@ -2,11 +2,11 @@ - + - + diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/DataTypeService.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/DataTypeService.java index 305b0cdaf..0c705ad0f 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/DataTypeService.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/DataTypeService.java @@ -39,6 +39,8 @@ import java.util.function.Function; import java.util.stream.Collectors; +import javax.xml.namespace.QName; + import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; import nl.talsmasoftware.lazy4j.Lazy; @@ -51,8 +53,9 @@ public final class DataTypeService { private static final Logger LOGGER = LogManager.getLogger(DataTypeService.class); private static final Lazy INSTANCE = Lazy.lazy(() -> new DataTypeService()); - private final Map> libraryByName; - private final Map>, IDataTypeAdapter> libraryByClass; + private final Map> typeByName; + private final Map> typeByQName; + private final Map>, IDataTypeAdapter> typeByClass; /** * Get the singleton service instance, which will be lazy constructed on first @@ -74,12 +77,29 @@ private DataTypeService() { .flatMap(provider -> provider.getJavaTypeAdapters().stream()) .collect(Collectors.toList()); - Map> libraryByName = dataTypes.stream() + Map> typeByName = dataTypes.stream() + .flatMap(dataType -> dataType.getNames().stream() + .map(qname -> Map.entry(qname.getLocalPart(), dataType))) + .collect(CustomCollectors.toMap( + Map.Entry::getKey, + Map.Entry::getValue, + (key, v1, v2) -> { + if (LOGGER.isWarnEnabled()) { + LOGGER.warn("Data types '{}' and '{}' have duplicate name '{}'. Using the first.", + v1.getClass().getName(), + v2.getClass().getName(), + key); + } + return v1; + }, + ConcurrentHashMap::new)); + + Map> typeByQName = dataTypes.stream() .flatMap(dataType -> dataType.getNames().stream() - .map(name -> Map.entry(name, dataType))) + .map(qname -> Map.entry(qname, dataType))) .collect(CustomCollectors.toMap( Map.Entry::getKey, - (entry) -> entry.getValue(), + Map.Entry::getValue, (key, v1, v2) -> { if (LOGGER.isWarnEnabled()) { LOGGER.warn("Data types '{}' and '{}' have duplicate name '{}'. Using the first.", @@ -92,7 +112,7 @@ private DataTypeService() { ConcurrentHashMap::new)); @SuppressWarnings({ "unchecked", "null" }) Map>, - IDataTypeAdapter> libraryByClass = dataTypes.stream() + IDataTypeAdapter> typeByClass = dataTypes.stream() .collect(CustomCollectors.toMap( dataType -> (Class>) dataType.getClass(), Function.identity(), @@ -104,21 +124,35 @@ private DataTypeService() { return v1; }, ConcurrentHashMap::new)); - this.libraryByName = libraryByName; - this.libraryByClass = libraryByClass; + this.typeByName = typeByName; + this.typeByQName = typeByQName; + this.typeByClass = typeByClass; + } + + /** + * Lookup a specific {@link IDataTypeAdapter} instance by its name. + * + * @param qname + * the qualified name of data type adapter to get the instance for + * @return the instance or {@code null} if the instance is unknown to the type + * system + */ + @Nullable + public IDataTypeAdapter getJavaTypeAdapterByQName(@NonNull QName qname) { + return typeByQName.get(qname); } /** * Lookup a specific {@link IDataTypeAdapter} instance by its name. * * @param name - * the data type name of data type adapter to get the instance for + * the name of data type adapter to get the instance for * @return the instance or {@code null} if the instance is unknown to the type * system */ @Nullable public IDataTypeAdapter getJavaTypeAdapterByName(@NonNull String name) { - return libraryByName.get(name); + return typeByName.get(name); } /** @@ -134,6 +168,6 @@ public IDataTypeAdapter getJavaTypeAdapterByName(@NonNull String name) { @SuppressWarnings("unchecked") @Nullable public > TYPE getJavaTypeAdapterByClass(@NonNull Class clazz) { - return (TYPE) libraryByClass.get(clazz); + return (TYPE) typeByClass.get(clazz); } } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/IDataTypeAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/IDataTypeAdapter.java index 3c967782f..18c2f14b8 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/IDataTypeAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/IDataTypeAdapter.java @@ -63,14 +63,7 @@ public interface IDataTypeAdapter { * @return the name */ @NonNull - List getNames(); - - /** - * The JSON primative type of the data type. - * - * @return the JSON data type - */ - JsonFormatTypes getJsonRawType(); + List getNames(); /** * Get the most preferred name for this data type. @@ -78,10 +71,17 @@ public interface IDataTypeAdapter { * @return the name */ @NonNull - default String getPreferredName() { + default QName getPreferredName() { return ObjectUtils.notNull(getNames().iterator().next()); } + /** + * The JSON primative type of the data type. + * + * @return the JSON data type + */ + JsonFormatTypes getJsonRawType(); + /** * Get the Java class supported by this adapter. * diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/Base64Adapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/Base64Adapter.java index 4f4847cec..abd644013 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/Base64Adapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/Base64Adapter.java @@ -29,6 +29,7 @@ import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes; import gov.nist.secauto.metaschema.core.datatype.AbstractDataTypeAdapter; +import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IBase64BinaryItem; import gov.nist.secauto.metaschema.core.util.ObjectUtils; @@ -36,23 +37,25 @@ import java.util.Base64; import java.util.List; +import javax.xml.namespace.QName; + import edu.umd.cs.findbugs.annotations.NonNull; public class Base64Adapter extends AbstractDataTypeAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( + private static final List NAMES = ObjectUtils.notNull( List.of( - "base64", + new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "base64"), // for backwards compatibility with original type name - "base64Binary")); + new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "base64Binary"))); Base64Adapter() { super(ByteBuffer.class); } @Override - public List getNames() { + public List getNames() { return NAMES; } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/BooleanAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/BooleanAdapter.java index 859185724..9fa446493 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/BooleanAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/BooleanAdapter.java @@ -31,6 +31,7 @@ import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes; import gov.nist.secauto.metaschema.core.datatype.AbstractDataTypeAdapter; +import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.function.InvalidValueForCastFunctionException; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyAtomicItem; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IBooleanItem; @@ -41,20 +42,22 @@ import java.io.IOException; import java.util.List; +import javax.xml.namespace.QName; + import edu.umd.cs.findbugs.annotations.NonNull; public class BooleanAdapter extends AbstractDataTypeAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( - List.of("boolean")); + private static final List NAMES = ObjectUtils.notNull( + List.of(new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "boolean"))); BooleanAdapter() { super(Boolean.class); } @Override - public List getNames() { + public List getNames() { return NAMES; } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DateAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DateAdapter.java index 874ae7003..c3beb3d3e 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DateAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DateAdapter.java @@ -30,6 +30,7 @@ import gov.nist.secauto.metaschema.core.datatype.AbstractCustomJavaDataTypeAdapter; import gov.nist.secauto.metaschema.core.datatype.object.Date; +import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.function.InvalidValueForCastFunctionException; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyAtomicItem; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IDateItem; @@ -48,13 +49,15 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import javax.xml.namespace.QName; + import edu.umd.cs.findbugs.annotations.NonNull; public class DateAdapter extends AbstractCustomJavaDataTypeAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( - List.of("date")); + private static final List NAMES = ObjectUtils.notNull( + List.of(new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "date"))); private static final Pattern DATE_TIMEZONE = Pattern.compile("^(" + "^(?:(?:2000|2400|2800|(?:19|2[0-9](?:0[48]|[2468][048]|[13579][26])))-02-29)" + "|(?:(?:(?:19|2[0-9])[0-9]{2})-02-(?:0[1-9]|1[0-9]|2[0-8]))" @@ -68,7 +71,7 @@ public class DateAdapter } @Override - public List getNames() { + public List getNames() { return NAMES; } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DateTimeAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DateTimeAdapter.java index d53061aed..0573b3b3f 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DateTimeAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DateTimeAdapter.java @@ -30,6 +30,7 @@ import gov.nist.secauto.metaschema.core.datatype.AbstractCustomJavaDataTypeAdapter; import gov.nist.secauto.metaschema.core.datatype.object.DateTime; +import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.function.InvalidValueForCastFunctionException; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyAtomicItem; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IDateItem; @@ -44,23 +45,25 @@ import java.time.format.DateTimeParseException; import java.util.List; +import javax.xml.namespace.QName; + import edu.umd.cs.findbugs.annotations.NonNull; public class DateTimeAdapter extends AbstractCustomJavaDataTypeAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( + private static final List NAMES = ObjectUtils.notNull( List.of( - "date-time", + new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "date-time"), // for backwards compatibility with original type name - "dateTime")); + new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "dateTime"))); DateTimeAdapter() { super(DateTime.class); } @Override - public List getNames() { + public List getNames() { return NAMES; } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DateTimeWithTZAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DateTimeWithTZAdapter.java index bcac872a4..1bfbf278e 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DateTimeWithTZAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DateTimeWithTZAdapter.java @@ -29,6 +29,7 @@ import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes; import gov.nist.secauto.metaschema.core.datatype.AbstractDataTypeAdapter; +import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IDateTimeItem; import gov.nist.secauto.metaschema.core.util.ObjectUtils; @@ -36,23 +37,25 @@ import java.time.format.DateTimeParseException; import java.util.List; +import javax.xml.namespace.QName; + import edu.umd.cs.findbugs.annotations.NonNull; public class DateTimeWithTZAdapter extends AbstractDataTypeAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( + private static final List NAMES = ObjectUtils.notNull( List.of( - "date-time-with-timezone", + new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "date-time-with-timezone"), // for backwards compatibility with original type name - "dateTime-with-timezone")); + new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "dateTime-with-timezone"))); DateTimeWithTZAdapter() { super(ZonedDateTime.class); } @Override - public List getNames() { + public List getNames() { return NAMES; } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DateWithTZAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DateWithTZAdapter.java index 7b6c04fde..3d0040d7d 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DateWithTZAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DateWithTZAdapter.java @@ -29,6 +29,7 @@ import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes; import gov.nist.secauto.metaschema.core.datatype.AbstractDataTypeAdapter; +import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IDateItem; import gov.nist.secauto.metaschema.core.util.ObjectUtils; @@ -38,14 +39,16 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import javax.xml.namespace.QName; + import edu.umd.cs.findbugs.annotations.NonNull; public class DateWithTZAdapter extends AbstractDataTypeAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( + private static final List NAMES = ObjectUtils.notNull( List.of( - "date-with-timezone")); + new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "date-with-timezone"))); private static final Pattern DATE_TIMEZONE = Pattern.compile("^(" + "^(?:(?:2000|2400|2800|(?:19|2[0-9](?:0[48]|[2468][048]|[13579][26])))-02-29)" + "|(?:(?:(?:19|2[0-9])[0-9]{2})-02-(?:0[1-9]|1[0-9]|2[0-8]))" @@ -59,7 +62,7 @@ public class DateWithTZAdapter } @Override - public List getNames() { + public List getNames() { return NAMES; } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DayTimeAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DayTimeAdapter.java index 9e2e2c795..b058f2eac 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DayTimeAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DayTimeAdapter.java @@ -29,6 +29,7 @@ import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes; import gov.nist.secauto.metaschema.core.datatype.AbstractDataTypeAdapter; +import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IDayTimeDurationItem; import gov.nist.secauto.metaschema.core.util.ObjectUtils; @@ -36,20 +37,22 @@ import java.time.format.DateTimeParseException; import java.util.List; +import javax.xml.namespace.QName; + import edu.umd.cs.findbugs.annotations.NonNull; public class DayTimeAdapter extends AbstractDataTypeAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( - List.of("day-time-duration")); + private static final List NAMES = ObjectUtils.notNull( + List.of(new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "day-time-duration"))); DayTimeAdapter() { super(Duration.class); } @Override - public List getNames() { + public List getNames() { return NAMES; } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DecimalAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DecimalAdapter.java index a6ce75d4c..49fd4ee29 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DecimalAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DecimalAdapter.java @@ -30,6 +30,7 @@ import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes; import gov.nist.secauto.metaschema.core.datatype.AbstractDataTypeAdapter; +import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyAtomicItem; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IBooleanItem; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IDecimalItem; @@ -41,6 +42,8 @@ import java.math.MathContext; import java.util.List; +import javax.xml.namespace.QName; + import edu.umd.cs.findbugs.annotations.NonNull; public class DecimalAdapter @@ -51,15 +54,15 @@ public class DecimalAdapter @NonNull private static final BigDecimal DECIMAL_BOOLEAN_FALSE = new BigDecimal("0.0"); @NonNull - private static final List NAMES = ObjectUtils.notNull( - List.of("decimal")); + private static final List NAMES = ObjectUtils.notNull( + List.of(new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "decimal"))); DecimalAdapter() { super(BigDecimal.class); } @Override - public List getNames() { + public List getNames() { return NAMES; } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/EmailAddressAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/EmailAddressAdapter.java index 8a7418177..9818890a2 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/EmailAddressAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/EmailAddressAdapter.java @@ -26,28 +26,31 @@ package gov.nist.secauto.metaschema.core.datatype.adapter; +import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IEmailAddressItem; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.util.List; +import javax.xml.namespace.QName; + import edu.umd.cs.findbugs.annotations.NonNull; public class EmailAddressAdapter extends AbstractStringAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( + private static final List NAMES = ObjectUtils.notNull( List.of( - "email-address", + new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "email-address"), // for backwards compatibility with original type name - "email")); + new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "email"))); EmailAddressAdapter() { // avoid general construction } @Override - public List getNames() { + public List getNames() { return NAMES; } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/HostnameAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/HostnameAdapter.java index d01b372d0..6b6a8455c 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/HostnameAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/HostnameAdapter.java @@ -26,25 +26,28 @@ package gov.nist.secauto.metaschema.core.datatype.adapter; +import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IHostnameItem; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.util.List; +import javax.xml.namespace.QName; + import edu.umd.cs.findbugs.annotations.NonNull; public class HostnameAdapter extends AbstractStringAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( - List.of("hostname")); + private static final List NAMES = ObjectUtils.notNull( + List.of(new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "hostname"))); HostnameAdapter() { // avoid general construction } @Override - public List getNames() { + public List getNames() { return NAMES; } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/IPv4AddressAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/IPv4AddressAdapter.java index f4e4f43b5..58ad33492 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/IPv4AddressAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/IPv4AddressAdapter.java @@ -29,11 +29,14 @@ import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes; import gov.nist.secauto.metaschema.core.datatype.AbstractDataTypeAdapter; +import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IIPv4AddressItem; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.util.List; +import javax.xml.namespace.QName; + import edu.umd.cs.findbugs.annotations.NonNull; import inet.ipaddr.AddressStringException; import inet.ipaddr.IPAddressString; @@ -44,14 +47,22 @@ public class IPv4AddressAdapter extends AbstractDataTypeAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( - List.of("ip-v4-address")); + private static final List NAMES = ObjectUtils.notNull( + List.of(new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "ip-v4-address"))); private static final IPAddressStringParameters IP_V_4; static { - IP_V_4 = new IPAddressStringParameters.Builder().allowIPv6(false).allowEmpty(false).allowSingleSegment(false) - .allowWildcardedSeparator(false).getIPv4AddressParametersBuilder().allowBinary(false).allowLeadingZeros(false) - .allowPrefixesBeyondAddressSize(false).getParentBuilder().toParams(); + IP_V_4 = new IPAddressStringParameters.Builder() + .allowIPv6(false) + .allowEmpty(false) + .allowSingleSegment(false) + .allowWildcardedSeparator(false) + .getIPv4AddressParametersBuilder() + .allowBinary(false) + .allowLeadingZeros(false) + .allowPrefixesBeyondAddressSize(false) + .getParentBuilder() + .toParams(); } IPv4AddressAdapter() { @@ -59,7 +70,7 @@ public class IPv4AddressAdapter } @Override - public List getNames() { + public List getNames() { return NAMES; } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/IPv6AddressAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/IPv6AddressAdapter.java index 6d5aa7fae..a09300569 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/IPv6AddressAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/IPv6AddressAdapter.java @@ -29,11 +29,14 @@ import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes; import gov.nist.secauto.metaschema.core.datatype.AbstractDataTypeAdapter; +import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IIPv6AddressItem; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.util.List; +import javax.xml.namespace.QName; + import edu.umd.cs.findbugs.annotations.NonNull; import inet.ipaddr.AddressStringException; import inet.ipaddr.IPAddressString; @@ -44,8 +47,8 @@ public class IPv6AddressAdapter extends AbstractDataTypeAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( - List.of("ip-v6-address")); + private static final List NAMES = ObjectUtils.notNull( + List.of(new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "ip-v6-address"))); private static final IPAddressStringParameters IP_V_6; static { @@ -59,7 +62,7 @@ public class IPv6AddressAdapter } @Override - public List getNames() { + public List getNames() { return NAMES; } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/IntegerAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/IntegerAdapter.java index 31ff2292c..02973460d 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/IntegerAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/IntegerAdapter.java @@ -26,6 +26,7 @@ package gov.nist.secauto.metaschema.core.datatype.adapter; +import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyAtomicItem; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IBooleanItem; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IIntegerItem; @@ -35,20 +36,22 @@ import java.math.BigInteger; import java.util.List; +import javax.xml.namespace.QName; + import edu.umd.cs.findbugs.annotations.NonNull; public class IntegerAdapter extends AbstractIntegerAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( - List.of("integer")); + private static final List NAMES = ObjectUtils.notNull( + List.of(new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "integer"))); IntegerAdapter() { // avoid general construction } @Override - public List getNames() { + public List getNames() { return NAMES; } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/NcNameAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/NcNameAdapter.java index 033a42bee..4a6c99d26 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/NcNameAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/NcNameAdapter.java @@ -26,28 +26,31 @@ package gov.nist.secauto.metaschema.core.datatype.adapter; +import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.INcNameItem; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.util.List; +import javax.xml.namespace.QName; + import edu.umd.cs.findbugs.annotations.NonNull; @Deprecated(forRemoval = true, since = "0.7.0") public class NcNameAdapter extends AbstractStringAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( - List.of("ncname", + private static final List NAMES = ObjectUtils.notNull( + List.of(new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "ncname"), // for backwards compatibility with original type name - "NCName")); + new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "NCName"))); NcNameAdapter() { // avoid general construction } @Override - public List getNames() { + public List getNames() { return NAMES; } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/NonNegativeIntegerAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/NonNegativeIntegerAdapter.java index 06e4c6ddb..23af3d9e3 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/NonNegativeIntegerAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/NonNegativeIntegerAdapter.java @@ -26,29 +26,32 @@ package gov.nist.secauto.metaschema.core.datatype.adapter; +import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.INonNegativeIntegerItem; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.math.BigInteger; import java.util.List; +import javax.xml.namespace.QName; + import edu.umd.cs.findbugs.annotations.NonNull; public class NonNegativeIntegerAdapter extends AbstractIntegerAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( + private static final List NAMES = ObjectUtils.notNull( List.of( - "non-negative-integer", + new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "non-negative-integer"), // for backwards compatibility with original type name - "nonNegativeInteger")); + new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "nonNegativeInteger"))); NonNegativeIntegerAdapter() { // avoid general construction } @Override - public List getNames() { + public List getNames() { return NAMES; } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/PositiveIntegerAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/PositiveIntegerAdapter.java index 2cf76f2b0..3eb2f949d 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/PositiveIntegerAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/PositiveIntegerAdapter.java @@ -26,29 +26,32 @@ package gov.nist.secauto.metaschema.core.datatype.adapter; +import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IPositiveIntegerItem; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.math.BigInteger; import java.util.List; +import javax.xml.namespace.QName; + import edu.umd.cs.findbugs.annotations.NonNull; public class PositiveIntegerAdapter extends AbstractIntegerAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( + private static final List NAMES = ObjectUtils.notNull( List.of( - "positive-integer", + new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "positive-integer"), // for backwards compatibility with original type name - "positiveInteger")); + new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "positiveInteger"))); PositiveIntegerAdapter() { // avoid general construction } @Override - public List getNames() { + public List getNames() { return NAMES; } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/StringAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/StringAdapter.java index bf674c9e2..e2810e229 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/StringAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/StringAdapter.java @@ -26,25 +26,28 @@ package gov.nist.secauto.metaschema.core.datatype.adapter; +import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IStringItem; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.util.List; +import javax.xml.namespace.QName; + import edu.umd.cs.findbugs.annotations.NonNull; public class StringAdapter extends AbstractStringAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( - List.of("string")); + private static final List NAMES = ObjectUtils.notNull( + List.of(new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "string"))); StringAdapter() { // avoid general construction } @Override - public List getNames() { + public List getNames() { return NAMES; } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/TokenAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/TokenAdapter.java index 327edfe7a..5136d297c 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/TokenAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/TokenAdapter.java @@ -26,25 +26,28 @@ package gov.nist.secauto.metaschema.core.datatype.adapter; +import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.ITokenItem; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.util.List; +import javax.xml.namespace.QName; + import edu.umd.cs.findbugs.annotations.NonNull; public class TokenAdapter extends AbstractStringAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( - List.of("token")); + private static final List NAMES = ObjectUtils.notNull( + List.of(new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "token"))); TokenAdapter() { // avoid general construction } @Override - public List getNames() { + public List getNames() { return NAMES; } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/UriAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/UriAdapter.java index b5f402c6c..f1bb35083 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/UriAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/UriAdapter.java @@ -29,26 +29,29 @@ import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes; import gov.nist.secauto.metaschema.core.datatype.AbstractDataTypeAdapter; +import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyUriItem; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.net.URI; import java.util.List; +import javax.xml.namespace.QName; + import edu.umd.cs.findbugs.annotations.NonNull; public class UriAdapter extends AbstractDataTypeAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( - List.of("uri")); + private static final List NAMES = ObjectUtils.notNull( + List.of(new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "uri"))); UriAdapter() { super(URI.class); } @Override - public List getNames() { + public List getNames() { return NAMES; } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/UriReferenceAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/UriReferenceAdapter.java index 45180c289..2e3015bcc 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/UriReferenceAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/UriReferenceAdapter.java @@ -29,26 +29,29 @@ import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes; import gov.nist.secauto.metaschema.core.datatype.AbstractDataTypeAdapter; +import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IUriReferenceItem; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.net.URI; import java.util.List; +import javax.xml.namespace.QName; + import edu.umd.cs.findbugs.annotations.NonNull; public class UriReferenceAdapter extends AbstractDataTypeAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( - List.of("uri-reference")); + private static final List NAMES = ObjectUtils.notNull( + List.of(new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "uri-reference"))); UriReferenceAdapter() { super(URI.class); } @Override - public List getNames() { + public List getNames() { return NAMES; } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/UuidAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/UuidAdapter.java index fda5a1234..7338723b5 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/UuidAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/UuidAdapter.java @@ -29,6 +29,7 @@ import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes; import gov.nist.secauto.metaschema.core.datatype.AbstractDataTypeAdapter; +import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IUuidItem; import gov.nist.secauto.metaschema.core.util.ObjectUtils; @@ -36,13 +37,15 @@ import java.util.UUID; import java.util.regex.Pattern; +import javax.xml.namespace.QName; + import edu.umd.cs.findbugs.annotations.NonNull; public class UuidAdapter extends AbstractDataTypeAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( - List.of("uuid")); + private static final List NAMES = ObjectUtils.notNull( + List.of(new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "uuid"))); public static final Pattern UUID_PATTERN = Pattern.compile("^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"); @@ -51,7 +54,7 @@ public class UuidAdapter } @Override - public List getNames() { + public List getNames() { return NAMES; } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/YearMonthAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/YearMonthAdapter.java index 0d9190696..b1fcff918 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/YearMonthAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/YearMonthAdapter.java @@ -29,6 +29,7 @@ import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes; import gov.nist.secauto.metaschema.core.datatype.AbstractDataTypeAdapter; +import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IYearMonthDurationItem; import gov.nist.secauto.metaschema.core.util.ObjectUtils; @@ -36,20 +37,22 @@ import java.time.format.DateTimeParseException; import java.util.List; +import javax.xml.namespace.QName; + import edu.umd.cs.findbugs.annotations.NonNull; public class YearMonthAdapter extends AbstractDataTypeAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( - List.of("year-month-duration")); + private static final List NAMES = ObjectUtils.notNull( + List.of(new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "year-month-duration"))); YearMonthAdapter() { super(Period.class); } @Override - public List getNames() { + public List getNames() { return NAMES; } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/markup/MarkupLineAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/markup/MarkupLineAdapter.java index d0a9ad585..0e3d0b31a 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/markup/MarkupLineAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/markup/MarkupLineAdapter.java @@ -29,6 +29,7 @@ import com.fasterxml.jackson.core.JsonParser; import gov.nist.secauto.metaschema.core.datatype.markup.flexmark.XmlMarkupParser; +import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IMarkupItem; import gov.nist.secauto.metaschema.core.util.ObjectUtils; @@ -37,6 +38,7 @@ import java.io.IOException; import java.util.List; +import javax.xml.namespace.QName; import javax.xml.stream.XMLStreamException; import edu.umd.cs.findbugs.annotations.NonNull; @@ -44,15 +46,15 @@ public class MarkupLineAdapter extends AbstractMarkupAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( - List.of("markup-line")); + private static final List NAMES = ObjectUtils.notNull( + List.of(new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "markup-line"))); MarkupLineAdapter() { super(MarkupLine.class); } @Override - public List getNames() { + public List getNames() { return NAMES; } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/markup/MarkupMultilineAdapter.java b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/markup/MarkupMultilineAdapter.java index 4bb3e6c4a..fee505840 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/markup/MarkupMultilineAdapter.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/datatype/markup/MarkupMultilineAdapter.java @@ -29,6 +29,7 @@ import com.fasterxml.jackson.core.JsonParser; import gov.nist.secauto.metaschema.core.datatype.markup.flexmark.XmlMarkupParser; +import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.item.atomic.IMarkupItem; import gov.nist.secauto.metaschema.core.util.ObjectUtils; @@ -45,15 +46,15 @@ public class MarkupMultilineAdapter extends AbstractMarkupAdapter { @NonNull - private static final List NAMES = ObjectUtils.notNull( - List.of("markup-multiline")); + private static final List NAMES = ObjectUtils.notNull( + List.of(new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "markup-multiline"))); MarkupMultilineAdapter() { super(MarkupMultiline.class); } @Override - public List getNames() { + public List getNames() { return NAMES; } diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/MetapathConstants.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/MetapathConstants.java index d9bf26c53..1ddc29efb 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/MetapathConstants.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/MetapathConstants.java @@ -50,18 +50,18 @@ public final class MetapathConstants { URI.create("http://csrc.nist.gov/ns/metaschema/metapath-functions")); @NonNull public static final URI NS_METAPATH_FUNCTIONS_MATH = ObjectUtils.requireNonNull( - URI.create("http://csrc.nist.gov/ns/metaschema/metapath-functions/math")); + URI.create(NS_METAPATH_FUNCTIONS + "/math")); @NonNull public static final URI NS_METAPATH_FUNCTIONS_ARRAY = ObjectUtils.requireNonNull( - URI.create("http://csrc.nist.gov/ns/metaschema/metapath-functions/array")); + URI.create(NS_METAPATH_FUNCTIONS + "/array")); @NonNull public static final URI NS_METAPATH_FUNCTIONS_MAP = ObjectUtils.requireNonNull( - URI.create("http://csrc.nist.gov/ns/metaschema/metapath-functions/map")); + URI.create(NS_METAPATH_FUNCTIONS + "/map")); @NonNull public static final URI NS_METAPATH_FUNCTIONS_EXTENDED = NS_METAPATH_FUNCTIONS; @NonNull - public static final String PREFIX_METAPATH = "mp"; + public static final String PREFIX_METAPATH = "meta"; @NonNull public static final String PREFIX_XML_SCHEMA = "xs"; @NonNull 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 9356bc5fd..10794c9df 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 @@ -32,6 +32,7 @@ import java.net.URI; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; import javax.xml.XMLConstants; @@ -47,6 +48,8 @@ public final class StaticContext { @NonNull private static final Map WELL_KNOWN_NAMESPACES; + @NonNull + private static final Map WELL_KNOWN_URI_TO_PREFIX; static { Map knownNamespaces = new ConcurrentHashMap<>(); @@ -69,6 +72,12 @@ public final class StaticContext { MetapathConstants.PREFIX_XPATH_FUNCTIONS_MAP, MetapathConstants.NS_METAPATH_FUNCTIONS_MAP); WELL_KNOWN_NAMESPACES = CollectionUtil.unmodifiableMap(knownNamespaces); + + WELL_KNOWN_URI_TO_PREFIX = WELL_KNOWN_NAMESPACES.entrySet().stream() + .collect(Collectors.toUnmodifiableMap( + entry -> entry.getValue().toASCIIString(), + Map.Entry::getKey, + (v1, v2) -> v2)); } @Nullable @@ -94,6 +103,22 @@ public static Map getWellKnownNamespaces() { return WELL_KNOWN_NAMESPACES; } + /** + * Get the mapping of namespace URIs to prefixes for all well-known namespaces + * provided by default to the static context. + * + * @return the mapping of namespace URI to prefix for all well-known namespaces + */ + @SuppressFBWarnings("MS_EXPOSE_REP") + public static Map getWellKnownURIToPrefix() { + return WELL_KNOWN_URI_TO_PREFIX; + } + + @Nullable + public static String getWellKnownPrefixForUri(String uri) { + return WELL_KNOWN_URI_TO_PREFIX.get(uri); + } + /** * Create a new static context instance using default values. * diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/SequenceTypeImpl.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/SequenceTypeImpl.java index 80d779f03..ece58474a 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/SequenceTypeImpl.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/SequenceTypeImpl.java @@ -27,6 +27,7 @@ package gov.nist.secauto.metaschema.core.metapath.function; import gov.nist.secauto.metaschema.core.metapath.item.IItem; +import gov.nist.secauto.metaschema.core.metapath.item.TypeSystem; import java.util.Objects; @@ -67,8 +68,11 @@ public String toString() { public String toSignature() { StringBuilder builder = new StringBuilder(); + Class type = getType(); // name - builder.append(getType().getName()) + builder.append(type == null + ? "" + : TypeSystem.getName(type)) // occurrence .append(getOccurrence().getIndicator()); diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/DefaultFunctionLibrary.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/DefaultFunctionLibrary.java index 3e1d70f52..2b40c53a2 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/DefaultFunctionLibrary.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/DefaultFunctionLibrary.java @@ -246,29 +246,38 @@ public DefaultFunctionLibrary() { // NOPMD - intentional registerFunction(MapRemove.SIGNATURE); // P3: https://www.w3.org/TR/xpath-functions-31/#func-map-for-each - // xpath casting functions - registerFunction( - CastFunction.signature(MetapathConstants.NS_XML_SCHEMA, "boolean", IBooleanItem.class, IBooleanItem::cast)); - registerFunction(CastFunction.signature( - MetapathConstants.NS_XML_SCHEMA, "date", IDateItem.class, IDateItem::cast)); - registerFunction(CastFunction.signature( - MetapathConstants.NS_XML_SCHEMA, "dateTime", IDateTimeItem.class, IDateTimeItem::cast)); - registerFunction(CastFunction.signature( - MetapathConstants.NS_XML_SCHEMA, "decimal", IDecimalItem.class, IDecimalItem::cast)); - registerFunction(CastFunction.signature( - MetapathConstants.NS_XML_SCHEMA, "duration", IDurationItem.class, IDurationItem::cast)); - registerFunction(CastFunction.signature( - MetapathConstants.NS_XML_SCHEMA, "integer", IIntegerItem.class, IIntegerItem::cast)); - registerFunction(CastFunction.signature( - MetapathConstants.NS_XML_SCHEMA, "NCName", INcNameItem.class, INcNameItem::cast)); - registerFunction(CastFunction.signature( - MetapathConstants.NS_XML_SCHEMA, "nonNegativeInteger", INonNegativeIntegerItem.class, - INonNegativeIntegerItem::cast)); - registerFunction(CastFunction.signature( - MetapathConstants.NS_XML_SCHEMA, "positiveInteger", IPositiveIntegerItem.class, - IPositiveIntegerItem::cast)); - registerFunction(CastFunction.signature( - MetapathConstants.NS_XML_SCHEMA, "string", IStringItem.class, IStringItem::cast)); + // // xpath casting functions + // registerFunction( + // CastFunction.signature(MetapathConstants.NS_XML_SCHEMA, "boolean", + // IBooleanItem.class, IBooleanItem::cast)); + // registerFunction(CastFunction.signature( + // MetapathConstants.NS_XML_SCHEMA, "date", IDateItem.class, IDateItem::cast)); + // registerFunction(CastFunction.signature( + // MetapathConstants.NS_XML_SCHEMA, "dateTime", IDateTimeItem.class, + // IDateTimeItem::cast)); + // registerFunction(CastFunction.signature( + // MetapathConstants.NS_XML_SCHEMA, "decimal", IDecimalItem.class, + // IDecimalItem::cast)); + // registerFunction(CastFunction.signature( + // MetapathConstants.NS_XML_SCHEMA, "duration", IDurationItem.class, + // IDurationItem::cast)); + // registerFunction(CastFunction.signature( + // MetapathConstants.NS_XML_SCHEMA, "integer", IIntegerItem.class, + // IIntegerItem::cast)); + // registerFunction(CastFunction.signature( + // MetapathConstants.NS_XML_SCHEMA, "NCName", INcNameItem.class, + // INcNameItem::cast)); + // registerFunction(CastFunction.signature( + // MetapathConstants.NS_XML_SCHEMA, "nonNegativeInteger", + // INonNegativeIntegerItem.class, + // INonNegativeIntegerItem::cast)); + // registerFunction(CastFunction.signature( + // MetapathConstants.NS_XML_SCHEMA, "positiveInteger", + // IPositiveIntegerItem.class, + // IPositiveIntegerItem::cast)); + // registerFunction(CastFunction.signature( + // MetapathConstants.NS_XML_SCHEMA, "string", IStringItem.class, + // IStringItem::cast)); // metapath casting functions registerFunction(CastFunction.signature( 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 60144f278..92c4f4df8 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 @@ -33,6 +33,7 @@ import java.util.stream.Stream; public interface IItem extends ICollectionValue { + /** * Get the item's "wrapped" value. This "wrapped" value may be: *
    diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/TypeSystem.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/TypeSystem.java new file mode 100644 index 000000000..483e468e8 --- /dev/null +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/TypeSystem.java @@ -0,0 +1,150 @@ +/* + * Portions of this software was developed by employees of the National Institute + * of Standards and Technology (NIST), an agency of the Federal Government and is + * being made available as a public service. Pursuant to title 17 United States + * Code Section 105, works of NIST employees are not subject to copyright + * protection in the United States. This software may be subject to foreign + * copyright. Permission in the United States and in foreign countries, to the + * extent that NIST may hold copyright, to use, copy, modify, create derivative + * works, and distribute this software and its documentation without fee is hereby + * granted on a non-exclusive basis, provided that this notice and disclaimer + * of warranty appears in all copies. + * + * THE SOFTWARE IS PROVIDED 'AS IS' WITHOUT ANY WARRANTY OF ANY KIND, EITHER + * EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY + * THAT THE SOFTWARE WILL CONFORM TO SPECIFICATIONS, ANY IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND FREEDOM FROM + * INFRINGEMENT, AND ANY WARRANTY THAT THE DOCUMENTATION WILL CONFORM TO THE + * SOFTWARE, OR ANY WARRANTY THAT THE SOFTWARE WILL BE ERROR FREE. IN NO EVENT + * SHALL NIST BE LIABLE FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO, DIRECT, + * INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF, RESULTING FROM, + * OR IN ANY WAY CONNECTED WITH THIS SOFTWARE, WHETHER OR NOT BASED UPON WARRANTY, + * CONTRACT, TORT, OR OTHERWISE, WHETHER OR NOT INJURY WAS SUSTAINED BY PERSONS OR + * PROPERTY OR OTHERWISE, AND WHETHER OR NOT LOSS WAS SUSTAINED FROM, OR AROSE OUT + * OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER. + */ + +package gov.nist.secauto.metaschema.core.metapath.item; + +import gov.nist.secauto.metaschema.core.datatype.IDataTypeAdapter; +import gov.nist.secauto.metaschema.core.datatype.adapter.MetaschemaDataTypeProvider; +import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; +import gov.nist.secauto.metaschema.core.metapath.StaticContext; +import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyAtomicItem; +import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyUriItem; +import gov.nist.secauto.metaschema.core.metapath.item.atomic.IBase64BinaryItem; +import gov.nist.secauto.metaschema.core.metapath.item.atomic.IBooleanItem; +import gov.nist.secauto.metaschema.core.metapath.item.atomic.IDateItem; +import gov.nist.secauto.metaschema.core.metapath.item.atomic.IDateTimeItem; +import gov.nist.secauto.metaschema.core.metapath.item.atomic.IDayTimeDurationItem; +import gov.nist.secauto.metaschema.core.metapath.item.atomic.IDecimalItem; +import gov.nist.secauto.metaschema.core.metapath.item.atomic.IDurationItem; +import gov.nist.secauto.metaschema.core.metapath.item.atomic.IEmailAddressItem; +import gov.nist.secauto.metaschema.core.metapath.item.atomic.IHostnameItem; +import gov.nist.secauto.metaschema.core.metapath.item.atomic.IIPv4AddressItem; +import gov.nist.secauto.metaschema.core.metapath.item.atomic.IIPv6AddressItem; +import gov.nist.secauto.metaschema.core.metapath.item.atomic.IIntegerItem; +import gov.nist.secauto.metaschema.core.metapath.item.atomic.INcNameItem; +import gov.nist.secauto.metaschema.core.metapath.item.atomic.INonNegativeIntegerItem; +import gov.nist.secauto.metaschema.core.metapath.item.atomic.INumericItem; +import gov.nist.secauto.metaschema.core.metapath.item.atomic.IPositiveIntegerItem; +import gov.nist.secauto.metaschema.core.metapath.item.atomic.IStringItem; +import gov.nist.secauto.metaschema.core.metapath.item.atomic.ITokenItem; +import gov.nist.secauto.metaschema.core.metapath.item.atomic.IUriReferenceItem; +import gov.nist.secauto.metaschema.core.metapath.item.atomic.IUuidItem; +import gov.nist.secauto.metaschema.core.metapath.item.atomic.IYearMonthDurationItem; +import gov.nist.secauto.metaschema.core.metapath.item.function.IArrayItem; +import gov.nist.secauto.metaschema.core.metapath.item.function.IMapItem; +import gov.nist.secauto.metaschema.core.metapath.item.node.IAssemblyNodeItem; +import gov.nist.secauto.metaschema.core.metapath.item.node.IDocumentNodeItem; +import gov.nist.secauto.metaschema.core.metapath.item.node.IFieldNodeItem; +import gov.nist.secauto.metaschema.core.metapath.item.node.IFlagNodeItem; +import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem; + +import java.util.Arrays; +import java.util.Collections; +import java.util.Map; +import java.util.stream.Stream; + +import javax.xml.namespace.QName; + +import edu.umd.cs.findbugs.annotations.NonNull; + +public class TypeSystem { + private static final Map, QName> ITEM_CLASS_TO_QNAME_MAP; + + static { + ITEM_CLASS_TO_QNAME_MAP = Collections.unmodifiableMap(Map.ofEntries( + register(IItem.class, "item"), + register(INodeItem.class, "node"), + register(IDocumentNodeItem.class, "document-node"), + register(IAssemblyNodeItem.class, "assembly-node"), + register(IFieldNodeItem.class, "field-node"), + register(IFlagNodeItem.class, "flag-node"), + register(IArrayItem.class, "array"), + register(IMapItem.class, "map"), + register(IAnyAtomicItem.class, "any-atomic-type"), + register(INumericItem.class, "numeric"), + register(IDurationItem.class, "duration"), + register(IBase64BinaryItem.class, MetaschemaDataTypeProvider.BASE64), + register(IBooleanItem.class, MetaschemaDataTypeProvider.BOOLEAN), + register(IDateItem.class, MetaschemaDataTypeProvider.DATE), + // register(IDate.class, MetaschemaDataTypeProvider.DATE_WITH_TZ), + register(IDateTimeItem.class, MetaschemaDataTypeProvider.DATE_TIME), + // register(IBooleanItem.class, MetaschemaDataTypeProvider.DATE_TIME_WITH_TZ), + register(IIPv4AddressItem.class, MetaschemaDataTypeProvider.IP_V4_ADDRESS), + register(IIPv6AddressItem.class, MetaschemaDataTypeProvider.IP_V6_ADDRESS), + register(IAnyUriItem.class, MetaschemaDataTypeProvider.URI), + register(IUriReferenceItem.class, MetaschemaDataTypeProvider.URI_REFERENCE), + register(IUuidItem.class, MetaschemaDataTypeProvider.UUID), + register(IDayTimeDurationItem.class, MetaschemaDataTypeProvider.DAY_TIME_DURATION), + register(IYearMonthDurationItem.class, MetaschemaDataTypeProvider.YEAR_MONTH_DURATION), + register(IDecimalItem.class, MetaschemaDataTypeProvider.DECIMAL), + register(IIntegerItem.class, MetaschemaDataTypeProvider.INTEGER), + register(INonNegativeIntegerItem.class, MetaschemaDataTypeProvider.NON_NEGATIVE_INTEGER), + register(IPositiveIntegerItem.class, MetaschemaDataTypeProvider.POSITIVE_INTEGER), + register(IEmailAddressItem.class, MetaschemaDataTypeProvider.EMAIL_ADDRESS), + register(IHostnameItem.class, MetaschemaDataTypeProvider.HOSTNAME), + register(INcNameItem.class, MetaschemaDataTypeProvider.NCNAME), + register(IStringItem.class, MetaschemaDataTypeProvider.STRING), + register(ITokenItem.class, MetaschemaDataTypeProvider.TOKEN))); + } + + private static Map.Entry, QName> register( + @NonNull Class clazz, + @NonNull IDataTypeAdapter adapter) { + return Map.entry(clazz, adapter.getPreferredName()); + } + + private static Map.Entry, QName> register( + @NonNull Class clazz, + @NonNull String typeName) { + return Map.entry(clazz, new QName(MetapathConstants.NS_METAPATH.toASCIIString(), typeName)); + } + + @NonNull + private static Stream> getItemInterfaces(@NonNull Class clazz) { + @SuppressWarnings("unchecked") Stream> retval = IItem.class.isAssignableFrom(clazz) + ? Stream.of((Class) clazz) + : Stream.empty(); + + Class[] interfaces = clazz.getInterfaces(); + if (interfaces.length > 0) { + retval = Stream.concat(retval, Arrays.stream(interfaces).flatMap(intf -> getItemInterfaces(intf))); + } + + return retval; + } + + public static String getName(@NonNull Class clazz) { + Class itemClass = getItemInterfaces(clazz).findFirst().orElse(null); + + QName qname = ITEM_CLASS_TO_QNAME_MAP.get(itemClass); + return qname == null ? clazz.getName() : asPrefixedName(qname); + } + + private static String asPrefixedName(@NonNull QName qname) { + String prefix = StaticContext.getWellKnownPrefixForUri(qname.getNamespaceURI()); + return prefix == null ? qname.toString() : prefix + ":" + qname.getLocalPart(); + } +} diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/MetaschemaModelConstants.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/MetaschemaModelConstants.java deleted file mode 100644 index f31d762bf..000000000 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/MetaschemaModelConstants.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Portions of this software was developed by employees of the National Institute - * of Standards and Technology (NIST), an agency of the Federal Government and is - * being made available as a public service. Pursuant to title 17 United States - * Code Section 105, works of NIST employees are not subject to copyright - * protection in the United States. This software may be subject to foreign - * copyright. Permission in the United States and in foreign countries, to the - * extent that NIST may hold copyright, to use, copy, modify, create derivative - * works, and distribute this software and its documentation without fee is hereby - * granted on a non-exclusive basis, provided that this notice and disclaimer - * of warranty appears in all copies. - * - * THE SOFTWARE IS PROVIDED 'AS IS' WITHOUT ANY WARRANTY OF ANY KIND, EITHER - * EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY - * THAT THE SOFTWARE WILL CONFORM TO SPECIFICATIONS, ANY IMPLIED WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND FREEDOM FROM - * INFRINGEMENT, AND ANY WARRANTY THAT THE DOCUMENTATION WILL CONFORM TO THE - * SOFTWARE, OR ANY WARRANTY THAT THE SOFTWARE WILL BE ERROR FREE. IN NO EVENT - * SHALL NIST BE LIABLE FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO, DIRECT, - * INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF, RESULTING FROM, - * OR IN ANY WAY CONNECTED WITH THIS SOFTWARE, WHETHER OR NOT BASED UPON WARRANTY, - * CONTRACT, TORT, OR OTHERWISE, WHETHER OR NOT INJURY WAS SUSTAINED BY PERSONS OR - * PROPERTY OR OTHERWISE, AND WHETHER OR NOT LOSS WAS SUSTAINED FROM, OR AROSE OUT - * OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER. - */ - -package gov.nist.secauto.metaschema.core.model; - -public final class MetaschemaModelConstants { - public static final String METAPATH_FUNCTION_NAMESPACE = "http://csrc.nist.gov/ns/metaschema"; - - private MetaschemaModelConstants() { - /* disable construction */ - } -} diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/xmlbeans/handler/DatatypesHandler.java b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/xmlbeans/handler/DatatypesHandler.java index bc52183e9..c07db0910 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/xmlbeans/handler/DatatypesHandler.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/model/xml/xmlbeans/handler/DatatypesHandler.java @@ -102,7 +102,7 @@ private static IDataTypeAdapter decode(SimpleValue target) { private static void encode(IDataTypeAdapter datatype, SimpleValue target) { if (datatype != null) { - target.setStringValue(datatype.getPreferredName()); + target.setStringValue(datatype.getPreferredName().getLocalPart()); } } diff --git a/databind/src/main/java/gov/nist/secauto/metaschema/databind/metapath/function/Model.java b/databind/src/main/java/gov/nist/secauto/metaschema/databind/metapath/function/Model.java index aa19f9913..2e6437035 100644 --- a/databind/src/main/java/gov/nist/secauto/metaschema/databind/metapath/function/Model.java +++ b/databind/src/main/java/gov/nist/secauto/metaschema/databind/metapath/function/Model.java @@ -28,6 +28,7 @@ import gov.nist.secauto.metaschema.core.metapath.DynamicContext; import gov.nist.secauto.metaschema.core.metapath.ISequence; +import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; import gov.nist.secauto.metaschema.core.metapath.function.FunctionUtils; import gov.nist.secauto.metaschema.core.metapath.function.IArgument; import gov.nist.secauto.metaschema.core.metapath.function.IFunction; @@ -35,7 +36,6 @@ import gov.nist.secauto.metaschema.core.metapath.item.node.IDefinitionNodeItem; import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem; import gov.nist.secauto.metaschema.core.model.INamedInstance; -import gov.nist.secauto.metaschema.core.model.MetaschemaModelConstants; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.util.List; @@ -46,7 +46,7 @@ public final class Model { @NonNull static final IFunction SIGNATURE = IFunction.builder() .name("model") - .namespace(MetaschemaModelConstants.METAPATH_FUNCTION_NAMESPACE) + .namespace(MetapathConstants.NS_METAPATH_FUNCTIONS_EXTENDED) .argument(IArgument.builder() .name("node") .type(INodeItem.class) 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 e29dfad73..21ec21808 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 @@ -36,6 +36,8 @@ import java.util.List; +import javax.xml.namespace.QName; + import edu.umd.cs.findbugs.annotations.NonNull; /** @@ -77,7 +79,7 @@ public VoidItem newItem(Object value) { } @Override - public List getNames() { + public List getNames() { throw new UnsupportedOperationException(NOT_VALID); }