Class DefaultMessageContext

java.lang.Object
org.springframework.binding.message.DefaultMessageContext
All Implemented Interfaces:
MessageContext, StateManageableMessageContext

public class DefaultMessageContext extends Object implements StateManageableMessageContext
The default message context implementation. Uses a MessageSource to resolve messages that are added by callers.
Author:
Keith Donald
  • 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

      public Message[] 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 interface MessageContext
      Returns:
      the messages
    • getMessagesBySource

      public Message[] getMessagesBySource(Object source)
      Description copied from interface: MessageContext
      Get all messages in this context for the source provided.
      Specified by:
      getMessagesBySource in interface MessageContext
      Parameters:
      source - the source associated with messages, or null for global messages
      Returns:
      the source's messages
    • getMessagesByCriteria

      public Message[] getMessagesByCriteria(MessageCriteria criteria)
      Description copied from interface: MessageContext
      Get all messages that meet the given result criteria.
      Specified by:
      getMessagesByCriteria in interface MessageContext
      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 interface MessageContext
      Returns:
      error messages
    • addMessage

      public void addMessage(MessageResolver messageResolver)
      Description copied from interface: MessageContext
      Add a new message to this context.
      Specified by:
      addMessage in interface MessageContext
      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 interface MessageContext
    • createMessagesMemento

      public Serializable 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 interface StateManageableMessageContext
      Returns:
      the messages memento
    • restoreMessages

      public void restoreMessages(Serializable messagesMemento)
      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 interface StateManageableMessageContext
      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 interface StateManageableMessageContext
      Parameters:
      messageSource - the message source
      See Also:
    • toString

      public String toString()
      Overrides:
      toString in class Object