1
19
20 package com.liferay.portal.kernel.messaging;
21
22 import com.liferay.portal.kernel.util.GetterUtil;
23 import com.liferay.portal.kernel.util.Validator;
24
25 import java.io.Serializable;
26
27 import java.util.HashMap;
28 import java.util.Map;
29
30
37 public class Message implements Serializable {
38
39 public Object get(String key) {
40 if (_values == null) {
41 return null;
42 }
43 else {
44 return _values.get(key);
45 }
46 }
47
48 public boolean getBoolean(String key) {
49 boolean value;
50
51 Object object = get(key);
52
53 if (object instanceof Boolean) {
54 value = ((Boolean)object).booleanValue();
55 }
56 else {
57 value = GetterUtil.getBoolean((String)object);
58 }
59
60 return value;
61 }
62
63 public String getDestination() {
64 return _destination;
65 }
66
67 public double getDouble(String key) {
68 double value;
69
70 Object object = get(key);
71
72 if (object instanceof Number) {
73 value = ((Number)object).doubleValue();
74 }
75 else {
76 value = GetterUtil.getDouble((String)object);
77 }
78
79 return value;
80 }
81
82 public int getInteger(String key) {
83 int value;
84
85 Object object = get(key);
86
87 if (object instanceof Number) {
88 value = ((Number)object).intValue();
89 }
90 else {
91 value = GetterUtil.getInteger((String)object);
92 }
93
94 return value;
95 }
96
97 public long getLong(String key) {
98 long value;
99
100 Object object = get(key);
101
102 if (object instanceof Number) {
103 value = ((Number)object).longValue();
104 }
105 else {
106 value = GetterUtil.getLong((String)object);
107 }
108
109 return value;
110 }
111
112 public Object getPayload() {
113 return _payload;
114 }
115
116 public String getResponseDestination() {
117 return _responseDestination;
118 }
119
120 public String getResponseId() {
121 return _responseId;
122 }
123
124 public String getString(String key) {
125 return GetterUtil.getString(String.valueOf(get(key)));
126 }
127
128 public void put(String key, Object value) {
129 if (_values == null) {
130 _values = new HashMap<String, Object>();
131 }
132
133 _values.put(key, value);
134 }
135
136 public void setDestination(String destination) {
137 _destination = destination;
138
139 if (Validator.isNull(_responseDestination)) {
140 _responseDestination =
141 _destination + _DEFAULT_RESPONSE_DESTINATION_SUFFIX;
142 }
143 }
144
145 public void setPayload(Object payload) {
146 _payload = payload;
147 }
148
149 public void setResponseDestination(String responseDestination) {
150 _responseDestination = responseDestination;
151 }
152
153 public void setResponseId(String responseId) {
154 _responseId = responseId;
155 }
156
157 public String toString() {
158 StringBuilder sb = new StringBuilder();
159
160 sb.append("{destination=");
161 sb.append(_destination);
162 sb.append(", responseDestination=");
163 sb.append(_responseDestination);
164 sb.append(", responseId=");
165 sb.append(_responseId);
166 sb.append(", payload=");
167 sb.append(_payload);
168 sb.append(", values=");
169 sb.append(_values);
170 sb.append("}");
171
172 return sb.toString();
173 }
174
175 private static final String _DEFAULT_RESPONSE_DESTINATION_SUFFIX =
176 "/response";
177
178 private String _destination;
179 private String _responseDestination;
180 private String _responseId;
181 private Object _payload;
182 private Map<String, Object> _values;
183
184 }