Class Message
- java.lang.Object
-
- de.hybris.platform.sap.core.common.message.Message
-
- All Implemented Interfaces:
java.io.Serializable
- Direct Known Subclasses:
OrderMgmtMessage
public class Message extends java.lang.Object implements java.io.SerializableThe 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.
getMessageText(Locale)can be used to get the message text in any case.- See Also:
MessageList,ModuleResourceAccess, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static intDEBUGConstant to define message type debug.static intERRORConstant to define message type success.static intINFOConstant to define message type info.static intINITIALConstant to define initial value.static intSUCCESSConstant to define message type success.static intWARNINGConstant to define message type warning.
-
Constructor Summary
Constructors Constructor Description Message(int type)Constructor to create a message with a given type.Message(int type, java.lang.String key)Constructor to create a message only with resource key.Message(int type, java.lang.String key, java.lang.String property)Constructor to create a message with a resource key without args.Message(int type, java.lang.String key, java.lang.String[] args, java.lang.String property)Constructor to create a message with a resource key.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object obj)Overwrites the method of the object class.java.lang.StringgetDescription()Gets the description of the message.java.lang.StringgetFieldId()Gets the field id.java.lang.StringgetMessageText()Determine the message text for the default locale given withLocale.getDefault().java.lang.StringgetMessageText(java.util.Locale locale)Determines the message text for the given locale.java.lang.StringgetPageLocation()Gets the page location of the message.java.lang.StringgetPosition()Gets the position of the message.java.lang.StringgetProperty()Gets the name of the property to which the message belongs.TechKeygetRefTechKey()Returns the property refTechKey.java.lang.String[]getResourceArgs()Returns the property resourceArgs.java.lang.StringgetResourceKey()Returns the property resourceKey.TechKeygetTechKey()Returns the technical key of the message.intgetType()Returns the type of the message.inthashCode()Returns hash code for the message.booleanisError()Returns if the message is an error message.booleanisInfo()booleanisWarning()Returns if the message is a warning.voidlog(org.apache.log4j.Logger logger)Logs the message in the given logger.voidsetDescription(java.lang.String description)Sets the description of the message.voidsetFieldId(java.lang.String fieldId)Sets the field id.voidsetModuleResourceAccess(ModuleResourceAccess moduleResourceAccess)Sets the module resource access from outside (optional, e.g.voidsetPageLocation(java.lang.String pagelocation)Sets the page location of the message.voidsetPosition(java.lang.String position)Sets the position of the message.voidsetProperty(java.lang.String property)Sets the name of the property to which the message belongs.voidsetRefTechKey(TechKey refTechKey)Sets the property refTechKey.voidsetResourceArgs(java.lang.String[] resourceArgs)Sets the property resourceArgs.voidsetResourceKey(java.lang.String resourceKey)Sets the property resourceKey.voidsetTechKey(TechKey techKey)Sets the techKey of the message.java.lang.StringtoString()Returns the object as string.
-
-
-
Field Detail
-
INITIAL
public static final int INITIAL
Constant to define initial value.- See Also:
- Constant Field Values
-
SUCCESS
public static final int SUCCESS
Constant to define message type success.- See Also:
- Constant Field Values
-
ERROR
public static final int ERROR
Constant to define message type success.- See Also:
- Constant Field Values
-
WARNING
public static final int WARNING
Constant to define message type warning.- See Also:
- Constant Field Values
-
INFO
public static final int INFO
Constant to define message type info.- See Also:
- Constant Field Values
-
DEBUG
public static final int DEBUG
Constant to define message type debug.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Message
public Message(int type, java.lang.String key, java.lang.String[] args, java.lang.String property)Constructor to create a message with a resource key.- Parameters:
type- message typekey- resource key to the message textargs- 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, java.lang.String key, java.lang.String property)Constructor to create a message with a resource key without args.- Parameters:
type- message typekey- resource key to the message textproperty- name of property of a bean
-
Message
public Message(int type, java.lang.String key)Constructor to create a message only with resource key.- Parameters:
type- message typekey- resource key to the message text
-
-
Method Detail
-
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 java.lang.String getMessageText(java.util.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:
ModuleResourceAccess
-
getMessageText
public java.lang.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 java.lang.String getDescription()
Gets the description of the message.- Returns:
- description of the message
-
setDescription
public void setDescription(java.lang.String description)
Sets the description of the message.- Parameters:
description- Description of the message
-
getPageLocation
public java.lang.String getPageLocation()
Gets the page location of the message.- Returns:
- The page location
-
setPageLocation
public void setPageLocation(java.lang.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 java.lang.String getPosition()
Gets the position of the message.- Returns:
- return the exact position where the message occurs
-
setPosition
public void setPosition(java.lang.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(java.lang.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 java.lang.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(java.lang.String resourceKey)
Sets the property resourceKey.- Parameters:
resourceKey- resource key
-
getResourceKey
public java.lang.String getResourceKey()
Returns the property resourceKey.- Returns:
- resource key
-
setResourceArgs
public void setResourceArgs(java.lang.String[] resourceArgs)
Sets the property resourceArgs.- Parameters:
resourceArgs- resource key arguments
-
getResourceArgs
public java.lang.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(java.lang.Object obj)
Overwrites the method of the object class.- Overrides:
equalsin classjava.lang.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:
hashCodein classjava.lang.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 java.lang.String toString()
Returns the object as string.- Overrides:
toStringin classjava.lang.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 java.lang.String getFieldId()
Gets the field id.- Returns:
- field id
-
setFieldId
public void setFieldId(java.lang.String fieldId)
Sets the field id.- Parameters:
fieldId- field id
-
-