OW_provinstCIM_NamespaceInManager.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2003-2004 Vintela, Inc. All rights reserved.
00003 *
00004 * Redistribution and use in source and binary forms, with or without
00005 * modification, are permitted provided that the following conditions are met:
00006 *
00007 *  - Redistributions of source code must retain the above copyright notice,
00008 *    this list of conditions and the following disclaimer.
00009 *
00010 *  - Redistributions in binary form must reproduce the above copyright notice,
00011 *    this list of conditions and the following disclaimer in the documentation
00012 *    and/or other materials provided with the distribution.
00013 *
00014 *  - Neither the name of Vintela, Inc. nor the names of its
00015 *    contributors may be used to endorse or promote products derived from this
00016 *    software without specific prior written permission.
00017 *
00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 * ARE DISCLAIMED. IN NO EVENT SHALL Vintela, Inc. OR THE CONTRIBUTORS
00022 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00023 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00024 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00027 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00028 * POSSIBILITY OF SUCH DAMAGE.
00029 *******************************************************************************/
00030 
00035 #include "OW_config.h"
00036 #include "OW_CppInstanceProviderIFC.hpp"
00037 #ifndef OW_DISABLE_ASSOCIATION_TRAVERSAL
00038 #include "OW_CppAssociatorProviderIFC.hpp"
00039 #endif
00040 #include "OW_CIMClass.hpp"
00041 #include "OW_CIMInstance.hpp"
00042 #include "OW_CIMException.hpp"
00043 #include "OW_CIMValue.hpp"
00044 #include "OW_CIMProperty.hpp"
00045 #include "OW_CIMObjectPath.hpp"
00046 #include "OW_CIMObjectPathEnumeration.hpp"
00047 #include "OW_Assertion.hpp"
00048 #include "OW_ResultHandlerIFC.hpp"
00049 #include "OW_Logger.hpp"
00050 #include "OW_CIMOMHandleIFC.hpp"
00051 
00052 namespace OW_NAMESPACE
00053 {
00054 
00055 namespace
00056 {
00057    const String COMPONENT_NAME("ow.provider.CIM_NamespaceInManager");
00058 }
00059 
00060 using namespace WBEMFlags;
00061 
00062 class CIM_NamespaceInManagerInstProv :
00063 #ifndef OW_DISABLE_ASSOCIATION_TRAVERSAL
00064 public CppAssociatorProviderIFC
00065 #else
00066 public CppInstanceProviderIFC
00067 #endif
00068 {
00069 public:
00071    virtual ~CIM_NamespaceInManagerInstProv()
00072    {
00073    }
00075    virtual void getInstanceProviderInfo(InstanceProviderInfo& info)
00076    {
00077       info.addInstrumentedClass("CIM_NamespaceInManager");
00078    }
00080    virtual void enumInstanceNames(
00081       const ProviderEnvironmentIFCRef& env,
00082       const String& ns,
00083       const String& className,
00084       CIMObjectPathResultHandlerIFC& result,
00085       const CIMClass& cimClass )
00086    {
00087       OW_LOG_DEBUG(env->getLogger(COMPONENT_NAME), "In CIM_NamespaceInManagerInstProv::enumInstanceNames");
00088       CIMObjectPath newCop(className, ns);
00089       CIMOMHandleIFCRef hdl = env->getCIMOMHandle();
00090       CIMObjectPathEnumeration objectManagers = hdl->enumInstanceNamesE(ns, "CIM_ObjectManager");
00091       CIMObjectPathEnumeration namespaces = hdl->enumInstanceNamesE(ns, "CIM_Namespace");
00092       if (!objectManagers.hasMoreElements())
00093       {
00094          return;
00095       }
00096       
00097       // should only be one ObjectManager
00098       CIMObjectPath omPath = objectManagers.nextElement();
00099       while (namespaces.hasMoreElements())
00100       {
00101          CIMObjectPath nsPath = namespaces.nextElement();
00102          newCop.setKeyValue("Antecedent", CIMValue(omPath));
00103          newCop.setKeyValue("Dependent", CIMValue(nsPath));
00104          result.handle(newCop);
00105       }
00106    }
00108    virtual void enumInstances(
00109       const ProviderEnvironmentIFCRef& env,
00110       const String& ns,
00111       const String& className,
00112       CIMInstanceResultHandlerIFC& result,
00113       ELocalOnlyFlag localOnly,
00114       EDeepFlag deep,
00115       EIncludeQualifiersFlag includeQualifiers,
00116       EIncludeClassOriginFlag includeClassOrigin,
00117       const StringArray* propertyList,
00118       const CIMClass& requestedClass,
00119       const CIMClass& cimClass )
00120    {
00121       OW_LOG_DEBUG(env->getLogger(COMPONENT_NAME), "In CIM_NamespaceInManagerInstProv::enumInstances");
00122       CIMOMHandleIFCRef hdl = env->getCIMOMHandle();
00123       CIMObjectPathEnumeration objectManagers = hdl->enumInstanceNamesE(ns, "CIM_ObjectManager");
00124       CIMObjectPathEnumeration namespaces = hdl->enumInstanceNamesE(ns, "CIM_Namespace");
00125       if (!objectManagers.hasMoreElements())
00126       {
00127          return;
00128       }
00129       
00130       // should only be one ObjectManager
00131       CIMObjectPath omPath = objectManagers.nextElement();
00132       while (namespaces.hasMoreElements())
00133       {
00134          CIMObjectPath nsPath = namespaces.nextElement();
00135          CIMInstance newInst = cimClass.newInstance();
00136          newInst.setProperty("Antecedent", CIMValue(omPath));
00137          newInst.setProperty("Dependent", CIMValue(nsPath));
00138          result.handle(newInst.clone(localOnly,deep,includeQualifiers,
00139             includeClassOrigin,propertyList,requestedClass,cimClass));
00140       }
00141    }
00143    virtual CIMInstance getInstance(
00144       const ProviderEnvironmentIFCRef& env,
00145       const String& ns,
00146       const CIMObjectPath& instanceName,
00147       ELocalOnlyFlag localOnly,
00148       EIncludeQualifiersFlag includeQualifiers,
00149       EIncludeClassOriginFlag includeClassOrigin,
00150       const StringArray* propertyList,
00151       const CIMClass& cimClass )
00152    {
00153       OW_LOG_DEBUG(env->getLogger(COMPONENT_NAME), "In CIM_NamespaceInManagerInstProv::getInstance");
00154       CIMInstance inst = cimClass.newInstance();
00155       try
00156       {
00157          // first verify that the object manager exists.
00158          CIMObjectPath objectManagerPath(instanceName.getKeyT("Antecedent").getValueT().toCIMObjectPath());
00159          String omNs = objectManagerPath.getNameSpace();
00160          if (omNs.empty())
00161          {
00162             omNs = ns;
00163          }
00164    
00165          // This will throw if it doesn't exist
00166          env->getCIMOMHandle()->getInstance(omNs, objectManagerPath);
00167    
00168          CIMObjectPath nsPath(instanceName.getKeyT("Dependent").getValueT().toCIMObjectPath());
00169          String nsNs = nsPath.getNameSpace();
00170          if (nsNs.empty())
00171          {
00172             nsNs = ns;
00173          }
00174    
00175          // This will throw if it doesn't exist
00176          env->getCIMOMHandle()->getInstance(nsNs, nsPath);
00177    
00178    
00179          inst = cimClass.newInstance();
00180          inst.setProperty("Antecedent", CIMValue(objectManagerPath));
00181          inst.setProperty("Dependent", CIMValue(nsPath));
00182    
00183       }
00184       catch (const CIMException& e)
00185       {
00186          throw;
00187       }
00188       catch (const Exception& e)
00189       {
00190          OW_THROWCIM_SUBEX(CIMException::NOT_FOUND, e);
00191       }
00192       return inst.clone(localOnly,includeQualifiers,includeClassOrigin,propertyList);
00193    }
00194 #ifndef OW_DISABLE_INSTANCE_MANIPULATION
00195 
00196    virtual CIMObjectPath createInstance(
00197       const ProviderEnvironmentIFCRef& env,
00198       const String& ns,
00199       const CIMInstance& cimInstance )
00200    {
00201       // just ignore createInstance.
00202       return CIMObjectPath(ns, cimInstance);
00203    }
00205    virtual void modifyInstance(
00206       const ProviderEnvironmentIFCRef& env,
00207       const String& ns,
00208       const CIMInstance& modifiedInstance,
00209       const CIMInstance& previousInstance,
00210       EIncludeQualifiersFlag includeQualifiers,
00211       const StringArray* propertyList,
00212       const CIMClass& theClass)
00213    {
00214       // just ignore, since there nothing they can modify.
00215    }
00217    virtual void deleteInstance(
00218       const ProviderEnvironmentIFCRef& env,
00219       const String& ns,
00220       const CIMObjectPath& cop)
00221    {
00222       // just ignore deleteInstance.
00223    }
00224 #endif // #ifndef OW_DISABLE_INSTANCE_MANIPULATION
00225 #ifndef OW_DISABLE_ASSOCIATION_TRAVERSAL
00226    // Associator provider functions.
00227    virtual void getAssociatorProviderInfo(AssociatorProviderInfo &info)
00228    {
00229       info.addInstrumentedClass("CIM_NamespaceInManager");
00230    }
00231    class InstanceToObjectPathHandler : public CIMInstanceResultHandlerIFC
00232    {
00233    public:
00234       InstanceToObjectPathHandler(CIMObjectPathResultHandlerIFC& result_, const String& ns_)
00235       : result(result_)
00236       , ns(ns_)
00237       {}
00238       void doHandle(const CIMInstance& inst)
00239       {
00240          result.handle(CIMObjectPath(ns, inst));
00241       }
00242    private:
00243       CIMObjectPathResultHandlerIFC& result;
00244       String ns;
00245    };
00246    virtual void associatorNames(
00247       const ProviderEnvironmentIFCRef &env,
00248       CIMObjectPathResultHandlerIFC &result,
00249       const String &ns,
00250       const CIMObjectPath &objectName,
00251       const String &assocClass,
00252       const String &resultClass,
00253       const String &role,
00254       const String &resultRole)
00255    {
00256       OW_LOG_DEBUG(env->getLogger(COMPONENT_NAME), "In CIM_NamespaceInManagerInstProv::associatorNames");
00257       // This assert should only fail if someone created a subclass of
00258       // CIM_NamespaceInManager and didn't create a provider for it.
00259       OW_ASSERT(assocClass.equalsIgnoreCase("CIM_NamespaceInManager"));
00260       InstanceToObjectPathHandler handler(result, ns);
00261       associators(env, handler, ns, objectName, assocClass, resultClass, role, resultRole, E_EXCLUDE_QUALIFIERS, E_EXCLUDE_CLASS_ORIGIN, 0);
00262    }
00263    virtual void referenceNames(
00264       const ProviderEnvironmentIFCRef &env,
00265       CIMObjectPathResultHandlerIFC &result,
00266       const String &ns,
00267       const CIMObjectPath &objectName,
00268       const String &resultClass,
00269       const String &role)
00270    {
00271       OW_LOG_DEBUG(env->getLogger(COMPONENT_NAME), "In CIM_NamespaceInManagerInstProv::referenceNames");
00272       
00273       // This assert should only fail if someone created a subclass of
00274       // CIM_NamespaceInManager and didn't create a provider for it.
00275       OW_ASSERT(resultClass.equalsIgnoreCase("CIM_NamespaceInManager"));
00276       InstanceToObjectPathHandler handler(result, ns);
00277       references(env, handler, ns, objectName, resultClass, role, E_EXCLUDE_QUALIFIERS, E_EXCLUDE_CLASS_ORIGIN, 0);
00278    }
00279    class AssociatorFilter : public CIMInstanceResultHandlerIFC
00280    {
00281    public:
00282       AssociatorFilter(const CIMObjectPath& objectName_, CIMInstanceResultHandlerIFC& result_,     
00283          CIMOMHandleIFCRef hdl_,
00284          const String& ns_,
00285          EIncludeQualifiersFlag includeQualifiers_,
00286          EIncludeClassOriginFlag includeClassOrigin_,
00287          const StringArray* propertyList_)
00288       : objectName(objectName_)
00289       , result(result_)
00290       , hdl(hdl_)
00291       , ns(ns_)
00292       , includeQualifiers(includeQualifiers_)
00293       , includeClassOrigin(includeClassOrigin_)
00294       , propertyList(propertyList_)
00295       {}
00296       void doHandle(const CIMInstance& i)
00297       {
00298          CIMObjectPath op = i.getPropertyT("Antecedent").getValueT().toCIMObjectPath();
00299          if (op == objectName)
00300          {
00301             CIMObjectPath toGet = i.getPropertyT("Dependent").getValueT().toCIMObjectPath();
00302             CIMInstance assocInst = hdl->getInstance(ns, toGet, E_NOT_LOCAL_ONLY, E_INCLUDE_QUALIFIERS, E_INCLUDE_CLASS_ORIGIN, 0);
00303             assocInst.clone(E_NOT_LOCAL_ONLY, includeQualifiers, includeClassOrigin, propertyList);
00304             //CIMInstance assocInst = hdl->getInstance(ns, toGet, false, includeQualifiers, includeClassOrigin, propertyList);
00305             //assocInst.setKeys(toGet.getKeys());
00306             result.handle(assocInst);
00307             return;
00308          }
00309          op = i.getPropertyT("Dependent").getValueT().toCIMObjectPath();
00310          if (op == objectName)
00311          {
00312             CIMObjectPath toGet = i.getPropertyT("Antecedent").getValueT().toCIMObjectPath();
00313             CIMInstance assocInst = hdl->getInstance(ns, toGet, E_NOT_LOCAL_ONLY, E_INCLUDE_QUALIFIERS, E_INCLUDE_CLASS_ORIGIN, 0);
00314             assocInst.clone(E_NOT_LOCAL_ONLY, includeQualifiers, includeClassOrigin, propertyList);
00315             //CIMInstance assocInst = hdl->getInstance(ns, toGet, false, includeQualifiers, includeClassOrigin, propertyList);
00316             //assocInst.setKeys(toGet.getKeys());
00317             result.handle(assocInst);
00318          }
00319       }
00320    private:
00321       const CIMObjectPath& objectName;
00322       CIMInstanceResultHandlerIFC& result;
00323       CIMOMHandleIFCRef hdl;
00324       String ns;
00325       EIncludeQualifiersFlag includeQualifiers;
00326       EIncludeClassOriginFlag includeClassOrigin;
00327       const StringArray* propertyList;
00328    };
00329    virtual void associators(
00330       const ProviderEnvironmentIFCRef &env,
00331       CIMInstanceResultHandlerIFC &result,
00332       const String &ns,
00333       const CIMObjectPath &objectName,
00334       const String &assocClass,
00335       const String &resultClass,
00336       const String &role,
00337       const String &resultRole,
00338       EIncludeQualifiersFlag includeQualifiers,
00339       EIncludeClassOriginFlag includeClassOrigin,
00340       const StringArray *propertyList)
00341    {
00342       OW_LOG_DEBUG(env->getLogger(COMPONENT_NAME), "In CIM_NamespaceInManagerInstProv::associators");
00343       // This assert should only fail if someone created a subclass of
00344       // CIM_NamespaceInManager and didn't create a provider for it.
00345       OW_ASSERT(assocClass.equalsIgnoreCase("CIM_NamespaceInManager"));
00346       if (objectName.getClassName().equalsIgnoreCase("OpenWBEM_ObjectManager")
00347          || objectName.getClassName().equalsIgnoreCase("CIM_ObjectManager"))
00348       {
00349          if (!role.empty() && !role.equalsIgnoreCase("Antecedent"))
00350          {
00351             return;
00352          }
00353          if (!resultRole.empty() && !resultRole.equalsIgnoreCase("Dependent"))
00354          {
00355             return;
00356          }
00357       }
00358       else if (objectName.getClassName().equalsIgnoreCase("CIM_Namespace"))
00359       {
00360          if (!role.empty() && !role.equalsIgnoreCase("Dependent"))
00361          {
00362             return;
00363          }
00364          if (!resultRole.empty() && !resultRole.equalsIgnoreCase("Antecedent"))
00365          {
00366             return;
00367          }
00368       }
00369       CIMClass theClass = env->getCIMOMHandle()->getClass(ns, "CIM_NamespaceInManager");
00370       AssociatorFilter handler(objectName, result, env->getCIMOMHandle(), ns, includeQualifiers, includeClassOrigin, propertyList);
00371       enumInstances(env, ns, "CIM_NamespaceInManager", handler, E_NOT_LOCAL_ONLY, E_DEEP, E_INCLUDE_QUALIFIERS, E_INCLUDE_CLASS_ORIGIN, 0, theClass, theClass);
00372    }
00373    class ReferencesFilter : public CIMInstanceResultHandlerIFC
00374    {
00375    public:
00376       ReferencesFilter(const CIMObjectPath& objectName_, CIMInstanceResultHandlerIFC& result_)
00377       : objectName(objectName_)
00378       , result(result_)
00379       {}
00380       void doHandle(const CIMInstance& i)
00381       {
00382          CIMObjectPath op = i.getPropertyT("Antecedent").getValueT().toCIMObjectPath();
00383          if (op == objectName)
00384          {
00385             result.handle(i);
00386             return;
00387          }
00388          op = i.getPropertyT("Dependent").getValueT().toCIMObjectPath();
00389          if (op == objectName)
00390          {
00391             result.handle(i);
00392          }
00393       }
00394    private:
00395       const CIMObjectPath& objectName;
00396       CIMInstanceResultHandlerIFC& result;
00397    };
00398    virtual void references(
00399       const ProviderEnvironmentIFCRef &env,
00400       CIMInstanceResultHandlerIFC &result,
00401       const String &ns,
00402       const CIMObjectPath &objectName,
00403       const String &resultClass,
00404       const String &role,
00405       EIncludeQualifiersFlag includeQualifiers,
00406       EIncludeClassOriginFlag includeClassOrigin,
00407       const StringArray *propertyList)
00408    {
00409       OW_LOG_DEBUG(env->getLogger(COMPONENT_NAME), "In CIM_NamespaceInManagerInstProv::references");
00410       // This assert should only fail if someone created a subclass of
00411       // CIM_NamespaceInManager and didn't create a provider for it.
00412       OW_ASSERT(resultClass.equalsIgnoreCase("CIM_NamespaceInManager"));
00413       if (objectName.getClassName().equalsIgnoreCase("OpenWBEM_ObjectManager")
00414          || objectName.getClassName().equalsIgnoreCase("CIM_ObjectManager"))
00415       {
00416          if (!role.empty() && !role.equalsIgnoreCase("Antecedent"))
00417          {
00418             return;
00419          }
00420       }
00421       else if (objectName.getClassName().equalsIgnoreCase("CIM_Namespace"))
00422       {
00423          if (!role.empty() && !role.equalsIgnoreCase("Dependent"))
00424          {
00425             return;
00426          }
00427       }
00428       CIMClass theClass = env->getCIMOMHandle()->getClass(ns, "CIM_NamespaceInManager");
00429       ReferencesFilter handler(objectName, result);
00430       enumInstances(env, ns, "CIM_NamespaceInManager", handler, E_NOT_LOCAL_ONLY, E_DEEP, includeQualifiers, includeClassOrigin, propertyList, theClass, theClass);
00431    }
00432 #endif // #ifndef OW_DISABLE_ASSOCIATION_TRAVERSAL
00433 };
00434 } // end namespace OW_NAMESPACE
00435 
00436 OW_PROVIDERFACTORY(OpenWBEM::CIM_NamespaceInManagerInstProv, owprovinstCIM_NamespaceInManager)
00437 

Generated on Thu Feb 9 08:48:09 2006 for openwbem by  doxygen 1.4.6