org.bibeault.frontman
Interface CommandContext

All Known Implementing Classes:
CommandContextImplementation

public interface CommandContext

Defines the interface for an object instance passed to the execute() method of a Command instance. Thw CommandContext not only provides access to context information such as the request and response, but also provides some handy convenience methods for performing common actions such as seting scoped variables and dispatching to other resources.


Method Summary
 java.lang.Object findScopedVariable(java.lang.Object name)
          Finds a scoped variable.
 void forward(java.lang.String path)
          Forwards the current request to the resource at the specified path.
 void forwardToCommand(java.lang.String verb)
          Convenience wrapper around the forward(String) method that forwards to the command specified by the passed command verb.
 void forwardToView(java.lang.String viewName)
          Convenience wrapper around the forward(String) method that forwards to the view specified by the passed view name.
 CommandBroker getCommandBroker()
           
 java.lang.String getPathInfo()
          Returns the path info for the current request.
 javax.servlet.http.HttpServletRequest getRequest()
           
 javax.servlet.http.HttpServletResponse getResponse()
           
 java.lang.Object getScopedVariable(java.lang.Object name, ScopedContext context)
          Gets a scoped variable from the specified context.
 javax.servlet.ServletContext getServletContext()
           
 javax.servlet.http.HttpSession getSession()
           
 void redirect(java.lang.String location)
          Sends a temporary redirect response to the client using the specified redirect location URL.
 void redirect(java.lang.String location, java.util.Map<java.lang.String,java.lang.String[]> parameters)
          Sends a temporary redirect response to the client using the specified redirect location URL.
 void redirectToCommand(java.lang.String verb)
          Convenience wrapper around the redirect(String) method that redirects to the command specified by the passed command verb.
 void redirectToCommand(java.lang.String verb, java.util.Map<java.lang.String,java.lang.String[]> parameters)
          Convenience wrapper around the redirect(String) method that redirects to the command specified by the passed command verb, with one or more request parameters.
 void redirectToView(java.lang.String viewName)
          Convenience wrapper around the redirect(String) method that redirects to the view specified by the passed view name.
 void redirectToView(java.lang.String viewName, java.util.Map<java.lang.String,java.lang.String[]> parameters)
          Convenience wrapper around the redirect(String) method that redirects to the view specified by the passed view name, with one or more request parameters.
 void sendError(int statusCode)
          Sends an error response to the client with the specified status code.
 void setScopedVariable(java.lang.Object name, java.lang.Object value)
          Sets a scoped variable into the request context.
 void setScopedVariable(java.lang.Object name, java.lang.Object value, ScopedContext scope)
          Sets a scoped variable into the specified context.
 

Method Detail

getCommandBroker

CommandBroker getCommandBroker()
Returns:
the Command Broker instance

getRequest

javax.servlet.http.HttpServletRequest getRequest()
Returns:
the current servlet request instance.

getResponse

javax.servlet.http.HttpServletResponse getResponse()
Returns:
the current response.

getSession

javax.servlet.http.HttpSession getSession()
Returns:
the current session instance.

getServletContext

javax.servlet.ServletContext getServletContext()
Returns:
the servlet context.

getPathInfo

java.lang.String getPathInfo()
Returns the path info for the current request. This method is sensitive to requests initiated via an include and will return the path info of the originating request.

Returns:
the determined path info

setScopedVariable

void setScopedVariable(java.lang.Object name,
                       java.lang.Object value,
                       ScopedContext scope)
                       throws javax.servlet.ServletException,
                              java.lang.NullPointerException
Sets a scoped variable into the specified context.

This is a convenience method that shortens the syntax of setting scoped variables into their contexts as well as providing improved semantics. The name can be provided as any object whose string value is used as the name.

Parameters:
name - the name of the scoped variable
value - the value of the scoped variable
scope - one of SCOPE_REQUEST, SCOPE_SESSION or SCOPE_APPLICATION
Throws:
javax.servlet.ServletException - if the specified scope is not a valid value
java.lang.NullPointerException - if name is null

setScopedVariable

void setScopedVariable(java.lang.Object name,
                       java.lang.Object value)
                       throws javax.servlet.ServletException
Sets a scoped variable into the request context.

This is a convenience method that shortens the syntax of setting scoped variables into request context. The name can be provided as any object whose string value is used as the name.

Parameters:
name - the name of the scoped variable
value - the value of the scoped variable
Throws:
javax.servlet.ServletException - if the specified scope is not a valid value
java.lang.NullPointerException - if name is null

getScopedVariable

java.lang.Object getScopedVariable(java.lang.Object name,
                                   ScopedContext context)
                                   throws javax.servlet.ServletException
Gets a scoped variable from the specified context. The name can be proviede as any object type whose string equivalent is used as the name.

Parameters:
name - the name of the scoped variable
context - the scoped context in which to look
Returns:
the located object, or null if not found
Throws:
javax.servlet.ServletException - if anything goes awry

findScopedVariable

java.lang.Object findScopedVariable(java.lang.Object name)
Finds a scoped variable. The name can be proviede as any object type whose string equivalent is used as the name.

