KickJava   Java API By Example, From Geeks To Geeks.

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


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.UserException;
23 import org.apache.jetspeed.services.security.JetspeedSecurityService;
24
25 /**
26  * Factory class for creating Jetspeed Users.
27  * The user class is configured in the JR.p
28  *
29  * @author <a HREF="mailto:taylor@apache.org">David Sean Taylor</a>
30  * @version $Id: JetspeedUserFactory.java,v 1.4 2004/02/23 03:14:12 jford Exp $
31  */

32 public class JetspeedUserFactory
33 {
34     private static final String JavaDoc CONFIG_USER_CLASSNAME = "user.class";
35
36     private static String JavaDoc userClassName = null;
37     private static Class JavaDoc userClass = null;
38     
39     /**
40      * Factory method to create JetspeedUser instances.
41      *
42      *
43      * @throws UnknownEntityException when the user instance cant be created.
44      * @return JetspeedUser a new created user.
45      */

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