(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.42 and 1.53

version 1.42, 2002/03/21 02:50:31 version 1.53, 2002/05/13 18:35:53
Line 29 
Line 29 
 //              Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com) //              Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
 // //
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
   #include <Pegasus/Common/Config.h>
 #include <cassert> #include <cassert>
 #include <cctype> #include <cctype>
 #include <cstdio> #include <cstdio>
 #include <cstdlib> #include <cstdlib>
   #if defined(PEGASUS_OS_TYPE_UNIX)
   #include <errno.h>
   #endif
 #include "CIMName.h" #include "CIMName.h"
 #include "XmlReader.h" #include "XmlReader.h"
 #include "XmlWriter.h" #include "XmlWriter.h"
Line 52 
Line 55 
  
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
 // //
 // expectXmlDeclaration()  // getXmlDeclaration()
   //
   //     <?xml version="1.0" encoding="utf-8"?>
 // //
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
  
 void XmlReader::expectXmlDeclaration(  void XmlReader::getXmlDeclaration(
     XmlParser& parser,     XmlParser& parser,
     XmlEntry& entry)      const char*& xmlVersion,
       const char*& xmlEncoding)
 { {
       XmlEntry entry;
   
     if (!parser.next(entry) ||     if (!parser.next(entry) ||
         entry.type != XmlEntry::XML_DECLARATION ||         entry.type != XmlEntry::XML_DECLARATION ||
         strcmp(entry.text, "xml") != 0)         strcmp(entry.text, "xml") != 0)
Line 67 
Line 75 
         throw XmlValidationError(parser.getLine(),         throw XmlValidationError(parser.getLine(),
             "Expected <?xml ... ?> style declaration");             "Expected <?xml ... ?> style declaration");
     }     }
   
       if (!entry.getAttributeValue("version", xmlVersion))
           throw XmlValidationError(
               parser.getLine(), "missing xml.version attribute");
   
       if (!entry.getAttributeValue("encoding", xmlEncoding))
       {
           // ATTN-RK-P3-20020403:  Is there a default encoding?
       }
 } }
  
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
Line 200 
Line 217 
  
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
 // //
 // testEndTag>()  // testEndTag()
 // //
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
  
Line 584 
Line 601 
  
 Boolean XmlReader::stringToReal(const char* stringValue, Real64& x) Boolean XmlReader::stringToReal(const char* stringValue, Real64& x)
 { {
       //
       // Check the string against the DMTF-defined grammar
       //
     const char* p = stringValue;     const char* p = stringValue;
  
     if (!*p)     if (!*p)
Line 640 
Line 660 
     if (*p)     if (*p)
         return false;         return false;
  
       //
       // Do the conversion
       //
     char* end;     char* end;
       errno = 0;
     x = strtod(stringValue, &end);     x = strtod(stringValue, &end);
       if (*end || (errno == ERANGE))
       {
           return false;
       }
   
     return true;     return true;
 } }
  
Line 699 
Line 728 
             if (!isxdigit(*p))             if (!isxdigit(*p))
                 return false;                 return false;
  
             // Find the first non-zero digit so we have something to negate  
             while (*p == '0')  
                 p++;  
   
             // If all the digits are zero, the result is zero  
             if (!*p)  
                 return true;  
   
             // Build the Sint64 as a negative number, regardless of the             // Build the Sint64 as a negative number, regardless of the
             // eventual sign (negative numbers can be bigger than positive ones)             // eventual sign (negative numbers can be bigger than positive ones)
             x = -Sint64(_hexCharToNumeric(*p++));  
  
             // Add on each digit, checking for overflow errors             // Add on each digit, checking for overflow errors
             while (isxdigit(*p))             while (isxdigit(*p))
Line 761 
Line 781 
  
     // Build the Sint64 as a negative number, regardless of the     // Build the Sint64 as a negative number, regardless of the
     // eventual sign (negative numbers can be bigger than positive ones)     // eventual sign (negative numbers can be bigger than positive ones)
     x = -(*p++ - '0');  
  
     // Add on each digit, checking for overflow errors     // Add on each digit, checking for overflow errors
     while (isdigit(*p))     while (isdigit(*p))
