📄 cimobjectpath.cpp
字号:
throw MalformedObjectNameException(objectName); } } valueString.append(*p++); } if (*p++ != '"') throw MalformedObjectNameException(objectName); /* Guess at the type of this quoted key value. If the value can be parsed into a CIMObjectPath with at least one key binding, the type is assumed to be a REFERENCE. Otherwise, the type is set to STRING. (See method header for details.) */ type = CIMKeyBinding::STRING; try { CIMObjectPath testForPath(valueString); if (testForPath.getKeyBindings().size() > 0) { // We've found a reference value! type = CIMKeyBinding::REFERENCE; } } catch (const Exception &) { // Not a reference value; leave type as STRING } } else if (toupper(*p) == 'T' || toupper(*p) == 'F') { type = CIMKeyBinding::BOOLEAN; char* r = p; Uint32 n = 0; while (*r && *r != ',') { *r = toupper(*r); r++; n++; } if (!(((strncmp(p, "TRUE", n) == 0) && n == 4) || ((strncmp(p, "FALSE", n) == 0) && n == 5))) throw MalformedObjectNameException(objectName); valueString.assign(p, n); p = p + n; } else { type = CIMKeyBinding::NUMERIC; char* r = p; Uint32 n = 0; while (*r && *r != ',') { r++; n++; } Boolean isComma = false; if (*r) { *r = '\0'; isComma = true; } if (*p == '-') { Sint64 x; if (!XmlReader::stringToSignedInteger(p, x)) throw MalformedObjectNameException(objectName); } else { Uint64 x; if (!XmlReader::stringToUnsignedInteger(p, x)) throw MalformedObjectNameException(objectName); } valueString.assign(p, n); if (isComma) { *r = ','; } p = p + n; } keyBindings.append(CIMKeyBinding(keyName.getString (), valueString, type)); if (*p) { if (*p++ != ',') { throw MalformedObjectNameException(objectName); } } } _BubbleSort(keyBindings);}void CIMObjectPath::set(const String& objectName){ clear(); //-------------------------------------------------------------------------- // We will extract components from an object name. Here is an sample // object name: // // //atp:9999/root/cimv25:TennisPlayer.first="Patrick",last="Rafter" //-------------------------------------------------------------------------- // Convert to a C String first: CString pCString = objectName.getCString(); char* p = const_cast<char*>((const char*) pCString); Boolean gotHost; Boolean gotNamespace; gotHost = _parseHostElement(objectName, p, _rep->_host); gotNamespace = _parseNamespaceElement(objectName, p, _rep->_nameSpace); if (gotHost && !gotNamespace) { throw MalformedObjectNameException(objectName); } // Extract the class name: char* dot = strchr(p, '.'); if (!dot) { if (!CIMName::legal(p)) { throw MalformedObjectNameException(objectName); } // ATTN: remove this later: a reference should only be able to hold // an instance name. _rep->_className = CIMName (p); return; } String className = String(p, (Uint32)(dot - p)); if (!CIMName::legal(className)) { throw MalformedObjectNameException(objectName); } _rep->_className = className; // Advance past dot: p = dot + 1; _parseKeyBindingPairs(objectName, p, _rep->_keyBindings);}CIMObjectPath& CIMObjectPath::operator=(const String& objectName){ set(objectName); return *this;}const String& CIMObjectPath::getHost() const{ return _rep->_host;}void CIMObjectPath::setHost(const String& host){ if ((host != String::EMPTY) && !CIMObjectPathRep::isValidHostname(host)) { throw MalformedObjectNameException(host); } _rep->_host = host;}const CIMNamespaceName& CIMObjectPath::getNameSpace() const{ return _rep->_nameSpace;}void CIMObjectPath::setNameSpace(const CIMNamespaceName& nameSpace){ _rep->_nameSpace = nameSpace;}const CIMName& CIMObjectPath::getClassName() const{ return _rep->_className;}void CIMObjectPath::setClassName(const CIMName& className){ _rep->_className = className;}const Array<CIMKeyBinding>& CIMObjectPath::getKeyBindings() const{ return _rep->_keyBindings;}void CIMObjectPath::setKeyBindings(const Array<CIMKeyBinding>& keyBindings){ _rep->_keyBindings = keyBindings; _BubbleSort(_rep->_keyBindings);}String CIMObjectPath::toString() const{ String objectName; // Get the host: if (_rep->_host.size()) { objectName = "//"; objectName.append(_rep->_host); objectName.append("/"); } // Get the namespace (if we have a host name, we must write namespace): if (!_rep->_nameSpace.isNull() || _rep->_host.size()) { objectName.append(_rep->_nameSpace.getString ()); objectName.append(":"); } // Get the class name: objectName.append(getClassName().getString ()); // // ATTN-CAKG-P2-20020726: The following condition does not correctly // distinguish instanceNames from classNames in every case // The instanceName of a singleton instance of a keyless class has no // key bindings // if (_rep->_keyBindings.size () != 0) { objectName.append('.'); // Append each key-value pair: const Array<CIMKeyBinding>& keyBindings = getKeyBindings(); for (Uint32 i = 0, n = keyBindings.size(); i < n; i++) { objectName.append(keyBindings[i].getName().getString ()); objectName.append('='); const String& value = _escapeSpecialCharacters( keyBindings[i].getValue()); CIMKeyBinding::Type type = keyBindings[i].getType(); if (type == CIMKeyBinding::STRING || type == CIMKeyBinding::REFERENCE) objectName.append('"'); objectName.append(value); if (type == CIMKeyBinding::STRING || type == CIMKeyBinding::REFERENCE) objectName.append('"'); if (i + 1 != n) objectName.append(','); } } return objectName;}String CIMObjectPath::_toStringCanonical() const{ CIMObjectPath ref = *this; // Normalize hostname by changing to lower case ref._rep->_host.toLower(); // ICU_TODO: // Normalize namespace by changing to lower case if (!ref._rep->_nameSpace.isNull()) { String nameSpaceLower = ref._rep->_nameSpace.getString(); nameSpaceLower.toLower(); // ICU_TODO: ref._rep->_nameSpace = nameSpaceLower; } // Normalize class name by changing to lower case if (!ref._rep->_className.isNull()) { String classNameLower = ref._rep->_className.getString(); classNameLower.toLower(); // ICU_TODO: ref._rep->_className = classNameLower; } for (Uint32 i = 0, n = ref._rep->_keyBindings.size(); i < n; i++) { // Normalize key binding name by changing to lower case if (!ref._rep->_keyBindings[i]._rep->_name.isNull()) { String keyBindingNameLower = ref._rep->_keyBindings[i]._rep->_name.getString(); keyBindingNameLower.toLower(); // ICU_TODO: ref._rep->_keyBindings[i]._rep->_name = keyBindingNameLower; } // Normalize the key value switch (ref._rep->_keyBindings[i]._rep->_type) { case CIMKeyBinding::REFERENCE: try { // Convert reference to CIMObjectPath and recurse ref._rep->_keyBindings[i]._rep->_value = CIMObjectPath(ref._rep->_keyBindings[i]._rep->_value). _toStringCanonical(); } catch (Exception&) { // Leave value unchanged if the CIMObjectPath parsing fails } break; case CIMKeyBinding::BOOLEAN: // Normalize the boolean string by changing to lower case ref._rep->_keyBindings[i]._rep->_value.toLower(); // ICU_TODO: break; case CIMKeyBinding::NUMERIC: // Normalize the numeric string by converting to integer and back Uint64 uValue; Sint64 sValue; // First try converting to unsigned integer if (XmlReader::stringToUnsignedInteger( ref._rep->_keyBindings[i]._rep->_value.getCString(), uValue)) { char buffer[32]; // Should need 21 chars max sprintf(buffer, "%" PEGASUS_64BIT_CONVERSION_WIDTH "u", uValue); ref._rep->_keyBindings[i]._rep->_value = String(buffer); } // Next try converting to signed integer else if (XmlReader::stringToSignedInteger( ref._rep->_keyBindings[i]._rep->_value.getCString(), sValue)) { char buffer[32]; // Should need 21 chars max sprintf(buffer, "%" PEGASUS_64BIT_CONVERSION_WIDTH "d", sValue); ref._rep->_keyBindings[i]._rep->_value = String(buffer); } // Leave value unchanged if it cannot be converted to an integer break; default: // CIMKeyBinding::STRING // No normalization required for STRING break; } } // Note: key bindings are sorted when set in the CIMObjectPath return ref.toString();}Boolean CIMObjectPath::identical(const CIMObjectPath& x) const{ return String::equalNoCase(_rep->_host, x._rep->_host) && _rep->_nameSpace.equal(x._rep->_nameSpace) && _rep->_className.equal(x._rep->_className) && _rep->_keyBindings == x._rep->_keyBindings;}Uint32 CIMObjectPath::makeHashCode() const{ return HashFunc<String>::hash(_toStringCanonical());}Boolean operator==(const CIMObjectPath& x, const CIMObjectPath& y){ return x.identical(y);}Boolean operator!=(const CIMObjectPath& x, const CIMObjectPath& y){ return !operator==(x, y);}PEGASUS_NAMESPACE_END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -