Skip to content

Commit

Permalink
Refactoring of Module Loading API (#211)
Browse files Browse the repository at this point in the history
* Refactored the module loading and data binding layers of the library. The result is a much cleaner API that should perform better overall, due to shorter code paths. This version is much more expansible and enabled dynamic compilation of module classes to be disabled by default. 
* Added a builder pattern to use in creating an IBindingContext with common options.
* Reformatted code.
  • Loading branch information
david-waltermire authored Oct 27, 2024
1 parent b6ba87c commit 37089cd
Show file tree
Hide file tree
Showing 107 changed files with 2,274 additions and 1,323 deletions.
2 changes: 1 addition & 1 deletion cli-processor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>dev.metaschema.java</groupId>
<artifactId>metaschema-framework</artifactId>
<version>1.3.0-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
</parent>

<artifactId>cli-processor</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion core/metaschema
Submodule metaschema updated 88 files
+12 −4 schema/metaschema/metaschema-module-metaschema.xml
+12 −0 schema/xml/metaschema-meta-constraints.xsd
+1 −1 test-suite/schema-generation/allowed-values/allowed-values-basic_metaschema.xml
+1 −1 test-suite/schema-generation/allowed-values/allowed-values-basic_test_baddates_FAIL.json
+1 −1 test-suite/schema-generation/allowed-values/allowed-values-basic_test_badvalues_FAIL.json
+2 −2 test-suite/schema-generation/allowed-values/allowed-values-basic_test_valid_FAIL.xml
+1 −1 test-suite/schema-generation/allowed-values/allowed-values-basic_test_valid_PASS.json
+2 −2 test-suite/schema-generation/allowed-values/allowed-values-basic_test_valid_PASS.xml
+4 −4 test-suite/schema-generation/choice/choice-multiple_metaschema.xml
+1 −1 test-suite/schema-generation/choice/choice-multiple_test_multiple_PASS.json
+0 −61 test-suite/schema-generation/choice/target/choice-multiple_metaschema-jsonschema.json
+0 −235 test-suite/schema-generation/choice/target/choice-multiple_metaschema-xmlschema.xsd
+1 −1 test-suite/schema-generation/collapsible/collapsible-no-op_metaschema.xml
+1 −1 test-suite/schema-generation/collapsible/collapsible_metaschema.xml
+1 −1 test-suite/schema-generation/collapsible/collapsible_test_multiple_PASS.json
+1 −1 test-suite/schema-generation/collapsible/collapsible_test_singleton_PASS.json
+4 −4 test-suite/schema-generation/datatypes/datatypes-prose_metaschema.xml
+1 −1 test-suite/schema-generation/datatypes/datatypes-prose_test_bad-date_FAIL.json
+1 −1 test-suite/schema-generation/datatypes/datatypes-prose_test_valid_PASS.json
+9 −5 test-suite/schema-generation/datatypes/datatypes-token_metaschema.xml
+0 −0 test-suite/schema-generation/datatypes/datatypes-token_test_invalid2_FAIL.json
+2 −2 test-suite/schema-generation/datatypes/datatypes-token_test_invalid_FAIL.json
+2 −2 test-suite/schema-generation/datatypes/datatypes-token_test_invalid_FAIL.xml
+1 −1 test-suite/schema-generation/datatypes/datatypes-token_test_valid2_PASS.json
+3 −3 test-suite/schema-generation/datatypes/datatypes-token_test_valid_PASS.json
+1 −1 test-suite/schema-generation/datatypes/datatypes-uri_metaschema.xml
+1 −1 test-suite/schema-generation/datatypes/datatypes-uri_test_broken_FAIL.json
+1 −1 test-suite/schema-generation/datatypes/datatypes-uri_test_valid_PASS.json
+3 −3 test-suite/schema-generation/datatypes/datatypes-uuid_metaschema.xml
+1 −1 test-suite/schema-generation/datatypes/datatypes-uuid_test_valid_PASS.json
+1 −1 test-suite/schema-generation/datatypes/datatypes-uuid_test_version-1-invalid_FAIL.json
+5 −5 test-suite/schema-generation/dates-times/datatypes-date_metaschema.xml
+2 −2 test-suite/schema-generation/dates-times/datatypes-date_test_fancy_FAIL.xml
+1 −1 test-suite/schema-generation/dates-times/datatypes-date_test_tricky_FAIL.json
+1 −1 test-suite/schema-generation/dates-times/datatypes-date_test_valid_PASS.json
+2 −2 test-suite/schema-generation/dates-times/datatypes-date_test_valid_PASS.xml
+0 −62 test-suite/schema-generation/dates-times/datatypes-datetime-no-tz_json-schema.json
+5 −5 test-suite/schema-generation/dates-times/datatypes-datetime-no-tz_metaschema.xml
+1 −1 test-suite/schema-generation/dates-times/datatypes-datetime-no-tz_test_valid_PASS.json
+2 −2 test-suite/schema-generation/dates-times/datatypes-datetime-notz_test_valid_PASS.xml
+2 −2 test-suite/schema-generation/dates-times/datatypes-datetime-notz_test_various_FAIL.xml
+1 −1 test-suite/schema-generation/dates-times/datatypes-datetime_metaschema.xml
+1 −1 test-suite/schema-generation/dates-times/datatypes-datetime_test_valid_PASS.json
+2 −2 test-suite/schema-generation/dates-times/datatypes-datetime_test_valid_PASS.xml
+2 −2 test-suite/schema-generation/dates-times/datatypes-datetime_test_various_FAIL.xml
+2 −2 test-suite/schema-generation/dates-times/datatypes-datetime_test_working_FAIL.xml
+2 −2 test-suite/schema-generation/dates-times/datatypes-datetime_test_working_PASS.xml
+1 −1 test-suite/schema-generation/flag/flag-basic_metaschema.xml
+1 −1 test-suite/schema-generation/flag/flag-basic_test_datatype_FAIL.json
+1 −1 test-suite/schema-generation/flag/flag-basic_test_simple_PASS.json
+2 −2 test-suite/schema-generation/flag/flag-override_metaschema.xml
+3 −3 test-suite/schema-generation/group-as/group-as-array-bounded_metaschema.xml
+1 −1 test-suite/schema-generation/group-as/group-as-array-bounded_test_array-inside_PASS.json
+1 −1 test-suite/schema-generation/group-as/group-as-array-bounded_test_array-singleton_FAIL.json
+1 −1 test-suite/schema-generation/group-as/group-as-array-bounded_test_array-upper_FAIL.json
+4 −4 test-suite/schema-generation/group-as/group-as-array-invalid-max_metaschema.xml
+3 −3 test-suite/schema-generation/group-as/group-as-array-optional_metaschema.xml
+1 −1 test-suite/schema-generation/group-as/group-as-array-optional_test_empty_FAIL.json
+1 −1 test-suite/schema-generation/group-as/group-as-array-optional_test_valid_PASS.json
+1 −1 test-suite/schema-generation/group-as/group-as-array_metaschema.xml
+1 −1 test-suite/schema-generation/group-as/group-as-array_test_singleton_FAIL.json
+1 −1 test-suite/schema-generation/group-as/group-as-array_test_valid_PASS.json
+3 −3 test-suite/schema-generation/group-as/group-as-by-key_metaschema.xml
+1 −1 test-suite/schema-generation/group-as/group-as-by-key_test_invalid-child_FAIL.json
+1 −1 test-suite/schema-generation/group-as/group-as-by-key_test_valid_PASS.json
+4 −4 test-suite/schema-generation/group-as/group-as-misc_metaschema.xml
+3 −3 test-suite/schema-generation/group-as/group-as-singleton-or-array-optional_metaschema.xml
+1 −1 test-suite/schema-generation/group-as/group-as-singleton-or-array-optional_test_empty_FAIL.json
+1 −1 ...uite/schema-generation/group-as/group-as-singleton-or-array-optional_test_invalid-array-singleton_FAIL.json
+1 −1 test-suite/schema-generation/group-as/group-as-singleton-or-array-optional_test_valid-array_PASS.json
+1 −1 test-suite/schema-generation/group-as/group-as-singleton-or-array-optional_test_valid-singleton_PASS.json
+2 −2 test-suite/schema-generation/group-as/group-as-singleton-or-array_metaschema.xml
+1 −1 test-suite/schema-generation/group-as/group-as-singleton-or-array_test_singleton_PASS.json
+1 −1 test-suite/schema-generation/group-as/group-as-singleton-or-array_test_valid-array_PASS.json
+1 −1 test-suite/schema-generation/json-value-key/json-value-key-field_metaschema.xml
+1 −1 test-suite/schema-generation/json-value-key/json-value-key-field_test_valid_PASS.json
+1 −1 test-suite/schema-generation/json-value-key/json-value-key-label_metaschema.xml
+1 −1 test-suite/schema-generation/json-value-key/json-value-key-label_test_valid2_PASS.json
+1 −1 test-suite/schema-generation/json-value-key/json-value-key-label_test_valid_PASS.json
+0 −248 test-suite/schema-generation/json-value-key/target/json-value-key-field_metaschema-xmlschema.xsd
+0 −246 test-suite/schema-generation/json-value-key/target/json-value-key-label_metaschema-xmlschema.xsd
+5 −5 test-suite/schema-generation/local-declarations/global-and-local_metaschema.xml
+4 −4 test-suite/schema-generation/local-declarations/global-and-scoped-local_metaschema.xml
+0 −35 test-suite/schema-generation/token/datatypes-token_metaschema.xml
+0 −7 test-suite/schema-generation/token/readme.md
+0 −42 test-suite/schema-generation/token/target/datatypes-token_metaschema-jsonschema.json
+0 −217 test-suite/schema-generation/token/target/datatypes-token_metaschema-xmlschema.xsd
+11 −1 test-suite/schema-generation/unit-tests.xml
6 changes: 5 additions & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>dev.metaschema.java</groupId>
<artifactId>metaschema-framework</artifactId>
<version>1.3.0-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
</parent>

<artifactId>metaschema-core</artifactId>
Expand Down Expand Up @@ -109,6 +109,10 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
</dependency>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import gov.nist.secauto.metaschema.core.datatype.adapter.MetaschemaDataTypeProvider;
import gov.nist.secauto.metaschema.core.util.CollectionUtil;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.locks.Lock;
Expand All @@ -32,9 +33,10 @@ public abstract class AbstractDataTypeProvider implements IDataTypeProvider {
@Override
public List<? extends IDataTypeAdapter<?>> getJavaTypeAdapters() {
Lock readLock = libraryLock.readLock();
readLock.lock();
try {
readLock.lock();
return CollectionUtil.unmodifiableList(library);
// make a defensive copy to protect callers from potential modifications
return CollectionUtil.unmodifiableList(new ArrayList<>(library));
} finally {
readLock.unlock();
}
Expand All @@ -53,8 +55,8 @@ protected void registerDatatype(@NonNull IDataTypeAdapter<?> adapter) {
throw new IllegalArgumentException("The adapter has no name: " + adapter.getClass().getName());
}
Lock writeLock = libraryLock.writeLock();
writeLock.lock();
try {
writeLock.lock();
library.add(adapter);
} finally {
writeLock.unlock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package gov.nist.secauto.metaschema.core.metapath;

import com.github.benmanes.caffeine.cache.Caffeine;

import gov.nist.secauto.metaschema.core.configuration.DefaultConfiguration;
import gov.nist.secauto.metaschema.core.configuration.IConfiguration;
import gov.nist.secauto.metaschema.core.configuration.IMutableConfiguration;
Expand All @@ -23,6 +25,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;

import javax.xml.namespace.QName;

Expand Down Expand Up @@ -87,7 +90,10 @@ public SharedState(@NonNull StaticContext staticContext) {
this.implicitTimeZone = ObjectUtils.notNull(clock.getZone());
this.currentDateTime = ObjectUtils.notNull(ZonedDateTime.now(clock));
this.availableDocuments = new HashMap<>();
this.functionResultCache = new HashMap<>();
this.functionResultCache = ObjectUtils.notNull(Caffeine.newBuilder()
.maximumSize(5000)
.expireAfterAccess(10, TimeUnit.MINUTES)
.<CallingContext, ISequence<?>>build().asMap());
this.configuration = new DefaultConfiguration<>();
this.configuration.enableFeature(MetapathEvaluationFeature.METAPATH_EVALUATE_PREDICATES);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ private void registerFunctionByQName(@NonNull IFunction function) {
QName qname = function.getQName();
IFunction duplicate;
Lock writeLock = instanceLock.writeLock();
writeLock.lock();
try {
writeLock.lock();
NamedFunctionSet functions = libraryByQName.get(qname);
if (functions == null) {
functions = new NamedFunctionSet();
Expand All @@ -66,8 +66,8 @@ private void registerFunctionByQName(@NonNull IFunction function) {
private void registerFunctionByName(@NonNull IFunction function) {
String name = function.getName();
Lock writeLock = instanceLock.writeLock();
writeLock.lock();
try {
writeLock.lock();
NamedFunctionSet functions = libraryByName.get(name);
if (functions == null) {
functions = new NamedFunctionSet();
Expand All @@ -83,8 +83,8 @@ private void registerFunctionByName(@NonNull IFunction function) {
@Override
public Stream<IFunction> stream() {
Lock readLock = instanceLock.readLock();
readLock.lock();
try {
readLock.lock();
return ObjectUtils.notNull(libraryByQName.values().stream().flatMap(NamedFunctionSet::getFunctionsAsStream));
} finally {
readLock.unlock();
Expand All @@ -95,8 +95,8 @@ public Stream<IFunction> stream() {
public IFunction getFunction(@NonNull String name, int arity) {
IFunction retval = null;
Lock readLock = instanceLock.readLock();
readLock.lock();
try {
readLock.lock();
NamedFunctionSet functions = libraryByName.get(name);
if (functions != null) {
retval = functions.getFunctionWithArity(arity);
Expand All @@ -111,8 +111,8 @@ public IFunction getFunction(@NonNull String name, int arity) {
public IFunction getFunction(@NonNull QName name, int arity) {
IFunction retval = null;
Lock readLock = instanceLock.readLock();
readLock.lock();
try {
readLock.lock();
NamedFunctionSet functions = libraryByQName.get(name);
if (functions != null) {
retval = functions.getFunctionWithArity(arity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@
import gov.nist.secauto.metaschema.core.metapath.item.atomic.IPositiveIntegerItem;
import gov.nist.secauto.metaschema.core.metapath.item.atomic.IStringItem;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

/**
* Provides built-in Metapath functions based on the XPath 3.1
* <a href= "https://www.w3.org/TR/xpath-functions-31/">function
* specification</a>.
*/
@SuppressWarnings({ "removal" })
@SuppressFBWarnings("UWF_UNWRITTEN_FIELD")
@AutoService(IFunctionLibrary.class)
public class DefaultFunctionLibrary
extends FunctionLibrary {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@
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;
import gov.nist.secauto.metaschema.core.metapath.function.InvalidTypeFunctionException;
import gov.nist.secauto.metaschema.core.metapath.item.IItem;
import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyAtomicItem;
import gov.nist.secauto.metaschema.core.metapath.item.atomic.IIntegerItem;
import gov.nist.secauto.metaschema.core.metapath.item.atomic.IStringItem;
import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;

import java.util.List;
import java.util.Locale;

import edu.umd.cs.findbugs.annotations.NonNull;

Expand Down Expand Up @@ -57,13 +55,11 @@ private static ISequence<IStringItem> executeOneArg(@NonNull IFunction function,
@NonNull List<ISequence<?>> arguments, @NonNull DynamicContext dynamicContext, IItem focus) {

// From the XPath 3.1 specification:
// If the value of $arg is the empty sequence, the zero-length string is returned.
if (arguments.get(0).size() == 0) {
return ISequence.of(IStringItem.valueOf(""));
}

IStringItem arg = FunctionUtils.asTypeOrNull(arguments.get(0).getFirstItem(true));
return ISequence.of(fnLowerCase(arg));
// If the value of $arg is the empty sequence, the zero-length string is
// returned.
return ISequence.of(arguments.get(0).isEmpty()
? IStringItem.valueOf("")
: fnLowerCase(FunctionUtils.asType(ObjectUtils.notNull(arguments.get(0).getFirstItem(true)))));
}

/**
Expand All @@ -76,6 +72,6 @@ private static ISequence<IStringItem> executeOneArg(@NonNull IFunction function,
*/
@NonNull
public static IStringItem fnLowerCase(@NonNull IStringItem arg) {
return IStringItem.valueOf(arg.toString().toLowerCase());
return IStringItem.valueOf(ObjectUtils.notNull(arg.toString().toLowerCase(Locale.ROOT)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ private static ISequence<IIntegerItem> executeOneArg(
// If the value of $arg is the empty sequence, the function returns the
// xs:integer value zero (0).
IStringItem arg = FunctionUtils.asTypeOrNull(arguments.get(0).getFirstItem(true));
return arg == null
? ISequence.of(IIntegerItem.ZERO)
: ISequence.of(fnStringLength(arg));
return ISequence.of(arg == null
? IIntegerItem.ZERO
: fnStringLength(arg));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import java.util.List;

import edu.umd.cs.findbugs.annotations.NonNull;
// CPD-OFF

// CPD-OFF
/**
* Implements the XPath 3.1 <a href=
* "https://www.w3.org/TR/xpath-functions-31/#func-substring-after">fn:substring-after</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import java.util.List;

import edu.umd.cs.findbugs.annotations.NonNull;
// CPD-OFF

// CPD-OFF
/**
* Implements the XPath 3.1 <a href=
* "https://www.w3.org/TR/xpath-functions-31/#func-substring-before">fn:substring-before</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@
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;
import gov.nist.secauto.metaschema.core.metapath.function.InvalidTypeFunctionException;
import gov.nist.secauto.metaschema.core.metapath.item.IItem;
import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyAtomicItem;
import gov.nist.secauto.metaschema.core.metapath.item.atomic.IIntegerItem;
import gov.nist.secauto.metaschema.core.metapath.item.atomic.IStringItem;
import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;

import java.util.List;
import java.util.Locale;

import edu.umd.cs.findbugs.annotations.NonNull;

Expand Down Expand Up @@ -57,13 +55,12 @@ private static ISequence<IStringItem> executeOneArg(@NonNull IFunction function,
@NonNull List<ISequence<?>> arguments, @NonNull DynamicContext dynamicContext, IItem focus) {

// From the XPath 3.1 specification:
// If the value of $arg is the empty sequence, the zero-length string is returned.
if (arguments.get(0).size() == 0) {
return ISequence.of(IStringItem.valueOf(""));
}
// If the value of $arg is the empty sequence, the zero-length string is
// returned.
return ISequence.of(arguments.get(0).isEmpty()
? IStringItem.valueOf("")
: fnUpperCase(FunctionUtils.asType(ObjectUtils.notNull(arguments.get(0).getFirstItem(true)))));

IStringItem arg = FunctionUtils.asTypeOrNull(arguments.get(0).getFirstItem(true));
return ISequence.of(fnUpperCase(arg));
}

/**
Expand All @@ -76,6 +73,6 @@ private static ISequence<IStringItem> executeOneArg(@NonNull IFunction function,
*/
@NonNull
public static IStringItem fnUpperCase(@NonNull IStringItem arg) {
return IStringItem.valueOf(arg.toString().toUpperCase());
return IStringItem.valueOf(ObjectUtils.notNull(arg.toString().toUpperCase(Locale.ROOT)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ private static <T extends ICollectionValue> ISequence<IMapItem<T>> execute(@NonN
@NonNull DynamicContext dynamicContext,
IItem focus) {
IAnyAtomicItem key = FunctionUtils.asType(ObjectUtils.requireNonNull(arguments.get(0).getFirstItem(true)));
@SuppressWarnings("unchecked")
T value = (T) arguments.get(1).toCollectionValue();
@SuppressWarnings("unchecked") T value = (T) arguments.get(1).toCollectionValue();

return entry(key, value).asSequence();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ private enum Duplicates {
private final CustomCollectors.DuplicateHandler<IMapKey, ICollectionValue> duplicateHander;

static {
@SuppressWarnings("PMD.UseConcurrentHashMap")
Map<String, Duplicates> map = new HashMap<>();
@SuppressWarnings("PMD.UseConcurrentHashMap") Map<String, Duplicates> map = new HashMap<>();
for (Duplicates value : values()) {
map.put(value.getName(), value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ private static <V extends ICollectionValue> ISequence<?> execute(@NonNull IFunct
IItem focus) {
IMapItem<V> map = FunctionUtils.asType(ObjectUtils.requireNonNull(arguments.get(0).getFirstItem(true)));
IAnyAtomicItem key = FunctionUtils.asType(ObjectUtils.requireNonNull(arguments.get(1).getFirstItem(true)));
@SuppressWarnings("unchecked")
V value = (V) ObjectUtils.requireNonNull(arguments.get(2)).toCollectionValue();
@SuppressWarnings("unchecked") V value = (V) ObjectUtils.requireNonNull(arguments.get(2)).toCollectionValue();

return put(map, key, value).asSequence();
}
Expand All @@ -95,8 +94,7 @@ public static <V extends ICollectionValue> IMapItem<V> put(
@NonNull IMapItem<V> map,
@NonNull IAnyAtomicItem key,
@NonNull V value) {
@SuppressWarnings("PMD.UseConcurrentHashMap")
Map<IMapKey, V> copy = new HashMap<>(map);
@SuppressWarnings("PMD.UseConcurrentHashMap") Map<IMapKey, V> copy = new HashMap<>(map);
copy.put(key.asMapKey(), value);

return IMapItem.ofCollection(copy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ public static ISequence<INodeItem> recurseDepth(

return ISequence.of(ObjectUtils.notNull(initialContext.stream()
.flatMap(item -> {
@NonNull
ISequence<INodeItem> metapathResult = recursionMetapath.evaluate(item, dynamicContext);
@NonNull ISequence<INodeItem> metapathResult = recursionMetapath.evaluate(item, dynamicContext);
// ensure this is list backed
metapathResult.getValue();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
* functions that operate on an underlying XML document model (XDM) have been
* adapted to work with an underlying Metaschema module-base model instead.
* <p>
* The {@link MpRecurseDepth} functions are new Metapath functions that are not
* present in XPath 3.1.
* The
* {@link gov.nist.secauto.metaschema.core.metapath.function.library.MpRecurseDepth}
* functions are new Metapath functions that are not present in XPath 3.1.
*/

package gov.nist.secauto.metaschema.core.metapath.function.library;
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public StreamSequence(@NonNull Stream<ITEM> stream) {

@Override
public List<ITEM> getValue() {
instanceLock.lock();
try {
instanceLock.lock();
if (list == null) {
list = stream().collect(Collectors.toUnmodifiableList());
}
Expand All @@ -62,8 +62,8 @@ public List<ITEM> getValue() {
public Stream<ITEM> stream() {
@NonNull Stream<ITEM> retval;
// Ensure thread safety and prevent multiple consumptions of the stream
instanceLock.lock();
try {
instanceLock.lock();
if (list == null) {
if (stream == null) {
throw new IllegalStateException("stream is already consumed");
Expand Down
Loading

0 comments on commit 37089cd

Please sign in to comment.