net.sf.mmm.util.nls.base.AbstractResourceBundle Maven / Gradle / Ivy
/* Copyright (c) The m-m-m Team, Licensed under the Apache License, Version 2.0
* http://www.apache.org/licenses/LICENSE-2.0 */
package net.sf.mmm.util.nls.base;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.Set;
/**
* This is the abstract base class for {@link ResourceBundle} implementations using this NLS support.
* ATTENTION:
* The preferred approach to define messages for the root locale is via {@link net.sf.mmm.util.nls.api.NlsBundle}
* instead of using this class.
*
* Create your {@link ResourceBundle}s by sub-classing this class and simply define some public static final fields that
* will be automatically added to the bundle using reflection (only from constructor).
* Please note that your sub-class must also be public or you need to set privileges in the security manager to allow
* this class reading the fields via reflection.
* Please also follow the convention using the following prefixes followed by a suffix that properly explains what the
* text is about:
*
*
* Prefix
* Comment
* Example
*
*
* ERR_
* Text for an exception message.
* ERR_VALUE_NOT_SET = "The value \"{value}\" is not set!"
*
*
* MSG_
* Text for a complete information message.
* {@code MSG_MAIN_OPTION_VERSION_USAGE = "Print the program-version."}
*
*
* INF_
* Text for a single information term.
* {@code INF_MAIN_MODE_DEFAULT = "default"}
*
*
* INT_
* Reserved for internal constants not to be localized.
* {@code INT_MAIN_OPTION_NAME_VERSION = "--version"}
*
*
*
* @author Joerg Hohwiller (hohwille at users.sourceforge.net)
* @since 1.0.0
*/
public abstract class AbstractResourceBundle extends ResourceBundle {
/**
* Fields that start with this prefix ({@value} ), will be ignored as {@link #getString(String) bundle properties}.
*/
private static final String PREFIX_INTERNAL_FIELD = "INT_";
/**
* The key value pairs; maps keys (String) to values (Object). No Map because Enumeration is required...
*/
private Hashtable bundle;
/** the inverse map of {@link #bundle} */
private Map