View Javadoc

1   /*
2    * $Id: ObjectToJMSMessage.java 7963 2007-08-21 08:53:15Z dirk.olmes $
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 CPAL v1.0
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  import org.mule.util.ClassUtils;
15  
16  /**
17   * <code>ObjectToJMSMessage</code> will convert any object to a
18   * <code>javax.jms.Message</code> or sub-type into an object. One of the 5 types of
19   * JMS message will be created based on the type of Object passed in.
20   * <ul>
21   * <li>java.lang.String - javax.jms.TextMessage</li>
22   * <li>byte[] - javax.jms.BytesMessage</li>
23   * <li>java.util.Map - javax.jms.MapMessage</li>
24   * <li>java.io.InputStream - javax.jms.StreamMessage</li>
25   * <li>java.lang.Object - javax.jms.ObjectMessage</li>
26   * </ul>
27   * Note that if compression is turned on then a <code>javax.jms.BytesMessage</code>
28   * is sent.
29   */
30  
31  public class ObjectToJMSMessage extends AbstractJmsTransformer
32  {
33  
34      public Object doTransform(Object src, String encoding) throws TransformerException
35      {
36          try
37          {
38              if (logger.isDebugEnabled())
39              {
40                  logger.debug("Source object is " + ClassUtils.getSimpleName(src.getClass()));
41              }
42  
43              Object result = transformToMessage(src);
44  
45              if (logger.isDebugEnabled())
46              {
47                  logger.debug("Resulting object is " + ClassUtils.getSimpleName(result.getClass()));
48              }
49  
50              return result;
51          }
52          catch (Exception e)
53          {
54              throw new TransformerException(this, e);
55          }
56      }
57  
58  }