Class Message

java.lang.Object
sailpoint.tools.xml.AbstractXmlObject
sailpoint.tools.Message
All Implemented Interfaces:
Serializable, sailpoint.tools.Localizable, sailpoint.tools.xml.PersistentXmlObject

public class Message extends sailpoint.tools.xml.AbstractXmlObject implements sailpoint.tools.Localizable, Serializable
A class containing all the elements needed to generate localized message text, including the key of the message and any parameters which should be injected into the message string.
See Also:
  • Constructor Details

    • Message

      public Message()
      Default constructor
    • Message

      public Message(String key, Object... args)
      Creates Message instance with given key and arguments. Message key can be a valid key from a resource bundle, or plain text. Message type is defaulted to Type.Info.
      Parameters:
      key - ResourceBundle essage key, or a plain text message
      args - message format args
    • Message

      public Message(Message.Type type, String key, Object... args)
      Creates a new instance for the given type, key and set of parameters.
      Parameters:
      type - Message type: Warn, Error, etc.
      key - ResourceBundle message key, or a plain text message
      args - Any parameters to be inserted into the message. The list can be made up of any object. If the parameter is another Message, it will be localized, if not we will call toString() to get the value.
    • Message

      public Message(Message.Type type, Throwable t)
      Creates a message for the given exception.

      If the throwable instance is an instance or subclass of sailpoint.tools.GeneralException the message is set using AbstractLocalizableException.getMessageInstance(). If the exception is any other type, a generic exception message is used, in the form of 'An unexpected error occurred: ' with the text from exception.getLocalizedMessage() used to populate the exception text parameter.

      Parameters:
      type - Message type: Warn, Error, etc. If null, Error is used.
      t - Exception instance to to create a message from. Can be null, but should not be.
  • Method Details

    • warn

      public static Message warn(String key, Object... args)
      Convenience constructors.
    • error

      public static Message error(String key, Object... args)
    • info

      public static Message info(String key, Object... args)
    • localize

      public static Message localize(String key)
      Localizes the given key. This method is ideally suited for use in Beanshell since Beanshell does not support varargs.
    • localize

      public static Message localize(String key, Object[] arguments)
      Localizes the given key with the given paramters. This method is ideally suited for use in Beanshell since Beanshell does not support varargs.
    • getMessage

      public String getMessage()
      Returns message localized in US english. Used for logging messages.
      Returns:
      Message localized for USofA.
    • getLocalizedMessage

      public String getLocalizedMessage()
      Gets message text localized for the default locale and server timezone.
      Specified by:
      getLocalizedMessage in interface sailpoint.tools.Localizable
      Returns:
      message localized for the default locale and timezone.
    • toString

      public String toString()
      Convenient so we can just print them.
      Overrides:
      toString in class Object
    • getLocalizedMessage

      public String getLocalizedMessage(Locale locale, TimeZone timezone)
      Creates localized text using the given locale and timezone.
      Specified by:
      getLocalizedMessage in interface sailpoint.tools.Localizable
      Parameters:
      locale - Locale to use. If null the default locale is used.
      timezone - TimeZone to use. If null the server timezone is used.
      Returns:
      localized message text.
    • getBundleMessage

      protected String getBundleMessage(String key, Locale locale)
      Gets message from the Internationalizer. This method is overridden in unit tests so that we do no rely on any external resource bundles.
      Parameters:
      key - The key to look up
      locale - Locale to
      Returns:
      String message for the given key and locale.
    • setKey

      public void setKey(String key)
      Sets the message key. If the key is not found in a resource bundle, it will be returned when the message is rendered, so the key argument can also be a plain text message.
      Parameters:
      key - ResourceBundle message key, or a plain text message
    • getKey

      public String getKey()
      Gets the message key. The key can be a valid key from a ResourceBundle, or plain text.
      Returns:
      Message key, or a plain text message
    • getType

      public Message.Type getType()
      Gets the type of message.
      Returns:
      Message type: Warn, Error, etc.
    • setType

      public void setType(Message.Type type)
      Sets the type of message.
      Parameters:
      type - Message type: Warn, Error, etc.
    • isType

      public boolean isType(Message.Type theType)
      Compares the given type to the instance's message type.
      Parameters:
      theType - The type to compare. If null, false is returned.
      Returns:
      True if theType matches the instances type.
    • isPlainText

      public boolean isPlainText()
      Returns true if the message is plain text and does not match an existing key in one of the message catalogs.
      Returns:
      true if the message does not match a key in the message catalogs.
    • setParameters

      public void setParameters(List<Object> parameters)
      Sets parameters to insert into the message when it is rendered. These parameters can be other Message instances, LocalizedDates Dates, Numbers, String or Throwables. Any other object will be converted to a string using the toString() method. Nulls are treated as an empty string.
      Parameters:
      parameters - Parameters to insert into the message
    • getParameters

      public List<Object> getParameters()
      Gets parameters to insert into the message when it is rendered. These parameters can be other Message instances, LocalizedDates Dates, Numbers, String or Throwables. Any other object will be converted to a string using the toString() method. Nulls are treated as an empty string.
      Returns:
      Parameters to insert into the message
    • getMaxLength

      public Integer getMaxLength()
      Maximum size of the resulting message text string. If Null message will not be truncated.
    • setMaxLength

      public void setMaxLength(Integer maxLength)
      Maximum size of the string. Resulting message text will be truncated at this length and formatted into MessageKeys.MSG_TRUNCATED. !!Note that that the formatted message can be longer than the maxlength due to the addition of the content of MSG_TRUNCATED.
    • isError

      public boolean isError()
      Convenience method to determine if this message is an error.
      Returns:
      True if message Type==Error
    • isWarning

      public boolean isWarning()
      Convenience method to determine if this message is a warning.
      Returns:
      True if message Type==Warn
    • equals

      public boolean equals(Object other)
      For comparing messages for equality test to see if the key, type and parameters are equal.
      Overrides:
      equals in class Object