KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > providers > stream > StreamMessageAdapter


1 /*
2  * $Id: StreamMessageAdapter.java 3937 2006-11-20 16:04:25Z lajos $
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.stream;
12
13 import org.mule.providers.AbstractMessageAdapter;
14 import org.mule.umo.provider.MessageTypeNotSupportedException;
15
16 /**
17  * <code>StreamMessageAdapter</code> TODO document
18  */

19 public class StreamMessageAdapter extends AbstractMessageAdapter
20 {
21     /**
22      * Serial version
23      */

24     private static final long serialVersionUID = 3094357859680956607L;
25
26     // TODO shouldn't this be an Object, for handling at least byte[]s too?
27
private final String JavaDoc message;
28
29     public StreamMessageAdapter(Object JavaDoc message) throws MessageTypeNotSupportedException
30     {
31         if (message instanceof String JavaDoc)
32         {
33             this.message = (String JavaDoc)message;
34         }
35         else
36         {
37             throw new MessageTypeNotSupportedException(message, StreamMessageAdapter.class);
38         }
39     }
40
41     /**
42      * Converts the message implementation into a String representation
43      *
44      * @param encoding The encoding to use when transforming the message (if
45      * necessary). The parameter is used when converting from a byte array
46      * @return String representation of the message payload
47      * @throws Exception Implementation may throw an endpoint specific exception
48      */

49     public String JavaDoc getPayloadAsString(String JavaDoc encoding) throws Exception JavaDoc
50     {
51         return message.toString();
52     }
53
54     /**
55      * Converts the message implementation into a String representation
56      *
57      * @return String representation of the message
58      * @throws Exception Implemetation may throw an endpoint specific exception
59      */

60     public byte[] getPayloadAsBytes() throws Exception JavaDoc
61     {
62         String JavaDoc msg = getPayloadAsString();
63         return msg.getBytes();
64     }
65
66     /**
67      * @return the current message
68      */

69     public Object JavaDoc getPayload()
70     {
71         return message;
72     }
73
74 }
75
Popular Tags