1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.struts2.dispatcher.mapper;
19
20 import java.util.HashMap;
21
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.apache.struts2.StrutsConstants;
25 import org.apache.struts2.StrutsException;
26 import org.apache.struts2.config.Settings;
27
28 import com.opensymphony.xwork2.ObjectFactory;
29
30 /***
31 * <!-- START SNIPPET: javadoc -->
32 *
33 * Factory that creates {@link ActionMapper}s. This factory looks up the class name of the {@link ActionMapper} from
34 * Struts's configuration using the key <b>struts.mapper.class</b>.
35 *
36 * <!-- END SNIPPET: javadoc -->
37 *
38 */
39 public class ActionMapperFactory {
40 protected static final Log LOG = LogFactory.getLog(ActionMapperFactory.class);
41
42 private static final HashMap<String,ActionMapper> classMap = new HashMap<String,ActionMapper>();
43
44 /***
45 * Gets an instance of the ActionMapper
46 *
47 * @return The action mapper
48 */
49 public static ActionMapper getMapper() {
50 synchronized (classMap) {
51 String clazz = (String) Settings.get(StrutsConstants.STRUTS_MAPPER_CLASS);
52 try {
53 ActionMapper mapper = (ActionMapper) classMap.get(clazz);
54 if (mapper == null) {
55 mapper = (ActionMapper) ObjectFactory.getObjectFactory().buildBean(clazz, null);
56 classMap.put(clazz, mapper);
57 }
58
59 return mapper;
60 } catch (Exception e) {
61 String msg = "Could not create ActionMapper: Struts will *not* work!";
62 throw new StrutsException(msg, e);
63 }
64 }
65 }
66 }