org.apache.camel.impl
Class MessageSupport

java.lang.Object
  extended by org.apache.camel.impl.MessageSupport
All Implemented Interfaces:
Message
Direct Known Subclasses:
DefaultMessage

public abstract class MessageSupport
extends Object
implements Message

A base class for implementation inheritance providing the core Message body handling features but letting the derived class deal with headers. Unless a specific provider wishes to do something particularly clever with headers you probably want to just derive from DefaultMessage

Version:

Constructor Summary
MessageSupport()
           
 
Method Summary
 Message copy()
          Creates a copy of this message so that it can be used and possibly modified further in another exchange
 void copyFrom(Message that)
          Copies the contents of the other message into this message
protected  Object createBody()
          A factory method to allow a provider to lazily create the message body for inbound messages from other sources
protected  String createMessageId()
          Allow implementations to auto-create a messageId
 Object getBody()
          Returns the body of the message as a POJO

The body can be null if no body is set

<T> T
getBody(Class<T> type)
          Returns the body as the specified type
protected
<T> T
getBody(Class<T> type, Object body)
           
 Exchange getExchange()
          Returns the exchange this message is related to
 Object getMandatoryBody()
          Returns the body of the message as a POJO
<T> T
getMandatoryBody(Class<T> type)
          Returns the mandatory body as the specified type
 String getMessageId()
          Returns the id of the message
abstract  Message newInstance()
          Returns a new instance
 void setBody(Object body)
          Sets the body of the message
<T> void
setBody(Object value, Class<T> type)
          Sets the body of the message as a specific type
 void setExchange(Exchange exchange)
           
 void setMessageId(String messageId)
          Sets the id of the message
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.camel.Message
addAttachment, createExchangeId, getAttachment, getAttachmentNames, getAttachments, getHeader, getHeader, getHeader, getHeader, getHeaders, hasAttachments, hasHeaders, isFault, removeAttachment, removeHeader, removeHeaders, removeHeaders, setAttachments, setFault, setHeader, setHeaders
 

Constructor Detail

MessageSupport

public MessageSupport()
Method Detail

getBody

public Object getBody()
Description copied from interface: Message
Returns the body of the message as a POJO

The body can be null if no body is set

Specified by:
getBody in interface Message
Returns:
the body, can be null

getBody

public <T> T getBody(Class<T> type)
Description copied from interface: Message
Returns the body as the specified type

Specified by:
getBody in interface Message
Parameters:
type - the type that the body
Returns:
the body of the message as the specified type, or null if no body exists

getMandatoryBody

public Object getMandatoryBody()
                        throws InvalidPayloadException
Description copied from interface: Message
Returns the body of the message as a POJO

Specified by:
getMandatoryBody in interface Message
Returns:
the body, is never null
Throws:
InvalidPayloadException - Is thrown if the body being null or wrong class type

getBody

protected <T> T getBody(Class<T> type,
                        Object body)

getMandatoryBody

public <T> T getMandatoryBody(Class<T> type)
                   throws InvalidPayloadException
Description copied from interface: Message
Returns the mandatory body as the specified type

Specified by:
getMandatoryBody in interface Message
Parameters:
type - the type that the body
Returns:
the body of the message as the specified type, is never null.
Throws:
InvalidPayloadException - Is thrown if the body being null or wrong class type

setBody

public void setBody(Object body)
Description copied from interface: Message
Sets the body of the message

Specified by:
setBody in interface Message
Parameters:
body - the body

setBody

public <T> void setBody(Object value,
                        Class<T> type)
Description copied from interface: Message
Sets the body of the message as a specific type

Specified by:
setBody in interface Message
Parameters:
value - the body
type - the type of the body

copy

public Message copy()
Description copied from interface: Message
Creates a copy of this message so that it can be used and possibly modified further in another exchange

Specified by:
copy in interface Message
Returns:
a new message instance copied from this message

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
Parameters:
that - the other message

getExchange

public Exchange getExchange()
Description copied from interface: Message
Returns the exchange this message is related to

Specified by:
getExchange in interface Message
Returns:
the exchange

setExchange

public void setExchange(Exchange exchange)

newInstance

public abstract Message newInstance()
Returns a new instance


createBody

protected Object createBody()
A factory method to allow a provider to lazily create the message body for inbound messages from other sources

Returns:
the value of the message body or null if there is no value available

getMessageId

public String getMessageId()
Description copied from interface: Message
Returns the id of the message

Specified by:
getMessageId in interface Message
Returns:
the message id

setMessageId

public void setMessageId(String messageId)
Description copied from interface: Message
Sets the id of the message

Specified by:
setMessageId in interface Message
Parameters:
messageId - id of the message

createMessageId

protected String createMessageId()
Allow implementations to auto-create a messageId



Apache CAMEL