OW_provinstCIM_Namespace.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_CppSimpleInstanceProviderIFC.hpp"
00037 #include "OW_CIMClass.hpp"
00038 #include "OW_CIMInstance.hpp"
00039 #include "OW_CIMException.hpp"
00040 #include "OW_CIMValue.hpp"
00041 #include "OW_CIMProperty.hpp"
00042 #include "OW_CIMObjectPath.hpp"
00043 #include "OW_CIMObjectPathEnumeration.hpp"
00044 #include "OW_OperationContext.hpp"
00045 #include "OW_ResultHandlerIFC.hpp"
00046 #include "OW_Logger.hpp"
00047 #include "OW_CIMOMHandleIFC.hpp"
00048 #include "OW_RepositoryIFC.hpp"
00049 
00050 namespace OW_NAMESPACE
00051 {
00052 
00053 namespace
00054 {
00055    const String COMPONENT_NAME("ow.provider.CIM_Namespace");
00056 }
00057 
00058 using namespace WBEMFlags;
00059    namespace
00060    {
00061       class NSHandlerInst : public StringResultHandlerIFC
00062       {
00063       public:
00064          NSHandlerInst(CIMInstanceResultHandlerIFC& result_,
00065             const CIMClass& cls,
00066             const String& sccn, const String& sn,
00067             const String& omccn, const String& omn)
00068          : result(result_)
00069          , inst(cls.newInstance())
00070          {
00071             inst.setProperty("SystemCreationClassName", CIMValue(sccn));
00072             inst.setProperty("SystemName", CIMValue(sn));
00073             inst.setProperty("ObjectManagerCreationClassName", CIMValue(omccn));
00074             inst.setProperty("ObjectManagerName", CIMValue(omn));
00075             inst.setProperty("CreationClassName", CIMValue("CIM_Namespace"));
00076          }
00077    
00078          void doHandle(const String& s)
00079          {
00080             inst.setProperty("Name", CIMValue(s));
00081             // This property is Required
00082             inst.setProperty("ClassInfo", CIMValue(0));
00083             //newInst.setProperty("Caption", CIMValue(/* TODO: Put the value here */));
00084             //newInst.setProperty("Description", CIMValue(/* TODO: Put the value here */));
00085             //newInst.setProperty("ElementName", CIMValue(/* TODO: Put the value here */));
00086             result.handle(inst);
00087          }
00088       private:
00089          CIMInstanceResultHandlerIFC& result;
00090          CIMInstance inst;
00091       };
00092       class DeleteHandler : public StringResultHandlerIFC
00093       {
00094       public:
00095          void doHandle(const String&)
00096          {
00097             OW_THROWCIMMSG(CIMException::FAILED, "Cannot delete namespace because it is not empty");
00098          }
00099       };
00100    }
00101 class CIM_NamespaceInstProv : public CppSimpleInstanceProviderIFC
00102 {
00103 public:
00105    virtual ~CIM_NamespaceInstProv()
00106    {
00107    }
00109    virtual void getInstanceProviderInfo(InstanceProviderInfo& info)
00110    {
00111       info.addInstrumentedClass("CIM_Namespace");
00112    }
00115    virtual void doSimpleEnumInstances(
00116       const ProviderEnvironmentIFCRef& env,
00117       const String& ns,
00118       const CIMClass& cimClass,
00119       CIMInstanceResultHandlerIFC& result,
00120       EPropertiesFlag propertiesFlag)
00121    {
00122       OW_LOG_DEBUG(env->getLogger(COMPONENT_NAME), "In CIM_NamespaceInstProv::enumInstances");
00123       CIMOMHandleIFCRef hdl = env->getCIMOMHandle();
00124       CIMObjectPathEnumeration e = hdl->enumInstanceNamesE(ns, "CIM_ObjectManager");
00125       String sccn;
00126       String sn;
00127       String omccn;
00128       String omn;
00129       if (e.numberOfElements() < 1)
00130       {
00131          // no CIM_ObjectManager... we'll just make these up then.
00132          sccn = "CIM_System";
00133          sn = "unknown";
00134          omccn = "CIM_ObjectManager";
00135          omn = "OpenWBEM";
00136       }
00137       else
00138       {
00139          // assume there'll only be one OpenWBEM_ObjectManager.
00140          CIMObjectPath objectManager = e.nextElement();
00141          sccn = objectManager.getKeyT("SystemCreationClassName").getValueT().toString();
00142          sn = objectManager.getKeyT("SystemName").getValueT().toString();
00143          omccn = objectManager.getKeyT("CreationClassName").getValueT().toString();
00144          omn = objectManager.getKeyT("Name").getValueT().toString();
00145       }
00146       
00147       NSHandlerInst nshandler(result, cimClass, sccn, sn, omccn, omn);
00148       RepositoryIFCRef rep = env->getRepository();
00149       rep->enumNameSpace(nshandler, env->getOperationContext());
00150    }
00151 #if !defined(OW_DISABLE_INSTANCE_MANIPULATION)
00152 
00153    virtual CIMObjectPath createInstance(
00154       const ProviderEnvironmentIFCRef& env,
00155       const String& ns,
00156       const CIMInstance& cimInstance )
00157    {
00158       OW_LOG_DEBUG(env->getLogger(COMPONENT_NAME), "In CIM_NamespaceInstProv::createInstance");
00159 #if !defined(OW_DISABLE_NAMESPACE_MANIPULATION)
00160       try
00161       {
00162          String name = cimInstance.getPropertyT("Name").getValueT().toString();
00163          RepositoryIFCRef rep = env->getRepository();
00164          rep->createNameSpace(name, env->getOperationContext());
00165       }
00166       catch (const CIMException& e)
00167       {
00168          throw;
00169       }
00170       catch (const Exception& e)
00171       {
00172          OW_THROWCIM_SUBEX(CIMException::INVALID_PARAMETER, e);
00173       }
00174 #else
00175       OW_THROWCIMMSG(CIMException::FAILED, "namespace creation not supported");
00176 #endif
00177       return CIMObjectPath(ns, cimInstance);
00178    }
00180    virtual void modifyInstance(
00181       const ProviderEnvironmentIFCRef& env,
00182       const String& ns,
00183       const CIMInstance& modifiedInstance,
00184       const CIMInstance& previousInstance,
00185       EIncludeQualifiersFlag includeQualifiers,
00186       const StringArray* propertyList,
00187       const CIMClass& theClass)
00188    {
00189       // This is just a no-op since we don't really care about any properties
00190       // other than the keys (which can't change.)
00191       //OW_THROWCIMMSG(CIMException::FAILED, "Provider does not support modifyInstance");
00192    }
00194    virtual void deleteInstance(
00195       const ProviderEnvironmentIFCRef& env,
00196       const String& ns,
00197       const CIMObjectPath& cop)
00198    {
00199       OW_LOG_DEBUG(env->getLogger(COMPONENT_NAME), "In CIM_NamespaceInstProv::createInstance");
00200 #if !defined(OW_DISABLE_NAMESPACE_MANIPULATION)
00201       try
00202       {
00203          String name = cop.getKeyT("Name").getValueT().toString();
00204          RepositoryIFCRef rep = env->getRepository();
00205          // The client can't delete a non-empty namespace.  If we find any class names, we'll throw an exception
00206          DeleteHandler handler;
00207          rep->enumClassNames(name,"", handler, E_SHALLOW, env->getOperationContext());
00208          rep->deleteNameSpace(name, env->getOperationContext());
00209       }
00210       catch (const CIMException& e)
00211       {
00212          throw;
00213       }
00214       catch (const Exception& e)
00215       {
00216          OW_THROWCIM_SUBEX(CIMException::FAILED, e);
00217       }
00218 #else
00219       OW_THROWCIMMSG(CIMException::FAILED, "namespace creation not supported");
00220 #endif
00221    }
00222 #endif // #ifndef OW_DISABLE_INSTANCE_MANIPULATION
00223 };
00224 
00225 } // end namespace OW_NAMESPACE
00226 
00227 OW_PROVIDERFACTORY(OW_NAMESPACE::CIM_NamespaceInstProv, owprovinstCIM_Namespace)
00228 

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