1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/fastinfoset/AbstractResourceBundle.java Tue Mar 06 16:09:35 2012 -0800 1.3 @@ -0,0 +1,132 @@ 1.4 +/* 1.5 + * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + * 1.28 + * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC. 1.29 + */ 1.30 + 1.31 +/* 1.32 + * 1.33 + * This code is subject to the freebxml License, Version 1.1 1.34 + * 1.35 + * Copyright (c) 2001 - 2005 freebxml.org. All rights reserved. 1.36 + * 1.37 + * $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 $ 1.38 + */ 1.39 +package com.sun.xml.internal.fastinfoset; 1.40 + 1.41 +import java.text.MessageFormat; 1.42 +import java.util.Enumeration; 1.43 +import java.util.Locale; 1.44 +import java.util.ResourceBundle; 1.45 + 1.46 + 1.47 +/** 1.48 + * This class contains methods common to all *ResourceBundle classes 1.49 + * 1.50 + * @author FastInfoset team 1.51 + */ 1.52 +public abstract class AbstractResourceBundle extends ResourceBundle { 1.53 + 1.54 + public static final String LOCALE = "com.sun.xml.internal.fastinfoset.locale"; 1.55 + 1.56 + /** 1.57 + * Gets 'key' from ResourceBundle and format mesage using 'args'. 1.58 + * 1.59 + * @param key String key for message. 1.60 + * @param args Array of arguments for message. 1.61 + * @return String formatted message. 1.62 + */ 1.63 + public String getString(String key, Object args[]) { 1.64 + String pattern = getBundle().getString(key); 1.65 + return MessageFormat.format(pattern, args); 1.66 + } 1.67 + 1.68 + /** 1.69 + * Parse a locale string, return corresponding Locale instance. 1.70 + * 1.71 + * @param localeString 1.72 + * Name for the locale of interest. If null, use VM default locale. 1.73 + * @return New Locale instance. 1.74 + */ 1.75 + public static Locale parseLocale(String localeString) { 1.76 + Locale locale = null; 1.77 + if (localeString == null) { 1.78 + locale = Locale.getDefault(); 1.79 + } else { 1.80 + try { 1.81 + String[] args = localeString.split("_"); 1.82 + if (args.length == 1) { 1.83 + locale = new Locale(args[0]); 1.84 + } else if (args.length == 2) { 1.85 + locale = new Locale(args[0], args[1]); 1.86 + } else if (args.length == 3) { 1.87 + locale = new Locale(args[0], args[1], args[2]); 1.88 + } 1.89 + } catch (Throwable t) { 1.90 + locale = Locale.getDefault(); 1.91 + } 1.92 + } 1.93 + return locale; 1.94 + } 1.95 + 1.96 + /** 1.97 + * Subclasses of this class must implement this method so that the 1.98 + * correct resource bundle is passed to methods in this class 1.99 + * 1.100 + * @return 1.101 + * A java.util.ResourceBundle from the subsclass. Methods in this class 1.102 + * will use this reference. 1.103 + */ 1.104 + public abstract ResourceBundle getBundle(); 1.105 + 1.106 + 1.107 + /** 1.108 + * Since we are changing the ResourceBundle extension point, must 1.109 + * implement handleGetObject() using delegate getBundle(). Uses 1.110 + * getObject() call to work around protected access to 1.111 + * ResourceBundle.handleGetObject(). Happily, this means parent tree 1.112 + * of delegate bundle is searched for a match. 1.113 + * 1.114 + * Implements java.util.ResourceBundle.handleGetObject; inherits that 1.115 + * javadoc information. 1.116 + * 1.117 + * @see java.util.ResourceBundle#handleGetObject(String) 1.118 + */ 1.119 + protected Object handleGetObject(String key) { 1.120 + return getBundle().getObject(key); 1.121 + } 1.122 + 1.123 + /** 1.124 + * Since we are changing the ResourceBundle extension point, must 1.125 + * implement getKeys() using delegate getBundle(). 1.126 + * 1.127 + * Implements java.util.ResourceBundle.getKeys; inherits that javadoc 1.128 + * information. 1.129 + * 1.130 + * @see java.util.ResourceBundle#getKeys() 1.131 + */ 1.132 + public final Enumeration getKeys() { 1.133 + return getBundle().getKeys(); 1.134 + } 1.135 +}