Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/util/PluggableLocale/providersrc/LocaleNameProviderImpl.java
47311 views
/*1* Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22/*23*24*/2526package com.bar;2728import java.text.*;29import java.util.*;30import java.util.spi.*;3132import com.foobar.Utils;3334public class LocaleNameProviderImpl extends LocaleNameProvider {35static Locale[] avail = {Locale.JAPANESE,36Locale.JAPAN,37new Locale("ja", "JP", "osaka"),38new Locale("ja", "JP", "kyoto"),39new Locale("xx"),40new Locale("yy", "YY", "YYYY")};41static List<Locale> availList = Arrays.asList(avail);42public Locale[] getAvailableLocales() {43return avail;44}4546@Override47public String getDisplayLanguage(String lang, Locale target) {48return getDisplayString(lang, target);49}5051@Override52public String getDisplayCountry(String ctry, Locale target) {53return getDisplayString(ctry, target);54}5556@Override57public String getDisplayVariant(String vrnt, Locale target) {58return getDisplayString(vrnt, target);59}6061private String getDisplayString(String key, Locale target) {62if (!Utils.supportsLocale(availList, target)) {63throw new IllegalArgumentException("locale is not supported: "+target);64}6566String ret = null;6768if (target.getLanguage().equals("yy") &&69target.getCountry().equals("YY")) {70String vrnt = target.getVariant();71if (vrnt.startsWith("YYYY")) {72switch (key) {73case "yy":74case "YY":75ret = "waiwai";76break;7778case "YYYY":79if (vrnt.equals("YYYY_suffix")) {80// for LocaleNameProviderTest.variantFallbackTest()81throw new RuntimeException(vrnt);82} else {83ret = "waiwai";84}85break;86}87}88} else {89// resource bundle based (allows fallback)90try {91ResourceBundle rb = ResourceBundle.getBundle("com.bar.LocaleNames", target);92ret = rb.getString(key);93} catch (MissingResourceException mre) {94}95}9697return ret;98}99}100101102