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