KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > runtime > MultiStatus


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  *******************************************************************************/

11 package org.eclipse.core.runtime;
12
13 /**
14  * A concrete multi-status implementation,
15  * suitable either for instantiating or subclassing.
16  * <p>
17  * This class can be used without OSGi running.
18  * </p>
19  */

20 public class MultiStatus extends Status {
21
22     /** List of child statuses.
23      */

24     private IStatus[] children;
25
26     /**
27      * Creates and returns a new multi-status object with the given children.
28      *
29      * @param pluginId the unique identifier of the relevant plug-in
30      * @param code the plug-in-specific status code
31      * @param newChildren the list of children status objects
32      * @param message a human-readable message, localized to the
33      * current locale
34      * @param exception a low-level exception, or <code>null</code> if not
35      * applicable
36      */

37     public MultiStatus(String JavaDoc pluginId, int code, IStatus[] newChildren, String JavaDoc message, Throwable JavaDoc exception) {
38         this(pluginId, code, message, exception);
39         Assert.isLegal(newChildren != null);
40         int maxSeverity = getSeverity();
41         for (int i = 0; i < newChildren.length; i++) {
42             Assert.isLegal(newChildren[i] != null);
43             int severity = newChildren[i].getSeverity();
44             if (severity > maxSeverity)
45                 maxSeverity = severity;
46         }
47         this.children = new IStatus[newChildren.length];
48         setSeverity(maxSeverity);
49         System.arraycopy(newChildren, 0, this.children, 0, newChildren.length);
50     }
51
52     /**
53      * Creates and returns a new multi-status object with no children.
54      *
55      * @param pluginId the unique identifier of the relevant plug-in
56      * @param code the plug-in-specific status code
57      * @param message a human-readable message, localized to the
58      * current locale
59      * @param exception a low-level exception, or <code>null</code> if not
60      * applicable
61      */

62     public MultiStatus(String JavaDoc pluginId, int code, String JavaDoc message, Throwable JavaDoc exception) {
63         super(OK, pluginId, code, message, exception);
64         children = new IStatus[0];
65     }
66
67     /**
68      * Adds the given status to this multi-status.
69      *
70      * @param status the new child status
71      */

72     public void add(IStatus status) {
73         Assert.isLegal(status != null);
74         IStatus[] result = new IStatus[children.length + 1];
75         System.arraycopy(children, 0, result, 0, children.length);
76         result[result.length - 1] = status;
77         children = result;
78         int newSev = status.getSeverity();
79         if (newSev > getSeverity()) {
80             setSeverity(newSev);
81         }
82     }
83
84     /**
85      * Adds all of the children of the given status to this multi-status.
86      * Does nothing if the given status has no children (which includes
87      * the case where it is not a multi-status).
88      *
89      * @param status the status whose children are to be added to this one
90      */

91     public void addAll(IStatus status) {
92         Assert.isLegal(status != null);
93         IStatus[] statuses = status.getChildren();
94         for (int i = 0; i < statuses.length; i++) {
95             add(statuses[i]);
96         }
97     }
98
99     /* (Intentionally not javadoc'd)
100      * Implements the corresponding method on <code>IStatus</code>.
101      */

102     public IStatus[] getChildren() {
103         return children;
104     }
105
106     /* (Intentionally not javadoc'd)
107      * Implements the corresponding method on <code>IStatus</code>.
108      */

109     public boolean isMultiStatus() {
110         return true;
111     }
112
113     /**
114      * Merges the given status into this multi-status.
115      * Equivalent to <code>add(status)</code> if the
116      * given status is not a multi-status.
117      * Equivalent to <code>addAll(status)</code> if the
118      * given status is a multi-status.
119      *
120      * @param status the status to merge into this one
121      * @see #add(IStatus)
122      * @see #addAll(IStatus)
123      */

124     public void merge(IStatus status) {
125         Assert.isLegal(status != null);
126         if (!status.isMultiStatus()) {
127             add(status);
128         } else {
129             addAll(status);
130         }
131     }
132
133     /**
134      * Returns a string representation of the status, suitable
135      * for debugging purposes only.
136      */

137     public String JavaDoc toString() {
138         StringBuffer JavaDoc buf = new StringBuffer JavaDoc(super.toString());
139         buf.append(" children=["); //$NON-NLS-1$
140
for (int i = 0; i < children.length; i++) {
141             if (i != 0) {
142                 buf.append(" "); //$NON-NLS-1$
143
}
144             buf.append(children[i].toString());
145         }
146         buf.append("]"); //$NON-NLS-1$
147
return buf.toString();
148     }
149 }
150
Popular Tags