void XMLParser::buildConfigParams()

in src/framework/taespecifierbuilder.cpp [579:669]


  void XMLParser::buildConfigParams(AnalysisEngineMetaData & aeMetaData,
      DOMElement * descElem) {
    //check for default group and search strategy
    const XMLCh* defaultGroup = descElem->getAttribute(convert(ATTR_CONFIG_PARAMS_DEF_GROUP));
    if (isDefined(defaultGroup)) {
      aeMetaData.setDefaultGroupName(convert(defaultGroup));
    }
    const XMLCh * searchStrategy = descElem->getAttribute(convert(ATTR_CONFIG_PARAMS_SEARCH));
    if (isDefined(searchStrategy)) {
      const icu::UnicodeString & strategy = convert(searchStrategy);
      if (strategy.compare(NO_FALLBACK) == 0) {
        aeMetaData.setSearchStrategy(AnalysisEngineMetaData::NONE);
      } else if (strategy.compare(DEFAULT_FALLBACK) == 0) {
        aeMetaData.setSearchStrategy(AnalysisEngineMetaData::DEFAULT_FALLBACK);
      } else if (strategy.compare(LANGUAGE_FALLBACK) == 0) {
        aeMetaData.setSearchStrategy(AnalysisEngineMetaData::LANGUAGE_FALLBACK);
      } else {
        /**
        ErrorMessage errMsg(UIMA_MSG_ID_EXC_CONFIG_XML_ATTRIBUTE_VALUE_NOT_ALLOWED);
        icu::UnicodeString tagName = convert( descElem->getTagName() );
        errMsg.addParam(strategy);
        errMsg.addParam(ATTR_CONFIG_PARAMS_SEARCH);
        errMsg.addParam(tagName);
        UIMA_EXC_THROW_NEW(InvalidXMLException,
                          UIMA_ERR_CONFIG_INVALID_XML_ATTRIBUTE_VALUE,
                          errMsg,
                          UIMA_MSG_ID_EXCON_BUILD_TAE_SPEC,
                          ErrorInfo::unrecoverable);
        **/
      }
    }

    DOMNodeList * children = descElem->getChildNodes();
    size_t i;
    for (i=0; i < children->getLength(); i++) {
      if ((children->item(i))->getNodeType() != DOMNode::ELEMENT_NODE) {
        continue;
      }

      DOMElement * child = (DOMElement *) children->item(i);
      const icu::UnicodeString & childTag = convert(child->getNodeName());

      if (childTag.compare(TAG_CONFIG_PARAM_COMMON) == 0) {
        DOMNodeList * commonParms = child->getChildNodes();
        size_t j;
        for (j=0; j < commonParms->getLength(); j++) {
          if ((commonParms->item(j))->getNodeType() != DOMNode::ELEMENT_NODE) {
            continue;
          }
          aeMetaData.addCommonParameter(buildConfigParam((DOMElement *) commonParms->item(j)));
        }
      } else if (childTag.compare(TAG_CONFIG_PARAM) == 0) {
        aeMetaData.addConfigurationParameter(buildConfigParam(child));
      } else if (childTag.compare(TAG_CONFIG_PARAM_GROUP) == 0) {
        //contains the groups as space-separated string
        const icu::UnicodeString & groupNameString = convert(child->getAttribute(convert(ATTR_CONFIG_PARAM_GROUP_NAMES)));
        vector <std::string> groupNames;
        //TBD: change this to true unicode processing
        delimitedString2Vector(groupNames,
                               UnicodeStringRef(groupNameString).asUTF8(),
                               " ", true, false);

        //add the configuration groups, even if they don't define any parameters themselves
        //this way, later assignValue calls will succeed, otherwise, they would fail, as
        //assignValue requires that the configuration group must already exist
        for (size_t m=0; m < groupNames.size(); m++) {
          const icu::UnicodeString & groupName = icu::UnicodeString(groupNames[m].c_str(), "UTF-8");
          aeMetaData.addConfigurationGroup(groupName);
        }

        //get the config params defined for that group
        DOMNodeList * confParmsInGroup = child->getChildNodes();
        size_t k;
        for (k=0; k < confParmsInGroup->getLength(); k++) {
          if ((confParmsInGroup->item(k))->getNodeType() != DOMNode::ELEMENT_NODE) {
            continue;
          }

          //add the config param for each group
          size_t l;
          for (l=0; l < groupNames.size(); l++) {
            //we can't put the same configParam into the groups, as they will delete their
            //member in their destructor
            //tbd: build only once, copy the result, pass the copies into 'add'
            ConfigurationParameter * configParam = buildConfigParam((DOMElement *) confParmsInGroup->item(k));
            aeMetaData.addConfigurationParameter(icu::UnicodeString(groupNames[l].c_str(), "UTF-8"), configParam);
          }
        }
      }
    }
  }