1 karl 1.40 //%2003////////////////////////////////////////////////////////////////////////
|
2 mike 1.13 //
|
3 karl 1.40 // 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 mike 1.13 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
9 kumpf 1.26 // of this software and associated documentation files (the "Software"), to
10 // deal in the Software without restriction, including without limitation the
11 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
12 mike 1.13 // sell copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
|
15 kumpf 1.26 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
16 mike 1.13 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
17 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
18 kumpf 1.26 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
19 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
21 mike 1.13 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 //
24 //==============================================================================
25 //
26 // Author: Mike Brasher (mbrasher@bmc.com)
27 //
|
28 kumpf 1.29 // Modified By: Carol Ann Krug Graves, Hewlett-Packard Company
29 // (carolann_graves@hp.com)
|
30 mike 1.13 //
31 //%/////////////////////////////////////////////////////////////////////////////
32
33 #include <cstdio>
|
34 kumpf 1.19 #include "CIMPropertyRep.h"
|
35 mike 1.13 #include "Indentor.h"
36 #include "CIMName.h"
37 #include "CIMScope.h"
|
38 kumpf 1.25 #include "XmlWriter.h"
39 #include "MofWriter.h"
|
40 mike 1.13
|
41 mike 1.17 PEGASUS_USING_STD;
42
|
43 mike 1.13 PEGASUS_NAMESPACE_BEGIN
44
45 CIMPropertyRep::CIMPropertyRep(
|
46 kumpf 1.30 const CIMName& name,
|
47 mike 1.13 const CIMValue& value,
48 Uint32 arraySize,
|
49 kumpf 1.30 const CIMName& referenceClassName,
50 const CIMName& classOrigin,
|
51 mike 1.17 Boolean propagated)
52 :
|
53 mike 1.13 _name(name), _value(value), _arraySize(arraySize),
54 _referenceClassName(referenceClassName), _classOrigin(classOrigin),
55 _propagated(propagated)
56 {
57 if (arraySize && (!value.isArray() || value.getArraySize() != arraySize))
|
58 kumpf 1.38 throw TypeMismatchException();
|
59 mike 1.13
|
60 kumpf 1.38 // If referenceClassName exists, must be CIMType REFERENCE.
|
61 kumpf 1.30 if (!referenceClassName.isNull())
|
62 mike 1.13 {
|
63 kumpf 1.30 if (_value.getType() != CIMTYPE_REFERENCE)
|
64 kumpf 1.38 throw TypeMismatchException();
|
65 kumpf 1.30 }
|
66 kumpf 1.40.4.1
67 // Can a property be of reference type with a null referenceClassName?
68 // The DMTF says yes if it is a property of an instance; no if it is a
69 // property of a class. We'll allow it here, but check in the CIMClass
70 // addProperty() method.
|
71 mike 1.13 }
72
73 CIMPropertyRep::~CIMPropertyRep()
74 {
75
76 }
77
|
78 kumpf 1.30 void CIMPropertyRep::setName(const CIMName& name)
|
79 mike 1.13 {
80 _name = name;
81 }
82
|
83 kumpf 1.30 void CIMPropertyRep::setClassOrigin(const CIMName& classOrigin)
|
84 mike 1.13 {
85 _classOrigin = classOrigin;
86 }
87
88 void CIMPropertyRep::resolve(
89 DeclContext* declContext,
|
90 kumpf 1.30 const CIMNamespaceName& nameSpace,
|
91 mike 1.13 Boolean isInstancePart,
|
92 mike 1.17 const CIMConstProperty& inheritedProperty,
93 Boolean propagateQualifiers)
|
94 mike 1.13 {
|
95 kumpf 1.32 PEGASUS_ASSERT(!inheritedProperty.isUninitialized());
|
96 mike 1.13
97 // Check the type:
98
99 if (!inheritedProperty.getValue().typeCompatible(_value))
|
100 kumpf 1.36 throw TypeMismatchException();
|
101 mike 1.13
102 // Validate the qualifiers of the property (according to
103 // superClass's property with the same name). This method
104 // will throw an exception if the validation fails.
105
|
106 kumpf 1.35 CIMScope scope = CIMScope::PROPERTY;
|
107 mike 1.13
|
108 kumpf 1.29 if (_value.getType() == CIMTYPE_REFERENCE)
|
109 kumpf 1.35 scope = CIMScope::REFERENCE;
|
110 mike 1.13
|
111 kumpf 1.40.4.1 // Get the reference class name from the inherited property
112 if (_value.getType() == CIMTYPE_REFERENCE)
113 {
114 _referenceClassName = inheritedProperty.getReferenceClassName();
115 }
116
|
117 mike 1.13 _qualifiers.resolve(
118 declContext,
119 nameSpace,
120 scope,
121 isInstancePart,
|
122 mike 1.17 inheritedProperty._rep->_qualifiers,
123 propagateQualifiers);
|
124 mike 1.13
125 _classOrigin = inheritedProperty.getClassOrigin();
126 }
127
128 void CIMPropertyRep::resolve(
129 DeclContext* declContext,
|
130 kumpf 1.30 const CIMNamespaceName& nameSpace,
|
131 mike 1.17 Boolean isInstancePart,
|
132 kumpf 1.28 Boolean propagateQualifiers)
|
133 mike 1.13 {
134 CIMQualifierList dummy;
135
|
136 kumpf 1.35 CIMScope scope = CIMScope::PROPERTY;
|
137 mike 1.13
|
138 kumpf 1.29 if (_value.getType() == CIMTYPE_REFERENCE)
|
139 kumpf 1.35 scope = CIMScope::REFERENCE;
|
140 mike 1.13
141 _qualifiers.resolve(
142 declContext,
143 nameSpace,
144 scope,
145 isInstancePart,
|
146 mike 1.17 dummy,
|
147 kumpf 1.28 propagateQualifiers);
|
148 mike 1.13 }
149
150 static const char* _toString(Boolean x)
151 {
152 return x ? "true" : "false";
153 }
154
155 void CIMPropertyRep::toXml(Array<Sint8>& out) const
156 {
157 if (_value.isArray())
158 {
159 out << "<PROPERTY.ARRAY";
160
161 out << " NAME=\"" << _name << "\" ";
162
|
163 kumpf 1.29 out << " TYPE=\"" << cimTypeToString (_value.getType ()) << "\"";
|
164 mike 1.13
165 if (_arraySize)
166 {
167 char buffer[32];
168 sprintf(buffer, "%d", _arraySize);
169 out << " ARRAYSIZE=\"" << buffer << "\"";
170 }
171
|
172 kumpf 1.30 if (!_classOrigin.isNull())
|
173 mike 1.13 out << " CLASSORIGIN=\"" << _classOrigin << "\"";
174
175 if (_propagated != false)
176 out << " PROPAGATED=\"" << _toString(_propagated) << "\"";
177
178 out << ">\n";
179
180 _qualifiers.toXml(out);
181
|
182 kumpf 1.23 XmlWriter::appendValueElement(out, _value);
|
183 mike 1.13
184 out << "</PROPERTY.ARRAY>\n";
185 }
|
186 kumpf 1.29 else if (_value.getType() == CIMTYPE_REFERENCE)
|
187 mike 1.13 {
188 out << "<PROPERTY.REFERENCE";
189
190 out << " NAME=\"" << _name << "\" ";
191
|
192 kumpf 1.40.4.1 if (!_referenceClassName.isNull())
193 {
194 out << " REFERENCECLASS=\"" << _referenceClassName << "\"";
195 }
|
196 mike 1.13
|
197 kumpf 1.30 if (!_classOrigin.isNull())
|
198 mike 1.13 out << " CLASSORIGIN=\"" << _classOrigin << "\"";
199
200 if (_propagated != false)
201 out << " PROPAGATED=\"" << _toString(_propagated) << "\"";
202
203 out << ">\n";
204
205 _qualifiers.toXml(out);
|
206 karl 1.15
|
207 kumpf 1.23 XmlWriter::appendValueElement(out, _value);
|
208 mike 1.13
209 out << "</PROPERTY.REFERENCE>\n";
210 }
211 else
212 {
213 out << "<PROPERTY";
214 out << " NAME=\"" << _name << "\" ";
215
|
216 kumpf 1.30 if (!_classOrigin.isNull())
|
217 mike 1.13 out << " CLASSORIGIN=\"" << _classOrigin << "\"";
218
219 if (_propagated != false)
220 out << " PROPAGATED=\"" << _toString(_propagated) << "\"";
221
|
222 kumpf 1.29 out << " TYPE=\"" << cimTypeToString (_value.getType ()) << "\"";
|
223 mike 1.13
224 out << ">\n";
225
226 _qualifiers.toXml(out);
|
227 karl 1.15
|
228 kumpf 1.23 XmlWriter::appendValueElement(out, _value);
|
229 mike 1.13
230 out << "</PROPERTY>\n";
231 }
232 }
233
|
234 mike 1.14 /** toMof - returns the MOF for the CIM Property Object in the parameter.
235 The BNF for the property MOF is:
236 <pre>
237 propertyDeclaration = [ qualifierList ] dataType propertyName
238 [ array ] [ defaultValue ] ";"
239
240 array = "[" [positiveDecimalValue] "]"
241
242 defaultValue = "=" initializer
243 </pre>
244 Format with qualifiers on one line and declaration on another. Start
245 with newline but none at the end.
246 */
247 void CIMPropertyRep::toMof(Array<Sint8>& out) const //ATTNKS:
248 {
249 //Output the qualifier list
250 if (_qualifiers.getCount())
251 out << "\n";
252 _qualifiers.toMof(out);
253
254 // Output the Type and name on a new line
|
255 kumpf 1.29 out << "\n" << cimTypeToString (_value.getType ()) << " " << _name;
|
256 mike 1.14
257 // If array put the Array indicator "[]" and possible size after name.
258 if (_value.isArray())
259 {
260 if (_arraySize)
261 {
262 char buffer[32];
263 sprintf(buffer, "[%d]", _arraySize);
264 out << buffer;
265 }
266 else
267 out << "[]";
268 }
269
270 // If the property value is not Null, add value after "="
271 if (!_value.isNull())
272 {
273 out << " = ";
274 if (_value.isArray())
275 {
276 // Insert any property values
|
277 kumpf 1.25 MofWriter::appendValueElement(out, _value);
|
278 mike 1.14 }
|
279 kumpf 1.29 else if (_value.getType() == CIMTYPE_REFERENCE)
|
280 mike 1.14 {
|
281 kumpf 1.25 MofWriter::appendValueElement(out, _value);
|
282 mike 1.14 }
283 else
284 {
|
285 kumpf 1.25 MofWriter::appendValueElement(out, _value);
|
286 mike 1.14 }
287 }
288 // Close the property MOF
289 out << ";";
290
291 }
292
|
293 mike 1.13 Boolean CIMPropertyRep::identical(const CIMPropertyRep* x) const
294 {
|
295 kumpf 1.39 if (!_name.equal (x->_name))
|
296 mike 1.13 return false;
297
298 if (_value != x->_value)
299 return false;
300
|
301 kumpf 1.39 if (!_referenceClassName.equal (x->_referenceClassName))
|
302 mike 1.13 return false;
303
304 if (!_qualifiers.identical(x->_qualifiers))
305 return false;
306
|
307 kumpf 1.39 if (!_classOrigin.equal (x->_classOrigin))
|
308 mike 1.13 return false;
309
310 if (_propagated != x->_propagated)
311 return false;
312
313 return true;
314 }
315
316 CIMPropertyRep::CIMPropertyRep()
317 {
318
319 }
320
|
321 mike 1.17 CIMPropertyRep::CIMPropertyRep(
322 const CIMPropertyRep& x,
323 Boolean propagateQualifiers)
324 :
|
325 mike 1.13 Sharable(),
326 _name(x._name),
327 _value(x._value),
328 _arraySize(x._arraySize),
329 _referenceClassName(x._referenceClassName),
330 _classOrigin(x._classOrigin),
331 _propagated(x._propagated)
332 {
|
333 mike 1.17 if (propagateQualifiers)
334 x._qualifiers.cloneTo(_qualifiers);
|
335 mike 1.13 }
336
337 void CIMPropertyRep::setValue(const CIMValue& value)
338 {
339 // CIMType of value is immutable:
340
341 if (!value.typeCompatible(_value))
|
342 kumpf 1.38 throw TypeMismatchException();
|
343 mike 1.13
344 if (_arraySize && _arraySize != value.getArraySize())
|
345 kumpf 1.38 throw TypeMismatchException();
|
346 mike 1.13
347 _value = value;
348 }
349
350 PEGASUS_NAMESPACE_END
|