(file) Return to XmlWriter.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

   1 mike  1.23 //%/////////////////////////////////////////////////////////////////////////////
   2            //
   3 kumpf 1.63 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM,
   4 mike  1.24 // The Open Group, Tivoli Systems
   5 mike  1.23 //
   6            // Permission is hereby granted, free of charge, to any person obtaining a copy
   7 kumpf 1.63 // of this software and associated documentation files (the "Software"), to
   8            // deal in the Software without restriction, including without limitation the
   9            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  10 mike  1.23 // sell copies of the Software, and to permit persons to whom the Software is
  11            // furnished to do so, subject to the following conditions:
  12            // 
  13 kumpf 1.63 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
  14 mike  1.23 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
  15            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
  16 kumpf 1.63 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  17            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  19 mike  1.23 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  20            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21            //
  22            //==============================================================================
  23            //
  24            // Author: Mike Brasher (mbrasher@bmc.com)
  25            //
  26 mike  1.24 // Modified By: Nitin Upasani, Hewlett-Packard Company (Nitin_Upasani@hp.com)
  27            //              Nag Boranna, Hewlett-Packard Company (nagaraja_boranna@hp.com)
  28            //              Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
  29 kumpf 1.61 //              Carol Ann Krug Graves, Hewlett-Packard Company
  30            //                  (carolann_graves@hp.com)
  31 mike  1.23 //
  32            //%/////////////////////////////////////////////////////////////////////////////
  33            
  34 sage  1.49 #include <Pegasus/Common/Config.h>
  35 mike  1.23 #include <cstdlib>
  36            #include <cstdio>
  37 kumpf 1.46 #include "Constants.h"
  38 kumpf 1.28 #include "Destroyer.h"
  39 mike  1.23 #include "CIMClass.h"
  40 kumpf 1.55 #include "CIMClassRep.h"
  41 mike  1.23 #include "CIMInstance.h"
  42 kumpf 1.55 #include "CIMInstanceRep.h"
  43 kumpf 1.56 #include "CIMProperty.h"
  44            #include "CIMPropertyRep.h"
  45            #include "CIMMethod.h"
  46            #include "CIMMethodRep.h"
  47            #include "CIMParameter.h"
  48            #include "CIMParameterRep.h"
  49            #include "CIMParamValue.h"
  50            #include "CIMParamValueRep.h"
  51            #include "CIMQualifier.h"
  52            #include "CIMQualifierRep.h"
  53            #include "CIMQualifierDecl.h"
  54            #include "CIMQualifierDeclRep.h"
  55 kumpf 1.54 #include "CIMValue.h"
  56 mike  1.23 #include "XmlWriter.h"
  57            #include "XmlParser.h"
  58 kumpf 1.44 #include "Tracer.h"
  59 sage  1.49 #include <Pegasus/Common/StatisticalData.h>
  60 mike  1.23 
  61            PEGASUS_NAMESPACE_BEGIN
  62            
  63 kumpf 1.27 Array<Sint8>& operator<<(Array<Sint8>& out, const char* x)
  64            {
  65                XmlWriter::append(out, x);
  66                return out;
  67            }
  68            
  69            Array<Sint8>& operator<<(Array<Sint8>& out, char x)
  70            {
  71                XmlWriter::append(out, x);
  72                return out;
  73            }
  74            
  75 kumpf 1.75 Array<Sint8>& operator<<(Array<Sint8>& out, const Char16& x)
  76 kumpf 1.27 {
  77                XmlWriter::append(out, x);
  78                return out;
  79            }
  80            
  81            Array<Sint8>& operator<<(Array<Sint8>& out, const String& x)
  82            {
  83                XmlWriter::append(out, x);
  84                return out;
  85            }
  86            
  87            Array<Sint8>& operator<<(Array<Sint8>& out, const Indentor& x)
  88            {
  89                XmlWriter::append(out, x);
  90                return out;
  91            }
  92            
  93            Array<Sint8>& operator<<(Array<Sint8>& out, const Array<Sint8>& x)
  94            {
  95                out.appendArray(x);
  96                return out;
  97 kumpf 1.27 }
  98            
  99            Array<Sint8>& operator<<(Array<Sint8>& out, Uint32 x)
 100            {
 101                XmlWriter::append(out, x);
 102                return out;
 103            }
 104            
 105 kumpf 1.80 Array<Sint8>& operator<<(Array<Sint8>& out, const CIMName& name)
 106            {
 107                XmlWriter::append(out, name.getString ());
 108                return out;
 109            }
 110            
 111 kumpf 1.72 PEGASUS_STD(ostream)& operator<<(PEGASUS_STD(ostream)& os, const CIMDateTime& x)
 112            {
 113                return os << x.toString();
 114            }
 115            
 116 kumpf 1.80 PEGASUS_STD(ostream)& operator<<(PEGASUS_STD(ostream)& os, const CIMName& name)
 117            {
 118                os << name.getString();
 119                return os;
 120            }
 121            
 122            PEGASUS_STD(ostream)& operator<<(PEGASUS_STD(ostream)& os,
 123                const CIMNamespaceName& name)
 124            {
 125                os << name.getString();
 126                return os;
 127            }
 128            
 129 kumpf 1.75 inline void _appendChar(Array<Sint8>& out, const Char16& c)
 130 mike  1.23 {
 131                out.append(Sint8(c));
 132            }
 133            
 134 kumpf 1.75 inline void _appendSpecialChar(Array<Sint8>& out, const Char16& c)
 135 mike  1.23 {
 136                // ATTN-B: Only UTF-8 handled for now.
 137            
 138                switch (c)
 139                {
 140            	case '&':
 141            	    out.append("&amp;", 5);
 142            	    break;
 143            
 144            	case '<':
 145            	    out.append("&lt;", 4);
 146            	    break;
 147            
 148            	case '>':
 149            	    out.append("&gt;", 4);
 150            	    break;
 151            
 152            	case '"':
 153            	    out.append("&quot;", 6);
 154            	    break;
 155            
 156 mike  1.23 	case '\'':
 157            	    out.append("&apos;", 6);
 158            	    break;
 159            
 160            	default:
 161            	    out.append(Sint8(c));
 162                }
 163            }
 164            
 165 kumpf 1.27 static inline void _appendSpecialChar(PEGASUS_STD(ostream)& os, char c)
 166            {
 167                switch (c)
 168                {
 169            	case '&':
 170            	    os << "&amp;";
 171            	    break;
 172            
 173            	case '<':
 174            	    os << "&lt;";
 175            	    break;
 176            
 177            	case '>':
 178            	    os << "&gt;";
 179            	    break;
 180            
 181            	case '"':
 182            	    os << "&quot;";
 183            	    break;
 184            
 185            	case '\'':
 186 kumpf 1.27 	    os << "&apos;";
 187            	    break;
 188            
 189            	default:
 190            	    os << c;
 191                }
 192            }
 193            
 194            static inline void _appendSpecial(PEGASUS_STD(ostream)& os, const char* str)
 195            {
 196                while (*str)
 197            	_appendSpecialChar(os, *str++);
 198            }
 199            
 200 kumpf 1.75 void XmlWriter::append(Array<Sint8>& out, const Char16& x)
 201 mike  1.23 {
 202 kumpf 1.27     _appendChar(out, x);
 203 mike  1.23 }
 204            
 205 kumpf 1.54 void XmlWriter::append(Array<Sint8>& out, Boolean x)
 206            {
 207                append(out, (x ? "TRUE" : "FALSE"));
 208            }
 209            
 210 mike  1.23 void XmlWriter::append(Array<Sint8>& out, Uint32 x)
 211            {
 212                char buffer[32];
 213 kumpf 1.54     sprintf(buffer, "%u", x);
 214                append(out, buffer);
 215            }
 216            
 217            void XmlWriter::append(Array<Sint8>& out, Sint32 x)
 218            {
 219                char buffer[32];
 220 mike  1.23     sprintf(buffer, "%d", x);
 221                append(out, buffer);
 222            }
 223            
 224 kumpf 1.54 void XmlWriter::append(Array<Sint8>& out, Uint64 x)
 225            {
 226                char buffer[32];  // Should need 21 chars max
 227                // I know I shouldn't put platform flags here, but the other way is too hard
 228            #if defined(PEGASUS_PLATFORM_WIN32_IX86_MSVC)
 229                sprintf(buffer, "%I64u", x);
 230            #else
 231                sprintf(buffer, "%llu", x);
 232            #endif
 233                append(out, buffer);
 234            }
 235            
 236            void XmlWriter::append(Array<Sint8>& out, Sint64 x)
 237            {
 238                char buffer[32];  // Should need 21 chars max
 239                // I know I shouldn't put platform flags here, but the other way is too hard
 240            #if defined(PEGASUS_PLATFORM_WIN32_IX86_MSVC)
 241                sprintf(buffer, "%I64d", x);
 242            #else
 243                sprintf(buffer, "%lld", x);
 244            #endif
 245 kumpf 1.54     append(out, buffer);
 246            }
 247            
 248            void XmlWriter::append(Array<Sint8>& out, Real64 x)
 249            {
 250                char buffer[128];
 251                // %e gives '[-]m.dddddde+/-xx', which seems compatible with CIM/XML spec
 252                sprintf(buffer, "%e", x);
 253                append(out, buffer);
 254            }
 255            
 256 mike  1.23 void XmlWriter::append(Array<Sint8>& out, const char* str)
 257            {
 258                while (*str)
 259 kumpf 1.27 	_appendChar(out, *str++);
 260            }
 261            
 262            void XmlWriter::append(Array<Sint8>& out, const String& str)
 263            {
 264 kumpf 1.64     for (Uint32 i = 0; i < str.size(); i++)
 265                {
 266                    _appendChar(out, str[i]);
 267                }
 268 kumpf 1.27 }
 269            
 270            void XmlWriter::append(Array<Sint8>& out, const Indentor& x)
 271            {
 272                for (Uint32 i = 0; i < 4 * x.getLevel(); i++)
 273            	out.append(' ');
 274 mike  1.23 }
 275            
 276 kumpf 1.75 void XmlWriter::appendSpecial(Array<Sint8>& out, const Char16& x)
 277 mike  1.23 {
 278 kumpf 1.27     _appendSpecialChar(out, x);
 279 mike  1.23 }
 280            
 281            void XmlWriter::appendSpecial(Array<Sint8>& out, char x)
 282            {
 283 kumpf 1.27     _appendSpecialChar(out, Char16(x));
 284 mike  1.23 }
 285            
 286            void XmlWriter::appendSpecial(Array<Sint8>& out, const char* str)
 287            {
 288                while (*str)
 289 kumpf 1.27 	_appendSpecialChar(out, *str++);
 290 mike  1.23 }
 291            
 292            void XmlWriter::appendSpecial(Array<Sint8>& out, const String& str)
 293            {
 294 kumpf 1.64     for (Uint32 i = 0; i < str.size(); i++)
 295                {
 296                    _appendSpecialChar(out, str[i]);
 297                }
 298 mike  1.23 }
 299            
 300 kumpf 1.29 //------------------------------------------------------------------------------
 301            //
 302            // appendLocalNameSpacePathElement()
 303            //
 304            //     <!ELEMENT LOCALNAMESPACEPATH (NAMESPACE+)>
 305            //
 306            //------------------------------------------------------------------------------
 307            
 308            void XmlWriter::appendLocalNameSpacePathElement(
 309                Array<Sint8>& out,
 310 kumpf 1.80     const CIMNamespaceName& nameSpace)
 311 mike  1.23 {
 312                out << "<LOCALNAMESPACEPATH>\n";
 313            
 314 kumpf 1.80     char* nameSpaceCopy = strdup(nameSpace.getString().getCString());
 315 kumpf 1.76     for (const char* p = strtok(nameSpaceCopy, "/"); p; p = strtok(NULL, "/"))
 316 mike  1.23     {
 317            	out << "<NAMESPACE NAME=\"" << p << "\"/>\n";
 318                }
 319 kumpf 1.76     delete nameSpaceCopy;
 320 mike  1.23 
 321                out << "</LOCALNAMESPACEPATH>\n";
 322            }
 323            
 324            //------------------------------------------------------------------------------
 325            //
 326 kumpf 1.29 // appendNameSpacePathElement()
 327            //
 328            //     <!ELEMENT NAMESPACEPATH (HOST,LOCALNAMESPACEPATH)>
 329            //
 330            //------------------------------------------------------------------------------
 331            
 332            void XmlWriter::appendNameSpacePathElement(
 333                Array<Sint8>& out,
 334                const String& host,
 335 kumpf 1.80     const CIMNamespaceName& nameSpace)
 336 kumpf 1.29 {
 337                out << "<NAMESPACEPATH>\n";
 338                out << "<HOST>" << host << "</HOST>\n";
 339                appendLocalNameSpacePathElement(out, nameSpace);
 340                out << "</NAMESPACEPATH>\n";
 341            }
 342            
 343            //------------------------------------------------------------------------------
 344            //
 345            // appendClassNameElement()
 346            //
 347            //     <!ELEMENT CLASSNAME EMPTY>
 348            //     <!ATTLIST CLASSNAME
 349            //              %CIMName;>
 350            //
 351            //------------------------------------------------------------------------------
 352            
 353            void XmlWriter::appendClassNameElement(
 354                Array<Sint8>& out,
 355 kumpf 1.80     const CIMName& className)
 356 kumpf 1.29 {
 357                out << "<CLASSNAME NAME=\"" << className << "\"/>\n";
 358            }
 359            
 360            //------------------------------------------------------------------------------
 361            //
 362            // appendInstanceNameElement()
 363            //
 364            //    <!ELEMENT INSTANCENAME (KEYBINDING*|KEYVALUE?|VALUE.REFERENCE?)>
 365            //    <!ATTLIST INSTANCENAME
 366            //              %ClassName;>
 367            //
 368            //------------------------------------------------------------------------------
 369            
 370            void XmlWriter::appendInstanceNameElement(
 371                Array<Sint8>& out,
 372 kumpf 1.59     const CIMObjectPath& instanceName)
 373 kumpf 1.29 {
 374                out << "<INSTANCENAME CLASSNAME=\"" << instanceName.getClassName() << "\">\n";
 375            
 376 kumpf 1.79     Array<CIMKeyBinding> keyBindings = instanceName.getKeyBindings();
 377 kumpf 1.29     for (Uint32 i = 0, n = keyBindings.size(); i < n; i++)
 378                {
 379                    out << "<KEYBINDING NAME=\"" << keyBindings[i].getName() << "\">\n";
 380            
 381 kumpf 1.79         if (keyBindings[i].getType() == CIMKeyBinding::REFERENCE)
 382 kumpf 1.29         {
 383 kumpf 1.59             CIMObjectPath ref = keyBindings[i].getValue();
 384 kumpf 1.56             appendValueReferenceElement(out, ref, true);
 385 kumpf 1.29         }
 386                    else {
 387                        out << "<KEYVALUE VALUETYPE=\"";
 388 kumpf 1.68             out << keyBindingTypeToString(keyBindings[i].getType());
 389 kumpf 1.29             out << "\">";
 390            
 391                        // fixed the special character problem - Markus
 392            
 393                        appendSpecial(out, keyBindings[i].getValue());
 394                        out << "</KEYVALUE>\n";
 395                    }
 396                    out << "</KEYBINDING>\n";
 397                }
 398                out << "</INSTANCENAME>\n";
 399            }
 400            
 401            //------------------------------------------------------------------------------
 402            //
 403            // appendClassPathElement()
 404            //
 405            //     <!ELEMENT CLASSPATH (NAMESPACEPATH,CLASSNAME)>
 406            //
 407            //------------------------------------------------------------------------------
 408            
 409            void XmlWriter::appendClassPathElement(
 410 kumpf 1.29     Array<Sint8>& out, 
 411 kumpf 1.59     const CIMObjectPath& classPath)
 412 kumpf 1.29 {
 413                out << "<CLASSPATH>\n";
 414                appendNameSpacePathElement(out,
 415                                           classPath.getHost(),
 416                                           classPath.getNameSpace());
 417                appendClassNameElement(out, classPath.getClassName());
 418                out << "</CLASSPATH>\n";
 419            }
 420            
 421            //------------------------------------------------------------------------------
 422            //
 423            // appendInstancePathElement()
 424            //
 425            //     <!ELEMENT INSTANCEPATH (NAMESPACEPATH,INSTANCENAME)>
 426            //
 427            //------------------------------------------------------------------------------
 428            
 429            void XmlWriter::appendInstancePathElement(
 430                Array<Sint8>& out, 
 431 kumpf 1.59     const CIMObjectPath& instancePath)
 432 kumpf 1.29 {
 433                out << "<INSTANCEPATH>\n";
 434                appendNameSpacePathElement(out,
 435                                           instancePath.getHost(),
 436                                           instancePath.getNameSpace());
 437                appendInstanceNameElement(out, instancePath);
 438                out << "</INSTANCEPATH>\n";
 439            }
 440            
 441            //------------------------------------------------------------------------------
 442            //
 443            // appendLocalClassPathElement()
 444            //
 445            //     <!ELEMENT LOCALCLASSPATH (LOCALNAMESPACEPATH, CLASSNAME)>
 446            //
 447            //------------------------------------------------------------------------------
 448            
 449            void XmlWriter::appendLocalClassPathElement(
 450                Array<Sint8>& out, 
 451 kumpf 1.59     const CIMObjectPath& classPath)
 452 kumpf 1.29 {
 453                out << "<LOCALCLASSPATH>\n";
 454                appendLocalNameSpacePathElement(out, classPath.getNameSpace());
 455                appendClassNameElement(out, classPath.getClassName());
 456                out << "</LOCALCLASSPATH>\n";
 457            }
 458            
 459            //------------------------------------------------------------------------------
 460            //
 461            // appendLocalInstancePathElement()
 462            //
 463            //     <!ELEMENT LOCALINSTANCEPATH (LOCALNAMESPACEPATH, INSTANCENAME)>
 464            //
 465            //------------------------------------------------------------------------------
 466            
 467            void XmlWriter::appendLocalInstancePathElement(
 468                Array<Sint8>& out, 
 469 kumpf 1.59     const CIMObjectPath& instancePath)
 470 kumpf 1.29 {
 471                out << "<LOCALINSTANCEPATH>\n";
 472                appendLocalNameSpacePathElement(out, instancePath.getNameSpace());
 473                appendInstanceNameElement(out, instancePath);
 474                out << "</LOCALINSTANCEPATH>\n";
 475            }
 476            
 477            //------------------------------------------------------------------------------
 478            //
 479 kumpf 1.30 // appendLocalObjectPathElement()
 480            //
 481 kumpf 1.31 //     If the reference refers to an instance, write a LOCALINSTANCEPATH;
 482            //     otherwise write a LOCALCLASSPATH.
 483 kumpf 1.30 //
 484            //------------------------------------------------------------------------------
 485            
 486            void XmlWriter::appendLocalObjectPathElement(
 487                Array<Sint8>& out, 
 488 kumpf 1.59     const CIMObjectPath& objectPath)
 489 kumpf 1.30 {
 490 kumpf 1.68     //
 491                //  ATTN-CAKG-P2-20020726:  The following condition does not correctly
 492                //  distinguish instanceNames from classNames in every case
 493                //  The instanceName of a singleton instance of a keyless class has no 
 494                //  key bindings
 495                //
 496                if (objectPath.getKeyBindings ().size () != 0)
 497 kumpf 1.30     {
 498                    appendLocalInstancePathElement(out, objectPath);
 499                }
 500                else
 501                {
 502                    appendLocalClassPathElement(out, objectPath);
 503                }
 504            }
 505            
 506            //------------------------------------------------------------------------------
 507            //
 508 kumpf 1.54 // Helper functions for appendValueElement()
 509            //
 510            //------------------------------------------------------------------------------
 511            
 512            inline void _appendValue(Array<Sint8>& out, Boolean x)
 513            {
 514                XmlWriter::append(out, x);
 515            }
 516            
 517            inline void _appendValue(Array<Sint8>& out, Uint8 x)
 518            {
 519                XmlWriter::append(out, Uint32(x));
 520            }
 521            
 522            inline void _appendValue(Array<Sint8>& out, Sint8 x)
 523            {
 524                XmlWriter::append(out, Sint32(x));
 525            }
 526            
 527            inline void _appendValue(Array<Sint8>& out, Uint16 x)
 528            {
 529 kumpf 1.54     XmlWriter::append(out, Uint32(x));
 530            }
 531            
 532            inline void _appendValue(Array<Sint8>& out, Sint16 x)
 533            {
 534                XmlWriter::append(out, Sint32(x));
 535            }
 536            
 537            inline void _appendValue(Array<Sint8>& out, Uint32 x)
 538            {
 539                XmlWriter::append(out, x);
 540            }
 541            
 542            inline void _appendValue(Array<Sint8>& out, Sint32 x)
 543            {
 544                XmlWriter::append(out, x);
 545            }
 546            
 547            inline void _appendValue(Array<Sint8>& out, Uint64 x)
 548            {
 549                XmlWriter::append(out, x);
 550 kumpf 1.54 }
 551            
 552            inline void _appendValue(Array<Sint8>& out, Sint64 x)
 553            {
 554                XmlWriter::append(out, x);
 555            }
 556            
 557            inline void _appendValue(Array<Sint8>& out, Real32 x)
 558            {
 559                XmlWriter::append(out, Real64(x));
 560            }
 561            
 562            inline void _appendValue(Array<Sint8>& out, Real64 x)
 563            {
 564                XmlWriter::append(out, x);
 565            }
 566            
 567 kumpf 1.75 inline void _appendValue(Array<Sint8>& out, const Char16& x)
 568 kumpf 1.54 {
 569                XmlWriter::appendSpecial(out, x);
 570            }
 571            
 572            inline void _appendValue(Array<Sint8>& out, const String& x)
 573            {
 574                XmlWriter::appendSpecial(out, x);
 575            }
 576            
 577            inline void _appendValue(Array<Sint8>& out, const CIMDateTime& x)
 578            {
 579 kumpf 1.72     out << x.toString();  //ATTN: append() method?
 580 kumpf 1.54 }
 581            
 582 kumpf 1.59 inline void _appendValue(Array<Sint8>& out, const CIMObjectPath& x)
 583 kumpf 1.54 {
 584 kumpf 1.56     XmlWriter::appendValueReferenceElement(out, x, true);
 585 kumpf 1.54 }
 586            
 587 kumpf 1.59 void _appendValueArray(Array<Sint8>& out, const CIMObjectPath* p, Uint32 size)
 588 kumpf 1.54 {
 589                out << "<VALUE.REFARRAY>\n";
 590                while (size--)
 591                {
 592                    _appendValue(out, *p++);
 593                }
 594                out << "</VALUE.REFARRAY>\n";
 595            }
 596            
 597            template<class T>
 598            void _appendValueArray(Array<Sint8>& out, const T* p, Uint32 size)
 599            {
 600                out << "<VALUE.ARRAY>\n";
 601            
 602                while (size--)
 603                {
 604                    out << "<VALUE>";
 605                    _appendValue(out, *p++);
 606                    out << "</VALUE>\n";
 607                }
 608            
 609 kumpf 1.54     out << "</VALUE.ARRAY>\n";
 610            }
 611            
 612            //------------------------------------------------------------------------------
 613            //
 614            // appendValueElement()
 615            //
 616 kumpf 1.55 //    <!ELEMENT VALUE (#PCDATA)>
 617            //    <!ELEMENT VALUE.ARRAY (VALUE*)>
 618            //    <!ELEMENT VALUE.REFERENCE
 619            //        (CLASSPATH|LOCALCLASSPATH|CLASSNAME|INSTANCEPATH|LOCALINSTANCEPATH|
 620            //         INSTANCENAME)>
 621            //    <!ELEMENT VALUE.REFARRAY (VALUE.REFERENCE*)>
 622            //
 623 kumpf 1.54 //------------------------------------------------------------------------------
 624            
 625            void XmlWriter::appendValueElement(
 626 kumpf 1.56     Array<Sint8>& out,
 627 kumpf 1.54     const CIMValue& value)
 628            {
 629                if (value.isNull())
 630                {
 631                    return;
 632                }
 633                if (value.isArray())
 634                {
 635                    switch (value.getType())
 636                    {
 637 kumpf 1.66             case CIMTYPE_BOOLEAN:
 638 kumpf 1.54             {
 639                            Array<Boolean> a;
 640                            value.get(a);
 641                            _appendValueArray(out, a.getData(), a.size());
 642                            break;
 643                        }
 644            
 645 kumpf 1.66             case CIMTYPE_UINT8:
 646 kumpf 1.54             {
 647                            Array<Uint8> a;
 648                            value.get(a);
 649                            _appendValueArray(out, a.getData(), a.size());
 650                            break;
 651                        }
 652            
 653 kumpf 1.66             case CIMTYPE_SINT8:
 654 kumpf 1.54             {
 655                            Array<Sint8> a;
 656                            value.get(a);
 657                            _appendValueArray(out, a.getData(), a.size());
 658                            break;
 659                        }
 660            
 661 kumpf 1.66             case CIMTYPE_UINT16:
 662 kumpf 1.54             {
 663                            Array<Uint16> a;
 664                            value.get(a);
 665                            _appendValueArray(out, a.getData(), a.size());
 666                            break;
 667                        }
 668            
 669 kumpf 1.66             case CIMTYPE_SINT16:
 670 kumpf 1.54             {
 671                            Array<Sint16> a;
 672                            value.get(a);
 673                            _appendValueArray(out, a.getData(), a.size());
 674                            break;
 675                        }
 676            
 677 kumpf 1.66             case CIMTYPE_UINT32:
 678 kumpf 1.54             {
 679                            Array<Uint32> a;
 680                            value.get(a);
 681                            _appendValueArray(out, a.getData(), a.size());
 682                            break;
 683                        }
 684            
 685 kumpf 1.66             case CIMTYPE_SINT32:
 686 kumpf 1.54             {
 687                            Array<Sint32> a;
 688                            value.get(a);
 689                            _appendValueArray(out, a.getData(), a.size());
 690                            break;
 691                        }
 692            
 693 kumpf 1.66             case CIMTYPE_UINT64:
 694 kumpf 1.54             {
 695                            Array<Uint64> a;
 696                            value.get(a);
 697                            _appendValueArray(out, a.getData(), a.size());
 698                            break;
 699                        }
 700            
 701 kumpf 1.66             case CIMTYPE_SINT64:
 702 kumpf 1.54             {
 703                            Array<Sint64> a;
 704                            value.get(a);
 705                            _appendValueArray(out, a.getData(), a.size());
 706                            break;
 707                        }
 708            
 709 kumpf 1.66             case CIMTYPE_REAL32:
 710 kumpf 1.54             {
 711                            Array<Real32> a;
 712                            value.get(a);
 713                            _appendValueArray(out, a.getData(), a.size());
 714                            break;
 715                        }
 716            
 717 kumpf 1.66             case CIMTYPE_REAL64:
 718 kumpf 1.54             {
 719                            Array<Real64> a;
 720                            value.get(a);
 721                            _appendValueArray(out, a.getData(), a.size());
 722                            break;
 723                        }
 724            
 725 kumpf 1.66             case CIMTYPE_CHAR16:
 726 kumpf 1.54             {
 727                            Array<Char16> a;
 728                            value.get(a);
 729                            _appendValueArray(out, a.getData(), a.size());
 730                            break;
 731                        }
 732            
 733 kumpf 1.66             case CIMTYPE_STRING:
 734 kumpf 1.54             {
 735                            Array<String> a;
 736                            value.get(a);
 737                            _appendValueArray(out, a.getData(), a.size());
 738                            break;
 739                        }
 740            
 741 kumpf 1.66             case CIMTYPE_DATETIME:
 742 kumpf 1.54             {
 743                            Array<CIMDateTime> a;
 744                            value.get(a);
 745                            _appendValueArray(out, a.getData(), a.size());
 746                            break;
 747                        }
 748            
 749 kumpf 1.66             case CIMTYPE_REFERENCE:
 750 kumpf 1.54             {
 751 kumpf 1.59                 Array<CIMObjectPath> a;
 752 kumpf 1.54                 value.get(a);
 753                            _appendValueArray(out, a.getData(), a.size());
 754                            break;
 755                        }
 756            
 757                        default:
 758 kumpf 1.78                 PEGASUS_ASSERT(false);
 759 kumpf 1.54         }
 760                }
 761 kumpf 1.66     else if (value.getType() == CIMTYPE_REFERENCE)
 762 kumpf 1.54     {
 763                    // Has to be separate because it uses VALUE.REFERENCE tag
 764 kumpf 1.59         CIMObjectPath v;
 765 kumpf 1.54         value.get(v);
 766                    _appendValue(out, v);
 767                }
 768                else
 769                {
 770                    out << "<VALUE>";
 771            
 772                    switch (value.getType())
 773                    {
 774 kumpf 1.66             case CIMTYPE_BOOLEAN:
 775 kumpf 1.54             {
 776                            Boolean v;
 777                            value.get(v);
 778                            _appendValue(out, v);
 779                            break;
 780                        }
 781            
 782 kumpf 1.66             case CIMTYPE_UINT8:
 783 kumpf 1.54             {
 784                            Uint8 v;
 785                            value.get(v);
 786                            _appendValue(out, v);
 787                            break;
 788                        }
 789            
 790 kumpf 1.66             case CIMTYPE_SINT8:
 791 kumpf 1.54             {
 792                            Sint8 v;
 793                            value.get(v);
 794                            _appendValue(out, v);
 795                            break;
 796                        }
 797            
 798 kumpf 1.66             case CIMTYPE_UINT16:
 799 kumpf 1.54             {
 800                            Uint16 v;
 801                            value.get(v);
 802                            _appendValue(out, v);
 803                            break;
 804                        }
 805            
 806 kumpf 1.66             case CIMTYPE_SINT16:
 807 kumpf 1.54             {
 808                            Sint16 v;
 809                            value.get(v);
 810                            _appendValue(out, v);
 811                            break;
 812                        }
 813            
 814 kumpf 1.66             case CIMTYPE_UINT32:
 815 kumpf 1.54             {
 816                            Uint32 v;
 817                            value.get(v);
 818                            _appendValue(out, v);
 819                            break;
 820                        }
 821            
 822 kumpf 1.66             case CIMTYPE_SINT32:
 823 kumpf 1.54             {
 824                            Sint32 v;
 825                            value.get(v);
 826                            _appendValue(out, v);
 827                            break;
 828                        }
 829            
 830 kumpf 1.66             case CIMTYPE_UINT64:
 831 kumpf 1.54             {
 832                            Uint64 v;
 833                            value.get(v);
 834                            _appendValue(out, v);
 835                            break;
 836                        }
 837            
 838 kumpf 1.66             case CIMTYPE_SINT64:
 839 kumpf 1.54             {
 840                            Sint64 v;
 841                            value.get(v);
 842                            _appendValue(out, v);
 843                            break;
 844                        }
 845            
 846 kumpf 1.66             case CIMTYPE_REAL32:
 847 kumpf 1.54             {
 848                            Real32 v;
 849                            value.get(v);
 850                            _appendValue(out, v);
 851                            break;
 852                        }
 853            
 854 kumpf 1.66             case CIMTYPE_REAL64:
 855 kumpf 1.54             {
 856                            Real64 v;
 857                            value.get(v);
 858                            _appendValue(out, v);
 859                            break;
 860                        }
 861            
 862 kumpf 1.66             case CIMTYPE_CHAR16:
 863 kumpf 1.54             {
 864                            Char16 v;
 865                            value.get(v);
 866                            _appendValue(out, v);
 867                            break;
 868                        }
 869            
 870 kumpf 1.66             case CIMTYPE_STRING:
 871 kumpf 1.54             {
 872                            String v;
 873                            value.get(v);
 874                            _appendValue(out, v);
 875                            break;
 876                        }
 877            
 878 kumpf 1.66             case CIMTYPE_DATETIME:
 879 kumpf 1.54             {
 880                            CIMDateTime v;
 881                            value.get(v);
 882                            _appendValue(out, v);
 883                            break;
 884                        }
 885            
 886                        default:
 887 kumpf 1.78                 PEGASUS_ASSERT(false);
 888 kumpf 1.54         }
 889            
 890                    out << "</VALUE>\n";
 891                }
 892            }
 893            
 894            void XmlWriter::printValueElement(
 895                const CIMValue& value,
 896                PEGASUS_STD(ostream)& os)
 897            {
 898                Array<Sint8> tmp;
 899                appendValueElement(tmp, value);
 900                tmp.append('\0');
 901                os << tmp.getData() << PEGASUS_STD(endl);
 902            }
 903            
 904            //------------------------------------------------------------------------------
 905            //
 906 kumpf 1.56 // appendValueObjectWithPathElement()
 907            //
 908            //     <!ELEMENT VALUE.OBJECTWITHPATH
 909            //         ((CLASSPATH,CLASS)|(INSTANCEPATH,INSTANCE))>
 910            //
 911            //------------------------------------------------------------------------------
 912            
 913            void XmlWriter::appendValueObjectWithPathElement(
 914                Array<Sint8>& out,
 915 kumpf 1.62     const CIMObject& objectWithPath)
 916 kumpf 1.56 {
 917                out << "<VALUE.OBJECTWITHPATH>\n";
 918            
 919 kumpf 1.62     appendValueReferenceElement(out, objectWithPath.getPath (), false);
 920                appendObjectElement(out, objectWithPath);
 921 kumpf 1.56 
 922                out << "</VALUE.OBJECTWITHPATH>\n";
 923            }
 924            
 925            //------------------------------------------------------------------------------
 926            //
 927            // appendValueReferenceElement()
 928            //
 929            //    <!ELEMENT VALUE.REFERENCE
 930            //        (CLASSPATH|LOCALCLASSPATH|CLASSNAME|INSTANCEPATH|LOCALINSTANCEPATH|
 931            //         INSTANCENAME)>
 932            //
 933            //------------------------------------------------------------------------------
 934            
 935            void XmlWriter::appendValueReferenceElement(
 936                Array<Sint8>& out,
 937 kumpf 1.59     const CIMObjectPath& reference,
 938 kumpf 1.56     Boolean putValueWrapper)
 939            {
 940                if (putValueWrapper)
 941                    out << "<VALUE.REFERENCE>\n";
 942            
 943                // See if it is a class or instance reference (instance references have
 944                // key-bindings; class references do not).
 945 kumpf 1.68     //
 946                //  ATTN-CAKG-P2-20020726:  The following condition does not correctly
 947                //  distinguish instanceNames from classNames in every case
 948                //  The instanceName of a singleton instance of a keyless class has no
 949                //  key bindings
 950                //
 951 kumpf 1.56 
 952 kumpf 1.79     Array<CIMKeyBinding> kbs = reference.getKeyBindings();
 953 sage  1.60 
 954 kumpf 1.56     if (kbs.size())
 955                {
 956                    if (reference.getHost().size())
 957                    {
 958                        appendInstancePathElement(out, reference);
 959                    }
 960 kumpf 1.67         else if (!reference.getNameSpace().isNull())
 961 kumpf 1.56         {
 962                        appendLocalInstancePathElement(out, reference);
 963                    }
 964                    else
 965                    {
 966                        appendInstanceNameElement(out, reference);
 967                    }
 968                }
 969                else
 970                {
 971                    if (reference.getHost().size())
 972                    {
 973                        appendClassPathElement(out, reference);
 974                    }
 975 kumpf 1.67         else if (!reference.getNameSpace().isNull())
 976 kumpf 1.56         {
 977                        appendLocalClassPathElement(out, reference);
 978                    }
 979                    else
 980                    {
 981                        appendClassNameElement(out, reference.getClassName());
 982                    }
 983                }
 984            
 985                if (putValueWrapper)
 986                    out << "</VALUE.REFERENCE>\n";
 987            }
 988            
 989            void XmlWriter::printValueReferenceElement(
 990 kumpf 1.59     const CIMObjectPath& reference,
 991 kumpf 1.56     PEGASUS_STD(ostream)& os)
 992            {
 993                Array<Sint8> tmp;
 994                appendValueReferenceElement(tmp, reference, true);
 995                tmp.append('\0');
 996                indentedPrint(os, tmp.getData());
 997            }
 998            
 999            //------------------------------------------------------------------------------
