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

  1 karl  1.51 //%2005////////////////////////////////////////////////////////////////////////
  2 mike  1.15 //
  3 karl  1.49 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
  4            // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
  5            // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
  6 karl  1.48 // IBM Corp.; EMC Corporation, The Open Group.
  7 karl  1.49 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  8            // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
  9 karl  1.51 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10            // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11 mike  1.15 //
 12            // Permission is hereby granted, free of charge, to any person obtaining a copy
 13 kumpf 1.35 // of this software and associated documentation files (the "Software"), to
 14            // deal in the Software without restriction, including without limitation the
 15            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 16 mike  1.15 // sell copies of the Software, and to permit persons to whom the Software is
 17            // furnished to do so, subject to the following conditions:
 18            // 
 19 kumpf 1.35 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 20 mike  1.15 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 21            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 22 kumpf 1.35 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 23            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 24            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 25 mike  1.15 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 26            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27            //
 28            //==============================================================================
 29            //
 30            // Author: Mike Brasher (mbrasher@bmc.com)
 31            //
 32 karl  1.24 // Modified By:	Karl Schopmeyer (k.schopmeyer@opengroup.org)
 33 kumpf 1.37 //              Carol Ann Krug Graves, Hewlett-Packard Company
 34 david.dillard 1.50 //                  (carolann_graves@hp.com)
 35                    //              David Dillard, VERITAS Software Corp.
 36                    //                  (david.dillard@veritas.com)
 37 mike          1.15 //
 38                    //%/////////////////////////////////////////////////////////////////////////////
 39                    
 40                    #include "CIMQualifierList.h"
 41                    #include "DeclContext.h"
 42 kumpf         1.37 #include "Resolver.h"
 43 mike          1.15 #include "CIMQualifierDecl.h"
 44                    #include "CIMName.h"
 45                    #include "Indentor.h"
 46                    #include "XmlWriter.h"
 47 kumpf         1.34 #include "MofWriter.h"
 48 karl          1.29 #include <Pegasus/Common/Tracer.h>
 49 humberto      1.47 #include <Pegasus/Common/MessageLoader.h> //l10n
 50 mike          1.53 #include "StrLit.h"
 51 mike          1.54 #include "ArrayIterator.h"
 52 mike          1.15 
 53                    PEGASUS_NAMESPACE_BEGIN
 54 karl          1.18 PEGASUS_USING_STD;
 55 mike          1.15 
 56                    CIMQualifierList::CIMQualifierList()
 57                    {
 58                    
 59                    }
 60                    
 61                    CIMQualifierList::~CIMQualifierList()
 62                    {
 63                    
 64                    }
 65                    
 66                    CIMQualifierList& CIMQualifierList::add(const CIMQualifier& qualifier)
 67                    {
 68 kumpf         1.40     if (qualifier.isUninitialized())
 69 kumpf         1.44 	throw UninitializedObjectException();
 70 mike          1.15 
 71 humberto      1.47     if (find(qualifier.getName()) != PEG_NOT_FOUND){
 72                        	//l10n
 73                    		//throw AlreadyExistsException
 74                                //("qualifier \"" + qualifier.getName().getString () + "\"");
 75                            MessageLoaderParms parms("Common.CIMQualifierList.QUALIFIER",
 76                            						 "qualifier \"$0\"",
 77                            						 qualifier.getName().getString());
 78                            throw AlreadyExistsException(parms);
 79                        }
 80 mike          1.15 
 81                        _qualifiers.append(qualifier);
 82                    
 83                        return *this;
 84                    }
 85                    //ATTN: Why do we not do the outofbounds check here. KS 18 May 2k
 86 kumpf         1.45 CIMQualifier& CIMQualifierList::getQualifier(Uint32 index)
 87 mike          1.15 {
 88 kumpf         1.45     return _qualifiers[index];
 89 mike          1.15 }
 90                    
 91                    //ATTN: added ks 18 may 2001. Should we have outofbounds?
 92 kumpf         1.45 void CIMQualifierList::removeQualifier(Uint32 index)
 93 mike          1.15 {
 94 kumpf         1.45     _qualifiers.remove(index);
 95 mike          1.15 }
 96                    
 97 kumpf         1.39 Uint32 CIMQualifierList::find(const CIMName& name) const
 98 mike          1.15 {
 99 mike          1.54     ConstArrayIterator<CIMQualifier> qualifiers(_qualifiers);
100                    
101                        for (Uint32 i = 0, n = qualifiers.size(); i < n; i++)
102 mike          1.15     {
103 mike          1.54 	if (name.equal(qualifiers[i].getName()))
104 mike          1.15 	    return i;
105                        }
106                    
107                        return PEG_NOT_FOUND;
108                    }
109 kumpf         1.39 Boolean CIMQualifierList::isTrue(const CIMName& name) const
110 karl          1.28 {
111 kumpf         1.45     Uint32 index = find(name);
112 karl          1.28 
113 kumpf         1.45     if (index == PEG_NOT_FOUND)
114 karl          1.28 	return false;
115                    
116                        Boolean flag;
117 kumpf         1.45     const CIMValue& value = getQualifier(index).getValue();
118 karl          1.28 
119 kumpf         1.38     if (value.getType() != CIMTYPE_BOOLEAN)
120 karl          1.28 	return false;
121                    
122                        value.get(flag);
123                        return flag;
124                    }
125 mike          1.15 
126 kumpf         1.39 Uint32 CIMQualifierList::findReverse(const CIMName& name) const
127 mike          1.15 {
128                        for (Uint32 i = _qualifiers.size(); i; --i)
129                        {
130 kumpf         1.39 	if (name.equal(_qualifiers[i-1].getName()))
131 mike          1.15 	    return i - 1;
132                        }
133                    
134                        return PEG_NOT_FOUND;
135                    }
136                    
137                    void CIMQualifierList::resolve(
138                        DeclContext* declContext,
139 kumpf         1.46     const CIMNamespaceName & nameSpace,
140 a.dunfey      1.54.2.1     CIMScope scope, // Scope of the entity being resolved.
141 mike          1.15         Boolean isInstancePart,
142 mike          1.23         CIMQualifierList& inheritedQualifiers,
143 a.dunfey      1.54.2.1     Boolean propagateQualifiers)  // Apparently not used ks 24 mar 2002
144 mike          1.15     {
145 karl          1.29         PEG_METHOD_ENTER(TRC_OBJECTRESOLUTION, "CIMQualifierList::resolve()");
146 mike          1.15         // For each qualifier in the qualifiers array, the following
147                            // is checked:
148                            //
149                            //     1. Whether it is declared (can be obtained from the declContext).
150                            //
151                            //     2. Whether it has the same type as the declaration.
152                            //
153 a.dunfey      1.54.2.1     //     3. Whether the qualifier is valid for the given scope.
154 mike          1.15         //
155 a.dunfey      1.54.2.1     //     4. Whether the qualifier can be overriden (the flavor is
156                            //        ENABLEOVERRIDE on the corresponding reference qualifier).
157 mike          1.15         //
158 a.dunfey      1.54.2.1     //     5. Whether the qualifier should be propagated to the subclass.
159 mike          1.15         //
160                            // If the qualifier should be overriden, then it is injected into the
161                            // qualifiers array (from the inheritedQualifiers array).
162                        
163                            for (Uint32 i = 0, n = _qualifiers.size(); i < n; i++)
164                            {
165 a.dunfey      1.54.2.1         CIMQualifier q = _qualifiers[i];
166                                //----------------------------------------------------------------------
167                                // 1. Check to see if it's declared.
168                                //----------------------------------------------------------------------
169                                // set this back to  CIMConstQualifierDecl
170                                CIMQualifierDecl qd = declContext->lookupQualifierDecl(
171                                    nameSpace, q.getName());
172                            
173                                if (qd.isUninitialized())
174                                    throw UndeclaredQualifier(q.getName().getString ());
175                            
176                                //----------------------------------------------------------------------
177                                // 2. Check the type and isArray.  Must be the same:
178                                //----------------------------------------------------------------------
179                            
180                                if (!(q.getType() == qd.getType() && q.isArray() == qd.isArray()))
181                                    throw BadQualifierType(q.getName().getString ());
182                                
183                        #ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT
184                                //----------------------------------------------------------------------
185                                // 3. If the qualifier is the EmbeddedInstance qualifier, then check
186 a.dunfey      1.54.2.1         // that the class specified by the qualifier exists in the namespace.
187                                //----------------------------------------------------------------------
188                                if(q.getName().equal(CIMName("EmbeddedInstance")))
189                                {
190                                    String className;
191                                    q.getValue().get(className);
192                                    CIMClass classDef = declContext->lookupClass(nameSpace,
193                                            CIMName(className));
194                                    if(classDef.isUninitialized())
195                                    {
196                                        String embeddedInstType("EmbeddedInstance(\"");
197                                        embeddedInstType = embeddedInstType + className + "\")";
198                                        throw BadQualifierType(embeddedInstType);
199                                    }
200                                }
201                        #endif // PEGASUS_EMBEDDED_INSTANCE_SUPPORT
202                        
203                                //----------------------------------------------------------------------
204                                // 4. Check the scope: Must be legal for this qualifier
205                                //----------------------------------------------------------------------
206 karl          1.24     //#if 0
207 a.dunfey      1.54.2.1             // ATTN:  These lines throw a bogus exception if the qualifier has
208                                    // a valid scope (such as Scope::ASSOCIATION) which is not Scope::CLASS
209                                    // ks Mar 2002. Reinstalled 23 March 2002 to test.
210                        
211                                if (!(qd.getScope().hasScope (scope)))
212                                    throw BadQualifierScope
213                                        (qd.getName().getString (), scope.toString ());
214 karl          1.24     //#endif
215 a.dunfey      1.54.2.1         //----------------------------------------------------------------------
216                                // Resolve the qualifierflavor. Since Flavors are a combination of inheritance
217                                // and input characteristics, resolve the inherited characteristics
218                                // against those provided with the creation.  If there is a superclass
219                                // the flavor is resolved against that superclass.  If not, it is resolved
220                                // against the declaration. If the flavor is disableoverride and tosubclass
221                                // the resolved qualifier value must be identical to the original
222                                //----------------------------------------------------------------------
223                                // Test for Qualifier found in SuperClass. If found and qualifier
224                                // is not overridable.
225                                // Abstract (not Overridable and restricted) can be found in subclasses
226                                // Can have nonabstracts below abstracts. That is function of nottosubclass
227                                // Association (notOverridable and tosubclass) can be found in subclasses but
228                                // cannot be changed. No non-associatons below associations. In other words
229                                // once a class becomes an association, no subclass can override that definition
230                                // apparently
231                                // Throw exception if DisableOverride and tosubclass and different value.
232                                // Gets the source from superclass if qualifier exists or from declaraction
233                                // If we do not throw the exception, resolve the flavor from the inheritance
234                                // point and resolve against current input.
235                                // Diableoverride is defined in the CIM Spec to mean that the value cannot change
236 a.dunfey      1.54.2.1         // The other characteristics including the flavor can change apparently. Thus, we
237                                // need only confirm that the value is the same (2.2 pp 33).  Strange since we 
238                                // would think that  override implies that you cannot override any of the 
239                                // characteristics (value, type, flavor, etc.) This also leaves the question
240                                // of NULL or no values.  The implication is that we must move the value
241                                // from the superclass or declaration.
242                        
243                                Uint32 index = inheritedQualifiers.find(q.getName());
244                        
245                                //cout << "KSTEST Qualifier resolve inherit test " << q.getName() 
246                                //<< " Inherited From " << ((index == PEG_NOT_FOUND) ? "Declaration" : "superclass")
247                                //<< " Flavor " << q.getFlavor() 
248                                //<< " inherited Flavor ";
249                        
250                                if (index == PEG_NOT_FOUND)
251                                {   // Qualifier does not exist in superclass
252                                    /* If from declaration, we can override the default value.
253                                      However, we need some way to get the value if we have a Null.
254                                    if (!(qd.getFlavor ().hasFlavor 
255                                                      (CIMFlavor::OVERRIDABLE))
256 kumpf         1.42                                 && qd.getFlavor ().hasFlavor 
257 a.dunfey      1.54.2.1                               (CIMFlavor::TOSUBCLASS))
258                                    {
259                                        if(!(q.getValue() == qd.getValue()))
260                                            cout << "KSTEST QL err NSCL " << q.getName()
261                                            << " decl flavor " << qd.getFlavor() << " Flavor " << q.getFlavor()
262                                            << " Not override " 
263 kumpf         1.42                                             << !(qd.getFlavor ().hasFlavor
264 a.dunfey      1.54.2.1                                           (CIMFlavor::OVERRIDABLE))
265                                            << " tosubclass " 
266 kumpf         1.42                                             <<  qd.getFlavor ().hasFlavor
267                                                                    (CIMFlavor::TOSUBCLASS) << endl;
268 a.dunfey      1.54.2.1                 XmlWriter::printQualifierDeclElement(qd);
269                                        XmlWriter::printQualifierElement(q);
270                                            //throw BadQualifierOverride(q.getName());
271                                    }
272                                    //cout <<  qd.getFlavor() << endl;*/
273                                    // Do not allow change from disable override to enable override.
274                                    if ((!qd.getFlavor ().hasFlavor(CIMFlavor::OVERRIDABLE))
275                                          && (q.getFlavor ().hasFlavor(CIMFlavor::OVERRIDABLE)))
276                                        throw BadQualifierOverride(q.getName().getString ());
277                        
278                                    Resolver::resolveQualifierFlavor
279                                        (q, CIMFlavor (qd.getFlavor ()), false);
280                                    /*if(!(q.getValue() == qd.getValue()))
281                                        cout << "KSTEST Flavor resolved from decl. " << q.getName()
282                                        << " decl flavor " << qd.getFlavor().toString ()
283 kumpf         1.42                                     << " Flavor " << q.getFlavor().toString ()
284 a.dunfey      1.54.2.1                 << " Not override " 
285 kumpf         1.42                                     << !(qd.getFlavor ().hasFlavor 
286 a.dunfey      1.54.2.1                                       (CIMFlavor::OVERRIDABLE))
287                                        << " tosubclass " <<  qd.getFlavor ().hasFlavor
288                                                              (CIMFlavor::TOSUBCLASS) << endl;            
289                                    XmlWriter::printQualifierDeclElement(qd);
290                                    XmlWriter::printQualifierElement(q); */
291                                }
292                                else  // qualifier exists in superclass 
293                                {   ////// Make Const again
294                                    CIMQualifier iq = inheritedQualifiers.getQualifier(index);
295                                    // don't allow change override to notoverride.
296                                    if (!(iq.getFlavor ().hasFlavor(CIMFlavor::OVERRIDABLE))
297                                          && q.getFlavor ().hasFlavor (CIMFlavor::OVERRIDABLE))
298                                        throw BadQualifierOverride(q.getName().getString ());
299                        
300                                    if (!(iq.getFlavor ().hasFlavor(CIMFlavor::OVERRIDABLE))
301                                          && iq.getFlavor ().hasFlavor(CIMFlavor::TOSUBCLASS))
302                                    {
303                                        /*if(!(q.getValue() == iq.getvalue()))
304                                            cout << "KSTEST QL err inherit " << q.getName()
305                                            << " from superclass " << iq.getName() 
306                                            << "   Superclass flavor " << iq.getFlavor().toString ()
307 a.dunfey      1.54.2.1                     << " Flavor " << q.getFlavor().toString () 
308                                            << endl;
309                                            XmlWriter::printQualifierElement(iq);
310                                            XmlWriter::printQualifierElement(q); */
311                                        // test if values the same.
312                                        CIMValue qv = q.getValue();
313                                        CIMValue iqv = iq.getValue();
314                                        if(!(qv == iqv)) {
315                                            throw BadQualifierOverride(q.getName().getString());
316                                      }
317                                    }
318                                    //cout << iq.getFlavor()  << endl;
319                                    Resolver::resolveQualifierFlavor 
320 kumpf         1.42                                 (q, CIMFlavor (iq.getFlavor ()), true);	
321 a.dunfey      1.54.2.1         }
322                            }   // end of this objects qualifier loop
323 mike          1.15     
324                            //--------------------------------------------------------------------------
325                            // Propagate qualifiers to subclass or to instance that do not have
326                            // already have those qualifiers:
327                            //--------------------------------------------------------------------------
328 karl          1.29         //cout << "KSTEST. Inherited qualifiers ct = " << inheritedQualifiers.getCount() << endl;
329 karl          1.25     
330 mike          1.15         for (Uint32 i = 0, n = inheritedQualifiers.getCount(); i < n; i++)
331                            {
332 a.dunfey      1.54.2.1         CIMQualifier iq = inheritedQualifiers.getQualifier(i);
333                                //cout << "KSTEST inherited qualifier propagate loop " <<  iq.getName() 
334                                //<< " flavor " << iq.getFlavor << " count " << i << endl;
335                        
336                                if (isInstancePart)
337                                {
338                                    if (!(iq.getFlavor ().hasFlavor
339                                          (CIMFlavor::TOINSTANCE)))
340                                        continue;
341                                }
342                                else
343                                {
344                                    if (!(iq.getFlavor ().hasFlavor
345                                          (CIMFlavor::TOSUBCLASS)))
346                                        continue;
347                                }
348                        
349                                // If the qualifiers list does not already contain this qualifier,
350                                // then propagate it (and set the propagated flag to true).	 Else we
351                                // keep current value. Note we have already eliminated any possibity that
352                                // a nonoverridable qualifier can be in the list.
353 a.dunfey      1.54.2.1         // Note that there is no exists() function ATTN:KS 25 Mar 2002
354                                if(find(iq.getName()) != PEG_NOT_FOUND)
355                                    continue;
356                        
357                                CIMQualifier q = iq.clone();
358                                q.setPropagated(true);
359                                _qualifiers.prepend(q);
360 mike          1.15         }
361                        }
362                        
363 mike          1.52     void CIMQualifierList::toXml(Buffer& out) const
364 mike          1.15     {
365                            for (Uint32 i = 0, n = _qualifiers.size(); i < n; i++)
366 kumpf         1.33     	XmlWriter::appendQualifierElement(out, _qualifiers[i]);
367 mike          1.15     }
368                        
369 mike          1.17     /** toMof - Generates MOF output for a list of CIM Qualifiers.
370                            The qualifiers may be class, property, parameter, etc.
371                            The BNF for this is:
372                            <pre>
373                            qualifierList       = "[" qualifier *( "," qualifier ) "]"
374                            </pre>
375                            Produces qualifiers as a string on without nl.
376                            */
377 mike          1.52     void CIMQualifierList::toMof(Buffer& out) const
378 mike          1.17     {
379                            // if no qualifiers, return
380                            if (_qualifiers.size() == 0)
381                        	return;
382                        
383                            // Qualifier leading bracket.
384 mike          1.53         out.append('[');
385 mike          1.17     
386                            // Loop to list qualifiers
387                            for (Uint32 i = 0, n = _qualifiers.size(); i < n; i++)
388                            {
389                        	// if second or greater, add comma separator
390                        	if (i > 0)
391 mike          1.53     	    out << STRLIT(", \n");
392 kumpf         1.34     	MofWriter::appendQualifierElement(out, _qualifiers[i]);
393 mike          1.17         }
394                            
395                            // Terminating bracket
396 mike          1.53         out.append(']');
397 mike          1.17     }
398                        
399                        
400 mike          1.15     void CIMQualifierList::print(PEGASUS_STD(ostream) &os) const
401                        {
402 mike          1.52         Buffer tmp;
403 mike          1.15         toXml(tmp);
404                            tmp.append('\0');
405                            os << tmp.getData() << PEGASUS_STD(endl);
406                        }
407                        
408                        Boolean CIMQualifierList::identical(const CIMQualifierList& x) const
409                        {
410                            Uint32 count = getCount();
411                        
412                            if (count != x.getCount())
413                        	return false;
414                        
415                            for (Uint32 i = 0; i < count; i++)
416 mike          1.16         {
417                        	if (!_qualifiers[i].identical(x._qualifiers[i]))
418                        	    return false;
419                            }
420 mike          1.15     
421                            return true;
422                        }
423                        
424                        void CIMQualifierList::cloneTo(CIMQualifierList& x) const
425                        {
426                            x._qualifiers.clear();
427 kumpf         1.36         x._qualifiers.reserveCapacity(_qualifiers.size());
428 mike          1.15     
429                            for (Uint32 i = 0, n = _qualifiers.size(); i < n; i++)
430                        	x._qualifiers.append(_qualifiers[i].clone());
431                        }
432                        
433                        PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2