KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > junit > util > JUnitStatus


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
12 package org.eclipse.jdt.internal.junit.util;
13
14 import org.eclipse.core.runtime.Assert;
15 import org.eclipse.core.runtime.IStatus;
16 import org.eclipse.jdt.internal.junit.ui.JUnitPlugin;
17
18 /**
19  * An implemention of IStatus.
20  * TO DO: Why is it duplicated, it should leverage the Status base class???
21  */

22 public class JUnitStatus implements IStatus {
23     private String JavaDoc fStatusMessage;
24     private int fSeverity;
25     
26     /**
27      * Creates a status set to OK (no message)
28      */

29     public JUnitStatus() {
30         this(OK, null);
31     }
32
33     /**
34      * Creates a status .
35      * @param severity The status severity: ERROR, WARNING, INFO and OK.
36      * @param message The message of the status. Applies only for ERROR,
37      * WARNING and INFO.
38      */

39     public JUnitStatus(int severity, String JavaDoc message) {
40         fStatusMessage= message;
41         fSeverity= severity;
42     }
43
44     public static IStatus createError(String JavaDoc message) {
45         return new JUnitStatus(IStatus.ERROR, message);
46     }
47     
48     public static IStatus createWarning(String JavaDoc message) {
49         return new JUnitStatus(IStatus.WARNING, message);
50     }
51
52     public static IStatus createInfo(String JavaDoc message) {
53         return new JUnitStatus(IStatus.INFO, message);
54     }
55     
56     /**
57      * Returns if the status' severity is OK.
58      */

59     public boolean isOK() {
60         return fSeverity == IStatus.OK;
61     }
62
63     /**
64      * Returns if the status' severity is WARNING.
65      */

66     public boolean isWarning() {
67         return fSeverity == IStatus.WARNING;
68     }
69
70     /**
71      * Returns if the status' severity is INFO.
72      */

73     public boolean isInfo() {
74         return fSeverity == IStatus.INFO;
75     }
76
77     /**
78      * Returns if the status' severity is ERROR.
79      */

80     public boolean isError() {
81         return fSeverity == IStatus.ERROR;
82     }
83     
84     /**
85      * @see IStatus#getMessage()
86      */

87     public String JavaDoc getMessage() {
88         return fStatusMessage;
89     }
90     
91     /**
92      * Sets the status to ERROR.
93      * @param errorMessage the error message (can be empty, but not null)
94      */

95     public void setError(String JavaDoc errorMessage) {
96         Assert.isNotNull(errorMessage);
97         fStatusMessage= errorMessage;
98         fSeverity= IStatus.ERROR;
99     }
100
101     /**
102      * Sets the status to WARNING.
103      * @param warningMessage the warning message (can be empty, but not null)
104      */

105     public void setWarning(String JavaDoc warningMessage) {
106         Assert.isNotNull(warningMessage);
107         fStatusMessage= warningMessage;
108         fSeverity= IStatus.WARNING;
109     }
110
111     /**
112      * Sets the status to INFO.
113      * @param infoMessage the info message (can be empty, but not null)
114      */

115     public void setInfo(String JavaDoc infoMessage) {
116         Assert.isNotNull(infoMessage);
117         fStatusMessage= infoMessage;
118         fSeverity= IStatus.INFO;
119     }
120
121     /**
122      * Sets the status to OK.
123      */

124     public void setOK() {
125         fStatusMessage= null;
126         fSeverity= IStatus.OK;
127     }
128     
129     /*
130      * @see IStatus#matches(int)
131      */

132     public boolean matches(int severityMask) {
133         return (fSeverity & severityMask) != 0;
134     }
135
136     /**
137      * Returns always <code>false</code>.
138      * @see IStatus#isMultiStatus()
139      */

140     public boolean isMultiStatus() {
141         return false;
142     }
143
144     /*
145      * @see IStatus#getSeverity()
146      */

147     public int getSeverity() {
148         return fSeverity;
149     }
150
151     /*
152      * @see IStatus#getPlugin()
153      */

154     public String JavaDoc getPlugin() {
155         return JUnitPlugin.PLUGIN_ID;
156     }
157
158     /**
159      * Returns always <code>null</code>.
160      * @see IStatus#getException()
161      */

162     public Throwable JavaDoc getException() {
163         return null;
164     }
165
166     /**
167      * Returns always the error severity.
168      * @see IStatus#getCode()
169      */

170     public int getCode() {
171         return fSeverity;
172     }
173
174     /**
175      * Returns always <code>null</code>.
176      * @see IStatus#getChildren()
177      */

178     public IStatus[] getChildren() {
179         return new IStatus[0];
180     }
181
182 }
183
Popular Tags