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

Diff for /pegasus/src/Pegasus/Common/CIMClassRep.cpp between version 1.7 and 1.29

version 1.7, 2001/04/29 18:57:33 version 1.29, 2002/03/25 16:27:51
Line 1 
Line 1 
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
 // //
 // Copyright (c) 2000 The Open Group, BMC Software, Tivoli Systems, IBM  // Copyright (c) 2000, 2001 The Open group, BMC Software, Tivoli Systems, IBM
 // //
 // Permission is hereby granted, free of charge, to any person obtaining a  // Permission is hereby granted, free of charge, to any person obtaining a copy
 // copy of this software and associated documentation files (the "Software"),  // of this software and associated documentation files (the "Software"), to
 // to deal in the Software without restriction, including without limitation  // deal in the Software without restriction, including without limitation the
 // the rights to use, copy, modify, merge, publish, distribute, sublicense,  // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 // and/or sell copies of the Software, and to permit persons to whom the  // sell copies of the Software, and to permit persons to whom the Software is
 // Software is furnished to do so, subject to the following conditions:  // furnished to do so, subject to the following conditions:
 // //
 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL  // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER  // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING  // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER  // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 // DEALINGS IN THE SOFTWARE.  // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
   // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 // //
 //============================================================================== //==============================================================================
 // //
Line 33 
Line 34 
 #include "XmlWriter.h" #include "XmlWriter.h"
  
 PEGASUS_NAMESPACE_BEGIN PEGASUS_NAMESPACE_BEGIN
   PEGASUS_USING_STD;
  
 CIMClassRep::CIMClassRep( CIMClassRep::CIMClassRep(
     const String& className,      const CIMReference& reference,
     const String& superClassName)     const String& superClassName)
     : _className(className), _superClassName(superClassName), _resolved(false)      :
       CIMObjectRep(reference),
       _superClassName(superClassName)
 { {
     if (!CIMName::legal(className))  
         throw IllegalName();  
   
     if (superClassName.size() && !CIMName::legal(superClassName))     if (superClassName.size() && !CIMName::legal(superClassName))
         throw IllegalName();         throw IllegalName();
 } }
Line 55 
Line 56 
 { {
     Uint32 pos = findQualifier(CIMQualifierNames::ASSOCIATION);     Uint32 pos = findQualifier(CIMQualifierNames::ASSOCIATION);
  
     if (pos == Uint32(-1))      if (pos == PEG_NOT_FOUND)
         return false;         return false;
  
     Boolean flag;     Boolean flag;
Line 73 
Line 74 
 { {
     Uint32 pos = findQualifier(CIMQualifierNames::ABSTRACT);     Uint32 pos = findQualifier(CIMQualifierNames::ABSTRACT);
  
     if (pos == Uint32(-1))      if (pos == PEG_NOT_FOUND)
         return false;         return false;
  
     Boolean flag;     Boolean flag;
Line 101 
Line 102 
  
     // Reject addition of duplicate property name:     // Reject addition of duplicate property name:
  
     if (findProperty(x.getName()) != Uint32(-1))      if (findProperty(x.getName()) != PEG_NOT_FOUND)
         throw AlreadyExists();         throw AlreadyExists();
  
     // Reject addition of references to non-associations:     // Reject addition of references to non-associations:
  
     if (!isAssociation() && x.getValue().getType() == CIMType::REFERENCE)     if (!isAssociation() && x.getValue().getType() == CIMType::REFERENCE)
         throw AddedReferenceToClass(_className);          throw AddedReferenceToClass(_reference.getClassName());
  
     // Set the class origin:     // Set the class origin:
     // ATTN: put this check in other places:     // ATTN: put this check in other places:
  
     if (x.getClassOrigin().size() == 0)     if (x.getClassOrigin().size() == 0)
         CIMProperty(x).setClassOrigin(_className);          CIMProperty(x).setClassOrigin(_reference.getClassName());
  
     // Add the property:     // Add the property:
  
     _properties.append(x);     _properties.append(x);
 } }
  
 void CIMClassRep::removeProperty(Uint32 pos)  
 {  
     if (pos >= _properties.size())  
         throw OutOfBounds();  
 }  
   
 Uint32 CIMClassRep::findProperty(const String& name)  
 {  
     for (Uint32 i = 0, n = _properties.size(); i < n; i++)  
     {  
         if (CIMName::equal(_properties[i].getName(), name))  
             return i;  
     }  
   
     return Uint32(-1);  
 }  
   
 CIMProperty CIMClassRep::getProperty(Uint32 pos)  
 {  
     if (pos >= _properties.size())  
         throw OutOfBounds();  
   
     return _properties[pos];  
 }  
   
 Uint32 CIMClassRep::getPropertyCount() const  
 {  
     return _properties.size();  
 }  
   
 void CIMClassRep::addMethod(const CIMMethod& x) void CIMClassRep::addMethod(const CIMMethod& x)
 { {
     if (!x)     if (!x)
Line 157 
Line 128 
  
     // Reject duplicate method names:     // Reject duplicate method names:
  
     if (findMethod(x.getName()) != Uint32(-1))      if (findMethod(x.getName()) != PEG_NOT_FOUND)
         throw AlreadyExists();         throw AlreadyExists();
  
     // Add the method:     // Add the method:
Line 173 
Line 144 
             return i;             return i;
     }     }
  
     return Uint32(-1);      return PEG_NOT_FOUND;
   }
   
   Boolean CIMClassRep::existsMethod(const String& name)
   {
       return(findMethod(name) == PEG_NOT_FOUND) ? false : true;
 } }
  
 CIMMethod CIMClassRep::getMethod(Uint32 pos) CIMMethod CIMClassRep::getMethod(Uint32 pos)
