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