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

  1 karl  1.70 //%2006////////////////////////////////////////////////////////////////////////
  2 mike  1.22 //
  3 karl  1.60 // 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.57 // IBM Corp.; EMC Corporation, The Open Group.
  7 karl  1.60 // 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.62 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10            // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11 karl  1.70 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 12            // EMC Corporation; Symantec Corporation; The Open Group.
 13 mike  1.22 //
 14            // Permission is hereby granted, free of charge, to any person obtaining a copy
 15 chip  1.25 // 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.22 // 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 kumpf 1.41 // 
 21 chip  1.25 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 22 mike  1.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 chip  1.25 // 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.22 // 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 kumpf 1.32 #include "CIMInstanceRep.h"
 35 mike  1.22 #include "CIMInstance.h"
 36 kumpf 1.32 #include "CIMClassRep.h"
 37 kumpf 1.34 #include "CIMScope.h"
 38 mike  1.22 #include "DeclContext.h"
 39 kumpf 1.42 #include "Resolver.h"
 40 mike  1.22 #include "Indentor.h"
 41            #include "CIMName.h"
 42 kumpf 1.38 #include "Constants.h"
 43 mike  1.22 #include "XmlWriter.h"
 44 kumpf 1.38 #include "MofWriter.h"
 45 mike  1.69 #include "StrLit.h"
 46 mike  1.22 
 47 mike  1.29 PEGASUS_USING_STD;
 48            
 49 mike  1.22 PEGASUS_NAMESPACE_BEGIN
 50            
 51 kumpf 1.39 CIMInstanceRep::CIMInstanceRep(const CIMObjectPath& reference)
 52 mike  1.29     : CIMObjectRep(reference)
 53 mike  1.22 {
 54 mike  1.24 
 55 mike  1.22 }
 56            
 57            CIMInstanceRep::~CIMInstanceRep()
 58            {
 59            
 60            }
 61            
 62            void CIMInstanceRep::resolve(
 63                DeclContext* context,
 64 kumpf 1.44     const CIMNamespaceName& nameSpace,
 65 mike  1.29     CIMConstClass& cimClassOut,
 66                Boolean propagateQualifiers)
 67 mike  1.22 {
 68                // ATTN: Verify that references are initialized.
 69            
 70            #if 0
 71                if (_resolved)
 72 kumpf 1.72         throw InstanceAlreadyResolved();
 73 mike  1.22 #endif
 74            
 75                if (!context)
 76 kumpf 1.72         throw NullPointer();
 77 mike  1.22 
 78                //----------------------------------------------------------------------
 79                // First obtain the class:
 80                //----------------------------------------------------------------------
 81            
 82                CIMConstClass cimClass =
 83 kumpf 1.72         context->lookupClass(nameSpace, _reference.getClassName());
 84 mike  1.22 
 85 kumpf 1.45     if (cimClass.isUninitialized())
 86 kumpf 1.72         throw PEGASUS_CIM_EXCEPTION(CIM_ERR_INVALID_CLASS,
 87 kumpf 1.50             _reference.getClassName().getString ());
 88 mike  1.22 
 89                cimClassOut = cimClass;
 90            
 91            #if 0
 92                if (!cimClass._rep->_resolved)
 93 kumpf 1.72         throw ClassNotResolved(_reference.getClassName());
 94 mike  1.22 #endif
 95            
 96                //----------------------------------------------------------------------
 97                // Disallow instantiation of abstract classes.
 98                //----------------------------------------------------------------------
 99            
100                if (cimClass.isAbstract())
101 kumpf 1.72         throw InstantiatedAbstractClass(_reference.getClassName().getString ());
102 mike  1.22 
103                //----------------------------------------------------------------------
104 mike  1.29     // Validate and propagate qualifiers.
105 mike  1.22     //----------------------------------------------------------------------
106                _qualifiers.resolve(
107 kumpf 1.72         context,
108                    nameSpace,
109 kumpf 1.53         (cimClass.isAssociation()) ? CIMScope::ASSOCIATION : CIMScope::CLASS,
110 kumpf 1.72         false,
111                    cimClass._rep->_qualifiers,
112                    propagateQualifiers);
113 mike  1.22 
114                //----------------------------------------------------------------------
115                // First iterate the properties of this instance and verify that
116                // each one is defined in the class and then resolve each one.
117                //----------------------------------------------------------------------
118            
119 kumpf 1.44     CIMName className = cimClass.getClassName();
120 mike  1.22 
121                for (Uint32 i = 0, n = _properties.size(); i < n; i++)
122                {
123 kumpf 1.72         CIMProperty& property = _properties[i];
124 mike  1.22 
125 kumpf 1.72         Uint32 index = cimClass.findProperty(property.getName());
126 mike  1.22 
127 kumpf 1.72         if (index == PEG_NOT_FOUND)
128 kumpf 1.31         {
129                        //
130                        //  Allow addition of Creator property to Indication Subscription,
131                        //  Filter and Handler instances
132                        //
133 kumpf 1.72 // l10n add language property support
134                        if (!(((className.equal
135 kumpf 1.50                     (CIMName (PEGASUS_CLASSNAME_INDSUBSCRIPTION))) ||
136 kumpf 1.72                 (className.equal
137 yi.zhou 1.63                     (CIMName (PEGASUS_CLASSNAME_FORMATTEDINDSUBSCRIPTION))) ||
138 kumpf   1.72                 (className.equal
139 kumpf   1.50                     (CIMName (PEGASUS_CLASSNAME_INDHANDLER_CIMXML))) ||
140 kumpf   1.72                 (className.equal
141 tony    1.56                     (CIMName (PEGASUS_CLASSNAME_LSTNRDST_CIMXML))) ||
142 kumpf   1.72                 (className.equal
143 kumpf   1.50                     (CIMName (PEGASUS_CLASSNAME_INDHANDLER_SNMP))) ||
144 yi.zhou 1.63 #ifdef  PEGASUS_ENABLE_SYSTEM_LOG_HANDLER
145 kumpf   1.72                 (className.equal
146 yi.zhou 1.63                     (CIMName (PEGASUS_CLASSNAME_LSTNRDST_SYSTEM_LOG))) ||
147              #endif
148 yi.zhou 1.64 #ifdef  PEGASUS_ENABLE_EMAIL_HANDLER
149 kumpf   1.72                 (className.equal
150 yi.zhou 1.64                     (CIMName (PEGASUS_CLASSNAME_LSTNRDST_EMAIL))) ||
151              #endif
152 kumpf   1.50                 (className.equal (CIMName (PEGASUS_CLASSNAME_INDFILTER)))) &&
153 kumpf   1.72                 ((property.getName ().equal
154 chuck   1.54                     (CIMName (PEGASUS_PROPERTYNAME_INDSUB_CREATOR))) ||
155 kumpf   1.72                 (property.getName ().equal
156 chuck   1.54                     (CIMName (PEGASUS_PROPERTYNAME_INDSUB_ACCEPTLANGS))) ||
157 kumpf   1.72                 (property.getName ().equal
158 chuck   1.54                     (CIMName (PEGASUS_PROPERTYNAME_INDSUB_CONTENTLANGS))))))
159 kumpf   1.31             {
160 kumpf   1.72                 throw NoSuchProperty(property.getName().getString ());
161 kumpf   1.31             }
162                      }
163                      else
164                      {
165 kumpf   1.72             // resolve the property
166                          Resolver::resolveProperty (property, context, nameSpace, true,
167 kumpf   1.48                 cimClass.getProperty (index), propagateQualifiers);
168 kumpf   1.31         }
169 mike    1.22     }
170              
171                  //----------------------------------------------------------------------
172                  // Inject all properties from the class that are not included in the
173                  // instance. Copy over the class-origin and set the propagated flag
174 karl    1.58     // to true. NOTE: The propagated flag indicates that the property
175                  // was not part of the property set input with the create and
176 kumpf   1.72     // was inherited from the default in the class (see cimxml spec sect 3.1.5)
177 mike    1.22     //----------------------------------------------------------------------
178              
179                  for (Uint32 i = 0, m = 0, n = cimClass.getPropertyCount(); i < n; i++)
180                  {
181 kumpf   1.72         CIMConstProperty property = cimClass.getProperty(i);
182                      const CIMName& name = property.getName();
183              
184                      // See if this instance already contains a property with this name:
185              
186                      Boolean found = false;
187              
188                      for (Uint32 j = m, n = _properties.size(); j < n; j++)
189                      {
190                          if (name.equal(_properties[j].getName()))
191                          {
192                              found = true;
193                              break;
194                          }
195                      }
196              
197                      if (!found)
198                      {
199                          CIMProperty p = property.clone();
200                          p.setPropagated(true);
201                          _properties.insert(m++, p);
202 kumpf   1.72         }
203 mike    1.22     }
204              
205              #if 0
206                  _resolved = true;
207              #endif
208              }
209              
210              CIMInstanceRep::CIMInstanceRep()
211              {
212              
213              }
214              
215 mike    1.24 CIMInstanceRep::CIMInstanceRep(const CIMInstanceRep& x) : CIMObjectRep(x)
216 mike    1.22 {
217              
218              }
219              
220 mike    1.68 void CIMInstanceRep::toXml(Buffer& out) const
221 mike    1.22 {
222                  // Class opening element:
223              
224 mike    1.69     out << STRLIT("<INSTANCE ");
225                  out << STRLIT(" CLASSNAME=\"") << _reference.getClassName();
226                  out << STRLIT("\" ");
227                  out << STRLIT(">\n");
228 mike    1.22 
229                  // Qualifiers:
230              
231                  _qualifiers.toXml(out);
232              
233                  // Parameters:
234              
235                  for (Uint32 i = 0, n = _properties.size(); i < n; i++)
236 kumpf   1.72         XmlWriter::appendPropertyElement(out, _properties[i]);
237 mike    1.22 
238                  // Class closing element:
239              
240 mike    1.69     out << STRLIT("</INSTANCE>\n");
241 mike    1.22 }
242              
243 mike    1.68 void CIMInstanceRep::toMof(Buffer& out) const
244 karl    1.27 {
245                  // Get and format the class qualifiers
246 karl    1.71     out << STRLIT("\n//Instance of ") << _reference.getClassName();
247 karl    1.27     if (_qualifiers.getCount())
248 kumpf   1.72         out.append('\n');
249 karl    1.27     _qualifiers.toMof(out);
250              
251                  // Separate qualifiers from Class Name
252 mike    1.69     out.append('\n');
253 karl    1.27 
254                  // output class statement
255 karl    1.71     out << STRLIT("instance of ") << _reference.getClassName();
256 karl    1.27 
257 mike    1.69     out << STRLIT("\n{");
258 karl    1.27 
259                  // format the Properties:
260                  for (Uint32 i = 0, n = _properties.size(); i < n; i++)
261                  {
262 kumpf   1.72         // Generate MOF if this property not propagated
263                      // Note that the test is required only because
264                      // there is an error in getclass that does not
265                      // test the localOnly flag.
266 karl    1.71         // The false identifies this as value initializer, not
267                      // property definition.
268 kumpf   1.72         if (!_properties[i].getPropagated())
269                          MofWriter::appendPropertyElement(false,out, _properties[i]);
270 karl    1.27     }
271              
272                  // Class closing element:
273 mike    1.69     out << STRLIT("\n};\n");
274 karl    1.27 }
275 kumpf   1.52 
276 kumpf   1.46 CIMObjectPath CIMInstanceRep::buildPath(
277 mike    1.22     const CIMConstClass& cimClass) const
278              {
279                  //--------------------------------------------------------------------------
280                  // Get class name:
281                  //--------------------------------------------------------------------------
282              
283 kumpf   1.44     CIMName className = getClassName();
284 mike    1.22 
285                  //--------------------------------------------------------------------------
286                  // Get key names:
287                  //--------------------------------------------------------------------------
288              
289 kumpf   1.44     Array<CIMName> keyNames;
290 mike    1.22     cimClass.getKeyNames(keyNames);
291              
292                  if (keyNames.size() == 0)
293 kumpf   1.72         return CIMObjectPath("", CIMNamespaceName(), className);
294 mike    1.22 
295                  //--------------------------------------------------------------------------
296                  // Get type and value for each key (building up key bindings):
297                  //--------------------------------------------------------------------------
298              
299 kumpf   1.49     Array<CIMKeyBinding> keyBindings;
300 mike    1.22 
301                  for (Uint32 i = 0, n = keyNames.size(); i < n; i++)
302                  {
303 kumpf   1.72         const CIMName& keyName = keyNames[i];
304 mike    1.22 
305 kumpf   1.72         Uint32 index = findProperty(keyName);
306 kumpf   1.66         if (index == PEG_NOT_FOUND)
307                      {
308                          throw NoSuchProperty(keyName.getString());
309                      }
310 mike    1.22 
311 kumpf   1.72         CIMConstProperty tmp = getProperty(index);
312 mike    1.22 
313 kumpf   1.72         if (keyName.equal(tmp.getName()))
314                      {
315                          keyBindings.append(CIMKeyBinding(keyName, tmp.getValue()));
316                      }
317 mike    1.22     }
318              
319 kumpf   1.55     return CIMObjectPath(String(), CIMNamespaceName(), className, keyBindings);
320 mike    1.22 }
321              
322 karl    1.65 // KS Mar 05 - The following removal functions are very inefficient and should
323              // be optimized to avoid the multiple memory moves.  Actually, the remove
324              // qualifiers should be added as a function and optimized that once.
325 kumpf   1.72 void CIMInstanceRep::filter(
326                  Boolean includeQualifiers,
327                  Boolean includeClassOrigin,
328                  const CIMPropertyList& propertyList)
329 karl    1.59 {
330                  // Filter any qualifiers from this instance.
331                  if (!includeQualifiers && _qualifiers.getCount() > 0)
332                  {
333 kumpf   1.73         while (_qualifiers.getCount())
334 karl    1.59         {
335                          _qualifiers.removeQualifier(0);
336                      }
337                  }
338              
339                  // For each property, remove if not in propertylist
340                  for (Uint32 i = 0 ; i < _properties.size(); i++)
341                  {
342                      CIMConstProperty p = getProperty(i);
343                      CIMName name = p.getName();
344                      Array<CIMName> pl = propertyList.getPropertyNameArray();
345                      if (propertyList.isNull() || Contains(pl, name))
346                      {
347                          // test ClassOrigin and possibly remove
348                          if (!includeClassOrigin)
349                          {
350                              _properties[i].setClassOrigin(CIMName());
351                          }
352 karl    1.65             // remove qualifiers if required.
353                          if (!includeQualifiers && _properties[i].getQualifierCount() > 0)
354                          {
355 kumpf   1.73                 while (_properties[i].getQualifierCount() > 0)
356 karl    1.65                 {
357                                  _properties[i].removeQualifier(0);
358                              }
359                          }
360 karl    1.59         }
361                      else
362                      {
363                          _properties.remove(i--);
364                      }
365                  }
366                  return;
367              }
368              
369 mike    1.22 PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2