Line 189 
Line 165 
     return _methods.size();     return _methods.size();
 } }
  
   void CIMClassRep::removeMethod(Uint32 pos)
   {
       if (pos >= _methods.size())
           throw OutOfBounds();
   
       _methods.remove(pos);
   }
   
 void CIMClassRep::resolve( void CIMClassRep::resolve(
     DeclContext* context,     DeclContext* context,
     const String& nameSpace)     const String& nameSpace)
 { {
 #if 0 #if 0
     if (_resolved)     if (_resolved)
         throw ClassAlreadyResolved(_className);          throw ClassAlreadyResolved(_reference.getClassName());
 #endif #endif
   
     if (!context)     if (!context)
         throw NullPointer();         throw NullPointer();
  
     if (_superClassName.size())     if (_superClassName.size())
     {     {
                   //cout << "KSTEST Class Resolve with Super class " << getClassName()
                   //<< " superClass " << _superClassName << endl;
         //----------------------------------------------------------------------         //----------------------------------------------------------------------
         // First check to see if the super-class really exists:                  // First check to see if the super-class really exists and the subclassing legal:
         //----------------------------------------------------------------------         //----------------------------------------------------------------------
   
         CIMConstClass superClass         CIMConstClass superClass
             = context->lookupClass(nameSpace, _superClassName);             = context->lookupClass(nameSpace, _superClassName);
  
         if (!superClass)         if (!superClass)
             throw NoSuchSuperClass(_superClassName);                          throw PEGASUS_CIM_EXCEPTION(CIM_ERR_INVALID_SUPERCLASS,_superClassName);
  
 #if 0 #if 0
         if (!superClass._rep->_resolved)         if (!superClass._rep->_resolved)
             throw ClassNotResolved(_superClassName);             throw ClassNotResolved(_superClassName);
 #endif #endif
                   // If subclass is abstract but superclass not, throw CIM Exception
  
                   /* ATTN:KS-24 Mar 2002 P1 - Test this and confirm that rule is correct
                   if isAbstract() && !superclass.isAbstract()
                           throw PEGASUS_CIM_EXCEPTION(CIM_ERR_INVALID_SUPERCLASS,_superClassName);
                   */
         //----------------------------------------------------------------------         //----------------------------------------------------------------------
         // Iterate all the properties of *this* class. Resolve each one and         // Iterate all the properties of *this* class. Resolve each one and
         // set the class-origin:         // set the class-origin:
Line 228 
Line 217 
             CIMProperty& property = _properties[i];             CIMProperty& property = _properties[i];
             Uint32 pos = superClass.findProperty(property.getName());             Uint32 pos = superClass.findProperty(property.getName());
  
             if (pos == Uint32(-1))                          if (pos == PEG_NOT_FOUND)
             {             {
                 property.resolve(context, nameSpace, false);                                  property.resolve(context, nameSpace, false, true);
             }             }
             else             else
             {             {
                 CIMConstProperty superClassProperty = superClass.getProperty(pos);                                  CIMConstProperty superClassProperty =
                 property.resolve(context, nameSpace, false, superClassProperty);                                  superClass.getProperty(pos);
                                   property.resolve(
                                           context, nameSpace, false, superClassProperty, true);
             }             }
         }         }
  
Line 254 
Line 245 
             // insert it (setting the propagated flag). Otherwise, change             // insert it (setting the propagated flag). Otherwise, change
             // the class-origin and propagated flag accordingly.             // the class-origin and propagated flag accordingly.
  
             Uint32 pos = Uint32(-1);                          Uint32 pos = PEG_NOT_FOUND;
                           /*       ATTN: KS move to simpler version of the find
             for (Uint32 j = m, n = _properties.size(); j < n; j++)             for (Uint32 j = m, n = _properties.size(); j < n; j++)
             {             {
                 if (CIMName::equal(                                  if (CIMName::equal(_properties[j].getName(),
                     _properties[j].getName(),  
                     superClassProperty.getName()))                     superClassProperty.getName()))
                 {                 {
                     pos = j;                     pos = j;
                     break;                     break;
                 }                 }
             }             }
                           */
                           pos = findProperty(superClassProperty.getName());
  
             // If property exists in super class but not in this one, then             // If property exists in super class but not in this one, then
             // clone and insert it. Otherwise, the properties class             // clone and insert it. Otherwise, the properties class
             // origin was set above.             // origin was set above.
  
             if (pos == Uint32(-1))                          CIMProperty superproperty = superClassProperty.clone(true);
   
                           if (pos == PEG_NOT_FOUND)
             {             {
                 CIMProperty property = superClassProperty.clone();                                  superproperty.setPropagated(true);
                 property.setPropagated(true);                                  _properties.insert(m++, superproperty);
                 _properties.insert(m++, property);                          }
                           else
                           {
                                   // Property Qualifiers must propagate if allowed
                                   // If property exists in the superclass and in the subclass,
                                   // then, enumerate the qualifiers of the superclass's property.
                                   // If a qualifier is defined on the superclass's property
                                   // but not on the subclass's, then add it to the subclass's
                                   // property's qualifier list.
                                   CIMProperty subproperty = _properties[pos];
                                   for (Uint32 i = 0, n = superproperty.getQualifierCount();
                                           i < n; i++)
                                   {
                                           Uint32 pos = PEG_NOT_FOUND;
                                           CIMQualifier superClassQualifier =
                                                                                           superproperty.getQualifier(i);
                                           const String name = superClassQualifier.getName();
                                           /* ATTN KS This is replacement find function.
                                           if((Uint32 j = subproperty.findQualifier(q.getName()) == PEG_NOT_FOUND)
                                           {
                                                   subproperty.addQualifier(superClassQualifier);
   
                                           }
                                           */
                                           for (Uint32 j = 0, m = subproperty.getQualifierCount();
                                                    j < m;
                                                    j++)
                                           {
                                                   CIMConstQualifier q = subproperty.getQualifier(j);
                                                   if (CIMName::equal(name,
                                                              q.getName()))
                                                   {
                                                           pos = j;
                                                           break;
                                                   }
                                           }  // end comparison of subclass property's qualifiers
                                           if (pos == PEG_NOT_FOUND)
                                           {
                                                   subproperty.addQualifier(superClassQualifier);
                                           }
                                           /*
                                           if ((pos = subproperty.findQualifier(name)) == PEG_NOT_FOUND)
                                           {
                                                   subproperty.addQualifier(superClassQualifier);
                                           }
                                           */
                                   } // end iteration over superclass property's qualifiers
             }             }
         }         }
  
