01: /*
02: * (C) Copyright 2006 Nabh Information Systems, Inc.
03: *
04: * All copyright notices regarding Nabh's products MUST remain
05: * intact in the scripts and in the outputted HTML.
06: * This program is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public License
08: * as published by the Free Software Foundation; either version 2.1
09: * of the License, or (at your option) any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: * GNU Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public License
17: * along with this program; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19: *
20: */
21: package com.nabhinc.util;
22:
23: import java.io.Serializable;
24: import java.lang.reflect.InvocationTargetException;
25: import java.util.ArrayList;
26: import java.util.List;
27:
28: import javax.xml.bind.annotation.XmlAttribute;
29: import javax.xml.bind.annotation.XmlElement;
30:
31: /**
32: *
33: *
34: * @author Padmanabh Dabke
35: * (c) 2006 Nabh Information Systems, Inc. All Rights Reserved.
36: */
37: public class ComponentConfig implements Serializable {
38:
39: private static final long serialVersionUID = 6431069396560077272L;
40:
41: @XmlAttribute(name="class")
42: public String componentClass = null;
43:
44: @XmlElement(name="init-param")
45: public List<InitParamConfig> params = new ArrayList<InitParamConfig>();
46:
47: public static Object createComponent(ComponentConfig cc)
48: throws InstantiationException, IllegalAccessException,
49: ClassNotFoundException, IllegalArgumentException,
50: InvocationTargetException {
51: if (cc == null)
52: throw new IllegalArgumentException("Null ComponentConfig!");
53: if (cc.componentClass == null)
54: throw new IllegalArgumentException(
55: "Component class must be specified.");
56: Object obj = Class.forName(cc.componentClass).newInstance();
57: if (cc.params != null) {
58: for (int i = 0; i < cc.params.size(); i++) {
59: InitParamConfig paramConfig = cc.params.get(i);
60:
61: ReflectionUtil.setObjectProperty(obj, paramConfig.name,
62: paramConfig.value, true);
63: }
64: }
65: return obj;
66: }
67: }
|