/*
* This software and supporting documentation were developed by
*
* Siemens Corporate Technology
* Competence Center Knowledge Management and Business Transformation
* D-81730 Munich, Germany
*
* Authors (representing a really great team ;-) )
* Stefan B. Augustin, Thorbj�rn Hansen, Manfred Langen
*
* This software is Open Source under GNU General Public License (GPL).
* Read the text of this license in LICENSE.TXT
* or look at www.opensource.org/licenses/
*
* Once more we emphasize, that:
* THIS SOFTWARE IS MADE AVAILABLE, AS IS, WITHOUT ANY WARRANTY
* REGARDING THE SOFTWARE, ITS PERFORMANCE OR
* FITNESS FOR ANY PARTICULAR USE, FREEDOM FROM ANY COMPUTER DISEASES OR
* ITS CONFORMITY TO ANY SPECIFICATION. THE ENTIRE RISK AS TO QUALITY AND
* PERFORMANCE OF THE SOFTWARE IS WITH THE USER.
*
*/
// KFM_ResourceBundleWrapper
// ************ package ******************************************************
package KFM.i18n;
// ************ imports ******************************************************
import java.util.ResourceBundle;
import java.util.MissingResourceException;
import KFM.log.KFMSystem;
import KFM.Exceptions.ProgrammerException;
/**
* Replaces the ResourceBundle object.
*
* We have a problem with ResourceBundles. The following code has 2 problems:
*
* ResourceBundle tRB = ...;
* ... tRB.getString(tKey) ...
*
* (1) It will throw an exception when tKey is missing.
* We do not know how to make a check for valid keys at compile time.
*
* (2) It is very difficult to understand for the programmer because he cannot
* see any string contents.
*
* Idea: Use this instead:
*
* KFM_ResourceBundleWrapper tRB = ...;
* ... tRB.getString(tKey, "Hello") ...
*
* Where "Hello" is a default string. If tKey is missing, we get an error mail and the default string is used.
*
* Problem: The default string is redundant, it's also in the english language resouce bundle. We do not
* know how to eliminate this redundancy yet.
*
* Note:
* It is intentional, that this class should not have a working getString(String aKey) method.
*
* @see ResourceBundle
*/
public class KFM_ResourceBundleWrapper
{
/** The ResourceBundle object to be wrapped. */
protected ResourceBundle mBundle;
public KFM_ResourceBundleWrapper(ResourceBundle aBundle)
{
mBundle = aBundle;
}
/** Deprecated. Do not use this!!!
*
* @deprecated
*/
private String getString(String aKey) {
throw new ProgrammerException("KFM_ResourceBundleWrapper: Call of getString(String) is deprecated.");
}
/**
* Wraps mResourceBundle.getString(), except that when the named resource is not found,
* it returns the specific default instead of throwing an exception.
*
* See class comment for detailed explanation.
*
* @see David Flanagan, Java Examples In A Nutshell 2nd, Example 10-22
*/
public String getString(String aKey, String aDefault)
{
try {
return mBundle.getString(aKey);
} catch (MissingResourceException e) {
KFMSystem.log.error("KFM_ResourceBundleWrapper::getString: resource file(s) " + mBundle.toString()
+ " has(have) no key '" + aKey + "', reverting to default");
return aDefault;
}
}
}