01: package hero.user;
02:
03: import hero.util.HeroHookException;
04:
05: import java.util.ArrayList;
06: import java.util.Collection;
07: import java.util.Properties;
08: import java.io.File;
09: import java.io.FileInputStream;
10: import java.lang.reflect.InvocationTargetException;
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 userbases;
31: static private UserBaseService ubs = null;
32:
33: private UserBaseService() {
34: userbases = new ArrayList();
35: ArrayList result = new ArrayList();
36: try {
37: Properties usersProps = new Properties();
38: ReadEnv re = new ReadEnv();
39: String bonitaHome = re.getVariable("BONITA_HOME");
40: usersProps.load(new FileInputStream(bonitaHome
41: + File.separator + ".ant.properties"));
42: result.add(constructor((String) usersProps
43: .getProperty("user.base")));
44: userbases = result;
45: if (result.isEmpty()) {
46: result.add(new DefaultUserBase());
47: userbases = result;
48: }
49: } catch (Exception userEx) {
50: result.add(new DefaultUserBase());
51: userbases = result;
52: userEx.printStackTrace();
53: }
54: }
55:
56: public Object constructor(String name) throws HeroHookException {
57: try {
58: ClassLoader cl = Thread.currentThread()
59: .getContextClassLoader();
60: Class clName = cl.loadClass(name);
61: Class[] o = {};
62: java.lang.reflect.Constructor cons = clName
63: .getConstructor(o);
64: return (cons.newInstance((Object[]) o));
65: } catch (Exception ite) {
66: ite.getCause().printStackTrace();
67: throw new HeroHookException("Dynamic invocation failed :"
68: + ite.getCause().getMessage());
69: }
70: }
71:
72: public static UserBaseService getInstance() {
73: if (ubs != null) {
74: return ubs;
75: } else {
76: ubs = new UserBaseService();
77: return ubs;
78: }
79: }
80:
81: public Collection getUserBases() {
82: return userbases;
83: }
84: }
|