1 mike 1.15 //%/////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001 The Open group, BMC Software, Tivoli Systems, IBM
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to
7 // deal in the Software without restriction, including without limitation the
8 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 // sell copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
13 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
14 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
15 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
16 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
18 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
19 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 //
21 //==============================================================================
22 mike 1.15 //
23 // Author: Mike Brasher (mbrasher@bmc.com)
24 //
|
25 karl 1.24 // Modified By: Karl Schopmeyer (k.schopmeyer@opengroup.org)
|
26 mike 1.15 //
27 //%/////////////////////////////////////////////////////////////////////////////
28
29 #include "CIMQualifierList.h"
30 #include "DeclContext.h"
31 #include "CIMQualifierDecl.h"
32 #include "CIMName.h"
33 #include "Indentor.h"
34 #include "XmlWriter.h"
35
36 PEGASUS_NAMESPACE_BEGIN
|
37 karl 1.18 PEGASUS_USING_STD;
|
38 mike 1.15
39 CIMQualifierList::CIMQualifierList()
40 {
41
42 }
43
44 CIMQualifierList::~CIMQualifierList()
45 {
46
47 }
48
49 CIMQualifierList& CIMQualifierList::add(const CIMQualifier& qualifier)
50 {
51 if (!qualifier)
52 throw UnitializedHandle();
53
54 if (find(qualifier.getName()) != PEG_NOT_FOUND)
55 throw AlreadyExists();
56
57 _qualifiers.append(qualifier);
58
59 mike 1.15 return *this;
60 }
61 //ATTN: Why do we not do the outofbounds check here. KS 18 May 2k
62 CIMQualifier& CIMQualifierList::getQualifier(Uint32 pos)
63 {
64 return _qualifiers[pos];
65 }
66
67 //ATTN: added ks 18 may 2001. Should we have outofbounds?
68 void CIMQualifierList::removeQualifier(Uint32 pos)
69 {
70 _qualifiers.remove(pos);
71 }
72
73 Uint32 CIMQualifierList::find(const String& name) const
74 {
75 for (Uint32 i = 0, n = _qualifiers.size(); i < n; i++)
76 {
77 if (CIMName::equal(_qualifiers[i].getName(), name))
78 return i;
79 }
80 mike 1.15
81 return PEG_NOT_FOUND;
82 }
83
84 Uint32 CIMQualifierList::findReverse(const String& name) const
85 {
86 for (Uint32 i = _qualifiers.size(); i; --i)
87 {
88 if (CIMName::equal(_qualifiers[i - 1].getName(), name))
89 return i - 1;
90 }
91
92 return PEG_NOT_FOUND;
93 }
94
95 void CIMQualifierList::resolve(
96 DeclContext* declContext,
97 const String& nameSpace,
|
98 karl 1.25 Uint32 scope, // Scope of the entity being resolved.
|
99 mike 1.15 Boolean isInstancePart,
|
100 mike 1.23 CIMQualifierList& inheritedQualifiers,
|
101 karl 1.25 Boolean propagateQualifiers) // Apparently not used ks 24 mar 2002
|
102 mike 1.15 {
103 // For each qualifier in the qualifiers array, the following
104 // is checked:
105 //
106 // 1. Whether it is declared (can be obtained from the declContext).
107 //
108 // 2. Whether it has the same type as the declaration.
109 //
|
110 karl 1.24 // 3. Whether the qualifier is valid for the given scope.
|
111 mike 1.15 //
112 // 4. Whether the qualifier can be overriden (the flavor is
113 // ENABLEOVERRIDE on the corresponding reference qualifier).
114 //
115 // 5. Whether the qualifier should be propagated to the subclass.
116 //
117 // If the qualifier should be overriden, then it is injected into the
118 // qualifiers array (from the inheritedQualifiers array).
119
120 for (Uint32 i = 0, n = _qualifiers.size(); i < n; i++)
121 {
|
122 karl 1.24 CIMQualifier q = _qualifiers[i];
123 //----------------------------------------------------------------------
124 // 1. Check to see if it's declared.
125 //----------------------------------------------------------------------
126
127 CIMConstQualifierDecl qd = declContext->lookupQualifierDecl(
128 nameSpace, q.getName());
129
130 if (!qd)
131 throw UndeclaredQualifier(q.getName());
132
133 //----------------------------------------------------------------------
134 // 2. Check the type and isArray. Must be the same:
135 //----------------------------------------------------------------------
136
137 if (!(q.getType() == qd.getType() && q.isArray() == qd.isArray()))
138 throw BadQualifierType(q.getName());
139
140 //----------------------------------------------------------------------
141 // 3. Check the scope: Must be legal for this qualifier
142 //----------------------------------------------------------------------
143 karl 1.24 //#if 0
144 // ATTN: These lines throw a bogus exception if the qualifier has
145 // a valid scope (such as Scope::ASSOCIATION) which is not Scope::CLASS
146 // ks Mar 2002. Reinstalled 23 March 2002 to test.
147
148 if (!(qd.getScope() & scope))
149 throw BadQualifierScope(qd.getName(), ScopeToString(scope));
150 //#endif
151 //----------------------------------------------------------------------
152 // See if this qualifier is contained in the inheritedQualifiers. If
153 // so then we must handle the OVERRIDABLE flavor.
154 //----------------------------------------------------------------------
155
156 // ATTN: there seems to be a problem with the CIM schema that marks the
157 // abstract qualifier as non-overridable but then they override it.
158 // For now it is just disabled. This problem exists in both XML and
159 // CIM schema.
|
160 karl 1.25
161 // Move the flavor from declaration
|
162 karl 1.26 // Always sets flavor to the declaration flavor.
|
163 karl 1.25 q.setFlavor(qd.getFlavor());
164 //#if 0
|
165 karl 1.24 Uint32 pos = inheritedQualifiers.find(q.getName());
|
166 karl 1.25
167 //cout << "KSTEST Qualifier resolve inherit test " << q.getName()
168 //<< " Inherited Position = " << pos << endl;
169
|
170 karl 1.26 // Test for Qualifier found in SuperClass. If found and qualifier
171 // is not overridable, Must be identical.
172 // Thus - abstract (not Overridable and restricted) can be found in subclasses
173 // I can have nonabstracts below abstracts. No propagation.
174 // Association (notOverridable and tosubclass) can be found in subclasses but
175 // cannot be changed. No non-aswsociatons below associations..
176 // Throw exception if DisableOverride and tosubclass and different value
|
177 karl 1.24 if (pos != PEG_NOT_FOUND)
178 {
179 CIMConstQualifier iq = inheritedQualifiers.getQualifier(pos);
|
180 karl 1.26 if (!qd.isFlavor(CIMFlavor::OVERRIDABLE) && qd.isFlavor(CIMFlavor::TOSUBCLASS))
181 if(!q.identical(iq))
182 throw BadQualifierOverride(q.getName());
|
183 karl 1.24 }
|
184 karl 1.25 //#endif
185 } // end of this objects qualifier loop
|
186 mike 1.15
187 //--------------------------------------------------------------------------
188 // Propagate qualifiers to subclass or to instance that do not have
189 // already have those qualifiers:
190 //--------------------------------------------------------------------------
|
191 karl 1.25 //cout << "KSTEST. Loop of inherited qualifiers. Number = "
192 // << inheritedQualifiers.getCount() << endl;
193
|
194 mike 1.15 for (Uint32 i = 0, n = inheritedQualifiers.getCount(); i < n; i++)
195 {
|
196 karl 1.24 CIMQualifier iq = inheritedQualifiers.getQualifier(i);
|
197 karl 1.25 //cout << "KSTEST inherited qualifier propagate loop " << iq.getName()
|
198 karl 1.24 //<< " flavor " << iq.getFlavor << " count " << i << endl;
199
200 // ATTN-DE-P1-This next test is incorrect. It is a temporary, hard-coded
201 // HACK to avoid propagating the "Abstract" Qualifier to subclasses
202 //if (CIMName::equal(iq.getName(), "Abstract"))
203 // continue;
|
204 karl 1.25 //<< " flavor= " << iq.getFlavor()
205 //<< " TOSUBCLASS " << (iq.getFlavor() && CIMFlavor::TOSUBCLASS) << endl;
|
206 karl 1.24
207 if (isInstancePart)
208 {
209 if (!iq.isFlavor(CIMFlavor::TOINSTANCE))
210 continue;
211 }
212 else
213 {
214 if (!iq.isFlavor(CIMFlavor::TOSUBCLASS))
215 continue;
216 }
217
218 // If the qualifiers list does not already contain this qualifier,
|
219 karl 1.25 // then propagate it (and set the propagated flag to true). Else we
220 // keep current value. Note we have already eliminated any possibity that
221 // a nonoverridable qualifier can be in the list.
222 // Note that there is no exists() function ATTN:KS 25 Mar 2002
223 if(find(iq.getName()) != PEG_NOT_FOUND)
|
224 karl 1.24 continue;
225
226 CIMQualifier q = iq.clone();
227 q.setPropagated(true);
228 _qualifiers.prepend(q);
|
229 mike 1.15 }
230 }
231
232 void CIMQualifierList::toXml(Array<Sint8>& out) const
233 {
234 for (Uint32 i = 0, n = _qualifiers.size(); i < n; i++)
235 _qualifiers[i].toXml(out);
236 }
237
|
238 mike 1.17 /** toMof - Generates MOF output for a list of CIM Qualifiers.
239 The qualifiers may be class, property, parameter, etc.
240 The BNF for this is:
241 <pre>
242 qualifierList = "[" qualifier *( "," qualifier ) "]"
243 </pre>
244 Produces qualifiers as a string on without nl.
245 */
246 void CIMQualifierList::toMof(Array<Sint8>& out) const
247 {
248 // if no qualifiers, return
249 if (_qualifiers.size() == 0)
250 return;
251
252 // Qualifier leading bracket.
253 out <<"[";
254
255 // Loop to list qualifiers
256 for (Uint32 i = 0, n = _qualifiers.size(); i < n; i++)
257 {
258 // if second or greater, add comma separator
259 mike 1.17 if (i > 0)
|
260 karl 1.22 out << ", \n";
|
261 mike 1.17 _qualifiers[i].toMof(out);
262 }
263
264 // Terminating bracket
265 out << "]";
266 }
267
268
|
269 mike 1.15 void CIMQualifierList::print(PEGASUS_STD(ostream) &os) const
270 {
271 Array<Sint8> tmp;
272 toXml(tmp);
273 tmp.append('\0');
274 os << tmp.getData() << PEGASUS_STD(endl);
275 }
276
277 Boolean CIMQualifierList::identical(const CIMQualifierList& x) const
278 {
279 Uint32 count = getCount();
280
281 if (count != x.getCount())
282 return false;
283
284 for (Uint32 i = 0; i < count; i++)
|
285 mike 1.16 {
286 if (!_qualifiers[i].identical(x._qualifiers[i]))
287 return false;
288 }
|
289 mike 1.15
290 return true;
291 }
292
293 void CIMQualifierList::cloneTo(CIMQualifierList& x) const
294 {
295 x._qualifiers.clear();
296 x._qualifiers.reserve(_qualifiers.size());
297
298 for (Uint32 i = 0, n = _qualifiers.size(); i < n; i++)
299 x._qualifiers.append(_qualifiers[i].clone());
300 }
301
302 PEGASUS_NAMESPACE_END
|