KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > rift > coad > lib > security > ThreadsPermissionContainerAccessor


1 /*
2  * CoadunationLib: The coaduntion implementation library.
3  * Copyright (C) 2006 Rift IT Contracting
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * ThreadsPermissionContainerAccessor.java
20  *
21  * This object supplies access to the thread permission container.
22  */

23
24 // package path
25
package com.rift.coad.lib.security;
26
27 // coadunation imports
28
import com.rift.coad.lib.configuration.ConfigurationFactory;
29 import com.rift.coad.lib.configuration.Configuration;
30
31 /**
32  * This object supplies access to the thread permission container.
33  *
34  * @author Brett Chaldecott
35  */

36 public class ThreadsPermissionContainerAccessor {
37     
38     // class constants
39
private final static String JavaDoc ROLE = "role";
40     
41     // private singleton
42
private static ThreadsPermissionContainerAccessor singleton = null;
43     
44     // private member variables
45
private String JavaDoc role = null;
46     private ThreadsPermissionContainer permissionContainer = null;
47     
48     /**
49      * Creates a new instance of ThreadsPermissionContainerAccessor
50      *
51      * @param permissionContainer The container reference.
52      * @exception SecurityException
53      */

54     private ThreadsPermissionContainerAccessor(
55             ThreadsPermissionContainer permissionContainer)
56             throws SecurityException JavaDoc {
57         try {
58             this.permissionContainer = permissionContainer;
59             Configuration config = ConfigurationFactory.getInstance().getConfig(
60                     this.getClass());
61             role = config.getString(ROLE);
62         } catch (Exception JavaDoc ex) {
63             throw new SecurityException JavaDoc(
64                     "Failed to instanciate the thread permission container " +
65                     "accessor because : " + ex.getMessage(),ex);
66         }
67     }
68     
69     
70     /**
71      * This method instanciates a new thread permission container accessor.
72      *
73      * @return A reference to this singleton.
74      * @param permissionContainer The reference to the permissions container.
75      */

76     public synchronized static ThreadsPermissionContainerAccessor init (
77             ThreadsPermissionContainer permissionContainer)
78             throws SecurityException JavaDoc {
79         if (singleton == null) {
80             singleton = new ThreadsPermissionContainerAccessor(
81                     permissionContainer);
82         }
83         return singleton;
84     }
85     
86     
87     /**
88      * This method is responsible for returning a reference to the singleton.
89      *
90      * @return A reference to the singleton.
91      * @exception SecurityException
92      */

93     public synchronized static ThreadsPermissionContainerAccessor getInstance()
94             throws SecurityException JavaDoc {
95         if (singleton == null) {
96             throw new SecurityException JavaDoc(
97                     "The accessor has not been instanciated.");
98         }
99         return singleton;
100     }
101     
102     
103     /**
104      * This method returns a reference to the threads permission container.
105      *
106      * @return A reference to the thread permission container.
107      * @exception AuthorizationException
108      * @exception SecurityException
109      */

110     public ThreadsPermissionContainer getThreadsPermissionContainer() throws
111             AuthorizationException, SecurityException JavaDoc
112     {
113         Validator.validate(this.getClass(),role);
114         return permissionContainer;
115     }
116     
117 }
118
Popular Tags