/** * Parses protocol. * * @param xmlString protocol as XML string * @return protocol * @throws ProtocolException if error parsing protocol */ public Protocol parseProtocol(String xmlString) { try { Document doc = DomUtil.makeDomFromString(xmlString, false); String protocolName = ""; long flags = 0; List<String> vDest = null; StringAttributeMap properties = new StringAttributeMap(); NodeList protocolNL = doc.getElementsByTagName("protocol"); if (protocolNL.getLength() >= 1) { Node protocolN = protocolNL.item(0); NamedNodeMap attributes = protocolN.getAttributes(); Node protocolTypeN = attributes.getNamedItem("type"); protocolName = Val.chkStr(protocolTypeN != null ? protocolTypeN.getNodeValue() : ""); Node flagsN = attributes.getNamedItem("flags"); flags = flagsN != null ? Val.chkLong(Val.chkStr(flagsN.getNodeValue()), 0) : 0; Node destinationsN = attributes.getNamedItem("destinations"); String sDest = destinationsN != null ? Val.chkStr(destinationsN.getNodeValue()) : null; vDest = sDest != null ? Arrays.asList(sDest.split(",")) : null; NodeList propertiesNL = protocolN.getChildNodes(); for (int i = 0; i < propertiesNL.getLength(); i++) { Node property = propertiesNL.item(i); String propertyName = property.getNodeName(); String propertyValue = property.getTextContent(); properties.set(propertyName, propertyValue); } } ProtocolFactory protocolFactory = get(protocolName); if (protocolFactory == null) { throw new IllegalArgumentException("Unsupported protocol: " + protocolName); } Protocol protocol = protocolFactory.newProtocol(); protocol.setFlags(flags); protocol.applyAttributeMap(properties); ProtocolInvoker.setDestinations(protocol, vDest); return protocol; } catch (ParserConfigurationException ex) { throw new IllegalArgumentException("Error parsing protocol.", ex); } catch (SAXException ex) { throw new IllegalArgumentException("Error parsing protocol.", ex); } catch (IOException ex) { throw new IllegalArgumentException("Error parsing protocol.", ex); } }