View Javadoc

1   /*
2    * $Id: BaseMessageDTO.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.message;
12  
13  import org.mule.transport.NullPayload;
14  
15  import java.io.Serializable;
16  import java.util.HashMap;
17  import java.util.Map;
18  
19  /**
20   * <code>BaseMessage</code> A default message implementation used for messages sent
21   * over the wire. client messages must NOT implement MuleMessage.
22   */
23  public class BaseMessageDTO implements Serializable
24  {
25      /**
26       * Serial version
27       */
28      private static final long serialVersionUID = -6105691921086093748L;
29  
30      private Object payload;
31  
32      protected Map<String, Object> properties;
33  
34      public BaseMessageDTO()
35      {
36          this(NullPayload.getInstance());
37      }
38  
39      public BaseMessageDTO(Object payload)
40      {
41          this.payload = payload;
42          properties = new HashMap<String, Object>();
43      }
44  
45  
46      public void setPayload(Object payload)
47      {
48          this.payload = payload;
49      }
50  
51      /**
52       * @return the current message
53       */
54      public Object getPayload()
55      {
56          return payload;
57      }
58  
59  
60      /**
61       * Adds a map of properties to associated with this message
62       *
63       * @param properties the properties add to this message
64       */
65      public void addProperties(Map<String, Object> properties)
66      {
67          this.properties.putAll(properties);
68      }
69  
70      /**
71       * Removes all properties on this message
72       */
73      public void clearProperties()
74      {
75          properties.clear();
76      }
77  
78      /**
79       * Returns a map of all properties on this message
80       *
81       * @return a map of all properties on this message
82       */
83      public Map getProperties()
84      {
85          return properties;
86      }
87  
88      public void setProperty(String key, Object value)
89      {
90          properties.put(key, value);
91      }
92  
93      public Object getProperty(String key)
94      {
95          return properties.get(key);
96      }
97  
98      public String toString()
99      {
100         return "BaseMessageDTO{" + "payload=" + payload + ", properties=" + properties + "}";
101     }
102 }