Class Message

  • All Implemented Interfaces:
    java.io.Serializable

    public class Message
    extends java.lang.Object
    implements java.io.Serializable
    A human readable text message with an optional code that identifies the type of the message and a severity that indicates if this is an error, warning or information.

    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:
    MsgReplacementParameter, Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Message.Builder
      A builder for the Message class.
    • Constructor Summary

      Constructors 
      Constructor Description
      Message​(java.lang.String code, java.lang.String text, Severity severity)
      Creates a new message by defining the following parameters.
      Message​(java.lang.String code, java.lang.String text, Severity severity, java.lang.Object invalidObject)
      Creates a new message by defining the following parameters.
      Message​(java.lang.String code, java.lang.String text, Severity severity, java.lang.Object invalidObject, java.lang.String... invalidObjectProperties)
      Creates a new message by defining the following parameters.
      Message​(java.lang.String code, java.lang.String text, Severity severity, java.util.List<ObjectProperty> invalidObjectProperties)
      Creates a new message by defining the following parameters.
      Message​(java.lang.String code, java.lang.String text, Severity severity, java.util.List<ObjectProperty> invalidObjectProperties, java.util.List<MsgReplacementParameter> replacementParameters)
      Creates a new message by defining the following parameters.
      Message​(java.lang.String code, java.lang.String text, Severity severity, java.util.List<ObjectProperty> invalidObjectProperties, java.util.List<MsgReplacementParameter> parameters, java.util.Set<? extends IMarker> markers)
      Creates a new message by defining the following parameters.
      Message​(java.lang.String code, java.lang.String text, Severity severity, ObjectProperty invalidObjectProperty)
      Creates a new message by defining the following parameters.
      Message​(java.lang.String code, java.lang.String text, Severity severity, ObjectProperty... invalidObjectProperties)
      Creates a new message by defining the following parameters.
      Message​(java.lang.String code, java.lang.String text, Severity severity, ObjectProperty[] invalidObjectProperties, MsgReplacementParameter[] parameters)
      Creates a new message by defining the following parameters.
      Message​(java.lang.String code, java.lang.String text, Severity severity, ObjectProperty invalidObjectProperty, java.util.List<MsgReplacementParameter> parameters)
      Creates a new message by defining the following parameters.
      Message​(java.lang.String code, java.lang.String text, Severity severity, ObjectProperty invalidObjectProperty, MsgReplacementParameter... parameters)
      Creates a new message by defining the following parameters.
      Message​(java.lang.String text, Severity severity)
      Creates a new message by defining the following parameters.
      Message​(Message msg)
      Creates a new message by copying everything of the given Message.
      Message​(Message.Builder builder)
      Creates a new message by using the fields of a Message.Builder.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static Message createCopy​(Message msg, java.lang.Object oldObject, java.lang.Object newObject)
      Creates a copy from the message and replaces all references to the old object with the new object.
      static Message createCopy​(Message msg, java.util.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.
      boolean equals​(java.lang.Object o)
      Returns true if o is a Message and severity, code and text are equal.
      static Message.Builder error​(java.lang.String text)
      Creates a new Message.Builder with ERROR and the given message.
      java.lang.String getCode()  
      java.util.List<ObjectProperty> getInvalidObjectProperties()
      Returns the list of object properties the message refers to.
      java.util.Set<? extends IMarker> getMarkers()
      Returns a set of IMarkers associated with this class.
      int getNumOfInvalidObjectProperties()
      Returns the number of referenced invalid object properties.
      int getNumOfReplacementParameters()
      Returns the number of replacement parameters..
      java.util.List<MsgReplacementParameter> getReplacementParameters()
      Returns the list of replacement parameters.
      java.lang.Object getReplacementValue​(java.lang.String paramName)
      Returns the value for the given replacement parameter.
      Severity getSeverity()
      Returns the message's severity as one of the constants ERROR, WARNING, INFO or NONE.
      java.lang.String getText()  
      int hashCode()  
      boolean hasMarker​(IMarker marker)
      Returns true if the message contains the specified IMarker marker otherwise false.
      boolean hasMarkers()
      Returns true if the message has markers otherwise false.
      boolean hasReplacementParameter​(java.lang.String paramName)
      Returns true if the message has a replacement parameter with the given name, otherwise false.
      static Message.Builder info​(java.lang.String text)
      Creates a new Message.Builder with INFO and the given message.
      static Message newError​(java.lang.String code, java.lang.String text)
      Constructs and returns a new error message.
      static Message newError​(java.lang.String code, java.lang.String text, java.lang.Object invalidObject, java.lang.String... invalidProperties)
      Constructs and returns a new error message.
      static Message newError​(java.lang.String code, java.lang.String text, ObjectProperty... invalidObjectProperty)
      Constructs and returns a new error message.
      static Message newInfo​(java.lang.String code, java.lang.String text)
      Constructs and returns a new information message.
      static Message newInfo​(java.lang.String code, java.lang.String text, java.lang.Object invalidObject, java.lang.String invalidProperty)
      Constructs and returns a new information message.
      static Message newWarning​(java.lang.String code, java.lang.String text)
      Constructs and returns a new warning message.
      static Message newWarning​(java.lang.String code, java.lang.String text, java.lang.Object invalidObject)
      Constructs and returns a new warning message.
      static Message newWarning​(java.lang.String code, java.lang.String text, java.lang.Object invalidObject, java.lang.String... invalidProperties)
      Constructs and returns a new warning message.
      java.lang.String toString()  
      static Message.Builder warning​(java.lang.String text)
      Creates a new Message.Builder with WARNING and the given message.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • NONE

        public static final Severity NONE
        Severity none.
      • INFO

        public static final Severity INFO
        Severity info.
      • WARNING

        public static final Severity WARNING
        Severity warning.
      • ERROR

        public static final Severity ERROR
        Severity error.
    • Constructor Detail

      • Message

        public Message​(Message msg)
        Creates a new message by copying everything of the given Message.
        Parameters:
        msg - the Message to copy from
      • Message

        public Message​(java.lang.String text,
                       Severity severity)
        Creates a new message by defining the following parameters.
        Parameters:
        text - The human readable text of this message
        severity - The message's severity: ERROR, WARNING or INFO
      • Message

        public Message​(java.lang.String code,
                       java.lang.String text,
                       Severity severity)
        Creates a new message by defining the following parameters.
        Parameters:
        code - A message code that identifies the kind of the message
        text - The human readable text of this message
        severity - The message's severity: ERROR, WARNING or INFO
      • Message

        public Message​(java.lang.String code,
                       java.lang.String text,
                       Severity severity,
                       java.lang.Object invalidObject)
        Creates a new message by defining the following parameters.
        Parameters:
        code - A message code that identifies the kind of the message
        text - The human readable text of this message
        severity - The message's severity: ERROR, WARNING or INFO
        invalidObject - An object properties the message refers to
      • Message

        public Message​(java.lang.String code,
                       java.lang.String text,
                       Severity severity,
                       ObjectProperty invalidObjectProperty)
        Creates a new message by defining the following parameters.
        Parameters:
        code - A message code that identifies the kind of the message
        text - The human readable text of this message
        severity - The message's severity: ERROR, WARNING or INFO
        invalidObjectProperty - An object property the message refers to
      • Message

        public Message​(java.lang.String code,
                       java.lang.String text,
                       Severity severity,
                       java.lang.Object invalidObject,
                       java.lang.String... invalidObjectProperties)
        Creates a new message by defining the following parameters.
        Parameters:
        code - A message code that identifies the kind of the message
        text - The human readable text of this message
        severity - The message's severity: ERROR, WARNING or INFO: ERROR, WARNING or INFO
        invalidObject - the Object of the ObjectProperty
        invalidObjectProperties - An array of propertie's names the message refers to
      • Message

        public Message​(java.lang.String code,
                       java.lang.String text,
                       Severity severity,
                       ObjectProperty... invalidObjectProperties)
        Creates a new message by defining the following parameters.
        Parameters:
        code - A message code that identifies the kind of the message
        text - The human readable text of this message
        severity - The message's severity: ERROR, WARNING or INFO
        invalidObjectProperties - An array of object properties the message refers to
      • Message

        public Message​(java.lang.String code,
                       java.lang.String text,
                       Severity severity,
                       java.util.List<ObjectProperty> invalidObjectProperties)
        Creates a new message by defining the following parameters.
        Parameters:
        code - A message code that identifies the kind of the message
        text - The human readable text of this message
        severity - The message's severity: ERROR, WARNING or INFO
        invalidObjectProperties - A list of object properties the message refers to
      • Message

        public Message​(java.lang.String code,
                       java.lang.String text,
                       Severity severity,
                       java.util.List<ObjectProperty> invalidObjectProperties,
                       java.util.List<MsgReplacementParameter> replacementParameters)
        Creates a new message by defining the following parameters.
        Parameters:
        code - A message code that identifies the kind of the message
        text - The human readable text of this message
        severity - The message's severity: ERROR, WARNING or INFO
        invalidObjectProperties - A list of object properties the message refers to
      • Message

        public Message​(java.lang.String code,
                       java.lang.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 message
        text - The human readable text of this message
        severity - The message's severity: ERROR, WARNING or INFO
        invalidObjectProperty - A list of object properties the message refers to
        parameters - an array of replacement parameters
      • Message

        public Message​(java.lang.String code,
                       java.lang.String text,
                       Severity severity,
                       ObjectProperty invalidObjectProperty,
                       java.util.List<MsgReplacementParameter> parameters)
        Creates a new message by defining the following parameters.
        Parameters:
        code - A message code that identifies the kind of the message
        text - The human readable text of this message
        severity - The message's severity: ERROR, WARNING or INFO
        invalidObjectProperty - An object properties the message refers to
        parameters - a list of replacement parameters
      • Message

        public Message​(java.lang.String code,
                       java.lang.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 message
        text - The human readable text of this message
        severity - The message's severity: ERROR, WARNING or INFO
        invalidObjectProperties - An array of object properties the message refers to
        parameters - an array of replacement parameters
      • Message

        public Message​(java.lang.String code,
                       java.lang.String text,
                       Severity severity,
                       java.util.List<ObjectProperty> invalidObjectProperties,
                       java.util.List<MsgReplacementParameter> parameters,
                       java.util.Set<? extends IMarker> markers)
        Creates a new message by defining the following parameters.
        Parameters:
        code - A message code that identifies the kind of the message
        text - The human readable text of this message
        severity - The message's severity: ERROR, WARNING or INFO
        invalidObjectProperties - A list of object properties the message refers to
        parameters - a list of replacement parameters
        markers - a list of markers. If this parameter is null an empty list is set as markers. The List of markers is
    • Method Detail

      • error

        public static final Message.Builder error​(java.lang.String text)
        Creates a new Message.Builder with ERROR and the given message.

        To create a new Message you can use for example:
        Message.error("MessageText").code("1").invalidObjects("object", "property").create();

        Parameters:
        text - The human readable text of this message
      • warning

        public static final Message.Builder warning​(java.lang.String text)
        Creates a new Message.Builder with WARNING and the given message.

        To create a new Message you can use for example:
        Message.warning("MessageText").code("1").invalidObjects("object", "property").create();

        Parameters:
        text - The human readable text of this message
      • info

        public static final Message.Builder info​(java.lang.String text)
        Creates a new Message.Builder with INFO and the given message.

        To create a new Message you can use for example:
        Message.info("MessageText").code("1").invalidObjects("object", "property").create();

        Parameters:
        text - The human readable text of this message
      • createCopy

        public static final Message createCopy​(Message msg,
                                               java.lang.Object oldObject,
                                               java.lang.Object newObject)
        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,
                                               java.util.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 - The Map between old and new ObjectProperty
        Returns:
        Message
      • newInfo

        public static final Message newInfo​(java.lang.String code,
                                            java.lang.String text)
        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​(java.lang.String code,
                                            java.lang.String text,
                                            java.lang.Object invalidObject,
                                            java.lang.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 object
        invalidProperty - The name of the invalid property (which is a property of the invalidObject)
      • newWarning

        public static final Message newWarning​(java.lang.String code,
                                               java.lang.String text)
        Constructs and returns a new warning message.
        Parameters:
        code - The code that identifies the message.
        text - The human readable text of the message.
      • newWarning

        public static final Message newWarning​(java.lang.String code,
                                               java.lang.String text,
                                               java.lang.Object invalidObject)
        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​(java.lang.String code,
                                               java.lang.String text,
                                               java.lang.Object invalidObject,
                                               java.lang.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 object
        invalidProperties - The name of the invalid properties (which are properties of the invalidObject)
      • newError

        public static final Message newError​(java.lang.String code,
                                             java.lang.String text)
        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​(java.lang.String code,
                                             java.lang.String text,
                                             java.lang.Object invalidObject,
                                             java.lang.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​(java.lang.String code,
                                             java.lang.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

        public Severity getSeverity()
        Returns the message's severity as one of the constants ERROR, WARNING, INFO or NONE.
      • getText

        public java.lang.String getText()
      • getCode

        public java.lang.String getCode()
      • getNumOfInvalidObjectProperties

        public int getNumOfInvalidObjectProperties()
        Returns the number of referenced invalid object properties.
      • getInvalidObjectProperties

        public java.util.List<ObjectProperty> 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

        public java.util.List<MsgReplacementParameter> getReplacementParameters()
        Returns the list of replacement parameters. Returns an empty list if this message hasn't got any replacements.
      • hasReplacementParameter

        public boolean hasReplacementParameter​(java.lang.String paramName)
        Returns true if the message has a replacement parameter with the given name, otherwise false. Returns false if paramName is null.
      • getReplacementValue

        public java.lang.Object getReplacementValue​(java.lang.String paramName)
        Returns the value for the given replacement parameter. Returns null if the message hasn't got a parameter with the indicated name.
        See Also:
        hasReplacementParameter(String)
      • getMarkers

        public java.util.Set<? extends IMarker> getMarkers()
        Returns a set of IMarkers associated with this class. Returns an empty set if no markers are set.
      • hasMarker

        public boolean hasMarker​(IMarker marker)
        Returns true if the message contains the specified IMarker marker otherwise false.
      • hasMarkers

        public boolean hasMarkers()
        Returns true if the message has markers otherwise false.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object o)
        Returns true if o is a Message and severity, code and text are equal.
        Overrides:
        equals in class java.lang.Object
        See Also:
        Object.equals(java.lang.Object)
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object