public interface MessageTemplates
Marker interface for classes or interfaces that contain MessageTemplate fields, which can be queried using getMessageTemplates(Class, boolean)
Example of a concrete MessageTemplates subclass:

 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:
  • Method Details

    • getMessageTemplates

      static List<MessageTemplate> getMessageTemplates(Class<? extends MessageTemplates> messageTemplatesType, boolean skipMessageTemplateWithNoDefaultMessage)
      Extract all MessageTemplate's defined as fields in MessageTemplates sub-type (interface or class)
      Parameters:
      messageTemplatesType - the MessageTemplates sub-type (interface or class)
      skipMessageTemplateWithNoDefaultMessage - skip MessageTemplate where MessageTemplate.getDefaultMessage() is null
      Returns:
      the MessageTemplate's that match the criteria
    • key

      static MessageTemplate0 key(String messageKey, String defaultMessage)
      Create a message key (same as root(String)) with no parameters.
      Example:
      
       MessageTemplate0 ROOT = MessageTemplates.key("MY_SERVICE", "My Service ...");
       
      Parameters:
      messageKey - the message key
      defaultMessage - The default message
      Returns:
      the MessageTemplate
    • key

      static MessageTemplate0 key(String messageKey)
      Create a message key (same as root(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 as key(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 a MessageTemplates with 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 key
      defaultMessage - the default message
      Returns:
      a new MessageTemplate with MessageTemplate.getKey(): messageKey and the provided defaultMessage
    • key2

      static <PARAM_1, PARAM_2> MessageTemplate2<PARAM_1,PARAM_2> key2(String messageKey, String defaultMessage)
      Create a MessageTemplates with 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 0
      PARAM_2 - the type for the parameter with index 1
      Parameters:
      messageKey - the message key
      defaultMessage - the default message
      Returns:
      a new MessageTemplate with MessageTemplate.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 a MessageTemplates with 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 0
      PARAM_2 - the type for the parameter with index 1
      PARAM_3 - the type for the parameter with index 2
      Parameters:
      messageKey - the message key
      defaultMessage - the default message
      Returns:
      a new MessageTemplate with MessageTemplate.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 a MessageTemplates with 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 0
      PARAM_2 - the type for the parameter with index 1
      PARAM_3 - the type for the parameter with index 2
      PARAM_3 - the type for the parameter with index 3
      Parameters:
      messageKey - the message key
      defaultMessage - the default message
      Returns:
      a new MessageTemplate with MessageTemplate.getKey(): messageKey and the provided defaultMessage