KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > providers > dq > DQMessageAdapter


1 /*
2  * $Id: DQMessageAdapter.java 3982 2006-11-22 14:28:01Z 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.dq;
12
13 import org.mule.providers.AbstractMessageAdapter;
14 import org.mule.transformers.simple.SerializableToByteArray;
15 import org.mule.umo.provider.MessageTypeNotSupportedException;
16
17 /**
18  * <code>DQMessageAdapter</code> provides a wrapper for a DataQueue Message. Users
19  * can obtain the contents of the message through the payload property.
20  */

21 public class DQMessageAdapter extends AbstractMessageAdapter
22 {
23     /**
24      * Serial version
25      */

26     private static final long serialVersionUID = -7484858345063740661L;
27
28     private static final SerializableToByteArray serializableToByteArray = new SerializableToByteArray();
29
30     private final DQMessage message;
31
32     /**
33      * Constructor
34      *
35      * @param message The message
36      */

37     public DQMessageAdapter(Object JavaDoc message) throws MessageTypeNotSupportedException
38     {
39         if (message instanceof DQMessage)
40         {
41             this.message = (DQMessage)message;
42         }
43         else
44         {
45             throw new MessageTypeNotSupportedException(message, getClass());
46         }
47     }
48
49     /**
50      * @see org.mule.umo.provider.UMOMessageAdapter#getPayload()
51      */

52     public final Object JavaDoc getPayload()
53     {
54         return message;
55     }
56
57     /**
58      * @see org.mule.umo.provider.UMOMessageAdapter#getPayloadAsBytes()
59      */

60
61     public final byte[] getPayloadAsBytes() throws Exception JavaDoc
62     {
63         return (byte[])serializableToByteArray.doTransform(message, getEncoding());
64     }
65
66     /**
67      * Converts the message implementation into a String representation
68      *
69      * @param encoding The encoding to use when transforming the message (if
70      * necessary). The parameter is used when converting from a byte array
71      * @return String representation of the message payload
72      * @throws Exception Implementation may throw an endpoint specific exception
73      */

74     public String JavaDoc getPayloadAsString(String JavaDoc encoding) throws Exception JavaDoc
75     {
76         return new String JavaDoc(getPayloadAsBytes(), encoding);
77     }
78
79 }
80
Popular Tags