class DialogDescriptorReferenceParser {

    public List<DialogDescriptor> parse(final Element sequenceElement, final Map<String, DialogDescriptor> nameToDialogDescriptor) {
        List<DialogDescriptor> result = new ArrayList<>();
        NodeList dialogDescriptorReferences = sequenceElement.getElementsByTagName(DIALOG_DESCRIPTOR_REFERENCE_TAG_NAME);
        for (int i = 0; i < dialogDescriptorReferences.getLength(); i++) {
            Element dialogDescriptorReferenceElement = (Element) dialogDescriptorReferences.item(i);
            String referencedName = dialogDescriptorReferenceElement.getAttribute("ref");
            DialogDescriptor dialogDescriptor = nameToDialogDescriptor.get(referencedName);
            if (dialogDescriptor != null) {
                result.add(dialogDescriptor);
            }
        }
        return result;
    }

}