SmartPtrCMethodParameterDoc MethodParameterXml::parse( const SmartPtrCXmlElement thisXml) { CAF_CM_STATIC_FUNC_VALIDATE("MethodParameterXml", "parse"); SmartPtrCMethodParameterDoc methodParameterDoc; CAF_CM_ENTER { CAF_CM_VALIDATE_SMARTPTR(thisXml); const std::string nameStrVal = thisXml->findRequiredAttribute("name"); const std::string nameVal = nameStrVal; const std::string typeStrVal = thisXml->findRequiredAttribute("type"); PARAMETER_TYPE typeVal = PARAMETER_NONE; if (! typeStrVal.empty()) { typeVal = EnumConvertersXml::convertStringToParameterType(typeStrVal); } const std::string isOptionalStrVal = thisXml->findRequiredAttribute("isOptional"); bool isOptionalVal = false; if (! isOptionalStrVal.empty()) { isOptionalVal = (isOptionalStrVal.compare("true") == 0) ? true : false; } const std::string isListStrVal = thisXml->findOptionalAttribute("isList"); bool isListVal = false; if (! isListStrVal.empty()) { isListVal = (isListStrVal.compare("true") == 0) ? true : false; } const std::string defaultValStrVal = thisXml->findOptionalAttribute("default"); const std::string defaultValVal = defaultValStrVal; const std::string displayNameStrVal = thisXml->findOptionalAttribute("displayName"); const std::string displayNameVal = displayNameStrVal; const std::string descriptionStrVal = thisXml->findOptionalAttribute("description"); const std::string descriptionVal = descriptionStrVal; methodParameterDoc.CreateInstance(); methodParameterDoc->initialize( nameVal, typeVal, isOptionalVal, isListVal, defaultValVal, displayNameVal, descriptionVal); } CAF_CM_EXIT; return methodParameterDoc; }
SmartPtrCErrorResponseDoc ErrorResponseXml::parse( const SmartPtrCXmlElement thisXml) { CAF_CM_STATIC_FUNC_VALIDATE("ErrorResponseXml", "parse"); SmartPtrCErrorResponseDoc errorResponseDoc; CAF_CM_ENTER { CAF_CM_VALIDATE_SMARTPTR(thisXml); const std::string clientIdStrVal = thisXml->findOptionalAttribute("clientId"); UUID clientIdVal = CAFCOMMON_GUID_NULL; if (! clientIdStrVal.empty()) { BasePlatform::UuidFromString(clientIdStrVal.c_str(), clientIdVal); } const std::string requestIdStrVal = thisXml->findOptionalAttribute("requestId"); UUID requestIdVal = CAFCOMMON_GUID_NULL; if (! requestIdStrVal.empty()) { BasePlatform::UuidFromString(requestIdStrVal.c_str(), requestIdVal); } const std::string pmeIdVal = thisXml->findOptionalAttribute("pmeId"); const SmartPtrCXmlElement responseHeaderXml = thisXml->findOptionalChild("responseHeader"); SmartPtrCResponseHeaderDoc responseHeaderVal; if (! responseHeaderXml.IsNull()) { responseHeaderVal = ResponseHeaderXml::parse(responseHeaderXml); } const SmartPtrCXmlElement errorMessageXml = thisXml->findOptionalChild("errorMessage"); std::string errorMessageVal; if (! errorMessageXml.IsNull()) { errorMessageVal = errorMessageXml->getValue(); } errorResponseDoc.CreateInstance(); errorResponseDoc->initialize( clientIdVal, requestIdVal, pmeIdVal, responseHeaderVal, errorMessageVal); } CAF_CM_EXIT; return errorResponseDoc; }
void CConfigProvider::setValue( const std::string& filePath, const std::string& encoding, const std::string& valueName, const std::string& valueData) const { CAF_CM_FUNCNAME("setValue"); CAF_CM_ENTER { CAF_CM_VALIDATE_STRING(filePath); CAF_CM_VALIDATE_STRING(encoding); CAF_CM_VALIDATE_STRING(valueName); CAF_CM_VALIDATE_STRING(valueData); if (encoding.compare("iniFileWithoutSection") == 0) { SmartPtrCIniFileWithoutSection iniFileWithoutSection; iniFileWithoutSection.CreateInstance(); iniFileWithoutSection->initialize(filePath); iniFileWithoutSection->setValue(valueName, valueData); } else if (encoding.compare("iniFile") == 0) { std::string sectionName; std::string keyName; parseIniFileValuePath(valueName, sectionName, keyName); SmartPtrCIniFile iniFile; iniFile.CreateInstance(); iniFile->initialize(filePath); iniFile->setValue(sectionName, keyName, valueData); } else if (encoding.compare("xmlFile") == 0) { std::string keyName; std::deque<std::string> keyPathCollection; parseKeyPath(valueName, keyPathCollection, keyName); const SmartPtrCXmlElement rootXml = CXmlUtils::parseFile(filePath, std::string()); const SmartPtrCXmlElement parentXml = findXmlElement(keyPathCollection, rootXml); const SmartPtrCXmlElement foundElement = parentXml->findOptionalChild(keyName); if (! foundElement.IsNull()) { foundElement->setValue(valueData); } else { const std::string foundAttribute = parentXml->findOptionalAttribute(keyName); if (! foundAttribute.empty()) { parentXml->setAttribute(keyName, valueData); } else { const SmartPtrCXmlElement createdElement = parentXml->createAndAddElement(keyName); createdElement->setValue(valueData); } } rootXml->saveToFile(filePath); } else { CAF_CM_EXCEPTIONEX_VA2(InvalidArgumentException, E_INVALIDARG, "URI encoding is not recognized - filePath: %s, encoding: %s", filePath.c_str(), encoding.c_str()); } } CAF_CM_EXIT; }
SmartPtrCResponseHeaderDoc ResponseHeaderXml::parse( const SmartPtrCXmlElement thisXml) { CAF_CM_STATIC_FUNC_VALIDATE("ResponseHeaderXml", "parse"); SmartPtrCResponseHeaderDoc responseHeaderDoc; CAF_CM_ENTER { CAF_CM_VALIDATE_SMARTPTR(thisXml); const std::string versionVal = thisXml->findRequiredAttribute("version"); const std::string createdDateTimeVal = thisXml->findRequiredAttribute("createdDateTime"); const std::string sequenceNumberStrVal = thisXml->findRequiredAttribute("sequenceNumber"); uint32 sequenceNumberVal = 0; if (! sequenceNumberStrVal.empty()) { sequenceNumberVal = CStringConv::fromString<uint32>(sequenceNumberStrVal); } const std::string isFinalResponseStrVal = thisXml->findRequiredAttribute("isFinalResponse"); bool isFinalResponseVal = false; if (! isFinalResponseStrVal.empty()) { isFinalResponseVal = (isFinalResponseStrVal.compare("true") == 0) ? true : false; } const std::string sessionIdStrVal = thisXml->findOptionalAttribute("sessionId"); UUID sessionIdVal = CAFCOMMON_GUID_NULL; if (! sessionIdStrVal.empty()) { BasePlatform::UuidFromString(sessionIdStrVal.c_str(), sessionIdVal); } responseHeaderDoc.CreateInstance(); responseHeaderDoc->initialize( versionVal, createdDateTimeVal, sequenceNumberVal, isFinalResponseVal, sessionIdVal); } CAF_CM_EXIT; return responseHeaderDoc; }
SmartPtrCJoinTypeDoc JoinTypeXml::parse( const SmartPtrCXmlElement thisXml) { CAF_CM_STATIC_FUNC_VALIDATE("JoinTypeXml", "parse"); SmartPtrCJoinTypeDoc joinTypeDoc; CAF_CM_ENTER { CAF_CM_VALIDATE_SMARTPTR(thisXml); const std::string operandStrVal = thisXml->findRequiredAttribute("operand"); OPERATOR_TYPE operandVal = OPERATOR_NONE; if (! operandStrVal.empty()) { operandVal = EnumConvertersXml::convertStringToOperatorType(operandStrVal); } const SmartPtrCXmlElement dataClassLeftXml = thisXml->findRequiredChild("dataClassLeft"); SmartPtrCClassFieldDoc dataClassLeftVal; if (! dataClassLeftXml.IsNull()) { dataClassLeftVal = ClassFieldXml::parse(dataClassLeftXml); } const SmartPtrCXmlElement dataClassRightXml = thisXml->findRequiredChild("dataClassRight"); SmartPtrCClassFieldDoc dataClassRightVal; if (! dataClassRightXml.IsNull()) { dataClassRightVal = ClassFieldXml::parse(dataClassRightXml); } const std::string descriptionStrVal = thisXml->findOptionalAttribute("description"); const std::string descriptionVal = descriptionStrVal; joinTypeDoc.CreateInstance(); joinTypeDoc->initialize( operandVal, dataClassLeftVal, dataClassRightVal, descriptionVal); } CAF_CM_EXIT; return joinTypeDoc; }
SmartPtrCSchemaSummaryDoc SchemaSummaryXml::parse( const SmartPtrCXmlElement thisXml) { CAF_CM_STATIC_FUNC_VALIDATE("SchemaSummaryXml", "parse"); SmartPtrCSchemaSummaryDoc schemaSummaryDoc; CAF_CM_ENTER { CAF_CM_VALIDATE_SMARTPTR(thisXml); const std::string providerNamespaceStrVal = thisXml->findRequiredAttribute("providerNamespace"); const std::string providerNamespaceVal = providerNamespaceStrVal; const std::string providerNameStrVal = thisXml->findRequiredAttribute("providerName"); const std::string providerNameVal = providerNameStrVal; const std::string providerVersionStrVal = thisXml->findRequiredAttribute("providerVersion"); const std::string providerVersionVal = providerVersionStrVal; const SmartPtrCXmlElement classCollectionXml = thisXml->findRequiredChild("classCollection"); SmartPtrCClassCollectionDoc classCollectionVal; if (! classCollectionXml.IsNull()) { classCollectionVal = ClassCollectionXml::parse(classCollectionXml); } const std::string invokerPathStrVal = thisXml->findOptionalAttribute("invokerPath"); const std::string invokerPathVal = invokerPathStrVal; schemaSummaryDoc.CreateInstance(); schemaSummaryDoc->initialize( providerNamespaceVal, providerNameVal, providerVersionVal, classCollectionVal, invokerPathVal); } CAF_CM_EXIT; return schemaSummaryDoc; }
SmartPtrCInstanceParameterDoc InstanceParameterXml::parse( const SmartPtrCXmlElement thisXml) { CAF_CM_STATIC_FUNC_VALIDATE("InstanceParameterXml", "parse"); SmartPtrCInstanceParameterDoc instanceParameterDoc; CAF_CM_ENTER { CAF_CM_VALIDATE_SMARTPTR(thisXml); const std::string nameStrVal = thisXml->findRequiredAttribute("name"); const std::string nameVal = nameStrVal; const std::string instanceNamespaceStrVal = thisXml->findRequiredAttribute("instanceNamespace"); const std::string instanceNamespaceVal = instanceNamespaceStrVal; const std::string instanceNameStrVal = thisXml->findRequiredAttribute("instanceName"); const std::string instanceNameVal = instanceNameStrVal; const std::string instanceVersionStrVal = thisXml->findRequiredAttribute("instanceVersion"); const std::string instanceVersionVal = instanceVersionStrVal; const std::string isOptionalStrVal = thisXml->findRequiredAttribute("isOptional"); bool isOptionalVal = false; if (! isOptionalStrVal.empty()) { isOptionalVal = (isOptionalStrVal.compare("true") == 0) ? true : false; } const std::string isListStrVal = thisXml->findOptionalAttribute("isList"); bool isListVal = false; if (! isListStrVal.empty()) { isListVal = (isListStrVal.compare("true") == 0) ? true : false; } const std::string displayNameStrVal = thisXml->findOptionalAttribute("displayName"); const std::string displayNameVal = displayNameStrVal; const std::string descriptionStrVal = thisXml->findOptionalAttribute("description"); const std::string descriptionVal = descriptionStrVal; instanceParameterDoc.CreateInstance(); instanceParameterDoc->initialize( nameVal, instanceNamespaceVal, instanceNameVal, instanceVersionVal, isOptionalVal, isListVal, displayNameVal, descriptionVal); } CAF_CM_EXIT; return instanceParameterDoc; }
void CApplicationContext::parseBeanConfig( const std::string& beanConfigFile, CBeanCollection& beanCollection) const { CAF_CM_FUNCNAME("parseBeanConfig"); CAF_CM_VALIDATE_STRING(beanConfigFile); CAF_CM_LOG_DEBUG_VA1("Parsing bean config file %s", beanConfigFile.c_str()); // We will look up class references early in the process to fail as early // as possible and to make logging better. // Parse the bean config file CXmlElement::SmartPtrCElementCollection rootElements = CXmlUtils::parseFile(beanConfigFile, "caf:beans")->getAllChildren(); for (TSmartConstMultimapIterator<CXmlElement::CElementCollection> rootChild(*rootElements); rootChild; rootChild++) { // if the child is a bean... if (rootChild->getName() == "bean") { // Syntactic sugar const SmartPtrCXmlElement beanElement = *rootChild; // Bean attributes const std::string beanId = beanElement->findRequiredAttribute("id"); CAF_CM_LOG_DEBUG_VA1("Parsing bean [id=%s]", beanId.c_str()); const std::string beanClass = beanElement->findRequiredAttribute("class"); CAF_CM_LOG_DEBUG_VA2( "Checking bean class [id=%s][class=%s]", beanId.c_str(), beanClass.c_str()); if (!CEcmSubSystemRegistry::IsRegistered(beanClass)) { CAF_CM_EXCEPTIONEX_VA3( NoSuchElementException, 0, "Bean class %s is not registered. Fix the AppConfig file. " "[bean id=%s][bean_config_file=%s]", beanClass.c_str(), beanId.c_str(), beanConfigFile.c_str()); } // get optional constructor args and properties CBeanCtorArgCollection beanCtorArgs; Cmapstrstr beanProperties; CAF_CM_LOG_DEBUG_VA1("Parsing bean ctor args and properties [id=%s]", beanId.c_str()); CXmlElement::SmartPtrCElementCollection beanElements = beanElement->getAllChildren(); for (TSmartConstMultimapIterator<CXmlElement::CElementCollection> beanChild(*beanElements); beanChild; beanChild++) { if (beanChild->getName() == "property") { // Syntactic sugar const SmartPtrCXmlElement propArgElement = *beanChild; // property attributes const std::string name = propArgElement->findRequiredAttribute("name"); const std::string value = propArgElement->findRequiredAttribute("value"); if (!beanProperties.insert(std::make_pair(name, value)).second) { CAF_CM_EXCEPTIONEX_VA3( DuplicateElementException, 0, "Bean property name is duplicated. " "[bean id=%s][property name=%s][bean_config_file=%s]", beanId.c_str(), name.c_str(), beanConfigFile.c_str()); } } else if (beanChild->getName() == "constructor-arg") { // Syntactic sugar const SmartPtrCXmlElement ctorArgElement = *beanChild; // ctor attributes const uint32 ctorArgIndex = CStringConv::fromString<uint32>(ctorArgElement->findRequiredAttribute("index")); CBeanCtorArg::ARG_TYPE ctorArgType = CBeanCtorArg::NOT_SET; std::string ctorArgValue = ctorArgElement->findOptionalAttribute("value"); if (ctorArgValue.length() > 0) { ctorArgType = CBeanCtorArg::VALUE; } else { ctorArgValue = ctorArgElement->findOptionalAttribute("ref"); if (ctorArgValue.length() > 0) { ctorArgType = CBeanCtorArg::REFERENCE; } else { CAF_CM_EXCEPTIONEX_VA2( InvalidArgumentException, 0, "Bean constructor argument must be of type value or ref and cannot be empty. " "[bean id=%s][bean_config_file=%s]", beanId.c_str(), beanConfigFile.c_str()); } } if (!beanCtorArgs.insert( CBeanCtorArgCollection::value_type( ctorArgIndex, CBeanCtorArg(ctorArgType, ctorArgValue))).second) { CAF_CM_EXCEPTIONEX_VA3( DuplicateElementException, 0, "Bean has a duplicate constructor-arg index. " "[bean id=%s][bean_config_file=%s][arg-index=%d]", beanId.c_str(), beanConfigFile.c_str(), ctorArgIndex); } CAF_CM_LOG_DEBUG_VA4( "Bean ctor arg parsed [id=%s][arg-index=%d][arg-type=%s][arg-value=%s]", beanId.c_str(), ctorArgIndex, (CBeanCtorArg::VALUE == ctorArgType ? "VALUE" : "REFERENCE"), ctorArgValue.c_str()); } } // Add the bean definition to the collection SmartPtrCBeanNode beanNode; beanNode.CreateInstance(); beanNode->_id = beanId; beanNode->_class = beanClass; beanNode->_ctorArgs = beanCtorArgs; beanNode->_properties = beanProperties; if (!beanCollection.insert( CBeanCollection::value_type( beanId, beanNode)).second) { CAF_CM_EXCEPTIONEX_VA3( DuplicateElementException, 0, "Duplicate bean definition detected. " "[bean id=%s][bean class=%s][bean_config_file=%s]", beanId.c_str(), beanNode->_class.c_str(), beanConfigFile.c_str()); } } } CAF_CM_LOG_DEBUG_VA2( "Bean configuration file defined %d beans. " "[file=%s]", beanCollection.size(), beanConfigFile.c_str()); }
SmartPtrCLogicalRelationshipDoc LogicalRelationshipXml::parse( const SmartPtrCXmlElement thisXml) { CAF_CM_STATIC_FUNC_VALIDATE("LogicalRelationshipXml", "parse"); SmartPtrCLogicalRelationshipDoc logicalRelationshipDoc; CAF_CM_ENTER { CAF_CM_VALIDATE_SMARTPTR(thisXml); const std::string namespaceValStrVal = thisXml->findRequiredAttribute("namespace"); const std::string namespaceValVal = namespaceValStrVal; const std::string nameStrVal = thisXml->findRequiredAttribute("name"); const std::string nameVal = nameStrVal; const std::string versionStrVal = thisXml->findRequiredAttribute("version"); const std::string versionVal = versionStrVal; const std::string arityStrVal = thisXml->findRequiredAttribute("arity"); ARITY_TYPE arityVal = ARITY_NONE; if (! arityStrVal.empty()) { arityVal = EnumConvertersXml::convertStringToArityType(arityStrVal); } const SmartPtrCXmlElement dataClassLeftXml = thisXml->findRequiredChild("dataClassLeft"); SmartPtrCClassCardinalityDoc dataClassLeftVal; if (! dataClassLeftXml.IsNull()) { dataClassLeftVal = ClassCardinalityXml::parse(dataClassLeftXml); } const SmartPtrCXmlElement dataClassRightXml = thisXml->findRequiredChild("dataClassRight"); SmartPtrCClassCardinalityDoc dataClassRightVal; if (! dataClassRightXml.IsNull()) { dataClassRightVal = ClassCardinalityXml::parse(dataClassRightXml); } const CXmlElement::SmartPtrCElementCollection joinChildrenXml = thisXml->findRequiredChildren("join"); std::deque<SmartPtrCJoinTypeDoc> joinVal; if (! joinChildrenXml.IsNull() && ! joinChildrenXml->empty()) { for (TConstIterator<CXmlElement::CElementCollection> joinXmlIter(*joinChildrenXml); joinXmlIter; joinXmlIter++) { const SmartPtrCXmlElement joinXml = joinXmlIter->second; const SmartPtrCJoinTypeDoc joinDoc = JoinTypeXml::parse(joinXml); joinVal.push_back(joinDoc); } } const std::string descriptionStrVal = thisXml->findOptionalAttribute("description"); const std::string descriptionVal = descriptionStrVal; logicalRelationshipDoc.CreateInstance(); logicalRelationshipDoc->initialize( namespaceValVal, nameVal, versionVal, arityVal, dataClassLeftVal, dataClassRightVal, joinVal, descriptionVal); } CAF_CM_EXIT; return logicalRelationshipDoc; }