org.apache.tools.ant.util

Class ScriptRunnerBase

public abstract class ScriptRunnerBase extends 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
voidaddBean(String key, Object bean)
Add a single object into the script context.
voidaddBeans(Map dictionary)
Add a list of named objects to the list to be exported to the script
voidaddText(String text)
Set the script text.
voidbindToComponent(ProjectComponent component)
Bind the runner to a project component.
voidbindToComponentMinimum(ProjectComponent component)
Bind the runner to a project component.
protected voidcheckLanguage()
Check if the language attribute is set.
voidclearScript()
Clear the current script text content.
abstract ObjectevaluateScript(String execName)
Evalulate the script.
abstract voidexecuteScript(String execName)
Do the work.
protected MapgetBeans()
Get the beans used for the script.
booleangetKeepEngine()
Get the keep engine attribute.
StringgetLanguage()
Get the script language
abstract StringgetManagerName()
Get the name of the manager prefix used for this scriptrunner.
ProjectgetProject()
Get the project for this runner.
StringgetScript()
Get the current script text content.
protected ClassLoadergetScriptClassLoader()
Get the classloader used to load the script engine.
protected ClassLoaderreplaceContextLoader()
Replace the current context classloader with the script context classloader.
protected voidrestoreContextLoader(ClassLoader origLoader)
Restore the context loader with the original context classloader. script context loader.
voidsetKeepEngine(boolean keepEngine)
Whether to keep the script engine between calls.
voidsetLanguage(String language)
Defines the language (required).
voidsetProject(Project project)
Set the project for this runner.
voidsetScriptClassLoader(ClassLoader classLoader)
Set the script classloader.
voidsetSrc(File file)
Load the script from an external file; optional.
abstract booleansupportsLanguage()
Check if a script engine can be created for this language.

Method Detail

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.

Throws: BuildException if it is not.

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.