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

  1 mike  1.1.2.1 //%2006////////////////////////////////////////////////////////////////////////
  2               //
  3               // 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               // IBM Corp.; EMC Corporation, The Open Group.
  7               // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  8               // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
  9               // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10               // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11               // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 12               // EMC Corporation; Symantec Corporation; The Open Group.
 13               //
 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               //
 21               // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 22 mike  1.1.2.1 // 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               //%/////////////////////////////////////////////////////////////////////////////
 33               
 34               #include <Pegasus/Common/Tracer.h>
 35               #include "Filtering.h"
 36               
 37               PEGASUS_NAMESPACE_BEGIN
 38               
 39               /** Check to see if the specified property is in the property list
 40                   @param property the specified property
 41                   @param propertyList the property list
 42                   @return true if the property is in the list otherwise false.
 43 mike  1.1.2.1 */
 44               static Boolean _containsProperty(
 45                   CIMProperty& property,
 46                   const CIMPropertyList& propertyList)
 47               {
 48                   //  For each property in the propertly list
 49                   for (Uint32 p=0; p<propertyList.size(); p++)
 50                   {
 51                       if (propertyList[p].equal(property.getName()))
 52                           return true;
 53                   }
 54                   return false;
 55               }
 56               
 57               /* removes all Qualifiers from a CIMClass.  This function removes all
 58                  of the qualifiers from the class, from all of the properties,
 59                  from the methods, and from the parameters attached to the methods.
 60                  @param cimClass reference to the class from which qualifiers are to
 61                  be removed.
 62                  NOTE: This would be logical to be moved to CIMClass since it may be
 63                  more general than this usage.
 64 mike  1.1.2.1 */
 65               static void _removeAllQualifiers(CIMClass& cimClass)
 66               {
 67                   // remove qualifiers of the class
 68                   Uint32 count = 0;
 69                   while ((count = cimClass.getQualifierCount()) > 0)
 70                       cimClass.removeQualifier(count - 1);
 71               
 72                   // remove qualifiers from the properties
 73                   for (Uint32 i = 0; i < cimClass.getPropertyCount(); i++)
 74                   {
 75                       CIMProperty p = cimClass.getProperty(i);
 76                       count = 0;
 77                       while ((count = p.getQualifierCount()) > 0)
 78                           p.removeQualifier(count - 1);
 79                   }
 80               
 81                   // remove qualifiers from the methods
 82                   for (Uint32 i = 0; i < cimClass.getMethodCount(); i++)
 83                   {
 84                       CIMMethod m = cimClass.getMethod(i);
 85 mike  1.1.2.1         for (Uint32 j = 0 ; j < m.getParameterCount(); j++)
 86                       {
 87                           CIMParameter p = m.getParameter(j);
 88                           count = 0;
 89                           while ((count = p.getQualifierCount()) > 0)
 90                               p.removeQualifier(count - 1);
 91                       }
 92                       count = 0;
 93                       while ((count = m.getQualifierCount()) > 0)
 94                           m.removeQualifier(count - 1);
 95                   }
 96               }
 97               
 98               /////////////////////////////////////////////////////////////////////////
 99               //
