php.java.script
Class PhpScriptContext

java.lang.Object
  extended by php.java.script.ScriptContextDecorator
      extended by php.java.script.AbstractPhpScriptContext
          extended by php.java.script.PhpScriptContext
All Implemented Interfaces:
ScriptContext, IContext, IManaged, Invocable, IPhpScriptContext

public final class PhpScriptContext
extends AbstractPhpScriptContext

This class implements a simple script context for PHP. It starts a standalone JavaBridgeRunner which listens for requests from php instances.

In a servlet environment please use a php.java.script.http.PhpSimpleHttpScriptContext instead.

Author:
jostb
See Also:
PhpScriptContext, JavaBridgeRunner

Field Summary
 
Fields inherited from interface php.java.bridge.http.IContext
ENGINE_SCOPE, GLOBAL_SCOPE, JAVA_BRIDGE, PHP_PROCEDURE, SERVLET, SERVLET_CONFIG, SERVLET_CONTEXT, SERVLET_REQUEST, SERVLET_RESPONSE
 
Fields inherited from interface javax.script.ScriptContext
ENGINE_SCOPE, GLOBAL_SCOPE
 
Constructor Summary
PhpScriptContext(ScriptContext ctx)
           
 
Method Summary
 Continuation createContinuation(java.io.Reader reader, java.util.Map env, java.io.OutputStream out, java.io.OutputStream err, HeaderParser headerParser, ResultProxy result, ILogger logger, boolean isCompiled)
          Create a continuation
 java.lang.Object get(java.lang.String key)
          Get a binding from the engine scope
 java.util.Map getAll()
          Get all bindings from the engine scope
 ContextServer getContextServer()
          Get the context server associated with this context, usually a HttpServer (JavaBridgeRunner) or a ContextServer from a ContextLoaderListener
 java.lang.Object getHttpServletRequest()
          Throws IllegalStateException
 java.lang.Object getHttpServletResponse()
          Throws IllegalStateException
 java.lang.String getRealPath(java.lang.String path)
          Get the full file system path for the given resource.
 java.lang.String getRedirectString()
          Deprecated.  
 java.lang.String getRedirectString(java.lang.String webPath)
          Deprecated.  
 java.lang.String getRedirectURL(java.lang.String webPath)
          Return the redirect string, for example http://localhost:8080/webPath Used by the non-compiling script engines to hard-code the back-end URL in the Java.inc
 java.lang.Object getServlet()
          Throws IllegalStateException
 java.lang.Object getServletConfig()
          Throws IllegalStateException
 java.lang.Object getServletContext()
          Throws IllegalStateException
 java.lang.String getSocketName()
          Return the socket name, for example 8080
 java.lang.Object init(java.lang.Object callable)
          Initialize a library.
 void onShutdown(java.lang.Object closeable)
          Register a shutdown hook for the library.
 void put(java.lang.String key, java.lang.Object val)
          Add a new binding to the engine scope
 void putAll(java.util.Map map)
          Put all bindings to the engine scope
 void remove(java.lang.String key)
          Remove a bindings from the engine scope
 
Methods inherited from class php.java.script.AbstractPhpScriptContext
call, getContinuation, getErrorWriter, getWriter, setContinuation, setErrorWriter, setWriter, startContinuation
 
Methods inherited from class php.java.script.ScriptContextDecorator
getAttribute, getAttribute, getAttributesScope, getBindings, getReader, getScopes, removeAttribute, setAttribute, setBindings, setReader
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface php.java.bridge.http.IContext
getAttribute, getAttribute, getAttributesScope, removeAttribute, setAttribute
 
Methods inherited from interface javax.script.ScriptContext
getAttribute, getAttribute, getAttributesScope, getBindings, getReader, getScopes, removeAttribute, setAttribute, setBindings, setReader
 

Constructor Detail

PhpScriptContext

public PhpScriptContext(ScriptContext ctx)
Method Detail

init

public java.lang.Object init(java.lang.Object callable)
                      throws java.lang.Exception
Initialize a library. This method may be called via java_context()->init(...) to initialize a library. Within init() onShutdown() may be called to register a shutdown hook for the library.

Parameters:
callable - Its call() method will be called synchronized.
Returns:
The result of the call() invocation.
Throws:
java.lang.Exception - The result of the call() invocation.

onShutdown

public void onShutdown(java.lang.Object closeable)
Register a shutdown hook for the library. This method may be called via java_context()->onShutdown(...) to register a shutdown hook during init().

Parameters:
closeable - Its close() method will be called before the context or the VM terminates.

getHttpServletRequest

public java.lang.Object getHttpServletRequest()
Throws IllegalStateException

Returns:
none

getServletContext

public java.lang.Object getServletContext()
Throws IllegalStateException

Returns:
none

getHttpServletResponse

public java.lang.Object getHttpServletResponse()
Throws IllegalStateException

Returns:
none

getServlet

public java.lang.Object getServlet()
Throws IllegalStateException

Returns:
none

getServletConfig

public java.lang.Object getServletConfig()
Throws IllegalStateException

Returns:
none

getRealPath

public java.lang.String getRealPath(java.lang.String path)
Get the full file system path for the given resource.

Parameters:
path - the relative path to an existing resource
Returns:
the file system path

get

public java.lang.Object get(java.lang.String key)
Get a binding from the engine scope

Parameters:
key - the key
Returns:
the value

put

public void put(java.lang.String key,
                java.lang.Object val)
Add a new binding to the engine scope

Parameters:
key - the key
val - the value

remove

public void remove(java.lang.String key)
Remove a bindings from the engine scope

Parameters:
key - the key

putAll

public void putAll(java.util.Map map)
Put all bindings to the engine scope

Parameters:
map - the map

getAll

public java.util.Map getAll()
Get all bindings from the engine scope

Returns:
the map

createContinuation

public Continuation createContinuation(java.io.Reader reader,
                                       java.util.Map env,
                                       java.io.OutputStream out,
                                       java.io.OutputStream err,
                                       HeaderParser headerParser,
                                       ResultProxy result,
                                       ILogger logger,
                                       boolean isCompiled)
Create a continuation

Parameters:
reader - the script reader
env - the environment passed to php
out - the fcgi output stream
err - the fcgi error stream
headerParser - fcgi header parser
result - the result proxy
logger - the logger
isCompiled - create a continuation for a compiled or non-compiled script engine
Returns:
the Continuation

getSocketName

public java.lang.String getSocketName()
Return the socket name, for example 8080

Returns:
the socket name

getRedirectString

public java.lang.String getRedirectString()
Deprecated. 


getRedirectString

public java.lang.String getRedirectString(java.lang.String webPath)
Deprecated. 


getRedirectURL

public java.lang.String getRedirectURL(java.lang.String webPath)
Return the redirect string, for example http://localhost:8080/webPath Used by the non-compiling script engines to hard-code the back-end URL in the Java.inc

Parameters:
webPath - Usually request.getContextPath()+request.getServletPath()
Returns:
the redirect string

getContextServer

public ContextServer getContextServer()
Get the context server associated with this context, usually a HttpServer (JavaBridgeRunner) or a ContextServer from a ContextLoaderListener

Returns:
the ContextServer