Skip to content

Commit f0d43fe

Browse files
Added support for QName for Metaschema data types, which are used in function signatures now instead of the Java class name.
1 parent 95a1e4e commit f0d43fe

35 files changed

+436
-134
lines changed

cli-processor/src/main/resources/log4j2.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
<!DOCTYPE Configuration>
33
<Configuration verbose="true">
44
<Appenders>
5-
<Console name="console-trace" target="SYSTEM_ERR" immediateFlush="true">
5+
<Console name="console-trace" target="SYSTEM_OUT" immediateFlush="true">
66
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n" charset="UTF-8" />
77
<ThresholdFilter level="INFO" onMatch="DENY" onMismatch="ACCEPT" />
88
</Console>
9-
<Console name="console-info" target="SYSTEM_ERR" immediateFlush="true">
9+
<Console name="console-info" target="SYSTEM_OUT" immediateFlush="true">
1010
<PatternLayout pattern="%m%n" charset="UTF-8" />
1111
<Filters>
1212
<ThresholdFilter level="ERROR" onMatch="DENY" onMismatch="ACCEPT" />

core/src/main/java/gov/nist/secauto/metaschema/core/datatype/DataTypeService.java

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
import java.util.function.Function;
4040
import java.util.stream.Collectors;
4141

42+
import javax.xml.namespace.QName;
43+
4244
import edu.umd.cs.findbugs.annotations.NonNull;
4345
import edu.umd.cs.findbugs.annotations.Nullable;
4446
import nl.talsmasoftware.lazy4j.Lazy;
@@ -51,8 +53,9 @@ public final class DataTypeService {
5153
private static final Logger LOGGER = LogManager.getLogger(DataTypeService.class);
5254
private static final Lazy<DataTypeService> INSTANCE = Lazy.lazy(() -> new DataTypeService());
5355

54-
private final Map<String, IDataTypeAdapter<?>> libraryByName;
55-
private final Map<Class<? extends IDataTypeAdapter<?>>, IDataTypeAdapter<?>> libraryByClass;
56+
private final Map<String, IDataTypeAdapter<?>> typeByName;
57+
private final Map<QName, IDataTypeAdapter<?>> typeByQName;
58+
private final Map<Class<? extends IDataTypeAdapter<?>>, IDataTypeAdapter<?>> typeByClass;
5659

5760
/**
5861
* Get the singleton service instance, which will be lazy constructed on first
@@ -74,12 +77,29 @@ private DataTypeService() {
7477
.flatMap(provider -> provider.getJavaTypeAdapters().stream())
7578
.collect(Collectors.toList());
7679

77-
Map<String, IDataTypeAdapter<?>> libraryByName = dataTypes.stream()
80+
Map<String, IDataTypeAdapter<?>> typeByName = dataTypes.stream()
81+
.flatMap(dataType -> dataType.getNames().stream()
82+
.map(qname -> Map.entry(qname.getLocalPart(), dataType)))
83+
.collect(CustomCollectors.toMap(
84+
Map.Entry::getKey,
85+
Map.Entry::getValue,
86+
(key, v1, v2) -> {
87+
if (LOGGER.isWarnEnabled()) {
88+
LOGGER.warn("Data types '{}' and '{}' have duplicate name '{}'. Using the first.",
89+
v1.getClass().getName(),
90+
v2.getClass().getName(),
91+
key);
92+
}
93+
return v1;
94+
},
95+
ConcurrentHashMap::new));
96+
97+
Map<QName, IDataTypeAdapter<?>> typeByQName = dataTypes.stream()
7898
.flatMap(dataType -> dataType.getNames().stream()
79-
.map(name -> Map.entry(name, dataType)))
99+
.map(qname -> Map.entry(qname, dataType)))
80100
.collect(CustomCollectors.toMap(
81101
Map.Entry::getKey,
82-
(entry) -> entry.getValue(),
102+
Map.Entry::getValue,
83103
(key, v1, v2) -> {
84104
if (LOGGER.isWarnEnabled()) {
85105
LOGGER.warn("Data types '{}' and '{}' have duplicate name '{}'. Using the first.",
@@ -92,7 +112,7 @@ private DataTypeService() {
92112
ConcurrentHashMap::new));
93113

94114
@SuppressWarnings({ "unchecked", "null" }) Map<Class<? extends IDataTypeAdapter<?>>,
95-
IDataTypeAdapter<?>> libraryByClass = dataTypes.stream()
115+
IDataTypeAdapter<?>> typeByClass = dataTypes.stream()
96116
.collect(CustomCollectors.toMap(
97117
dataType -> (Class<? extends IDataTypeAdapter<?>>) dataType.getClass(),
98118
Function.identity(),
@@ -104,21 +124,35 @@ private DataTypeService() {
104124
return v1;
105125
},
106126
ConcurrentHashMap::new));
107-
this.libraryByName = libraryByName;
108-
this.libraryByClass = libraryByClass;
127+
this.typeByName = typeByName;
128+
this.typeByQName = typeByQName;
129+
this.typeByClass = typeByClass;
130+
}
131+
132+
/**
133+
* Lookup a specific {@link IDataTypeAdapter} instance by its name.
134+
*
135+
* @param qname
136+
* the qualified name of data type adapter to get the instance for
137+
* @return the instance or {@code null} if the instance is unknown to the type
138+
* system
139+
*/
140+
@Nullable
141+
public IDataTypeAdapter<?> getJavaTypeAdapterByQName(@NonNull QName qname) {
142+
return typeByQName.get(qname);
109143
}
110144

111145
/**
112146
* Lookup a specific {@link IDataTypeAdapter} instance by its name.
113147
*
114148
* @param name
115-
* the data type name of data type adapter to get the instance for
149+
* the name of data type adapter to get the instance for
116150
* @return the instance or {@code null} if the instance is unknown to the type
117151
* system
118152
*/
119153
@Nullable
120154
public IDataTypeAdapter<?> getJavaTypeAdapterByName(@NonNull String name) {
121-
return libraryByName.get(name);
155+
return typeByName.get(name);
122156
}
123157

124158
/**
@@ -134,6 +168,6 @@ public IDataTypeAdapter<?> getJavaTypeAdapterByName(@NonNull String name) {
134168
@SuppressWarnings("unchecked")
135169
@Nullable
136170
public <TYPE extends IDataTypeAdapter<?>> TYPE getJavaTypeAdapterByClass(@NonNull Class<TYPE> clazz) {
137-
return (TYPE) libraryByClass.get(clazz);
171+
return (TYPE) typeByClass.get(clazz);
138172
}
139173
}

core/src/main/java/gov/nist/secauto/metaschema/core/datatype/IDataTypeAdapter.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,25 +63,25 @@ public interface IDataTypeAdapter<TYPE> {
6363
* @return the name
6464
*/
6565
@NonNull
66-
List<String> getNames();
67-
68-
/**
69-
* The JSON primative type of the data type.
70-
*
71-
* @return the JSON data type
72-
*/
73-
JsonFormatTypes getJsonRawType();
66+
List<QName> getNames();
7467

7568
/**
7669
* Get the most preferred name for this data type.
7770
*
7871
* @return the name
7972
*/
8073
@NonNull
81-
default String getPreferredName() {
74+
default QName getPreferredName() {
8275
return ObjectUtils.notNull(getNames().iterator().next());
8376
}
8477

78+
/**
79+
* The JSON primative type of the data type.
80+
*
81+
* @return the JSON data type
82+
*/
83+
JsonFormatTypes getJsonRawType();
84+
8585
/**
8686
* Get the Java class supported by this adapter.
8787
*

core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/Base64Adapter.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,33 @@
2929
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes;
3030

3131
import gov.nist.secauto.metaschema.core.datatype.AbstractDataTypeAdapter;
32+
import gov.nist.secauto.metaschema.core.metapath.MetapathConstants;
3233
import gov.nist.secauto.metaschema.core.metapath.item.atomic.IBase64BinaryItem;
3334
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
3435

3536
import java.nio.ByteBuffer;
3637
import java.util.Base64;
3738
import java.util.List;
3839

40+
import javax.xml.namespace.QName;
41+
3942
import edu.umd.cs.findbugs.annotations.NonNull;
4043

4144
public class Base64Adapter
4245
extends AbstractDataTypeAdapter<ByteBuffer, IBase64BinaryItem> {
4346
@NonNull
44-
private static final List<String> NAMES = ObjectUtils.notNull(
47+
private static final List<QName> NAMES = ObjectUtils.notNull(
4548
List.of(
46-
"base64",
49+
new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "base64"),
4750
// for backwards compatibility with original type name
48-
"base64Binary"));
51+
new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "base64Binary")));
4952

5053
Base64Adapter() {
5154
super(ByteBuffer.class);
5255
}
5356

5457
@Override
55-
public List<String> getNames() {
58+
public List<QName> getNames() {
5659
return NAMES;
5760
}
5861

core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/BooleanAdapter.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes;
3232

3333
import gov.nist.secauto.metaschema.core.datatype.AbstractDataTypeAdapter;
34+
import gov.nist.secauto.metaschema.core.metapath.MetapathConstants;
3435
import gov.nist.secauto.metaschema.core.metapath.function.InvalidValueForCastFunctionException;
3536
import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyAtomicItem;
3637
import gov.nist.secauto.metaschema.core.metapath.item.atomic.IBooleanItem;
@@ -41,20 +42,22 @@
4142
import java.io.IOException;
4243
import java.util.List;
4344

45+
import javax.xml.namespace.QName;
46+
4447
import edu.umd.cs.findbugs.annotations.NonNull;
4548

4649
public class BooleanAdapter
4750
extends AbstractDataTypeAdapter<Boolean, IBooleanItem> {
4851
@NonNull
49-
private static final List<String> NAMES = ObjectUtils.notNull(
50-
List.of("boolean"));
52+
private static final List<QName> NAMES = ObjectUtils.notNull(
53+
List.of(new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "boolean")));
5154

5255
BooleanAdapter() {
5356
super(Boolean.class);
5457
}
5558

5659
@Override
57-
public List<String> getNames() {
60+
public List<QName> getNames() {
5861
return NAMES;
5962
}
6063

core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DateAdapter.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
import gov.nist.secauto.metaschema.core.datatype.AbstractCustomJavaDataTypeAdapter;
3232
import gov.nist.secauto.metaschema.core.datatype.object.Date;
33+
import gov.nist.secauto.metaschema.core.metapath.MetapathConstants;
3334
import gov.nist.secauto.metaschema.core.metapath.function.InvalidValueForCastFunctionException;
3435
import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyAtomicItem;
3536
import gov.nist.secauto.metaschema.core.metapath.item.atomic.IDateItem;
@@ -48,13 +49,15 @@
4849
import java.util.regex.Matcher;
4950
import java.util.regex.Pattern;
5051

52+
import javax.xml.namespace.QName;
53+
5154
import edu.umd.cs.findbugs.annotations.NonNull;
5255

5356
public class DateAdapter
5457
extends AbstractCustomJavaDataTypeAdapter<Date, IDateItem> {
5558
@NonNull
56-
private static final List<String> NAMES = ObjectUtils.notNull(
57-
List.of("date"));
59+
private static final List<QName> NAMES = ObjectUtils.notNull(
60+
List.of(new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "date")));
5861
private static final Pattern DATE_TIMEZONE = Pattern.compile("^("
5962
+ "^(?:(?:2000|2400|2800|(?:19|2[0-9](?:0[48]|[2468][048]|[13579][26])))-02-29)"
6063
+ "|(?:(?:(?:19|2[0-9])[0-9]{2})-02-(?:0[1-9]|1[0-9]|2[0-8]))"
@@ -68,7 +71,7 @@ public class DateAdapter
6871
}
6972

7073
@Override
71-
public List<String> getNames() {
74+
public List<QName> getNames() {
7275
return NAMES;
7376
}
7477

core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DateTimeAdapter.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
import gov.nist.secauto.metaschema.core.datatype.AbstractCustomJavaDataTypeAdapter;
3232
import gov.nist.secauto.metaschema.core.datatype.object.DateTime;
33+
import gov.nist.secauto.metaschema.core.metapath.MetapathConstants;
3334
import gov.nist.secauto.metaschema.core.metapath.function.InvalidValueForCastFunctionException;
3435
import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyAtomicItem;
3536
import gov.nist.secauto.metaschema.core.metapath.item.atomic.IDateItem;
@@ -44,23 +45,25 @@
4445
import java.time.format.DateTimeParseException;
4546
import java.util.List;
4647

48+
import javax.xml.namespace.QName;
49+
4750
import edu.umd.cs.findbugs.annotations.NonNull;
4851

4952
public class DateTimeAdapter
5053
extends AbstractCustomJavaDataTypeAdapter<DateTime, IDateTimeItem> {
5154
@NonNull
52-
private static final List<String> NAMES = ObjectUtils.notNull(
55+
private static final List<QName> NAMES = ObjectUtils.notNull(
5356
List.of(
54-
"date-time",
57+
new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "date-time"),
5558
// for backwards compatibility with original type name
56-
"dateTime"));
59+
new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "dateTime")));
5760

5861
DateTimeAdapter() {
5962
super(DateTime.class);
6063
}
6164

6265
@Override
63-
public List<String> getNames() {
66+
public List<QName> getNames() {
6467
return NAMES;
6568
}
6669

core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DateTimeWithTZAdapter.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,33 @@
2929
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes;
3030

3131
import gov.nist.secauto.metaschema.core.datatype.AbstractDataTypeAdapter;
32+
import gov.nist.secauto.metaschema.core.metapath.MetapathConstants;
3233
import gov.nist.secauto.metaschema.core.metapath.item.atomic.IDateTimeItem;
3334
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
3435

3536
import java.time.ZonedDateTime;
3637
import java.time.format.DateTimeParseException;
3738
import java.util.List;
3839

40+
import javax.xml.namespace.QName;
41+
3942
import edu.umd.cs.findbugs.annotations.NonNull;
4043

4144
public class DateTimeWithTZAdapter
4245
extends AbstractDataTypeAdapter<ZonedDateTime, IDateTimeItem> {
4346
@NonNull
44-
private static final List<String> NAMES = ObjectUtils.notNull(
47+
private static final List<QName> NAMES = ObjectUtils.notNull(
4548
List.of(
46-
"date-time-with-timezone",
49+
new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "date-time-with-timezone"),
4750
// for backwards compatibility with original type name
48-
"dateTime-with-timezone"));
51+
new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "dateTime-with-timezone")));
4952

5053
DateTimeWithTZAdapter() {
5154
super(ZonedDateTime.class);
5255
}
5356

5457
@Override
55-
public List<String> getNames() {
58+
public List<QName> getNames() {
5659
return NAMES;
5760
}
5861

core/src/main/java/gov/nist/secauto/metaschema/core/datatype/adapter/DateWithTZAdapter.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes;
3030

3131
import gov.nist.secauto.metaschema.core.datatype.AbstractDataTypeAdapter;
32+
import gov.nist.secauto.metaschema.core.metapath.MetapathConstants;
3233
import gov.nist.secauto.metaschema.core.metapath.item.atomic.IDateItem;
3334
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
3435

@@ -38,14 +39,16 @@
3839
import java.util.regex.Matcher;
3940
import java.util.regex.Pattern;
4041

42+
import javax.xml.namespace.QName;
43+
4144
import edu.umd.cs.findbugs.annotations.NonNull;
4245

4346
public class DateWithTZAdapter
4447
extends AbstractDataTypeAdapter<ZonedDateTime, IDateItem> {
4548
@NonNull
46-
private static final List<String> NAMES = ObjectUtils.notNull(
49+
private static final List<QName> NAMES = ObjectUtils.notNull(
4750
List.of(
48-
"date-with-timezone"));
51+
new QName(MetapathConstants.NS_METAPATH.toASCIIString(), "date-with-timezone")));
4952
private static final Pattern DATE_TIMEZONE = Pattern.compile("^("
5053
+ "^(?:(?:2000|2400|2800|(?:19|2[0-9](?:0[48]|[2468][048]|[13579][26])))-02-29)"
5154
+ "|(?:(?:(?:19|2[0-9])[0-9]{2})-02-(?:0[1-9]|1[0-9]|2[0-8]))"
@@ -59,7 +62,7 @@ public class DateWithTZAdapter
5962
}
6063

6164
@Override
62-
public List<String> getNames() {
65+
public List<QName> getNames() {
6366
return NAMES;
6467
}
6568

0 commit comments

Comments
 (0)