KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > workflow > util > XWorkExecutor


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

5 package com.opensymphony.workflow.util;
6
7 import com.opensymphony.module.propertyset.PropertySet;
8
9 import com.opensymphony.workflow.FunctionProvider;
10 import com.opensymphony.workflow.WorkflowException;
11
12 import com.opensymphony.xwork.ActionContext;
13 import com.opensymphony.xwork.ActionProxy;
14 import com.opensymphony.xwork.ActionProxyFactory;
15
16 import java.util.Collections JavaDoc;
17 import java.util.HashMap JavaDoc;
18 import java.util.Locale JavaDoc;
19 import java.util.Map JavaDoc;
20
21
22 /**
23  * Executes an XWork function.
24  * The following conversion is done:
25  * <ul>
26  * <li>inputs -> ActionContext#parameters</li>
27  * <li>variables -> ActionContext#session</li>
28  * <li>args -> ActionContext#application</li>
29  * </ul>
30  * <p>
31  *
32  * <ul>
33  * <li><b>action.name</b> - the actionName to ask from the ActionProxy</li>
34  * <li><b>namespace</b> - the namespace to ask from the ActionProxy</li>
35  * </ul>
36  */

37 public class XWorkExecutor implements FunctionProvider {
38     //~ Methods ////////////////////////////////////////////////////////////////
39

40     public void execute(Map JavaDoc transientVars, Map JavaDoc args, PropertySet ps) throws WorkflowException {
41         String JavaDoc actionName = (String JavaDoc) args.get("action.name");
42         String JavaDoc namespace = (String JavaDoc) args.get("namespace");
43
44         Map JavaDoc extraContext = new HashMap JavaDoc();
45         extraContext.put(ActionContext.APPLICATION, args);
46         extraContext.put(ActionContext.SESSION, ps.getProperties(""));
47         extraContext.put(ActionContext.LOCALE, Locale.getDefault());
48
49         Map JavaDoc params = new HashMap JavaDoc(transientVars);
50         params.putAll(args);
51         extraContext.put(ActionContext.PARAMETERS, Collections.unmodifiableMap(params));
52
53         try {
54             ActionProxy proxy = ActionProxyFactory.getFactory().createActionProxy(namespace, actionName, extraContext, false);
55             proxy.execute();
56         } catch (Exception JavaDoc e) {
57             throw new WorkflowException("Could not execute action " + actionName, e);
58         }
59     }
60 }
61
Popular Tags