org.picocontainer.defaults
Class ThreadLocalCyclicDependencyGuard

java.lang.Object
  extended byjava.lang.ThreadLocal
      extended byorg.picocontainer.defaults.ThreadLocalCyclicDependencyGuard
All Implemented Interfaces:
CyclicDependencyGuard
Direct Known Subclasses:
InstantiatingComponentAdapter.Guard

public abstract class ThreadLocalCyclicDependencyGuard
extends ThreadLocal
implements CyclicDependencyGuard

Abstract utility class to detect recursion cycles. Derive from this class and implement run(). The method will be called by observe(java.lang.Class). Select an appropriate guard for your scope. Any ObjectReference can be used as long as it is initialized with Boolean.FALSE.

Since:
1.1
Author:
Jörg Schaible

Constructor Summary
ThreadLocalCyclicDependencyGuard()
           
 
Method Summary
protected  Object initialValue()
           
 Object observe(Class stackFrame)
          Call the observing function.
abstract  Object run()
          Derive from this class and implement this function with the functionality to observe for a dependency cycle.
 
Methods inherited from class java.lang.ThreadLocal
get, set
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ThreadLocalCyclicDependencyGuard

public ThreadLocalCyclicDependencyGuard()
Method Detail

initialValue

protected Object initialValue()

run

public abstract Object run()
Derive from this class and implement this function with the functionality to observe for a dependency cycle.

Specified by:
run in interface CyclicDependencyGuard
Returns:
a value, if the functionality result in an expression, otherwise just return null

observe

public final Object observe(Class stackFrame)
Call the observing function. The provided guard will hold the Boolean value. If the guard is already Boolean.TRUE a CyclicDependencyException will be thrown.

Specified by:
observe in interface CyclicDependencyGuard
Parameters:
stackFrame - the current stack frame
Returns:
the result of the run method


Copyright © 2003-2007 Codehaus. All Rights Reserved.