KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ErrorManagerImpl


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.apisupport.project;
21
22 import java.io.PrintWriter JavaDoc;
23 import java.io.StringWriter JavaDoc;
24 import java.util.Date JavaDoc;
25 import junit.framework.Assert;
26 import org.netbeans.junit.NbTestCase;
27 import org.openide.ErrorManager;
28
29 /**
30  * NbTestCase logging error manager.
31  * @author Jaroslav Tulach
32  */

33 public class ErrorManagerImpl extends ErrorManager {
34
35     static NbTestCase running;
36
37     private String JavaDoc prefix;
38
39     /** Creates a new instance of ErrorManagerImpl */
40     public ErrorManagerImpl() {
41         this("[em]");
42     }
43
44     private ErrorManagerImpl(String JavaDoc p) {
45         this.prefix = p;
46     }
47     
48     public static void registerCase(NbTestCase r) {
49         running = r;
50     }
51     
52     public Throwable JavaDoc attachAnnotations(Throwable JavaDoc t, Annotation[] arr) {
53         return t;
54     }
55     
56     public Annotation[] findAnnotations(Throwable JavaDoc t) {
57         return null;
58     }
59     
60     public Throwable JavaDoc annotate(Throwable JavaDoc t, int severity, String JavaDoc message, String JavaDoc localizedMessage, Throwable JavaDoc stackTrace, Date JavaDoc date) {
61         return t;
62     }
63     
64     public void notify(int severity, Throwable JavaDoc t) {
65         StringWriter JavaDoc w = new StringWriter JavaDoc();
66         w.write(prefix);
67         w.write(' ');
68         t.printStackTrace(new PrintWriter JavaDoc(w));
69         
70         System.err.println(w.toString());
71         
72         if (running == null) {
73             return;
74         }
75         running.getLog().println(w.toString());
76     }
77     
78     public void log(int severity, String JavaDoc s) {
79         String JavaDoc msg = prefix + ' ' + s;
80         if (severity != INFORMATIONAL) {
81             System.err.println(msg);
82         }
83         
84         if (running == null) {
85             return;
86         }
87         running.getLog().println(msg);
88     }
89     
90     public ErrorManager getInstance(String JavaDoc name) {
91         return new ErrorManagerImpl(name);
92     }
93     
94 }
95
Popular Tags