S
- the script interfacepublic abstract class AbstractScriptWrapper<S> extends java.lang.Object implements ScriptWrapper<S>
Modifier and Type | Field and Description |
---|---|
protected java.util.Map<java.lang.String,java.lang.Object> |
additionalHelpers
The additional helpers for the scripts.
|
protected ScriptContext |
context
The script context.
|
protected java.util.List<ScriptExceptionListener> |
exListeners
The script exception listeners.
|
protected boolean |
firstException
True for the first exception.
|
protected boolean |
hasCustomHelper
True if there is a custom Helper.
|
protected ScriptHelper |
helper
The script helper.
|
protected int |
importLines
The number of specific import lines specified in the initial script.
|
protected ScriptLogger |
logger
The script logger.
|
protected int |
offset
The offset from the beginning of the script text content to the text effectively defined in the Script file.
|
protected java.lang.String |
optimLevel
The optimization level, set to
ScriptWrapper.OPTIM_LEVEL_DEFAULT by default. |
protected java.lang.String |
scriptContent
The script text content.
|
protected ScriptSource |
source
The script source.
|
protected short |
VARIABLES_DECL_AFTER_CLASS_DECL
Specifies the the variables declarations must be positioned after the class declaration in the script.
|
protected short |
VARIABLES_DECL_BEFORE_CLASS_DECL
Specifies the the variables declarations must be positioned before the class declaration in the script.
|
MODE_BLOCKING, MODE_NON_BLOCKING, OPTIM_LEVEL_DEFAULT, OPTIM_LEVEL_MAX, OPTIM_LEVEL_MIN
Constructor and Description |
---|
AbstractScriptWrapper() |
Modifier and Type | Method and Description |
---|---|
void |
addAdditionalHelper(java.lang.String name,
java.lang.Object helper)
Add an additional helper instance which will be usable in the script.
|
void |
addExceptionListener(ScriptExceptionListener listener)
Set the listener which will be fired for script exceptions.
|
void |
addImports(java.lang.Class<?>... imports)
Add additional custom import declarations for the scripts.
|
void |
addImports(java.util.Set<java.lang.String> imports)
Add additional custom import declarations for the scripts.
|
void |
addImports(java.lang.String... imports)
Add additional custom import declarations for the scripts.
|
void |
clearAdditionalHelpers()
Clear the additional helper instances.
|
void |
clearImports()
Clear the import declarations.
|
protected java.lang.Class<?> |
convertPrimitiveArgument(java.lang.Class<?> clazz)
Convert a primitive argument.
|
int |
countImportLines()
Return the number of import lines.
|
protected ScriptContext |
createScriptContext()
Create the script context.
|
protected java.lang.Object |
createScriptObject() |
protected abstract java.lang.Object |
createScriptObject(java.lang.String scriptContent)
Create the script instance.
|
void |
err(java.lang.String message,
char errorType,
java.lang.Throwable e)
Log an error.
|
java.util.Map<java.lang.String,java.lang.Object> |
getAdditionalHelpers()
Return the additional helpers.
|
java.lang.ClassLoader |
getClassLoader()
Return the ClassLoader.
|
protected abstract ScriptException<S> |
getCompileException(java.lang.Exception e)
Return a proper exception from a Grooby compile-time exception, with the correct file and line number.
|
protected java.lang.String |
getContextClassPath()
Return the script context classpath.
|
protected java.util.Set<java.lang.String> |
getCustomImports()
Return the additional custom import declarations for the scripts.
|
protected java.lang.String |
getDefaultContent()
Return the default content lines at the start of the script.Return null by default.
|
protected java.lang.String |
getDefaultDeclaration()
Return the default declaration lines at the start of the script.
|
protected java.lang.String |
getDefaultImports()
Return the default import lines at the start of the script.
|
protected java.lang.String |
getEnd()
Return the lines at the end of the script.
|
java.util.List<ScriptExceptionListener> |
getExceptionListeners()
Return the listener which will be fired for script exceptions.
|
short |
getExecutionMode()
Return the execution mode.
|
java.lang.String |
getFilename()
Return the script filename.
|
protected java.lang.String |
getHelperClassPath()
Return the script helper classpath.
|
protected CachedMethodKey |
getInvocableMethodKey(java.lang.String name,
java.lang.Class<?>[] argTypes)
Return the key for the invocable method with a specified name and arguments.
|
int |
getLineNumber(int lineNumber)
Return the effective line number of a line detected in the script runtime.
|
protected java.lang.String |
getLoggerClassPath()
Return the script logger classpath.
|
int |
getOffset()
Return the script offset.
|
java.lang.String |
getOptimizationLevel()
Return the default optimization level.
|
protected ScriptLogger |
getPreferredLogger()
Return the preferred logger.
|
S |
getRawScript()
Return the raw script.
|
java.lang.String |
getScriptClassName()
Return the script class name.
|
java.lang.String |
getScriptContent()
Return the script text content.
|
ScriptContext |
getScriptContext()
Return the script context.
|
java.lang.Class<S> |
getScriptInterface()
Return the class of the script interface.
|
ScriptProxy<S> |
getScriptProxy(S script)
Return the script proxy.
|
protected java.lang.reflect.Method |
getSingletonMethod()
Return the unique method declared in the script.
|
ScriptSource |
getSource()
Return the script source.
|
protected short |
getVariablesDeclarationsPosition()
Return the position of the variables declaration.
|
boolean |
hasAdditionalHelpers()
Return true the there are additional helper instances.
|
boolean |
hasScriptHelper()
Return true if there is a script helper.
|
boolean |
hasSingletonMethod()
Return true if there is a singleton method.
|
S |
installScript(java.io.File file)
Create the script.
|
S |
installScript(java.io.File file,
java.lang.ClassLoader loader)
Create the script.
|
S |
installScript(ScriptSource source,
java.lang.ClassLoader loader)
Create the script.
|
S |
installScript(java.lang.String content)
Create the script.
|
boolean |
isLoggingExceptions()
Return true if the wrapper must log exceptions.
|
void |
logExceptions(boolean isLoggingExceptions)
Set if the wrapper must log exceptions.
|
protected abstract boolean |
parseScript(ScriptSource source,
ScriptContent content)
Parse the script content.
|
S |
reInstallScript()
Reinstall an already installed script.
|
protected S |
reInstallScript(java.lang.String scriptContent,
boolean isSilent)
Reinstall an already installed script.
|
protected S |
reInstallScript(java.lang.String scriptContent,
boolean inDebug,
boolean isSilent)
Reinstall an already installed script.
|
boolean |
removeExceptionListener(ScriptExceptionListener listener)
Remove a previously added exception listener.
|
protected java.lang.String |
removeTabulations(java.lang.String message)
Remove tabulations from an error message
|
void |
setClassLoader(java.lang.ClassLoader loader)
Set the ClassLoader.
|
void |
setExecutionMode(short mode)
Set the execution mode.
|
void |
setOptimizationLevel(java.lang.String optimLevel)
Set the optimization level.
|
void |
setScriptContext(ScriptContext context)
Set the script context.
|
void |
setScriptLogger(ScriptLogger logger)
Set the script logger.
|
void |
startMethod()
Start a script method.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
__step__, err, getLineNumber, getMIME, getScript, getScriptException, getScriptExtension, getScriptProxy, getScriptProxyHandler, installScript, installScript, installScript, installScript, isDebugging, isDebugSupported, isInDebugSession, isLibAvailable, isLibAvailable, isMultiImplementSupported, isSingletonMethodEnabled, resetWrapperState
cacheInvocableMethods, getInvocableMethods, getInvocableMethodsByNames, hasInvocableMethod, invokeMethod, invokeMethod, isAutoCachingInvocableMethods, isInvocableByName, isInvocableMethodsEnabled, setAutoCacheInvocableMethods
protected final short VARIABLES_DECL_BEFORE_CLASS_DECL
protected final short VARIABLES_DECL_AFTER_CLASS_DECL
protected ScriptContext context
protected ScriptHelper helper
protected java.lang.String scriptContent
protected int offset
protected int importLines
protected ScriptSource source
protected boolean firstException
protected boolean hasCustomHelper
protected final java.util.List<ScriptExceptionListener> exListeners
protected java.util.Map<java.lang.String,java.lang.Object> additionalHelpers
protected java.lang.String optimLevel
ScriptWrapper.OPTIM_LEVEL_DEFAULT
by default.protected ScriptLogger logger
public ScriptSource getSource()
getSource
in interface ScriptWrapper<S>
public void setExecutionMode(short mode)
setExecutionMode
in interface ScriptWrapper<S>
mode
- the execution modepublic short getExecutionMode()
getExecutionMode
in interface ScriptWrapper<S>
public java.lang.String getOptimizationLevel()
getOptimizationLevel
in interface ScriptWrapper<S>
public void setOptimizationLevel(java.lang.String optimLevel)
setOptimizationLevel
in interface ScriptWrapper<S>
optimLevel
- the optimization levelpublic void setClassLoader(java.lang.ClassLoader loader)
setClassLoader
in interface ScriptWrapper<S>
loader
- the ClassLoaderpublic java.lang.ClassLoader getClassLoader()
getClassLoader
in interface ScriptWrapper<S>
protected ScriptContext createScriptContext()
DefaultScriptContext
.public boolean hasScriptHelper()
hasScriptHelper
in interface ScriptWrapper<S>
public void addImports(java.util.Set<java.lang.String> imports)
addImports
in interface ScriptWrapper<S>
imports
- the additional custom import declarationspublic void addImports(java.lang.String... imports)
addImports
in interface ScriptWrapper<S>
imports
- the additional custom import declarationspublic void addImports(java.lang.Class<?>... imports)
addImports
in interface ScriptWrapper<S>
imports
- the additional custom import declarationspublic void clearImports()
clearImports
in interface ScriptWrapper<S>
public void addAdditionalHelper(java.lang.String name, java.lang.Object helper)
addAdditionalHelper
in interface ScriptWrapper<S>
name
- the helper instance namehelper
- the helper instancepublic boolean hasAdditionalHelpers()
hasAdditionalHelpers
in interface ScriptWrapper<S>
public void clearAdditionalHelpers()
clearAdditionalHelpers
in interface ScriptWrapper<S>
protected java.util.Set<java.lang.String> getCustomImports()
public java.util.Map<java.lang.String,java.lang.Object> getAdditionalHelpers()
getAdditionalHelpers
in interface ScriptWrapper<S>
protected java.lang.reflect.Method getSingletonMethod()
public boolean hasSingletonMethod()
hasSingletonMethod
in interface ScriptWrapper<S>
public void logExceptions(boolean isLoggingExceptions)
logExceptions
in interface ScriptWrapper<S>
isLoggingExceptions
- true if the wrapper must log exceptionspublic boolean isLoggingExceptions()
isLoggingExceptions
in interface ScriptWrapper<S>
protected java.lang.String getContextClassPath()
protected java.lang.String getHelperClassPath()
protected java.lang.String getLoggerClassPath()
public java.lang.String getFilename()
getFilename
in interface ScriptWrapper<S>
public java.lang.String getScriptClassName()
getFilename()
by default.getScriptClassName
in interface ScriptWrapper<S>
protected CachedMethodKey getInvocableMethodKey(java.lang.String name, java.lang.Class<?>[] argTypes)
name
- the method nameargTypes
- the method argumentsprotected java.lang.Class<?> convertPrimitiveArgument(java.lang.Class<?> clazz)
clazz
- the classpublic java.lang.Class<S> getScriptInterface()
getScriptInterface
in interface ScriptWrapper<S>
public S getRawScript()
ScriptWrapper.getScript()
instead if you want to be able to catch exceptions.getRawScript
in interface ScriptWrapper<S>
public ScriptProxy<S> getScriptProxy(S script)
ScriptExceptionListener
s if
isLoggingExceptions()
returns true.getScriptProxy
in interface ScriptWrapper<S>
script
- the scriptpublic void setScriptLogger(ScriptLogger logger)
setScriptLogger
in interface ScriptWrapper<S>
logger
- the script loggerpublic void setScriptContext(ScriptContext context)
setScriptContext
in interface ScriptWrapper<S>
context
- the script contextpublic java.lang.String getScriptContent()
getScriptContent
in interface ScriptWrapper<S>
public ScriptContext getScriptContext()
getScriptContext
in interface ScriptWrapper<S>
protected java.lang.String getDefaultDeclaration()
"class GroovyClass implements " + getScriptInterface().getName() + {\n" + " ScriptContext context;\n"
protected java.lang.String getDefaultContent()
"public void init(ScriptContext ctx) {\n" + "context = ctx;\n" + " }\n";
protected java.lang.String getDefaultImports()
"import org.scripthelper.groovy.*;\n" + "import org.scripthelper.context.ScriptContext;\n";
protected java.lang.String getEnd()
public void startMethod()
startMethod
in interface ScriptWrapper<S>
protected java.lang.Object createScriptObject() throws java.lang.Exception
java.lang.Exception
protected abstract java.lang.Object createScriptObject(java.lang.String scriptContent) throws java.lang.Exception
scriptContent
- the script contentjava.lang.Exception
- if the script instance coult not be createdprotected short getVariablesDeclarationsPosition()
public S installScript(java.lang.String content)
installScript
in interface ScriptWrapper<S>
content
- the script contentpublic S installScript(java.io.File file)
installScript
in interface ScriptWrapper<S>
file
- the script filepublic S installScript(java.io.File file, java.lang.ClassLoader loader)
installScript
in interface ScriptWrapper<S>
file
- the script fileloader
- the ClassLoaderpublic S installScript(ScriptSource source, java.lang.ClassLoader loader)
installScript
in interface ScriptWrapper<S>
source
- the script sourceloader
- the ClassLoaderpublic S reInstallScript()
reInstallScript
in interface ScriptWrapper<S>
protected S reInstallScript(java.lang.String scriptContent, boolean isSilent)
scriptContent
- the script contentisSilent
- true if no exception should be emittedprotected S reInstallScript(java.lang.String scriptContent, boolean inDebug, boolean isSilent)
scriptContent
- the script contentinDebug
- true in Debug modeisSilent
- true if no exception should be emittedprotected ScriptLogger getPreferredLogger()
public void err(java.lang.String message, char errorType, java.lang.Throwable e)
err
in interface ScriptWrapper<S>
message
- the error messageerrorType
- the error typee
- the ThrowableErrorType
public void addExceptionListener(ScriptExceptionListener listener)
addExceptionListener
in interface ScriptWrapper<S>
listener
- the listenerpublic boolean removeExceptionListener(ScriptExceptionListener listener)
removeExceptionListener
in interface ScriptWrapper<S>
listener
- the listenerpublic java.util.List<ScriptExceptionListener> getExceptionListeners()
getExceptionListeners
in interface ScriptWrapper<S>
protected abstract ScriptException<S> getCompileException(java.lang.Exception e)
e
- the initial Exceptionprotected java.lang.String removeTabulations(java.lang.String message)
message
- the messagepublic int getOffset()
getOffset
in interface ScriptWrapper<S>
public int countImportLines()
countImportLines
in interface ScriptWrapper<S>
public int getLineNumber(int lineNumber)
getLineNumber
in interface ScriptWrapper<S>
lineNumber
- the line numberprotected abstract boolean parseScript(ScriptSource source, ScriptContent content)
source
- the script sourcecontent
- the content objectCopyright © 2019-2024 Herve Girod. All Rights Reserved. Documentation and source under the BSD licence