jdk/src/share/classes/sun/awt/DebugSettings.java
author leonidr
Wed, 29 Aug 2012 19:53:35 +0400
changeset 13648 90effcfc064f
parent 11264 54f2f4c6bd30
child 16839 d0f2e97b7359
permissions -rw-r--r--
7124375: [macosx] Focus isn't transfered as expected between components Reviewed-by: art, ant, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4214
diff changeset
     2
 * Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved.
2
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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4214
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4214
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4214
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4214
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4214
diff changeset
    23
 * questions.
2
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 */
11264
54f2f4c6bd30 7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents: 5506
diff changeset
    90
    private static DebugSettings instance = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
11264
54f2f4c6bd30 7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents: 5506
diff changeset
    92
    private Properties props = new Properties();
2
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() {
11264
54f2f4c6bd30 7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents: 5506
diff changeset
   105
        java.security.AccessController.doPrivileged(
54f2f4c6bd30 7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents: 5506
diff changeset
   106
            new java.security.PrivilegedAction<Void>() {
54f2f4c6bd30 7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents: 5506
diff changeset
   107
                public Void run() {
54f2f4c6bd30 7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents: 5506
diff changeset
   108
                    loadProperties();
54f2f4c6bd30 7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents: 5506
diff changeset
   109
                    return null;
54f2f4c6bd30 7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents: 5506
diff changeset
   110
                }
54f2f4c6bd30 7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents: 5506
diff changeset
   111
            });
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * Load debug properties from file, then override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * with any command line specified properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    private synchronized void loadProperties() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        // setup initial properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        java.security.AccessController.doPrivileged(
11264
54f2f4c6bd30 7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents: 5506
diff changeset
   121
            new java.security.PrivilegedAction<Void>() {
54f2f4c6bd30 7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents: 5506
diff changeset
   122
                public Void run() {
54f2f4c6bd30 7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents: 5506
diff changeset
   123
                    loadDefaultProperties();
54f2f4c6bd30 7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents: 5506
diff changeset
   124
                    loadFileProperties();
54f2f4c6bd30 7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents: 5506
diff changeset
   125
                    loadSystemProperties();
54f2f4c6bd30 7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents: 5506
diff changeset
   126
                    return null;
54f2f4c6bd30 7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents: 5506
diff changeset
   127
                }
54f2f4c6bd30 7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents: 5506
diff changeset
   128
            });
