Class Messages

java.lang.Object
com.echothree.util.common.message.Messages
All Implemented Interfaces:
Serializable

public class Messages extends Object implements Serializable

A class that encapsulates messages. Messages can be either global or they are specific to a particular bean property.

Each individual message is described by an Message object, which contains a message key (to be looked up in an appropriate message resources database), and up to four placeholder arguments used for parametric substitution in the resulting message.

IMPLEMENTATION NOTE - It is assumed that these objects are created and manipulated only within the context of a single thread. Therefore, no synchronization is required for access to internal collections.

Since:
Struts 1.1
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    protected static class 
    This class is used to store a set of messages associated with a property/key and the position it was initially added to list.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
    static final String
    The "property name" marker to use for BaseCommand messages, as opposed to those related to a specific property.
    protected int
    The current number of the property/key being added.
    The accumulated set of Message objects (represented as an ArrayList) for each property, keyed by property name.
    static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new instance of Messages
    Messages(Messages messages)
    Creates a new instance of Messages
  • Method Summary

    Modifier and Type
    Method
    Description
    add(Messages messages)
    Adds the messages from the given Messages object to this set of messages.
    add(String property, Message message)
    Add a message to the set of messages for the specified property.
    void
    Clear all messages recorded by this object.
    boolean
    containsKey(String property, String key)
     
    boolean
    containsKeys(String property, String... keys)
     
    get()
    Return the set of all recorded messages, without distinction by which property the messages are associated with.
    get(String property)
    Return the set of messages related to a specific property.
    boolean
    Return true if there are no messages recorded in this collection, or false otherwise.
    Return the set of property names for which at least one message has been recorded.
    int
    Return the number of messages recorded for all properties (including global messages).
    int
    size(String property)
    Return the number of messages associated with the specified property.
    Converts to a string representing the data contained within this set of Messages.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • Messages

      public Messages()
      Creates a new instance of Messages
    • Messages

      public Messages(Messages messages)
      Creates a new instance of Messages
  • Method Details

    • add

      public Messages add(String property, Message message)
      Add a message to the set of messages for the specified property. An order of the property/key is maintained based on the initial addition of the property/key.
      Parameters:
      property - Property name (or Messages.GLOBAL_MESSAGE)
      message - The message to be added
    • add

      public Messages add(Messages messages)
      Adds the messages from the given Messages object to this set of messages. The messages are added in the order they are returned from the properties() method. If a message's property is already in the current Messages object it is added to the end of the list for that property. If a message's property is not in the current list it is added to the end of the properties.
      Parameters:
      messages - The Messages object to be added. This parameter can be null.
      Since:
      Struts 1.1
    • clear

      public void clear()
      Clear all messages recorded by this object.
    • isEmpty

      public boolean isEmpty()
      Return true if there are no messages recorded in this collection, or false otherwise.
      Since:
      Struts 1.1
    • get

      public Iterator<Message> get()
      Return the set of all recorded messages, without distinction by which property the messages are associated with. If there are no messages recorded, an empty enumeration is returned.
    • get

      public Iterator<Message> get(String property)
      Return the set of messages related to a specific property. If there are no such messages, an empty enumeration is returned.
      Parameters:
      property - Property name (or Messages.GLOBAL_MESSAGE)
    • containsKey

      public boolean containsKey(String property, String key)
    • containsKeys

      public boolean containsKeys(String property, String... keys)
    • properties

      Return the set of property names for which at least one message has been recorded. If there are no messages, an empty Iterator is returned. If you have recorded global messages, the String value of Messages.GLOBAL_MESSAGE will be one of the returned property names.
    • size

      public int size()
      Return the number of messages recorded for all properties (including global messages). NOTE - it is more efficient to call empty() if all you care about is whether or not there are any messages at all.
    • size

      public int size(String property)
      Return the number of messages associated with the specified property.
      Parameters:
      property - Property name (or Messages.GLOBAL_MESSAGE)
    • toString

      public String toString()
      Converts to a string representing the data contained within this set of Messages.
      Overrides:
      toString in class Object