php.java.script
Class PhpScriptContextDecorator

java.lang.Object
  extended by php.java.script.PhpScriptContextDecorator
All Implemented Interfaces:
ScriptContext, IContext, IManaged, Invocable, IPhpScriptContext
Direct Known Subclasses:
PhpCompiledScriptContext, PhpHttpScriptContext, PhpJavaBridgeRunnerScriptContext, PhpSecureScriptContext

public abstract class PhpScriptContextDecorator
extends java.lang.Object
implements IPhpScriptContext

Abstract class for IPhpScriptContexts. The abstract class itself provides default methods that pass all requests to the contained IPhpScriptContext. Subclasses of PhpScriptContextDecoratorDecorator should override some of these methods and may also provide additional methods and fields.

Author:
jostb

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
PhpScriptContextDecorator(IPhpScriptContext ctx)
          Create a new PhpScriptContextDecorator
 
Method Summary
 boolean call(java.lang.Object kont)
          Call the java continuation with the current continuation kont as its argument.
 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
 java.lang.Object getAttribute(java.lang.String name)
          Retrieves the value for getAttribute(String, int) for the lowest scope in which it returns a non-null value.
 java.lang.Object getAttribute(java.lang.String name, int scope)
          Retrieves the value associated with specified name in the specified level of scope.
 int getAttributesScope(java.lang.String name)
          Retrieves the lowest value of scopes for which the attribute is defined.
 Bindings getBindings(int scope)
          Retrieves the Namespace instance associated with the gieve scope.
 ContextServer getContextServer()
          Get the context server associated with this context, usually a HttpServer (JavaBridgeRunner) or a ContextServer from a ContextLoaderListener
 Continuation getContinuation()
          Get the php continuation
 java.io.Writer getErrorWriter()
          Returns the Writer used to display error output.
 java.lang.Object getHttpServletRequest()
          Return the http servlet request
 java.lang.Object getHttpServletResponse()
          Return the http servlet response
 java.io.Reader getReader()
          Returns a Reader to be used by the script to read input.
 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.util.List getScopes()
          Returns immutable List of all the valid values for scope in the ScriptContext.
 java.lang.Object getServlet()
          Return the http servlet
 java.lang.Object getServletConfig()
          Return the servlet config
 java.lang.Object getServletContext()
          Return the servlet context
 java.lang.String getSocketName()
          Return the socket name, for example 8080
 java.io.Writer getWriter()
          Retrieves an instance of java.io.Writer which can be used by scripts to display their output.
 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
 java.lang.Object removeAttribute(java.lang.String name, int scope)
          Removes the specified attribute form the specified level of scope.
 void setAttribute(java.lang.String key, java.lang.Object value, int scope)
          Sets an attribute specified by the name in specified level of scope.
 void setBindings(Bindings namespace, int scope)
          Associates the specified namespace with the specified scope.
 void setContinuation(Continuation kont)
          Set the php continuation
 void setErrorWriter(java.io.Writer writer)
          Sets the Writer used to display error output.
 void setReader(java.io.Reader reader)
          Sets the Reader for scripts to read input .
 void setWriter(java.io.Writer writer)
          Sets the Writer for scripts to use when displaying output.
 void startContinuation()
          Start the current continuation using a context-specific thread pool
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PhpScriptContextDecorator

public PhpScriptContextDecorator(IPhpScriptContext ctx)
Create a new PhpScriptContextDecorator

Parameters:
ctx - the PhpScriptContext to decorate.
Method Detail

getAttribute

public java.lang.Object getAttribute(java.lang.String name)
                              throws java.lang.IllegalArgumentException
Retrieves the value for getAttribute(String, int) for the lowest scope in which it returns a non-null value.

Specified by:
getAttribute in interface ScriptContext
Specified by:
getAttribute in interface IContext
Parameters:
name - the name of the attribute
Returns:
the value of the attribute
Throws:
java.lang.IllegalArgumentException - if the name is null

getAttribute

public java.lang.Object getAttribute(java.lang.String name,
                                     int scope)
                              throws java.lang.IllegalArgumentException
Retrieves the value associated with specified name in the specified level of scope. Returns null if no value is associated with specified key in specified level of scope.

Specified by:
getAttribute in interface ScriptContext
Specified by:
getAttribute in interface IContext
Parameters:
name - the name of the attribute
scope - the level of scope
Returns:
the value value associated with the specified name in specified level of scope
Throws:
java.lang.IllegalArgumentException - if the name is null or the scope is invalid

getAttributesScope

public int getAttributesScope(java.lang.String name)
Retrieves the lowest value of scopes for which the attribute is defined. If there is no associate scope with the given attribute (-1) is returned.

Specified by:
getAttributesScope in interface ScriptContext
Specified by:
getAttributesScope in interface IContext
Parameters:
name - the name of attribute
Returns:
the value of level of scope

getBindings

public Bindings getBindings(int scope)
Retrieves the Namespace instance associated with the gieve scope. Returns null if no namespace is assoicited with specified level of scope.

Specified by:
getBindings in interface ScriptContext
Parameters:
scope - the level of the scope
Returns:
the Namespace associated with the specified levle of scope

getErrorWriter

public java.io.Writer getErrorWriter()
Returns the Writer used to display error output.

Specified by:
getErrorWriter in interface ScriptContext
Returns:
The Writer

