< prev index next >

src/com/sun/javatest/util/Debug.java

Print this page
rev 145 : 7902237: Fixing raw use of parameterized class
Reviewed-by: jjg


 115 
 116         String match = dProps.getProperty(key);
 117 
 118         if (match != null)
 119             return match;
 120         else {
 121             match = wildProps.search(key);
 122             // may be null
 123             return match;
 124         }
 125     }
 126 
 127     /**
 128      * Find out the debugging setting for class c.
 129      * Lookup is done by looking for fully qualified class name.
 130      *
 131      * @param c Class whose name should be used to lookup the setting, null results in
 132      *    a return value of zero.
 133      * @return the debugging setting for the specified class
 134      */
 135     public static boolean getBoolean(Class c) {
 136         init(false);
 137 
 138         if (!masterSwitch)
 139             return false;
 140 
 141         String key = getName(c);
 142         String setting = getSetting(key);
 143         boolean state = convertToBool(setting);
 144 
 145         return state;
 146     }
 147 
 148     /**
 149      * Find out the debugging setting for class c.
 150      * Lookup is done by looking for fully qualified class name with a dot and the
 151      * given suffix appended.
 152      *
 153      * @param c Class whose name should be used to lookup the setting, null results in
 154      *    a return value of zero.
 155      * @param suffix String to append to the classname, null will result in a lookup
 156      *    of just the classname.
 157      * @return the debugging setting for the specified class
 158      */
 159     public static boolean getBoolean(Class c, String suffix) {
 160         init(false);
 161 
 162         if (!masterSwitch)
 163             return false;
 164 
 165         StringBuffer buf = new StringBuffer(getName(c));
 166         if (suffix != null && suffix.length() != 0) {
 167             buf.append(Debug.SEPARATOR);
 168             buf.append(suffix);
 169         }
 170 
 171         String key = buf.toString();
 172         String setting = getSetting(key);
 173         boolean state = convertToBool(setting);
 174 
 175         return state;
 176     }
 177 
 178     /**
 179      * Get a named debugging setting.


 183     public static boolean getBoolean(String s) {
 184         init(false);
 185 
 186         if (!masterSwitch || s == null)
 187             return false;
 188 
 189         String setting = getSetting(s);
 190         boolean state = convertToBool(setting);
 191 
 192         return state;
 193     }
 194 
 195     /**
 196      * Find out the debugging setting for class c.
 197      * Lookup is done by looking for fully qualified class name.
 198      *
 199      * @param c the class whose name should be used to lookup the setting
 200      * @return the debugging setting for the given class, or 0 if no class
 201      *    was specified
 202      */
 203     public static int getInt(Class c) {
 204         init(false);
 205 
 206         if (!masterSwitch || c == null)
 207             return 0;
 208 
 209         String key = getName(c);
 210         String setting = getSetting(key);
 211         int state = convertToInt(setting);
 212 
 213         return state;
 214     }
 215 
 216     /**
 217      * Find out the debugging setting for class c.
 218      * Lookup is done by looking for fully qualified class name with a dot and the
 219      * given suffix appended.
 220      *
 221      * @param c a class whose name should be used to lookup the setting;
 222      *    null results in a return value of zero.
 223      * @param suffix a string to append to the classname;
 224      *    null will result in a lookup of just the classname.
 225      * @return the debugging setting for the class
 226      */
 227     public static int getInt(Class c, String suffix) {
 228         init(false);
 229 
 230         if (!masterSwitch || c == null)
 231             return 0;
 232 
 233         StringBuffer buf = new StringBuffer(getName(c));
 234         if (suffix != null && suffix.length() != 0) {
 235             buf.append(Debug.SEPARATOR);
 236             buf.append(suffix);
 237         }
 238 
 239         String key = buf.toString();
 240         String setting = getSetting(key);
 241         int state = convertToInt(setting);
 242 
 243         return state;
 244     }
 245 
 246     /**
 247      * Get a named debugging setting.


 300     public synchronized static void init(boolean force) {
 301         if (dProps != null && force != true)
 302             return;
 303 
 304         Properties props;
 305 
 306         try {
 307             props = System.getProperties();
 308         }
 309         catch (SecurityException e) {
 310             // this is the backup source of settings
 311             props = givenProps;
 312         }
 313 
 314         if (props == null) {
 315             // we're stuck, must disable debugging
 316             masterSwitch = false;
 317             return;
 318         }
 319 
 320         Enumeration keys = props.propertyNames();
 321 
 322         dProps = new Properties();
 323         wildProps = new WildcardProperties();
 324 
 325         while (keys.hasMoreElements()) {
 326             String key = (String)(keys.nextElement());
 327             if (key.startsWith(DEBUG_PREFIX)) {
 328                 // this should be a setProperty() in JDK 1.2+
 329                 if (key.equalsIgnoreCase(MASTER_KEY)) {
 330                     String val = props.getProperty(key);
 331                     // this will disable all debugging, all methods will return zero or false
 332                     if (val.equalsIgnoreCase(TRUE_STRING))
 333                         masterSwitch = false;
 334                 }
 335                 else if (key.endsWith(WILD_SUFFIX)) {
 336                     wildProps.put(key.substring(DEBUG_PREFIX.length()), props.getProperty(key));
 337                 }
 338                 else
 339                     dProps.put(key.substring(DEBUG_PREFIX.length()), props.getProperty(key));
 340             }
 341         }   // while
 342     }
 343 
 344     // -------- Private ---------
 345 
 346     /**
 347      * Convert a class object into a string appropriate for lookup.
 348      *
 349      * @param c Must not be null.
 350      */
 351     private static String getName(Class c) {
 352         // null checking skipped
 353 
 354         String name = c.getName();
 355 
 356         // compensate for inner classes for which getName() return the internal name
 357         name = name.replace('$', '.');
 358 
 359         return name;
 360     }
 361 
 362     /*
 363      * Take the user setting and interpret it.
 364      * If the setting corresponds to the true string, true is returned.  If it corresponds to
 365      * an integer greater than zero, true is returned.  Otherwise, false is returned.
 366      */
 367     private static boolean convertToBool(String setting) {
 368         if (setting == null)
 369             return false;
 370 
 371         if (setting.equalsIgnoreCase(TRUE_STRING))


 438      */
 439     private static boolean masterSwitch = true;
 440 
 441     static {
 442         out = new PrintWriter(System.err);
 443     }
 444 
 445     /**
 446      * Wildcards are compared against the given key minus one field.
 447      * So a search(<tt>"foo.bar.baz"</tt>) does a search for <tt>"foo.bar.*"</tt>.
 448      * <tt>"foo.*"</tt> will not be a match.
 449      */
 450     private static class WildcardProperties extends Properties {
 451         /**
 452          * This is the only method in this class that accounts for wildcards.
 453          */
 454         public String search(String key) {
 455             String lowerKey = key.toLowerCase();
 456             String target = trimTarget(lowerKey);
 457 
 458             Enumeration keys = propertyNames();
 459             while (keys.hasMoreElements()) {
 460                 String k = (String)(keys.nextElement());
 461                 String lowerK = k.toLowerCase();
 462 
 463                 if (lowerK.startsWith(target)) {
 464                     // should strip target string and dot
 465                     String tail = lowerK.substring(target.length());
 466                     String head = lowerK.substring(0, target.length());
 467                     if (tail.equals(wildTail) || head.equals(lowerKey))
 468                         return getProperty(k);
 469                 }
 470             }   // while
 471 
 472             return null;
 473         }
 474 
 475         /**
 476          * Remove the last element of the requested key to see if a wildcard fits into
 477          * that position.  Wildcards can only be valid up one level, so
 478          * foo.* cannot match foo.bar.baz, but will match foo.bar.  This method


 115 
 116         String match = dProps.getProperty(key);
 117 
 118         if (match != null)
 119             return match;
 120         else {
 121             match = wildProps.search(key);
 122             // may be null
 123             return match;
 124         }
 125     }
 126 
 127     /**
 128      * Find out the debugging setting for class c.
 129      * Lookup is done by looking for fully qualified class name.
 130      *
 131      * @param c Class whose name should be used to lookup the setting, null results in
 132      *    a return value of zero.
 133      * @return the debugging setting for the specified class
 134      */
 135     public static boolean getBoolean(Class<?> c) {
 136         init(false);
 137 
 138         if (!masterSwitch)
 139             return false;
 140 
 141         String key = getName(c);
 142         String setting = getSetting(key);
 143         boolean state = convertToBool(setting);
 144 
 145         return state;
 146     }
 147 
 148     /**
 149      * Find out the debugging setting for class c.
 150      * Lookup is done by looking for fully qualified class name with a dot and the
 151      * given suffix appended.
 152      *
 153      * @param c Class whose name should be used to lookup the setting, null results in
 154      *    a return value of zero.
 155      * @param suffix String to append to the classname, null will result in a lookup
 156      *    of just the classname.
 157      * @return the debugging setting for the specified class
 158      */
 159     public static boolean getBoolean(Class<?> c, String suffix) {
 160         init(false);
 161 
 162         if (!masterSwitch)
 163             return false;
 164 
 165         StringBuffer buf = new StringBuffer(getName(c));
 166         if (suffix != null && suffix.length() != 0) {
 167             buf.append(Debug.SEPARATOR);
 168             buf.append(suffix);
 169         }
 170 
 171         String key = buf.toString();
 172         String setting = getSetting(key);
 173         boolean state = convertToBool(setting);
 174 
 175         return state;
 176     }
 177 
 178     /**
 179      * Get a named debugging setting.


 183     public static boolean getBoolean(String s) {
 184         init(false);
 185 
 186         if (!masterSwitch || s == null)
 187             return false;
 188 
 189         String setting = getSetting(s);
 190         boolean state = convertToBool(setting);
 191 
 192         return state;
 193     }
 194 
 195     /**
 196      * Find out the debugging setting for class c.
 197      * Lookup is done by looking for fully qualified class name.
 198      *
 199      * @param c the class whose name should be used to lookup the setting
 200      * @return the debugging setting for the given class, or 0 if no class
 201      *    was specified
 202      */
 203     public static int getInt(Class<?> c) {
 204         init(false);
 205 
 206         if (!masterSwitch || c == null)
 207             return 0;
 208 
 209         String key = getName(c);
 210         String setting = getSetting(key);
 211         int state = convertToInt(setting);
 212 
 213         return state;
 214     }
 215 
 216     /**
 217      * Find out the debugging setting for class c.
 218      * Lookup is done by looking for fully qualified class name with a dot and the
 219      * given suffix appended.
 220      *
 221      * @param c a class whose name should be used to lookup the setting;
 222      *    null results in a return value of zero.
 223      * @param suffix a string to append to the classname;
 224      *    null will result in a lookup of just the classname.
 225      * @return the debugging setting for the class
 226      */
 227     public static int getInt(Class<?> c, String suffix) {
 228         init(false);
 229 
 230         if (!masterSwitch || c == null)
 231             return 0;
 232 
 233         StringBuffer buf = new StringBuffer(getName(c));
 234         if (suffix != null && suffix.length() != 0) {
 235             buf.append(Debug.SEPARATOR);
 236             buf.append(suffix);
 237         }
 238 
 239         String key = buf.toString();
 240         String setting = getSetting(key);
 241         int state = convertToInt(setting);
 242 
 243         return state;
 244     }
 245 
 246     /**
 247      * Get a named debugging setting.


 300     public synchronized static void init(boolean force) {
 301         if (dProps != null && force != true)
 302             return;
 303 
 304         Properties props;
 305 
 306         try {
 307             props = System.getProperties();
 308         }
 309         catch (SecurityException e) {
 310             // this is the backup source of settings
 311             props = givenProps;
 312         }
 313 
 314         if (props == null) {
 315             // we're stuck, must disable debugging
 316             masterSwitch = false;
 317             return;
 318         }
 319 
 320         Enumeration<?> keys = props.propertyNames();
 321 
 322         dProps = new Properties();
 323         wildProps = new WildcardProperties();
 324 
 325         while (keys.hasMoreElements()) {
 326             String key = (String)(keys.nextElement());
 327             if (key.startsWith(DEBUG_PREFIX)) {
 328                 // this should be a setProperty() in JDK 1.2+
 329                 if (key.equalsIgnoreCase(MASTER_KEY)) {
 330                     String val = props.getProperty(key);
 331                     // this will disable all debugging, all methods will return zero or false
 332                     if (val.equalsIgnoreCase(TRUE_STRING))
 333                         masterSwitch = false;
 334                 }
 335                 else if (key.endsWith(WILD_SUFFIX)) {
 336                     wildProps.put(key.substring(DEBUG_PREFIX.length()), props.getProperty(key));
 337                 }
 338                 else
 339                     dProps.put(key.substring(DEBUG_PREFIX.length()), props.getProperty(key));
 340             }
 341         }   // while
 342     }
 343 
 344     // -------- Private ---------
 345 
 346     /**
 347      * Convert a class object into a string appropriate for lookup.
 348      *
 349      * @param c Must not be null.
 350      */
 351     private static String getName(Class<?> c) {
 352         // null checking skipped
 353 
 354         String name = c.getName();
 355 
 356         // compensate for inner classes for which getName() return the internal name
 357         name = name.replace('$', '.');
 358 
 359         return name;
 360     }
 361 
 362     /*
 363      * Take the user setting and interpret it.
 364      * If the setting corresponds to the true string, true is returned.  If it corresponds to
 365      * an integer greater than zero, true is returned.  Otherwise, false is returned.
 366      */
 367     private static boolean convertToBool(String setting) {
 368         if (setting == null)
 369             return false;
 370 
 371         if (setting.equalsIgnoreCase(TRUE_STRING))


 438      */
 439     private static boolean masterSwitch = true;
 440 
 441     static {
 442         out = new PrintWriter(System.err);
 443     }
 444 
 445     /**
 446      * Wildcards are compared against the given key minus one field.
 447      * So a search(<tt>"foo.bar.baz"</tt>) does a search for <tt>"foo.bar.*"</tt>.
 448      * <tt>"foo.*"</tt> will not be a match.
 449      */
 450     private static class WildcardProperties extends Properties {
 451         /**
 452          * This is the only method in this class that accounts for wildcards.
 453          */
 454         public String search(String key) {
 455             String lowerKey = key.toLowerCase();
 456             String target = trimTarget(lowerKey);
 457 
 458             Enumeration<?> keys = propertyNames();
 459             while (keys.hasMoreElements()) {
 460                 String k = (String)(keys.nextElement());
 461                 String lowerK = k.toLowerCase();
 462 
 463                 if (lowerK.startsWith(target)) {
 464                     // should strip target string and dot
 465                     String tail = lowerK.substring(target.length());
 466                     String head = lowerK.substring(0, target.length());
 467                     if (tail.equals(wildTail) || head.equals(lowerKey))
 468                         return getProperty(k);
 469                 }
 470             }   // while
 471 
 472             return null;
 473         }
 474 
 475         /**
 476          * Remove the last element of the requested key to see if a wildcard fits into
 477          * that position.  Wildcards can only be valid up one level, so
 478          * foo.* cannot match foo.bar.baz, but will match foo.bar.  This method
< prev index next >