KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > websphere6 > util > WSDebug


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.modules.j2ee.websphere6.util;
20
21 /**
22  * The central debugging utility for the plugin. The plugin whould forward all
23  * the debugging information to this tool, which will output it to System.out
24  * if the debug has been enabled
25  *
26  * @author Kirill Sorokin
27  */

28 public class WSDebug {
29
30     /**
31      * The name of the system property that should be present in order to
32      * enable the debugging output for the plugin
33      */

34     private static final String JavaDoc PROPERTY = "j2eeplugins.websphere6.debug";
35
36     /**
37      * The prefix that should be inserted before any messages that are output
38      * by this class
39      */

40     private static final String JavaDoc PREFIX = "j2eeplugins.websphere6 --- ";
41     
42     /**
43      * Indicated whether the debug is enabled. At initialization we check for
44      * the presence of the "j2eeplugins.websphere6.debug" property and if it is
45      * present we consider the debug for the plugin enabled.
46      */

47     private static boolean isEnabled = System.
48             getProperty(PROPERTY) != null; // NOI18N
49

50     /**
51      * Tells whether the debug for the plugin is enabled
52      */

53     public static boolean isEnabled() {
54         return isEnabled;
55     }
56     
57     /**
58      * Outputs the given message to the System.out with the fixed prefix
59      *
60      * @param message the message to be output
61      */

62     public static void notify(String JavaDoc message) {
63         System.out.println(PREFIX + message); // NOI18N
64
}
65     
66     /**
67      * Outputs the given message to the System.out with the fixed prefix and the
68      * class name
69      *
70      * @param clazz the class from which the message originated
71      * @param message the message to be output
72      */

73     public static void notify(Class JavaDoc clazz, String JavaDoc message) {
74         System.out.println("j2eeplugins.websphere6 --- [" + // NOI18N
75
clazz.getName() + "]: " + message); // NOI18N
76
}
77     
78     /**
79      * Outputs the given exception to the System.out
80      *
81      * @param exception the exception
82      */

83     public static void notify(Exception JavaDoc exception) {
84         exception.printStackTrace(System.out);
85     }
86     
87     /**
88      * Outputs the supplied pack of objects to the System.out
89      *
90      * @param objects an array of objects that need to be output
91      */

92     public static void notify(Object JavaDoc[] objects) {
93         System.out.println(PREFIX + objects);
94         for (int i = 0; i < objects.length; i++) {
95             System.out.println(PREFIX + objects[i]);
96         }
97     }
98     
99     /**
100      * Prints the current stack to the System.out
101      */

102     public static void printStack() {
103         // get the stack trace
104
StackTraceElement JavaDoc[] stack = new Exception JavaDoc().getStackTrace();
105         
106         // for each stack element output import to the System.out
107
for (int i = 3; i < stack.length; i++) {
108             System.out.println(PREFIX + // NOI18N
109
stack[i]);
110         }
111     }
112     
113 }
114
Popular Tags