org.apache.commons.jexl

## Class ScriptFactory

- java.lang.Object
- - org.apache.commons.jexl.ScriptFactory

    public class ScriptFactory
    extends java.lang.Object

Creates `Script`s. 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.

Since:
  1.1
Version:
  $Id: ScriptFactory.java 429175 2006-08-06 12:05:23 -0700 (Sun, 06 Aug 2006) rahul $

### Field Summary

Fields
`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 org.apache.commons.jexl.parser.Parser` `parser` The singleton ScriptFactory also holds a single instance of `Parser`.

### Method Summary

Methods
`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.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### log

    protected static org.apache.commons.logging.Log log

The Log to which all ScriptFactory messages will be logged.

#### parser

    protected static org.apache.commons.jexl.parser.Parser parser

The singleton ScriptFactory also holds a single instance of `Parser`. When parsing expressions, ScriptFactory synchronizes on Parser.

#### factory

    protected static ScriptFactory factory

ScriptFactory is a singleton and this is the private instance fufilling that pattern.

### Method Detail

#### getInstance

    protected static ScriptFactory getInstance()

Returns the single instance of ScriptFactory.

Returns:
  the instance of ScriptFactory.

#### createScript

    public static Script createScript(java.lang.String scriptText)
                               throws java.lang.Exception

Creates a Script from a String containing valid JEXL syntax. This method parses the script which validates the syntax.

Parameters:
  `scriptText` - A String containing valid JEXL syntax
Returns:
  A `Script` which can be executed with a `JexlContext`.
Throws:
  `java.lang.Exception` - An exception can be thrown if there is a problem parsing the script.

#### createScript

    public static Script createScript(java.io.File scriptFile)
                               throws java.lang.Exception

Creates a Script from a `File` containing valid JEXL syntax. This method parses the script and validates the syntax.

Parameters:
  `scriptFile` - A `File` containing valid JEXL syntax. Must not be null. Must be a readable file.
Returns:
  A `Script` which can be executed with a `JexlContext`.
Throws:
  `java.lang.Exception` - An exception can be thrown if there is a problem parsing the script.

#### createScript

    public static Script createScript(java.net.URL scriptUrl)
                               throws java.lang.Exception

Creates a Script from a `URL` containing valid JEXL syntax. This method parses the script and validates the syntax.

Parameters:
  `scriptUrl` - A `URL` containing valid JEXL syntax. Must not be null. Must be a readable file.
Returns:
  A `Script` which can be executed with a `JexlContext`.
Throws:
  `java.lang.Exception` - An exception can be thrown if there is a problem parsing the script.

#### createNewScript

    protected Script createNewScript(java.lang.String scriptText)
                              throws java.lang.Exception

Creates a new Script based on the string.

Parameters:
  `scriptText` - valid Jexl script
Returns:
  Script a new script
Throws:
  `java.lang.Exception` - for a variety of reasons - mostly malformed scripts