1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portal.kernel.messaging;
21  
22  import com.liferay.portal.kernel.util.GetterUtil;
23  
24  import java.io.Serializable;
25  
26  import java.util.HashMap;
27  import java.util.Map;
28  
29  /**
30   * <a href="Message.java.html"><b><i>View Source</i></b></a>
31   *
32   * @author Brian Wing Shun Chan
33   * @author Michael C. Han
34   *
35   */
36  public class Message implements Serializable {
37  
38      public Object get(String key) {
39          if (_values == null) {
40              return null;
41          }
42          else {
43              return _values.get(key);
44          }
45      }
46  
47      public boolean getBoolean(String key) {
48          boolean value;
49  
50          Object object = get(key);
51  
52          if (object instanceof Boolean) {
53              value = ((Boolean)object).booleanValue();
54          }
55          else {
56              value = GetterUtil.getBoolean((String)object);
57          }
58  
59          return value;
60      }
61  
62      public String getDestination() {
63          return _destination;
64      }
65  
66      public double getDouble(String key) {
67          double value;
68  
69          Object object = get(key);
70  
71          if (object instanceof Number) {
72              value = ((Number)object).doubleValue();
73          }
74          else {
75              value = GetterUtil.getDouble((String)object);
76          }
77  
78          return value;
79      }
80  
81      public int getInteger(String key) {
82          int value;
83  
84          Object object = get(key);
85  
86          if (object instanceof Number) {
87              value = ((Number)object).intValue();
88          }
89          else {
90              value = GetterUtil.getInteger((String)object);
91          }
92  
93          return value;
94      }
95  
96      public long getLong(String key) {
97          long value;
98  
99          Object object = get(key);
100 
101         if (object instanceof Number) {
102             value = ((Number)object).longValue();
103         }
104         else {
105             value = GetterUtil.getLong((String)object);
106         }
107 
108         return value;
109     }
110 
111     public Object getPayload() {
112         return _payload;
113     }
114 
115     public String getResponseDestination() {
116         return _responseDestination;
117     }
118 
119     public String getResponseId() {
120         return _responseId;
121     }
122 
123     public String getString(String key) {
124         return GetterUtil.getString(String.valueOf(get(key)));
125     }
126 
127     public void put(String key, Object value) {
128         if (_values == null) {
129              _values = new HashMap<String, Object>();
130         }
131 
132         _values.put(key, value);
133     }
134 
135     public void setDestination(String destination) {
136         _destination = destination;
137     }
138 
139     public void setPayload(Object payload) {
140         _payload = payload;
141     }
142 
143     public void setResponseDestination(String responseDestination) {
144         _responseDestination = responseDestination;
145     }
146 
147     public void setResponseId(String responseId) {
148         _responseId = responseId;
149     }
150 
151     public String toString() {
152         StringBuilder sb = new StringBuilder();
153 
154         sb.append("{destination=");
155         sb.append(_destination);
156         sb.append(", responseDestination=");
157         sb.append(_responseDestination);
158         sb.append(", responseId=");
159         sb.append(_responseId);
160         sb.append(", payload=");
161         sb.append(_payload);
162         sb.append(", values=");
163         sb.append(_values);
164         sb.append("}");
165 
166         return sb.toString();
167     }
168 
169     private String _destination;
170     private Object _payload;
171     private String _responseDestination;
172     private String _responseId;
173     private Map<String, Object> _values;
174 
175 }