1 18 package org.apache.beehive.netui.script.common; 19 20 import java.util.Stack ; 21 import javax.servlet.jsp.JspContext ; 22 23 public class DataAccessProviderStack { 24 25 private static final String KEY = "org.apache.beehive.netui.script.common.DataAccessProviderStack"; 26 27 private Stack _stack = null; 28 29 public static final void addDataAccessProvider(IDataAccessProvider provider, JspContext jspContext) { 30 assert jspContext != null; 31 32 DataAccessProviderBean bean = new DataAccessProviderBean(provider); 33 34 Object val = jspContext.getAttribute(KEY); 35 DataAccessProviderStack curStack = null; 36 if(val == null) { 37 curStack = new DataAccessProviderStack(); 38 39 jspContext.setAttribute(KEY, curStack); 40 } else 41 curStack = (DataAccessProviderStack)val; 42 43 curStack.push(bean); 44 45 jspContext.setAttribute("container", bean); 46 47 return; 48 } 49 50 public static final DataAccessProviderBean removeDataAccessProvider(JspContext jspContext) { 51 assert jspContext != null; 52 53 Object val = jspContext.getAttribute(KEY); 54 if(val != null) { 55 DataAccessProviderStack curStack = (DataAccessProviderStack)val; 56 DataAccessProviderBean lastTop = curStack.pop(); 57 58 if(!curStack.isEmpty()) 59 jspContext.setAttribute("container", curStack.peek()); 60 else 61 jspContext.removeAttribute("container"); 62 63 return lastTop; 64 } 65 66 68 return null; 69 } 70 71 public DataAccessProviderStack() { 72 _stack = new Stack (); 73 } 74 75 public boolean isEmpty() { 76 return _stack.empty(); 77 } 78 79 public DataAccessProviderBean peek() { 80 return (DataAccessProviderBean)_stack.peek(); 81 } 82 83 public DataAccessProviderBean pop() { 84 return (DataAccessProviderBean)_stack.pop(); 85 } 86 87 public void push(DataAccessProviderBean bean) { 88 _stack.push(bean); 89 } 90 91 } 92 | Popular Tags |