jdk/src/jdk.compiler/share/classes/sun/tools/serialver/SerialVer.java
author psadhukhan
Tue, 13 Sep 2016 13:40:32 +0530
changeset 41012 c4e843656a4d
parent 36511 9d0388c6b336
permissions -rw-r--r--
7064425: PageFormat Dialog has no owner window to reactivate 6948907: sun.print.DialogOwner does not support Dialogs as DialogOwner Reviewed-by: prr, jdv
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
29485
5a4c74eeaeab 8075160: Add javadoc to serialver class
darcy
parents: 25859
diff changeset
     2
 * Copyright (c) 1996, 2015, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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.tools.serialver;
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
import java.io.ObjectStreamClass;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 29485
diff changeset
    30
import java.nio.file.Paths;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.text.MessageFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.ResourceBundle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.MissingResourceException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.net.URLClassLoader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.net.MalformedURLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
29485
5a4c74eeaeab 8075160: Add javadoc to serialver class
darcy
parents: 25859
diff changeset
    38
/**
5a4c74eeaeab 8075160: Add javadoc to serialver class
darcy
parents: 25859
diff changeset
    39
 * Supporting class for the serialver tool.
5a4c74eeaeab 8075160: Add javadoc to serialver class
darcy
parents: 25859
diff changeset
    40
 */
24510
a96915fc059d 8042887: Remove serialver -show, this tool does not need a GUI
alanb
parents: 23010
diff changeset
    41
