KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > providers > tcp > TcpMessageAdapter


1 /*
2  * $Id: TcpMessageAdapter.java 3798 2006-11-04 04:07:14Z aperepel $
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 MuleSource MPL
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.tcp;
12
13 import org.mule.providers.AbstractMessageAdapter;
14 import org.mule.umo.MessagingException;
15 import org.mule.umo.provider.MessageTypeNotSupportedException;
16
17 /**
18  * <code>TcpMessageAdapter</code> TODO
19  *
20  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
21  * @version $Revision: 3798 $
22  */

23
24 public class TcpMessageAdapter extends AbstractMessageAdapter
25 {
26     /**
27      * Serial version
28      */

29     private static final long serialVersionUID = 7229837140160407794L;
30
31     private byte[] message;
32
33     public TcpMessageAdapter(Object JavaDoc message) throws MessagingException
34     {
35         if (message instanceof byte[])
36         {
37             this.message = (byte[])message;
38         }
39         else
40         {
41             throw new MessageTypeNotSupportedException(message, getClass());
42         }
43     }
44
45     /**
46      * Converts the message implementation into a String representation
47      *
48      * @param encoding The encoding to use when transforming the message (if
49      * necessary). The parameter is used when converting from a byte array
50      * @return String representation of the message payload
51      * @throws Exception Implementation may throw an endpoint specific exception
52      */

53     public String JavaDoc getPayloadAsString(String JavaDoc encoding) throws Exception JavaDoc
54     {
55         return new String JavaDoc(message, encoding);
56     }
57
58     public byte[] getPayloadAsBytes() throws Exception JavaDoc
59     {
60         return message;
61     }
62
63     public Object JavaDoc getPayload()
64     {
65         return message;
66     }
67 }
68
Popular Tags