KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > om > security > JetspeedRoleFactory


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 at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * 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 and
14  * limitations under the License.
15  */

16
17 package org.apache.jetspeed.om.security;
18
19 import org.apache.turbine.services.TurbineServices;
20 import org.apache.turbine.services.resources.ResourceService;
21
22 import org.apache.jetspeed.services.security.RoleException;
23 import org.apache.jetspeed.services.security.JetspeedSecurityService;
24
25 /**
26  * Factory class for creating Jetspeed Roles.
27  * The role class is configured in the JR.p
28  *
29  */

30 public class JetspeedRoleFactory
31 {
32     private static final String JavaDoc CONFIG_ROLE_CLASSNAME = "role.class";
33
34     private static String JavaDoc roleClassName = null;
35     private static Class JavaDoc roleClass = null;
36     
37     /**
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      */

44     public static Role getInstance()
45         throws RoleException
46     {
47         return getInstance(true);
48     }
49
50     public static Role getInstance(boolean isNew)
51         throws RoleException
52     {
53         Role role = null;
54
55         if (null == roleClassName)
56         {
57             try
58             {
59                 ResourceService serviceConf = ((TurbineServices)TurbineServices.getInstance())
60                                                          .getResources(JetspeedSecurityService.SERVICE_NAME);
61                 roleClassName = serviceConf.getString(CONFIG_ROLE_CLASSNAME);
62                 roleClass = Class.forName(roleClassName);
63             }
64             catch(Exception JavaDoc e)
65             {
66                 throw new RoleException(
67                     "RoleFactory: Failed to create a Class object for Role implementation: " + e.toString());
68             }
69         }
70
71         try
72         {
73             role = (Role)roleClass.newInstance();
74             if (role instanceof BaseJetspeedRole)
75             {
76                 ((BaseJetspeedRole)role).setNew(isNew);
77             }
78         }
79         catch(Exception JavaDoc e)
80         {
81             throw new RoleException("Failed instantiate an Role implementation object: " + e.toString());
82         }
83
84         return role;
85     }
86     
87
88 }
89
90
91
Popular Tags