/** Create a query header from an XML node. * * @param node The <queryAttributes> node. */ public QueryHeader(Node node) { if (!"queryAttributes".equals(node.getNodeName())) { throw new IllegalArgumentException("QueryHeader must be constructed from <queryAttributes> node, not <" + node.getNodeName() + ">"); } NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); ++i) { Node child = children.item(i); if ("queryId".equals(child.getNodeName())) { id = XML.unwrappedText(child); } else if ("queryTitle".equals(child.getNodeName())) { title = XML.unwrappedText(child); } else if ("queryDesc".equals(child.getNodeName())) { description = XML.unwrappedText(child); } else if ("queryType".equals(child.getNodeName())) { type = XML.unwrappedText(child); } else if ("queryStatusId".equals(child.getNodeName())) { statusID = XML.unwrappedText(child); } else if ("querySecurityType".equals(child.getNodeName())) { securityType = XML.unwrappedText(child); } else if ("queryParentId".equals(child.getNodeName())) { } else if ("queryChildId".equals(child.getNodeName())) { } else if ("queryRevisionNote".equals(child.getNodeName())) { revisionNote = XML.unwrappedText(child); } else if ("queryDataDictId".equals(child.getNodeName())) { dataDictID = XML.unwrappedText(child); } } }
public void testXML() throws Exception { QueryElement q1 = new QueryElement("a", "1"); Document doc = XML.createDocument(); Node root = q1.toXML(doc); assertEquals("queryElement", root.getNodeName()); NodeList children = root.getChildNodes(); for (int i = 0; i < children.getLength(); ++i) { Node child = children.item(i); if ("tokenRole".equals(child.getNodeName())) { assertEquals("a", XML.text(child)); } else if ("tokenValue".equals(child.getNodeName())) { assertEquals("1", XML.text(child)); } else fail("Unknown node \"" + child.getNodeName() + "\" in XML result"); } QueryElement q2 = new QueryElement(root); assertEquals(q1, q2); }
public Node toXML(Document doc) throws DOMException { Element root = doc.createElement("queryAttributes"); XML.add(root, "queryId", getID()); XML.add(root, "queryTitle", getTitle()); XML.add(root, "queryDesc", getDescription()); XML.add(root, "queryType", getType()); XML.add(root, "queryStatusId", getStatusID()); XML.add(root, "querySecurityType", getSecurityType()); XML.add(root, "queryRevisionNote", getRevisionNote()); XML.add(root, "queryDataDictId", getDataDictID()); return root; }