1 11 package org.eclipse.core.runtime; 12 13 import org.eclipse.core.internal.runtime.IRuntimeConstants; 14 import org.eclipse.core.internal.runtime.LocalizationUtils; 15 16 23 public class Status implements IStatus { 24 25 30 public static final IStatus OK_STATUS = new Status(OK, IRuntimeConstants.PI_RUNTIME, OK, LocalizationUtils.safeLocalize("ok"), null); 36 public static final IStatus CANCEL_STATUS = new Status(CANCEL, IRuntimeConstants.PI_RUNTIME, 1, "", null); 47 private int severity = OK; 48 49 51 private String pluginId; 52 53 55 private int code; 56 57 59 private String message; 60 61 63 private Throwable exception = null; 64 65 67 private static final IStatus[] theEmptyStatusArray = new IStatus[0]; 68 69 81 public Status(int severity, String pluginId, int code, String message, Throwable exception) { 82 setSeverity(severity); 83 setPlugin(pluginId); 84 setCode(code); 85 setMessage(message); 86 setException(exception); 87 } 88 89 103 public Status(int severity, String pluginId, String message, Throwable exception) { 104 setSeverity(severity); 105 setPlugin(pluginId); 106 setMessage(message); 107 setException(exception); 108 setCode(OK); 109 } 110 111 123 public Status(int severity, String pluginId, String message) { 124 setSeverity(severity); 125 setPlugin(pluginId); 126 setMessage(message); 127 setCode(OK); 128 setException(null); 129 } 130 131 134 public IStatus[] getChildren() { 135 return theEmptyStatusArray; 136 } 137 138 141 public int getCode() { 142 return code; 143 } 144 145 148 public Throwable getException() { 149 return exception; 150 } 151 152 155 public String getMessage() { 156 return message; 157 } 158 159 162 public String getPlugin() { 163 return pluginId; 164 } 165 166 169 public int getSeverity() { 170 return severity; 171 } 172 173 176 public boolean isMultiStatus() { 177 return false; 178 } 179 180 183 public boolean isOK() { 184 return severity == OK; 185 } 186 187 190 public boolean matches(int severityMask) { 191 return (severity & severityMask) != 0; 192 } 193 194 199 protected void setCode(int code) { 200 this.code = code; 201 } 202 203 209 protected void setException(Throwable exception) { 210 this.exception = exception; 211 } 212 213 220 protected void setMessage(String message) { 221 if (message == null) 222 this.message = ""; else 224 this.message = message; 225 } 226 227 232 protected void setPlugin(String pluginId) { 233 Assert.isLegal(pluginId != null && pluginId.length() > 0); 234 this.pluginId = pluginId; 235 } 236 237 243 protected void setSeverity(int severity) { 244 Assert.isLegal(severity == OK || severity == ERROR || severity == WARNING || severity == INFO || severity == CANCEL); 245 this.severity = severity; 246 } 247 248 252 public String toString() { 253 StringBuffer buf = new StringBuffer (); 254 buf.append("Status "); if (severity == OK) { 256 buf.append("OK"); } else if (severity == ERROR) { 258 buf.append("ERROR"); } else if (severity == WARNING) { 260 buf.append("WARNING"); } else if (severity == INFO) { 262 buf.append("INFO"); } else if (severity == CANCEL) { 264 buf.append("CANCEL"); } else { 266 buf.append("severity="); buf.append(severity); 268 } 269 buf.append(": "); buf.append(pluginId); 271 buf.append(" code="); buf.append(code); 273 buf.append(' '); 274 buf.append(message); 275 buf.append(' '); 276 buf.append(exception); 277 return buf.toString(); 278 } 279 } 280 | Popular Tags |