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