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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2