01: package org.swingml.action;
02:
03: import org.w3c.dom.*;
04:
05: /**
06: * @author NumberSix
07: */
08: public class SelectionMade extends RemoteAction {
09:
10: SelectionMadeRemoteActionSubject subject = null;
11:
12: public void applyResult(RemoteActionResult result) {
13: // create ActionModel and map result.
14: SelectionMadeResult selectionResult = (SelectionMadeResult) result;
15: getSubject().invoke(selectionResult);
16: }
17:
18: public String createParamString() {
19: String results = null;
20: results = "?id=" + getId();
21: results += "&name=" + getName();
22: return results;
23: }
24:
25: public SelectionMadeRemoteActionSubject getSubject() {
26: return subject;
27: }
28:
29: public void parseResponse(Node element) {
30: Node resultElement = null;
31: if (element != null) {
32: if (element.hasChildNodes()) {
33: // first child should be REMOTE_ACTION_RESULT
34: resultElement = element.getFirstChild();
35: }
36: if (resultElement == null) {
37: throw new RuntimeException(
38: "Result XML for Remote Action is Invalid");
39: }
40: NodeList theNodes = resultElement.getChildNodes();
41: SelectionMadeResultMapper mapper = new SelectionMadeResultMapper();
42: for (int i = 0; i < theNodes.getLength(); i++) {
43: Node node = theNodes.item(i);
44:
45: if (node.getNodeName().equals("PERFORM")) {
46: SelectionMadeResult resultObject = new SelectionMadeResult();
47: mapper.mapModelAttributes(node, resultObject);
48: // execute with result object
49: applyResult(resultObject);
50: }
51:
52: }
53: }
54: }
55:
56: public void setSubject(SelectionMadeRemoteActionSubject aSubject) {
57: this.subject = aSubject;
58: }
59: }
|