java.lang.Object
de.hybris.platform.sap.core.common.message.Message
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
OrderMgmtMessage

public class Message extends Object implements Serializable
The Message class helps you to handle messages which can by displayed on the UI or logged in the log file.

To create the message you give the type, the resource key and optional the name of a property.

The message text itself can be defined in to different ways:

  • Resource key: The resource key needs to be defined as described in ModuleResourceAccess. .
  • Message description: This is best approach if you already have a translated message description e.g. provided from the back end.
The method getMessageText(Locale) can be used to get the message text in any case.

See Also:
  • Field Details

    • INITIAL

      public static final int INITIAL
      Constant to define initial value.
      See Also:
    • SUCCESS

      public static final int SUCCESS
      Constant to define message type success.
      See Also:
    • ERROR

      public static final int ERROR
      Constant to define message type success.
      See Also:
    • WARNING

      public static final int WARNING
      Constant to define message type warning.
      See Also:
    • INFO

      public static final int INFO
      Constant to define message type info.
      See Also:
    • DEBUG

      public static final int DEBUG
      Constant to define message type debug.
      See Also:
  • Constructor Details

    • Message

      public Message(int type, String key, String[] args, String property)
      Constructor to create a message with a resource key.
      Parameters:
      type - message type
      key - resource key to the message text
      args - an array of arguments.
      property - name of property of a bean (only if property isn't null)
    • Message

      public Message(int type)
      Constructor to create a message with a given type.
      Parameters:
      type - message type
    • Message

      public Message(int type, String key, String property)
      Constructor to create a message with a resource key without args.
      Parameters:
      type - message type
      key - resource key to the message text
      property - name of property of a bean
    • Message

      public Message(int type, String key)
      Constructor to create a message only with resource key.
      Parameters:
      type - message type
      key - resource key to the message text
  • Method Details

    • setModuleResourceAccess

      public void setModuleResourceAccess(ModuleResourceAccess moduleResourceAccess)
      Sets the module resource access from outside (optional, e.g. for tests)
      Parameters:
      moduleResourceAccess - module resource access
    • getMessageText

      public String getMessageText(Locale locale)
      Determines the message text for the given locale.

      The method checks first, if the there is a resourceKey is defined. If so, this is used to get a translated message text with the ModuleResourceAccess. If not, the message description, which is independent from the given locale, is used.

      Parameters:
      locale - locale to get the correct translation.
      Returns:
      the translated message
      See Also:
    • getMessageText

      public String getMessageText()

      Determine the message text for the default locale given with Locale.getDefault().

      For further details take a look at getMessageText(Locale)

      Returns:
      translated message tag
    • getDescription

      public String getDescription()
      Gets the description of the message.
      Returns:
      description of the message
    • setDescription

      public void setDescription(String description)
      Sets the description of the message.
      Parameters:
      description - Description of the message
    • getPageLocation

      public String getPageLocation()
      Gets the page location of the message.
      Returns:
      The page location
    • setPageLocation

      public void setPageLocation(String pagelocation)
      Sets the page location of the message.

      The page location is used in the accessibility mode to describe, where the error occurs. Please define a resource key access.message.location. for your page locations.

      Parameters:
      pagelocation - Location where the message occurs
    • getPosition

      public String getPosition()
      Gets the position of the message.
      Returns:
      return the exact position where the message occurs
    • setPosition

      public void setPosition(String position)
      Sets the position of the message.
      Parameters:
      position - Exact position where the message occurs
    • isError

      public boolean isError()
      Returns if the message is an error message.
      Returns:
      true if the message is an error message
    • isWarning

      public boolean isWarning()
      Returns if the message is a warning.
      Returns:
      true if the message is a warning
    • isInfo

      public boolean isInfo()
    • setProperty

      public void setProperty(String property)
      Sets the name of the property to which the message belongs.
      Parameters:
      property - name of the property to which the message belongs (only if property isn't null)
    • getProperty

      public String getProperty()
      Gets the name of the property to which the message belongs.
      Returns:
      field name of the property to which the message belongs
    • setRefTechKey

      public void setRefTechKey(TechKey refTechKey)
      Sets the property refTechKey.
      Parameters:
      refTechKey - techKey for object to which belongs the message. is only for message which can not directly assign to the corresponding business object.
    • getRefTechKey

      public TechKey getRefTechKey()
      Returns the property refTechKey.
      Returns:
      refTechKey
    • setResourceKey

      public void setResourceKey(String resourceKey)
      Sets the property resourceKey.
      Parameters:
      resourceKey - resource key
    • getResourceKey

      public String getResourceKey()
      Returns the property resourceKey.
      Returns:
      resource key
    • setResourceArgs

      public void setResourceArgs(String[] resourceArgs)
      Sets the property resourceArgs.
      Parameters:
      resourceArgs - resource key arguments
    • getResourceArgs

      public String[] getResourceArgs()
      Returns the property resourceArgs.
      Returns:
      resource key arguments
    • getType

      public int getType()
      Returns the type of the message.
      Returns:
      The type of the message
    • equals

      public boolean equals(Object obj)
      Overwrites the method of the object class.
      Overrides:
      equals in class Object
      Parameters:
      obj - the object which will be compare with the object
      Returns:
      true if the objects are equal
    • hashCode

      public int hashCode()
      Returns hash code for the message.
      Overrides:
      hashCode in class Object
      Returns:
      hash code of the objects
    • log

      public void log(org.apache.log4j.Logger logger)
      Logs the message in the given logger.
      Parameters:
      logger - logger
    • toString

      public String toString()
      Returns the object as string.
      Overrides:
      toString in class Object
      Returns:
      String which contains all fields of the object
    • getTechKey

      public TechKey getTechKey()
      Returns the technical key of the message. For CRM or ERP messages the technical key consists of the message ID and message number separated by space (e.g. "CRM_ORDER 002").
      Returns:
      the techKey
    • setTechKey

      public void setTechKey(TechKey techKey)
      Sets the techKey of the message.
      Parameters:
      techKey - the techKey to set
    • getFieldId

      public String getFieldId()
      Gets the field id.
      Returns:
      field id
    • setFieldId

      public void setFieldId(String fieldId)
      Sets the field id.
      Parameters:
      fieldId - field id