public class ScriptFactory
extends java.lang.Object
Creates Scripts. To create a JEXL Script, pass
valid JEXL syntax to the static createScript() method:
String jexl = "y = x * 12 + 44; y = y * 4;"; Script script = ScriptFactory.createScript( jexl );
When an Script is created, the JEXL syntax is
parsed and verified.
| Modifier and Type | Field and Description |
|---|---|
protected static ScriptFactory |
factory
ScriptFactory is a singleton and this is the private
instance fufilling that pattern.
|
protected static org.apache.commons.logging.Log |
log
The Log to which all ScriptFactory messages will be logged.
|
protected static Parser |
parser
The singleton ScriptFactory also holds a single instance of
Parser. |
| Modifier | Constructor and Description |
|---|---|
private |
ScriptFactory()
Private constructor, the single instance is always obtained
with a call to getInstance().
|
| Modifier and Type | Method and Description |
|---|---|
private java.lang.String |
cleanScript(java.lang.String script) |
protected Script |
createNewScript(java.lang.String scriptText)
Creates a new Script based on the string.
|
static Script |
createScript(java.io.File scriptFile)
Creates a Script from a
File containing valid JEXL syntax. |
static Script |
createScript(java.lang.String scriptText)
Creates a Script from a String containing valid JEXL syntax.
|
static Script |
createScript(java.net.URL scriptUrl)
Creates a Script from a
URL containing valid JEXL syntax. |
protected static ScriptFactory |
getInstance()
Returns the single instance of ScriptFactory.
|
private static java.lang.String |
readerToString(java.io.BufferedReader reader)
Read a buffered reader into a StringBuffer and return a String with
the contents of the reader.
|
protected static org.apache.commons.logging.Log log
protected static Parser parser
Parser. When parsing expressions, ScriptFactory
synchronizes on Parser.protected static ScriptFactory factory
private ScriptFactory()
protected static ScriptFactory getInstance()
public static Script createScript(java.lang.String scriptText) throws java.lang.Exception
scriptText - A String containing valid JEXL syntaxScript which can be executed with a
JexlContext.java.lang.Exception - An exception can be thrown if there is a
problem parsing the script.public static Script createScript(java.io.File scriptFile) throws java.lang.Exception
File containing valid JEXL syntax.
This method parses the script and validates the syntax.scriptFile - A File containing valid JEXL syntax.
Must not be null. Must be a readable file.Script which can be executed with a
JexlContext.java.lang.Exception - An exception can be thrown if there is a problem
parsing the script.public static Script createScript(java.net.URL scriptUrl) throws java.lang.Exception
URL containing valid JEXL syntax.
This method parses the script and validates the syntax.scriptUrl - A URL containing valid JEXL syntax.
Must not be null. Must be a readable file.Script which can be executed with a
JexlContext.java.lang.Exception - An exception can be thrown if there is a problem
parsing the script.protected Script createNewScript(java.lang.String scriptText) throws java.lang.Exception
scriptText - valid Jexl scriptjava.lang.Exception - for a variety of reasons - mostly malformed scriptsprivate java.lang.String cleanScript(java.lang.String script)
script - to cleanprivate static java.lang.String readerToString(java.io.BufferedReader reader)
throws java.io.IOException
reader - to be read.java.io.IOException - on any error reading the reader.