Line 289 
Line 329 
             CIMMethod& method = _methods[i];             CIMMethod& method = _methods[i];
             Uint32 pos = superClass.findMethod(method.getName());             Uint32 pos = superClass.findMethod(method.getName());
  
             if (pos == Uint32(-1))                          if (pos == PEG_NOT_FOUND)
             {             {
                 method.resolve(context, nameSpace);                 method.resolve(context, nameSpace);
             }             }
Line 313 
Line 353 
             // insert it (setting the propagated flag). Otherwise, change             // insert it (setting the propagated flag). Otherwise, change
             // the class-origin and propagated flag accordingly.             // the class-origin and propagated flag accordingly.
  
             Uint32 pos = Uint32(-1);                          Uint32 pos = PEG_NOT_FOUND;
                           /**********************  KS move to simpler version
             for (Uint32 j = m, n = _methods.size(); j < n; j++)             for (Uint32 j = m, n = _methods.size(); j < n; j++)
             {             {
                 if (CIMName::equal(                                  if (CIMName::equal(_methods[j].getName(),
                     _methods[j].getName(),  
                     superClassMethod.getName()))                     superClassMethod.getName()))
                 {                 {
                     pos = j;                     pos = j;
Line 330 
Line 369 
             // clone and insert it. Otherwise, the method's class origin             // clone and insert it. Otherwise, the method's class origin
             // has already been set above.             // has already been set above.
  
             if (pos == Uint32(-1))                          if (pos == PEG_NOT_FOUND)
                           {
                                   CIMMethod method = superClassMethod.clone();
                                   method.setPropagated(true);
                                   _methods.insert(m++, method);
                           }
                           */
                           if((pos = findMethod(superClassMethod.getName())) == PEG_NOT_FOUND)
             {             {
                 CIMMethod method = superClassMethod.clone();                 CIMMethod method = superClassMethod.clone();
                 method.setPropagated(true);                 method.setPropagated(true);
Line 341 
Line 387 
         //----------------------------------------------------------------------         //----------------------------------------------------------------------
         // Validate the qualifiers of this class:         // Validate the qualifiers of this class:
         //----------------------------------------------------------------------         //----------------------------------------------------------------------
                   //cout << "KSTEST Class Qualifiers resolve for class" << getClassName() << endl;
         _qualifiers.resolve(         _qualifiers.resolve(
             context,             context,
             nameSpace,             nameSpace,
             isAssociation() ? CIMScope::ASSOCIATION : CIMScope::CLASS,             isAssociation() ? CIMScope::ASSOCIATION : CIMScope::CLASS,
             false,             false,
             superClass._rep->_qualifiers);                          superClass._rep->_qualifiers,
                           true);
     }     }
     else      else        // No SuperClass exsts
     {     {
         //----------------------------------------------------------------------         //----------------------------------------------------------------------
         // Resolve each property:         // Resolve each property:
         //----------------------------------------------------------------------         //----------------------------------------------------------------------
                   //cout << "KSTEST Class Resolve, No Super class " << getClassName() << endl;
  
         for (Uint32 i = 0, n = _properties.size(); i < n; i++)         for (Uint32 i = 0, n = _properties.size(); i < n; i++)
             _properties[i].resolve(context, nameSpace, false);                          _properties[i].resolve(context, nameSpace, false, true);
  
         //----------------------------------------------------------------------         //----------------------------------------------------------------------
         // Resolve each method:         // Resolve each method:
Line 376 
Line 424 
             nameSpace,             nameSpace,
             isAssociation() ? CIMScope::ASSOCIATION : CIMScope::CLASS,             isAssociation() ? CIMScope::ASSOCIATION : CIMScope::CLASS,
             false,             false,
             dummy);                          dummy,
                           true);
     }     }
  
     // _resolved = true;     // _resolved = true;
