1/*
2 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package sun.rmi.rmic.newrmic;
27
28import java.text.MessageFormat;
29import java.util.MissingResourceException;
30import java.util.ResourceBundle;
31
32/**
33 * Provides resource support for rmic.
34 *
35 * WARNING: The contents of this source file are not part of any
36 * supported API.  Code that depends on them does so at its own risk:
37 * they are subject to change or removal without notice.
38 *
39 * @author Peter Jones
40 **/
41public final class Resources {
42
43    private static ResourceBundle resources = null;
44    private static ResourceBundle resourcesExt = null;
45    static {
46        try {
47            resources =
48                ResourceBundle.getBundle("sun.rmi.rmic.resources.rmic");
49        } catch (MissingResourceException e) {
50            // gracefully handle this later
51        }
52        try {
53            resourcesExt =
54                ResourceBundle.getBundle("sun.rmi.rmic.resources.rmicext");
55        } catch (MissingResourceException e) {
56            // OK if this isn't found
57        }
58    }
59
60    private Resources() { throw new AssertionError(); }
61
62    /**
63     * Returns the text of the rmic resource for the specified key
64     * formatted with the specified arguments.
65     **/
66    public static String getText(String key, String... args) {
67        String format = getString(key);
68        if (format == null) {
69            format = "missing resource key: key = \"" + key + "\", " +
70                "arguments = \"{0}\", \"{1}\", \"{2}\"";
71        }
72        return MessageFormat.format(format, (Object[]) args);
73    }
74
75    /**
76     * Returns the rmic resource string for the specified key.
77     **/
78    private static String getString(String key) {
79        if (resourcesExt != null) {
80            try {
81                return resourcesExt.getString(key);
82            } catch (MissingResourceException e) {
83            }
84        }
85        if (resources != null) {
86            try {
87                return resources.getString(key);
88            } catch (MissingResourceException e) {
89                return null;
90            }
91        }
92        return "missing resource bundle: key = \"" + key + "\", " +
93            "arguments = \"{0}\", \"{1}\", \"{2}\"";
94    }
95}
96