KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > security > jacc > JPolicyContextHandlerCurrent


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 2004-2005 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * 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,v 1.3 2005/06/20 13:25:37 benoitf Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.jonas.security.jacc;
28
29 /**
30  * This class manages the current data object which is given to the
31  * PolicyContext
32  * @author Florent Benoit
33  */

34 public class JPolicyContextHandlerCurrent {
35
36     /**
37      * Unique instance
38      */

39     private static JPolicyContextHandlerCurrent current = new JPolicyContextHandlerCurrent();
40
41     /**
42      * Local thread
43      */

44     private static ThreadLocal JavaDoc threadData;
45
46     /**
47      * Method getCurrent
48      * @return JPolicyContextHandlerDataCurrent the current
49      */

50     public static JPolicyContextHandlerCurrent getCurrent() {
51         return current;
52     }
53
54     /**
55      * Default constructor
56      */

57     private JPolicyContextHandlerCurrent() {
58         threadData = new ThreadLocal JavaDoc();
59         threadData.set(new JPolicyContextHandlerData());
60     }
61
62     /**
63      * Method getJPolicyContextHandlerData
64      * @return the JPolicyContextHandlerData associated to the current thread
65      */

66     public synchronized JPolicyContextHandlerData getJPolicyContextHandlerData() {
67         if (threadData.get() == null) {
68             threadData.set(new JPolicyContextHandlerData());
69         }
70         return (JPolicyContextHandlerData) threadData.get();
71     }
72
73     /**
74      * Method setJPolicyContextHandlerData
75      * @param data JPolicyContextHandlerData to associate to the current thread
76      */

77     public void setJPolicyContextHandlerData(JPolicyContextHandlerData data) {
78         threadData.set(data);
79     }
80
81 }
82
Popular Tags