void CacheXmlParser::startRegionAttributes()

in cppcache/src/CacheXmlParser.cpp [790:969]


void CacheXmlParser::startRegionAttributes(const xercesc::Attributes &attrs) {
  bool isDistributed = false;
  bool isTCR = false;
  std::shared_ptr<RegionAttributesFactory> regionAttributesFactory = nullptr;

  if (attrs.getLength() > 24) {
    throw CacheXmlException(
        "XML:Too many attributes provided for <region-attributes>");
  }

  if (attrs.getLength() == 0) {
    auto region = std::static_pointer_cast<RegionXmlCreation>(_stack.top());
    regionAttributesFactory =
        std::make_shared<RegionAttributesFactory>(region->getAttributes());
  } else {
    auto id = getOptionalAttribute(attrs, ID);
    if (!id.empty()) {
      auto region = std::static_pointer_cast<RegionXmlCreation>(_stack.top());
      region->setAttrId(id);
    }

    auto refid = getOptionalAttribute(attrs, REFID);
    if (refid.empty()) {
      auto region = std::static_pointer_cast<RegionXmlCreation>(_stack.top());
      regionAttributesFactory =
          std::make_shared<RegionAttributesFactory>(region->getAttributes());
    } else {
      if (namedRegions_.find(refid) != namedRegions_.end()) {
        regionAttributesFactory =
            std::make_shared<RegionAttributesFactory>(namedRegions_[refid]);
      } else {
        throw CacheXmlException("XML:referenced named attribute '" + refid +
                                "' does not exist.");
      }
    }

    if (!regionAttributesFactory) {
      throw UnknownException(
          "CacheXmlParser::startRegionAttributes:Out of memory");
    }

    auto clientNotificationEnabled =
        getOptionalAttribute(attrs, CLIENT_NOTIFICATION_ENABLED);
    if (!clientNotificationEnabled.empty()) {
      bool flag = false;
      std::transform(clientNotificationEnabled.begin(),
                     clientNotificationEnabled.end(),
                     clientNotificationEnabled.begin(), ::tolower);
      if ("false" == clientNotificationEnabled) {
        flag = false;
      } else if ("true" == clientNotificationEnabled) {
        flag = true;
      } else {
        throw CacheXmlException(
            "XML: " + clientNotificationEnabled +
            " is not a valid name for the attribute <client-notification>");
      }
      if (poolFactory_) {
        poolFactory_->setSubscriptionEnabled(flag);
      }
    }

    auto initialCapacity = getOptionalAttribute(attrs, INITIAL_CAPACITY);
    if (!initialCapacity.empty()) {
      regionAttributesFactory->setInitialCapacity(std::stoi(initialCapacity));
    }

    auto concurrencyLevel = getOptionalAttribute(attrs, CONCURRENCY_LEVEL);
    if (!concurrencyLevel.empty()) {
      regionAttributesFactory->setConcurrencyLevel(std::stoi(concurrencyLevel));
    }

    auto loadFactor = getOptionalAttribute(attrs, LOAD_FACTOR);
    if (!loadFactor.empty()) {
      regionAttributesFactory->setLoadFactor(std::stof(loadFactor));
    }

    auto cachingEnabled = getOptionalAttribute(attrs, CACHING_ENABLED);
    if (!cachingEnabled.empty()) {
      bool flag = false;
      std::transform(cachingEnabled.begin(), cachingEnabled.end(),
                     cachingEnabled.begin(), ::tolower);
      if ("false" == cachingEnabled) {
        flag = false;
      } else if ("true" == cachingEnabled) {
        flag = true;
      } else {
        throw CacheXmlException(
            "XML: " + cachingEnabled +
            " is not a valid name for the attribute <caching-enabled>");
      }
      regionAttributesFactory->setCachingEnabled(flag);
    }

    auto lruEntriesLimit = getOptionalAttribute(attrs, LRU_ENTRIES_LIMIT);
    if (!lruEntriesLimit.empty()) {
      regionAttributesFactory->setLruEntriesLimit(std::stoi(lruEntriesLimit));
    }

    auto diskPolicyString = getOptionalAttribute(attrs, DISK_POLICY);
    if (!diskPolicyString.empty()) {
      auto diskPolicy = apache::geode::client::DiskPolicyType::NONE;
      if (OVERFLOWS == diskPolicyString) {
        diskPolicy = apache::geode::client::DiskPolicyType::OVERFLOWS;
      } else if (PERSIST == diskPolicyString) {
        throw IllegalStateException("Persistence feature is not supported");
      } else if (NONE == diskPolicyString) {
        diskPolicy = apache::geode::client::DiskPolicyType::NONE;
      } else {
        throw CacheXmlException(
            "XML: " + diskPolicyString +
            " is not a valid name for the attribute <disk-policy>");
      }
      regionAttributesFactory->setDiskPolicy(diskPolicy);
    }

    auto endpoints = getOptionalAttribute(attrs, ENDPOINTS);
    if (!endpoints.empty()) {
      if (poolFactory_) {
        for (auto &&endPoint : parseEndPoints(ENDPOINTS)) {
          poolFactory_->addServer(endPoint.first, endPoint.second);
        }
      }
      isTCR = true;
    }

    auto poolName = getOptionalAttribute(attrs, POOL_NAME);
    if (!poolName.empty()) {
      regionAttributesFactory->setPoolName(poolName);
      isTCR = true;
    }

    auto cloningEnabled = getOptionalAttribute(attrs, CLONING_ENABLED);
    if (!cloningEnabled.empty()) {
      bool flag = false;
      std::transform(cloningEnabled.begin(), cloningEnabled.end(),
                     cloningEnabled.begin(), ::tolower);

      if ("false" == cloningEnabled) {
        flag = false;
      } else if ("true" == cloningEnabled) {
        flag = true;
      } else {
        throw CacheXmlException("XML: " + cloningEnabled +
                                " is not a valid value for the attribute <" +
                                std::string(CLONING_ENABLED) + ">");
      }
      regionAttributesFactory->setCloningEnabled(flag);
      isTCR = true;
    }

    auto concurrencyChecksEnabled =
        getOptionalAttribute(attrs, CONCURRENCY_CHECKS_ENABLED);
    if (!concurrencyChecksEnabled.empty()) {
      bool flag = false;
      std::transform(concurrencyChecksEnabled.begin(),
                     concurrencyChecksEnabled.end(),
                     concurrencyChecksEnabled.begin(), ::tolower);
      if ("false" == concurrencyChecksEnabled) {
        flag = false;
      } else if ("true" == concurrencyChecksEnabled) {
        flag = true;
      } else {
        throw CacheXmlException("XML: " + concurrencyChecksEnabled +
                                " is not a valid value for the attribute "
                                "<" +
                                std::string(CONCURRENCY_CHECKS_ENABLED) + ">");
      }
      regionAttributesFactory->setConcurrencyChecksEnabled(flag);
    }
  }

  if (isDistributed && isTCR) {
    // we don't allow DR+TCR at current stage
    throw CacheXmlException(
        "XML:endpoints cannot be defined for distributed region.\n");
  }

  _stack.push(regionAttributesFactory);
}