Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
OracleJmsMessageAdapter |
|
| 3.6666666666666665;3.667 |
1 | /* | |
2 | * $Id: OracleJmsMessageAdapter.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.oracle.jms; | |
12 | ||
13 | import org.mule.providers.jms.JmsMessageAdapter; | |
14 | import org.mule.umo.MessagingException; | |
15 | ||
16 | import oracle.jms.AdtMessage; | |
17 | import oracle.xdb.XMLType; | |
18 | ||
19 | /** | |
20 | * If the message payload is XML, returns the XML as a string. If the message payload | |
21 | * is an ADT, simply returns {@code Object.toString()} in order to avoid a null | |
22 | * pointer exception. Any other message is handled by the standard | |
23 | * {@code JmsMessageAdapter}. | |
24 | */ | |
25 | public class OracleJmsMessageAdapter extends JmsMessageAdapter | |
26 | { | |
27 | ||
28 | /** | |
29 | * Serial version | |
30 | */ | |
31 | private static final long serialVersionUID = -5304537031626649816L; | |
32 | ||
33 | public OracleJmsMessageAdapter(Object message) throws MessagingException | |
34 | { | |
35 | 10 | super(message); |
36 | 8 | } |
37 | ||
38 | /** | |
39 | * If the message payload is XML, returns the XML as an array of bytes. If the | |
40 | * message payload is an ADT, simply returns {@code Object.toString().getBytes()} | |
41 | * in order to avoid a null pointer exception. Any other message is handled by | |
42 | * the standard {@code JmsMessageAdapter} | |
43 | * | |
44 | * @see JmsMessageAdapter#getPayloadAsBytes | |
45 | */ | |
46 | public byte[] getPayloadAsBytes() throws Exception | |
47 | { | |
48 | 4 | Object jmsMessage = getPayload(); |
49 | 4 | if (jmsMessage instanceof AdtMessage) |
50 | { | |
51 | 0 | Object adtMessage = ((AdtMessage)jmsMessage).getAdtPayload(); |
52 | 0 | if (adtMessage instanceof XMLType) |
53 | { | |
54 | 0 | return ((XMLType)adtMessage).getBytesValue(); |
55 | } | |
56 | else | |
57 | { | |
58 | 0 | return adtMessage.toString().getBytes(getEncoding()); |
59 | } | |
60 | } | |
61 | else | |
62 | { | |
63 | 4 | return super.getPayloadAsBytes(); |
64 | } | |
65 | } | |
66 | ||
67 | /** | |
68 | * Converts the message implementation into a String representation | |
69 | * | |
70 | * @param encoding The encoding to use when transforming the message (if | |
71 | * necessary). The parameter is used when converting from a byte array | |
72 | * @return String representation of the message payload | |
73 | * @throws Exception Implementation may throw an endpoint specific exception | |
74 | */ | |
75 | public String getPayloadAsString(String encoding) throws Exception | |
76 | { | |
77 | 2 | Object jmsMessage = getPayload(); |
78 | 2 | if (jmsMessage instanceof AdtMessage) |
79 | { | |
80 | 0 | Object adtMessage = ((AdtMessage)jmsMessage).getAdtPayload(); |
81 | 0 | if (adtMessage instanceof XMLType) |
82 | { | |
83 | 0 | return ((XMLType)adtMessage).getStringVal(); |
84 | } | |
85 | else | |
86 | { | |
87 | 0 | return adtMessage.toString(); |
88 | } | |
89 | } | |
90 | else | |
91 | { | |
92 | 2 | return super.getPayloadAsString(encoding); |
93 | } | |
94 | } | |
95 | ||
96 | } |