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

Diff for /pegasus/src/Pegasus/Common/XmlReader.cpp between version 1.108 and 1.109

version 1.108, 2005/02/22 18:08:32 version 1.109, 2005/02/28 21:12:22
Line 579 
Line 579 
  
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
 // //
   // getEmbeddedObjectAttribute()
   //
   //     <!ENTITY % EmbeddedObject "EMBEDDEDOBJECT (object | instance) #IMPLIED">
   //
   //------------------------------------------------------------------------------
   
   String XmlReader::getEmbeddedObjectAttribute(
       Uint32 lineNumber,
       const XmlEntry& entry,
       const char* elementName)
   {
       String embeddedObject;
   
       if (!entry.getAttributeValue("EMBEDDEDOBJECT", embeddedObject))
           return String();
   
       // The embeddedObject attribute, if present, must have the string
       // value "object" or "instance".
       if (!(String::equal(embeddedObject, "object") ||
             String::equal(embeddedObject, "instance")
             )
           )
       {
         // l10n
   
         // char buffer[MESSAGE_SIZE];
         // sprintf(buffer,
         //   "Illegal value for %s.EMBEDDEDOBJECT attribute", elementName);
         // throw XmlSemanticError(lineNumber, buffer);
   
         char buffer[MESSAGE_SIZE];
         sprintf(buffer, "%s.EMBEDDEDOBJECT", elementName);
   
         MessageLoaderParms mlParms("Common.XmlReader.ILLEGAL_VALUE_FOR_ATTRIBUTE",
                                    "Illegal value for $0 attribute",
                                    buffer);
   
         throw XmlSemanticError(lineNumber, mlParms);
   
       }
   
       return embeddedObject;
   }
   
   //------------------------------------------------------------------------------
   //
 // getReferenceClassAttribute() // getReferenceClassAttribute()
 // //
 //     <!ENTITY % ReferenceClass "REFERENCECLASS CDATA #IMPLIED"> //     <!ENTITY % ReferenceClass "REFERENCECLASS CDATA #IMPLIED">
Line 751 
Line 797 
         type = CIMTYPE_REAL64;         type = CIMTYPE_REAL64;
     else if (strcmp(typeName, "reference") == 0)     else if (strcmp(typeName, "reference") == 0)
         type = CIMTYPE_REFERENCE;         type = CIMTYPE_REFERENCE;
   //  PEP 194:
   //  Note that "object" (ie. CIMTYPE_OBJECT) is not a real CIM datatype, just a
   //  Pegasus internal representation of an embedded object, so it won't be found here.
     else unrecognizedType = true;     else unrecognizedType = true;
  
     if (unrecognizedType ||     if (unrecognizedType ||
Line 1532 
Line 1581 
             return CIMValue(x);             return CIMValue(x);
         }         }
  
   //  PEP 194:
   //  Note that "object" (ie. CIMTYPE_OBJECT) is not a real CIM datatype, but just a
   //  Pegasus internal representation of an embedded object. However, this case is
   //  used when decoding string representations of embedded objects.
       case CIMTYPE_OBJECT:
       {
           CIMObject x;
   
           if (*valueString == '\0')
           {
               x = CIMObject();
           }
           else
           {
               // Convert the non-NULL string to a CIMObject (containing either a
               // CIMInstance or a CIMClass).
   
               // First we need to create a new "temporary" XMLParser that is
               // just the value of the Embedded Object in String representation.
               char* tmp_buffer = new char[strlen(valueString) + 1];
               strcpy(tmp_buffer, valueString);
               XmlParser tmp_parser(tmp_buffer);
               delete [] tmp_buffer;
   
               // The next bit of logic constructs a CIMObject from the Embedded Object String.
               // It is similar to the method XmlReader::getValueObjectElement().
               CIMInstance cimInstance;
               CIMClass cimClass;
   
               if (XmlReader::getInstanceElement(tmp_parser, cimInstance))
               {
                   x = CIMObject(cimInstance);
               }
               else if (XmlReader::getClassElement(tmp_parser, cimClass))
               {
                   x = CIMObject(cimClass);
               }
               else
               {
                   // l10n
   
                   // throw XmlValidationError(parser.getLine(),
                   //   "Expected INSTANCE or CLASS element");
   
                   MessageLoaderParms mlParms("Common.XmlReader.EXPECTED_INSTANCE_OR_CLASS_ELEMENT",
                              "Expected INSTANCE or CLASS element"); // change "element" to "embedded object"
   
                   throw XmlValidationError(lineNumber, mlParms);
   
               }
           }
           return CIMValue(x);
       }
   
         default:         default:
             break;             break;
     }     }
