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

Diff for /pegasus/src/Pegasus/Common/SCMO.cpp between version 1.2.2.8 and 1.24

version 1.2.2.8, 2009/07/31 12:41:02 version 1.24, 2013/02/13 11:39:58
Line 27 
Line 27 
 // //
 ////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
 // //
   // This code implements part of PEP#348 - The CMPI infrastructure using SCMO
   // (Single Chunk Memory Objects).
   // The design document can be found on the OpenPegasus website openpegasus.org
   // at https://collaboration.opengroup.org/pegasus/pp/documents/21210/PEP_348.pdf
   //
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
 #include "SCMO.h"  #include <Pegasus/Common/SCMO.h>
   #include <Pegasus/Common/SCMOClass.h>
   #include <Pegasus/Common/SCMOInstance.h>
   #include <Pegasus/Common/SCMODump.h>
   #include <Pegasus/Common/SCMOClassCache.h>
 #include <Pegasus/Common/CharSet.h> #include <Pegasus/Common/CharSet.h>
 #include <Pegasus/Common/CIMDateTimeRep.h> #include <Pegasus/Common/CIMDateTimeRep.h>
 #include <Pegasus/Common/CIMPropertyRep.h> #include <Pegasus/Common/CIMPropertyRep.h>
   #include <Pegasus/Common/CIMInstanceRep.h>
   #include <Pegasus/Common/CIMObjectPathRep.h>
   #include <Pegasus/Common/CIMNameCast.h>
 #include <Pegasus/Common/CommonUTF.h> #include <Pegasus/Common/CommonUTF.h>
 #include <Pegasus/Common/StrLit.h> #include <Pegasus/Common/StrLit.h>
   #include <Pegasus/Common/Tracer.h>
 #include <Pegasus/Common/XmlWriter.h> #include <Pegasus/Common/XmlWriter.h>
 #include <Pegasus/Common/System.h> #include <Pegasus/Common/System.h>
 #include <Pegasus/Common/FileSystem.h> #include <Pegasus/Common/FileSystem.h>
   #include <Pegasus/Common/StringConversion.h>
   #include <Pegasus/Common/ArrayIterator.h>
   #include <Pegasus/Common/PegasusAssert.h>
   #include <Pegasus/Common/CIMValueRep.h>
   
   # if defined PEGASUS_OS_ZOS
   #  include <strings.h>
   # else
   #  include <string.h>
   # endif
  
 #ifdef PEGASUS_OS_ZOS #ifdef PEGASUS_OS_ZOS
   #include <Pegasus/General/SetFileDescriptorToEBCDICEncoding.h>   #include <Pegasus/General/SetFileDescriptorToEBCDICEncoding.h>
 #endif #endif
  
   #ifdef PEGASUS_HAS_ICU
   # include <unicode/platform.h>
   # include <unicode/urename.h>
   # include <unicode/ures.h>
   # include <unicode/ustring.h>
   # include <unicode/uchar.h>
   # include <unicode/ucnv.h>
   #endif
   
 PEGASUS_USING_STD; PEGASUS_USING_STD;
  
 #define SCMB_INITIAL_MEMORY_CHUNK_SIZE 4096 #define SCMB_INITIAL_MEMORY_CHUNK_SIZE 4096
