Class Messages
java.lang.Object
com.echothree.util.common.message.Messages
- All Implemented Interfaces:
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 ClassesModifier and TypeClassDescriptionprotected 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
FieldsModifier and TypeFieldDescriptionstatic 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.protected Map<String,
Messages.MessageItem> The accumulated set ofMessage
objects (represented as an ArrayList) for each property, keyed by property name.static final String
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds the messages from the givenMessages
object to this set of messages.Add a message to the set of messages for the specified property.void
clear()
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.Return the set of messages related to a specific property.boolean
isEmpty()
Returntrue
if there are no messages recorded in this collection, orfalse
otherwise.Return the set of property names for which at least one message has been recorded.int
size()
Return the number of messages recorded for all properties (including global messages).int
Return the number of messages associated with the specified property.toString()
Converts to a string representing the data contained within this set of Messages.
-
Field Details
-
EXECUTION_WARNING
The "property name" marker to use for BaseCommand messages, as opposed to those related to a specific property.- See Also:
-
EXECUTION_ERROR
- See Also:
-
SECURITY_MESSAGE
- See Also:
-
messages
The accumulated set ofMessage
objects (represented as an ArrayList) for each property, keyed by property name. -
iCount
The current number of the property/key being added. This is used to maintain the order messages are added.
-
-
Constructor Details
-
Messages
public Messages()Creates a new instance of Messages -
Messages
Creates a new instance of Messages
-
-
Method Details
-
add
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
Adds the messages from the givenMessages
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 currentMessages
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
- TheMessages
object to be added. This parameter can benull
.- Since:
- Struts 1.1
-
clear
Clear all messages recorded by this object. -
isEmpty
Returntrue
if there are no messages recorded in this collection, orfalse
otherwise.- Since:
- Struts 1.1
-
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
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
-
containsKeys
-
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 ofMessages.GLOBAL_MESSAGE
will be one of the returned property names. -
size
Return the number of messages recorded for all properties (including global messages). NOTE - it is more efficient to callempty()
if all you care about is whether or not there are any messages at all. -
size
Return the number of messages associated with the specified property.- Parameters:
property
- Property name (or Messages.GLOBAL_MESSAGE)
-
toString
Converts to a string representing the data contained within this set of Messages.
-