View Javadoc

1   /*
2    * $Id: RmiMessageAdapter.java 7976 2007-08-21 14:26:13Z 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      {
32          if (message == null)
33          {
34              throw new MessageTypeNotSupportedException(null, getClass());
35          }
36          this.message = message;
37      }
38  
39      protected RmiMessageAdapter(RmiMessageAdapter template)
40      {
41          super(template);
42          message = template.message;
43      }
44  
45      public byte[] getPayloadAsBytes() throws Exception
46      {
47          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          return message.toString();
61      }
62  
63      public Object getPayload()
64      {
65          return message;
66      }
67  
68      public ThreadSafeAccess newThreadCopy()
69      {
70          return new RmiMessageAdapter(this);
71      }
72      
73  }