1
package org.postgresql.util;
7
* A singleton class to translate JDBC driver messages in SQLException's.
9
public class MessageTranslator
12
// The singleton instance.
13
private static MessageTranslator instance = null;
15
private ResourceBundle bundle;
17
private MessageTranslator()
21
bundle = ResourceBundle.getBundle("org.postgresql.errors");
23
catch (MissingResourceException e)
25
// translation files have not been installed.
30
// Synchronized, otherwise multiple threads may perform the test and
31
// assign to the singleton instance simultaneously.
32
private synchronized final static MessageTranslator getInstance()
36
instance = new MessageTranslator();
41
public final static String translate(String id, Object[] args)
44
MessageTranslator translator = MessageTranslator.getInstance();
46
return translator._translate(id, args);
49
private final String _translate(String id, Object[] args)
53
if (bundle != null && id != null)
55
// Now look up a localized message. If one is not found, then use
56
// the supplied message instead.
59
message = bundle.getString(id);
61
catch (MissingResourceException e)
71
// Expand any arguments
72
if (args != null && message != null)
74
message = MessageFormat.format(message, args);