org.apache.tools.ant.util

Class ScriptRunnerBase

Known Direct Subclasses:
JavaxScriptRunner, ScriptRunner

public abstract class ScriptRunnerBase
extends java.lang.Object

This is a common abstract base case for script runners. These classes need to implement executeScript, evaluateScript and supportsLanguage.
Since:
Ant 1.7.0

Method Summary

void
addBean(String key, Object bean)
Add a single object into the script context.
void
addBeans(Map dictionary)
Add a list of named objects to the list to be exported to the script
void
addText(String text)
Set the script text.
void
bindToComponent(ProjectComponent component)
Bind the runner to a project component.
void
bindToComponentMinimum(ProjectComponent component)
Bind the runner to a project component.
protected void
checkLanguage()
Check if the language attribute is set.
void
clearScript()
Clear the current script text content.
abstract Object
evaluateScript(String execName)
Evalulate the script.
abstract void
executeScript(String execName)
Do the work.
protected Map
getBeans()
Get the beans used for the script.
boolean
getKeepEngine()
Get the keep engine attribute.
String
getLanguage()
Get the script language
abstract String
getManagerName()
Get the name of the manager prefix used for this scriptrunner.
Project
getProject()
Get the project for this runner.
String
getScript()
Get the current script text content.
protected ClassLoader
getScriptClassLoader()
Get the classloader used to load the script engine.
protected ClassLoader
replaceContextLoader()
Replace the current context classloader with the script context classloader.
protected void
restoreContextLoader(ClassLoader origLoader)
Restore the context loader with the original context classloader.
void
setKeepEngine(boolean keepEngine)
Whether to keep the script engine between calls.
void
setLanguage(String language)
Defines the language (required).
void
setProject(Project project)
Set the project for this runner.
void
setScriptClassLoader(ClassLoader classLoader)
Set the script classloader.
void
setSrc(File file)
Load the script from an external file; optional.
abstract boolean
supportsLanguage()
Check if a script engine can be created for this language.

Method Details

addBean

public void addBean(String key,
                    Object bean)
Add a single object into the script context.
Parameters:
key - the name in the context this object is to stored under.
bean - the object to be stored in the script context.

addBeans

public void addBeans(Map dictionary)
Add a list of named objects to the list to be exported to the script
Parameters:
dictionary - a map of objects to be placed into the script context indexed by String names.

addText

public void addText(String text)
Set the script text.
Parameters:
text - a component of the script text to be added.

bindToComponent

public void bindToComponent(ProjectComponent component)
Bind the runner to a project component. Properties, targets and references are all added as beans; project is bound to project, and self to the component.
Parameters:
component - to become self

bindToComponentMinimum

public void bindToComponentMinimum(ProjectComponent component)
Bind the runner to a project component. The project and self are the only beans set.
Parameters:
component - to become self

checkLanguage

protected void checkLanguage()
Check if the language attribute is set.

clearScript

public void clearScript()
Clear the current script text content.

evaluateScript

public abstract Object evaluateScript(String execName)
Evalulate the script.
Parameters:
execName - the name that will be passed to BSF for this script execution.
Returns:
the result of evalulating the script.

executeScript

public abstract void executeScript(String execName)
Do the work.
Parameters:
execName - the name that will be passed to BSF for this script execution.

getBeans

protected Map getBeans()
Get the beans used for the script.
Returns:
the map of beans.

getKeepEngine

public boolean getKeepEngine()
Get the keep engine attribute.
Returns:
the attribute.

getLanguage

public String getLanguage()
Get the script language
Returns:
the script language

getManagerName

public abstract String getManagerName()
Get the name of the manager prefix used for this scriptrunner.
Returns:
the prefix string.

getProject

public Project getProject()
Get the project for this runner.
Returns:
the project.

getScript

public String getScript()
Get the current script text content.
Returns:
the script text.

getScriptClassLoader

protected ClassLoader getScriptClassLoader()
Get the classloader used to load the script engine.
Returns:
the classloader.

replaceContextLoader

protected ClassLoader replaceContextLoader()
Replace the current context classloader with the script context classloader.
Returns:
the current context classloader.

restoreContextLoader

protected void restoreContextLoader(ClassLoader origLoader)
Restore the context loader with the original context classloader. script context loader.
Parameters:
origLoader - the original context classloader.

setKeepEngine

public void setKeepEngine(boolean keepEngine)
Whether to keep the script engine between calls.
Parameters:
keepEngine - if true, keep the engine.

setLanguage

public void setLanguage(String language)
Defines the language (required).
Parameters:
language - the scripting language name for the script.

setProject

public void setProject(Project project)
Set the project for this runner.
Parameters:
project - the project.

setScriptClassLoader

public void setScriptClassLoader(ClassLoader classLoader)
Set the script classloader.
Parameters:
classLoader - the classloader to use.

setSrc

public void setSrc(File file)
Load the script from an external file; optional.
Parameters:
file - the file containing the script source.

supportsLanguage

public abstract boolean supportsLanguage()
Check if a script engine can be created for this language.
Returns:
true if a script engine can be created, false otherwise.