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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2