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