def generate_mediation_matrix(dsm):
        cat = dsm.categories
        ent = dsm.entities
        size = dsm.size[0]
        if not cat:
            cat = ['appmodule'] * size
        packages = [e.split('.')[0] for e in ent]
        mediation_matrix = [[0 for _ in range(size)]
                            for _ in range(size)]
        for i in range(0, size):
            for j in range(0, size):
                if cat[i] == 'framework':
                    if cat[j] == 'framework':
                        mediation_matrix[i][j] = -1
                    else:
                        mediation_matrix[i][j] = 0
                elif cat[i] == 'corelib':
                    if (cat[j] in ('framework', 'corelib') or
                            ent[i].startswith(packages[j] + '.') or
                            i == j):
                        mediation_matrix[i][j] = -1
                    else:
                        mediation_matrix[i][j] = 0
                elif cat[i] == 'applib':
                    if (cat[j] in ('framework', 'corelib', 'applib') or
                            ent[i].startswith(packages[j] + '.') or
                            i == j):
                        mediation_matrix[i][j] = -1
                    else:
                        mediation_matrix[i][j] = 0
                elif cat[i] == 'appmodule':
                    if (cat[j] in ('framework', 'corelib',
                                   'applib', 'broker', 'data') or
                            ent[i].startswith(packages[j] + '.') or
                            i == j):
                        mediation_matrix[i][j] = -1
                    else:
                        mediation_matrix[i][j] = 0
                elif cat[i] == 'broker':
                    if (cat[j] in (
                            'appmodule', 'corelib', 'framework') or
                            ent[i].startswith(packages[j] + '.') or
                            i == j):
                        mediation_matrix[i][j] = -1
                    else:
                        mediation_matrix[i][j] = 0
                elif cat[i] == 'data':
                    if (cat[j] == 'framework' or
                            i == j):
                        mediation_matrix[i][j] = -1
                    else:
                        mediation_matrix[i][j] = 0
                else:
                    raise DesignStructureMatrixError(
                        'Mediation matrix value NOT generated for %s:%s' % (
                            i, j))
        return mediation_matrix