01: package com.opensymphony.webwork.dispatcher.mapper;
02:
03: import com.opensymphony.webwork.config.Configuration;
04: import com.opensymphony.webwork.WebWorkConstants;
05: import com.opensymphony.webwork.WebWorkException;
06: import com.opensymphony.xwork.ObjectFactory;
07: import org.apache.commons.logging.Log;
08: import org.apache.commons.logging.LogFactory;
09:
10: import java.util.HashMap;
11:
12: /**
13: * <!-- START SNIPPET: javadoc -->
14: *
15: * Factory that creates {@link ActionMapper}s. This factory looks up the class name of the {@link ActionMapper} from
16: * WebWork's configuration using the key <b>webwork.mapper.class</b>.
17: *
18: * <!-- END SNIPPET: javadoc -->
19: *
20: * @author Patrick Lightbody
21: */
22: public class ActionMapperFactory {
23: protected static final Log LOG = LogFactory
24: .getLog(ActionMapperFactory.class);
25:
26: private static final HashMap classMap = new HashMap();
27:
28: public static ActionMapper getMapper() {
29: synchronized (classMap) {
30: String clazz = (String) Configuration
31: .get(WebWorkConstants.WEBWORK_MAPPER_CLASS);
32: try {
33: ActionMapper mapper = (ActionMapper) classMap
34: .get(clazz);
35: if (mapper == null) {
36: mapper = (ActionMapper) ObjectFactory
37: .getObjectFactory().buildBean(clazz, null);
38: classMap.put(clazz, mapper);
39: }
40:
41: return mapper;
42: } catch (Exception e) {
43: String msg = "Could not create ActionMapper: WebWork will *not* work!";
44: LOG.fatal(msg, e);
45: throw new WebWorkException(msg, e);
46: }
47: }
48: }
49: }
|