1 10 11 package org.picocontainer.defaults; 12 13 23 public abstract class ThreadLocalCyclicDependencyGuard extends ThreadLocal implements CyclicDependencyGuard { 24 25 29 protected Object initialValue() { 30 return Boolean.FALSE; 31 } 32 39 public abstract Object run(); 40 41 49 public final Object observe(Class stackFrame) { 50 if (Boolean.TRUE.equals(get())) { 51 throw new CyclicDependencyException(stackFrame); 52 } 53 Object result = null; 54 try { 55 set(Boolean.TRUE); 56 result = run(); 57 } catch (final CyclicDependencyException e) { 58 e.push(stackFrame); 59 throw e; 60 } finally { 61 set(Boolean.FALSE); 62 } 63 return result; 64 } 65 } 66 | Popular Tags |