KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > osgi > framework > debug > Debug


1 /*******************************************************************************
2  * Copyright (c) 2003, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.osgi.framework.debug;
13
14 import java.io.PrintStream JavaDoc;
15 import java.lang.reflect.*;
16
17 /**
18  * This class has debug constants which can be used by the Framework implementation
19  * and Adaptor implementations
20  * @since 3.1
21  */

22 public class Debug {
23     /**
24      * DEBUG flag. If set to false then the debug statements will be optimized out during compilation.
25      */

26     public static final boolean DEBUG = true;
27
28     /**
29      * Indicates if tracing is enabled
30      */

31     public static boolean DEBUG_ENABLED = false;
32
33     /**
34      * General debug flag.
35      */

36     public static boolean DEBUG_GENERAL = false; // "debug"
37
/**
38      * Bundle time debug flag.
39      */

40     public static boolean DEBUG_BUNDLE_TIME = false; //"debug.bundleTime"
41
/**
42      * Loader debug flag.
43      */

44     public static boolean DEBUG_LOADER = false; // "debug.loader"
45
/**
46      * Events debug flag.
47      */

48     public static boolean DEBUG_EVENTS = false; // "debug.events"
49
/**
50      * Services debug flag.
51      */

52     public static boolean DEBUG_SERVICES = false; // "debug.services"
53
/**
54      * Packages debug flag.
55      */

56     // TODO remove this or use it somewhere
57
public static boolean DEBUG_PACKAGES = false; // "debug.packages"
58
/**
59      * Manifest debug flag.
60      */

61     public static boolean DEBUG_MANIFEST = false; // "debug.manifest"
62
/**
63      * Filter debug flag.
64      */

65     public static boolean DEBUG_FILTER = false; // "debug.filter"
66
/**
67      * Security debug flag.
68      */

69     public static boolean DEBUG_SECURITY = false; // "debug.security"
70
/**
71      * Start level debug flag.
72      */

73     public static boolean DEBUG_STARTLEVEL = false; // "debug.startlevel"
74
/**
75      * PackageAdmin debug flag.
76      */

77     public static boolean DEBUG_PACKAGEADMIN = false; // "debug.packageadmin"
78
/**
79      * PackageAdmin timing debug flag.
80      */

81     // TODO remove this or use it somewhere
82
public static boolean DEBUG_PACKAGEADMIN_TIMING = false; //"debug.packageadmin/timing"
83
/**
84      * Message debug flag.
85      */

86     public static boolean DEBUG_MESSAGE_BUNDLES = false; //"/debug/messageBundles"
87
/**
88      * Monitor activation debug flag.
89      */

90     public static boolean MONITOR_ACTIVATION = false; // "monitor/bundles"
91

92     /**
93      * Base debug option key (org.eclispe.osgi).
94      */

95     public static final String JavaDoc ECLIPSE_OSGI = "org.eclipse.osgi"; //$NON-NLS-1$
96
/**
97      * General Debug option key.
98      */

99     public static final String JavaDoc OPTION_DEBUG_GENERAL = ECLIPSE_OSGI + "/debug"; //$NON-NLS-1$
100
/**
101      * Bundle time Debug option key.
102      */

103     // TODO remove this or use it somewhere
104
public static final String JavaDoc OPTION_DEBUG_BUNDLE_TIME = ECLIPSE_OSGI + "/debug/bundleTime"; //$NON-NLS-1$
105
/**
106      * Loader Debug option key.
107      */

108     public static final String JavaDoc OPTION_DEBUG_LOADER = ECLIPSE_OSGI + "/debug/loader"; //$NON-NLS-1$
109
/**
110      * Events Debug option key.
111      */

112     public static final String JavaDoc OPTION_DEBUG_EVENTS = ECLIPSE_OSGI + "/debug/events"; //$NON-NLS-1$
113
/**
114      * Services Debug option key.
115      */

116     public static final String JavaDoc OPTION_DEBUG_SERVICES = ECLIPSE_OSGI + "/debug/services"; //$NON-NLS-1$
117
/**
118      * Packages Debug option key.
119      */

120     public static final String JavaDoc OPTION_DEBUG_PACKAGES = ECLIPSE_OSGI + "/debug/packages"; //$NON-NLS-1$
121
/**
122      * Manifest Debug option key.
123      */

124     public static final String JavaDoc OPTION_DEBUG_MANIFEST = ECLIPSE_OSGI + "/debug/manifest"; //$NON-NLS-1$
125
/**
126      * Filter Debug option key.
127      */

128     public static final String JavaDoc OPTION_DEBUG_FILTER = ECLIPSE_OSGI + "/debug/filter"; //$NON-NLS-1$
129
/**
130      * Security Debug option key.
131      */

132     public static final String JavaDoc OPTION_DEBUG_SECURITY = ECLIPSE_OSGI + "/debug/security"; //$NON-NLS-1$
133
/**
134      * Start level Debug option key.
135      */

136     public static final String JavaDoc OPTION_DEBUG_STARTLEVEL = ECLIPSE_OSGI + "/debug/startlevel"; //$NON-NLS-1$
137
/**
138      * PackageAdmin Debug option key.
139      */

140     public static final String JavaDoc OPTION_DEBUG_PACKAGEADMIN = ECLIPSE_OSGI + "/debug/packageadmin"; //$NON-NLS-1$
141
/**
142      * PackageAdmin timing Debug option key.
143      */

144     public static final String JavaDoc OPTION_DEBUG_PACKAGEADMIN_TIMING = ECLIPSE_OSGI + "/debug/packageadmin/timing"; //$NON-NLS-1$
145
/**
146      * Monitor activation Debug option key.
147      */

148     public static final String JavaDoc OPTION_MONITOR_ACTIVATION = ECLIPSE_OSGI + "/monitor/activation"; //$NON-NLS-1$
149
/**
150      * Message bundles Debug option key.
151      */

152     public static final String JavaDoc OPTION_DEBUG_MESSAGE_BUNDLES = ECLIPSE_OSGI + "/debug/messageBundles"; //$NON-NLS-1$
153

154     static {
155         FrameworkDebugOptions dbgOptions = FrameworkDebugOptions.getDefault();
156         if (dbgOptions != null) {
157             DEBUG_ENABLED = true;
158             DEBUG_GENERAL = dbgOptions.getBooleanOption(OPTION_DEBUG_GENERAL, false);
159             DEBUG_BUNDLE_TIME = dbgOptions.getBooleanOption(OPTION_DEBUG_BUNDLE_TIME, false) || dbgOptions.getBooleanOption("org.eclipse.core.runtime/timing/startup", false); //$NON-NLS-1$
160
DEBUG_LOADER = dbgOptions.getBooleanOption(OPTION_DEBUG_LOADER, false);
161             DEBUG_EVENTS = dbgOptions.getBooleanOption(OPTION_DEBUG_EVENTS, false);
162             DEBUG_SERVICES = dbgOptions.getBooleanOption(OPTION_DEBUG_SERVICES, false);
163             DEBUG_PACKAGES = dbgOptions.getBooleanOption(OPTION_DEBUG_PACKAGES, false);
164             DEBUG_MANIFEST = dbgOptions.getBooleanOption(OPTION_DEBUG_MANIFEST, false);
165             DEBUG_FILTER = dbgOptions.getBooleanOption(OPTION_DEBUG_FILTER, false);
166             DEBUG_SECURITY = dbgOptions.getBooleanOption(OPTION_DEBUG_SECURITY, false);
167             DEBUG_STARTLEVEL = dbgOptions.getBooleanOption(OPTION_DEBUG_STARTLEVEL, false);
168             DEBUG_PACKAGEADMIN = dbgOptions.getBooleanOption(OPTION_DEBUG_PACKAGEADMIN, false);
169             DEBUG_PACKAGEADMIN_TIMING = dbgOptions.getBooleanOption(OPTION_DEBUG_PACKAGEADMIN_TIMING, false) || dbgOptions.getBooleanOption("org.eclipse.core.runtime/debug", false); //$NON-NLS-1$
170
DEBUG_MESSAGE_BUNDLES = dbgOptions.getBooleanOption(OPTION_DEBUG_MESSAGE_BUNDLES, false);
171             MONITOR_ACTIVATION = dbgOptions.getBooleanOption(OPTION_MONITOR_ACTIVATION, false);
172         }
173     }
174
175     /**
176      * The PrintStream to print debug messages to.
177      */

178     public static PrintStream JavaDoc out = System.out;
179
180     /**
181      * Prints x to the PrintStream
182      * @param x
183      */

184     public static void print(boolean x) {
185         out.print(x);
186     }
187
188     /**
189      * Prints x to the PrintStream
190      * @param x
191      */

192     public static void print(char x) {
193         out.print(x);
194     }
195
196     /**
197      * Prints x to the PrintStream
198      * @param x
199      */

200     public static void print(int x) {
201         out.print(x);
202     }
203
204     /**
205      * Prints x to the PrintStream
206      * @param x
207      */

208     public static void print(long x) {
209         out.print(x);
210     }
211
212     /**
213      * Prints x to the PrintStream
214      * @param x
215      */

216     public static void print(float x) {
217         out.print(x);
218     }
219
220     /**
221      * Prints x to the PrintStream
222      * @param x
223      */

224     public static void print(double x) {
225         out.print(x);
226     }
227
228     /**
229      * Prints x to the PrintStream
230      * @param x
231      */

232     public static void print(char x[]) {
233         out.print(x);
234     }
235
236     /**
237      * Prints x to the PrintStream
238      * @param x
239      */

240     public static void print(String JavaDoc x) {
241         out.print(x);
242     }
243
244     /**
245      * Prints x to the PrintStream
246      * @param x
247      */

248     public static void print(Object JavaDoc x) {
249         out.print(x);
250     }
251
252     /**
253      * Prints x to the PrintStream
254      * @param x
255      */

256     public static void println(boolean x) {
257         out.println(x);
258     }
259
260     /**
261      * Prints x to the PrintStream
262      * @param x
263      */

264     public static void println(char x) {
265         out.println(x);
266     }
267
268     /**
269      * Prints x to the PrintStream
270      * @param x
271      */

272     public static void println(int x) {
273         out.println(x);
274     }
275
276     /**
277      * Prints x to the PrintStream
278      * @param x
279      */

280     public static void println(long x) {
281         out.println(x);
282     }
283
284     /**
285      * Prints x to the PrintStream
286      * @param x
287      */

288     public static void println(float x) {
289         out.println(x);
290     }
291
292     /**
293      * Prints x to the PrintStream
294      * @param x
295      */

296     public static void println(double x) {
297         out.println(x);
298     }
299
300     /**
301      * Prints x to the PrintStream
302      * @param x
303      */

304     public static void println(char x[]) {
305         out.println(x);
306     }
307
308     /**
309      * Prints x to the PrintStream
310      * @param x
311      */

312     public static void println(String JavaDoc x) {
313         out.println(x);
314     }
315
316     /**
317      * Prints x to the PrintStream
318      * @param x
319      */

320     public static void println(Object JavaDoc x) {
321         out.println(x);
322     }
323
324     /**
325      * Prints t to the PrintStream
326      * @param t
327      */

328     public static void printStackTrace(Throwable JavaDoc t) {
329         if (t == null)
330             return;
331         t.printStackTrace(out);
332
333         Method[] methods = t.getClass().getMethods();
334
335         int size = methods.length;
336         Class JavaDoc throwable = Throwable JavaDoc.class;
337
338         for (int i = 0; i < size; i++) {
339             Method method = methods[i];
340
341             if (Modifier.isPublic(method.getModifiers()) && method.getName().startsWith("get") && throwable.isAssignableFrom(method.getReturnType()) && (method.getParameterTypes().length == 0)) { //$NON-NLS-1$
342
try {
343                     Throwable JavaDoc nested = (Throwable JavaDoc) method.invoke(t, null);
344
345                     if ((nested != null) && (nested != t)) {
346                         out.println("Nested Exception:"); //$NON-NLS-1$
347
printStackTrace(nested);
348                     }
349                 } catch (IllegalAccessException JavaDoc e) {
350                 } catch (InvocationTargetException e) {
351                 }
352             }
353         }
354     }
355
356 }
357
Popular Tags