Interface MessageFactory


public interface MessageFactory

A MessageFactory allows i18n messages to be declared and looked up from a MessageSource using a declarative dsl-ish technique. A MessageFactory implementation can be instantiated using the #get(Class, Locale, MessageSource) method to return a live instance that returns translated messages.

Messages are looked up from the message source using a MessageFactory interface method's fully qualified name, e.g. String com.FooMessages.thisIsTheBestMessage() will look up com.FooMessages.THIS_IS_THE_BEST_MESSAGE from its MessageSource. If no key is present, a default is returned based on the called method's name 0 - "this is the best message" would be returned from the previous example if no message had been found in the MessageSource. for the preset Locale

MessageFactory sub-interfaces can declare methods that return MessageKeys as well as Strings. This is provided as a convenience, but is not preferred, as it leaves the user of the MessageKey without a way of knowing which MessageSource to resolve against.

see MessageFactoryProxy for the actual lookup implementation.