View Javadoc

1   /*
2    WSMO Studio - a Semantic Web Service Editor
3    Copyright (c) 2004-2006, OntoText Lab. / SIRMA Group
4    
5    This library is free software; you can redistribute it and/or modify it under
6    the terms of the GNU Lesser General Public License as published by the Free
7    Software Foundation; either version 2.1 of the License, or (at your option)
8    any later version.
9    This library is distributed in the hope that it will be useful, but WITHOUT
10   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   details.
13   You should have received a copy of the GNU Lesser General Public License along
14   with this library; if not, write to the Free Software Foundation, Inc.,
15   59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16   */
17  
18  /***
19   * <p>Title: WSMO Studio</p>
20   * <p>Description: Semantic Web Service Editor</p>
21   * <p>Copyright:  Copyright (c) 2004-2006</p>
22   * <p>Company: OntoText Lab. / SIRMA </p>
23   */
24  
25  package org.wsmostudio.runtime;
26  
27  import org.eclipse.core.runtime.ILogListener;
28  import org.eclipse.core.runtime.IStatus;
29  import org.eclipse.core.runtime.Status;
30  
31  /***
32   * A utility class to facilitate logging messages, warnings and errors
33   * in the standart Eclipse's destination. 
34   * 
35   * Additionally, a custom logger class can be attached to listen for
36   * log events (the implementation delegates to the plugin's default log
37   * manager).
38   *
39   * @author not attributable
40   * @version $Revision: 469 $ $Date: 2006-01-09 14:51:14 +0200 $
41   */
42  
43  public class LogManager {
44  
45      public static void logError(String message, Throwable error) {
46          logEntry(IStatus.ERROR, "<unknown source>", message, error);
47      }
48      public static void logError(String message) {
49          logEntry(IStatus.ERROR, "<unknown source>", message, null);
50      }
51      public static void logError(Throwable error) {
52          logEntry(IStatus.ERROR, "<unknown source>", error.getMessage(), error);
53      }
54      public static void logError(String pluginID, String message, Throwable error) {
55          logEntry(IStatus.ERROR, pluginID, message, error);
56      }
57  
58      public static void logWarning(String message, Throwable error) {
59          logEntry(IStatus.WARNING, "<unknown source>", message, error);
60      }
61      public static void logWarning(String message) {
62          logEntry(IStatus.WARNING, "<unknown source>", message, null);
63      }
64      public static void logWarning(Throwable error) {
65          logEntry(IStatus.WARNING, "<unknown source>", error.getMessage(), error);
66      }
67      public static void logWarning(String pluginID, String message, Throwable error) {
68          logEntry(IStatus.WARNING, pluginID, message, error);
69      }
70  
71      private static void logEntry(int severity, String pluginID, String message, Throwable error) {
72          if (message == null) {
73              message = "No message available";
74          }
75          Status stat = new Status(severity,
76                                   pluginID,
77                                   IStatus.OK,
78                                   message,
79                                   error);
80          RuntimePlugin.getDefault().getLog().log(stat);
81      }
82      
83      public static void addLogListener(ILogListener listener) {
84          RuntimePlugin.getDefault().getLog().addLogListener(listener);
85      }
86  
87      public static void removeLogListener(ILogListener listener) {
88          RuntimePlugin.getDefault().getLog().removeLogListener(listener);
89      }
90      
91  }
92  
93  /*
94   * $Log$
95   * Revision 1.4  2006/01/09 12:51:12  alex_simov
96   * Copyright message in header updated
97   *
98   * Revision 1.3  2005/12/02 15:56:38  alex_simov
99   * bigfix: NPE
100  *
101  * Revision 1.2  2005/07/21 14:44:40  alex_simov
102  * added javadoc: class description, footer
103  *
104  */