01: /*
02: * Copyright 2000,2005 wingS development team.
03: *
04: * This file is part of wingS (http://wingsframework.org).
05: *
06: * wingS is free software; you can redistribute it and/or modify
07: * it under the terms of the GNU Lesser General Public License
08: * as published by the Free Software Foundation; either version 2.1
09: * of the License, or (at your option) any later version.
10: *
11: * Please see COPYING for the complete licence.
12: */
13: package org.wings.util;
14:
15: import org.wings.SimpleURL;
16:
17: /**
18: * This is a thread save global stack.
19: *
20: * @author <a href="mailto:H.Zeller@acm.org">Henner Zeller</a>
21: */
22: public class AnchorRenderStack {
23: /**
24: * 10 should be sufficient, so that we never need resizing. Usually
25: * this will not go over 2
26: */
27: private final static int INITIAL_STACK_DEPTH = 10;
28:
29: /*
30: * state for the ClickableRenderComponent.
31: */
32: private final static ThreadLocal eventURLStack = new ThreadLocal() {
33: protected synchronized Object initialValue() {
34: return new FastStack(INITIAL_STACK_DEPTH);
35: }
36: };
37:
38: /**
39: * reset the internal stacks. This should be done everytime a complete
40: * frame is rendered (maybe in some finally { }) to make sure the internal
41: * stacks do not fill up.
42: */
43: public static void reset() {
44: ((FastStack) eventURLStack.get()).clear();
45: }
46:
47: /**
48: * Push a new URL.
49: */
50: public static void push(SimpleURL url, String target) {
51: FastStack s = (FastStack) eventURLStack.get();
52: s.push(new AnchorProperties(url, target));
53: }
54:
55: public static void push(String formEventName, String formEventValue) {
56: FastStack s = (FastStack) eventURLStack.get();
57: s.push(new AnchorProperties(formEventName, formEventValue));
58: }
59:
60: public static void pop() {
61: FastStack s = (FastStack) eventURLStack.get();
62: s.pop();
63: }
64:
65: /**
66: * returns the topmost request URL on the stack or 'null', if there
67: * is no such element.
68: */
69: public static AnchorProperties get() {
70: FastStack s = (FastStack) eventURLStack.get();
71: return s.isEmpty() ? null : (AnchorProperties) s.peek();
72: }
73:
74: public static Object clear() {
75: Object oldValue = eventURLStack.get();
76: eventURLStack.set(new FastStack(INITIAL_STACK_DEPTH));
77: return oldValue;
78: }
79:
80: public static void set(Object stack) {
81: eventURLStack.set(stack);
82: }
83:
84: }
|