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

  1 karl  1.31 //%2006////////////////////////////////////////////////////////////////////////
  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 karl  1.31 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 12            // EMC Corporation; Symantec Corporation; The Open Group.
 13 chip  1.1  //
 14            // Permission is hereby granted, free of charge, to any person obtaining a copy
 15            // 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            // 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 karl  1.31 // 
 21 chip  1.1  // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 22            // 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            // 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            // 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: Chip Vincent (cvincent@us.ibm.com)
 33            //
 34 chip  1.17 // Modified By:
 35 chip  1.1  //
 36            //%/////////////////////////////////////////////////////////////////////////////
 37            
 38            #include <Pegasus/Common/ObjectNormalizer.h>
 39            
 40            PEGASUS_NAMESPACE_BEGIN
 41            
 42 chip  1.17 static CIMQualifier _processQualifier(
 43 chip  1.26     CIMConstQualifier & referenceQualifier,
 44                CIMConstQualifier & cimQualifier)
 45 chip  1.1  {
 46 chip  1.17     // check name
 47                if(!referenceQualifier.getName().equal(cimQualifier.getName()))
 48                {
 49 chip  1.22         MessageLoaderParms message(
 50                        "Common.ObjectNormalizer.INVALID_QUALIFIER_NAME",
 51 chip  1.23             "Invalid qualifier name: $0",
 52 chip  1.22             cimQualifier.getName().getString());
 53 chip  1.17 
 54                    throw CIMException(CIM_ERR_FAILED, message);
 55                }
 56 chip  1.15 
 57                // check type
 58                if(referenceQualifier.getType() != cimQualifier.getType())
 59                {
 60 chip  1.22         MessageLoaderParms message(
 61                        "Common.ObjectNormalizer.INVALID_QUALIFIER_TYPE",
 62 chip  1.23             "Invalid qualifier type: $0",
 63 chip  1.22             cimQualifier.getName().getString());
 64 chip  1.15 
 65 chip  1.17         throw CIMException(CIM_ERR_FAILED, message);
 66 chip  1.15     }
 67 chip  1.1  
 68 chip  1.17     CIMQualifier normalizedQualifier(
 69                    referenceQualifier.getName(),
 70                    referenceQualifier.getValue(),  // default value
 71                    referenceQualifier.getFlavor(),
 72                    referenceQualifier.getPropagated() == 0 ? false : true);
 73 chip  1.1  
 74 chip  1.26     // TODO: check override
 75            
 76 chip  1.17     // update value
 77                if(!cimQualifier.getValue().isNull())
 78 chip  1.1      {
 79 chip  1.17         normalizedQualifier.setValue(cimQualifier.getValue());
 80 chip  1.1      }
 81            
 82 chip  1.17     return(normalizedQualifier);
 83 chip  1.1  }
 84            
 85 chip  1.17 static CIMProperty _processProperty(
 86 chip  1.26     CIMConstProperty & referenceProperty,
 87                CIMConstProperty & cimProperty,
 88                Boolean includeQualifiers,
 89                Boolean includeClassOrigin)
 90 chip  1.1  {
 91 chip  1.17     // check name
 92                if(!referenceProperty.getName().equal(cimProperty.getName()))
 93                {
 94 chip  1.22         MessageLoaderParms message(
 95                        "Common.ObjectNormalizer.INVALID_PROPERTY_NAME",
 96 chip  1.23             "Invalid property name: $0",
 97 chip  1.22             cimProperty.getName().getString());
 98 chip  1.17 
 99                    throw CIMException(CIM_ERR_FAILED, message);
100                }
101 chip  1.1  
102 chip  1.15     // check type
103                if(referenceProperty.getType() != cimProperty.getType())
104                {
105 chip  1.22         MessageLoaderParms message(
106 chip  1.23             "Common.ObjectNormalizer.INVALID_PROPERTY_TYPE",
107                        "Invalid property type: $0",
108 chip  1.22             cimProperty.getName().getString());
109 chip  1.15 
110 chip  1.17         throw CIMException(CIM_ERR_FAILED, message);
111 chip  1.15     }
112            
113 chip  1.17     // TODO: check array size?
114            
115                CIMProperty normalizedProperty(
116                    referenceProperty.getName(),
117                    referenceProperty.getValue(),   // default value
118                    referenceProperty.getArraySize(),
119                    referenceProperty.getReferenceClassName(),
120                    CIMName(),
121                    false);
122 chip  1.1  
123                // TODO: check override (especially for references)?
124            
125 chip  1.14     // update value
126 chip  1.17     if(!cimProperty.getValue().isNull())
127                {
128                    normalizedProperty.setValue(cimProperty.getValue());
129                }
130 chip  1.6  
131 chip  1.17     // update class origin
132 chip  1.1      if(includeClassOrigin)
133                {
134 chip  1.17         normalizedProperty.setClassOrigin(referenceProperty.getClassOrigin());
135 chip  1.1      }
136            
137                // add qualifiers
138                if(includeQualifiers)
139                {
140 chip  1.17         // propagate class property qualifiers
141 chip  1.26         for(Uint32 i = 0, n = referenceProperty.getQualifierCount(); i < n; i++)
142 chip  1.1          {
143 chip  1.17             CIMConstQualifier referenceQualifier = referenceProperty.getQualifier(i);
144 chip  1.1  
145 chip  1.26             Uint32 pos = cimProperty.findQualifier(referenceQualifier.getName());
146 chip  1.1  
147 chip  1.26             // update value if qualifier is present in the specified property
148                        if(pos != PEG_NOT_FOUND)
149                        {
150                            CIMConstQualifier cimQualifier = cimProperty.getQualifier(pos);
151 chip  1.14 
152 chip  1.26                 CIMQualifier normalizedQualifier =
153                                _processQualifier(
154                                    referenceQualifier,
155                                    cimQualifier);
156 chip  1.14 
157 chip  1.26                 normalizedProperty.addQualifier(normalizedQualifier);
158 chip  1.14             }
159                        else
160                        {
161 chip  1.26                 normalizedProperty.addQualifier(referenceQualifier.clone());
162 chip  1.1              }
163                    }
164                }
165            
166 chip  1.17     return(normalizedProperty);
167 chip  1.1  }
168            
169 chip  1.20 ObjectNormalizer::ObjectNormalizer(void)
170 chip  1.24     : _includeQualifiers(false),
171 chip  1.20     _includeClassOrigin(false)
172            {
173            }
174            
175 chip  1.17 ObjectNormalizer::ObjectNormalizer(
176                const CIMClass & cimClass,
177 chip  1.26     Boolean includeQualifiers,
178                Boolean includeClassOrigin)
179                : _cimClass(cimClass),
180 chip  1.17     _includeQualifiers(includeQualifiers),
181                _includeClassOrigin(includeClassOrigin)
182 chip  1.1  {
183 chip  1.26     if(!_cimClass.isUninitialized())
184                {
185                    // ATTN: the following code is intended to expedite normalizing instances and instance object
186                    // paths by establishing the keys once now rather than multiple times later. it is biased
187                    // toward providers that return many instances with many properties.
188            
189                    // build a reference object path within the class
190                    Array<CIMKeyBinding> keys;
191            
192                    for(Uint32 i = 0, n = _cimClass.getPropertyCount(); i < n; i++)
193                    {
194                        CIMConstProperty referenceProperty = _cimClass.getProperty(i);
195            
196                        Uint32 pos = referenceProperty.findQualifier("key");
197            
198                        if((pos != PEG_NOT_FOUND) && (referenceProperty.getQualifier(pos).getValue().equal(CIMValue(true))))
199                        {
200 chip  1.30                 if(referenceProperty.getType() == CIMTYPE_REFERENCE)
201                            {
202                                // ATTN: a fake reference is inserted in the key so that the _BubbleSort() method
203                                // in CIMObjectPath does not throw and exception. It implicitly validates keys of
204                                // type REFERENCE so just place a dummy value for now. The value will be replaced
205                                // by the normalized object later.
206                                keys.append(CIMKeyBinding(referenceProperty.getName(), "class.key=\"value\"", CIMKeyBinding::REFERENCE));
207                            }
208                            else
209                            {
210                                keys.append(CIMKeyBinding(referenceProperty.getName(), referenceProperty.getValue()));
211                            }
212 chip  1.26             }
213                    }
214            
215                    // update class object path
216                    CIMObjectPath cimObjectPath(_cimClass.getPath());
217            
218                    cimObjectPath.setKeyBindings(keys);
219            
220                    _cimClass.setPath(cimObjectPath);
221                }
222 chip  1.1  }
223            
224 chip  1.17 CIMObjectPath ObjectNormalizer::processClassObjectPath(const CIMObjectPath & cimObjectPath) const
225 chip  1.1  {
226 chip  1.17     // pre-check
227                if(_cimClass.isUninitialized())
228                {
229                    // do nothing
230                    return(cimObjectPath);
231                }
232 chip  1.1  
233 chip  1.29     /*
234                // ATTN: moving similar logic to the response handlers because this type of error should
235                // be checked regardless with or without normalization enabled.
236 chip  1.17     if(cimObjectPath.getClassName().isNull())
237                {
238                    throw CIMException(CIM_ERR_FAILED, "uninitialized object path");
239                }
240 chip  1.29     */
241 chip  1.1  
242 chip  1.22     /*
243                // ATTN: The following code is currently redundant because the CIMName object validates
244                // legal names when it is constructed. It is included here for completeness.
245 chip  1.17     // check class name
246 chip  1.22     if(!CIMName(cimObjectPath.getClassName()).legal())
247                {
248                    MessageLoaderParms message(
249                        "Common.ObjectNormalizer.INVALID_CLASS_NAME",
250 chip  1.23             "Invalid class name: $0",
251 chip  1.22             cimObjectPath.getClassName().getString());
252            
253                    throw CIMException(CIM_ERR_FAILED, message);
254                }
255                */
256            
257                // check class type
258 chip  1.17     if(!_cimClass.getClassName().equal(cimObjectPath.getClassName()))
259 chip  1.1      {
260 chip  1.22         MessageLoaderParms message(
261                        "Common.ObjectNormalizer.INVALID_CLASS_TYPE",
262 chip  1.23             "Invalid class type: $0",
263 chip  1.22             cimObjectPath.getClassName().getString());
264 chip  1.1  
265 chip  1.17         throw CIMException(CIM_ERR_FAILED, message);
266                }
267 chip  1.1  
268 chip  1.17     CIMObjectPath normalizedObjectPath(
269                    _cimClass.getPath().getHost(),
270                    _cimClass.getPath().getNameSpace(),
271 chip  1.26         _cimClass.getClassName());
272 chip  1.1  
273 chip  1.17     // ignore any keys, they are not part of a class object path
274 chip  1.6  
275 chip  1.17     return(normalizedObjectPath);
276            }
277 chip  1.1  
278 chip  1.17 CIMObjectPath ObjectNormalizer::processInstanceObjectPath(const CIMObjectPath & cimObjectPath) const
279            {
280                // pre-check
281                if(_cimClass.isUninitialized())
282                {
283                    // do nothing
284                    return(cimObjectPath);
285                }
286 chip  1.14 
287 chip  1.29     /*
288                // ATTN: moving similar logic to the response handlers because this type of error should
289                // be checked regardless with or without normalization enabled.
290 chip  1.17     if(cimObjectPath.getClassName().isNull())
291                {
292                    throw CIMException(CIM_ERR_FAILED, "uninitialized object path");
293 chip  1.1      }
294 chip  1.29     */
295 chip  1.1  
296 chip  1.22     /*
297                // ATTN: The following code is currently redundant because the CIMName object validates
298                // legal names when it is constructed. It is included here for completeness.
299 chip  1.17     // check class name
300 chip  1.22     if(!CIMName(cimObjectPath.getClassName()).legal())
301                {
302                    MessageLoaderParms message(
303                        "Common.ObjectNormalizer.INVALID_CLASS_NAME",
304 chip  1.23             "Invalid class name: $0",
305 chip  1.22             cimObjectPath.getClassName().getString());
306            
307                    throw CIMException(CIM_ERR_FAILED, message);
308                }
309                */
310            
311                // check class type
312 chip  1.17     if(!_cimClass.getClassName().equal(cimObjectPath.getClassName()))
313 chip  1.1      {
314 chip  1.22         MessageLoaderParms message(
315                        "Common.ObjectNormalizer.INVALID_CLASS_TYPE",
316 chip  1.23             "Invalid class type: $0",
317 chip  1.22             cimObjectPath.getClassName().getString());
318 chip  1.1  
319 chip  1.17         throw CIMException(CIM_ERR_FAILED, message);
320                }
321 chip  1.1  
322 chip  1.17     CIMObjectPath normalizedObjectPath(
323                    _cimClass.getPath().getHost(),
324                    _cimClass.getPath().getNameSpace(),
325 chip  1.26         _cimClass.getClassName());
326            
327                Array<CIMKeyBinding> normalizedKeys;
328 chip  1.1  
329 chip  1.26     Array<CIMKeyBinding> referenceKeys = _cimClass.getPath().getKeyBindings();
330                Array<CIMKeyBinding> cimKeys = cimObjectPath.getKeyBindings();
331 chip  1.1  
332 chip  1.26     for(Uint32 i = 0, n = referenceKeys.size(); i < n; i++)
333 chip  1.1      {
334 chip  1.26         CIMKeyBinding key;
335 chip  1.17 
336 chip  1.26         // override the value from the specified object
337                    for(Uint32 j = 0, m = cimKeys.size(); j < m; j++)
338 chip  1.17         {
339 chip  1.26             if(referenceKeys[i].getName().equal(cimKeys[j].getName()))
340 chip  1.17             {
341 chip  1.26                 // check type
342                            if(referenceKeys[i].getType() != cimKeys[j].getType())
343 chip  1.22                 {
344                                MessageLoaderParms message(
345 chip  1.26                         "Common.ObjectNormalizer.INVALID_KEY_TYPE",
346                                    "Invalid key type: $0",
347                                    referenceKeys[i].getName().getString());
348 chip  1.22 
349                                throw CIMException(CIM_ERR_FAILED, message);
350                            }
351            
352 chip  1.28                 key = CIMKeyBinding(referenceKeys[i].getName(), cimKeys[j].getValue(), referenceKeys[i].getType());
353 chip  1.26 
354 chip  1.17                 break;
355                        }
356 chip  1.26         }
357 chip  1.1  
358 chip  1.26         // key not found
359                    if(key.getName().isNull())
360                    {
361                        MessageLoaderParms message(
362                            "Common.ObjectNormalizer.MISSING_KEY",
363                            "Missing key: $0",
364                            referenceKeys[i].getName().getString());
365            
366                        throw CIMException(CIM_ERR_FAILED, message);
367 chip  1.1          }
368 chip  1.26 
369                    normalizedKeys.append(key);
370 chip  1.1      }
371            
372 chip  1.26     normalizedObjectPath.setKeyBindings(normalizedKeys);
373 chip  1.17 
374                return(normalizedObjectPath);
375            }
376            
377            CIMInstance ObjectNormalizer::processInstance(const CIMInstance & cimInstance) const
378            {
379                // pre-checks
380                if(_cimClass.isUninitialized())
381 chip  1.1      {
382 chip  1.17         // do nothing
383                    return(cimInstance);
384                }
385 chip  1.1  
386 chip  1.29     /*
387                // ATTN: moving similar logic to the response handlers because this type of error should
388                // be checked regardless with or without normalization enabled.
389 chip  1.17     if(cimInstance.isUninitialized())
390                {
391                    throw CIMException(CIM_ERR_FAILED, "unintialized instance object.");
392 chip  1.1      }
393 chip  1.29     */
394 chip  1.1  
395 chip  1.26     CIMInstance normalizedInstance(_cimClass.getClassName());
396 chip  1.22 
397 chip  1.26     // proces object path
398                normalizedInstance.setPath(processInstanceObjectPath(cimInstance.getPath()));
399 chip  1.1  
400 chip  1.17     // process instance qualifiers
401                if(_includeQualifiers)
402 chip  1.1      {
403 chip  1.17         // propagate class qualifiers
404                    for(Uint32 i = 0, n = _cimClass.getQualifierCount(); i < n; i++)
405 chip  1.1          {
406 chip  1.17             CIMConstQualifier referenceQualifier = _cimClass.getQualifier(i);
407 chip  1.1  
408 chip  1.26             Uint32 pos = cimInstance.findQualifier(referenceQualifier.getName());
409 chip  1.1  
410 chip  1.26             // update value if qualifier is present in the specified property
411                        if(pos != PEG_NOT_FOUND)
412 chip  1.1              {
413 chip  1.26                 CIMConstQualifier cimQualifier = cimInstance.getQualifier(pos);
414 chip  1.12 
415 chip  1.26                 CIMQualifier normalizedQualifier =
416                                _processQualifier(
417                                    referenceQualifier,
418                                    cimQualifier);
419 chip  1.12 
420 chip  1.26                 normalizedInstance.addQualifier(normalizedQualifier);
421 chip  1.1              }
422 chip  1.12             else
423                        {
424 chip  1.26                 normalizedInstance.addQualifier(referenceQualifier.clone());
425 chip  1.12             }
426 chip  1.1          }
427                }
428            
429 chip  1.26     // check property names and types. any properties in the class but not in the instance
430                // are implicitly dropped.
431                for(Uint32 i = 0, n = _cimClass.getPropertyCount(); i < n; i++)
432 chip  1.1      {
433 chip  1.26         CIMConstProperty referenceProperty = _cimClass.getProperty(i);
434 chip  1.6  
435 chip  1.26         Uint32 pos = cimInstance.findProperty(referenceProperty.getName());
436 chip  1.1  
437 chip  1.17         if(pos != PEG_NOT_FOUND)
438 chip  1.1          {
439 chip  1.26             CIMConstProperty cimProperty = cimInstance.getProperty(pos);
440 chip  1.1  
441 chip  1.24             CIMProperty normalizedProperty =
442                            _processProperty(
443 chip  1.26                     referenceProperty,
444                                cimProperty,
445 chip  1.24                     _includeQualifiers,
446                                _includeClassOrigin);
447 chip  1.1  
448 chip  1.24             normalizedInstance.addProperty(normalizedProperty);
449 chip  1.9          }
450 chip  1.1      }
451            
452 chip  1.17     return(normalizedInstance);
453 chip  1.1  }
454            
455            PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2