Path: blob/master/src/java.base/share/classes/sun/util/locale/provider/HostLocaleProviderAdapter.java
41161 views
/*1* Copyright (c) 2012, 2020, 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. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.util.locale.provider;2627import java.lang.reflect.InvocationTargetException;28import java.text.DecimalFormat;29import java.util.ServiceConfigurationError;30import java.util.spi.LocaleServiceProvider;3132/**33* LocaleProviderAdapter implementation for the host locale data.34* Currently it is only implemented on Windows Vista or later.35*36* @author Naoto Sato37*/38public class HostLocaleProviderAdapter extends AuxLocaleProviderAdapter {3940/**41* Returns the type of this LocaleProviderAdapter42*/43@Override44public LocaleProviderAdapter.Type getAdapterType() {45return LocaleProviderAdapter.Type.HOST;46}4748@Override49@SuppressWarnings("unchecked")50protected <P extends LocaleServiceProvider> P findInstalledProvider(final Class<P> c) {51try {52return (P)Class.forName(53"sun.util.locale.provider.HostLocaleProviderAdapterImpl")54.getMethod("get" + c.getSimpleName(), (Class<?>[]) null)55.invoke(null, (Object[]) null);56} catch (ClassNotFoundException |57NoSuchMethodException ex) {58// permissible exceptions as platform may not support host adapter59return null;60} catch (IllegalAccessException |61IllegalArgumentException |62InvocationTargetException ex) {63throw new ServiceConfigurationError(64"Host locale provider cannot be located.", ex);65}66}6768/**69* Utility to make the decimal format specific to integer, called70* by the platform dependent adapter implementations.71*72* @param df A DecimalFormat object73* @return The same DecimalFormat object in the argument, modified74* to allow integer formatting/parsing only.75*/76static DecimalFormat makeIntegerFormatter(DecimalFormat df) {77df.setMaximumFractionDigits(0);78df.setDecimalSeparatorAlwaysShown(false);79df.setParseIntegerOnly(true);80return df;81}82}838485