getReader

public java.io.Reader getReader()
Returns a Reader to be used by the script to read input.

Specified by:
getReader in interface ScriptContext
Returns:
The Reader.

getScopes

public java.util.List getScopes()
Returns immutable List of all the valid values for scope in the ScriptContext.

Specified by:
getScopes in interface ScriptContext
Returns:
list of scope values

getWriter

public java.io.Writer getWriter()
Retrieves an instance of java.io.Writer which can be used by scripts to display their output.

Specified by:
getWriter in interface ScriptContext
Specified by:
getWriter in interface IContext
Returns:
an instance of java.io.Writer

removeAttribute

public java.lang.Object removeAttribute(java.lang.String name,
                                        int scope)
                                 throws java.lang.IllegalArgumentException
Removes the specified attribute form the specified level of scope.

Specified by:
removeAttribute in interface ScriptContext
Specified by:
removeAttribute in interface IContext
Parameters:
name - the name of the attribute
scope - the level of scope
Returns:
value which is removed
Throws:
java.lang.IllegalArgumentException - if the name is null or if the scope is invalid

setAttribute

public void setAttribute(java.lang.String key,
                         java.lang.Object value,
                         int scope)
                  throws java.lang.IllegalArgumentException
Sets an attribute specified by the name in specified level of scope.

Specified by:
setAttribute in interface ScriptContext
Specified by:
setAttribute in interface IContext
Parameters:
key - the name of the attribute
value - the value of the attribute
scope - the level of the scope
Throws:
java.lang.IllegalArgumentException - if the name is null scope is invlaid

setBindings

public void setBindings(Bindings namespace,
                        int scope)
                 throws java.lang.IllegalArgumentException
Associates the specified namespace with the specified scope.

Specified by:
setBindings in interface ScriptContext
Parameters:
namespace - the namespace to be associated with the specified level of scope
scope - the specified level of scope
Throws:
java.lang.IllegalArgumentException - if the scope is invalid

setErrorWriter

public void setErrorWriter(java.io.Writer writer)
Sets the Writer used to display error output.

Specified by:
setErrorWriter in interface ScriptContext
Parameters:
writer - The Writer.

setReader

public void setReader(java.io.Reader reader)
Sets the Reader for scripts to read input .

Specified by:
setReader in interface ScriptContext
Parameters:
reader - The new Reader.

setWriter

public void setWriter(java.io.Writer writer)
Sets the Writer for scripts to use when displaying output.

Specified by:
setWriter in interface ScriptContext
Parameters:
writer - The new Writer.

getContinuation

public Continuation getContinuation()
Get the php continuation

Specified by:
getContinuation in interface IPhpScriptContext
Returns:
The HttpProxy

setContinuation

public void setContinuation(Continuation kont)
Set the php continuation

Specified by:
setContinuation in interface IPhpScriptContext
Parameters:
kont - The continuation.

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.

Specified by:
init in interface IManaged
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().

Specified by:
onShutdown in interface IManaged
Parameters:
closeable - Its close() method will be called before the context or the VM terminates.

call

public boolean call(java.lang.Object kont)
             throws java.lang.Exception
Call the java continuation with the current continuation kont as its argument.

Specified by:
call in interface Invocable
Parameters:
kont - The continuation.
Returns:
True on success, false otherwise.
Throws:
java.lang.Exception

get

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

Specified by:
get in interface IContext
Parameters:
key - the key
Returns:
the value

getAll

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

Specified by:
getAll in interface IContext
Returns:
the map

getHttpServletRequest

public java.lang.Object getHttpServletRequest()
Return the http servlet request

Specified by:
getHttpServletRequest in interface IContext
Returns:
The http servlet request

getHttpServletResponse

public java.lang.Object getHttpServletResponse()
Return the http servlet response

Specified by:
getHttpServletResponse in interface IContext
Returns:
The http servlet reponse

getRealPath

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

Specified by:
getRealPath in interface IContext
Parameters:
path - the relative path to an existing resource
Returns:
the file system path

getServlet

public java.lang.Object getServlet()
Return the http servlet

Specified by:
getServlet in interface IContext
Returns:
The http servlet

getServletConfig

public java.lang.Object getServletConfig()
Return the servlet config

Specified by:
getServletConfig in interface IContext
Returns:
The servlet config

getServletContext

public java.lang.Object getServletContext()
Return the servlet context

Specified by:
getServletContext in interface IContext
Returns:
The servlet context

put

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

Specified by:
put in interface IContext
Parameters:
key - the key
val - the value

putAll

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

Specified by:
putAll in interface IContext
Parameters:
map - the map

remove

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

Specified by:
remove in interface IContext
Parameters:
key - the key

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

Specified by:
createContinuation in interface IPhpScriptContext
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

getRedirectString

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

Specified by:
getRedirectString in interface IContext

getRedirectString

public java.lang.String getRedirectString()
Deprecated. 

Specified by:
getRedirectString in interface IContext

getSocketName

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

Specified by:
getSocketName in interface IContext
Returns:
the socket name

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

Specified by:
getRedirectURL in interface IContext
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

Specified by:
getContextServer in interface IPhpScriptContext
Returns:
the ContextServer

startContinuation

public void startContinuation()
Start the current continuation using a context-specific thread pool

Specified by:
startContinuation in interface IPhpScriptContext