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.3 // Revision 1.2 2001/01/22 00:45:47 mike
27 // more work on resolve scheme
28 //
|
29 mike 1.2 // Revision 1.1.1.1 2001/01/14 19:53:05 mike
30 // Pegasus import
31 //
|
32 mike 1.1 //
33 //END_HISTORY
34
35 #include <cassert>
36 #include <cstdio>
37 #include "Property.h"
38 #include "XmlWriter.h"
39 #include "Indentor.h"
40 #include "Name.h"
41 #include "Scope.h"
42
43 PEGASUS_NAMESPACE_BEGIN
44
45 PropertyRep::PropertyRep(
46 const String& name,
47 const Value& value,
48 Uint32 arraySize,
49 const String& referenceClassName,
50 const String& classOrigin,
51 Boolean propagated) :
52 _name(name), _value(value), _arraySize(arraySize),
53 mike 1.1 _referenceClassName(referenceClassName), _classOrigin(classOrigin),
54 _propagated(propagated)
55 {
56 if (!Name::legal(name))
57 throw IllegalName();
58
59 if (arraySize && (!value.isArray() || value.getArraySize() != arraySize))
60 throw IncompatibleTypes();
61
62 if (classOrigin.getLength() && !Name::legal(classOrigin))
63 throw IllegalName();
64
65 if (_value.getType() == Type::NONE)
66 throw NullType();
67
68 if (referenceClassName.getLength())
69 {
70 if (!Name::legal(referenceClassName))
71 throw IllegalName();
72
73 if (_value.getType() != Type::REFERENCE)
74 mike 1.1 {
75 throw ExpectedReferenceValue();
76 }
77 }
78 else
79 {
80 if (_value.getType() == Type::REFERENCE)
81 {
82 throw MissingReferenceClassName();
83 }
84 }
85 }
86
87 PropertyRep::~PropertyRep()
88 {
89
90 }
91
92 void PropertyRep::setName(const String& name)
93 {
94 if (!Name::legal(name))
95 mike 1.1 throw IllegalName();
96
97 _name = name;
98 }
99
100 void PropertyRep::setClassOrigin(const String& classOrigin)
101 {
102 if (!Name::legal(classOrigin))
103 throw IllegalName();
104
105 _classOrigin = classOrigin;
106 }
107
108 void PropertyRep::resolve(
109 DeclContext* declContext,
110 const String& nameSpace,
111 Boolean isInstancePart,
112 const ConstProperty& inheritedProperty)
113 {
|
114 mike 1.3 assert (inheritedProperty);
|
115 mike 1.1
|
116 mike 1.3 // Check the type:
|
117 mike 1.2
|
118 mike 1.3 if (!inheritedProperty.getValue().typeCompatible(_value))
119 throw TypeMismatch();
|
120 mike 1.1
121 // Validate the qualifiers of the property (according to
122 // superClass's property with the same name). This method
123 // will throw an exception if the validation fails.
124
|
125 mike 1.3 _qualifiers.resolve(
126 declContext,
127 nameSpace,
128 Scope::PROPERTY,
129 isInstancePart,
130 inheritedProperty._rep->_qualifiers);
131
132 _classOrigin = inheritedProperty.getClassOrigin();
|
133 mike 1.1 }
134
135 void PropertyRep::resolve(
136 DeclContext* declContext,
137 const String& nameSpace,
138 Boolean isInstancePart)
139 {
140 QualifierList dummy;
141
142 _qualifiers.resolve(
143 declContext,
144 nameSpace,
145 Scope::PROPERTY,
146 isInstancePart,
147 dummy);
148 }
149
150 static const char* _toString(Boolean x)
151 {
152 return x ? "true" : "false";
153 }
154 mike 1.1
155 void PropertyRep::toXml(Array<Sint8>& out) const
156 {
157 if (_value.isArray())
158 {
159 out << "<PROPERTY.ARRAY";
160
161 out << " NAME=\"" << _name << "\" ";
162
163 out << " TYPE=\"" << TypeToString(_value.getType()) << "\"";
164
165 if (_arraySize)
166 {
167 char buffer[32];
168 sprintf(buffer, "%d", _arraySize);
169 out << " ARRAYSIZE=\"" << buffer << "\"";
170 }
171
172 if (_classOrigin.getLength())
173 out << " CLASSORIGIN=\"" << _classOrigin << "\"";
174
175 mike 1.1 if (_propagated != false)
176 out << " PROPAGATED=\"" << _toString(_propagated) << "\"";
177
178 out << ">\n";
179
180 _qualifiers.toXml(out);
181
182 _value.toXml(out);
183
184 out << "</PROPERTY.ARRAY>\n";
185 }
186 else if (_value.getType() == Type::REFERENCE)
187 {
188 out << "<PROPERTY.REFERENCE";
189
190 out << " NAME=\"" << _name << "\" ";
191
192 out << " REFERENCECLASS=\"" << _referenceClassName << "\"";
193
194 if (_classOrigin.getLength())
195 out << " CLASSORIGIN=\"" << _classOrigin << "\"";
196 mike 1.1
197 if (_propagated != false)
198 out << " PROPAGATED=\"" << _toString(_propagated) << "\"";
199
200 out << ">\n";
201
202 _qualifiers.toXml(out);
203
204 _value.toXml(out);
205
206 out << "</PROPERTY.REFERENCE>\n";
207 }
208 else
209 {
210 out << "<PROPERTY";
211 out << " NAME=\"" << _name << "\" ";
212
213 if (_classOrigin.getLength())
214 out << " CLASSORIGIN=\"" << _classOrigin << "\"";
215
216 if (_propagated != false)
217 mike 1.1 out << " PROPAGATED=\"" << _toString(_propagated) << "\"";
218
219 out << " TYPE=\"" << TypeToString(_value.getType()) << "\"";
220
221 out << ">\n";
222
223 _qualifiers.toXml(out);
224
225 _value.toXml(out);
226
227 out << "</PROPERTY>\n";
228 }
229 }
230
231 void PropertyRep::print() const
232 {
233 Array<Sint8> tmp;
234 toXml(tmp);
235 tmp.append('\0');
236 std::cout << tmp.getData() << std::endl;
237 }
238 mike 1.1
239 Boolean PropertyRep::identical(const PropertyRep* x) const
240 {
241 if (_name != x->_name)
242 return false;
243
244 if (_value != x->_value)
245 return false;
246
247 if (_referenceClassName != x->_referenceClassName)
248 return false;
249
250 if (!_qualifiers.identical(x->_qualifiers))
251 return false;
252
253 if (_classOrigin != x->_classOrigin)
254 return false;
255
256 if (_propagated != x->_propagated)
257 return false;
258
259 mike 1.1 return true;
260 }
261
262 PropertyRep::PropertyRep()
263 {
264
265 }
266
267 PropertyRep::PropertyRep(const PropertyRep& x) :
268 Sharable(),
269 _name(x._name),
270 _value(x._value),
271 _arraySize(x._arraySize),
272 _referenceClassName(x._referenceClassName),
273 _classOrigin(x._classOrigin),
274 _propagated(x._propagated)
275 {
276 x._qualifiers.cloneTo(_qualifiers);
277 }
278
279 PropertyRep& PropertyRep::operator=(const PropertyRep& x)
280 mike 1.1 {
281 return *this;
282 }
283
284 void PropertyRep::setValue(const Value& value)
285 {
286 // Type of value is immutable:
287
288 if (!value.typeCompatible(_value))
289 throw IncompatibleTypes();
290
291 if (_arraySize && _arraySize != value.getArraySize())
292 throw IncompatibleTypes();
293
294 _value = value;
295 }
296
297 PEGASUS_NAMESPACE_END
|