1 25 package com.mysql.jdbc; 26 27 import java.text.MessageFormat ; 28 import java.util.Locale ; 29 import java.util.MissingResourceException ; 30 import java.util.ResourceBundle ; 31 32 38 public class Messages { 39 40 private static final String BUNDLE_NAME = "com.mysql.jdbc.LocalizedErrorMessages"; 42 private static final ResourceBundle RESOURCE_BUNDLE; 43 44 static { 45 ResourceBundle temp = null; 46 47 53 try { 54 temp = ResourceBundle.getBundle(BUNDLE_NAME, Locale.getDefault(), 55 Messages.class.getClassLoader()); 56 } catch (Throwable t) { 57 try { 58 temp = ResourceBundle.getBundle(BUNDLE_NAME); 59 } catch (Throwable t2) { 60 throw new RuntimeException ( 61 "Can't load resource bundle due to underlying exception " 62 + t.toString()); 63 } 64 } finally { 65 RESOURCE_BUNDLE = temp; 66 } 67 } 68 69 76 public static String getString(String key) { 77 if (RESOURCE_BUNDLE == null) { 78 throw new RuntimeException ( 79 "Localized messages from resource bundle '" + BUNDLE_NAME 80 + "' not loaded during initialization of driver."); 81 } 82 83 try { 84 if (key == null) { 85 throw new IllegalArgumentException ( 86 "Message key can not be null"); 87 } 88 89 String message = RESOURCE_BUNDLE.getString(key); 90 91 if (message == null) { 92 message = "Missing error message for key '" + key + "'"; 93 } 94 95 return message; 96 } catch (MissingResourceException e) { 97 return '!' + key + '!'; 98 } 99 } 100 101 public static String getString(String key, Object [] args) { 102 return MessageFormat.format(getString(key), args); 103 } 104 105 108 private Messages() { 109 110 } 112 } 113 | Popular Tags |