Line 54 
Line 86 
  * for a string format specification, the string "(null)" is  * for a string format specification, the string "(null)" is
  * substituted. On other platforms no string "" is substituded.  * substituted. On other platforms no string "" is substituded.
  */  */
 #define NULLSTR(x) ((x) == NULL ? "" : (x))  #define NULLSTR(x) ((x) == 0 ? "" : (x))
  
 PEGASUS_NAMESPACE_BEGIN PEGASUS_NAMESPACE_BEGIN
  
 static StrLit _qualifierNameStrLit[] =  #define PEGASUS_ARRAY_T SCMOInstance
   # include "ArrayImpl.h"
   #undef PEGASUS_ARRAY_T
   
   const StrLit SCMOClass::_qualifierNameStrLit[72] =
 { {
     STRLIT(""),     STRLIT(""),
     STRLIT("ABSTRACT"),     STRLIT("ABSTRACT"),
Line 137 
Line 173 
 #define _NUM_QUALIFIER_NAMES \ #define _NUM_QUALIFIER_NAMES \
            (sizeof(_qualifierNameStrLit)/sizeof(_qualifierNameStrLit[0]))            (sizeof(_qualifierNameStrLit)/sizeof(_qualifierNameStrLit[0]))
  
   
   /*****************************************************************************
    * The static declaration of the common SCMO memory functions.
    *****************************************************************************/
   
   static Uint64 _getFreeSpace(
       SCMBDataPtr& ptr,
       Uint32 size,
       SCMBMgmt_Header** pmem);
   
   static void _setString(
       const String& theString,
       SCMBDataPtr& ptr,
       SCMBMgmt_Header** pmem);
   
   static void _setBinary(
       const void* theBuffer,
       Uint32 bufferSize,
       SCMBDataPtr& ptr,
       SCMBMgmt_Header** pmem);
   
   
   
   /*****************************************************************************
    * Internal inline functions.
    *****************************************************************************/
   
   inline String _newCimString(const SCMBDataPtr & ptr, const char * base)
   {
       if (ptr.size > 0)
       {
           return String(&(base[ptr.start]),ptr.size-1);
       }
       else
       {
           return String();
       }
   }
   
   inline void _deleteArrayExtReference(
       SCMBDataPtr& theArray,
       SCMBMgmt_Header** pmem )
   {
       SCMBUnion* ptr;
       // if the array was already set,
       // the previous references has to be deleted
       if(theArray.size != 0)
       {
           Uint32 oldArraySize=(theArray.size/sizeof(SCMBUnion));
   
           ptr = (SCMBUnion*)&(((char*)*pmem)[theArray.start]);
           for (Uint32 i = 0 ; i < oldArraySize ; i++)
           {
               delete ptr[i].extRefPtr;
               ptr[i].extRefPtr = 0;
           }
       }
   }
   
   static void _deleteExternalReferenceInternal(
       SCMBMgmt_Header* memHdr, SCMOInstance *extRefPtr)
   {
       Uint32 nuExtRef = memHdr->numberExtRef;
       char * base = ((char*)memHdr);
       Uint64* array =
           (Uint64*)&(base[memHdr->extRefIndexArray.start]);
       Uint32 extRefIndex = PEG_NOT_FOUND;
   
       for (Uint32 i = 0; i < nuExtRef; i++)
       {
            if (((SCMBUnion*)(&(base[array[i]])))->extRefPtr == extRefPtr)
            {
                extRefIndex = i;
                break;
            }
       }
       PEGASUS_ASSERT (extRefIndex != PEG_NOT_FOUND);
   
      // Shrink extRefIndexArray
   
       for (Uint32 i = extRefIndex + 1; i < nuExtRef; i++)
       {
           array[i-1] = array[i];
       }
   
       array[nuExtRef-1] = 0;
       memHdr->numberExtRef--;
   
       delete extRefPtr;
   }
   
 /***************************************************************************** /*****************************************************************************
  * The SCMOClass methods  * The SCMOClass methods
  *****************************************************************************/  *****************************************************************************/
 SCMOClass::SCMOClass() SCMOClass::SCMOClass()
 { {
     cls.mem = NULL;      _initSCMOClass();
   
       _setBinary("",1,cls.hdr->className,&cls.mem );
       _setBinary("",1,cls.hdr->nameSpace,&cls.mem );
       cls.hdr->flags.isEmpty=true;
 } }
  
 SCMOClass::SCMOClass(CIMClass& theCIMClass)  inline void SCMOClass::_initSCMOClass()
 { {
     PEGASUS_ASSERT(SCMB_INITIAL_MEMORY_CHUNK_SIZE     PEGASUS_ASSERT(SCMB_INITIAL_MEMORY_CHUNK_SIZE
         - sizeof(SCMBClass_Main)>0);         - sizeof(SCMBClass_Main)>0);
  
     cls.base = (char*)malloc(SCMB_INITIAL_MEMORY_CHUNK_SIZE);     cls.base = (char*)malloc(SCMB_INITIAL_MEMORY_CHUNK_SIZE);
     if (cls.base == NULL)      if (cls.base == 0)
     {     {
         // Not enough memory!         // Not enough memory!
         throw PEGASUS_STD(bad_alloc)();         throw PEGASUS_STD(bad_alloc)();
     }     }
  
       memset(cls.base,0,sizeof(SCMBClass_Main));
   
     // initalize eye catcher     // initalize eye catcher
     cls.hdr->header.magic=PEGASUS_SCMB_CLASS_MAGIC;     cls.hdr->header.magic=PEGASUS_SCMB_CLASS_MAGIC;
     cls.hdr->header.totalSize=SCMB_INITIAL_MEMORY_CHUNK_SIZE;     cls.hdr->header.totalSize=SCMB_INITIAL_MEMORY_CHUNK_SIZE;
Line 169 
Line 302 
  
     cls.hdr->refCount=1;     cls.hdr->refCount=1;
  
   }
   
   SCMOClass::SCMOClass(const char* className, const char* nameSpaceName )
   {
       Uint32 clsNameLen = strlen(className);
       Uint32 nsNameLen = strlen(nameSpaceName);
   
       if (0 == className )
       {
           String message("SCMOClass: Class name not set (null pointer)!");
           throw CIMException(CIM_ERR_FAILED,message );
       }
   
       if (0 == nameSpaceName)
       {
           String message("SCMOClass: Name Space not set (null pointer)!");
           throw CIMException(CIM_ERR_FAILED,message );
       }
   
       _initSCMOClass();
   
       _setBinary(className,clsNameLen+1,cls.hdr->className,&cls.mem );
   
       _setBinary(nameSpaceName,nsNameLen+1,cls.hdr->nameSpace,&cls.mem );
   
       cls.hdr->flags.isEmpty=true;
   
   }
   
   SCMOClass::SCMOClass(
       const CIMClass& theCIMClass,
       const char* nameSpaceName)
   {
   
       _initSCMOClass();
   
     try     try
     {     {
         _setString(theCIMClass.getSuperClassName().getString(),         _setString(theCIMClass.getSuperClassName().getString(),
Line 179 
Line 348 
     {     {
         // there is no Super ClassName         // there is no Super ClassName
         cls.hdr->superClassName.start=0;         cls.hdr->superClassName.start=0;
         cls.hdr->superClassName.length=0;          cls.hdr->superClassName.size=0;
     }     }
  
     CIMObjectPath theObjectPath=theCIMClass.getPath();     CIMObjectPath theObjectPath=theCIMClass.getPath();
  
     //set name space     //set name space
       if (nameSpaceName)
       {
           _setBinary(nameSpaceName,
                      strlen(nameSpaceName)+1,
                      cls.hdr->nameSpace,
                      &cls.mem );
       }
       else
       {
    _setString(theObjectPath.getNameSpace().getString(),    _setString(theObjectPath.getNameSpace().getString(),
               cls.hdr->nameSpace,               cls.hdr->nameSpace,
               &cls.mem );               &cls.mem );
       }
   
  
     //set class name     //set class name
     _setString(theObjectPath.getClassName().getString(),     _setString(theObjectPath.getClassName().getString(),
                cls.hdr->className,                cls.hdr->className,
                &cls.mem );                &cls.mem );
  
   
     //set class Qualifiers     //set class Qualifiers
     _setClassQualifers(theCIMClass);      _setClassQualifers(theCIMClass._rep->_qualifiers);
  
     //set properties     //set properties
     _setClassProperties(theCIMClass);      _setClassProperties(theCIMClass._rep->_properties);
   
   }
   
   void SCMOClass::_destroyExternalReferences()
   {
       _destroyExternalReferencesInternal(cls.mem);
   }
   
   const char* SCMOClass::getSuperClassName() const
   {
       return _getCharString(cls.hdr->superClassName,cls.base);
   }
   
   const char* SCMOClass::getSuperClassName_l(Uint32 & length) const
   {
       length = cls.hdr->superClassName.size;
       if (0 == length)
       {
           return 0;
       }
       else
       {
           length--;
       }
       return _getCharString(cls.hdr->superClassName,cls.base);
   }
   
   void  SCMOClass::getCIMClass(CIMClass& cimClass) const
   {
       CIMClass newCimClass(
           CIMNameCast(_newCimString(cls.hdr->className,cls.base)),
           CIMNameCast(_newCimString(cls.hdr->superClassName,cls.base)));
   
       // set the name space
       newCimClass._rep->_reference._rep->_nameSpace=
           CIMNamespaceNameCast(_newCimString(cls.hdr->nameSpace,cls.base));
   
       // Add class qualifier if exist
       if (0 != cls.hdr->numberOfQualifiers)
       {
           SCMBQualifier* qualiArray =
               (SCMBQualifier*)&(cls.base[cls.hdr->qualifierArray.start]);
   
           CIMQualifier theCimQualifier;
   
           Uint32 i, k = cls.hdr->numberOfQualifiers;
           for ( i = 0 ; i < k ; i++)
           {
               _getCIMQualifierFromSCMBQualifier(
                   theCimQualifier,
                   qualiArray[i],
                   cls.base);
   
               newCimClass._rep->_qualifiers.addUnchecked(theCimQualifier);
           }
       }
   
       // If properties are in that class
       if (0 != cls.hdr->propertySet.number)
       {
           Uint32 i, k = cls.hdr->propertySet.number;
           for ( i = 0 ; i < k ; i++)
           {
              newCimClass._rep->_properties.append(
                  _getCIMPropertyAtNodeIndex(i));
           }
       }
   
       cimClass = newCimClass;
   }
   
   CIMProperty SCMOClass::_getCIMPropertyAtNodeIndex(Uint32 nodeIdx) const
   {
       CIMValue theCimValue;
       CIMProperty retCimProperty;
   
       SCMBClassPropertyNode& clsProp =
           ((SCMBClassPropertyNode*)
            &(cls.base[cls.hdr->propertySet.nodeArray.start]))[nodeIdx];
  
       // get the default value
       SCMOInstance::_getCIMValueFromSCMBValue(
           theCimValue,
           clsProp.theProperty.defaultValue,
           cls.base);
   
       // have to check if there is the origin class name set.
       // An empty origin class name is differnt then a NULL class name
       if (0 != clsProp.theProperty.originClassName.start)
       {
           retCimProperty = CIMProperty(
               CIMNameCast(_newCimString(clsProp.theProperty.name,cls.base)),
               theCimValue,
               theCimValue.getArraySize(),
               CIMNameCast(
                   _newCimString(clsProp.theProperty.refClassName,cls.base)),
               CIMNameCast(
                   _newCimString(clsProp.theProperty.originClassName,cls.base)),
               clsProp.theProperty.flags.propagated);
       }
       else
       {
            retCimProperty = CIMProperty(
               CIMNameCast(_newCimString(clsProp.theProperty.name,cls.base)),
               theCimValue,
               theCimValue.getArraySize(),
               CIMNameCast(
                   _newCimString(clsProp.theProperty.refClassName,cls.base)),
               CIMName(),
               clsProp.theProperty.flags.propagated);
       }
   
       SCMBQualifier* qualiArray =
           (SCMBQualifier*)
                &(cls.base[clsProp.theProperty.qualifierArray.start]);
   
       CIMQualifier theCimQualifier;
       Uint32 i, k = clsProp.theProperty.numberOfQualifiers;
       for ( i = 0 ; i < k ; i++)
       {
           _getCIMQualifierFromSCMBQualifier(
               theCimQualifier,
               qualiArray[i],
               cls.base);
   
           retCimProperty._rep->_qualifiers.addUnchecked(theCimQualifier);
       }
   
       return retCimProperty;
   
   }
   
   void SCMOClass::_getCIMQualifierFromSCMBQualifier(
       CIMQualifier& theCimQualifier,
       const SCMBQualifier& scmbQualifier,
       const char* base)
   
   {
   
       CIMName theCimQualiName;
       CIMValue theCimValue;
   
       SCMOInstance::_getCIMValueFromSCMBValue(
           theCimValue,
           scmbQualifier.value,
           base);
   
       if (scmbQualifier.name == QUALNAME_USERDEFINED)
       {
           theCimQualiName = _newCimString(scmbQualifier.userDefName,base);
       }
       else
       {
           theCimQualiName = String(
               SCMOClass::qualifierNameStrLit(scmbQualifier.name).str,
               SCMOClass::qualifierNameStrLit(scmbQualifier.name).size);
       }
   
       theCimQualifier = CIMQualifier(
           theCimQualiName,
           theCimValue,
           scmbQualifier.flavor,
           scmbQualifier.propagated);
 } }
  
 void SCMOClass::getKeyNamesAsString(Array<String>& keyNames) const void SCMOClass::getKeyNamesAsString(Array<String>& keyNames) const
Line 212 
Line 550 
  
     keyNames.clear();     keyNames.clear();
  
     for (Uint32 i = 0 ; i < cls.hdr->propertySet.number; i++)      for (Uint32 i = 0, k = cls.hdr->keyBindingSet.number; i < k; i++)
     {     {
         // Append the key property name.         // Append the key property name.
         // The length has to be reduces by 1 not to copy the trailing '\0'          keyNames.append(_newCimString(nodeArray[i].name,cls.base));
         keyNames.append(      }
             String((const char*)_getCharString(nodeArray[i].name,cls.base),  
                    nodeArray[i].name.length-1));  
   
     }     }
   
   const char* SCMOClass::_getPropertyNameAtNode(Uint32 propNode) const
   {
       SCMBClassPropertyNode* nodeArray =
           (SCMBClassPropertyNode*)
               &(cls.base[cls.hdr->propertySet.nodeArray.start]);
   
       return(_getCharString(nodeArray[propNode].theProperty.name,cls.base));
 } }
  
 SCMO_RC SCMOClass::_getKeyBindingNodeIndex(Uint32& node, const char* name) const SCMO_RC SCMOClass::_getKeyBindingNodeIndex(Uint32& node, const char* name) const
Line 232 
Line 575 
     tag = _generateStringTag((const char*)name, len);     tag = _generateStringTag((const char*)name, len);
     // get the node index of the hash table     // get the node index of the hash table
     hashIdx =     hashIdx =
         cls.hdr->keyBindingSet.hashTable[tag%PEGASUS_KEYBINDIG_SCMB_HASHSIZE];        cls.hdr->keyBindingSet.hashTable[tag&(PEGASUS_KEYBINDIG_SCMB_HASHSIZE-1)];
     // there is no entry in the hash table on this hash table index.     // there is no entry in the hash table on this hash table index.
     if (hashIdx == 0)     if (hashIdx == 0)
     {     {
Line 255 
Line 598 
         if (nodeArray[node].nameHashTag == tag)         if (nodeArray[node].nameHashTag == tag)
         {         {
             // Now it is worth to compare the two names             // Now it is worth to compare the two names
             if (_equalUTF8Strings(              if (_equalNoCaseUTF8Strings(nodeArray[node].name,cls.base,name,len))
                 nodeArray[node].name,cls.base,name,len))  
             {             {
                 // we found the property !                 // we found the property !
                 return SCMO_OK;                 return SCMO_OK;
Line 279 
Line 621 
  
 } }
  
   
 SCMO_RC SCMOClass::_getProperyNodeIndex(Uint32& node, const char* name) const SCMO_RC SCMOClass::_getProperyNodeIndex(Uint32& node, const char* name) const
 { {
  
Line 289 
Line 630 
     tag = _generateStringTag((const char*)name, len);     tag = _generateStringTag((const char*)name, len);
     // get the node index of the hash table     // get the node index of the hash table
     hashIdx =     hashIdx =
         cls.hdr->propertySet.hashTable[tag%PEGASUS_PROPERTY_SCMB_HASHSIZE];        cls.hdr->propertySet.hashTable[tag&(PEGASUS_PROPERTY_SCMB_HASHSIZE -1)];
     // there is no entry in the hash table on this hash table index.     // there is no entry in the hash table on this hash table index.
     if (hashIdx == 0)     if (hashIdx == 0)
     {     {
Line 312 
Line 653 
         if (nodeArray[node].theProperty.nameHashTag == tag)         if (nodeArray[node].theProperty.nameHashTag == tag)
         {         {
             // Now it is worth to compare the two names             // Now it is worth to compare the two names
             if (_equalUTF8Strings(              if (_equalNoCaseUTF8Strings(
                 nodeArray[node].theProperty.name,cls.base,name,len))                 nodeArray[node].theProperty.name,cls.base,name,len))
             {             {
                 // we found the property !                 // we found the property !
Line 332 
Line 673 
     } while ( true );     } while ( true );
  
     // this should never be reached     // this should never be reached
     return SCMO_NOT_FOUND;      PEGASUS_UNREACHABLE(return SCMO_NOT_FOUND;)
   
 } }
  
 void SCMOClass::_setClassProperties(CIMClass& theCIMClass)  void SCMOClass::_setClassProperties(PropertySet& theCIMProperties)
 { {
     Uint32 noProps = theCIMClass.getPropertyCount();      Uint32 noProps = theCIMProperties.size();
     Uint64 start, startKeyIndexList;     Uint64 start, startKeyIndexList;
     Uint32 noKeys = 0;     Uint32 noKeys = 0;
     Boolean isKey = false;     Boolean isKey = false;
  
     Uint32 keyIndex[noProps];      Array<Uint32> keyIndex(noProps);
  
     cls.hdr->propertySet.number=noProps;     cls.hdr->propertySet.number=noProps;
  
Line 351 
Line 691 
     startKeyIndexList = _getFreeSpace(     startKeyIndexList = _getFreeSpace(
         cls.hdr->keyIndexList,         cls.hdr->keyIndexList,
         noProps*sizeof(Uint32),         noProps*sizeof(Uint32),
         &cls.mem,          &cls.mem);
         true);  
  
     if(noProps != 0)     if(noProps != 0)
     {     {
Line 378 
Line 717 
                0,                0,
                PEGASUS_PROPERTY_SCMB_HASHSIZE*sizeof(Uint32));                PEGASUS_PROPERTY_SCMB_HASHSIZE*sizeof(Uint32));
  
         _clearKeyPropertyMask();  
  
         for (Uint32 i = 0; i < noProps; i++)         for (Uint32 i = 0; i < noProps; i++)
         {         {
  
             _setProperty(start,&isKey ,theCIMClass.getProperty(i));              _setProperty(start,&isKey ,theCIMProperties[i]);
             if(isKey)             if(isKey)
             {             {
                 // if the property is a key                 // if the property is a key
Line 415 
Line 753 
             // fill the key index list             // fill the key index list
             memcpy(             memcpy(
                 &(cls.base[startKeyIndexList]),                 &(cls.base[startKeyIndexList]),
                 keyIndex,                  keyIndex.getData(),
                 noKeys*sizeof(Uint32));                 noKeys*sizeof(Uint32));
  
             for (Uint32 i = 0 ; i < noKeys; i++)             for (Uint32 i = 0 ; i < noKeys; i++)
             {             {
  
                 _setClassKeyBinding(start,theCIMClass.getProperty(keyIndex[i]));                  _setClassKeyBinding(start,theCIMProperties[keyIndex[i]]);
                 // Adjust ordered set management structures.                 // Adjust ordered set management structures.
                 _insertKeyBindingIntoOrderedSet(start,i);                 _insertKeyBindingIntoOrderedSet(start,i);
  
Line 432 
Line 770 
         else         else
         {         {
             cls.hdr->keyBindingSet.nodeArray.start=0;             cls.hdr->keyBindingSet.nodeArray.start=0;
             cls.hdr->keyBindingSet.nodeArray.length=0;              cls.hdr->keyBindingSet.nodeArray.size=0;
         }         }
     }     }
     else     else
     {     {
         cls.hdr->propertySet.nodeArray.start=0;         cls.hdr->propertySet.nodeArray.start=0;
         cls.hdr->propertySet.nodeArray.length=0;          cls.hdr->propertySet.nodeArray.size=0;
         cls.hdr->keyPropertyMask.start=0;         cls.hdr->keyPropertyMask.start=0;
         cls.hdr->keyPropertyMask.length=0;          cls.hdr->keyPropertyMask.size=0;
         cls.hdr->keyBindingSet.nodeArray.start=0;         cls.hdr->keyBindingSet.nodeArray.start=0;
         cls.hdr->keyBindingSet.nodeArray.length=0;          cls.hdr->keyBindingSet.nodeArray.size=0;
     }     }
 } }
  
Line 458 
Line 796 
  
     Uint32 *hashTable = cls.hdr->keyBindingSet.hashTable;     Uint32 *hashTable = cls.hdr->keyBindingSet.hashTable;
  
     if ( newIndex >= cls.hdr->keyBindingSet.number)  
     {  
         throw IndexOutOfBoundsException();  
     }  
   
     // calculate the new hash index of the new property.     // calculate the new hash index of the new property.
     Uint32 hash = newKeyNode->nameHashTag % PEGASUS_KEYBINDIG_SCMB_HASHSIZE;      Uint32 hash = newKeyNode->nameHashTag &
           (PEGASUS_KEYBINDIG_SCMB_HASHSIZE - 1);
  
     // 0 is an invalid index in the hash table     // 0 is an invalid index in the hash table
     if (hashTable[hash] == 0)     if (hashTable[hash] == 0)
Line 514 
Line 848 
  
     Uint32 *hashTable = cls.hdr->propertySet.hashTable;     Uint32 *hashTable = cls.hdr->propertySet.hashTable;
  
     if ( newIndex >= cls.hdr->propertySet.number)  
     {  
         throw IndexOutOfBoundsException();  
     }  
   
     // calcuate the new hash index of the new property.     // calcuate the new hash index of the new property.
     Uint32 hash = newPropNode->theProperty.nameHashTag %      Uint32 hash = newPropNode->theProperty.nameHashTag &
         PEGASUS_PROPERTY_SCMB_HASHSIZE;          (PEGASUS_PROPERTY_SCMB_HASHSIZE -1);
  
     // 0 is an invalid index in the hash table     // 0 is an invalid index in the hash table
     if (hashTable[hash] == 0)     if (hashTable[hash] == 0)
Line 564 
Line 893 
     const CIMProperty& theCIMProperty)     const CIMProperty& theCIMProperty)
 { {
     CIMPropertyRep* propRep = theCIMProperty._rep;     CIMPropertyRep* propRep = theCIMProperty._rep;
     Uint64 valueStart;  
  
     // First do all _setString(). Can cause reallocation.     // First do all _setString(). Can cause reallocation.
     _setString(propRep->_name.getString(),     _setString(propRep->_name.getString(),
Line 577 
Line 905 
     // calculate the new hash tag     // calculate the new hash tag
     scmoKeyBindNode->nameHashTag =     scmoKeyBindNode->nameHashTag =
         _generateSCMOStringTag(scmoKeyBindNode->name,cls.base);         _generateSCMOStringTag(scmoKeyBindNode->name,cls.base);
     scmoKeyBindNode->type = _cimTypeToKeyBindType(propRep->_value.getType());      scmoKeyBindNode->type = propRep->_value.getType();
     scmoKeyBindNode->hasNext=false;     scmoKeyBindNode->hasNext=false;
     scmoKeyBindNode->nextNode=0;     scmoKeyBindNode->nextNode=0;
  
 } }
  
 void SCMOClass::_clearKeyPropertyMask()  
 {  
   
     Uint64 *keyMask;  
   
     // Calculate the real pointer to the Uint64 array  
     keyMask = (Uint64*)&cls.base[cls.hdr->keyPropertyMask.start];  
   
     // the number of Uint64 in the key mask is :  
     // Decrease the number of properties by 1  
     // since the array is starting at index 0!  
     // Divide with the number of bits in a Uint64.  
     // e.g. number of Properties = 68  
     // (68 - 1) / 64 = 1 --> The mask consists of 2 Uint64  
   
     memset(keyMask,0, sizeof(Uint64)*(((cls.hdr->propertySet.number-1)/64)+1));  
   
 }  
   
 void SCMOClass::_setPropertyAsKeyInMask(Uint32 i) void SCMOClass::_setPropertyAsKeyInMask(Uint32 i)
 { {
     Uint64 *keyMask;     Uint64 *keyMask;
Line 613 
Line 922 
  
     // Create a filter to set the bit.     // Create a filter to set the bit.
     // Modulo division with 64. Shift left a bit by the remainder.     // Modulo division with 64. Shift left a bit by the remainder.
     Uint64 filter = ( (Uint64)1 << (i%64));      Uint64 filter = ( (Uint64)1 << (i & 63));
  
     // Calculate the real pointer to the Uint64 array     // Calculate the real pointer to the Uint64 array
     keyMask = (Uint64*)&cls.base[cls.hdr->keyPropertyMask.start];      keyMask = (Uint64*)&(cls.base[cls.hdr->keyPropertyMask.start]);
  
     keyMask[idx] = keyMask[idx] | filter ;     keyMask[idx] = keyMask[idx] | filter ;
 } }
Line 633 
Line 942 
  
     // Create a filter to check if the bit is set:     // Create a filter to check if the bit is set:
     // Modulo division with 64. Shift left a bit by the remainder.     // Modulo division with 64. Shift left a bit by the remainder.
     Uint64 filter = ( (Uint64)1 << (i%64));      Uint64 filter = ( (Uint64)1 << (i & 63));
  
     // Calculate the real pointer to the Uint64 array     // Calculate the real pointer to the Uint64 array
     keyMask = (Uint64*)&cls.base[cls.hdr->keyPropertyMask.start];      keyMask = (Uint64*)&(cls.base[cls.hdr->keyPropertyMask.start]);
  
     return keyMask[idx] & filter ;     return keyMask[idx] & filter ;
  
Line 732 
Line 1041 
     else     else
     {     {
         scmoPropNode->theProperty.qualifierArray.start=0;         scmoPropNode->theProperty.qualifierArray.start=0;
         scmoPropNode->theProperty.qualifierArray.length=0;          scmoPropNode->theProperty.qualifierArray.size=0;
     }     }
  
     return isKey;     return isKey;
 } }
 void SCMOClass::_setClassQualifers(CIMClass& theCIMClass)  
   void SCMOClass::_setClassQualifers(const CIMQualifierList& theQualifierList)
 { {
  
     Uint32 noQuali = theCIMClass.getQualifierCount();      Uint32 noQuali = theQualifierList.getCount();
     Uint64 start;     Uint64 start;
  
     cls.hdr->numberOfQualifiers = noQuali;     cls.hdr->numberOfQualifiers = noQuali;
Line 753 
Line 1063 
                       &cls.mem);                       &cls.mem);
         for (Uint32 i = 0; i < noQuali; i++)         for (Uint32 i = 0; i < noQuali; i++)
         {         {
             _setQualifier(start,theCIMClass.getQualifier(i));              _setQualifier(start,theQualifierList.getQualifier(i));
             start = start + sizeof(SCMBQualifier);             start = start + sizeof(SCMBQualifier);
  
         }         }
Line 762 
Line 1072 
     else     else
     {     {
         cls.hdr->qualifierArray.start=0;         cls.hdr->qualifierArray.start=0;
         cls.hdr->qualifierArray.length=0;          cls.hdr->qualifierArray.size=0;
     }     }
   
   
 } }
  
 QualifierNameEnum SCMOClass::_setQualifier( QualifierNameEnum SCMOClass::_setQualifier(
Line 797 
Line 1105 
     return name;     return name;
 } }
  
 void SCMOClass::_setValue(Uint64 start, const CIMValue& theCIMValue)  void SCMOClass::_setValue(
       Uint64 start,
       const CIMValue& theCIMValue)
 { {
     Uint64 valueStart;     Uint64 valueStart;
  
Line 808 
Line 1118 
     scmoValue->valueArraySize = 0;     scmoValue->valueArraySize = 0;
     scmoValue->flags.isNull = rep->isNull;     scmoValue->flags.isNull = rep->isNull;
     scmoValue->flags.isArray = rep->isArray;     scmoValue->flags.isArray = rep->isArray;
     // Only initalized by for completeness.  
     scmoValue->flags.isSet = false;     scmoValue->flags.isSet = false;
  
     valueStart = (char*)&scmoValue->value - cls.base;  
   
     if (rep->isNull)     if (rep->isNull)
     {     {
         return;         return;
     }     }
  
       valueStart = (char*)&scmoValue->value - cls.base;
   
     if (scmoValue->flags.isArray)     if (scmoValue->flags.isArray)
     {     {
         scmoValue->valueArraySize = theCIMValue.getArraySize();          SCMOInstance::_setUnionArrayValue(
         _setArrayValue(valueStart,rep->type, rep->u);              valueStart,
               &cls.mem,
               rep->type,
               // Is set to the number of array members by the function.
               scmoValue->valueArraySize,
               cls.hdr->nameSpace.start,
               cls.hdr->nameSpace.size,
               rep->u);
     }     }
     else     else
     {     {
         _setUnionValue(valueStart, rep->type, rep->u);          SCMOInstance::_setUnionValue(
               valueStart,
               &cls.mem,
               rep->type,
               cls.hdr->nameSpace.start,
               cls.hdr->nameSpace.size,
               rep->u);
     }     }
 } }
  
 void SCMOClass::_setArrayValue(Uint64 start, CIMType type, Union& u)  QualifierNameEnum SCMOClass::_getSCMOQualifierNameEnum(
       const CIMName& theCIMName)
 { {
     SCMBUnion* scmoUnion = (SCMBUnion*)&(cls.base[start]);      // Get the UTF8 CString
     Uint64 arrayStart;      CString theCString=theCIMName.getString().getCString();
     Uint32 n;      // Get the real size of the UTF8 sting.
       Uint32 length = strlen((const char*)theCString);
  
     switch (type)  
       // The start index is 1, because the at index 0 is a place holder for
       // the user defined qualifier name which is not part of the qualifier name
       // list.
       for (Uint32 i = 1; i < _NUM_QUALIFIER_NAMES; i++)
     {     {
     case CIMTYPE_BOOLEAN:          if (qualifierNameStrLit(i).size == length)
         {         {
             Array<Boolean> *x = reinterpret_cast<Array<Boolean>*>(&u);              // TBD: Make it more efficent...
             n = x->size();              if(String::equalNoCase(
             arrayStart = _getFreeSpace(                  theCIMName.getString(),
                 scmoUnion->_arrayValue,                  qualifierNameStrLit(i).str))
                 n*sizeof(Boolean),  
                 &cls.mem);  
             memcpy(&cls.base[arrayStart],x->getData(),n * sizeof(Boolean));  
             break;  
         }  
   
     case CIMTYPE_UINT8:  
         {         {
             Array<Uint8> *x = reinterpret_cast<Array<Uint8>*>(&u);                  return (QualifierNameEnum)i;
             n = x->size();              }
             arrayStart = _getFreeSpace(          }
                 scmoUnion->_arrayValue,  
                 n*sizeof(Uint8),  
                 &cls.mem);  
             memcpy(&cls.base[arrayStart],x->getData(),n * sizeof(Uint8));  
             break;  
         }         }
  
     case CIMTYPE_SINT8:      return QUALNAME_USERDEFINED;
         {  
             Array<Sint8> *x = reinterpret_cast<Array<Sint8>*>(&u);  
             n = x->size();  
             arrayStart = _getFreeSpace(  
                 scmoUnion->_arrayValue,  
                 n*sizeof(Sint8),  
                 &cls.mem);  
             memcpy(&cls.base[arrayStart],x->getData(),n * sizeof(Sint8));  
             break;  
         }         }
  
     case CIMTYPE_UINT16:  Boolean SCMOClass::_isSamePropOrigin(Uint32 node, const char* origin) const
         {         {
             Array<Uint16> *x = reinterpret_cast<Array<Uint16>*>(&u);     Uint32 len = strlen(origin);
             n = x->size();  
             arrayStart = _getFreeSpace(  
                 scmoUnion->_arrayValue,  
                 n*sizeof(Uint16),  
                 &cls.mem);  
             memcpy(&cls.base[arrayStart],x->getData(),n * sizeof(Uint16));  
  
             break;     SCMBClassPropertyNode* nodeArray =
         }         (SCMBClassPropertyNode*)
              &(cls.base[cls.hdr->propertySet.nodeArray.start]);
  
     case CIMTYPE_SINT16:     return(_equalNoCaseUTF8Strings(
         {         nodeArray[node].theProperty.originClassName,
             Array<Sint16> *x = reinterpret_cast<Array<Sint16>*>(&u);         cls.base,
             n = x->size();         origin,
             arrayStart = _getFreeSpace(         len));
                 scmoUnion->_arrayValue,  
                 n*sizeof(Sint16),  
                 &cls.mem);  
             memcpy(&cls.base[arrayStart],x->getData(),n * sizeof(Sint16));  
             break;  
         }         }
  
     case CIMTYPE_UINT32:  SCMO_RC SCMOClass::_isNodeSameType(
         {      Uint32 node,
             Array<Uint32> *x = reinterpret_cast<Array<Uint32>*>(&u);      CIMType type,
             n = x->size();      Boolean isArray,
             arrayStart = _getFreeSpace(      CIMType& realType) const
                 scmoUnion->_arrayValue,  {
                 n*sizeof(Uint32),  
                 &cls.mem);      SCMBClassPropertyNode* nodeArray =
             memcpy(&cls.base[arrayStart],x->getData(),n * sizeof(Uint32));          (SCMBClassPropertyNode*)
             break;              &(cls.base[cls.hdr->propertySet.nodeArray.start]);
   
       // The type stored in the class information is set on realType.
       // It must be used in further calls to guaranty consistence.
       realType = nodeArray[node].theProperty.defaultValue.valueType;
   
       if(nodeArray[node].theProperty.defaultValue.valueType != type)
       {
           // Accept an property of type instance also
           // for an CIMTYPE_OBJECT property.
           if (!(type == CIMTYPE_INSTANCE &&
                 nodeArray[node].theProperty.defaultValue.valueType
                 == CIMTYPE_OBJECT))
           {
               return SCMO_WRONG_TYPE;
           }
         }         }
  
     case CIMTYPE_SINT32:      if (isArray)
         {         {
             Array<Sint32> *x = reinterpret_cast<Array<Sint32>*>(&u);          if (nodeArray[node].theProperty.defaultValue.flags.isArray)
             n = x->size();          {
             arrayStart = _getFreeSpace(              return SCMO_OK;
                 scmoUnion->_arrayValue,          }
                 n*sizeof(Sint32),          else
                 &cls.mem);          {
             memcpy(&cls.base[arrayStart],x->getData(),n * sizeof(Sint32));              return SCMO_NOT_AN_ARRAY;
             break;  
         }         }
  
     case CIMTYPE_UINT64:      }
   
       if (nodeArray[node].theProperty.defaultValue.flags.isArray)
         {         {
             Array<Uint64> *x = reinterpret_cast<Array<Uint64>*>(&u);          return SCMO_IS_AN_ARRAY;
             n = x->size();  
             arrayStart = _getFreeSpace(  
                 scmoUnion->_arrayValue,  
                 n*sizeof(Uint64),  
                 &cls.mem);  
             memcpy(&cls.base[arrayStart],x->getData(),n * sizeof(Uint64));  
             break;  
         }         }
  
     case CIMTYPE_SINT64:      return SCMO_OK;
   
   }
   
   /*****************************************************************************
    * The SCMOInstance methods
    *****************************************************************************/
   
   SCMOInstance::SCMOInstance()
         {         {
             Array<Sint64> *x = reinterpret_cast<Array<Sint64>*>(&u);      inst.base = 0;
             n = x->size();  
             arrayStart = _getFreeSpace(  
                 scmoUnion->_arrayValue,  
                 n*sizeof(Sint64),  
                 &cls.mem);  
             memcpy(&cls.base[arrayStart],x->getData(),n * sizeof(Sint64));  
             break;  
         }         }
  
     case CIMTYPE_REAL32:  SCMOInstance::SCMOInstance(SCMOClass& baseClass)
         {         {
             Array<Real32> *x = reinterpret_cast<Array<Real32>*>(&u);      _initSCMOInstance(new SCMOClass(baseClass));
             n = x->size();  
             arrayStart = _getFreeSpace(  
                 scmoUnion->_arrayValue,  
                 n*sizeof(Real32),  
                 &cls.mem);  
             memcpy(&cls.base[arrayStart],x->getData(),n * sizeof(Real32));  
             break;  
         }         }
  
     case CIMTYPE_REAL64:  SCMOInstance::SCMOInstance(
       SCMOClass& baseClass,
       Boolean includeQualifiers,
       Boolean includeClassOrigin)
         {         {
             Array<Real64> *x = reinterpret_cast<Array<Real64>*>(&u);  
             n = x->size();      _initSCMOInstance(new SCMOClass(baseClass));
             arrayStart = _getFreeSpace(  
                 scmoUnion->_arrayValue,      inst.hdr->flags.includeQualifiers=includeQualifiers;
                 n*sizeof(Real64),      inst.hdr->flags.includeClassOrigin=includeClassOrigin;
                 &cls.mem);  
             memcpy(&cls.base[arrayStart],x->getData(),n * sizeof(Real64));  
             break;  
         }         }
  
     case CIMTYPE_CHAR16:  SCMOInstance::SCMOInstance(SCMOClass& baseClass, const CIMObjectPath& cimObj)
         {         {
             Array<Char16> *x = reinterpret_cast<Array<Char16>*>(&u);      _initSCMOInstance(new SCMOClass(baseClass));
             n = x->size();  
             arrayStart = _getFreeSpace(      _setCIMObjectPath(cimObj);
                 scmoUnion->_arrayValue,  
                 n*sizeof(Char16),  
                 &cls.mem);  
             memcpy(&cls.base[arrayStart],x->getData(),n * sizeof(Char16));  
             break;  
         }         }
  
     case CIMTYPE_STRING:  SCMOInstance::SCMOInstance(SCMOClass& baseClass, const CIMInstance& cimInstance)
         {         {
             SCMBDataPtr *ptr;  
  
             Array<String> *x = reinterpret_cast<Array<String>*>(&u);      _initSCMOInstance(new SCMOClass(baseClass));
  
             n = x->size();      _setCIMInstance(cimInstance);
             arrayStart = _getFreeSpace(  
                 scmoUnion->_arrayValue,  
                 n*sizeof(SCMBDataPtr),  
                 &cls.mem);  
  
             for (Uint32 i = 0; i < n ; i++)  
             {  
                 // the pointer has to be set eache loop,  
                 // because a reallocation may take place.  
                 ptr = (SCMBDataPtr*)(&cls.base[arrayStart]);  
                 _setString( (*x)[i],ptr[i], &cls.mem );  
             }             }
  
             break;  SCMOInstance::SCMOInstance(CIMClass& theCIMClass, const char* altNameSpace)
   {
       _initSCMOInstance(new SCMOClass(theCIMClass,altNameSpace));
   
         }         }
  
     case CIMTYPE_DATETIME:  SCMOInstance::SCMOInstance(
       const CIMInstance& cimInstance,
       const char* altNameSpace,
       Uint32 altNSLen)
         {         {
             SCMBDateTime *ptr;      SCMOClass theSCMOClass = _getSCMOClass(
             Array<CIMDateTime> *x = reinterpret_cast<Array<CIMDateTime>*>(&u);          cimInstance._rep->_reference,
             n = x->size();          altNameSpace,
             arrayStart = _getFreeSpace(          altNSLen);
                 scmoUnion->_arrayValue,  
                 n*sizeof(SCMBDateTime),  
                 &cls.mem);  
  
             ptr=(SCMBDateTime*)(&cls.base[arrayStart]);      _initSCMOInstance( new SCMOClass(theSCMOClass));
  
             for (Uint32 i = 0; i < n ; i++)      if(theSCMOClass.isEmpty())
             {             {
                 memcpy(&(ptr[i]),(*x)[i]._rep,sizeof(SCMBDateTime));          // flag the instance as compromized
           inst.hdr->flags.isCompromised=true;
       }
       else
       {
           _setCIMInstance(cimInstance);
             }             }
             break;  
         }         }
  
         case CIMTYPE_REFERENCE:  SCMOInstance::SCMOInstance(
       const CIMObject& cimObject,
       const char* altNameSpace,
       Uint32 altNSLen)
   {
       if (cimObject.isClass())
       {
           CIMClass cimClass(cimObject);
  
             break;          _initSCMOInstance(new SCMOClass(cimClass,altNameSpace));
  
         case CIMTYPE_OBJECT:          inst.hdr->flags.isClassOnly=true;
       }
       else
       {
           CIMInstance cimInstance(cimObject);
  
             break;          SCMOClass theSCMOClass = _getSCMOClass(
               cimInstance._rep->_reference,
               altNameSpace,
               altNSLen);
  
         case CIMTYPE_INSTANCE:          _initSCMOInstance( new SCMOClass(theSCMOClass));
  
             break;          if(theSCMOClass.isEmpty())
           {
               // flag the instance as compromized
               inst.hdr->flags.isCompromised=true;
           }
           else
           {
               _setCIMInstance(cimInstance);
           }
     }     }
 } }
  
   SCMOInstance::SCMOInstance(
 void SCMOClass::_setUnionValue(Uint64 start, CIMType type, Union& u)      const CIMObjectPath& cimObj,
       const char* altNameSpace,
       Uint32 altNSLen)
 { {
     SCMBUnion* scmoUnion = (SCMBUnion*)&(cls.base[start]);      SCMOClass theSCMOClass = _getSCMOClass(
           cimObj,
           altNameSpace,
           altNSLen);
  
     switch (type)      _initSCMOInstance( new SCMOClass(theSCMOClass));
   
       if(theSCMOClass.isEmpty())
     {     {
     case CIMTYPE_BOOLEAN:          // flag the instance as compromized
           inst.hdr->flags.isCompromised=true;
       }
       else
         {         {
             scmoUnion->_booleanValue = u._booleanValue;          _setCIMObjectPath(cimObj);
             break;      }
         }         }
  
     case CIMTYPE_UINT8:  void SCMOInstance::_destroyExternalReferences()
         {         {
             scmoUnion->_uint8Value = u._uint8Value;      _destroyExternalReferencesInternal(inst.mem);
             break;  
         }         }
  
     case CIMTYPE_SINT8:  SCMOClass SCMOInstance::_getSCMOClass(
       const CIMObjectPath& theCIMObj,
       const char* altNS,
       Uint32 altNSlength)
         {         {
             scmoUnion->_sint8Value = u._sint8Value;      SCMOClass theClass;
             break;  
         }  
  
     case CIMTYPE_UINT16:      if (theCIMObj.getClassName().isNull())
         {         {
             scmoUnion->_uint16Value = u._uint16Value;          return SCMOClass();
             break;  
         }         }
  
     case CIMTYPE_SINT16:      if (theCIMObj.getNameSpace().isNull())
         {         {
             scmoUnion->_sint16Value = u._sint16Value;          // the name space of the object path is empty,
             break;          // use alternative name space.
         }          CString clsName = theCIMObj.getClassName().getString().getCString();
  
     case CIMTYPE_UINT32:          SCMOClassCache* theCache = SCMOClassCache::getInstance();
           theClass = theCache->getSCMOClass(
               altNS,
               altNSlength,
               (const char*)clsName,
               strlen(clsName));
       }
       else
         {         {
             scmoUnion->_uint32Value = u._uint32Value;          CString nameSpace = theCIMObj.getNameSpace().getString().getCString();
             break;          CString clsName = theCIMObj.getClassName().getString().getCString();
   
           SCMOClassCache* theCache = SCMOClassCache::getInstance();
           theClass = theCache->getSCMOClass(
               (const char*)nameSpace,
               strlen(nameSpace),
               (const char*)clsName,
               strlen(clsName));
         }         }
  
     case CIMTYPE_SINT32:      return theClass;
         {  
             scmoUnion->_sint32Value = u._sint32Value;  
             break;  
         }         }
  
     case CIMTYPE_UINT64:  #define PEGASUS_SIZE_REFERENCE_INDEX_ARRAY 8
   
   void SCMOInstance::_setExtRefIndex(SCMBUnion* pInst, SCMBMgmt_Header** pmem)
         {         {
             scmoUnion->_uint64Value = u._uint64Value;  
             break;  
         }  
  
     case CIMTYPE_SINT64:      Uint64 refPtr =(((char *)pInst) - (char *)(*pmem));
       SCMBMgmt_Header* memHdr = (*pmem);
       // Save the number of external references in the array
       Uint32 noExtRef = memHdr->numberExtRef;
   
       // Allocate the external reflerence array
       // if it is full or empty ( 0 == 0 ).
       if (noExtRef == memHdr->sizeExtRefIndexArray)
         {         {
             scmoUnion->_sint64Value = u._sint64Value;          Uint64 oldArrayStart = memHdr->extRefIndexArray.start;
             break;          Uint32 newSize =
         }              memHdr->sizeExtRefIndexArray + PEGASUS_SIZE_REFERENCE_INDEX_ARRAY;
  
     case CIMTYPE_REAL32:          // Allocate the external reference index array
           _getFreeSpace(
                 memHdr->extRefIndexArray,
                 sizeof(Uint64)*newSize,
                 pmem);
   
           // reset the pointer. It could be changed due to reallocation !
           memHdr = (*pmem);
   
           // Assign new size.
           memHdr->sizeExtRefIndexArray=newSize;
   
           // Get absolute pointer to old index array.
           Uint64* oldArray = (Uint64*)&(((char*)(*pmem))[oldArrayStart]);
           // Get absolute pointer to new index array
           Uint64* newArray =
               (Uint64*)&(((char*)(*pmem))[memHdr->extRefIndexArray.start]);
   
           // Copy all elements of the old array to the new.
           // If noExtRef = 0, no elements are copied.
           for (Uint32 i = 0 ; i < noExtRef ; i++)
         {         {
             scmoUnion->_real32Value = u._real32Value;              newArray[i] = oldArray[i];
             break;          }
         }         }
  
     case CIMTYPE_REAL64:      // Get absolute pointer to the array
       Uint64* array =
           (Uint64*)&(((char*)(*pmem))[memHdr->extRefIndexArray.start]);
       // look in the table if the index is already in the array
       for (Uint32 i = 0 ; i < noExtRef ; i++)
         {         {
             scmoUnion->_real64Value = u._real64Value;          // is the index already part of the array
             break;          if (array[i] == refPtr)
           {
               // leave.
               return;
           }
         }         }
       // It is not part of the array -> set the new index.
       array[noExtRef] = refPtr;
       // increment the nuber of external references of this instance.
       memHdr->numberExtRef++;
  
     case CIMTYPE_CHAR16:  }
   
   SCMOInstance* SCMOInstance::getExtRef(Uint32 idx) const
         {         {
             scmoUnion->_char16Value = u._char16Value;      Uint64* array =
             break;          (Uint64*)&(inst.base[inst.mem->extRefIndexArray.start]);
       SCMBUnion* pUnion;
       pUnion = (SCMBUnion*)(&(inst.base[array[idx]]));
       return pUnion->extRefPtr;
         }         }
  
     case CIMTYPE_STRING:  void SCMOInstance::putExtRef(Uint32 idx,SCMOInstance* ptr)
         {         {
             _setString(*((String*)((void*)&u)),      Uint64* array =
                        scmoUnion->_stringValue,          (Uint64*)&(inst.base[inst.mem->extRefIndexArray.start]);
                        &cls.mem );      SCMBUnion* pUnion;
             break;      pUnion = (SCMBUnion*)(&(inst.base[array[idx]]));
       pUnion->extRefPtr = ptr;
         }         }
  
     case CIMTYPE_DATETIME:  void SCMOInstance::_copyExternalReferences()
         {         {
       Uint32 number = inst.mem->numberExtRef;
  
             memcpy(      if (0 != number)
                 &scmoUnion->_dateTimeValue,      {
                 (*((CIMDateTime*)((void*)&u)))._rep,          SCMBUnion* pUnion;
                 sizeof(SCMBDateTime));          Uint64* array =
             break;              (Uint64*)&(inst.base[inst.mem->extRefIndexArray.start]);
           for (Uint32 i = 0; i < number; i++)
           {
               pUnion = (SCMBUnion*)(&(inst.base[array[i]]));
               if (0 != pUnion)
               {
                   pUnion->extRefPtr = new SCMOInstance(*(pUnion->extRefPtr));
               }
         }         }
  
         case CIMTYPE_REFERENCE:      }
  
             break;  }
  
         case CIMTYPE_OBJECT:  void SCMOInstance::_destroyExternalKeyBindings()
   {
       // Create a pointer to keybinding node array of the class.
       Uint64 idx = inst.hdr->theClass.ptr->cls.hdr->keyBindingSet.nodeArray.start;
       SCMBKeyBindingNode* theClassKeyBindNodeArray =
           (SCMBKeyBindingNode*)&((inst.hdr->theClass.ptr->cls.base)[idx]);
  
             break;      // create a pointer to instanc key binding array.
         case CIMTYPE_INSTANCE:      SCMBKeyBindingValue* theInstanceKeyBindingNodeArray =
           (SCMBKeyBindingValue*)&(inst.base[inst.hdr->keyBindingArray.start]);
  
             break;      for (Uint32 i = 0; i < inst.hdr->numberKeyBindings; i++)
       {
           if (theInstanceKeyBindingNodeArray[i].isSet)
           {
               // only references can be a key binding
               if (theClassKeyBindNodeArray[i].type == CIMTYPE_REFERENCE)
               {
                  _deleteExternalReferenceInternal(
                      inst.mem,
                      theInstanceKeyBindingNodeArray[i].data.extRefPtr);
     }     }
   
 } }
       }// for all key bindings
  
 QualifierNameEnum SCMOClass::_getSCMOQualifierNameEnum(      // Are there user defined key bindings ?
     const CIMName& theCIMName)      if (0 != inst.hdr->numberUserKeyBindings)
 { {
     // Get the UTF8 CString          SCMBUserKeyBindingElement* theUserDefKBElement =
     CString theCString=theCIMName.getString().getCString();              (SCMBUserKeyBindingElement*)
     // Get the real size of the UTF8 sting.                   &(inst.base[inst.hdr->userKeyBindingElement.start]);
     Uint32 length = strlen((const char*)theCString);  
  
           for(Uint32 i = 0; i < inst.hdr->numberUserKeyBindings; i++)
     // The start index is 1, because the at index 0 is a place holder for  
     // the user defined qualifier name which is not part of the qualifier name  
     // list.  
     for (Uint32 i = 1; i < _NUM_QUALIFIER_NAMES; i++)  
     {     {
         if (_qualifierNameStrLit[i].size == length)              if (theUserDefKBElement->value.isSet)
         {         {
             // TBD: Make it more efficent...                  // only references can be a key binding.
             if(String::equalNoCase(                  if (theUserDefKBElement->type == CIMTYPE_REFERENCE)
                 theCIMName.getString(),  
                 _qualifierNameStrLit[i].str))  
             {             {
                 return (QualifierNameEnum)i;                     _deleteExternalReferenceInternal(
             }                         inst.mem,
                          theUserDefKBElement->value.data.extRefPtr);
         }         }
     }     }
  
     return QUALNAME_USERDEFINED;              theUserDefKBElement =
                   (SCMBUserKeyBindingElement*)
                        &(inst.base[theUserDefKBElement->nextElement.start]);
           } // for all user def. key bindings.
       }
 } }
  
 Boolean SCMOClass::_isSamePropOrigin(Uint32 node, const char* origin) const  SCMO_RC SCMOInstance::getCIMInstance(CIMInstance& cimInstance) const
 { {
    Uint32 len = strlen(origin);  
  
    SCMBClassPropertyNode* nodeArray =      SCMO_RC rc = SCMO_OK;
        (SCMBClassPropertyNode*)      CIMObjectPath objPath;
            &(cls.base[cls.hdr->propertySet.nodeArray.start]);  
  
    return(_equalUTF8Strings(      // For better usability define pointers to SCMO Class data structures.
        nodeArray[node].theProperty.originClassName,      SCMBClass_Main* clshdr = inst.hdr->theClass.ptr->cls.hdr;
        cls.base,      char* clsbase = inst.hdr->theClass.ptr->cls.base;
        origin,  
        len));  
 }  
  
 inline SCMO_RC SCMOClass::_isNodeSameType(      getCIMObjectPath(objPath);
     Uint32 node,  
     CIMType type,      CIMInstance newInstance;
     Boolean isArray) const      newInstance._rep = new CIMInstanceRep(objPath);
   
       if (inst.hdr->flags.includeQualifiers)
 { {
     SCMBClassPropertyNode* nodeArray =          SCMBQualifier* qualiArray =
         (SCMBClassPropertyNode*)              (SCMBQualifier*)&(clsbase[clshdr->qualifierArray.start]);
             &(cls.base[cls.hdr->propertySet.nodeArray.start]);  
  
  
     if(nodeArray[node].theProperty.defaultValue.valueType != type)          CIMQualifier theCimQualifier;
           Uint32 i, k = clshdr->numberOfQualifiers;
   
           for ( i = 0 ; i < k ; i++)
     {     {
         return SCMO_WRONG_TYPE;              SCMOClass::_getCIMQualifierFromSCMBQualifier(
                   theCimQualifier,
                   qualiArray[i],
                   clsbase);
   
               newInstance._rep->_qualifiers.addUnchecked(theCimQualifier);
           }
     }     }
  
     if (isArray)      if (inst.hdr->flags.exportSetOnly)
     {     {
         if (nodeArray[node].theProperty.defaultValue.flags.isArray)          for(Uint32 i = 0, k = inst.hdr->numberProperties; i<k; i++)
         {         {
             return SCMO_OK;              SCMBValue* theInstPropArray =
                   (SCMBValue*)&(inst.base[inst.hdr->propertyArray.start]);
   
               // was the property set by the provider ?
               if(theInstPropArray[i].flags.isSet)
               {
                   // no filtering. Counter is node index
                   CIMProperty theProperty=_getCIMPropertyAtNodeIndex(i);
   
                   newInstance._rep->_properties.append(theProperty);
               }
           }
         }         }
         else         else
         {         {
             return SCMO_NOT_AN_ARRAY;          for(Uint32 i = 0, k = inst.hdr->numberProperties; i<k; i++)
         }          {
               // Set all properties in the CIMInstance gegarding they
               // are part of the SCMOInstance or the SCMOClass.
               CIMProperty theProperty=_getCIMPropertyAtNodeIndex(i);
  
               newInstance._rep->_properties.append(theProperty);
     }     }
   
     if (nodeArray[node].theProperty.defaultValue.flags.isArray)  
     {  
         return SCMO_IS_AN_ARRAY;  
     }     }
  
     return SCMO_OK;      cimInstance = newInstance;
  
       return rc;
 } }
 /*****************************************************************************  
  * The SCMOInstance methods  
  *****************************************************************************/  
  
 SCMOInstance::SCMOInstance()  void SCMOInstance::getCIMObjectPath(CIMObjectPath& cimObj) const
 { {
     inst.base = NULL;      Array<CIMKeyBinding> keys;
 }  
  
 SCMOInstance::SCMOInstance(SCMOClass baseClass)      // For better usability define pointers to SCMO Class data structures.
 {      SCMBClass_Main* clshdr = inst.hdr->theClass.ptr->cls.hdr;
     _initSCMOInstance(new SCMOClass(baseClass),false,false);      char* clsbase = inst.hdr->theClass.ptr->cls.base;
 }  
  
 SCMOInstance::SCMOInstance(      // Address the class keybinding information
     SCMOClass baseClass,      SCMBKeyBindingNode* scmoClassArray =
     Boolean includeQualifiers,          (SCMBKeyBindingNode*)&(clsbase[clshdr->keyBindingSet.nodeArray.start]);
     Boolean includeClassOrigin,  
     const char** propertyList)  
 {  
  
     _initSCMOInstance(      // Address the instance keybinding information
         new SCMOClass(baseClass),      SCMBKeyBindingValue* scmoInstArray =
         includeQualifiers,          (SCMBKeyBindingValue*)&(inst.base[inst.hdr->keyBindingArray.start]);
         includeClassOrigin);  
  
     setPropertyFilter(propertyList);      Uint32 numberKeyBindings = inst.hdr->numberKeyBindings;
  
 }      CIMValue theKeyBindingValue;
  
 Boolean SCMOInstance::isSame(SCMOInstance& theInstance) const      for (Uint32 i = 0; i < numberKeyBindings; i ++)
 { {
     return inst.base == theInstance.inst.base;          if (scmoInstArray[i].isSet)
 }  
   
 const char* SCMOInstance::getHostName() const  
 { {
   return _getCharString(inst.hdr->hostName,inst.base);              _getCIMValueFromSCMBUnion(
                   theKeyBindingValue,
                   scmoClassArray[i].type,
                   false, // can never be a null value
                   false, // can never be an array
                   0,
                   scmoInstArray[i].data,
                   inst.base);
               keys.append(
                   CIMKeyBinding(
                       CIMNameCast(_newCimString(scmoClassArray[i].name,clsbase)),
                       theKeyBindingValue
                       ));
           }
 } }
  
 void SCMOInstance::setHostName(const char* hostName)      // Are there user defined key bindings ?
       if (0 != inst.hdr->numberUserKeyBindings)
 { {
     Uint32 len;          SCMBUserKeyBindingElement* theUserDefKBElement =
               (SCMBUserKeyBindingElement*)
                    &(inst.base[inst.hdr->userKeyBindingElement.start]);
  
     if (hostName!=NULL)          for(Uint32 i = 0; i < inst.hdr->numberUserKeyBindings; i++)
     {     {
               if (theUserDefKBElement->value.isSet)
         len = strlen((const char*)hostName);  
         if(len != 0)  
         {         {
                   _getCIMValueFromSCMBUnion(
                       theKeyBindingValue,
                       theUserDefKBElement->type,
                       false, // can never be a null value
                       false, // can never be an array
                       0,
                       theUserDefKBElement->value.data,
                       inst.base);
  
             // copy including trailing '\0'                  keys.append(
             _setBinary(hostName,len+1,inst.hdr->hostName,&inst.mem);                      CIMKeyBinding(
             return;                          CIMNameCast(
         }                              _newCimString(theUserDefKBElement->name,inst.base)),
                       theKeyBindingValue));
     }  
     inst.hdr->hostName.start=0;  
     inst.hdr->hostName.length=0;  
 } }
               theUserDefKBElement =
 const char* SCMOInstance::getClassName() const                  (SCMBUserKeyBindingElement*)
 {                       &(inst.base[theUserDefKBElement->nextElement.start]);
     return _getCharString(          } // for all user def. key bindings.
         inst.hdr->theClass->cls.hdr->className,  
         inst.hdr->theClass->cls.base);  
 } }
  
 const char* SCMOInstance::getNameSpace() const      String host = _newCimString(inst.hdr->hostName,inst.base);
 {  
     return _getCharString(  
         inst.hdr->theClass->cls.hdr->nameSpace,  
         inst.hdr->theClass->cls.base);  
 }  
  
 void SCMOInstance::_initSCMOInstance(      // Use name space and class name of the instance
     SCMOClass* pClass,      CIMNamespaceName nameSpace =
     Boolean inclQual,          CIMNamespaceNameCast(_newCimString(inst.hdr->instNameSpace,inst.base));
     Boolean inclOrigin)  
 {  
     PEGASUS_ASSERT(SCMB_INITIAL_MEMORY_CHUNK_SIZE  
         - sizeof(SCMBInstance_Main)>0);  
  
       CIMName className =
           CIMNameCast(_newCimString(inst.hdr->instClassName,inst.base));
  
     inst.base = (char*)malloc(SCMB_INITIAL_MEMORY_CHUNK_SIZE);      cimObj.set(host,nameSpace,className,keys);
     if (inst.base == NULL)  
     {  
         // Not enough memory!  
         throw PEGASUS_STD(bad_alloc)();  
     }     }
  
     // initalize eye catcher  CIMProperty SCMOInstance::_getCIMPropertyAtNodeIndex(Uint32 nodeIdx) const
     inst.hdr->header.magic=PEGASUS_SCMB_INSTANCE_MAGIC;  {
     inst.hdr->header.totalSize=SCMB_INITIAL_MEMORY_CHUNK_SIZE;      CIMValue theValue;
     // The # of bytes free      CIMProperty retProperty;
     inst.hdr->header.freeBytes=  
         SCMB_INITIAL_MEMORY_CHUNK_SIZE-sizeof(SCMBInstance_Main);  
     // Index to the start of the free space in this instance  
     inst.hdr->header.startOfFreeSpace=sizeof(SCMBInstance_Main);  
   
     inst.hdr->refCount=1;  
   
     //Assign the SCMBClass structure this instance based on.  
     inst.hdr->theClass = pClass;  
   
     // Init flags  
     inst.hdr->flags.includeQualifiers=inclQual;  
     inst.hdr->flags.includeClassOrigin=inclOrigin;  
     inst.hdr->flags.isFiltered=false;  
   
     inst.hdr->hostName.start=0;  
     inst.hdr->hostName.length=0;  
   
     // Number of key bindings  
     inst.hdr->numberKeyBindings =  
         inst.hdr->theClass->cls.hdr->keyBindingSet.number;  
   
     // Number of properties  
     inst.hdr->numberProperties =  
         inst.hdr->theClass->cls.hdr->propertySet.number;  
   
     // Allocate the SCMOInstanceKeyBindingArray  
     _getFreeSpace(  
           inst.hdr->keyBindingArray,  
           sizeof(SCMBDataPtr)*inst.hdr->numberKeyBindings,  
           &inst.mem,  
           true);  
   
     // Allocate the SCMBInstancePropertyArray  
     _getFreeSpace(  
         inst.hdr->propertyArray,  
         sizeof(SCMBValue)*inst.hdr->numberProperties,  
         &inst.mem,  
         true);  
   
     inst.hdr->propertyFilter.start=0;  
     inst.hdr->propertyFilter.length=0;  
     inst.hdr->propertyFilterIndexMap.start=0;  
     inst.hdr->propertyFilterIndexMap.length=0;  
  
       // For better usability define pointers to SCMO Class data structures.
       SCMBClass_Main* clshdr = inst.hdr->theClass.ptr->cls.hdr;
       char* clsbase = inst.hdr->theClass.ptr->cls.base;
  
 }  
  
 SCMO_RC SCMOInstance::getProperty(      SCMBClassPropertyNode& clsProp =
     const char* name,          ((SCMBClassPropertyNode*)
     CIMType& type,           &(clsbase[clshdr->propertySet.nodeArray.start]))[nodeIdx];
     const void** pvalue,  
     Boolean& isArray,  
     Uint32& size ) const  
 {  
     Uint32 node;  
     const char* pname;  
     SCMO_RC rc = SCMO_OK;  
  
     *pvalue = NULL;      SCMBValue& instValue =
     isArray = false;          ((SCMBValue*)&(inst.base[inst.hdr->propertyArray.start]))[nodeIdx];
     size = 0;  
  
     rc = inst.hdr->theClass->_getProperyNodeIndex(node,name);      if (instValue.flags.isSet)
     if (rc != SCMO_OK)  
     {     {
         return rc;          _getCIMValueFromSCMBValue(theValue,instValue,inst.base);
     }     }
       else
     // is filtering on ?  
     if (inst.hdr->flags.isFiltered)  
     {  
         // Is the property NOT in the property filter ?  
         if(!_isPropertyInFilter(node))  
         {         {
             // The named propery is not part of this instance          _getCIMValueFromSCMBValue(
             // due to filtering.              theValue,
             return SCMO_NOT_FOUND;              clsProp.theProperty.defaultValue,
         }              clsbase);
     }     }
  
     return  _getPropertyAtNodeIndex(node,&pname,type,pvalue,isArray,size);  
 }  
  
 SCMO_RC SCMOInstance::getPropertyAt(  
         Uint32 idx,  
         const char** pname,  
         CIMType& type,  
         const void** pvalue,  
         Boolean& isArray,  
         Uint32& size ) const  
 {  
     *pname = NULL;  
     *pvalue = NULL;  
     isArray = false;  
     size = 0;  
     Uint32 node;  
  
     // is filtering on ?      if (inst.hdr->flags.includeClassOrigin)
     if (inst.hdr->flags.isFiltered)  
     {     {
         // check the number of properties part of the filter          retProperty = CIMProperty(
         if (idx >= inst.hdr->filterProperties)              CIMNameCast(_newCimString(clsProp.theProperty.name,clsbase)),
         {              theValue,
             return SCMO_INDEX_OUT_OF_BOUND;              theValue.getArraySize(),
         }              CIMNameCast(
                   _newCimString(clsProp.theProperty.refClassName,clsbase)),
         // Get absolut pointer to property filter index map of the instance              CIMNameCast(
         Uint32* propertyFilterIndexMap =                  _newCimString(clsProp.theProperty.originClassName,clsbase)),
         (Uint32*)&(inst.base[inst.hdr->propertyFilterIndexMap.start]);              clsProp.theProperty.flags.propagated);
   
         // get the real node index of the property.  
         node = propertyFilterIndexMap[idx];  
     }     }
     else     else
     {     {
         // the index is used as node index.           retProperty = CIMProperty(
         node = idx;              CIMNameCast(_newCimString(clsProp.theProperty.name,clsbase)),
         if (node >= inst.hdr->numberProperties)              theValue,
         {              theValue.getArraySize(),
             return SCMO_INDEX_OUT_OF_BOUND;              CIMNameCast(
                   _newCimString(clsProp.theProperty.refClassName,clsbase)),
               CIMName(),
               clsProp.theProperty.flags.propagated);
       }
   
       if (inst.hdr->flags.includeQualifiers)
       {
           SCMBQualifier* qualiArray =
               (SCMBQualifier*)
                    &(clsbase[clsProp.theProperty.qualifierArray.start]);
   
           CIMQualifier theCimQualifier;
   
           Uint32 i, k = clsProp.theProperty.numberOfQualifiers;
           for ( i = 0 ; i < k ; i++)
           {
               SCMOClass::_getCIMQualifierFromSCMBQualifier(
                   theCimQualifier,
                   qualiArray[i],
                   clsbase);
   
               retProperty._rep->_qualifiers.addUnchecked(theCimQualifier);
         }         }
     }     }
  
     return  _getPropertyAtNodeIndex(node,pname,type,pvalue,isArray,size);      return retProperty;
 } }
  
 SCMO_RC SCMOInstance::getPropertyNodeIndex(const char* name, Uint32& node) const  void SCMOInstance::_getCIMValueFromSCMBUnion(
 {      CIMValue& cimV,
     SCMO_RC rc;      const CIMType type,
     if(name==NULL)      const Boolean isNull,
       const Boolean isArray,
       const Uint32 arraySize,
       const SCMBUnion& scmbUn,
       const char * base)
     {     {
         return SCMO_INVALID_PARAMETER;  
     }  
   
     rc = inst.hdr->theClass->_getProperyNodeIndex(node,name);  
  
     return rc;      const SCMBUnion* pscmbArrayUn = 0;
  
 }      if (isNull)
 SCMO_RC SCMOInstance::setPropertyWithOrigin(  
     const char* name,  
     CIMType type,  
     void* value,  
     Boolean isArray,  
     Uint32 size,  
     const char* origin)  
 { {
     Uint32 node;          cimV.setNullValue(type,isArray,arraySize);
     SCMO_RC rc;          return;
       }
  
     rc = inst.hdr->theClass->_getProperyNodeIndex(node,name);      if (isArray)
     if (rc != SCMO_OK)  
     {     {
         return rc;          pscmbArrayUn =(SCMBUnion*)&(base[scmbUn.arrayValue.start]);
     }     }
  
     // Is the traget type OK ?      switch (type)
     rc = inst.hdr->theClass->_isNodeSameType(node,type,isArray);  
     if (rc != SCMO_OK)  
     {     {
         return rc;  
     }  
  
     // is filtering on ?      case CIMTYPE_UINT8:
     if (inst.hdr->flags.isFiltered)          {
               if (isArray)
     {     {
         // Is the property NOT in the property filter ?                  Array<Uint8> x;
         if(!_isPropertyInFilter(node))                  for (Uint32 i = 0, k = arraySize; i < k ; i++)
         {         {
             // The named propery is not part of this instance                      x.append(pscmbArrayUn[i].simple.val.u8);
             // due to filtering.  
             return SCMO_NOT_FOUND;  
         }         }
                   cimV.set(x);
     }     }
               else
     // check class origin if set.  
     if (origin!= NULL)  
     {  
         if(!inst.hdr->theClass->_isSamePropOrigin(node,origin))  
         {         {
             return SCMO_NOT_SAME_ORIGIN;                  cimV.set(scmbUn.simple.val.u8);
         }  
     }     }
               break;
   
     _setPropertyAtNodeIndex(node,type,value,isArray,size);  
   
     return SCMO_OK;  
 } }
  
  SCMO_RC SCMOInstance::setPropertyWithNodeIndex(      case CIMTYPE_UINT16:
      Uint32 node,  
      CIMType type,  
      void* value,  
      Boolean isArray,  
      Uint32 size)  
  {  
      SCMO_RC rc;  
   
      if (node >= inst.hdr->numberProperties)  
      {      {
          return SCMO_INDEX_OUT_OF_BOUND;              if (isArray)
      }  
   
      // is filtering on ?  
      if (inst.hdr->flags.isFiltered)  
      {      {
          // Is the property NOT in the property filter ?                  Array<Uint16> x;
          if(!_isPropertyInFilter(node))                  for (Uint32 i = 0, k = arraySize; i < k ; i++)
          {          {
              // The proptery of the is not set due to filtering.                      x.append(pscmbArrayUn[i].simple.val.u16);
              return SCMO_OK;  
          }          }
                   cimV.set(x);
      }      }
               else
      // Is the traget type OK ?  
      rc = inst.hdr->theClass->_isNodeSameType(node,type,isArray);  
      if (rc != SCMO_OK)  
      {      {
          return rc;                  cimV.set(scmbUn.simple.val.u16);
      }      }
               break;
      _setPropertyAtNodeIndex(node,type,value,isArray,size);  
   
      return SCMO_OK;  
  }  }
  
 void SCMOInstance::_setPropertyAtNodeIndex(      case CIMTYPE_UINT32:
     Uint32 node,  
     CIMType type,  
     void* value,  
     Boolean isArray,  
     Uint32 size)  
 { {
     SCMBValue* theInstPropNodeArray =  
         (SCMBValue*)&inst.base[inst.hdr->propertyArray.start];  
   
   
     theInstPropNodeArray[node].flags.isSet=true;  
     theInstPropNodeArray[node].valueType=type;  
     theInstPropNodeArray[node].flags.isArray=isArray;  
     if (isArray)     if (isArray)
     {     {
         theInstPropNodeArray[node].valueArraySize=size;                  Array<Uint32> x;
     }                  for (Uint32 i = 0, k = arraySize; i < k ; i++)
   
     if (value==NULL)  
     {     {
         theInstPropNodeArray[node].flags.isNull=true;                      x.append(pscmbArrayUn[i].simple.val.u32);
                   }
                   cimV.set(x);
     }     }
     else     else
     {     {
         Uint64 start =                  cimV.set(scmbUn.simple.val.u32);
             (const char*)&(theInstPropNodeArray[node].value)-inst.base;  
   
         _setSCMBUnion(value,type,isArray,size,start);  
     }     }
               break;
 } }
  
 void SCMOInstance::_setSCMBUnion(      case CIMTYPE_UINT64:
     void* value,  
     CIMType type,  
     Boolean isArray,  
     Uint32 size,  
     Uint64 start)  
 {  
     SCMBUnion* u = (SCMBUnion*)&(inst.base[start]);  
   
     switch (type)  
     {  
     case CIMTYPE_BOOLEAN:  
         {         {
             if (isArray)             if (isArray)
             {             {
                 _setBinary(value,size*sizeof(Boolean),                  Array<Uint64> x;
                            u->_arrayValue,                  for (Uint32 i = 0, k = arraySize; i < k ; i++)
                            &inst.mem );                  {
                       x.append(pscmbArrayUn[i].simple.val.u64);
                   }
                   cimV.set(x);
             }             }
             else             else
             {             {
                 u->_booleanValue = *((Boolean*)value);                  cimV.set(scmbUn.simple.val.u64);
             }             }
             break;             break;
         }         }
  
     case CIMTYPE_UINT8:      case CIMTYPE_SINT8:
         {         {
             if (isArray)             if (isArray)
             {             {
                 _setBinary(value,size*sizeof(Uint8),                  Array<Sint8> x;
                            u->_arrayValue,                  for (Uint32 i = 0, k = arraySize; i < k ; i++)
                            &inst.mem );                  {
                       x.append(pscmbArrayUn[i].simple.val.s8);
                   }
                   cimV.set(x);
             }             }
             else             else
             {             {
                 u->_uint8Value = *((Uint8*)value);                  cimV.set(scmbUn.simple.val.s8);
             }             }
             break;             break;
         }         }
  
     case CIMTYPE_SINT8:      case CIMTYPE_SINT16:
         {         {
             if (isArray)             if (isArray)
             {             {
                 _setBinary(value,size*sizeof(Sint8),                  Array<Sint16> x;
                            u->_arrayValue,                  for (Uint32 i = 0, k = arraySize; i < k ; i++)
                            &inst.mem );                  {
                       x.append(pscmbArrayUn[i].simple.val.s16);
                   }
                   cimV.set(x);
             }             }
             else             else
             {             {
                 u->_sint8Value = *((Sint8*)value);                  cimV.set(scmbUn.simple.val.s16);
             }             }
             break;             break;
         }         }
  
     case CIMTYPE_UINT16:      case CIMTYPE_SINT32:
         {         {
             if (isArray)             if (isArray)
             {             {
                 _setBinary(value,size*sizeof(Uint16),                  Array<Sint32> x;
                            u->_arrayValue,                  for (Uint32 i = 0, k = arraySize; i < k ; i++)
                            &inst.mem );                  {
                       x.append(pscmbArrayUn[i].simple.val.s32);
                   }
                   cimV.set(x);
             }             }
             else             else
             {             {
                 u->_uint16Value = *((Uint16*)value);                  cimV.set(scmbUn.simple.val.s32);
             }             }
             break;             break;
         }         }
  
     case CIMTYPE_SINT16:      case CIMTYPE_SINT64:
         {         {
             if (isArray)             if (isArray)
             {             {
                 _setBinary(value,size*sizeof(Sint16),                  Array<Sint64> x;
                            u->_arrayValue,                  for (Uint32 i = 0, k = arraySize; i < k ; i++)
                            &inst.mem );                  {
                       x.append(pscmbArrayUn[i].simple.val.s64);
                   }
                   cimV.set(x);
             }             }
             else             else
             {             {
                 u->_sint16Value = *((Sint16*)value);                  cimV.set(scmbUn.simple.val.s64);
             }             }
             break;             break;
         }         }
  
     case CIMTYPE_UINT32:      case CIMTYPE_REAL32:
         {         {
             if (isArray)             if (isArray)
             {             {
                 _setBinary(value,size*sizeof(Uint32),                  Array<Real32> x;
                            u->_arrayValue,                  for (Uint32 i = 0, k = arraySize; i < k ; i++)
                            &inst.mem );                  {
                       x.append(pscmbArrayUn[i].simple.val.r32);
                   }
                   cimV.set(x);
             }             }
             else             else
             {             {
                 u->_uint32Value = *((Uint32*)value);                  cimV.set(scmbUn.simple.val.r32);
             }             }
             break;             break;
         }         }
  
     case CIMTYPE_SINT32:      case CIMTYPE_REAL64:
         {         {
             if (isArray)             if (isArray)
             {             {
                 _setBinary(value,size*sizeof(Sint32),                  Array<Real64> x;
                            u->_arrayValue,                  for (Uint32 i = 0, k = arraySize; i < k ; i++)
                            &inst.mem );                  {
                       x.append(pscmbArrayUn[i].simple.val.r64);
                   }
                   cimV.set(x);
             }             }
             else             else
             {             {
                 u->_sint32Value = *((Sint32*)value);                  cimV.set(scmbUn.simple.val.r64);
             }             }
             break;             break;
         }         }
  
     case CIMTYPE_UINT64:      case CIMTYPE_CHAR16:
         {         {
             if (isArray)             if (isArray)
             {             {
                 _setBinary(value,size*sizeof(Uint64),                  Array<Char16> x;
                            u->_arrayValue,                  for (Uint32 i = 0, k = arraySize; i < k ; i++)
                            &inst.mem );                  {
                       x.append(Char16(pscmbArrayUn[i].simple.val.c16));
                   }
                   cimV.set(x);
             }             }
             else             else
             {             {
                 u->_uint64Value = *((Uint64*)value);                  cimV.set(Char16(scmbUn.simple.val.c16));
             }             }
             break;             break;
         }         }
  
     case CIMTYPE_SINT64:      case CIMTYPE_BOOLEAN:
         {         {
             if (isArray)             if (isArray)
             {             {
                 _setBinary(value,size*sizeof(Sint64),                  Array<Boolean> x;
                            u->_arrayValue,                  for (Uint32 i = 0, k = arraySize; i < k ; i++)
                            &inst.mem );                  {
                       x.append(pscmbArrayUn[i].simple.val.bin);
                   }
                   cimV.set(x);
             }             }
             else             else
             {             {
                 u->_sint64Value = *((Sint64*)value);                  cimV.set(scmbUn.simple.val.bin);
             }             }
             break;             break;
         }         }
  
     case CIMTYPE_REAL32:      case CIMTYPE_STRING:
         {         {
             if (isArray)             if (isArray)
             {             {
                 _setBinary(value,size*sizeof(Real32),  
                            u->_arrayValue,                  Array<String> x;
                            &inst.mem );  
                   for (Uint32 i = 0, k = arraySize; i < k ; i++)
                   {
                       x.append(_newCimString(pscmbArrayUn[i].stringValue,base));
                   }
                   cimV.set(x);
             }             }
             else             else
             {             {
                 u->_real32Value = *((Real32*)value);                  cimV.set(_newCimString(scmbUn.stringValue,base));
             }             }
             break;             break;
         }         }
  
     case CIMTYPE_REAL64:      case CIMTYPE_DATETIME:
         {         {
             if (isArray)             if (isArray)
             {             {
                 _setBinary(value,size*sizeof(Real64),                  Array<CIMDateTime> x;
                            u->_arrayValue,  
                            &inst.mem );                  for (Uint32 i = 0, k = arraySize; i < k ; i++)
                   {
                       x.append(CIMDateTime(&(pscmbArrayUn[i].dateTimeValue)));
                   }
                   cimV.set(x);
             }             }
             else             else
             {             {
                 u->_real64Value = *((Real64*)value);                  cimV.set(CIMDateTime(&scmbUn.dateTimeValue));
             }             }
             break;             break;
   
         }         }
  
     case CIMTYPE_CHAR16:      case CIMTYPE_REFERENCE:
         {         {
               CIMObjectPath theObjPath;
   
             if (isArray)             if (isArray)
             {             {
                 _setBinary(value,size*sizeof(Char16),                  Array<CIMObjectPath> x;
                            u->_arrayValue,                  for (Uint32 i = 0, k = arraySize; i < k ; i++)
                            &inst.mem );                  {
                       if (0 != pscmbArrayUn[i].extRefPtr)
                       {
                           pscmbArrayUn[i].extRefPtr->getCIMObjectPath(theObjPath);
                           x.append(theObjPath);
             }             }
             else             else
             {             {
                 u->_char16Value = *((Char16*)value);                          // set an empty object
                           x.append(CIMObjectPath());
             }             }
             break;  
         }         }
                   cimV.set(x);
               }
               else
               {
  
     case CIMTYPE_DATETIME:                  if (0 != scmbUn.extRefPtr)
                   {
                       scmbUn.extRefPtr->getCIMObjectPath(theObjPath);
                       cimV.set(theObjPath);
                   }
                   else
                   {
                       cimV.set(CIMObjectPath());
                   }
               }
               break;
           }
       case CIMTYPE_OBJECT:
         {         {
               CIMInstance cimInstance;
               CIMClass cimClass;
   
             if (isArray)             if (isArray)
             {             {
                 _setBinary(value,size*sizeof(SCMBDateTime),                  Array<CIMObject> x;
                            u->_arrayValue,                  for (Uint32 i = 0, k = arraySize; i < k ; i++)
                            &inst.mem );                  {
                       if (0 != pscmbArrayUn[i].extRefPtr)
                       {
                           // check if the Object is an emedded instance or class
                           if(pscmbArrayUn[i].extRefPtr->
                                  inst.hdr->flags.isClassOnly)
                           {
                               pscmbArrayUn[i].extRefPtr->
                                   inst.hdr->theClass.ptr->getCIMClass(cimClass);
                               x.append(CIMObject(cimClass));
             }             }
             else             else
             {             {
                 u->_dateTimeValue = *((SCMBDateTime*)value);                              pscmbArrayUn[i].extRefPtr->
                                   getCIMInstance(cimInstance);
                               x.append(CIMObject(cimInstance));
             }             }
             break;  
         }         }
                       else
                       {
                           // set an empty object
                           x.append(CIMObject());
                       }
                   }
                   cimV.set(x);
               }
               else
               {
  
     case CIMTYPE_STRING:                  if (0 != scmbUn.extRefPtr)
         {         {
             if (isArray)                      // check if the Object is an emedded instance or class
                       if(scmbUn.extRefPtr->inst.hdr->flags.isClassOnly)
             {             {
                 SCMBDataPtr* ptr;                          scmbUn.extRefPtr->
                 char** tmp;                              inst.hdr->theClass.ptr->getCIMClass(cimClass);
                 Uint64 startPtr;                          cimV.set(CIMObject(cimClass));
                       }
                       else
                       {
                           scmbUn.extRefPtr->getCIMInstance(cimInstance);
                           cimV.set(CIMObject(cimInstance));
                       }
                   }
                   else
                   {
                       cimV.set(CIMObject());
                   }
               }
               break;
           }
  
                 startPtr = _getFreeSpace(      case CIMTYPE_INSTANCE:
                     u->_arrayValue,          {
                     size*sizeof(SCMBDataPtr),              CIMInstance theInstance;
                     &inst.mem,false);  
                 // the value is pointer to an array of char*  
                 tmp = (char**)value;  
  
                 for (Uint32 i = 0; i < size; i++)              if(isArray)
                 {                 {
                     ptr = (SCMBDataPtr*)&(inst.base[startPtr]);                  Array<CIMInstance> x;
                     // Copy the sting including the trailing '\0'                  for (Uint32 i = 0, k = arraySize; i < k ; i++)
                     _setBinary(tmp[i],strlen(tmp[i])+1,ptr[i],&inst.mem );                  {
                       if (0 != pscmbArrayUn[i].extRefPtr)
                       {
                           pscmbArrayUn[i].extRefPtr->
                               getCIMInstance(theInstance);
                           x.append(theInstance);
                       }
                       else
                       {
                           // set an empty object
                           x.append(CIMInstance());
                 }                 }
             }             }
                   cimV.set(x);
               }
             else             else
             {             {
                 // Copy the sting including the trailing '\0'  
                 _setBinary(                  if (0 != scmbUn.extRefPtr)
                     value,                  {
                     strlen((char*)value)+1,                      scmbUn.extRefPtr->getCIMInstance(theInstance);
                     u->_stringValue,                      cimV.set(theInstance);
                     &inst.mem );                  }
                   else
                   {
                       cimV.set(CIMInstance());
                   }
               }
               break;
             }             }
       default:
           {
               PEGASUS_ASSERT(false);
             break;             break;
         }         }
       }
   }
  
         case CIMTYPE_REFERENCE:  void SCMOInstance::_getCIMValueFromSCMBValue(
       CIMValue& cimV,
       const SCMBValue& scmbV,
       const char * base)
   {
       SCMOInstance::_getCIMValueFromSCMBUnion(
           cimV,
           scmbV.valueType,
           scmbV.flags.isNull,
           scmbV.flags.isArray,
           scmbV.valueArraySize,
           scmbV.value,
           base);
   }
  
             break;  
  
         case CIMTYPE_OBJECT:  void SCMOInstance::_setCIMObjectPath(const CIMObjectPath& cimObj)
   {
       CString className = cimObj.getClassName().getString().getCString();
  
             break;      // Is the instance from the same class ?
         case CIMTYPE_INSTANCE:      if (!(_equalNoCaseUTF8Strings(
                inst.hdr->instClassName,
                inst.base,
                (const char*)className,
                strlen(className))))
       {
           throw PEGASUS_CIM_EXCEPTION(CIM_ERR_INVALID_CLASS,
              cimObj.getClassName().getString());
       }
  
             break;      //set host name
       _setString(cimObj.getHost(),inst.hdr->hostName,&inst.mem );
   
       const Array<CIMKeyBinding> & keys=cimObj.getKeyBindings();
       for (Uint32 i = 0, k = keys.size(); i < k; i++)
       {
           String key = keys[i].getValue();
           _setKeyBindingFromString(
               (const char*) keys[i].getName().getString().getCString(),
               _CIMTypeFromKeyBindingType(
                   (const char*)key.getCString(),
                   keys[i].getType()),
               key);
     }     }
 } }
  
 SCMO_RC SCMOInstance::_getPropertyAtNodeIndex(  void SCMOInstance::_setCIMValueAtNodeIndex(
         Uint32 node,         Uint32 node,
         const char** pname,      CIMValueRep* valRep,
         CIMType& type,      CIMType realType)
         const void** pvalue,  
         Boolean& isArray,  
         Uint32& size ) const  
 { {
     SCMBValue* theInstPropNodeArray =     SCMBValue* theInstPropNodeArray =
         (SCMBValue*)&inst.base[inst.hdr->propertyArray.start];          (SCMBValue*)&(inst.base[inst.hdr->propertyArray.start]);
  
     // create a pointer to property node array of the class.  
     Uint64 idx = inst.hdr->theClass->cls.hdr->propertySet.nodeArray.start;  
     SCMBClassPropertyNode* theClassPropNodeArray =  
         (SCMBClassPropertyNode*)&(inst.hdr->theClass->cls.base)[idx];  
  
     // the property name is always from the class.      SCMBValue& theInstProp = theInstPropNodeArray[node];
     // return the absolut pointer to the property name,  
     // the caller has to copy the name!  
     *pname=_getCharString(  
         theClassPropNodeArray[node].theProperty.name,  
         inst.hdr->theClass->cls.base);  
  
     // the property was set by the provider.      theInstProp.valueType=realType;
     if (theInstPropNodeArray[node].flags.isSet)      theInstProp.flags.isNull=valRep->isNull;
       theInstProp.flags.isArray=valRep->isArray;
       theInstProp.flags.isSet=true;
       theInstProp.valueArraySize=0;
   
       if (valRep->isNull)
     {     {
           return;
       }
  
         type = theInstPropNodeArray[node].valueType;      Uint64 start = ((const char*)&(theInstProp.value))-inst.base;
         isArray = theInstPropNodeArray[node].flags.isArray;  
         if (isArray)      if (valRep->isArray)
         {         {
             size = theInstPropNodeArray[node].valueArraySize;          _setUnionArrayValue(
               start,
               &inst.mem,
               realType,
               // Is set to the number of array members by the function.
               theInstProp.valueArraySize,
               inst.hdr->instNameSpace.start,
               inst.hdr->instNameSpace.size,
               valRep->u);
       }
       else
       {
           _setUnionValue(
               start,
               &inst.mem,
               realType,
               inst.hdr->instNameSpace.start,
               inst.hdr->instNameSpace.size,
               valRep->u);
       }
         }         }
  
         if (theInstPropNodeArray[node].flags.isNull)  
   Boolean SCMOInstance::isSame(SCMOInstance& theInstance) const
         {         {
             return SCMO_NULL_VALUE;      return inst.base == theInstance.inst.base;
         }         }
  
         // calculate the relative index for the value.  void SCMOInstance::setHostName(const char* hostName)
         Uint64 start =  {
             (const char*)&(theInstPropNodeArray[node].value) -      Uint32 len = 0;
             inst.base;  
  
         // the caller has to copy the value !      _copyOnWrite();
         *pvalue = _getSCMBUnion(type,isArray,size,start,inst.base);  
  
         return SCMO_OK;      if (hostName!=0)
       {
   
           len = strlen((const char*)hostName);
       }
       // copy including trailing '\0'
       _setBinary(hostName,len+1,inst.hdr->hostName,&inst.mem);
     }     }
  
     // the get the defaults out of the class.  const char* SCMOInstance::getHostName() const
     type = theClassPropNodeArray[node].theProperty.defaultValue.valueType;  
     isArray =  
         theClassPropNodeArray[node].theProperty.defaultValue.flags.isArray;  
     if (isArray)  
     {     {
         size = theClassPropNodeArray[node].      return _getCharString(inst.hdr->hostName,inst.base);
                    theProperty.defaultValue.valueArraySize;  
     }     }
  
     if (theClassPropNodeArray[node].theProperty.defaultValue.flags.isNull)  const char* SCMOInstance::getHostName_l(Uint32& length) const
     {     {
         return SCMO_NULL_VALUE;      length = inst.hdr->hostName.size;
       if (0 == length)
       {
           return 0;
       }
       else
       {
           length--;
       }
       return _getCharString(inst.hdr->hostName,inst.base);
     }     }
  
     // calcutate the relativ start address of the value  void SCMOInstance::setClassName(const char* className)
     Uint64 start =  {
         (const char*)      Uint32 len=0;
                &(theClassPropNodeArray[node].theProperty.defaultValue.value) -  
         (inst.hdr->theClass->cls.base);  
  
     *pvalue = _getSCMBUnion(      _copyOnWrite();
         type,  
         isArray,  
         size,  
         start,  
         (inst.hdr->theClass->cls.base)  
         );  
  
     return SCMO_OK;      // flag the instance as compromized
       inst.hdr->flags.isCompromised=true;
       if (className!=0)
       {
           len = strlen((const char*)className);
       }
       // copy including trailing '\0'
       // _setBinary also sets the name to 0 if either className==0 or len+1==1
       _setBinary(className,len+1,inst.hdr->instClassName,&inst.mem);
   }
   
   void SCMOInstance::setClassName_l(const char* className, Uint32 len)
   {
       _copyOnWrite();
   
       // flag the instance as compromised
       inst.hdr->flags.isCompromised=true;
       // copy including trailing '\0'
       // _setBinary also sets the name to 0 if either className==0 or len+1==1
       _setBinary(className,len+1,inst.hdr->instClassName,&inst.mem);
   }
   
   const char* SCMOInstance::getClassName() const
   {
       return _getCharString(inst.hdr->instClassName,inst.base);
   }
   
   const char* SCMOInstance::getClassName_l(Uint32 & length) const
   {
       length = inst.hdr->instClassName.size;
       if (0 == length)
       {
           return 0;
       }
       else
       {
           length--;
       }
       return _getCharString(inst.hdr->instClassName,inst.base);
   }
   
   void SCMOInstance::setNameSpace(const char* nameSpace)
   {
       Uint32 len = 0;
   
       _copyOnWrite();
   
       // flag the instance as compromized
       inst.hdr->flags.isCompromised=true;
   
       if (nameSpace!=0)
       {
   
           len = strlen((const char*)nameSpace);
       }
       // copy including trailing '\0'
       _setBinary(nameSpace,len+1,inst.hdr->instNameSpace,&inst.mem);
   }
   
   void SCMOInstance::setNameSpace_l(const char* nameSpace, Uint32 len)
   {
       // Copy on Write is only necessary if a realloc() becomes necessary
       if (inst.mem->freeBytes < ((len+8) & ~7))
       {
           _copyOnWrite();
       }
       // flag the instance as compromized
       inst.hdr->flags.isCompromised=true;
       // copy including trailing '\0'
       _setBinary(nameSpace,len+1,inst.hdr->instNameSpace,&inst.mem);
   }
   
   const char* SCMOInstance::getNameSpace() const
   {
       return _getCharString(inst.hdr->instNameSpace,inst.base);
   }
   
   const char* SCMOInstance::getNameSpace_l(Uint32 & length) const
   {
       length = inst.hdr->instNameSpace.size;
       if (0 == length)
       {
           return 0;
       }
       else
       {
           length--;
       }
       return _getCharString(inst.hdr->instNameSpace,inst.base);
   }
   
   void SCMOInstance::completeHostNameAndNamespace(
       const char* hn,
       Uint32 hnLen,
       const char* ns,
       Uint32 nsLen)
   {
       // hostName is Null or empty String ?
       if (0 == inst.hdr->hostName.size ||
           0 == inst.base[inst.hdr->hostName.start])
       {
           // Copy on Write is only necessary if a realloc() becomes necessary
           if (inst.mem->freeBytes < ((hnLen+8) & ~7))
           {
               _copyOnWrite();
           }
           // copy including trailing '\0'
           _setBinary(hn,hnLen+1,inst.hdr->hostName,&inst.mem);
       }
       // namespace is Null or empty String ?
       if (0 == inst.hdr->instNameSpace.size ||
           0 == inst.base[inst.hdr->instNameSpace.start])
       {
           setNameSpace_l(ns,nsLen);
       }
   }
   
   
   void SCMOInstance::buildKeyBindingsFromProperties()
   {
       Uint32 propNode;
       // The theClassKeyPropList pointer will always be valid,
       // even after a realloc() caused by copyOnWrite()
       // as this is an absolute pointer to the class which does not change
       Uint32* theClassKeyPropList =
           (Uint32*) &((inst.hdr->theClass.ptr->cls.base)
                       [(inst.hdr->theClass.ptr->cls.hdr->keyIndexList.start)]);
   
       SCMBKeyBindingValue* theKeyBindValueArray =
           (SCMBKeyBindingValue*)&(inst.base[inst.hdr->keyBindingArray.start]);
       SCMBValue* theInstPropNodeArray=
           (SCMBValue*)&inst.base[inst.hdr->propertyArray.start];
   
       inst.hdr->numberKeyBindings =
           inst.hdr->theClass.ptr->cls.hdr->keyBindingSet.number;
   
       for (Uint32 i = 0, k = inst.hdr->numberKeyBindings; i < k; i++)
       {
           // If the keybinding is not set.
           if (!theKeyBindValueArray[i].isSet)
           {
               // get the node index for this key binding form class
               propNode = theClassKeyPropList[i];
   
               // if property was set by the provider and it is not null.
               if ( theInstPropNodeArray[propNode].flags.isSet &&
                   !theInstPropNodeArray[propNode].flags.isNull)
               {
                   _copyOnWrite();
                   // the instance pointers have to be recalculated as copyOnWrite
                   // might change the absolute address of these pointers
                   theInstPropNodeArray =
                       (SCMBValue*)&inst.base[inst.hdr->propertyArray.start];
                   theKeyBindValueArray =
                       (SCMBKeyBindingValue*)
                           &(inst.base[inst.hdr->keyBindingArray.start]);
   
                   _setKeyBindingFromSCMBUnion(
                       theInstPropNodeArray[propNode].valueType,
                       theInstPropNodeArray[propNode].value,
                       inst.base,
                       theKeyBindValueArray[i]);
   
                   // the instance pointers have to be reinitialized each time,
                   // because a reallocation can take place
                   // in _setKeyBindingFromSCMBUnion()
                   theKeyBindValueArray =
                       (SCMBKeyBindingValue*)
                           &(inst.base[inst.hdr->keyBindingArray.start]);
                   theInstPropNodeArray =
                       (SCMBValue*)&inst.base[inst.hdr->propertyArray.start];
   
               }
           }
       }
   }
   
   void SCMOInstance::_setKeyBindingFromSCMBUnion(
       CIMType type,
       const SCMBUnion& u,
       const char * uBase,
       SCMBKeyBindingValue& keyData)
   {
       switch (type)
       {
       case CIMTYPE_UINT8:
       case CIMTYPE_UINT16:
       case CIMTYPE_UINT32:
       case CIMTYPE_UINT64:
       case CIMTYPE_SINT8:
       case CIMTYPE_SINT16:
       case CIMTYPE_SINT32:
       case CIMTYPE_SINT64:
       case CIMTYPE_REAL32:
       case CIMTYPE_REAL64:
       case CIMTYPE_CHAR16:
       case CIMTYPE_BOOLEAN:
           {
               memcpy(&keyData.data,&u,sizeof(SCMBUnion));
               keyData.data.simple.hasValue=true;
               keyData.isSet=true;
               break;
           }
       case CIMTYPE_DATETIME:
           {
               memcpy(&keyData.data,&u,sizeof(SCMBUnion));
               keyData.isSet=true;
               break;
           }
       case CIMTYPE_STRING:
           {
               keyData.isSet=true;
               // Check if a key binding is set with in the same instance.
               // If this is the case, a reallocation can take place and the
               // uBase pointer can be invalid and cause a read in freed memory!
               if (uBase == inst.base)
               {
                   if (0 != u.stringValue.size )
                   {
                       // We are doing a in instance copy of data.
                       // We can not use the _setBinary() function because
                       // all real pointer can be in valid after
                       // the _getFreeSprace() function!
                       // We have to save all relative pointer on the stack.
                       Uint64 start;
                       SCMBDataPtr tmp;
                       tmp.size = u.stringValue.size;
                       tmp.start = u.stringValue.start;
   
                       // In this function a reallocation may take place!
                       // The keyData.data.stringValue is set
                       // before the rallocation.
                       start = _getFreeSpace(
                           keyData.data.stringValue,
                           u.stringValue.size,
                           &inst.mem);
                       // Copy the string,
                       // but using the own base pointer and the saved relative
                       // string pointer.
                       memcpy(
                           &(inst.base[start]),
                           _getCharString(tmp,inst.base),
                           tmp.size);
                   }
                   else
                   {
                      keyData.data.stringValue.size=0;
                      keyData.data.stringValue.start=0;
                   }
   
               }
               else
               {
                   _setBinary(
                       &uBase[u.stringValue.start],
                       u.stringValue.size,
                       keyData.data.stringValue,
                       &inst.mem);
               }
   
               break;
           }
       case CIMTYPE_REFERENCE:
           {
               if(0 != keyData.data.extRefPtr)
               {
                   delete keyData.data.extRefPtr;
               }
   
               if(u.extRefPtr)
               {
                   keyData.data.extRefPtr = new SCMOInstance(*u.extRefPtr);
                   keyData.isSet=true;
                   // This function can cause a reallocation !
                   // Pointers can be invalid after the call.
                   _setExtRefIndex(&(keyData.data),&inst.mem);
               }
               else
               {
                   keyData.isSet=true;
                   keyData.data.extRefPtr=0;
               }
               break;
           }
       case CIMTYPE_OBJECT:
       case CIMTYPE_INSTANCE:
           {
               // From PEP 194: EmbeddedObjects cannot be keys.
               throw TypeMismatchException();
               break;
           }
       default:
           {
               PEGASUS_ASSERT(false);
               break;
           }
       }
   }
   
   void SCMOInstance::_initSCMOInstance(SCMOClass* pClass)
   {
       PEGASUS_ASSERT(SCMB_INITIAL_MEMORY_CHUNK_SIZE
           - sizeof(SCMBInstance_Main)>0);
   
   
       inst.base = (char*)malloc(SCMB_INITIAL_MEMORY_CHUNK_SIZE);
       if (inst.base == 0)
       {
           // Not enough memory!
           throw PEGASUS_STD(bad_alloc)();
       }
   
       memset(inst.base,0,sizeof(SCMBInstance_Main));
   
       // initalize eye catcher
       inst.hdr->header.magic=PEGASUS_SCMB_INSTANCE_MAGIC;
       inst.hdr->header.totalSize=SCMB_INITIAL_MEMORY_CHUNK_SIZE;
       // The # of bytes free
       inst.hdr->header.freeBytes=
           SCMB_INITIAL_MEMORY_CHUNK_SIZE-sizeof(SCMBInstance_Main);
       // Index to the start of the free space in this instance
       inst.hdr->header.startOfFreeSpace=sizeof(SCMBInstance_Main);
   
       inst.hdr->refCount=1;
   
       //Assign the SCMBClass structure this instance based on.
       inst.hdr->theClass.ptr = pClass;
   
       // Copy name space name and class name of the class
       _setBinary(
           _getCharString(inst.hdr->theClass.ptr->cls.hdr->className,
                          inst.hdr->theClass.ptr->cls.base),
           inst.hdr->theClass.ptr->cls.hdr->className.size,
           inst.hdr->instClassName,
           &inst.mem);
   
       _setBinary(
           _getCharString(inst.hdr->theClass.ptr->cls.hdr->nameSpace,
                          inst.hdr->theClass.ptr->cls.base),
           inst.hdr->theClass.ptr->cls.hdr->nameSpace.size,
           inst.hdr->instNameSpace,
           &inst.mem);
   
       // Number of key bindings
       inst.hdr->numberKeyBindings =
           inst.hdr->theClass.ptr->cls.hdr->keyBindingSet.number;
   
       // Number of properties
       inst.hdr->numberProperties =
           inst.hdr->theClass.ptr->cls.hdr->propertySet.number;
   
       // Allocate the SCMOInstanceKeyBindingArray
       _getFreeSpace(
             inst.hdr->keyBindingArray,
             sizeof(SCMBKeyBindingValue)*inst.hdr->numberKeyBindings,
             &inst.mem);
   
       // Allocate the SCMBInstancePropertyArray
       _getFreeSpace(
           inst.hdr->propertyArray,
           sizeof(SCMBValue)*inst.hdr->numberProperties,
           &inst.mem);
   
   }
   
   void SCMOInstance::_setCIMInstance(const CIMInstance& cimInstance)
   {
       CIMPropertyRep* propRep;
       Uint32 propNode;
       SCMO_RC rc;
       CIMType realType;
   
       CIMInstanceRep* instRep = cimInstance._rep;
   
       // Test if the instance has qualifiers.
       // The instance level qualifiers are stored on the associated SCMOClass.
       inst.hdr->flags.includeQualifiers=(instRep->_qualifiers.getCount()>0);
   
       // To ensure that at converting a CIMInstance to a SCMOInstance
       // and vice versa do have the same property set.
       inst.hdr->flags.exportSetOnly=true;
   
       _setCIMObjectPath(instRep->_reference);
   
       // Copy all properties
       for (Uint32 i = 0, k = instRep->_properties.size(); i < k; i++)
       {
           propRep = instRep->_properties[i]._rep;
           // if not already detected that qualifiers are specified and
           // there are qualifers at that property.
           if (!inst.hdr->flags.includeQualifiers &&
               propRep->getQualifierCount() > 0)
           {
               includeQualifiers();
           }
           // if not already detected that class origins are specified and
           // there is a class origin specified at that property.
           if (!inst.hdr->flags.includeClassOrigin &&
               !propRep->_classOrigin.isNull())
           {
               includeClassOrigins();
           }
   
           // get the property node index for the property
           rc = inst.hdr->theClass.ptr->_getProperyNodeIndex(
               propNode,
               (const char*)propRep->_name.getString().getCString());
   
           if (rc == SCMO_OK)
           {
               // The type stored in the class information is set on realType.
               // It must be used in further calls to guaranty consistence.
               rc = inst.hdr->theClass.ptr->_isNodeSameType(
                        propNode,
                        propRep->_value._rep->type,
                        propRep->_value._rep->isArray,
                        realType);
               if (rc == SCMO_OK)
               {
                   _setCIMValueAtNodeIndex(
                       propNode,
                       propRep->_value._rep,
                       realType);
               }
               else
               {
                   PEG_TRACE((TRC_DISCARDED_DATA,Tracer::LEVEL2,
                       "CIMProperty '%s' with type '%s' "
                           "can not be set at SCMOInstance."
                           "It is has not same type '%s' as defined in "
                           "class '%s' of name space '%s'",
                        cimTypeToString(propRep->_value._rep->type),
                       (const char*)propRep->_name.getString().getCString(),
                        cimTypeToString(realType),
                       (const char*)instRep->_reference._rep->
                              _className.getString().getCString(),
                       (const char*)instRep->_reference._rep->
                              _nameSpace.getString().getCString()));
               }
   
           }
           else
           {
   
               PEG_TRACE((TRC_DISCARDED_DATA,Tracer::LEVEL2,
                   "CIMProperty '%s' can not be set at SCMOInstance."
                       "It is not part of class '%s' of name space '%s'",
                   (const char*)propRep->_name.getString().getCString(),
                   (const char*)instRep->_reference._rep->
                          _className.getString().getCString(),
                   (const char*)instRep->_reference._rep->
                          _nameSpace.getString().getCString()));
           }
       }
   }
   
   SCMO_RC SCMOInstance::getProperty(
       const char* name,
       CIMType& type,
       const SCMBUnion** pOutVal,
       Boolean& isArray,
       Uint32& size ) const
   {
       Uint32 node;
       const char* pname;
       SCMO_RC rc = SCMO_OK;
   
       *pOutVal = 0;
       isArray = false;
       size = 0;
   
       rc = inst.hdr->theClass.ptr->_getProperyNodeIndex(node,name);
       if (rc != SCMO_OK)
       {
           return rc;
       }
   
       return  _getPropertyAtNodeIndex(node,&pname,type,pOutVal,isArray,size);
   }
   
   SCMO_RC SCMOInstance::getPropertyAt(
           Uint32 idx,
           const char** pname,
           CIMType& type,
           const SCMBUnion** pOutVal,
           Boolean& isArray,
           Uint32& size ) const
   {
       *pname = 0;
       *pOutVal = 0;
       isArray = false;
       size = 0;
   
       if (idx >= inst.hdr->numberProperties)
       {
           return SCMO_INDEX_OUT_OF_BOUND;
       }
   
       return  _getPropertyAtNodeIndex(idx,pname,type,pOutVal,isArray,size);
   }
   
   SCMO_RC SCMOInstance::getPropertyNodeIndex(const char* name, Uint32& node) const
   {
       SCMO_RC rc;
       if(name==0)
       {
           return SCMO_INVALID_PARAMETER;
       }
   
       rc = inst.hdr->theClass.ptr->_getProperyNodeIndex(node,name);
   
       return rc;
   
   }
   
   SCMO_RC SCMOInstance::setPropertyWithOrigin(
       const char* name,
       CIMType type,
       const SCMBUnion* pInVal,
       Boolean isArray,
       Uint32 size,
       const char* origin)
   {
       // In this function no  _copyOnWrite(), it does not change the instance.
   
       Uint32 node;
       SCMO_RC rc;
       CIMType realType;
   
       rc = inst.hdr->theClass.ptr->_getProperyNodeIndex(node,name);
       if (rc != SCMO_OK)
       {
           return rc;
       }
   
       // Is the traget type OK ?
       // The type stored in the class information is set on realType.
       // It must be used in further calls to guaranty consistence.
       rc = inst.hdr->theClass.ptr->_isNodeSameType(node,type,isArray,realType);
       if (rc != SCMO_OK)
       {
           return rc;
       }
   
       // check class origin if set.
       if (origin!= 0)
       {
           if(!inst.hdr->theClass.ptr->_isSamePropOrigin(node,origin))
           {
               return SCMO_NOT_SAME_ORIGIN;
           }
       }
   
   
       _setPropertyAtNodeIndex(node,realType,pInVal,isArray,size);
   
       return SCMO_OK;
   }
   
   SCMO_RC SCMOInstance::setPropertyWithNodeIndex(
       Uint32 node,
       CIMType type,
       const SCMBUnion* pInVal,
       Boolean isArray,
       Uint32 size)
   {
       // In this function no  _copyOnWrite(), it does not change the instance.
   
       SCMO_RC rc;
       CIMType realType;
   
       if (node >= inst.hdr->numberProperties)
       {
           return SCMO_INDEX_OUT_OF_BOUND;
       }
   
       // Is the traget type OK ?
       // The type stored in the class information is set on realType.
       // It must be used in further calls to guaranty consistence.
       rc = inst.hdr->theClass.ptr->_isNodeSameType(node,type,isArray,realType);
       if (rc != SCMO_OK)
       {
           return rc;
       }
   
       _setPropertyAtNodeIndex(node,realType,pInVal,isArray,size);
   
       return SCMO_OK;
   }
   
   void SCMOInstance::_setPropertyAtNodeIndex(
       Uint32 node,
       CIMType type,
       const SCMBUnion* pInVal,
       Boolean isArray,
       Uint32 size)
   {
   
       _copyOnWrite();
   
       SCMBValue* theInstPropNodeArray =
           (SCMBValue*)&(inst.base[inst.hdr->propertyArray.start]);
   
   
       theInstPropNodeArray[node].flags.isSet=true;
       theInstPropNodeArray[node].valueType=type;
       theInstPropNodeArray[node].flags.isArray=isArray;
       if (isArray)
       {
           theInstPropNodeArray[node].valueArraySize=size;
       }
   
       if (pInVal==0)
       {
           theInstPropNodeArray[node].flags.isNull=true;
       }
       else
       {
           theInstPropNodeArray[node].flags.isNull=false;
           _setSCMBUnion(
               pInVal,
               type,
               isArray,
               size,
               theInstPropNodeArray[node].value);
       }
   }
   
   void SCMOInstance::_setSCMBUnion(
       const SCMBUnion* pInVal,
       CIMType type,
       Boolean isArray,
       Uint32 size,
       SCMBUnion & u)
   {
   
       switch (type)
       {
       case CIMTYPE_BOOLEAN:
       case CIMTYPE_UINT8:
       case CIMTYPE_SINT8:
       case CIMTYPE_UINT16:
       case CIMTYPE_SINT16:
       case CIMTYPE_UINT32:
       case CIMTYPE_SINT32:
       case CIMTYPE_UINT64:
       case CIMTYPE_SINT64:
       case CIMTYPE_REAL32:
       case CIMTYPE_REAL64:
       case CIMTYPE_CHAR16:
           {
               if (isArray)
               {
                   _setBinary(pInVal,size*sizeof(SCMBUnion),
                              u.arrayValue,
                              &inst.mem );
               }
               else
               {
                   memcpy(&u,pInVal,sizeof(SCMBUnion));
                   u.simple.hasValue=true;
               }
               break;
           }
       case CIMTYPE_DATETIME:
           {
               if (isArray)
               {
                   _setBinary(pInVal,size*sizeof(SCMBUnion),
                              u.arrayValue,
                              &inst.mem );
               }
               else
               {
                   memcpy(&u,pInVal,sizeof(SCMBUnion));
   
               }
               break;
           }
       case CIMTYPE_STRING:
           {
               if (isArray)
               {
                   SCMBUnion* ptr;
                   Uint64 startPtr;
   
                   startPtr = _getFreeSpace(
                       u.arrayValue,
                       size*sizeof(SCMBUnion),
                       &inst.mem);
   
                   for (Uint32 i = 0; i < size; i++)
                   {
                       ptr = (SCMBUnion*)&(inst.base[startPtr]);
                       // Copy the sting including the trailing '\0'
                       _setBinary(
                           pInVal[i].extString.pchar,
                           pInVal[i].extString.length+1,
                           ptr[i].stringValue,
                           &inst.mem );
                   }
               }
               else
               {
                   // Copy the sting including the trailing '\0'
                   _setBinary(
                       pInVal->extString.pchar,
                       pInVal->extString.length+1,
                       u.stringValue,
                       &inst.mem );
               }
               break;
           }
   
       case CIMTYPE_REFERENCE:
       case CIMTYPE_OBJECT:
       case CIMTYPE_INSTANCE:
           {
               if(isArray)
               {
                   SCMBUnion* ptr;
                   Uint64 startPtr;
   
                   // if the array was previously set, delete the references !
                   _deleteArrayExtReference(u.arrayValue,&inst.mem);
   
                   // get new array
                   startPtr = _getFreeSpace(
                       u.arrayValue,
                       size*sizeof(SCMBUnion),
                       &inst.mem);
   
                   ptr = (SCMBUnion*)&(inst.base[startPtr]);
   
                   for (Uint32 i = 0 ; i < size ; i++)
                   {
                       if(pInVal[i].extRefPtr)
                       {
                           ptr[i].extRefPtr=
                               new SCMOInstance(*(pInVal[i].extRefPtr));
   
                           // This function can cause a reallocation !
                           // Pointers can be invalid after the call.
                           _setExtRefIndex(&(ptr[i]),&inst.mem);
                       }
                       else
                       {
                           ptr[i].extRefPtr = 0;
                       }
                   }
   
               }
               else
               {
                   if(0 != u.extRefPtr)
                   {
                       delete u.extRefPtr;
                   }
   
                   if(pInVal->extRefPtr)
                   {
                       u.extRefPtr = new SCMOInstance(*(pInVal->extRefPtr));
                       // This function can cause a reallocation !
                       // Pointers can be invalid after the call.
                       _setExtRefIndex(&u,&inst.mem);
   
                   }
                   else
                   {
                       u.extRefPtr = 0;
                   }
               }
               break;
           }
       default:
           {
               PEGASUS_ASSERT(false);
               break;
           }
       }
   }
   
   void SCMOInstance::_setUnionArrayValue(
       Uint64 start,
       SCMBMgmt_Header** pmem,
       CIMType type,
       Uint32& n,
       Uint64 startNS,
       Uint32 sizeNS,
       Union& u)
   {
       SCMBUnion* scmoUnion = (SCMBUnion*)&(((char*)*pmem)[start]);
       SCMBUnion* ptargetUnion;
       Uint64 arrayStart;
       Uint32 loop;
   
       switch (type)
       {
       case CIMTYPE_BOOLEAN:
           {
               Array<Boolean> *x = reinterpret_cast<Array<Boolean>*>(&u);
               // n can be invalid after re-allocation in _getFreeSpace !
               loop = n = x->size();
               arrayStart = _getFreeSpace(
                   scmoUnion->arrayValue,
                   loop*sizeof(SCMBUnion),
                   pmem);
   
               ConstArrayIterator<Boolean> iterator(*x);
   
               ptargetUnion = (SCMBUnion*)&(((char*)*pmem)[arrayStart]);
               for (Uint32 i = 0; i < loop; i++)
               {
                   ptargetUnion[i].simple.val.bin  = iterator[i];
                   ptargetUnion[i].simple.hasValue = true;
               }
               break;
           }
   
       case CIMTYPE_UINT8:
           {
               Array<Uint8> *x = reinterpret_cast<Array<Uint8>*>(&u);
               // n can be invalid after re-allocation in _getFreeSpace !
               loop = n = x->size();
               arrayStart = _getFreeSpace(
                   scmoUnion->arrayValue,
                   loop*sizeof(SCMBUnion),
                   pmem);
   
               ConstArrayIterator<Uint8> iterator(*x);
   
               ptargetUnion = (SCMBUnion*)&(((char*)*pmem)[arrayStart]);
               for (Uint32 i = 0; i < loop; i++)
               {
                   ptargetUnion[i].simple.val.u8  = iterator[i];
                   ptargetUnion[i].simple.hasValue = true;
               }
               break;
           }
   
       case CIMTYPE_SINT8:
           {
               Array<Sint8> *x = reinterpret_cast<Array<Sint8>*>(&u);
               // n can be invalid after re-allocation in _getFreeSpace !
               loop = n = x->size();
               arrayStart = _getFreeSpace(
                   scmoUnion->arrayValue,
                   loop*sizeof(SCMBUnion),
                   pmem);
   
               ConstArrayIterator<Sint8> iterator(*x);
   
               ptargetUnion = (SCMBUnion*)&(((char*)*pmem)[arrayStart]);
               for (Uint32 i = 0; i < loop; i++)
               {
                   ptargetUnion[i].simple.val.s8  = iterator[i];
                   ptargetUnion[i].simple.hasValue = true;
               }
               break;
           }
   
       case CIMTYPE_UINT16:
           {
               Array<Uint16> *x = reinterpret_cast<Array<Uint16>*>(&u);
               // n can be invalid after re-allocation in _getFreeSpace !
               loop = n = x->size();
               arrayStart = _getFreeSpace(
                   scmoUnion->arrayValue,
                   loop*sizeof(SCMBUnion),
                   pmem);
   
               ConstArrayIterator<Uint16> iterator(*x);
   
               ptargetUnion = (SCMBUnion*)&(((char*)*pmem)[arrayStart]);
               for (Uint32 i = 0; i < loop; i++)
               {
                   ptargetUnion[i].simple.val.u16  = iterator[i];
                   ptargetUnion[i].simple.hasValue = true;
               }
               break;
           }
   
       case CIMTYPE_SINT16:
           {
               Array<Sint16> *x = reinterpret_cast<Array<Sint16>*>(&u);
               // n can be invalid after re-allocation in _getFreeSpace !
               loop = n = x->size();
               arrayStart = _getFreeSpace(
                   scmoUnion->arrayValue,
                   loop*sizeof(SCMBUnion),
                   pmem);
   
               ConstArrayIterator<Sint16> iterator(*x);
   
               ptargetUnion = (SCMBUnion*)&(((char*)*pmem)[arrayStart]);
               for (Uint32 i = 0; i < loop; i++)
               {
                   ptargetUnion[i].simple.val.s16  = iterator[i];
                   ptargetUnion[i].simple.hasValue = true;
               }
               break;
           }
   
       case CIMTYPE_UINT32:
           {
               Array<Uint32> *x = reinterpret_cast<Array<Uint32>*>(&u);
               // n can be invalid after re-allocation in _getFreeSpace !
               loop = n = x->size();
               arrayStart = _getFreeSpace(
                   scmoUnion->arrayValue,
                   loop*sizeof(SCMBUnion),
                   pmem);
   
               ConstArrayIterator<Uint32> iterator(*x);
   
               ptargetUnion = (SCMBUnion*)&(((char*)*pmem)[arrayStart]);
               for (Uint32 i = 0; i < loop; i++)
               {
                   ptargetUnion[i].simple.val.u32  = iterator[i];
                   ptargetUnion[i].simple.hasValue = true;
               }
               break;
           }
   
       case CIMTYPE_SINT32:
           {
               Array<Sint32> *x = reinterpret_cast<Array<Sint32>*>(&u);
               // n can be invalid after re-allocation in _getFreeSpace !
               loop = n = x->size();
               arrayStart = _getFreeSpace(
                   scmoUnion->arrayValue,
                   loop*sizeof(SCMBUnion),
                   pmem);
   
               ConstArrayIterator<Sint32> iterator(*x);
   
               ptargetUnion = (SCMBUnion*)&(((char*)*pmem)[arrayStart]);
               for (Uint32 i = 0; i < loop; i++)
               {
                   ptargetUnion[i].simple.val.s32  = iterator[i];
                   ptargetUnion[i].simple.hasValue = true;
               }
               break;
           }
   
       case CIMTYPE_UINT64:
           {
               Array<Uint64> *x = reinterpret_cast<Array<Uint64>*>(&u);
               // n can be invalid after re-allocation in _getFreeSpace !
               loop = n = x->size();
               arrayStart = _getFreeSpace(
                   scmoUnion->arrayValue,
                   loop*sizeof(SCMBUnion),
                   pmem);
   
               ConstArrayIterator<Uint64> iterator(*x);
   
               ptargetUnion = (SCMBUnion*)&(((char*)*pmem)[arrayStart]);
               for (Uint32 i = 0; i < loop; i++)
               {
                   ptargetUnion[i].simple.val.u64  = iterator[i];
                   ptargetUnion[i].simple.hasValue = true;
               }
               break;
           }
   
       case CIMTYPE_SINT64:
           {
               Array<Sint64> *x = reinterpret_cast<Array<Sint64>*>(&u);
               // n can be invalid after re-allocation in _getFreeSpace !
               loop = n = x->size();
               arrayStart = _getFreeSpace(
                   scmoUnion->arrayValue,
                   loop*sizeof(SCMBUnion),
                   pmem);
   
               ConstArrayIterator<Sint64> iterator(*x);
   
               ptargetUnion = (SCMBUnion*)&(((char*)*pmem)[arrayStart]);
               for (Uint32 i = 0; i < loop; i++)
               {
                   ptargetUnion[i].simple.val.s64  = iterator[i];
                   ptargetUnion[i].simple.hasValue = true;
               }
               break;
           }
   
       case CIMTYPE_REAL32:
           {
               Array<Real32> *x = reinterpret_cast<Array<Real32>*>(&u);
               // n can be invalid after re-allocation in _getFreeSpace !
               loop = n = x->size();
               arrayStart = _getFreeSpace(
                   scmoUnion->arrayValue,
                   loop*sizeof(SCMBUnion),
                   pmem);
   
               ConstArrayIterator<Real32> iterator(*x);
   
               ptargetUnion = (SCMBUnion*)&(((char*)*pmem)[arrayStart]);
               for (Uint32 i = 0; i < loop; i++)
               {
                   ptargetUnion[i].simple.val.r32  = iterator[i];
                   ptargetUnion[i].simple.hasValue = true;
               }
               break;
           }
   
       case CIMTYPE_REAL64:
           {
               Array<Real64> *x = reinterpret_cast<Array<Real64>*>(&u);
               // n can be invalid after re-allocation in _getFreeSpace !
               loop = n = x->size();
               arrayStart = _getFreeSpace(
                   scmoUnion->arrayValue,
                   loop*sizeof(SCMBUnion),
                   pmem);
   
               ConstArrayIterator<Real64> iterator(*x);
   
               ptargetUnion = (SCMBUnion*)&(((char*)*pmem)[arrayStart]);
               for (Uint32 i = 0; i < loop; i++)
               {
                   ptargetUnion[i].simple.val.r64  = iterator[i];
                   ptargetUnion[i].simple.hasValue = true;
               }
               break;
           }
   
       case CIMTYPE_CHAR16:
           {
               Array<Char16> *x = reinterpret_cast<Array<Char16>*>(&u);
               // n can be invalid after re-allocation in _getFreeSpace !
               loop = n = x->size();
               arrayStart = _getFreeSpace(
                   scmoUnion->arrayValue,
                   loop*sizeof(SCMBUnion),
                   pmem);
   
               ConstArrayIterator<Char16> iterator(*x);
   
               ptargetUnion = (SCMBUnion*)&(((char*)*pmem)[arrayStart]);
               for (Uint32 i = 0; i < loop; i++)
               {
                   ptargetUnion[i].simple.val.c16  = iterator[i];
                   ptargetUnion[i].simple.hasValue = true;
               }
               break;
           }
   
       case CIMTYPE_STRING:
           {
               Array<String> *x = reinterpret_cast<Array<String>*>(&u);
               // n can be invalid after re-allocation in _getFreeSpace !
               loop = n = x->size();
   
               arrayStart = _getFreeSpace(
                   scmoUnion->arrayValue,
                   loop*sizeof(SCMBUnion),
                   pmem);
   
               ConstArrayIterator<String> iterator(*x);
   
               for (Uint32 i = 0; i < loop ; i++)
               {
                   // the pointer has to be set eache loop,
                   // because a reallocation may take place.
                   ptargetUnion = (SCMBUnion*)(&((char*)*pmem)[arrayStart]);
                   _setString( iterator[i],ptargetUnion[i].stringValue, pmem );
               }
   
               break;
           }
   
       case CIMTYPE_DATETIME:
           {
               Array<CIMDateTime> *x = reinterpret_cast<Array<CIMDateTime>*>(&u);
               // n can be invalid after reallocation in _getFreeSpace !
               loop = n = x->size();
   
               arrayStart = _getFreeSpace(
                   scmoUnion->arrayValue,
                   loop*sizeof(SCMBUnion),
                   pmem);
   
               ConstArrayIterator<CIMDateTime> iterator(*x);
   
               ptargetUnion = (SCMBUnion*)(&((char*)*pmem)[arrayStart]);
   
               for (Uint32 i = 0; i < loop ; i++)
               {
                   memcpy(
                       &(ptargetUnion[i].dateTimeValue),
                       iterator[i]._rep,
                       sizeof(SCMBDateTime));
               }
               break;
           }
   
       case CIMTYPE_REFERENCE:
           {
               Array<CIMObjectPath> *x =
                   reinterpret_cast<Array<CIMObjectPath>*>(&u);
   
               // if the array was previously set, delete the references !
               _deleteArrayExtReference(scmoUnion->arrayValue,pmem);
   
               // n can be invalid after reallocation in _getFreeSpace !
               loop = n = x->size();
   
               arrayStart = _getFreeSpace(
                   scmoUnion->arrayValue,
                   loop*sizeof(SCMBUnion),
                   pmem);
   
               ConstArrayIterator<CIMObjectPath> iterator(*x);
   
               ptargetUnion = (SCMBUnion*)(&((char*)*pmem)[arrayStart]);
   
               for (Uint32 i = 0; i < loop ; i++)
               {
   
                   ptargetUnion[i].extRefPtr =
                       new SCMOInstance(
                           iterator[i],
                           &(((const char*)*pmem)[startNS]),
                           sizeNS-1);
                   // Was the conversion successful?
                   if (ptargetUnion[i].extRefPtr->isEmpty())
                   {
                       // N0, delete the SCMOInstance.
                       delete ptargetUnion[i].extRefPtr;
                       ptargetUnion[i].extRefPtr = 0;
                   }
                   else
                   {
                       _setExtRefIndex(&(ptargetUnion[i]),pmem);
                   }
               }
   
               break;
           }
       case CIMTYPE_OBJECT:
           {
               Array<CIMObject> *x =
                   reinterpret_cast<Array<CIMObject>*>(&u);
   
               // if the array was previously set, delete the references !
               _deleteArrayExtReference(scmoUnion->arrayValue,pmem);
   
               // n can be invalid after reallocation in _getFreeSpace !
               loop = n = x->size();
   
               arrayStart = _getFreeSpace(
                   scmoUnion->arrayValue,
                   loop*sizeof(SCMBUnion),
                   pmem);
   
               ConstArrayIterator<CIMObject> iterator(*x);
   
               ptargetUnion = (SCMBUnion*)(&((char*)*pmem)[arrayStart]);
   
               for (Uint32 i = 0; i < loop ; i++)
               {
                   if (iterator[i].isUninitialized())
                   {
                       // the Object was empty.
                       ptargetUnion[i].extRefPtr = 0;
                   }
                   else
                   {
                       if (iterator[i].isClass())
                       {
                           CIMClass cimClass(iterator[i]);
   
                           ptargetUnion[i].extRefPtr =
                               new SCMOInstance(
                                   cimClass,
                                   (&((const char*)*pmem)[startNS]));
                           // marke as class only !
                           ptargetUnion[i].extRefPtr->
                               inst.hdr->flags.isClassOnly=true;
   
                           // This function can cause a reallocation !
                           // Pointers can be invalid after the call.
                           _setExtRefIndex(&(ptargetUnion[i]),pmem);
                       }
                       else
                       {
                           CIMInstance theInst(iterator[i]);
   
                           ptargetUnion[i].extRefPtr =
                               new SCMOInstance(
                                   theInst,
                                   &(((const char*)*pmem)[startNS]),
                                   sizeNS-1);
                            // Was the conversion successful?
                            if (ptargetUnion[i].extRefPtr->isEmpty())
                            {
                                // N0, delete the SCMOInstance.
                                delete ptargetUnion[i].extRefPtr;
                                ptargetUnion[i].extRefPtr = 0;
                            }
                            else
                            {
                                // This function can cause a reallocation !
                                // Pointers can be invalid after the call.
                                _setExtRefIndex(&(ptargetUnion[i]),pmem);
                            }
                       }
                   }
               }
   
               break;
           }
       case CIMTYPE_INSTANCE:
           {
               Array<CIMInstance> *x =
                   reinterpret_cast<Array<CIMInstance>*>(&u);
   
               // if the array was previously set, delete the references !
               _deleteArrayExtReference(scmoUnion->arrayValue,pmem);
   
               // n can be invalid after reallocation in _getFreeSpace !
               loop = n = x->size();
   
               arrayStart = _getFreeSpace(
                   scmoUnion->arrayValue,
                   loop*sizeof(SCMBUnion),
                   pmem);
   
               ConstArrayIterator<CIMInstance> iterator(*x);
   
               ptargetUnion = (SCMBUnion*)(&((char*)*pmem)[arrayStart]);
   
               for (Uint32 i = 0; i < loop ; i++)
               {
                   if (iterator[i].isUninitialized())
                   {
                       // the Instance was empty.
                       ptargetUnion[i].extRefPtr = 0;
                   }
                   else
                   {
                       ptargetUnion[i].extRefPtr =
                           new SCMOInstance(
                               iterator[i],
                               &(((const char*)*pmem)[startNS]),
                               sizeNS-1);
                       // Was the conversion successful?
                       if (ptargetUnion[i].extRefPtr->isEmpty())
                       {
                           // N0, delete the SCMOInstance.
                           delete ptargetUnion[i].extRefPtr;
                           ptargetUnion[i].extRefPtr = 0;
                       }
                       else
                       {
                           // This function can cause a reallocation !
                           // Pointers can be invalid after the call.
                           _setExtRefIndex(&(ptargetUnion[i]),pmem);
                       }
   
                   }
               }
   
               break;
           }
       default:
           {
               PEGASUS_ASSERT(false);
               break;
           }
       }
   }
   
   
   void SCMOInstance::_setUnionValue(
       Uint64 start,
       SCMBMgmt_Header** pmem,
       CIMType type,
       Uint64 startNS,
       Uint32 sizeNS,
       Union& u)
   {
       SCMBUnion* scmoUnion = (SCMBUnion*)&(((char*)*pmem)[start]);
   
       switch (type)
       {
       case CIMTYPE_BOOLEAN:
           {
               scmoUnion->simple.val.bin = u._booleanValue;
               scmoUnion->simple.hasValue=true;
               break;
           }
   
       case CIMTYPE_UINT8:
           {
               scmoUnion->simple.val.u8 = u._uint8Value;
               scmoUnion->simple.hasValue=true;
               break;
           }
   
       case CIMTYPE_SINT8:
           {
               scmoUnion->simple.val.s8 = u._sint8Value;
               scmoUnion->simple.hasValue=true;
               break;
           }
   
       case CIMTYPE_UINT16:
           {
               scmoUnion->simple.val.u16 = u._uint16Value;
               scmoUnion->simple.hasValue=true;
               break;
           }
   
       case CIMTYPE_SINT16:
           {
               scmoUnion->simple.val.s16 = u._sint16Value;
               scmoUnion->simple.hasValue=true;
               break;
           }
   
       case CIMTYPE_UINT32:
           {
               scmoUnion->simple.val.u32 = u._uint32Value;
               scmoUnion->simple.hasValue=true;
               break;
           }
   
       case CIMTYPE_SINT32:
           {
               scmoUnion->simple.val.s32 = u._sint32Value;
               scmoUnion->simple.hasValue=true;
               break;
           }
   
       case CIMTYPE_UINT64:
           {
               scmoUnion->simple.val.u64 = u._uint64Value;
               scmoUnion->simple.hasValue=true;
               break;
           }
   
       case CIMTYPE_SINT64:
           {
               scmoUnion->simple.val.s64 = u._sint64Value;
               scmoUnion->simple.hasValue=true;
               break;
           }
   
       case CIMTYPE_REAL32:
           {
               scmoUnion->simple.val.r32 = u._real32Value;
               scmoUnion->simple.hasValue=true;
               break;
           }
   
       case CIMTYPE_REAL64:
           {
               scmoUnion->simple.val.r64 = u._real64Value;
               scmoUnion->simple.hasValue=true;
               break;
           }
   
       case CIMTYPE_CHAR16:
           {
               scmoUnion->simple.val.c16 = u._char16Value;
               scmoUnion->simple.hasValue=true;
               break;
           }
   
       case CIMTYPE_STRING:
           {
               CString cstr = ((String*)((void*)&u))->getCString();
               const char *cptr = (const char*)cstr;
               _setBinary(
                   cptr,
                   strlen(cptr) + 1,
                   scmoUnion->stringValue,
                   pmem );
               break;
           }
   
       case CIMTYPE_DATETIME:
           {
               memcpy(
                   &scmoUnion->dateTimeValue,
                   (*((CIMDateTime*)((void*)&u)))._rep,
                   sizeof(SCMBDateTime));
               break;
           }
   
       case CIMTYPE_REFERENCE:
           {
               if (0 != scmoUnion->extRefPtr)
               {
                   delete scmoUnion->extRefPtr;
                   scmoUnion->extRefPtr = 0;
               }
   
               if (0 == u._referenceValue)
               {
                 scmoUnion->extRefPtr = 0;
                 return;
               }
   
               CIMObjectPath* theCIMObj =
                   (CIMObjectPath*)((void*)&u._referenceValue);
   
               scmoUnion->extRefPtr =
                   new SCMOInstance(
                       *theCIMObj,
                       &(((const char*)*pmem)[startNS]),
                       sizeNS-1);
   
               // Was the conversion successful?
               if (scmoUnion->extRefPtr->isEmpty())
               {
                   // N0, delete the SCMOInstance.
                   delete scmoUnion->extRefPtr;
                   scmoUnion->extRefPtr = 0;
               }
               else
               {
                   // This function can cause a reallocation !
                   // Pointers can be invalid after the call.
                   _setExtRefIndex(scmoUnion,pmem);
               }
   
               break;
           }
       case CIMTYPE_OBJECT:
           {
               if (0 != scmoUnion->extRefPtr)
               {
                   delete scmoUnion->extRefPtr;
                   scmoUnion->extRefPtr = 0;
               }
   
               if (0 == u._referenceValue)
               {
                 scmoUnion->extRefPtr=0;
                 return;
               }
   
               CIMObject* theCIMObject =(CIMObject*)((void*)&u._objectValue);
   
               if (theCIMObject->isUninitialized())
               {
                   // the Object was empty.
                   scmoUnion->extRefPtr = 0;
               }
               else
               {
                   if (theCIMObject->isClass())
                   {
                       CIMClass cimClass(*theCIMObject);
   
                       scmoUnion->extRefPtr =
                           new SCMOInstance(
                               cimClass,
                               (&((const char*)*pmem)[startNS]));
                       // marke as class only !
                       scmoUnion->extRefPtr->inst.hdr->flags.isClassOnly=true;
   
                       // This function can cause a reallocation !
                       // Pointers can be invalid after the call.
                       _setExtRefIndex(scmoUnion,pmem);
                   }
                   else
                   {
                       CIMInstance theCIMInst(*theCIMObject);
   
                       scmoUnion->extRefPtr =
                           new SCMOInstance(
                               theCIMInst,
                               &(((const char*)*pmem)[startNS]),
                               sizeNS-1);
   
                        // Was the conversion successful?
                        if (scmoUnion->extRefPtr->isEmpty())
                        {
                            // N0, delete the SCMOInstance.
                            delete scmoUnion->extRefPtr;
                            scmoUnion->extRefPtr = 0;
                        }
                        else
                        {
                            // This function can cause a reallocation !
                            // Pointers can be invalid after the call.
                            _setExtRefIndex(scmoUnion,pmem);
                        }
                   }
               }
               break;
           }
       case CIMTYPE_INSTANCE:
           {
               if (0 != scmoUnion->extRefPtr)
               {
                   delete scmoUnion->extRefPtr;
                   scmoUnion->extRefPtr = 0;
               }
   
               if (0 == u._referenceValue)
               {
                 scmoUnion->extRefPtr=0;
                 return;
               }
   
               CIMInstance* theCIMInst =
                   (CIMInstance*)((void*)&u._instanceValue);
   
               if (theCIMInst->isUninitialized())
               {
                   // the Instance was empty.
                   scmoUnion->extRefPtr = 0;
               }
               else
               {
                   scmoUnion->extRefPtr =
                       new SCMOInstance(
                           *theCIMInst,
                           &(((const char*)*pmem)[startNS]),
                           sizeNS-1);
   
                    // Was the conversion successful?
                    if (scmoUnion->extRefPtr->isEmpty())
                    {
                        // N0, delete the SCMOInstance.
                        delete scmoUnion->extRefPtr;
                        scmoUnion->extRefPtr = 0;
                    }
                    else
                    {
                        // This function can cause a reallocation !
                        // Pointers can be invalid after the call.
                        _setExtRefIndex(scmoUnion,pmem);
                    }
               }
               break;
           }
       default:
           {
               PEGASUS_ASSERT(false);
               break;
           }
       }
   }
   
   SCMO_RC SCMOInstance::_getPropertyAtNodeIndex(
           Uint32 node,
           const char** pname,
           CIMType& type,
           const SCMBUnion** pvalue,
           Boolean& isArray,
           Uint32& size ) const
   {
       SCMBValue* theInstPropNodeArray =
           (SCMBValue*)&inst.base[inst.hdr->propertyArray.start];
   
       // create a pointer to property node array of the class.
       Uint64 idx = inst.hdr->theClass.ptr->cls.hdr->propertySet.nodeArray.start;
       SCMBClassPropertyNode* theClassPropNodeArray =
           (SCMBClassPropertyNode*)&(inst.hdr->theClass.ptr->cls.base)[idx];
   
       // the property name is always from the class.
       // return the absolut pointer to the property name,
       // the caller has to copy the name!
       *pname=_getCharString(
           theClassPropNodeArray[node].theProperty.name,
           inst.hdr->theClass.ptr->cls.base);
   
       // the property was set by the provider.
       if (theInstPropNodeArray[node].flags.isSet)
       {
   
           type = theInstPropNodeArray[node].valueType;
           isArray = theInstPropNodeArray[node].flags.isArray;
           if (isArray)
           {
               size = theInstPropNodeArray[node].valueArraySize;
           }
   
           if (theInstPropNodeArray[node].flags.isNull)
           {
               return SCMO_NULL_VALUE;
           }
   
           // calculate the relative index for the value.
           Uint64 start =
               (const char*)&(theInstPropNodeArray[node].value) -
               inst.base;
   
           // the caller has to copy the value !
           *pvalue = _resolveSCMBUnion(type,isArray,size,start,inst.base);
   
           return SCMO_OK;
       }
   
       // the get the defaults out of the class.
       type = theClassPropNodeArray[node].theProperty.defaultValue.valueType;
       isArray =
           theClassPropNodeArray[node].theProperty.defaultValue.flags.isArray;
       if (isArray)
       {
           size = theClassPropNodeArray[node].
                      theProperty.defaultValue.valueArraySize;
       }
   
       if (theClassPropNodeArray[node].theProperty.defaultValue.flags.isNull)
       {
           return SCMO_NULL_VALUE;
       }
   
       // calcutate the relativ start address of the value
       Uint64 start =
           (const char*)
                  &(theClassPropNodeArray[node].theProperty.defaultValue.value) -
           (inst.hdr->theClass.ptr->cls.base);
   
       *pvalue = _resolveSCMBUnion(
           type,
           isArray,
           size,
           start,
           (inst.hdr->theClass.ptr->cls.base)
           );
   
       return SCMO_OK;
   
   }
   
   SCMOInstance SCMOInstance::clone(Boolean objectPathOnly) const
   {
       if (objectPathOnly)
       {
           // Create a new, empty SCMOInstance
           SCMOInstance newInst(*(this->inst.hdr->theClass.ptr));
   
           // Copy the host name to tha new instance-
           _setBinary(
               _resolveDataPtr(this->inst.hdr->hostName,this->inst.base),
               this->inst.hdr->hostName.size,
               newInst.inst.hdr->hostName,
               &newInst.inst.mem);
   
           newInst.inst.hdr->flags.isCompromised =
               this->inst.hdr->flags.isCompromised;
   
           // If the instance contains a user set class and/or name space name
           if (this->inst.hdr->flags.isCompromised)
           {
               // Copy the class name to tha new instance-
               _setBinary(
                   _resolveDataPtr(this->inst.hdr->instClassName,this->inst.base),
                   this->inst.hdr->instClassName.size,
                   newInst.inst.hdr->instClassName,
                   &newInst.inst.mem);
   
               // Copy the name space name to tha new instance-
               _setBinary(
                   _resolveDataPtr(this->inst.hdr->instNameSpace,this->inst.base),
                   this->inst.hdr->instNameSpace.size,
                   newInst.inst.hdr->instNameSpace,
                   &newInst.inst.mem);
           }
   
           // Copy the key bindings to that new instance.
           this->_copyKeyBindings(newInst);
   
           return newInst;
       }
   
       SCMOInstance newInst;
       newInst.inst.base = inst.base;
       newInst._clone();
   
       return newInst;
   }
   
   void SCMOInstance::_clone()
   {
       char* newBase;
       newBase = (char*)malloc((size_t)inst.mem->totalSize);
       if (0 == newBase )
       {
           throw PEGASUS_STD(bad_alloc)();
       }
   
       memcpy( newBase,inst.base,(size_t)inst.mem->totalSize);
   
       // make new new memory block to mine.
       inst.base = newBase;
       // reset the refcounter of this instance
       inst.hdr->refCount = 1;
       // keep the ref counter of the class correct !
       inst.hdr->theClass.ptr = new SCMOClass(*(inst.hdr->theClass.ptr));
       // keep the ref count for external references
       _copyExternalReferences();
   
   }
   
   void SCMOInstance::_copyKeyBindings(SCMOInstance& targetInst) const
   {
       Uint32 noBindings = inst.hdr->numberKeyBindings;
   
       SCMBKeyBindingValue* sourceArray =
           (SCMBKeyBindingValue*)&(inst.base[inst.hdr->keyBindingArray.start]);
   
       // Address the class keybinding information
       const SCMBClass_Main* clshdr = inst.hdr->theClass.ptr->cls.hdr;
       const char * clsbase = inst.hdr->theClass.ptr->cls.base;
       SCMBKeyBindingNode* scmoClassArray =
           (SCMBKeyBindingNode*)&(clsbase[clshdr->keyBindingSet.nodeArray.start]);
   
       SCMBKeyBindingValue* targetArray;
   
       for (Uint32 i = 0; i < noBindings; i++)
       {
           // hast to be set every time, because of reallocation.
           targetArray=(SCMBKeyBindingValue*)&(targetInst.inst.base)
                                [targetInst.inst.hdr->keyBindingArray.start];
           if(sourceArray[i].isSet)
           {
               // this has to be done on the target instance to keep constantness.
               targetInst._setKeyBindingFromSCMBUnion(
                   scmoClassArray[i].type,
                   sourceArray[i].data,
                   inst.base,
                   targetArray[i]);
           }
       }
   
       // Are there user defined key bindings ?
       if (0 != inst.hdr->numberUserKeyBindings)
       {
           SCMBUserKeyBindingElement* theUserDefKBElement =
               (SCMBUserKeyBindingElement*)
                    &(inst.base[inst.hdr->userKeyBindingElement.start]);
   
           for(Uint32 i = 0; i < inst.hdr->numberUserKeyBindings; i++)
           {
               if (theUserDefKBElement->value.isSet)
               {
                   targetInst._setUserDefinedKeyBinding(*theUserDefKBElement,
                                                           inst.base);
               }
   
               theUserDefKBElement =
                   (SCMBUserKeyBindingElement*)
                        &(inst.base[theUserDefKBElement->nextElement.start]);
           } // for all user def. key bindings.
       }
   }
   
   
   void SCMOInstance::_setUserDefinedKeyBinding(
           SCMBUserKeyBindingElement& theInsertElement,
           char* elementBase)
   {
   
       SCMBUserKeyBindingElement* ptrNewElement;
   
       // get an exsiting or new user defined key binding
       ptrNewElement = _getUserDefinedKeyBinding(
           _getCharString(theInsertElement.name,elementBase),
           // lenght is without the trailing '\0'
           theInsertElement.name.size-1,
           theInsertElement.type);
   
       // Copy the data
       _setKeyBindingFromSCMBUnion(
                   theInsertElement.type,
                   theInsertElement.value.data,
                   elementBase,
                   ptrNewElement->value);
   
   }
   
   
   SCMBUserKeyBindingElement* SCMOInstance::_getUserDefinedKeyBindingAt(
       Uint32 index ) const
   {
   
       // Get the start element
       SCMBUserKeyBindingElement *ptrNewElement =
           (SCMBUserKeyBindingElement*)
                &(inst.base[inst.hdr->userKeyBindingElement.start]);
   
       // calculate the index within the user defined key bindings
       index = index - inst.hdr->numberKeyBindings;
   
       // traverse trough the user defindes key binding nodes.
       for (Uint32 i = 0; i < index; i ++)
       {
           PEGASUS_ASSERT(ptrNewElement->nextElement.start != 0);
           ptrNewElement = (SCMBUserKeyBindingElement*)
                 &(inst.base[ptrNewElement->nextElement.start]);
       }
   
       return ptrNewElement;
   }
   
   SCMBUserKeyBindingElement* SCMOInstance::_getUserDefinedKeyBinding(
       const char* name,
       Uint32 nameLen,
       CIMType type)
   {
       SCMBDataPtr newElement;
       SCMBUserKeyBindingElement* ptrNewElement;
       Uint32 node;
   
       // is the key binding already stored as user defind in the instance ?
       if (SCMO_OK == _getUserKeyBindingNodeIndex(node,name))
       {
          ptrNewElement = _getUserDefinedKeyBindingAt(node);
       }
       else // Not found, create a new user defined key binding.
       {
   
           _getFreeSpace(newElement,
                         sizeof(SCMBUserKeyBindingElement),
                         &inst.mem);
   
           ptrNewElement =
               (SCMBUserKeyBindingElement*)&(inst.base[newElement.start]);
   
           // link new first user defined key binding element into chain:
           // - Assing the start point of user key binding element chain
           //   to the next element of the new element.
           ptrNewElement->nextElement.start =
               inst.hdr->userKeyBindingElement.start;
           ptrNewElement->nextElement.size =
               inst.hdr->userKeyBindingElement.size;
           // - Assing the the new element
           //   to the  start point of user key binding element chain
           inst.hdr->userKeyBindingElement.start = newElement.start;
           inst.hdr->userKeyBindingElement.size = newElement.size;
           // Adjust the couter of user defined key bindings.
           inst.hdr->numberUserKeyBindings++;
   
   
           // Copy the type
           ptrNewElement->type = type;
           ptrNewElement->value.isSet=false;
   
           // Copy the key binding name including the trailing '\0'
           _setBinary(name,nameLen+1,ptrNewElement->name,&inst.mem);
   
           // reset the pointer. May the instance was reallocated.
           ptrNewElement =
               (SCMBUserKeyBindingElement*)&(inst.base[newElement.start]);
   
       }
   
   
       return ptrNewElement;
   
   }
   
   Uint32 SCMOInstance::getPropertyCount() const
   {
       return(inst.hdr->numberProperties);
   }
   
   SCMBUnion * SCMOInstance::_resolveSCMBUnion(
       CIMType type,
       Boolean isArray,
       Uint32 size,
       Uint64 start,
       char* base) const
   {
   
       SCMBUnion* u = (SCMBUnion*)&(base[start]);
   
       SCMBUnion* av = 0;
   
       if (isArray)
       {
           if (size == 0)
           {
               return 0;
           }
           av = (SCMBUnion*)&(base[u->arrayValue.start]);
       }
   
       switch (type)
       {
       case CIMTYPE_BOOLEAN:
       case CIMTYPE_UINT8:
       case CIMTYPE_SINT8:
       case CIMTYPE_UINT16:
       case CIMTYPE_SINT16:
       case CIMTYPE_UINT32:
       case CIMTYPE_SINT32:
       case CIMTYPE_UINT64:
       case CIMTYPE_SINT64:
       case CIMTYPE_REAL32:
       case CIMTYPE_REAL64:
       case CIMTYPE_CHAR16:
       case CIMTYPE_DATETIME:
       case CIMTYPE_REFERENCE:
       case CIMTYPE_OBJECT:
       case CIMTYPE_INSTANCE:
           {
               if(isArray)
               {
                   return (av);
               }
               else
               {
                   return(u);
               }
           }
   
       case CIMTYPE_STRING:
           {
               SCMBUnion *ptr;
   
               if (isArray)
               {
   
                   ptr = (SCMBUnion*)malloc(size*sizeof(SCMBUnion));
                   if (ptr == 0 )
                   {
                       throw PEGASUS_STD(bad_alloc)();
                   }
   
                   for(Uint32 i = 0; i < size; i++)
                   {
                       // resolv relative pointer to absolute pointer
                       ptr[i].extString.pchar =
                           (char*)_getCharString(av[i].stringValue,base);
                       // lenght with out the trailing /0 !
                       ptr[i].extString.length = av[i].stringValue.size-1;
                   }
               }
               else
               {
                   ptr = (SCMBUnion*)malloc(sizeof(SCMBUnion));
                   ptr->extString.pchar =
                       (char*)_getCharString(u->stringValue,base);
                   // lenght with out the trailing /0 !
                   ptr->extString.length = u->stringValue.size-1;
               }
   
               return(ptr);
           }
       default:
           {
               PEGASUS_ASSERT(false);
               break;
           }
       }
       return 0;
   }
   
   void SCMOInstance::clearKeyBindings()
   {
       _copyOnWrite();
   
       // First destroy all external references in the key bindings
       _destroyExternalKeyBindings();
   
       // reset user keybindings
       inst.hdr->numberUserKeyBindings = 0;
       inst.hdr->userKeyBindingElement.start = 0;
       inst.hdr->userKeyBindingElement.size = 0;
   
       // Allocate a clean the SCMOInstanceKeyBindingArray
       _getFreeSpace(
             inst.hdr->keyBindingArray,
             sizeof(SCMBKeyBindingValue)*inst.hdr->numberKeyBindings,
             &inst.mem);
   
       // Clear the keybindings after the allocation. Setting the keybindings
       // later causes this value to be reinitialized.
       inst.hdr->numberKeyBindings = 0;
   
       markAsCompromised();
   }
   
   Uint32 SCMOInstance::getKeyBindingCount() const
   {
       // count of class keys + user definded keys
       return(inst.hdr->numberKeyBindings+
              inst.hdr->numberUserKeyBindings);
   }
   
   
   SCMO_RC SCMOInstance::getKeyBindingAt(
           Uint32 node,
           const char** pname,
           CIMType& type,
           const SCMBUnion** pvalue) const
   {
       SCMO_RC rc;
       const SCMBUnion* pdata=0;
       Uint32 pnameLen=0;
   
       *pname = 0;
       *pvalue = 0;
   
       // count of class keys + user definded keys
       if (node >= (inst.hdr->numberKeyBindings+
                    inst.hdr->numberUserKeyBindings))
       {
           return SCMO_INDEX_OUT_OF_BOUND;
       }
   
       rc = _getKeyBindingDataAtNodeIndex(node,pname,pnameLen,type,&pdata);
       if (rc != SCMO_OK)
       {
           return rc;
       }
   
       *pvalue = _resolveSCMBUnion(
           type,
           false,  // A key binding can never be an array.
           0,
           (char*)pdata-inst.base,
           inst.base);
   
       return SCMO_OK;
   
   }
   
   SCMO_RC SCMOInstance::getKeyBinding(
       const char* name,
       CIMType& type,
       const SCMBUnion** pvalue) const
   {
       SCMO_RC rc;
       Uint32 node;
       const char* pname=0;
       const SCMBUnion* pdata=0;
       Uint32 pnameLen=0;
   
       *pvalue = 0;
   
       rc = inst.hdr->theClass.ptr->_getKeyBindingNodeIndex(node,name);
       if (rc != SCMO_OK)
       {
           // look at the user defined key bindings.
           rc = _getUserKeyBindingNodeIndex(node,name);
           if (rc != SCMO_OK)
           {
               return rc;
           }
       }
   
       rc = _getKeyBindingDataAtNodeIndex(node,&pname,pnameLen,type,&pdata);
   
       if (rc != SCMO_OK)
       {
           return rc;
       }
   
       *pvalue = _resolveSCMBUnion(
           type,
           false,  // A key binding can never be an array.
           0,
           (char*)pdata-inst.base,
           inst.base);
   
       return SCMO_OK;
   }
   
   
   SCMO_RC SCMOInstance::_getKeyBindingDataAtNodeIndex(
       Uint32 node,
       const char** pname,
       Uint32 & pnameLen,
       CIMType & type,
       const SCMBUnion** pdata) const
   {
       if (node < inst.hdr->numberKeyBindings)
       {
           SCMBKeyBindingValue* theInstKeyBindValueArray =
               (SCMBKeyBindingValue*)&(inst.base[inst.hdr->keyBindingArray.start]);
   
           // create a pointer to key binding node array of the class.
           Uint64 idx = inst.hdr->theClass.ptr->cls.hdr->
               keyBindingSet.nodeArray.start;
           SCMBKeyBindingNode* theClassKeyBindNodeArray =
               (SCMBKeyBindingNode*)&((inst.hdr->theClass.ptr->cls.base)[idx]);
   
           type = theClassKeyBindNodeArray[node].type;
   
           // First resolve pointer to the key binding name
           pnameLen = theClassKeyBindNodeArray[node].name.size;
           *pname = _getCharString(
               theClassKeyBindNodeArray[node].name,
               inst.hdr->theClass.ptr->cls.base);
   
           // There is no value set in the instance
           if (!theInstKeyBindValueArray[node].isSet)
           {
               return SCMO_NULL_VALUE;
           }
   
           *pdata = &(theInstKeyBindValueArray[node].data);
       }
       else // look at the user defined key bindings
       {
   
           SCMBUserKeyBindingElement* theElem = _getUserDefinedKeyBindingAt(node);
   
           type = theElem->type;
   
           pnameLen = theElem->name.size;
           *pname = _getCharString(theElem->name,inst.base);
   
           // There is no value set in the instance
           if (!theElem->value.isSet)
           {
               return SCMO_NULL_VALUE;
           }
   
           *pdata = &(theElem->value.data);
   
       }
   
       return SCMO_OK;
   }
   
   SCMO_RC SCMOInstance::_getUserKeyBindingNodeIndex(
       Uint32& node,
       const char* name) const
   {
   
       Uint32 len = strlen(name);
       node = 0;
   
       Uint64 elementStart = inst.hdr->userKeyBindingElement.start;
   
       while (elementStart != 0)
       {
           SCMBUserKeyBindingElement* theUserDefKBElement =
               (SCMBUserKeyBindingElement*)&(inst.base[elementStart]);
   
           if (_equalNoCaseUTF8Strings(
               theUserDefKBElement->name,inst.base,name,len))
           {
               // the node index of a user defined key binding has an offset
               // by the number of key bindings defined in the class
               node = node + inst.hdr->numberKeyBindings;
               return SCMO_OK;
           }
           node = node + 1;
           elementStart = theUserDefKBElement->nextElement.start;
       }
   
       return SCMO_NOT_FOUND;
   
   }
   
   CIMType SCMOInstance::_CIMTypeFromKeyBindingType(
       const char* key,
       CIMKeyBinding::Type t)
   {
       switch( t )
       {
           case CIMKeyBinding::NUMERIC:
               {
                   if( *(key)=='-' )
                   {
                      Sint64 x;
                      // check if it is realy an integer
                      if (StringConversion::stringToSignedInteger(key, x))
                      {
                          return CIMTYPE_SINT64;
                      }
                      else
                      {
                          return CIMTYPE_REAL64;
                      }
                   }
                   else
                   {
                       Uint64 x;
                       // check if it is realy an integer
                       if (StringConversion::stringToUnsignedInteger(key, x))
                       {
                           return CIMTYPE_UINT64;
                       }
                       else
                       {
                           return CIMTYPE_REAL64;
                       }
                   }
               }
   
   
           case CIMKeyBinding::STRING:
           {
               return CIMTYPE_STRING;
           }
   
           case CIMKeyBinding::BOOLEAN:
           {
               return CIMTYPE_BOOLEAN;
           }
   
           case CIMKeyBinding::REFERENCE:
           {
               return CIMTYPE_REFERENCE;
           }
   
           default:
               return CIMTYPE_UINT64;
       }
       return CIMTYPE_UINT64;
   }
   
   Boolean SCMOInstance::_setCimKeyBindingStringToSCMOKeyBindingValue(
       const String& kbs,
       CIMType type,
       SCMBKeyBindingValue& scmoKBV
       )
   {
       scmoKBV.isSet=false;
       // If it not a simple value, it will be over written.
       scmoKBV.data.simple.hasValue=false;
   
       if ( kbs.size() == 0 && type != CIMTYPE_STRING)
       {
           // The string is empty ! Do nothing.
           return false;
       }
   
       CString a = kbs.getCString();
       const char* v = a;
   
       switch (type)
       {
       case CIMTYPE_UINT8:
           {
               Uint64 x;
               if (StringConversion::stringToUnsignedInteger(v, x) &&
                   StringConversion::checkUintBounds(x, type))
               {
                 scmoKBV.data.simple.val.u8 = Uint8(x);
                 scmoKBV.data.simple.hasValue=true;
                 scmoKBV.isSet=true;
               }
               break;
           }
       case CIMTYPE_UINT16:
           {
               Uint64 x;
               if (StringConversion::stringToUnsignedInteger(v, x) &&
                   StringConversion::checkUintBounds(x, type))
               {
                 scmoKBV.data.simple.val.u16 = Uint16(x);
                 scmoKBV.data.simple.hasValue=true;
                 scmoKBV.isSet=true;
               }
               break;
           }
   
       case CIMTYPE_UINT32:
           {
               Uint64 x;
               if (StringConversion::stringToUnsignedInteger(v, x) &&
                   StringConversion::checkUintBounds(x, type))
               {
                 scmoKBV.data.simple.val.u32 = Uint32(x);
                 scmoKBV.data.simple.hasValue=true;
                 scmoKBV.isSet=true;
               }
               break;
           }
   
       case CIMTYPE_UINT64:
           {
               Uint64 x;
               if (StringConversion::stringToUnsignedInteger(v, x))
               {
                 scmoKBV.data.simple.val.u64 = x;
                 scmoKBV.data.simple.hasValue=true;
                 scmoKBV.isSet=true;
               }
               break;
           }
   
       case CIMTYPE_SINT8:
           {
               Sint64 x;
               if (StringConversion::stringToSignedInteger(v, x) &&
                   StringConversion::checkSintBounds(x, type))
               {
                 scmoKBV.data.simple.val.s8 = Sint8(x);
                 scmoKBV.data.simple.hasValue=true;
                 scmoKBV.isSet=true;
               }
               break;
           }
   
       case CIMTYPE_SINT16:
           {
               Sint64 x;
               if (StringConversion::stringToSignedInteger(v, x) &&
                   StringConversion::checkSintBounds(x, type))
               {
                 scmoKBV.data.simple.val.s16 = Sint16(x);
                 scmoKBV.data.simple.hasValue=true;
                 scmoKBV.isSet=true;
               }
               break;
           }
  
       case CIMTYPE_SINT32:
           {
               Sint64 x;
               if (StringConversion::stringToSignedInteger(v, x) &&
                   StringConversion::checkSintBounds(x, type))
               {
                 scmoKBV.data.simple.val.s32 = Sint32(x);
                 scmoKBV.data.simple.hasValue=true;
                 scmoKBV.isSet=true;
               }
               break;
 } }
  
 SCMOInstance SCMOInstance::clone() const      case CIMTYPE_SINT64:
 { {
     SCMOInstance newInst;              Sint64 x;
     newInst.inst.base = (char*)malloc(this->inst.mem->totalSize);              if (StringConversion::stringToSignedInteger(v, x))
     if (newInst.inst.base == NULL )  
     {     {
         throw PEGASUS_STD(bad_alloc)();                scmoKBV.data.simple.val.s64 = x;
                 scmoKBV.data.simple.hasValue=true;
                 scmoKBV.isSet=true;
     }     }
               break;
     memcpy( newInst.inst.base,this->inst.base,this->inst.mem->totalSize);  
     // reset the refcounter of this new instance  
     newInst.inst.hdr->refCount = 1;  
     // kepp the ref counter of the class correct !  
     newInst.inst.hdr->theClass = new SCMOClass(*(this->inst.hdr->theClass));  
   
     return newInst;  
 } }
  
 Uint32 SCMOInstance::getPropertyCount() const      case CIMTYPE_DATETIME:
           {
               CIMDateTime tmp;
   
               try
 { {
     if (inst.hdr->flags.isFiltered)                  tmp.set(v);
               }
               catch (InvalidDateTimeFormatException&)
     {     {
         return(inst.hdr->filterProperties);                  return false;
     }     }
  
     return(inst.hdr->numberProperties);              memcpy(
                   &(scmoKBV.data.dateTimeValue),
                   tmp._rep,
                   sizeof(SCMBDateTime));
               scmoKBV.isSet=true;
               break;
 } }
  
 void* SCMOInstance::_getSCMBUnion(      case CIMTYPE_REAL32:
     CIMType type,  
     Boolean isArray,  
     Uint32 size,  
     Uint64 start,  
     char* base) const  
 { {
               Real64 x;
  
     SCMBUnion* u = (SCMBUnion*)&(base[start]);              if (StringConversion::stringToReal64(v, x))
               {
     void* av = NULL;                scmoKBV.data.simple.val.r32 = Real32(x);
                 scmoKBV.data.simple.hasValue=true;
                 scmoKBV.isSet=true;
               }
               break;
           }
  
     if (isArray)      case CIMTYPE_REAL64:
     {     {
         if (size == 0)              Real64 x;
   
               if (StringConversion::stringToReal64(v, x))
         {         {
             return NULL;                scmoKBV.data.simple.val.r64 = x;
                 scmoKBV.data.simple.hasValue=true;
                 scmoKBV.isSet=true;
         }         }
         av = (void*)&base[u->_arrayValue.start];              break;
     }     }
  
       case CIMTYPE_CHAR16:
     switch (type)  
     {     {
               if (kbs.size() == 1)
               {
                   scmoKBV.data.simple.val.c16 = kbs[0];
                   scmoKBV.data.simple.hasValue=true;
                   scmoKBV.isSet=true;
               }
               break;
           }
     case CIMTYPE_BOOLEAN:     case CIMTYPE_BOOLEAN:
     case CIMTYPE_UINT8:  
     case CIMTYPE_SINT8:  
     case CIMTYPE_UINT16:  
     case CIMTYPE_SINT16:  
     case CIMTYPE_UINT32:  
     case CIMTYPE_SINT32:  
     case CIMTYPE_UINT64:  
     case CIMTYPE_SINT64:  
     case CIMTYPE_REAL32:  
     case CIMTYPE_REAL64:  
     case CIMTYPE_CHAR16:  
     case CIMTYPE_DATETIME:  
         {         {
             if(isArray)              if (String::equalNoCase(kbs,"TRUE"))
             {             {
                 return ((void*)av);                  scmoKBV.data.simple.val.bin = true;
                   scmoKBV.data.simple.hasValue=true;
                   scmoKBV.isSet=true;
             }             }
             else              else if (String::equalNoCase(kbs,"FALSE"))
             {             {
                 return((void*)u);                       scmoKBV.data.simple.val.bin = false;
                        scmoKBV.data.simple.hasValue=true;
                        scmoKBV.isSet=true;
             }             }
             break;             break;
         }         }
  
     case CIMTYPE_STRING:     case CIMTYPE_STRING:
         {         {
             SCMBDataPtr *ptr;              scmoKBV.isSet=true;
             char** tmp=NULL;              // Can cause reallocation !
               _setString(kbs,scmoKBV.data.stringValue,&inst.mem);
             if (isArray)              return true;
           }
       case CIMTYPE_REFERENCE:
             {             {
                 // allocate an array of char* pointers.              if (0 != scmoKBV.data.extRefPtr)
                 tmp = (char**)malloc(size*sizeof(char*));  
                 if (tmp == NULL )  
                 {                 {
                     throw PEGASUS_STD(bad_alloc)();                  delete scmoKBV.data.extRefPtr;
                   scmoKBV.data.extRefPtr = 0;
                   scmoKBV.isSet=false;
                 }                 }
               // TBD: Optimize parsing and SCMOInstance creation.
               CIMObjectPath theCIMObj(kbs);
  
                 // use temporary variables to avoid casting              scmoKBV.data.extRefPtr = new SCMOInstance(theCIMObj);
                 ptr = (SCMBDataPtr*)av;              scmoKBV.isSet=true;
  
                 for(Uint32 i = 0; i < size; i++)              // Was the conversion successful?
               if (scmoKBV.data.extRefPtr->isEmpty())
                 {                 {
                     // resolv relative pointer to absolute pointer                  // N0, delete the SCMOInstance.
                     tmp[i] = (char*)_getCharString(ptr[i],base);                  delete scmoKBV.data.extRefPtr;
                 }                  scmoKBV.data.extRefPtr = 0;
                   scmoKBV.isSet=false;
                 return((void*)tmp);  
             }             }
             else             else
             {             {
                 return((void*)_getCharString(u->_stringValue,base));                  // This function can cause a reallocation !
                   // Pointers can be invalid after the call.
                   _setExtRefIndex(&(scmoKBV.data),&inst.mem);
             }             }
   
   
             break;             break;
         }         }
   
     case CIMTYPE_REFERENCE:  
   
         break;  
   
     case CIMTYPE_OBJECT:     case CIMTYPE_OBJECT:
   
         break;  
   
     case CIMTYPE_INSTANCE:     case CIMTYPE_INSTANCE:
           {
         break;              // From PEP 194: EmbeddedObjects cannot be keys.
               throw TypeMismatchException();
           }
     default:     default:
           {
         PEGASUS_ASSERT(false);         PEGASUS_ASSERT(false);
         break;         break;
     }     }
     return NULL;  
 } }
  
 Uint32 SCMOInstance::getKeyBindingCount()      return scmoKBV.isSet;
   }
   
   SCMO_RC SCMOInstance::_setKeyBindingFromString(
       const char* name,
       CIMType type,
       String cimKeyBinding)
   {
       Uint32 node;
   
       if (0 == name)
 { {
     return(inst.hdr->numberKeyBindings);          return SCMO_INVALID_PARAMETER;
 } }
  
       if (SCMO_OK == inst.hdr->theClass.ptr->_getKeyBindingNodeIndex(node,name))
       {
           // create a pointer to keybinding node array of the class.
           Uint64 idx = inst.hdr->theClass.ptr->cls.hdr->
               keyBindingSet.nodeArray.start;
           SCMBKeyBindingNode* theClassKeyBindNodeArray =
               (SCMBKeyBindingNode*)&((inst.hdr->theClass.ptr->cls.base)[idx]);
  
 SCMO_RC SCMOInstance::getKeyBindingAt(          // create a pointer to instance keybinding values
         Uint32 node,          SCMBKeyBindingValue* theInstKeyBindValueArray =
         const char** pname,              (SCMBKeyBindingValue*)&(inst.base[inst.hdr->keyBindingArray.start]);
         CIMKeyBinding::Type& type,  
         const char** pvalue) const          // If the set was not successful, the conversion was not successful
           if ( !_setCimKeyBindingStringToSCMOKeyBindingValue(
                   cimKeyBinding,
                   theClassKeyBindNodeArray[node].type,
                   theInstKeyBindValueArray[node]))
 { {
     *pname = NULL;              return SCMO_TYPE_MISSMATCH;
     *pvalue = NULL;          }
  
     if (node >= inst.hdr->numberKeyBindings)          return SCMO_OK;
       }
   
       // the key binig does not belong to the associated class
       // add/set it as user defined key binding.
       SCMBUserKeyBindingElement* ptrNewElement;
   
       ptrNewElement = _getUserDefinedKeyBinding( name,strlen(name),type);
   
       // Copy the data.
       // If the set was not successful, the conversion was not successful
       if ( !_setCimKeyBindingStringToSCMOKeyBindingValue(
               cimKeyBinding,
               type,
               ptrNewElement->value))
     {     {
         return SCMO_INDEX_OUT_OF_BOUND;          return SCMO_TYPE_MISSMATCH;
     }     }
  
     return _getKeyBindingAtNodeIndex(node,pname,type,pvalue);      return SCMO_OK;
 } }
  
 SCMO_RC SCMOInstance::getKeyBinding(  SCMO_RC SCMOInstance::setKeyBinding(
     const char* name,     const char* name,
     CIMKeyBinding::Type& type,      CIMType type,
     const char** pvalue) const      const SCMBUnion* keyvalue)
 { {
     SCMO_RC rc;     SCMO_RC rc;
     Uint32 node;     Uint32 node;
     const char* pname=NULL;  
  
     rc = inst.hdr->theClass->_getKeyBindingNodeIndex(node,name);      if (0 == name)
     if (rc != SCMO_OK)  
     {     {
         return rc;          return SCMO_INVALID_PARAMETER;
     }  
   
     return _getKeyBindingAtNodeIndex(node,&pname,type,pvalue);  
   
 } }
  
 SCMO_RC SCMOInstance::_getKeyBindingAtNodeIndex(      if (0 == keyvalue)
     Uint32 node,  
     const char** pname,  
     CIMKeyBinding::Type& type,  
     const char** pvalue) const  
 { {
           return SCMO_INVALID_PARAMETER;
       }
  
     SCMBDataPtr* theInstKeyBindNodeArray =      _copyOnWrite();
         (SCMBDataPtr*)&inst.base[inst.hdr->keyBindingArray.start];  
  
     // create a pointer to keybinding node array of the class.      // If keybindings exists and cleared using the clearKeyBindings()
     Uint64 idx = inst.hdr->theClass->cls.hdr->keyBindingSet.nodeArray.start;      // method, reset the value to the actual keybindings count exists
     SCMBKeyBindingNode* theClassKeyBindNodeArray =      // in the class.
         (SCMBKeyBindingNode*)&(inst.hdr->theClass->cls.base)[idx];      if (!inst.hdr->numberKeyBindings)
       {
           inst.hdr->numberKeyBindings =
               inst.hdr->theClass.ptr->cls.hdr->keyBindingSet.number;
       }
  
     type = theClassKeyBindNodeArray[node].type;      rc = inst.hdr->theClass.ptr->_getKeyBindingNodeIndex(node,name);
       if (rc != SCMO_OK)
       {
           // the key bindig does not belong to the associated class
           // add/set it as user defined key binding.
           SCMBUserKeyBindingElement *theNode;
  
     *pname = _getCharString(          theNode = _getUserDefinedKeyBinding( name,strlen(name),type);
         theClassKeyBindNodeArray[node].name,  
         inst.hdr->theClass->cls.base);  
  
     // There is no value set in the instance          // Is this a new node or an existing user key binding?
     // if the relative pointer has no start value.          if (theNode->value.isSet && (theNode->type != type))
     if (theInstKeyBindNodeArray[node].start==0)  
     {     {
         *pvalue = NULL;              return SCMO_TYPE_MISSMATCH;
         return SCMO_NULL_VALUE;  
     }     }
  
     // Set the absolut pointer to the key binding value          theNode->value.isSet=true;
     *pvalue = _getCharString(theInstKeyBindNodeArray[node],inst.base);  
           _setSCMBUnion(
               keyvalue,
               type,
               false, // a key binding can never be an array.
               0,
               theNode->value.data);
  
     return SCMO_OK;     return SCMO_OK;
       }
  
       return setKeyBindingAt(node, type, keyvalue);
 } }
  
 SCMO_RC SCMOInstance::setKeyBinding(  SCMO_RC SCMOInstance::setKeyBindingAt(
     const char* name,          Uint32 node,
     CIMKeyBinding::Type type,          CIMType type,
     const char* pvalue)          const SCMBUnion* keyvalue)
 { {
     SCMO_RC rc;      if (0 == keyvalue)
     Uint32 node;      {
           return SCMO_INVALID_PARAMETER;
       }
  
     rc = inst.hdr->theClass->_getKeyBindingNodeIndex(node,name);      // count of class keys + user definded keys
     if (rc != SCMO_OK)      if (node >= (inst.hdr->numberKeyBindings+
                    inst.hdr->numberUserKeyBindings))
     {     {
         return rc;          return SCMO_INDEX_OUT_OF_BOUND;
       }
   
       _copyOnWrite();
   
       // If keybindings exists and cleared using the clearKeyBindings()
       // method, reset the value to the actual keybindings count exists
       // in the class.
       if (!inst.hdr->numberKeyBindings)
       {
           inst.hdr->numberKeyBindings =
               inst.hdr->theClass.ptr->cls.hdr->keyBindingSet.number;
     }     }
  
   
    // create a pointer to keybinding node array of the class.    // create a pointer to keybinding node array of the class.
     Uint64 idx = inst.hdr->theClass->cls.hdr->keyBindingSet.nodeArray.start;      Uint64 idx = inst.hdr->theClass.ptr->cls.hdr->
           keyBindingSet.nodeArray.start;
     SCMBKeyBindingNode* theClassKeyBindNodeArray =     SCMBKeyBindingNode* theClassKeyBindNodeArray =
         (SCMBKeyBindingNode*)&(inst.hdr->theClass->cls.base)[idx];          (SCMBKeyBindingNode*)&((inst.hdr->theClass.ptr->cls.base)[idx]);
  
     if (theClassKeyBindNodeArray[node].type != type)      // is the node a user defined key binding ?
       if (node >= inst.hdr->numberKeyBindings)
       {
           SCMBUserKeyBindingElement* theNode = _getUserDefinedKeyBindingAt(node);
   
           // Does the new value for the user defined keybinding match?
           if (theNode->type != type)
     {     {
         return SCMO_TYPE_MISSMATCH;         return SCMO_TYPE_MISSMATCH;
     }     }
  
     SCMBDataPtr* theInstKeyBindNodeArray =          _setSCMBUnion(
         (SCMBDataPtr*)&inst.base[inst.hdr->keyBindingArray.start];              keyvalue,
               type,
     // copy the value including trailing '\0'              false, // a key binding can never be an array.
     _setBinary(pvalue,strlen(pvalue)+1,theInstKeyBindNodeArray[node],&inst.mem);              0,
               theNode->value.data);
  
     return SCMO_OK;     return SCMO_OK;
  
 } }
  
 void SCMOInstance::setPropertyFilter(const char **propertyList)      SCMBKeyBindingValue* theInstKeyBindValueArray =
 {          (SCMBKeyBindingValue*)&(inst.base[inst.hdr->keyBindingArray.start]);
     SCMO_RC rc;  
     Uint32 node,i = 0;  
  
     if (inst.hdr->propertyFilter.start == 0)  
       if (theClassKeyBindNodeArray[node].type == type)
     {     {
         // Allocate the SCMBPropertyFilter  
         _getFreeSpace(  
             inst.hdr->propertyFilter,  
             sizeof(Uint64)*(((inst.hdr->numberProperties-1)/64)+1),  
             &inst.mem,  
             true);  
  
         // Allocate the SCMBPropertyFilterIndexMap          // Has to be set first,
         _getFreeSpace(          // because reallocaton can take place in _setSCMBUnion()
             inst.hdr->propertyFilterIndexMap,          theInstKeyBindValueArray[node].isSet=true;
             sizeof(Uint32)*inst.hdr->numberProperties,  
             &inst.mem,          _setSCMBUnion(
             true);              keyvalue,
     }              type,
     // Get absolut pointer to property filter index map of the instance              false, // a key binding can never be an array.
     Uint32* propertyFilterIndexMap =  
         (Uint32*)&(inst.base[inst.hdr->propertyFilterIndexMap.start]);  
   
     // All properties are accepted  
     if (propertyList == NULL)  
     {  
         // Clear filtering:  
         // Switch filtering off.  
         inst.hdr->flags.isFiltered = false;  
   
         // Clear filter index map  
         memset(  
             propertyFilterIndexMap,  
             0,             0,
             sizeof(Uint32)*inst.hdr->filterProperties);              theInstKeyBindValueArray[node].data);
  
         //reset number filter properties to all          return SCMO_OK;
         inst.hdr->filterProperties = inst.hdr->numberProperties;  
  
         return;  
     }     }
  
     // Switch filtering on.      // The type does not match.
     inst.hdr->flags.isFiltered = true;      return _setKeyBindingTypeTolerate(
           theClassKeyBindNodeArray[node].type,
           type,
           keyvalue,
           theInstKeyBindValueArray[node]);
  
     // intit the filter with the key properties  }
     inst.hdr->filterProperties=_initPropFilterWithKeys();  
  
     // add the properties to the filter.  /**
     while (propertyList[i] != NULL)   * Set a SCMO user defined key binding using the class CIM type tolerating
    * CIM key binding types converted to CIM types by fuction
    *  _CIMTypeFromKeyBindingType().
    *
    * @parm classType The type of the key binding in the class definition
    * @parm setType The type of the key binding to be set.
    * @param keyValue A pointer to the key binding to be set.
    * @param kbValue Out parameter, the SCMO keybinding to be set.
    *
    **/
   SCMO_RC SCMOInstance::_setKeyBindingTypeTolerate(
       CIMType classType,
       CIMType setType,
       const SCMBUnion* keyValue,
       SCMBKeyBindingValue& kbValue)
   {
       if (setType == CIMTYPE_UINT64 )
       {
           switch (classType)
     {     {
         // the hash index of the property if the property name is found  
         rc = inst.hdr->theClass->_getProperyNodeIndex(node,propertyList[i]);  
  
         if (rc == SCMO_OK)          case CIMTYPE_UINT8:
         {         {
             // The property name was found. Otherwise ignore this property name.                  kbValue.isSet=true;
             // insert the hash index into the filter index map                  kbValue.data.simple.hasValue=true;
             propertyFilterIndexMap[inst.hdr->filterProperties]=node;                  kbValue.data.simple.val.u8=Uint8(keyValue->simple.val.u64);
             // increase number of properties in filter.                  break;
             inst.hdr->filterProperties++;  
             // set bit in the property filter  
             _setPropertyInPropertyFilter(node);  
         }         }
         // Proceed with the next property name.          case CIMTYPE_UINT16:
         i++;              {
                   kbValue.isSet=true;
                   kbValue.data.simple.hasValue=true;
                   kbValue.data.simple.val.u16=Uint16(keyValue->simple.val.u64);
                   break;
     }     }
           case CIMTYPE_UINT32:
               {
                   kbValue.isSet=true;
                   kbValue.data.simple.hasValue=true;
                   kbValue.data.simple.val.u32=Uint32(keyValue->simple.val.u64);
                   break;
 } }
           case CIMTYPE_UINT64:
   
 Uint32 SCMOInstance::_initPropFilterWithKeys()  
 { {
                   kbValue.isSet=true;
                   kbValue.data.simple.hasValue=true;
                   kbValue.data.simple.val.u64=keyValue->simple.val.u64;
                   break;
               }
           default:
               {
                   return SCMO_TYPE_MISSMATCH;
               }
           }
           return SCMO_OK;
  
     // Get absolut pointer to the key property mask of the class.      }
     Uint64 idx = inst.hdr->theClass->cls.hdr->keyPropertyMask.start;  
     Uint64* keyMask =(Uint64*)&(inst.hdr->theClass->cls.base)[idx];  
   
     // Get absolut pointer to property filter mask  
     Uint64* propertyFilterMask =  
         (Uint64*)&(inst.base[inst.hdr->propertyFilter.start]);  
   
     // copy the key mask to the property filter mask  
     memcpy(  
         propertyFilterMask,  
         keyMask,  
         sizeof(Uint64)*(((inst.hdr->numberProperties-1)/64)+1));  
   
     // Get absolut pointer to key index list of the class  
     idx=inst.hdr->theClass->cls.hdr->keyIndexList.start;  
     Uint32* keyIndex = (Uint32*)&(inst.hdr->theClass->cls.base)[idx];  
   
     // Get absolut pointer to property filter index map of the instance  
     Uint32* propertyFilterIndexMap =  
         (Uint32*)&(inst.base[inst.hdr->propertyFilterIndexMap.start]);  
  
     Uint32 noKeys = inst.hdr->theClass->cls.hdr->keyBindingSet.number;      if (setType == CIMTYPE_SINT64)
     memcpy(propertyFilterIndexMap,keyIndex,sizeof(Uint32)*noKeys);      {
           switch (classType)
           {
  
     // return the number of properties already in the filter index map          case CIMTYPE_SINT8:
     return noKeys;              {
                   kbValue.isSet=true;
                   kbValue.data.simple.hasValue=true;
                   kbValue.data.simple.val.s8=Sint8(keyValue->simple.val.s64);
                   break;
               }
           case CIMTYPE_SINT16:
               {
                   kbValue.isSet=true;
                   kbValue.data.simple.hasValue=true;
                   kbValue.data.simple.val.s16=Sint16(keyValue->simple.val.s64);
                   break;
               }
           case CIMTYPE_SINT32:
               {
                   kbValue.isSet=true;
                   kbValue.data.simple.hasValue=true;
                   kbValue.data.simple.val.s32=Sint32(keyValue->simple.val.s64);
                   break;
               }
           case CIMTYPE_SINT64:
               {
                   kbValue.isSet=true;
                   kbValue.data.simple.hasValue=true;
                   kbValue.data.simple.val.s64=keyValue->simple.val.s64;
                   break;
               }
           default:
               {
                   return SCMO_TYPE_MISSMATCH;
               }
           }
           return SCMO_OK;
       }
  
       if (setType == CIMTYPE_REAL64)
       {
           switch (classType)
           {
           case CIMTYPE_REAL32:
               {
                   kbValue.isSet=true;
                   kbValue.data.simple.hasValue=true;
                   kbValue.data.simple.val.r32=Real32(keyValue->simple.val.r64);
                   break;
               }
           case CIMTYPE_REAL64:
               {
                   kbValue.isSet=true;
                   kbValue.data.simple.hasValue=true;
                   kbValue.data.simple.val.r64=keyValue->simple.val.r64;
                   break;
               }
           default:
               {
                   return SCMO_TYPE_MISSMATCH;
               }
           }
           return SCMO_OK;
 } }
       else
 void SCMOInstance::_clearPropertyFilter()  
 { {
     Uint64 *propertyFilter;          // If type defined in the class and the provided type does not match
           // at this point, no convertaion can be done and the provided type
     // Calculate the real pointer to the Uint64 array          // is handlend as type missmatch.
     propertyFilter = (Uint64*)&inst.base[inst.hdr->propertyFilter.start];          if (classType != setType)
   
     // the number of Uint64 in the key mask is :  
     // Decrease the number of properties by 1  
     // since the array is starting at index 0!  
     // Divide with the number of bits in a Uint64.  
     // e.g. number of Properties = 68  
     // (68 - 1) / 64 = 1 --> The mask consists of 2 Uint64  
   
     memset(propertyFilter,  
            0,  
            sizeof(Uint64)*(((inst.hdr->numberProperties-1)/64)+1));  
   
 }  
 void SCMOInstance::_setPropertyInPropertyFilter(Uint32 i)  
 { {
     Uint64 *propertyFilter;              return SCMO_TYPE_MISSMATCH;
   
     // In which Uint64 of key mask is the bit for property i ?  
     // Divide with the number of bits in a Uint64.  
     // 47 / 64 = 0 --> The key bit for property i is in in keyMask[0].  
     Uint32 idx = i/64 ;  
   
     // Create a filter to set the bit.  
     // Modulo division with 64. Shift left a bit by the remainder.  
     Uint64 filter = ( (Uint64)1 << (i%64));  
   
     // Calculate the real pointer to the Uint64 array  
     propertyFilter = (Uint64*)&(inst.base[inst.hdr->propertyFilter.start]);  
   
     propertyFilter[idx] = propertyFilter[idx] | filter ;  
 } }
  
 Boolean SCMOInstance::_isPropertyInFilter(Uint32 i) const          switch (classType)
 { {
     Uint64 *propertyFilter;          case CIMTYPE_DATETIME:
           case CIMTYPE_BOOLEAN:
     // In which Uint64 of key mask is the bit for property i ?          case CIMTYPE_UINT64:
     // Divide with the number of bits in a Uint64.          case CIMTYPE_SINT64:
     // e.g. number of Properties = 68          case CIMTYPE_REAL64:
     // 47 / 64 = 0 --> The key bit for property i is in in keyMask[0].          case CIMTYPE_STRING:
     Uint32 idx = i/64 ;          case CIMTYPE_REFERENCE:
               {
     // Create a filter to check if the bit is set:                  kbValue.isSet=true;
     // Modulo division with 64. Shift left a bit by the remainder.                  _setSCMBUnion(keyValue,classType,false, 0,kbValue.data);
     Uint64 filter = ( (Uint64)1 << (i%64));                  return SCMO_OK;
               }
     // Calculate the real pointer to the Uint64 array          default:
     propertyFilter = (Uint64*)&inst.base[inst.hdr->propertyFilter.start];              {
                   return SCMO_TYPE_MISSMATCH;
               }
           }
       }
  
     // If the bit is set the property is NOT filtered.      return SCMO_TYPE_MISSMATCH;
     // So the result has to be negated!  
     return propertyFilter[idx] & filter ;  
  
 } }
  
   // class SCMODump only in debug builds available
   #ifdef PEGASUS_DEBUG
 /****************************************************************************** /******************************************************************************
  * SCMODump Print and Dump functions  * SCMODump Print and Dump functions
  *****************************************************************************/  *****************************************************************************/
 SCMODump::SCMODump() SCMODump::SCMODump()
 { {
     _out = stdout;      _out = stderr;
     _fileOpen = false;     _fileOpen = false;
  
 #ifdef PEGASUS_OS_ZOS #ifdef PEGASUS_OS_ZOS
Line 2343 
Line 5221 
  
 } }
  
 SCMODump::SCMODump(char* filename)  SCMODump::SCMODump(const char* filename)
 { {
     openFile(filename);     openFile(filename);
 } }
  
 void SCMODump::openFile(char* filename)  void SCMODump::openFile(const char* filename)
 { {
     const char* pegasusHomeDir = getenv("PEGASUS_HOME");     const char* pegasusHomeDir = getenv("PEGASUS_HOME");
  
     if (pegasusHomeDir == NULL)      if (pegasusHomeDir == 0)
     {     {
         pegasusHomeDir = ".";         pegasusHomeDir = ".";
     }     }
Line 2402 
Line 5280 
  
 Boolean SCMODump::compareFile(String master) Boolean SCMODump::compareFile(String master)
 { {
   
     if (!_fileOpen)     if (!_fileOpen)
     {     {
         return false;         return false;
     }     }
   
     closeFile();     closeFile();
  
     return (FileSystem::compareFiles(_filename, master));      ifstream isMaster;
       ifstream isDumpFile;
   
       Open(isDumpFile, _filename);
       Open(isMaster, master);
   
       String aLine;
       String bLine;
   
       while (GetLine(isDumpFile, aLine) && GetLine(isMaster, bLine))
       {
           if (aLine != bLine)
           {
               cout << "|" << aLine << "|" << endl;
               cout << "|" << bLine << "|" << endl;
               isDumpFile.close();
               isMaster.close();
               return false;
           }
       };
       isDumpFile.close();
       isMaster.close();
       return true;
 } }
  
 void SCMODump::dumpSCMOInstance(SCMOInstance& testInst) const  void SCMODump::dumpSCMOInstance(SCMOInstance& testInst, Boolean inclMemHdr)const
 { {
     SCMBInstance_Main* insthdr = testInst.inst.hdr;     SCMBInstance_Main* insthdr = testInst.inst.hdr;
     char* instbase = testInst.inst.base;     char* instbase = testInst.inst.base;
  
     fprintf(_out,"\n\nDump of SCMOInstance\n");     fprintf(_out,"\n\nDump of SCMOInstance\n");
     // The magic number for SCMO class  
     fprintf(_out,"\nheader.magic=%08X",insthdr->header.magic);      if (inclMemHdr)
     // Total size of the instance memory block( # bytes )      {
     fprintf(_out,"\nheader.totalSize=%llu",insthdr->header.totalSize);          _dumpSCMBMgmt_Header(insthdr->header,instbase);
       }
   
     // The reference counter for this c++ class     // The reference counter for this c++ class
     fprintf(_out,"\nrefCount=%i",insthdr->refCount.get());     fprintf(_out,"\nrefCount=%i",insthdr->refCount.get());
     fprintf(_out,"\ntheClass: %p",insthdr->theClass);      fprintf(_out,"\ntheClass: %p",insthdr->theClass.ptr);
     fprintf(_out,"\n\nThe Flags:");     fprintf(_out,"\n\nThe Flags:");
     fprintf(_out,"\n   includeQualifiers: %s",     fprintf(_out,"\n   includeQualifiers: %s",
            (insthdr->flags.includeQualifiers ? "True" : "False"));            (insthdr->flags.includeQualifiers ? "True" : "False"));
     fprintf(_out,"\n   includeClassOrigin: %s",     fprintf(_out,"\n   includeClassOrigin: %s",
            (insthdr->flags.includeClassOrigin ? "True" : "False"));            (insthdr->flags.includeClassOrigin ? "True" : "False"));
     fprintf(_out,"\n   isFiltered: %s",      fprintf(_out,"\n   isClassOnly: %s",
            (insthdr->flags.isFiltered ? "True" : "False"));             (insthdr->flags.isClassOnly ? "True" : "False"));
       fprintf(_out,"\n   isCompromised: %s",
              (insthdr->flags.isCompromised ? "True" : "False"));
       fprintf(_out,"\n   exportSetOnly: %s",
              (insthdr->flags.exportSetOnly ? "True" : "False"));
       fprintf(_out,"\n\ninstNameSpace: \'%s\'",
              NULLSTR(_getCharString(insthdr->instNameSpace,instbase)));
       fprintf(_out,"\n\ninstClassName: \'%s\'",
              NULLSTR(_getCharString(insthdr->instClassName,instbase)));
     fprintf(_out,"\n\nhostName: \'%s\'",     fprintf(_out,"\n\nhostName: \'%s\'",
            NULLSTR(_getCharString(insthdr->hostName,instbase)));            NULLSTR(_getCharString(insthdr->hostName,instbase)));
  
     dumpSCMOInstanceKeyBindings(testInst);     dumpSCMOInstanceKeyBindings(testInst);
  
     dumpSCMOInstancePropertyFilter(testInst);  
   
     dumpInstanceProperties(testInst);     dumpInstanceProperties(testInst);
     fprintf(_out,"\n\n");     fprintf(_out,"\n\n");
  
 } }
  
 void SCMODump::dumpSCMOInstancePropertyFilter(SCMOInstance& testInst) const  void SCMODump::dumpInstanceProperties(
 {      SCMOInstance& testInst,
     SCMBInstance_Main* insthdr = testInst.inst.hdr;      Boolean verbose) const
     char* instbase = testInst.inst.base;  
   
     if (!insthdr->flags.isFiltered)  
     {  
         fprintf(_out,"\n\nNo propterty filter!\n\n");  
         return;  
     }  
   
     fprintf(_out,"\n\nInstance Property Filter :");  
     fprintf(_out,"\n==========================");  
     fprintf(_out,"\n\nNumber of properties in the filter : %u\n"  
         ,insthdr->filterProperties);  
   
     dumpPropertyFilter(testInst);  
   
     dumpPropertyFilterIndexMap(testInst);  
   
 }  
   
 void SCMODump::dumpInstanceProperties(SCMOInstance& testInst) const  
 { {
     SCMBInstance_Main* insthdr = testInst.inst.hdr;     SCMBInstance_Main* insthdr = testInst.inst.hdr;
     char* instbase = testInst.inst.base;     char* instbase = testInst.inst.base;
Line 2480 
Line 5366 
     fprintf(_out,"\n\nNumber of properties in instance : %u",     fprintf(_out,"\n\nNumber of properties in instance : %u",
            insthdr->numberProperties);            insthdr->numberProperties);
  
     for (Uint32 i = 0; i < insthdr->numberProperties; i++)      for (Uint32 i = 0, k = insthdr->numberProperties; i < k; i++)
     {  
         fprintf(_out,"\n\nInstance property #%3u",i);  
         fprintf(_out,"\n=====================\n");  
         if(insthdr->flags.isFiltered && !testInst._isPropertyInFilter(i))  
         {  
             fprintf(_out,"\nProperty is filtered out!");  
         }  
         else  
         {         {
             printSCMOValue(val[i],instbase);          fprintf(_out,"\n\nInstance property (#%3u) %s\n",i,
         }                  NULLSTR(insthdr->theClass.ptr->_getPropertyNameAtNode(i)));
   
           printSCMOValue(val[i],instbase,verbose);
     }     }
  
 } }
  
 void SCMODump::dumpPropertyFilterIndexMap(SCMOInstance& testInst) const  
 {  
  
   void SCMODump::dumpSCMOInstanceKeyBindings(
       SCMOInstance& testInst,
       Boolean verbose) const
   {
     SCMBInstance_Main* insthdr = testInst.inst.hdr;     SCMBInstance_Main* insthdr = testInst.inst.hdr;
     char* instbase = testInst.inst.base;     char* instbase = testInst.inst.base;
  
     if (!insthdr->flags.isFiltered)      // create a pointer to keybinding node array of the class.
     {      Uint64 idx = insthdr->theClass.ptr->cls.hdr->keyBindingSet.nodeArray.start;
         fprintf(_out,"\n\nNo propterty filter!\n\n");      SCMBKeyBindingNode* theClassKeyBindNodeArray =
         return;          (SCMBKeyBindingNode*)&((insthdr->theClass.ptr->cls.base)[idx]);
     }  
  
     fprintf(_out,"\n\nProperty Filter Index Max:");      SCMBKeyBindingValue* ptr =
     fprintf(_out,"\n==========================\n");          (SCMBKeyBindingValue*)
                _resolveDataPtr(insthdr->keyBindingArray,instbase);
  
     // Get absolut pointer to key index list of the class      fprintf(_out,"\n\nInstance Key Bindings :");
     Uint32* keyIndex =      fprintf(_out,"\n=======================");
         (Uint32*)&(instbase)[insthdr->propertyFilterIndexMap.start];      fprintf(_out,"\n\nNumber of Key Bindings defined in the Class: %u",
     Uint32 line,j,i;              insthdr->numberKeyBindings);
     for (j = 0; j < insthdr->filterProperties; j = j + line)  
       for (Uint32 i = 0, k = insthdr->numberKeyBindings; i < k; i++)
     {     {
         if ((insthdr->filterProperties-j)/16)          if (ptr[i].isSet)
         {         {
             line = 16 ;              fprintf(_out,"\n\nName: '%s'\nType: '%s'",
                   NULLSTR(_getCharString(
                       theClassKeyBindNodeArray[i].name,
                       insthdr->theClass.ptr->cls.base)),
                   cimTypeToString(theClassKeyBindNodeArray[i].type));
               printUnionValue(
                   theClassKeyBindNodeArray[i].type,
                   ptr[i].data,
                   instbase,
                   verbose);
         }         }
         else         else
         {         {
             line = insthdr->filterProperties%16;              fprintf(_out,"\n\nName: '%s': Not Set",
         }                  NULLSTR(_getCharString(
                       theClassKeyBindNodeArray[i].name,
                       insthdr->theClass.ptr->cls.base)));
         fprintf(_out,"Index :");  
         for (i = 0; i < line; i++)  
         {  
             fprintf(_out," %3u",j+i);  
         }  
   
         fprintf(_out,"\nNode  :");  
         for (i = 0; i < line; i++)  
         {  
             fprintf(_out," %3u",keyIndex[j+i]);  
         }         }
   
         fprintf(_out,"\n\n");  
   
     }     }
  
 }      fprintf(_out,"\n\nNumber of User Defined Key Bindings: %u",
               insthdr->numberUserKeyBindings);
  
 void SCMODump::dumpPropertyFilter(SCMOInstance& testInst) const  
 {  
  
     SCMBInstance_Main* insthdr = testInst.inst.hdr;      SCMBUserKeyBindingElement* theUserDefKBElement;
     char* instbase = testInst.inst.base;  
  
     if (!insthdr->flags.isFiltered)      Uint64 start = insthdr->userKeyBindingElement.start;
       while (start != 0)
     {     {
         fprintf(_out,"\n\nNo propterty filter!");          theUserDefKBElement = (SCMBUserKeyBindingElement*)&(instbase[start]);
         return;  
     }  
   
     Uint64 *thePropertyFilter =  
         (Uint64*)&(instbase[insthdr->propertyFilter.start]);  
      Uint32 end, noProperties = insthdr->numberProperties;  
      Uint32 noMasks = (noProperties-1)/64;  
      Uint64 printMask = 1;  
  
      for (Uint32 i = 0; i <= noMasks; i++ )          if (theUserDefKBElement->value.isSet)
      {  
          printMask = 1;  
          if (i < noMasks)  
          {          {
              end = 64;              fprintf(_out,"\n\nName: '%s'\nType: '%s'",
                   NULLSTR(_getCharString(theUserDefKBElement->name,instbase)),
                   cimTypeToString(theUserDefKBElement->type));
               printUnionValue(
                   theUserDefKBElement->type,
                   theUserDefKBElement->value.data,
                   instbase,
                   verbose);
          }          }
          else          else
          {          {
              end = noProperties%64;              fprintf(_out,"\n\n    %s : Not Set",
                   NULLSTR(_getCharString(theUserDefKBElement->name,instbase)));
   
          }          }
           start = theUserDefKBElement->nextElement.start;
       } // for all user def. key bindings.
  
          fprintf(_out,"\npropertyFilter[%02u]= ",i);      fprintf(_out,"\n\n");
  
          for (Uint32 j = 0; j < end; j++)  
          {  
              if (j > 0 && !(j%8))  
              {  
                  fprintf(_out," ");  
              }              }
  
              if (thePropertyFilter[i] & printMask)  void SCMODump::_dumpSCMBMgmt_Header(SCMBMgmt_Header& header,char* base) const
              {              {
                  fprintf(_out,"1");      fprintf(_out,"\nThe Management Header:");
              }      // The magic number
              else      fprintf(_out,"\n   magic=%08X",header.magic);
       // Total size of the memory block( # bytes )
       fprintf(_out,"\n   totalSize=%llu",header.totalSize);
       // Free bytes in the block
       fprintf(_out,"\n   freeBytes=%llu",header.freeBytes);
       // Index to the start of the free space in this SCMB memory block.
       fprintf(_out,"\n   startOfFreeSpace=%llu",header.startOfFreeSpace);
       // Number of external references in this instance.
       fprintf(_out,"\n   numberExtRef=%u",header.numberExtRef);
       // Size of external reference index array;
       fprintf(_out,"\n   sizeExtRefIndexArray=%u",header.sizeExtRefIndexArray);
   
       if (header.numberExtRef > 0)
       {
           fprintf(_out,"\n   extRefIndexArray=[");
           Uint64* extRefIndexArray =
               (Uint64*)&(base[header.extRefIndexArray.start]);
   
           for (Uint32 i = 0; i < header.numberExtRef;)
              {              {
                  fprintf(_out,"0");              fprintf(_out,"%llu",extRefIndexArray[i]);
               i++;
               if (i != header.numberExtRef)
               {
                   fprintf(_out,", ");
              }              }
   
              printMask = printMask << 1;  
          }          }
          fprintf(_out,"\n");          fprintf(_out,"\n");
      }      }
 }      else
   
 void SCMODump::dumpSCMOInstanceKeyBindings(SCMOInstance& testInst) const  
 {  
     SCMBInstance_Main* insthdr = testInst.inst.hdr;  
     char* instbase = testInst.inst.base;  
   
     SCMBDataPtr* ptr =  
         (SCMBDataPtr*)_resolveDataPtr(insthdr->keyBindingArray,instbase);  
   
     fprintf(_out,"\n\nInstance Key Bindings :");  
     fprintf(_out,"\n=======================");  
     fprintf(_out,"\n\nNumber of Key Bindings : %u",insthdr->numberKeyBindings);  
   
     for (Uint32 i = 0; i < insthdr->numberKeyBindings; i++)  
     {     {
         fprintf(_out,"\n\nNo %u : '%s'",i,             fprintf(_out,"\n   extRefIndexArray=[NO INDEX]\n");
                 NULLSTR(_getCharString(ptr[i],instbase)));  
     }     }
     fprintf(_out,"\n");  
 } }
  
 void SCMODump::dumpSCMOClass(SCMOClass& testCls) const  void SCMODump::dumpSCMOClass(SCMOClass& testCls, Boolean inclMemHdr) const
 { {
     SCMBClass_Main* clshdr = testCls.cls.hdr;     SCMBClass_Main* clshdr = testCls.cls.hdr;
     char* clsbase = testCls.cls.base;     char* clsbase = testCls.cls.base;
  
     fprintf(_out,"\n\nDump of SCMOClass\n");     fprintf(_out,"\n\nDump of SCMOClass\n");
     // The magic number for SCMO class  
     fprintf(_out,"\nheader.magic=%08X",clshdr->header.magic);      if (inclMemHdr)
     // Total size of the instance memory block( # bytes )      {
     fprintf(_out,"\nheader.totalSize=%llu",clshdr->header.totalSize);          _dumpSCMBMgmt_Header(clshdr->header,clsbase);
       }
   
     // The reference counter for this c++ class     // The reference counter for this c++ class
     fprintf(_out,"\nrefCount=%i",clshdr->refCount.get());     fprintf(_out,"\nrefCount=%i",clshdr->refCount.get());
       fprintf(_out,"\n\nThe Flags:");
       fprintf(_out,"\n   isEmpty: %s",
              (clshdr->flags.isEmpty ? "True" : "False"));
     fprintf(_out,"\n\nsuperClassName: \'%s\'",     fprintf(_out,"\n\nsuperClassName: \'%s\'",
            NULLSTR(_getCharString(clshdr->superClassName,clsbase)));            NULLSTR(_getCharString(clshdr->superClassName,clsbase)));
     fprintf(_out,"\nnameSpace: \'%s\'",     fprintf(_out,"\nnameSpace: \'%s\'",
Line 2674 
Line 5555 
  
 void SCMODump::hexDumpSCMOClass(SCMOClass& testCls) const void SCMODump::hexDumpSCMOClass(SCMOClass& testCls) const
 { {
     char* tmp;  
   
     SCMBClass_Main* clshdr = testCls.cls.hdr;     SCMBClass_Main* clshdr = testCls.cls.hdr;
     char* clsbase = testCls.cls.base;     char* clsbase = testCls.cls.base;
  
Line 2696 
Line 5575 
  
     // Get absolut pointer to key index list of the class     // Get absolut pointer to key index list of the class
     Uint32* keyIndex = (Uint32*)&(clsbase)[clshdr->keyIndexList.start];     Uint32* keyIndex = (Uint32*)&(clsbase)[clshdr->keyIndexList.start];
     Uint32 line,j,i;      Uint32 line,j,i,k = clshdr->propertySet.number;
     for (j = 0; j < clshdr->propertySet.number; j = j + line)      for (j = 0; j < k; j = j + line)
     {     {
         if ((clshdr->propertySet.number-j)/16)         if ((clshdr->propertySet.number-j)/16)
         {         {
Line 2705 
Line 5584 
         }         }
         else         else
         {         {
             line = clshdr->propertySet.number%16;              line = clshdr->propertySet.number & 15;
         }         }
  
  
Line 2730 
Line 5609 
 void SCMODump::dumpKeyBindingSet(SCMOClass& testCls) const void SCMODump::dumpKeyBindingSet(SCMOClass& testCls) const
 { {
     SCMBClass_Main* clshdr = testCls.cls.hdr;     SCMBClass_Main* clshdr = testCls.cls.hdr;
     char* clsbase = testCls.cls.base;  
  
     fprintf(_out,"\n\nKey Binding Set:");     fprintf(_out,"\n\nKey Binding Set:");
     fprintf(_out,"\n=================\n");     fprintf(_out,"\n=================\n");
Line 2752 
Line 5630 
         (SCMBKeyBindingNode*)         (SCMBKeyBindingNode*)
              &(clsbase[clshdr->keyBindingSet.nodeArray.start]);              &(clsbase[clshdr->keyBindingSet.nodeArray.start]);
  
     for (Uint32 i = 0; i <  clshdr->keyBindingSet.number; i++)      for (Uint32 i = 0, k = clshdr->keyBindingSet.number; i < k; i++)
     {     {
         fprintf(_out,"\n\n===================");         fprintf(_out,"\n\n===================");
         fprintf(_out,"\nKey Binding #%3u",i);         fprintf(_out,"\nKey Binding #%3u",i);
Line 2773 
Line 5651 
  
         fprintf(_out,"\nHash Tag %3u Hash Index %3u",         fprintf(_out,"\nHash Tag %3u Hash Index %3u",
                nodeArray[i].nameHashTag,                nodeArray[i].nameHashTag,
                nodeArray[i].nameHashTag%PEGASUS_KEYBINDIG_SCMB_HASHSIZE);                 nodeArray[i].nameHashTag & (PEGASUS_KEYBINDIG_SCMB_HASHSIZE -1));
  
         fprintf(_out,"\nKey binding type: %s",          fprintf(_out,"\nType: %s",cimTypeToString(nodeArray[i].type));
                XmlWriter::keyBindingTypeToString(nodeArray[i].type).str);  
  
     }     }
  
Line 2785 
Line 5662 
 void SCMODump::dumpClassProperties(SCMOClass& testCls) const void SCMODump::dumpClassProperties(SCMOClass& testCls) const
 { {
     SCMBClass_Main* clshdr = testCls.cls.hdr;     SCMBClass_Main* clshdr = testCls.cls.hdr;
     char* clsbase = testCls.cls.base;  
  
     fprintf(_out,"\n\nClass Properties:");     fprintf(_out,"\n\nClass Properties:");
     fprintf(_out,"\n=================\n");     fprintf(_out,"\n=================\n");
Line 2806 
Line 5682 
         (SCMBClassPropertyNode*)         (SCMBClassPropertyNode*)
             &(clsbase[clshdr->propertySet.nodeArray.start]);             &(clsbase[clshdr->propertySet.nodeArray.start]);
  
     for (Uint32 i = 0; i <  clshdr->propertySet.number; i++)      for (Uint32 i = 0, k =  clshdr->propertySet.number; i < k; i++)
     {     {
  
         fprintf(_out,"\nClass property #%3u",i);         fprintf(_out,"\nClass property #%3u",i);
Line 2835 
Line 5711 
  
     fprintf(_out,"\nHash Tag %3u Hash Index %3u",     fprintf(_out,"\nHash Tag %3u Hash Index %3u",
            prop.nameHashTag,            prop.nameHashTag,
            prop.nameHashTag%PEGASUS_PROPERTY_SCMB_HASHSIZE);             prop.nameHashTag & (PEGASUS_PROPERTY_SCMB_HASHSIZE -1));
     fprintf(_out,"\nPropagated: %s isKey: %s",     fprintf(_out,"\nPropagated: %s isKey: %s",
            (prop.flags.propagated?"TRUE":"FALSE"),            (prop.flags.propagated?"TRUE":"FALSE"),
            (prop.flags.isKey?"TRUE":"FALSE")            (prop.flags.isKey?"TRUE":"FALSE")
Line 2869 
Line 5745 
         }         }
         else         else
         {         {
             line = size%16;              line = size & 15;
         }         }
  
  
Line 2920 
Line 5796 
      else      else
      {      {
          fprintf(_out,"\n\nQualifier DMTF defined name: \'%s\'",          fprintf(_out,"\n\nQualifier DMTF defined name: \'%s\'",
                 _qualifierNameStrLit[theQualifier.name].str);                  SCMOClass::qualifierNameStrLit(theQualifier.name).str);
      }      }
  
      fprintf(_out,"\nPropagated : %s",      fprintf(_out,"\nPropagated : %s",
Line 2934 
Line 5810 
  
 void SCMODump::printSCMOValue( void SCMODump::printSCMOValue(
     const SCMBValue& theValue,     const SCMBValue& theValue,
     char* base) const      char* base,
       Boolean verbose) const
 { {
    fprintf(_out,"\nValueType : %s",cimTypeToString(theValue.valueType));    fprintf(_out,"\nValueType : %s",cimTypeToString(theValue.valueType));
    fprintf(_out,"\nValue was set by the provider: %s",     fprintf(_out,"\nValue was set: %s",
        (theValue.flags.isSet ? "True" : "False"));        (theValue.flags.isSet ? "True" : "False"));
    if (theValue.flags.isNull)    if (theValue.flags.isNull)
    {    {
        fprintf(_out,"\nIt's a NULL value.");         fprintf(_out,"\nIt's a NULL value.");
        return;         return;
      }
      if (theValue.flags.isArray)
      {
          fprintf(
              _out,
              "\nThe value is an Array of size: %u",
              theValue.valueArraySize);
          printArrayValue(
              theValue.valueType,
              theValue.valueArraySize,
              theValue.value,
              base,
              verbose);
      }
      else
      {
          printUnionValue(theValue.valueType,theValue.value,base,verbose);
      }
   
      return;
   
   }
   
   void SCMODump::dumpKeyPropertyMask(SCMOClass& testCls ) const
   {
   
       SCMBClass_Main* clshdr = testCls.cls.hdr;
       char* clsbase = testCls.cls.base;
   
        Uint64 *theKeyMask = (Uint64*)&(clsbase[clshdr->keyPropertyMask.start]);
        Uint32 end, noProperties = clshdr->propertySet.number;
        Uint32 noMasks = (noProperties-1)/64;
        Uint64 printMask = 1;
   
        for (Uint32 i = 0; i <= noMasks; i++ )
        {
            printMask = 1;
            if (i < noMasks)
            {
                end = 64;
            }
            else
            {
                end = noProperties & 63;
            }
   
            fprintf(_out,"\nkeyPropertyMask[%02u]= ",i);
   
            for (Uint32 j = 0; j < end; j++)
            {
                if (j > 0 && !(j & 7))
                {
                    fprintf(_out," ");
                }
   
                if (theKeyMask[i] & printMask)
                {
                    fprintf(_out,"1");
                }
                else
                {
                    fprintf(_out,"0");
                }
   
                printMask = printMask << 1;
            }
            fprintf(_out,"\n");
        }
   }
   
   void SCMODump::_hexDump(char* buffer,Uint64 length) const
   {
   
       unsigned char printLine[3][80];
       int p;
       int len;
       unsigned char item;
   
       for (Uint64 i = 0; i < length;i=i+1)
       {
           p = (int)i%80;
   
           if ((p == 0 && i > 0) || i == length-1 )
           {
               for (int y = 0; y < 3; y=y+1)
               {
                   if (p == 0)
                   {
                       len = 80;
                   } else
                   {
                       len = p;
                   }
   
                   for (int x = 0; x < len; x=x+1)
                   {
                       if (y == 0)
                       {
                           fprintf(_out,"%c",printLine[y][x]);
    }    }
    if (theValue.flags.isArray)                      else
    {    {
        fprintf(_out,                          fprintf(_out,"%1X",printLine[y][x]);
                "\nThe value is an Array of size: %u",  
                theValue.valueArraySize);  
        fprintf(_out,"\nThe values are: '%s'",  
               (const char*)printArrayValue(  
                   theValue.valueType,  
                   theValue.valueArraySize,  
                   theValue.value,  
                   base).getCString());  
    }    }
    else                  }
                   fprintf(_out,"\n");
               }
               fprintf(_out,"\n");
           }
   
           item = (unsigned char)buffer[i];
   
           if (item < 32 || item > 125 )
    {    {
       fprintf(_out,"\nThe Value is: '%s'",              printLine[0][p] = '.';
           (const char*)          } else
              printUnionValue(theValue.valueType,theValue.value,base)          {
              .getCString());              printLine[0][p] = item;
    }    }
  
    return;          printLine[1][p] = item/16;
           printLine[2][p] = item & 15;
  
 } }
   }
  
 String SCMODump::printArrayValue(  void SCMODump::printArrayValue(
     CIMType type,     CIMType type,
     Uint32 size,     Uint32 size,
     SCMBUnion u,     SCMBUnion u,
     char* base) const      char* base,
       Boolean verbose) const
 { {
     Buffer out;     Buffer out;
  
       SCMBUnion* p;
       p = (SCMBUnion*)&(base[u.arrayValue.start]);
   
     switch (type)     switch (type)
     {     {
     case CIMTYPE_BOOLEAN:     case CIMTYPE_BOOLEAN:
         {         {
             Boolean* p=(Boolean*)&(base[u._arrayValue.start]);  
             for (Uint32 i = 0; i < size; i++)             for (Uint32 i = 0; i < size; i++)
             {             {
                 _toString(out,p[i]);                  out.append('\'');
                 out.append(' ');                  _toString(out,p[i].simple.val.bin);
                   out << STRLIT("\'(hasValue=");
                   out << (p[i].simple.hasValue ?
                             STRLIT("TRUE)"):
                             STRLIT("FALSE)"));
                   out.append(';');
             }             }
               fprintf(_out,"\nThe values are: %s",out.getData());
             break;             break;
         }         }
  
     case CIMTYPE_UINT8:     case CIMTYPE_UINT8:
         {         {
             Uint8* p=(Uint8*)&(base[u._arrayValue.start]);              for (Uint32 i = 0; i < size; i++)
             _toString(out,p,size);              {
                   out.append('\'');
                   _toString(out,p[i].simple.val.u8);
                   out << STRLIT("\'(hasValue=");
                   out << (p[i].simple.hasValue ?
                             STRLIT("TRUE)"):
                             STRLIT("FALSE)"));
                   out.append(';');
               }
               fprintf(_out,"\nThe values are: %s",out.getData());
             break;             break;
         }         }
  
     case CIMTYPE_SINT8:     case CIMTYPE_SINT8:
         {         {
             Sint8* p=(Sint8*)&(base[u._arrayValue.start]);              for (Uint32 i = 0; i < size; i++)
               {
                   out.append('\'');
                   _toString(out,p[i].simple.val.s8);
                   out << STRLIT("\'(hasValue=");
                   out << (p[i].simple.hasValue ?
                             STRLIT("TRUE)"):
                             STRLIT("FALSE)"));
                   out.append(';');
               }
               fprintf(_out,"\nThe values are: %s",out.getData());
             break;             break;
         }         }
  
     case CIMTYPE_UINT16:     case CIMTYPE_UINT16:
         {         {
             Uint16* p=(Uint16*)&(base[u._arrayValue.start]);              for (Uint32 i = 0; i < size; i++)
             _toString(out,p,size);              {
                   out.append('\'');
                   _toString(out,p[i].simple.val.u16);
                   out << STRLIT("\'(hasValue=");
                   out << (p[i].simple.hasValue ?
                             STRLIT("TRUE)"):
                             STRLIT("FALSE)"));
                   out.append(';');
               }
               fprintf(_out,"\nThe values are: %s",out.getData());
             break;             break;
         }         }
  
     case CIMTYPE_SINT16:     case CIMTYPE_SINT16:
         {         {
             Sint16* p=(Sint16*)&(base[u._arrayValue.start]);              for (Uint32 i = 0; i < size; i++)
             _toString(out,p,size);              {
                   out.append('\'');
                   _toString(out,p[i].simple.val.s16);
                   out << STRLIT("\'(hasValue=");
                   out << (p[i].simple.hasValue ?
                             STRLIT("TRUE)"):
                             STRLIT("FALSE)"));
                   out.append(';');
               }
               fprintf(_out,"\nThe values are: %s",out.getData());
             break;             break;
         }         }
  
     case CIMTYPE_UINT32:     case CIMTYPE_UINT32:
         {         {
             Uint32* p=(Uint32*)&(base[u._arrayValue.start]);              for (Uint32 i = 0; i < size; i++)
             _toString(out,p,size);              {
                   out.append('\'');
                   _toString(out,p[i].simple.val.u32);
                   out << STRLIT("\'(hasValue=");
                   out << (p[i].simple.hasValue ?
                             STRLIT("TRUE)"):
                             STRLIT("FALSE)"));
                   out.append(';');
               }
               fprintf(_out,"\nThe values are: %s",out.getData());
             break;             break;
         }         }
  
     case CIMTYPE_SINT32:     case CIMTYPE_SINT32:
         {         {
             Sint32* p=(Sint32*)&(base[u._arrayValue.start]);              for (Uint32 i = 0; i < size; i++)
             _toString(out,p,size);              {
                   out.append('\'');
                   _toString(out,p[i].simple.val.s32);
                   out << STRLIT("\'(hasValue=");
                   out << (p[i].simple.hasValue ?
                             STRLIT("TRUE)"):
                             STRLIT("FALSE)"));
                   out.append(';');
               }
               fprintf(_out,"\nThe values are: %s",out.getData());
             break;             break;
         }         }
  
     case CIMTYPE_UINT64:     case CIMTYPE_UINT64:
         {         {
             Uint64* p=(Uint64*)&(base[u._arrayValue.start]);              for (Uint32 i = 0; i < size; i++)
             _toString(out,p,size);              {
                   out.append('\'');
                   _toString(out,p[i].simple.val.u64);
                   out << STRLIT("\'(hasValue=");
                   out << (p[i].simple.hasValue ?
                             STRLIT("TRUE)"):
                             STRLIT("FALSE)"));
                   out.append(';');
               }
               fprintf(_out,"\nThe values are: %s",out.getData());
             break;             break;
         }         }
  
     case CIMTYPE_SINT64:     case CIMTYPE_SINT64:
         {         {
             Sint64* p=(Sint64*)&(base[u._arrayValue.start]);              for (Uint32 i = 0; i < size; i++)
             _toString(out,p,size);              {
                   out.append('\'');
                   _toString(out,p[i].simple.val.s64);
                   out << STRLIT("\'(hasValue=");
                   out << (p[i].simple.hasValue ?
                             STRLIT("TRUE)"):
                             STRLIT("FALSE)"));
                   out.append(';');
               }
               fprintf(_out,"\nThe values are: %s",out.getData());
             break;             break;
         }         }
  
     case CIMTYPE_REAL32:     case CIMTYPE_REAL32:
         {         {
             Real32* p=(Real32*)&(base[u._arrayValue.start]);              for (Uint32 i = 0; i < size; i++)
             _toString(out,p,size);              {
                   out.append('\'');
                   _toString(out,p[i].simple.val.r32);
                   out << STRLIT("\'(hasValue=");
                   out << (p[i].simple.hasValue ?
                             STRLIT("TRUE)"):
                             STRLIT("FALSE)"));
                   out.append(';');
               }
               fprintf(_out,"\nThe values are: %s",out.getData());
             break;             break;
         }         }
  
     case CIMTYPE_REAL64:     case CIMTYPE_REAL64:
         {         {
             Real64* p=(Real64*)&(base[u._arrayValue.start]);              for (Uint32 i = 0; i < size; i++)
             _toString(out,p,size);              {
                   out.append('\'');
                   _toString(out,p[i].simple.val.r64);
                   out << STRLIT("\'(hasValue=");
                   out << (p[i].simple.hasValue ?
                             STRLIT("TRUE)"):
                             STRLIT("FALSE)"));
                   out.append(';');
               }
               fprintf(_out,"\nThe values are: %s",out.getData());
             break;             break;
         }         }
  
     case CIMTYPE_CHAR16:     case CIMTYPE_CHAR16:
         {         {
             Char16* p=(Char16*)&(base[u._arrayValue.start]);              for (Uint32 i = 0; i < size; i++)
             _toString(out,p,size);              {
                   out.append('\'');
                   _toString(out,p[i].simple.val.c16);
                   out << STRLIT("\'(hasValue=");
                   out << (p[i].simple.hasValue ?
                             STRLIT("TRUE)"):
                             STRLIT("FALSE)"));
                   out.append(';');
               }
               fprintf(_out,"\nThe values are: %s",out.getData());
             break;             break;
         }         }
  
     case CIMTYPE_STRING:     case CIMTYPE_STRING:
         {         {
             SCMBDataPtr* p = (SCMBDataPtr*)&(base[u._arrayValue.start]);  
             for (Uint32 i = 0; i < size; i++)             for (Uint32 i = 0; i < size; i++)
             {             {
                 out.append((const char*)_getCharString(p[i],base),                  if ( 0 != p[i].stringValue.size)
                            p[i].length-1);                  {
                 out.append(' ');                      out.append('\'');
                       out.append(
                           (const char*)_getCharString(p[i].stringValue,base),
                           p[i].stringValue.size-1);
                       out.append('\'');
                   }
                   else
                   {
                     out << STRLIT("NULL;");
             }             }
                   out.append(';');
               }
               fprintf(_out,"\nThe values are: %s",out.getData());
             break;             break;
         }         }
  
     case CIMTYPE_DATETIME:     case CIMTYPE_DATETIME:
         {         {
             SCMBDateTime* p = (SCMBDateTime*)&(base[u._arrayValue.start]);  
             CIMDateTime x;             CIMDateTime x;
             for (Uint32 i = 0; i < size; i++)             for (Uint32 i = 0; i < size; i++)
             {             {
                 memcpy(x._rep,&(p[i]),sizeof(SCMBDateTime));                  memcpy(x._rep,&(p[i].dateTimeValue),sizeof(SCMBDateTime));
                 _toString(out,x);                 _toString(out,x);
                 out.append(' ');                 out.append(' ');
             }             }
               fprintf(_out,"\nThe values are: %s",out.getData());
             break;             break;
         }         }
  
     case CIMTYPE_REFERENCE:     case CIMTYPE_REFERENCE:
       case CIMTYPE_OBJECT:
       case CIMTYPE_INSTANCE:
         {         {
             break;              if (verbose)
               {
                   for (Uint32 i = 0; i < size; i++)
                   {
                       fprintf(_out,"\n-----------> "
                                     "Start of embedded external reference [%d]"
                                     " <-----------\n\n",i);
                       dumpSCMOInstance(*(p[i].extRefPtr));
                       fprintf(_out,"\n-----------> "
                                     "End of embedded external reference [%d]"
                                     " <-----------\n\n",i);
         }         }
  
     case CIMTYPE_OBJECT:              } else
         {         {
             break;                  fprintf(_out,"\nThe values are: ");
         }  
  
     case CIMTYPE_INSTANCE:                  for (Uint32 i = 0; i < size; i++)
         {         {
                       fprintf(
                           _out,
                           "Pointer to external Reference[%d] : \'%p\';",
                           i,p[i].extRefPtr);
                   }
               }
   
             break;             break;
   
         }         }
     default:     default:
         {         {
             PEGASUS_ASSERT(0);              PEGASUS_ASSERT(false);
               break;
         }         }
     }     }
  
     return out.getData();      return;
 } }
  
 String SCMODump::printUnionValue(  void SCMODump::printUnionValue(
     CIMType type,     CIMType type,
     SCMBUnion u,     SCMBUnion u,
     char* base) const      char* base,
       Boolean verbose) const
 { {
   
     Buffer out;     Buffer out;
  
     switch (type)     switch (type)
     {     {
     case CIMTYPE_BOOLEAN:     case CIMTYPE_BOOLEAN:
         {         {
             _toString(out,u._booleanValue);              _toString(out,u.simple.val.bin);
               fprintf(_out,"\nThe Value is: '%s'",out.getData());
             break;             break;
         }         }
  
     case CIMTYPE_UINT8:     case CIMTYPE_UINT8:
         {         {
             _toString(out,u._uint8Value);              _toString(out,u.simple.val.u8);
               fprintf(_out,"\nThe Value is: '%s'",out.getData());
             break;             break;
         }         }
  
     case CIMTYPE_SINT8:     case CIMTYPE_SINT8:
         {         {
             _toString(out,u._sint8Value);              _toString(out,u.simple.val.s8);
               fprintf(_out,"\nThe Value is: '%s'",out.getData());
             break;             break;
         }         }
  
     case CIMTYPE_UINT16:     case CIMTYPE_UINT16:
         {         {
             _toString(out,(Uint32)u._uint16Value);              _toString(out,(Uint32)u.simple.val.u16);
               fprintf(_out,"\nThe Value is: '%s'",out.getData());
             break;             break;
         }         }
  
     case CIMTYPE_SINT16:     case CIMTYPE_SINT16:
         {         {
             _toString(out,u._sint16Value);              _toString(out,u.simple.val.s16);
               fprintf(_out,"\nThe Value is: '%s'",out.getData());
             break;             break;
         }         }
  
     case CIMTYPE_UINT32:     case CIMTYPE_UINT32:
         {         {
             _toString(out,u._uint32Value);              _toString(out,u.simple.val.u32);
               fprintf(_out,"\nThe Value is: '%s'",out.getData());
             break;             break;
         }         }
  
     case CIMTYPE_SINT32:     case CIMTYPE_SINT32:
         {         {
             _toString(out,u._sint32Value);              _toString(out,u.simple.val.s32);
               fprintf(_out,"\nThe Value is: '%s'",out.getData());
             break;             break;
         }         }
  
     case CIMTYPE_UINT64:     case CIMTYPE_UINT64:
         {         {
             _toString(out,u._uint64Value);              _toString(out,u.simple.val.u64);
               fprintf(_out,"\nThe Value is: '%s'",out.getData());
             break;             break;
         }         }
  
     case CIMTYPE_SINT64:     case CIMTYPE_SINT64:
         {         {
             _toString(out,u._sint64Value);              _toString(out,u.simple.val.s64);
               fprintf(_out,"\nThe Value is: '%s'",out.getData());
             break;             break;
         }         }
  
     case CIMTYPE_REAL32:     case CIMTYPE_REAL32:
         {         {
             _toString(out,u._real32Value);              _toString(out,u.simple.val.r32);
               fprintf(_out,"\nThe Value is: '%s'",out.getData());
             break;             break;
         }         }
  
     case CIMTYPE_REAL64:     case CIMTYPE_REAL64:
         {         {
             _toString(out,u._real32Value);              _toString(out,u.simple.val.r32);
               fprintf(_out,"\nThe Value is: '%s'",out.getData());
             break;             break;
         }         }
  
     case CIMTYPE_CHAR16:     case CIMTYPE_CHAR16:
         {         {
             _toString(out,u._char16Value);              _toString(out,u.simple.val.c16);
               fprintf(_out,"\nThe Value is: '%s'",out.getData());
             break;             break;
         }         }
  
     case CIMTYPE_STRING:     case CIMTYPE_STRING:
         {         {
             out.append((const char*)_getCharString(u._stringValue,base),              if ( 0 != u.stringValue.size)
                        u._stringValue.length-1);              {
                   out.append((const char*)_getCharString(u.stringValue,base),
                              u.stringValue.size-1);
               }
               fprintf(_out,"\nThe Value is: '%s'",out.getData());
             break;             break;
         }         }
  
     case CIMTYPE_DATETIME:     case CIMTYPE_DATETIME:
         {         {
             CIMDateTime x;             CIMDateTime x;
             memcpy(x._rep,&(u._dateTimeValue),sizeof(SCMBDateTime));              memcpy(x._rep,&(u.dateTimeValue),sizeof(SCMBDateTime));
             _toString(out,x);             _toString(out,x);
               fprintf(_out,"\nThe Value is: '%s'",out.getData());
             break;             break;
         }         }
  
     case CIMTYPE_REFERENCE:     case CIMTYPE_REFERENCE:
         {  
             break;  
         }  
   
     case CIMTYPE_OBJECT:     case CIMTYPE_OBJECT:
         {  
             break;  
         }  
   
     case CIMTYPE_INSTANCE:     case CIMTYPE_INSTANCE:
         {         {
             break;              if (verbose)
         }  
     default:  
         {  
             PEGASUS_ASSERT(0);  
         }  
     }  
   
   return out.getData();  
 }  
   
 void SCMODump::dumpKeyPropertyMask(SCMOClass& testCls ) const  
 {  
   
     SCMBClass_Main* clshdr = testCls.cls.hdr;  
     char* clsbase = testCls.cls.base;  
   
      Uint64 *theKeyMask = (Uint64*)&(clsbase[clshdr->keyPropertyMask.start]);  
      Uint32 end, noProperties = clshdr->propertySet.number;  
      Uint32 noMasks = (noProperties-1)/64;  
      Uint64 printMask = 1;  
   
      for (Uint32 i = 0; i <= noMasks; i++ )  
      {  
          printMask = 1;  
          if (i < noMasks)  
          {  
              end = 64;  
          }  
          else  
          {  
              end = noProperties%64;  
          }  
   
          fprintf(_out,"\nkeyPropertyMask[%02u]= ",i);  
   
          for (Uint32 j = 0; j < end; j++)  
          {  
              if (j > 0 && !(j%8))  
              {  
                  fprintf(_out," ");  
              }  
   
              if (theKeyMask[i] & printMask)  
              {  
                  fprintf(_out,"1");  
              }  
              else  
              {  
                  fprintf(_out,"0");  
              }  
   
              printMask = printMask << 1;  
          }  
          fprintf(_out,"\n");  
      }  
 }  
   
 void SCMODump::_hexDump(char* buffer,int length) const  
 {  
   
     unsigned char printLine[3][80];  
     int p;  
     int len;  
     unsigned char item;  
   
     for (int i = 0; i < length;i=i+1)  
     {  
         p = i%80;  
   
         if ((p == 0 && i > 0) || i == length-1 )  
         {  
             for (int y = 0; y < 3; y=y+1)  
             {  
                 if (p == 0)  
                 {                 {
                     len = 80;                  fprintf(_out,"\n-----------> "
                                 "Start of embedded external reference"
                                 " <-----------\n\n");
                   dumpSCMOInstance(*u.extRefPtr);
                   fprintf(_out,"\n-----------> "
                                "End of embedded external reference"
                                " <-----------\n\n");
                 } else                 } else
                 {                 {
                     len = p;                  fprintf(
                       _out,
                       "Pointer to external Reference : \'%p\'",
                       u.extRefPtr);
                 }                 }
  
                 for (int x = 0; x < len; x=x+1)              break;
                 {  
                     if (y == 0)  
                     {  
                         fprintf(_out,"%c",printLine[y][x]);  
                     }                     }
                     else      default:
                     {                     {
                         fprintf(_out,"%1X",printLine[y][x]);              PEGASUS_ASSERT(false);
                     }              break;
                 }  
                 fprintf(_out,"\n");  
             }             }
             fprintf(_out,"\n");  
         }         }
  
         item = (unsigned char)buffer[i];    return;
   
         if (item < 32 || item > 125 )  
         {  
             printLine[0][p] = '.';  
         } else  
         {  
             printLine[0][p] = item;  
         }         }
   #endif // PEGASUS_DEBUG (class SCMODump only in debug builds available)
  
         printLine[1][p] = item/16;  
         printLine[2][p] = item%16;  
   
     }  
 }  
  
 /***************************************************************************** /*****************************************************************************
  * The constant functions  * The constant functions
  *****************************************************************************/  *****************************************************************************/
  
 static const void* _resolveDataPtr(  #ifdef PEGASUS_HAS_ICU
     const SCMBDataPtr& ptr,  Uint32 _utf8ICUncasecmp(
     char* base)      const char* a,
       const char* b,
       Uint32 len)
 { {
     return ((ptr.start==(Uint64)0 ? NULL : (void*)&(base[ptr.start])));      UErrorCode errorCode=U_ZERO_ERROR;
 }  
  
 PEGASUS_COMMON_LINKAGE const char* _getCharString(      Uint32 rc, a16len,b16len,utf16BufLen;
     const SCMBDataPtr& ptr,      utf16BufLen = (len*sizeof(UChar))+2;
     char* base)  
 {  
     return ((ptr.start==(Uint64)0 ? NULL : &(base[ptr.start])));  
 }  
  
       UChar* a_UTF16 = (UChar*)malloc(utf16BufLen);
       UChar* b_UTF16 = (UChar*)malloc(utf16BufLen);
  
 static Uint32 _generateSCMOStringTag(      UConverter *conv = ucnv_open(0, &errorCode);
     const SCMBDataPtr& ptr,      if(U_FAILURE(errorCode))
     char* base)  
 { {
     // The lenght of a SCMBDataPtr to a UTF8 string includs the trailing '\0'.          free(a_UTF16);
     return _generateStringTag(_getCharString(ptr,base),ptr.length-1);          free(b_UTF16);
           String message("SCMO::_utf8ICUncasecmp() ICUError: ");
           message.append(u_errorName(errorCode));
           message.append(" Can not open ICU default converter!");
           throw CIMException(CIM_ERR_FAILED,message );
 } }
  
 static Uint32 _generateStringTag(const char* str, Uint32 len)      a16len = ucnv_toUChars(conv,a_UTF16,utf16BufLen,a,len,&errorCode);
 {  
     if (len == 0)      if(U_FAILURE(errorCode))
     {     {
         return 0;          free(a_UTF16);
     }          free(b_UTF16);
     return          ucnv_close(conv);
         (Uint32(CharSet::toUpperHash(str[0]) << 1) |          String message("SCMO::_utf8ICUncasecmp() ICUError: ");
         Uint32(CharSet::toUpperHash(str[len-1])));          message.append(u_errorName(errorCode));
           message.append(" Can not convert string a:'");
           message.append(String(a,len));
           message.append('\'');
           throw CIMException(CIM_ERR_FAILED,message );
 } }
  
 static CIMKeyBinding::Type _cimTypeToKeyBindType(CIMType cimType)      b16len = ucnv_toUChars(conv,b_UTF16,utf16BufLen,b,len,&errorCode);
 {  
     switch (cimType)      if(U_FAILURE(errorCode))
     {     {
     case CIMTYPE_BOOLEAN:          free(a_UTF16);
         return(CIMKeyBinding::BOOLEAN);          free(b_UTF16);
         break;          ucnv_close(conv);
     case CIMTYPE_CHAR16:          String message("SCMO::_utf8ICUncasecmp() ICUError: ");
     case CIMTYPE_STRING:          message.append(u_errorName(errorCode));
     case CIMTYPE_DATETIME:          message.append(" Can not convert string b:'");
         return(CIMKeyBinding::STRING);          message.append(String(b,len));
         break;          message.append('\'');
     case CIMTYPE_REFERENCE:          throw CIMException(CIM_ERR_FAILED,message );
         return(CIMKeyBinding::REFERENCE);  
         break;  
     case CIMTYPE_OBJECT:  
     case CIMTYPE_INSTANCE:  
         // From PEP 194: EmbeddedObjects cannot be keys.  
         throw TypeMismatchException();  
         break;  
     default:  
         return(CIMKeyBinding::NUMERIC);  
         break;  
     }  
 } }
  
 static Boolean _equalUTF8Strings(      rc = u_strCaseCompare(
     const SCMBDataPtr& ptr_a,          a_UTF16,a16len,
     char* base,          b_UTF16,b16len,
     const char* name,          U_FOLD_CASE_DEFAULT,
     Uint32 len)          &errorCode);
  
       if(U_FAILURE(errorCode))
 { {
     // size without trailing '\0' !!          free(a_UTF16);
     if (ptr_a.length-1 != len)          free(b_UTF16);
     {          ucnv_close(conv);
         return false;          String message("SCMO::_utf8ICUncasecmp() ICUError: ");
           message.append(u_errorName(errorCode));
           message.append(" Can not compare string a:'");
           message.append(String(a,len));
           message.append("' with b: '");
           message.append(String(b,len));
           message.append('\'');
           throw CIMException(CIM_ERR_FAILED,message );
     }     }
  
     const char* a = (const char*)_getCharString(ptr_a,base);      free(a_UTF16);
       free(b_UTF16);
     // ToDo: Here an UTF8 complinet comparison should take place      ucnv_close(conv);
     return ( strncmp(a,name,len )== 0 );  
  
       return(rc);
 } }
   #endif
  
 /** /**
  * This function calcutates a free memory slot in the single chunk memory block.  * This function calcutates a free memory slot in the single chunk memory block.
Line 3433 
Line 6481 
  *            e.g. &cls.mem  *            e.g. &cls.mem
  * @return The relaive index of the free memory slot.  * @return The relaive index of the free memory slot.
  */  */
   Uint64 _getFreeSpace(
 static Uint64 _getFreeSpace(  
     SCMBDataPtr& ptr,     SCMBDataPtr& ptr,
     Uint64 size,      Uint32 size,
     SCMBMgmt_Header** pmem,      SCMBMgmt_Header** pmem)
     Boolean clear)  
 { {
     Uint64 oldSize, start;     Uint64 oldSize, start;
       Uint64 alignedStart, reqAlignSize;
  
     if (size == 0)     if (size == 0)
     {     {
         ptr.start = 0;         ptr.start = 0;
         ptr.length = 0;          ptr.size = 0;
         return 0;         return 0;
     }     }
  
     // The SCMBDataPtr has to be set before any reallocation.     // The SCMBDataPtr has to be set before any reallocation.
     start = (*pmem)->startOfFreeSpace;     start = (*pmem)->startOfFreeSpace;
     ptr.start = start;  
     ptr.length = size;  
  
     while ((*pmem)->freeBytes < size)      // Need to align the start of freespace to 8 byte
       // boundaries to avoid alignment issues on some architectures
       // Round up to nearest multiple of 8
       alignedStart = (start + 7) & ~7;
       // due to the alignment, a little more room is needed in the SCMB
       reqAlignSize = (size + alignedStart - start);
   
       ptr.start = alignedStart;
       ptr.size = size;
       // add 8 bytes of size for later alignment on the next pointer
       while ((*pmem)->freeBytes < reqAlignSize)
     {     {
         // save old size of buffer         // save old size of buffer
         oldSize = (*pmem)->totalSize;         oldSize = (*pmem)->totalSize;
         // reallocate the buffer, double the space !         // reallocate the buffer, double the space !
         // This is a working approach until a better algorithm is found.         // This is a working approach until a better algorithm is found.
         (*pmem) = (SCMBMgmt_Header*)realloc((*pmem),oldSize*2);          void* newBlockPtr = realloc((*pmem),(size_t)oldSize*2);
         if ((*pmem) == NULL)          if ((newBlockPtr) == 0)
         {         {
             // Not enough memory!             // Not enough memory!
             throw PEGASUS_STD(bad_alloc)();             throw PEGASUS_STD(bad_alloc)();
         }         }
           (*pmem) = (SCMBMgmt_Header*)newBlockPtr;
         // increase the total size and free space         // increase the total size and free space
         (*pmem)->freeBytes= (*pmem)->freeBytes + oldSize;          (*pmem)->freeBytes+=oldSize;
         (*pmem)->totalSize= (*pmem)->totalSize + oldSize;          (*pmem)->totalSize+=oldSize;
     }     }
  
     (*pmem)->freeBytes = (*pmem)->freeBytes - size;      (*pmem)->freeBytes -= reqAlignSize;
     (*pmem)->startOfFreeSpace = (*pmem)->startOfFreeSpace + size;      (*pmem)->startOfFreeSpace = alignedStart + size;
  
     if (clear)      // Init memory from unaligned start up to the size required with alignment
     {      // to zero.
         // If requested, set memory to 0.      memset(&((char*)(*pmem))[start],0,(size_t)reqAlignSize);
         memset(&((char*)(*pmem))[start],0,size);      PEGASUS_DEBUG_ASSERT(
     }          ((*pmem)->freeBytes+(*pmem)->startOfFreeSpace) == (*pmem)->totalSize);
     return start;  
       return alignedStart;
 } }
  
 static void _setString(  void _setString(
     const String& theString,     const String& theString,
     SCMBDataPtr& ptr,     SCMBDataPtr& ptr,
     SCMBMgmt_Header** pmem)     SCMBMgmt_Header** pmem)
Line 3493 
Line 6550 
     // Get the real size of the UTF8 sting + \0.     // Get the real size of the UTF8 sting + \0.
     // It maybe greater then the length in the String due to     // It maybe greater then the length in the String due to
     // 4 byte encoding of non ASCII chars.     // 4 byte encoding of non ASCII chars.
     Uint64 start,length = strlen((const char*)theCString)+1;      Uint64 start;
       Uint32 length = strlen((const char*)theCString)+1;
  
     // If the string is not empty.     // If the string is not empty.
     if (length != 1)     if (length != 1)
Line 3509 
Line 6567 
     else     else
     {     {
         ptr.start = 0;         ptr.start = 0;
         ptr.length = 0;          ptr.size = 0;
     }     }
 } }
  
 static void _setBinary(  void _setBinary(
     const void* theBuffer,     const void* theBuffer,
     Uint64 bufferSize,      Uint32 bufferSize,
     SCMBDataPtr& ptr,     SCMBDataPtr& ptr,
     SCMBMgmt_Header** pmem)     SCMBMgmt_Header** pmem)
 { {
  
     // If buffer is not empty.     // If buffer is not empty.
     if (bufferSize != 1)      if (bufferSize != 0 && theBuffer != 0)
     {     {
  
         Uint64 start;         Uint64 start;
Line 3538 
Line 6596 
     else     else
     {     {
         ptr.start = 0;         ptr.start = 0;
         ptr.length = 0;          ptr.size = 0;
       }
     }     }
   
   void _destroyExternalReferencesInternal(SCMBMgmt_Header* memHdr)
   {
   
       Uint32 number = memHdr->numberExtRef;
   
       if (0 != number)
       {
           char * base = ((char*)memHdr);
           Uint64* array =
               (Uint64*)&(base[memHdr->extRefIndexArray.start]);
           for (Uint32 i = 0; i < number; i++)
           {
                delete ((SCMBUnion*)(&(base[array[i]])))->extRefPtr;
 } }
  
       }
   }
  
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END


Legend:
Removed from v.1.2.2.8  
changed lines
  Added in v.1.24

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2