001: package org.swingml.errors;
002:
003: import java.util.*;
004:
005: /**
006: * @author CrossLogic
007: */
008: public class SwingMLError implements ISwingMLError {
009:
010: private Map attributes = new HashMap();
011: private String text;
012: private String tooltipText;
013: private int type;
014:
015: public SwingMLError(String text, int type) {
016: setText(text);
017: setType(type);
018: }
019:
020: public SwingMLError(String text, Map attributes, int type) {
021: this (text, type);
022: if (attributes != null && attributes.size() > 0) {
023: Iterator schmiterator = attributes.keySet().iterator();
024: while (schmiterator.hasNext()) {
025: String key = (String) schmiterator.next();
026: String value = (String) attributes.get(key);
027: setAttribute(key, value);
028: }
029: }
030: }
031:
032: public SwingMLError(String text, String tooltipText, int type) {
033: this (text, type);
034: setTooltipText(tooltipText);
035: }
036:
037: public String getAttribute(String key) {
038: String result = null;
039: Object value = getAttributes().get(key);
040: if (value != null) {
041: result = value.toString();
042: }
043: return result;
044: }
045:
046: public Map getAttributes() {
047: if (attributes == null) {
048: attributes = new HashMap();
049: }
050: return attributes;
051: }
052:
053: public String getText() {
054: return text;
055: }
056:
057: public String getTooltipText() {
058: if (tooltipText == null) {
059: return getText();
060: } else {
061: return tooltipText;
062: }
063: }
064:
065: public int getType() {
066: return type;
067: }
068:
069: public void setAttribute(String key, String value) {
070: getAttributes().put(key, value);
071: }
072:
073: public void setText(String someText) {
074: this .text = someText;
075: }
076:
077: public void setTooltipText(String text) {
078: this .tooltipText = text;
079: }
080:
081: public void setType(int type) {
082: if (validType(type)) {
083: this .type = type;
084: } else {
085: this .type = ISwingMLError.ERROR_UNKNOWN;
086: }
087: }
088:
089: private boolean validType(int aType) {
090: boolean result = false;
091: switch (aType) {
092: case ISwingMLError.ERROR_BUSINESS_LOGIC:
093: result = true;
094: break;
095: case ISwingMLError.ERROR_INVALID_SERVER_RESPONSE:
096: result = true;
097: break;
098: case ISwingMLError.ERROR_NO_SERVER_RESPONSE:
099: result = true;
100: break;
101: case ISwingMLError.ERROR_PROCESSING_REQUEST:
102: result = true;
103: break;
104: case ISwingMLError.ERROR_SERVER_COMMUNICATION:
105: result = true;
106: break;
107: case ISwingMLError.ERROR_UNKNOWN:
108: result = true;
109: break;
110: case ISwingMLError.WARNING:
111: result = true;
112: break;
113: case ISwingMLError.MESSAGE:
114: result = true;
115: break;
116: default:
117: result = false;
118: }
119:
120: return result;
121: }
122:
123: }
|