X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.api%2Fsrc%2Forg%2Fargeo%2Fapi%2Fgcr%2FCrAttributeType.java;h=1e3445653e624fd0bd6a30166b49dd432513c7e2;hb=865fc51900459b888938cc0d6943673ee6f20d09;hp=28f1bc0f6b3af02744326425624336aac8e0f341;hpb=212a43ed44ffc186b69e838d65a1421fd5e1f3a5;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.api/src/org/argeo/api/gcr/CrAttributeType.java b/org.argeo.api/src/org/argeo/api/gcr/CrAttributeType.java index 28f1bc0f6..1e3445653 100644 --- a/org.argeo.api/src/org/argeo/api/gcr/CrAttributeType.java +++ b/org.argeo.api/src/org/argeo/api/gcr/CrAttributeType.java @@ -6,32 +6,34 @@ import java.time.Instant; import java.time.format.DateTimeParseException; import java.util.UUID; +import javax.xml.XMLConstants; + /** * Minimal standard attribute types that MUST be supported. All related classes * belong to java.base and can be implicitly derived form a given * String. */ -public enum CrAttributeType { +public enum CrAttributeType implements ContentNameSupplier { BOOLEAN(Boolean.class, new BooleanFormatter()), // INTEGER(Integer.class, new IntegerFormatter()), // LONG(Long.class, new LongFormatter()), // DOUBLE(Double.class, new DoubleFormatter()), // // we do not support short and float, like recent additions to Java // (e.g. optional primitives) - INSTANT(Instant.class, new InstantFormatter()), // + DATE_TIME(Instant.class, new InstantFormatter()), // UUID(UUID.class, new UuidFormatter()), // - URI(URI.class, new UriFormatter()), // + ANY_URI(URI.class, new UriFormatter()), // STRING(String.class, new StringFormatter()), // ; + private final Class clss; + private final AttributeFormatter formatter; + private CrAttributeType(Class clss, AttributeFormatter formatter) { this.clss = clss; this.formatter = formatter; } - private final Class clss; - private final AttributeFormatter formatter; - public Class getClss() { return clss; } @@ -40,6 +42,22 @@ public enum CrAttributeType { return formatter; } + @Override + public String getDefaultPrefix() { + if (equals(UUID)) + return CrName.CR_DEFAULT_PREFIX; + else + return "xs"; + } + + @Override + public String getNamespaceURI() { + if (equals(UUID)) + return CrName.CR_NAMESPACE_URI; + else + return XMLConstants.W3C_XML_SCHEMA_NS_URI; + } + public static Object parse(String str) { if (str == null) throw new IllegalArgumentException("String cannot be null"); @@ -66,7 +84,7 @@ public enum CrAttributeType { // silent } try { - return INSTANT.getFormatter().parse(str); + return DATE_TIME.getFormatter().parse(str); } catch (IllegalArgumentException e) { // silent } @@ -77,7 +95,7 @@ public enum CrAttributeType { // silent } try { - java.net.URI uri = (java.net.URI) URI.getFormatter().parse(str); + java.net.URI uri = (java.net.URI) ANY_URI.getFormatter().parse(str); if (uri.getScheme() != null) return uri; String path = uri.getPath();