1 /* -------------------------------------------------------------------
2 * Java source file for the class Debug
3 *
4 * Copyright (c), 2002, Masahiro Takatsuka.
5 * All Rights Researved.
6 *
7 * Original Author: Masahiro Takatsuka (masa@jbeans.net)
8 * $Author: takatsukam $
9 *
10 * $Date: 2003/07/25 04:51:47 $
11 *
12 * $Id: Debug.java,v 1.1.1.1 2003/07/25 04:51:47 takatsukam Exp $
13 *
14 * Reference: Document no:
15 * ___ ___
16 *
17 * To Do:
18 * ___
19 *
20 ------------------------------------------------------------------- */
21
22 /* --------------------------- Package ---------------------------- */
23 package net.jbeans.util.debug;
24
25 /* ------------------ Import classes (packages) ------------------- *//package-summary/html">color="#329900"> ------------------ Import classes (packages) ------------------- *//package-summary.html">color="#329900">/* ------------------ Import classes (packages) ------------------- *//package-summary.html">color="#329900"> ------------------ Import classes (packages) ------------------- */
26 // import foo.*;
27
28 /*====================================================================
29 Implementation of class Debug
30 ====================================================================*/
31 /***
32 * Debug handles command line debug flags.
33 *
34 * @version $Revision: 1.1.1.1 $
35 * @author Masahiro Takatsuka (masa@jbeans.net)
36 */
37
38 public class Debug {
39 private static final String SYSTEM_DEBUG = "System.Debug";
40 private static final boolean DEBUG;
41
42 static {
43 DEBUG = findDebugFlag(SYSTEM_DEBUG);
44 }
45
46 /***
47 * get debug flag from system properties.
48 */
49 private static boolean findDebugFlag(String key) {
50 boolean ret = false;
51 try {
52 String debugString = System.getProperty(key);
53 if (debugString != null) {
54 ret = true;
55 }
56 } catch (SecurityException se) {
57 //se.printStackTrace();
58 //System.out.println("Debug is not allowed to read properties");
59 ret = false;
60 }
61 return ret;
62 }
63
64 /***
65 * Returns a system debug flag.
66 */
67 public static final boolean getSystemDebugFlag() {
68 return DEBUG;
69 }
70
71 /***
72 * Returns a debug flag for a specified key.
73 */
74 public static final boolean getDebugFlag(String key) {
75 return (DEBUG || findDebugFlag(key));
76 }
77
78 /***
79 * Returns a debug flag for a specified class. The fully-qualified
80 * class name + ".Debug" is used as a debug key.
81 */
82 public static final boolean getDebugFlag(Class clazz) {
83 return getDebugFlag(clazz.getName() + ".Debug");
84 }
85
86 /* --------------------------- for test --------------------------- */
87 private static final String usage = "Usage: java [-DSystem.Debug | -Dnet.jbeans.util.debug.Debug.Debug] net.jbeans.util.debug.Debug";
88 public static void main(String[] args) {
89 if (args.length > 0 && args[0].equalsIgnoreCase("--help")) {
90 System.out.println(usage);
91 }
92 boolean debug = getDebugFlag(Debug.class);
93
94 if (debug) {
95 System.out.println("debugging...");
96 }
97 }
98
99 }
This page was automatically generated by Maven