1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.struts.chain.commands;
19
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22 import org.apache.struts.action.Action;
23 import org.apache.struts.chain.contexts.ActionContext;
24 import org.apache.struts.config.ActionConfig;
25
26 /***
27 * <p> Create (if necessary) and cache an <code>Action</code> for this
28 * request. </p>
29 *
30 * @version $Rev: 421119 $ $Date: 2005-11-12 13:01:44 -0500 (Sat, 12 Nov 2005)
31 * $
32 */
33 public abstract class AbstractCreateAction extends ActionCommandBase {
34
35
36 /***
37 * Provide a Commons logging instance for this class.
38 */
39 private static final Log LOG =
40 LogFactory.getLog(AbstractCreateAction.class);
41
42
43
44 /***
45 * <p>Create (if necessary) and cache an <code>Action</code> for this
46 * request.</p>
47 *
48 * @param actionCtx The <code>Context</code> for the current request
49 * @return <code>false</code> so that processing continues
50 * @throws Exception if there are any problems instantiating the Action
51 * class.
52 */
53 public boolean execute(ActionContext actionCtx)
54 throws Exception {
55
56 Boolean valid = actionCtx.getFormValid();
57
58 if ((valid == null) || !valid.booleanValue()) {
59 LOG.trace("Invalid form; not going to execute.");
60
61 return (false);
62 }
63
64
65 if (actionCtx.getAction() != null) {
66 LOG.trace("already have an action [" + actionCtx.getAction() + "]");
67
68 return (false);
69 }
70
71
72 ActionConfig actionConfig = actionCtx.getActionConfig();
73 String type = actionConfig.getType();
74
75 if (type == null) {
76 LOG.trace("no type for " + actionConfig.getPath());
77
78 return (false);
79 }
80
81
82 Action action = getAction(actionCtx, type, actionConfig);
83
84 if (LOG.isTraceEnabled()) {
85 LOG.trace("setting action to " + action);
86 }
87
88 actionCtx.setAction(action);
89
90 return (false);
91 }
92
93
94
95 /***
96 * <p> Create and return the appropriate <code>Action</code> class for the
97 * given <code>type</code> and <code>actionConfig</code>. </p> <p> NOTE:
98 * The dependence on ActionServlet suggests that this should be broken up
99 * along the lines of the other Abstract/concrete pairs in the
100 * org.apache.struts.chain.commands package. </p>
101 *
102 * @param context The <code>Context</code> for this request
103 * @param type Name of class to instantiate
104 * @param actionConfig The {@link ActionConfig} for this request
105 * @return Instantiated Action class
106 * @throws Exception if there are any problems instantiating the Action
107 * class.
108 */
109 protected abstract Action getAction(ActionContext context, String type,
110 ActionConfig actionConfig)
111 throws Exception;
112 }