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