public virtual void test_matchingRegex()
 {
     assertEquals(FpmlPartySelector.matchingRegex(Pattern.compile("a[12]")).selectParties(MAP), ImmutableList.of("A"));
     assertEquals(FpmlPartySelector.matchingRegex(Pattern.compile("b")).selectParties(MAP), ImmutableList.of("B"));
     assertEquals(FpmlPartySelector.matchingRegex(Pattern.compile("c[0-9]")).selectParties(MAP), ImmutableList.of("C1", "C2"));
     assertEquals(FpmlPartySelector.matchingRegex(Pattern.compile("d")).selectParties(MAP), ImmutableList.of());
 }
 //-------------------------------------------------------------------------
 /// <summary>
 /// Creates an instance, based on the specified element.
 /// </summary>
 /// <param name="ourPartySelector">  the selector used to find "our" party within the set of parties in the FpML document </param>
 /// <param name="tradeInfoParser">  the trade info parser </param>
 /// <param name="tradeParsers">  the map of trade parsers, keyed by the FpML element name </param>
 private FpmlDocumentParser(FpmlPartySelector ourPartySelector, FpmlTradeInfoParserPlugin tradeInfoParser, IDictionary <string, FpmlParserPlugin> tradeParsers, ReferenceData refData)
 {
     this.ourPartySelector = ourPartySelector;
     this.tradeInfoParser  = tradeInfoParser;
     this.tradeParsers     = tradeParsers;
     this.refData          = refData;
 }
 public virtual void test_matching()
 {
     assertEquals(FpmlPartySelector.matching("a1").selectParties(MAP), ImmutableList.of("A"));
     assertEquals(FpmlPartySelector.matching("a2").selectParties(MAP), ImmutableList.of("A"));
     assertEquals(FpmlPartySelector.matching("b").selectParties(MAP), ImmutableList.of("B"));
     assertEquals(FpmlPartySelector.matching("c").selectParties(MAP), ImmutableList.of());
 }
        // locate our party href/id reference
        private ImmutableList <string> findOurParty(FpmlPartySelector ourPartySelector)
        {
            // check for "any" selector to avoid logging message in normal case
            if (ourPartySelector == FpmlPartySelector.any())
            {
                return(ImmutableList.of());
            }
            IList <string> selected = ourPartySelector.selectParties(parties);

            if (selected.Count > 0)
            {
                foreach (string id in selected)
                {
                    if (!parties.Keys.Contains(id))
                    {
                        throw new FpmlParseException(Messages.format("Selector returned an ID '{}' that is not present in the document: {}", id, parties));
                    }
                }
                return(ImmutableList.copyOf(selected));
            }
            log.warn("Failed to resolve \"our\" counterparty from FpML document, using leg defaults instead: " + parties);
            return(ImmutableList.of());
        }
 //-------------------------------------------------------------------------
 /// <summary>
 /// Obtains an instance of the parser, based on the specified selector.
 /// <para>
 /// The FpML parser has a number of plugin points that can be controlled:
 /// <ul>
 /// <li>the <seealso cref="FpmlPartySelector party selector"/>
 /// <li>the <seealso cref="FpmlTradeInfoParserPlugin trade info parser"/>
 /// <li>the <seealso cref="FpmlParserPlugin trade parsers"/>
 /// <li>the <seealso cref="ReferenceData reference data"/>
 /// </ul>
 /// This method uses the <seealso cref="FpmlTradeInfoParserPlugin#standard() standard"/>
 /// trade info parser, the trade parsers registered in <seealso cref="FpmlParserPlugin"/>
 /// configuration and the <seealso cref="ReferenceData#standard() standard"/> reference data.
 ///
 /// </para>
 /// </summary>
 /// <param name="ourPartySelector">  the selector used to find "our" party within the set of parties in the FpML document </param>
 /// <returns> the document parser </returns>
 public static FpmlDocumentParser of(FpmlPartySelector ourPartySelector)
 {
     return(of(ourPartySelector, FpmlTradeInfoParserPlugin.standard()));
 }
 /// <summary>
 /// Obtains an instance of the parser, based on the specified selector and plugins.
 /// <para>
 /// The FpML parser has a number of plugin points that can be controlled:
 /// <ul>
 /// <li>the <seealso cref="FpmlPartySelector party selector"/>
 /// <li>the <seealso cref="FpmlTradeInfoParserPlugin trade info parser"/>
 /// <li>the <seealso cref="FpmlParserPlugin trade parsers"/>
 /// <li>the <seealso cref="ReferenceData reference data"/>
 /// </ul>
 ///
 /// </para>
 /// </summary>
 /// <param name="ourPartySelector">  the selector used to find "our" party within the set of parties in the FpML document </param>
 /// <param name="tradeInfoParser">  the trade info parser </param>
 /// <param name="tradeParsers">  the map of trade parsers, keyed by the FpML element name </param>
 /// <param name="refData">  the reference data to use </param>
 /// <returns> the document parser </returns>
 public static FpmlDocumentParser of(FpmlPartySelector ourPartySelector, FpmlTradeInfoParserPlugin tradeInfoParser, IDictionary <string, FpmlParserPlugin> tradeParsers, ReferenceData refData)
 {
     return(new FpmlDocumentParser(ourPartySelector, tradeInfoParser, tradeParsers, refData));
 }
 /// <summary>
 /// Obtains an instance of the parser, based on the specified selector and plugins.
 /// <para>
 /// The FpML parser has a number of plugin points that can be controlled:
 /// <ul>
 /// <li>the <seealso cref="FpmlPartySelector party selector"/>
 /// <li>the <seealso cref="FpmlTradeInfoParserPlugin trade info parser"/>
 /// <li>the <seealso cref="FpmlParserPlugin trade parsers"/>
 /// <li>the <seealso cref="ReferenceData reference data"/>
 /// </ul>
 /// This method uses the <seealso cref="ReferenceData#standard() standard"/> reference data.
 ///
 /// </para>
 /// </summary>
 /// <param name="ourPartySelector">  the selector used to find "our" party within the set of parties in the FpML document </param>
 /// <param name="tradeInfoParser">  the trade info parser </param>
 /// <param name="tradeParsers">  the map of trade parsers, keyed by the FpML element name </param>
 /// <returns> the document parser </returns>
 public static FpmlDocumentParser of(FpmlPartySelector ourPartySelector, FpmlTradeInfoParserPlugin tradeInfoParser, IDictionary <string, FpmlParserPlugin> tradeParsers)
 {
     return(of(ourPartySelector, tradeInfoParser, tradeParsers, ReferenceData.standard()));
 }
 /// <summary>
 /// Obtains an instance of the parser, based on the specified selector and trade info plugin.
 /// <para>
 /// The FpML parser has a number of plugin points that can be controlled:
 /// <ul>
 /// <li>the <seealso cref="FpmlPartySelector party selector"/>
 /// <li>the <seealso cref="FpmlTradeInfoParserPlugin trade info parser"/>
 /// <li>the <seealso cref="FpmlParserPlugin trade parsers"/>
 /// <li>the <seealso cref="ReferenceData reference data"/>
 /// </ul>
 /// This method uses the trade parsers registered in <seealso cref="FpmlParserPlugin"/> configuration
 /// and the <seealso cref="ReferenceData#standard() standard"/> reference data.
 ///
 /// </para>
 /// </summary>
 /// <param name="ourPartySelector">  the selector used to find "our" party within the set of parties in the FpML document </param>
 /// <param name="tradeInfoParser">  the trade info parser </param>
 /// <returns> the document parser </returns>
 public static FpmlDocumentParser of(FpmlPartySelector ourPartySelector, FpmlTradeInfoParserPlugin tradeInfoParser)
 {
     return(of(ourPartySelector, tradeInfoParser, FpmlParserPlugin.extendedEnum().lookupAllNormalized()));
 }
 //-------------------------------------------------------------------------
 public virtual void test_any()
 {
     assertEquals(FpmlPartySelector.any().selectParties(MAP), ImmutableList.of());
 }
 //-------------------------------------------------------------------------
 /// <summary>
 /// Creates an instance, based on the specified element.
 /// <para>
 /// The map of references is used 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>}.
 ///
 /// </para>
 /// </summary>
 /// <param name="fpmlRootEl">  the source of the FpML XML document </param>
 /// <param name="references">  the map of id/href to referenced element </param>
 /// <param name="ourPartySelector">  the selector used to find "our" party within the set of parties in the FpML document </param>
 /// <param name="tradeInfoParser">  the trade info parser </param>
 /// <param name="refData">  the reference data to use </param>
 public FpmlDocument(XmlElement fpmlRootEl, IDictionary <string, XmlElement> references, FpmlPartySelector ourPartySelector, FpmlTradeInfoParserPlugin tradeInfoParser, ReferenceData refData)
 {
     this.fpmlRoot        = fpmlRootEl;
     this.references      = ImmutableMap.copyOf(references);
     this.parties         = parseParties(fpmlRootEl);
     this.ourPartyHrefIds = findOurParty(ourPartySelector);
     this.tradeInfoParser = tradeInfoParser;
     this.refData         = refData;
 }