KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > rift > coad > lib > security > user > UserStoreManagerAccessor


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  * UserStoreManagerAccessor.java
20  *
21  * This object is responsible for supplying access to the user store manager.
22  */

23
24 // package path
25
package com.rift.coad.lib.security.user;
26
27 // coadunation imports
28
import com.rift.coad.lib.configuration.Configuration;
29 import com.rift.coad.lib.configuration.ConfigurationFactory;
30 import com.rift.coad.lib.security.Validator;
31 import com.rift.coad.lib.security.AuthorizationException;
32 import com.rift.coad.lib.security.SecurityException;
33
34
35 /**
36  * This object is responsible for supplying access to the user store manager.
37  *
38  * @author Brett Chaldecott
39  */

40 public class UserStoreManagerAccessor {
41     
42     // class constants
43
private final static String JavaDoc ROLE = "role";
44     
45     // class member variables
46
private static UserStoreManagerAccessor singleton = null;
47     
48     // private member variables
49
private UserStoreManager userStoreManager = null;
50     private String JavaDoc role = null;
51     
52     /**
53      * Creates a new instance of UserStoreManagerAccessor
54      *
55      * @param userStoreManager The reference to the user store object.
56      * @exception UserException
57      */

58     private UserStoreManagerAccessor(UserStoreManager userStoreManager)
59             throws UserException {
60         try {
61             this.userStoreManager = userStoreManager;
62             Configuration configuration =
63                     ConfigurationFactory.getInstance().getConfig(this.getClass());
64             role = configuration.getString(ROLE);
65         } catch (Exception JavaDoc ex) {
66             throw new UserException (
67                     "Failed to instanciate the user store manager accessor : " +
68                     ex.getMessage(),ex);
69         }
70     }
71     
72     
73     /**
74      * This method instanciates the user store manager accessor.
75      *
76      * @return A reference to the user store manager accessor.
77      * @param userStoreManager The reference to the user store manager.
78      * @exception UserException
79      */

80     public synchronized static UserStoreManagerAccessor init(
81             UserStoreManager userStoreManager)
82             throws UserException {
83         if (singleton == null) {
84             singleton = new UserStoreManagerAccessor(userStoreManager);
85         }
86         return singleton;
87     }
88     
89     
90     /**
91      * This method retrieves a reference to the user store manager instance.
92      *
93      * @return A reference to the user store manager accessor.
94      * @exception UserException;
95      */

96     public synchronized static UserStoreManagerAccessor getInstance()
97             throws UserException {
98         if (singleton == null) {
99             throw new UserException(
100                     "The user store manager accessor has not been instanciated");
101         }
102         return singleton;
103     }
104     
105     
106     /**
107      * This method returns a reference to the user store manager.
108      *
109      * @return A reference to the user session manager object.
110      * @exception AuthorizationException
111      * @exception SecurityException
112      */

113     public UserStoreManager getUserStoreManager()
114             throws AuthorizationException, SecurityException JavaDoc {
115         Validator.validate(this.getClass(),role);
116         return userStoreManager;
117     }
118 }
119
Popular Tags