2004.04.29


com.jdc.http.mvc
Class HttpModel

java.lang.Object
  |
  +--jdc.java.lang.Object
        |
        +--com.jdc.app.mvc.Model
              |
              +--com.jdc.http.mvc.HttpModel

public abstract class HttpModel
extends Model

HttpModel processes the user request, i.e. it is the Model in a Model-View-Controller (MVC) framework. Handles to the following implicit objects are provided to simpify usage by classes extending this class: request - The current HTTP servlet request object. response - The current HTTP servlet response object. session - The current HTTP user session object. user - The current user profile object browser - The type of browser in use.

Version:
1.0
Author:
Jay Damon
See Also:
Serialized Form

Field Summary
protected  Browser browser
          The type of browser used by the user to make the current request, e.g.
protected  ServletConfig config
          The current servlet configuration object, if provided.
protected  ServletContext context
          The current servlet context object, if provided.
protected  HttpServletRequest request
          The current HTTP servlet request object.
protected  HttpServletResponse response
          The current HTTP servlet response object.
protected  HttpSession session
          The current HTTP user session object.
protected  HttpTransaction transaction
          The current user transaction object.
protected  HttpUserProfile user
          The current user, i.e.
protected  HttpView view
          The current user view object.
 
Fields inherited from class com.jdc.app.mvc.Model
currency, locale, log, number, string, timestamp, USER, VIEW
 
Constructor Summary
HttpModel(HttpServletRequest request, HttpServletResponse response)
          Constructs an HttpModel object.
HttpModel(HttpServletRequest request, HttpServletResponse response, ServletContext context)
          Constructs a HttpModel object.
HttpModel(HttpServletRequest request, HttpServletResponse response, ServletContext context, ServletConfig config)
          Constructs a HttpModel object.
 
Method Summary
 String addContext(String requestURL)
          Adds the web application context to fully qualify a url.
 boolean areCookiesEnabled()
          Returns true if cookies are enabled.
 void createCookie(String name, String value, int hours)
          Creates a cookie to be stored on the user's computer.
protected  void displayCookies()
          Displays current request cookies.
protected  void displayRequestParameters()
          Displays current request parameters.
 HttpModel doRequest()
          Handles the current HTTP servlet request.
abstract  HttpView doRequest(HttpView view)
          Handles the current HTTP servlet request.
 Browser getBrowser()
          Returns the type of browser used by the user to make the current request.
 ServletConfig getConfig()
          Returns the current servlet configuration object, if provided.
 ServletContext getContext()
          Returns the current servlet context object, if provided..
 String getCookieValue(String cookieName)
          Returns the cookie value for the requested cookie name, if the cookie exists.
 Locale getLocale()
          Returns the user locale object.
 String getParameterValue(String parameterName)
          Returns the parameter value for the requested parameter name, if the parameter exists.
 HttpServletRequest getRequest()
          Returns the current HTTP servlet request object.
 HttpServletResponse getResponse()
          Returns the current HTTP servlet response object.
 HttpSession getSession()
          Returns the current HTTP user session object.
 Object getSessionAttribute(String name)
          Returns the requested session attribute.
 String getTargetURL()
          Returns the target Uniform Resource Locator (URL) for the request.
 String getText(String identifier)
          Returns the resource display text for the specified display text identifier.
 String getText(String identifier, String value)
          Returns the resource display text for the specified display text identifier.
 String getText(String identifier, String[] values)
          Returns the resource display text for the specified display text identifier.
 String getText(String identifier, String value1, String value2)
          Returns the resource display text for the specified display text identifier.
 HttpTransaction getTransaction()
          Returns the current user transaction object.
 HttpUserProfile getUser()
          Returns the current user, i.e.
 HttpView getView()
          Returns the current user view object.
 boolean isGet()
          Returns true if the method used to invoke current request is GET.
 boolean isPost()
          Returns true if the method used to invoke current request is POST.
 void setNoCache()
          Sets the appropriate HTTP servlet response object header to prevent the JSP page from being cached by the client browser.
protected  void setResource(String name)
          Sets the resource bundle containing page labels and text for the current user locale.
 void setSessionAttribute(String name, Object object)
          Sets the requested session attribute.
 
Methods inherited from class com.jdc.app.mvc.Model
setLocale
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

request

protected HttpServletRequest request
The current HTTP servlet request object.


response

protected HttpServletResponse response
The current HTTP servlet response object.


context

protected ServletContext context
The current servlet context object, if provided.


config

protected ServletConfig config
The current servlet configuration object, if provided.


session

protected HttpSession session
The current HTTP user session object. A new session object will be created if one does not exist.


user

protected HttpUserProfile user
The current user, i.e. client, profile object. A new user profile object will be created if one does not exist.


browser

protected Browser browser
The type of browser used by the user to make the current request, e.g. Microsoft Internet Explorer, Netscape Navigator, etc.


transaction

protected HttpTransaction transaction
The current user transaction object.


view

protected HttpView view
The current user view object.

Constructor Detail

HttpModel

