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, IManaged, Invocable, IPhpScriptContext

public class PhpSimpleHttpScriptContext
extends AbstractPhpScriptContext
implements 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.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.
 javax.servlet.http.HttpServletRequest getRequest()
          Get the HttpServletRequest
 javax.servlet.http.HttpServletResponse getResponse()
          Get the servlet response
 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.io.Writer getWriter()
          Returns the Writer for scripts to use when displaying output.
 java.lang.Object init(java.lang.Object callable)
          Initialize a library.
 void initialize(javax.servlet.Servlet servlet, javax.servlet.ServletContext ctx, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          Initialize the context.
 void onShutdown(java.lang.Object closeable)
          Register a shutdown hook for the library.
 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

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.

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.

getHttpServletResponse

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

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

getHttpServletRequest

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

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

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

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