KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jpublish > action > XWorkAction


1 package org.jpublish.action;
2
3 import java.util.HashMap JavaDoc;
4 import java.util.Map JavaDoc;
5
6 import com.anthonyeden.lib.config.Configuration;
7 import com.anthonyeden.lib.util.MessageUtilities;
8 import com.opensymphony.xwork.ActionProxy;
9 import com.opensymphony.xwork.ActionProxyFactory;
10 import org.jpublish.JPublishEngine;
11 import org.jpublish.JPublishRuntimeException;
12 import org.jpublish.RequestContext;
13
14 /**
15  * Wrapper which executes an XWork action.
16  *
17  * @author Anthony Eden
18  */

19
20 public class XWorkAction implements Action {
21
22     private String JavaDoc name = null;
23     private String JavaDoc namespace = null;
24     private boolean executeResult;
25
26     /**
27      * Get the action name.
28      *
29      * @return The action name
30      */

31
32     public String JavaDoc getName() {
33         return name;
34     }
35
36     /**
37      * Set the action name.
38      *
39      * @param name The action name
40      */

41
42     public void setName(String JavaDoc name) {
43         this.name = name;
44     }
45
46     /**
47      * Get the action namespace.
48      *
49      * @return The namespace
50      */

51
52     public String JavaDoc getNamespace() {
53         return namespace;
54     }
55
56     /**
57      * Set the action namespace.
58      *
59      * @param namespace The namespace
60      */

61
62     public void setNamespace(String JavaDoc namespace) {
63         this.namespace = namespace;
64     }
65
66     /**
67      * Returns true if the result should be executed.
68      *
69      * @return The execute result flag
70      */

71
72     public boolean isExecuteResult() {
73         return executeResult;
74     }
75
76     /**
77      * Set to true if the result should be executed.
78      *
79      * @param executeResult True to execute the result
80      */

81
82     public void setExecuteResult(boolean executeResult) {
83         this.executeResult = executeResult;
84     }
85
86     /**
87      * Set to true if the result should be executed.
88      *
89      * @param executeResult True to execute the result
90      */

91
92     public void setExecuteResult(String JavaDoc executeResult) {
93         setExecuteResult("true".equals(executeResult));
94     }
95
96     /**
97      * Execute the action using the given context.
98      *
99      * @param context The current context
100      * @param configuration The configuration
101      */

102
103     public void execute(RequestContext context, Configuration configuration) {
104         try {
105             Map JavaDoc extraContext = new HashMap JavaDoc();
106             extraContext.put("requestContext", context);
107             extraContext.put("configuration", configuration);
108
109             ActionProxyFactory factory = ActionProxyFactory.getFactory();
110             ActionProxy proxy = factory.createActionProxy(namespace, name,
111                     extraContext, executeResult);
112             proxy.execute();
113             //String result = proxy.execute();
114
} catch (Exception JavaDoc e) {
115             Object JavaDoc[] args = {name, namespace, e.getMessage()};
116             String JavaDoc msg = MessageUtilities.getMessage(getClass(),
117                     JPublishEngine.MESSAGE_PACKAGE, "actionInvocationError", args);
118             throw new JPublishRuntimeException(msg);
119         }
120     }
121
122 }
123
Popular Tags