@Test public void testReadBootRecord () { try { URL url = new URL("file:src/test/resources/boot.xml"); uut.readBootRecord(url);; } catch (MalformedURLException e) { fail(e.toString()); } List<Object> items; Competition bc = uut.getBootstrapCompetition(); assertNotNull(bc, "found bootstrap competition"); items = uut.getData(CustomerInfo.class); assertEquals(11, items.size(), "11 customers"); assertEquals(336, uut.getData(WeatherReport.class).size(), "24 weather reports"); }
public void readBootRecord (URL bootUrl) { Document document = getDocument(bootUrl); XPathFactory factory = XPathFactory.newInstance(); XPath xPath = factory.newXPath(); try { XPathExpression exp = xPath.compile("/powertac-bootstrap-data/config/competition"); NodeList nodes = (NodeList) exp.evaluate(document, XPathConstants.NODESET); String xml = nodeToString(nodes.item(0)); bootstrapCompetition = (Competition) messageConverter.fromXML(xml); add(bootstrapCompetition); for (CustomerInfo cust: bootstrapCompetition.getCustomers()) add(cust); exp = xPath.compile("/powertac-bootstrap-data/bootstrap-state/properties"); nodes = (NodeList) exp.evaluate(document, XPathConstants.NODESET); if (null != nodes && nodes.getLength() > 0) { xml = nodeToString(nodes.item(0)); bootState = (Properties) messageConverter.fromXML(xml); } } catch (XPathExpressionException xee) { log.error("Error reading boot record from {}: {}", bootUrl, xee.toString()); System.out.println("Error reading boot dataset: " + xee.toString()); } processBootDataset(document); }
BootstrapDataRepo implements DomainRepo { public void readBootRecord (URL bootUrl) { Document document = getDocument(bootUrl); XPathFactory factory = XPathFactory.newInstance(); XPath xPath = factory.newXPath(); try { XPathExpression exp = xPath.compile("/powertac-bootstrap-data/config/competition"); NodeList nodes = (NodeList) exp.evaluate(document, XPathConstants.NODESET); String xml = nodeToString(nodes.item(0)); bootstrapCompetition = (Competition) messageConverter.fromXML(xml); add(bootstrapCompetition); for (CustomerInfo cust: bootstrapCompetition.getCustomers()) add(cust); exp = xPath.compile("/powertac-bootstrap-data/bootstrap-state/properties"); nodes = (NodeList) exp.evaluate(document, XPathConstants.NODESET); if (null != nodes && nodes.getLength() > 0) { xml = nodeToString(nodes.item(0)); bootState = (Properties) messageConverter.fromXML(xml); } } catch (XPathExpressionException xee) { log.error("Error reading boot record from {}: {}", bootUrl, xee.toString()); System.out.println("Error reading boot dataset: " + xee.toString()); } processBootDataset(document); } }
BootstrapDataRepo implements DomainRepo { public void readBootRecord (URL bootUrl) { Document document = getDocument(bootUrl); XPathFactory factory = XPathFactory.newInstance(); XPath xPath = factory.newXPath(); try { XPathExpression exp = xPath.compile("/powertac-bootstrap-data/config/competition"); NodeList nodes = (NodeList) exp.evaluate(document, XPathConstants.NODESET); String xml = nodeToString(nodes.item(0)); bootstrapCompetition = (Competition) messageConverter.fromXML(xml); add(bootstrapCompetition); for (CustomerInfo cust: bootstrapCompetition.getCustomers()) add(cust); exp = xPath.compile("/powertac-bootstrap-data/bootstrap-state/properties"); nodes = (NodeList) exp.evaluate(document, XPathConstants.NODESET); if (null != nodes && nodes.getLength() > 0) { xml = nodeToString(nodes.item(0)); bootState = (Properties) messageConverter.fromXML(xml); } } catch (XPathExpressionException xee) { log.error("Error reading boot record from {}: {}", bootUrl, xee.toString()); System.out.println("Error reading boot dataset: " + xee.toString()); } processBootDataset(document); } BootstrapDataRepo(); }
BootstrapDataRepo implements DomainRepo { public void readBootRecord (URL bootUrl) { Document document = getDocument(bootUrl); XPathFactory factory = XPathFactory.newInstance(); XPath xPath = factory.newXPath(); try { XPathExpression exp = xPath.compile("/powertac-bootstrap-data/config/competition"); NodeList nodes = (NodeList) exp.evaluate(document, XPathConstants.NODESET); String xml = nodeToString(nodes.item(0)); bootstrapCompetition = (Competition) messageConverter.fromXML(xml); add(bootstrapCompetition); for (CustomerInfo cust: bootstrapCompetition.getCustomers()) add(cust); exp = xPath.compile("/powertac-bootstrap-data/bootstrap-state/properties"); nodes = (NodeList) exp.evaluate(document, XPathConstants.NODESET); if (null != nodes && nodes.getLength() > 0) { xml = nodeToString(nodes.item(0)); bootState = (Properties) messageConverter.fromXML(xml); } } catch (XPathExpressionException xee) { log.error("Error reading boot record from {}: {}", bootUrl, xee.toString()); System.out.println("Error reading boot dataset: " + xee.toString()); } processBootDataset(document); } BootstrapDataRepo(); void add(Object item); void add(List<Object> items); List<Object> getData(); List<Object> getData(Class<?> type); Competition getBootstrapCompetition(); Properties getBootState(); @Override void recycle(); void readBootRecord(URL bootUrl); }
BootstrapDataRepo implements DomainRepo { public void readBootRecord (URL bootUrl) { Document document = getDocument(bootUrl); XPathFactory factory = XPathFactory.newInstance(); XPath xPath = factory.newXPath(); try { XPathExpression exp = xPath.compile("/powertac-bootstrap-data/config/competition"); NodeList nodes = (NodeList) exp.evaluate(document, XPathConstants.NODESET); String xml = nodeToString(nodes.item(0)); bootstrapCompetition = (Competition) messageConverter.fromXML(xml); add(bootstrapCompetition); for (CustomerInfo cust: bootstrapCompetition.getCustomers()) add(cust); exp = xPath.compile("/powertac-bootstrap-data/bootstrap-state/properties"); nodes = (NodeList) exp.evaluate(document, XPathConstants.NODESET); if (null != nodes && nodes.getLength() > 0) { xml = nodeToString(nodes.item(0)); bootState = (Properties) messageConverter.fromXML(xml); } } catch (XPathExpressionException xee) { log.error("Error reading boot record from {}: {}", bootUrl, xee.toString()); System.out.println("Error reading boot dataset: " + xee.toString()); } processBootDataset(document); } BootstrapDataRepo(); void add(Object item); void add(List<Object> items); List<Object> getData(); List<Object> getData(Class<?> type); Competition getBootstrapCompetition(); Properties getBootState(); @Override void recycle(); void readBootRecord(URL bootUrl);  }