Path: blob/master/src/java.sql.rowset/share/classes/com/sun/rowset/JdbcRowSetResourceBundle.java
40948 views
/*1* Copyright (c) 2005, 2011, 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 com.sun.rowset;2627import java.io.*;28import java.util.*;2930/**31* This class is used to help in localization of resources,32* especially the exception strings.33*34* @author Amit Handa35*/3637public class JdbcRowSetResourceBundle implements Serializable {3839/**40* This <code>String</code> variable stores the location41* of the resource bundle location.42*/43private static String fileName;4445/**46* This variable will hold the <code>PropertyResourceBundle</code>47* of the text to be internationalized.48*/49private transient PropertyResourceBundle propResBundle;5051/**52* The constructor initializes to this object53*54*/55private static volatile JdbcRowSetResourceBundle jpResBundle;5657/**58* The variable which will represent the properties59* the suffix or extension of the resource bundle.60**/61private static final String PROPERTIES = "properties";6263/**64* The variable to represent underscore65**/66private static final String UNDERSCORE = "_";6768/**69* The variable which will represent dot70**/71private static final String DOT = ".";7273/**74* The variable which will represent the slash.75**/76private static final String SLASH = "/";7778/**79* The variable where the default resource bundle will80* be placed.81**/82private static final String PATH = "com/sun/rowset/RowSetResourceBundle";8384/**85* The constructor which initializes the resource bundle.86* Note this is a private constructor and follows Singleton87* Design Pattern.88*89* @throws IOException if unable to load the ResourceBundle90* according to locale or the default one.91*/92private JdbcRowSetResourceBundle () throws IOException {93// Try to load the resource bundle according94// to the locale. Else if no bundle found according95// to the locale load the default.9697// In default case the default locale resource bundle98// should always be loaded else it99// will be difficult to throw appropriate100// exception string messages.101Locale locale = Locale.getDefault();102103// Load appropriate bundle according to locale104propResBundle = (PropertyResourceBundle) ResourceBundle.getBundle(PATH,105locale, JdbcRowSetResourceBundle.class.getModule());106107}108109/**110* This method is used to get a handle to the111* initialized instance of this class. Note that112* at any time there is only one instance of this113* class initialized which will be returned.114*115* @throws IOException if unable to find the RowSetResourceBundle.properties116*/117public static JdbcRowSetResourceBundle getJdbcRowSetResourceBundle()118throws IOException {119120if(jpResBundle == null){121synchronized(JdbcRowSetResourceBundle.class) {122if(jpResBundle == null){123jpResBundle = new JdbcRowSetResourceBundle();124} //end if125} //end synchronized block126} //end if127return jpResBundle;128}129130/**131* This method returns an enumerated handle of the keys132* which correspond to values translated to various locales.133*134* @return an enumeration of keys which have messages tranlated to135* corresponding locales.136*/137@SuppressWarnings("rawtypes")138public Enumeration getKeys() {139return propResBundle.getKeys();140}141142143/**144* This method takes the key as an argument and145* returns the corresponding value reading it146* from the Resource Bundle loaded earlier.147*148* @return value in locale specific language149* according to the key passed.150*/151public Object handleGetObject(String key) {152return propResBundle.handleGetObject(key);153}154155static final long serialVersionUID = 436199386225359954L;156}157158159