org.picocontainer.defaults
Class ThreadLocalCyclicDependencyGuard

java.lang.Object
  extended by java.lang.ThreadLocal
      extended by org.picocontainer.defaults.ThreadLocalCyclicDependencyGuard
All Implemented Interfaces:
CyclicDependencyGuard
Direct Known Subclasses:
ConstructorInjectionComponentAdapter.Guard, InstantiatingComponentAdapter.Guard

public abstract class ThreadLocalCyclicDependencyGuard
extends java.lang.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  java.lang.Object initialValue()
           
 java.lang.Object observe(java.lang.Class stackFrame)
          Call the observing function.
abstract  java.lang.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, remove, 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 java.lang.Object initialValue()
Overrides:
initialValue in class java.lang.ThreadLocal

run

public abstract java.lang.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 java.lang.Object observe(java.lang.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