php.java.script
Class SimplePhpScriptEngine

java.lang.Object
  extended by javax.script.AbstractScriptEngine
      extended by php.java.script.SimplePhpScriptEngine
All Implemented Interfaces:
ScriptEngine
Direct Known Subclasses:
InvocablePhpScriptEngine, PhpScriptEngine

abstract class SimplePhpScriptEngine
extends AbstractScriptEngine

This class implements the ScriptEngine.

See Also:
InvocablePhpScriptEngine, PhpScriptEngine

Field Summary
protected  HttpProxy continuation
          The continuation of the script
protected  IContextFactory ctx
           
protected  java.util.Map env
           
protected  java.lang.String name
           
protected static java.util.HashMap processEnvironment
           
protected  ResultProxy resultProxy
           
protected  PhpProcedureProxy script
          The allocated script
protected  java.lang.Object scriptClosure
           
 
Fields inherited from interface javax.script.ScriptEngine
ARGV, ENGINE, ENGINE_VERSION, FILENAME, LANGUAGE, LANGUAGE_VERSION, NAME
 
Constructor Summary
SimplePhpScriptEngine()
          Create a new ScriptEngine with a default context.
SimplePhpScriptEngine(PhpScriptEngineFactory factory)
          Create a new ScriptEngine from a factory.
 
Method Summary
 void close()
          Release the script engine.
 Bindings createBindings()
          Retrieves an uninitailized namespace which can be used as the scope of the ScriptEngine.
protected  PhpProcedureProxy doEval(java.io.Reader reader, ScriptContext context)
           
 java.lang.Object eval(java.io.Reader reader, ScriptContext context)
          Evaluates a script obtained using the specified reader as the script source and using the namespaces in the specifed ScriptContext.
protected  java.lang.Object eval(java.io.Reader reader, ScriptContext context, java.lang.String name)
           
 java.lang.Object eval(java.lang.String script, ScriptContext context)
          Evaluates a script using the namespaces in the specifed ScriptContext.
protected  HttpProxy getContinuation(java.io.Reader reader, ScriptContext context)
           
 ScriptEngineFactory getFactory()
          Retrieves a ScriptEngineFactory for the class to which describes the underlying ScriptEngine.
protected  ScriptContext getPhpScriptContext()
           
(package private) static java.util.HashMap getProcessEnvironment()
          Get the current process environment which will be passed to the sub-process.
protected  void initialize()
           
 void release()
          Release the continuation
protected  void setName(java.lang.String name)
           
protected  void setNewContextFactory()
          Create a new context ID and a environment map which we send to the client.
protected  void setStandardEnvironmentValues(java.util.Map env)
          Set the context id (X_JAVABRIDGE_CONTEXT) and the override flag (X_JAVABRIDGE_OVERRIDE_HOSTS) into env
 
Methods inherited from class javax.script.AbstractScriptEngine
eval, eval, eval, eval, get, getBindings, getContext, getScriptContext, put, setBindings, setContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

script

protected PhpProcedureProxy script
The allocated script


scriptClosure

protected java.lang.Object scriptClosure

name

protected java.lang.String name

continuation

protected HttpProxy continuation
The continuation of the script


env

protected java.util.Map env

ctx

protected IContextFactory ctx

resultProxy

protected ResultProxy resultProxy

processEnvironment

protected static final java.util.HashMap processEnvironment
Constructor Detail

SimplePhpScriptEngine

public SimplePhpScriptEngine()
Create a new ScriptEngine with a default context.


SimplePhpScriptEngine

public SimplePhpScriptEngine(PhpScriptEngineFactory factory)
Create a new ScriptEngine from a factory.

Parameters:
factory - The factory
See Also:
getFactory()
Method Detail

initialize

protected void initialize()

getProcessEnvironment

static java.util.HashMap getProcessEnvironment()
Get the current process environment which will be passed to the sub-process. Requires jdk1.5 or higher. In jdk1.4, where System.getenv() is not available, we allocate an empty map.

To add custom environment variables (such as PATH=... or LD_ASSUME_KERNEL=2.4.21, ...), use a custom PhpScriptEngine, for example:
public class MyPhpScriptEngine extends PhpScriptEngine {
  protected HashMap getProcessEnvironment() {
    HashMap map = new HashMap();
    map.put("PATH", "/usr/local/bin");
    return map;
  }
}

Returns:
The current process environment.

setName

protected void setName(java.lang.String name)

setStandardEnvironmentValues

protected void setStandardEnvironmentValues(java.util.Map env)
Set the context id (X_JAVABRIDGE_CONTEXT) and the override flag (X_JAVABRIDGE_OVERRIDE_HOSTS) into env

Parameters:
env - the environment which will be passed to PHP

setNewContextFactory

protected void setNewContextFactory()
Create a new context ID and a environment map which we send to the client.


eval

protected java.lang.Object eval(java.io.Reader reader,
                                ScriptContext context,
                                java.lang.String name)
                         throws ScriptException
Throws:
ScriptException

eval

public java.lang.Object eval(java.io.Reader reader,
                             ScriptContext context)
                      throws ScriptException
Description copied from interface: ScriptEngine
Evaluates a script obtained using the specified reader as the script source and using the namespaces in the specifed ScriptContext. Returns null for non-returning scripts

Parameters:
reader - the script source
context - the context contianing different namespace for script evaluation
Returns:
the value of the evaluated script
Throws:
ScriptException - if an error occurs

getContinuation

protected HttpProxy getContinuation(java.io.Reader reader,
                                    ScriptContext context)

doEval

protected PhpProcedureProxy doEval(java.io.Reader reader,
                                   ScriptContext context)
                            throws java.lang.Exception
Throws:
java.lang.Exception

eval

public java.lang.Object eval(java.lang.String script,
                             ScriptContext context)
                      throws ScriptException
Description copied from interface: ScriptEngine
Evaluates a script using the namespaces in the specifed ScriptContext. Return null for non-returning scripts.

Parameters:
script - the String representation of the script
context - tbe ScriptContext containing namespaces for the script evaluation
Returns:
the value of the evaluated script
Throws:
ScriptException - if an error occurs

getFactory

public ScriptEngineFactory getFactory()
Description copied from interface: ScriptEngine
Retrieves a ScriptEngineFactory for the class to which describes the underlying ScriptEngine.

Returns:
an instance of ScriptEngineFactory which describes the underlying ScriptEngine

getPhpScriptContext

protected ScriptContext getPhpScriptContext()

release

public void release()
Release the continuation


createBindings

public Bindings createBindings()
Retrieves an uninitailized namespace which can be used as the scope of the ScriptEngine.

Returns:
an initialzed namespace which can be used to repalce the state of the ScriptEngine

close

public void close()
           throws java.io.IOException
Release the script engine.

Throws:
java.io.IOException