org.apache.camel.impl
Class DefaultMessage

java.lang.Object
  extended by org.apache.camel.impl.MessageSupport
      extended by org.apache.camel.impl.DefaultMessage
All Implemented Interfaces:
Message
Direct Known Subclasses:
GenericFileMessage, HttpMessage, IrcMessage, JmsMessage, MailMessage, QuartzMessage, SmppMessage, SnmpMessage, SpringIntegrationMessage, XmppMessage

public class DefaultMessage
extends MessageSupport

The default implementation of Message

This implementation uses a CaseInsensitiveMap storing the headers. This allows us to be able to lookup headers using case insensitive keys, making it easier for end users as they do not have to be worried about using exact keys. See more details at CaseInsensitiveMap.

Version:
$Revision: 17089 $

Constructor Summary
DefaultMessage()
           
 
Method Summary
 void addAttachment(String id, DataHandler content)
          Adds an attachment to the message using the id
 void copyFrom(Message that)
          Copies the contents of the other message into this message
protected  Map<String,DataHandler> createAttachments()
          A factory method to lazily create the attachments to make it easy to create efficient Message implementations which only construct and populate the Map on demand
 String createExchangeId()
          Returns the unique ID for a message exchange if this message is capable of creating one or null if not
protected  Map<String,Object> createHeaders()
          A factory method to lazily create the headers to make it easy to create efficient Message implementations which only construct and populate the Map on demand
 DataHandler getAttachment(String id)
          Returns the attachment specified by the id
 Set<String> getAttachmentNames()
          Returns a set of attachment names of the message
 Map<String,DataHandler> getAttachments()
          Returns all attachments of the message
 Object getHeader(String name)
          Accesses a specific header
<T> T
getHeader(String name, Class<T> type)
          Returns a header associated with this message by name and specifying the type required
 Object getHeader(String name, Object defaultValue)
          Accesses a specific header
<T> T
getHeader(String name, Object defaultValue, Class<T> type)
          Returns a header associated with this message by name and specifying the type required
 Map<String,Object> getHeaders()
          Returns all of the headers associated with the message
 boolean hasAttachments()
          Returns whether this message has attachments.
 boolean hasHeaders()
          Returns whether has any headers has been set.
protected  boolean hasPopulatedHeaders()
          Returns true if the headers have been mutated in some way
 boolean isFault()
          Returns true if this message represents a fault
 DefaultMessage newInstance()
          Returns a new instance
protected  void populateInitialAttachments(Map<String,DataHandler> map)
          A strategy method populate the initial set of attachments on an inbound message from an underlying binding
protected  void populateInitialHeaders(Map<String,Object> map)
          A strategy method populate the initial set of headers on an inbound message from an underlying binding
 void removeAttachment(String id)
          Removes the attachment specified by the id
 Object removeHeader(String name)
          Removes the named header from this message
 void setAttachments(Map<String,DataHandler> attachments)
          Set all the attachments associated with this message
 void setFault(boolean fault)
          Sets the fault flag on this message
 void setHeader(String name, Object value)
          Sets a header on the message
 void setHeaders(Map<String,Object> headers)
          Set all the headers associated with this message
 String toString()
           
 
Methods inherited from class org.apache.camel.impl.MessageSupport
copy, createBody, createMessageId, getBody, getBody, getBody, getExchange, getMandatoryBody, getMandatoryBody, getMessageId, setBody, setBody, setExchange, setMessageId
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultMessage

public DefaultMessage()
Method Detail

toString

public String toString()
Overrides:
toString in class Object

copyFrom

public void copyFrom(Message that)
Description copied from interface: Message
Copies the contents of the other message into this message

Specified by:
copyFrom in interface Message
Overrides:
copyFrom in class MessageSupport
Parameters:
that - the other message

isFault

public boolean isFault()
Description copied from interface: Message
Returns true if this message represents a fault

Returns:
true if this is a fault message, false for regular messages.

setFault

public void setFault(boolean fault)
Description copied from interface: Message
Sets the fault flag on this message

Parameters:
fault - the fault flag

getHeader

public Object getHeader(String name)
Description copied from interface: Message
Accesses a specific header

Parameters:
name - name of header
Returns:
the value of the given header or null if there is no header for the given name

getHeader

public Object getHeader(String name,
                        Object defaultValue)
