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

Diff for /pegasus/src/Pegasus/Common/CIMQualifierList.cpp between version 1.5 and 1.70

version 1.5, 2001/04/08 01:13:21 version 1.70, 2008/12/01 17:49:50
Line 1 
Line 1 
 //BEGIN_LICENSE  //%LICENSE////////////////////////////////////////////////////////////////
 // //
 // Copyright (c) 2000 The Open Group, BMC Software, Tivoli Systems, IBM  // Licensed to The Open Group (TOG) under one or more contributor license
   // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
   // this work for additional information regarding copyright ownership.
   // Each contributor licenses this file to you under the OpenPegasus Open
   // Source License; you may not use this file except in compliance with the
   // License.
 // //
 // 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 of this software and associated documentation files (the "Software"), // copy of this software and associated documentation files (the "Software"),
Line 9 
Line 14 
 // and/or sell copies of the Software, and to permit persons to whom the // and/or sell copies of the Software, and to permit persons to whom the
 // Software is furnished to do so, subject to the following conditions: // Software is 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
 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  // in all copies or substantial portions of the Software.
 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL  
 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER  
 // LIABILITY, WHETHER IN AN 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.  
 // //
 //END_LICENSE  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 //BEGIN_HISTORY  // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
   // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
   // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
   // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 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.
 // //
 // Author:  //////////////////////////////////////////////////////////////////////////
 // //
 // $Log$  //%/////////////////////////////////////////////////////////////////////////////
 // Revision 1.5  2001/04/08 01:13:21  mike  
 // Changed "ConstCIM" to "CIMConst"  
 //  
 // Revision 1.3  2001/02/20 05:16:57  mike  
 // Implemented CIMInstance::getInstanceName()  
 //  
 // Revision 1.2  2001/02/19 01:47:16  mike  
 // Renamed names of the form CIMConst to CIMConst.  
 //  
 // Revision 1.1  2001/02/18 18:39:06  mike  
 // new  
 //  
 // Revision 1.3  2001/02/18 03:56:01  mike  
 // Changed more class names (e.g., ConstClassDecl -> CIMConstClass)  
 //  
 // Revision 1.2  2001/02/17 00:41:28  bob  
 // #ifdefed around the check of scope to avoid bogus exceptions  
 //  
 // Revision 1.1  2001/02/16 02:07:06  mike  
 // Renamed many classes and headers (using new CIM prefixes).  
 //  
 // Revision 1.5  2001/02/13 02:06:40  mike  
 // Added renameFile() method.  
 //  
 // Revision 1.4  2001/01/28 04:11:03  mike  
 // fixed qualifier resolution  
 //  
 // Revision 1.3  2001/01/23 01:25:35  mike  
 // Reworked resolve scheme.  
 //  
 // Revision 1.2  2001/01/22 00:45:47  mike  
 // more work on resolve scheme  
 //  
 // Revision 1.1.1.1  2001/01/14 19:53:09  mike  
 // Pegasus import  
 //  
 //  
 //END_HISTORY  
  
 #include "CIMQualifierList.h" #include "CIMQualifierList.h"
 #include "DeclContext.h" #include "DeclContext.h"
   #include "Resolver.h"
 #include "CIMQualifierDecl.h" #include "CIMQualifierDecl.h"
 #include "CIMName.h" #include "CIMName.h"
 #include "Indentor.h"  
 #include "XmlWriter.h" #include "XmlWriter.h"
   #include <Pegasus/Common/Tracer.h>
   #include <Pegasus/Common/MessageLoader.h>
   #include "StrLit.h"
   #include "ArrayIterator.h"
   #include "CIMQualifierRep.h"
  
 PEGASUS_NAMESPACE_BEGIN PEGASUS_NAMESPACE_BEGIN
   PEGASUS_USING_STD;
   
   static CIMName _KEY("Key");
   
   CIMQualifierList::CIMQualifierList() :
                       _keyIndex(PEGASUS_ORDEREDSET_INDEX_UNKNOWN)
   {
   
   }
   
   CIMQualifierList::~CIMQualifierList()
   {
   
   }
  
 CIMQualifierList& CIMQualifierList::add(const CIMQualifier& qualifier) CIMQualifierList& CIMQualifierList::add(const CIMQualifier& qualifier)
 { {
     if (!qualifier)      if (qualifier.isUninitialized())
         throw UnitializedHandle();          throw UninitializedObjectException();
  
     if (find(qualifier.getName()) != Uint32(-1))      if (find(qualifier.getName()) != PEG_NOT_FOUND)
         throw AlreadyExists();      {
           MessageLoaderParms parms("Common.CIMQualifierList.QUALIFIER",
               "qualifier \"$0\"",
               qualifier.getName().getString());
           throw AlreadyExistsException(parms);
       }
  
     _qualifiers.append(qualifier);     _qualifiers.append(qualifier);
  
       // Update key index:
       if (_keyIndex == PEGASUS_ORDEREDSET_INDEX_UNKNOWN &&
               qualifier._rep->_name == _KEY)
           _keyIndex = _qualifiers.size()-1;
   
     return *this;     return *this;
 } }
  
 Uint32 CIMQualifierList::find(const String& name) const  CIMQualifier& CIMQualifierList::getQualifier(Uint32 index)
 { {
     for (Uint32 i = 0, n = _qualifiers.getSize(); i < n; i++)      return _qualifiers[index];
     {  
         if (CIMName::equal(_qualifiers[i].getName(), name))  
             return i;  
     }     }
  
     return Uint32(-1);  void CIMQualifierList::removeQualifier(Uint32 index)
   {
       _qualifiers.remove(index);
       _keyIndex = PEGASUS_ORDEREDSET_INDEX_UNKNOWN;
 } }
  
 Uint32 CIMQualifierList::findReverse(const String& name) const  void CIMQualifierList::clear()
 { {
     for (Uint32 i = _qualifiers.getSize(); i; --i)      _qualifiers.clear();
   }
   
   Uint32 CIMQualifierList::find(const CIMName& name) const
     {     {
         if (CIMName::equal(_qualifiers[i - 1].getName(), name))      return _qualifiers.find(name, generateCIMNameTag(name));
             return i - 1;  
     }     }
  
     return Uint32(-1);  Boolean CIMQualifierList::isTrue(const CIMName& name) const
   {
       Uint32 index = find(name);
   
       if (index == PEG_NOT_FOUND)
           return false;
   
       Boolean flag;
       const CIMValue& value = getQualifier(index).getValue();
   
       if (value.getType() != CIMTYPE_BOOLEAN)
           return false;
   
       value.get(flag);
       return flag;
 } }
  
 void CIMQualifierList::resolve( void CIMQualifierList::resolve(
     DeclContext* declContext,     DeclContext* declContext,
     const String& nameSpace,      const CIMNamespaceName & nameSpace,
     Uint32 scope,      CIMScope scope, // Scope of the entity being resolved.
     Boolean isInstancePart,     Boolean isInstancePart,
     CIMQualifierList& inheritedQualifiers)      CIMQualifierList& inheritedQualifiers,
       Boolean propagateQualifiers)
 { {
       _keyIndex = PEGASUS_ORDEREDSET_INDEX_UNKNOWN;
   
       PEG_METHOD_ENTER(TRC_OBJECTRESOLUTION, "CIMQualifierList::resolve()");
     // For each qualifier in the qualifiers array, the following     // For each qualifier in the qualifiers array, the following
     // is checked:     // is checked:
     //     //
Line 120 
Line 136 
     //     //
     //     2. Whether it has the same type as the declaration.     //     2. Whether it has the same type as the declaration.
     //     //
     //     3. Whether the the qualifier is valid for the given scope.      //     3. Whether the qualifier is valid for the given scope.
     //     //
     //     4. Whether the qualifier can be overriden (the flavor is     //     4. Whether the qualifier can be overriden (the flavor is
     //        ENABLEOVERRIDE on the corresponding reference qualifier).     //        ENABLEOVERRIDE on the corresponding reference qualifier).
Line 130 
Line 146 
     // If the qualifier should be overriden, then it is injected into the     // If the qualifier should be overriden, then it is injected into the
     // qualifiers array (from the inheritedQualifiers array).     // qualifiers array (from the inheritedQualifiers array).
  
     for (Uint32 i = 0, n = _qualifiers.getSize(); i < n; i++)      for (Uint32 i = 0, n = _qualifiers.size(); i < n; i++)
     {     {
         CIMQualifier q = _qualifiers[i];         CIMQualifier q = _qualifiers[i];
   
         //----------------------------------------------------------------------         //----------------------------------------------------------------------
         // 1. Check to see if it's declared.         // 1. Check to see if it's declared.
         //----------------------------------------------------------------------         //----------------------------------------------------------------------
           // set this back to  CIMConstQualifierDecl
         CIMConstQualifierDecl qd = declContext->lookupQualifierDecl(          CIMQualifierDecl qd = declContext->lookupQualifierDecl(
             nameSpace, q.getName());             nameSpace, q.getName());
  
         if (!qd)          if (qd.isUninitialized())
             throw UndeclaredQualifier(q.getName());          {
               PEG_METHOD_EXIT();
               throw UndeclaredQualifier(q.getName().getString ());
           }
  
         //----------------------------------------------------------------------         //----------------------------------------------------------------------
         // 2. Check the type:          // 2. Check the type and isArray.  Must be the same:
         //----------------------------------------------------------------------         //----------------------------------------------------------------------
  
         if (!(q.getType() == qd.getType() && q.isArray() == qd.isArray()))         if (!(q.getType() == qd.getType() && q.isArray() == qd.isArray()))
             throw BadQualifierType(q.getName());          {
               PEG_METHOD_EXIT();
               throw BadQualifierType(q.getName().getString ());
           }
  
         //----------------------------------------------------------------------         //----------------------------------------------------------------------
         // 3. Check the scope:          // 3. If the qualifier is the EmbeddedInstance qualifier, then check
           // that the class specified by the qualifier exists in the namespace.
         //----------------------------------------------------------------------         //----------------------------------------------------------------------
 #if 0          if (q.getName().equal(PEGASUS_QUALIFIERNAME_EMBEDDEDINSTANCE))
         // ATTN:  These lines throw a bogus exception if the qualifier has          {
         // a valid scope (such as Scope::ASSOCIATION) which is not Scope::CLASS              String className;
         // grb 1/16/01              q.getValue().get(className);
         if (!(qd.getScope() & scope))              CIMClass classDef = declContext->lookupClass(nameSpace,
             throw BadQualifierScope(qd.getName(), ScopeToString(scope));                      CIMName(className));
 #endif              if (classDef.isUninitialized())
               {
                   String embeddedInstType("EmbeddedInstance(\"");
                   embeddedInstType = embeddedInstType + className + "\")";
                   PEG_METHOD_EXIT();
                   throw BadQualifierType(embeddedInstType);
               }
           }
   
         //----------------------------------------------------------------------         //----------------------------------------------------------------------
         // See if this qualifier is contained in the inheritedQualifiers. If          // 4. Check the scope: Must be legal for this qualifier
         // so then we must handle the OVERRIDABLE flavor.  
         //----------------------------------------------------------------------         //----------------------------------------------------------------------
           // ATTN:  These lines throw a bogus exception if the qualifier has
           // a valid scope (such as Scope::ASSOCIATION) which is not Scope::CLASS
           // ks Mar 2002. Reinstalled 23 March 2002 to test.
  
         // ATTN: there seems to be a problem with the CIM schema that marks the          if (!(qd.getScope().hasScope (scope)))
         // abstract qualifier as non-overridable but then they override it.  
         // For now it is just disabled. This problem exists in both XML and  
         // CIM schema.  
   
 #if 0  
         Uint32 pos = inheritedQualifiers.find(q.getName());  
   
         if (pos != Uint32(-1))  
         {         {
             CIMConstQualifier iq = inheritedQualifiers.getQualifier(pos);              PEG_METHOD_EXIT();
               throw BadQualifierScope
                   (qd.getName().getString (), scope.toString ());
           }
  
             if (!(iq.getFlavor() & CIMFlavor::OVERRIDABLE))          //----------------------------------------------------------------------
                 throw BadQualifierOverride(q.getName());          // Resolve the qualifierflavor. Since Flavors are a combination of
           // inheritance and input characteristics, resolve the inherited
           // characteristics against those provided with the creation.  If
           // there is a superclass the flavor is resolved against that
           // superclass.  If not, it is resolved against the declaration. If
           // the flavor is disableoverride and tosubclass the resolved
           // qualifier value must be identical to the original
           //----------------------------------------------------------------------
           // Test for Qualifier found in SuperClass. If found and qualifier
           // is not overridable.
           // Abstract (not Overridable and restricted) can be found in subclasses
           // Can have nonabstracts below abstracts. That is function of
           // nottosubclass Association (notOverridable and tosubclass) can be
           // found in subclasses but cannot be changed. No non-associatons below
           // associations. In other words once a class becomes an association,
           // no subclass can override that definition apparently
           // Throw exception if DisableOverride and tosubclass and different
           // value.  Gets the source from superclass if qualifier exists or from
           // declaraction.
           // If we do not throw the exception, resolve the flavor from the
           // inheritance point and resolve against current input.
           // Diableoverride is defined in the CIM Spec to mean that the value
           // cannot change.
           // The other characteristics including the flavor can change
           // apparently. Thus, we need only confirm that the value is the same
           // (2.2 pp 33).  Strange since we would think that override implies
           // that you cannot override any of the characteristics (value, type,
           // flavor, etc.) This also leaves the question of NULL or no values.
           // The implication is that we must move the value from the superclass
           // or declaration.
   
           Uint32 index = inheritedQualifiers.find(q.getName());
   
           if (index == PEG_NOT_FOUND)
           {   // Qualifier does not exist in superclass
               /* If from declaration, we can override the default value.
                 However, we need some way to get the value if we have a Null.
               if (!qd.getFlavor().hasFlavor(CIMFlavor::OVERRIDABLE) &&
                   qd.getFlavor().hasFlavor(CIMFlavor::TOSUBCLASS))
               {
                   //throw BadQualifierOverride(q.getName());
               }
               */
               // Do not allow change from disable override to enable override.
               if ((!qd.getFlavor ().hasFlavor(CIMFlavor::OVERRIDABLE))
                     && (q.getFlavor ().hasFlavor(CIMFlavor::OVERRIDABLE)))
               {
                   PEG_METHOD_EXIT();
                   throw BadQualifierOverride(q.getName().getString ());
               }
   
               Resolver::resolveQualifierFlavor(
                   q, CIMFlavor (qd.getFlavor ()), false);
           }
           else  // qualifier exists in superclass
           {   ////// Make Const again
               CIMQualifier iq = inheritedQualifiers.getQualifier(index);
               // don't allow change override to notoverride.
               if (!(iq.getFlavor ().hasFlavor(CIMFlavor::OVERRIDABLE))
                     && q.getFlavor ().hasFlavor (CIMFlavor::OVERRIDABLE))
               {
                   PEG_METHOD_EXIT();
                   throw BadQualifierOverride(q.getName().getString ());
               }
   
               if (!(iq.getFlavor ().hasFlavor(CIMFlavor::OVERRIDABLE))
                     && iq.getFlavor ().hasFlavor(CIMFlavor::TOSUBCLASS))
               {
                   // test if values the same.
                   CIMValue qv = q.getValue();
                   CIMValue iqv = iq.getValue();
                   if (!(qv == iqv))
                   {
                       PEG_METHOD_EXIT();
                       throw BadQualifierOverride(q.getName().getString());
                   }
         }         }
 #endif  
               Resolver::resolveQualifierFlavor(
                   q, CIMFlavor(iq.getFlavor()), true);
     }     }
       }   // end of this objects qualifier loop
  
     //--------------------------------------------------------------------------     //--------------------------------------------------------------------------
     // Propagate qualifiers to subclass or to instance that do not have     // Propagate qualifiers to subclass or to instance that do not have
     // already have those qualifiers:     // already have those qualifiers:
     //--------------------------------------------------------------------------     //--------------------------------------------------------------------------
  
       if (propagateQualifiers)
       {
     for (Uint32 i = 0, n = inheritedQualifiers.getCount(); i < n; i++)     for (Uint32 i = 0, n = inheritedQualifiers.getCount(); i < n; i++)
     {     {
         CIMQualifier iq = inheritedQualifiers.getQualifier(i);         CIMQualifier iq = inheritedQualifiers.getQualifier(i);
  
         if (isInstancePart)         if (isInstancePart)
         {         {
             if (!(iq.getFlavor() & CIMFlavor::TOINSTANCE))                  if (!(iq.getFlavor().hasFlavor(CIMFlavor::TOINSTANCE)))
                 continue;                 continue;
         }         }
         else         else
         {         {
             if (!(iq.getFlavor() & CIMFlavor::TOSUBCLASS))                  if (!(iq.getFlavor().hasFlavor(CIMFlavor::TOSUBCLASS)))
                 continue;                 continue;
         }         }
  
         // If the qualifiers list does not already contain this qualifier,         // If the qualifiers list does not already contain this qualifier,
         // then propagate it (and set the propagated flag to true).              // then propagate it (and set the propagated flag to true).  Else
               // we keep current value. Note we have already eliminated any
         if (find(iq.getName()) != Uint32(-1))              // possibility that a nonoverridable qualifier can be in the list.
               if (find(iq.getName()) != PEG_NOT_FOUND)
             continue;             continue;
  
         CIMQualifier q = iq.clone();         CIMQualifier q = iq.clone();
         q.setPropagated(true);         q.setPropagated(true);
         _qualifiers.prepend(q);              _qualifiers.insert(0, q);
     }     }
 } }
       PEG_METHOD_EXIT();
 void CIMQualifierList::toXml(Array<Sint8>& out) const  
 {  
     for (Uint32 i = 0, n = _qualifiers.getSize(); i < n; i++)  
         _qualifiers[i].toXml(out);  
 } }
  
 void CIMQualifierList::print(std::ostream &os) const  void CIMQualifierList::print(PEGASUS_STD(ostream) &os) const
 { {
     Array<Sint8> tmp;      Buffer tmp;
     toXml(tmp);      for (Uint32 i = 0, n = getCount(); i < n; i++)
     tmp.append('\0');          XmlWriter::appendQualifierElement(tmp, _qualifiers[i]);
     os << tmp.getData() << std::endl;      os << tmp.getData() << PEGASUS_STD(endl);
 } }
  
 Boolean CIMQualifierList::identical(const CIMQualifierList& x) const Boolean CIMQualifierList::identical(const CIMQualifierList& x) const
