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 #include "CIMProperty.h"
32 #include "XmlWriter.h"
33 #include "Indentor.h"
34 #include "CIMName.h"
35 #include "CIMScope.h"
36
37 PEGASUS_NAMESPACE_BEGIN
38
39 CIMPropertyRep::CIMPropertyRep(
40 const String& name,
41 const CIMValue& value,
42 Uint32 arraySize,
43 mike 1.13 const String& referenceClassName,
44 const String& classOrigin,
45 Boolean propagated) :
46 _name(name), _value(value), _arraySize(arraySize),
47 _referenceClassName(referenceClassName), _classOrigin(classOrigin),
48 _propagated(propagated)
49 {
50 if (!CIMName::legal(name))
51 throw IllegalName();
52
53 if (arraySize && (!value.isArray() || value.getArraySize() != arraySize))
54 throw IncompatibleTypes();
55
56 if (classOrigin.size() && !CIMName::legal(classOrigin))
57 throw IllegalName();
58
59 if (_value.getType() == CIMType::NONE)
60 throw NullType();
61
62 if (referenceClassName.size())
63 {
64 mike 1.13 if (!CIMName::legal(referenceClassName))
65 throw IllegalName();
66
67 if (_value.getType() != CIMType::REFERENCE)
68 {
69 throw ExpectedReferenceValue();
70 }
71 }
72 else
73 {
74 if (_value.getType() == CIMType::REFERENCE)
75 {
76 throw MissingReferenceClassName();
77 }
78 }
79 }
80
81 CIMPropertyRep::~CIMPropertyRep()
82 {
83
84 }
85 mike 1.13
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 _classOrigin = classOrigin;
100 }
101
102 void CIMPropertyRep::resolve(
103 DeclContext* declContext,
104 const String& nameSpace,
105 Boolean isInstancePart,
106 mike 1.13 const CIMConstProperty& inheritedProperty)
107 {
108 assert (inheritedProperty);
109
110 // Check the type:
111
112 if (!inheritedProperty.getValue().typeCompatible(_value))
113 throw TypeMismatch();
114
115 // Validate the qualifiers of the property (according to
116 // superClass's property with the same name). This method
117 // will throw an exception if the validation fails.
118
119 Uint32 scope = CIMScope::PROPERTY;
120
121 if (_value.getType() == CIMType::REFERENCE)
122 scope = CIMScope::REFERENCE;
123
124 _qualifiers.resolve(
125 declContext,
126 nameSpace,
127 mike 1.13 scope,
128 isInstancePart,
129 inheritedProperty._rep->_qualifiers);
130
131 _classOrigin = inheritedProperty.getClassOrigin();
132 }
133
134 void CIMPropertyRep::resolve(
135 DeclContext* declContext,
136 const String& nameSpace,
137 Boolean isInstancePart)
138 {
139 CIMQualifierList dummy;
140
141 Uint32 scope = CIMScope::PROPERTY;
142
143 if (_value.getType() == CIMType::REFERENCE)
144 scope = CIMScope::REFERENCE;
145
146 _qualifiers.resolve(
147 declContext,
148 mike 1.13 nameSpace,
149 scope,
150 isInstancePart,
151 dummy);
152 }
153
154 static const char* _toString(Boolean x)
155 {
156 return x ? "true" : "false";
157 }
158
159 void CIMPropertyRep::toXml(Array<Sint8>& out) const
160 {
161 if (_value.isArray())
162 {
163 out << "<PROPERTY.ARRAY";
164
165 out << " NAME=\"" << _name << "\" ";
166
167 out << " TYPE=\"" << TypeToString(_value.getType()) << "\"";
168
169 mike 1.13 if (_arraySize)
170 {
171 char buffer[32];
172 sprintf(buffer, "%d", _arraySize);
173 out << " ARRAYSIZE=\"" << buffer << "\"";
174 }
175
176 if (_classOrigin.size())
177 out << " CLASSORIGIN=\"" << _classOrigin << "\"";
178
179 if (_propagated != false)
180 out << " PROPAGATED=\"" << _toString(_propagated) << "\"";
181
182 out << ">\n";
183
184 _qualifiers.toXml(out);
185
186 _value.toXml(out);
187
188 out << "</PROPERTY.ARRAY>\n";
189 }
190 mike 1.13 else if (_value.getType() == CIMType::REFERENCE)
191 {
192 out << "<PROPERTY.REFERENCE";
193
194 out << " NAME=\"" << _name << "\" ";
195
196 out << " REFERENCECLASS=\"" << _referenceClassName << "\"";
197
198 if (_classOrigin.size())
199 out << " CLASSORIGIN=\"" << _classOrigin << "\"";
200
201 if (_propagated != false)
202 out << " PROPAGATED=\"" << _toString(_propagated) << "\"";
203
204 out << ">\n";
205
206 _qualifiers.toXml(out);
207
208 _value.toXml(out);
209
210 out << "</PROPERTY.REFERENCE>\n";
211 mike 1.13 }
212 else
213 {
214 out << "<PROPERTY";
215 out << " NAME=\"" << _name << "\" ";
216
217 if (_classOrigin.size())
218 out << " CLASSORIGIN=\"" << _classOrigin << "\"";
219
220 if (_propagated != false)
221 out << " PROPAGATED=\"" << _toString(_propagated) << "\"";
222
223 out << " TYPE=\"" << TypeToString(_value.getType()) << "\"";
224
225 out << ">\n";
226
227 _qualifiers.toXml(out);
228
229 _value.toXml(out);
230
231 out << "</PROPERTY>\n";
232 mike 1.13 }
233 }
234
235 void CIMPropertyRep::print(PEGASUS_STD(ostream) &os) const
236 {
237 Array<Sint8> tmp;
238 toXml(tmp);
239 tmp.append('\0');
240 os << tmp.getData() << PEGASUS_STD(endl);
241 }
242
|