Interface MessageTemplates
-
public interface MessageTemplatesMarker interface for classes or interfaces that containMessageTemplatefields, which can be queried usinggetMessageTemplates(Class, boolean)
Example of a concreteMessageTemplatessubclass:public interface MyMessageTemplates extends MessageTemplates { // Has key: "ESSENTIALS" MessageTemplate0 ROOT = MessageTemplates.root("ESSENTIALS"); // Has key: "ESSENTIALS.VALIDATION" MessageTemplate0 VALIDATION = ROOT.subKey("VALIDATION"); // Has key: "ESSENTIALS.VALIDATION.AMOUNT_TOO_HIGH" MessageTemplate2<BigDecimal, BigDecimal> AMOUNT_TOO_HIGH = VALIDATION.key2("AMOUNT_TOO_HIGH", "Amount {0} is higher than {1}"); // Has key: "ESSENTIALS.VALIDATION.AMOUNT_TOO_LOW" MessageTemplate2<BigDecimal, BigDecimal> AMOUNT_TOO_LOW = VALIDATION.key2("AMOUNT_TOO_LOW", "Amount {0} is lower than {1}"); // Has key: "ESSENTIALS.BUSINESS_RULES" MessageTemplate0 BUSINESS_RULES = ROOT.subKey("BUSINESS_RULES"); // Has key: "ESSENTIALS.BUSINESS_RULES.ACCOUNT_NOT_ACTIVATED" MessageTemplate1<String> ACCOUNT_NOT_ACTIVATED = BUSINESS_RULES.key1("ACCOUNT_NOT_ACTIVATED", "Account {0} is not activated"); }- See Also:
MessageTemplate,Message
-
-
Method Summary
Static Methods Modifier and Type Method Description static List<MessageTemplate>getMessageTemplates(Class<? extends MessageTemplates> messageTemplatesType, boolean skipMessageTemplateWithNoDefaultMessage)Extract allMessageTemplate's defined as fields inMessageTemplatessub-type (interface or class)static MessageTemplate0key(String messageKey)Create a message key (same asroot(String)) with no parameters.
Example:static MessageTemplate0key(String messageKey, String defaultMessage)Create a message key (same asroot(String)) with no parameters.
Example:static <PARAM_1> MessageTemplate1<PARAM_1>key1(String messageKey, String defaultMessage)Create aMessageTemplateswith 1 parameter Example:static <PARAM_1,PARAM_2>
MessageTemplate2<PARAM_1,PARAM_2>key2(String messageKey, String defaultMessage)Create aMessageTemplateswith 2 parameters Example:static <PARAM_1,PARAM_2,PARAM_3>
MessageTemplate3<PARAM_1,PARAM_2,PARAM_3>key3(String messageKey, String defaultMessage)Create aMessageTemplateswith 3 parameters Example:static <PARAM_1,PARAM_2,PARAM_3,PARAM_4>
MessageTemplate4<PARAM_1,PARAM_2,PARAM_3,PARAM_4>key4(String messageKey, String defaultMessage)Create aMessageTemplateswith 4 parameters Example:static MessageTemplate0root(String messageKey)Create a root message key (same askey(String)).
This is usually used for the root key, to provide context for message template.
Example:
-
-
-
Method Detail
-
getMessageTemplates
static List<MessageTemplate> getMessageTemplates(Class<? extends MessageTemplates> messageTemplatesType, boolean skipMessageTemplateWithNoDefaultMessage)
Extract allMessageTemplate's defined as fields inMessageTemplatessub-type (interface or class)- Parameters:
messageTemplatesType- theMessageTemplatessub-type (interface or class)skipMessageTemplateWithNoDefaultMessage- skipMessageTemplatewhereMessageTemplate.getDefaultMessage()is null- Returns:
- the
MessageTemplate's that match the criteria
-
key
static MessageTemplate0 key(String messageKey, String defaultMessage)
Create a message key (same asroot(String)) with no parameters.
Example:MessageTemplate0 ROOT = MessageTemplates.key("MY_SERVICE", "My Service ...");- Parameters:
messageKey- the message keydefaultMessage- The default message- Returns:
- the
MessageTemplate
-
key
static MessageTemplate0 key(String messageKey)
Create a message key (same asroot(String)) with no parameters.
Example:MessageTemplate0 ROOT = MessageTemplates.key("MY_SERVICE");- Parameters:
messageKey- the message key- Returns:
- the
MessageTemplate(with no default message)
-
root
static MessageTemplate0 root(String messageKey)
Create a root message key (same askey(String)).
This is usually used for the root key, to provide context for message template.
Example:MessageTemplate0 ROOT = MessageTemplates.root("MY_SERVICE");- Parameters:
messageKey- the root message key- Returns:
- the
MessageTemplate(with no default message)
-
key1
static <PARAM_1> MessageTemplate1<PARAM_1> key1(String messageKey, String defaultMessage)
Create aMessageTemplateswith 1 parameter Example:// Has key: "ACCOUNT_NOT_ACTIVATED" MessageTemplate1<String> ACCOUNT_NOT_ACTIVATED = MessageTemplates.key1("ACCOUNT_NOT_ACTIVATED", "Account {0} is not activated");- Type Parameters:
PARAM_1- the type for the parameter with index 0- Parameters:
messageKey- the message keydefaultMessage- the default message- Returns:
- a new
MessageTemplatewithMessageTemplate.getKey(): messageKey and the provided defaultMessage
-
key2
static <PARAM_1,PARAM_2> MessageTemplate2<PARAM_1,PARAM_2> key2(String messageKey, String defaultMessage)
Create aMessageTemplateswith 2 parameters Example:// Has key: "AMOUNT_TOO_HIGH" MessageTemplate2<BigDecimal, BigDecimal> AMOUNT_TOO_HIGH = MessageTemplates.key2("AMOUNT_TOO_HIGH", "Amount {0} is higher than {1}");- Type Parameters:
PARAM_1- the type for the parameter with index 0PARAM_2- the type for the parameter with index 1- Parameters:
messageKey- the message keydefaultMessage- the default message- Returns:
- a new
MessageTemplatewithMessageTemplate.getKey(): messageKey and the provided defaultMessage
-
key3
static <PARAM_1,PARAM_2,PARAM_3> MessageTemplate3<PARAM_1,PARAM_2,PARAM_3> key3(String messageKey, String defaultMessage)
Create aMessageTemplateswith 3 parameters Example:// Has key: "ACCOUNT_OVERDRAWN" MessageTemplate3<String, BigDecimal, BigDecimal> ACCOUNT_OVERDRAWN = MessageTemplates.key3("ACCOUNT_OVERDRAWN", "Account {0} is overdrawn by {1}. Fee {2}");- Type Parameters:
PARAM_1- the type for the parameter with index 0PARAM_2- the type for the parameter with index 1PARAM_3- the type for the parameter with index 2- Parameters:
messageKey- the message keydefaultMessage- the default message- Returns:
- a new
MessageTemplatewithMessageTemplate.getKey(): messageKey and the provided defaultMessage
-
key4
static <PARAM_1,PARAM_2,PARAM_3,PARAM_4> MessageTemplate4<PARAM_1,PARAM_2,PARAM_3,PARAM_4> key4(String messageKey, String defaultMessage)
Create aMessageTemplateswith 4 parameters Example:// Has key: "ACCOUNT_OVERDRAWN" MessageTemplate4<String, BigDecimal, BigDecimal, LocalDate> ACCOUNT_OVERDRAWN = MessageTemplates.key4("ACCOUNT_OVERDRAWN", "Account {0} is overdrawn by {1}. Fee of {2} will be debited on the {3}");- Type Parameters:
PARAM_1- the type for the parameter with index 0PARAM_2- the type for the parameter with index 1PARAM_3- the type for the parameter with index 2PARAM_3- the type for the parameter with index 3- Parameters:
messageKey- the message keydefaultMessage- the default message- Returns:
- a new
MessageTemplatewithMessageTemplate.getKey(): messageKey and the provided defaultMessage
-
-