Line 1601 
Line 1704 
  
     Boolean empty = entry.type == XmlEntry::EMPTY_TAG;     Boolean empty = entry.type == XmlEntry::EMPTY_TAG;
  
       // Since stringToValue() takes a char* as input, we handle CIMTYPE_OBJECT separately.
       if (type == CIMTYPE_OBJECT)
       {
           CIMObject cimObject;
   
           if (empty)
           {
               cimObject = CIMObject();
           }
           else
           {
               // Convert the non-empty value to a CIMObject (containing either a
               // CIMInstance or a CIMClass).
   
               // The next bit of logic constructs a CIMObject from the Embedded Object String.
               // It is similar to the method XmlReader::getValueObjectElement().
               CIMInstance cimInstance;
               CIMClass cimClass;
   
               if (XmlReader::getInstanceElement(parser, cimInstance))
               {
                   cimObject = CIMObject(cimInstance);
               }
               else if (XmlReader::getClassElement(parser, cimClass))
               {
                   cimObject = CIMObject(cimClass);
               }
               else
               {
                   // l10n
   
                   // throw XmlValidationError(parser.getLine(),
                   //   "Expected INSTANCE or CLASS element");
   
                   MessageLoaderParms mlParms("Common.XmlReader.EXPECTED_INSTANCE_OR_CLASS_ELEMENT",
                              "Expected INSTANCE or CLASS element"); // change "element" to "embedded object"
   
                   throw XmlValidationError(parser.getLine(), mlParms);
               }
               expectEndTag(parser, "VALUE");
           }
           value = CIMValue(cimObject);
       }
       else
       {
     const char* valueString = "";     const char* valueString = "";
  
     if (!empty)     if (!empty)
Line 1618 
Line 1766 
     if (!empty)     if (!empty)
 #endif #endif
         value = stringToValue(parser.getLine(), valueString,type);         value = stringToValue(parser.getLine(), valueString,type);
       }
  
     return true;     return true;
 } }
Line 1804 
Line 1953 
         case CIMTYPE_REAL64:         case CIMTYPE_REAL64:
             return StringArrayToValueAux(lineNumber, array, type, (Real64*)0);             return StringArrayToValueAux(lineNumber, array, type, (Real64*)0);
  
   //  PEP 194:
   //  Note that "object" (ie. CIMTYPE_OBJECT) is not a real CIM datatype, but just a
   //  Pegasus internal representation of an embedded object. However, this case is
   //  used when decoding string representations of embedded objects.
       case CIMTYPE_OBJECT:
               return StringArrayToValueAux(lineNumber, array, type, (CIMObject*)0);
   
         default:         default:
             break;             break;
     }     }
Line 1833 
Line 1989 
     // Get VALUE.ARRAY open tag:     // Get VALUE.ARRAY open tag:
  
     XmlEntry entry;     XmlEntry entry;
     Array<const char*> stringArray;  
  
     // If no VALUE.ARRAY start tag, return false     // If no VALUE.ARRAY start tag, return false
     if (!testStartTagOrEmptyTag(parser, entry, "VALUE.ARRAY"))     if (!testStartTagOrEmptyTag(parser, entry, "VALUE.ARRAY"))
