Mercurial > projects > dwt2
comparison org.eclipse.equinox.common/src/org/eclipse/core/runtime/Status.d @ 105:bbe49769ec18
...
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 08 Nov 2009 12:42:30 +0100 |
parents | 6f068362a363 |
children |
comparison
equal
deleted
inserted
replaced
104:88652073d1c2 | 105:bbe49769ec18 |
---|---|
2 * Copyright (c) 2000, 2006 IBM Corporation and others. | 2 * Copyright (c) 2000, 2006 IBM Corporation and others. |
3 * All rights reserved. This program and the accompanying materials | 3 * All rights reserved. This program and the accompanying materials |
4 * are made available under the terms of the Eclipse Public License v1.0 | 4 * are made available under the terms of the Eclipse Public License v1.0 |
5 * which accompanies this distribution, and is available at | 5 * which accompanies this distribution, and is available at |
6 * http://www.eclipse.org/legal/epl-v10.html | 6 * http://www.eclipse.org/legal/epl-v10.html |
7 * | 7 * |
8 * Contributors: | 8 * Contributors: |
9 * IBM Corporation - initial API and implementation | 9 * IBM Corporation - initial API and implementation |
10 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | 10 *******************************************************************************/ |
13 module org.eclipse.core.runtime.Status; | 11 // Port to the D programming language: |
12 // Frank Benoit <benoit@tionex.de> | |
13 module org.eclipse.core.runtimeStatus; | |
14 | |
15 import java.lang.all; | |
16 | |
17 import org.eclipse.core.runtimeAssert; // packageimport | |
18 import org.eclipse.core.runtimeIStatus; // packageimport | |
14 | 19 |
15 import org.eclipse.core.internal.runtime.IRuntimeConstants; | 20 import org.eclipse.core.internal.runtime.IRuntimeConstants; |
16 import org.eclipse.core.internal.runtime.LocalizationUtils; | 21 import org.eclipse.core.internal.runtime.LocalizationUtils; |
17 import org.eclipse.core.runtime.IStatus; | |
18 import org.eclipse.core.runtime.Assert; | |
19 | |
20 import java.lang.all; | |
21 | 22 |
22 /** | 23 /** |
23 * A concrete status implementation, suitable either for | 24 * A concrete status implementation, suitable either for |
24 * instantiating or subclassing. | 25 * instantiating or subclassing. |
25 * <p> | 26 * <p> |
26 * This class can be used without OSGi running. | 27 * This class can be used without OSGi running. |
27 * </p> | 28 * </p> |
28 */ | 29 */ |
31 /** | 32 /** |
32 * A standard OK status with an "ok" message. | 33 * A standard OK status with an "ok" message. |
33 * | 34 * |
34 * @since 3.0 | 35 * @since 3.0 |
35 */ | 36 */ |
36 public static const IStatus OK_STATUS; | 37 public static final IStatus OK_STATUS = new Status(OK, IRuntimeConstants.PI_RUNTIME, OK, LocalizationUtils.safeLocalize("ok"), null); //$NON-NLS-1$ |
37 /** | 38 /** |
38 * A standard CANCEL status with no message. | 39 * A standard CANCEL status with no message. |
39 * | 40 * |
40 * @since 3.0 | 41 * @since 3.0 |
41 */ | 42 */ |
42 public static const IStatus CANCEL_STATUS; | 43 public static final IStatus CANCEL_STATUS = new Status(CANCEL, IRuntimeConstants.PI_RUNTIME, 1, "", null); //$NON-NLS-1$ |
43 | |
44 static this(){ | |
45 OK_STATUS = new Status(OK, IRuntimeConstants.PI_RUNTIME, OK, LocalizationUtils.safeLocalize("ok"), null); //$NON-NLS-1$ | |
46 CANCEL_STATUS = new Status(CANCEL, IRuntimeConstants.PI_RUNTIME, 1, "", null); //$NON-NLS-1$ | |
47 } | |
48 | |
49 /** | 44 /** |
50 * The severity. One of | 45 * The severity. One of |
51 * <ul> | 46 * <ul> |
52 * <li><code>CANCEL</code></li> | 47 * <li><code>CANCEL</code></li> |
53 * <li><code>ERROR</code></li> | 48 * <li><code>ERROR</code></li> |
70 */ | 65 */ |
71 private String message; | 66 private String message; |
72 | 67 |
73 /** Wrapped exception, or <code>null</code> if none. | 68 /** Wrapped exception, or <code>null</code> if none. |
74 */ | 69 */ |
75 private Exception exception = null; | 70 private Throwable exception = null; |
76 | 71 |
77 /** Constant to avoid generating garbage. | 72 /** Constant to avoid generating garbage. |
78 */ | 73 */ |
79 private static const IStatus[] theEmptyStatusArray = null; | 74 private static final IStatus[] theEmptyStatusArray = new IStatus[0]; |
80 | 75 |
81 /** | 76 /** |
82 * Creates a new status object. The created status has no children. | 77 * Creates a new status object. The created status has no children. |
83 * | 78 * |
84 * @param severity the severity; one of <code>OK</code>, <code>ERROR</code>, | 79 * @param severity the severity; one of <code>OK</code>, <code>ERROR</code>, |
85 * <code>INFO</code>, <code>WARNING</code>, or <code>CANCEL</code> | 80 * <code>INFO</code>, <code>WARNING</code>, or <code>CANCEL</code> |
86 * @param pluginId the unique identifier of the relevant plug-in | 81 * @param pluginId the unique identifier of the relevant plug-in |
87 * @param code the plug-in-specific status code, or <code>OK</code> | 82 * @param code the plug-in-specific status code, or <code>OK</code> |
88 * @param message a human-readable message, localized to the | 83 * @param message a human-readable message, localized to the |
89 * current locale | 84 * current locale |
90 * @param exception a low-level exception, or <code>null</code> if not | 85 * @param exception a low-level exception, or <code>null</code> if not |
91 * applicable | 86 * applicable |
92 */ | 87 */ |
93 public this(int severity, String pluginId, int code, String message, Exception exception) { | 88 public this(int severity, String pluginId, int code, String message, Throwable exception) { |
94 setSeverity(severity); | 89 setSeverity(severity); |
95 setPlugin(pluginId); | 90 setPlugin(pluginId); |
96 setCode(code); | 91 setCode(code); |
97 setMessage(message); | 92 setMessage(message); |
98 setException(exception); | 93 setException(exception); |
100 | 95 |
101 /** | 96 /** |
102 * Simplified constructor of a new status object; assumes that code is <code>OK</code>. | 97 * Simplified constructor of a new status object; assumes that code is <code>OK</code>. |
103 * The created status has no children. | 98 * The created status has no children. |
104 * | 99 * |
105 * @param severity the severity; one of <code>OK</code>, <code>ERROR</code>, | 100 * @param severity the severity; one of <code>OK</code>, <code>ERROR</code>, |
106 * <code>INFO</code>, <code>WARNING</code>, or <code>CANCEL</code> | 101 * <code>INFO</code>, <code>WARNING</code>, or <code>CANCEL</code> |
107 * @param pluginId the unique identifier of the relevant plug-in | 102 * @param pluginId the unique identifier of the relevant plug-in |
108 * @param message a human-readable message, localized to the | 103 * @param message a human-readable message, localized to the |
109 * current locale | 104 * current locale |
110 * @param exception a low-level exception, or <code>null</code> if not | 105 * @param exception a low-level exception, or <code>null</code> if not |
111 * applicable | 106 * applicable |
112 * | 107 * |
113 * @since org.eclipse.equinox.common 3.3 | 108 * @since org.eclipse.equinox.common 3.3 |
114 */ | 109 */ |
115 public this(int severity, String pluginId, String message, Exception exception) { | 110 public this(int severity, String pluginId, String message, Throwable exception) { |
116 setSeverity(severity); | 111 setSeverity(severity); |
117 setPlugin(pluginId); | 112 setPlugin(pluginId); |
118 setMessage(message); | 113 setMessage(message); |
119 setException(exception); | 114 setException(exception); |
120 setCode(OK); | 115 setCodecast(OK); |
121 } | 116 } |
122 | 117 |
123 /** | 118 /** |
124 * Simplified constructor of a new status object; assumes that code is <code>OK</code> and | 119 * Simplified constructor of a new status object; assumes that code is <code>OK</code> and |
125 * exception is <code>null</code>. The created status has no children. | 120 * exception is <code>null</code>. The created status has no children. |
126 * | 121 * |
127 * @param severity the severity; one of <code>OK</code>, <code>ERROR</code>, | 122 * @param severity the severity; one of <code>OK</code>, <code>ERROR</code>, |
128 * <code>INFO</code>, <code>WARNING</code>, or <code>CANCEL</code> | 123 * <code>INFO</code>, <code>WARNING</code>, or <code>CANCEL</code> |
129 * @param pluginId the unique identifier of the relevant plug-in | 124 * @param pluginId the unique identifier of the relevant plug-in |
130 * @param message a human-readable message, localized to the | 125 * @param message a human-readable message, localized to the |
131 * current locale | 126 * current locale |
132 * | 127 * |
133 * @since org.eclipse.equinox.common 3.3 | 128 * @since org.eclipse.equinox.common 3.3 |
134 */ | 129 */ |
135 public this(int severity, String pluginId, String message) { | 130 public this(int severity, String pluginId, String message) { |
136 setSeverity(severity); | 131 setSeverity(severity); |
137 setPlugin(pluginId); | 132 setPlugin(pluginId); |
138 setMessage(message); | 133 setMessage(message); |
139 setCode(OK); | 134 setCodecast(OK); |
140 setException(null); | 135 setException(null); |
141 } | 136 } |
142 | 137 |
143 /* (Intentionally not javadoc'd) | 138 /* (Intentionally not javadoc'd) |
144 * Implements the corresponding method on <code>IStatus</code>. | 139 * Implements the corresponding method on <code>IStatus</code>. |
155 } | 150 } |
156 | 151 |
157 /* (Intentionally not javadoc'd) | 152 /* (Intentionally not javadoc'd) |
158 * Implements the corresponding method on <code>IStatus</code>. | 153 * Implements the corresponding method on <code>IStatus</code>. |
159 */ | 154 */ |
160 public Exception getException() { | 155 public Throwable getException() { |
161 return exception; | 156 return exception; |
162 } | 157 } |
163 | 158 |
164 /* (Intentionally not javadoc'd) | 159 /* (Intentionally not javadoc'd) |
165 * Implements the corresponding method on <code>IStatus</code>. | 160 * Implements the corresponding method on <code>IStatus</code>. |
214 | 209 |
215 /** | 210 /** |
216 * Sets the exception. | 211 * Sets the exception. |
217 * | 212 * |
218 * @param exception a low-level exception, or <code>null</code> if not | 213 * @param exception a low-level exception, or <code>null</code> if not |
219 * applicable | 214 * applicable |
220 */ | 215 */ |
221 protected void setException(Exception exception) { | 216 protected void setException(Throwable exception) { |
222 this.exception = exception; | 217 this.exception = exception; |
223 } | 218 } |
224 | 219 |
225 /** | 220 /** |
226 * Sets the message. If null is passed, message is set to an empty | 221 * Sets the message. If null is passed, message is set to an empty |
240 * Sets the plug-in id. | 235 * Sets the plug-in id. |
241 * | 236 * |
242 * @param pluginId the unique identifier of the relevant plug-in | 237 * @param pluginId the unique identifier of the relevant plug-in |
243 */ | 238 */ |
244 protected void setPlugin(String pluginId) { | 239 protected void setPlugin(String pluginId) { |
245 Assert.isLegal(pluginId !is null && pluginId.length > 0); | 240 Assert.isLegal(pluginId !is null && pluginId.length() > 0); |
246 this.pluginId = pluginId; | 241 this.pluginId = pluginId; |
247 } | 242 } |
248 | 243 |
249 /** | 244 /** |
250 * Sets the severity. | 245 * Sets the severity. |
251 * | 246 * |
252 * @param severity the severity; one of <code>OK</code>, <code>ERROR</code>, | 247 * @param severity the severity; one of <code>OK</code>, <code>ERROR</code>, |
253 * <code>INFO</code>, <code>WARNING</code>, or <code>CANCEL</code> | 248 * <code>INFO</code>, <code>WARNING</code>, or <code>CANCEL</code> |
254 */ | 249 */ |
255 protected void setSeverity(int severity) { | 250 protected void setSeverity(int severity) { |
256 Assert.isLegal(severity is OK || severity is ERROR || severity is WARNING || severity is INFO || severity is CANCEL); | 251 Assert.isLegal(severity is OK || severity is ERROR || severity is WARNING || severity is INFO || severity is CANCEL); |
257 this.severity = severity; | 252 this.severity = severity; |
258 } | 253 } |
259 | 254 |
260 /** | 255 /** |
261 * Returns a string representation of the status, suitable | 256 * Returns a string representation of the status, suitable |
262 * for debugging purposes only. | 257 * for debugging purposes only. |
263 */ | 258 */ |
264 public override String toString() { | 259 public String toString() { |
265 String sev; | 260 StringBuffer buf = new StringBuffer(); |
261 buf.append("Status "); //$NON-NLS-1$ | |
266 if (severity is OK) { | 262 if (severity is OK) { |
267 sev="OK"; //$NON-NLS-1$ | 263 buf.append("OK"); //$NON-NLS-1$ |
268 } else if (severity is ERROR) { | 264 } else if (severity is ERROR) { |
269 sev="ERROR"; //$NON-NLS-1$ | 265 buf.append("ERROR"); //$NON-NLS-1$ |
270 } else if (severity is WARNING) { | 266 } else if (severity is WARNING) { |
271 sev="WARNING"; //$NON-NLS-1$ | 267 buf.append("WARNING"); //$NON-NLS-1$ |
272 } else if (severity is INFO) { | 268 } else if (severity is INFO) { |
273 sev="INFO"; //$NON-NLS-1$ | 269 buf.append("INFO"); //$NON-NLS-1$ |
274 } else if (severity is CANCEL) { | 270 } else if (severity is CANCEL) { |
275 sev="CANCEL"; //$NON-NLS-1$ | 271 buf.append("CANCEL"); //$NON-NLS-1$ |
276 } else { | 272 } else { |
277 sev=Format( "severity={}", severity); | 273 buf.append("severity="); //$NON-NLS-1$ |
274 buf.append(severity); | |
278 } | 275 } |
279 return Format("Status {}: {} code={} {} {}", sev, pluginId, code, message, exception.toString ); | 276 buf.append(": "); //$NON-NLS-1$ |
277 buf.append(pluginId); | |
278 buf.append(" code="); //$NON-NLS-1$ | |
279 buf.append(code); | |
280 buf.append(' '); | |
281 buf.append(message); | |
282 buf.append(' '); | |
283 buf.append(exception); | |
284 return buf.toString(); | |
280 } | 285 } |
281 } | 286 } |