Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.cantaa.util.resource;
Convenient Manager around a resource bundle. This class is a pseudo singleton. You can create more then one instance but only the last created instance can be retrieved with the getInstance-Method.

If you have only one bundle, then call the constructor once and pass the bundlename to it. From there you can always get a reference to the manager with the static getInstance-Method.

The manager can be configured through Spring by just adding it as a bean and configuring the bundlename as a constructor parameter.

use BundleProvider instead
Hans Lesmeister
public class ResourceManager implements MessageResolver {
   private volatile static ResourceManager resourceManager;
   private String bundleName;


bundleName fully qualified resource name, i.e. "com.cantaa.res.Resource" (without extension .properties)
   public ResourceManager(String bundleName) {
      this. = bundleName;
       = this;

Get the one and only singleton instance.

The instance or null if no instance exists
   public static ResourceManager getInstance() {
      return ;
   public MessageBean createMessageBean(String keyObject...insets) {
      return new MessageBean(thiskeyinsets);

   public String getString(String keyObject...insets) {
      String text;
      try {
         ResourceBundle bundle = ResourceBundle.getBundle();
         text = bundle.getString(key);
      catch (MissingResourceException e) {
         text = key;
      return MessageFormat.format(textinsets);

Gets a string from the resource bundle. The resource key and insets are taken from the passed bean

String or null if the bean is null
   public String getString(MessageHolder messageBean) {
      if (messageBean == null) {
         return null;
      return getString(messageBean.getKey(), messageBean.getInsets());

Name of the resource bundle

Name which was originally passed to the constructor
   public String getBundleName() {
      return ;
   public void setBundleName(String bundleName) {
      this. = bundleName;
New to GrepCode? Check out our FAQ X