@Test public void failedRBLookup() { MessageConveyor mc = new MessageConveyor(Locale.CHINA); try { mc.getMessage(Colors.BLUE); fail("missing exception"); } catch (MessageConveyorException e) { assertEquals( "Failed to locate resource bundle [colors] for locale [zh_CN] for enum type [ch.qos.cal10n.sample.Colors]", e.getMessage()); } }
public <E extends Enum<?>> String getMessage(E key, Object... args) throws MessageConveyorException { Class<? extends Enum<?>> declaringClass = key.getDeclaringClass(); String declaringClassName = declaringClass.getName(); CAL10NBundle rb = cache.get(declaringClassName); if (rb == null || rb.hasChanged()) { rb = lookupResourceBundleByEnumClassAndLocale(declaringClass); cache.put(declaringClassName, rb); } String keyAsStr = key.toString(); String value = rb.getString(keyAsStr); if (value == null) { return "No key found for " + keyAsStr; } else { if (args == null || args.length == 0) { return value; } else { return MessageFormat.format(value, args); } } }
MessageConveyor implements IMessageConveyor { public <E extends Enum<?>> String getMessage(E key, Object... args) throws MessageConveyorException { Class<? extends Enum<?>> declaringClass = key.getDeclaringClass(); String declaringClassName = declaringClass.getName(); CAL10NBundle rb = cache.get(declaringClassName); if (rb == null || rb.hasChanged()) { rb = lookupResourceBundleByEnumClassAndLocale(declaringClass); cache.put(declaringClassName, rb); } String keyAsStr = key.toString(); String value = rb.getString(keyAsStr); if (value == null) { return "No key found for " + keyAsStr; } else { if (args == null || args.length == 0) { return value; } else { return MessageFormat.format(value, args); } } } }
MessageConveyor implements IMessageConveyor { public <E extends Enum<?>> String getMessage(E key, Object... args) throws MessageConveyorException { Class<? extends Enum<?>> declaringClass = key.getDeclaringClass(); String declaringClassName = declaringClass.getName(); CAL10NBundle rb = cache.get(declaringClassName); if (rb == null || rb.hasChanged()) { rb = lookupResourceBundleByEnumClassAndLocale(declaringClass); cache.put(declaringClassName, rb); } String keyAsStr = key.toString(); String value = rb.getString(keyAsStr); if (value == null) { return "No key found for " + keyAsStr; } else { if (args == null || args.length == 0) { return value; } else { return MessageFormat.format(value, args); } } } MessageConveyor(Locale locale); }
MessageConveyor implements IMessageConveyor { public <E extends Enum<?>> String getMessage(E key, Object... args) throws MessageConveyorException { Class<? extends Enum<?>> declaringClass = key.getDeclaringClass(); String declaringClassName = declaringClass.getName(); CAL10NBundle rb = cache.get(declaringClassName); if (rb == null || rb.hasChanged()) { rb = lookupResourceBundleByEnumClassAndLocale(declaringClass); cache.put(declaringClassName, rb); } String keyAsStr = key.toString(); String value = rb.getString(keyAsStr); if (value == null) { return "No key found for " + keyAsStr; } else { if (args == null || args.length == 0) { return value; } else { return MessageFormat.format(value, args); } } } MessageConveyor(Locale locale); String getMessage(E key, Object... args); String getMessage(MessageParameterObj mpo); }
MessageConveyor implements IMessageConveyor { public <E extends Enum<?>> String getMessage(E key, Object... args) throws MessageConveyorException { Class<? extends Enum<?>> declaringClass = key.getDeclaringClass(); String declaringClassName = declaringClass.getName(); CAL10NBundle rb = cache.get(declaringClassName); if (rb == null || rb.hasChanged()) { rb = lookupResourceBundleByEnumClassAndLocale(declaringClass); cache.put(declaringClassName, rb); } String keyAsStr = key.toString(); String value = rb.getString(keyAsStr); if (value == null) { return "No key found for " + keyAsStr; } else { if (args == null || args.length == 0) { return value; } else { return MessageFormat.format(value, args); } } } MessageConveyor(Locale locale); String getMessage(E key, Object... args); String getMessage(MessageParameterObj mpo);  }