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

   1 karl  1.20 //%2006////////////////////////////////////////////////////////////////////////
   2 yi.zhou 1.1  //
   3              // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
   4              // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
   5              // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
   6              // IBM Corp.; EMC Corporation, The Open Group.
   7              // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
   8              // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
   9              // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
  10              // EMC Corporation; VERITAS Software Corporation; The Open Group.
  11 karl    1.20 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
  12              // EMC Corporation; Symantec Corporation; The Open Group.
  13 yi.zhou 1.1  //
  14              // Permission is hereby granted, free of charge, to any person obtaining a copy
  15              // of this software and associated documentation files (the "Software"), to
  16              // deal in the Software without restriction, including without limitation the
  17              // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  18              // sell copies of the Software, and to permit persons to whom the Software is
  19              // furnished to do so, subject to the following conditions:
  20 karl    1.20 // 
  21 yi.zhou 1.1  // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
  22              // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
  23              // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
  24              // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  25              // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  26              // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  27              // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28              // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29              //
  30              //==============================================================================
  31              //
  32              //%/////////////////////////////////////////////////////////////////////////////
  33              
  34              #include <Pegasus/Common/Exception.h>
  35              #include <Pegasus/Common/Tracer.h>
  36 yi.zhou 1.12 #include <Pegasus/Common/CommonUTF.h>
  37 kumpf   1.26 #include <Pegasus/Common/Constants.h>
  38              #include <Pegasus/Common/StringConversion.h>
  39              #include <Pegasus/Common/ArrayInternal.h>
  40              
  41              #if defined(PEGASUS_HAS_ICU) && defined(PEGASUS_INDFORMATTER_USE_ICU)
  42              # include <unicode/locid.h>
  43              # include <unicode/datefmt.h>
  44              # include <unicode/unistr.h>
  45              #endif
  46 yi.zhou 1.1  
  47              #include "IndicationFormatter.h"
  48              
  49              PEGASUS_NAMESPACE_BEGIN
  50              
  51 kumpf   1.26 ///////////////////////////////////////////////////////////////////////////////
  52              //
  53              // CIMValueLocalizer
  54              //
  55              ///////////////////////////////////////////////////////////////////////////////
  56              
  57              class CIMValueLocalizer
  58              {
  59              public:
  60              
  61                  /**
  62                      Constructs a CIMValueLocalizer object.  The CIMValueLocalizer can be
  63                      used to localize a CIMValue string based on a specified
  64                      ContentLanguageList.  Localization is possible only if the
  65                      ContentLanguageList includes no more than one language tag.
  66              
  67                      @param contentLangs A ContentLanguageList containing a LanguageTag
  68                          with which to perform localization.
  69                  */
  70                  CIMValueLocalizer(const ContentLanguageList& contentLangs);
  71                  ~CIMValueLocalizer();
  72 kumpf   1.26 
  73                  String getLocalizedValue(Boolean value) const
  74                  {
  75                      return _localizeBoolean(value);
  76                  }
  77              
  78                  String getLocalizedValue(Uint8 value) const
  79                  {
  80                      return getLocalizedValue(Uint32(value));
  81                  }
  82              
  83                  String getLocalizedValue(Sint8 value) const
  84                  {
  85                      return getLocalizedValue(Sint32(value));
  86                  }
  87              
  88                  String getLocalizedValue(Uint16 value) const
  89                  {
  90                      return getLocalizedValue(Uint32(value));
  91                  }
  92              
  93 kumpf   1.26     String getLocalizedValue(Sint16 value) const
  94                  {
  95                      return getLocalizedValue(Sint32(value));
  96                  }
  97              
  98                  String getLocalizedValue(Uint32 value) const
  99                  {
 100                      Uint32 outputLength = 0;
 101                      char buffer[22];
 102                      const char* output = Uint32ToString(buffer, value, outputLength);
 103                      return String(output, outputLength);
 104                  }
 105              
 106                  String getLocalizedValue(Sint32 value) const
 107                  {
 108                      Uint32 outputLength = 0;
 109                      char buffer[22];
 110                      const char* output = Sint32ToString(buffer, value, outputLength);
 111                      return String(output, outputLength);
 112                  }
 113              
 114 kumpf   1.26     String getLocalizedValue(Uint64 value) const
 115                  {
 116                      Uint32 outputLength = 0;
 117                      char buffer[22];
 118                      const char* output = Uint64ToString(buffer, value, outputLength);
 119                      return String(output, outputLength);
 120                  }
 121              
 122                  String getLocalizedValue(Sint64 value) const
 123                  {
 124                      Uint32 outputLength = 0;
 125                      char buffer[22];
 126                      const char* output = Sint64ToString(buffer, value, outputLength);
 127                      return String(output, outputLength);
 128                  }
 129              
 130                  String getLocalizedValue(Real32 value) const
 131                  {
 132                      char buffer[32];
 133                      sprintf(buffer, "%.7e", value);
 134                      return String(buffer);
 135 kumpf   1.26     }
 136              
 137                  String getLocalizedValue(Real64 value) const
 138                  {
 139                      char buffer[32];
 140                      sprintf(buffer, "%.16e", value);
 141                      return String(buffer);
 142                  }
 143              
 144                  String getLocalizedValue(Char16 value) const
 145                  {
 146                      return String(&value, 1);
 147                  }
 148              
 149                  String getLocalizedValue(const String& value) const
 150                  {
 151                      return value;
 152                  }
 153              
 154                  String getLocalizedValue(const CIMDateTime& value) const
 155                  {
 156 kumpf   1.26         return _localizeDateTime(value);
 157                  }
 158              
 159                  String getLocalizedValue(const CIMObjectPath& value) const
 160                  {
 161                      return value.toString();
 162                  }
 163              
 164                  String getLocalizedValue(const CIMObject& value) const
 165                  {
 166                      return value.toString();
 167                  }
 168              
 169                  String getLocalizedValue(const CIMInstance& value) const
 170                  {
 171                      return CIMObject(value).toString();
 172                  }
 173              
 174              private:
 175              
 176                  CIMValueLocalizer(const CIMValueLocalizer&);
 177 kumpf   1.26     CIMValueLocalizer& operator=(const CIMValueLocalizer&);
 178              
 179                  String _localizeDateTime(const CIMDateTime& dateTimeValue) const;
 180                  String _localizeBoolean(Boolean booleanValue) const;
 181              
 182                  Boolean canLocalize;
 183              #if defined(PEGASUS_HAS_ICU) && defined(PEGASUS_INDFORMATTER_USE_ICU)
 184                  Locale locale;
 185              #endif
 186              };
 187              
 188              CIMValueLocalizer::CIMValueLocalizer(const ContentLanguageList& contentLangs)
 189              {
 190                  canLocalize = false;
 191              
 192              #if defined(PEGASUS_HAS_ICU) && defined(PEGASUS_INDFORMATTER_USE_ICU)
 193                  if (InitializeICU::initICUSuccessful())
 194                  {
 195                      if (contentLangs.size() == 0)
 196                      {
 197                          // No language specified; use the default.
 198 kumpf   1.26             locale = Locale::getDefault();
 199                          canLocalize = true;
 200                      }
 201                      else if (contentLangs.size() == 1)
 202                      {
 203                          LanguageTag languageTag = contentLangs.getLanguageTag(0);
 204                          locale = Locale(
 205                              (const char*) languageTag.getLanguage.getCString(),
 206                              (const char*) languageTag.getCountry.getCString(),
 207                              (const char*) languageTag.getVariant.getCString());
 208                          canLocalize = !locale.isBogus();
 209                      }
 210                      else
 211                      {
 212                          // ContentLanguageList has multiple language tags; do not localize.
 213                      }
 214                  }
 215              #endif
 216              }
 217              
 218              CIMValueLocalizer::~CIMValueLocalizer()
 219 kumpf   1.26 {
 220              }
 221              
 222              String CIMValueLocalizer::_localizeDateTime(
 223                  const CIMDateTime& dateTimeValue) const
 224              {
 225              #if defined(PEGASUS_HAS_ICU) && defined(PEGASUS_INDFORMATTER_USE_ICU)
 226                  PEG_METHOD_ENTER(TRC_IND_FORMATTER, "CIMValueLocalizer::_localizeDateTime");
 227              
 228                  if (canLocalize)
 229                  {
 230                      // The CIMDateTime epoch begins 1/1/0000 (12 am Jan 1, 1BCE).
 231                      // The ICU epoch begins 1/1/1970 (1 January 1970 0:00 UTC).
 232              
 233                      const CIMDateTime EPOCH1970 = CIMDateTime("19700101000000.000000+000");
 234                      UDate icuDateTimeMillisecs = (Sint64)
 235                          (dateTimeValue.toMicroSeconds() - EPOCH1970.toMicroSeconds())/1000;
 236              
 237                      // Use a medium length DATE/TIME format (e.g., Jan 12, 1982 3:30:32pm)
 238                      AutoPtr<DateFormat> fmt;
 239              
 240 kumpf   1.26         try
 241                      {
 242                          if (locale == 0)
 243                          {
 244                              fmt.reset(DateFormat::createDateTimeInstance(
 245                                  DateFormat::MEDIUM, DateFormat::MEDIUM);
 246                          }
 247                          else
 248                          {
 249                              fmt.reset(DateFormat::createDateTimeInstance(
 250                                  DateFormat::MEDIUM, DateFormat::MEDIUM, locale);
 251                          }
 252                      }
 253                      catch (...)
 254                      {
 255 marek   1.28             PEG_TRACE_CSTRING(TRC_IND_FORMATTER, Tracer::LEVEL2,
 256 kumpf   1.26                 "Caught exception from DateFormat::createDateTimeInstance");
 257              
 258                          PEG_METHOD_EXIT();
 259                          return dateTimeValue.toString();
 260                      }
 261              
 262                      if (fmt.get() == 0)
 263                      {
 264 marek   1.28             PEG_TRACE_CSTRING(TRC_IND_FORMATTER, Tracer::LEVEL2,
 265 kumpf   1.26                 "Memory allocation error creating DateTime instance.");
 266                          PEG_METHOD_EXIT();
 267                          return dateTimeValue.toString();
 268                      }
 269              
 270                      // Format the Date and Time
 271                      UErrorCode status = U_ZERO_ERROR;
 272                      UnicodeString dateTimeUniStr;
 273                      fmt->format(icuDateTimeMillisecs, dateTimeUniStr, status);
 274              
 275                      if (U_FAILURE(status))
 276                      {
 277                          PEG_METHOD_EXIT();
 278                          return dateTimeValue.toString();
 279                      }
 280              
 281                      // convert UnicodeString to char *
 282                      char dateTimeBuffer[256];
 283                      String datetimeStr;
 284              
 285                      // Copy the contents of the string into dateTimeBuffer
 286 kumpf   1.26         Uint32 strLen = dateTimeUniStr.extract(
 287                          0, sizeof(dateTimeBuffer), dateTimeBuffer);
 288              
 289                      if (strLen >= sizeof(dateTimeBuffer))
 290                      {
 291                          // There is not enough space in dateTimeBuffer
 292                          char* extractedStr = new char[strLen + 1];
 293                          strLen = dateTimeUniStr.extract(0, strLen + 1, extractedStr);
 294                          datetimeStr = extractedStr;
 295                          delete extractedStr;
 296                      }
 297                      else
 298                      {
 299                          datetimeStr = dateTimeBuffer;
 300                      }
 301              
 302                      PEG_METHOD_EXIT();
 303                      return datetimeStr;
 304                  }
 305              
 306                  PEG_METHOD_EXIT();
 307 kumpf   1.26 #endif
 308              
 309                  return dateTimeValue.toString();
 310              }
 311              
 312              String CIMValueLocalizer::_localizeBoolean(Boolean booleanValue) const
 313              {
 314                  PEG_METHOD_ENTER(TRC_IND_FORMATTER, "CIMValueLocalizer::_localizeBoolean");
 315              
 316                  if (canLocalize)
 317                  {
 318                      if (booleanValue)
 319                      {
 320                          MessageLoaderParms parms(
 321                              "Common.IndicationFormatter._MSG_BOOLEAN_TRUE",
 322                              "true");
 323              
 324                          PEG_METHOD_EXIT();
 325                          return MessageLoader::getMessage(parms);
 326                      }
 327                      else
 328 kumpf   1.26         {
 329                          MessageLoaderParms parms(
 330                              "Common.IndicationFormatter._MSG_BOOLEAN_FALSE",
 331                              "false");
 332              
 333                          PEG_METHOD_EXIT();
 334                          return MessageLoader::getMessage(parms);
 335                      }
 336                  }
 337              
 338                  PEG_METHOD_EXIT();
 339                  return booleanValue ? "true" : "false";
 340              }
 341              
 342              
 343              ///////////////////////////////////////////////////////////////////////////////
 344              //
 345              // IndicationFormatter
 346              //
 347              ///////////////////////////////////////////////////////////////////////////////
 348              
 349 kumpf   1.26 template<class T>
 350              void appendArrayValue(
 351                  String& buffer,
 352                  const CIMValue& value,
 353                  Uint32 arrayIndex,
 354                  const CIMValueLocalizer& cimValueLocalizer)
 355              {
 356                  PEGASUS_ASSERT(value.isArray());
 357              
 358                  Array<T> arrayValue;
 359                  value.get(arrayValue);
 360              
 361                  // Empty brackets (e.g. []), gets all values of the array
 362                  if (arrayIndex == PEG_NOT_FOUND)
 363                  {
 364                      buffer.append("[");
 365              
 366                      for (Uint32 i = 0, arraySize = arrayValue.size(); i < arraySize; i++)
 367                      {
 368                          buffer.append(cimValueLocalizer.getLocalizedValue(arrayValue[i]));
 369                          if (i < arraySize - 1)
 370 kumpf   1.26             {
 371                              buffer.append(",");
 372                          }
 373                      }
 374              
 375                      buffer.append("]");
 376                  }
 377                  else
 378                  {
 379                      buffer.append(
 380                          cimValueLocalizer.getLocalizedValue(arrayValue[arrayIndex]));
 381                  }
 382              }
 383              
 384 kumpf   1.21 void IndicationFormatter::validateTextFormat(
 385                  const String& textStr,
 386                  const CIMClass& indicationClass,
 387                  const Array<String>& textFormatParams)
 388 yi.zhou 1.1  {
 389 kumpf   1.21     PEG_METHOD_ENTER(TRC_IND_FORMATTER,
 390                      "IndicationFormatter::validateTextFormat");
 391 yi.zhou 1.1  
 392                  String textFormatStr = textStr;
 393                  Uint32 leftBrace = textFormatStr.find("{");
 394                  Uint32 rightBrace;
 395              
 396 kumpf   1.21     do
 397                  {
 398 kumpf   1.26         String textFormatSubStr;
 399              
 400 kumpf   1.21         if (leftBrace != PEG_NOT_FOUND)
 401                      {
 402                          // Do not expect a right brace before the left
 403                          // brace. e.g An invalid text format string could be:
 404                          // "Indication occurred at 2, datetime} with
 405                          // identify ID {3, string}"
 406              
 407                          textFormatSubStr = textFormatStr.subString(0, leftBrace);
 408              
 409                          Uint32 rightBrace2 = textFormatSubStr.find("}");
 410                          if (rightBrace2 != PEG_NOT_FOUND)
 411                          {
 412                              textFormatSubStr = textFormatStr.subString(
 413                                  0, (rightBrace2 + 1));
 414                              MessageLoaderParms parms(
 415 kumpf   1.25                     "Common.IndicationFormatter."
 416 kumpf   1.21                         "_MSG_INVALID_SYNTAX_OF_FOR_PROPERTY",
 417                                  "Invalid syntax at $0 in property $1",
 418                                  textFormatSubStr,
 419                                  _PROPERTY_TEXTFORMAT.getString());
 420              
 421                              PEG_METHOD_EXIT();
 422 kumpf   1.26                 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_INVALID_PARAMETER, parms);
 423 kumpf   1.21             }
 424              
 425                          // expect right brace
 426 kumpf   1.26             textFormatStr = textFormatStr.subString(leftBrace+1);
 427 kumpf   1.21             rightBrace = textFormatStr.find("}");
 428              
 429                          // Do not expect a left brace between left and right
 430                          // braces. e.g A text string: "Indication occurred
 431                          // at {2, datetime with identify ID {3, string}" is
 432                          // an invalid format.
 433              
 434                          if (rightBrace != PEG_NOT_FOUND)
 435                          {
 436                              textFormatSubStr.clear();
 437                              textFormatSubStr = textFormatStr.subString(0, rightBrace);
 438              
 439                              Uint32 leftBrace2 = textFormatSubStr.find("{");
 440                              if (leftBrace2 != PEG_NOT_FOUND)
 441                              {
 442                                  textFormatSubStr = textFormatStr.subString(
 443                                      0, (leftBrace2 + 1));
 444                                  MessageLoaderParms parms(
 445 kumpf   1.25                         "Common.IndicationFormatter."
 446 kumpf   1.21                             "_MSG_INVALID_SYNTAX_OF_FOR_PROPERTY",
 447                                      "Invalid syntax at $0 in property $1",
 448                                      textFormatSubStr,
 449                                      _PROPERTY_TEXTFORMAT.getString());
 450              
 451                                  PEG_METHOD_EXIT();
 452 kumpf   1.26                     throw PEGASUS_CIM_EXCEPTION_L(
 453                                      CIM_ERR_INVALID_PARAMETER, parms);
 454 kumpf   1.21                 }
 455              
 456                              String propertyParam;
 457                              String propertyTypeStr;
 458                              String propertyIndexStr;
 459 kumpf   1.26                 Uint32 comma = textFormatSubStr.find(",");
 460 kumpf   1.21 
 461                              if (comma == PEG_NOT_FOUND)
 462                              {
 463 kumpf   1.26                     // A dynamic content can have format either
 464                                  // {index} or {index[x]}
 465                                  propertyParam = textFormatSubStr;
 466 kumpf   1.21                     propertyTypeStr = String::EMPTY;
 467                              }
 468                              else
 469                              {
 470 kumpf   1.26                     // A dynamic content can have format either
 471                                  // {index, type} or {index[x], type}
 472 kumpf   1.21                     propertyParam = textFormatSubStr.subString(0, comma);
 473 kumpf   1.26                     propertyTypeStr = textFormatSubStr.subString(comma +1);
 474                              }
 475 kumpf   1.21 
 476 kumpf   1.26                 Uint32 leftBracket = propertyParam.find("[");
 477                              Uint32 rightBracket = propertyParam.find("]");
 478                              Boolean isArray = false;
 479 kumpf   1.21 
 480                              // A dynamic content has syntax either {index} or {index, type}
 481                              if (leftBracket == PEG_NOT_FOUND)
 482                              {
 483                                  // there is no left bracket, do not expect a right bracket
 484                                  if (rightBracket != PEG_NOT_FOUND)
 485                                  {
 486                                      textFormatSubStr = textFormatStr.subString(
 487                                          0, (rightBracket + 1));
 488                                      MessageLoaderParms parms(
 489 kumpf   1.25                             "Common.IndicationFormatter."
 490 kumpf   1.21                                 "_MSG_INVALID_SYNTAX_OF_FOR_PROPERTY",
 491                                          "Invalid syntax at $0 in property $1",
 492                                          textFormatSubStr,
 493                                          _PROPERTY_TEXTFORMAT.getString());
 494              
 495                                      PEG_METHOD_EXIT();
 496 kumpf   1.26                         throw PEGASUS_CIM_EXCEPTION_L(
 497                                          CIM_ERR_INVALID_PARAMETER, parms);
 498 kumpf   1.21                     }
 499              
 500                                  propertyIndexStr = propertyParam;
 501                                  isArray = false;
 502                              }
 503                              // A dynamic content has syntax either
 504                              // {index[]} or {index[], type}
 505                              else
 506                              {
 507                                  // there is a left bracket, expect a right bracket
 508                                  if (rightBracket == PEG_NOT_FOUND)
 509                                  {
 510                                      MessageLoaderParms parms(
 511 kumpf   1.25                             "Common.IndicationFormatter."
 512 kumpf   1.21                                 "_MSG_INVALID_SYNTAX_OF_FOR_PROPERTY",
 513                                          "Invalid syntax at $0 in property $1",
 514                                          textFormatSubStr,
 515                                          _PROPERTY_TEXTFORMAT.getString());
 516              
 517                                      PEG_METHOD_EXIT();
 518 kumpf   1.26                         throw PEGASUS_CIM_EXCEPTION_L(
 519                                          CIM_ERR_INVALID_PARAMETER, parms);
 520 kumpf   1.21                     }
 521              
 522                                  propertyIndexStr = propertyParam.subString(0, leftBracket);
 523                                  isArray = true;
 524                              }
 525              
 526 kumpf   1.26                 Uint32 propertyIndex = _parseIndex(propertyIndexStr);
 527 kumpf   1.21 
 528                              // check the property index
 529 kumpf   1.26                 if (propertyIndex >= textFormatParams.size())
 530 kumpf   1.21                 {
 531                                  // property index is out of bounds
 532                                  MessageLoaderParms parms(
 533 kumpf   1.25                         "Common.IndicationFormatter."
 534                                          "_MSG_INDEX_IS_OUT_OF_BOUNDS",
 535                                      "The value of index $0 in property $1 is out of bounds",
 536                                      propertyIndex,
 537                                      _PROPERTY_TEXTFORMATPARAMETERS.getString());
 538 kumpf   1.21 
 539                                  PEG_METHOD_EXIT();
 540 kumpf   1.26                     throw PEGASUS_CIM_EXCEPTION_L(
 541                                      CIM_ERR_INVALID_PARAMETER, parms);
 542 kumpf   1.21                 }
 543              
 544                              if (propertyTypeStr != String::EMPTY)
 545                              {
 546                                  _validatePropertyType(indicationClass,
 547                                      textFormatParams[propertyIndex],
 548                                      propertyTypeStr, isArray);
 549                              }
 550              
 551 kumpf   1.26                 textFormatStr = textFormatStr.subString(rightBrace+1);
 552 kumpf   1.21             }
 553                          else // no right brace
 554                          {
 555                              MessageLoaderParms parms(
 556 kumpf   1.25                     "Common.IndicationFormatter."
 557 kumpf   1.21                         "_MSG_INVALID_SYNTAX_OF_FOR_PROPERTY",
 558                                  "Invalid syntax at $0 in property $1",
 559                                  textFormatSubStr,
 560                                  _PROPERTY_TEXTFORMAT.getString());
 561              
 562                              PEG_METHOD_EXIT();
 563 kumpf   1.26                 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_INVALID_PARAMETER, parms);
 564 kumpf   1.21             }
 565 yi.zhou 1.1          }
 566                      else // no left brace
 567                      {
 568                          // does not expect right brace
 569 kumpf   1.21             rightBrace = textFormatStr.find("}");
 570 yi.zhou 1.1  
 571 kumpf   1.21             if (rightBrace != PEG_NOT_FOUND)
 572                          {
 573                              textFormatSubStr = textFormatStr.subString(0, rightBrace + 1);
 574                              MessageLoaderParms parms(
 575 kumpf   1.25                     "Common.IndicationFormatter."
 576 kumpf   1.21                         "_MSG_INVALID_SYNTAX_OF_FOR_PROPERTY",
 577                                  "Invalid syntax at $0 in property $1",
 578                                  textFormatSubStr,
 579                                  _PROPERTY_TEXTFORMAT.getString());
 580              
 581                                  PEG_METHOD_EXIT();
 582 kumpf   1.26                     throw PEGASUS_CIM_EXCEPTION_L(
 583                                      CIM_ERR_INVALID_PARAMETER, parms);
 584 yi.zhou 1.1              }
 585 david.dillard 1.4  
 586 kumpf         1.21             break;
 587                            }
 588 yi.zhou       1.1  
 589 kumpf         1.21         leftBrace = textFormatStr.find("{");
 590                        } while (textFormatStr.size() > 0);
 591 yi.zhou       1.1  
 592                        PEG_METHOD_EXIT();
 593                    }
 594                    
 595 kumpf         1.26 inline Boolean _isSpace(Char16 c)
 596                    {
 597                        return (c == ' ') || (c == '\t') || (c == '\r') || (c == '\n');
 598                    }
 599                    
 600                    void IndicationFormatter::_trim(String& s)
 601                    {
 602                        while (s.size() && _isSpace(s[s.size()-1]))
 603                        {
 604                            s.remove(s.size() - 1);
 605                        }
 606                    
 607                        while (s.size() && _isSpace(s[0]))
 608                        {
 609                            s.remove(0, 1);
 610                        }
 611                    }
 612                    
 613 kumpf         1.21 void IndicationFormatter::_validatePropertyType(
 614                        const CIMClass& indicationClass,
 615                        const String& propertyParam,
 616                        const String& typeStr,
 617                        const Boolean& isArray)
 618 yi.zhou       1.1  {
 619 kumpf         1.26     PEG_METHOD_ENTER(TRC_IND_FORMATTER,
 620 kumpf         1.21         "IndicationFormatter::_validatePropertyType");
 621 yi.zhou       1.1  
 622                        String propertyTypeStr = typeStr;
 623                    
 624 kumpf         1.26     Array<String> validPropertyTypes;
 625 kumpf         1.21     validPropertyTypes.append("boolean");
 626                        validPropertyTypes.append("uint8");
 627                        validPropertyTypes.append("sint8");
 628                        validPropertyTypes.append("uint16");
 629                        validPropertyTypes.append("sint16");
 630                        validPropertyTypes.append("uint32");
 631                        validPropertyTypes.append("sint32");
 632                        validPropertyTypes.append("uint64");
 633                        validPropertyTypes.append("sint64");
 634                        validPropertyTypes.append("real32");
 635                        validPropertyTypes.append("real64");
 636                        validPropertyTypes.append("char16");
 637                        validPropertyTypes.append("string");
 638                        validPropertyTypes.append("datetime");
 639                        validPropertyTypes.append("reference");
 640 yi.zhou       1.1  
 641                        propertyTypeStr.toLower();
 642 kumpf         1.26     _trim(propertyTypeStr);
 643 david.dillard 1.4  
 644 yi.zhou       1.1      //
 645                        // Checks if the provided property type is a valid type
 646                        //
 647 kumpf         1.26     if (!(Contains(validPropertyTypes, propertyTypeStr)))
 648 yi.zhou       1.1      {
 649 kumpf         1.21         // the provided property type is not valid type
 650                            MessageLoaderParms parms(
 651 kumpf         1.25             "Common.IndicationFormatter."
 652 kumpf         1.21                 "_MSG_INVALID_TYPE_OF_FOR_PROPERTY",
 653                                "Invalid property type of $0 in property $1",
 654 kumpf         1.26             propertyTypeStr,
 655 kumpf         1.21             _PROPERTY_TEXTFORMAT.getString());
 656 yi.zhou       1.1  
 657 kumpf         1.21         PEG_METHOD_EXIT();
 658 kumpf         1.26         throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_INVALID_PARAMETER, parms);
 659 yi.zhou       1.1      }
 660                    
 661 kumpf         1.21     for (Uint32 i = 0; i < indicationClass.getPropertyCount(); i++)
 662 yi.zhou       1.1      {
 663 kumpf         1.21         CIMName propertyName = indicationClass.getProperty(i).getName();
 664 yi.zhou       1.1  
 665 kumpf         1.21         if (String::equalNoCase(propertyParam, propertyName.getString()))
 666 yi.zhou       1.1          {
 667 kumpf         1.21             // get the property type;
 668                                CIMType propertyType = indicationClass.getProperty(i).getType();
 669 yi.zhou       1.1  
 670 kumpf         1.21             // Check if the property is an array type
 671                                if ((isArray && !(indicationClass.getProperty(i).isArray())) ||
 672                                    (!isArray && indicationClass.getProperty(i).isArray()))
 673                                {
 674                                    MessageLoaderParms parms(
 675 kumpf         1.25                     "Common.IndicationFormatter."
 676 kumpf         1.21                         "_MSG_PROPERTY_IS_NOT_AN_ARRAY_TYPE",
 677                                        "The property $0 is not an array type",
 678                                        propertyName.getString());
 679 yi.zhou       1.1  
 680 kumpf         1.21                 PEG_METHOD_EXIT();
 681 kumpf         1.26                 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_INVALID_PARAMETER, parms);
 682 kumpf         1.21             }
 683 yi.zhou       1.1  
 684 kumpf         1.26             // property type matches
 685                                if (String::equalNoCase(
 686                                        propertyTypeStr, cimTypeToString(propertyType)))
 687 yi.zhou       1.1              {
 688 kumpf         1.21                 break;
 689 david.dillard 1.4              }
 690 kumpf         1.21 
 691 kumpf         1.26             MessageLoaderParms parms(
 692                                    "Common.IndicationFormatter."
 693                                        "_MSG_MISS_MATCHED_TYPE_OF_FOR_PROPERTY",
 694                                    "The provided property type of $0 in $1 does not match "
 695                                        "the property type $2",
 696                                    propertyTypeStr,
 697                                    cimTypeToString(propertyType),
 698                                    _PROPERTY_TEXTFORMAT.getString());
 699 yi.zhou       1.1  
 700 kumpf         1.26             PEG_METHOD_EXIT();
 701                                throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_INVALID_PARAMETER, parms);
 702 yi.zhou       1.1          }
 703                        }
 704                    
 705                        PEG_METHOD_EXIT();
 706                    }
 707                    
 708 kumpf         1.21 void IndicationFormatter::validateTextFormatParameters(
 709                        const CIMPropertyList& propertyList,
 710                        const CIMClass& indicationClass,
 711                        const Array<String>& textFormatParams)
 712 yi.zhou       1.1  {
 713 kumpf         1.21     PEG_METHOD_ENTER(TRC_IND_FORMATTER,
 714                            "IndicationFormatter::validateTextFormatParameters");
 715 yi.zhou       1.1  
 716 kumpf         1.21     Array<String> indicationClassProperties;
 717 david.dillard 1.4  
 718 kumpf         1.21     if (propertyList.isNull())
 719 yi.zhou       1.1      {
 720 kumpf         1.26         // All the properties are selected
 721 kumpf         1.21         for (Uint32 i = 0; i < indicationClass.getPropertyCount(); i++)
 722                            {
 723                                indicationClassProperties.append(
 724                                    indicationClass.getProperty(i).getName().getString());
 725                            }
 726 yi.zhou       1.1      }
 727                        else
 728                        {
 729 kumpf         1.26         // Partial properties are selected
 730 yi.zhou       1.1          Array<CIMName> propertyNames = propertyList.getPropertyNameArray();
 731                    
 732 kumpf         1.21         for (Uint32 j = 0; j < propertyNames.size(); j++)
 733                            {
 734                                indicationClassProperties.append(propertyNames[j].getString());
 735                            }
 736 yi.zhou       1.1      }
 737                    
 738 david.dillard 1.4      // check if the textFormatParams is contained in the
 739 yi.zhou       1.1      // indicationClassProperties
 740                        for (Uint32 k = 0; k < textFormatParams.size(); k++)
 741                        {
 742                            if (!Contains(indicationClassProperties, textFormatParams[k]))
 743 kumpf         1.21         {
 744                                // The property name in TextFormatParameters is not
 745                                // included in the select clause of the associated filter query
 746                                MessageLoaderParms parms(
 747 kumpf         1.25                 "Common.IndicationFormatter."
 748 kumpf         1.21                     "_MSG_MISS_MATCHED_PROPERTY_NAME",
 749                                    "The property name $0 in $1 does not match the properties "
 750                                        "in the select clause",
 751                                    textFormatParams[k],
 752                                    _PROPERTY_TEXTFORMATPARAMETERS.getString());
 753                    
 754                                PEG_METHOD_EXIT();
 755 kumpf         1.26             throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_INVALID_PARAMETER, parms);
 756 kumpf         1.21         }
 757 yi.zhou       1.1      }
 758                    
 759                        PEG_METHOD_EXIT();
 760                    }
 761                    
 762 kumpf         1.26 Uint32 IndicationFormatter::_parseIndex(const String& indexStr)
 763 yi.zhou       1.1  {
 764 kumpf         1.26     Uint32 index = PEG_NOT_FOUND;
 765 marek         1.27     char dummy[2];
 766 kumpf         1.26     int numConversions =
 767 marek         1.27         sscanf(indexStr.getCString(), "%u%1s", &index, dummy);
 768 yi.zhou       1.1  
 769 kumpf         1.26     if ((numConversions != 1) || (index == PEG_NOT_FOUND))
 770                        {
 771                            MessageLoaderParms parms(
 772                                "IndicationFormatter.IndicationFormatter._MSG_INVALID_INDEX",
 773                                "Invalid index string '$0'",
 774                                indexStr);
 775 yi.zhou       1.1  
 776 kumpf         1.26         throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_INVALID_PARAMETER, parms);
 777                        }
 778 yi.zhou       1.16 
 779 kumpf         1.26     return index;
 780                    }
 781 yi.zhou       1.16 
 782 kumpf         1.26 String IndicationFormatter::getFormattedIndText(
 783                        const CIMInstance& subscription,
 784                        const CIMInstance& indication,
 785                        const ContentLanguageList& contentLangs)
 786                    {
 787                        PEG_METHOD_ENTER (TRC_IND_FORMATTER,
 788                            "IndicationFormatter::getFormattedIndText");
 789 yi.zhou       1.16 
 790 kumpf         1.26     String indicationText;
 791                        String textFormat;
 792                        CIMValue textFormatValue;
 793 yi.zhou       1.2      CIMValue textFormatParamsValue;
 794                    
 795 yi.zhou       1.7      Array<String> textFormatParams;
 796 yi.zhou       1.2  
 797 kumpf         1.21     // get TextFormat from subscription
 798                        Uint32 textFormatPos = subscription.findProperty(_PROPERTY_TEXTFORMAT);
 799                    
 800                        // if the property TextFormat is not found,
 801                        // indication is constructed with default format
 802                        if (textFormatPos == PEG_NOT_FOUND)
 803                        {
 804                            indicationText = _formatDefaultIndicationText(indication, contentLangs);
 805                        }
 806                        else
 807                        {
 808                            textFormatValue = subscription.getProperty(textFormatPos).getValue();
 809                    
 810                            // if the value of textFormat is NULL,
 811                            // indication is constructed with default format
 812                            if (textFormatValue.isNull())
 813 yi.zhou       1.2          {
 814 kumpf         1.21             indicationText =
 815                                    _formatDefaultIndicationText(indication, contentLangs);
 816 yi.zhou       1.2          }
 817                            else
 818                            {
 819 kumpf         1.21             // get TextFormatParameters from subscription
 820                                Uint32 textFormatParamsPos = subscription.findProperty(
 821                                    _PROPERTY_TEXTFORMATPARAMETERS);
 822 yi.zhou       1.2  
 823 kumpf         1.21             if (textFormatParamsPos != PEG_NOT_FOUND)
 824                                {
 825                                    textFormatParamsValue = subscription.getProperty(
 826                                        textFormatParamsPos).getValue();
 827                                }
 828 yi.zhou       1.2  
 829 kumpf         1.21             // constructs indication with specified format
 830                                if ((textFormatValue.getType() == CIMTYPE_STRING) &&
 831                                    !(textFormatValue.isArray()))
 832                                {
 833                                    textFormatValue.get(textFormat);
 834                                    if (!textFormatParamsValue.isNull())
 835                                    {
 836                                        if ((textFormatParamsValue.getType() == CIMTYPE_STRING) &&
 837                                            (textFormatParamsValue.isArray()))
 838                                        {
 839                                            textFormatParamsValue.get(textFormatParams);
 840                                        }
 841                                    }
 842 yi.zhou       1.2  
 843 kumpf         1.21                 indicationText = _formatIndicationText(
 844                                        textFormat,
 845                                        textFormatParams,
 846                                        indication,
 847                                        contentLangs);
 848                                }
 849                                else
 850                                {
 851                                    indicationText =
 852                                        _formatDefaultIndicationText(indication, contentLangs);
 853                                }
 854 yi.zhou       1.2          }
 855 kumpf         1.21     }
 856 yi.zhou       1.2  
 857 kumpf         1.21     PEG_METHOD_EXIT();
 858                        return indicationText;
 859 yi.zhou       1.2  }
 860                    
 861                    String IndicationFormatter::_formatDefaultIndicationText(
 862 kumpf         1.21     const CIMInstance& indication,
 863                        const ContentLanguageList& contentLangs)
 864 yi.zhou       1.1  {
 865 david.dillard 1.4      PEG_METHOD_ENTER (TRC_IND_FORMATTER,
 866 yi.zhou       1.2          "IndicationFormatter::_formatDefaultIndicationText");
 867 yi.zhou       1.1  
 868 kumpf         1.26     String indicationStr = "Indication (default format):";
 869 yi.zhou       1.1  
 870 kumpf         1.26     CIMValueLocalizer cimValueLocalizer(contentLangs);
 871 yi.zhou       1.1  
 872 kumpf         1.26     for (Uint32 i = 0, n = indication.getPropertyCount(); i < n; i++)
 873                        {
 874                            if (i > 0)
 875                            {
 876                                indicationStr.append(", ");
 877                            }
 878 yi.zhou       1.2  
 879 kumpf         1.26         CIMConstProperty property = indication.getProperty(i);
 880 yi.zhou       1.1          CIMValue propertyValue = property.getValue();
 881                    
 882 kumpf         1.26         indicationStr.append(property.getName().getString());
 883 yi.zhou       1.1          indicationStr.append(" = ");
 884                    
 885 kumpf         1.26         if (!propertyValue.isNull())
 886 yi.zhou       1.1          {
 887 kumpf         1.26             if (propertyValue.isArray())
 888 yi.zhou       1.1              {
 889 kumpf         1.26                 indicationStr.append(_getArrayValues(
 890                                        propertyValue, PEG_NOT_FOUND, contentLangs));
 891 yi.zhou       1.1              }
 892                                else // value is not an array
 893                                {
 894 kumpf         1.26                 CIMType type = propertyValue.getType();
 895                    
 896                                    if (type == CIMTYPE_DATETIME)
 897 kumpf         1.21                 {
 898 kumpf         1.26                     CIMDateTime dateTimeValue;
 899                                        propertyValue.get(dateTimeValue);
 900                                        indicationStr.append(
 901                                            cimValueLocalizer.getLocalizedValue(dateTimeValue));
 902 kumpf         1.21                 }
 903 kumpf         1.26                 else if (type == CIMTYPE_BOOLEAN)
 904 kumpf         1.21                 {
 905 kumpf         1.26                     Boolean booleanValue;
 906                                        propertyValue.get(booleanValue);
 907                                        indicationStr.append(
 908                                            cimValueLocalizer.getLocalizedValue(booleanValue));
 909 kumpf         1.21                 }
 910                                    else
 911                                    {
 912 yi.zhou       1.2                      indicationStr.append(propertyValue.toString());
 913 kumpf         1.21                 }
 914 yi.zhou       1.1              }
 915                            }
 916 kumpf         1.21         else
 917                            {
 918                                indicationStr.append("NULL");
 919                            }
 920 yi.zhou       1.1      }
 921                    
 922                        PEG_METHOD_EXIT();
 923 kumpf         1.21     return indicationStr;
 924 yi.zhou       1.1  }
 925                    
 926 yi.zhou       1.2  String IndicationFormatter::_formatIndicationText(
 927 kumpf         1.21     const String& textFormat,
 928 yi.zhou       1.1      const Array<String>& textFormatParams,
 929 kumpf         1.21     const CIMInstance& indication,
 930                        const ContentLanguageList& contentLangs)
 931 yi.zhou       1.1  {
 932 kumpf         1.26     PEG_METHOD_ENTER(TRC_IND_FORMATTER,
 933 yi.zhou       1.2          "IndicationFormatter::_formatIndicationText");
 934 yi.zhou       1.1  
 935                        String indicationText;
 936                        String indicationFormat = textFormat;
 937                    
 938                        // Parsing the specified indication text format.
 939                        // As an example, a format string for a UPS AlertIndication
 940                        // could be defined as follows: A {4, string} UPS Alert was
 941                        // detected on the device {6[1]}.
 942 kumpf         1.26     Uint32 leftBrace;
 943                        while ((leftBrace = indicationFormat.find("{")) != PEG_NOT_FOUND)
 944 yi.zhou       1.1      {
 945 kumpf         1.26         // Append the text up to the left brace
 946                            indicationText.append(indicationFormat.subString(0, leftBrace));
 947                            indicationFormat = indicationFormat.subString(leftBrace+1);
 948                            Uint32 rightBrace = indicationFormat.find("}");
 949 yi.zhou       1.1  
 950                            // expecting a right brace
 951                            if (rightBrace != PEG_NOT_FOUND)
 952                            {
 953 david.dillard 1.4              // gets property index which is inside braces.
 954 yi.zhou       1.1              // The supported formats are: {index} or {index, type}
 955 kumpf         1.21             // or {index[x]} or {index[x], type}
 956 kumpf         1.26             String propertyParam = indicationFormat.subString(0, rightBrace);
 957                                Uint32 comma = propertyParam.find(",");
 958 yi.zhou       1.1  
 959 kumpf         1.21             // A dynamic content has syntax {index, type} or {index[x], type}
 960 yi.zhou       1.1              if (comma != PEG_NOT_FOUND)
 961                                {
 962 kumpf         1.21                 propertyParam = propertyParam.subString(0, comma);
 963 yi.zhou       1.1              }
 964                    
 965 kumpf         1.26             String propertyIndexStr;
 966                                String arrayIndexStr;
 967                                Uint32 leftBracket = propertyParam.find("[");
 968 yi.zhou       1.1  
 969 kumpf         1.21             if (leftBracket == PEG_NOT_FOUND)
 970                                {
 971 kumpf         1.26                 // A dynamic content has syntax {index} or {index, type}
 972 david.dillard 1.4                  propertyIndexStr = propertyParam;
 973 kumpf         1.21             }
 974                                else
 975                                {
 976 kumpf         1.26                 // A dynamic content has syntax {index[x]} or {index[x], type}
 977                                    propertyIndexStr = propertyParam.subString(0, leftBracket);
 978                                    propertyParam = propertyParam.subString(leftBracket);
 979 kumpf         1.21 
 980 kumpf         1.26                 Uint32 rightBracket = propertyParam.find("]");
 981 kumpf         1.21                 arrayIndexStr = propertyParam.subString(1, rightBracket-1);
 982                                }
 983                    
 984 kumpf         1.26             String propertyValue;
 985                    
 986 kumpf         1.21             try
 987                                {
 988 kumpf         1.26                 Uint32 propertyIndex = _parseIndex(propertyIndexStr);
 989                                    Uint32 arrayIndex = PEG_NOT_FOUND;
 990                    
 991                                    if (arrayIndexStr.size())
 992                                    {
 993                                        arrayIndex = _parseIndex(arrayIndexStr);
 994                                    }
 995                    
 996                                    if (propertyIndex >= textFormatParams.size())
 997                                    {
 998                                        // Property index is out of range
 999                                        propertyValue = "UNKNOWN";
1000                                    }
1001                                    else
1002                                    {
1003                                        // get indication property value
1004                                        propertyValue = _getIndPropertyValue(
1005                                            textFormatParams[propertyIndex],
1006                                            arrayIndex,
1007                                            indication,
1008                                            contentLangs);
1009 kumpf         1.26                 }
1010 kumpf         1.21             }
1011                                catch (CIMException& c)
1012                                {
1013 thilo.boehm   1.29                 PEG_TRACE((TRC_IND_FORMATTER, Tracer::LEVEL2,
1014                                        "Exception at parsing indication property: %s",
1015                                        (const char*)c.getMessage().getCString()));
1016 kumpf         1.21                 propertyValue = "UNKNOWN";
1017 yi.zhou       1.1              }
1018                    
1019                                indicationText.append(propertyValue);
1020                            }
1021                    
1022 kumpf         1.26         indicationFormat = indicationFormat.subString(rightBrace+1);
1023 yi.zhou       1.1      }
1024                    
1025                        indicationText.append(indicationFormat);
1026                    
1027                        PEG_METHOD_EXIT();
1028 kumpf         1.21     return indicationText;
1029 yi.zhou       1.1  }
1030                    
1031                    String IndicationFormatter::_getIndPropertyValue(
1032 kumpf         1.26     const String& propertyName,
1033                        Uint32 arrayIndex,
1034 kumpf         1.21     const CIMInstance& indication,
1035                        const ContentLanguageList& contentLangs)
1036 yi.zhou       1.1  {
1037 kumpf         1.21     PEG_METHOD_ENTER(TRC_IND_FORMATTER,
1038 yi.zhou       1.1          "IndicationFormatter::_getIndPropertyValue");
1039                    
1040 kumpf         1.26     Uint32 pos = indication.findProperty(propertyName);
1041                    
1042                        if (pos == PEG_NOT_FOUND)
1043                        {
1044                            PEG_METHOD_EXIT();
1045                            return "UNKNOWN";
1046                        }
1047 yi.zhou       1.1  
1048 kumpf         1.26     CIMConstProperty property = indication.getProperty(pos);
1049                        CIMValue propertyValue = property.getValue();
1050 yi.zhou       1.2  
1051 kumpf         1.26     if (propertyValue.isNull())
1052                        {
1053                            PEG_METHOD_EXIT();
1054                            return "NULL";
1055                        }
1056 yi.zhou       1.2  
1057 kumpf         1.26     if (propertyValue.isArray())
1058 yi.zhou       1.1      {
1059 kumpf         1.26         PEG_METHOD_EXIT();
1060                            return _getArrayValues(propertyValue, arrayIndex, contentLangs);
1061                        }
1062 yi.zhou       1.1  
1063 kumpf         1.26     // Value is not an array
1064 yi.zhou       1.1  
1065 kumpf         1.26     CIMValueLocalizer cimValueLocalizer(contentLangs);
1066 yi.zhou       1.1  
1067 kumpf         1.26     if (propertyValue.getType() == CIMTYPE_DATETIME)
1068                        {
1069                            CIMDateTime dateTimeValue;
1070                            propertyValue.get(dateTimeValue);
1071                            PEG_METHOD_EXIT();
1072                            return cimValueLocalizer.getLocalizedValue(dateTimeValue);
1073                        }
1074 yi.zhou       1.1  
1075 kumpf         1.26     if (propertyValue.getType() == CIMTYPE_BOOLEAN)
1076                        {
1077                            Boolean booleanValue;
1078                            propertyValue.get(booleanValue);
1079                            PEG_METHOD_EXIT();
1080                            return cimValueLocalizer.getLocalizedValue(booleanValue);
1081 yi.zhou       1.1      }
1082                    
1083                        PEG_METHOD_EXIT();
1084 kumpf         1.26     return propertyValue.toString();
1085 yi.zhou       1.1  }
1086                    
1087                    String IndicationFormatter::_getArrayValues(
1088 kumpf         1.26     const CIMValue& value,
1089                        Uint32 arrayIndex,
1090 kumpf         1.21     const ContentLanguageList& contentLangs)
1091 yi.zhou       1.1  {
1092 kumpf         1.26     PEG_METHOD_ENTER(TRC_IND_FORMATTER, "IndicationFormatter::_getArrayValues");
1093 yi.zhou       1.1  
1094 kumpf         1.26     if ((arrayIndex != PEG_NOT_FOUND) &&
1095                            (arrayIndex >= value.getArraySize()))
1096 yi.zhou       1.1      {
1097 kumpf         1.26         // Array index is out of range
1098                            PEG_METHOD_EXIT();
1099                            return "UNKNOWN";
1100 yi.zhou       1.1      }
1101                    
1102 kumpf         1.26     String arrayValues;
1103                        CIMValueLocalizer cimValueLocalizer(contentLangs);
1104 yi.zhou       1.1  
1105 kumpf         1.26     switch (value.getType())
1106 yi.zhou       1.1      {
1107 kumpf         1.21         case CIMTYPE_UINT8:
1108                            {
1109 kumpf         1.26             appendArrayValue<Uint8>(
1110                                    arrayValues, value, arrayIndex, cimValueLocalizer);
1111                                break;
1112                            }
1113 david.dillard 1.4  
1114 kumpf         1.26         case CIMTYPE_SINT8:
1115                            {
1116                                appendArrayValue<Sint8>(
1117                                    arrayValues, value, arrayIndex, cimValueLocalizer);
1118 yi.zhou       1.1              break;
1119 kumpf         1.21         }
1120 yi.zhou       1.1  
1121 kumpf         1.21         case CIMTYPE_UINT16:
1122                            {
1123 kumpf         1.26             appendArrayValue<Uint16>(
1124                                    arrayValues, value, arrayIndex, cimValueLocalizer);
1125                                break;
1126                            }
1127 david.dillard 1.4  
1128 kumpf         1.26         case CIMTYPE_SINT16:
1129                            {
1130                                appendArrayValue<Sint16>(
1131                                    arrayValues, value, arrayIndex, cimValueLocalizer);
1132 yi.zhou       1.1              break;
1133 kumpf         1.21         }
1134 yi.zhou       1.1  
1135 kumpf         1.21         case CIMTYPE_UINT32:
1136                            {
1137 kumpf         1.26             appendArrayValue<Uint32>(
1138                                    arrayValues, value, arrayIndex, cimValueLocalizer);
1139                                break;
1140                            }
1141 david.dillard 1.4  
1142 kumpf         1.26         case CIMTYPE_SINT32:
1143                            {
1144                                appendArrayValue<Sint32>(
1145                                    arrayValues, value, arrayIndex, cimValueLocalizer);
1146 yi.zhou       1.1              break;
1147 kumpf         1.21         }
1148 yi.zhou       1.1  
1149 kumpf         1.21         case CIMTYPE_UINT64:
1150                            {
1151 kumpf         1.26             appendArrayValue<Uint64>(
1152                                    arrayValues, value, arrayIndex, cimValueLocalizer);
1153                                break;
1154                            }
1155 kumpf         1.21 
1156 kumpf         1.26         case CIMTYPE_SINT64:
1157                            {
1158                                appendArrayValue<Sint64>(
1159                                    arrayValues, value, arrayIndex, cimValueLocalizer);
1160                                break;
1161                            }
1162 kumpf         1.21 
1163 kumpf         1.26         case CIMTYPE_REAL32:
1164                            {
1165                                appendArrayValue<Real32>(
1166                                    arrayValues, value, arrayIndex, cimValueLocalizer);
1167                                break;
1168                            }
1169 kumpf         1.21 
1170 kumpf         1.26         case CIMTYPE_REAL64:
1171                            {
1172                                appendArrayValue<Real64>(
1173                                    arrayValues, value, arrayIndex, cimValueLocalizer);
1174                                break;
1175                            }
1176 david.dillard 1.4  
1177 kumpf         1.26         case CIMTYPE_BOOLEAN:
1178                            {
1179                                appendArrayValue<Boolean>(
1180                                    arrayValues, value, arrayIndex, cimValueLocalizer);
1181 yi.zhou       1.1              break;
1182 kumpf         1.21         }
1183 yi.zhou       1.1  
1184 kumpf         1.26         case CIMTYPE_CHAR16:
1185 kumpf         1.21         {
1186 kumpf         1.26             appendArrayValue<Char16>(
1187                                    arrayValues, value, arrayIndex, cimValueLocalizer);
1188                                break;
1189                            }
1190 david.dillard 1.4  
1191 kumpf         1.26         case CIMTYPE_STRING:
1192                            {
1193                                appendArrayValue<String>(
1194                                    arrayValues, value, arrayIndex, cimValueLocalizer);
1195 yi.zhou       1.1              break;
1196 kumpf         1.21         }
1197                    
1198 kumpf         1.26         case CIMTYPE_DATETIME:
1199 kumpf         1.21         {
1200 kumpf         1.26             appendArrayValue<CIMDateTime>(
1201                                    arrayValues, value, arrayIndex, cimValueLocalizer);
1202                                break;
1203                            }
1204 yi.zhou       1.1  
1205 kumpf         1.26         case CIMTYPE_REFERENCE:
1206 kumpf         1.21         {
1207 kumpf         1.26             appendArrayValue<CIMObjectPath>(
1208                                    arrayValues, value, arrayIndex, cimValueLocalizer);
1209 yi.zhou       1.1              break;
1210 kumpf         1.21         }
1211 yi.zhou       1.1  
1212 kumpf         1.26         case CIMTYPE_OBJECT:
1213 kumpf         1.21         {
1214 kumpf         1.26             appendArrayValue<CIMObject>(
1215                                    arrayValues, value, arrayIndex, cimValueLocalizer);
1216 yi.zhou       1.1              break;
1217 kumpf         1.21         }
1218                    
1219 kumpf         1.26         case CIMTYPE_INSTANCE:
1220 kumpf         1.21         {
1221 kumpf         1.26             appendArrayValue<CIMInstance>(
1222                                    arrayValues, value, arrayIndex, cimValueLocalizer);
1223 yi.zhou       1.1              break;
1224 kumpf         1.21         }
1225 yi.zhou       1.2  
1226 kumpf         1.26         default:
1227 kumpf         1.21         {
1228 marek         1.28             PEG_TRACE((TRC_IND_FORMATTER, Tracer::LEVEL2,
1229 kumpf         1.26                 "Unknown CIMType: %u",
1230                                    value.getType()));
1231 kumpf         1.21 
1232                                arrayValues.append("UNKNOWN");
1233 yi.zhou       1.1              break;
1234 kumpf         1.21         }
1235 yi.zhou       1.1      }
1236                    
1237                        PEG_METHOD_EXIT();
1238 kumpf         1.21     return arrayValues;
1239 yi.zhou       1.1  }
1240                    
1241                    PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2