mirror of
https://github.com/postgres/postgres.git
synced 2025-08-27 07:42:10 +03:00
pgjindent jdbc files. First time jdbc files were formatted.
This commit is contained in:
@@ -6,58 +6,74 @@ import java.text.*;
|
||||
/**
|
||||
* A singleton class to translate JDBC driver messages in SQLException's.
|
||||
*/
|
||||
public class MessageTranslator {
|
||||
public class MessageTranslator
|
||||
{
|
||||
|
||||
// The singleton instance.
|
||||
private static MessageTranslator instance = null;
|
||||
|
||||
private ResourceBundle bundle;
|
||||
|
||||
private MessageTranslator() {
|
||||
try {
|
||||
private MessageTranslator()
|
||||
{
|
||||
try
|
||||
{
|
||||
bundle = ResourceBundle.getBundle("org.postgresql.errors");
|
||||
} catch(MissingResourceException e) {
|
||||
}
|
||||
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) {
|
||||
private synchronized final static MessageTranslator getInstance()
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = new MessageTranslator();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public final static String translate(String id, Object[] args) {
|
||||
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) {
|
||||
private final String _translate(String id, Object[] args)
|
||||
{
|
||||
String message;
|
||||
|
||||
if (bundle != null && id != null) {
|
||||
if (bundle != null && id != null)
|
||||
{
|
||||
// Now look up a localized message. If one is not found, then use
|
||||
// the supplied message instead.
|
||||
try {
|
||||
try
|
||||
{
|
||||
message = bundle.getString(id);
|
||||
} catch(MissingResourceException e) {
|
||||
}
|
||||
catch (MissingResourceException e)
|
||||
{
|
||||
message = id;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
message = id;
|
||||
}
|
||||
|
||||
// Expand any arguments
|
||||
if (args != null && message != null) {
|
||||
message = MessageFormat.format(message,args);
|
||||
if (args != null && message != null)
|
||||
{
|
||||
message = MessageFormat.format(message, args);
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user