KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > providers > jms > transformers > ObjectToJMSMessage


1 /*
2  * $Id: ObjectToJMSMessage.java 3798 2006-11-04 04:07:14Z aperepel $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.providers.jms.transformers;
12
13 import org.mule.umo.transformer.TransformerException;
14
15 /**
16  * <code>ObjectToJMSMessage</code> will convert any object to a
17  * <code>javax.jms.Message</code> or sub-type into an object. One of the 5 types of
18  * JMS message will be created based on the type of Object passed in.
19  * <ul>
20  * <li>java.lang.String - javax.jms.TextMessage</li>
21  * <li>byte[] - javax.jms.BytesMessage</li>
22  * <li>java.util.Map - javax.jms.MapMessage</li>
23  * <li>java.io.InputStream - javax.jms.StreamMessage</li>
24  * <li>java.lang.Object - javax.jms.ObjectMessage</li>
25  * </ul>
26  * Note that if compression is turned on then a <code>javax.jms.BytesMessage</code>
27  * is sent.
28  */

29
30 public class ObjectToJMSMessage extends AbstractJmsTransformer
31 {
32     /**
33      * Serial version
34      */

35     private static final long serialVersionUID = 6900208781863624801L;
36
37     public Object JavaDoc doTransform(Object JavaDoc src, String JavaDoc encoding) throws TransformerException
38     {
39         try
40         {
41             if (logger.isDebugEnabled())
42             {
43                 logger.debug("Source object is " + src.getClass().getName());
44             }
45
46             Object JavaDoc result = transformToMessage(src);
47
48             if (logger.isDebugEnabled())
49             {
50                 logger.debug("Resulting object is " + result.getClass().getName());
51             }
52
53             return result;
54         }
55         catch (Exception JavaDoc e)
56         {
57             throw new TransformerException(this, e);
58         }
59     }
60
61 }
62
Popular Tags