1 /* 2 * Copyright 2002-2007 the original author or authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package org.springframework.jms.support.converter; 18 19 import javax.jms.JMSException; 20 import javax.jms.Message; 21 import javax.jms.Session; 22 23 /** 24 * Strategy interface that specifies a converter between Java objects and JMS messages. 25 * 26 * <p>Check out {@link SimpleMessageConverter} for a default implementation, 27 * converting between the 'standard' message payloads and JMS Message types. 28 * 29 * @author Mark Pollack 30 * @author Juergen Hoeller 31 * @since 1.1 32 * @see org.springframework.jms.core.JmsTemplate#setMessageConverter 33 * @see org.springframework.jms.listener.adapter.MessageListenerAdapter#setMessageConverter 34 * @see org.springframework.jms.remoting.JmsInvokerClientInterceptor#setMessageConverter 35 * @see org.springframework.jms.remoting.JmsInvokerServiceExporter#setMessageConverter 36 */ 37 public interface MessageConverter { 38 39 /** 40 * Convert a Java object to a JMS Message using the supplied session 41 * to create the message object. 42 * @param object the object to convert 43 * @param session the Session to use for creating a JMS Message 44 * @return the JMS Message 45 * @throws javax.jms.JMSException if thrown by JMS API methods 46 * @throws MessageConversionException in case of conversion failure 47 */ 48 Message toMessage(Object object, Session session) throws JMSException, MessageConversionException; 49 50 /** 51 * Convert from a JMS Message to a Java object. 52 * @param message the message to convert 53 * @return the converted Java object 54 * @throws javax.jms.JMSException if thrown by JMS API methods 55 * @throws MessageConversionException in case of conversion failure 56 */ 57 Object fromMessage(Message message) throws JMSException, MessageConversionException; 58 59 }