Class MetapathExpression
- java.lang.Object
-
- gov.nist.secauto.metaschema.core.metapath.MetapathExpression
-
public class MetapathExpression extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MetapathExpression.ResultType
-
Field Summary
Fields Modifier and Type Field Description static MetapathExpression
CONTEXT_NODE
-
Constructor Summary
Constructors Modifier Constructor Description protected
MetapathExpression(String path, IExpression expr)
Construct a new Metapath expression.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static MetapathExpression
compile(String path)
Compiles a Metapath expression string.<T extends IItem>
ISequence<T>evaluate()
Evaluate this Metapath expression without a specific focus.<T extends IItem>
ISequence<T>evaluate(IItem focus)
Evaluate this Metapath expression using the providedfocus
as the initial evaluation context.<T extends IItem>
ISequence<T>evaluate(IItem focus, DynamicContext dynamicContext)
Evaluate this Metapath expression using the providedfocus
as the initial evaluation context.<T> T
evaluateAs(IItem focus, MetapathExpression.ResultType resultType)
Evaluate this Metapath expression using the providedfocus
as the initial evaluation context.<T> T
evaluateAs(IItem focus, MetapathExpression.ResultType resultType, DynamicContext dynamicContext)
Evaluate this Metapath expression using the providedfocus
as the initial evaluation context.<T> T
evaluateAs(MetapathExpression.ResultType resultType)
Evaluate this Metapath expression without a specific focus.protected IExpression
getASTNode()
Get the compiled abstract syntax tree (AST) representation of the Metapath.String
getPath()
Get the original Metapath expression as a string.protected <T> T
toResultType(ISequence<?> sequence, MetapathExpression.ResultType resultType)
Converts the providedsequence
to the requestedresultType
.String
toString()
-
-
-
Field Detail
-
CONTEXT_NODE
@NonNull public static final MetapathExpression CONTEXT_NODE
-
-
Constructor Detail
-
MetapathExpression
protected MetapathExpression(@NonNull String path, @NonNull IExpression expr)
Construct a new Metapath expression.- Parameters:
path
- the Metapath as a stringexpr
- the Metapath as a compiled abstract syntax tree (AST)
-
-
Method Detail
-
compile
@NonNull public static MetapathExpression compile(@NonNull String path)
Compiles a Metapath expression string.- Parameters:
path
- the metapath expression- Returns:
- the compiled expression object
- Throws:
MetapathException
- if an error occurred while compiling the Metapath expression
-
getPath
public String getPath()
Get the original Metapath expression as a string.- Returns:
- the expression
-
getASTNode
@NonNull protected IExpression getASTNode()
Get the compiled abstract syntax tree (AST) representation of the Metapath.- Returns:
- the Metapath AST
-
evaluateAs
@Nullable public <T> T evaluateAs(@NonNull MetapathExpression.ResultType resultType)
Evaluate this Metapath expression without a specific focus. The required result type will be determined by theresultType
argument.- Type Parameters:
T
- the expected result type- Parameters:
resultType
- the type of result to produce- Returns:
- the converted result
- Throws:
TypeMetapathException
- if the provided sequence is incompatible with the requested result typeMetapathException
- if an error occurred during evaluation- See Also:
toResultType(ISequence, ResultType)
-
evaluateAs
@Nullable public <T> T evaluateAs(@Nullable IItem focus, @NonNull MetapathExpression.ResultType resultType)
Evaluate this Metapath expression using the providedfocus
as the initial evaluation context. The required result type will be determined by theresultType
argument.- Type Parameters:
T
- the expected result type- Parameters:
focus
- the outer focus of the expressionresultType
- the type of result to produce- Returns:
- the converted result
- Throws:
TypeMetapathException
- if the provided sequence is incompatible with the requested result typeMetapathException
- if an error occurred during evaluation- See Also:
toResultType(ISequence, ResultType)
-
evaluateAs
@Nullable public <T> T evaluateAs(@NonNull IItem focus, @NonNull MetapathExpression.ResultType resultType, @NonNull DynamicContext dynamicContext)
Evaluate this Metapath expression using the providedfocus
as the initial evaluation context. The specific result type will be determined by theresultType
argument.This variant allow for reuse of a provided
dynamicContext
.- Type Parameters:
T
- the expected result type- Parameters:
focus
- the outer focus of the expressionresultType
- the type of result to producedynamicContext
- the dynamic context to use for evaluation- Returns:
- the converted result
- Throws:
TypeMetapathException
- if the provided sequence is incompatible with the requested result typeMetapathException
- if an error occurred during evaluation- See Also:
toResultType(ISequence, ResultType)
-
toResultType
@Nullable protected <T> T toResultType(@NonNull ISequence<?> sequence, @NonNull MetapathExpression.ResultType resultType)
Converts the providedsequence
to the requestedresultType
.The
resultType
determines the returned result, which is derived from the evaluation result sequence, as follows:- BOOLEAN - the effective boolean result is produced using
FnBoolean.fnBoolean(ISequence)
. - NODE - the first result item in the sequence is returned.
- NUMBER - the sequence is cast to a number using
IDecimalItem.cast(IAnyAtomicItem)
. - SEQUENCE - the evaluation result sequence.
- STRING - the string value of the first result item in the sequence.
- Type Parameters:
T
- the requested return value- Parameters:
sequence
- the sequence to convertresultType
- the type of result to produce- Returns:
- the converted result
- Throws:
TypeMetapathException
- if the provided sequence is incompatible with the requested result type
- BOOLEAN - the effective boolean result is produced using
-
evaluate
@NonNull public <T extends IItem> ISequence<T> evaluate()
Evaluate this Metapath expression without a specific focus.- Type Parameters:
T
- the type of items contained in the resulting sequence- Returns:
- a sequence of Metapath items representing the result of the evaluation
- Throws:
MetapathException
- if an error occurred during evaluation
-
evaluate
@NonNull public <T extends IItem> ISequence<T> evaluate(@Nullable IItem focus)
Evaluate this Metapath expression using the providedfocus
as the initial evaluation context.- Type Parameters:
T
- the type of items contained in the resulting sequence- Parameters:
focus
- the outer focus of the expression- Returns:
- a sequence of Metapath items representing the result of the evaluation
- Throws:
MetapathException
- if an error occurred during evaluation
-
evaluate
@NonNull public <T extends IItem> ISequence<T> evaluate(@Nullable IItem focus, @NonNull DynamicContext dynamicContext)
Evaluate this Metapath expression using the providedfocus
as the initial evaluation context.This variant allow for reuse of a provided
dynamicContext
.- Type Parameters:
T
- the type of items contained in the resulting sequence- Parameters:
focus
- the outer focus of the expressiondynamicContext
- the dynamic context to use for evaluation- Returns:
- a sequence of Metapath items representing the result of the evaluation
- Throws:
MetapathException
- if an error occurred during evaluation
-
-