public class SerialVer {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
     * A class loader that will load from the CLASSPATH environment
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     * variable set by the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    static URLClassLoader loader = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * Create a URL class loader that will load classes from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * specified classpath.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     */
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 29485
diff changeset
    53
    static void initializeLoader(String cp) throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 29485
diff changeset
    54
        String[] paths = cp.split(File.pathSeparator);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 29485
diff changeset
    55
        int count = paths.length;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 29485
diff changeset
    56
        URL[] urls = new URL[count];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        for (int i = 0; i < count; i++) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 29485
diff changeset
    58
            urls[i] = Paths.get(paths[i]).toUri().toURL();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        loader = new URLClassLoader(urls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * From the classname find the serialVersionUID string formatted
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * for to be copied to a java class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    static String serialSyntax(String classname) throws ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        String ret = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        boolean classFound = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        // If using old style of qualifyling inner classes with '$'s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        if (classname.indexOf('$') != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            ret = resolveClass(classname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            /* Try to resolve the fully qualified name and if that fails, start
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
             * replacing the '.'s with '$'s starting from the last '.', until
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
             * the class is resolved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                ret = resolveClass(classname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                classFound = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            } catch (ClassNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                /* Class not found so far */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            if (!classFound) {
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 24510
diff changeset
    86
                StringBuilder workBuffer = new StringBuilder(classname);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                String workName = workBuffer.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                while ((i = workName.lastIndexOf('.')) != -1 && !classFound) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                    workBuffer.setCharAt(i, '$');
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                        workName = workBuffer.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                        ret = resolveClass(workName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                        classFound = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                    } catch (ClassNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                        /* Continue searching */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            if (!classFound) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                throw new ClassNotFoundException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    static String resolveClass(String classname) throws ClassNotFoundException {
11125
99b115114fa3 7117357: Warnings in sun.instrument, tools and other sun.* classes
alanb
parents: 5506
diff changeset
   108
        Class<?> cl = Class.forName(classname, false, loader);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        ObjectStreamClass desc = ObjectStreamClass.lookup(cl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        if (desc != null) {
21651
07756e24916a 8028027: serialver should emit declaration with the 'private' modifier
smarks
parents: 14342
diff changeset
   111
            return "    private static final long serialVersionUID = " +
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                desc.getSerialVersionUID() + "L;";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
29485
5a4c74eeaeab 8075160: Add javadoc to serialver class
darcy
parents: 25859
diff changeset
   118
    /**
5a4c74eeaeab 8075160: Add javadoc to serialver class
darcy
parents: 25859
diff changeset
   119
     * Entry point for serialver tool.
5a4c74eeaeab 8075160: Add javadoc to serialver class
darcy
parents: 25859
diff changeset
   120
     * @param args the arguments
5a4c74eeaeab 8075160: Add javadoc to serialver class
darcy
parents: 25859
diff changeset
   121
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        String envcp = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        if (args.length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            usage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        for (i = 0; i < args.length; i++) {
24510
a96915fc059d 8042887: Remove serialver -show, this tool does not need a GUI
alanb
parents: 23010
diff changeset
   132
            if (args[i].equals("-classpath")) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                if ((i+1 == args.length) || args[i+1].startsWith("-")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                    System.err.println(Res.getText("error.missing.classpath"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                    usage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                    System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                envcp = new String(args[i+1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            }  else if (args[i].startsWith("-")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                System.err.println(Res.getText("invalid.flag", args[i]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                usage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                break;          // drop into processing class names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            }
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
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
         * Get user's CLASSPATH environment variable, if the -classpath option
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
         * is not defined, and make a loader that can read from that path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        if (envcp == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            envcp = System.getProperty("env.class.path");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
             * If environment variable not set, add current directory to path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            if (envcp == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                envcp = ".";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            initializeLoader(envcp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        } catch (MalformedURLException mue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            System.err.println(Res.getText("error.parsing.classpath", envcp));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            System.exit(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            System.err.println(Res.getText("error.parsing.classpath", envcp));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            System.exit(3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
24510
a96915fc059d 8042887: Remove serialver -show, this tool does not need a GUI
alanb
parents: 23010
diff changeset
   174
        /*
a96915fc059d 8042887: Remove serialver -show, this tool does not need a GUI
alanb
parents: 23010
diff changeset
   175
         * Check if there are any class names specified
a96915fc059d 8042887: Remove serialver -show, this tool does not need a GUI
alanb
parents: 23010
diff changeset
   176
         */
a96915fc059d 8042887: Remove serialver -show, this tool does not need a GUI
alanb
parents: 23010
diff changeset
   177
        if (i == args.length) {
a96915fc059d 8042887: Remove serialver -show, this tool does not need a GUI
alanb
parents: 23010
diff changeset
   178
            usage();
a96915fc059d 8042887: Remove serialver -show, this tool does not need a GUI
alanb
parents: 23010
diff changeset
   179
            System.exit(1);
a96915fc059d 8042887: Remove serialver -show, this tool does not need a GUI
alanb
parents: 23010
diff changeset
   180
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
24510
a96915fc059d 8042887: Remove serialver -show, this tool does not need a GUI
alanb
parents: 23010
diff changeset
   182
        /*
a96915fc059d 8042887: Remove serialver -show, this tool does not need a GUI
alanb
parents: 23010
diff changeset
   183
         * The rest of the parameters are classnames.
a96915fc059d 8042887: Remove serialver -show, this tool does not need a GUI
alanb
parents: 23010
diff changeset
   184
         */
a96915fc059d 8042887: Remove serialver -show, this tool does not need a GUI
alanb
parents: 23010
diff changeset
   185
        boolean exitFlag = false;
a96915fc059d 8042887: Remove serialver -show, this tool does not need a GUI
alanb
parents: 23010
diff changeset
   186
        for (i = i; i < args.length; i++ ) {
a96915fc059d 8042887: Remove serialver -show, this tool does not need a GUI
alanb
parents: 23010
diff changeset
   187
            try {
a96915fc059d 8042887: Remove serialver -show, this tool does not need a GUI
alanb
parents: 23010
diff changeset
   188
                String syntax = serialSyntax(args[i]);
a96915fc059d 8042887: Remove serialver -show, this tool does not need a GUI
alanb
parents: 23010
diff changeset
   189
                if (syntax != null)
a96915fc059d 8042887: Remove serialver -show, this tool does not need a GUI
alanb
parents: 23010
diff changeset
   190
                    System.out.println(args[i] + ":" + syntax);
a96915fc059d 8042887: Remove serialver -show, this tool does not need a GUI
alanb
parents: 23010
diff changeset
   191
                else {
a96915fc059d 8042887: Remove serialver -show, this tool does not need a GUI
alanb
parents: 23010
diff changeset
   192
                    System.err.println(Res.getText("NotSerializable",
a96915fc059d 8042887: Remove serialver -show, this tool does not need a GUI
alanb
parents: 23010
diff changeset
   193
                        args[i]));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                    exitFlag = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                }
24510
a96915fc059d 8042887: Remove serialver -show, this tool does not need a GUI
alanb
parents: 23010
diff changeset
   196
            } catch (ClassNotFoundException cnf) {
a96915fc059d 8042887: Remove serialver -show, this tool does not need a GUI
alanb
parents: 23010
diff changeset
   197
                System.err.println(Res.getText("ClassNotFound", args[i]));
a96915fc059d 8042887: Remove serialver -show, this tool does not need a GUI
alanb
parents: 23010
diff changeset
   198
                exitFlag = true;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            }
24510
a96915fc059d 8042887: Remove serialver -show, this tool does not need a GUI
alanb
parents: 23010
diff changeset
   200
        }
a96915fc059d 8042887: Remove serialver -show, this tool does not need a GUI
alanb
parents: 23010
diff changeset
   201
        if (exitFlag) {
a96915fc059d 8042887: Remove serialver -show, this tool does not need a GUI
alanb
parents: 23010
diff changeset
   202
            System.exit(1);
2
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
     * Usage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    public static void usage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        System.err.println(Res.getText("usage"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
 * Utility for integrating with serialver and for localization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
 * Handle Resources. Access to error and warning counts.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
 * Message formatting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
 * @see java.util.ResourceBundle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
 * @see java.text.MessageFormat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
class Res {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    private static ResourceBundle messageRB;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * Initialize ResourceBundle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    static void initResource() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            messageRB =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                ResourceBundle.getBundle("sun.tools.serialver.resources.serialver");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        } catch (MissingResourceException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            throw new Error("Fatal: Resource for serialver is missing");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * get and format message string from resource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @param key selects message from resource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    static String getText(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        return getText(key, (String)null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * get and format message string from resource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * @param key selects message from resource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * @param a1 first argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    static String getText(String key, String a1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        return getText(key, a1, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * get and format message string from resource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * @param key selects message from resource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * @param a1 first argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * @param a2 second argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    static String getText(String key, String a1, String a2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        return getText(key, a1, a2, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * get and format message string from resource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * @param key selects message from resource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * @param a1 first argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @param a2 second argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * @param a3 third argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    static String getText(String key, String a1, String a2, String a3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        if (messageRB == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            initResource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            String message = messageRB.getString(key);
11125
99b115114fa3 7117357: Warnings in sun.instrument, tools and other sun.* classes
alanb
parents: 5506
diff changeset
   284
            return MessageFormat.format(message, a1, a2, a3);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        } catch (MissingResourceException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            throw new Error("Fatal: Resource for serialver is broken. There is no " + key + " key in resource.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
}