jdk/src/share/classes/sun/awt/DebugSettings.java
author mchung
Tue, 29 Sep 2009 16:03:03 -0700
changeset 3938 ef327bd847c0
parent 2 90ce3da70b43
child 4214 0fa32d38146b
permissions -rw-r--r--
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes Summary: Replace calls to Logger with sun.util.logging.PlatformLogger Reviewed-by: prr, art, alexp, dcherepanov, igor, dav, anthony
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1999-2003 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.awt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.*;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2
diff changeset
    31
import sun.util.logging.PlatformLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * Internal class that manages sun.awt.Debug settings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * Settings can be specified on a global, per-package,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * or per-class level.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * Properties affecting the behaviour of the Debug class are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * loaded from the awtdebug.properties file at class load
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * time. The properties file is assumed to be in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * user.home directory. A different file can be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * by setting the awtdebug.properties system property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *      e.g. java -Dawtdebug.properties=foo.properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * Only properties beginning with 'awtdebug' have any
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * meaning-- all other properties are ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * You can override the properties file by specifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * 'awtdebug' props as system properties on the command line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *      e.g. java -Dawtdebug.trace=true
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * Properties specific to a package or a class can be set
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * by qualifying the property names as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *      awtdebug.<property name>.<class or package name>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * So for example, turning on tracing in the com.acme.Fubar
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * class would be done as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *      awtdebug.trace.com.acme.Fubar=true
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * Class settings always override package settings, which in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * turn override global settings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * Addition from July, 2007.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * After the fix for 4638447 all the usage of DebugHelper
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * classes in Java code are replaced with the corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * Java Logging API calls. This file is now used only to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * control native logging.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * To enable native logging you should set the following
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * system property to 'true': sun.awt.nativedebug. After
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * the native logging is enabled, the actual debug settings
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * are read the same way as described above (as before
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * the fix for 4638447).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
final class DebugSettings {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2
diff changeset
    75
    private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.debug.DebugSettings");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /* standard debug property key names */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    static final String PREFIX = "awtdebug";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    static final String PROP_FILE = "properties";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    /* default property settings */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    private static final String DEFAULT_PROPS[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        "awtdebug.assert=true",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        "awtdebug.trace=false",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        "awtdebug.on=true",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        "awtdebug.ctrace=false"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /* global instance of the settings object */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private static DebugSettings        instance = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    private Properties  props = new Properties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    static void init() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        if (instance != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        NativeLibLoader.loadLibraries();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        instance = new DebugSettings();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        instance.loadNativeSettings();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    private DebugSettings() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        new java.security.PrivilegedAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            public Object run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                loadProperties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        }.run();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * Load debug properties from file, then override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * with any command line specified properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    private synchronized void loadProperties() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        // setup initial properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            new java.security.PrivilegedAction()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            public Object run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                loadDefaultProperties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                loadFileProperties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                loadSystemProperties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        // echo the initial property settings to stdout
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2
diff changeset
   131
        if (log.isLoggable(PlatformLogger.FINE)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2
diff changeset
   132
            log.fine("DebugSettings:\n{0}" + this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        Enumeration enum_ = props.propertyNames();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        PrintStream pout = new PrintStream(bout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        while (enum_.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            String key = (String)enum_.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            String value = props.getProperty(key, "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            pout.println(key + " = " + value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        return new String(bout.toByteArray());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * Sets up default property values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    private void loadDefaultProperties() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        // is there a more inefficient way to setup default properties?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        // maybe, but this has got to be close to 100% non-optimal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            for ( int nprop = 0; nprop < DEFAULT_PROPS.length; nprop++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                StringBufferInputStream in = new StringBufferInputStream(DEFAULT_PROPS[nprop]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                props.load(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                in.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        } catch(IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * load properties from file, overriding defaults
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    private void loadFileProperties() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        String          propPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        Properties      fileProps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        // check if the user specified a particular settings file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        propPath = System.getProperty(PREFIX + "." + PROP_FILE, "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        if (propPath.equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        // otherwise get it from the user's home directory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            propPath = System.getProperty("user.home", "") +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                        File.separator +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                        PREFIX + "." + PROP_FILE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        File    propFile = new File(propPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            println("Reading debug settings from '" + propFile.getCanonicalPath() + "'...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            FileInputStream     fin = new FileInputStream(propFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            props.load(fin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            fin.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        } catch ( FileNotFoundException fne ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            println("Did not find settings file.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        } catch ( IOException ioe ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            println("Problem reading settings, IOException: " + ioe.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * load properties from system props (command line spec'd usually),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * overriding default or file properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    private void loadSystemProperties() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        // override file properties with system properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        Properties sysProps = System.getProperties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        Enumeration enum_ = sysProps.propertyNames();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        while ( enum_.hasMoreElements() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            String key = (String)enum_.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            String value = sysProps.getProperty(key,"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            // copy any "awtdebug" properties over
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            if ( key.startsWith(PREFIX) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                props.setProperty(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * Gets named boolean property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * @param key       Name of property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @param defval    Default value if property does not exist
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * @return boolean value of the named property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    public synchronized boolean getBoolean(String key, boolean defval) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        String  value = getString(key, String.valueOf(defval));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        return value.equalsIgnoreCase("true");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * Gets named integer property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @param key       Name of property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @param defval    Default value if property does not exist
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * @return integer value of the named property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    public synchronized int getInt(String key, int defval) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        String  value = getString(key, String.valueOf(defval));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        return Integer.parseInt(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * Gets named String property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * @param key       Name of property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * @param defval    Default value if property does not exist
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * @return string value of the named property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    public synchronized String getString(String key, String defval) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        String  actualKeyName = PREFIX + "." + key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        String  value = props.getProperty(actualKeyName, defval);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        //println(actualKeyName+"="+value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    public synchronized Enumeration getPropertyNames() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        Vector          propNames = new Vector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        Enumeration     enum_ = props.propertyNames();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        // remove global prefix from property names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        while ( enum_.hasMoreElements() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            String propName = (String)enum_.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            propName = propName.substring(PREFIX.length()+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            propNames.addElement(propName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        return propNames.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    private void println(Object object) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2
diff changeset
   261
        if (log.isLoggable(PlatformLogger.FINER)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2
diff changeset
   262
            log.finer(object.toString());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    private static final String PROP_CTRACE = "ctrace";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    private static final int PROP_CTRACE_LEN = PROP_CTRACE.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    private native synchronized void setCTracingOn(boolean enabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    private native synchronized void setCTracingOn(boolean enabled, String file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    private native synchronized void setCTracingOn(boolean enabled, String file, int line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    private void loadNativeSettings() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        boolean        ctracingOn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        ctracingOn = getBoolean(PROP_CTRACE, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        setCTracingOn(ctracingOn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        // Filter out file/line ctrace properties from debug settings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        Vector                traces = new Vector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        Enumeration         enum_ = getPropertyNames();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        while ( enum_.hasMoreElements() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            String key = (String)enum_.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            if ( key.startsWith(PROP_CTRACE) && key.length() > PROP_CTRACE_LEN ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                traces.addElement(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        // sort traces list so file-level traces will be before line-level ones
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        Collections.sort(traces);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        // Setup the trace points
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        Enumeration        enumTraces = traces.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        while ( enumTraces.hasMoreElements() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            String        key = (String)enumTraces.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            String         trace = key.substring(PROP_CTRACE_LEN+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            String        filespec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            String        linespec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            int                delim= trace.indexOf('@');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            boolean        enabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            // parse out the filename and linenumber from the property name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            filespec = delim != -1 ? trace.substring(0, delim) : trace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            linespec = delim != -1 ? trace.substring(delim+1) : "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            enabled = getBoolean(key, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            //System.out.println("Key="+key+", File="+filespec+", Line="+linespec+", Enabled="+enabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            if ( linespec.length() == 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            // set file specific trace setting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                    setCTracingOn(enabled, filespec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            // set line specific trace setting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                int        linenum = Integer.parseInt(linespec, 10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                setCTracingOn(enabled, filespec, linenum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
}