1 23 package com.sun.enterprise.util; 24 25 import java.util.Properties ; 26 import java.util.Enumeration ; 27 import java.io.FileInputStream ; 28 import java.io.IOException ; 29 import java.lang.reflect.*; 30 31 import java.util.logging.*; 33 import com.sun.logging.*; 34 36 37 49 public final class DebugController { 50 51 static Logger _logger=LogDomains.getLogger(LogDomains.UTIL_LOGGER); 53 55 private static final String PROPS_FILENAME = "debug.properties"; 56 private static final String FIELD_NAME = "debug"; 57 58 private static DebugController controller = null; 59 60 private Properties props = new Properties (); 61 private String 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 propsFileName) { 83 this.propsFileName = propsFileName; 84 } 85 86 private void load() { 87 try { 88 FileInputStream fin = new FileInputStream (propsFileName); 89 props.load(fin); 90 91 for(Enumeration e = props.propertyNames(); e.hasMoreElements(); ) { 92 String className = (String ) e.nextElement(); 93 boolean value = 94 Boolean.valueOf(props.getProperty(className)).booleanValue(); 95 setInfo(className, value); 96 } 97 fin.close(); 98 } catch(IOException e) { 99 102 _logger.log(Level.SEVERE,"enterprise_util.dbgcntl_ioexception",e); 104 } 106 } 107 108 private void setInfo(String className, boolean value) { 109 try { 110 Class cls = Class.forName(className); 111 Field dField = cls.getField(FIELD_NAME); 112 dField.setBoolean(null, value); 113 } catch (Exception e) { 114 120 126 } 127 } 128 } 129 130 131 132 133 134 | Popular Tags |