php.java.bridge.http
Class Context

java.lang.Object
  extended by php.java.bridge.http.Context
All Implemented Interfaces:
IContext, Invocable
Direct Known Subclasses:
Context

public class Context
extends java.lang.Object
implements Invocable, IContext

Emulates a JSR223 script context when the JSR223 classes are not available. The method call(kont) returns false, so that it can be used to check if a script was called from java:
function toString() {return "hello java, I am a php script, but in your eyes I am an ordinary java object...";}
java_context()->call(java_closure()) || die("This script must be called from java!");

Author:
jostb
See Also:
IPhpScriptContext, ScriptContext, PhpSimpleHttpScriptContext, PhpScriptContext

Field Summary
 
Fields inherited from interface php.java.bridge.http.IContext
ENGINE_SCOPE, GLOBAL_SCOPE, JAVA_BRIDGE, SERVLET, SERVLET_CONFIG, SERVLET_CONTEXT, SERVLET_REQUEST, SERVLET_RESPONSE
 
Method Summary
 boolean call(PhpProcedureProxy kont)
          Call the java continuation with the current continuation kont as its argument.
 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.
 java.lang.Object getHttpServletRequest()
           
 java.lang.Object getHttpServletResponse()
           
 java.lang.Object getServletContext()
           
 java.io.Writer getWriter()
          Retrieves an instance of java.io.Writer which can be used by scripts to display their output.
 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 name, java.lang.Object value, int scope)
          Sets an attribute specified by the name in specified level of scope.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getAttribute

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

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

getAttribute

public java.lang.Object getAttribute(java.lang.String name,
                                     int scope)
                              throws java.lang.IllegalArgumentException
Description copied from interface: IContext
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 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

getAttributesScope

public int getAttributesScope(java.lang.String name)
Description copied from interface: IContext
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 IContext
Parameters:
name - the name of attribute
Returns:
the value of level of scope

getWriter

public java.io.Writer getWriter()
                         throws java.io.IOException
Description copied from interface: IContext
Retrieves an instance of java.io.Writer which can be used by scripts to display their output.

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

removeAttribute

public java.lang.Object removeAttribute(java.lang.String name,
                                        int scope)
                                 throws java.lang.IllegalArgumentException
Description copied from interface: IContext
Removes the specified attribute form the specified level of scope.

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

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.Object value,
                         int scope)
                  throws java.lang.IllegalArgumentException
Description copied from interface: IContext
Sets an attribute specified by the name in specified level of scope.

Specified by:
setAttribute in interface IContext
Parameters:
name - the name of the attribute
value - the value of the attribute
scope - the level of the scope
Throws:
java.lang.IllegalArgumentException

getHttpServletRequest

public java.lang.Object getHttpServletRequest()

getServletContext

public java.lang.Object getServletContext()

getHttpServletResponse

public java.lang.Object getHttpServletResponse()

call

public boolean call(PhpProcedureProxy kont)
Description copied from interface: Invocable
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.