View Javadoc

1   /*
2    * Created on 2003-6-2 16:54:15 by joel guo
3    *
4    * vTradEx Information Technology Inc.
5    */
6   package com.cyclops.albumbuilder;
7   import java.util.ArrayList;
8   import java.util.HashMap;
9   import java.util.Iterator;
10  import java.util.List;
11  
12  import org.apache.commons.configuration.Configuration;
13  import org.apache.commons.logging.Log;
14  import org.apache.commons.logging.LogFactory;
15  import org.apache.stratum.lifecycle.Configurable;
16  import org.apache.stratum.lifecycle.Executable;
17  import org.apache.stratum.lifecycle.Initializable;
18  /***
19   * Add description for this class <font color="red">HERE</font>!
20   * <big><font face="黑体">惩前毖后,治病救人</font></big>
21   * 
22   * @author <a href="mailto:[email protected]">joel guo</a>
23   * @company <a href="http://www.vtradex.com">vTradEx</a>
24   * @since 2003-6-2 16:54:15
25   */
26  public class AlbumBuilder implements Configurable, Initializable, Executable {
27      private HashMap components = new HashMap();
28      private Configuration configuration;
29      private Log logger = LogFactory.getLog(getClass());
30      private List commands = new ArrayList();
31      /*** Override method configure() of super class
32       * @see org.apache.stratum.lifecycle.Configurable#configure(org.apache.commons.configuration.Configuration)
33       */
34      public void configure(Configuration conf) {
35          configuration = conf;
36      }
37      /*** Override method initialize() of super class
38       * @see org.apache.stratum.lifecycle.Initializable#initialize()
39       */
40      public void initialize() {
41          components.put("thumbnail", ThumbnailGenerator.class);
42          components.put("index", GalleryIndexGenerator.class);
43          components.put("copy", SourceResourceCopier.class);
44      }
45      /*** Method addCommand()
46       * @param command Command string to be add
47       */
48      public void addCommand(String command) {
49          commands.add(command);
50      }
51      /*** Override method execute() of super class
52       * @see org.apache.stratum.lifecycle.Executable#execute()
53       */
54      public void execute() throws Exception {
55          ComponentLoader cl = new ComponentLoader(configuration);
56          for (Iterator i = commands.iterator(); i.hasNext();) {
57              String command = (String) i.next();
58              if (components.containsKey(command)) {
59                  Class clazz = (Class) components.get(command);
60                  try {
61                      cl.executeComponent(clazz);
62                  } catch (Exception e) {
63                      logger.error("Execute command error");
64                  }
65              }
66          }
67      }
68  }