KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > common > validation > util > BundleReader


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * BundleReader.java May 6, 2003, 3:33 PM
26  *
27  */

28
29 package com.sun.enterprise.tools.common.validation.util;
30
31 import java.util.MissingResourceException JavaDoc;
32 import java.util.ResourceBundle JavaDoc;
33
34 import com.sun.enterprise.tools.common.validation.Constants;
35
36
37 /**
38  * BundleReader is a Class to read properties from the bundle.
39  * <code>getValue()</code> method can be used to read the properties
40  * from the bundle file(Bundle.properties). Default bundle file used
41  * is <code>{ @link Constants }.BUNDLE_FILE</code>. Bundle file to use
42  * can be set by using <code>setBundle()</code> method.
43  *
44  * @author Rajeshwar Patil
45  * @version %I%, %G%
46  */

47 public class BundleReader {
48
49     /**
50      * A resource bundle of this reader.
51      */

52     private static ResourceBundle JavaDoc resourceBundle;
53
54     
55     /** Creates a new instance of BundleReader */
56     public BundleReader() {
57     }
58
59     /**
60      * Gets the value of the the given <code>key</code> from the bundle
61      *
62      * @param key the key of which, the value needs to be fetched from
63      * the bundle.
64      */

65     public static String JavaDoc getValue(String JavaDoc key) {
66         if(resourceBundle == null)
67             return key;
68         try {
69             return resourceBundle.getString(key);
70         } catch (MissingResourceException JavaDoc missingResourceException) {
71             return key;
72         }
73     }
74
75
76     /**
77      * sets the given bundle file as the file to use by this object.
78      */

79     public static void setBundle(String JavaDoc bundleFile){
80         try {
81             resourceBundle = ResourceBundle.getBundle(bundleFile);
82         } catch (Exception JavaDoc ex) { }
83     }
84     
85
86     static {
87         try {
88             resourceBundle = ResourceBundle.getBundle(Constants.BUNDLE_FILE);
89         } catch (Exception JavaDoc ex) { }
90     }
91 }
92
Popular Tags