org.apache.pig.scripting.js
Class JsScriptEngine

java.lang.Object
  extended by org.apache.pig.scripting.ScriptEngine
      extended by org.apache.pig.scripting.js.JsScriptEngine

public class JsScriptEngine
extends ScriptEngine

ScriptEngine implementation for JavaScript


Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.pig.scripting.ScriptEngine
ScriptEngine.SupportedScriptLang
 
Field Summary
 
Fields inherited from class org.apache.pig.scripting.ScriptEngine
NAMESPACE_SEPARATOR
 
Constructor Summary
JsScriptEngine()
           
 
Method Summary
protected  Object eval(String expr)
           
static JsScriptEngine getInstance()
           
protected  Map<String,Object> getParamsFromVariables()
          Returns a map from local variable names to their values
protected  String getScriptingLang()
          Gets ScriptEngine classname or keyword for the scripting language
 Object jsCall(String functionName, Object[] passedParams)
          call a javascript function
 Object jsEval(String name, Reader scriptReader)
          evaluate javascript from a reader
 Object jsEval(String name, String script)
          evaluate a javascript String
 org.mozilla.javascript.Scriptable jsNewArray(long size)
          creates a new javascript array
 org.mozilla.javascript.Scriptable jsNewObject()
          creates a new JavaScript object
 void jsPut(String name, Object value)
          put a value in the current scope
protected  void load(String name, InputStream script)
           
protected  Map<String,List<PigStats>> main(PigContext pigContext, String scriptFile)
          Actually runs the script file.
 void registerFunctions(String path, String namespace, PigContext pigContext)
          Registers scripting language functions as Pig functions with given namespace
 
Methods inherited from class org.apache.pig.scripting.ScriptEngine
getInstance, getJarPath, getPigStatsMap, getScriptAsStream, getSupportedScriptLang, run
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JsScriptEngine

public JsScriptEngine()
Method Detail

getInstance

public static JsScriptEngine getInstance()

jsEval

public Object jsEval(String name,
                     String script)
evaluate a javascript String

Parameters:
name - the name of the script (for error messages)
script - the content of the script
Returns:
the result

jsEval

public Object jsEval(String name,
                     Reader scriptReader)
evaluate javascript from a reader

Parameters:
name - the name of the script (for error messages)
scriptReader - the content of the script
Returns:
the result

jsPut

public void jsPut(String name,
                  Object value)
put a value in the current scope

Parameters:
name - the name of the variable
value - its value

jsCall

public Object jsCall(String functionName,
                     Object[] passedParams)
call a javascript function

Parameters:
functionName - the name of the function
passedParams - the parameters to pass
Returns:
the result of the function

jsNewObject

public org.mozilla.javascript.Scriptable jsNewObject()
creates a new JavaScript object

Returns:
an empty object

jsNewArray

public org.mozilla.javascript.Scriptable jsNewArray(long size)
creates a new javascript array

Parameters:
size - the size of the array
Returns:
an empty array of the given size

eval

protected Object eval(String expr)

load

protected void load(String name,
                    InputStream script)

main

protected Map<String,List<PigStats>> main(PigContext pigContext,
                                          String scriptFile)
                                   throws IOException
Description copied from class: ScriptEngine
Actually runs the script file. This method will be implemented by individual script engines.

Specified by:
main in class ScriptEngine
Parameters:
pigContext - ScriptPigContext to run the script file
scriptFile - the file
Throws:
IOException

registerFunctions

public void registerFunctions(String path,
                              String namespace,
                              PigContext pigContext)
                       throws IOException
Description copied from class: ScriptEngine
Registers scripting language functions as Pig functions with given namespace

Specified by:
registerFunctions in class ScriptEngine
Parameters:
path - path of the script
namespace - namespace for the functions
pigContext - pigcontext to register functions to pig in the given namespace
Throws:
IOException

getParamsFromVariables

protected Map<String,Object> getParamsFromVariables()
                                             throws IOException
Description copied from class: ScriptEngine
Returns a map from local variable names to their values

Specified by:
getParamsFromVariables in class ScriptEngine
Throws:
IOException

getScriptingLang

protected String getScriptingLang()
Description copied from class: ScriptEngine
Gets ScriptEngine classname or keyword for the scripting language

Specified by:
getScriptingLang in class ScriptEngine


Copyright © 2007-2012 The Apache Software Foundation