01: /*
02: * Copyright (c) 2002-2006 by OpenSymphony
03: * All rights reserved.
04: */
05: package com.opensymphony.xwork.interceptor;
06:
07: import com.opensymphony.xwork.ActionInvocation;
08: import com.opensymphony.xwork.ModelDriven;
09: import com.opensymphony.xwork.util.OgnlValueStack;
10:
11: /**
12: * <!-- START SNIPPET: description -->
13: *
14: * Watches for {@link ModelDriven} actions and adds the action's model on to the value stack.
15: *
16: * <p/> <b>Note:</b> The ModelDrivenInterceptor must come before the both {@link StaticParametersInterceptor} and
17: * {@link ParametersInterceptor} if you want the parameters to be applied to the model.
18: *
19: * <p/> <b>Note:</b> The ModelDrivenInterceptor will only push the model into the stack when the
20: * model is not null, else it will be ignored.
21: *
22: * <!-- END SNIPPET: description -->
23: *
24: * <p/> <u>Interceptor parameters:</u>
25: *
26: * <!-- START SNIPPET: parameters -->
27: *
28: * <ul>
29: *
30: * <li>None</li>
31: *
32: * </ul>
33: *
34: * <!-- END SNIPPET: parameters -->
35: *
36: * <p/> <u>Extending the interceptor:</u>
37: *
38: * <p/>
39: *
40: * <!-- START SNIPPET: extending -->
41: *
42: * There are no known extension points to this interceptor.
43: *
44: * <!-- END SNIPPET: extending -->
45: *
46: * <p/> <u>Example code:</u>
47: *
48: * <pre>
49: * <!-- START SNIPPET: example -->
50: * <action name="someAction" class="com.examples.SomeAction">
51: * <interceptor-ref name="model-driven"/>
52: * <interceptor-ref name="basicStack"/>
53: * <result name="success">good_result.ftl</result>
54: * </action>
55: * <!-- END SNIPPET: example -->
56: * </pre>
57: *
58: * @author tm_jee
59: * @version $Date: 2006-05-13 14:06:42 +0200 (Sa, 13 Mai 2006) $ $Id: ModelDrivenInterceptor.java 1016 2006-05-13 12:06:42Z tmjee $
60: */
61: public class ModelDrivenInterceptor extends AroundInterceptor {
62:
63: protected void after(ActionInvocation dispatcher, String result)
64: throws Exception {
65: }
66:
67: protected void before(ActionInvocation invocation) throws Exception {
68: Object action = invocation.getAction();
69:
70: if (action instanceof ModelDriven) {
71: ModelDriven modelDriven = (ModelDriven) action;
72: OgnlValueStack stack = invocation.getStack();
73: if (modelDriven.getModel() != null) {
74: stack.push(modelDriven.getModel());
75: }
76: }
77: }
78: }
|