com.arsdigita.dispatcher
Class RequestValue

java.lang.Object
  extended bycom.arsdigita.dispatcher.RequestValue

public class RequestValue
extends Object

A variable whose value is specific to each request. Objects that need to store values that change in every request should decare them to be RequestValue. These variables hold their values only during a duration of a request. They get reinitialized by a call to initialValue for every new HTTP request.

For example, a class that wants to implement a request specific property foo would do the following:

 public class SomeClass {
   private RequestValue m_foo;

   public SomeClass() {
     m_foo = new RequestValue() {
  protected Object initialValue(HttpServletRequest r) {
    // Foo could be a much more complicated value
    return r.getRequestURI();
  }
     };
   }

   public String getFoo(HttpServletRequest r) {
     return (String)m_foo.get(r);
   }

   public void setFoo(HttpServletRequest r, String v) {
     m_foo.set(r, v);
   }
 }
 

Version:
$Id: //core-platform/dev/src/com/arsdigita/dispatcher/RequestValue.java#7 $
Author:
Eric Lorenzo

Field Summary
static String versionId
           
 
Constructor Summary
RequestValue()
           
 
Method Summary
 Object get()
          This convenience method works like get(HttpServletRequest), but uses DispatcherHelper.getRequest() to get the request object.
 Object get(javax.servlet.http.HttpServletRequest request)
          Return the request specific value for this variable for the request associated with request.
protected  Object initialValue(javax.servlet.http.HttpServletRequest request)
          Return the value to be used during the request represented by request.
 void set(javax.servlet.http.HttpServletRequest request, Object value)
          Set a new value for the request local variable and associate it with the request represented by request
 void set(Object value)
          This convenience method works like set(HttpServletRequest, Object), but uses DispatcherHelper.getRequest() to get the request object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

versionId

public static final String versionId
See Also:
Constant Field Values
Constructor Detail

RequestValue

public RequestValue()
Method Detail

initialValue

protected Object initialValue(javax.servlet.http.HttpServletRequest request)
Return the value to be used during the request represented by request. This method is called at most once per request, the first time the value of this RequestValue is requested with get. RequestValue must be subclassed, and this method overridden. Typically, an anonymous inner class will be used.

Parameters:
request - represents the current request
Returns:
the initial value for this request local variable

get

public Object get(javax.servlet.http.HttpServletRequest request)
Return the request specific value for this variable for the request associated with request.

Parameters:
request - represents the current request
Returns:
the value for this request local variable

get

public Object get()
This convenience method works like get(HttpServletRequest), but uses DispatcherHelper.getRequest() to get the request object.

Returns:
the value for this request-local variable

set

public void set(javax.servlet.http.HttpServletRequest request,
                Object value)

Set a new value for the request local variable and associate it with the request represented by request

Parameters:
request - represents the current request
value - the new value for this request value

set

public void set(Object value)

This convenience method works like set(HttpServletRequest, Object), but uses DispatcherHelper.getRequest() to get the request object.

Parameters:
value - the new value for this request value


Copyright (c) 2004 Red Hat, Inc. Corporation. All Rights Reserved. Generated at July 20 2004:2337 UTC