org.apache.commons.resources.impl
Class BasicMessageList

java.lang.Object
  extended by org.apache.commons.resources.impl.BasicMessageList
All Implemented Interfaces:
Serializable, MessageList

public class BasicMessageList
extends Object
implements Serializable, MessageList

A basic implementation of a MessageList.

Orginally based on org.apache.struts.action.ActionMessages, Revision 49670.

See Also:
Serialized Form

Nested Class Summary
protected static class BasicMessageList.MessageItem
          Holds messages for a specified property.
 
Field Summary
 
Fields inherited from interface org.apache.commons.resources.MessageList
GLOBAL_MESSAGE_KEY
 
Constructor Summary
BasicMessageList()
          Create an empty MessageList object.
BasicMessageList(MessageList messages)
          Create an MessageList object initialized with the given messages.
BasicMessageList(String globalMessageKey)
          Create an MessageList object initialized to use the given value for the "global" message key.
BasicMessageList(String globalMessageKey, MessageList messages)
          Create an MessageList object initialized with the given messages and the given global message key.
 
Method Summary
 void add(Message message)
          Add a message to the set of messages for the "global" property.
 void add(MessageList messageList)
          Adds the messages from the given MessageList object to this set of messages.
 void add(String property, Message message)
          Add a message to the set of messages for the specified property.
 void clear()
          Clear all messages recorded by this object.
 Iterator get()
          Return the set of all recorded messages, without distinction by which property the messages are associated with.
 Iterator get(String property)
          Return the set of messages related to a specific property.
 String getGlobalMessageKey()
           
 boolean isAccessed()
          Determines if the MessageList's messages have been accessed one or more times.
 boolean isEmpty()
           
 Iterator properties()
          Return the set of property names for which at least one message has been recorded.
 void setGlobalMessageKey(String globalMessageKey)
           
 int size()
          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.
 String toString()
          Returns a String representation of this MessageList's [property name]=[message list] mapping.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BasicMessageList

public BasicMessageList()
Create an empty MessageList object.


BasicMessageList

public BasicMessageList(String globalMessageKey)
Create an MessageList object initialized to use the given value for the "global" message key.

Parameters:
globalMessageKey - The new default global message key

BasicMessageList

public BasicMessageList(MessageList messages)
Create an MessageList object initialized with the given messages.

Parameters:
messages - The messages to be initially added to this object.

BasicMessageList

public BasicMessageList(String globalMessageKey,
                        MessageList messages)
Create an MessageList object initialized with the given messages and the given global message key.

Parameters:
globalMessageKey - The new default global message key
messages - The messages to be initially added to this object.
Method Detail

getGlobalMessageKey

public String getGlobalMessageKey()
Specified by:
getGlobalMessageKey in interface MessageList
Returns:
The default global message key

setGlobalMessageKey

public void setGlobalMessageKey(String globalMessageKey)
Specified by:
setGlobalMessageKey in interface MessageList
Parameters:
globalMessageKey - The new default global message key

add

public void 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.

Specified by:
add in interface MessageList
Parameters:
property - Property name (or MessageList.GLOBAL_MESSAGE_KEY)
message - The message to be added

add

public void add(Message message)
Add a message to the set of messages for the "global" property. An order of the property/key is maintained based on the initial addition of the property/key.

Specified by:
add in interface MessageList
Parameters:
message - The message to be added

add

public void add(MessageList messageList)
Adds the messages from the given MessageList 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 MessageList 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.

Specified by:
add in interface MessageList
Parameters:
messageList - The MessageList object to be added.

clear

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

Specified by:
clear in interface MessageList

isAccessed

public boolean isAccessed()
Determines if the MessageList's messages have been accessed one or more times. Returns true if the get() or get(String) methods are called.

Specified by:
isAccessed in interface MessageList
Returns:
true if the messages have been accessed one or more times.

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface MessageList
Returns:
Return true if there are no messages recorded in this collection, or false otherwise.

get

public Iterator 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.

Specified by:
get in interface MessageList
Returns:
All messages.

get

public Iterator get(String property)
Return the set of messages related to a specific property. If there are no such messages, an empty enumeration is returned.

Specified by:
get in interface MessageList
Parameters:
property - Property name
Returns:
Messages related to a specific property.

properties

public Iterator 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 MessageList.GLOBAL_MESSAGE will be one of the returned property names.

Specified by:
properties in interface MessageList
Returns:
The 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 isEmpty() if all you care about is whether or not there are any messages at all.

Specified by:
size in interface MessageList
Returns:
The number of messages.

size

public int size(String property)
Return the number of messages associated with the specified property.

Specified by:
size in interface MessageList
Parameters:
property - Property name (or MessageList.GLOBAL_MESSAGE_KEY
Returns:
The number of messages for a specific property.

toString

public String toString()
Returns a String representation of this MessageList's [property name]=[message list] mapping.

Overrides:
toString in class Object
See Also:
Object.toString()


Copyright © 2001-2010 The Apache Software Foundation. All Rights Reserved.