src/share/jaxws_classes/com/sun/xml/internal/fastinfoset/AbstractResourceBundle.java

Thu, 12 Oct 2017 19:44:07 +0800

author
aoqi
date
Thu, 12 Oct 2017 19:44:07 +0800
changeset 760
e530533619ec
parent 0
373ffda63c9a
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 *
aoqi@0 25 * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
aoqi@0 26 */
aoqi@0 27
aoqi@0 28 /*
aoqi@0 29 *
aoqi@0 30 * This code is subject to the freebxml License, Version 1.1
aoqi@0 31 *
aoqi@0 32 * Copyright (c) 2001 - 2005 freebxml.org. All rights reserved.
aoqi@0 33 *
aoqi@0 34 * $Header: /zpool01/javanet/scm/svn/tmp/cvs2svn/fi/FastInfoset/src/com/sun/xml/internal/fastinfoset/AbstractResourceBundle.java,v 1.3.2.4 2009-05-13 08:53:01 oleksiys Exp $
aoqi@0 35 */
aoqi@0 36 package com.sun.xml.internal.fastinfoset;
aoqi@0 37
aoqi@0 38 import java.text.MessageFormat;
aoqi@0 39 import java.util.Enumeration;
aoqi@0 40 import java.util.Locale;
aoqi@0 41 import java.util.ResourceBundle;
aoqi@0 42
aoqi@0 43
aoqi@0 44 /**
aoqi@0 45 * This class contains methods common to all *ResourceBundle classes
aoqi@0 46 *
aoqi@0 47 * @author FastInfoset team
aoqi@0 48 */
aoqi@0 49 public abstract class AbstractResourceBundle extends ResourceBundle {
aoqi@0 50
aoqi@0 51 public static final String LOCALE = "com.sun.xml.internal.fastinfoset.locale";
aoqi@0 52
aoqi@0 53 /**
aoqi@0 54 * Gets 'key' from ResourceBundle and format mesage using 'args'.
aoqi@0 55 *
aoqi@0 56 * @param key String key for message.
aoqi@0 57 * @param args Array of arguments for message.
aoqi@0 58 * @return String formatted message.
aoqi@0 59 */
aoqi@0 60 public String getString(String key, Object args[]) {
aoqi@0 61 String pattern = getBundle().getString(key);
aoqi@0 62 return MessageFormat.format(pattern, args);
aoqi@0 63 }
aoqi@0 64
aoqi@0 65 /**
aoqi@0 66 * Parse a locale string, return corresponding Locale instance.
aoqi@0 67 *
aoqi@0 68 * @param localeString
aoqi@0 69 * Name for the locale of interest. If null, use VM default locale.
aoqi@0 70 * @return New Locale instance.
aoqi@0 71 */
aoqi@0 72 public static Locale parseLocale(String localeString) {
aoqi@0 73 Locale locale = null;
aoqi@0 74 if (localeString == null) {
aoqi@0 75 locale = Locale.getDefault();
aoqi@0 76 } else {
aoqi@0 77 try {
aoqi@0 78 String[] args = localeString.split("_");
aoqi@0 79 if (args.length == 1) {
aoqi@0 80 locale = new Locale(args[0]);
aoqi@0 81 } else if (args.length == 2) {
aoqi@0 82 locale = new Locale(args[0], args[1]);
aoqi@0 83 } else if (args.length == 3) {
aoqi@0 84 locale = new Locale(args[0], args[1], args[2]);
aoqi@0 85 }
aoqi@0 86 } catch (Throwable t) {
aoqi@0 87 locale = Locale.getDefault();
aoqi@0 88 }
aoqi@0 89 }
aoqi@0 90 return locale;
aoqi@0 91 }
aoqi@0 92
aoqi@0 93 /**
aoqi@0 94 * Subclasses of this class must implement this method so that the
aoqi@0 95 * correct resource bundle is passed to methods in this class
aoqi@0 96 *
aoqi@0 97 * @return
aoqi@0 98 * A java.util.ResourceBundle from the subsclass. Methods in this class
aoqi@0 99 * will use this reference.
aoqi@0 100 */
aoqi@0 101 public abstract ResourceBundle getBundle();
aoqi@0 102
aoqi@0 103
aoqi@0 104 /**
aoqi@0 105 * Since we are changing the ResourceBundle extension point, must
aoqi@0 106 * implement handleGetObject() using delegate getBundle(). Uses
aoqi@0 107 * getObject() call to work around protected access to
aoqi@0 108 * ResourceBundle.handleGetObject(). Happily, this means parent tree
aoqi@0 109 * of delegate bundle is searched for a match.
aoqi@0 110 *
aoqi@0 111 * Implements java.util.ResourceBundle.handleGetObject; inherits that
aoqi@0 112 * javadoc information.
aoqi@0 113 *
aoqi@0 114 * @see java.util.ResourceBundle#handleGetObject(String)
aoqi@0 115 */
aoqi@0 116 protected Object handleGetObject(String key) {
aoqi@0 117 return getBundle().getObject(key);
aoqi@0 118 }
aoqi@0 119
aoqi@0 120 /**
aoqi@0 121 * Since we are changing the ResourceBundle extension point, must
aoqi@0 122 * implement getKeys() using delegate getBundle().
aoqi@0 123 *
aoqi@0 124 * Implements java.util.ResourceBundle.getKeys; inherits that javadoc
aoqi@0 125 * information.
aoqi@0 126 *
aoqi@0 127 * @see java.util.ResourceBundle#getKeys()
aoqi@0 128 */
aoqi@0 129 public final Enumeration getKeys() {
aoqi@0 130 return getBundle().getKeys();
aoqi@0 131 }
aoqi@0 132 }

mercurial