Line 910 
Line 929 
 { {
     // ATTN-B: accepting only UTF-8 for now! (affects string and char16):     // ATTN-B: accepting only UTF-8 for now! (affects string and char16):
  
 // The Specification for the Representation of CIM in XML does not indicate  
 // that a default value should be used when a VALUE element is empty.  
 //#if 0  
     // If strlen == 0, set to default value for type  
   
     if (strlen(valueString)==0)  
     {  
         switch (type)  
         {  
             case CIMType::BOOLEAN: return CIMValue(false);  
             case CIMType::STRING: return CIMValue(valueString);  
             case CIMType::CHAR16: return CIMValue(Char16('\0'));  
             case CIMType::UINT8: return CIMValue(Uint8(0));  
             case CIMType::UINT16: return CIMValue(Uint16(0));  
             case CIMType::UINT32: return CIMValue(Uint32(0));  
             case CIMType::UINT64: return CIMValue(Uint64(0));  
             case CIMType::SINT8: return CIMValue(Sint8(0));  
             case CIMType::SINT16: return CIMValue(Sint16(0));  
             case CIMType::SINT32: return CIMValue(Sint32(0));  
             case CIMType::SINT64: return CIMValue(Sint64(0));  
             case CIMType::REAL32: return CIMValue(Real32(0));  
             case CIMType::REAL64: return CIMValue(Real64(0));  
         }  
     }  
 //#endif  
   
     // Create value per type     // Create value per type
     switch (type)     switch (type)
     {     {
Line 1078 
Line 1071 
             Real64 x;             Real64 x;
  
             if (!stringToReal(valueString, x))             if (!stringToReal(valueString, x))
                 throw XmlSemanticError(lineNumber, "Bad real value");                  throw XmlSemanticError(lineNumber, "Bad real number value");
  
             // ATTN-RK-P3-20010319: This value gets truncated.  
             return CIMValue(Real32(x));             return CIMValue(Real32(x));
         }         }
  
Line 1089 
Line 1081 
             Real64 x;             Real64 x;
  
             if (!stringToReal(valueString, x))             if (!stringToReal(valueString, x))
                 throw XmlSemanticError(lineNumber, "Bad real value");                  throw XmlSemanticError(lineNumber, "Bad real number value");
  
             return CIMValue(x);             return CIMValue(x);
         }         }
