📄 objectnormalizer.cpp
字号:
{}ObjectNormalizer::ObjectNormalizer( const CIMClass& cimClass, Boolean includeQualifiers, Boolean includeClassOrigin, const CIMNamespaceName& nameSpace, AutoPtr<NormalizerContext>& context) : _cimClass(cimClass), _includeQualifiers(includeQualifiers), _includeClassOrigin(includeClassOrigin), _context(context), _nameSpace(nameSpace){ if (!_cimClass.isUninitialized()) { // ATTN: the following code is intended to expedite normalizing // instances and instance object paths by establishing the keys // once now rather than multiple times later. it is biased // toward providers that return many instances with many properties. // build a reference object path within the class Array<CIMKeyBinding> keys; for (Uint32 i = 0, n = _cimClass.getPropertyCount(); i < n; i++) { CIMConstProperty referenceProperty = _cimClass.getProperty(i); Uint32 pos = referenceProperty.findQualifier("key"); if ((pos != PEG_NOT_FOUND) && (referenceProperty.getQualifier(pos).getValue().equal( CIMValue(true)))) { if (referenceProperty.getType() == CIMTYPE_REFERENCE) { // ATTN: a fake reference is inserted in the key so that // the _BubbleSort() method in CIMObjectPath does not // throw and exception. It implicitly validates keys of // type REFERENCE so just place a dummy value for now. // The value will be replaced by the normalized object // later. keys.append(CIMKeyBinding(referenceProperty.getName(), "class.key=\"value\"", CIMKeyBinding::REFERENCE)); } else { keys.append(CIMKeyBinding(referenceProperty.getName(), referenceProperty.getValue())); } } } // update class object path CIMObjectPath cimObjectPath(_cimClass.getPath()); cimObjectPath.setKeyBindings(keys); _cimClass.setPath(cimObjectPath); }}CIMObjectPath ObjectNormalizer::processClassObjectPath( const CIMObjectPath& cimObjectPath) const{ // pre-check if (_cimClass.isUninitialized()) { // do nothing return cimObjectPath; } /* // ATTN: moving similar logic to the response handlers because this // type of error should be checked regardless with or without // normalization enabled. if (cimObjectPath.getClassName().isNull()) { throw CIMException(CIM_ERR_FAILED, "uninitialized object path"); } */ /* // ATTN: The following code is currently redundant because the CIMName // object validates legal names when it is constructed. It is included // here for completeness. // check class name if (!CIMName(cimObjectPath.getClassName()).legal()) { MessageLoaderParms message( "Common.ObjectNormalizer.INVALID_CLASS_NAME", "Invalid class name: $0", cimObjectPath.getClassName().getString()); throw CIMException(CIM_ERR_FAILED, message); } */ // check class type if (!_cimClass.getClassName().equal(cimObjectPath.getClassName())) { MessageLoaderParms message( "Common.ObjectNormalizer.INVALID_CLASS_TYPE", "Invalid class type: $0", cimObjectPath.getClassName().getString()); throw CIMException(CIM_ERR_FAILED, message); } CIMObjectPath normalizedObjectPath( _cimClass.getPath().getHost(), _cimClass.getPath().getNameSpace(), _cimClass.getClassName()); // ignore any keys, they are not part of a class object path return normalizedObjectPath;}CIMObjectPath ObjectNormalizer::processInstanceObjectPath( const CIMObjectPath& cimObjectPath) const{ // pre-check if (_cimClass.isUninitialized()) { // do nothing return cimObjectPath; } /* // ATTN: moving similar logic to the response handlers because this // type of error should be checked regardless with or without // normalization enabled. if (cimObjectPath.getClassName().isNull()) { throw CIMException(CIM_ERR_FAILED, "uninitialized object path"); } */ /* // ATTN: The following code is currently redundant because the CIMName // object validates legal names when it is constructed. It is included // here for completeness. // check class name if (!CIMName(cimObjectPath.getClassName()).legal()) { MessageLoaderParms message( "Common.ObjectNormalizer.INVALID_CLASS_NAME", "Invalid class name: $0", cimObjectPath.getClassName().getString()); throw CIMException(CIM_ERR_FAILED, message); } */ // check class type if (!_cimClass.getClassName().equal(cimObjectPath.getClassName())) { MessageLoaderParms message( "Common.ObjectNormalizer.INVALID_CLASS_TYPE", "Invalid class type: $0", cimObjectPath.getClassName().getString()); throw CIMException(CIM_ERR_FAILED, message); } CIMObjectPath normalizedObjectPath( _cimClass.getPath().getHost(), _cimClass.getPath().getNameSpace(), _cimClass.getClassName()); Array<CIMKeyBinding> normalizedKeys; Array<CIMKeyBinding> referenceKeys = _cimClass.getPath().getKeyBindings(); Array<CIMKeyBinding> cimKeys = cimObjectPath.getKeyBindings(); for (Uint32 i = 0, n = referenceKeys.size(); i < n; i++) { CIMKeyBinding key; // override the value from the specified object for (Uint32 j = 0, m = cimKeys.size(); j < m; j++) { if (referenceKeys[i].getName().equal(cimKeys[j].getName())) { // check type if (referenceKeys[i].getType() != cimKeys[j].getType()) { MessageLoaderParms message( "Common.ObjectNormalizer.INVALID_KEY_TYPE", "Invalid key type: $0", referenceKeys[i].getName().getString()); throw CIMException(CIM_ERR_FAILED, message); } key = CIMKeyBinding(referenceKeys[i].getName(), cimKeys[j].getValue(), referenceKeys[i].getType()); break; } } // key not found if (key.getName().isNull()) { MessageLoaderParms message( "Common.ObjectNormalizer.MISSING_KEY", "Missing key: $0", referenceKeys[i].getName().getString()); throw CIMException(CIM_ERR_FAILED, message); } normalizedKeys.append(key); } normalizedObjectPath.setKeyBindings(normalizedKeys); return normalizedObjectPath;}CIMInstance ObjectNormalizer::processInstance( const CIMInstance& cimInstance) const{ // pre-checks if (_cimClass.isUninitialized()) { // do nothing return cimInstance; } /* // ATTN: moving similar logic to the response handlers because this // type of error should be checked regardless with or without // normalization enabled. if (cimInstance.isUninitialized()) { throw CIMException(CIM_ERR_FAILED, "unintialized instance object."); } */ CIMInstance normalizedInstance(_cimClass.getClassName()); // proces object path normalizedInstance.setPath( processInstanceObjectPath(cimInstance.getPath())); // process instance qualifiers if (_includeQualifiers) { // propagate class qualifiers for (Uint32 i = 0, n = _cimClass.getQualifierCount(); i < n; i++) { CIMConstQualifier referenceQualifier = _cimClass.getQualifier(i); Uint32 pos = cimInstance.findQualifier(referenceQualifier.getName()); // update value if qualifier is present in the specified property if (pos != PEG_NOT_FOUND) { CIMConstQualifier cimQualifier = cimInstance.getQualifier(pos); CIMQualifier normalizedQualifier = _processQualifier( referenceQualifier, cimQualifier); normalizedInstance.addQualifier(normalizedQualifier); } else { normalizedInstance.addQualifier(referenceQualifier.clone()); } } } // check property names and types. any properties in the class but not // in the instance are implicitly dropped. for (Uint32 i = 0, n = _cimClass.getPropertyCount(); i < n; i++) { CIMConstProperty referenceProperty = _cimClass.getProperty(i); Uint32 pos = cimInstance.findProperty(referenceProperty.getName()); if (pos != PEG_NOT_FOUND) { CIMConstProperty cimProperty = cimInstance.getProperty(pos); CIMProperty normalizedProperty = _processProperty( referenceProperty, cimProperty, _includeQualifiers, _includeClassOrigin, _context.get(), _nameSpace); normalizedInstance.addProperty(normalizedProperty); } } return normalizedInstance;}PEGASUS_NAMESPACE_END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -