First, in a rich client environment the Application Context is the Front Controller. That, notwithstanding, there are many cases in an application where a command may be invoked from several points in an application context and each invoker may need to dynamically pass local data to the command and locally handle the result of the command execution differently. These are not insignificant requests.
Here is a quickie suggestion for a Request and a Response contruct:
Code:
public class ActionRequest implements java.io.Serializable
{
private String toAction; //Requested Action's Logical Name
private HashMap args; //Requested Action's Constructor Args (String argName : Object argValue)
private Object sender; //Action Request Source/Sender; Who Sent the Action Request?
private Object addressee; //Action Result Destination; Who gets the result?
//
// No-arg constructor
//
public ActionRequest() {}
//
// Place Getters and Setters Here
//
//
//Request Send Yourself With local Caller's data
//
public ActionResponse send(ActionResponse res)
{
try {
ActionCommand command = window.getCommandManager().getActionCommand(toAction);
return command.execute(this,res);//Presumes that execute() has been appropriately overloaded
}
catch (ClassNotFoundException cnfe){return null;}
catch (Exception e) {return null;}
}
//
//Request Send Yourself Without data
//
public void send()
{
ActionCommand command = window.getCommandManager().getActionCommand(toAction);
command.execute();
}
//
//Forward A New/Modified Request To Another Action
//
public ActionResponse forward(ActionRequest req,ActionResponse res)
{
try {
ActionCommand command = window.getCommandManager().getActionCommand(toAction);
return command.execute(this,res);//Presumes that execute() has been appropriately overloaded
}
catch (ClassNotFoundException cnfe){return null;}
catch (Exception e) {return null;}
}
}
//*************************************************************************************88
public class ActionResponse implements java.io.Serializable
{
private String code = ActionIF.ERROR; //Execution Return Code
private String message = ""; //Action-Side ActionResult Message
private Object result = null; //The ActionResult Object (Pre-Structured For Each Action)
private Object tAddress= null; //Address Of The ActionResult's Destination Object
//
// No-arg constructor
//
public ActionResponse() {}
//
// Getters and Setters Go Here
//
}
Using command declarations in commands_context.xml, the above contructs can actually be simplified some.
A typical usage code, when sending data and processing return value, may look like this:
Code:
ActionResponse res = new ActionResponse();
ActionRequest req = new ActionRequest();
String returnCode = null;
String errorMsg = null;
HashMap args = new HashMap();
//
req.setToAction("actionCommandLogicalName");
//Set other request data;
args.put("//populate action's args as needed");
req.setArgs(args);
//
//Invoke The Action.
//
res = req.send(res);
//
if (res != null) {
returnCode = (String)res.getCode();
if (returnCode.trim().equals(ActionIF.SUCCESS)) {//Selected Action Succeeded
//Extract return data and process as needed
}
else {
//Do some other processing
}
}
else {
//Do Some other processing
}
When not sending local data or expecting return value, use exactly as is currently done in Spring RCP.
It is possible that Spring RCP's Action Framework can already provide the above capabilities. I just don't know how to use them, yet.