package org.swingml.errors;
import java.util.*;
/**
* @author CrossLogic
*/
public class SwingMLError implements ISwingMLError {
private Map attributes = new HashMap();
private String text;
private String tooltipText;
private int type;
public SwingMLError (String text, int type) {
setText(text);
setType(type);
}
public SwingMLError (String text, Map attributes, int type) {
this(text, type);
if (attributes != null && attributes.size() > 0) {
Iterator schmiterator = attributes.keySet().iterator();
while (schmiterator.hasNext()) {
String key = (String) schmiterator.next();
String value = (String) attributes.get(key);
setAttribute(key, value);
}
}
}
public SwingMLError (String text, String tooltipText, int type) {
this(text, type);
setTooltipText(tooltipText);
}
public String getAttribute (String key) {
String result = null;
Object value = getAttributes().get(key);
if (value != null) {
result = value.toString();
}
return result;
}
public Map getAttributes () {
if (attributes == null) {
attributes = new HashMap();
}
return attributes;
}
public String getText () {
return text;
}
public String getTooltipText () {
if (tooltipText == null) {
return getText();
} else {
return tooltipText;
}
}
public int getType () {
return type;
}
public void setAttribute (String key, String value) {
getAttributes().put(key, value);
}
public void setText (String someText) {
this.text = someText;
}
public void setTooltipText (String text) {
this.tooltipText = text;
}
public void setType (int type) {
if (validType(type)) {
this.type = type;
} else {
this.type = ISwingMLError.ERROR_UNKNOWN;
}
}
private boolean validType (int aType) {
boolean result = false;
switch (aType) {
case ISwingMLError.ERROR_BUSINESS_LOGIC:
result = true;
break;
case ISwingMLError.ERROR_INVALID_SERVER_RESPONSE:
result = true;
break;
case ISwingMLError.ERROR_NO_SERVER_RESPONSE:
result = true;
break;
case ISwingMLError.ERROR_PROCESSING_REQUEST:
result = true;
break;
case ISwingMLError.ERROR_SERVER_COMMUNICATION:
result = true;
break;
case ISwingMLError.ERROR_UNKNOWN:
result = true;
break;
case ISwingMLError.WARNING:
result = true;
break;
case ISwingMLError.MESSAGE:
result = true;
break;
default:
result = false;
}
return result;
}
}
|