01: /**
02: * JOnAS: Java(TM) Open Application Server
03: * Copyright (C) 2004-2005 Bull S.A.
04: * Contact: jonas-team@objectweb.org
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19: * USA
20: *
21: * Initial developer: Florent BENOIT
22: * --------------------------------------------------------------------------
23: * $Id: JPolicyContextHandlerCurrent.java 6977 2005-06-20 13:25:37Z benoitf $
24: * --------------------------------------------------------------------------
25: */package org.objectweb.jonas.security.jacc;
26:
27: /**
28: * This class manages the current data object which is given to the
29: * PolicyContext
30: * @author Florent Benoit
31: */
32: public class JPolicyContextHandlerCurrent {
33:
34: /**
35: * Unique instance
36: */
37: private static JPolicyContextHandlerCurrent current = new JPolicyContextHandlerCurrent();
38:
39: /**
40: * Local thread
41: */
42: private static ThreadLocal threadData;
43:
44: /**
45: * Method getCurrent
46: * @return JPolicyContextHandlerDataCurrent the current
47: */
48: public static JPolicyContextHandlerCurrent getCurrent() {
49: return current;
50: }
51:
52: /**
53: * Default constructor
54: */
55: private JPolicyContextHandlerCurrent() {
56: threadData = new ThreadLocal();
57: threadData.set(new JPolicyContextHandlerData());
58: }
59:
60: /**
61: * Method getJPolicyContextHandlerData
62: * @return the JPolicyContextHandlerData associated to the current thread
63: */
64: public synchronized JPolicyContextHandlerData getJPolicyContextHandlerData() {
65: if (threadData.get() == null) {
66: threadData.set(new JPolicyContextHandlerData());
67: }
68: return (JPolicyContextHandlerData) threadData.get();
69: }
70:
71: /**
72: * Method setJPolicyContextHandlerData
73: * @param data JPolicyContextHandlerData to associate to the current thread
74: */
75: public void setJPolicyContextHandlerData(
76: JPolicyContextHandlerData data) {
77: threadData.set(data);
78: }
79:
80: }
|