* @param fields the set of fields, not null
* @param resultElements the result elements from Bloomberg, not null
* @return the parsed result, not null
*/
protected ReferenceDataProviderGetResult parse(Set<String> securityKeys, Set<String> fields, BlockingQueue<Element> resultElements) {
ReferenceDataProviderGetResult result = new ReferenceDataProviderGetResult();
for (Element resultElem : resultElements) {
if (resultElem.hasElement(RESPONSE_ERROR)) {
Element responseError = resultElem.getElement(RESPONSE_ERROR);
String category = responseError.getElementAsString(BloombergConstants.CATEGORY);
if ("LIMIT".equals(category)) {
s_logger.error("Limit reached {}", responseError);
}
throw new OpenGammaRuntimeException("Unable to get a Bloomberg response for " + fields + " fields for " + securityKeys + ": " + responseError);
}
Element securityDataArray = resultElem.getElement(SECURITY_DATA);
int numSecurities = securityDataArray.numValues();
for (int iSecurityElem = 0; iSecurityElem < numSecurities; iSecurityElem++) {
Element securityElem = securityDataArray.getValueAsElement(iSecurityElem);
String securityKey = securityElem.getElementAsString(SECURITY);
ReferenceData refData = new ReferenceData(securityKey);
if (securityElem.hasElement(SECURITY_ERROR)) {
parseIdentifierError(refData, securityElem.getElement(SECURITY_ERROR));
}
if (securityElem.hasElement(FIELD_DATA)) {
parseFieldData(refData, securityElem.getElement(FIELD_DATA));
}
if (securityElem.hasElement(FIELD_EXCEPTIONS)) {
parseFieldExceptions(refData, securityElem.getElement(FIELD_EXCEPTIONS));
}
if (securityElem.hasElement(EID_DATA)) {
parseEidData(refData, securityElem.getElement(FIELD_DATA));
}
result.addReferenceData(refData);
}
}
return result;
}