Line 1841 
Line 1996 
  
     if (entry.type != XmlEntry::EMPTY_TAG)     if (entry.type != XmlEntry::EMPTY_TAG)
     {     {
           if (type == CIMTYPE_OBJECT)
           {
               Array<CIMObject> objectArray;
   
         // For each VALUE element:         // For each VALUE element:
               while (testStartTagOrEmptyTag(parser, entry, "VALUE"))
               {
                   CIMObject cimObject;
   
                   if (entry.type == XmlEntry::EMPTY_TAG)
                   {
                       cimObject = CIMObject();
                   }
                   else
                   {
                       // Convert the non-empty value to a CIMObject (containing either a
                       // CIMInstance or a CIMClass).
   
                       // The next bit of logic constructs a CIMObject from the Embedded Object String.
                       // It is similar to the method XmlReader::getValueObjectElement().
                       CIMInstance cimInstance;
                       CIMClass cimClass;
   
                       if (XmlReader::getInstanceElement(parser, cimInstance))
                       {
                           cimObject = CIMObject(cimInstance);
                       }
                       else if (XmlReader::getClassElement(parser, cimClass))
                       {
                           cimObject = CIMObject(cimClass);
                       }
                       else
                       {
                           // l10n
   
                           // throw XmlValidationError(parser.getLine(),
                           //   "Expected INSTANCE or CLASS element");
   
                           MessageLoaderParms mlParms("Common.XmlReader.EXPECTED_INSTANCE_OR_CLASS_ELEMENT",
                                      "Expected INSTANCE or CLASS element"); // change "element" to "embedded object"
   
                           throw XmlValidationError(parser.getLine(), mlParms);
                       }
                       expectEndTag(parser, "VALUE");
                   }
                   objectArray.append(cimObject);
               }
               value = CIMValue(objectArray);
           }
           else
           {
               Array<const char*> stringArray;
  
               // For each VALUE element:
         while (testStartTagOrEmptyTag(parser, entry, "VALUE"))         while (testStartTagOrEmptyTag(parser, entry, "VALUE"))
         {         {
             if (entry.type == XmlEntry::EMPTY_TAG)             if (entry.type == XmlEntry::EMPTY_TAG)
Line 1858 
Line 2065 
  
             expectEndTag(parser, "VALUE");             expectEndTag(parser, "VALUE");
         }         }
               value = stringArrayToValue(parser.getLine(), stringArray, type);
           }
  
         expectEndTag(parser, "VALUE.ARRAY");         expectEndTag(parser, "VALUE.ARRAY");
     }     }
  
     value = stringArrayToValue(parser.getLine(), stringArray, type);  
     return true;     return true;
 } }
  
Line 2104 
Line 2312 
 //         %CIMName; //         %CIMName;
 //         %ClassOrigin; //         %ClassOrigin;
 //         %Propagated; //         %Propagated;
   //         %EmbeddedObject; #IMPLIED
 //         %CIMType; #REQUIRED> //         %CIMType; #REQUIRED>
 // //
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
Line 2131 
Line 2340 
     Boolean propagated = getCimBooleanAttribute(     Boolean propagated = getCimBooleanAttribute(
         parser.getLine(), entry, "PROPERTY", "PROPAGATED", false, false);         parser.getLine(), entry, "PROPERTY", "PROPAGATED", false, false);
  
       // Get PROPERTY.EMBEDDEDOBJECT
   
       String embeddedObject = getEmbeddedObjectAttribute(
           parser.getLine(), entry, "PROPERTY");
   
     // Get PROPERTY.TYPE attribute:     // Get PROPERTY.TYPE attribute:
  
     CIMType type;     CIMType type;