Parameters:
name - the name of the scoped variable
Returns:
the located object, or null if not found

forward

void forward(java.lang.String path)
             throws java.io.IOException,
                    javax.servlet.ServletException,
                    java.lang.IllegalStateException
Forwards the current request to the resource at the specified path.

The semantics of path are the same as that required by the javax.servlet.RequestDispatcher.forward() method.

Parameters:
path - the path of the resource to whcih the request is to be forwarded
Throws:
java.io.IOException - if the request dispatcher throws this exception
javax.servlet.ServletException - if the request dispatcher throws this exception
java.lang.IllegalStateException - if the response is already committed
See Also:
RequestDispatcher

redirect

void redirect(java.lang.String location)
              throws java.io.IOException,
                     java.lang.IllegalStateException
Sends a temporary redirect response to the client using the specified redirect location URL.

The semantics of location are the same as that required by the javax.servlet.http.HttpServletResponse.sendRedirect() method.

This method automatically ensures that the redirect is properly encoded to ensure that the session id is included in the URL if necessary.

Parameters:
location - the location of the redirect resource
Throws:
java.io.IOException - If an input or output exception occurs
java.lang.IllegalStateException - if the response is already committed, or the location cannot be made into a valid URL
See Also:
HttpServletResponse

redirect

void redirect(java.lang.String location,
              java.util.Map<java.lang.String,java.lang.String[]> parameters)
              throws java.io.IOException,
                     java.lang.IllegalStateException
Sends a temporary redirect response to the client using the specified redirect location URL.

The semantics of location are the same as that required by the javax.servlet.http.HttpServletResponse.sendRedirect() method.

This method automatically ensures that the redirect is properly encoded to ensure that the session id is included in the URL if necessary.

Parameters:
location - the location of the redirect resource
parameters - a Map of the request parameters to add the URL as a query string
Throws:
java.io.IOException - If an input or output exception occurs
java.lang.IllegalStateException - if the response is already committed, or the location cannot be made into a valid URL
See Also:
HttpServletResponse

sendError

void sendError(int statusCode)
               throws java.io.IOException,
                      java.lang.IllegalStateException
Sends an error response to the client with the specified status code.

This method is a thin wrapper around the javax.servlet.http.HttpServletResponse.sendError() method.

Parameters:
statusCode - one of the SC_ codes defined by javax.servlet.http.HttpServletResponse
Throws:
java.io.IOException - If an input or output exception occurs
java.lang.IllegalStateException - if the response is already committed

forwardToCommand

void forwardToCommand(java.lang.String verb)
                      throws java.io.IOException,
                             javax.servlet.ServletException
Convenience wrapper around the forward(String) method that forwards to the command specified by the passed command verb.

Parameters:
verb - the verb for the forward command
Throws:
java.io.IOException - see forward(String)
javax.servlet.ServletException - see forward(String)

forwardToView

void forwardToView(java.lang.String viewName)
                   throws java.io.IOException,
                          javax.servlet.ServletException
Convenience wrapper around the forward(String) method that forwards to the view specified by the passed view name.

Parameters:
viewName - the name for the forward view
Throws:
java.io.IOException - see forward(String)
javax.servlet.ServletException - see forward(String)

redirectToCommand

void redirectToCommand(java.lang.String verb)
                       throws java.io.IOException,
                              javax.servlet.ServletException
Convenience wrapper around the redirect(String) method that redirects to the command specified by the passed command verb.

Parameters:
verb - the verb for the redirect command
Throws:
java.io.IOException - see redirect(String)
javax.servlet.ServletException - see redirect(String)

redirectToCommand

void redirectToCommand(java.lang.String verb,
                       java.util.Map<java.lang.String,java.lang.String[]> parameters)
                       throws java.io.IOException,
                              javax.servlet.ServletException
Convenience wrapper around the redirect(String) method that redirects to the command specified by the passed command verb, with one or more request parameters.

Parameters:
verb - the verb for the redirect command
parameters - a Map of the request parameters to add the URL as a query string
Throws:
java.io.IOException - see redirect(String)
javax.servlet.ServletException - see redirect(String)

redirectToView

void redirectToView(java.lang.String viewName)
                    throws java.io.IOException,
                           javax.servlet.ServletException
Convenience wrapper around the redirect(String) method that redirects to the view specified by the passed view name.

Parameters:
viewName - the name for the redirect view
Throws:
java.io.IOException - see redirect(String)
javax.servlet.ServletException - see redirect(String)

redirectToView

void redirectToView(java.lang.String viewName,
                    java.util.Map<java.lang.String,java.lang.String[]> parameters)
                    throws java.io.IOException,
                           javax.servlet.ServletException
Convenience wrapper around the redirect(String) method that redirects to the view specified by the passed view name, with one or more request parameters.

Parameters:
viewName - the name for the redirect view
parameters - a Map of the request parameters to add the URL as a query string
Throws:
java.io.IOException - see redirect(String)
javax.servlet.ServletException - see redirect(String)