KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > providers > vm > VMMessageAdapter


1 /*
2  * $Id: VMMessageAdapter.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.vm;
12
13 import org.mule.providers.AbstractMessageAdapter;
14 import org.mule.umo.UMOMessage;
15 import org.mule.umo.provider.MessageTypeNotSupportedException;
16
17 /**
18  * <code>VMMessageAdapter</code> provides a common abstraction of Mule Event
19  * message. The message adapter allows a Mule event to be read and manipulated like
20  * any other object data type from any external system that has a Mule endpoint
21  * implementation.
22  *
23  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
24  * @version $Revision: 3798 $
25  */

26 public class VMMessageAdapter extends AbstractMessageAdapter
27 {
28     /**
29      * Serial version
30      */

31     private static final long serialVersionUID = 4037066880189053665L;
32
33     /**
34      * The message itself in this case an UMOEvent
35      */

36     private UMOMessage message = null;
37
38     public VMMessageAdapter(UMOMessage message) throws MessageTypeNotSupportedException
39     {
40         setMessage(message);
41     }
42
43     /**
44      * Converts the message implementation into a String representation
45      *
46      * @param encoding The encoding to use when transforming the message (if
47      * necessary). The parameter is used when converting from a byte array
48      * @return String representation of the message payload
49      * @throws Exception Implementation may throw an endpoint specific exception
50      */

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

62     public byte[] getPayloadAsBytes() throws Exception JavaDoc
63     {
64         return convertToBytes(message.getPayload());
65     }
66
67     /**
68      * @return the current message
69      */

70     public Object JavaDoc getPayload()
71     {
72         return message;
73     }
74
75     /**
76      * @param message new value for the message
77      */

78     private void setMessage(UMOMessage message) throws MessageTypeNotSupportedException
79     {
80         if (message == null)
81         {
82             throw new MessageTypeNotSupportedException(null, getClass());
83         }
84         this.message = message;
85     }
86
87     public String JavaDoc getUniqueId()
88     {
89         return message.getUniqueId();
90     }
91
92 }
93
Popular Tags