class ZMSImpl implements Authorizer, KeyStore, ZMSHandler {

    void deleteDomain(ResourceContext ctx, String auditRef, String domainName, String caller) {

        // make sure we're not deleting any of the reserved system domain

        if (reservedSystemDomains.contains(domainName)) {
            throw ZMSUtils.requestError("Cannot delete reserved system domain", caller);
        }

        DomainList subDomainList = listDomains(null, null, domainName + ".", null, 0, true);
        if (subDomainList.getNames().size() > 0) {
            throw ZMSUtils.requestError(caller + ": Cannot delete domain " +
                    domainName + ": " + subDomainList.getNames().size() + " subdomains of it exist", caller);
        }

        // we're going to make sure the domain does not have any
        // groups that are referenced in other domains. if that is the
        // case the group should be removed from all those domains
        // before the domain can be deleted

        AthenzDomain domain = getAthenzDomain(domainName, false);
        if (domain == null) {
            throw ZMSUtils.notFoundError("Domain not found: '" + domainName + "'", caller);
        }

        for (Group group : domain.getGroups()) {
            groupMemberConsistencyCheck(domainName, group.getName(), true, caller);
        }

        // consistency checks are ok so we can go ahead and delete the domain

        dbService.executeDeleteDomain(ctx, domainName, auditRef, caller);
    }

    public  ZMSImpl();

}