def get_dxlink_ids(link):
    '''
    :param link: A DNAnexus link
    :type link: dict
    :returns: (Object ID, Project ID) if the link is to a data object (or :const:`None`
        if no project specified in the link), or (Job ID, Field) if the link is
        a job-based object reference (JBOR).
    :rtype: tuple

    Get the object ID and detail from a link. There are three types of links:

    * Simple link of the form ``{"$dnanexus_link": "file-XXXX"}`` returns
      ``("file-XXXX", None)``.
    * Data object link of the form ``{"$dnanexus_link': {"id": "file-XXXX",
      "project": "project-XXXX"}}`` returns ``("file-XXXX", "project-XXXX")``.
    * Job-based object reference (JBOR) of the form ``{"$dnanexus_link":
      {"job": "job-XXXX", "field": "foo"}}`` returns ``("job-XXXX", "foo")``.
    '''
    if not is_dxlink(link):
        raise DXError('Invalid link: %r' % link)
    if isinstance(link['$dnanexus_link'], basestring):
        return link['$dnanexus_link'], None
    elif 'id' in link['$dnanexus_link']:
        return link['$dnanexus_link']['id'], link['$dnanexus_link'].get('project')
    else:
        return link['$dnanexus_link']['job'], link['$dnanexus_link']['field']