2
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
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        PrintStream pout = new PrintStream(bout);
11264
54f2f4c6bd30 7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents: 5506
diff changeset
   139
        for (String key : props.stringPropertyNames()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            String value = props.getProperty(key, "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            pout.println(key + " = " + value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        return new String(bout.toByteArray());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * Sets up default property values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    private void loadDefaultProperties() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        // is there a more inefficient way to setup default properties?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        // maybe, but this has got to be close to 100% non-optimal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            for ( int nprop = 0; nprop < DEFAULT_PROPS.length; nprop++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                StringBufferInputStream in = new StringBufferInputStream(DEFAULT_PROPS[nprop]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                props.load(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                in.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        } catch(IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * load properties from file, overriding defaults
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    private void loadFileProperties() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        String          propPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        Properties      fileProps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        // check if the user specified a particular settings file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        propPath = System.getProperty(PREFIX + "." + PROP_FILE, "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        if (propPath.equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        // otherwise get it from the user's home directory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            propPath = System.getProperty("user.home", "") +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                        File.separator +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                        PREFIX + "." + PROP_FILE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        File    propFile = new File(propPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            println("Reading debug settings from '" + propFile.getCanonicalPath() + "'...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            FileInputStream     fin = new FileInputStream(propFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            props.load(fin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            fin.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        } catch ( FileNotFoundException fne ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            println("Did not find settings file.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        } catch ( IOException ioe ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            println("Problem reading settings, IOException: " + ioe.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * load properties from system props (command line spec'd usually),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * overriding default or file properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    private void loadSystemProperties() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        // override file properties with system properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        Properties sysProps = System.getProperties();
11264
54f2f4c6bd30 7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents: 5506
diff changeset
   198
        for (String key : sysProps.stringPropertyNames()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            String value = sysProps.getProperty(key,"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            // copy any "awtdebug" properties over
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            if ( key.startsWith(PREFIX) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                props.setProperty(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * Gets named boolean property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * @param key       Name of property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * @param defval    Default value if property does not exist
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * @return boolean value of the named property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    public synchronized boolean getBoolean(String key, boolean defval) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        String  value = getString(key, String.valueOf(defval));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        return value.equalsIgnoreCase("true");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * Gets named integer property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @param key       Name of property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @param defval    Default value if property does not exist
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * @return integer value of the named property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    public synchronized int getInt(String key, int defval) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        String  value = getString(key, String.valueOf(defval));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        return Integer.parseInt(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * Gets named String property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * @param key       Name of property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @param defval    Default value if property does not exist
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @return string value of the named property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    public synchronized String getString(String key, String defval) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        String  actualKeyName = PREFIX + "." + key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        String  value = props.getProperty(actualKeyName, defval);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        //println(actualKeyName+"="+value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
11264
54f2f4c6bd30 7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents: 5506
diff changeset
   242
    private synchronized List<String> getPropertyNames() {
54f2f4c6bd30 7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents: 5506
diff changeset
   243
        List<String> propNames = new LinkedList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        // remove global prefix from property names
11264
54f2f4c6bd30 7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents: 5506
diff changeset
   245
        for (String propName : props.stringPropertyNames()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            propName = propName.substring(PREFIX.length()+1);
11264
54f2f4c6bd30 7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents: 5506
diff changeset
   247
            propNames.add(propName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        }
11264
54f2f4c6bd30 7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents: 5506
diff changeset
   249
        return propNames;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    private void println(Object object) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2
diff changeset
   253
        if (log.isLoggable(PlatformLogger.FINER)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2
diff changeset
   254
            log.finer(object.toString());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    private static final String PROP_CTRACE = "ctrace";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    private static final int PROP_CTRACE_LEN = PROP_CTRACE.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    private native synchronized void setCTracingOn(boolean enabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    private native synchronized void setCTracingOn(boolean enabled, String file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    private native synchronized void setCTracingOn(boolean enabled, String file, int line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    private void loadNativeSettings() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        boolean        ctracingOn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        ctracingOn = getBoolean(PROP_CTRACE, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        setCTracingOn(ctracingOn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        // Filter out file/line ctrace properties from debug settings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        //
11264
54f2f4c6bd30 7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents: 5506
diff changeset
   274
        List<String> traces = new LinkedList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
11264
54f2f4c6bd30 7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents: 5506
diff changeset
   276
        for (String key : getPropertyNames()) {
54f2f4c6bd30 7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents: 5506
diff changeset
   277
            if (key.startsWith(PROP_CTRACE) && key.length() > PROP_CTRACE_LEN) {
54f2f4c6bd30 7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents: 5506
diff changeset
   278
                traces.add(key);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        // sort traces list so file-level traces will be before line-level ones
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        Collections.sort(traces);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        // Setup the trace points
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        //
11264
54f2f4c6bd30 7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents: 5506
diff changeset
   288
        for (String key : traces) {
54f2f4c6bd30 7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents: 5506
diff changeset
   289
            String        trace = key.substring(PROP_CTRACE_LEN+1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            String        filespec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            String        linespec;
11264
54f2f4c6bd30 7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents: 5506
diff changeset
   292
            int           delim= trace.indexOf('@');
54f2f4c6bd30 7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents: 5506
diff changeset
   293
            boolean       enabled;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            // parse out the filename and linenumber from the property name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            filespec = delim != -1 ? trace.substring(0, delim) : trace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            linespec = delim != -1 ? trace.substring(delim+1) : "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            enabled = getBoolean(key, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            //System.out.println("Key="+key+", File="+filespec+", Line="+linespec+", Enabled="+enabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            if ( linespec.length() == 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            // set file specific trace setting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                    setCTracingOn(enabled, filespec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            // set line specific trace setting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                int        linenum = Integer.parseInt(linespec, 10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                setCTracingOn(enabled, filespec, linenum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
}