30 Message::Message(
string xml)
35 Document doc = parser.getDocument(xml);
36 Element message = doc.getRootElement();
37 if(message.getTagName()!=
"message")
41 else if(message.getChildElements().size()!=2)
45 Element headers = message.getChildElements().at(0);
46 Element body = message.getChildElements().at(1);
47 if(headers.getTagName()!=
"headers")
51 else if(body.getTagName()!=
"body")
55 Element destination = headers.getElementByName(
"destination");
56 Element encoding = headers.getElementByName(
"encoding");
57 Element timestamp = headers.getElementByName(
"timestamp");
58 Element priority = headers.getElementByName(
"priority");
59 Element type = headers.getElementByName(
"type");
60 Element userid = headers.getElementByName(
"userid");
61 if(destination.getTagName()!=
"destination")
65 else if (destination.getAttributes().size()!=2)
69 else if (destination.getAttribute(
"name")==
"" || destination.getAttribute(
"type")==
"")
73 else if(type.getTagName()!=
"type")
78 des.setName(destination.getAttribute(
"name"));
79 des.setType(destination.getAttribute(
"type"));
80 this->destination = des;
81 this->body = body.getText();
82 this->timestamp = timestamp.getText();
83 this->type = type.getText();
84 this->priority = priority.getText();
85 this->userId = userid.getText();
86 this->encoding = encoding.getText();
96 Element message = doc.getRootElement();
97 if(message.getTagName()!=
"message")
101 else if(message.getChildElements().size()!=2)
105 Element headers = message.getChildElements().at(0);
106 Element body = message.getChildElements().at(1);
107 if(headers.getTagName()!=
"headers")
111 else if(body.getTagName()!=
"body")
115 Element destination = headers.getElementByName(
"destination");
116 Element encoding = headers.getElementByName(
"encoding");
117 Element timestamp = headers.getElementByName(
"timestamp");
118 Element priority = headers.getElementByName(
"priority");
119 Element type = headers.getElementByName(
"type");
120 Element userid = headers.getElementByName(
"userid");
121 if(destination.getTagName()!=
"destination")
125 else if (destination.getAttributes().size()!=2)
129 else if (destination.getAttribute(
"name")==
"" || destination.getAttribute(
"type")==
"")
133 else if(type.getTagName()!=
"type")
138 des.setName(destination.getAttribute(
"name"));
139 des.setType(destination.getAttribute(
"type"));
140 this->destination = des;
141 this->body = body.getText();
142 this->timestamp = timestamp.getText();
143 this->type = type.getText();
144 this->priority = priority.getText();
145 this->userId = userid.getText();
146 this->encoding = encoding.getText();
149 string Message::toXml()
152 xml =
"<message>\n<headers>\n<destination ";
153 xml += (
"name=\""+this->getDestination().getName());
154 xml += (
"\" type=\""+this->getDestination().getType());
155 xml += (
"\"></destination>\n");
156 xml += (
"<timestamp>\n");
157 xml += (this->getTimestamp());
158 xml += (
"</timestamp>\n");
159 xml += (
"<priority>\n");
160 xml += (this->getPriority());
161 xml += (
"</priority>\n");
163 xml += (this->getType());
164 xml += (
"</type>\n");
165 xml += (
"<userId>\n");
166 xml += (this->getUserId());
167 xml += (
"</userId>\n");
168 xml += (
"<encoding>\n");
169 xml += (this->getEncoding());
170 xml += (
"</encoding>\n");
171 xml += (
"</headers>\n");
173 xml += (this->getBody());
174 xml += (
"</body>\n");
175 xml += (
"</message>\n");
179 Message::~Message() {
185 return this->destination;
188 void Message::setDestination(
Destination destination)
190 this->destination = destination;
193 string Message::getTimestamp()
const
195 return this->timestamp;
198 void Message::setTimestamp(
string timestamp)
200 this->timestamp = timestamp;
203 string Message::getType()
const
208 void Message::setType(
string type)
213 string Message::getPriority()
const
215 return this->priority;
218 void Message::setPriority(
string priority)
220 this->priority = priority;
223 string Message::getUserId()
const
228 void Message::setUserId(
string userId)
230 this->userId = userId;
233 string Message::getBody()
const
238 void Message::setBody(
string body)
243 string Message::getEncoding()
const
245 return this->encoding;
248 void Message::setEncoding(
string encoding)
250 this->encoding = encoding;