KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > wings > util > AnchorRenderStack


1 /*
2  * $Id: AnchorRenderStack.java,v 1.3 2004/12/01 07:54:30 hengels Exp $
3  * Copyright 2000,2005 wingS development team.
4  *
5  * This file is part of wingS (http://www.j-wings.org).
6  *
7  * wingS is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * Please see COPYING for the complete licence.
13  */

14 package org.wings.util;
15
16 import org.wings.SimpleURL;
17
18 /**
19  * This is a thread save global stack.
20  *
21  * @author <a HREF="mailto:H.Zeller@acm.org">Henner Zeller</a>
22  * @version $Revision: 1.3 $
23  */

24 public class AnchorRenderStack {
25     /**
26      * 10 should be sufficient, so that we never need resizing. Usually
27      * this will not go over 2
28      */

29     private final static int INITIAL_STACK_DEPTH = 10;
30
31     /*
32      * state for the ClickableRenderComponent.
33      */

34     private final static ThreadLocal JavaDoc eventURLStack = new ThreadLocal JavaDoc() {
35         protected synchronized Object JavaDoc initialValue() {
36             return new FastStack(INITIAL_STACK_DEPTH);
37         }
38     };
39
40     /**
41      * reset the internal stacks. This should be done everytime a complete
42      * frame is rendered (maybe in some finally { }) to make sure the internal
43      * stacks do not fill up.
44      */

45     public static void reset() {
46         ((FastStack) eventURLStack.get()).clear();
47     }
48
49     /**
50      * Push a new URL.
51      */

52     public static void push(SimpleURL url, String JavaDoc target) {
53         FastStack s = (FastStack) eventURLStack.get();
54         s.push(new AnchorProperties(url, target));
55     }
56
57     public static void push(String JavaDoc formEventName, String JavaDoc formEventValue) {
58         FastStack s = (FastStack) eventURLStack.get();
59         s.push(new AnchorProperties(formEventName, formEventValue));
60     }
61
62
63     public static void pop() {
64         FastStack s = (FastStack) eventURLStack.get();
65         s.pop();
66     }
67
68     /**
69      * returns the topmost request URL on the stack or 'null', if there
70      * is no such element.
71      */

72     public static AnchorProperties get() {
73         FastStack s = (FastStack) eventURLStack.get();
74         return s.isEmpty() ? null : (AnchorProperties) s.peek();
75     }
76
77     public static Object JavaDoc clear() {
78         Object JavaDoc oldValue = eventURLStack.get();
79         eventURLStack.set(new FastStack(INITIAL_STACK_DEPTH));
80         return oldValue;
81     }
82
83     public static void set(Object JavaDoc stack) {
84         eventURLStack.set(stack);
85     }
86
87
88 }
89
90
91
Popular Tags