KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > impl > message > BaseMessage


1 /*
2  * $Id: BaseMessage.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.impl.message;
12
13 import java.io.Serializable JavaDoc;
14 import java.util.HashMap JavaDoc;
15 import java.util.Map JavaDoc;
16
17 /**
18  * <code>BaseMessage</code> A default message implementation used for messages sent
19  * over the wire. client messages should NOT implement UMOMessage.
20  *
21  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
22  * @version $Revision: 3798 $
23  */

24 public class BaseMessage implements Serializable JavaDoc
25 {
26     /**
27      * Serial version
28      */

29     private static final long serialVersionUID = -6105691921086093748L;
30
31     protected Object JavaDoc message;
32
33     protected Map JavaDoc context;
34
35     public BaseMessage(Object JavaDoc message)
36     {
37         this.message = message;
38         context = new HashMap JavaDoc();
39     }
40
41     /**
42      * Converts the message implementation into a String representation
43      *
44      * @return String representation of the message payload
45      * @throws Exception Implementation may throw an endpoint specific exception
46      */

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

58     public byte[] getPayloadAsBytes() throws Exception JavaDoc
59     {
60         return getPayloadAsString(message.toString()).getBytes();
61     }
62
63     /**
64      * @return the current message
65      */

66     public Object JavaDoc getPayload()
67     {
68         return message;
69     }
70
71     /**
72      * Adds a map of properties to associated with this message
73      *
74      * @param properties the properties add to this message
75      */

76     public void addProperties(Map JavaDoc properties)
77     {
78         context.putAll(properties);
79     }
80
81     /**
82      * Removes all properties on this message
83      */

84     public void clearProperties()
85     {
86         context.clear();
87     }
88
89     /**
90      * Returns a map of all properties on this message
91      *
92      * @return a map of all properties on this message
93      */

94     public Map JavaDoc getProperties()
95     {
96         return context;
97     }
98
99     public void setProperty(Object JavaDoc key, Object JavaDoc value)
100     {
101         context.put(key, value);
102     }
103
104     public Object JavaDoc getProperty(Object JavaDoc key)
105     {
106         return context.get(key);
107     }
108
109     public String JavaDoc toString()
110     {
111         return "BaseMessage{" + "message=" + message + ", context=" + context + "}";
112     }
113 }
114
Popular Tags