php.java.script.servlet
Class EngineFactory

java.lang.Object
  extended by php.java.script.servlet.EngineFactory

public final class EngineFactory
extends java.lang.Object

Create JSR 223 script engines from a servlet context.

See Also:
ContextLoaderListener, PhpServletScriptEngine, InvocablePhpServletRemoteHttpServerScriptEngine

Field Summary
static java.lang.String ROOT_ENGINE_FACTORY_ATTRIBUTE
          The key used to store the factory in the servlet context
 
Constructor Summary
EngineFactory()
          Create a new EngineFactory
 
Method Summary
static java.io.Reader createPhpScriptFileReader(java.lang.String path)
          Create a Reader from a given PHP script file.
static java.io.Reader createPhpScriptFileReader(java.lang.String path, java.io.Reader reader)
          Create a Reader from a given PHP script file.
static java.io.Reader createPhpScriptFileReader(java.lang.String path, php.java.script.servlet.ScriptReader reader)
          Create a Reader from a given PHP script file.
static java.io.Reader createPhpScriptReader(java.io.Reader script)
          Create a Reader from a given PHP script file.
static java.io.Reader createPhpScriptReader(java.lang.String script)
          Create a Reader from a given PHP script file.
static ScriptEngine getInvocablePhpScriptEngine(javax.servlet.Servlet servlet, javax.servlet.ServletContext ctx, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, java.net.URI uri)
          Get a PHP JSR 223 ScriptEngine, which implements the Invocable interface, from a HTTP server running on the local or a remote host.
static ScriptEngine getInvocablePhpScriptEngine(javax.servlet.Servlet servlet, javax.servlet.ServletContext ctx, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, java.net.URI uri, java.lang.String localName)
          Get a PHP JSR 223 ScriptEngine, which implements the Invocable interface, from a HTTP server running on the local or a remote host.
