public abstract class Scope
extends java.lang.Object
SymbolResolver to partition
library objects and user variables registered by clients of the expression
engine. Whenever a worker library or user variable is registered, a
Scope instance must be provided by the registering client.
This instance is associated with the library or variable for the lifetime
of the resolver.
When and expression is parsed and compiled, the resolver's current scope
is requested via SymbolResolver.getCurrentScope(). The instance of
Scope returned by that call is used as a key to resolve
library and variable references as they are encountered in the expression.
Only references contained within the current scope or within an enclosing
scope (or within its enclosing scope, and so on...) are correctly
resolved.
Scope is also used when resetting the values of variables in a variable pool.
| Modifier and Type | Class and Description |
|---|---|
private static class |
Scope.ScopeState
A scope state, kept for each resolver.
|
| Modifier and Type | Field and Description |
|---|---|
private static java.util.function.Function<SymbolResolver,Scope.ScopeState> |
NEW_STATE
Function to create a new
Scope.ScopeState for a resolver. |
private java.util.Map<SymbolResolver,Scope.ScopeState> |
resolverState
A map of the scope state for each resolver.
|
private SymbolResolver |
singleResolver
The resolver instance, used as long as only one resolver associates this scope.
|
private Scope.ScopeState |
singleState
Singleton scope state.
|
| Constructor and Description |
|---|
Scope() |
| Modifier and Type | Method and Description |
|---|---|
abstract Scope |
getEnclosingScope()
This method must return the object which represents the scope context
which encloses this scope, if this scope is nested within a broader
scope.
|
java.util.Map<java.lang.String,java.lang.Object> |
getLibraries(SymbolResolver sr,
boolean create)
Resolve the
Scope.ScopeState.libraries map for the specified resolver. |
java.util.Map<java.lang.Class<?>,java.lang.String> |
getLibraryClasses(SymbolResolver sr,
boolean create)
Resolve the
Scope.ScopeState.libraryClasses map for the specified resolver. |
java.util.Map<java.lang.Class<?>,java.lang.Object> |
getLibsByClass(SymbolResolver sr,
boolean create)
Resolve the
Scope.ScopeState.libsByClass map for the specified resolver. |
private Scope.ScopeState |
getResolverState(SymbolResolver sr)
Calculate the
Scope.ScopeState associated with the given resolver. |
Variable[] |
getVariableList(SymbolResolver sr)
Resolve the
Scope.ScopeState.variableList array for the specified resolver. |
java.util.Map<java.lang.String,Variable> |
getVariables(SymbolResolver sr,
boolean create)
Resolve the
Scope.ScopeState.variableList map for the specified resolver. |
private static final java.util.function.Function<SymbolResolver,Scope.ScopeState> NEW_STATE
Scope.ScopeState for a resolver.private java.util.Map<SymbolResolver,Scope.ScopeState> resolverState
null as long as only one resolver uses
this scope state.private Scope.ScopeState singleState
resolverState will be initialized and used.private SymbolResolver singleResolver
resolverState
is used.public abstract Scope getEnclosingScope()
null if this scope
represents the broadest scope available.public java.util.Map<java.lang.String,java.lang.Object> getLibraries(SymbolResolver sr, boolean create)
Scope.ScopeState.libraries map for the specified resolver.sr - The resolver which uses this scope.create - Flag indicating to create a new instance if one is not created yet.Scope.ScopeState.libraries map.public java.util.Map<java.lang.String,Variable> getVariables(SymbolResolver sr, boolean create)
Scope.ScopeState.variableList map for the specified resolver.sr - The resolver which uses this scope.create - Flag indicating to create a new instance if one is not created yet.Scope.ScopeState.variableList map.public java.util.Map<java.lang.Class<?>,java.lang.Object> getLibsByClass(SymbolResolver sr, boolean create)
Scope.ScopeState.libsByClass map for the specified resolver.sr - The resolver which uses this scope.create - Flag indicating to create a new instance if one is not created yet.Scope.ScopeState.libsByClass map.public java.util.Map<java.lang.Class<?>,java.lang.String> getLibraryClasses(SymbolResolver sr, boolean create)
Scope.ScopeState.libraryClasses map for the specified resolver.sr - The resolver which uses this scope.create - Flag indicating to create a new instance if one is not created yet.Scope.ScopeState.libraryClasses map.public Variable[] getVariableList(SymbolResolver sr)
Scope.ScopeState.variableList array for the specified resolver.sr - The resolver which uses this scope.Scope.ScopeState.variableList array.private Scope.ScopeState getResolverState(SymbolResolver sr)
Scope.ScopeState associated with the given resolver.
If singleState is not yet set or the singleResolver is the same as the received one,
keep the 'singleton' mode and use singleResolver and singleState.
Otherwise, switch to a dynamic approach where resolverState map keeps the scope state for each
resolver.
sr - The resolve which uses this scope.