'If the combination of name, version and type of each element is defined in the <requirement> tag for
at least one tool in self.repository, then update the received metadata_dict with information from the
parsed tool_dependencies_config.'

def generate_tool_dependency_metadata(self, tool_dependencies_config, metadata_dict, original_repository_metadata=None):

    error_message = ''
    if original_repository_metadata:
        original_valid_tool_dependencies_dict = original_repository_metadata.get('tool_dependencies', None)
    else:
        original_valid_tool_dependencies_dict = None
    (tree, error_message) = xml_util.parse_xml(tool_dependencies_config)
    if (tree is None):
        return (metadata_dict, error_message)
    root = tree.getroot()
    class RecurserValueStore(object, ):
        pass
    rvs = RecurserValueStore()
    rvs.valid_tool_dependencies_dict = {}
    rvs.invalid_tool_dependencies_dict = {}
    valid_repository_dependency_tups = []
    invalid_repository_dependency_tups = []
    description = root.get('description')
    def _check_elem_for_dep(elems):
        error_messages = []
        for elem in elems:
            if (elem.tag == 'package'):
                (rvs.valid_tool_dependencies_dict, rvs.invalid_tool_dependencies_dict, repository_dependency_tup, repository_dependency_is_valid, message) = self.generate_package_dependency_metadata(elem, rvs.valid_tool_dependencies_dict, rvs.invalid_tool_dependencies_dict)
                if repository_dependency_is_valid:
                    if (repository_dependency_tup and (repository_dependency_tup not in valid_repository_dependency_tups)):
                        valid_repository_dependency_tups.append(repository_dependency_tup)
                elif (repository_dependency_tup and (repository_dependency_tup not in invalid_repository_dependency_tups)):
                    (toolshed, name, owner, changeset_revision, prior_installation_required, only_if_compiling_contained_td) = repository_dependency_tup
                    repository_dependency_tup = (toolshed, name, owner, changeset_revision, prior_installation_required, only_if_compiling_contained_td, message)
                    invalid_repository_dependency_tups.append(repository_dependency_tup)
                    error_messages.append(('%s        %s' % (error_message, message)))
            elif (elem.tag == 'set_environment'):
                rvs.valid_tool_dependencies_dict = self.generate_environment_dependency_metadata(elem, rvs.valid_tool_dependencies_dict)
            error_messages += _check_elem_for_dep(elem)
        return error_messages
    error_message = '\n'.join(([error_message] + _check_elem_for_dep(root)))
    if rvs.valid_tool_dependencies_dict:
        if original_valid_tool_dependencies_dict:
            irm = self.app.installed_repository_manager
            (updated_tool_dependency_names, deleted_tool_dependency_names) = irm.handle_existing_tool_dependencies_that_changed_in_update(self.repository, original_valid_tool_dependencies_dict, rvs.valid_tool_dependencies_dict)
        metadata_dict['tool_dependencies'] = rvs.valid_tool_dependencies_dict
    if rvs.invalid_tool_dependencies_dict:
        metadata_dict['invalid_tool_dependencies'] = rvs.invalid_tool_dependencies_dict
    if valid_repository_dependency_tups:
        metadata_dict = self.update_repository_dependencies_metadata(metadata=metadata_dict, repository_dependency_tups=valid_repository_dependency_tups, is_valid=True, description=description)
    if invalid_repository_dependency_tups:
        metadata_dict = self.update_repository_dependencies_metadata(metadata=metadata_dict, repository_dependency_tups=invalid_repository_dependency_tups, is_valid=False, description=description)
    return (metadata_dict, error_message)
