Source code: org/mule/providers/vm/MuleMessageAdapter.java
1 /*
2 * $Header: /cvsroot/mule/mule/src/java/org/mule/providers/vm/MuleMessageAdapter.java,v 1.4 2003/10/20 21:44:38 rossmason Exp $
3 * $Revision: 1.4 $
4 * $Date: 2003/10/20 21:44:38 $
5 * ------------------------------------------------------------------------------------------------------
6 *
7 * Copyright (c) Cubis Limited. All rights reserved.
8 * http://www.cubis.co.uk
9 *
10 * The software in this package is published under the terms of the BSD
11 * style license a copy of which has been included with this distribution in
12 * the LICENSE.txt file.
13 *
14 */
15 package org.mule.providers.vm;
16
17 import java.util.HashMap;
18 import java.util.Iterator;
19
20 import org.mule.umo.provider.UMOMessageAdapter;
21 import org.mule.util.Utility;
22
23 /**
24 * <p><code>MuleMessageAdapter</code> provides a common abstraction of Mule Event message.
25 * The message adapter allows a Mule event to be read and manipulated like any other object
26 * data type from any external system that has a Mule provider implementation.
27
28 *
29 * @author <a href="mailto:ross.mason@cubis.co.uk">Ross Mason</a>
30 * @version $Revision: 1.4 $
31 *
32 */
33 public class MuleMessageAdapter implements UMOMessageAdapter
34 {
35 /** The message itself in this case an UMOEvent */
36 Object message = null;
37
38 /** Any properties bound to the message */
39 HashMap props = new HashMap();
40 /**
41 * Gets a property of the message implementation
42 * @param key the key on which to lookup the property value
43 * @return the property value or null if the property does not exist
44 */
45 public Object getProperty(Object key)
46 {
47 return props.get(key.toString());
48 }
49
50 /**
51 * Gets a property of the message implementation
52 * @param key the key on which to associate the value
53 * @param value the property value
54 */
55 public void setProperty(Object key, Object value)
56 {
57 props.put(key.toString(), value);
58 }
59
60 /**
61 * Converts the message implementation into a String representation
62 * @return String representation of the message
63 * @throws Exception Implemetation may throw a provider specific exception
64 */
65 public String getMessageAsString() throws Exception
66 {
67 return message.toString();
68 }
69
70 /**
71 *
72 * @return all properties on this message
73 */
74 public Iterator getPropertyNames()
75 {
76 return props.keySet().iterator();
77 }
78
79 /**
80 * Converts the message implementation into a String representation
81 * @return String representation of the message
82 * @throws Exception Implemetation may throw a provider specific exception
83 */
84 public byte[] getMessageAsBytes() throws Exception
85 {
86 return Utility.objectToByteArray(message);
87 }
88
89 /**
90 *
91 * @return the current message
92 */
93 public Object getMessage()
94 {
95 return message;
96 }
97
98 /**
99 *
100 * @param message new value for the message
101 */
102 public void setMessage(Object message)
103 {
104 this.message = message;
105 }
106 }