Mercurial > projects > dwt-addons
comparison dwtx/core/runtime/MultiStatus.d @ 3:6518c18a01f7
eclipse.core package without osgi dependencies
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Wed, 26 Mar 2008 00:57:19 +0100 |
parents | |
children | ea8ff534f622 |
comparison
equal
deleted
inserted
replaced
2:a012107a911c | 3:6518c18a01f7 |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2000, 2006 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module dwtx.core.runtime.MultiStatus; | |
14 | |
15 import dwtx.core.runtime.Assert; | |
16 import dwtx.core.runtime.Status; | |
17 import dwtx.core.runtime.IStatus; | |
18 | |
19 import dwt.dwthelper.utils; | |
20 static import tango.text.Text; | |
21 | |
22 /** | |
23 * A concrete multi-status implementation, | |
24 * suitable either for instantiating or subclassing. | |
25 * <p> | |
26 * This class can be used without OSGi running. | |
27 * </p> | |
28 */ | |
29 public class MultiStatus : Status { | |
30 | |
31 /** List of child statuses. | |
32 */ | |
33 private IStatus[] children; | |
34 | |
35 /** | |
36 * Creates and returns a new multi-status object with the given children. | |
37 * | |
38 * @param pluginId the unique identifier of the relevant plug-in | |
39 * @param code the plug-in-specific status code | |
40 * @param newChildren the list of children status objects | |
41 * @param message a human-readable message, localized to the | |
42 * current locale | |
43 * @param exception a low-level exception, or <code>null</code> if not | |
44 * applicable | |
45 */ | |
46 public this(String pluginId, int code, IStatus[] newChildren, String message, Exception exception) { | |
47 this(pluginId, code, message, exception); | |
48 Assert.isLegal(newChildren !is null); | |
49 int maxSeverity = getSeverity(); | |
50 for (int i = 0; i < newChildren.length; i++) { | |
51 Assert.isLegal(newChildren[i] !is null); | |
52 int severity = newChildren[i].getSeverity(); | |
53 if (severity > maxSeverity) | |
54 maxSeverity = severity; | |
55 } | |
56 this.children = new IStatus[newChildren.length]; | |
57 setSeverity(maxSeverity); | |
58 SimpleType!(IStatus).arraycopy(newChildren, 0, this.children, 0, newChildren.length); | |
59 } | |
60 | |
61 /** | |
62 * Creates and returns a new multi-status object with no children. | |
63 * | |
64 * @param pluginId the unique identifier of the relevant plug-in | |
65 * @param code the plug-in-specific status code | |
66 * @param message a human-readable message, localized to the | |
67 * current locale | |
68 * @param exception a low-level exception, or <code>null</code> if not | |
69 * applicable | |
70 */ | |
71 public this(String pluginId, int code, String message, Exception exception) { | |
72 super(OK, pluginId, code, message, exception); | |
73 children = new IStatus[0]; | |
74 } | |
75 | |
76 /** | |
77 * Adds the given status to this multi-status. | |
78 * | |
79 * @param status the new child status | |
80 */ | |
81 public void add(IStatus status) { | |
82 Assert.isLegal(status !is null); | |
83 IStatus[] result = new IStatus[children.length + 1]; | |
84 SimpleType!(IStatus).arraycopy(children, 0, result, 0, children.length); | |
85 result[result.length - 1] = status; | |
86 children = result; | |
87 int newSev = status.getSeverity(); | |
88 if (newSev > getSeverity()) { | |
89 setSeverity(newSev); | |
90 } | |
91 } | |
92 | |
93 /** | |
94 * Adds all of the children of the given status to this multi-status. | |
95 * Does nothing if the given status has no children (which includes | |
96 * the case where it is not a multi-status). | |
97 * | |
98 * @param status the status whose children are to be added to this one | |
99 */ | |
100 public void addAll(IStatus status) { | |
101 Assert.isLegal(status !is null); | |
102 IStatus[] statuses = status.getChildren(); | |
103 for (int i = 0; i < statuses.length; i++) { | |
104 add(statuses[i]); | |
105 } | |
106 } | |
107 | |
108 /* (Intentionally not javadoc'd) | |
109 * Implements the corresponding method on <code>IStatus</code>. | |
110 */ | |
111 public IStatus[] getChildren() { | |
112 return children; | |
113 } | |
114 | |
115 /* (Intentionally not javadoc'd) | |
116 * Implements the corresponding method on <code>IStatus</code>. | |
117 */ | |
118 public bool isMultiStatus() { | |
119 return true; | |
120 } | |
121 | |
122 /** | |
123 * Merges the given status into this multi-status. | |
124 * Equivalent to <code>add(status)</code> if the | |
125 * given status is not a multi-status. | |
126 * Equivalent to <code>addAll(status)</code> if the | |
127 * given status is a multi-status. | |
128 * | |
129 * @param status the status to merge into this one | |
130 * @see #add(IStatus) | |
131 * @see #addAll(IStatus) | |
132 */ | |
133 public void merge(IStatus status) { | |
134 Assert.isLegal(status !is null); | |
135 if (!status.isMultiStatus()) { | |
136 add(status); | |
137 } else { | |
138 addAll(status); | |
139 } | |
140 } | |
141 | |
142 /** | |
143 * Returns a string representation of the status, suitable | |
144 * for debugging purposes only. | |
145 */ | |
146 public String toString() { | |
147 tango.text.Text.Text!(char) buf = new tango.text.Text.Text!(char); | |
148 buf.append(super.toString()); | |
149 buf.append(" children=["); //$NON-NLS-1$ | |
150 for (int i = 0; i < children.length; i++) { | |
151 if (i !is 0) { | |
152 buf.append(" "); //$NON-NLS-1$ | |
153 } | |
154 buf.append( (cast(Object)children[i]).toString()); | |
155 } | |
156 buf.append("]"); //$NON-NLS-1$ | |
157 return buf.toString(); | |
158 } | |
159 } |