1/*2 * Copyright 2000-2001,2004 The Apache Software Foundation.3 * 4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */1617packageorg.apache.jetspeed.om.security;
1819import org.apache.turbine.services.TurbineServices;
20import org.apache.turbine.services.resources.ResourceService;
2122import org.apache.jetspeed.services.security.RoleException;
23import org.apache.jetspeed.services.security.JetspeedSecurityService;
2425/***26 * Factory class for creating Jetspeed Roles.27 * The role class is configured in the JR.p28 *29 */30publicclassJetspeedRoleFactory31 {
32privatestaticfinal String CONFIG_ROLE_CLASSNAME = "role.class";
3334privatestatic String roleClassName = null;
35privatestatic Class roleClass = null;
3637/***38 * Factory method to create JetspeedRole instances. 39 *40 *41 * @throws UnknownEntityException when the role instance cant be created.42 * @return Role a new created role.43 */44publicstaticRole getInstance()
45 throws RoleException46 {
47return getInstance(true);
48 }
4950publicstaticRole getInstance(boolean isNew)
51 throws RoleException52 {
53Role role = null;
5455if (null == roleClassName)
56 {
57try58 {
59 ResourceService serviceConf = ((TurbineServices)TurbineServices.getInstance())
60 .getResources(JetspeedSecurityService.SERVICE_NAME);
61 roleClassName = serviceConf.getString(CONFIG_ROLE_CLASSNAME);
62 roleClass = Class.forName(roleClassName);
63 }
64catch(Exception e)
65 {
66thrownewRoleException(
67"RoleFactory: Failed to create a Class object for Role implementation: " + e.toString());
68 }
69 }
7071try72 {
73 role = (Role)roleClass.newInstance();
74if (role instanceof BaseJetspeedRole)
75 {
76 ((BaseJetspeedRole)role).setNew(isNew);
77 }
78 }
79catch(Exception e)
80 {
81thrownewRoleException("Failed instantiate an Role implementation object: " + e.toString());
82 }
8384return role;
85 }
868788 }
8990