(file) Return to CIMPropertyRep.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2