php.java.script
Class PhpScriptEngine

java.lang.Object
  extended by javax.script.AbstractScriptEngine
      extended by php.java.script.PhpScriptEngine
All Implemented Interfaces:
java.io.FileFilter, java.lang.Cloneable, java.security.cert.CertStoreParameters, Compilable, ScriptEngine, CloneableScript, IPhpScriptEngine

public class PhpScriptEngine
extends AbstractScriptEngine

This class implements the ScriptEngine.

Example:

ScriptEngine e = (new ScriptEngineManager()).getEngineByName("php");
try { e.eval(<?php foo() ?>"); } catch (ScriptException e) { ... }

Author:
jostb

Field Summary
 
Fields inherited from interface javax.script.ScriptEngine
ARGV, ENGINE, ENGINE_VERSION, FILENAME, LANGUAGE, LANGUAGE_VERSION, NAME
 
Constructor Summary
PhpScriptEngine()
          Create a new ScriptEngine with a default context.
PhpScriptEngine(Bindings n)
          Create a new ScriptEngine with bindings.
PhpScriptEngine(PhpScriptEngineFactory factory)
          Create a new ScriptEngine from a factory.
 
Method Summary
 boolean accept(java.io.File outputFile)
          
 java.lang.Object clone()
          
 void close()
          Release the script engine.
 CompiledScript compile(java.io.Reader reader)
          Retrieves a CompileScript implementation for the script obtained using java.io.Reader as the script source.
 CompiledScript compile(java.lang.String script)
          Retrieves a CompileScript implementation for the given piece of script which is a abstraction for the intermediate code produced by the compilation.
 Bindings createBindings()
          Retrieves an uninitailized namespace which can be used as the scope of the ScriptEngine.
 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.
 java.lang.Object eval(java.lang.String script, ScriptContext context)
          Evaluates a script using the namespaces in the specifed ScriptContext.
 ScriptContext getContext()
          Return the script context.
 ScriptEngineFactory getFactory()
          Retrieves a ScriptEngineFactory for the class to which describes the underlying ScriptEngine.
 void release()
          Release the continuation
 void setContext(ScriptContext context)
          Set a new context.
 
Methods inherited from class javax.script.AbstractScriptEngine
eval, eval, eval, eval, get, getBindings, put, setBindings
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.script.ScriptEngine
eval, eval, eval, eval, get, getBindings, put, setBindings
 

Constructor Detail

PhpScriptEngine

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


PhpScriptEngine

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

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

PhpScriptEngine

public PhpScriptEngine(Bindings n)
Create a new ScriptEngine with bindings.

Parameters:
n - the bindings
Method Detail

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

Specified by:
eval in interface ScriptEngine
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

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.

Specified by:
eval in interface ScriptEngine
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.

Specified by:
getFactory in interface ScriptEngine
Returns:
an instance of ScriptEngineFactory which describes the underlying ScriptEngine

release

public void release()
Release the continuation

Specified by:
release in interface IPhpScriptEngine

createBindings

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

Specified by:
createBindings in interface 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.

Specified by:
close in interface IPhpScriptEngine
Throws:
java.io.IOException

compile

public CompiledScript compile(java.lang.String script)
                       throws ScriptException
Retrieves a CompileScript implementation for the given piece of script which is a abstraction for the intermediate code produced by the compilation.

Specified by:
compile in interface Compilable
Parameters:
script - the source of the script represented as String
Returns:
an implementation of CompileScript which can be used to re-execute intermediate code produced by the compilation of script
Throws:
ScriptException - if the compilation fials due to any reason

compile

public CompiledScript compile(java.io.Reader reader)
                       throws ScriptException
Retrieves a CompileScript implementation for the script obtained using java.io.Reader as the script source.

Specified by:
compile in interface Compilable
Parameters:
reader - the reader form which the script source is obtained
Returns:
an implementation of CompileScript which can be used to re-execute intermediate code produced by the compilation of script
Throws:
ScriptException - if the compilation fials due to any reason

getContext

public ScriptContext getContext()
Return the script context.

Specified by:
getContext in interface ScriptEngine
Overrides:
getContext in class AbstractScriptEngine
Returns:
The script context.

setContext

public void setContext(ScriptContext context)
Set a new context.

Specified by:
setContext in interface ScriptEngine
Overrides:
setContext in class AbstractScriptEngine
Parameters:
context - The context

accept

public boolean accept(java.io.File outputFile)

Specified by:
accept in interface java.io.FileFilter

clone

public java.lang.Object clone()

Specified by:
clone in interface java.security.cert.CertStoreParameters
Overrides:
clone in class java.lang.Object