class QuotaChecker {

    void checkSubdomainQuota(ObjectStoreConnection con, String domainName, String caller) {
        
        // if quota check is disabled we have nothing to do
        
        if (!quotaCheckEnabled) {
            return;
        }
        
        // for sub-domains we need to run the quota check against
        // the top level domain so let's get that first. If we are
        // creating a top level domain then there is no need for
        // quota check
        
        int idx = domainName.indexOf('.');
        if (idx == -1) {
            return;
        }
        
        final String topLevelDomain = domainName.substring(0, idx);
        
        // now get the quota for the top level domain
        
        final Quota quota = getDomainQuota(con, topLevelDomain);
        
        // get the list of sub-domains for our given top level domain
        
        final String domainPrefix = topLevelDomain + ".";
        int objectCount = con.listDomains(domainPrefix, 0).size() + 1;

        if (quota.getSubdomain() < objectCount) {
            throw ZMSUtils.quotaLimitError("subdomain quota exceeded - limit: "
                    + quota.getSubdomain() + " actual: " + objectCount, caller);
        }
    }

    public  QuotaChecker();

}