1 /*
2 * Created on 2003-5-30 10:59:24 by joel guo
3 *
4 * vTradEx Information Technology Inc.
5 */
6 package com.cyclops.albumbuilder;
7 import org.apache.commons.configuration.Configuration;
8 import org.apache.commons.logging.Log;
9 import org.apache.commons.logging.LogFactory;
10 import org.apache.stratum.lifecycle.Configurable;
11 import org.apache.stratum.lifecycle.Executable;
12 import org.apache.stratum.lifecycle.Initializable;
13 /***
14 * Temporary component loader class, it'll be replaced by some common framework in the future
15 * <big><font face="黑体">惩前毖后,治病救人</font></big>
16 *
17 * @author <a href="mailto:joeblack.guo@vtradex.com">joel guo</a>
18 * @company <a href="http://www.vtradex.com">vTradEx</a>
19 * @since 2003-5-30 10:59:24
20 */
21 public class ComponentLoader {
22 private Configuration configuration;
23 private Log logger = LogFactory.getLog(getClass());
24 /*** Constructor method for class ComponentLoader
25 * @param conf Configuration object
26 */
27 public ComponentLoader(Configuration conf) {
28 configuration = conf;
29 }
30 /*** Method executeComponent()
31 * @param clazz Requested class
32 * @throws Exception Just throw it out
33 */
34 public void executeComponent(Class clazz) throws Exception {
35 executeComponent(getComponent(clazz));
36 }
37 private void executeComponent(Object obj) throws Exception {
38 if (obj instanceof Executable) {
39 ((Executable) obj).execute();
40 }
41 }
42 /*** Method executeComponent()
43 * @param className Name of requested class
44 * @throws Exception Just throw it out
45 */
46 public void executeComponent(String className) throws Exception {
47 executeComponent(getComponent(className));
48 }
49 /*** Method getComponent()
50 * @param clazz Class of the component
51 * @return Instance of created component
52 * @throws Exception Just throw it out
53 */
54 public Object getComponent(Class clazz) throws Exception {
55 Object obj = clazz.newInstance();
56 logger.debug(clazz + " instance created");
57 if (obj instanceof Configurable) {
58 ((Configurable) obj).configure(configuration);
59 }
60 if (obj instanceof Initializable) {
61 ((Initializable) obj).initialize();
62 }
63 return obj;
64 }
65 /*** Method getComponent()
66 * @param className Name of requested class
67 * @return Instance of created component
68 * @throws Exception Just throw it out
69 */
70 public Object getComponent(String className) throws Exception {
71 return getComponent(Class.forName(className));
72 }
73 }
This page was automatically generated by Maven