Description copied from interface: Message
Accesses a specific header

Parameters:
name - name of header
defaultValue - the default value to return if header was absent
Returns:
the value of the given header or defaultValue if there is no header for the given name

getHeader

public <T> T getHeader(String name,
                       Class<T> type)
Description copied from interface: Message
Returns a header associated with this message by name and specifying the type required

Parameters:
name - the name of the header
type - the type of the header
Returns:
the value of the given header or null if there is no header for the given name or null if it cannot be converted to the given type

getHeader

public <T> T getHeader(String name,
                       Object defaultValue,
                       Class<T> type)
Description copied from interface: Message
Returns a header associated with this message by name and specifying the type required

Parameters:
name - the name of the header
defaultValue - the default value to return if header was absent
type - the type of the header
Returns:
the value of the given header or defaultValue if there is no header for the given name or null if it cannot be converted to the given type

setHeader

public void setHeader(String name,
                      Object value)
Description copied from interface: Message
Sets a header on the message

Parameters:
name - of the header
value - to associate with the name

removeHeader

public Object removeHeader(String name)
Description copied from interface: Message
Removes the named header from this message

Parameters:
name - name of the header
Returns:
the old value of the header

getHeaders

public Map<String,Object> getHeaders()
Description copied from interface: Message
Returns all of the headers associated with the message

Returns:
all the headers in a Map

setHeaders

public void setHeaders(Map<String,Object> headers)
Description copied from interface: Message
Set all the headers associated with this message

Parameters:
headers - headers to set

hasHeaders

public boolean hasHeaders()
Description copied from interface: Message
Returns whether has any headers has been set.

Returns:
true if any headers has been set

newInstance

public DefaultMessage newInstance()
Description copied from class: MessageSupport
Returns a new instance

Specified by:
newInstance in class MessageSupport

createHeaders

protected Map<String,Object> createHeaders()
A factory method to lazily create the headers to make it easy to create efficient Message implementations which only construct and populate the Map on demand

Returns:
return a newly constructed Map possibly containing headers from the underlying inbound transport

createAttachments

protected Map<String,DataHandler> createAttachments()
A factory method to lazily create the attachments to make it easy to create efficient Message implementations which only construct and populate the Map on demand

Returns:
return a newly constructed Map

populateInitialHeaders

protected void populateInitialHeaders(Map<String,Object> map)
A strategy method populate the initial set of headers on an inbound message from an underlying binding

Parameters:
map - is the empty header map to populate

populateInitialAttachments

protected void populateInitialAttachments(Map<String,DataHandler> map)
A strategy method populate the initial set of attachments on an inbound message from an underlying binding

Parameters:
map - is the empty attachment map to populate

addAttachment

public void addAttachment(String id,
                          DataHandler content)
Description copied from interface: Message
Adds an attachment to the message using the id

Parameters:
id - the id to store the attachment under
content - the data handler for the attachment

getAttachment

public DataHandler getAttachment(String id)
Description copied from interface: Message
Returns the attachment specified by the id

Parameters:
id - the id under which the attachment is stored
Returns:
the data handler for this attachment or null

getAttachmentNames

public Set<String> getAttachmentNames()
Description copied from interface: Message
Returns a set of attachment names of the message

Returns:
a set of attachment names

removeAttachment

public void removeAttachment(String id)
Description copied from interface: Message
Removes the attachment specified by the id

Parameters:
id - the id of the attachment to remove

getAttachments

public Map<String,DataHandler> getAttachments()
Description copied from interface: Message
Returns all attachments of the message

Returns:
the attachments in a map or null

setAttachments

public void setAttachments(Map<String,DataHandler> attachments)
Description copied from interface: Message
Set all the attachments associated with this message

Parameters:
attachments - the attachments

hasAttachments

public boolean hasAttachments()
Description copied from interface: Message
Returns whether this message has attachments.

Returns:
true if this message has any attachments.

hasPopulatedHeaders

protected boolean hasPopulatedHeaders()
Returns true if the headers have been mutated in some way


createExchangeId

public String createExchangeId()
Description copied from interface: Message
Returns the unique ID for a message exchange if this message is capable of creating one or null if not

Returns:
the created exchange id, or null if not capable of creating


Copyright © 2007-2010 IONA Open Source Community. All Rights Reserved.