Message::Message(const string& xml) { XmlParser parser("Parser"); Document doc; parser.parse(xml, doc); const Element& message = doc.getRootElement(); if(message.getTagName()!="message") { throw InvalidMessageException("No message Tag\n"); } else if(message.getChildElements().size()!=2) { throw InvalidMessageException("Every message should have a headers and body tag\n"); } Element* headers = message.getChildElements().at(0); Element* body = message.getChildElements().at(1); if(headers->getTagName()!="headers") { throw InvalidMessageException("No headers Tag\n"); } else if(body->getTagName()!="body") { throw InvalidMessageException("No body Tag\n"); } Element* destination = headers->getElementByName("destination"); Element* encoding = headers->getElementByName("encoding"); Element* timestamp = headers->getElementByName("timestamp"); Element* priority = headers->getElementByName("priority"); Element* type = headers->getElementByName("type"); Element* userid = headers->getElementByName("userid"); if(destination->getTagName()!="destination") { throw InvalidMessageException("Destination Header is mandatory\n"); } else if (destination->getAttributes().size()!=2) { throw InvalidMessageException("Type and Name Attributes should be speciifes for a Destination\n"); } else if (destination->getAttribute("name")=="" || destination->getAttribute("type")=="") { throw InvalidMessageException("Type and Name Attributes cannot be blank for a Destination\n"); } else if(type->getTagName()!="type") { throw InvalidMessageException("Type Header is mandatory\n"); } Destination des; des.setName(destination->getAttribute("name")); des.setType(destination->getAttribute("type")); this->destination = des; this->body = body->getText(); this->timestamp = timestamp->getText(); this->type = type->getText(); this->priority = priority->getText(); this->userId = userid->getText(); this->encoding = encoding->getText(); }
Destination *UdpDestination::duplicate() { Destination *d = new UdpDestination(ip_addr, port, ignorePort); if (d && name) d->setName(name); return d; }