Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
RmiMessageAdapter |
|
| 1.3333333333333333;1.333 |
1 | /* | |
2 | * $Id: RmiMessageAdapter.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.rmi; | |
12 | ||
13 | import org.mule.impl.ThreadSafeAccess; | |
14 | import org.mule.providers.AbstractMessageAdapter; | |
15 | import org.mule.umo.provider.MessageTypeNotSupportedException; | |
16 | ||
17 | /** | |
18 | * Wraps an object obtained by calling a method on a Remote object | |
19 | */ | |
20 | ||
21 | public class RmiMessageAdapter extends AbstractMessageAdapter | |
22 | { | |
23 | /** | |
24 | * Serial version | |
25 | */ | |
26 | private static final long serialVersionUID = -1765089871661318129L; | |
27 | ||
28 | private final Object message; | |
29 | ||
30 | public RmiMessageAdapter(Object message) throws MessageTypeNotSupportedException | |
31 | 30 | { |
32 | 30 | if (message == null) |
33 | { | |
34 | 2 | throw new MessageTypeNotSupportedException(null, getClass()); |
35 | } | |
36 | 28 | this.message = message; |
37 | 28 | } |
38 | ||
39 | protected RmiMessageAdapter(RmiMessageAdapter template) | |
40 | { | |
41 | 0 | super(template); |
42 | 0 | message = template.message; |
43 | 0 | } |
44 | ||
45 | public byte[] getPayloadAsBytes() throws Exception | |
46 | { | |
47 | 2 | return convertToBytes(getPayload()); |
48 | } | |
49 | ||
50 | /** | |
51 | * Converts the message implementation into a String representation | |
52 | * | |
53 | * @param encoding The encoding to use when transforming the message (if | |
54 | * necessary). The parameter is used when converting from a byte array | |
55 | * @return String representation of the message payload | |
56 | * @throws Exception Implementation may throw an endpoint specific exception | |
57 | */ | |
58 | public String getPayloadAsString(String encoding) throws Exception | |
59 | { | |
60 | 2 | return message.toString(); |
61 | } | |
62 | ||
63 | public Object getPayload() | |
64 | { | |
65 | 26 | return message; |
66 | } | |
67 | ||
68 | public ThreadSafeAccess newThreadCopy() | |
69 | { | |
70 | 0 | return new RmiMessageAdapter(this); |
71 | } | |
72 | ||
73 | } |