Class Message
- All Implemented Interfaces:
Serializable
In addition a message provides access to the objects and their properties the message relates to. E.g. if a message reads that "insured person's age must be at least 18" than the person's age is invalid. This information can be used for example to mark controls in the UI that display this property.
If the provided message has replacement parameters that cannot be evaluated while creating the
message text, it is possible to provide there parameters to the message object. Have a look at
MsgReplacementParameter for further information.
If you need any further information stored with the message, it is possible to implement the IMarker object and provide some additional markers to the message. The exact use of the markers depends on the custom implementation.
Message is an immutable value object. Two message objects are considered equal if they have the same severity, code, text, "invalid properties" and replacement parameters.
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new message by defining the following parameters.Creates a new message by defining the following parameters.Message(String code, String text, Severity severity, Object invalidObject, String... invalidObjectProperties) Creates a new message by defining the following parameters.Creates a new message by defining the following parameters.Message(String code, String text, Severity severity, List<ObjectProperty> invalidObjectProperties, List<MsgReplacementParameter> replacementParameters) Creates a new message by defining the following parameters.Message(String code, String text, Severity severity, List<ObjectProperty> invalidObjectProperties, List<MsgReplacementParameter> parameters, Set<? extends IMarker> markers) Creates a new message by defining the following parameters.Message(String code, String text, Severity severity, ObjectProperty invalidObjectProperty) Creates a new message by defining the following parameters.Message(String code, String text, Severity severity, ObjectProperty... invalidObjectProperties) Creates a new message by defining the following parameters.Message(String code, String text, Severity severity, ObjectProperty[] invalidObjectProperties, MsgReplacementParameter[] parameters) Creates a new message by defining the following parameters.Message(String code, String text, Severity severity, ObjectProperty invalidObjectProperty, List<MsgReplacementParameter> parameters) Creates a new message by defining the following parameters.Message(String code, String text, Severity severity, ObjectProperty invalidObjectProperty, MsgReplacementParameter... parameters) Creates a new message by defining the following parameters.Creates a new message by defining the following parameters.Creates a new message by copying everything of the givenMessage.Message(Message.Builder builder) Creates a new message by using the fields of aMessage.Builder. -
Method Summary
Modifier and TypeMethodDescriptionvoidstatic final MessagecreateCopy(Message msg, Object oldObject, Object newObject) Creates a copy from the message and replaces all references to the old object with the new object.static final MessagecreateCopy(Message msg, Map<ObjectProperty, ObjectProperty> objectPropertyMap) Creates and returns a copy of the given message and replaces all references to the old object with the new object.booleanReturns true if o is a Message and severity, code and text are equal.static final Message.BuilderCreates a newMessage.BuilderwithERRORand the given message.getCode()Returns the list of object properties the message refers to.Returns a set ofIMarkers associated with this class.intReturns the number of referenced invalid object properties.intReturns the number of replacement parameters..Returns the list of replacement parameters.getReplacementValue(String paramName) Returns the value for the given replacement parameter.Returns the message's severity as one of the constants ERROR, WARNING, INFO or NONE.getText()inthashCode()booleanbooleanReturnstrueif the message has markers otherwisefalse.booleanhasReplacementParameter(String paramName) Returnstrueif the message has a replacement parameter with the given name, otherwisefalse.static final Message.BuilderCreates a newMessage.BuilderwithINFOand the given message.static final MessageConstructs and returns a new error message.static final MessageConstructs and returns a new error message.static final MessagenewError(String code, String text, ObjectProperty... invalidObjectProperty) Constructs and returns a new error message.static final MessageConstructs and returns a new information message.static final MessageConstructs and returns a new information message.static final MessagenewWarning(String code, String text) Constructs and returns a new warning message.static final MessagenewWarning(String code, String text, Object invalidObject) Constructs and returns a new warning message.static final MessagenewWarning(String code, String text, Object invalidObject, String... invalidProperties) Constructs and returns a new warning message.toString()static final Message.BuilderCreates a newMessage.BuilderwithWARNINGand the given message.
-
Field Details
-
NONE
Severity none. -
INFO
Severity info. -
WARNING
Severity warning. -
ERROR
Severity error.
-
-
Constructor Details
-
Message
Creates a new message by using the fields of aMessage.Builder.- Parameters:
builder- theMessage.Builder
-
Message
Creates a new message by copying everything of the givenMessage.- Parameters:
msg- theMessageto copy from
-
Message
Creates a new message by defining the following parameters. -
Message
Creates a new message by defining the following parameters. -
Message
Creates a new message by defining the following parameters. -
Message
Creates a new message by defining the following parameters. -
Message
public Message(String code, String text, Severity severity, Object invalidObject, String... invalidObjectProperties) Creates a new message by defining the following parameters.- Parameters:
code- A message code that identifies the kind of the messagetext- The human readable text of this messageseverity- The message's severity:ERROR,WARNINGorINFO:ERROR,WARNINGorINFOinvalidObject- the Object of the ObjectPropertyinvalidObjectProperties- An array of propertie's names the message refers to
-
Message
public Message(String code, String text, Severity severity, ObjectProperty... invalidObjectProperties) Creates a new message by defining the following parameters. -
Message
public Message(String code, String text, Severity severity, List<ObjectProperty> invalidObjectProperties) Creates a new message by defining the following parameters. -
Message
public Message(String code, String text, Severity severity, List<ObjectProperty> invalidObjectProperties, List<MsgReplacementParameter> replacementParameters) Creates a new message by defining the following parameters. -
Message
public Message(String code, String text, Severity severity, ObjectProperty invalidObjectProperty, MsgReplacementParameter... parameters) Creates a new message by defining the following parameters.- Parameters:
code- A message code that identifies the kind of the messagetext- The human readable text of this messageseverity- The message's severity:ERROR,WARNINGorINFOinvalidObjectProperty- A list of object properties the message refers toparameters- an array of replacement parameters
-
Message
public Message(String code, String text, Severity severity, ObjectProperty invalidObjectProperty, List<MsgReplacementParameter> parameters) Creates a new message by defining the following parameters. -
Message
public Message(String code, String text, Severity severity, ObjectProperty[] invalidObjectProperties, MsgReplacementParameter[] parameters) Creates a new message by defining the following parameters.- Parameters:
code- A message code that identifies the kind of the messagetext- The human readable text of this messageseverity- The message's severity:ERROR,WARNINGorINFOinvalidObjectProperties- An array of object properties the message refers toparameters- an array of replacement parameters
-
Message
public Message(String code, String text, Severity severity, List<ObjectProperty> invalidObjectProperties, List<MsgReplacementParameter> parameters, Set<? extends IMarker> markers) Creates a new message by defining the following parameters.- Parameters:
code- A message code that identifies the kind of the messagetext- The human readable text of this messageseverity- The message's severity:ERROR,WARNINGorINFOinvalidObjectProperties- A list of object properties the message refers toparameters- a list of replacement parametersmarkers- a list of markers. If this parameter is null an empty list is set as markers. The List of markers is
-
-
Method Details
-
error
Creates a newMessage.BuilderwithERRORand the given message.To create a new
Messageyou can use for example:
Message.error("MessageText").code("1").invalidObjects("object", "property").create();- Parameters:
text- The human readable text of this message
-
warning
Creates a newMessage.BuilderwithWARNINGand the given message.To create a new
Messageyou can use for example:
Message.warning("MessageText").code("1").invalidObjects("object", "property").create();- Parameters:
text- The human readable text of this message
-
info
Creates a newMessage.BuilderwithINFOand the given message.To create a new
Messageyou can use for example:
Message.info("MessageText").code("1").invalidObjects("object", "property").create();- Parameters:
text- The human readable text of this message
-
createCopy
Creates a copy from the message and replaces all references to the old object with the new object. -
createCopy
public static final Message createCopy(Message msg, Map<ObjectProperty, ObjectProperty> objectPropertyMap) Creates and returns a copy of the given message and replaces all references to the old object with the new object.- Parameters:
objectPropertyMap- TheMapbetween old and newObjectProperty- Returns:
- Message
-
newInfo
Constructs and returns a new information message.- Parameters:
code- The code that identifies the message.text- The human readable text of the message.
-
newInfo
public static final Message newInfo(String code, String text, Object invalidObject, String invalidProperty) Constructs and returns a new information message.- Parameters:
code- The code that identifies the message.text- The human readable text of the message.invalidObject- The invalid objectinvalidProperty- The name of the invalid property (which is a property of the invalidObject)
-
newWarning
Constructs and returns a new warning message.- Parameters:
code- The code that identifies the message.text- The human readable text of the message.
-
newWarning
Constructs and returns a new warning message.- Parameters:
code- The code that identifies the message.text- The human readable text of the message.invalidObject- The invalid object
-
newWarning
public static final Message newWarning(String code, String text, Object invalidObject, String... invalidProperties) Constructs and returns a new warning message.- Parameters:
code- The code that identifies the message.text- The human readable text of the message.invalidObject- The invalid objectinvalidProperties- The name of the invalid properties (which are properties of the invalidObject)
-
newError
Constructs and returns a new error message.- Parameters:
code- The code that identifies the message.text- The human readable text of the message.
-
newError
public static final Message newError(String code, String text, Object invalidObject, String... invalidProperties) Constructs and returns a new error message.- Parameters:
code- The code that identifies the message.text- The human readable text of the message.invalidObject- The invalid object to refer to.invalidProperties- The name of the invalid properties (which are properties of the invalidObject)
-
newError
public static final Message newError(String code, String text, ObjectProperty... invalidObjectProperty) Constructs and returns a new error message.- Parameters:
code- The code that identifies the message.text- The human readable text of the message.invalidObjectProperty- The invalid object properties to refer to.
-
getSeverity
Returns the message's severity as one of the constants ERROR, WARNING, INFO or NONE. -
getText
-
getCode
-
getNumOfInvalidObjectProperties
public int getNumOfInvalidObjectProperties()Returns the number of referenced invalid object properties. -
getInvalidObjectProperties
Returns the list of object properties the message refers to. E.g. if a message reads "The driver's age must be greater than 18.", this method would probably return the driver object and the property name age. Returns an empty list if this message does not refer to any objects / properties. -
getNumOfReplacementParameters
public int getNumOfReplacementParameters()Returns the number of replacement parameters.. -
getReplacementParameters
Returns the list of replacement parameters. Returns an empty list if this message hasn't got any replacements. -
hasReplacementParameter
Returnstrueif the message has a replacement parameter with the given name, otherwisefalse. Returnsfalseif paramName isnull. -
getReplacementValue
Returns the value for the given replacement parameter. Returnsnullif the message hasn't got a parameter with the indicated name.- See Also:
-
getMarkers
Returns a set ofIMarkers associated with this class. Returns an empty set if no markers are set. -
hasMarker
-
hasMarkers
public boolean hasMarkers()Returnstrueif the message has markers otherwisefalse. -
toString
-
appendInvalidObjectProperties
-
equals
Returns true if o is a Message and severity, code and text are equal. -
hashCode
public int hashCode()
-