/** * Parses the FpML document extracting the trades. * <p> * This parses the specified FpML root element, using the map of references. * The FpML specification uses references to link one part of the XML to another. * For example, if one part of the XML has {@code <foo id="fooId">}, the references * map will contain an entry mapping "fooId" to the parsed element {@code <foo>}. * * @param fpmlRootEl the source of the FpML XML document * @param references the map of id/href to referenced element * @return the parsed trades * @throws RuntimeException if a parse error occurred */ public List<Trade> parseTrades( XmlElement fpmlRootEl, Map<String, XmlElement> references) { FpmlDocument document = new FpmlDocument(fpmlRootEl, references, ourPartySelector, tradeInfoParser, refData); List<XmlElement> tradeEls = document.getFpmlRoot().getChildren("trade"); ImmutableList.Builder<Trade> builder = ImmutableList.builder(); for (XmlElement tradeEl : tradeEls) { builder.add(parseTrade(document, tradeEl)); } return builder.build(); }
public void document() { XmlElement tradeDateEl = XmlElement.ofContent("tradeDate", "2000-06-30"); XmlElement tradeHeaderEl = XmlElement.ofChildren("tradeHeader", ImmutableList.of(tradeDateEl)); XmlElement tradeEl = XmlElement.ofChildren("trade", ImmutableMap.of("href", "foo"), ImmutableList.of(tradeHeaderEl)); XmlElement rootEl = XmlElement.ofChildren("dataDocument", ImmutableList.of(tradeEl)); FpmlDocument test = new FpmlDocument(rootEl, ImmutableMap.of(), FpmlPartySelector.any(), FpmlTradeInfoParserPlugin.standard(), REF_DATA); assertEquals(test.getFpmlRoot(), rootEl); assertEquals(test.getParties(), ImmutableListMultimap.of()); assertEquals(test.getReferences(), ImmutableMap.of()); assertEquals(test.getOurPartyHrefIds(), ImmutableList.of()); assertThrows(() -> test.lookupReference(tradeEl), FpmlParseException.class, ".*reference not found.*"); assertThrows(() -> test.validateNotPresent(tradeEl, "tradeHeader"), FpmlParseException.class, ".*tradeHeader.*"); }