Line 2143 
Line 2357 
  
     if (!empty)     if (!empty)
     {     {
         // Get qualifiers:              // Get qualifiers. We need to do this before checking for the property as an
           // embedded object, because we need to also check for the EmbeddedObject qualifier.
         getQualifierElements(parser, property);         getQualifierElements(parser, property);
       }
  
         // Get value:  Insert value if getValueElement exists (returns True)      // If the EMBEDDEDOBJECT attribute is present with value "object"
       // or the EmbeddedObject qualifier exists on this property
       // then
       //     Convert the EmbeddedObject-encoded string into a CIMObject
       if (String::equal(embeddedObject, "object")
           || property.findQualifier(CIMName("EmbeddedObject")) != PEG_NOT_FOUND
           )
       {
           // The EMBEDDEDOBJECT attribute is only valid on Properties of type string
           if (type == CIMTYPE_STRING)
           {
               type = CIMTYPE_OBJECT;
               CIMValue new_value(type, false);
               CIMProperty new_property = CIMProperty(name, new_value, 0, CIMName(), classOrigin, propagated);
   
               // Copy the qualifiers from the String property to the CIMObject property.
               for (Uint32 ix = 0; ix < property.getQualifierCount(); ++ix)
               {
                   // All properties are copied, including the EmbeddedObject qualifier.
                   // This way we don't have to keep track to know that the EmbeddedObject
                   // qualifier needs to be added back during the encode step.
                   new_property.addQualifier(property.getQualifier(ix));
               }
  
               value = new_value; // does this leak?
               property = new_property; // does this leak?
           }
           else
           {
               // Error -- throw exception
               // (the EmbeddedObject attribute may be applied only to entities that have the type String)
   
               // l10n
   
               // throw XmlValidationError(parser.getLine(),
               //   "expected string type");
   
               MessageLoaderParms mlParms("Common.XmlReader.INVALID_EMBEDDEDOBJECT_TYPE",
                                "The EMBEDDEDOBJECT attribute is only valid on string types.");
   
               throw XmlValidationError(parser.getLine(), mlParms);
           }
       }
   
       // Continue on to get property value, if not empty.
       if (!empty)
       {
         if (getValueElement(parser, type, value))         if (getValueElement(parser, type, value))
             property.setValue(value);             property.setValue(value);
   
         expectEndTag(parser, "PROPERTY");         expectEndTag(parser, "PROPERTY");
     }     }
  
Line 2214 
Line 2473 
 //             %CIMType; #REQUIRED //             %CIMType; #REQUIRED
 //             %ArraySize; //             %ArraySize;
 //             %ClassOrigin; //             %ClassOrigin;
 //             %Propagated;>  //             %Propagated;
   //             %EmbeddedObject; #IMPLIED>
 // //
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
  
