php.java.script.servlet
Class PhpSimpleHttpScriptContext

java.lang.Object
  extended by javax.script.SimpleScriptContext
      extended by php.java.script.AbstractPhpScriptContext
          extended by php.java.script.servlet.PhpSimpleHttpScriptContext
All Implemented Interfaces:
ScriptContext, IContext, Invocable, IPhpScriptContext

public class PhpSimpleHttpScriptContext
extends AbstractPhpScriptContext
implements IContext, IPhpScriptContext

A simple ScriptContext which can be used in servlet environments.

Author:
jostb

Field Summary
 
Fields inherited from class php.java.script.AbstractPhpScriptContext
APPLICATION_SCOPE, REQUEST_SCOPE, SESSION_SCOPE
 
Fields inherited from interface php.java.bridge.http.IContext
ENGINE_SCOPE, GLOBAL_SCOPE, JAVA_BRIDGE, SERVLET, SERVLET_CONFIG, SERVLET_CONTEXT, SERVLET_REQUEST, SERVLET_RESPONSE
 
Fields inherited from interface javax.script.ScriptContext
ENGINE_SCOPE, GLOBAL_SCOPE
 
Constructor Summary
PhpSimpleHttpScriptContext()
           
 
Method Summary
 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 key, int scope)
          Retrieves the value associated with specified name in the specified level of scope.
 javax.servlet.ServletContext getContext()
          Get the ServletContext
 java.lang.String getContextString()
          Return the context string, for example http://localhost:8080/JavaBridge
 java.io.Writer getErrorWriter()
          Returns the Writer used to display error output.
 java.io.Reader getReader()
          Returns a Reader to be used by the script to read input.
 javax.servlet.http.HttpServletRequest getRequest()
          Get the HttpServletRequest
 javax.servlet.http.HttpServletResponse getResponse()
          Get the servlet response
 java.lang.String getSocketName()
          Return the socket name, for example 8080
 java.io.Writer getWriter()
          Returns the Writer for scripts to use when displaying output.
 void initialize(javax.servlet.Servlet servlet, javax.servlet.ServletContext ctx, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          Initialize the context.
 void setAttribute(java.lang.String key, java.lang.Object value, int scope)
          Sets an attribute specified by the name in specified level of scope.
 
Methods inherited from class php.java.script.AbstractPhpScriptContext
call, getContinuation, setContinuation, setErrorWriter, setWriter
 
Methods inherited from class javax.script.SimpleScriptContext
getAttributesScope, getBindings, getScopes, removeAttribute, setBindings, setReader
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface php.java.script.IPhpScriptContext
getContinuation, setContinuation, setWriter
 
Methods inherited from interface php.java.bridge.Invocable
call
 
Methods inherited from interface php.java.bridge.http.IContext
getAttributesScope, removeAttribute
 

Constructor Detail

PhpSimpleHttpScriptContext

public PhpSimpleHttpScriptContext()
Method Detail

initialize

public void initialize(javax.servlet.Servlet servlet,
                       javax.servlet.ServletContext ctx,
                       javax.servlet.http.HttpServletRequest req,
                       javax.servlet.http.HttpServletResponse res)
Initialize the context.

Parameters:
servlet - The servlet
ctx - The ServletContext
req - The HttpServletRequest
res - The HttpServletResponse

getAttribute

public java.lang.Object getAttribute(java.lang.String key,
                                     int scope)
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
Overrides:
getAttribute in class SimpleScriptContext
Parameters:
key - the name of the attribute
scope - the level of scope
Returns:
the value value associated with the specified name in specified level of scope

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
Overrides:
getAttribute in class SimpleScriptContext
Parameters:
name - the name of the attribute
Returns:
the value of the attribute
Throws:
java.lang.IllegalArgumentException - if the name is null

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
Overrides:
setAttribute in class SimpleScriptContext
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 invalid

getResponse

public javax.servlet.http.HttpServletResponse getResponse()
Get the servlet response

Returns:
The HttpServletResponse

getRequest

public javax.servlet.http.HttpServletRequest getRequest()
Get the HttpServletRequest

Returns:
The HttpServletRequest

getContext

public javax.servlet.ServletContext getContext()
Get the ServletContext

Returns:
The current ServletContext

getContextString

public java.lang.String getContextString()
Return the context string, for example http://localhost:8080/JavaBridge

Specified by:
getContextString in interface IPhpScriptContext
Specified by:
getContextString in class AbstractPhpScriptContext
Returns:
the context string

getSocketName

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

Specified by:
getSocketName in interface IPhpScriptContext
Specified by:
getSocketName in class AbstractPhpScriptContext
Returns:
the socket name

getWriter

public java.io.Writer getWriter()
Returns the Writer for scripts to use when displaying output.

Specified by:
getWriter in interface ScriptContext
Specified by:
getWriter in interface IContext
Specified by:
getWriter in interface IPhpScriptContext
Overrides:
getWriter in class AbstractPhpScriptContext
Returns:
The Writer.

getErrorWriter

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

Specified by:
getErrorWriter in interface ScriptContext
Overrides:
getErrorWriter in class AbstractPhpScriptContext
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
Overrides:
getReader in class SimpleScriptContext
Returns:
The Reader.