1 16 17 package org.springframework.context.support; 18 19 import java.util.Enumeration ; 20 import java.util.Locale ; 21 import java.util.ResourceBundle ; 22 23 import org.springframework.context.MessageSource; 24 import org.springframework.context.NoSuchMessageException; 25 import org.springframework.util.Assert; 26 27 37 public class MessageSourceResourceBundle extends ResourceBundle { 38 39 private final MessageSource messageSource; 40 41 private final Locale locale; 42 43 44 49 public MessageSourceResourceBundle(MessageSource source, Locale locale) { 50 Assert.notNull(source, "MessageSource is required"); 51 this.messageSource = source; 52 this.locale = locale; 53 } 54 55 56 60 protected Object handleGetObject(String code) { 61 try { 62 return this.messageSource.getMessage(code, null, this.locale); 63 } 64 catch (NoSuchMessageException ex) { 65 return null; 66 } 67 } 68 69 73 public Enumeration getKeys() { 74 return null; 75 } 76 77 } 78 | Popular Tags |