Class DefaultMessageContext
java.lang.Object
org.springframework.binding.message.DefaultMessageContext
- All Implemented Interfaces:
MessageContext
,StateManageableMessageContext
The default message context implementation. Uses a
MessageSource
to resolve messages that are added by
callers.- Author:
- Keith Donald
-
Constructor Summary
ConstructorDescriptionCreates a new default message context.DefaultMessageContext
(org.springframework.context.MessageSource messageSource) Creates a new default message context. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addMessage
(MessageResolver messageResolver) Add a new message to this context.void
Clear all messages added to this context.Create a serializable memento, or token representing a snapshot of the internal state of this message context.Message[]
Get all messages in this context.Message[]
getMessagesByCriteria
(MessageCriteria criteria) Get all messages that meet the given result criteria.Message[]
getMessagesBySource
(Object source) Get all messages in this context for the source provided.org.springframework.context.MessageSource
boolean
Returns true if there are error messages in this context.void
restoreMessages
(Serializable messagesMemento) Set the state of this context from the memento provided.void
setMessageSource
(org.springframework.context.MessageSource messageSource) Configure the message source used to resolve messages added to this context.toString()
-
Constructor Details
-
DefaultMessageContext
public DefaultMessageContext()Creates a new default message context. Defaults to a message source that simply resolves default text and cannot resolve localized message codes. -
DefaultMessageContext
public DefaultMessageContext(org.springframework.context.MessageSource messageSource) Creates a new default message context.- Parameters:
messageSource
- the message source to resolve messages added to this context
-
-
Method Details
-
getMessageSource
public org.springframework.context.MessageSource getMessageSource() -
getAllMessages
Description copied from interface:MessageContext
Get all messages in this context. The messages returned should be suitable for display as-is.- Specified by:
getAllMessages
in interfaceMessageContext
- Returns:
- the messages
-
getMessagesBySource
Description copied from interface:MessageContext
Get all messages in this context for the source provided.- Specified by:
getMessagesBySource
in interfaceMessageContext
- Parameters:
source
- the source associated with messages, or null for global messages- Returns:
- the source's messages
-
getMessagesByCriteria
Description copied from interface:MessageContext
Get all messages that meet the given result criteria.- Specified by:
getMessagesByCriteria
in interfaceMessageContext
- Parameters:
criteria
- the message criteria
-
hasErrorMessages
public boolean hasErrorMessages()Description copied from interface:MessageContext
Returns true if there are error messages in this context.- Specified by:
hasErrorMessages
in interfaceMessageContext
- Returns:
- error messages
-
addMessage
Description copied from interface:MessageContext
Add a new message to this context.- Specified by:
addMessage
in interfaceMessageContext
- Parameters:
messageResolver
- the resolver that will resolve the message to be added
-
clearMessages
public void clearMessages()Description copied from interface:MessageContext
Clear all messages added to this context.- Specified by:
clearMessages
in interfaceMessageContext
-
createMessagesMemento
Description copied from interface:StateManageableMessageContext
Create a serializable memento, or token representing a snapshot of the internal state of this message context.- Specified by:
createMessagesMemento
in interfaceStateManageableMessageContext
- Returns:
- the messages memento
-
restoreMessages
Description copied from interface:StateManageableMessageContext
Set the state of this context from the memento provided. After this call, the messages in this context will match what is encapsulated inside the memento. Any previous state will be overridden.- Specified by:
restoreMessages
in interfaceStateManageableMessageContext
- Parameters:
messagesMemento
- the messages memento
-
setMessageSource
public void setMessageSource(org.springframework.context.MessageSource messageSource) Description copied from interface:StateManageableMessageContext
Configure the message source used to resolve messages added to this context. May be set at any time to change how coded messages are resolved.- Specified by:
setMessageSource
in interfaceStateManageableMessageContext
- Parameters:
messageSource
- the message source- See Also:
-
toString
-