1 karl 1.21 //%2005////////////////////////////////////////////////////////////////////////
|
2 chip 1.1 //
|
3 karl 1.16 // 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 chip 1.1 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.16 // 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.21 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 chip 1.1 //
12 // Permission is hereby granted, free of charge, to any person obtaining a copy
13 // 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 // 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 karl 1.21 //
|
19 chip 1.1 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
20 // 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 // 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 // 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: Chip Vincent (cvincent@us.ibm.com)
31 //
|
32 chip 1.17 // Modified By:
|
33 chip 1.1 //
34 //%/////////////////////////////////////////////////////////////////////////////
35
36 #include <Pegasus/Common/ObjectNormalizer.h>
37
38 PEGASUS_NAMESPACE_BEGIN
39
|
40 chip 1.17 static CIMQualifier _processQualifier(
|
41 chip 1.1 const CIMQualifier & referenceQualifier,
42 const CIMQualifier & cimQualifier)
43 {
|
44 chip 1.17 // check name
45 if(!referenceQualifier.getName().equal(cimQualifier.getName()))
46 {
47 String message = cimQualifier.getName().getString() + String(" invalid qualifier name.");
48
49 throw CIMException(CIM_ERR_FAILED, message);
50 }
|
51 chip 1.15
52 // check type
53 if(referenceQualifier.getType() != cimQualifier.getType())
54 {
|
55 chip 1.17 String message = cimQualifier.getName().getString() + String(" incorrect qualifier type.");
|
56 chip 1.15
|
57 chip 1.17 throw CIMException(CIM_ERR_FAILED, message);
|
58 chip 1.15 }
|
59 chip 1.1
|
60 chip 1.17 CIMQualifier normalizedQualifier(
61 referenceQualifier.getName(),
62 referenceQualifier.getValue(), // default value
63 referenceQualifier.getFlavor(),
64 referenceQualifier.getPropagated() == 0 ? false : true);
|
65 chip 1.1
|
66 chip 1.17 // update value
67 if(!cimQualifier.getValue().isNull())
|
68 chip 1.1 {
|
69 chip 1.17 normalizedQualifier.setValue(cimQualifier.getValue());
|
70 chip 1.1 }
71
|
72 chip 1.17 return(normalizedQualifier);
|
73 chip 1.1 }
74
|
75 chip 1.17 static CIMProperty _processProperty(
|
76 chip 1.1 const CIMProperty & referenceProperty,
77 const CIMProperty & cimProperty,
78 const Boolean includeQualifiers,
79 const Boolean includeClassOrigin)
80 {
|
81 chip 1.17 // check name
82 if(!referenceProperty.getName().equal(cimProperty.getName()))
83 {
84 String message = cimProperty.getName().getString() + String(" invalid property name.");
85
86 throw CIMException(CIM_ERR_FAILED, message);
87 }
|
88 chip 1.1
|
89 chip 1.15 // check type
90 if(referenceProperty.getType() != cimProperty.getType())
91 {
|
92 chip 1.17 String message = cimProperty.getName().getString() + String(" incorrect property type.");
|
93 chip 1.15
|
94 chip 1.17 throw CIMException(CIM_ERR_FAILED, message);
|
95 chip 1.15 }
96
|
97 chip 1.17 // TODO: check array size?
98
99 CIMProperty normalizedProperty(
100 referenceProperty.getName(),
101 referenceProperty.getValue(), // default value
102 referenceProperty.getArraySize(),
103 referenceProperty.getReferenceClassName(),
104 CIMName(),
105 false);
|
106 chip 1.1
107 // TODO: check override (especially for references)?
108
|
109 chip 1.14 // update value
|
110 chip 1.17 if(!cimProperty.getValue().isNull())
111 {
112 normalizedProperty.setValue(cimProperty.getValue());
113 }
|
114 chip 1.6
|
115 chip 1.17 // update class origin
|
116 chip 1.1 if(includeClassOrigin)
117 {
|
118 chip 1.17 normalizedProperty.setClassOrigin(referenceProperty.getClassOrigin());
|
119 chip 1.1 }
120
121 // add qualifiers
122 if(includeQualifiers)
123 {
|
124 chip 1.17 // propagate class property qualifiers
|
125 chip 1.1 for(Uint32 i = 0, n = referenceProperty.getQualifierCount(); i < n;i++)
126 {
|
127 chip 1.17 CIMConstQualifier referenceQualifier = referenceProperty.getQualifier(i);
|
128 chip 1.1
|
129 chip 1.17 normalizedProperty.addQualifier(referenceQualifier.clone());
|
130 chip 1.1 }
131
|
132 chip 1.17 // update qualifier values from property or add any new ones
|
133 chip 1.1 for(Uint32 i = 0, n = cimProperty.getQualifierCount(); i < n; i++)
134 {
|
135 chip 1.17 CIMConstQualifier cimQualifier = cimProperty.getQualifier(i);
|
136 chip 1.1
|
137 chip 1.17 // attempt to find existing qualifier
138 Uint32 pos = normalizedProperty.findQualifier(cimQualifier.getName());
|
139 chip 1.14
|
140 chip 1.1 if(pos == PEG_NOT_FOUND)
141 {
|
142 chip 1.17 // add qualifier
|
143 chip 1.14
144 // TODO: ensure the qualifier is exists and is valid in this scope
145
|
146 chip 1.17 normalizedProperty.addQualifier(cimQualifier.clone());
|
147 chip 1.14 }
148 else
149 {
150 // update qualifier
151
|
152 chip 1.17 // TODO: normalize qualifier fisrt to check type, etc.?
153
154 normalizedProperty.getQualifier(pos).setValue(cimQualifier.getValue());
|
155 chip 1.1 }
156 }
157 }
158
|
159 chip 1.17 return(normalizedProperty);
|
160 chip 1.1 }
161
|
162 chip 1.20 ObjectNormalizer::ObjectNormalizer(void)
163 : _localOnly(false),
164 _includeQualifiers(false),
165 _includeClassOrigin(false)
166 {
167 }
168
|
169 chip 1.17 ObjectNormalizer::ObjectNormalizer(
170 const CIMClass & cimClass,
171 const Boolean localOnly,
|
172 chip 1.1 const Boolean includeQualifiers,
173 const Boolean includeClassOrigin)
|
174 chip 1.17 :
175 _cimClass(cimClass),
176 _localOnly(localOnly),
177 _includeQualifiers(includeQualifiers),
178 _includeClassOrigin(includeClassOrigin)
|
179 chip 1.1 {
180 }
181
|
182 chip 1.17 CIMObjectPath ObjectNormalizer::processClassObjectPath(const CIMObjectPath & cimObjectPath) const
|
183 chip 1.1 {
|
184 chip 1.17 // pre-check
185 if(_cimClass.isUninitialized())
186 {
187 // do nothing
188 return(cimObjectPath);
189 }
|
190 chip 1.1
|
191 chip 1.17 if(cimObjectPath.getClassName().isNull())
192 {
193 throw CIMException(CIM_ERR_FAILED, "uninitialized object path");
194 }
|
195 chip 1.1
|
196 chip 1.17 // check class name
197 if(!_cimClass.getClassName().equal(cimObjectPath.getClassName()))
|
198 chip 1.1 {
|
199 chip 1.17 String message = cimObjectPath.getClassName().getString() + String(" invalid class name.");
|
200 chip 1.1
|
201 chip 1.17 throw CIMException(CIM_ERR_FAILED, message);
202 }
|
203 chip 1.1
|
204 chip 1.17 CIMObjectPath normalizedObjectPath(
205 _cimClass.getPath().getHost(),
206 _cimClass.getPath().getNameSpace(),
207 _cimClass.getClassName()); // use reference class name to preserve case
|
208 chip 1.1
|
209 chip 1.17 // ignore any keys, they are not part of a class object path
|
210 chip 1.6
|
211 chip 1.17 return(normalizedObjectPath);
212 }
|
213 chip 1.1
|
214 chip 1.17 CIMObjectPath ObjectNormalizer::processInstanceObjectPath(const CIMObjectPath & cimObjectPath) const
215 {
216 // pre-check
217 if(_cimClass.isUninitialized())
218 {
219 // do nothing
220 return(cimObjectPath);
221 }
|
222 chip 1.14
|
223 chip 1.17 if(cimObjectPath.getClassName().isNull())
224 {
225 throw CIMException(CIM_ERR_FAILED, "uninitialized object path");
|
226 chip 1.1 }
227
|
228 chip 1.17 // check class name
229 if(!_cimClass.getClassName().equal(cimObjectPath.getClassName()))
|
230 chip 1.1 {
|
231 chip 1.17 String message = cimObjectPath.getClassName().getString() + String(" invalid class name.");
|
232 chip 1.1
|
233 chip 1.17 throw CIMException(CIM_ERR_FAILED, message);
234 }
|
235 chip 1.1
|
236 chip 1.17 CIMObjectPath normalizedObjectPath(
237 _cimClass.getPath().getHost(),
238 _cimClass.getPath().getNameSpace(),
239 _cimClass.getClassName()); // use reference class name to preserve case
|
240 chip 1.1
|
241 chip 1.17 // get the key property names from the class
242 Array<CIMKeyBinding> keys;
|
243 chip 1.1
|
244 chip 1.17 // identify and complete the keys
245 for(Uint32 i = 0, n = _cimClass.getPropertyCount(); i < n; i++)
|
246 chip 1.1 {
|
247 chip 1.17 CIMConstProperty cimProperty = _cimClass.getProperty(i);
248
249 Uint32 pos = cimProperty.findQualifier("key");
|
250 chip 1.1
|
251 chip 1.17 if((pos != PEG_NOT_FOUND) && (cimProperty.getQualifier(pos).getValue().equal(CIMValue(true))))
252 {
253 // get the property name from the class to preserve case
254 CIMName name = cimProperty.getName();
|
255 chip 1.4
|
256 chip 1.17 // ATTN: there is no way to determine the differenciate a null string and a
257 // zero length string. the former is invalid, while the later is valid. as
258 // a lame workaround, the string value of a key is set to the literal '<null>'
259 // if there is no default value. this allows a missing key without a default value
260 // to be detected. hopefully, '<null>' is never used as a literal key value.
|
261 chip 1.4
|
262 chip 1.17 // get the string value regardless of type
263 String value = cimProperty.getValue().isNull() ? "<null>" : cimProperty.getValue().toString();
|
264 chip 1.1
|
265 chip 1.17 // override the value from the specified object
266 for(Uint32 j = 0, m = cimObjectPath.getKeyBindings().size(); j < m; j++)
267 {
268 if(name.equal(cimObjectPath.getKeyBindings()[j].getName()))
269 {
270 // TODO: convert to value to check type compatibility
271 value = cimObjectPath.getKeyBindings()[j].getValue();
|
272 chip 1.1
|
273 chip 1.17 break;
274 }
275 }
|
276 chip 1.1
|
277 chip 1.17 // no default and not overriden by specified object path
278 if(value == "<null>")
|
279 chip 1.1 {
|
280 chip 1.17 String message = name.getString() + String(" key property missing from object path.");
281
282 throw CIMException(CIM_ERR_FAILED, message);
|
283 chip 1.1 }
284
|
285 chip 1.17 CIMKeyBinding::Type type;
|
286 chip 1.1
|
287 chip 1.17 switch(_cimClass.getProperty(_cimClass.findProperty(name)).getType())
288 {
289 case CIMTYPE_BOOLEAN:
290 type = CIMKeyBinding::BOOLEAN;
|
291 chip 1.1
|
292 chip 1.17 break;
293 case CIMTYPE_UINT8:
294 case CIMTYPE_SINT8:
295 case CIMTYPE_UINT16:
296 case CIMTYPE_SINT16:
297 case CIMTYPE_UINT32:
298 case CIMTYPE_SINT32:
299 case CIMTYPE_UINT64:
300 case CIMTYPE_SINT64:
301 case CIMTYPE_REAL32:
302 case CIMTYPE_REAL64:
303 type = CIMKeyBinding::NUMERIC;
304
305 break;
306 case CIMTYPE_CHAR16:
307 case CIMTYPE_STRING:
308 case CIMTYPE_DATETIME:
309 type = CIMKeyBinding::STRING;
310
311 break;
312 case CIMTYPE_REFERENCE:
313 chip 1.17 type = CIMKeyBinding::REFERENCE;
314
315 break;
316 case CIMTYPE_OBJECT:
317 default:
318 throw CIMException(CIM_ERR_FAILED, "invalid key type.");
319 break;
320 }
|
321 chip 1.1
|
322 chip 1.17 keys.append(CIMKeyBinding(name, value, type));
|
323 chip 1.1 }
324 }
325
|
326 chip 1.17 normalizedObjectPath.setKeyBindings(keys);
327
328 return(normalizedObjectPath);
329 }
330
331 CIMInstance ObjectNormalizer::processInstance(const CIMInstance & cimInstance) const
332 {
333 // pre-checks
334 if(_cimClass.isUninitialized())
|
335 chip 1.1 {
|
336 chip 1.17 // do nothing
337 return(cimInstance);
338 }
|
339 chip 1.1
|
340 chip 1.17 if(cimInstance.isUninitialized())
341 {
342 throw CIMException(CIM_ERR_FAILED, "unintialized instance object.");
|
343 chip 1.1 }
344
|
345 chip 1.17 // check class name
346 if(!_cimClass.getClassName().equal(cimInstance.getClassName()))
|
347 chip 1.1 {
|
348 chip 1.17 String message = cimInstance.getClassName().getString() + String(" invalid class name.");
|
349 chip 1.1
|
350 chip 1.17 throw CIMException(CIM_ERR_FAILED, message);
|
351 chip 1.1 }
352
|
353 chip 1.17 CIMInstance normalizedInstance(_cimClass.getClassName()); // use the original class name to preserve case
|
354 chip 1.1
|
355 chip 1.17 // process instance qualifiers
356 if(_includeQualifiers)
|
357 chip 1.1 {
|
358 chip 1.17 // propagate class qualifiers
359 for(Uint32 i = 0, n = _cimClass.getQualifierCount(); i < n; i++)
|
360 chip 1.1 {
|
361 chip 1.17 CIMConstQualifier referenceQualifier = _cimClass.getQualifier(i);
|
362 chip 1.1
|
363 chip 1.17 // ATTN: all class qualifiers are propagated to instance because making it
364 // work as it should (only pass qualifiers with TOINSTANCE) would break
365 // existing behavior.
366 CIMQualifier cimQualifier(
367 referenceQualifier.getName(),
368 referenceQualifier.getValue(),
369 referenceQualifier.getFlavor(),
370 false);
|
371 chip 1.1
|
372 chip 1.17 normalizedInstance.addQualifier(cimQualifier);
|
373 chip 1.1 }
374
|
375 chip 1.17 // update qualifier values from instance or add any new ones
|
376 chip 1.1 for(Uint32 i = 0, n = cimInstance.getQualifierCount(); i < n; i++)
377 {
|
378 chip 1.17 CIMConstQualifier cimQualifier = cimInstance.getQualifier(i);
|
379 chip 1.1
|
380 chip 1.17 // attempt to find existing qualifier
381 Uint32 pos = normalizedInstance.findQualifier(cimQualifier.getName());
|
382 chip 1.14
|
383 chip 1.1 if(pos == PEG_NOT_FOUND)
384 {
|
385 chip 1.17 // add
|
386 chip 1.12
387 // TODO: ensure the qualifier is exists and is valid in this scope
388
|
389 chip 1.17 normalizedInstance.addQualifier(cimQualifier.clone());
|
390 chip 1.1 }
|
391 chip 1.12 else
392 {
|
393 chip 1.17 // update
394
395 // ATTN: normalize qualifier fisrt to check type, etc.?
|
396 chip 1.1
|
397 chip 1.17 normalizedInstance.getQualifier(pos).setValue(cimQualifier.getValue());
|
398 chip 1.12 }
|
399 chip 1.1 }
400 }
401
|
402 chip 1.17 // 3) check property names and types. any properties in the instance but not in the
403 // class are implictly dropped (normalized).
|
404 chip 1.1 for(Uint32 i = 0, n = cimInstance.getPropertyCount(); i < n; i++)
405 {
|
406 chip 1.17 CIMConstProperty cimProperty = cimInstance.getProperty(i);
|
407 chip 1.6
|
408 chip 1.17 Uint32 pos = _cimClass.findProperty(cimProperty.getName());
|
409 chip 1.1
|
410 chip 1.17 if(pos != PEG_NOT_FOUND)
|
411 chip 1.1 {
|
412 chip 1.17 CIMConstProperty referenceProperty = _cimClass.getProperty(pos);
|
413 chip 1.1
|
414 chip 1.17 // 4) if local only is true, only process properties defined in the class. otherwise, do all properties
415 if(!_localOnly || (_localOnly && _cimClass.getClassName().equal(referenceProperty.getClassOrigin())))
416 {
417 CIMProperty normalizedProperty =
418 _processProperty(
419 referenceProperty.clone(),
420 cimProperty.clone(),
421 _includeQualifiers,
422 _includeClassOrigin);
|
423 chip 1.1
|
424 chip 1.17 normalizedInstance.addProperty(normalizedProperty);
425 }
|
426 chip 1.9 }
|
427 chip 1.1 }
428
|
429 chip 1.17 // update object path
430 CIMObjectPath cimObjectPath(cimInstance.getPath());
|
431 chip 1.14
|
432 chip 1.17 cimObjectPath.setClassName(_cimClass.getClassName());
|
433 chip 1.14
|
434 chip 1.17 // add keys from instance if none specified
435 if(cimInstance.getPath().getKeyBindings().size() == 0)
|
436 chip 1.13 {
|
437 chip 1.17 Array<CIMKeyBinding> keys;
|
438 chip 1.1
|
439 chip 1.17 Array<CIMName> keyNames;
|
440 chip 1.13
|
441 chip 1.17 _cimClass.getKeyNames(keyNames);
|
442 chip 1.1
|
443 chip 1.17 for(Uint32 i = 0, n = keyNames.size(); i < n; i++)
|
444 chip 1.1 {
|
445 chip 1.17 Uint32 pos = cimInstance.findProperty(keyNames[i]);
|
446 chip 1.13
447 if(pos != PEG_NOT_FOUND)
448 {
|
449 chip 1.17 keys.append(CIMKeyBinding(keyNames[i], cimInstance.getProperty(pos).getValue())); // get key name from class to preserve case
|
450 chip 1.13 }
|
451 chip 1.1 }
452
|
453 chip 1.17 cimObjectPath.setKeyBindings(keys);
|
454 chip 1.1 }
455
|
456 chip 1.17 normalizedInstance.setPath(processInstanceObjectPath(cimObjectPath));
|
457 chip 1.1
|
458 chip 1.17 return(normalizedInstance);
|
459 chip 1.1 }
460
461 PEGASUS_NAMESPACE_END
|