public HttpModel(HttpServletRequest request,
                 HttpServletResponse response)
          throws IllegalArgumentException
Constructs an HttpModel object.


HttpModel

public HttpModel(HttpServletRequest request,
                 HttpServletResponse response,
                 ServletContext context)
          throws RuntimeException
Constructs a HttpModel object.


HttpModel

public HttpModel(HttpServletRequest request,
                 HttpServletResponse response,
                 ServletContext context,
                 ServletConfig config)
          throws RuntimeException
Constructs a HttpModel object.

Method Detail

addContext

public String addContext(String requestURL)
Adds the web application context to fully qualify a url.

Returns:
String

areCookiesEnabled

public boolean areCookiesEnabled()
Returns true if cookies are enabled. This will only work on the first request if there are, in fact, cookies. This cannot be properly tested, however, until the second request, i.e. after the first request actually creates the session and a corresponding session identifier.

Returns:
boolean

createCookie

public void createCookie(String name,
                         String value,
                         int hours)
Creates a cookie to be stored on the user's computer.


displayCookies

protected void displayCookies()
Displays current request cookies. This is a convenience method to display all request cookies to the console


displayRequestParameters

protected void displayRequestParameters()
Displays current request parameters. This is a convenience method to display all request parameters to the console


doRequest

public abstract HttpView doRequest(HttpView view)
Handles the current HTTP servlet request. This method must be implemented in the model subclass.

Returns:
HttpModel This HTTP model object.

doRequest

public HttpModel doRequest()
Handles the current HTTP servlet request. This method invokes doAction() on the model subclass. Upon completion, this method updates the user profile and all associated objects in the session object.

Returns:
HttpModel This HTTP model object.

getBrowser

public Browser getBrowser()
Returns the type of browser used by the user to make the current request. A new browser object is (implicitly) created (by the user object) if one does not exist.

Returns:
Browser The type of browser in use.

getConfig

public ServletConfig getConfig()
Returns the current servlet configuration object, if provided.

Returns:
ServletConfig The servlet configuration object.

getContext

public ServletContext getContext()
Returns the current servlet context object, if provided..

Returns:
ServletContext The servlet context object.

getCookieValue

public String getCookieValue(String cookieName)
Returns the cookie value for the requested cookie name, if the cookie exists.

Returns:
String The cookie value.

getLocale

public Locale getLocale()
Returns the user locale object.

Overrides:
getLocale in class Model
Returns:
Locale The user locale.

getParameterValue

public String getParameterValue(String parameterName)
Returns the parameter value for the requested parameter name, if the parameter exists.

Returns:
String The parameter value.

getRequest

public HttpServletRequest getRequest()
Returns the current HTTP servlet request object.

Returns:
HttpServletRequest The HTTP servlet request object.

getResponse

public HttpServletResponse getResponse()
Returns the current HTTP servlet response object.

Returns:
HttpServletResponse The HTTP servlet response object.

getSession

public HttpSession getSession()
Returns the current HTTP user session object. A new HTTP user session object is created if one does not exist.

Returns:
HttpSession The HTTP user session object.

getTargetURL

public String getTargetURL()
Returns the target Uniform Resource Locator (URL) for the request.

Returns:
String The target URL for the request.

getText

public String getText(String identifier)
Returns the resource display text for the specified display text identifier.

Returns:
String The display text.

getText

public String getText(String identifier,
                      String value)
Returns the resource display text for the specified display text identifier.

Returns:
String The display text.

getText

public String getText(String identifier,
                      String value1,
                      String value2)
Returns the resource display text for the specified display text identifier.

Returns:
String The display text.

getText

public String getText(String identifier,
                      String[] values)
Returns the resource display text for the specified display text identifier.

Returns:
String The display text.

getTransaction

public HttpTransaction getTransaction()
Returns the current user transaction object.

Returns:
HttpTransaction The user transaction object.

getUser

public HttpUserProfile getUser()
Returns the current user, i.e. client, profile object. A new user object is created if one does not exist.

Returns:
HttpUserProfile The user profile object.

getView

public HttpView getView()
Returns the current user view object.

Returns:
HttpView The user view object.

isGet

public boolean isGet()
Returns true if the method used to invoke current request is GET. The servlet invoking this model object must extend servlet class HttpController

Returns:
boolean True if the current request is a GET.

isPost

public boolean isPost()
Returns true if the method used to invoke current request is POST. The servlet invoking this model object must extend servlet class HttpController

Returns:
boolean True if the current request is a POST.

setNoCache

public void setNoCache()
Sets the appropriate HTTP servlet response object header to prevent the JSP page from being cached by the client browser.


setResource

protected void setResource(String name)
Sets the resource bundle containing page labels and text for the current user locale. The user locale defaults to English, via getLocale(), if not specified.


getSessionAttribute

public Object getSessionAttribute(String name)
Returns the requested session attribute.


setSessionAttribute

public void setSessionAttribute(String name,
                                Object object)
Sets the requested session attribute.


2004.04.29



Copyright © 2004 J. Damon & Co.; All Rights Reserved WorldWide.