Line 238 
Line 342 
         return false;         return false;
  
     for (Uint32 i = 0; i < count; i++)     for (Uint32 i = 0; i < count; i++)
         return _qualifiers[i].identical(x._qualifiers[i]);      {
           if (!_qualifiers[i].identical(x._qualifiers[i]))
               return false;
       }
  
     return true;     return true;
 } }
  
 void CIMQualifierList::cloneTo(CIMQualifierList& x) const void CIMQualifierList::cloneTo(CIMQualifierList& x) const
 { {
       x._keyIndex = PEGASUS_ORDEREDSET_INDEX_UNKNOWN;
     x._qualifiers.clear();     x._qualifiers.clear();
     x._qualifiers.reserve(_qualifiers.getSize());      x._qualifiers.reserveCapacity(_qualifiers.size());
  
     for (Uint32 i = 0, n = _qualifiers.getSize(); i < n; i++)      for (Uint32 i = 0, n = _qualifiers.size(); i < n; i++)
         x._qualifiers.append(_qualifiers[i].clone());         x._qualifiers.append(_qualifiers[i].clone());
       x._keyIndex = _keyIndex;
   }
   
   Boolean CIMQualifierList::isKey() const
   {
       static Uint32 _KEY_TAG = generateCIMNameTag(_KEY);
   
       // Resolve key index if unresolved.
   
       if (_keyIndex == PEGASUS_ORDEREDSET_INDEX_UNKNOWN)
       {
           Uint32 pos = _qualifiers.find(_KEY, _KEY_TAG);
           ((CIMQualifierList*)this)->_keyIndex = int(pos);
       }
   
       // If no key qualifier in list, then return false (default key value).
   
       if (_keyIndex == PEGASUS_ORDEREDSET_INDEX_NOTFOUND)
           return false;
   
       // Obtain value of key qualifier.
   
       const CIMValue& value = _qualifiers[_keyIndex]._rep->_value;
       if (!value.isNull() &&
           value.getType() == CIMTYPE_BOOLEAN)
       {
           Boolean boolVal;
           value.get(boolVal);
           return boolVal;
       }
   
       return false;
   }
   
   CIMQualifierList& CIMQualifierList::addUnchecked(const CIMQualifier& qualifier)
   {
       if (qualifier.isUninitialized())
           throw UninitializedObjectException();
   
       _qualifiers.append(qualifier);
   
       if (_keyIndex == PEGASUS_ORDEREDSET_INDEX_UNKNOWN &&
               qualifier._rep->_name == _KEY)
           _keyIndex = _qualifiers.size()-1;
   
       return *this;
 } }
  
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END


Legend:
Removed from v.1.5  
changed lines
  Added in v.1.70

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2