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

changeset 286
f50545b5e2f1
parent 0
373ffda63c9a
equal deleted inserted replaced
284:88b85470e72c 286:f50545b5e2f1
1 /*
2 * Copyright (c) 2004, 2011, 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 * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
26 */
27
28 /*
29 *
30 * This code is subject to the freebxml License, Version 1.1
31 *
32 * Copyright (c) 2001 - 2005 freebxml.org. All rights reserved.
33 *
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 $
35 */
36 package com.sun.xml.internal.fastinfoset;
37
38 import java.text.MessageFormat;
39 import java.util.Enumeration;
40 import java.util.Locale;
41 import java.util.ResourceBundle;
42
43
44 /**
45 * This class contains methods common to all *ResourceBundle classes
46 *
47 * @author FastInfoset team
48 */
49 public abstract class AbstractResourceBundle extends ResourceBundle {
50
51 public static final String LOCALE = "com.sun.xml.internal.fastinfoset.locale";
52
53 /**
54 * Gets 'key' from ResourceBundle and format mesage using 'args'.
55 *
56 * @param key String key for message.
57 * @param args Array of arguments for message.
58 * @return String formatted message.
59 */
60 public String getString(String key, Object args[]) {
61 String pattern = getBundle().getString(key);
62 return MessageFormat.format(pattern, args);
63 }
64
65 /**
66 * Parse a locale string, return corresponding Locale instance.
67 *
68 * @param localeString
69 * Name for the locale of interest. If null, use VM default locale.
70 * @return New Locale instance.
71 */
72 public static Locale parseLocale(String localeString) {
73 Locale locale = null;
74 if (localeString == null) {
75 locale = Locale.getDefault();
76 } else {
77 try {
78 String[] args = localeString.split("_");
79 if (args.length == 1) {
80 locale = new Locale(args[0]);
81 } else if (args.length == 2) {
82 locale = new Locale(args[0], args[1]);
83 } else if (args.length == 3) {
84 locale = new Locale(args[0], args[1], args[2]);
85 }
86 } catch (Throwable t) {
87 locale = Locale.getDefault();
88 }
89 }
90 return locale;
91 }
92
93 /**
94 * Subclasses of this class must implement this method so that the
95 * correct resource bundle is passed to methods in this class
96 *
97 * @return
98 * A java.util.ResourceBundle from the subsclass. Methods in this class
99 * will use this reference.
100 */
101 public abstract ResourceBundle getBundle();
102
103
104 /**
105 * Since we are changing the ResourceBundle extension point, must
106 * implement handleGetObject() using delegate getBundle(). Uses
107 * getObject() call to work around protected access to
108 * ResourceBundle.handleGetObject(). Happily, this means parent tree
109 * of delegate bundle is searched for a match.
110 *
111 * Implements java.util.ResourceBundle.handleGetObject; inherits that
112 * javadoc information.
113 *
114 * @see java.util.ResourceBundle#handleGetObject(String)
115 */
116 protected Object handleGetObject(String key) {
117 return getBundle().getObject(key);
118 }
119
120 /**
121 * Since we are changing the ResourceBundle extension point, must
122 * implement getKeys() using delegate getBundle().
123 *
124 * Implements java.util.ResourceBundle.getKeys; inherits that javadoc
125 * information.
126 *
127 * @see java.util.ResourceBundle#getKeys()
128 */
129 public final Enumeration getKeys() {
130 return getBundle().getKeys();
131 }
132 }

mercurial