resource bundle


public class PropertyMessageResourcesFactory implements MessageResourcesFactory {

	private Map mrMap = new HashMap();
	
	public MessageResources getInstance(String filename,Locale locale){
		MessageResources messageResources = (MessageResources) mrMap.get(filename);
		if(null!=messageResources){
			return messageResources;
		}
		ResourceBundle rb = ResourceBundle.getBundle(filename, locale);
		messageResources = new PropertyMessageResources(rb);
		mrMap.put(filename, messageResources);
		return messageResources;
	}
	
	public MessageResources getInstance(String filename,String language,String country){
		return getInstance(filename,new Locale(language,country));
	}
}

 
 
public class PropertyMessageResources implements MessageResources {
	
	private ResourceBundle resourceBundle;

	public ResourceBundle getResourceBundle() {
		return resourceBundle;
	}

	public void setResourceBundle(ResourceBundle resourceBundle) {
		this.resourceBundle = resourceBundle;
	}
    
	public PropertyMessageResources(ResourceBundle resourceBundle){
		this.resourceBundle = resourceBundle;
	}
	
	private String getString(String key){
		return resourceBundle.getString(key);
	}
}

 
 
public class MessageFormatIin18 {  
  
    public static void main(String[] args) {  
        MessageResourceFactory factory = MessageResourceFactory.getInstance();  
        MessageResource res = factory.createMessageResource("message",  
                			  new Locale("en", "US"));  
        String value = res.getString("button.add");  
        System.out.println(value);  
        String value_args = res.getString("message", new Object[] { "C", "12" });  
        System.out.println(value_args);  
    }  
  
}