00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
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
00082 inst.setProperty("ClassInfo", CIMValue(0));
00083
00084
00085
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
00132 sccn = "CIM_System";
00133 sn = "unknown";
00134 omccn = "CIM_ObjectManager";
00135 omn = "OpenWBEM";
00136 }
00137 else
00138 {
00139
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
00190
00191
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
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 }
00226
00227 OW_PROVIDERFACTORY(OW_NAMESPACE::CIM_NamespaceInstProv, owprovinstCIM_Namespace)
00228