KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > providers > gs > GigaSpacesMessageAdapter


1 /*
2  * $Id: GigaSpacesMessageAdapter.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.gs;
12
13 import net.jini.core.entry.Entry;
14
15 import org.mule.providers.AbstractMessageAdapter;
16 import org.mule.umo.provider.MessageTypeNotSupportedException;
17 import org.mule.umo.provider.UMOMessageAdapter;
18
19 import com.j_spaces.core.client.ExternalEntry;
20
21 public class GigaSpacesMessageAdapter extends AbstractMessageAdapter
22 {
23     /**
24      * Serial version
25      */

26     private static final long serialVersionUID = 2895659875976934721L;
27
28     private static final GigaSpacesEntryConverter converter = new GigaSpacesEntryConverter();
29
30     private final Object JavaDoc message;
31
32     /**
33      * Creates a default message adapter with properties and attachments
34      *
35      * @param message the message to wrap. If this is null and NullPayload object
36      * will be used
37      * @see org.mule.providers.NullPayload
38      */

39     public GigaSpacesMessageAdapter(Object JavaDoc message) throws MessageTypeNotSupportedException
40     {
41         if (message == null)
42         {
43             // TODO this is not what the javadocs say?!
44
throw new MessageTypeNotSupportedException(null, getClass());
45         }
46         else
47         {
48             this.message = message;
49         }
50     }
51
52     /**
53      * @see UMOMessageAdapter#getPayloadAsBytes()
54      */

55     public byte[] getPayloadAsBytes() throws Exception JavaDoc
56     {
57         return convertToBytes(getPayload());
58     }
59
60     /**
61      * @see UMOMessageAdapter#getPayloadAsString()
62      */

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

71     public Object JavaDoc getPayload()
72     {
73         if (message instanceof ExternalEntry)
74         {
75             return converter.toPojo((Entry)message);
76         }
77         return message;
78     }
79
80 }
81
Popular Tags