org.apache.tapestry5.internal.services
Class EnvironmentImpl

java.lang.Object
  extended by org.apache.tapestry5.internal.services.EnvironmentImpl
All Implemented Interfaces:
EventListener, ThreadCleanupListener, Environment

public class EnvironmentImpl
extends Object
implements Environment, ThreadCleanupListener

A non-threadsafe implementation (expects to use the "perthread" service lifecyle).


Constructor Summary
EnvironmentImpl()
           
 
Method Summary
 void clear()
          Clears all stacks; used when initializing the Environment before a render.
<T> EnvironmentalAccess<T>
getAccess(Class<T> type)
          For some type, returns a temporary access object for the type.
<T> T
peek(Class<T> type)
          Peeks at the current top of the indicated stack.
<T> T
peekRequired(Class<T> type)
          Peeks at the current top of the indicated stack (which must have a non-null value).
<T> T
pop(Class<T> type)
          Removes and returns the top environmental object of the selected type.
<T> T
push(Class<T> type, T instance)
          Pushes a new service onto the stack.
 void threadDidCleanup()
          Invoked by PerthreadManager service when a thread performs and end-of-request cleanup.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EnvironmentImpl

public EnvironmentImpl()
Method Detail

peek

public <T> T peek(Class<T> type)
Description copied from interface: Environment
Peeks at the current top of the indicated stack.

Specified by:
peek in interface Environment
Type Parameters:
T - the type of environmental object
Parameters:
type - class used to select the object
Returns:
the current object of that type, or null if no service of that type has been added

peekRequired

public <T> T peekRequired(Class<T> type)
Description copied from interface: Environment
Peeks at the current top of the indicated stack (which must have a non-null value).

Specified by:
peekRequired in interface Environment
Type Parameters:
T - the type of environmental object
Parameters:
type - class used to select the object
Returns:
the current object of the specified type

pop

public <T> T pop(Class<T> type)
Description copied from interface: Environment
Removes and returns the top environmental object of the selected type.

Specified by:
pop in interface Environment
Type Parameters:
T - the type of environmental object
Parameters:
type - class used to select the object
Returns:
the object just removed

push

public <T> T push(Class<T> type,
                  T instance)
Description copied from interface: Environment
Pushes a new service onto the stack. The old service at the top of the stack is returned (it may be null).

Specified by:
push in interface Environment
Type Parameters:
T - the type of environmental object
Parameters:
type - class used to select the object
instance - the service object
Returns:
the previous top service

clear

public void clear()
Description copied from interface: Environment
Clears all stacks; used when initializing the Environment before a render.

Specified by:
clear in interface Environment

getAccess

public <T> EnvironmentalAccess<T> getAccess(Class<T> type)
Description copied from interface: Environment
For some type, returns a temporary access object for the type. The access object is efficient because it ties directly to the thread's instance of the Environment service, it also caches the current value.

The access object must be discarded at the end of the request (it will be unusable at that point anyway).

Specified by:
getAccess in interface Environment
Parameters:
type - type of environmental object
Returns:
access object that can be used to see the current environmental object of the type

threadDidCleanup

public void threadDidCleanup()
Description copied from interface: ThreadCleanupListener
Invoked by PerthreadManager service when a thread performs and end-of-request cleanup.

Specified by:
threadDidCleanup in interface ThreadCleanupListener


Copyright © 2006-2009 Apache Software Foundation. All Rights Reserved.