类 MarshallingMessageConverter
- java.lang.Object
- org.springframework.jms.support.converter.MarshallingMessageConverter
- 所有已实现的接口:
InitializingBean,MessageConverter
public class MarshallingMessageConverter extends Object implements MessageConverter, InitializingBean
Spring JMSMessageConverterthat uses aMarshallerandUnmarshaller. Marshals an object to aBytesMessage, or to aTextMessageif thetargetTypeis set toMessageType.TEXT. Unmarshals from aTextMessageorBytesMessageto an object.- 从以下版本开始:
- 3.0
- 作者:
- Arjen Poutsma, Juergen Hoeller
构造器概要
构造器 构造器 说明 MarshallingMessageConverter()MarshallingMessageConverter(Marshaller marshaller)Construct a newMarshallingMessageConverterwith the givenMarshallerset.MarshallingMessageConverter(Marshaller marshaller, Unmarshaller unmarshaller)Construct a newMarshallingMessageConverterwith the given Marshaller and Unmarshaller.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 voidafterPropertiesSet()Invoked by the containingBeanFactoryafter it has set all bean properties and satisfiedBeanFactoryAware,ApplicationContextAwareetc.ObjectfromMessage(Message message)This implementation unmarshals the givenMessageinto an object.protected BytesMessagemarshalToBytesMessage(Object object, Session session, Marshaller marshaller)Marshal the given object to aBytesMessage.protected MessagemarshalToMessage(Object object, Session session, Marshaller marshaller, MessageType targetType)Template method that allows for custom message marshalling.protected TextMessagemarshalToTextMessage(Object object, Session session, Marshaller marshaller)Marshal the given object to aTextMessage.voidsetMarshaller(Marshaller marshaller)Set theMarshallerto be used by this message converter.voidsetTargetType(MessageType targetType)voidsetUnmarshaller(Unmarshaller unmarshaller)Set theUnmarshallerto be used by this message converter.MessagetoMessage(Object object, Session session)This implementation marshals the given object to aTextMessageorBytesMessage.protected ObjectunmarshalFromBytesMessage(BytesMessage message, Unmarshaller unmarshaller)Unmarshal the givenBytesMessageinto an object.protected ObjectunmarshalFromMessage(Message message, Unmarshaller unmarshaller)Template method that allows for custom message unmarshalling.protected ObjectunmarshalFromTextMessage(TextMessage message, Unmarshaller unmarshaller)Unmarshal the givenTextMessageinto an object.
构造器详细资料
MarshallingMessageConverter
public MarshallingMessageConverter()
Construct a newMarshallingMessageConverterwith noMarshallerorUnmarshallerset. The marshaller must be set after construction by invokingsetMarshaller(Marshaller)andsetUnmarshaller(Unmarshaller).
MarshallingMessageConverter
public MarshallingMessageConverter(Marshaller marshaller)
Construct a newMarshallingMessageConverterwith the givenMarshallerset.If the given
Marshalleralso implements theUnmarshallerinterface, it is used for both marshalling and unmarshalling. Otherwise, an exception is thrown.Note that all
Marshallerimplementations in Spring also implement theUnmarshallerinterface, so that you can safely use this constructor.- 参数:
marshaller- object used as marshaller and unmarshaller- 抛出:
IllegalArgumentException- whenmarshallerdoes not implement theUnmarshallerinterface as well
MarshallingMessageConverter
public MarshallingMessageConverter(Marshaller marshaller, Unmarshaller unmarshaller)
Construct a newMarshallingMessageConverterwith the given Marshaller and Unmarshaller.- 参数:
marshaller- the Marshaller to useunmarshaller- the Unmarshaller to use
方法详细资料
setMarshaller
public void setMarshaller(Marshaller marshaller)
Set theMarshallerto be used by this message converter.
setUnmarshaller
public void setUnmarshaller(Unmarshaller unmarshaller)
Set theUnmarshallerto be used by this message converter.
setTargetType
public void setTargetType(MessageType targetType)
Specify whethertoMessage(Object, Session)should marshal to aBytesMessageor aTextMessage.The default is
MessageType.BYTES, i.e. this converter marshals to aBytesMessage. Note that the default version of this converter supportsMessageType.BYTESandMessageType.TEXTonly.
afterPropertiesSet
public void afterPropertiesSet()
从接口复制的说明:InitializingBeanInvoked by the containingBeanFactoryafter it has set all bean properties and satisfiedBeanFactoryAware,ApplicationContextAwareetc.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 aTextMessageorBytesMessage. 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 givenMessageinto 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.TEXTorMessageType.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 givenTextMessageinto 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 givenBytesMessageinto 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 aTextMessageorBytesMessage.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