01: /*
02: *
03: * Mapper.java -
04: * Copyright (C) 2003 Ecoo Team
05: * charoy@loria.fr
06: *
07: *
08: * This program is free software; you can redistribute it and/or
09: * modify it under the terms of the GNU Lesser General Public License
10: * as published by the Free Software Foundation; either version 2
11: * of the License, or (at your option) any later version.
12: *
13: * This program is distributed in the hope that it will be useful,
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16: * GNU Lesser General Public License for more details.
17: *
18: * You should have received a copy of the GNU Lesser General Public License
19: * along with this program; if not, write to the Free Software
20: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21: */
22:
23: package hero.mapper;
24:
25: import hero.interfaces.BnRoleLocal;
26: import hero.util.HeroException;
27: import java.io.Serializable;
28: import java.util.Collection;
29:
30: public abstract class Mapper implements Serializable {
31:
32: public static final int LDAP = 0;
33: public static final int PROPERTIES = 1;
34: public static final int CUSTOM = 2;
35:
36: private String name;
37: private int type;
38:
39: public static Mapper make(String name, int type)
40: throws HeroException {
41: if (type == LDAP) {
42: return new LdapMapper(name, type);
43: }
44: if (type == PROPERTIES) {
45: return new PropertiesMapper(name, type);
46: }
47: if (type == CUSTOM) {
48: return new CustomMapper(name, type);
49: }
50:
51: throw new HeroException("Wrong Mapper Type " + type);
52: }
53:
54: protected Mapper(String name, int type) {
55: this .name = name;
56: this .type = type;
57: }
58:
59: public String getName() {
60: return this .name;
61: }
62:
63: public void setName(String name) {
64: this .name = name;
65: }
66:
67: public int getType() {
68: return this .type;
69: }
70:
71: public void setType(int type) {
72: this .type = type;
73: }
74:
75: public String toXML() {
76: String result = new String();
77: result = "<mapper name=\"" + this .getName() + "\" type=\""
78: + this .getType() + "\"/>";
79: return result;
80: }
81:
82: public abstract Collection execute(Object bean, int type,
83: BnRoleLocal role, String userName) throws HeroException;
84:
85: }
|