01: /*
02: Mdarad-Toolobox is a collection of tools for Architected RAD
03: (Rapid Application Development) based on an MDA approach.
04: The toolbox contains frameworks and generators for many environments
05: (JAVA, J2EE, Hibernate, .NET, C++, etc.) which allow to generate
06: applications from a design Model
07: Copyright (C) 2004-2005 Elapse Technologies Inc.
08:
09: This library is free software; you can redistribute it and/or
10: modify it under the terms of the GNU General Public
11: License as published by the Free Software Foundation; either
12: version 2.1 of the License, or (at your option) any later version.
13:
14: This library is distributed in the hope that it will be useful,
15: but WITHOUT ANY WARRANTY; without even the implied warranty of
16: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17: General Public License for more details.
18:
19: You should have received a copy of the GNU General Public
20: License along with this library; if not, write to the Free Software
21: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22: */
23:
24: package org.mdarad.framework.util.struts;
25:
26: /**
27: * Created by IntelliJ IDEA.
28: * User: Administrateur
29: * Date: 8-Sep-2004
30: * Time: 2:29:38 PM
31: * To change this template use File | Settings | File Templates.
32: */
33: public class Alternator {
34: private static final ThreadLocal THREAD_LOCAL = new ThreadLocal();
35: private static final String ALTERNATOR_EVEN_LABEL = "even";
36: private static final String ALTERNATOR_ODD_LABEL = "odd";
37:
38: public static String alternate() {
39: String output = null;
40:
41: Boolean state = (Boolean) THREAD_LOCAL.get();
42: if (state == null) {
43: // initialize at false, -1, "odd", to start at true, 0, "even"
44: state = new Boolean(false);
45: }
46:
47: THREAD_LOCAL.set(new Boolean(!state.booleanValue()));
48:
49: if (state.booleanValue()) {
50: output = ALTERNATOR_ODD_LABEL;
51: } else {
52: output = ALTERNATOR_EVEN_LABEL;
53: }
54:
55: return output;
56: }
57:
58: public static void reset() {
59: THREAD_LOCAL.set(null);
60: }
61: }
|