类 MarshallingMessageConverter
- java.lang.Object
- org.springframework.jms.support.converter.MarshallingMessageConverter
- 所有已实现的接口:
InitializingBean
,MessageConverter
public class MarshallingMessageConverter extends Object implements MessageConverter, InitializingBean
Spring JMSMessageConverter
that uses aMarshaller
andUnmarshaller
. Marshals an object to aBytesMessage
, or to aTextMessage
if thetargetType
is set toMessageType.TEXT
. Unmarshals from aTextMessage
orBytesMessage
to an object.- 从以下版本开始:
- 3.0
- 作者:
- Arjen Poutsma, Juergen Hoeller
构造器概要
构造器 构造器 说明 MarshallingMessageConverter()
MarshallingMessageConverter(Marshaller marshaller)
Construct a newMarshallingMessageConverter
with the givenMarshaller
set.MarshallingMessageConverter(Marshaller marshaller, Unmarshaller unmarshaller)
Construct a newMarshallingMessageConverter
with the given Marshaller and Unmarshaller.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 void
afterPropertiesSet()
Invoked by the containingBeanFactory
after it has set all bean properties and satisfiedBeanFactoryAware
,ApplicationContextAware
etc.Object
fromMessage(Message message)
This implementation unmarshals the givenMessage
into an object.protected BytesMessage
marshalToBytesMessage(Object object, Session session, Marshaller marshaller)
Marshal the given object to aBytesMessage
.protected Message
marshalToMessage(Object object, Session session, Marshaller marshaller, MessageType targetType)
Template method that allows for custom message marshalling.protected TextMessage
marshalToTextMessage(Object object, Session session, Marshaller marshaller)
Marshal the given object to aTextMessage
.void
setMarshaller(Marshaller marshaller)
Set theMarshaller
to be used by this message converter.void
setTargetType(MessageType targetType)
void
setUnmarshaller(Unmarshaller unmarshaller)
Set theUnmarshaller
to be used by this message converter.Message
toMessage(Object object, Session session)
This implementation marshals the given object to aTextMessage
orBytesMessage
.protected Object
unmarshalFromBytesMessage(BytesMessage message, Unmarshaller unmarshaller)
Unmarshal the givenBytesMessage
into an object.protected Object
unmarshalFromMessage(Message message, Unmarshaller unmarshaller)
Template method that allows for custom message unmarshalling.protected Object
unmarshalFromTextMessage(TextMessage message, Unmarshaller unmarshaller)
Unmarshal the givenTextMessage
into an object.
构造器详细资料
MarshallingMessageConverter
public MarshallingMessageConverter()
Construct a newMarshallingMessageConverter
with noMarshaller
orUnmarshaller
set. The marshaller must be set after construction by invokingsetMarshaller(Marshaller)
andsetUnmarshaller(Unmarshaller)
.
MarshallingMessageConverter
public MarshallingMessageConverter(Marshaller marshaller)
Construct a newMarshallingMessageConverter
with the givenMarshaller
set.If the given
Marshaller
also implements theUnmarshaller
interface, it is used for both marshalling and unmarshalling. Otherwise, an exception is thrown.Note that all
Marshaller
implementations in Spring also implement theUnmarshaller
interface, so that you can safely use this constructor.- 参数:
marshaller
- object used as marshaller and unmarshaller- 抛出:
IllegalArgumentException
- whenmarshaller
does not implement theUnmarshaller
interface as well
MarshallingMessageConverter
public MarshallingMessageConverter(Marshaller marshaller, Unmarshaller unmarshaller)
Construct a newMarshallingMessageConverter
with the given Marshaller and Unmarshaller.- 参数:
marshaller
- the Marshaller to useunmarshaller
- the Unmarshaller to use
方法详细资料
setMarshaller
public void setMarshaller(Marshaller marshaller)
Set theMarshaller
to be used by this message converter.
setUnmarshaller
public void setUnmarshaller(Unmarshaller unmarshaller)
Set theUnmarshaller
to be used by this message converter.
setTargetType
public void setTargetType(MessageType targetType)
Specify whethertoMessage(Object, Session)
should marshal to aBytesMessage
or aTextMessage
.The default is
MessageType.BYTES
, i.e. this converter marshals to aBytesMessage
. Note that the default version of this converter supportsMessageType.BYTES
andMessageType.TEXT
only.
afterPropertiesSet
public void afterPropertiesSet()
从接口复制的说明:InitializingBean
Invoked by the containingBeanFactory
after it has set all bean properties and satisfiedBeanFactoryAware
,ApplicationContextAware
etc.This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.
- 指定者:
afterPropertiesSet
在接口中InitializingBean
toMessage
public Message toMessage(Object object, Session session) throws JMSException, MessageConversionException
This implementation marshals the given object to aTextMessage
orBytesMessage
. The desired message type can be defined by setting the"marshalTo"
property.- 指定者:
toMessage
在接口中MessageConverter
- 参数:
object
- the object to convertsession
- the Session to use for creating a JMS Message- 返回:
- the JMS Message
- 抛出:
JMSException
- if thrown by JMS API methodsMessageConversionException
- in case of conversion failure- 另请参阅:
marshalToTextMessage(java.lang.Object, javax.jms.Session, org.springframework.oxm.Marshaller)
,marshalToBytesMessage(java.lang.Object, javax.jms.Session, org.springframework.oxm.Marshaller)
fromMessage
public Object fromMessage(Message message) throws JMSException, MessageConversionException
This implementation unmarshals the givenMessage
into an object.- 指定者:
fromMessage
在接口中MessageConverter
- 参数:
message
- the message to convert- 返回:
- the converted Java object
- 抛出:
JMSException
- if thrown by JMS API methodsMessageConversionException
- in case of conversion failure- 另请参阅:
unmarshalFromTextMessage(javax.jms.TextMessage, org.springframework.oxm.Unmarshaller)
,unmarshalFromBytesMessage(javax.jms.BytesMessage, org.springframework.oxm.Unmarshaller)
marshalToTextMessage
protected TextMessage marshalToTextMessage(Object object, Session session, Marshaller marshaller) throws JMSException, IOException, XmlMappingException
Marshal the given object to aTextMessage
.- 参数:
object
- the object to be marshalledsession
- current JMS sessionmarshaller
- the marshaller to use- 返回:
- the resulting message
- 抛出:
JMSException
- if thrown by JMS methodsIOException
- in case of I/O errorsXmlMappingException
- in case of OXM mapping errors- 另请参阅:
Session.createTextMessage()
,Marshaller.marshal(Object, Result)
marshalToBytesMessage
protected BytesMessage marshalToBytesMessage(Object object, Session session, Marshaller marshaller) throws JMSException, IOException, XmlMappingException
Marshal the given object to aBytesMessage
.- 参数:
object
- the object to be marshalledsession
- current JMS sessionmarshaller
- the marshaller to use- 返回:
- the resulting message
- 抛出:
JMSException
- if thrown by JMS methodsIOException
- in case of I/O errorsXmlMappingException
- in case of OXM mapping errors- 另请参阅:
Session.createBytesMessage()
,Marshaller.marshal(Object, Result)
marshalToMessage
protected Message marshalToMessage(Object object, Session session, Marshaller marshaller, MessageType targetType) throws JMSException, IOException, XmlMappingException
Template method that allows for custom message marshalling. Invoked whensetTargetType(org.springframework.jms.support.converter.MessageType)
is notMessageType.TEXT
orMessageType.BYTES
.The default implementation throws an
IllegalArgumentException
.- 参数:
object
- the object to marshalsession
- the JMS sessionmarshaller
- the marshaller to usetargetType
- the target message type (other than TEXT or BYTES)- 返回:
- the resulting message
- 抛出:
JMSException
- if thrown by JMS methodsIOException
- in case of I/O errorsXmlMappingException
- in case of OXM mapping errors
unmarshalFromTextMessage
protected Object unmarshalFromTextMessage(TextMessage message, Unmarshaller unmarshaller) throws JMSException, IOException, XmlMappingException
Unmarshal the givenTextMessage
into an object.- 参数:
message
- the messageunmarshaller
- the unmarshaller to use- 返回:
- the unmarshalled object
- 抛出:
JMSException
- if thrown by JMS methodsIOException
- in case of I/O errorsXmlMappingException
- in case of OXM mapping errors- 另请参阅:
Unmarshaller.unmarshal(Source)
unmarshalFromBytesMessage
protected Object unmarshalFromBytesMessage(BytesMessage message, Unmarshaller unmarshaller) throws JMSException, IOException, XmlMappingException
Unmarshal the givenBytesMessage
into an object.- 参数:
message
- the messageunmarshaller
- the unmarshaller to use- 返回:
- the unmarshalled object
- 抛出:
JMSException
- if thrown by JMS methodsIOException
- in case of I/O errorsXmlMappingException
- in case of OXM mapping errors- 另请参阅:
Unmarshaller.unmarshal(Source)
unmarshalFromMessage
protected Object unmarshalFromMessage(Message message, Unmarshaller unmarshaller) throws JMSException, IOException, XmlMappingException
Template method that allows for custom message unmarshalling. Invoked whenfromMessage(Message)
is invoked with a message that is not aTextMessage
orBytesMessage
.The default implementation throws an
IllegalArgumentException
.- 参数:
message
- the messageunmarshaller
- the unmarshaller to use- 返回:
- the unmarshalled object
- 抛出:
JMSException
- if thrown by JMS methodsIOException
- in case of I/O errorsXmlMappingException
- in case of OXM mapping errors