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
00036 #include "OW_config.h"
00037 #include "OW_XMLExecute.hpp"
00038 #include "OW_Format.hpp"
00039 #include "OW_XMLClass.hpp"
00040 #include "OW_CIMXMLParser.hpp"
00041 #include "OW_XMLEscape.hpp"
00042 #include "OW_Assertion.hpp"
00043 #include "OW_CIMErrorException.hpp"
00044 #include "OW_CIMMethod.hpp"
00045 #include "OW_CIMParameter.hpp"
00046 #include "OW_CIMValue.hpp"
00047 #include "OW_CIMNameSpace.hpp"
00048 #include "OW_CIMProperty.hpp"
00049 #include "OW_TempFileStream.hpp"
00050 #include "OW_CIMClass.hpp"
00051 #include "OW_CIMFeatures.hpp"
00052 #include "OW_XMLCIMFactory.hpp"
00053 #include "OW_CIMtoXML.hpp"
00054 #include "OW_CIMParamValue.hpp"
00055 #include "OW_CIMObjectPath.hpp"
00056 #include "OW_CIMInstance.hpp"
00057 #include "OW_CIMQualifierType.hpp"
00058 #include "OW_CIMQualifier.hpp"
00059 #include "OW_SocketUtils.hpp"
00060 #include "OW_SocketException.hpp"
00061 #include "OW_Logger.hpp"
00062 #include "OW_OperationContext.hpp"
00063 #include "OW_ExceptionIds.hpp"
00064 #include "OW_ResultHandlerIFC.hpp"
00065 #include "OW_ServiceIFCNames.hpp"
00066 #include "OW_ConfigOpts.hpp"
00067
00068 #include <algorithm>
00069
00070 #define OW_LOGDEBUG(msg) OW_LOG_DEBUG(this->getEnvironment()->getLogger(COMPONENT_NAME), msg)
00071 #define OW_LOGINFO(msg) OW_LOG_INFO(this->getEnvironment()->getLogger(COMPONENT_NAME), msg)
00072 #define OW_LOGERROR(msg) OW_LOG_ERROR(this->getEnvironment()->getLogger(COMPONENT_NAME), msg)
00073 #define OW_LOGFATALERROR(msg) OW_LOG_FATAL_ERROR(this->getEnvironment()->getLogger(COMPONENT_NAME), msg)
00074
00075 namespace OW_NAMESPACE
00076 {
00077
00078 namespace
00079 {
00080 const String COMPONENT_NAME("ow.requesthandler.cimxml");
00081 }
00082
00083 OW_DECLARE_EXCEPTION(BadStream)
00084 OW_DEFINE_EXCEPTION_WITH_ID(BadStream)
00085 using std::ostream;
00086 using namespace WBEMFlags;
00087
00088 template<typename T> inline static void checkStream(T& str)
00089 {
00090 if (!str.good())
00091 {
00092 OW_THROW(BadStreamException, "The stream is bad");
00093 }
00094 }
00095 XMLExecute::FuncEntry XMLExecute::g_funcs[] =
00096 {
00097
00098 #ifndef OW_DISABLE_ASSOCIATION_TRAVERSAL
00099 { "associatornames", &XMLExecute::associatorNames },
00100 { "associators", &XMLExecute::associators },
00101 #endif
00102 #ifndef OW_DISABLE_SCHEMA_MANIPULATION
00103 { "createclass", &XMLExecute::createClass },
00104 #endif
00105 #ifndef OW_DISABLE_INSTANCE_MANIPULATION
00106 { "createinstance", &XMLExecute::createInstance },
00107 #endif
00108 #ifndef OW_DISABLE_SCHEMA_MANIPULATION
00109 { "deleteclass", &XMLExecute::deleteClass },
00110 #endif
00111 #ifndef OW_DISABLE_INSTANCE_MANIPULATION
00112 { "deleteinstance", &XMLExecute::deleteInstance },
00113 #endif
00114 #ifndef OW_DISABLE_QUALIFIER_DECLARATION
00115 { "deletequalifier", &XMLExecute::deleteQualifier },
00116 #endif
00117 { "enumerateclasses", &XMLExecute::enumerateClasses },
00118 { "enumerateclassnames", &XMLExecute::enumerateClassNames },
00119 { "enumerateinstancenames", &XMLExecute::enumerateInstanceNames },
00120 { "enumerateinstances", &XMLExecute::enumerateInstances },
00121 #ifndef OW_DISABLE_QUALIFIER_DECLARATION
00122 { "enumeratequalifiers", &XMLExecute::enumerateQualifiers },
00123 #endif
00124 { "execquery", &XMLExecute::execQuery },
00125 { "getclass", &XMLExecute::getClass },
00126 { "getinstance", &XMLExecute::getInstance },
00127 #if !defined(OW_DISABLE_PROPERTY_OPERATIONS)
00128 { "getproperty", &XMLExecute::getProperty },
00129 #endif // #if !defined(OW_DISABLE_PROPERTY_OPERATIONS)
00130 { "getqualifier", &XMLExecute::getQualifier },
00131 #ifndef OW_DISABLE_SCHEMA_MANIPULATION
00132 { "modifyclass", &XMLExecute::modifyClass },
00133 #endif
00134 #ifndef OW_DISABLE_INSTANCE_MANIPULATION
00135 { "modifyinstance", &XMLExecute::modifyInstance },
00136 #endif
00137 #ifndef OW_DISABLE_ASSOCIATION_TRAVERSAL
00138 { "referencenames", &XMLExecute::referenceNames },
00139 { "references", &XMLExecute::references },
00140 #endif
00141 #ifndef OW_DISABLE_INSTANCE_MANIPULATION
00142 #if !defined(OW_DISABLE_PROPERTY_OPERATIONS)
00143 { "setproperty", &XMLExecute::setProperty },
00144 #endif // #if !defined(OW_DISABLE_PROPERTY_OPERATIONS)
00145 #endif
00146 #ifndef OW_DISABLE_QUALIFIER_DECLARATION
00147 { "setqualifier", &XMLExecute::setQualifier },
00148 #endif
00149 { "garbage", 0 }
00150 };
00151 XMLExecute::FuncEntry* XMLExecute::g_funcsEnd = &XMLExecute::g_funcs[0] +
00152 (sizeof(XMLExecute::g_funcs)/sizeof(*XMLExecute::g_funcs)) - 1;
00154 bool
00155 XMLExecute::funcEntryCompare(const XMLExecute::FuncEntry& f1,
00156 const XMLExecute::FuncEntry& f2)
00157 {
00158 return (strcmp(f1.name, f2.name) < 0);
00159 }
00161 XMLExecute::XMLExecute()
00162 : RequestHandlerIFCXML(),
00163 m_ostrEntity(NULL),
00164 m_ostrError(NULL),
00165 m_isIntrinsic(false),
00166 m_functionName(),
00167 m_commMechPath(CIMNULL),
00168 m_hostedAccessPointPath(CIMNULL),
00169 m_commMechForManager(CIMNULL)
00170 {
00171 }
00173 XMLExecute::~XMLExecute()
00174 {
00175 }
00177 String
00178 XMLExecute::getName() const
00179 {
00180 return ServiceIFCNames::XMLExecute;
00181 }
00183 StringArray
00184 XMLExecute::getDependencies() const
00185 {
00186 StringArray rv;
00187 rv.push_back(ServiceIFCNames::CIMServer);
00188 return rv;
00189 }
00190
00192
00193 int
00194 XMLExecute::executeXML(CIMXMLParser& parser, ostream* ostrEntity,
00195 ostream* ostrError, OperationContext& context)
00196 {
00197 clearError();
00198 m_ostrEntity = ostrEntity;
00199 m_ostrError = ostrError;
00200 m_isIntrinsic = false;
00201 String messageId = parser.mustGetAttribute(CIMXMLParser::A_ID);
00202 parser.getChild();
00203 if (!parser)
00204 {
00205 OW_THROW(CIMErrorException, CIMErrorException::request_not_loosely_valid);
00206 }
00207 makeXMLHeader(messageId, *m_ostrEntity);
00208 if (parser.getToken() == CIMXMLParser::E_MULTIREQ)
00209 {
00210 (*m_ostrEntity) << "<MULTIRSP>";
00211 parser.getChild();
00212 while (parser.tokenIsId(CIMXMLParser::E_SIMPLEREQ))
00213 {
00214 TempFileStream ostrEnt, ostrErr(500);
00215 processSimpleReq(parser, ostrEnt, ostrErr, context);
00216 if (hasError())
00217 {
00218 (*m_ostrEntity) << ostrErr.rdbuf();
00219 clearError();
00220 }
00221 else
00222 {
00223 (*m_ostrEntity) << ostrEnt.rdbuf();
00224 }
00225 parser.getNextTag();
00226 parser.mustGetEndTag();
00227 }
00228 (*m_ostrEntity) << "</MULTIRSP>";
00229 }
00230 else if (parser.getToken() == CIMXMLParser::E_SIMPLEREQ)
00231 {
00232 makeXMLHeader(messageId, *m_ostrError);
00233 processSimpleReq(parser, *m_ostrEntity, *m_ostrError, context);
00234 }
00235 else
00236 {
00237 OW_THROWCIMMSG(CIMException::FAILED,
00238 "No <SIMPLEREQ> or <MULTIREQ> tag");
00239 }
00240 if (!hasError())
00241 {
00242 (*m_ostrEntity) << "</MESSAGE></CIM>\r\n";
00243 }
00244 return 0;
00245 }
00247 void
00248 XMLExecute::executeIntrinsic(ostream& ostr,
00249 CIMXMLParser& parser, CIMOMHandleIFC& hdl,
00250 const String& ns)
00251 {
00252 String functionNameLC = m_functionName;
00253 functionNameLC.toLowerCase();
00254 OW_LOGDEBUG(Format("Got function name. calling function %1",
00255 functionNameLC));
00256 FuncEntry fe = { 0, 0 };
00257 fe.name = functionNameLC.c_str();
00258 FuncEntry* i = std::lower_bound(g_funcs, g_funcsEnd, fe, funcEntryCompare);
00259 if (i == g_funcsEnd || strcmp((*i).name, fe.name) != 0)
00260 {
00261
00262 OW_THROWCIM(CIMException::NOT_SUPPORTED);
00263 }
00264 else
00265 {
00266 ostr << "<IMETHODRESPONSE NAME=\"" << m_functionName <<
00267 "\">";
00268
00269 (this->*((*i).func))(ostr, parser, ns, hdl);
00270 ostr << "</IMETHODRESPONSE>";
00271 }
00272 }
00274 void
00275 XMLExecute::executeExtrinsic(ostream& ostr, CIMXMLParser& parser,
00276 CIMOMHandleIFC& lch)
00277 {
00278 ostr << "<METHODRESPONSE NAME=\"" << m_functionName <<
00279 "\">";
00280 doInvokeMethod(ostr, parser, m_functionName, lch);
00281 ostr << "</METHODRESPONSE>";
00282 }
00284 void
00285 XMLExecute::doInvokeMethod(ostream& ostr, CIMXMLParser& parser,
00286 const String& methodName, CIMOMHandleIFC& hdl)
00287 {
00288 CIMParamValueArray inParams;
00289 CIMParamValueArray outParams;
00290 CIMObjectPath path = XMLCIMFactory::createObjectPath(parser);
00291
00292 getParameters(parser, inParams);
00293 CIMValue cv = hdl.invokeMethod(path.getNameSpace(), path, methodName,
00294 inParams, outParams);
00295 if (cv)
00296 {
00297 ostr << "<RETURNVALUE PARAMTYPE=\"";
00298 CIMtoXML(cv.getCIMDataType(), ostr);
00299 ostr << "\" ";
00300 if (cv.getCIMDataType().isEmbeddedObjectType())
00301 {
00302 ostr << "EmbeddedObject=\"object\" ";
00303 }
00304 ostr << '>';
00305 CIMtoXML(cv, ostr);
00306 ostr << "</RETURNVALUE>";
00307 }
00308 for (size_t i=0; i < outParams.size(); i++)
00309 {
00310 CIMParamValueToXML(outParams[i], ostr);
00311 }
00312 }
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325 void
00326 XMLExecute::getParameters(CIMXMLParser& parser,
00327 CIMParamValueArray& params)
00328 {
00329
00330
00331
00332 while (parser.tokenIsId(CIMXMLParser::E_PARAMVALUE))
00333 {
00334 String parameterName = parser.mustGetAttribute(CIMXMLParser::A_NAME);
00335 String parameterType = parser.getAttribute(CIMXMLParser::A_PARAMTYPE);
00336 if (parameterType.empty())
00337 {
00338 parameterType = "string";
00339 }
00340
00341 XMLCIMFactory::EEmbeddedObjectFlag embeddedObjectType = XMLCIMFactory::getEmbeddedObjectType(parser);
00342
00343 parser.getNextTag();
00344 int token = parser.getToken();
00345 if (token != CIMXMLParser::E_VALUE
00346 && token != CIMXMLParser::E_VALUE_REFERENCE
00347 && token != CIMXMLParser::E_VALUE_ARRAY
00348 && token != CIMXMLParser::E_VALUE_REFARRAY
00349 )
00350 {
00351 params.push_back(CIMParamValue(parameterName,
00352 CIMValue(CIMNULL)));
00353 }
00354 else
00355 {
00356 params.push_back(CIMParamValue(parameterName, XMLCIMFactory::createValue(parser, parameterType, embeddedObjectType)));
00357 }
00358 parser.mustGetEndTag();
00359 }
00360 }
00362 namespace
00363 {
00364 class CIMObjectPathXMLOutputter : public CIMObjectPathResultHandlerIFC
00365 {
00366 public:
00367 CIMObjectPathXMLOutputter(ostream& ostr_, const String& host, const String& ns)
00368 : ostr(ostr_)
00369 , m_host(host)
00370 , m_namespace(ns)
00371 {}
00372 protected:
00373 virtual void doHandle(const CIMObjectPath &cop_)
00374 {
00375 ostr << "<OBJECTPATH>";
00376
00377 CIMObjectPath cop(cop_);
00378 if (cop.getFullNameSpace().isLocal())
00379 {
00380 try
00381 {
00382 cop.setHost(m_host);
00383 }
00384 catch (const SocketException& e)
00385 {
00386 }
00387 }
00388 if (cop.isClassPath())
00389 {
00390 CIMClassPathtoXML(cop, ostr);
00391 }
00392 else
00393 {
00394
00395 if (cop.getNameSpace().empty())
00396 {
00397 cop.setNameSpace(m_namespace);
00398 }
00399 CIMInstancePathtoXML(cop, ostr);
00400 }
00401 ostr << "</OBJECTPATH>";
00402 checkStream(ostr);
00403 }
00404 private:
00405 ostream& ostr;
00406 String m_host;
00407 String m_namespace;
00408 };
00409 }
00411 namespace
00412 {
00413 struct param
00414 {
00415 enum Type
00416 {
00417 CLASSNAME,
00418 BOOLEAN,
00419 STRINGARRAY,
00420 INSTANCENAME,
00421 NAMEDINSTANCE,
00422 STRING,
00423 OBJECTNAME,
00424 PROPERTYVALUE
00425 };
00426 String name;
00427 bool optional;
00428 Type type;
00429 CIMValue defaultVal;
00430 bool isSet;
00431 CIMValue val;
00432 param(const String& name_,
00433 bool optional_ = true,
00434 Type type_ = STRING,
00435 const CIMValue& defaultVal_ = CIMValue(CIMNULL))
00436 : name(name_)
00437 , optional(optional_)
00438 , type(type_)
00439 , defaultVal(defaultVal_)
00440 , isSet(false)
00441 , val(CIMNULL)
00442 {}
00443 };
00444 struct name_comparer
00445 {
00446 name_comparer(const String& s_)
00447 : s(s_)
00448 {}
00449 bool operator()(const param& p)
00450 {
00451 return p.name.equalsIgnoreCase(s);
00452 }
00453 String s;
00454 };
00456 void getParameterValues(CIMXMLParser& parser,
00457 Array<param>& params)
00458 {
00459
00460 while (parser.tokenIsId(CIMXMLParser::E_IPARAMVALUE))
00461 {
00462 String name = parser.mustGetAttribute(CIMXMLParser::A_NAME);
00463 Array<param>::iterator i = std::find_if (params.begin(), params.end(),
00464 name_comparer(name));
00465 if (i == params.end())
00466 {
00467 OW_THROWCIMMSG(CIMException::INVALID_PARAMETER,
00468 Format("Parameter %1 is not a valid parameter", name).c_str());
00469 }
00470
00471 parser.getNextTag();
00472 if (parser.tokenIsId(CIMXMLParser::E_IPARAMVALUE))
00473 {
00474
00475
00476 i->isSet = true;
00477
00478 }
00479 else
00480 {
00481 switch (i->type)
00482 {
00483 case param::CLASSNAME:
00484 if (!parser.tokenIsId(CIMXMLParser::E_CLASSNAME))
00485 {
00486 OW_THROWCIMMSG(CIMException::INVALID_PARAMETER,
00487 Format("Parameter %1 is the wrong type. Expected <CLASSNAME> tag.",
00488 i->name).c_str());
00489 }
00490 i->isSet = true;
00491 i->val = CIMValue(XMLCIMFactory::createObjectPath(parser).getClassName());
00492 break;
00493 case param::BOOLEAN:
00494 if (!parser.tokenIsId(CIMXMLParser::E_VALUE))
00495 {
00496 OW_THROWCIMMSG(CIMException::INVALID_PARAMETER,
00497 Format("Parameter %1 is the wrong type. Expected <VALUE> tag.",
00498 i->name).c_str());
00499 }
00500 i->isSet = true;
00501 i->val = XMLCIMFactory::createValue(parser, "boolean", XMLCIMFactory::E_VALUE_NOT_EMBEDDED_OBJECT);
00502 break;
00503 case param::STRINGARRAY:
00504 if (!parser.tokenIsId(CIMXMLParser::E_VALUE_ARRAY))
00505 {
00506 OW_THROWCIMMSG(CIMException::INVALID_PARAMETER,
00507 Format("Parameter %1 is the wrong type. Expected <VALUE.ARRAY> tag.",
00508 i->name).c_str());
00509 }
00510 i->isSet = true;
00511 i->val = XMLCIMFactory::createValue(parser, "string", XMLCIMFactory::E_VALUE_NOT_EMBEDDED_OBJECT);
00512 break;
00513 case param::INSTANCENAME:
00514 if (!parser.tokenIsId(CIMXMLParser::E_INSTANCENAME))
00515 {
00516 OW_THROWCIMMSG(CIMException::INVALID_PARAMETER,
00517 Format("Parameter %1 is the wrong type. Expected <INSTANCENAME> tag.",
00518 i->name).c_str());
00519 }
00520 i->isSet = true;
00521 i->val = CIMValue(XMLCIMFactory::createObjectPath(parser));
00522 break;
00523 case param::NAMEDINSTANCE:
00524 {
00525 if (!parser.tokenIsId(CIMXMLParser::E_VALUE_NAMEDINSTANCE))
00526 {
00527 OW_THROWCIMMSG(CIMException::INVALID_PARAMETER,
00528 Format("Parameter %1 is the wrong type. Expected <VALUE.NAMEDINSTANCE> tag. %2",
00529 i->name, parser).c_str());
00530 }
00531 i->isSet = true;
00532 parser.mustGetChildId(CIMXMLParser::E_INSTANCENAME);
00533 CIMObjectPath ipath(XMLCIMFactory::createObjectPath(parser));
00534 CIMInstance inst(XMLCIMFactory::createInstance(parser));
00535 parser.mustGetEndTag();
00536 inst.setKeys(ipath.getKeys());
00537 i->val = CIMValue(inst);
00538 break;
00539 }
00540 case param::STRING:
00541 if (!parser.tokenIsId(CIMXMLParser::E_VALUE))
00542 {
00543 OW_THROWCIMMSG(CIMException::INVALID_PARAMETER,
00544 Format("Parameter %1 is the wrong type. Expected <VALUE> tag.",
00545 i->name).c_str());
00546 }
00547 i->isSet = true;
00548 i->val = XMLCIMFactory::createValue(parser, "string", XMLCIMFactory::E_VALUE_NOT_EMBEDDED_OBJECT);
00549 break;
00550 case param::OBJECTNAME:
00551 if (!parser.tokenIsId(CIMXMLParser::E_INSTANCENAME)
00552 && !parser.tokenIsId(CIMXMLParser::E_CLASSNAME))
00553 {
00554 OW_THROWCIMMSG(CIMException::INVALID_PARAMETER,
00555 Format("Parameter %1 is the wrong type. Expected <INSTANCENAME> or <CLASSNAME> tag.",
00556 i->name).c_str());
00557 }
00558 i->isSet = true;
00559 i->val = CIMValue(XMLCIMFactory::createObjectPath(parser));
00560 break;
00561 case param::PROPERTYVALUE:
00562 if (!parser.tokenIsId(CIMXMLParser::E_VALUE)
00563 && !parser.tokenIsId(CIMXMLParser::E_VALUE_ARRAY)
00564 && !parser.tokenIsId(CIMXMLParser::E_VALUE_REFERENCE))
00565 {
00566 OW_THROWCIMMSG(CIMException::INVALID_PARAMETER,
00567 Format("Parameter %1 is the wrong type. Expected <VALUE> or <VALUE.ARRAY> or <VALUE.REFERENCE> tag.",
00568 i->name).c_str());
00569 }
00570 i->isSet = true;
00571 i->val = XMLCIMFactory::createValue(parser, "string", XMLCIMFactory::E_VALUE_NOT_EMBEDDED_OBJECT);
00572 break;
00573 default:
00574 OW_ASSERT(0);
00575 break;
00576 }
00577 }
00578 parser.mustGetEndTag();
00579 }
00580
00581
00582 for (size_t i = 0; i < params.size(); ++i)
00583 {
00584 if (params[i].optional == false && params[i].isSet == false)
00585 {
00586 OW_THROWCIMMSG(CIMException::INVALID_PARAMETER,
00587 Format("Non-optional parameter %1 was not given",
00588 params[i].name).c_str());
00589 }
00590 if (params[i].isSet == false)
00591 {
00592 params[i].val = params[i].defaultVal;
00593 }
00594
00595 if (!params[i].val)
00596 {
00597 switch (params[i].type)
00598 {
00599 case param::BOOLEAN:
00600 params[i].val = CIMValue(false);
00601 break;
00602 case param::STRING:
00603 case param::CLASSNAME:
00604 params[i].val = CIMValue("");
00605 break;
00606
00607 default:
00608 break;
00609 }
00610 }
00611 }
00612 }
00613 }
00614 #ifndef OW_DISABLE_ASSOCIATION_TRAVERSAL
00615
00616 void
00617 XMLExecute::associatorNames(ostream& ostr, CIMXMLParser& parser,
00618 const String& ns, CIMOMHandleIFC& hdl)
00619 {
00620 Array<param> params;
00621 params.push_back(param(CIMXMLParser::P_ObjectName, false, param::OBJECTNAME));
00622 params.push_back(param(CIMXMLParser::P_AssocClass, true, param::CLASSNAME));
00623 params.push_back(param(CIMXMLParser::P_ResultClass, true, param::CLASSNAME));
00624 params.push_back(param(CIMXMLParser::P_Role, true, param::STRING, CIMValue("")));
00625 params.push_back(param(CIMXMLParser::P_ResultRole, true, param::STRING, CIMValue("")));
00626 getParameterValues(parser, params);
00627 CIMObjectPath objectName = params[0].val.toCIMObjectPath();
00628 String assocClass;
00629 if (params[1].isSet)
00630 {
00631 assocClass = params[1].val.toString();
00632 }
00633 String resultClass;
00634 if (params[2].isSet)
00635 {
00636 resultClass = params[2].val.toString();
00637 }
00638 ostr << "<IRETURNVALUE>";
00639 CIMObjectPathXMLOutputter handler(ostr, getHost(), ns);
00640 hdl.associatorNames(ns, objectName, handler, assocClass, resultClass,
00641 params[3].val.toString(), params[4].val.toString());
00642 ostr << "</IRETURNVALUE>";
00643 }
00645 namespace
00646 {
00647 class AssocCIMInstanceXMLOutputter : public CIMInstanceResultHandlerIFC
00648 {
00649 public:
00650 AssocCIMInstanceXMLOutputter(
00651 std::ostream& ostr_,
00652 const String& ns_,
00653 const String& host_)
00654 : ostr(ostr_)
00655 , ns(ns_)
00656 , m_host(host_)
00657 {}
00658 protected:
00659 virtual void doHandle(const CIMInstance &ci)
00660 {
00661 ostr << "<VALUE.OBJECTWITHPATH>";
00662
00663
00664 String cins = ci.getNameSpace();
00665 if (cins.empty())
00666 {
00667 cins = ns;
00668 }
00669 CIMObjectPath cop( cins, ci );
00670
00671 cop.setHost(m_host);
00672 CIMInstancePathAndInstancetoXML(ci, ostr, cop);
00673 ostr << "</VALUE.OBJECTWITHPATH>\n";
00674 checkStream(ostr);
00675
00676 }
00677 std::ostream& ostr;
00678 String ns;
00679 String m_host;
00680 };
00681 class AssocCIMClassXMLOutputter : public CIMClassResultHandlerIFC
00682 {
00683 public:
00684 AssocCIMClassXMLOutputter(
00685 std::ostream& ostr_,
00686 const String& ns_)
00687 : ostr(ostr_)
00688 , ns(ns_)
00689 {}
00690 protected:
00691 virtual void doHandle(const CIMClass &cc)
00692 {
00693 ostr << "<VALUE.OBJECTWITHPATH>";
00694 CIMObjectPath cop(cc.getName(), ns);
00695 CIMClassPathtoXML(cop,ostr);
00696 CIMtoXML(cc, ostr);
00697 ostr << "</VALUE.OBJECTWITHPATH>\n";
00698 checkStream(ostr);
00699
00700 }
00701 std::ostream& ostr;
00702 const String& ns;
00703 };
00704 }
00706 void XMLExecute::associators(ostream& ostr,
00707 CIMXMLParser& parser, const String& ns, CIMOMHandleIFC& hdl)
00708 {
00709 Array<param> params;
00710 params.push_back(param(CIMXMLParser::P_ObjectName, false, param::OBJECTNAME));
00711 params.push_back(param(CIMXMLParser::P_AssocClass, true, param::CLASSNAME));
00712 params.push_back(param(CIMXMLParser::P_ResultClass, true, param::CLASSNAME));
00713 params.push_back(param(CIMXMLParser::P_Role, true, param::STRING, CIMValue("")));
00714 params.push_back(param(CIMXMLParser::P_ResultRole, true, param::STRING, CIMValue("")));
00715 params.push_back(param(CIMXMLParser::P_IncludeQualifiers, true, param::BOOLEAN, CIMValue(false)));
00716 params.push_back(param(CIMXMLParser::P_IncludeClassOrigin, true, param::BOOLEAN, CIMValue(false)));
00717 params.push_back(param(CIMXMLParser::P_PropertyList, true, param::STRINGARRAY, CIMValue(CIMNULL)));
00718 getParameterValues(parser, params);
00719 CIMObjectPath objectName = params[0].val.toCIMObjectPath();
00720 String assocClass;
00721 if (params[1].isSet)
00722 {
00723 assocClass = params[1].val.toString();
00724 }
00725 String resultClass;
00726 if (params[2].isSet)
00727 {
00728 resultClass = params[2].val.toString();
00729 }
00730 StringArray propertyList;
00731 StringArray* pPropList = 0;
00732 if (params[7].isSet)
00733 {
00734 propertyList = params[7].val.toStringArray();
00735 pPropList = &propertyList;
00736 }
00737
00738 bool includeQualifiers = params[5].val.toBool();
00739 bool includeClassOrigin = params[6].val.toBool();
00740 String role = params[3].val.toString();
00741 String resultRole = params[4].val.toString();
00742 ostr << "<IRETURNVALUE>";
00743 if (objectName.isClassPath())
00744 {
00745
00746 AssocCIMClassXMLOutputter handler(ostr, ns);
00747 hdl.associatorsClasses(ns, objectName, handler,
00748 assocClass, resultClass, role, resultRole,
00749 includeQualifiers ? E_INCLUDE_QUALIFIERS : E_EXCLUDE_QUALIFIERS,
00750 includeClassOrigin ? E_INCLUDE_CLASS_ORIGIN : E_EXCLUDE_CLASS_ORIGIN,
00751 pPropList);
00752 }
00753 else
00754 {
00755
00756 AssocCIMInstanceXMLOutputter handler(ostr, ns,
00757 getHost());
00758 hdl.associators(ns, objectName, handler,
00759 assocClass, resultClass, role, resultRole,
00760 includeQualifiers ? E_INCLUDE_QUALIFIERS : E_EXCLUDE_QUALIFIERS,
00761 includeClassOrigin ? E_INCLUDE_CLASS_ORIGIN : E_EXCLUDE_CLASS_ORIGIN,
00762 pPropList);
00763 }
00764 ostr << "</IRETURNVALUE>";
00765 }
00766 #endif // #ifndef OW_DISABLE_ASSOCIATION_TRAVERSAL
00767 #ifndef OW_DISABLE_SCHEMA_MANIPULATION
00768
00769 void XMLExecute::createClass(ostream& , CIMXMLParser& parser,
00770 const String& ns, CIMOMHandleIFC& hdl)
00771 {
00772 parser.mustGetChild();
00773 hdl.createClass( ns, XMLCIMFactory::createClass(parser) );
00774 }
00776 void
00777 XMLExecute::modifyClass(ostream& , CIMXMLParser& parser,
00778 const String& ns, CIMOMHandleIFC& hdl)
00779 {
00780 String name = parser.mustGetAttribute(CIMXMLParser::A_NAME);
00781 if (!name.equalsIgnoreCase(CIMXMLParser::P_ModifiedClass))
00782 {
00783 OW_THROWCIMMSG(CIMException::INVALID_PARAMETER,
00784 Format("Parameter name was %1", name).c_str());
00785 }
00786 parser.mustGetChild();
00787
00788
00789
00790 CIMClass cimClass = XMLCIMFactory::createClass(parser);
00791 hdl.modifyClass(ns, cimClass);
00792 }
00794 void XMLExecute::deleteClass(ostream& , CIMXMLParser& parser,
00795 const String& ns, CIMOMHandleIFC& hdl)
00796 {
00797 Array<param> params;
00798 params.push_back(param(CIMXMLParser::P_ClassName, false, param::CLASSNAME));
00799 getParameterValues(parser, params);
00800 String className = params[0].val.toString();
00801 hdl.deleteClass(ns, className);
00802 }
00803 #endif // #ifndef OW_DISABLE_SCHEMA_MANIPULATION
00804 #ifndef OW_DISABLE_INSTANCE_MANIPULATION
00805
00806 void XMLExecute::createInstance(ostream& ostr, CIMXMLParser& parser,
00807 const String& ns, CIMOMHandleIFC& hdl)
00808 {
00809 parser.mustGetChild();
00810 CIMInstance cimInstance = XMLCIMFactory::createInstance(parser);
00811 CIMName className = cimInstance.getClassName();
00812
00813
00814 if (className == "__Namespace")
00815 {
00816 CIMProperty prop = cimInstance.getProperty(
00817 CIMProperty::NAME_PROPERTY);
00818
00819
00820 if (!prop)
00821 {
00822 OW_THROWCIMMSG(CIMException::INVALID_PARAMETER,
00823 "Name property not specified for new namespace");
00824 }
00825
00826
00827 if (!prop.isKey())
00828 {
00829 prop.addQualifier(CIMQualifier::createKeyQualifier());
00830 }
00831 cimInstance.setProperty(prop);
00832 }
00833 ostr << "<IRETURNVALUE>";
00834 CIMObjectPath newPath = hdl.createInstance(ns, cimInstance);
00835 CIMInstanceNametoXML(newPath, ostr);
00836 ostr << "</IRETURNVALUE>";
00837 }
00839 void
00840 XMLExecute::modifyInstance(ostream& , CIMXMLParser& parser,
00841 const String& ns, CIMOMHandleIFC& hdl)
00842 {
00843 Array<param> params;
00844 params.push_back(param(CIMXMLParser::P_ModifiedInstance, false, param::NAMEDINSTANCE));
00845 params.push_back(param(CIMXMLParser::P_IncludeQualifiers, true, param::BOOLEAN, CIMValue(true)));
00846 params.push_back(param(CIMXMLParser::P_PropertyList, true, param::STRINGARRAY, CIMValue(CIMNULL)));
00847
00848 getParameterValues(parser, params);
00849
00850 StringArray propertyList;
00851 StringArray* pPropList = 0;
00852 if (params[2].isSet)
00853 {
00854 propertyList = params[2].val.toStringArray();
00855 pPropList = &propertyList;
00856 }
00857
00858 bool includeQualifiers = params[1].val.toBool();
00859 CIMInstance modifiedInstance(CIMNULL);
00860 params[0].val.get(modifiedInstance);
00861 hdl.modifyInstance(ns, modifiedInstance,
00862 includeQualifiers ? E_INCLUDE_QUALIFIERS : E_EXCLUDE_QUALIFIERS,
00863 pPropList);
00864 }
00866 void
00867 XMLExecute::deleteInstance(ostream& , CIMXMLParser& parser,
00868 const String& ns, CIMOMHandleIFC& hdl)
00869 {
00870 String name = parser.getAttribute( CIMXMLParser::A_NAME );
00871 if ( !name.equalsIgnoreCase( "InstanceName" ) )
00872 {
00873 OW_THROWCIMMSG( CIMException::INVALID_PARAMETER,
00874 String( "Parameter name was " + name ).c_str() );
00875 }
00876 parser.mustGetChild();
00877 CIMObjectPath instPath = XMLCIMFactory::createObjectPath(parser);
00878 hdl.deleteInstance( ns, instPath );
00879 }
00880 #if !defined(OW_DISABLE_PROPERTY_OPERATIONS)
00881
00882 void
00883 XMLExecute::setProperty(ostream& , CIMXMLParser& parser,
00884 const String& ns, CIMOMHandleIFC& hdl)
00885 {
00886 Array<param> params;
00887 params.push_back(param(CIMXMLParser::P_InstanceName, false, param::INSTANCENAME));
00888 params.push_back(param(CIMXMLParser::P_PropertyName, false, param::STRING, CIMValue("")));
00889 params.push_back(param(CIMXMLParser::P_NewValue, true, param::PROPERTYVALUE));
00890 getParameterValues(parser, params);
00891 CIMObjectPath instpath = params[0].val.toCIMObjectPath();
00892 hdl.setProperty(ns, instpath, params[1].val.toString(), params[2].val);
00893 }
00894 #endif // #if !defined(OW_DISABLE_PROPERTY_OPERATIONS)
00895 #endif // #ifndef OW_DISABLE_INSTANCE_MANIPULATION
00896 #ifndef OW_DISABLE_QUALIFIER_DECLARATION
00897
00898 void
00899 XMLExecute::setQualifier(ostream& , CIMXMLParser& parser,
00900 const String& ns, CIMOMHandleIFC& hdl)
00901 {
00902 String argName = parser.mustGetAttribute(CIMXMLParser::A_NAME);
00903 if (!argName.equalsIgnoreCase(CIMXMLParser::P_QualifierDeclaration))
00904 {
00905 OW_THROWCIMMSG(CIMException::INVALID_PARAMETER,
00906 "invalid qualifier xml");
00907 }
00908 parser.mustGetChildId(
00909 CIMXMLParser::E_QUALIFIER_DECLARATION);
00910
00911 CIMQualifierType cimQualifier;
00912 XMLQualifier::processQualifierDecl(parser, cimQualifier);
00913 hdl.setQualifierType(ns, cimQualifier);
00914 }
00916 void
00917 XMLExecute::deleteQualifier(ostream& , CIMXMLParser& parser,
00918 const String& ns, CIMOMHandleIFC& hdl)
00919 {
00920 String qualName = XMLQualifier::getQualifierName(parser);
00921 hdl.deleteQualifierType(ns, qualName);
00922 }
00924 namespace
00925 {
00926 class CIMQualifierTypeXMLOutputter : public CIMQualifierTypeResultHandlerIFC
00927 {
00928 public:
00929 CIMQualifierTypeXMLOutputter(
00930 std::ostream& ostr_)
00931 : ostr(ostr_)
00932 {}
00933 protected:
00934 virtual void doHandle(const CIMQualifierType &i)
00935 {
00936 CIMtoXML(i, ostr);
00937 checkStream(ostr);
00938 }
00939 std::ostream& ostr;
00940 };
00941 }
00943 void
00944 XMLExecute::enumerateQualifiers(ostream& ostr, CIMXMLParser& ,
00945 const String& ns, CIMOMHandleIFC& hdl)
00946 {
00947 ostr << "<IRETURNVALUE>";
00948 CIMQualifierTypeXMLOutputter handler(ostr);
00949 hdl.enumQualifierTypes(ns, handler);
00950 ostr << "</IRETURNVALUE>";
00951 }
00952 #endif // #ifndef OW_DISABLE_QUALIFIER_DECLARATION
00953
00954 namespace
00955 {
00956 class ClassNameXMLWriter : public StringResultHandlerIFC
00957 {
00958 public:
00959 ClassNameXMLWriter(std::ostream& ostr_) : ostr(ostr_) {}
00960 protected:
00961 virtual void doHandle(const String &name)
00962 {
00963 ostr << "<CLASSNAME NAME=\"" << name <<
00964 "\"/>";
00965 checkStream(ostr);
00966 }
00967 private:
00968 std::ostream& ostr;
00969 };
00970 }
00972 void
00973 XMLExecute::enumerateClassNames(ostream& ostr, CIMXMLParser& parser,
00974 const String& ns, CIMOMHandleIFC& hdl)
00975 {
00976 Array<param> params;
00977 params.push_back(param(CIMXMLParser::P_ClassName, true, param::CLASSNAME, CIMValue("")));
00978 params.push_back(param(CIMXMLParser::P_DeepInheritance, true, param::BOOLEAN, CIMValue(false)));
00979 getParameterValues(parser, params);
00980 String className = params[0].val.toString();
00981 EDeepFlag deepInheritance(
00982 params[1].val.toBool() ? E_DEEP : E_SHALLOW);
00983 ostr << "<IRETURNVALUE>";
00984 ClassNameXMLWriter handler(ostr);
00985 hdl.enumClassNames(ns, className, handler,
00986 deepInheritance);
00987 ostr << "</IRETURNVALUE>";
00988 }
00990 namespace
00991 {
00992 class CIMClassXMLOutputter : public CIMClassResultHandlerIFC
00993 {
00994 public:
00995 CIMClassXMLOutputter(ostream& ostr_)
00996 : ostr(ostr_)
00997 {}
00998 protected:
00999 virtual void doHandle(const CIMClass &c)
01000 {
01001 CIMtoXML(c, ostr);
01002 checkStream(ostr);
01003 }
01004 private:
01005 ostream& ostr;
01006 };
01007 }
01009 void
01010 XMLExecute::enumerateClasses( ostream& ostr, CIMXMLParser& parser,
01011 const String& ns, CIMOMHandleIFC& hdl)
01012 {
01013 Array<param> params;
01014 params.push_back(param(CIMXMLParser::P_ClassName, true, param::CLASSNAME));
01015 params.push_back(param(CIMXMLParser::P_DeepInheritance, true, param::BOOLEAN, CIMValue(false)));
01016 params.push_back(param(CIMXMLParser::P_LocalOnly, true, param::BOOLEAN, CIMValue(true)));
01017 params.push_back(param(CIMXMLParser::P_IncludeQualifiers, true, param::BOOLEAN, CIMValue(true)));
01018 params.push_back(param(CIMXMLParser::P_IncludeClassOrigin, true, param::BOOLEAN, CIMValue(false)));
01019 getParameterValues(parser, params);
01020 String className;
01021 if (params[0].isSet)
01022 {
01023 className = params[0].val.toString();
01024 }
01025 ostr << "<IRETURNVALUE>";
01026 bool deep = params[1].val.toBool();
01027 bool localOnly = params[2].val.toBool();
01028 bool includeQualifiers = params[3].val.toBool();
01029 bool includeClassOrigin = params[4].val.toBool();
01030 CIMClassXMLOutputter handler(ostr);
01031 hdl.enumClass(ns, className, handler,
01032 deep ? E_DEEP : E_SHALLOW,
01033 localOnly ? E_LOCAL_ONLY : E_NOT_LOCAL_ONLY,
01034 includeQualifiers ? E_INCLUDE_QUALIFIERS : E_EXCLUDE_QUALIFIERS,
01035 includeClassOrigin ? E_INCLUDE_CLASS_ORIGIN : E_EXCLUDE_CLASS_ORIGIN);
01036 ostr << "</IRETURNVALUE>";
01037 }
01039 namespace
01040 {
01041 class CIMInstanceNameXMLOutputter : public CIMObjectPathResultHandlerIFC
01042 {
01043 public:
01044 CIMInstanceNameXMLOutputter(ostream& ostr_)
01045 : ostr(ostr_)
01046 {}
01047 protected:
01048 virtual void doHandle(const CIMObjectPath &cop)
01049 {
01050 CIMInstanceNametoXML(cop, ostr);
01051 checkStream(ostr);
01052 }
01053 private:
01054 ostream& ostr;
01055 };
01056 }
01058 void
01059 XMLExecute::enumerateInstanceNames(ostream& ostr, CIMXMLParser& parser,
01060 const String& ns, CIMOMHandleIFC& hdl)
01061 {
01062 Array<param> params;
01063 params.push_back(param(CIMXMLParser::P_ClassName, false, param::CLASSNAME));
01064 getParameterValues(parser, params);
01065 String className = params[0].val.toString();
01066
01067 ostr << "<IRETURNVALUE>";
01068 CIMInstanceNameXMLOutputter handler(ostr);
01069 hdl.enumInstanceNames(ns, className, handler);
01070 ostr << "</IRETURNVALUE>";
01071 }
01073 namespace
01074 {
01075 class CIMInstanceXMLOutputter : public CIMInstanceResultHandlerIFC
01076 {
01077 public:
01078 CIMInstanceXMLOutputter(
01079 std::ostream& ostr_,
01080 const String& ns_)
01081 : ostr(ostr_)
01082 , ns(ns_)
01083 {}
01084 protected:
01085 virtual void doHandle(const CIMInstance &i)
01086 {
01087 const CIMInstance& cimInstance = i;
01088 CIMObjectPath cop(ns, cimInstance);
01089 ostr << "<VALUE.NAMEDINSTANCE>";
01090 CIMInstanceNameAndInstancetoXML(cimInstance, ostr, cop);
01091 ostr << "</VALUE.NAMEDINSTANCE>";
01092 checkStream(ostr);
01093 }
01094 std::ostream& ostr;
01095 String ns;
01096 };
01097 }
01099 void
01100 XMLExecute::enumerateInstances(ostream& ostr, CIMXMLParser& parser,
01101 const String& ns, CIMOMHandleIFC& hdl)
01102 {
01103 Array<param> params;
01104 params.push_back(param(CIMXMLParser::P_ClassName, false, param::CLASSNAME));
01105 params.push_back(param(CIMXMLParser::P_LocalOnly, true, param::BOOLEAN, CIMValue(true)));
01106 params.push_back(param(CIMXMLParser::P_DeepInheritance, true, param::BOOLEAN, CIMValue(true)));
01107 params.push_back(param(CIMXMLParser::P_IncludeQualifiers, true, param::BOOLEAN, CIMValue(false)));
01108 params.push_back(param(CIMXMLParser::P_IncludeClassOrigin, true, param::BOOLEAN, CIMValue(false)));
01109 params.push_back(param(CIMXMLParser::P_PropertyList, true, param::STRINGARRAY, CIMValue(CIMNULL)));
01110 getParameterValues(parser, params);
01111 String className = params[0].val.toString();
01112 StringArray propertyList;
01113 StringArray* pPropList = 0;
01114 if (params[5].isSet)
01115 {
01116 propertyList = params[5].val.toStringArray();
01117 pPropList = &propertyList;
01118 }
01119 bool localOnly = params[1].val.toBool();
01120 bool deep = params[2].val.toBool();
01121 bool includeQualifiers = params[3].val.toBool();
01122 bool includeClassOrigin = params[4].val.toBool();
01123 ostr << "<IRETURNVALUE>";
01124 CIMInstanceXMLOutputter handler(ostr, ns);
01125 hdl.enumInstances(ns, className, handler,
01126 deep ? E_DEEP : E_SHALLOW,
01127 localOnly ? E_LOCAL_ONLY : E_NOT_LOCAL_ONLY,
01128 includeQualifiers ? E_INCLUDE_QUALIFIERS : E_EXCLUDE_QUALIFIERS,
01129 includeClassOrigin ? E_INCLUDE_CLASS_ORIGIN : E_EXCLUDE_CLASS_ORIGIN,
01130 pPropList);
01131 ostr << "</IRETURNVALUE>";
01132 }
01134 void
01135 XMLExecute::getClass(ostream& ostr, CIMXMLParser& parser,
01136 const String& ns, CIMOMHandleIFC& hdl)
01137 {
01138 Array<param> params;
01139 params.push_back(param(CIMXMLParser::P_ClassName, false, param::CLASSNAME));
01140 params.push_back(param(CIMXMLParser::P_LocalOnly, true, param::BOOLEAN, CIMValue(true)));
01141 params.push_back(param(CIMXMLParser::P_IncludeQualifiers, true, param::BOOLEAN, CIMValue(true)));
01142 params.push_back(param(CIMXMLParser::P_IncludeClassOrigin, true, param::BOOLEAN, CIMValue(false)));
01143 params.push_back(param(CIMXMLParser::P_PropertyList, true, param::STRINGARRAY, CIMValue(CIMNULL)));
01144 getParameterValues(parser, params);
01145 String className = params[0].val.toString();
01146 StringArray propertyList;
01147 StringArray* pPropList = 0;
01148 if (params[4].isSet)
01149 {
01150 propertyList = params[4].val.toStringArray();
01151 pPropList = &propertyList;
01152 }
01153 bool localOnly = params[1].val.toBool();
01154 bool includeQualifiers = params[2].val.toBool();
01155 bool includeClassOrigin = params[3].val.toBool();
01156 ostr << "<IRETURNVALUE>";
01157 CIMClass cimClass = hdl.getClass(ns, className,
01158 localOnly ? E_LOCAL_ONLY : E_NOT_LOCAL_ONLY,
01159 includeQualifiers ? E_INCLUDE_QUALIFIERS : E_EXCLUDE_QUALIFIERS,
01160 includeClassOrigin ? E_INCLUDE_CLASS_ORIGIN : E_EXCLUDE_CLASS_ORIGIN,
01161 pPropList);
01162
01163 CIMtoXML(cimClass, ostr);
01164 ostr << "</IRETURNVALUE>";
01165 }
01167 void
01168 XMLExecute::getInstance(ostream& ostr, CIMXMLParser& parser,
01169 const String& ns, CIMOMHandleIFC& hdl)
01170 {
01171 Array<param> params;
01172 params.push_back(param(CIMXMLParser::P_InstanceName, false, param::INSTANCENAME));
01173 params.push_back(param(CIMXMLParser::P_LocalOnly, true, param::BOOLEAN, CIMValue(true)));
01174 params.push_back(param(CIMXMLParser::P_IncludeQualifiers, true, param::BOOLEAN, CIMValue(false)));
01175 params.push_back(param(CIMXMLParser::P_IncludeClassOrigin, true, param::BOOLEAN, CIMValue(false)));
01176 params.push_back(param(CIMXMLParser::P_PropertyList, true, param::STRINGARRAY, CIMValue(CIMNULL)));
01177 getParameterValues(parser, params);
01178 CIMObjectPath instancePath = params[0].val.toCIMObjectPath();
01179 StringArray propertyList;
01180 StringArray* pPropList = 0;
01181 if (params[4].isSet)
01182 {
01183 propertyList = params[4].val.toStringArray();
01184 pPropList = &propertyList;
01185 }
01186 bool localOnly = params[1].val.toBool();
01187 bool includeQualifiers = params[2].val.toBool();
01188 bool includeClassOrigin = params[3].val.toBool();
01189 ostr << "<IRETURNVALUE>";
01190 CIMInstance cimInstance = hdl.getInstance(ns, instancePath,
01191 localOnly ? E_LOCAL_ONLY : E_NOT_LOCAL_ONLY,
01192 includeQualifiers ? E_INCLUDE_QUALIFIERS : E_EXCLUDE_QUALIFIERS,
01193 includeClassOrigin ? E_INCLUDE_CLASS_ORIGIN : E_EXCLUDE_CLASS_ORIGIN,
01194 pPropList);
01195 CIMInstancetoXML(cimInstance, ostr);
01196 ostr << "</IRETURNVALUE>";
01197 }
01198 #if !defined(OW_DISABLE_PROPERTY_OPERATIONS)
01199
01200 void
01201 XMLExecute::getProperty(ostream& ostr, CIMXMLParser& parser,
01202 const String& ns, CIMOMHandleIFC& hdl)
01203 {
01204 Array<param> params;
01205 params.push_back(param(CIMXMLParser::P_InstanceName, false, param::INSTANCENAME));
01206 params.push_back(param(CIMXMLParser::P_PropertyName, false, param::STRING, CIMValue("")));
01207 getParameterValues(parser, params);
01208 CIMObjectPath instpath = params[0].val.toCIMObjectPath();
01209 ostr << "<IRETURNVALUE>";
01210 CIMValue cv = hdl.getProperty(ns, instpath, params[1].val.toString());
01211 if (cv)
01212 {
01213 CIMtoXML(cv, ostr);
01214 }
01215 ostr << "</IRETURNVALUE>";
01216 }
01217 #endif // #if !defined(OW_DISABLE_PROPERTY_OPERATIONS)
01218
01219 void
01220 XMLExecute::getQualifier(ostream& ostr, CIMXMLParser& parser,
01221 const String& ns, CIMOMHandleIFC& hdl)
01222 {
01223 String qualifierName = XMLQualifier::getQualifierName(parser);
01224 ostr << "<IRETURNVALUE>";
01225 CIMQualifierType qual = hdl.getQualifierType(ns, qualifierName);
01226 CIMtoXML(qual, ostr);
01227 ostr << "</IRETURNVALUE>";
01228 }
01229 #ifndef OW_DISABLE_ASSOCIATION_TRAVERSAL
01230
01231 void
01232 XMLExecute::referenceNames(ostream& ostr, CIMXMLParser& parser,
01233 const String& ns,CIMOMHandleIFC& hdl)
01234 {
01235 Array<param> params;
01236 params.push_back(param(CIMXMLParser::P_ObjectName, false, param::OBJECTNAME));
01237 params.push_back(param(CIMXMLParser::P_ResultClass, true, param::CLASSNAME));
01238 params.push_back(param(CIMXMLParser::P_Role, true, param::STRING, CIMValue("")));
01239 getParameterValues(parser, params);
01240 CIMObjectPath path = params[0].val.toCIMObjectPath();
01241 String resultClass;
01242 if (params[1].isSet)
01243 {
01244 resultClass = params[1].val.toString();
01245 }
01246 ostr << "<IRETURNVALUE>";
01247 CIMObjectPathXMLOutputter handler(ostr, getHost(), ns);
01248 hdl.referenceNames(ns, path, handler, resultClass, params[2].val.toString());
01249 ostr << "</IRETURNVALUE>";
01250 }
01252 void
01253 XMLExecute::references(ostream& ostr, CIMXMLParser& parser,
01254 const String& ns, CIMOMHandleIFC& hdl)
01255 {
01256 Array<param> params;
01257 params.push_back(param(CIMXMLParser::P_ObjectName, false, param::OBJECTNAME));
01258 params.push_back(param(CIMXMLParser::P_ResultClass, true, param::CLASSNAME));
01259 params.push_back(param(CIMXMLParser::P_Role, true, param::STRING, CIMValue("")));
01260 params.push_back(param(CIMXMLParser::P_IncludeQualifiers, true, param::BOOLEAN, CIMValue(false)));
01261 params.push_back(param(CIMXMLParser::P_IncludeClassOrigin, true, param::BOOLEAN, CIMValue(false)));
01262 params.push_back(param(CIMXMLParser::P_PropertyList, true, param::STRINGARRAY, CIMValue(CIMNULL)));
01263 getParameterValues(parser, params);
01264 CIMObjectPath path = params[0].val.toCIMObjectPath();
01265 String resultClass;
01266 if (params[1].isSet)
01267 {
01268 resultClass = params[1].val.toString();
01269 }
01270 StringArray propertyList;
01271 StringArray* pPropList = 0;
01272 if (params[5].isSet)
01273 {
01274 propertyList = params[5].val.toStringArray();
01275 pPropList = &propertyList;
01276 }
01277
01278 bool includeQualifiers = params[3].val.toBool();
01279 bool includeClassOrigin = params[4].val.toBool();
01280 String role = params[2].val.toString();
01281
01282 ostr << "<IRETURNVALUE>";
01283 if (path.isClassPath())
01284 {
01285
01286 AssocCIMClassXMLOutputter handler(ostr, ns);
01287 hdl.referencesClasses(ns, path, handler, resultClass,
01288 role,
01289 includeQualifiers ? E_INCLUDE_QUALIFIERS : E_EXCLUDE_QUALIFIERS,
01290 includeClassOrigin ? E_INCLUDE_CLASS_ORIGIN : E_EXCLUDE_CLASS_ORIGIN,
01291 pPropList);
01292 }
01293 else
01294 {
01295 AssocCIMInstanceXMLOutputter handler(ostr, ns,
01296 getHost());
01297 hdl.references(ns, path, handler, resultClass,
01298 role,
01299 includeQualifiers ? E_INCLUDE_QUALIFIERS : E_EXCLUDE_QUALIFIERS,
01300 includeClassOrigin ? E_INCLUDE_CLASS_ORIGIN : E_EXCLUDE_CLASS_ORIGIN,
01301 pPropList);
01302 }
01303 ostr << "</IRETURNVALUE>";
01304 }
01305 #endif // #ifndef OW_DISABLE_ASSOCIATION_TRAVERSAL
01306
01307 namespace
01308 {
01309 class execQueryXMLOutputter : public CIMInstanceResultHandlerIFC
01310 {
01311 public:
01312 execQueryXMLOutputter(std::ostream& ostr_, const String& ns_)
01313 : ostr(ostr_)
01314 , ns(ns_)
01315 {}
01316 protected:
01317 virtual void doHandle(const CIMInstance &i)
01318 {
01319
01320
01321 String cins = i.getNameSpace();
01322 if (cins.empty())
01323 {
01324 cins = ns;
01325 }
01326 CIMObjectPath cop(cins, i);
01327 ostr << "<VALUE.OBJECTWITHPATH>";
01328 CIMInstancePathAndInstancetoXML(i, ostr, cop);
01329 ostr << "</VALUE.OBJECTWITHPATH>";
01330 checkStream(ostr);
01331 }
01332 private:
01333 std::ostream& ostr;
01334 const String& ns;
01335 };
01336 }
01338 void
01339 XMLExecute::execQuery(ostream& ostr, CIMXMLParser& parser,
01340 const String& ns, CIMOMHandleIFC& hdl)
01341 {
01342 Array<param> params;
01343 params.push_back(param(CIMXMLParser::P_QueryLanguage, false, param::STRING));
01344 params.push_back(param(CIMXMLParser::P_Query, false, param::STRING));
01345 getParameterValues(parser, params);
01346 ostr << "<IRETURNVALUE>";
01347 execQueryXMLOutputter handler(ostr, ns);
01348 hdl.execQuery(ns, handler, params[1].val.toString(), params[0].val.toString());
01349 ostr << "</IRETURNVALUE>";
01350 }
01352 void
01353 XMLExecute::processSimpleReq(CIMXMLParser& parser, ostream& ostrEntity,
01354 ostream& ostrError, OperationContext& context)
01355 {
01356 try
01357 {
01358 ostrEntity << "<SIMPLERSP>";
01359
01360
01361 OW_ASSERT(parser.tokenIsId(CIMXMLParser::E_SIMPLEREQ));
01362
01363 parser.mustGetChild();
01364 if (parser.getToken() == CIMXMLParser::E_METHODCALL)
01365 {
01366 m_isIntrinsic = false;
01367 }
01368 else if (parser.getToken() == CIMXMLParser::E_IMETHODCALL)
01369 {
01370 m_isIntrinsic = true;
01371 }
01372 else
01373 {
01374 OW_THROWCIMMSG(CIMException::FAILED,
01375 "No <METHODCALL> or <IMETHODCALL> element");
01376 }
01377
01378
01379
01380
01381
01382 m_functionName = parser.mustGetAttribute(CIMXMLParser::A_NAME);
01383 parser.mustGetChild();
01384 CIMOMHandleIFCRef hdl = this->getEnvironment()->getCIMOMHandle(context);
01385 if (m_isIntrinsic)
01386 {
01387
01388 parser.mustGetChildId(CIMXMLParser::E_NAMESPACE);
01389 String nameSpace = XMLClass::getNameSpace(parser);
01390
01391
01392 parser.mustGetEndTag();
01393 executeIntrinsic(ostrEntity, parser, *hdl, nameSpace);
01394 }
01395 else
01396 {
01397 executeExtrinsic(ostrEntity, parser, *hdl);
01398 }
01399 ostrEntity << "</SIMPLERSP>";
01400 }
01401 catch (CIMException& ce)
01402 {
01403 OW_LOGDEBUG(Format("XMLExecute::processSimpleReq caught CIM "
01404 "exception:\nCode: %1\nFile: %2\n Line: %3\nMessage: %4",
01405 ce.getErrNo(), ce.getFile(), ce.getLine(), ce.getMessage()));
01406 outputError(ce.getErrNo(), ce.getDescription(), ostrError);
01407 }
01408 }
01410 void
01411 XMLExecute::doOptions(CIMFeatures& cf,
01412 OperationContext& context)
01413 {
01414 cf = this->getEnvironment()->getCIMOMHandle(context)->getServerFeatures();
01415 }
01417 RequestHandlerIFC*
01418 XMLExecute::clone() const
01419 {
01420 OW_ASSERT(!m_ostrEntity);
01421 OW_ASSERT(!m_ostrError);
01422 return new XMLExecute(*this);
01423 }
01425
01426 void
01427 XMLExecute::outputError(CIMException::ErrNoType errorCode,
01428 const String& msg, ostream& ostr)
01429 {
01430 setError(errorCode, msg);
01431 ostr << "<SIMPLERSP>\r\n";
01432 if (m_isIntrinsic)
01433 {
01434 ostr << "<IMETHODRESPONSE NAME=\"" << m_functionName << "\">\r\n";
01435 }
01436 else
01437 {
01438 ostr << "<METHODRESPONSE NAME=\"" << m_functionName << "\">\r\n";
01439 }
01440
01441 ostr << "<ERROR CODE=\"" << errorCode << "\"";
01442
01443
01444
01445 ostr << " DESCRIPTION=\"" <<
01446 XMLEscape(msg) <<
01447 "\"";
01448
01449 ostr << "></ERROR>\r\n";
01450
01451 if (m_isIntrinsic)
01452 {
01453 ostr << "</IMETHODRESPONSE>\r\n";
01454 }
01455 else
01456 {
01457 ostr << "</METHODRESPONSE>\r\n";
01458 }
01459 ostr << "</SIMPLERSP>\r\n";
01460 }
01461
01463 void
01464 XMLExecute::init(const ServiceEnvironmentIFCRef& env)
01465 {
01466 setEnvironment(env);
01467 #ifndef OW_DISABLE_INSTANCE_MANIPULATION
01468 LoggerRef logger(env->getLogger(COMPONENT_NAME));
01469
01470
01471
01472 try
01473 {
01474 String interopNS = env->getConfigItem(ConfigOpts::INTEROP_SCHEMA_NAMESPACE_opt, OW_DEFAULT_INTEROP_SCHEMA_NAMESPACE);
01475 OperationContext context;
01476 CIMOMHandleIFCRef hdl(env->getCIMOMHandle(context));
01477
01478 CIMClass CIM_CIMXMLCommunicationMechanism(hdl->getClass(interopNS, "CIM_CIMXMLCommunicationMechanism"));
01479
01480 CIMInstance commMech(CIM_CIMXMLCommunicationMechanism.newInstance());
01481
01482
01483
01484 CIMObjectPathArray objectManagers(hdl->enumInstanceNamesA(interopNS, "CIM_ObjectManager"));
01485 if (objectManagers.size() != 1)
01486 {
01487 OW_THROWCIMMSG(CIMException::FAILED, Format("Expected 1 instance of CIM_ObjectManager, got %1", objectManagers.size()).c_str());
01488 }
01489
01490 CIMObjectPath& objectManager(objectManagers[0]);
01491 commMech.updatePropertyValue("SystemCreationClassName", objectManager.getKeyValue("SystemCreationClassName"));
01492 commMech.updatePropertyValue("SystemName", objectManager.getKeyValue("SystemName"));
01493 commMech.updatePropertyValue("CreationClassName", CIMValue("CIM_CIMXMLCommunicationMechanism"));
01494 commMech.updatePropertyValue("Name", CIMValue("cim-xml"));
01495
01496
01497 commMech.updatePropertyValue("CIMValidated", CIMValue(true));
01498 commMech.updatePropertyValue("CIMXMLProtocolVersion", CIMValue(UInt16(1)));
01499 commMech.updatePropertyValue("Version", CIMValue("1.1"));
01500
01501
01502 enum
01503 {
01504 E_FP_Unknown = 0,
01505 E_FP_Other = 1,
01506 E_FP_Basic_Read = 2,
01507 E_FP_Basic_Write = 3,
01508 E_FP_Schema_Manipulation = 4,
01509 E_FP_Instance_Manipulation = 5,
01510 E_FP_Association_Traversal = 6,
01511 E_FP_Query_Execution = 7,
01512 E_FP_Qualifier_Declaration = 8,
01513 E_FP_Indications = 9
01514 };
01515
01516 UInt16Array functionalProfilesSupported;
01517 functionalProfilesSupported.push_back(E_FP_Basic_Read);
01518 functionalProfilesSupported.push_back(E_FP_Basic_Write);
01519 #ifndef OW_DISABLE_SCHEMA_MANIPULATION
01520 functionalProfilesSupported.push_back(E_FP_Schema_Manipulation);
01521 #endif
01522 #ifndef OW_DISABLE_INSTANCE_MANIPULATION
01523 functionalProfilesSupported.push_back(E_FP_Instance_Manipulation);
01524 #endif
01525 #ifndef OW_DISABLE_ASSOCIATION_TRAVERSAL
01526 functionalProfilesSupported.push_back(E_FP_Association_Traversal);
01527 #endif
01528 functionalProfilesSupported.push_back(E_FP_Query_Execution);
01529 #ifndef OW_DISABLE_QUALIFIER_DECLARATION
01530 functionalProfilesSupported.push_back(E_FP_Qualifier_Declaration);
01531 #endif
01532 if (!env->getConfigItem(ConfigOpts::DISABLE_INDICATIONS_opt, OW_DEFAULT_DISABLE_INDICATIONS).equalsIgnoreCase("true"))
01533 {
01534 functionalProfilesSupported.push_back(E_FP_Indications);
01535 }
01536
01537 commMech.updatePropertyValue("FunctionalProfilesSupported", CIMValue(functionalProfilesSupported));
01538 commMech.updatePropertyValue("MultipleOperationsSupported", CIMValue(true));
01539
01540 enum
01541 {
01542 E_AM_Unknown = 0,
01543 E_AM_Other = 1,
01544 E_AM_None = 2,
01545 E_AM_Basic = 3,
01546 E_AM_Digest = 4
01547 };
01548
01549 UInt16Array authenticationMechanismsSupported;
01550 authenticationMechanismsSupported.push_back(E_AM_Other);
01551 authenticationMechanismsSupported.push_back(E_AM_Basic);
01552 #ifndef OW_DISABLE_DIGEST
01553 authenticationMechanismsSupported.push_back(E_AM_Digest);
01554 #endif
01555 commMech.updatePropertyValue("AuthenticationMechanismsSupported", CIMValue(authenticationMechanismsSupported));
01556
01557 StringArray authenticationMechanismDescriptions(1, "OWLocal");
01558 commMech.updatePropertyValue("AuthenticationMechanismDescriptions", CIMValue(authenticationMechanismDescriptions));
01559
01560
01561 commMech.updatePropertyValue("ElementName", CIMValue("CIM/XML Communication Mechanism"));
01562
01563
01564 UInt16Array operationalStatus;
01565 operationalStatus.push_back(2);
01566 commMech.updatePropertyValue("OperationalStatus", CIMValue(operationalStatus));
01567
01568
01569 try
01570 {
01571
01572 hdl->deleteInstance(interopNS, CIMObjectPath(interopNS, commMech));
01573 }
01574 catch (CIMException&)
01575 {
01576
01577 }
01578 m_commMechPath = hdl->createInstance(interopNS, commMech);
01579 m_commMechPath.setNameSpace(interopNS);
01580 OW_LOG_DEBUG(logger, Format("Sucessfully created instance of CIM_CIMXMLCommunicationMechanism. Saving path: %1", m_commMechPath.toString()));
01581
01582
01583
01584 CIMClass CIM_HostedAccessPoint(hdl->getClass(interopNS, "CIM_HostedAccessPoint"));
01585 CIMInstance hostedAccessPoint(CIM_HostedAccessPoint.newInstance());
01586 hostedAccessPoint.updatePropertyValue("Dependent", CIMValue(m_commMechPath));
01587
01588
01589 CIMObjectPath systemPath(objectManager.getKeyValue("SystemCreationClassName").toString(), interopNS);
01590 systemPath.setKeyValue("CreationClassName", objectManager.getKeyValue("SystemCreationClassName"));
01591 systemPath.setKeyValue("Name", objectManager.getKeyValue("SystemName"));
01592
01593 hostedAccessPoint.updatePropertyValue("Antecedent", CIMValue(systemPath));
01594
01595
01596 try
01597 {
01598
01599 hdl->deleteInstance(interopNS, CIMObjectPath(interopNS, hostedAccessPoint));
01600 }
01601 catch (CIMException&)
01602 {
01603
01604 }
01605 m_hostedAccessPointPath = hdl->createInstance(interopNS, hostedAccessPoint);
01606 m_hostedAccessPointPath.setNameSpace(interopNS);
01607 OW_LOG_DEBUG(logger, Format("Sucessfully created instance of CIM_HostedAccessPoint. Saving path: %1", m_hostedAccessPointPath.toString()));
01608
01609
01610
01611 CIMClass OpenWBEM_CIMXMLCommMechanismForOpenWBEMManager(hdl->getClass(interopNS, "OpenWBEM_CIMXMLCommMechanismForOpenWBEMManager"));
01612 CIMInstance commMechForManager(OpenWBEM_CIMXMLCommMechanismForOpenWBEMManager.newInstance());
01613 commMechForManager.updatePropertyValue("Dependent", CIMValue(m_commMechPath));
01614 commMechForManager.updatePropertyValue("Antecedent", CIMValue(objectManager));
01615
01616
01617 try
01618 {
01619
01620 hdl->deleteInstance(interopNS, CIMObjectPath(interopNS, commMechForManager));
01621 }
01622 catch (CIMException&)
01623 {
01624
01625 }
01626 m_commMechForManager = hdl->createInstance(interopNS, commMechForManager);
01627 m_commMechForManager.setNameSpace(interopNS);
01628 OW_LOG_DEBUG(logger, Format("Sucessfully created instance of OpenWBEM_CIMXMLCommMechanismForOpenWBEMManager. Saving path: %1",
01629 m_commMechForManager.toString()));
01630 }
01631 catch (CIMException& e)
01632 {
01633
01634 OW_LOG_DEBUG(logger, Format("Failed creating CIM_CIMXMLCommunicationMechanism: %1", e));
01635 }
01636 #endif // #ifndef OW_DISABLE_INSTANCE_MANIPULATION
01637
01638 }
01639
01641 namespace
01642 {
01643 void cleanupInteropInstance(const CIMObjectPath& path, const LoggerRef& logger, const ServiceEnvironmentIFCRef& env)
01644 {
01645 #ifndef OW_DISABLE_INSTANCE_MANIPULATION
01646 if (path)
01647 {
01648 OW_LOG_DEBUG(logger, "XMLExecute::shutdown() cleaning up CIM_HostedAccessPoint instance");
01649
01650 try
01651 {
01652 String interopNS(path.getNameSpace());
01653 OperationContext context;
01654 CIMOMHandleIFCRef hdl(env->getCIMOMHandle(context));
01655 hdl->deleteInstance(interopNS, path);
01656 }
01657 catch (CIMException& e)
01658 {
01659
01660 OW_LOG_DEBUG(logger, Format("Failed deleting: %1", e));
01661 }
01662 }
01663 #endif // #ifndef OW_DISABLE_INSTANCE_MANIPULATION
01664 }
01665 }
01666
01668 void
01669 XMLExecute::shutdown()
01670 {
01671
01672 ServiceEnvironmentIFCRef env(getEnvironment());
01673 OW_ASSERT(env);
01674 LoggerRef logger(env->getLogger(COMPONENT_NAME));
01675 OW_ASSERT(logger);
01676
01677 cleanupInteropInstance(m_commMechPath, logger, env);
01678 cleanupInteropInstance(m_hostedAccessPointPath, logger, env);
01679 cleanupInteropInstance(m_commMechForManager, logger, env);
01680
01681
01682 setEnvironment(ServiceEnvironmentIFCRef());
01683 }
01684
01685 }
01686
01688 OW_REQUEST_HANDLER_FACTORY(OW_NAMESPACE::XMLExecute,XMLExecute);
01689