01: package org.swingml.server;
02:
03: import java.util.*;
04:
05: import org.swingml.errors.*;
06: import org.swingml.errors.handlers.*;
07: import org.xml.sax.*;
08:
09: /**
10: * Container class for SwingML Spec xml. The server's response xml is parsed and data is
11: * stored in this container.
12: *
13: * @author CrossLogic
14: */
15: public class SwingMLServerResponse {
16:
17: private ISwingMLError[] errors = null;
18: private String swingMLSpec = null;
19:
20: public void addError(String message, Attributes attributes, int type) {
21: Map newAtts = new HashMap();
22: if (attributes != null && attributes.getLength() > 0) {
23: for (int x = 0; x < attributes.getLength(); x++) {
24: String key = attributes.getQName(x);
25: String value = attributes.getValue(x);
26: newAtts.put(key, value);
27: }
28: }
29: addError(new SwingMLError(message, newAtts, type));
30: }
31:
32: public void addError(SwingMLError error) {
33: List tempErrors = new ArrayList();
34: if (getErrors() != null && getErrors().length > 0) {
35: // TODO - Fix this - copy all current errors into list
36: ISwingMLError[] theErrors = getErrors();
37: for (int x = 0; x < theErrors.length; x++) {
38: tempErrors.add(theErrors[x]);
39: }
40: }
41:
42: if (!tempErrors.contains(error)) {
43: tempErrors.add(error);
44: setErrors((ISwingMLError[]) tempErrors
45: .toArray(new ISwingMLError[tempErrors.size()]));
46: }
47: }
48:
49: public ISwingMLError[] getErrors() {
50: return errors;
51: }
52:
53: public String getErrorSpec() {
54: String result = "";
55: if (getErrors() != null && getErrors().length > 0) {
56: result = ErrorHandlerUtilities.getDialogFor(getErrors());
57: }
58: return result;
59: }
60:
61: public String getSwingMLSpec() {
62: return swingMLSpec;
63: }
64:
65: public boolean hasErrors() {
66: return getErrors() != null && getErrors().length > 0;
67: }
68:
69: public void setErrors(ISwingMLError[] errorList) {
70: this .errors = errorList;
71: }
72:
73: public void setSwingMLSpec(String xml) {
74: this.swingMLSpec = xml;
75: }
76: }
|