01: package hero.mapper;
02:
03: /*
04: * 02/01/2002 - 15:24:07
05: *
06: * LdapMapper.java -
07: * Copyright (C) 2002 Ecoo Team
08: * charoy@loria.fr
09: *
10: *
11: * This program is free software; you can redistribute it and/or
12: * modify it under the terms of the GNU Lesser General Public License
13: * as published by the Free Software Foundation; either version 2
14: * of the License, or (at your option) any later version.
15: *
16: * This program is distributed in the hope that it will be useful,
17: * but WITHOUT ANY WARRANTY; without even the implied warranty of
18: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19: * GNU Lesser General Public License for more details.
20: *
21: * You should have received a copy of the GNU Lesser General Public License
22: * along with this program; if not, write to the Free Software
23: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24: */
25:
26: import hero.interfaces.BnRoleLocal;
27: import hero.util.HeroException;
28:
29: import java.lang.reflect.InvocationTargetException;
30: import java.lang.reflect.Method;
31:
32: import org.apache.log4j.Category;
33: import java.util.Collection;
34:
35: public class LdapMapper extends Mapper {
36:
37: // Utility variable
38: private static final Category log = Category
39: .getInstance(LdapMapper.class);
40:
41: public LdapMapper(String name, int type) {
42: super (name, type);
43: }
44:
45: public Collection execute(Object bean, int type, BnRoleLocal role,
46: String userName) throws HeroException {
47: log.debug("execute: type=" + type + " role=" + role.getName());
48:
49: try {
50: // The name of the class depend only on the mapper type
51: //Class clmapper=Class.forName(this.getName());
52: Class clmapper = Class.forName(
53: "hero.mapper.LdapGroupMembers", true, Thread
54: .currentThread().getContextClassLoader());
55: RoleMapperI ndh = (RoleMapperI) clmapper.newInstance();
56: Class[] param = {
57: Class.forName("java.lang.Object"),
58: Class.forName("hero.interfaces.BnRoleLocal", true,
59: Thread.currentThread()
60: .getContextClassLoader()),
61: Class.forName("java.lang.String") };
62: Method evth = clmapper.getMethod("searchMembers", param);
63: Object[] o = { bean, role, userName };
64: return ((Collection) evth.invoke(ndh, o));
65: } catch (InvocationTargetException ite) {
66: throw new HeroException(
67: "Failure during mapper execution : "
68: + ite.getMessage());
69: } catch (Exception e) {
70: throw new HeroException(
71: "Dynamic invocation of mapper failed :"
72: + this .getName() + "#" + role.getName()
73: + "--> mapper type = " + type + " ///" + e);
74: }
75: }
76:
77: }
|