View Javadoc

1   /*
2    * Copyright 2011 FatWire Corporation. All Rights Reserved.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *    http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package com.fatwire.gst.foundation.controller.action.support;
18  
19  import java.util.HashMap;
20  import java.util.Map;
21  
22  import org.apache.commons.logging.Log;
23  import org.apache.commons.logging.LogFactory;
24  
25  import COM.FutureTense.Interfaces.ICS;
26  
27  import com.fatwire.gst.foundation.controller.action.Action;
28  
29  /**
30   * ActionLocator that holds a Map with the Actions. The 'name' is keyed to a map
31   * that holds the Actions in a key/value pair.
32   * <p/>
33   * 
34   * @author Tony Field
35   * @author Dolf Dijkstra
36   * @since 2011-03-15
37   */
38  
39  public class MapActionLocator extends BaseActionLocator {
40  
41      protected static final Log LOG = LogFactory.getLog(MapActionLocator.class.getPackage().getName());
42      private Map<String, Action> commandActionMap = new HashMap<String, Action>();
43  
44      public MapActionLocator() {
45          super();
46      }
47  
48      public void setActionMap(final Map<String, Action> map) {
49          LOG.debug("Configured action mapping with " + (map == null ? 0 : map.size() + " entries."));
50          this.commandActionMap = map;
51      }
52  
53      @Override
54      protected Action doFindAction(ICS ics, String name) {
55          Action action;
56          action = commandActionMap.get(name);
57          if (action != null) {
58              injectDependencies(ics, action);
59          }
60          return action;
61  
62      }
63  
64  }