|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.springframework.jms.support.converter.MarshallingMessageConverter
public class MarshallingMessageConverter
Spring JMS MessageConverter
that uses a Marshaller
and Unmarshaller
.
Marshals an object to a BytesMessage
, or to a TextMessage
if the
marshalTo
is set to MessageType.TEXT
.
Unmarshals from a TextMessage
or BytesMessage
to an object.
JmsTemplate.convertAndSend(java.lang.Object)
,
JmsTemplate.receiveAndConvert()
Field Summary | |
---|---|
private Marshaller |
marshaller
|
private MessageType |
targetType
|
private Unmarshaller |
unmarshaller
|
Constructor Summary | |
---|---|
MarshallingMessageConverter()
Construct a new MarshallingMessageConverter with no Marshaller or Unmarshaller set. |
|
MarshallingMessageConverter(Marshaller marshaller)
Construct a new MarshallingMessageConverter with the given Marshaller set. |
|
MarshallingMessageConverter(Marshaller marshaller,
Unmarshaller unmarshaller)
Construct a new MarshallingMessageConverter with the
given Marshaller and Unmarshaller. |
Method Summary | |
---|---|
void |
afterPropertiesSet()
Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware). |
java.lang.Object |
fromMessage(Message message)
This implementation unmarshals the given Message into an object. |
protected BytesMessage |
marshalToBytesMessage(java.lang.Object object,
Session session,
Marshaller marshaller)
Marshal the given object to a BytesMessage . |
protected Message |
marshalToMessage(java.lang.Object object,
Session session,
Marshaller marshaller,
MessageType targetType)
Template method that allows for custom message marshalling. |
protected TextMessage |
marshalToTextMessage(java.lang.Object object,
Session session,
Marshaller marshaller)
Marshal the given object to a TextMessage . |
void |
setMarshaller(Marshaller marshaller)
Set the Marshaller to be used by this message converter. |
void |
setTargetType(MessageType targetType)
Specify whether toMessage(Object, Session) should marshal to
a BytesMessage or a TextMessage . |
void |
setUnmarshaller(Unmarshaller unmarshaller)
Set the Unmarshaller to be used by this message converter. |
Message |
toMessage(java.lang.Object object,
Session session)
This implementation marshals the given object to a javax.jms.TextMessage or
javax.jms.BytesMessage . |
protected java.lang.Object |
unmarshalFromBytesMessage(BytesMessage message,
Unmarshaller unmarshaller)
Unmarshal the given BytesMessage into an object. |
protected java.lang.Object |
unmarshalFromMessage(Message message,
Unmarshaller unmarshaller)
Template method that allows for custom message unmarshalling. |
protected java.lang.Object |
unmarshalFromTextMessage(TextMessage message,
Unmarshaller unmarshaller)
Unmarshal the given TextMessage into an object. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private Marshaller marshaller
private Unmarshaller unmarshaller
private MessageType targetType
Constructor Detail |
---|
public MarshallingMessageConverter()
MarshallingMessageConverter
with no Marshaller
or Unmarshaller
set.
The marshaller must be set after construction by invoking setMarshaller(Marshaller)
and
setUnmarshaller(Unmarshaller)
.
public MarshallingMessageConverter(Marshaller marshaller)
MarshallingMessageConverter
with the given Marshaller
set.
If the given Marshaller
also implements the Unmarshaller
interface,
it is used for both marshalling and unmarshalling. Otherwise, an exception is thrown.
Note that all Marshaller
implementations in Spring also implement the
Unmarshaller
interface, so that you can safely use this constructor.
marshaller
- object used as marshaller and unmarshaller
java.lang.IllegalArgumentException
- when marshaller
does not implement the
Unmarshaller
interface as wellpublic MarshallingMessageConverter(Marshaller marshaller, Unmarshaller unmarshaller)
MarshallingMessageConverter
with the
given Marshaller and Unmarshaller.
marshaller
- the Marshaller to useunmarshaller
- the Unmarshaller to useMethod Detail |
---|
public void setMarshaller(Marshaller marshaller)
Marshaller
to be used by this message converter.
public void setUnmarshaller(Unmarshaller unmarshaller)
Unmarshaller
to be used by this message converter.
public void setTargetType(MessageType targetType)
toMessage(Object, Session)
should marshal to
a BytesMessage
or a TextMessage
.
The default is MessageType.BYTES
, i.e. this converter marshals
to a BytesMessage
. Note that the default version of this converter
supports MessageType.BYTES
and MessageType.TEXT
only.
MessageType.BYTES
,
MessageType.TEXT
public void afterPropertiesSet()
InitializingBean
This method allows the bean instance to perform initialization only possible when all bean properties have been set and to throw an exception in the event of misconfiguration.
afterPropertiesSet
in interface InitializingBean
public Message toMessage(java.lang.Object object, Session session) throws JMSException, MessageConversionException
javax.jms.TextMessage
or
javax.jms.BytesMessage
. The desired message type can be defined by setting
the "marshalTo"
property.
toMessage
in interface MessageConverter
object
- the object to convertsession
- the Session to use for creating a JMS Message
MessageConversionException
- in case of conversion failure
JMSException
marshalToTextMessage(java.lang.Object, Session, org.springframework.oxm.Marshaller)
,
marshalToBytesMessage(java.lang.Object, Session, org.springframework.oxm.Marshaller)
public java.lang.Object fromMessage(Message message) throws JMSException, MessageConversionException
Message
into an object.
fromMessage
in interface MessageConverter
message
- the message to convert
MessageConversionException
- in case of conversion failure
JMSException
unmarshalFromTextMessage(TextMessage, org.springframework.oxm.Unmarshaller)
,
unmarshalFromBytesMessage(BytesMessage, org.springframework.oxm.Unmarshaller)
protected TextMessage marshalToTextMessage(java.lang.Object object, Session session, Marshaller marshaller) throws JMSException, java.io.IOException, XmlMappingException
TextMessage
.
object
- the object to be marshalledsession
- current JMS sessionmarshaller
- the marshaller to use
JMSException
- if thrown by JMS methods
java.io.IOException
- in case of I/O errors
XmlMappingException
- in case of OXM mapping errorsSession#createTextMessage
,
Marshaller.marshal(Object, Result)
protected BytesMessage marshalToBytesMessage(java.lang.Object object, Session session, Marshaller marshaller) throws JMSException, java.io.IOException, XmlMappingException
BytesMessage
.
object
- the object to be marshalledsession
- current JMS sessionmarshaller
- the marshaller to use
JMSException
- if thrown by JMS methods
java.io.IOException
- in case of I/O errors
XmlMappingException
- in case of OXM mapping errorsSession#createBytesMessage
,
Marshaller.marshal(Object, Result)
protected Message marshalToMessage(java.lang.Object object, Session session, Marshaller marshaller, MessageType targetType) throws JMSException, java.io.IOException, XmlMappingException
setTargetType(org.springframework.jms.support.converter.MessageType)
is not MessageType.TEXT
or
MessageType.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)
JMSException
- if thrown by JMS methods
java.io.IOException
- in case of I/O errors
XmlMappingException
- in case of OXM mapping errorsprotected java.lang.Object unmarshalFromTextMessage(TextMessage message, Unmarshaller unmarshaller) throws JMSException, java.io.IOException, XmlMappingException
TextMessage
into an object.
message
- the messageunmarshaller
- the unmarshaller to use
JMSException
- if thrown by JMS methods
java.io.IOException
- in case of I/O errors
XmlMappingException
- in case of OXM mapping errorsUnmarshaller.unmarshal(Source)
protected java.lang.Object unmarshalFromBytesMessage(BytesMessage message, Unmarshaller unmarshaller) throws JMSException, java.io.IOException, XmlMappingException
BytesMessage
into an object.
message
- the messageunmarshaller
- the unmarshaller to use
JMSException
- if thrown by JMS methods
java.io.IOException
- in case of I/O errors
XmlMappingException
- in case of OXM mapping errorsUnmarshaller.unmarshal(Source)
protected java.lang.Object unmarshalFromMessage(Message message, Unmarshaller unmarshaller) throws JMSException, java.io.IOException, XmlMappingException
fromMessage(Message)
is invoked with a message
that is not a TextMessage
or BytesMessage
.
The default implemenetation throws an IllegalArgumentException
.
message
- the messageunmarshaller
- the unmarshaller to use
JMSException
- if thrown by JMS methods
java.io.IOException
- in case of I/O errors
XmlMappingException
- in case of OXM mapping errors
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |