CIMClass LocalRepository::getClass( const String & nameSpace, const String & className, Boolean includeQualifiers, Boolean includeClassOrigin, const CIMPropertyList & propertyList) { // create a duplicate object before modifying CIMClass cimClass = context->lookupClass("test_namespace", className).clone(); if(!includeQualifiers) { // remove qualifiers from class for(Uint32 i = 0, n = cimClass.getQualifierCount(); i < n; i++) { cimClass.removeQualifier(i); } // remove qualifiers from properties for(Uint32 i = 0, n = cimClass.getPropertyCount(); i < n; i++) { CIMProperty cimProperty = cimClass.getProperty(i); for(Uint32 j = 0, m = cimProperty.getQualifierCount(); j < m; j++) { cimProperty.removeQualifier(j); } } } if(!includeClassOrigin) { // remove class origin for(Uint32 i = 0, n = cimClass.getPropertyCount(); i < n; i++) { cimClass.getProperty(i).setClassOrigin(CIMName()); } } cimClass.setPath(CIMObjectPath("localhost", "test_namespace", cimClass.getClassName())); return(cimClass); }
///////////////////////////////////////////////////////////////////////////// // WMIClassProvider::createClassNameAndClassQualifiers // // /////////////////////////////////////////////////////////////////////////// void WMIClassProvider::createClassNameAndClassQualifiers(const CIMClass& newClass, IWbemServices *pServices, IWbemClassObject **pNewClass, const bool hasSuperClass) { HRESULT hr; PEG_METHOD_ENTER(TRC_WMIPROVIDER, "WmiClassProvider::createClassNameAndClassQualifiers()"); // if the class has a superclass, we need to spwan a derived if (hasSuperClass) { // get the superclass name CComPtr<IWbemClassObject> pSuperClass; String tmp = newClass.getSuperClassName().getString(); CComBSTR bs = tmp.getCString(); hr = pServices->GetObject( bs, NULL, NULL, &pSuperClass, NULL); bs.Empty(); if (FAILED(hr)) { if (pSuperClass) pSuperClass.Release(); CMyString msg; msg.Format("Failed to get a pointer to Superclass [%s]. Error: 0x%X", 255, tmp.getCString(), hr); Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3, "WMIClassProvider::createClassNameAndClassQualifiers() - %s", (LPCTSTR)msg); throw CIMException(CIM_ERR_FAILED, (LPCTSTR)msg); } //Creates the new class pSuperClass->SpawnDerivedClass(NULL, pNewClass); if (pSuperClass) pSuperClass.Release(); } else { // we are creating a base class hr = pServices->GetObject(NULL, NULL, NULL, pNewClass, NULL); if (FAILED(hr)) { CMyString msg; msg.Format("Failed to get a pointer to a new class. Error: 0x%X", hr); Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3, "WMIClassProvider::createClassNameAndClassQualifiers() - %s", (LPCTSTR)msg); throw CIMException(CIM_ERR_FAILED, (LPCTSTR)msg); } } // create the class name CComVariant v; v = newClass.getClassName().getString().getCString(); hr = (*pNewClass)->Put(L"__CLASS", 0, &v, 0); v.Clear(); if (FAILED(hr)) { CMyString msg; msg.Format("Failed to add class name on class [%s]. Error: 0x%X", 255, newClass.getClassName().getString().getCString(), hr); Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3, "WMIClassProvider::createClassNameAndClassQualifiers() - %s", (LPCTSTR)msg); if (*pNewClass) (*pNewClass)->Release(); throw CIMException(CIM_ERR_FAILED, (LPCTSTR)msg); } // get a pointer to work with qualifiers CComPtr<IWbemQualifierSet> pNewClassQualifier; hr = (*pNewClass)->GetQualifierSet(&pNewClassQualifier); if (FAILED(hr)) { CMyString msg; msg.Format("Failed to get the Qualifier set pointer of class [%s]. Error: 0x%X", 255, newClass.getClassName().getString().getCString(), hr); Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3, "WMIClassProvider::createClassNameAndClassQualifiers() - %s", (LPCTSTR)msg); if (*pNewClass) (*pNewClass)->Release(); if (pNewClassQualifier) pNewClassQualifier.Release(); throw CIMException(CIM_ERR_FAILED, (LPCTSTR)msg); } // check the class qualifiers and create them if they are valid // we are taking care of the class qualifiers and not methods/properties qualifiers :D for (Uint32 i = 0; i < newClass.getQualifierCount(); i++) { try { WMIQualifier qualifier(newClass.getQualifier(i).clone()); createQualifier(qualifier, pNewClassQualifier); } catch (CIMException&) { if (*pNewClass) (*pNewClass)->Release(); if (pNewClassQualifier) pNewClassQualifier.Release(); throw; } } if (pNewClassQualifier) pNewClassQualifier.Release(); PEG_METHOD_EXIT(); return; }