KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > util > DebugController


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.util;
24
25 import java.util.Properties JavaDoc;
26 import java.util.Enumeration JavaDoc;
27 import java.io.FileInputStream JavaDoc;
28 import java.io.IOException JavaDoc;
29 import java.lang.reflect.*;
30
31 //START OF IASRI 4660742
32
import java.util.logging.*;
33 import com.sun.logging.*;
34 //END OF IASRI 4660742
35

36
37 /**
38  * This class lets the developers trigger the debug information
39  * at Runtime.
40  * <BR>
41  * <P>Any class that intends to use this feature needs to have a
42  * public static boolean variable called "debug".
43  * This variable can be triggered to true or false at runtime
44  * by having a properties file with the keys as the fully qualified
45  * name of classes and the values to be the boolean value the debug
46  * variable.
47  * <BR>
48  */

49 public final class DebugController {
50
51     // START OF IASRI 4660742
52
static Logger _logger=LogDomains.getLogger(LogDomains.UTIL_LOGGER);
53     // END OF IASRI 4660742
54

55     private static final String JavaDoc PROPS_FILENAME = "debug.properties";
56     private static final String JavaDoc FIELD_NAME = "debug";
57
58     private static DebugController controller = null;
59
60     private Properties JavaDoc props = new Properties JavaDoc();
61     private String JavaDoc propsFileName;
62
63     private static DebugController getInstance() {
64     if(controller == null) {
65         synchronized(DebugController.class) {
66         controller = new DebugController();
67         }
68     }
69     
70     return controller;
71     }
72
73     public static void init() {
74     DebugController ctrller = getInstance();
75     ctrller.load();
76     }
77
78     private DebugController() {
79     this(PROPS_FILENAME);
80     }
81
82     private DebugController(String JavaDoc propsFileName) {
83     this.propsFileName = propsFileName;
84     }
85
86     private void load() {
87     try {
88         FileInputStream JavaDoc fin = new FileInputStream JavaDoc(propsFileName);
89         props.load(fin);
90         
91         for(Enumeration JavaDoc e = props.propertyNames(); e.hasMoreElements(); ) {
92         String JavaDoc className = (String JavaDoc) e.nextElement();
93         boolean value =
94             Boolean.valueOf(props.getProperty(className)).booleanValue();
95         setInfo(className, value);
96         }
97         fin.close();
98     } catch(IOException JavaDoc e) {
99         /** IASRI 4660742
100        e.printStackTrace();
101       **/

102         // START OF IASRI 4660742
103
_logger.log(Level.SEVERE,"enterprise_util.dbgcntl_ioexception",e);
104         // END OF IASRI 4660742
105
}
106     }
107
108     private void setInfo(String JavaDoc className, boolean value) {
109     try {
110         Class JavaDoc cls = Class.forName(className);
111         Field dField = cls.getField(FIELD_NAME);
112         dField.setBoolean(null, value);
113     } catch (Exception JavaDoc e) {
114         // If there is an exception lets ingore it, there's nothing
115
// we can do about it.
116
/** IASRI 4660742
117         // System.err.println("Debug Controller: " + e.getMessage());
118         // e.printStackTrace();
119       **/

120         // START OF IASRI 4660742
121
// if(_logger.isLoggable(Level.FINE))
122
// _logger.log(Level.FINE,"Debug Controller: " + e.getMessage());
123
// _logger.log(Level.SEVERE,"enterprise_util.excep_in_dbgcntl_setInfo",e);
124
// END OF IASRI 4660742
125

126     }
127     }
128 }
129
130
131
132
133
134
Popular Tags