1 /*
2  * Copyright (c) 2005, 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 
26 package com.sun.rowset;
27 
28 import java.io.*;
29 import java.util.*;
30 
31 /**
32  * This class is used to help in localization of resources,
33  * especially the exception strings.
34  *
35  * @author Amit Handa
36  */
37 
38 public class JdbcRowSetResourceBundle implements Serializable {
39 
40     /**
41      * This <code>String</code> variable stores the location
42      * of the resource bundle location.
43      */
44     private static String fileName;
45 
46     /**
47      * This variable will hold the <code>PropertyResourceBundle</code>
48      * of the text to be internationalized.
49      */
50     private transient PropertyResourceBundle propResBundle;
51 
52     /**
53      * The constructor initializes to this object
54      *
55      */
56     private static volatile JdbcRowSetResourceBundle jpResBundle;
57 
58     /**
59      * The variable which will represent the properties
60      * the suffix or extension of the resource bundle.
61      **/
62     private static final String PROPERTIES = "properties";
63 
64     /**
65      * The variable to represent underscore
66      **/
67     private static final String UNDERSCORE = "_";
68 
69     /**
70      * The variable which will represent dot
71      **/
72     private static final String DOT = ".";
73 
74     /**
75      * The variable which will represent the slash.
76      **/
77     private static final String SLASH = "/";
78 
79     /**
80      * The variable where the default resource bundle will
81      * be placed.
82      **/
83     private static final String PATH = "com/sun/rowset/RowSetResourceBundle";
84 
85     /**
86      * The constructor which initializes the resource bundle.
87      * Note this is a private constructor and follows Singleton
88      * Design Pattern.
89      *
90      * @throws IOException if unable to load the ResourceBundle
91      * according to locale or the default one.
92      */
JdbcRowSetResourceBundle()93     private JdbcRowSetResourceBundle () throws IOException {
94         // Try to load the resource bundle according
95         // to the locale. Else if no bundle found according
96         // to the locale load the default.
97 
98         // In default case the default locale resource bundle
99         // should always be loaded else it
100         // will be difficult to throw appropriate
101         // exception string messages.
102         Locale locale = Locale.getDefault();
103 
104         // Load appropriate bundle according to locale
105         propResBundle = (PropertyResourceBundle) ResourceBundle.getBundle(PATH,
106                            locale, JdbcRowSetResourceBundle.class.getModule());
107 
108    }
109 
110     /**
111      * This method is used to get a handle to the
112      * initialized instance of this class. Note that
113      * at any time there is only one instance of this
114      * class initialized which will be returned.
115      *
116      * @throws IOException if unable to find the RowSetResourceBundle.properties
117      */
getJdbcRowSetResourceBundle()118     public static JdbcRowSetResourceBundle getJdbcRowSetResourceBundle()
119     throws IOException {
120 
121          if(jpResBundle == null){
122              synchronized(JdbcRowSetResourceBundle.class) {
123                 if(jpResBundle == null){
124                     jpResBundle = new JdbcRowSetResourceBundle();
125                 } //end if
126              } //end synchronized block
127          } //end if
128          return jpResBundle;
129     }
130 
131     /**
132      * This method returns an enumerated handle of the keys
133      * which correspond to values translated to various locales.
134      *
135      * @return an enumeration of keys which have messages tranlated to
136      * corresponding locales.
137      */
138     @SuppressWarnings("rawtypes")
getKeys()139     public Enumeration getKeys() {
140        return propResBundle.getKeys();
141     }
142 
143 
144     /**
145      * This method takes the key as an argument and
146      * returns the corresponding value reading it
147      * from the Resource Bundle loaded earlier.
148      *
149      * @return value in locale specific language
150      * according to the key passed.
151      */
handleGetObject(String key)152     public Object handleGetObject(String key) {
153        return propResBundle.handleGetObject(key);
154     }
155 
156     static final long serialVersionUID = 436199386225359954L;
157 }
158