J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2005-2006 Sun Microsystems, Inc. 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. Sun designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 23 | * have any questions. |
| 24 | */ |
| 25 | |
| 26 | package com.sun.rowset; |
| 27 | |
| 28 | import java.io.*; |
| 29 | import java.util.*; |
| 30 | import java.lang.*; |
| 31 | |
| 32 | /** |
| 33 | * This class is used to help in localization of resources, |
| 34 | * especially the exception strings. |
| 35 | * |
| 36 | * @author Amit Handa |
| 37 | */ |
| 38 | |
| 39 | public class JdbcRowSetResourceBundle implements Serializable { |
| 40 | |
| 41 | /** |
| 42 | * This <code>String</code> variable stores the location |
| 43 | * of the resource bundle location. |
| 44 | */ |
| 45 | static String fileName; |
| 46 | |
| 47 | /** |
| 48 | * This variable will hold the <code>PropertyResourceBundle</code> |
| 49 | * of the text to be internationalized. |
| 50 | */ |
| 51 | transient PropertyResourceBundle propResBundle; |
| 52 | |
| 53 | /** |
| 54 | * The constructor initializes to this object |
| 55 | * |
| 56 | */ |
| 57 | static JdbcRowSetResourceBundle jpResBundle; |
| 58 | |
| 59 | /** |
| 60 | * The varible which will represent the properties |
| 61 | * the suffix or extension of the resource bundle. |
| 62 | **/ |
| 63 | private static final String PROPERTIES = "properties"; |
| 64 | |
| 65 | /** |
| 66 | * The varibale to represent underscore |
| 67 | **/ |
| 68 | private static final String UNDERSCORE = "_"; |
| 69 | |
| 70 | /** |
| 71 | * The variable which will represent dot |
| 72 | **/ |
| 73 | private static final String DOT = "."; |
| 74 | |
| 75 | /** |
| 76 | * The variable which will represent the slash. |
| 77 | **/ |
| 78 | private static final String SLASH = "/"; |
| 79 | |
| 80 | /** |
| 81 | * The variable where the default resource bundle will |
| 82 | * be placed. |
| 83 | **/ |
| 84 | private static final String PATH = "com/sun/rowset/RowSetResourceBundle"; |
| 85 | |
| 86 | /** |
| 87 | * The constructor which initializes the resource bundle. |
| 88 | * Note this is a private constructor and follows Singleton |
| 89 | * Design Pattern. |
| 90 | * |
| 91 | * @throws IOException if unable to load the ResourceBundle |
| 92 | * according to locale or the default one. |
| 93 | */ |
| 94 | private JdbcRowSetResourceBundle () throws IOException { |
| 95 | // Try to load the resource bundle according |
| 96 | // to the locale. Else if no bundle found according |
| 97 | // to the locale load the default. |
| 98 | |
| 99 | // In default case the default locale resource bundle |
| 100 | // should always be loaded else it |
| 101 | // will be difficult to throw appropriate |
| 102 | // exception string messages. |
| 103 | Locale locale = Locale.getDefault(); |
| 104 | |
| 105 | // Load appropriate bundle according to locale |
| 106 | propResBundle = (PropertyResourceBundle) ResourceBundle.getBundle(PATH, |
| 107 | locale, Thread.currentThread().getContextClassLoader()); |
| 108 | |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * This method is used to get a handle to the |
| 113 | * initialized instance of this class. Note that |
| 114 | * at any time there is only one instance of this |
| 115 | * class initialized which will be returned. |
| 116 | * |
| 117 | * @throws IOException if unable to find the RowSetResourceBundle.properties |
| 118 | */ |
| 119 | public static JdbcRowSetResourceBundle getJdbcRowSetResourceBundle() |
| 120 | throws IOException { |
| 121 | |
| 122 | if(jpResBundle == null){ |
| 123 | synchronized(JdbcRowSetResourceBundle.class) { |
| 124 | if(jpResBundle == null){ |
| 125 | jpResBundle = new JdbcRowSetResourceBundle(); |
| 126 | } //end if |
| 127 | } //end synchronized block |
| 128 | } //end if |
| 129 | return jpResBundle; |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * This method returns an enumerated handle of the keys |
| 134 | * which correspond to values translated to various locales. |
| 135 | * |
| 136 | * @returns an enumerated keys which have messages tranlated to |
| 137 | * corresponding locales. |
| 138 | */ |
| 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 | * @returns value in locale specific language |
| 150 | * according to the key passed. |
| 151 | */ |
| 152 | public Object handleGetObject(String key) { |
| 153 | return propResBundle.handleGetObject(key); |
| 154 | } |
| 155 | |
| 156 | } |