Class FpmlDocumentParser
- java.lang.Object
-
- com.opengamma.strata.loader.fpml.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 theFpmlParserPlugin.ini
configuration file.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete 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.
-
-
-
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:
- the party selector
- the trade info parser
- the trade parsers
- the reference data
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:
- the party selector
- the trade info parser
- the trade parsers
- the reference data
FpmlParserPlugin
configuration and the standard reference data.- Parameters:
ourPartySelector
- the selector used to find "our" party within the set of parties in the FpML documenttradeInfoParser
- the trade info parser- Returns:
- the document parser
-
of
public 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.The FpML parser has a number of plugin points that can be controlled:
- the party selector
- the trade info parser
- the trade parsers
- the reference data
FpmlParserPlugin
configuration.- Parameters:
ourPartySelector
- the selector used to find "our" party within the set of parties in the FpML documenttradeInfoParser
- the trade info parserrefData
- the reference data to use- Returns:
- the document parser
-
of
public static FpmlDocumentParser of(FpmlPartySelector ourPartySelector, FpmlTradeInfoParserPlugin tradeInfoParser, 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:
- the party selector
- the trade info parser
- the trade parsers
- the reference data
- Parameters:
ourPartySelector
- the selector used to find "our" party within the set of parties in the FpML documenttradeInfoParser
- the trade info parsertradeParsers
- the map of trade parsers, keyed by the FpML element name- Returns:
- the document parser
-
of
public 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.The FpML parser has a number of plugin points that can be controlled:
- the party selector
- the trade info parser
- the trade parsers
- the reference data
- Parameters:
ourPartySelector
- the selector used to find "our" party within the set of parties in the FpML documenttradeInfoParser
- the trade info parsertradeParsers
- the map of trade parsers, keyed by the FpML element namerefData
- 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
-
parseTrades
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:
- the parsed trades
- Throws:
RuntimeException
- if a parse error occurred
-
parseTrades
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:
- the parsed trades
- Throws:
RuntimeException
- if a parse error occurred
-
parseTrades
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 documentreferences
- the map of id/href to referenced element- Returns:
- the parsed trades
- Throws:
RuntimeException
- if a parse error occurred
-
-