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