KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > mdrant > MdrantLogger


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 package org.netbeans.mdrant;
20
21 import java.io.*;
22 import java.util.*;
23 import org.openide.ErrorManager;
24 import org.apache.tools.ant.Project;
25 import org.apache.tools.ant.Task;
26
27 /**
28  * Logger which forwards MDR notifications to Ant.
29  *
30  * @author John V. Sichi
31  */

32 public class MdrantLogger extends ErrorManager
33 {
34     private static Task task;
35
36     public MdrantLogger()
37     {
38     }
39
40     static void setTask(Task newTask)
41     {
42         task = newTask;
43     }
44
45     // implement ErrorManager
46
public Throwable JavaDoc attachAnnotations(
47         Throwable JavaDoc t, Annotation[] arr)
48     {
49         return t;
50     }
51         
52     // implement ErrorManager
53
public Annotation[] findAnnotations(Throwable JavaDoc t)
54     {
55         return null;
56     }
57         
58     // implement ErrorManager
59
public Throwable JavaDoc annotate(
60         Throwable JavaDoc t, int severity,
61         String JavaDoc message, String JavaDoc localizedMessage,
62         Throwable JavaDoc stackTrace, java.util.Date JavaDoc date)
63     {
64         if (task != null) {
65             task.log(message, convertSeverity(severity));
66         }
67         return t;
68     }
69         
70     // implement ErrorManager
71
public void notify(int severity, Throwable JavaDoc t)
72     {
73         if (task != null) {
74             task.log(t.toString(), convertSeverity(severity));
75         }
76     }
77         
78     // implement ErrorManager
79
public void log(int severity, String JavaDoc s)
80     {
81         if (task != null) {
82             task.log(s, convertSeverity(severity));
83         }
84     }
85         
86     // implement ErrorManager
87
public ErrorManager getInstance(String JavaDoc name)
88     {
89         return this;
90     }
91     
92     private static int convertSeverity(int severity)
93     {
94         switch(severity) {
95         case INFORMATIONAL:
96             return Project.MSG_VERBOSE;
97         case WARNING:
98             return Project.MSG_WARN;
99         case USER:
100             return Project.MSG_INFO;
101         case EXCEPTION:
102             return Project.MSG_ERR;
103         case ERROR:
104             return Project.MSG_ERR;
105         default:
106             return Project.MSG_DEBUG;
107         }
108     }
109 }
110
111 // End MdrantLogger.java
112
Popular Tags