1000            //
1001            // appendValueNamedInstanceElement()
1002            //
1003            //     <!ELEMENT VALUE.NAMEDINSTANCE (INSTANCENAME,INSTANCE)>
1004            //
1005            //------------------------------------------------------------------------------
1006            
1007            void XmlWriter::appendValueNamedInstanceElement(
1008                Array<Sint8>& out,
1009 kumpf 1.61     const CIMInstance& namedInstance)
1010 kumpf 1.56 {
1011                out << "<VALUE.NAMEDINSTANCE>\n";
1012            
1013 kumpf 1.61     appendInstanceNameElement(out, namedInstance.getPath ());
1014                appendInstanceElement(out, namedInstance);
1015 kumpf 1.56 
1016                out << "</VALUE.NAMEDINSTANCE>\n";
1017            }
1018            
1019            //------------------------------------------------------------------------------
1020            //
1021 kumpf 1.55 // appendClassElement()
1022            //
1023            //     <!ELEMENT CLASS
1024            //         (QUALIFIER*,(PROPERTY|PROPERTY.ARRAY|PROPERTY.REFERENCE)*,METHOD*)>
1025 kumpf 1.56 //     <!ATTLIST CLASS
1026 kumpf 1.55 //         %CIMName;
1027            //         %SuperClass;>
1028            //
1029            //------------------------------------------------------------------------------
1030            
1031            void XmlWriter::appendClassElement(
1032 kumpf 1.56     Array<Sint8>& out,
1033 kumpf 1.55     const CIMConstClass& cimclass)
1034            {
1035                cimclass._checkRep();
1036                cimclass._rep->toXml(out);
1037            }
1038            
1039            void XmlWriter::printClassElement(
1040                const CIMConstClass& cimclass,
1041                PEGASUS_STD(ostream)& os)
1042            {
1043                Array<Sint8> tmp;
1044                appendClassElement(tmp, cimclass);
1045                tmp.append('\0');
1046                indentedPrint(os, tmp.getData(), 4);
1047            }
1048            
1049            //------------------------------------------------------------------------------
1050            //
1051            // appendInstanceElement()
1052            //
1053            //     <!ELEMENT INSTANCE
1054 kumpf 1.55 //         (QUALIFIER*,(PROPERTY|PROPERTY.ARRAY|PROPERTY.REFERENCE)*)>
1055            //     <!ATTLIST INSTANCE
1056            //         %ClassName;>
1057            //
1058            //------------------------------------------------------------------------------
1059            
1060            void XmlWriter::appendInstanceElement(
1061 kumpf 1.56     Array<Sint8>& out,
1062 kumpf 1.55     const CIMConstInstance& instance)
1063            {
1064                instance._checkRep();
1065                instance._rep->toXml(out);
1066            }
1067            
1068            void XmlWriter::printInstanceElement(
1069                const CIMConstInstance& instance,
1070                PEGASUS_STD(ostream)& os)
1071            {
1072                Array<Sint8> tmp;
1073                appendInstanceElement(tmp, instance);
1074                tmp.append('\0');
1075                os << tmp.getData() << PEGASUS_STD(endl);
1076            }
1077            
1078            //------------------------------------------------------------------------------
1079            //
1080 kumpf 1.56 // appendObjectElement()
1081            //
1082            // May refer to a CLASS or an INSTANCE
1083            //
1084            //------------------------------------------------------------------------------
1085            
1086            void XmlWriter::appendObjectElement(
1087                Array<Sint8>& out,
1088                const CIMConstObject& object)
1089            {
1090 kumpf 1.73     if (object.isClass())
1091 kumpf 1.56     {
1092                    CIMConstClass c(object);
1093                    appendClassElement(out, c);
1094                }
1095 kumpf 1.73     else if (object.isInstance())
1096 kumpf 1.56     {
1097 kumpf 1.73         CIMConstInstance i(object);
1098                    appendInstanceElement(out, i);
1099 kumpf 1.56     }
1100 kumpf 1.73     // else PEGASUS_ASSERT(0);
1101 kumpf 1.56 }
1102            
1103            //------------------------------------------------------------------------------
1104            //
1105            // appendPropertyElement()
1106            //
1107            //     <!ELEMENT PROPERTY (QUALIFIER*,VALUE?)>
1108            //     <!ATTLIST PROPERTY
1109            //              %CIMName;
1110            //              %CIMType;           #REQUIRED
1111            //              %ClassOrigin;
1112            //              %Propagated;>
1113            //
1114            //     <!ELEMENT PROPERTY.ARRAY (QUALIFIER*,VALUE.ARRAY?)>
1115            //     <!ATTLIST PROPERTY.ARRAY
1116            //              %CIMName;
1117            //              %CIMType;           #REQUIRED
1118            //              %ArraySize;
1119            //              %ClassOrigin;
1120            //              %Propagated;>
1121            //
1122 kumpf 1.56 //     <!ELEMENT PROPERTY.REFERENCE (QUALIFIER*,VALUE.REFERENCE?)>
1123            //     <!ATTLIST PROPERTY.REFERENCE
1124            //              %CIMName;
1125            //              %ReferenceClass;
1126            //              %ClassOrigin;
1127            //              %Propagated;>
1128            //
1129            //------------------------------------------------------------------------------
1130            
1131            void XmlWriter::appendPropertyElement(
1132                Array<Sint8>& out,
1133                const CIMConstProperty& property)
1134            {
1135                property._checkRep();
1136                property._rep->toXml(out);
1137            }
1138            
1139            void XmlWriter::printPropertyElement(
1140                const CIMConstProperty& property,
1141                PEGASUS_STD(ostream)& os)
1142            {
1143 kumpf 1.56     Array<Sint8> tmp;
1144                appendPropertyElement(tmp, property);
1145                tmp.append('\0');
1146                os << tmp.getData() << PEGASUS_STD(endl);
1147            }
1148            
1149            //------------------------------------------------------------------------------
1150            //
1151            // appendMethodElement()
1152            //
1153            //     <!ELEMENT METHOD (QUALIFIER*,
1154            //         (PARAMETER|PARAMETER.REFERENCE|PARAMETER.ARRAY|PARAMETER.REFARRAY)*)>
1155            //     <!ATTLIST METHOD
1156            //              %CIMName;
1157            //              %CIMType;          #IMPLIED
1158            //              %ClassOrigin;
1159            //              %Propagated;>
1160            //
1161            //------------------------------------------------------------------------------
1162            
1163            void XmlWriter::appendMethodElement(
1164 kumpf 1.56     Array<Sint8>& out,
1165                const CIMConstMethod& method)
1166            {
1167                method._checkRep();
1168                method._rep->toXml(out);
1169            }
1170            
1171            void XmlWriter::printMethodElement(
1172                const CIMConstMethod& method,
1173                PEGASUS_STD(ostream)& os)
1174            {
1175                Array<Sint8> tmp;
1176                appendMethodElement(tmp, method);
1177                tmp.append('\0');
1178                os << tmp.getData() << PEGASUS_STD(endl);
1179            }
1180            
1181            //------------------------------------------------------------------------------
1182            //
1183            // appendParameterElement()
1184            //
1185 kumpf 1.56 //     <!ELEMENT PARAMETER (QUALIFIER*)>
1186            //     <!ATTLIST PARAMETER
1187            //              %CIMName;
1188            //              %CIMType;      #REQUIRED>
1189            //
1190            //     <!ELEMENT PARAMETER.REFERENCE (QUALIFIER*)>
1191            //     <!ATTLIST PARAMETER.REFERENCE
1192            //              %CIMName;
1193            //              %ReferenceClass;>
1194            //
1195            //     <!ELEMENT PARAMETER.ARRAY (QUALIFIER*)>
1196            //     <!ATTLIST PARAMETER.ARRAY
1197            //              %CIMName;
1198            //              %CIMType;           #REQUIRED
1199            //              %ArraySize;>
1200            //
1201            //     <!ELEMENT PARAMETER.REFARRAY (QUALIFIER*)>
1202            //     <!ATTLIST PARAMETER.REFARRAY
1203            //              %CIMName;
1204            //              %ReferenceClass;
1205            //              %ArraySize;>
1206 kumpf 1.56 //
1207            //------------------------------------------------------------------------------
1208            
1209            void XmlWriter::appendParameterElement(
1210                Array<Sint8>& out,
1211                const CIMConstParameter& parameter)
1212            {
1213                parameter._checkRep();
1214                parameter._rep->toXml(out);
1215            }
1216            
1217            void XmlWriter::printParameterElement(
1218                const CIMConstParameter& parameter,
1219                PEGASUS_STD(ostream)& os)
1220            {
1221                Array<Sint8> tmp;
1222                appendParameterElement(tmp, parameter);
1223                tmp.append('\0');
1224                os << tmp.getData() << PEGASUS_STD(endl);
1225            }
1226            
1227 kumpf 1.56 //------------------------------------------------------------------------------
1228            //
1229            // appendParamValueElement()
1230            //
1231            //     <!ELEMENT PARAMVALUE (VALUE|VALUE.REFERENCE|VALUE.ARRAY|VALUE.REFARRAY)?>
1232            //     <!ATTLIST PARAMVALUE
1233            //              %CIMName;>
1234            //
1235            //------------------------------------------------------------------------------
1236            
1237            void XmlWriter::appendParamValueElement(
1238                Array<Sint8>& out,
1239                const CIMParamValue& paramValue)
1240            {
1241                paramValue._checkRep();
1242                paramValue._rep->toXml(out);
1243            }
1244            
1245            void XmlWriter::printParamValueElement(
1246                const CIMParamValue& paramValue,
1247                PEGASUS_STD(ostream)& os)
1248 kumpf 1.56 {
1249                Array<Sint8> tmp;
1250                appendParamValueElement(tmp, paramValue);
1251                tmp.append('\0');
1252                os << tmp.getData() << PEGASUS_STD(endl);
1253            }
1254            
1255            //------------------------------------------------------------------------------
1256            //
1257            // appendQualifierElement()
1258            //
1259            //     <!ELEMENT QUALIFIER (VALUE|VALUE.ARRAY)>
1260            //     <!ATTLIST QUALIFIER
1261            //              %CIMName;
1262            //              %CIMType;               #REQUIRED
1263            //              %Propagated;
1264            //              %QualifierFlavor;>
1265            //
1266            //------------------------------------------------------------------------------
1267            
1268            void XmlWriter::appendQualifierElement(
1269 kumpf 1.56     Array<Sint8>& out,
1270                const CIMConstQualifier& qualifier)
1271            {
1272                qualifier._checkRep();
1273                qualifier._rep->toXml(out);
1274            }
1275            
1276            void XmlWriter::printQualifierElement(
1277                const CIMConstQualifier& qualifier,
1278                PEGASUS_STD(ostream)& os)
1279            {
1280                Array<Sint8> tmp;
1281                appendQualifierElement(tmp, qualifier);
1282                tmp.append('\0');
1283                os << tmp.getData() << PEGASUS_STD(endl);
1284            }
1285            
1286            //------------------------------------------------------------------------------
1287            //
1288            // appendQualifierDeclElement()
1289            //
1290 kumpf 1.56 //     <!ELEMENT QUALIFIER.DECLARATION (SCOPE?,(VALUE|VALUE.ARRAY)?)>
1291            //     <!ATTLIST QUALIFIER.DECLARATION
1292            //              %CIMName;
1293            //              %CIMType;                       #REQUIRED
1294            //              ISARRAY        (true|false)     #IMPLIED
1295            //              %ArraySize;
1296            //              %QualifierFlavor;>
1297            //
1298            //------------------------------------------------------------------------------
1299            
1300            void XmlWriter::appendQualifierDeclElement(
1301                Array<Sint8>& out,
1302                const CIMConstQualifierDecl& qualifierDecl)
1303            {
1304                qualifierDecl._checkRep();
1305                qualifierDecl._rep->toXml(out);
1306            }
1307            
1308            void XmlWriter::printQualifierDeclElement(
1309                const CIMConstQualifierDecl& qualifierDecl,
1310                PEGASUS_STD(ostream)& os)
1311 kumpf 1.56 {
1312                Array<Sint8> tmp;
1313                appendQualifierDeclElement(tmp, qualifierDecl);
1314                tmp.append('\0');
1315                os << tmp.getData() << PEGASUS_STD(endl);
1316            }
1317            
1318            //------------------------------------------------------------------------------
1319            //
1320 kumpf 1.57 // appendQualifierFlavorEntity()
1321            //
1322            //     <!ENTITY % QualifierFlavor "OVERRIDABLE  (true|false)   'true'
1323            //                                 TOSUBCLASS   (true|false)   'true'
1324            //                                 TOINSTANCE   (true|false)   'false'
1325            //                                 TRANSLATABLE (true|false)   'false'">
1326            //
1327            //------------------------------------------------------------------------------
1328            
1329            void XmlWriter::appendQualifierFlavorEntity(
1330                Array<Sint8>& out,
1331 kumpf 1.70     const CIMFlavor & flavor)
1332 kumpf 1.57 {
1333 kumpf 1.70     if (!(flavor.hasFlavor (CIMFlavor::OVERRIDABLE)))
1334 kumpf 1.57         out << " OVERRIDABLE=\"false\"";
1335            
1336 kumpf 1.70     if (!(flavor.hasFlavor (CIMFlavor::TOSUBCLASS)))
1337 kumpf 1.57         out << " TOSUBCLASS=\"false\"";
1338            
1339 kumpf 1.70     if (flavor.hasFlavor (CIMFlavor::TOINSTANCE))
1340 kumpf 1.57         out << " TOINSTANCE=\"true\"";
1341            
1342 kumpf 1.70     if (flavor.hasFlavor (CIMFlavor::TRANSLATABLE))
1343 kumpf 1.57         out << " TRANSLATABLE=\"true\"";
1344            }
1345            
1346            //------------------------------------------------------------------------------
1347            //
1348 kumpf 1.58 // appendScopeElement()
1349            //
1350            //     <!ELEMENT SCOPE EMPTY>
1351            //     <!ATTLIST SCOPE
1352            //              CLASS        (true|false)      'false'
1353            //              ASSOCIATION  (true|false)      'false'
1354            //              REFERENCE    (true|false)      'false'
1355            //              PROPERTY     (true|false)      'false'
1356            //              METHOD       (true|false)      'false'
1357            //              PARAMETER    (true|false)      'false'
1358            //              INDICATION   (true|false)      'false'>
1359            //
1360            //------------------------------------------------------------------------------
1361            
1362            void XmlWriter::appendScopeElement(
1363                Array<Sint8>& out,
1364 kumpf 1.69     const CIMScope & scope)
1365 kumpf 1.58 {
1366 kumpf 1.69     if (!(scope.equal (CIMScope ())))
1367 kumpf 1.58     {
1368                    out << "<SCOPE";
1369            
1370 kumpf 1.69         if (scope.hasScope (CIMScope::CLASS))
1371 kumpf 1.58             out << " CLASS=\"true\"";
1372            
1373 kumpf 1.69         if (scope.hasScope (CIMScope::ASSOCIATION))
1374 kumpf 1.58             out << " ASSOCIATION=\"true\"";
1375            
1376 kumpf 1.69         if (scope.hasScope (CIMScope::REFERENCE))
1377 kumpf 1.58             out << " REFERENCE=\"true\"";
1378            
1379 kumpf 1.69         if (scope.hasScope (CIMScope::PROPERTY))
1380 kumpf 1.58             out << " PROPERTY=\"true\"";
1381            
1382 kumpf 1.69         if (scope.hasScope (CIMScope::METHOD))
1383 kumpf 1.58             out << " METHOD=\"true\"";
1384            
1385 kumpf 1.69         if (scope.hasScope (CIMScope::PARAMETER))
1386 kumpf 1.58             out << " PARAMETER=\"true\"";
1387            
1388 kumpf 1.69         if (scope.hasScope (CIMScope::INDICATION))
1389 kumpf 1.58             out << " INDICATION=\"true\"";
1390            
1391                    out << "/>";
1392                }
1393            }
1394            
1395            //------------------------------------------------------------------------------
1396            //
1397 kumpf 1.27 // appendMethodCallHeader()
1398 mike  1.23 //
1399 kumpf 1.31 //     Build HTTP method call request header.
1400 mike  1.23 //
1401            //------------------------------------------------------------------------------
1402            
1403 kumpf 1.27 void XmlWriter::appendMethodCallHeader(
1404                Array<Sint8>& out,
1405 mike  1.23     const char* host,
1406 kumpf 1.80     const CIMName& cimMethod,
1407 mike  1.23     const String& cimObject,
1408 mike  1.24     const String& authenticationHeader,
1409 kumpf 1.82     HttpMethod httpMethod,
1410 kumpf 1.27     Uint32 contentLength)
1411 mike  1.23 {
1412                char nn[] = { '0' + (rand() % 10), '0' + (rand() % 10), '\0' };
1413            
1414 karl  1.81     // ATTN: KS 20020926 - Temporary change to issue only POST. This may
1415                // be changed in the DMTF CIM Operations standard in the future.
1416                // If we kept M-Post we would have to retry with Post. Does not
1417                // do that in client today. Permanent change is to retry until spec
1418                // updated. This change is temp to finish tests or until the retry
1419                // installed.  Required because of change to wbemservices cimom
1420            #ifdef PEGASUS_SNIA_INTEROP_TEST
1421                out << "POST /cimom HTTP/1.1\r\n";
1422            #else
1423 kumpf 1.82     if (httpMethod == HTTP_METHOD_M_POST)
1424                {
1425                    out << "M-POST /cimom HTTP/1.1\r\n";
1426                }
1427                else
1428                {
1429                    out << "POST /cimom HTTP/1.1\r\n";
1430                }
1431 karl  1.81 #endif
1432 mike  1.23     out << "HOST: " << host << "\r\n";
1433 kumpf 1.47     out << "Content-Type: application/xml; charset=\"utf-8\"\r\n";
1434 kumpf 1.27     out << "Content-Length: " << contentLength << "\r\n";
1435 kumpf 1.82     if (httpMethod == HTTP_METHOD_M_POST)
1436                {
1437                    out << "Man: http://www.dmtf.org/cim/mapping/http/v1.0; ns=";
1438                    out << nn <<"\r\n";
1439                    out << nn << "-CIMOperation: MethodCall\r\n";
1440                    out << nn << "-CIMMethod: " << cimMethod << "\r\n";
1441                    out << nn << "-CIMObject: " << cimObject << "\r\n";
1442                }
1443                else 
1444                {
1445                    out << "CIMOperation: MethodCall\r\n";
1446                    out << "CIMMethod: " << cimMethod << "\r\n";
1447                    out << "CIMObject: " << cimObject << "\r\n";
1448                }
1449            
1450 mike  1.24     if (authenticationHeader.size())
1451                {
1452                    out << authenticationHeader << "\r\n";
1453                }
1454                out << "\r\n";
1455 mike  1.23 }
1456            
1457            //------------------------------------------------------------------------------
1458            //
1459 kumpf 1.27 // appendMethodResponseHeader()
1460 mike  1.23 //
1461            //     Build HTTP response header.
1462            //
1463            //------------------------------------------------------------------------------
1464            
1465 kumpf 1.27 void XmlWriter::appendMethodResponseHeader(
1466                Array<Sint8>& out,
1467 kumpf 1.82     HttpMethod httpMethod,
1468 kumpf 1.27     Uint32 contentLength)
1469 mike  1.23 {
1470                char nn[] = { '0' + (rand() % 10), '0' + (rand() % 10), '\0' };
1471            
1472 kumpf 1.48     out << "HTTP/1.1 " HTTP_STATUS_OK "\r\n";
1473 sage  1.49     STAT_SERVERTIME
1474 kumpf 1.47     out << "Content-Type: application/xml; charset=\"utf-8\"\r\n";
1475 kumpf 1.27     out << "Content-Length: " << contentLength << "\r\n";
1476 kumpf 1.82     if (httpMethod == HTTP_METHOD_M_POST)
1477                {
1478                    out << "Ext:\r\n";
1479                    out << "Cache-Control: no-cache\r\n";
1480                    out << "Man: http://www.dmtf.org/cim/mapping/http/v1.0; ns=";
1481                    out << nn <<"\r\n";
1482                    out << nn << "-CIMOperation: MethodResponse\r\n\r\n";
1483                }
1484                else
1485                {
1486                    out << "CIMOperation: MethodResponse\r\n\r\n";
1487                }
1488 mike  1.23 }
1489            
1490            //------------------------------------------------------------------------------
1491            //
1492 kumpf 1.40 // appendHttpErrorResponseHeader()
1493            //
1494            //     Build HTTP error response header.
1495            //
1496            //     Returns error response message in the following format:
1497            //
1498 kumpf 1.41 //        HTTP/1.1 400 Bad Request       (using specified status code)
1499            //        CIMError: <error type>         (if specified by caller)
1500            //        PGErrorDetail: <error text>    (if specified by caller)
1501 kumpf 1.40 //
1502            //------------------------------------------------------------------------------
1503            
1504            void XmlWriter::appendHttpErrorResponseHeader(
1505                Array<Sint8>& out,
1506                const String& status,
1507                const String& cimError,
1508 kumpf 1.41     const String& errorDetail)
1509 kumpf 1.40 {
1510                out << "HTTP/1.1 " << status << "\r\n";
1511                if (cimError != String::EMPTY)
1512                {
1513                    out << "CIMError: " << cimError << "\r\n";
1514                }
1515 kumpf 1.41     if (errorDetail != String::EMPTY)
1516 kumpf 1.40     {
1517 kumpf 1.41         // ATTN-RK-P3-20020404: It is critical that this text not contain '\n'
1518                    // ATTN-RK-P3-20020404: Need to encode this value properly.  (See
1519                    // CIM/HTTP Specification section 3.3.2
1520 kumpf 1.46         out << PEGASUS_HTTPHEADERTAG_ERRORDETAIL ": " << errorDetail << "\r\n";
1521 kumpf 1.40     }
1522                out << "\r\n";
1523            }
1524            
1525            //------------------------------------------------------------------------------
1526            //
1527 kumpf 1.27 // appendUnauthorizedResponseHeader()
1528            //
1529            //     Build HTTP authentication response header for unauthorized requests.
1530            //
1531            //     Returns unauthorized message in the following format:
1532            //
1533            //        HTTP/1.1 401 Unauthorized
1534            //        WWW-Authenticate: Basic "hostname:80"
1535            //        <HTML><HEAD>
1536            //        <TITLE>401 Unauthorized</TITLE>
1537            //        </HEAD><BODY BGCOLOR="#99cc99">
1538            //        <H2>TEST401 Unauthorized</H2>
1539            //        <HR>
1540            //        </BODY></HTML>
1541            //
1542            //------------------------------------------------------------------------------
1543            
1544            void XmlWriter::appendUnauthorizedResponseHeader(
1545                Array<Sint8>& out,
1546                const String& content)
1547            {
1548 kumpf 1.40     out << "HTTP/1.1 " HTTP_STATUS_UNAUTHORIZED "\r\n";
1549 kumpf 1.27     out << content << "\r\n";
1550                out << "\r\n";
1551            
1552            //ATTN: We may need to include the following line, so that the browsers
1553            //      can display the error message.
1554            //    out << "<HTML><HEAD>\r\n";
1555            //    out << "<TITLE>" << "401 Unauthorized" <<  "</TITLE>\r\n";
1556            //    out << "</HEAD><BODY BGCOLOR=\"#99cc99\">\r\n";
1557            //    out << "<H2>TEST" << "401 Unauthorized" << "</H2>\r\n";
1558            //    out << "<HR>\r\n";
1559            //    out << "</BODY></HTML>\r\n";
1560            }
1561            
1562            //------------------------------------------------------------------------------
1563            //
1564 kumpf 1.29 // _appendMessageElementBegin()
1565            // _appendMessageElementEnd()
1566 mike  1.23 //
1567            //     <!ELEMENT MESSAGE (SIMPLEREQ|MULTIREQ|SIMPLERSP|MULTIRSP)>
1568            //     <!ATTLIST MESSAGE
1569            //         ID CDATA #REQUIRED
1570            //         PROTOCOLVERSION CDATA #REQUIRED>
1571            //
1572            //------------------------------------------------------------------------------
1573            
1574 kumpf 1.29 void XmlWriter::_appendMessageElementBegin(
1575 kumpf 1.27     Array<Sint8>& out,
1576                const String& messageId)
1577 mike  1.23 {
1578                out << "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
1579                out << "<CIM CIMVERSION=\"2.0\" DTDVERSION=\"2.0\">\n";
1580                out << "<MESSAGE ID=\"" << messageId << "\" PROTOCOLVERSION=\"1.0\">\n";
1581 kumpf 1.27 }
1582            
1583 kumpf 1.29 void XmlWriter::_appendMessageElementEnd(
1584 kumpf 1.27     Array<Sint8>& out)
1585            {
1586 mike  1.23     out << "</MESSAGE>\n";
1587                out << "</CIM>\n";
1588            }
1589            
1590            //------------------------------------------------------------------------------
1591            //
1592 kumpf 1.29 // _appendSimpleReqElementBegin()
1593            // _appendSimpleReqElementEnd()
1594 mike  1.23 //
1595            //     <!ELEMENT SIMPLEREQ (IMETHODCALL|METHODCALL)>
1596            //
1597            //------------------------------------------------------------------------------
1598            
1599 kumpf 1.29 void XmlWriter::_appendSimpleReqElementBegin(
1600 kumpf 1.27     Array<Sint8>& out)
1601            {
1602                out << "<SIMPLEREQ>\n";
1603            }
1604            
1605 kumpf 1.29 void XmlWriter::_appendSimpleReqElementEnd(
1606 kumpf 1.27     Array<Sint8>& out)
1607 mike  1.23 {
1608 kumpf 1.27     out << "</SIMPLEREQ>\n";
1609 mike  1.23 }
1610            
1611            //------------------------------------------------------------------------------
1612            //
1613 kumpf 1.29 // _appendMethodCallElementBegin()
1614            // _appendMethodCallElementEnd()
1615 mike  1.23 //
1616 kumpf 1.27 //     <!ELEMENT METHODCALL ((LOCALCLASSPATH|LOCALINSTANCEPATH),PARAMVALUE*)>
1617            //     <!ATTLIST METHODCALL %CIMName;>
1618 mike  1.23 //
1619            //------------------------------------------------------------------------------
1620            
1621 kumpf 1.29 void XmlWriter::_appendMethodCallElementBegin(
1622 kumpf 1.27     Array<Sint8>& out,
1623 kumpf 1.80     const CIMName& name)
1624 kumpf 1.27 {
1625                out << "<METHODCALL NAME=\"" << name << "\">\n";
1626            }
1627            
1628 kumpf 1.29 void XmlWriter::_appendMethodCallElementEnd(
1629 kumpf 1.27     Array<Sint8>& out)
1630 mike  1.23 {
1631 kumpf 1.27     out << "</METHODCALL>\n";
1632 mike  1.23 }
1633            
1634            //------------------------------------------------------------------------------
1635            //
1636 kumpf 1.29 // _appendIMethodCallElementBegin()
1637            // _appendIMethodCallElementEnd()
1638 mike  1.23 //
1639            //     <!ELEMENT IMETHODCALL (LOCALNAMESPACEPATH,IPARAMVALUE*)>
1640            //     <!ATTLIST IMETHODCALL %CIMName;>
1641            //
1642            //------------------------------------------------------------------------------
1643            
1644 kumpf 1.29 void XmlWriter::_appendIMethodCallElementBegin(
1645 kumpf 1.27     Array<Sint8>& out,
1646 kumpf 1.80     const CIMName& name)
1647 mike  1.23 {
1648                out << "<IMETHODCALL NAME=\"" << name << "\">\n";
1649 kumpf 1.27 }
1650            
1651 kumpf 1.29 void XmlWriter::_appendIMethodCallElementEnd(
1652 kumpf 1.27     Array<Sint8>& out)
1653            {
1654 mike  1.23     out << "</IMETHODCALL>\n";
1655            }
1656            
1657            //------------------------------------------------------------------------------
1658            //
1659 kumpf 1.29 // _appendIParamValueElementBegin()
1660            // _appendIParamValueElementEnd()
1661 mike  1.23 //
1662 kumpf 1.27 //     <!ELEMENT IPARAMVALUE (VALUE|VALUE.ARRAY|VALUE.REFERENCE
1663            //         |INSTANCENAME|CLASSNAME|QUALIFIER.DECLARATION
1664            //         |CLASS|INSTANCE|VALUE.NAMEDINSTANCE)?>
1665            //     <!ATTLIST IPARAMVALUE %CIMName;>
1666 mike  1.23 //
1667            //------------------------------------------------------------------------------
1668            
1669 kumpf 1.29 void XmlWriter::_appendIParamValueElementBegin(
1670 kumpf 1.27     Array<Sint8>& out,
1671                const char* name)
1672            {
1673                out << "<IPARAMVALUE NAME=\"" << name << "\">\n";
1674            }
1675            
1676 kumpf 1.29 void XmlWriter::_appendIParamValueElementEnd(
1677 kumpf 1.27     Array<Sint8>& out)
1678 mike  1.23 {
1679 kumpf 1.27     out << "</IPARAMVALUE>\n";
1680 mike  1.23 }
1681            
1682            //------------------------------------------------------------------------------
1683            //
1684 kumpf 1.29 // _appendSimpleRspElementBegin()
1685            // _appendSimpleRspElementEnd()
1686 mike  1.23 //
1687 kumpf 1.27 //     <!ELEMENT SIMPLERSP (METHODRESPONSE|IMETHODRESPONSE)>
1688 mike  1.23 //
1689            //------------------------------------------------------------------------------
1690            
1691 kumpf 1.29 void XmlWriter::_appendSimpleRspElementBegin(
1692 kumpf 1.27     Array<Sint8>& out)
1693            {
1694                out << "<SIMPLERSP>\n";
1695            }
1696            
1697 kumpf 1.29 void XmlWriter::_appendSimpleRspElementEnd(
1698 kumpf 1.27     Array<Sint8>& out)
1699 mike  1.23 {
1700 kumpf 1.27     out << "</SIMPLERSP>\n";
1701 mike  1.23 }
1702            
1703            //------------------------------------------------------------------------------
1704            //
1705 kumpf 1.29 // _appendMethodResponseElementBegin()
1706            // _appendMethodResponseElementEnd()
1707 mike  1.23 //
1708 kumpf 1.27 //     <!ELEMENT METHODRESPONSE (ERROR|IRETURNVALUE?)>
1709            //     <!ATTLIST METHODRESPONSE %CIMName;>
1710 mike  1.23 //
1711            //------------------------------------------------------------------------------
1712            
1713 kumpf 1.29 void XmlWriter::_appendMethodResponseElementBegin(
1714 mike  1.23     Array<Sint8>& out,
1715 kumpf 1.80     const CIMName& name)
1716 kumpf 1.27 {
1717                out << "<METHODRESPONSE NAME=\"" << name << "\">\n";
1718            }
1719            
1720 kumpf 1.29 void XmlWriter::_appendMethodResponseElementEnd(
1721 kumpf 1.27     Array<Sint8>& out)
1722 mike  1.23 {
1723 kumpf 1.27     out << "</METHODRESPONSE>\n";
1724            }
1725            
1726            //------------------------------------------------------------------------------
1727            //
1728 kumpf 1.29 // _appendIMethodResponseElementBegin()
1729            // _appendIMethodResponseElementEnd()
1730 kumpf 1.27 //
1731            //     <!ELEMENT IMETHODRESPONSE (ERROR|IRETURNVALUE?)>
1732            //     <!ATTLIST IMETHODRESPONSE %CIMName;>
1733            //
1734            //------------------------------------------------------------------------------
1735            
1736 kumpf 1.29 void XmlWriter::_appendIMethodResponseElementBegin(
1737 kumpf 1.27     Array<Sint8>& out,
1738 kumpf 1.80     const CIMName& name)
1739 kumpf 1.27 {
1740                out << "<IMETHODRESPONSE NAME=\"" << name << "\">\n";
1741            }
1742            
1743 kumpf 1.29 void XmlWriter::_appendIMethodResponseElementEnd(
1744 kumpf 1.27     Array<Sint8>& out)
1745            {
1746                out << "</IMETHODRESPONSE>\n";
1747 mike  1.23 }
1748            
1749            //------------------------------------------------------------------------------
1750            //
1751 kumpf 1.29 // _appendErrorElement()
1752 mike  1.23 //
1753            //------------------------------------------------------------------------------
1754            
1755 kumpf 1.29 void XmlWriter::_appendErrorElement(
1756 kumpf 1.27     Array<Sint8>& out,
1757 kumpf 1.42     const CIMException& cimException)
1758 mike  1.23 {
1759 kumpf 1.71     Tracer::traceCIMException(TRC_XML_WRITER, Tracer::LEVEL2, cimException);
1760 kumpf 1.44 
1761 mike  1.23     out << "<ERROR";
1762 kumpf 1.42     out << " CODE=\"" << Uint32(cimException.getCode()) << "\"";
1763 kumpf 1.71     String description = TraceableCIMException(cimException).getDescription();
1764 kumpf 1.51     if (description != String::EMPTY)
1765 kumpf 1.42     {
1766                    out << " DESCRIPTION=\"";
1767 kumpf 1.51         appendSpecial(out, description);
1768 kumpf 1.42         out << "\"";
1769                }
1770                out << "/>";
1771 mike  1.23 }
1772            
1773            //------------------------------------------------------------------------------
1774            //
1775 kumpf 1.27 // appendReturnValueElement()
1776            //
1777            // <!ELEMENT RETURNVALUE (VALUE|VALUE.REFERENCE)>
1778            // <!ATTLIST RETURNVALUE
1779            //     %ParamType;>
1780 mike  1.23 //
1781            //------------------------------------------------------------------------------
1782            
1783 kumpf 1.27 void XmlWriter::appendReturnValueElement(
1784 mike  1.23     Array<Sint8>& out,
1785 kumpf 1.27     const CIMValue& value)
1786            {
1787                out << "<RETURNVALUE";
1788            
1789                CIMType type = value.getType();
1790 kumpf 1.74     out << " PARAMTYPE=\"" << cimTypeToString (type) << "\"";
1791 kumpf 1.27 
1792                out << ">\n";
1793 karl  1.37 
1794 kumpf 1.54     // Add value.
1795                appendValueElement(out, value);
1796 kumpf 1.27     out << "</RETURNVALUE>\n";
1797            }
1798            
1799            //------------------------------------------------------------------------------
1800            //
1801 kumpf 1.29 // _appendIReturnValueElementBegin()
1802            // _appendIReturnValueElementEnd()
1803 kumpf 1.27 //
1804            //      <!ELEMENT IRETURNVALUE (CLASSNAME*|INSTANCENAME*|VALUE*|
1805            //          VALUE.OBJECTWITHPATH*|VALUE.OBJECTWITHLOCALPATH*|VALUE.OBJECT*|
1806            //          OBJECTPATH*|QUALIFIER.DECLARATION*|VALUE.ARRAY?|VALUE.REFERENCE?|
1807            //          CLASS*|INSTANCE*|VALUE.NAMEDINSTANCE*)>
1808            //
1809            //------------------------------------------------------------------------------
1810            
1811 kumpf 1.29 void XmlWriter::_appendIReturnValueElementBegin(
1812 kumpf 1.27     Array<Sint8>& out)
1813            {
1814                out << "<IRETURNVALUE>\n";
1815            }
1816            
1817 kumpf 1.29 void XmlWriter::_appendIReturnValueElementEnd(
1818 kumpf 1.27     Array<Sint8>& out)
1819 mike  1.23 {
1820 kumpf 1.27     out << "</IRETURNVALUE>\n";
1821 mike  1.23 }
1822            
1823            //------------------------------------------------------------------------------
1824            //
1825 kumpf 1.27 // appendBooleanIParameter()
1826 mike  1.23 //
1827            //------------------------------------------------------------------------------
1828            
1829 kumpf 1.27 void XmlWriter::appendBooleanIParameter(
1830 mike  1.23     Array<Sint8>& out,
1831                const char* name,
1832 kumpf 1.27     Boolean flag)
1833 mike  1.23 {
1834 kumpf 1.29     _appendIParamValueElementBegin(out, name);
1835 kumpf 1.54     out << "<VALUE>";
1836                append(out, flag);
1837                out << "</VALUE>\n";
1838 kumpf 1.29     _appendIParamValueElementEnd(out);
1839 mike  1.23 }
1840            
1841            //------------------------------------------------------------------------------
1842            //
1843 kumpf 1.27 // appendStringIParameter()
1844 mike  1.23 //
1845            //------------------------------------------------------------------------------
1846            
1847 kumpf 1.27 void XmlWriter::appendStringIParameter(
1848 mike  1.23     Array<Sint8>& out,
1849                const char* name,
1850 kumpf 1.27     const String& str)
1851 mike  1.23 {
1852 kumpf 1.29     _appendIParamValueElementBegin(out, name);
1853 kumpf 1.27     out << "<VALUE>";
1854                appendSpecial(out, str);
1855                out << "</VALUE>\n";
1856 kumpf 1.29     _appendIParamValueElementEnd(out);
1857 mike  1.23 }
1858            
1859            //------------------------------------------------------------------------------
1860            //
1861 kumpf 1.27 // appendQualifierNameIParameter()
1862 mike  1.23 //
1863            //------------------------------------------------------------------------------
1864            
1865 kumpf 1.27 void XmlWriter::appendQualifierNameIParameter(
1866 mike  1.23     Array<Sint8>& out,
1867                const char* name,
1868                const String& qualifierName)
1869            {
1870                // <!ELEMENT IPARAMVALUE (VALUE|VALUE.ARRAY|VALUE.REFERENCE
1871                //     |INSTANCENAME|CLASSNAME|QUALIFIER.DECLARATION
1872                //     |CLASS|INSTANCE|VALUE.NAMEDINSTANCE)?>
1873                //
1874                // ATTN: notice that there is really no way to pass a qualifier name
1875                // as an IPARAMVALUE element according to the spec (look above). So we
1876                // just pass it as a class name. An answer must be obtained later.
1877                
1878 kumpf 1.29     _appendIParamValueElementBegin(out, name);
1879 kumpf 1.27     appendClassNameElement(out, qualifierName);
1880 kumpf 1.29     _appendIParamValueElementEnd(out);
1881 mike  1.23 }
1882            
1883            //------------------------------------------------------------------------------
1884            //
1885 kumpf 1.27 // appendClassNameIParameter()
1886 mike  1.23 //
1887            //------------------------------------------------------------------------------
1888            
1889 kumpf 1.27 void XmlWriter::appendClassNameIParameter(
1890 mike  1.23     Array<Sint8>& out,
1891 kumpf 1.27     const char* name,
1892 kumpf 1.80     const CIMName& className)
1893 mike  1.23 {
1894 kumpf 1.29     _appendIParamValueElementBegin(out, name);
1895 kumpf 1.83 
1896                //
1897                //  A NULL (unassigned) value for a parameter is specified by an 
1898                //  <IPARAMVALUE> element with no subelement
1899                //
1900                if (!className.isNull ())
1901                {
1902                    appendClassNameElement(out, className);
1903                }
1904            
1905 kumpf 1.29     _appendIParamValueElementEnd(out);
1906 mike  1.23 }
1907            
1908            //------------------------------------------------------------------------------
1909            //
1910 kumpf 1.27 // appendInstanceNameIParameter()
1911 mike  1.23 //
1912            //------------------------------------------------------------------------------
1913            
1914 kumpf 1.27 void XmlWriter::appendInstanceNameIParameter(
1915 mike  1.23     Array<Sint8>& out,
1916 kumpf 1.27     const char* name,
1917 kumpf 1.59     const CIMObjectPath& instanceName)
1918 mike  1.23 {
1919 kumpf 1.29     _appendIParamValueElementBegin(out, name);
1920                appendInstanceNameElement(out, instanceName);
1921                _appendIParamValueElementEnd(out);
1922 kumpf 1.27 }
1923            
1924            void XmlWriter::appendObjectNameIParameter(
1925                Array<Sint8>& out,
1926                const char* name,
1927 kumpf 1.59     const CIMObjectPath& objectName)
1928 kumpf 1.27 {
1929 kumpf 1.68     //
1930                //  ATTN-CAKG-P2-20020726:  The following condition does not correctly
1931                //  distinguish instanceNames from classNames in every case
1932                //  The instanceName of a singleton instance of a keyless class also 
1933                //  has no key bindings
1934                //
1935                if (objectName.getKeyBindings ().size () == 0)
1936 kumpf 1.27     {
1937            	XmlWriter::appendClassNameIParameter(
1938            	    out, name, objectName.getClassName());
1939                }
1940                else
1941                {
1942            	XmlWriter::appendInstanceNameIParameter(
1943            	    out, name, objectName);
1944                }
1945            }
1946            
1947            //------------------------------------------------------------------------------
1948            //
1949            // appendClassIParameter()
1950            //
1951            //------------------------------------------------------------------------------
1952            
1953            void XmlWriter::appendClassIParameter(
1954                Array<Sint8>& out,
1955                const char* name,
1956                const CIMConstClass& cimClass)
1957 kumpf 1.27 {
1958 kumpf 1.29     _appendIParamValueElementBegin(out, name);
1959 kumpf 1.55     appendClassElement(out, cimClass);
1960 kumpf 1.29     _appendIParamValueElementEnd(out);
1961 mike  1.23 }
1962            
1963            //------------------------------------------------------------------------------
1964            //
1965 kumpf 1.27 // appendInstanceIParameter()
1966 mike  1.23 //
1967            //------------------------------------------------------------------------------
1968            
1969 kumpf 1.27 void XmlWriter::appendInstanceIParameter(
1970 mike  1.23     Array<Sint8>& out,
1971 kumpf 1.27     const char* name,
1972 mike  1.23     const CIMConstInstance& instance)
1973            {
1974 kumpf 1.29     _appendIParamValueElementBegin(out, name);
1975 kumpf 1.55     appendInstanceElement(out, instance);
1976 kumpf 1.29     _appendIParamValueElementEnd(out);
1977 mike  1.23 }
1978            
1979 mike  1.24 //------------------------------------------------------------------------------
1980            //
1981 kumpf 1.27 // appendNamedInstanceIParameter()
1982 mike  1.24 //
1983            //------------------------------------------------------------------------------
1984            
1985 kumpf 1.27 void XmlWriter::appendNamedInstanceIParameter(
1986 mike  1.24     Array<Sint8>& out,
1987 kumpf 1.27     const char* name,
1988 kumpf 1.61     const CIMInstance& namedInstance)
1989 mike  1.24 {
1990 kumpf 1.29     _appendIParamValueElementBegin(out, name);
1991 kumpf 1.56     appendValueNamedInstanceElement(out, namedInstance);
1992 kumpf 1.29     _appendIParamValueElementEnd(out);
1993 mike  1.24 }
1994            
1995 mike  1.23 //----------------------------------------------------------
1996            //
1997 kumpf 1.27 //  appendPropertyNameIParameter()
1998 mike  1.23 //   	
1999            //     </IPARAMVALUE>
2000            //     <IPARAMVALUE NAME="PropertyName"><VALUE>FreeSpace</VALUE></IPARAMVALUE>
2001            //
2002            //     USE: Create parameter for getProperty operation
2003            //==========================================================
2004 kumpf 1.27 void XmlWriter::appendPropertyNameIParameter(
2005 mike  1.23     Array<Sint8>& out,
2006 kumpf 1.80     const CIMName& propertyName)
2007 mike  1.23 {
2008 kumpf 1.29     _appendIParamValueElementBegin(out, "PropertyName");
2009 kumpf 1.27     out << "<VALUE>" << propertyName << "</VALUE>\n"; 
2010 kumpf 1.29     _appendIParamValueElementEnd(out);
2011 kumpf 1.27 }
2012 mike  1.23 
2013            //------------------------------------------------------------------------------
2014            //
2015 kumpf 1.27 // appendPropertyValueIParameter()
2016 mike  1.24 //
2017            //------------------------------------------------------------------------------
2018            
2019 kumpf 1.27 void XmlWriter::appendPropertyValueIParameter(
2020 mike  1.24     Array<Sint8>& out,
2021 kumpf 1.27     const char* name,
2022 mike  1.24     const CIMValue& value)
2023            {
2024 kumpf 1.29     _appendIParamValueElementBegin(out, name);
2025 kumpf 1.54     appendValueElement(out, value);
2026 kumpf 1.29     _appendIParamValueElementEnd(out);
2027 mike  1.24 }
2028            
2029            //------------------------------------------------------------------------------
2030            //
2031 kumpf 1.27 // appendPropertyListIParameter()
2032 mike  1.24 //
2033            //------------------------------------------------------------------------------
2034            
2035 kumpf 1.27 void XmlWriter::appendPropertyListIParameter(
2036 mike  1.24     Array<Sint8>& out,
2037                const CIMPropertyList& propertyList)
2038            {
2039 kumpf 1.29     _appendIParamValueElementBegin(out, "PropertyList");
2040 mike  1.24 
2041 kumpf 1.83     //
2042                //  A NULL (unassigned) value for a parameter is specified by an 
2043                //  <IPARAMVALUE> element with no subelement
2044                //
2045                if (!propertyList.isNull ())
2046 mike  1.24     {
2047 kumpf 1.83         out << "<VALUE.ARRAY>\n";
2048                    for (Uint32 i = 0; i < propertyList.size(); i++)
2049                    {
2050                        out << "<VALUE>" << propertyList[i] << "</VALUE>\n"; 
2051                    }
2052                    out << "</VALUE.ARRAY>\n";
2053 mike  1.24     }
2054 kumpf 1.27 
2055 kumpf 1.29     _appendIParamValueElementEnd(out);
2056 mike  1.24 }
2057            
2058            //------------------------------------------------------------------------------
2059            //
2060 kumpf 1.27 // appendQualifierDeclarationIParameter()
2061 mike  1.23 //
2062            //------------------------------------------------------------------------------
2063            
2064 kumpf 1.27 void XmlWriter::appendQualifierDeclarationIParameter(
2065 mike  1.23     Array<Sint8>& out,
2066 kumpf 1.27     const char* name,
2067 mike  1.23     const CIMConstQualifierDecl& qualifierDecl)
2068            {
2069 kumpf 1.29     _appendIParamValueElementBegin(out, name);
2070 kumpf 1.56     appendQualifierDeclElement(out, qualifierDecl);
2071 kumpf 1.29     _appendIParamValueElementEnd(out);
2072 kumpf 1.40 }
2073            
2074            //------------------------------------------------------------------------------
2075            //
2076            // XmlWriter::formatHttpErrorRspMessage()
2077            //
2078            //------------------------------------------------------------------------------
2079            
2080            Array<Sint8> XmlWriter::formatHttpErrorRspMessage(
2081                const String& status,
2082                const String& cimError,
2083 kumpf 1.41     const String& errorDetail)
2084 kumpf 1.40 {
2085                Array<Sint8> out;
2086            
2087 kumpf 1.41     appendHttpErrorResponseHeader(out, status, cimError, errorDetail);
2088 kumpf 1.40 
2089 kumpf 1.41     return out;
2090 mike  1.23 }
2091            
2092            //------------------------------------------------------------------------------
2093            //
2094 kumpf 1.27 // XmlWriter::formatSimpleMethodReqMessage()
2095 mike  1.23 //
2096            //------------------------------------------------------------------------------
2097            
2098 kumpf 1.27 // ATTN-RK-P1-20020228: Need to complete copy elimination optimization
2099            Array<Sint8> XmlWriter::formatSimpleMethodReqMessage(
2100                const char* host,
2101 kumpf 1.80     const CIMNamespaceName& nameSpace,
2102 kumpf 1.59     const CIMObjectPath& path,
2103 kumpf 1.80     const CIMName& methodName,
2104 kumpf 1.30     const Array<CIMParamValue>& parameters,
2105 kumpf 1.27     const String& messageId,
2106 kumpf 1.82     HttpMethod httpMethod,
2107 kumpf 1.30     const String& authenticationHeader)
2108 kumpf 1.27 {
2109                Array<Sint8> out;
2110                Array<Sint8> tmp;
2111 kumpf 1.59     CIMObjectPath localObjectPath = path;
2112 kumpf 1.80     localObjectPath.setNameSpace(nameSpace.getString());
2113 kumpf 1.77     localObjectPath.setHost(String::EMPTY);
2114 kumpf 1.27 
2115 kumpf 1.29     _appendMessageElementBegin(out, messageId);
2116                _appendSimpleReqElementBegin(out);
2117                _appendMethodCallElementBegin(out, methodName);
2118 kumpf 1.38     appendLocalObjectPathElement(out, localObjectPath);
2119 kumpf 1.30     for (Uint32 i=0; i < parameters.size(); i++)
2120 kumpf 1.29     {
2121 kumpf 1.56         appendParamValueElement(out, parameters[i]);
2122 kumpf 1.29     }
2123                _appendMethodCallElementEnd(out);
2124                _appendSimpleReqElementEnd(out);
2125                _appendMessageElementEnd(out);
2126 kumpf 1.27 
2127                appendMethodCallHeader(
2128            	tmp,
2129            	host,
2130            	methodName,
2131 kumpf 1.77 	localObjectPath.toString(),
2132 kumpf 1.27         authenticationHeader,
2133 kumpf 1.82         httpMethod,
2134 kumpf 1.27 	out.size());
2135                tmp << out;
2136            
2137                return tmp;
2138            }
2139            
2140            Array<Sint8> XmlWriter::formatSimpleMethodRspMessage(
2141 kumpf 1.80     const CIMName& methodName,
2142 kumpf 1.27     const String& messageId,
2143 kumpf 1.82     HttpMethod httpMethod,
2144 kumpf 1.27     const Array<Sint8>& body)
2145 mike  1.23 {
2146 kumpf 1.27     Array<Sint8> out;
2147                Array<Sint8> tmp;
2148            
2149 kumpf 1.29     _appendMessageElementBegin(out, messageId);
2150                _appendSimpleRspElementBegin(out);
2151                _appendMethodResponseElementBegin(out, methodName);
2152 kumpf 1.27     out << body;
2153 kumpf 1.29     _appendMethodResponseElementEnd(out);
2154                _appendSimpleRspElementEnd(out);
2155                _appendMessageElementEnd(out);
2156 mike  1.23 
2157 kumpf 1.82     appendMethodResponseHeader(tmp, httpMethod, out.size());
2158 kumpf 1.27     tmp << out;
2159 mike  1.23 
2160 kumpf 1.27     return tmp;
2161 mike  1.23 }
2162            
2163            //------------------------------------------------------------------------------
2164            //
2165 kumpf 1.28 // XmlWriter::formatSimpleMethodErrorRspMessage()
2166            //
2167            //------------------------------------------------------------------------------
2168            
2169            Array<Sint8> XmlWriter::formatSimpleMethodErrorRspMessage(
2170 kumpf 1.80     const CIMName& methodName,
2171 kumpf 1.28     const String& messageId,
2172 kumpf 1.82     HttpMethod httpMethod,
2173 kumpf 1.42     const CIMException& cimException)
2174 kumpf 1.28 {
2175                Array<Sint8> out;
2176                Array<Sint8> tmp;
2177            
2178 kumpf 1.29     _appendMessageElementBegin(out, messageId);
2179                _appendSimpleRspElementBegin(out);
2180 kumpf 1.80     _appendMethodResponseElementBegin(out, methodName);
2181 kumpf 1.42     _appendErrorElement(out, cimException);
2182 kumpf 1.29     _appendMethodResponseElementEnd(out);
2183                _appendSimpleRspElementEnd(out);
2184                _appendMessageElementEnd(out);
2185 kumpf 1.28 
2186 kumpf 1.82     appendMethodResponseHeader(tmp, httpMethod, out.size());
2187 kumpf 1.28     tmp << out;
2188            
2189                return tmp;
2190            }
2191            
2192            //------------------------------------------------------------------------------
2193            //
2194 kumpf 1.27 // XmlWriter::formatSimpleIMethodReqMessage()
2195 mike  1.23 //
2196            //------------------------------------------------------------------------------
2197            
2198 kumpf 1.27 Array<Sint8> XmlWriter::formatSimpleIMethodReqMessage(
2199                const char* host,
2200 kumpf 1.80     const CIMNamespaceName& nameSpace,
2201                const CIMName& iMethodName,
2202 kumpf 1.27     const String& messageId,
2203 kumpf 1.82     HttpMethod httpMethod,
2204 kumpf 1.27     const String& authenticationHeader,
2205                const Array<Sint8>& body)
2206 mike  1.23 {
2207 kumpf 1.27     Array<Sint8> out;
2208                Array<Sint8> tmp;
2209            
2210 kumpf 1.29     _appendMessageElementBegin(out, messageId);
2211                _appendSimpleReqElementBegin(out);
2212                _appendIMethodCallElementBegin(out, iMethodName);
2213 kumpf 1.80     appendLocalNameSpacePathElement(out, nameSpace.getString());
2214 kumpf 1.27     out << body;
2215 kumpf 1.29     _appendIMethodCallElementEnd(out);
2216                _appendSimpleReqElementEnd(out);
2217                _appendMessageElementEnd(out);
2218 kumpf 1.27 
2219                appendMethodCallHeader(
2220            	tmp,
2221            	host,
2222            	iMethodName,
2223 kumpf 1.80 	nameSpace.getString(),
2224 kumpf 1.27         authenticationHeader,
2225 kumpf 1.82         httpMethod,
2226 kumpf 1.27 	out.size());
2227                tmp << out;
2228 mike  1.23 
2229 kumpf 1.27     return tmp;
2230 mike  1.23 }
2231            
2232            //------------------------------------------------------------------------------
2233            //
2234 kumpf 1.27 // XmlWriter::formatSimpleIMethodRspMessage()
2235 mike  1.23 //
2236            //------------------------------------------------------------------------------
2237            
2238 kumpf 1.27 Array<Sint8> XmlWriter::formatSimpleIMethodRspMessage(
2239 kumpf 1.80     const CIMName& iMethodName,
2240 kumpf 1.27     const String& messageId,
2241 kumpf 1.82     HttpMethod httpMethod,
2242 kumpf 1.27     const Array<Sint8>& body)
2243 mike  1.23 {
2244 kumpf 1.27     Array<Sint8> out;
2245                Array<Sint8> tmp;
2246 mike  1.23 
2247 kumpf 1.29     _appendMessageElementBegin(out, messageId);
2248                _appendSimpleRspElementBegin(out);
2249                _appendIMethodResponseElementBegin(out, iMethodName);
2250 kumpf 1.45     if (body.size() != 0)
2251                {
2252                    _appendIReturnValueElementBegin(out);
2253                    out << body;
2254                    _appendIReturnValueElementEnd(out);
2255                }
2256 kumpf 1.29     _appendIMethodResponseElementEnd(out);
2257                _appendSimpleRspElementEnd(out);
2258                _appendMessageElementEnd(out);
2259 mike  1.23 
2260 kumpf 1.82     appendMethodResponseHeader(tmp, httpMethod, out.size());
2261 kumpf 1.27     tmp << out;
2262 mike  1.23 
2263 kumpf 1.27     return tmp;
2264            }
2265 mike  1.23 
2266 kumpf 1.28 //------------------------------------------------------------------------------
2267            //
2268            // XmlWriter::formatSimpleIMethodErrorRspMessage()
2269            //
2270            //------------------------------------------------------------------------------
2271            
2272            Array<Sint8> XmlWriter::formatSimpleIMethodErrorRspMessage(
2273 kumpf 1.80     const CIMName& iMethodName,
2274 kumpf 1.28     const String& messageId,
2275 kumpf 1.82     HttpMethod httpMethod,
2276 kumpf 1.42     const CIMException& cimException)
2277 kumpf 1.28 {
2278                Array<Sint8> out;
2279                Array<Sint8> tmp;
2280            
2281 kumpf 1.29     _appendMessageElementBegin(out, messageId);
2282                _appendSimpleRspElementBegin(out);
2283 kumpf 1.80     _appendIMethodResponseElementBegin(out, iMethodName);
2284 kumpf 1.42     _appendErrorElement(out, cimException);
2285 kumpf 1.29     _appendIMethodResponseElementEnd(out);
2286                _appendSimpleRspElementEnd(out);
2287                _appendMessageElementEnd(out);
2288 kumpf 1.28 
2289 kumpf 1.82     appendMethodResponseHeader(tmp, httpMethod, out.size());
2290 kumpf 1.28     tmp << out;
2291            
2292                return tmp;
2293            }
2294            
2295 kumpf 1.27 //******************************************************************************
2296            //
2297            // Export Messages (used for indications)
2298            //
2299            //******************************************************************************
2300 mike  1.23 
2301 kumpf 1.27 //------------------------------------------------------------------------------
2302            //
2303            // appendEMethodRequestHeader()
2304            //
2305            //     Build HTTP request header for export operation.
2306            //
2307            //------------------------------------------------------------------------------
2308 mike  1.23 
2309 kumpf 1.27 void XmlWriter::appendEMethodRequestHeader(
2310                Array<Sint8>& out,
2311 kumpf 1.50     const char* requestUri,
2312 kumpf 1.27     const char* host,
2313 kumpf 1.80     const CIMName& cimMethod,
2314 kumpf 1.82     HttpMethod httpMethod,
2315 kumpf 1.27     const String& authenticationHeader,
2316                Uint32 contentLength)
2317            {
2318                char nn[] = { '0' + (rand() % 10), '0' + (rand() % 10), '\0' };
2319 mike  1.23 
2320 kumpf 1.82     if (httpMethod == HTTP_METHOD_M_POST)
2321                {
2322                    out << "M-POST " << requestUri << " HTTP/1.1\r\n";
2323                }
2324                else
2325                {
2326                    out << "POST " << requestUri << " HTTP/1.1\r\n";
2327                }
2328 kumpf 1.27     out << "HOST: " << host << "\r\n";
2329 kumpf 1.47     out << "Content-Type: application/xml; charset=\"utf-8\"\r\n";
2330 kumpf 1.27     out << "Content-Length: " << contentLength << "\r\n";
2331 kumpf 1.82     if (httpMethod == HTTP_METHOD_M_POST)
2332                {
2333                    out << "Man: http://www.hp.com; ns=";
2334                    out << nn <<"\r\n";
2335                    out << nn << "-CIMExport: MethodRequest\r\n";
2336                    out << nn << "-CIMExportMethod: " << cimMethod << "\r\n";
2337                }
2338                else
2339                {
2340                    out << "CIMExport: MethodRequest\r\n";
2341                    out << "CIMExportMethod: " << cimMethod << "\r\n";
2342                }
2343            
2344 kumpf 1.27     if (authenticationHeader.size())
2345                {
2346                    out << authenticationHeader << "\r\n";
2347                }
2348                out << "\r\n";
2349            }
2350 mike  1.23 
2351 kumpf 1.27 //------------------------------------------------------------------------------
2352            //
2353            // appendEMethodResponseHeader()
2354            //
2355            //     Build HTTP response header for export operation.
2356            //
2357            //------------------------------------------------------------------------------
2358 mike  1.23 
2359 kumpf 1.27 void XmlWriter::appendEMethodResponseHeader(
2360                Array<Sint8>& out,
2361 kumpf 1.82     HttpMethod httpMethod,
2362 kumpf 1.27     Uint32 contentLength)
2363            {
2364                char nn[] = { '0' + (rand() % 10), '0' + (rand() % 10), '\0' };
2365 mike  1.23 
2366 kumpf 1.48     out << "HTTP/1.1 " HTTP_STATUS_OK "\r\n";
2367 kumpf 1.47     out << "Content-Type: application/xml; charset=\"utf-8\"\r\n";
2368 kumpf 1.27     out << "Content-Length: " << contentLength << "\r\n";
2369 kumpf 1.82     if (httpMethod == HTTP_METHOD_M_POST)
2370                {
2371                    out << "Ext:\r\n";
2372                    out << "Cache-Control: no-cache\r\n";
2373                    out << "Man: http://www.dmtf.org/cim/mapping/http/v1.0; ns=";
2374                    out << nn <<"\r\n";
2375                    out << nn << "-CIMExport: MethodResponse\r\n\r\n";
2376                }
2377                else
2378                {
2379                    out << "CIMExport: MethodResponse\r\n\r\n";
2380                }
2381 mike  1.23 }
2382            
2383            //------------------------------------------------------------------------------
2384            //
2385 kumpf 1.29 // _appendSimpleExportReqElementBegin()
2386            // _appendSimpleExportReqElementEnd()
2387 kumpf 1.27 //
2388            //     <!ELEMENT SIMPLEEXPREQ (EXPMETHODCALL)>
2389 mike  1.23 //
2390            //------------------------------------------------------------------------------
2391            
2392 kumpf 1.29 void XmlWriter::_appendSimpleExportReqElementBegin(
2393 kumpf 1.27     Array<Sint8>& out)
2394 mike  1.23 {
2395 kumpf 1.27     out << "<SIMPLEEXPREQ>\n";
2396            }
2397 mike  1.23 
2398 kumpf 1.29 void XmlWriter::_appendSimpleExportReqElementEnd(
2399 kumpf 1.27     Array<Sint8>& out)
2400            {
2401                out << "</SIMPLEEXPREQ>\n";
2402 mike  1.23 }
2403            
2404            //------------------------------------------------------------------------------
2405            //
2406 kumpf 1.29 // _appendEMethodCallElementBegin()
2407            // _appendEMethodCallElementEnd()
2408 kumpf 1.27 //
2409            //     <!ELEMENT EXPMETHODCALL (IPARAMVALUE*)>
2410            //     <!ATTLIST EXPMETHODCALL %CIMName;>
2411 mike  1.23 //
2412            //------------------------------------------------------------------------------
2413            
2414 kumpf 1.29 void XmlWriter::_appendEMethodCallElementBegin(
2415 mike  1.23     Array<Sint8>& out,
2416 kumpf 1.80     const CIMName& name)
2417 mike  1.23 {
2418 kumpf 1.27     out << "<EXPMETHODCALL NAME=\"" << name << "\">\n";
2419 mike  1.24 }
2420            
2421 kumpf 1.29 void XmlWriter::_appendEMethodCallElementEnd(
2422 kumpf 1.27     Array<Sint8>& out)
2423 mike  1.24 {
2424                out << "</EXPMETHODCALL>\n";
2425            }
2426            
2427            //------------------------------------------------------------------------------
2428            //
2429 kumpf 1.29 // _appendSimpleExportRspElementBegin()
2430            // _appendSimpleExportRspElementEnd()
2431 mike  1.24 //
2432 kumpf 1.27 //     <!ELEMENT SIMPLEEXPRSP (EXPMETHODRESPONSE)>
2433 mike  1.24 //
2434            //------------------------------------------------------------------------------
2435            
2436 kumpf 1.29 void XmlWriter::_appendSimpleExportRspElementBegin(
2437 kumpf 1.27     Array<Sint8>& out)
2438            {
2439                out << "<SIMPLEEXPRSP>\n";
2440            }
2441            
2442 kumpf 1.29 void XmlWriter::_appendSimpleExportRspElementEnd(
2443 kumpf 1.27     Array<Sint8>& out)
2444 mike  1.24 {
2445 kumpf 1.27     out << "</SIMPLEEXPRSP>\n";
2446 mike  1.24 }
2447            
2448            //------------------------------------------------------------------------------
2449            //
2450 kumpf 1.29 // _appendEMethodResponseElementBegin()
2451            // _appendEMethodResponseElementEnd()
2452 mike  1.24 //
2453            //     <!ELEMENT EXPMETHODRESPONSE (ERROR|IRETURNVALUE?)>
2454            //     <!ATTLIST EXPMETHODRESPONSE %CIMName;>
2455            //
2456            //------------------------------------------------------------------------------
2457            
2458 kumpf 1.29 void XmlWriter::_appendEMethodResponseElementBegin(
2459 kumpf 1.27     Array<Sint8>& out,
2460 kumpf 1.80     const CIMName& name)
2461 mike  1.24 {
2462                out << "<EXPMETHODRESPONSE NAME=\"" << name << "\">\n";
2463 kumpf 1.27 }
2464            
2465 kumpf 1.29 void XmlWriter::_appendEMethodResponseElementEnd(
2466 kumpf 1.27     Array<Sint8>& out)
2467            {
2468 mike  1.24     out << "</EXPMETHODRESPONSE>\n";
2469            }
2470            
2471            //------------------------------------------------------------------------------
2472            //
2473 kumpf 1.27 // XmlWriter::formatSimpleEMethodReqMessage()
2474 mike  1.24 //
2475            //------------------------------------------------------------------------------
2476            
2477 kumpf 1.27 Array<Sint8> XmlWriter::formatSimpleEMethodReqMessage(
2478 kumpf 1.50     const char* requestUri,
2479 kumpf 1.27     const char* host,
2480 kumpf 1.80     const CIMName& eMethodName,
2481 kumpf 1.27     const String& messageId,
2482 kumpf 1.82     HttpMethod httpMethod,
2483 kumpf 1.27     const String& authenticationHeader,
2484                const Array<Sint8>& body)
2485 mike  1.24 {
2486                Array<Sint8> out;
2487 kumpf 1.27     Array<Sint8> tmp;
2488            
2489 kumpf 1.29     _appendMessageElementBegin(out, messageId);
2490                _appendSimpleExportReqElementBegin(out);
2491                _appendEMethodCallElementBegin(out, eMethodName);
2492 kumpf 1.27     out << body;
2493 kumpf 1.29     _appendEMethodCallElementEnd(out);
2494                _appendSimpleExportReqElementEnd(out);
2495                _appendMessageElementEnd(out);
2496 kumpf 1.27 
2497                appendEMethodRequestHeader(
2498                    tmp,
2499 kumpf 1.50         requestUri,
2500 kumpf 1.27         host,
2501                    eMethodName,
2502 kumpf 1.82         httpMethod,
2503 kumpf 1.27         authenticationHeader,
2504            	out.size());
2505                tmp << out;
2506 mike  1.24 
2507 kumpf 1.50     return tmp;
2508 mike  1.24 }
2509            
2510            //------------------------------------------------------------------------------
2511            //
2512 kumpf 1.27 // XmlWriter::formatSimpleEMethodRspMessage()
2513 mike  1.24 //
2514            //------------------------------------------------------------------------------
2515            
2516 kumpf 1.27 Array<Sint8> XmlWriter::formatSimpleEMethodRspMessage(
2517 kumpf 1.80     const CIMName& eMethodName,
2518 mike  1.24     const String& messageId,
2519 kumpf 1.82     HttpMethod httpMethod,
2520 mike  1.24     const Array<Sint8>& body)
2521            {
2522 kumpf 1.27     Array<Sint8> out;
2523                Array<Sint8> tmp;
2524            
2525 kumpf 1.29     _appendMessageElementBegin(out, messageId);
2526                _appendSimpleExportRspElementBegin(out);
2527                _appendEMethodResponseElementBegin(out, eMethodName);
2528 kumpf 1.27     out << body;
2529 kumpf 1.29     _appendEMethodResponseElementEnd(out);
2530                _appendSimpleExportRspElementEnd(out);
2531                _appendMessageElementEnd(out);
2532 kumpf 1.28 
2533 kumpf 1.82     appendEMethodResponseHeader(tmp, httpMethod, out.size());
2534 kumpf 1.28     tmp << out;
2535            
2536                return tmp;
2537            }
2538            
2539            //------------------------------------------------------------------------------
2540            //
2541            // XmlWriter::formatSimpleEMethodErrorRspMessage()
2542            //
2543            //------------------------------------------------------------------------------
2544            
2545            Array<Sint8> XmlWriter::formatSimpleEMethodErrorRspMessage(
2546 kumpf 1.80     const CIMName& eMethodName,
2547 kumpf 1.28     const String& messageId,
2548 kumpf 1.82     HttpMethod httpMethod,
2549 kumpf 1.42     const CIMException& cimException)
2550 kumpf 1.28 {
2551                Array<Sint8> out;
2552                Array<Sint8> tmp;
2553            
2554 kumpf 1.29     _appendMessageElementBegin(out, messageId);
2555                _appendSimpleExportRspElementBegin(out);
2556 kumpf 1.80     _appendEMethodResponseElementBegin(out, eMethodName);
2557 kumpf 1.42     _appendErrorElement(out, cimException);
2558 kumpf 1.29     _appendEMethodResponseElementEnd(out);
2559                _appendSimpleExportRspElementEnd(out);
2560                _appendMessageElementEnd(out);
2561 kumpf 1.27 
2562 kumpf 1.82     appendEMethodResponseHeader(tmp, httpMethod, out.size());
2563 kumpf 1.27     tmp << out;
2564            
2565                return tmp;
2566 mike  1.24 }
2567            
2568            //------------------------------------------------------------------------------
2569            //
2570 kumpf 1.27 // _printAttributes()
2571 mike  1.24 //
2572            //------------------------------------------------------------------------------
2573            
2574 kumpf 1.27 static void _printAttributes(
2575                PEGASUS_STD(ostream)& os,
2576                const XmlAttribute* attributes,
2577                Uint32 attributeCount)
2578 mike  1.24 {
2579 kumpf 1.27     for (Uint32 i = 0; i < attributeCount; i++)
2580                {
2581            	os << attributes[i].name << "=";
2582            
2583            	os << '"';
2584            	_appendSpecial(os, attributes[i].value);
2585            	os << '"';
2586 mike  1.24 
2587 kumpf 1.27 	if (i + 1 != attributeCount)
2588            	    os << ' ';
2589                }
2590 mike  1.24 }
2591            
2592            //------------------------------------------------------------------------------
2593            //
2594 kumpf 1.27 // _indent()
2595 mike  1.24 //
2596            //------------------------------------------------------------------------------
2597            
2598 kumpf 1.27 static void _indent(PEGASUS_STD(ostream)& os, Uint32 level, Uint32 indentChars)
2599 mike  1.24 {
2600 kumpf 1.27     Uint32 n = level * indentChars;
2601            
2602                for (Uint32 i = 0; i < n; i++)
2603            	os << ' ';
2604 mike  1.24 }
2605            
2606            //------------------------------------------------------------------------------
2607            //
2608 kumpf 1.27 // indentedPrint()
2609 mike  1.24 //
2610            //------------------------------------------------------------------------------
2611            
2612 kumpf 1.27 void XmlWriter::indentedPrint(
2613                PEGASUS_STD(ostream)& os, 
2614                const char* text, 
2615                Uint32 indentChars)
2616 mike  1.24 {
2617 kumpf 1.27     char* tmp = strcpy(new char[strlen(text) + 1], text);
2618            
2619                XmlParser parser(tmp);
2620                XmlEntry entry;
2621                Stack<const char*> stack;
2622 kumpf 1.26 
2623 kumpf 1.27     while (parser.next(entry))
2624 kumpf 1.26     {
2625 kumpf 1.27 	switch (entry.type)
2626            	{
2627            	    case XmlEntry::XML_DECLARATION:
2628            	    {
2629            		_indent(os, stack.size(), indentChars);
2630            
2631            		os << "<?" << entry.text << " ";
2632            		_printAttributes(os, entry.attributes, entry.attributeCount);
2633            		os << "?>";
2634            		break;
2635            	    }
2636            
2637            	    case XmlEntry::START_TAG:
2638            	    {
2639            		_indent(os, stack.size(), indentChars);
2640            
2641            		os << "<" << entry.text;
2642            
2643            		if (entry.attributeCount)
2644            		    os << ' ';
2645            
2646 kumpf 1.27 		_printAttributes(os, entry.attributes, entry.attributeCount);
2647            		os << ">";
2648            		stack.push(entry.text);
2649            		break;
2650            	    }
2651            
2652            	    case XmlEntry::EMPTY_TAG:
2653            	    {
2654            		_indent(os, stack.size(), indentChars);
2655            
2656            		os << "<" << entry.text << " ";
2657            		_printAttributes(os, entry.attributes, entry.attributeCount);
2658            		os << "/>";
2659            		break;
2660            	    }
2661            
2662            	    case XmlEntry::END_TAG:
2663            	    {
2664            		if (!stack.isEmpty() && strcmp(stack.top(), entry.text) == 0)
2665            		    stack.pop();
2666            
2667 kumpf 1.27 		_indent(os, stack.size(), indentChars);
2668            
2669            		os << "</" << entry.text << ">";
2670            		break;
2671            	    }
2672            
2673            	    case XmlEntry::COMMENT:
2674            	    {
2675            
2676            		_indent(os, stack.size(), indentChars);
2677            		os << "<!--";
2678            		_appendSpecial(os, entry.text);
2679            		os << "-->";
2680            		break;
2681            	    }
2682            
2683            	    case XmlEntry::CONTENT:
2684            	    {
2685            		_indent(os, stack.size(), indentChars);
2686            		_appendSpecial(os, entry.text);
2687            		break;
2688 kumpf 1.27 	    }
2689            
2690            	    case XmlEntry::CDATA:
2691            	    {
2692            		_indent(os, stack.size(), indentChars);
2693            		os << "<![CDATA[...]]>";
2694            		break;
2695            	    }
2696            
2697            	    case XmlEntry::DOCTYPE:
2698            	    {
2699            		_indent(os, stack.size(), indentChars);
2700            		os << "<!DOCTYPE...>";
2701            		break;
2702            	    }
2703            	}
2704            
2705            	os << PEGASUS_STD(endl);
2706 kumpf 1.26     }
2707            
2708 kumpf 1.27     delete [] tmp;
2709 mike  1.24 }
2710            
2711            //------------------------------------------------------------------------------
2712            //
2713 kumpf 1.27 // XmlWriter::getNextMessageId()
2714 mike  1.24 //
2715            //------------------------------------------------------------------------------
2716            
2717 kumpf 1.27 String XmlWriter::getNextMessageId()
2718 mike  1.24 {
2719 kumpf 1.27     // ATTN: make thread-safe:
2720                static Uint32 messageId = 1000;
2721 mike  1.24 
2722 kumpf 1.27     messageId++;
2723 mike  1.24 
2724 kumpf 1.27     if (messageId < 1000)
2725            	messageId = 1001;
2726 mike  1.23 
2727 kumpf 1.27     char buffer[16];
2728                sprintf(buffer, "%d", messageId);
2729                return buffer;
2730 kumpf 1.68 }
2731            
2732            //------------------------------------------------------------------------------
2733            //
2734            // XmlWriter::keyBindingTypeToString
2735            //
2736            //------------------------------------------------------------------------------
2737 kumpf 1.79 const char* XmlWriter::keyBindingTypeToString (CIMKeyBinding::Type type)
2738 kumpf 1.68 {
2739                switch (type)
2740                {
2741 kumpf 1.79         case CIMKeyBinding::BOOLEAN:
2742 kumpf 1.68             return "boolean";
2743            
2744 kumpf 1.79         case CIMKeyBinding::STRING:
2745 kumpf 1.68             return "string";
2746            
2747 kumpf 1.79         case CIMKeyBinding::NUMERIC:
2748 kumpf 1.68             return "numeric";
2749            
2750 kumpf 1.79         case CIMKeyBinding::REFERENCE:
2751 kumpf 1.68         default:
2752                        PEGASUS_ASSERT(false);
2753                }
2754            
2755                return "unknown";
2756 mike  1.23 }
2757            
2758            PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2