protected function validateTypeName($type, $exists = null)
    {
        if (empty($type) && !is_string($type)) {
            throw new \Exception("Identity type must be a valid string.");
        }

        if (($exists === true) && !isset($this->types[$type])) {
            throw new \Exception(sprintf("Undefined Identity type '%s'.", $type));
        }

        if (($exists === false) && !empty($this->types[$type])) {
            throw new \Exception(sprintf("Identity type '%s' already exists.", $type));
        }

        return true;
    }