1 package org.apache.beehive.controls.api.context; 2 19 20 import java.util.Stack ; 21 22 29 public class ControlThreadContext 30 { 31 34 static private ThreadLocal <Stack <ControlContainerContext>> _threadContexts = 35 new ThreadLocal <Stack <ControlContainerContext>>(); 36 37 42 public static ControlContainerContext getContext() 43 { 44 Stack <ControlContainerContext> contextStack = _threadContexts.get(); 45 if (contextStack == null || contextStack.size() == 0) 46 return null; 47 48 return contextStack.peek(); 49 } 50 51 54 public static void beginContext(ControlContainerContext context) 55 { 56 Stack <ControlContainerContext> contextStack = _threadContexts.get(); 57 if (contextStack == null) 58 { 59 contextStack = new Stack <ControlContainerContext>(); 60 _threadContexts.set(contextStack); 61 } 62 contextStack.push(context); 63 } 64 65 70 public static void endContext(ControlContainerContext context) 71 { 72 Stack <ControlContainerContext> contextStack = _threadContexts.get(); 73 if (contextStack == null || contextStack.size() == 0) 74 throw new IllegalStateException ("No context started for current thread"); 75 76 if (contextStack.peek() != context) 77 throw new IllegalStateException ("Context is not the current active context"); 78 79 contextStack.pop(); 80 } 81 } 82 | Popular Tags |