com.arsdigita.bebop
Class RequestLocal

java.lang.Object
  extended bycom.arsdigita.bebop.RequestLocal

public class RequestLocal
extends Object

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

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

 public class SomeClass {
     private RequestLocal m_foo;
     
     public SomeClass() {
       m_foo = new RequestLocal() {
             protected Object initialValue(PageState s) {
                 // Foo could be a much more complicated value
                 return s.getRequestURI();
             }
         };
     }
     
     public String getFoo(PageState s) {
         return (String) m_foo.get(s);
     }
     
     public void setFoo(PageState s, String v) {
         m_foo.set(s, v);
     }
 }
 

Version:
$Id: //core-platform/dev/src/com/arsdigita/bebop/RequestLocal.java#9 $
Author:
David Lutterkort

Field Summary
static String versionId
           
 
Constructor Summary
RequestLocal()
           
 
Method Summary
 Object get(PageState state)
          Returns the request-specific value for this variable for the request associated with state.
protected  Object initialValue(PageState state)
          Returns the value to be used during the request represented by state.
 void set(javax.servlet.http.HttpServletRequest request, Object value)
          Sets a new value for the request local variable and associates it with the request represented by request
 void set(PageState state, Object value)
          Sets a new value for the request local variable and associates it with the request represented by state.
 
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

RequestLocal

public RequestLocal()
Method Detail

initialValue

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

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

get

public Object get(PageState state)
Returns the request-specific value for this variable for the request associated with state.

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

set

public void set(PageState state,
                Object value)
Sets a new value for the request local variable and associates it with the request represented by state.

Parameters:
state - represents the current state of the request
value - the new value for this request local variable

set

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

Sets a new value for the request local variable and associates it with the request represented by request

This method is intended for use when a Dispatcher needs to assign some value to a RequestLocal for Bebop Page processing before Page processing begins.

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


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