KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hero > user > UserBaseService


1 package hero.user;
2
3 import hero.util.HeroHookException;
4
5 import java.util.ArrayList JavaDoc;
6 import java.util.Collection JavaDoc;
7 import java.util.Properties JavaDoc;
8 import java.io.File JavaDoc;
9 import java.io.FileInputStream JavaDoc;
10 import java.lang.reflect.InvocationTargetException JavaDoc;
11
12 /**
13  * @author charoy 27 avr. 2004 - UserBaseService.java This program is free
14  * software; you can redistribute it and/or modify it under the terms of
15  * the GNU Lesser General Public License as published by the Free
16  * Software Foundation; either version 2 of the License, or (at your
17  * option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful, but WITHOUT
20  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
21  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
22  * details.
23  *
24  * You should have received a copy of the GNU Lesser General Public License
25  * along with this program; if not, write to the Free Software Foundation, Inc.,
26  * 675 Mass Ave, Cambridge, MA 02139, USA.
27  */

28
29 public class UserBaseService {
30     private ArrayList JavaDoc userbases;
31     static private UserBaseService ubs=null;
32     
33     private UserBaseService() {
34         userbases=new ArrayList JavaDoc();
35         ArrayList JavaDoc result = new ArrayList JavaDoc();
36         try {
37           Properties JavaDoc usersProps = new Properties JavaDoc();
38           ReadEnv re = new ReadEnv();
39           String JavaDoc bonitaHome=re.getVariable("BONITA_HOME");
40           usersProps.load(new FileInputStream JavaDoc(bonitaHome+File.separator+".ant.properties"));
41           result.add(constructor((String JavaDoc)usersProps.getProperty("user.base")));
42           userbases=result;
43           if (result.isEmpty())
44           {
45             result.add(new DefaultUserBase());
46             userbases=result;
47           }
48       }catch(Exception JavaDoc userEx){
49         result.add(new DefaultUserBase());
50         userbases=result;
51         userEx.printStackTrace();}
52     }
53         
54      public Object JavaDoc constructor(String JavaDoc name) throws HeroHookException {
55         try {
56             ClassLoader JavaDoc cl = Thread.currentThread().getContextClassLoader();
57             Class JavaDoc clName=cl.loadClass(name);
58             Class JavaDoc[] o={};
59             java.lang.reflect.Constructor JavaDoc cons = clName.getConstructor(o);
60             return(cons.newInstance(o));
61         } catch (Exception JavaDoc ite) {ite.getCause().printStackTrace();
62             throw new HeroHookException("Dynamic invocation failed :"+ite.getCause().getMessage());
63         }
64      }
65     
66     public static UserBaseService getInstance() {
67         if (ubs!=null) {
68             return ubs;
69         } else {
70             ubs=new UserBaseService();
71             return ubs;
72         }
73     }
74     
75     public Collection JavaDoc getUserBases() {
76         return userbases;
77     }
78 }
79
Popular Tags