KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hero > mapper > CustomMapper


1 package hero.mapper;
2
3 /*
4 * 02/01/2002 - 15:24:07
5 *
6 * LdapMapper.java -
7 * Copyright (C) 2002 Ecoo Team
8 * charoy@loria.fr
9 *
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 JavaDoc;
30 import java.lang.reflect.Method JavaDoc;
31 import org.apache.log4j.Category;
32
33 import java.util.Collection JavaDoc;
34
35 public class CustomMapper extends Mapper {
36
37     // Utility variable
38
private static final Category log = Category.getInstance(LdapMapper.class);
39
40
41     public CustomMapper(String JavaDoc name, int type) {
42     super(name,type);
43     }
44
45     public Collection JavaDoc execute(Object JavaDoc bean, int type, BnRoleLocal role, String JavaDoc userName) throws HeroException {
46     log.debug("execute: type="+type+" role="+role.getName());
47         
48     try {
49         // The name of the class depend only on the mapper type
50
Class JavaDoc clmapper=Class.forName(this.getName());
51         RoleMapperI ndh =(RoleMapperI)clmapper.newInstance();
52         Class JavaDoc[] param={
53         Class.forName("java.lang.Object"),
54         Class.forName("hero.interfaces.BnRoleLocal"),
55         Class.forName("java.lang.String")};
56         Method JavaDoc evth=clmapper.getMethod("searchMembers",param);
57         Object JavaDoc[] o={bean,role,userName};
58         return((Collection JavaDoc)evth.invoke(ndh,o));
59     } catch (InvocationTargetException JavaDoc ite) {
60         throw new HeroException("Failure during mapper execution : " + ite.getMessage());
61     } catch (Exception JavaDoc e) {
62         throw new HeroException("Dynamic invocation of mapper failed :"+this.getName()+"#"+role.getName()+"--> mapper type = "+type+" ///"+e);
63     }
64     }
65
66
67 }
68
Popular Tags