Line 2248 
Line 2508 
  
     // Get PROPERTY.CLASSORIGIN attribute:     // Get PROPERTY.CLASSORIGIN attribute:
  
     CIMName classOrigin      CIMName classOrigin = getClassOriginAttribute(parser.getLine(), entry, "PROPERTY.ARRAY");
         = getClassOriginAttribute(parser.getLine(), entry, "PROPERTY.ARRAY");  
  
     // Get PROPERTY.ARRAY.PROPAGATED     // Get PROPERTY.ARRAY.PROPAGATED
  
     Boolean propagated = getCimBooleanAttribute(      Boolean propagated = getCimBooleanAttribute(parser.getLine()
         parser.getLine(), entry, "PROPERTY.ARRAY", "PROPAGATED", false, false);                                                  ,entry
                                                   ,"PROPERTY.ARRAY"
                                                   ,"PROPAGATED"
                                                   ,false
                                                   ,false);
   
       // Get PROPERTY.EMBEDDEDOBJECT
   
       String embeddedObject = getEmbeddedObjectAttribute(parser.getLine()
                                                          ,entry
                                                          ,"PROPERTY.ARRAY");
  
     // Create property:     // Create property:
  
     CIMValue value(type, true, arraySize);     CIMValue value(type, true, arraySize);
     property = CIMProperty(      property = CIMProperty(name, value, arraySize, CIMName(), classOrigin, propagated);
         name, value, arraySize, CIMName(), classOrigin, propagated);  
  
     if (!empty)     if (!empty)
     {     {
         // Get qualifiers:         // Get qualifiers:
   
         getQualifierElements(parser, property);         getQualifierElements(parser, property);
       }
   
       // If the EMBEDDEDOBJECT attribute is present with value "object"
       // or the EmbeddedObject qualifier exists on this property
       // then
       //     Convert the EmbeddedObject-encoded string into a CIMObject
       if (String::equal(embeddedObject, "object")
           || property.findQualifier(CIMName("EmbeddedObject")) != PEG_NOT_FOUND
           )
       {
           // The EMBEDDEDOBJECT attribute is only valid on Properties of type string
           if (type == CIMTYPE_STRING)
           {
               type = CIMTYPE_OBJECT;
               CIMValue new_value(type, true, arraySize);
               CIMProperty new_property = CIMProperty(name, new_value, arraySize, CIMName(), classOrigin, propagated);
   
               // Copy the qualifiers from the String property to the CIMObject property.
               for (Uint32 ix = 0; ix < property.getQualifierCount(); ++ix)
               {
                   // All properties are copied, including the EmbeddedObject qualifier.
                   // This way we don't have to keep track to know that the EmbeddedObject
                   // qualifier needs to be added back during the encode step.
                   new_property.addQualifier(property.getQualifier(ix));
               }
   
               value = new_value; // does this leak?
               property = new_property; // does this leak?
           }
           else
           {
               // Error -- throw exception
               // (the EmbeddedObject attribute may be applied only to entities that have the type String)
   
               // l10n
   
               // throw XmlValidationError(parser.getLine(),
               //   "expected string type");
  
         // Get value:              MessageLoaderParms mlParms("Common.XmlReader.INVALID_EMBEDDEDOBJECT_TYPE",
                                "The EMBEDDEDOBJECT attribute is only valid on string types.");
  
               throw XmlValidationError(parser.getLine(), mlParms);
           }
       }
   
       // Continue on to get property array value, if not empty.
       // Else not an embedded object, if not empty, get the property array value.
       if (!empty)
       {
         if (getValueArrayElement(parser, type, value))         if (getValueArrayElement(parser, type, value))
         {         {
             if (arraySize && arraySize != value.getArraySize())             if (arraySize && arraySize != value.getArraySize())
Line 2288 
Line 2602 
  
             property.setValue(value);             property.setValue(value);
         }         }
   
         expectEndTag(parser, "PROPERTY.ARRAY");         expectEndTag(parser, "PROPERTY.ARRAY");
     }     }
  
Line 4652 
Line 4965 
 // <!ELEMENT PARAMVALUE (VALUE|VALUE.REFERENCE|VALUE.ARRAY|VALUE.REFARRAY)?> // <!ELEMENT PARAMVALUE (VALUE|VALUE.REFERENCE|VALUE.ARRAY|VALUE.REFARRAY)?>
 // <!ATTLIST PARAMVALUE // <!ATTLIST PARAMVALUE
 //      %CIMName; //      %CIMName;
   //      %EmbeddedObject; #IMPLIED
 //      %ParamType;> //      %ParamType;>
 // //
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
Line 4685 
Line 4999 
       throw XmlValidationError(parser.getLine(), mlParms);       throw XmlValidationError(parser.getLine(), mlParms);
     }     }
  
       // Get PROPERTY.EMBEDDEDOBJECT
   
       String embeddedObject = getEmbeddedObjectAttribute(
           parser.getLine(), entry, "PARAMVALUE");
  
     // Get PARAMVALUE.PARAMTYPE attribute:     // Get PARAMVALUE.PARAMTYPE attribute:
  
