Interface Evaluator
- All Known Subinterfaces:
GenerationContext
public interface Evaluator
Evaluator definition for templating engines.
- Since:
- 4.0.17
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Variable name for classloader instance.static final String
Name of specific variable referring to global properties.static final String
Name of a specific variable holding a mathematical context.static final String
Variable name for the list of tags (comma separated) to limit the generation to resolutions tagged with one of the specified tags. -
Method Summary
Modifier and TypeMethodDescriptiongetAttribute
(Object instance, String attributeName) Reads the value for the named attribute from the given instance.Provides the current context object.Provides the defined default expression.Provides the currently defined locale.A locale key, default value isgetLocale()
.getLanguage().toUpperCase()}getOut()
Provides a writer to the output.getStack()
Provides a textual representation of the current evaluation stack.Looks up a variable based on the given type and name and provides a printable template initialized with the given parameters.The currently evaluated stack element as string - for debugging.getVariableValue
(String variableName) Looks up the value stored for the variable having the given name.void
Includes something in the output.invokeMethod
(Object instance, String methodName, List<Object> args) Invokes the named method on the given instance.boolean
Indicates, whether this evaluation is operating in debugging mode.void
Logs a debug message.void
Logs an error message giving a line and column to locate the cause within the template.void
Logs an error message giving a line and column to locate the cause within the template.void
Logs an error message.void
Logs an error message and a trace.void
Logs an information message.void
logWarning
(String message) Logs a warning message.Parses the given source and creates an evaluatable template.Parses the given source text and creates an evaluatable template.Provides and pops the current context from this evaluation.void
Instructs to evaluate and print the given template.void
Print an object instance to theoutput
.void
pushContext
(Context context) Set a new top context.pushContext
(String name) Will push a new context.pushContext
(String name, Object target) Will push a new context and set the target object as #this.pushContext
(String name, String info) Will push a new context and an info text on the stackResolves a firstspirit reference by the given parameters corresponding to the definition of CMS_REF.void
setDefaultExpression
(Object value) Sets the default expression to be used for output when some value evaluates to null or undefined.void
setErrorOut
(PrintWriter out) Sets the error output writer.void
setErrorOut
(Writer out) Shortcut forsetErrorOut(new PrintWriter(out))
.void
Defines the locale to be used for further evaluation.void
setLocaleKey
(String value) Defines the locale key to be used for further evaluation.void
setMaxStackSize
(int value) Defines the maximum stack size for evaluation.void
Sets the writer for the output.void
setVariableValue
(String variableName, Object value) Stores the given value for the variable with the given name.
-
Field Details
-
MATH_CONTEXT_VARIABLE
Name of a specific variable holding a mathematical context.- Since:
- 4.1.16
- See Also:
-
GLOBAL_VARIABLE
Name of specific variable referring to global properties.- Since:
- 4.1.16
- See Also:
-
CLASSLOADER_VARIABLE
Variable name for classloader instance.- Since:
- 4.2.211
- See Also:
-
RESOLUTION_TAGS_VARIABLE
Variable name for the list of tags (comma separated) to limit the generation to resolutions tagged with one of the specified tags.- Since:
- 5.2.210803
- See Also:
-
-
Method Details
-
getVariableValue
Looks up the value stored for the variable having the given name.- Parameters:
variableName
- The variable's name.- Returns:
- The stored value.
- Since:
- 4.0.17
-
setVariableValue
Stores the given value for the variable with the given name.- Parameters:
variableName
- The variable's name.value
- The value to be stored.- Since:
- 4.0.17
-
resolveReference
Resolves a firstspirit reference by the given parameters corresponding to the definition of CMS_REF. If the reference was not resolved, an error message will be logged and an empty result will be returned.- Parameters:
params
- A list of parameters.namedParams
- A list of named parameters.- Returns:
- The referenced element.
- Throws:
Exception
- Since:
- 4.0.17
-
include
Includes something in the output.- Parameters:
type
- recognized types are:"file", "url", "jar"
toInclude
- used to determine the source, e.g. treated as file name,File
object, ...params
- recognized parameter keys are:"encoding", "parse", "info"
- Throws:
IOException
- if including the source failed.- Since:
- 4.0.17
-
getAttribute
Reads the value for the named attribute from the given instance.- Parameters:
instance
- The instance.attributeName
- The name of the attribute.- Returns:
- The attribute's value.
- Throws:
Exception
- if accessing the attribute failed for some reason.- Since:
- 4.0.17
-
invokeMethod
Invokes the named method on the given instance.- Parameters:
instance
- The instance.methodName
- The name of the method.args
- Arguments for the method to be invoked.- Returns:
- The resulting return value from the method invocation.
- Throws:
Exception
- if invoking the method failed for some reason.- Since:
- 4.0.17
-
print
Print an object instance to theoutput
.- Parameters:
value
- object- Throws:
IOException
- Since:
- 4.0.17
-
getContext
Context getContext()Provides the current context object.- Returns:
- The context.
- Since:
- 4.0.17
-
setLocale
Defines the locale to be used for further evaluation.- Parameters:
value
- The locale.- Since:
- 4.2
-
getLocale
Locale getLocale()Provides the currently defined locale.- Returns:
- The locale.
- Since:
- 4.0.17
-
getLocaleKey
String getLocaleKey()A locale key, default value isgetLocale()
.getLanguage().toUpperCase()}- Since:
- 4.0.17
- See Also:
-
setLocaleKey
Defines the locale key to be used for further evaluation.- Parameters:
value
- The locale key.- Since:
- 4.2
- See Also:
-
logError
Logs an error message.- Parameters:
message
- The error message.- Since:
- 4.0.17
-
logError
Logs an error message and a trace.- Parameters:
message
- The error message.throwable
- A throwable.- Since:
- 4.0.17
-
logError
Logs an error message giving a line and column to locate the cause within the template.- Parameters:
line
- The line.col
- The coumn.message
- The error message.- Since:
- 4.0.17
-
logError
Logs an error message giving a line and column to locate the cause within the template. Additionally gives a throwable for printing a trace.- Parameters:
line
- The line.col
- The coumn.message
- The error message.t
- A throwable.- Since:
- 4.0.17
-
logWarning
Logs a warning message.- Parameters:
message
- The warning message.- Since:
- 4.0.17
-
logInfo
Logs an information message.- Parameters:
message
- The information message.- Since:
- 4.0.17
-
logDebug
Logs a debug message.- Parameters:
message
- The debug message.- Since:
- 4.0.17
-
pushContext
Will push a new context and an info text on the stack- Parameters:
name
- the name of the new contextinfo
- the text wich is put on the context stack- Returns:
- the new top context
- Since:
- 4.0.17
- See Also:
-
pushContext
Will push a new context. SeepushContext(Context)
for further informations.- Parameters:
name
- the name of the new context- Returns:
- the new top context
- Since:
- 4.0.17
- See Also:
-
pushContext
Will push a new context and set the target object as #this.- Parameters:
name
- The name of the new context.target
- The target object the context operates on.- Returns:
- The new top context.
- Since:
- 5.0.100
- See Also:
-
pushContext
Set a new top context. The implementation will callContext.setParentContext(Context)
on the providedcontext object.
Always use this in atry .. finally
block:evaluator.pushContext(myContext) try { ... } finally { evaluator.popContext(); }
- Parameters:
context
- the new top context,null
is not allowed- Since:
- 4.0.17
- See Also:
-
popContext
Context popContext()Provides and pops the current context from this evaluation.- Returns:
- the actual top context
- Since:
- 4.0.17
- See Also:
-
getOut
Writer getOut()Provides a writer to the output.- Returns:
- A writer.
- Since:
- 4.0.17
-
setOut
Sets the writer for the output.- Parameters:
out
- A writer.- Since:
- 4.0.17
-
setErrorOut
Shortcut forsetErrorOut(new PrintWriter(out))
.- Parameters:
out
- A writer.- Since:
- 4.0.17
-
setErrorOut
Sets the error output writer.- Parameters:
out
- A writer.- Since:
- 4.0.17
-
print
Instructs to evaluate and print the given template.- Parameters:
template
- A template.- Throws:
IOException
- Since:
- 4.0.17
-
getTemplate
Looks up a variable based on the given type and name and provides a printable template initialized with the given parameters.- Parameters:
type
- The template type.name
- The variable name.params
- The parameters.- Returns:
- A template or null.
- Throws:
IOException
- Since:
- 4.0.18
-
getStack
String getStack()Provides a textual representation of the current evaluation stack.- Returns:
- The dumped stack.
- Since:
- 4.0.17
-
getTopStackElement
String getTopStackElement()The currently evaluated stack element as string - for debugging.- Returns:
- The top stack element.
- Since:
- 5.0.204
-
setDefaultExpression
Sets the default expression to be used for output when some value evaluates to null or undefined.- Parameters:
value
- The default expression.- Since:
- 4.0.17
-
getDefaultExpression
Object getDefaultExpression()Provides the defined default expression.- Returns:
- The expression.
- Since:
- 4.0.17
-
setMaxStackSize
void setMaxStackSize(int value) Defines the maximum stack size for evaluation.- Parameters:
value
- The maximum stack size.- Since:
- 4.0.17
-
parse
Parses the given source text and creates an evaluatable template.- Parameters:
source
- The source.- Returns:
- A template.
- Since:
- 4.0.17
-
parse
Parses the given source and creates an evaluatable template.- Parameters:
source
- The source.- Returns:
- A template.
- Throws:
IOException
- Since:
- 4.0.17
-
isDebugging
boolean isDebugging()Indicates, whether this evaluation is operating in debugging mode.- Returns:
true
, if debugging.- Since:
- 4.0.17
-