View Javadoc

1   package net.sf.chainedoptions;
2   
3   import java.util.Iterator;
4   import java.util.List;
5   import java.util.Map;
6   
7   import org.springframework.beans.factory.InitializingBean;
8   
9   /***
10   * Default implementation of <code>ChainedOptionManager</code>. Operates on an
11   * ordered collection of <code>ChainedOption</code> objects.
12   * 
13   * @author Mattias Arthursson
14   * @author Ulrik Sandberg
15   * 
16   */
17  public class ChainedOptionManagerImpl implements ChainedOptionManager,
18          InitializingBean {
19  
20      private List chainedOptions;
21  
22      /***
23       * Iterate through the collection of <code>ChainedOption</code> objects and
24       * call <code>retrieveOptions</code> and <code>updateValue</code>. Put
25       * the option Lists in the map with keys retrieved from the ChainedOption
26       * objects.
27       * 
28       * @param model
29       *            the map to store option Lists in.
30       * @param command
31       *            the command to operate on.
32       * @param context
33       *            the context.
34       */
35      public void referenceData(Map model, Object command, Object context) {
36          for (Iterator iter = chainedOptions.iterator(); iter.hasNext();) {
37              ChainedOption chainedOption = (ChainedOption) iter.next();
38              List options = chainedOption.retrieveOptions(command, context);
39              model.put(chainedOption.getOptionsKey(), options);
40              chainedOption.updateValue(command, options, context);
41          }
42      }
43  
44      /***
45       * @return Returns the chainedOptions.
46       */
47      public List getChainedOptions() {
48          return chainedOptions;
49      }
50  
51      /***
52       * @param chainedOptions
53       *            The chainedOptions to set.
54       */
55      public void setChainedOptions(List chainedOptions) {
56          this.chainedOptions = chainedOptions;
57      }
58  
59      public void afterPropertiesSet() throws Exception {
60          if (chainedOptions == null) {
61              throw new IllegalArgumentException(
62                      "Property 'chainedOptions' must be set.");
63          }
64      }
65  }