static ScriptEngine getPhpScriptEngine(javax.servlet.Servlet servlet, javax.servlet.ServletContext ctx, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          Get a PHP JSR 223 ScriptEngine from the servlet context.
 void releaseScriptEngines(java.util.List list)
          Only for internal use.
Release all managed script engines.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ROOT_ENGINE_FACTORY_ATTRIBUTE

public static final java.lang.String ROOT_ENGINE_FACTORY_ATTRIBUTE
The key used to store the factory in the servlet context

Constructor Detail

EngineFactory

public EngineFactory()
Create a new EngineFactory

Method Detail

getPhpScriptEngine

public static ScriptEngine getPhpScriptEngine(javax.servlet.Servlet servlet,
                                              javax.servlet.ServletContext ctx,
                                              javax.servlet.http.HttpServletRequest req,
                                              javax.servlet.http.HttpServletResponse res)
                                       throws java.lang.Exception
Get a PHP JSR 223 ScriptEngine from the servlet context. Example:
private static final Reader HELLO_SCRIPT_READER = EngineFactory.createPhpScriptReader("<?php echo 'Hello!'; ?>");
Reader reader = EngineFactory.createPhpScriptFileReader(request.getServletPath()+"._cache_.php", HELLO_SCRIPT_READER);
ScriptEngine scriptEngine = EngineFactory.getPhpScriptEngine(this, application, request, response);
scriptEngine.eval(reader);
reader.close();

Parameters:
servlet - the servlet
ctx - the servlet context
req - the request
res - the response
Returns:
the PHP JSR 223 ScriptEngine
Throws:
java.lang.Exception

getInvocablePhpScriptEngine

public static ScriptEngine getInvocablePhpScriptEngine(javax.servlet.Servlet servlet,
                                                       javax.servlet.ServletContext ctx,
                                                       javax.servlet.http.HttpServletRequest req,
                                                       javax.servlet.http.HttpServletResponse res,
                                                       java.net.URI uri,
                                                       java.lang.String localName)
                                                throws java.lang.Exception
Get a PHP JSR 223 ScriptEngine, which implements the Invocable interface, from a HTTP server running on the local or a remote host. Example:
ScriptEngine scriptEngine = EngineFactory.getInvocablePhpScriptEngine(this, application, request, response, new URI("http://127.0.0.1:80/JavaBridge/java/JavaProxy.php"), "thisHostName");
...
Invocable invocableEngine = (Invocable)scriptEngine;
invocableEngine.invoceFunction("phpinfo", new Object[]{});
...
scriptEngine.eval ((Reader)null);
Note: When connecting to a remote host, the WEB-INF/web.xml promiscuous option must be set.

Parameters:
servlet - the servlet
ctx - the servlet context
req - the request
res - the response
uri - the URI of the remote PHP script engine. The localName is used by the remote script engine to connect back to the current host.
localName - the official STATIC(!) server name or ip address of this host (in case there's an IP based load balancer in between).
Returns:
the invocable PHP JSR 223 ScriptEngine
Throws:
java.lang.Exception

getInvocablePhpScriptEngine

public static ScriptEngine getInvocablePhpScriptEngine(javax.servlet.Servlet servlet,
                                                       javax.servlet.ServletContext ctx,
                                                       javax.servlet.http.HttpServletRequest req,
                                                       javax.servlet.http.HttpServletResponse res,
                                                       java.net.URI uri)
                                                throws java.lang.Exception
Get a PHP JSR 223 ScriptEngine, which implements the Invocable interface, from a HTTP server running on the local or a remote host. Example:
ScriptEngine scriptEngine = EngineFactory.getInvocablePhpScriptEngine(this, application, request, response, new URI("http://127.0.0.1:80/JavaBridge/java/JavaProxy.php"));
...
Invocable invocableEngine = (Invocable)scriptEngine;
invocableEngine.invoceFunction("phpinfo", new Object[]{});
...
scriptEngine.eval ((Reader)null);
Note: When connecting to a remote host, the WEB-INF/web.xml promiscuous option must be set.

Parameters:
servlet - the servlet
ctx - the servlet context
req - the request
res - the response
uri - the URI of the remote PHP script engine, there must not be an IP-based load balancer in between
Returns:
the invocable PHP JSR 223 ScriptEngine
Throws:
java.lang.Exception

createPhpScriptReader

public static java.io.Reader createPhpScriptReader(java.lang.String script)
Create a Reader from a given PHP script file. This procedure can be used to create a reader from a cached script Example:
private static final Reader HELLO_READER = EngineFactory.createPhpScriptReader("<?php echo 'Hello!'; ?>");
Reader reader = EngineFactory.createPhpScriptFileReader(request.getServletPath()+"._cache_.php", HELLO_READER);
scriptEngine.eval (reader);
reader.close();
...

Parameters:
script - the php script.
Returns:
A reference to the cached PHP script

createPhpScriptReader

public static java.io.Reader createPhpScriptReader(java.io.Reader script)
Create a Reader from a given PHP script file. This procedure can be used to create a reader from a cached script Example:
private static final Reader HELLO_READER = EngineFactory.createPhpScriptReader(new StringReader("<?php echo 'Hello!'; ?>"));
Reader reader = EngineFactory.createPhpScriptFileReader(request.getServletPath()+"._cache_.php", HELLO_READER);
scriptEngine.eval (reader);
reader.close();
...

Parameters:
script - the script reader, will be closed automatically by the bridge.
Returns:
A reference to the cached PHP script

createPhpScriptFileReader

public static java.io.Reader createPhpScriptFileReader(java.lang.String path,
                                                       java.io.Reader reader)
Create a Reader from a given PHP script file. This procedure can be used to create a reader from a cached script Example:
private static final Reader HELLO_READER = EngineFactory.createPhpScriptReader("<?php echo 'Hello!'; ?>");
Reader reader = EngineFactory.createPhpScriptFileReader(request.getServletPath()+"._cache_.php", HELLO_READER);
scriptEngine.eval (reader);
reader.close();
...

Parameters:
path - the file containing the cached script
reader - the reader, will be closed automatically by the bridge.
Returns:
A reference to the cached PHP script

createPhpScriptFileReader

public static java.io.Reader createPhpScriptFileReader(java.lang.String path,
                                                       php.java.script.servlet.ScriptReader reader)
Create a Reader from a given PHP script file. This procedure can be used to create a reader from a cached script Example:
private static final Reader HELLO_READER = EngineFactory.createPhpScriptReader("<?php echo 'Hello!'; ?>");
Reader reader = EngineFactory.createPhpScriptFileReader(request.getServletPath()+"._cache_.php", HELLO_READER);
scriptEngine.eval (reader);
reader.close();
...

Parameters:
path - the file containing the cached script
reader - the reader, will be closed automatically by the bridge.
Returns:
A reference to the cached PHP script

createPhpScriptFileReader

public static java.io.Reader createPhpScriptFileReader(java.lang.String path)
Create a Reader from a given PHP script file. This procedure can be used to create a reader from a cached script Example:
Reader reader = EngineFactory.createPhpScriptFileReader("/sessionSharing.php");
scriptEngine.eval (reader);
reader.close();
...

Parameters:
path - the file containing the script
Returns:
A reader for the script

releaseScriptEngines

public void releaseScriptEngines(java.util.List list)
Only for internal use.
Release all managed script engines. Will be called automatically during shutdown,

Parameters:
list - the list of script engines