Line 4725 
Line 5043 
                 effectiveType = type;                 effectiveType = type;
             }             }
  
               // If the EMBEDDEDOBJECT attribute is present with value "object"
               // then
               //     Convert the EmbeddedObject-encoded string into a CIMObject
               if (String::equal(embeddedObject, "object"))
               {
                   // The EMBEDDEDOBJECT attribute is only valid on Parameters of type string
                   // The type must have been specified.
                   if (gotType && (type == CIMTYPE_STRING))
                   {
                       type = CIMTYPE_OBJECT; // Used below by getValueElement() or getValueArrayElement()
                   }
                   else
                   {
                       // Error -- throw exception
                       // (the EmbeddedObject attribute may be applied only to entities that have the type String)
   
                       // l10n
   
                       // throw XmlValidationError(parser.getLine(),
                       //   "expected string type");
   
                       MessageLoaderParms mlParms("Common.XmlReader.INVALID_EMBEDDEDOBJECT_TYPE",
                                        "The EMBEDDEDOBJECT attribute is only valid on string types.");
   
                       throw XmlValidationError(parser.getLine(), mlParms);
                   }
               }
   
             if ( !XmlReader::getValueArrayElement(parser, effectiveType, value) &&             if ( !XmlReader::getValueArrayElement(parser, effectiveType, value) &&
                  !XmlReader::getValueElement(parser, effectiveType, value) )                  !XmlReader::getValueElement(parser, effectiveType, value) )
             {             {
                 value.clear();    // Isn't necessary; should already be cleared                 value.clear();    // Isn't necessary; should already be cleared
             }             }
   
         }         }
  
         expectEndTag(parser, "PARAMVALUE");         expectEndTag(parser, "PARAMVALUE");
     }     }
  
   
     paramValue = CIMParamValue(name, value, gotType);     paramValue = CIMParamValue(name, value, gotType);
  
     return true;     return true;
Line 4746 
Line 5094 
 // //
 // <!ELEMENT RETURNVALUE (VALUE|VALUE.REFERENCE)> // <!ELEMENT RETURNVALUE (VALUE|VALUE.REFERENCE)>
 // <!ATTLIST RETURNVALUE // <!ATTLIST RETURNVALUE
   //      %EmbeddedObject; #IMPLIED
 //      %ParamType;> //      %ParamType;>
 // //
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
Line 4761 
Line 5110 
     if (!testStartTag(parser, entry, "RETURNVALUE"))     if (!testStartTag(parser, entry, "RETURNVALUE"))
         return false;         return false;
  
       // Get PROPERTY.EMBEDDEDOBJECT
   
       String embeddedObject = getEmbeddedObjectAttribute(
           parser.getLine(), entry, "RETURNVALUE");
   
     // Get RETURNVALUE.PARAMTYPE attribute:     // Get RETURNVALUE.PARAMTYPE attribute:
     // NOTE: Array type return values are not allowed (2/20/02)     // NOTE: Array type return values are not allowed (2/20/02)
  
Line 4801 
Line 5155 
             type = CIMTYPE_STRING;             type = CIMTYPE_STRING;
         }         }
  
           if (String::equal(embeddedObject, "object"))
           {
               if (gotType && (type == CIMTYPE_STRING))
               {
                   type = CIMTYPE_OBJECT;  // Used below by getValueElement()
               }
               else
               {
                   // Error -- throw exception
                   // (the EmbeddedObject attribute may be applied only to entities that have the type String)
   
                   // l10n
   
                   // throw XmlValidationError(parser.getLine(),
                   //   "expected string type");
   
                   MessageLoaderParms mlParms("Common.XmlReader.INVALID_EMBEDDEDOBJECT_TYPE",
                                    "The EMBEDDEDOBJECT attribute is only valid on string types.");
   
                   throw XmlValidationError(parser.getLine(), mlParms);
               }
           }
   
         if ( !XmlReader::getValueElement(parser, type, returnValue) )         if ( !XmlReader::getValueElement(parser, type, returnValue) )
         {         {
  


Legend:
Removed from v.1.108  
changed lines
  Added in v.1.109

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2