KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > logger > errormanager > UIErrorManager


1 /*
2  * ErrorManager.java
3  *
4  * Created on May 18, 2005, 1:45 PM
5  *
6  * To change this template, choose Tools | Options and locate the template under
7  * the Source Creation and Management node. Right-click the template and choose
8  * Open. You can then make changes to the template in the Source Editor.
9  */

10
11 package org.netbeans.modules.logger.errormanager;
12 import org.netbeans.modules.logger.listeners.ListenerTools;
13 import org.openide.ErrorManager;
14
15
16 /**
17  * This class implements the famous NB ErrorManager.
18  *
19  * The most important thing to know is that just one instance of this class
20  * should be enabled for logging. Logging will take place only if
21  * method <CODE>getInstance(String name)</CODE> is called and
22  * <CODE>name==org.netbeans.ui.log</CODE> . The instance returned will be able
23  * to log.
24  *
25  * The instance that does the logging is contained inside the static
26  * variable <CODE>realUIErrorManager</CODE>.
27  *
28  * @author loicsegapelli
29  */

30 public class UIErrorManager extends ErrorManager{
31     
32     private static UIErrorManagerWriter manager;
33     private static UIErrorManager realUIErrorManager;
34     boolean doLog=false;
35     private String JavaDoc id;
36     
37     
38     private UIErrorManager(boolean doLogBoolean, String JavaDoc name) {
39         super();
40         doLog=doLogBoolean;
41         id=name;
42     }
43     
44     
45     /**
46      * Creates a new instance of ErrorManager, sets the doLog variable at false
47      */

48     public UIErrorManager(){
49         doLog=false;
50         id="registeredLogger";
51         manager=new UIErrorManagerWriter();
52     }
53     
54     
55     /**
56      * returns an instance of UIErrorManager. According to the parameter
57      * <CODE>name</CODE> it is either the instance that logs or the other one.
58      * @param name name of the required instance.
59      * @return An instance of UIErrorManager.
60      */

61     public ErrorManager getInstance(String JavaDoc name){
62         if(!id.equals("registeredLogger")){
63             ListenerTools.logError(new Throwable JavaDoc("MAJOR BUG:Error Manager not unique!"));
64         }
65         if(realUIErrorManager==null){
66             realUIErrorManager=new UIErrorManager(true,"realUIErrorManager");
67         }
68         if(name==null)return this;
69         return name.equals("org.netbeans.ui.log") ? realUIErrorManager : this;
70     }
71     
72     /**
73      * Nothing too interesting for us
74      * @param severity severity of the error
75      * @param t throwable to annotate
76      */

77     public void notify(int severity, Throwable JavaDoc t){
78     }
79     
80     /**
81      * This funny method is not declared as abstract in the original
82      * ErrorManager, BUUUT it should be :-)))
83      * @param severity supposed to be the severity of the error, but in our case
84      * we do not mind at all
85      * @return indicates whether or not this instance logs messages.
86      */

87     public boolean isLoggable(int severity) {
88         return doLog;
89     }
90     
91     /**
92      * Logs messages sent to the <CODE>UIErrorManager</CODE>
93      * @param severity severity of the error, but we do not mind here
94      * @param s the message
95      */

96     public void log(int severity, String JavaDoc s){
97         if(doLog){
98             String JavaDoc time=Long.toString(System.currentTimeMillis());
99             manager.log(time+" "+s);
100         }
101     }
102     
103     /**
104      * Nothing interesting for us
105      * @param t t
106      * @param severity severity
107      * @param message message
108      * @param localizedMessage localizedMessage
109      * @param stackTrace stackTrace
110      * @param date date
111      * @return return
112      */

113     public Throwable JavaDoc annotate(
114             Throwable JavaDoc t, int severity,
115             String JavaDoc message, String JavaDoc localizedMessage,
116             Throwable JavaDoc stackTrace, java.util.Date JavaDoc date
117             ) {
118         return t;
119     }
120     
121     /**
122      * Nothing interesting for us
123      * @param t t
124      * @return return
125      */

126     public Annotation[] findAnnotations(Throwable JavaDoc t){
127         return null;
128     }
129     
130     /**
131      * Nothing interesting for us
132      * @param t t
133      * @param arr arr
134      * @return return
135      */

136     public Throwable JavaDoc attachAnnotations(Throwable JavaDoc t, Annotation[] arr){
137         return null;
138     }
139     
140 }
141
Popular Tags