100               // _removePropagatedQualifiers - Removes all qualifiers from the class
101               // that are marked propagated
102               //
103               /////////////////////////////////////////////////////////////////////////
104               
105               /* removes propagatedQualifiers from the defined CIMClass.
106 mike  1.1.2.1    This function removes the qualifiers from the class,
107                  from each of the properties, from the methods and
108                  the parameters if the qualifiers are marked propagated.
109                  NOTE: This could be logical to be moved to CIMClass since it may be
110                  more general than the usage here.
111               */
112               static void _removePropagatedQualifiers(CIMClass& cimClass)
113               {
114                   Uint32 count = cimClass.getQualifierCount();
115                   // Remove nonlocal qualifiers from Class
116                   for (Sint32 i = (count - 1); i >= 0; i--)
117                   {
118                       CIMQualifier q = cimClass.getQualifier(i);
119                       if (q.getPropagated())
120                       {
121                           cimClass.removeQualifier(i);
122                       }
123                   }
124               
125                   // remove  non localOnly qualifiers from the properties
126                   for (Uint32 i = 0; i < cimClass.getPropertyCount(); i++)
127 mike  1.1.2.1     {
128                       CIMProperty p = cimClass.getProperty(i);
129                       // loop to search qualifiers for nonlocal parameters
130                       count = p.getQualifierCount();
131                       for (Sint32 j = (count - 1); j >= 0; j--)
132                       {
133                           CIMQualifier q = p.getQualifier(j);
134                           if (q.getPropagated())
135                           {
136                               p.removeQualifier(j);
137                           }
138                       }
139                   }
140               
141                   // remove non LocalOnly qualifiers from the methods and parameters
142                   for (Uint32 i = 0; i < cimClass.getMethodCount(); i++)
143                   {
144                       CIMMethod m = cimClass.getMethod(i);
145                       // Remove  nonlocal qualifiers from all parameters
146                       for (Uint32 j = 0 ; j < m.getParameterCount(); j++)
147                       {
148 mike  1.1.2.1             CIMParameter p = m.getParameter(j);
149                           count = p.getQualifierCount();
150                           for (Sint32 k = (count - 1); k >= 0; k--)
151                           {
152                               CIMQualifier q = p.getQualifier(k);
153                               if (q.getPropagated())
154                               {
155                                   p.removeQualifier(k);
156                               }
157                           }
158                       }
159               
160                       // remove nonlocal qualifiers from the method
161                       count = m.getQualifierCount();
162                       for (Sint32 j = (count - 1); j >= 0; j--)
163                       {
164                           CIMQualifier q = m.getQualifier(j);
165                           if (q.getPropagated())
166                           {
167                               m.removeQualifier(j);
168                           }
169 mike  1.1.2.1         }
170                   }
171               }
172               
173               /* remove the properties from an instance based on attributes.
174                   @param Instance from which properties will be removed.
175                   @param propertyList PropertyList is used in the removal algorithm
176                   @param localOnly - Boolean used in the removal.
177                   NOTE: This could be logical to move to CIMInstance since the
178                   usage is more general than just in the repository
179               */
180               static void _removeProperties(
181                   CIMInstance& cimInstance,
182                   const CIMPropertyList& propertyList,
183                   Boolean localOnly)
184               {
185                   Boolean propertyListNull = propertyList.isNull();
186                   if ((!propertyListNull) || localOnly)
187                   {
188                       // Loop through properties to remove those that do not filter through
189                       // local only attribute and are not in the property list.
190 mike  1.1.2.1         Uint32 count = cimInstance.getPropertyCount();
191                       // Work backwards because removal may be cheaper. Sint32 covers count=0
192                       for (Sint32 i = (count - 1); i >= 0; i--)
193                       {
194                           CIMProperty p = cimInstance.getProperty(i);
195               
196                           // if localOnly == true, ignore properties defined in super class
197                           if (localOnly && (p.getPropagated()))
198                           {
199                               cimInstance.removeProperty(i);
200                               continue;
201                           }
202               
203                           // propertyList NULL means deliver properties.  PropertyList
204                           // empty, none.
205                           // Test for removal if propertyList not NULL. The empty list option
206                           // is covered by fact that property is not in the list.
207                           if (!propertyListNull)
208                               if (!_containsProperty(p, propertyList))
209                                   cimInstance.removeProperty(i);
210                       }
211 mike  1.1.2.1     }
212               }
213               
214               /* remove all Qualifiers from a single CIMInstance. Removes
215                   all of the qualifiers from the instance and from properties
216                   within the instance.
217                   @param instance from which parameters are removed.
218                   NOTE: This could be logical to be moved to CIMInstance since
219                   the usage may be more general than just in the repository.
220               */
221               static void _removeAllQualifiers(CIMInstance& cimInstance)
222               {
223                   // remove qualifiers from the instance
224                   Uint32 count = 0;
225                   while ((count = cimInstance.getQualifierCount()) > 0)
226                       cimInstance.removeQualifier(count - 1);
227               
228                   // remove qualifiers from the properties
229                   for (Uint32 i = 0; i < cimInstance.getPropertyCount(); i++)
230                   {
231                       CIMProperty p = cimInstance.getProperty(i);
232 mike  1.1.2.1         count = 0;
233                       while ((count = p.getQualifierCount()) > 0)
234                           p.removeQualifier(count - 1);
235                   }
236               }
237               
238               /* removes all ClassOrigin attributes from a single CIMInstance. Removes
239                   the classOrigin attribute from each property in the Instance.
240                  @param Instance from which the ClassOrigin Properties will be removed.
241                  NOTE: Logical to be moved to CIMInstance since it may be more general
242                  than just the repositoryl
243               */
244               void _removeClassOrigins(CIMInstance& cimInstance)
245               {
246                   PEG_TRACE_CSTRING(TRC_REPOSITORY, Tracer::LEVEL4, "Remove Class Origins");
247               
248                   Uint32 propertyCount = cimInstance.getPropertyCount();
249                   for (Uint32 i = 0; i < propertyCount ; i++)
250                       cimInstance.getProperty(i).setClassOrigin(CIMName());
251               }
252               
253 mike  1.1.2.1 /* Filters the properties, qualifiers, and classorigin out of a single instance.
254                   Based on the parameters provided for localOnly, includeQualifiers,
255                   and includeClassOrigin, this function simply filters the properties
256                   qualifiers, and classOrigins out of a single instance.  This function
257                   was created to have a single piece of code that processes getinstance
258                   and enumerateInstances returns.
259                   @param cimInstance reference to instance to be processed.
260                   @param localOnly defines if request is for localOnly parameters.
261                   @param includeQualifiers Boolean defining if qualifiers to be returned.
262                   @param includeClassOrigin Boolean defining if ClassOrigin attribute to
263                   be removed from properties.
264               */
265               void Filtering::filterInstance(
266                   CIMInstance& cimInstance,
267                   Boolean localOnly,
268                   Boolean includeQualifiers,
269                   Boolean includeClassOrigin,
270                   const CIMPropertyList& propertyList)
271               {
272                   // Remove properties based on propertyList and localOnly flag
273                   _removeProperties(cimInstance, propertyList, localOnly);
274 mike  1.1.2.1 
275                   // If includequalifiers false, remove all qualifiers from
276                   // properties.
277               
278                   if (!includeQualifiers)
279                   {
280                       _removeAllQualifiers(cimInstance);
281                   }
282               
283                   // if ClassOrigin Flag false, remove classOrigin info from Instance object
284                   // by setting the classOrigin to Null.
285               
286                   if (!includeClassOrigin)
287                   {
288                       _removeClassOrigins(cimInstance);
289                   }
290               }
291               
292               void Filtering::filterClass(
293                   CIMClass& cimClass,
294                   Boolean localOnly,
295 mike  1.1.2.1     Boolean includeQualifiers,
296                   Boolean includeClassOrigin,
297                   const CIMPropertyList& propertyList)
298               {
299                   // Remove properties based on propertylist and localOnly flag (Bug 565)
300                   Boolean propertyListNull = propertyList.isNull();
301               
302                   // if localOnly OR there is a property list, process properties
303                   if ((!propertyListNull) || localOnly)
304                   {
305                       // Loop through properties to remove those that do not filter through
306                       // local only attribute and are not in the property list.
307                       Uint32 count = cimClass.getPropertyCount();
308                       // Work backwards because removal may be cheaper. Sint32 covers count=0
309                       for (Sint32 i = (count - 1); i >= 0; i--)
310                       {
311                           CIMProperty p = cimClass.getProperty(i);
312                           // if localOnly==true, ignore properties defined in super class
313                           if (localOnly && (p.getPropagated()))
314                           {
315                               cimClass.removeProperty(i);
316 mike  1.1.2.1                 continue;
317                           }
318               
319                           // propertyList NULL means all properties.  PropertyList
320                           // empty, none.
321                           // Test for removal if propertyList not NULL. The empty list option
322                           // is covered by fact that property is not in the list.
323                           if (!propertyListNull)
324                               if (!_containsProperty(p, propertyList))
325                                   cimClass.removeProperty(i);
326                       }
327                   }
328               
329                   // remove methods based on localOnly flag
330                   if (localOnly)
331                   {
332                       Uint32 count = cimClass.getMethodCount();
333                       // Work backwards because removal may be cheaper.
334                       for (Sint32 i = (count - 1); i >= 0; i--)
335                       {
336                           CIMMethod m = cimClass.getMethod(i);
337 mike  1.1.2.1 
338                           // if localOnly==true, ignore properties defined in super class
339                           if (localOnly && (m.getPropagated()))
340                               cimClass.removeMethod(i);
341                       }
342               
343                   }
344                   // If includequalifiers false, remove all qualifiers from
345                   // properties, methods and parameters.
346                   if (!includeQualifiers)
347                   {
348                       _removeAllQualifiers(cimClass);
349                   }
350                   else
351                   {
352                       // if includequalifiers and localOnly, remove nonLocal qualifiers
353                       if (localOnly)
354                       {
355                           _removePropagatedQualifiers(cimClass);
356                       }
357               
358 mike  1.1.2.1     }
359               
360               
361                   // if ClassOrigin Flag false, remove classOrigin info from class object
362                   // by setting the property to Null.
363                   if (!includeClassOrigin)
364                   {
365                       PEG_TRACE_CSTRING(TRC_REPOSITORY, Tracer::LEVEL4,
366                           "Remove Class Origins");
367               
368                       Uint32 propertyCount = cimClass.getPropertyCount();
369                       for (Uint32 i = 0; i < propertyCount ; i++)
370                           cimClass.getProperty(i).setClassOrigin(CIMName());
371               
372                       Uint32 methodCount =  cimClass.getMethodCount();
373                       for (Uint32 i=0; i < methodCount ; i++)
374                           cimClass.getMethod(i).setClassOrigin(CIMName());
375                   }
376               }
377               
378               PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2