1 mike 1.1 //BEGIN_LICENSE
2 //
3 // Copyright (c) 2000 The Open Group, BMC Software, Tivoli Systems, IBM
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a
6 // copy of this software and associated documentation files (the "Software"),
7 // to deal in the Software without restriction, including without limitation
8 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 // and/or sell copies of the Software, and to permit persons to whom the
10 // Software is furnished to do so, subject to the following conditions:
11 //
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
15 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18 // DEALINGS IN THE SOFTWARE.
19 //
20 //END_LICENSE
21 //BEGIN_HISTORY
22 mike 1.1 //
23 // Author:
24 //
|
25 mike 1.2 // $Log: PropertyRep.cpp,v $
|
26 mike 1.4 // Revision 1.3 2001/01/23 01:25:35 mike
27 // Reworked resolve scheme.
28 //
|
29 mike 1.3 // Revision 1.2 2001/01/22 00:45:47 mike
30 // more work on resolve scheme
31 //
|
32 mike 1.2 // Revision 1.1.1.1 2001/01/14 19:53:05 mike
33 // Pegasus import
34 //
|
35 mike 1.1 //
36 //END_HISTORY
37
38 #include <cassert>
39 #include <cstdio>
40 #include "Property.h"
41 #include "XmlWriter.h"
42 #include "Indentor.h"
43 #include "Name.h"
44 #include "Scope.h"
45
46 PEGASUS_NAMESPACE_BEGIN
47
48 PropertyRep::PropertyRep(
49 const String& name,
50 const Value& value,
51 Uint32 arraySize,
52 const String& referenceClassName,
53 const String& classOrigin,
54 Boolean propagated) :
55 _name(name), _value(value), _arraySize(arraySize),
56 mike 1.1 _referenceClassName(referenceClassName), _classOrigin(classOrigin),
57 _propagated(propagated)
58 {
59 if (!Name::legal(name))
60 throw IllegalName();
61
62 if (arraySize && (!value.isArray() || value.getArraySize() != arraySize))
63 throw IncompatibleTypes();
64
65 if (classOrigin.getLength() && !Name::legal(classOrigin))
66 throw IllegalName();
67
68 if (_value.getType() == Type::NONE)
69 throw NullType();
70
71 if (referenceClassName.getLength())
72 {
73 if (!Name::legal(referenceClassName))
74 throw IllegalName();
75
76 if (_value.getType() != Type::REFERENCE)
77 mike 1.1 {
78 throw ExpectedReferenceValue();
79 }
80 }
81 else
82 {
83 if (_value.getType() == Type::REFERENCE)
84 {
85 throw MissingReferenceClassName();
86 }
87 }
88 }
89
90 PropertyRep::~PropertyRep()
91 {
92
93 }
94
95 void PropertyRep::setName(const String& name)
96 {
97 if (!Name::legal(name))
98 mike 1.1 throw IllegalName();
99
100 _name = name;
101 }
102
103 void PropertyRep::setClassOrigin(const String& classOrigin)
104 {
105 if (!Name::legal(classOrigin))
106 throw IllegalName();
107
108 _classOrigin = classOrigin;
109 }
110
111 void PropertyRep::resolve(
112 DeclContext* declContext,
113 const String& nameSpace,
114 Boolean isInstancePart,
115 const ConstProperty& inheritedProperty)
116 {
|
117 mike 1.3 assert (inheritedProperty);
|
118 mike 1.1
|
119 mike 1.3 // Check the type:
|
120 mike 1.2
|
121 mike 1.3 if (!inheritedProperty.getValue().typeCompatible(_value))
122 throw TypeMismatch();
|
123 mike 1.1
124 // Validate the qualifiers of the property (according to
125 // superClass's property with the same name). This method
126 // will throw an exception if the validation fails.
127
|
128 mike 1.4 Uint32 scope = Scope::PROPERTY;
129
130 if (_value.getType() == Type::REFERENCE)
131 scope = Scope::REFERENCE;
132
|
133 mike 1.3 _qualifiers.resolve(
134 declContext,
135 nameSpace,
|
136 mike 1.4 scope,
|
137 mike 1.3 isInstancePart,
138 inheritedProperty._rep->_qualifiers);
139
140 _classOrigin = inheritedProperty.getClassOrigin();
|
141 mike 1.1 }
142
143 void PropertyRep::resolve(
144 DeclContext* declContext,
145 const String& nameSpace,
146 Boolean isInstancePart)
147 {
148 QualifierList dummy;
149
|
150 mike 1.4 Uint32 scope = Scope::PROPERTY;
151
152 if (_value.getType() == Type::REFERENCE)
153 scope = Scope::REFERENCE;
154
|
155 mike 1.1 _qualifiers.resolve(
156 declContext,
157 nameSpace,
|
158 mike 1.4 scope,
|
159 mike 1.1 isInstancePart,
160 dummy);
161 }
162
163 static const char* _toString(Boolean x)
164 {
165 return x ? "true" : "false";
166 }
167
168 void PropertyRep::toXml(Array<Sint8>& out) const
169 {
170 if (_value.isArray())
171 {
172 out << "<PROPERTY.ARRAY";
173
174 out << " NAME=\"" << _name << "\" ";
175
176 out << " TYPE=\"" << TypeToString(_value.getType()) << "\"";
177
178 if (_arraySize)
179 {
180 mike 1.1 char buffer[32];
181 sprintf(buffer, "%d", _arraySize);
182 out << " ARRAYSIZE=\"" << buffer << "\"";
183 }
184
185 if (_classOrigin.getLength())
186 out << " CLASSORIGIN=\"" << _classOrigin << "\"";
187
188 if (_propagated != false)
189 out << " PROPAGATED=\"" << _toString(_propagated) << "\"";
190
191 out << ">\n";
192
193 _qualifiers.toXml(out);
194
195 _value.toXml(out);
196
197 out << "</PROPERTY.ARRAY>\n";
198 }
199 else if (_value.getType() == Type::REFERENCE)
200 {
201 mike 1.1 out << "<PROPERTY.REFERENCE";
202
203 out << " NAME=\"" << _name << "\" ";
204
205 out << " REFERENCECLASS=\"" << _referenceClassName << "\"";
206
207 if (_classOrigin.getLength())
208 out << " CLASSORIGIN=\"" << _classOrigin << "\"";
209
210 if (_propagated != false)
211 out << " PROPAGATED=\"" << _toString(_propagated) << "\"";
212
213 out << ">\n";
214
215 _qualifiers.toXml(out);
216
217 _value.toXml(out);
218
219 out << "</PROPERTY.REFERENCE>\n";
220 }
221 else
222 mike 1.1 {
223 out << "<PROPERTY";
224 out << " NAME=\"" << _name << "\" ";
225
226 if (_classOrigin.getLength())
227 out << " CLASSORIGIN=\"" << _classOrigin << "\"";
228
229 if (_propagated != false)
230 out << " PROPAGATED=\"" << _toString(_propagated) << "\"";
231
232 out << " TYPE=\"" << TypeToString(_value.getType()) << "\"";
233
234 out << ">\n";
235
236 _qualifiers.toXml(out);
237
238 _value.toXml(out);
239
240 out << "</PROPERTY>\n";
241 }
242 }
243 mike 1.1
244 void PropertyRep::print() const
245 {
246 Array<Sint8> tmp;
247 toXml(tmp);
248 tmp.append('\0');
249 std::cout << tmp.getData() << std::endl;
250 }
251
252 Boolean PropertyRep::identical(const PropertyRep* x) const
253 {
254 if (_name != x->_name)
255 return false;
256
257 if (_value != x->_value)
258 return false;
259
260 if (_referenceClassName != x->_referenceClassName)
261 return false;
262
263 if (!_qualifiers.identical(x->_qualifiers))
264 mike 1.1 return false;
265
266 if (_classOrigin != x->_classOrigin)
267 return false;
268
269 if (_propagated != x->_propagated)
270 return false;
271
272 return true;
273 }
274
275 PropertyRep::PropertyRep()
276 {
277
278 }
279
280 PropertyRep::PropertyRep(const PropertyRep& x) :
281 Sharable(),
282 _name(x._name),
283 _value(x._value),
284 _arraySize(x._arraySize),
285 mike 1.1 _referenceClassName(x._referenceClassName),
286 _classOrigin(x._classOrigin),
287 _propagated(x._propagated)
288 {
289 x._qualifiers.cloneTo(_qualifiers);
290 }
291
292 PropertyRep& PropertyRep::operator=(const PropertyRep& x)
293 {
294 return *this;
295 }
296
297 void PropertyRep::setValue(const Value& value)
298 {
299 // Type of value is immutable:
300
301 if (!value.typeCompatible(_value))
302 throw IncompatibleTypes();
303
304 if (_arraySize && _arraySize != value.getArraySize())
305 throw IncompatibleTypes();
306 mike 1.1
307 _value = value;
308 }
309
310 PEGASUS_NAMESPACE_END
|