001/*
002 * Copyright 2002-2007 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.jms.support.converter;
018
019import javax.jms.JMSException;
020import javax.jms.Message;
021import javax.jms.Session;
022
023/**
024 * Strategy interface that specifies a converter between Java objects and JMS messages.
025 *
026 * <p>Check out {@link SimpleMessageConverter} for a default implementation,
027 * converting between the 'standard' message payloads and JMS Message types.
028 *
029 * @author Mark Pollack
030 * @author Juergen Hoeller
031 * @since 1.1
032 * @see org.springframework.jms.core.JmsTemplate#setMessageConverter
033 * @see org.springframework.jms.listener.adapter.MessageListenerAdapter#setMessageConverter
034 * @see org.springframework.jms.remoting.JmsInvokerClientInterceptor#setMessageConverter
035 * @see org.springframework.jms.remoting.JmsInvokerServiceExporter#setMessageConverter
036 */
037public interface MessageConverter {
038
039        /**
040         * Convert a Java object to a JMS Message using the supplied session
041         * to create the message object.
042         * @param object the object to convert
043         * @param session the Session to use for creating a JMS Message
044         * @return the JMS Message
045         * @throws javax.jms.JMSException if thrown by JMS API methods
046         * @throws MessageConversionException in case of conversion failure
047         */
048        Message toMessage(Object object, Session session) throws JMSException, MessageConversionException;
049
050        /**
051         * Convert from a JMS Message to a Java object.
052         * @param message the message to convert
053         * @return the converted Java object
054         * @throws javax.jms.JMSException if thrown by JMS API methods
055         * @throws MessageConversionException in case of conversion failure
056         */
057        Object fromMessage(Message message) throws JMSException, MessageConversionException;
058
059}