Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ObjectToJMSMessage |
|
| 0.0;0 |
1 | /* | |
2 | * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com | |
3 | * The software in this package is published under the terms of the CPAL v1.0 | |
4 | * license, a copy of which has been included with this distribution in the | |
5 | * LICENSE.txt file. | |
6 | */ | |
7 | package org.mule.transport.jms.transformers; | |
8 | ||
9 | import org.mule.api.MuleMessage; | |
10 | import org.mule.api.transformer.TransformerException; | |
11 | import org.mule.transformer.types.DataTypeFactory; | |
12 | import org.mule.util.ClassUtils; | |
13 | ||
14 | import javax.jms.Message; | |
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 | public class ObjectToJMSMessage extends AbstractJmsTransformer | |
31 | { | |
32 | ||
33 | public ObjectToJMSMessage() | |
34 | { | |
35 | 0 | super(); |
36 | 0 | } |
37 | ||
38 | @Override | |
39 | protected void declareInputOutputClasses() | |
40 | { | |
41 | 0 | setReturnDataType(DataTypeFactory.create(Message.class)); |
42 | 0 | } |
43 | ||
44 | @Override | |
45 | public Object transformMessage(MuleMessage message, String outputEncoding) throws TransformerException | |
46 | { | |
47 | try | |
48 | { | |
49 | 0 | if (logger.isDebugEnabled()) |
50 | { | |
51 | 0 | logger.debug("Source object is " + ClassUtils.getSimpleName(message.getPayload().getClass())); |
52 | } | |
53 | ||
54 | 0 | Object result = transformToMessage(message); |
55 | ||
56 | 0 | if (logger.isDebugEnabled()) |
57 | { | |
58 | 0 | logger.debug("Resulting object is " + ClassUtils.getSimpleName(result.getClass())); |
59 | } | |
60 | ||
61 | 0 | return result; |
62 | } | |
63 | 0 | catch (Exception e) |
64 | { | |
65 | 0 | throw new TransformerException(this, e); |
66 | } | |
67 | } | |
68 | ||
69 | } |