ResourceBundleUtil.java revision 608:7e06bf1dcb09
1/* 2 * Copyright (c) 1999, 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 * COMPONENT_NAME: idl.parser 27 * 28 * ORIGINS: 27 29 * 30 * Licensed Materials - Property of IBM 31 * 5639-D57 (C) COPYRIGHT International Business Machines Corp. 1997, 1999 32 * RMI-IIOP v1.0 33 * 34 */ 35 36package com.sun.tools.corba.se.idl; 37 38// NOTES: 39// -capitalize and parseTypeModifier should probably be in the 40// generators package. 41// -D58319<daz> Add version() method. 42 43import java.util.ResourceBundle; 44import java.text.MessageFormat; 45import java.util.Hashtable; 46 47public class ResourceBundleUtil 48{ 49 // <d58319> 50 /** 51 * Fetch the version number of this build of the IDL Parser Framework. 52 * This method may be called before or after the framework has been 53 * initialized. If the framework is inititialized, the version information 54 * is extracted from the message properties object; otherwise, it is extracted 55 * from the indicated resouce bundle. 56 * @return the version number. 57 **/ 58 public static String getVersion () 59 { 60 String version = getMessage ("Version.product", getMessage ("Version.number")); 61 return version; 62 } // getVersion 63 64 65 ////////////// 66 // Message-related methods 67 68 public static String getMessage (String key) 69 { 70 return fBundle.getString(key); 71 } // getMessage 72 73 public static String getMessage (String key, String fill) 74 { 75 Object[] args = { fill }; 76 return MessageFormat.format(fBundle.getString(key), args); 77 } // getMessage 78 79 public static String getMessage (String key, String[] fill) 80 { 81 return MessageFormat.format(fBundle.getString(key), fill); 82 } // getMessage 83 84 85 /** Register a ResourceBundle. This file will be searched for 86 in the CLASSPATH. */ 87 public static void registerResourceBundle (ResourceBundle bundle) 88 { 89 if (bundle != null) 90 fBundle = bundle; 91 } // registerResourceBundle 92 93 94 /** Gets the current ResourceBundle. */ 95 public static ResourceBundle getResourceBundle () 96 { 97 return fBundle; 98 } // getResourceBundle 99 100 private static ResourceBundle fBundle; 101 static 102 { 103 // get the resource bundle for the locale on this machine 104 fBundle = ResourceBundle.getBundle("com.sun.tools.corba.se.idl.idl"); 105 } 106 107} // class ResourceBundleUtil 108