View Javadoc

1   /*
2    * Copyright 2004-2008 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.seasar.eclipse.common.util;
17  
18  import org.eclipse.core.runtime.IStatus;
19  import org.eclipse.core.runtime.Plugin;
20  import org.eclipse.core.runtime.Status;
21  
22  public class StatusUtil {
23  
24      public static IStatus create(Plugin plugin, int severity, int code,
25              String message, Throwable throwable) {
26          return new Status(severity, plugin.getBundle().getSymbolicName(), code,
27                  message, throwable);
28      }
29  
30      public static IStatus createError(Plugin plugin, int code,
31              Throwable throwable) {
32          String message = throwable.getMessage();
33          if (message == null) {
34              message = throwable.getClass().getName();
35          }
36          return create(plugin, IStatus.ERROR, code, message, throwable);
37      }
38  
39      public static IStatus createError(Plugin plugin, int code, String message,
40              Throwable throwable) {
41          return create(plugin, IStatus.ERROR, code, message, throwable);
42      }
43  
44      public static IStatus createWarning(Plugin plugin, int code,
45              String message, Throwable throwable) {
46          return create(plugin, IStatus.WARNING, code, message, throwable);
47      }
48  
49      public static IStatus createInfo(Plugin plugin, int code, String message,
50              Throwable throwable) {
51          return create(plugin, IStatus.INFO, code, message, throwable);
52      }
53  
54      public static boolean isError(IStatus status) {
55          return status.getSeverity() == IStatus.ERROR
56                  || status.getSeverity() == IStatus.WARNING;
57      }
58  
59  }