Line 387 
Line 436 
     // Class opening element:     // Class opening element:
  
     out << "<CLASS ";     out << "<CLASS ";
     out << " NAME=\"" << _className << "\" ";      out << " NAME=\"" << _reference.getClassName() << "\" ";
  
     if (_superClassName.size())     if (_superClassName.size())
         out << " SUPERCLASS=\"" << _superClassName << "\" ";         out << " SUPERCLASS=\"" << _superClassName << "\" ";
Line 412 
Line 461 
  
     out << "</CLASS>\n";     out << "</CLASS>\n";
 } }
   /** toMof prepares an 8-bit string with the MOF for the class.
       The BNF for this is:
       <pre>
       classDeclaration    =    [ qualifierList ]
                                CLASS className [ alias ] [ superClass ]
                                "{" *classFeature "}" ";"
   
       superClass          =    :" className
   
       classFeature        =    propertyDeclaration | methodDeclaration
   
   */
   
   void CIMClassRep::toMof(Array<Sint8>& out) const
   {
       // Get and format the class qualifiers
       out << "\n//    Class " << _reference.getClassName();
       if (_qualifiers.getCount())
           out << "\n";
       out << "\n";
       _qualifiers.toMof(out);
   
       // Separate qualifiers from Class Name
       out << "\n";
   
       // output class statement
       out << "class " << _reference.getClassName();
   
       if (_superClassName.size())
           out << " : " << _superClassName;
   
       out << "\n{";
   
       // format the Properties:
       for (Uint32 i = 0, n = _properties.size(); i < n; i++)
       {
           // Generate MOF if this property not propogated
           // Note that the test is required only because
           // there is an error in getclass that does not
           // test the localOnly flag.
           if (!_properties[i].getPropagated())
               _properties[i].toMof(out);
       }
  
 void CIMClassRep::print(std::ostream &os) const      // Format the Methods:  for non-propagated methods
       for (Uint32 i = 0, n = _methods.size(); i < n; i++)
       {
           if (!_methods[i].getPropagated())
           _methods[i].toMof(out);
       }
   
       // Class closing element:
       out << "\n};\n";
   }
   
   void CIMClassRep::print(PEGASUS_STD(ostream) &os) const
 { {
     Array<Sint8> tmp;     Array<Sint8> tmp;
     toXml(tmp);     toXml(tmp);
     tmp.append('\0');     tmp.append('\0');
     XmlWriter::indentedPrint(os, tmp.getData(), 4);     XmlWriter::indentedPrint(os, tmp.getData(), 4);
     // cout << tmp.getData() << endl;  
 } }
  
   void CIMClassRep::printMof(PEGASUS_STD(ostream) &os) const
   {
       Array<Sint8> tmp;
       toMof(tmp);
       tmp.append('\0');
       os << tmp.getData() << PEGASUS_STD(endl);
   }
   
   
 CIMClassRep::CIMClassRep() CIMClassRep::CIMClassRep()
 { {
  
 } }
  
 CIMClassRep::CIMClassRep(const CIMClassRep& x) : CIMClassRep::CIMClassRep(const CIMClassRep& x) :
     Sharable(),      CIMObjectRep(x),
     _className(x._className),      _superClassName(x._superClassName)
     _superClassName(x._superClassName),  
     _resolved(x._resolved)  
 { {
     x._qualifiers.cloneTo(_qualifiers);  
   
     _properties.reserve(x._properties.size());  
   
     for (Uint32 i = 0, n = x._properties.size(); i < n; i++)  
         _properties.append(x._properties[i].clone());  
   
     _methods.reserve(x._methods.size());     _methods.reserve(x._methods.size());
  
     for (Uint32 i = 0, n = x._methods.size(); i < n; i++)     for (Uint32 i = 0, n = x._methods.size(); i < n; i++)
         _methods.append(x._methods[i].clone());         _methods.append(x._methods[i].clone());
 } }
  
 CIMClassRep& CIMClassRep::operator=(const CIMClassRep& x)  
 {  
     return *this;  
 }  
   
 Boolean CIMClassRep::identical(const CIMClassRep* x) const Boolean CIMClassRep::identical(const CIMClassRep* x) const
 { {
     if (_className != x->_className)      if (!CIMObjectRep::identical(x))
         return false;         return false;
  
     if (_superClassName != x->_superClassName)     if (_superClassName != x->_superClassName)
         return false;         return false;
  
     if (!_qualifiers.identical(x->_qualifiers))      //
         return false;      // Check methods:
       //
     // Compare properties:  
   
     {  
         const Array<CIMProperty>& tmp1 = _properties;  
         const Array<CIMProperty>& tmp2 = x->_properties;  
   
         if (tmp1.size() != tmp2.size())  
             return false;  
   
         for (Uint32 i = 0, n = tmp1.size(); i < n; i++)  
         {  
             if (!tmp1[i].identical(tmp2[i]))  
                 return false;  
         }  
     }  
   
     // Compare methods:  
  
     {     {
         const Array<CIMMethod>& tmp1 = _methods;         const Array<CIMMethod>& tmp1 = _methods;
Line 519 
Line 599 
     }     }
 } }
  
   Boolean CIMClassRep::hasKeys() const
   {
       for (Uint32 i = 0, n = getPropertyCount(); i < n; i++)
       {
           CIMConstProperty property = getProperty(i);
   
           if (getProperty(i).isKey())
               return true;
       }
   
       return false;
   }
   
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END
   


Legend:
Removed from v.1.7  
changed lines
  Added in v.1.29

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2