private Trade parseTrade(FpmlDocument document, XmlElement tradeEl) { // find which trade type it is by comparing children to known parsers for (Entry<String, FpmlParserPlugin> entry : tradeParsers.entrySet()) { Optional<XmlElement> productOptEl = tradeEl.findChild(entry.getKey()); if (productOptEl.isPresent()) { return entry.getValue().parseTrade(document, tradeEl); } } // failed to find a known trade type ImmutableSet<String> childNames = tradeEl.getChildren().stream().map(XmlElement::getName).collect(toImmutableSet()); throw new FpmlParseException("Unknown product type: " + childNames); }
/** * Obtains an instance of the parser, based on the specified selector and trade info plugin. * <p> * The FpML parser has a number of plugin points that can be controlled: * <ul> * <li>the {@linkplain FpmlPartySelector party selector} * <li>the {@linkplain FpmlTradeInfoParserPlugin trade info parser} * <li>the {@linkplain FpmlParserPlugin trade parsers} * <li>the {@linkplain ReferenceData reference data} * </ul> * This method uses the trade parsers registered in {@link FpmlParserPlugin} configuration * and the {@linkplain ReferenceData#standard() standard} reference data. * * @param ourPartySelector the selector used to find "our" party within the set of parties in the FpML document * @param tradeInfoParser the trade info parser * @return the document parser */ public static FpmlDocumentParser of( FpmlPartySelector ourPartySelector, FpmlTradeInfoParserPlugin tradeInfoParser) { return of(ourPartySelector, tradeInfoParser, FpmlParserPlugin.extendedEnum().lookupAllNormalized()); }
/** * Obtains an instance from the specified unique name. * * @param uniqueName the unique name * @return the parser * @throws IllegalArgumentException if the name is not known */ @FromString public static FpmlParserPlugin of(String uniqueName) { ArgChecker.notNull(uniqueName, "uniqueName"); return extendedEnum().lookup(uniqueName); }