-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TEIIDDES-2118: Factor out all connectivity plugin's message strings
* Uses enums in Messages class to refactor all exception messages into separate resource properties file
- Loading branch information
Paul Richardson
committed
Aug 7, 2014
1 parent
cb232b2
commit 2478e6c
Showing
4 changed files
with
128 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
plugins/org.teiid.datatools.connectivity/src/org/teiid/datatools/connectivity/Messages.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* | ||
* See the LEGAL.txt file distributed with this work for information regarding copyright ownership and licensing. | ||
* | ||
* See the AUTHORS.txt file distributed with this work for a full listing of individual contributors. | ||
*/ | ||
package org.teiid.datatools.connectivity; | ||
|
||
import java.text.MessageFormat; | ||
import java.util.MissingResourceException; | ||
import java.util.ResourceBundle; | ||
|
||
/** | ||
* | ||
*/ | ||
public class Messages { | ||
|
||
private static final String BUNDLE_NAME = "org.teiid.datatools.connectivity.messages"; //$NON-NLS-1$ | ||
|
||
private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME); | ||
|
||
private static final String DOT = "."; //$NON-NLS-1$ | ||
|
||
@SuppressWarnings( "javadoc" ) | ||
public enum ConnectivityUtil { | ||
noTeiidDriverDefinitionFound, | ||
errorGettingProfile, | ||
errorGettingProfileProperties, | ||
noTeiidDriverFound; | ||
|
||
@Override | ||
public String toString() { | ||
return getEnumName(this) + DOT + name(); | ||
} | ||
} | ||
|
||
@SuppressWarnings( "javadoc" ) | ||
public enum TeiidJDBCConnection { | ||
noDriverFound, | ||
invalidUserPassword; | ||
|
||
@Override | ||
public String toString() { | ||
return getEnumName(this) + DOT + name(); | ||
} | ||
} | ||
|
||
private static String getEnumName(Enum<?> enumValue) { | ||
String className = enumValue.getClass().getName(); | ||
String[] components = className.split("\\$"); //$NON-NLS-1$ | ||
return components[components.length - 1]; | ||
} | ||
|
||
private Messages() { | ||
} | ||
|
||
/** | ||
* Get message string | ||
* | ||
* @param key | ||
* | ||
* @return i18n string | ||
*/ | ||
private static String getString(Enum<?> key) { | ||
try { | ||
return RESOURCE_BUNDLE.getString(key.toString()); | ||
} catch (final Exception err) { | ||
String msg; | ||
|
||
if (err instanceof NullPointerException) { | ||
msg = "<No message available>"; //$NON-NLS-1$ | ||
} else if (err instanceof MissingResourceException) { | ||
msg = "<Missing message for key \"" + key + "\" in: " + BUNDLE_NAME + '>'; //$NON-NLS-1$ //$NON-NLS-2$ | ||
} else { | ||
msg = err.getLocalizedMessage(); | ||
} | ||
|
||
return msg; | ||
} | ||
} | ||
|
||
/** | ||
* Get message string with parameters | ||
* | ||
* @param key | ||
* @param parameters | ||
* | ||
* @return i18n string | ||
*/ | ||
public static String getString(Enum<?> key, Object... parameters) { | ||
String text = getString(key); | ||
|
||
// Check the trivial cases ... | ||
if (text == null) { | ||
return '<' + key.toString() + '>'; | ||
} | ||
if (parameters == null || parameters.length == 0) { | ||
return text; | ||
} | ||
|
||
return MessageFormat.format(text, parameters); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...org.teiid.datatools.connectivity/src/org/teiid/datatools/connectivity/messages.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# JBoss, Home of Professional Open Source. | ||
# | ||
# See the LEGAL.txt file distributed with this work for information regarding copyright ownership and licensing. | ||
# | ||
# See the AUTHORS.txt file distributed with this work for a full listing of individual contributors. | ||
|
||
ConnectivityUtil.noTeiidDriverDefinitionFound=Failure to find or create Teiid driver definition for version {0} | ||
ConnectivityUtil.errorGettingProfile=Error acquiring connection profile | ||
ConnectivityUtil.errorGettingProfileProperties=Error acquiring connection profile properties | ||
ConnectivityUtil.noTeiidDriverFound=No Teiid Driver ({0}) available for version {1} | ||
|
||
TeiidJDBCConnection.noDriverFound=No driver found for connection to {0} | ||
TeiidJDBCConnection.invalidUserPassword=The teiid driver failed to connect to {0} with the given username and password |