KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > providers > space > SpaceMessageAdapter


1 /*
2  * $Id: SpaceMessageAdapter.java 3865 2006-11-09 17:11:08Z 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.space;
12
13 import org.mule.providers.AbstractMessageAdapter;
14 import org.mule.umo.provider.MessageTypeNotSupportedException;
15 import org.mule.util.UUID;
16
17 /**
18  * Wraps a JavaSpaces Entry object
19  */

20 public class SpaceMessageAdapter extends AbstractMessageAdapter
21 {
22     /**
23      * Serial version
24      */

25     private static final long serialVersionUID = -2984429022763795361L;
26
27     private final String JavaDoc id;
28     private final Object JavaDoc message;
29
30     /**
31      * Creates a default message adapter with properties and attachments
32      *
33      * @param message the message to wrap. If this is null and NullPayload object
34      * will be used
35      * @see org.mule.providers.NullPayload
36      */

37     public SpaceMessageAdapter(Object JavaDoc message) throws MessageTypeNotSupportedException
38     {
39         if (message == null)
40         {
41             throw new MessageTypeNotSupportedException(null, getClass());
42         }
43         else
44         {
45             this.id = UUID.getUUID();
46             this.message = message;
47         }
48     }
49
50     public byte[] getPayloadAsBytes() throws Exception JavaDoc
51     {
52         return convertToBytes(getPayload());
53     }
54
55     /**
56      * Converts the message implementation into a String representation
57      *
58      * @param encoding The encoding to use when transforming the message (if
59      * necessary). The parameter is used when converting from a byte array
60      * @return String representation of the message payload
61      * @throws Exception Implementation may throw an endpoint specific exception
62      */

63     public String JavaDoc getPayloadAsString(String JavaDoc encoding) throws Exception JavaDoc
64     {
65         return message.toString();
66     }
67
68     /**
69      * @return the current message
70      */

71     public Object JavaDoc getPayload()
72     {
73         return message;
74     }
75
76     public String JavaDoc getUniqueId()
77     {
78         return id;
79     }
80
81 }
82
Popular Tags