public class Status extends java.lang.Object implements IStatus
This class can be used without OSGi running.
For performance critical code, such as when Status objects are not created
for logging or error handling, there may be a small performance penalty when using
static methods or constructors that automatically determine the plug-in id from
the provided Class or by using StackWalker.
| Modifier and Type | Field and Description |
|---|---|
static IStatus |
CANCEL_STATUS
A standard CANCEL status with no message.
|
static IStatus |
OK_STATUS
A standard OK status with an "ok" message.
|
| Constructor and Description |
|---|
Status(int severity,
java.lang.Class<?> caller,
int code,
java.lang.String message,
java.lang.Throwable exception)
Creates a new status object.
|
Status(int severity,
java.lang.Class<?> caller,
java.lang.String message)
Simplified constructor of a new status object; assumes that code is
OK and
exception is null. |
Status(int severity,
java.lang.Class<?> caller,
java.lang.String message,
java.lang.Throwable exception)
Simplified constructor of a new status object; assumes that code is
OK. |
Status(int severity,
java.lang.String pluginId,
int code,
java.lang.String message,
java.lang.Throwable exception)
Creates a new status object.
|
Status(int severity,
java.lang.String pluginId,
java.lang.String message)
Simplified constructor of a new status object; assumes that code is
OK and
exception is null. |
Status(int severity,
java.lang.String pluginId,
java.lang.String message,
java.lang.Throwable exception)
Simplified constructor of a new status object; assumes that code is
OK. |
| Modifier and Type | Method and Description |
|---|---|
static IStatus |
error(java.lang.String message)
Construct a new status object with severity
IStatus.ERROR,
code IStatus.OK, and pluginId determined automatically
from the calling class using StackWalker. |
static IStatus |
error(java.lang.String message,
java.lang.Throwable exception)
Construct a new status object with severity
IStatus.ERROR,
code IStatus.OK, and pluginId determined automatically
from the calling class using StackWalker. |
IStatus[] |
getChildren()
Returns a list of status object immediately contained in this
multi-status, or an empty list if this is not a multi-status.
|
int |
getCode()
Returns the plug-in-specific status code describing the outcome.
|
java.lang.Throwable |
getException()
Returns the relevant low-level exception, or
null if none. |
java.lang.String |
getMessage()
Returns the message describing the outcome.
|
java.lang.String |
getPlugin()
Returns the unique identifier of the plug-in associated with this status
(this is the plug-in that defines the meaning of the status code).
|
int |
getSeverity()
Returns the severity.
|
static IStatus |
info(java.lang.String message)
Construct a new status object with severity
IStatus.INFO,
code IStatus.OK, and pluginId determined automatically
from the calling class using StackWalker. |
boolean |
isMultiStatus()
Returns whether this status is a multi-status.
|
boolean |
isOK()
Returns whether this status indicates everything is okay
(neither info, warning, nor error).
|
boolean |
matches(int severityMask)
Returns whether the severity of this status matches the given
severity mask.
|
protected void |
setCode(int code)
Sets the status code.
|
protected void |
setException(java.lang.Throwable exception)
Sets the exception.
|
protected void |
setMessage(java.lang.String message)
Sets the message.
|
protected void |
setPlugin(java.lang.String pluginId)
Sets the plug-in id.
|
protected void |
setSeverity(int severity)
Sets the severity.
|
java.lang.String |
toString()
Returns a string representation of the status, suitable
for debugging purposes only.
|
static IStatus |
warning(java.lang.String message)
Construct a new status object with severity
IStatus.WARNING,
code IStatus.OK, and pluginId determined automatically
from the calling class using StackWalker. |
static Status |
warning(java.lang.String message,
java.lang.Throwable exception)
Construct a new status object with severity
IStatus.WARNING,
code IStatus.OK, and pluginId determined automatically
from the calling class using StackWalker. |
public static final IStatus OK_STATUS
public static final IStatus CANCEL_STATUS
public Status(int severity,
java.lang.Class<?> caller,
int code,
java.lang.String message,
java.lang.Throwable exception)
severity - the severity; one of OK, ERROR,
INFO, WARNING, or CANCELcaller - the relevant class to build unique identifier fromcode - the caller-specific status code, or OKmessage - a human-readable message, localized to the
current locale. If null or empty a message from the exception is interpolated.exception - a low-level exception, or null if not
applicablepublic Status(int severity,
java.lang.String pluginId,
int code,
java.lang.String message,
java.lang.Throwable exception)
severity - the severity; one of OK, ERROR,
INFO, WARNING, or CANCELpluginId - the unique identifier of the relevant plug-incode - the plug-in-specific status code, or OKmessage - a human-readable message, localized to the
current locale. If null or empty a message from the exception is interpolated.exception - a low-level exception, or null if not
applicablepublic Status(int severity,
java.lang.Class<?> caller,
java.lang.String message,
java.lang.Throwable exception)
OK.
The created status has no children.severity - the severity; one of OK, ERROR,
INFO, WARNING, or CANCELcaller - the relevant class to build unique identifier frommessage - a human-readable message, localized to the
current locale. If null or empty a message from the exception is interpolated.exception - a low-level exception, or null if not
applicablepublic Status(int severity,
java.lang.String pluginId,
java.lang.String message,
java.lang.Throwable exception)
OK.
The created status has no children.severity - the severity; one of OK, ERROR,
INFO, WARNING, or CANCELpluginId - the unique identifier of the relevant plug-inmessage - a human-readable message, localized to the
current locale. If null or empty a message from the exception is interpolated.exception - a low-level exception, or null if not
applicablepublic Status(int severity,
java.lang.Class<?> caller,
java.lang.String message)
OK and
exception is null. The created status has no children.severity - the severity; one of OK, ERROR,
INFO, WARNING, or CANCELcaller - the relevant class to build unique identifier frommessage - a human-readable message, localized to the
current localepublic Status(int severity,
java.lang.String pluginId,
java.lang.String message)
OK and
exception is null. The created status has no children.severity - the severity; one of OK, ERROR,
INFO, WARNING, or CANCELpluginId - the unique identifier of the relevant plug-inmessage - a human-readable message, localized to the
current localepublic static IStatus info(java.lang.String message)
IStatus.INFO,
code IStatus.OK, and pluginId determined automatically
from the calling class using StackWalker.
The created status has no children.message - a human-readable message, localized to the
current localepublic static IStatus warning(java.lang.String message)
IStatus.WARNING,
code IStatus.OK, and pluginId determined automatically
from the calling class using StackWalker.
The created status has no children.message - a human-readable message, localized to the
current localepublic static Status warning(java.lang.String message, java.lang.Throwable exception)
IStatus.WARNING,
code IStatus.OK, and pluginId determined automatically
from the calling class using StackWalker.
The created status has no children.message - a human-readable message, localized to the
current localeexception - a low-level exception, or null if not
applicablepublic static IStatus error(java.lang.String message)
IStatus.ERROR,
code IStatus.OK, and pluginId determined automatically
from the calling class using StackWalker.
The created status has no children.message - a human-readable message, localized to the
current localepublic static IStatus error(java.lang.String message, java.lang.Throwable exception)
IStatus.ERROR,
code IStatus.OK, and pluginId determined automatically
from the calling class using StackWalker.
The created status has no children.message - a human-readable message, localized to the
current localeexception - a low-level exception, or null if not
applicablepublic IStatus[] getChildren()
IStatusgetChildren in interface IStatusIStatus.isMultiStatus()public int getCode()
IStatuspublic java.lang.Throwable getException()
IStatusnull if none.
For example, when an operation fails because of a network communications
failure, this might return the java.io.IOException
describing the exact nature of that failure.getException in interface IStatusnull if nonepublic java.lang.String getMessage()
IStatusgetMessage in interface IStatuspublic java.lang.String getPlugin()
IStatuspublic int getSeverity()
IStatusCANCEL - cancelation occurredERROR - a serious error (most severe)WARNING - a warning (less severe)INFO - an informational ("fyi") message (least severe)OK - everything is just fine
The severity of a multi-status is defined to be the maximum
severity of any of its children, or OK if it has
no children.
getSeverity in interface IStatusOK, ERROR,
INFO, WARNING, or CANCELIStatus.matches(int)public boolean isMultiStatus()
IStatus
The severity of a multi-status is derived from the severities
of its children; a multi-status with no children is
OK by definition.
A multi-status carries a plug-in identifier, a status code,
a message, and an optional exception. Clients may treat
multi-status objects in a multi-status unaware way.
isMultiStatus in interface IStatustrue for a multi-status,
false otherwiseIStatus.getChildren()public boolean isOK()
IStatuspublic boolean matches(int severityMask)
IStatusOK
will never match; use isOK instead to detect
a status with a severity of OK.matches in interface IStatusseverityMask - a mask formed by bitwise or'ing severity mask
constants (ERROR, WARNING,
INFO, CANCEL)true if there is at least one match,
false if there are no matchesIStatus.getSeverity(),
IStatus.CANCEL,
IStatus.ERROR,
IStatus.WARNING,
IStatus.INFOprotected void setCode(int code)
code - the plug-in-specific status code, or OKprotected void setException(java.lang.Throwable exception)
exception - a low-level exception, or null if not
applicableprotected void setMessage(java.lang.String message)
message - a human-readable message, localized to the
current localeprotected void setPlugin(java.lang.String pluginId)
pluginId - the unique identifier of the relevant plug-inprotected void setSeverity(int severity)
severity - the severity; one of OK, ERROR,
INFO, WARNING, or CANCELpublic java.lang.String toString()
toString in class java.lang.Object