Line 1346 
Line 1338 
     if (!testStartTagOrEmptyTag(parser, entry, "VALUE.ARRAY"))     if (!testStartTagOrEmptyTag(parser, entry, "VALUE.ARRAY"))
         return false;         return false;
  
     //ATTN: P1 KS KSTESTNULL - Need to relook at this one.  
     if (entry.type == XmlEntry::EMPTY_TAG)  
         return true;  
   
     if (entry.type != XmlEntry::EMPTY_TAG)     if (entry.type != XmlEntry::EMPTY_TAG)
     {     {
         // For each VALUE element:         // For each VALUE element:
Line 1414 
Line 1402 
     Boolean translatable = getCimBooleanAttribute(     Boolean translatable = getCimBooleanAttribute(
         lineNumber, entry, tagName, "TRANSLATABLE", false, false);         lineNumber, entry, tagName, "TRANSLATABLE", false, false);
  
     // ATTN: KS P1 5 Mar 2002 Should this not be CIMFlavor::DEFAULTS??      // Start with CIMFlavor::NONE.  Defaults are specified in the
     //Uint32 flavor = CIMFlavor::DEFAULTS;      // getCimBooleanAttribute() calls above.
     // ATTN-RK-P1-20020307: No, Karl.  If you initialize to the defaults,  
     // you have to unset the default flavors that don't apply.  The code  
     // below only adds qualifiers.  
     Uint32 flavor = CIMFlavor::NONE;     Uint32 flavor = CIMFlavor::NONE;
  
     if (overridable)     if (overridable)
         flavor |= CIMFlavor::OVERRIDABLE;         flavor |= CIMFlavor::OVERRIDABLE;
           else
                   flavor |= CIMFlavor::DISABLEOVERRIDE;
  
     if (toSubClass)     if (toSubClass)
         flavor |= CIMFlavor::TOSUBCLASS;         flavor |= CIMFlavor::TOSUBCLASS;
           else
                   flavor |= CIMFlavor::RESTRICTED;
  
     if (toInstance)     if (toInstance)
         flavor |= CIMFlavor::TOINSTANCE;         flavor |= CIMFlavor::TOINSTANCE;
Line 1506 
Line 1495 
 // //
 // getQualifierElement() // getQualifierElement()
 // //
 //     <!ELEMENT QUALIFIER (VALUE|VALUE.ARRAY)>  //     <!ELEMENT QUALIFIER (VALUE|VALUE.ARRAY)?>
 //     <!ATTLIST QUALIFIER //     <!ATTLIST QUALIFIER
 //         %CIMName; //         %CIMName;
 //         %CIMType; #REQUIRED //         %CIMType; #REQUIRED
Line 1544 
Line 1533 
  
     // Get VALUE or VALUE.ARRAY element:     // Get VALUE or VALUE.ARRAY element:
  
     // ATTN: KS P1 4 March 2002 - Requires either value or array element or  
     // generates exception.  Correct for spec but means no NULL values on qualifier  
     // values. Alternative is to set NULL value and continue  
   
     CIMValue value;     CIMValue value;
  
     if (!getValueElement(parser, type, value) &&     if (!getValueElement(parser, type, value) &&
         !getValueArrayElement(parser, type, value))         !getValueArrayElement(parser, type, value))
     {     {
         throw XmlSemanticError(parser.getLine(),          value.setNullValue(type, false);
             "Expected VALUE or VALUE.ARRAY element");  
     }     }
  
     // Expect </QUALIFIER>:     // Expect </QUALIFIER>:
Line 2463 
Line 2447 
  
     // Create property:     // Create property:
  
     CIMValue value;      CIMValue value = CIMValue(CIMType::REFERENCE, false, 0);
     value.set(CIMReference());  //    value.set(CIMReference());
     property = CIMProperty(     property = CIMProperty(
         name, value, 0, referenceClass, classOrigin, propagated);         name, value, 0, referenceClass, classOrigin, propagated);
  
Line 3213 
Line 3197 
  
 Boolean XmlReader::getErrorElement( Boolean XmlReader::getErrorElement(
     XmlParser& parser,     XmlParser& parser,
     CIMStatusCode& code,      CIMException& cimException,
     const char*& description,  
     Boolean required)     Boolean required)
 { {
     XmlEntry entry;     XmlEntry entry;
Line 3236 
Line 3219 
         throw XmlValidationError(         throw XmlValidationError(
             parser.getLine(), "missing ERROR.CODE attribute");             parser.getLine(), "missing ERROR.CODE attribute");
  
     code = CIMStatusCode(tmpCode);  
   
     // Get ERROR.DESCRIPTION:     // Get ERROR.DESCRIPTION:
  
     description = "";      String tmpDescription;
     entry.getAttributeValue("DESCRIPTION", description);  
       entry.getAttributeValue("DESCRIPTION", tmpDescription);
  
     if (!empty)     if (!empty)
         expectEndTag(parser, "ERROR");         expectEndTag(parser, "ERROR");
  
       cimException = PEGASUS_CIM_EXCEPTION(CIMStatusCode(tmpCode), tmpDescription);
     return true;     return true;
 } }
  
  
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
 // getObjectWithPath()  // getValueObjectElement()
   //
   // <!ELEMENT VALUE.OBJECT (CLASS|INSTANCE)>
   //
   //------------------------------------------------------------------------------
   
   Boolean XmlReader::getValueObjectElement(
       XmlParser& parser,
       CIMObject& object)
   {
       XmlEntry entry;
   
       if (!testStartTag(parser, entry, "VALUE.OBJECT"))
           return false;
   
       CIMInstance cimInstance;
       CIMClass cimClass;
   
       if (XmlReader::getInstanceElement(parser, cimInstance))
       {
           object = CIMObject(cimInstance);
       }
       else if (!XmlReader::getClassElement(parser, cimClass))
       {
           object = CIMObject(cimClass);
       }
       else
       {
           throw XmlValidationError(parser.getLine(),
               "Expected INSTANCE or CLASS element");
       }
   
       expectEndTag(parser, "VALUE.OBJECT");
   
       return true;
   }
   
   //------------------------------------------------------------------------------
   // getValueObjectWithPathElement()
 // //
 // <!ELEMENT VALUE.OBJECTWITHPATH ((CLASSPATH,CLASS)|(INSTANCEPATH,INSTANCE))> // <!ELEMENT VALUE.OBJECTWITHPATH ((CLASSPATH,CLASS)|(INSTANCEPATH,INSTANCE))>
 // //
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
  
 Boolean XmlReader::getObjectWithPath(  Boolean XmlReader::getValueObjectWithPathElement(
     XmlParser& parser,     XmlParser& parser,
     CIMObjectWithPath& objectWithPath)     CIMObjectWithPath& objectWithPath)
 { {
Line 3274 
Line 3295 
     else if (!XmlReader::getClassPathElement(parser, reference))     else if (!XmlReader::getClassPathElement(parser, reference))
     {     {
         throw XmlValidationError(parser.getLine(),         throw XmlValidationError(parser.getLine(),
             "Expected INSTANCE element");              "Expected INSTANCEPATH or CLASSPATH element");
     }     }
  
     if (isInstance)     if (isInstance)
Line 3284 
Line 3305 
         if (!XmlReader::getInstanceElement(parser, cimInstance))         if (!XmlReader::getInstanceElement(parser, cimInstance))
         {         {
             throw XmlValidationError(parser.getLine(),             throw XmlValidationError(parser.getLine(),
                 "Expected INSTANCEPATH or CLASSPATH element");                  "Expected INSTANCE element");
         }         }
         objectWithPath.set(reference, CIMObject(cimInstance));         objectWithPath.set(reference, CIMObject(cimInstance));
     }     }
Line 3306 
Line 3327 
 } }
  
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
   // getValueObjectWithLocalPathElement()
   //
   // <!ELEMENT VALUE.OBJECTWITHLOCALPATH
   //     ((LOCALCLASSPATH,CLASS)|(LOCALINSTANCEPATH,INSTANCE))>
   //
   //------------------------------------------------------------------------------
   
   Boolean XmlReader::getValueObjectWithLocalPathElement(
       XmlParser& parser,
       CIMObjectWithPath& objectWithPath)
   {
       XmlEntry entry;
   
       if (!testStartTag(parser, entry, "VALUE.OBJECTWITHLOCALPATH"))
           return false;
   
       CIMReference reference;
       Boolean isInstance = false;
   
       if (XmlReader::getLocalInstancePathElement(parser, reference))
           isInstance = true;
       else if (!XmlReader::getLocalClassPathElement(parser, reference))
       {
           throw XmlValidationError(parser.getLine(),
               "Expected LOCALINSTANCEPATH or LOCALCLASSPATH element");
       }
   
       if (isInstance)
       {
           CIMInstance cimInstance;
   
           if (!XmlReader::getInstanceElement(parser, cimInstance))
           {
               throw XmlValidationError(parser.getLine(),
                   "Expected INSTANCE element");
           }
           objectWithPath.set(reference, CIMObject(cimInstance));
       }
       else
       {
           CIMClass cimClass;
   
           if (!XmlReader::getClassElement(parser, cimClass))
           {
               throw XmlValidationError(parser.getLine(),
                   "Expected CLASS element");
           }
           objectWithPath.set(reference, CIMObject(cimClass));
       }
   
       expectEndTag(parser, "VALUE.OBJECTWITHLOCALPATH");
   
       return true;
   }
   
   //------------------------------------------------------------------------------
   // getObjectArray()
   //
   // <object>
   //     (VALUE.OBJECT|VALUE.OBJECTWITHLOCALPATH|VALUE.OBJECTWITHPATH)
   //
   //------------------------------------------------------------------------------
   
   void XmlReader::getObjectArray(
       XmlParser& parser,
       Array<CIMObjectWithPath>& objectArray)
   {
       CIMObject object;
       CIMObjectWithPath objectWithPath;
   
       objectArray.clear();
   
       if (getValueObjectElement(parser, object))
       {
           objectArray.append(CIMObjectWithPath(CIMReference(), object));
           while (getValueObjectElement(parser, object))
               objectArray.append(CIMObjectWithPath(CIMReference(), object));
       }
       else if (getValueObjectWithPathElement(parser, objectWithPath))
       {
           objectArray.append(objectWithPath);
           while (getValueObjectWithPathElement(parser, objectWithPath))
               objectArray.append(objectWithPath);
       }
       else if (getValueObjectWithLocalPathElement(parser, objectWithPath))
       {
           objectArray.append(objectWithPath);
           while (getValueObjectWithLocalPathElement(parser, objectWithPath))
               objectArray.append(objectWithPath);
       }
   }
   
   //------------------------------------------------------------------------------
 // //
 // <objectName>: (CLASSNAME|INSTANCENAME) // <objectName>: (CLASSNAME|INSTANCENAME)
 // //


Legend:
Removed from v.1.42  
changed lines
  Added in v.1.53

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2