📄 messagetranslator.java
字号:
package org.ephman.utils;import java.util.*;import java.text.*;/* * A singleton class to translate JDBC driver messages in SQLException's. * copied patter from org.postgresql. */public class MessageTranslator{ // The singleton instance. private static MessageTranslator instance = null; private ResourceBundle bundle; private MessageTranslator() { try { bundle = ResourceBundle.getBundle("org.ephman.errors"); } catch (MissingResourceException e) { // translation files have not been installed. bundle = null; } } // Synchronized, otherwise multiple threads may perform the test and // assign to the singleton instance simultaneously. private synchronized final static MessageTranslator getInstance() { if (instance == null) { instance = new MessageTranslator(); } return instance; } public final static String translate(String id, Object[] args) { MessageTranslator translator = MessageTranslator.getInstance(); return translator._translate(id, args); } private final String _translate(String id, Object[] args) { String message; if (bundle != null && id != null) { // Now look up a localized message. If one is not found, then use // the supplied message instead. try { message = bundle.getString(id); } catch (MissingResourceException e) { message = id; } } else { message = id; } // Expand any arguments if (args != null && message != null) { message = MessageFormat.format(message, args); } return message; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -