## Class FpmlDocumentParser

• public final class FpmlDocumentParser
extends Object
Loader of trade data in FpML format.

This handles the subset of FpML necessary to populate the trade model. The standard parsers accept FpML v5.8, which is often the same as earlier versions.

The trade parsers implement FpmlParserPlugin and are pluggable using the FpmlParserPlugin.ini configuration file.

• ### Method Summary

All Methods
Modifier and Type Method Description
boolean isKnownFormat​(ByteSource source)
Basic check to see if the source can probably be parsed as FpML.
static FpmlDocumentParser of​(FpmlPartySelector ourPartySelector)
Obtains an instance of the parser, based on the specified selector.
static FpmlDocumentParser of​(FpmlPartySelector ourPartySelector, FpmlTradeInfoParserPlugin tradeInfoParser)
Obtains an instance of the parser, based on the specified selector and trade info plugin.
static FpmlDocumentParser of​(FpmlPartySelector ourPartySelector, FpmlTradeInfoParserPlugin tradeInfoParser, ReferenceData refData)
Obtains an instance of the parser, based on the specified selector, trade info plugin and reference data.
static FpmlDocumentParser of​(FpmlPartySelector ourPartySelector, FpmlTradeInfoParserPlugin tradeInfoParser, Map<String,​FpmlParserPlugin> tradeParsers)
Obtains an instance of the parser, based on the specified selector and plugins.
static FpmlDocumentParser of​(FpmlPartySelector ourPartySelector, FpmlTradeInfoParserPlugin tradeInfoParser, Map<String,​FpmlParserPlugin> tradeParsers, ReferenceData refData)
Obtains an instance of the parser, based on the specified selector and plugins.
List<Trade> parseTrades​(ByteSource source)
Parses FpML from the specified source, extracting the trades.
List<Trade> parseTrades​(XmlElement fpmlRootEl, Map<String,​XmlElement> references)
Parses the FpML document extracting the trades.
List<Trade> parseTrades​(XmlFile xmlFile)
Parses FpML from the specified XML document, extracting the trades.
FpmlDocumentParser withLenientMode()
Obtains a 'lenient' version of this parser instance.
• ### Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• ### Method Detail

• #### of

public static FpmlDocumentParser of​(FpmlPartySelector ourPartySelector)
Obtains an instance of the parser, based on the specified selector.

The FpML parser has a number of plugin points that can be controlled:

This method uses the standard trade info parser, the trade parsers registered in FpmlParserPlugin configuration and the standard reference data.
Parameters:
ourPartySelector - the selector used to find "our" party within the set of parties in the FpML document
Returns:
the document parser
• #### of

public static FpmlDocumentParser of​(FpmlPartySelector ourPartySelector,
FpmlTradeInfoParserPlugin tradeInfoParser)
Obtains an instance of the parser, based on the specified selector and trade info plugin.

The FpML parser has a number of plugin points that can be controlled:

This method uses the trade parsers registered in FpmlParserPlugin configuration and the standard reference data.
Parameters:
ourPartySelector - the selector used to find "our" party within the set of parties in the FpML document
tradeInfoParser - the trade info parser
Returns:
the document parser
• #### of

public static FpmlDocumentParser of​(FpmlPartySelector ourPartySelector,
ReferenceData refData)
Obtains an instance of the parser, based on the specified selector, trade info plugin and reference data.

The FpML parser has a number of plugin points that can be controlled:

This method uses the trade parsers registered in FpmlParserPlugin configuration.
Parameters:
ourPartySelector - the selector used to find "our" party within the set of parties in the FpML document
tradeInfoParser - the trade info parser
refData - the reference data to use
Returns:
the document parser
• #### of

public static FpmlDocumentParser of​(FpmlPartySelector ourPartySelector,
Map<String,​FpmlParserPlugin> tradeParsers)
Obtains an instance of the parser, based on the specified selector and plugins.

The FpML parser has a number of plugin points that can be controlled:

This method uses the standard reference data.
Parameters:
ourPartySelector - the selector used to find "our" party within the set of parties in the FpML document
tradeInfoParser - the trade info parser
tradeParsers - the map of trade parsers, keyed by the FpML element name
Returns:
the document parser
• #### of

public static FpmlDocumentParser of​(FpmlPartySelector ourPartySelector,
ReferenceData refData)
Obtains an instance of the parser, based on the specified selector and plugins.

The FpML parser has a number of plugin points that can be controlled:

Parameters:
ourPartySelector - the selector used to find "our" party within the set of parties in the FpML document
tradeInfoParser - the trade info parser
tradeParsers - the map of trade parsers, keyed by the FpML element name
refData - the reference data to use
Returns:
the document parser
• #### withLenientMode

public FpmlDocumentParser withLenientMode()
Obtains a 'lenient' version of this parser instance.

In 'lenient' mode any FpML elements unsupported in Strata will be silently ignored (rather than resulting in errors).

Returns:
the lenient document parser
• #### isKnownFormat

public boolean isKnownFormat​(ByteSource source)
Basic check to see if the source can probably be parsed as FpML.

This checks the first part of the byte source to see if it appears to be FpML. This is determined by looking for "fpml" (case insensitive) within the first 2000 characters.

A more thorough check would involve parsing the XML, which is relatively slow. If you want to perform the more thorough check benchmarking indicates you might as well just parse the whole document.

Parameters:
source - the source to check
Returns:
true if the source appears to be FpML
Throws:
UncheckedIOException - if an IO error occurred

public List<Trade> parseTrades​(ByteSource source)
Parses FpML from the specified source, extracting the trades.

This parses the specified byte source which must be an XML document.

Sometimes, the FpML document is embedded in a non-FpML wrapper. This method will intelligently find the FpML document at the root, within any children of the root, or within any grand-children of the root. The FpML root element is the one that contains both <trade> and <party>.

Parameters:
source - the source of the FpML XML document
Returns:
Throws:
RuntimeException - if a parse error occurred

public List<Trade> parseTrades​(XmlFile xmlFile)
Parses FpML from the specified XML document, extracting the trades.

This parses the specified XmlFile.

Sometimes, the FpML document is embedded in a non-FpML wrapper. This method will intelligently find the FpML document at the root, within any children of the root, or within any grand-children of the root. The FpML root element is the one that contains both <trade> and <party>.

Parameters:
xmlFile - the FpML XML document
Returns:
Throws:
RuntimeException - if a parse error occurred

public List<Trade> parseTrades​(XmlElement fpmlRootEl,
Map<String,​XmlElement> references)
Parses the FpML document extracting the trades.

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 <foo id="fooId">, the references map will contain an entry mapping "fooId" to the parsed element <foo>.

Parameters:
fpmlRootEl - the source of the FpML XML document
references - the map of id/href to referenced element
Returns:
RuntimeException - if a parse error occurred