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

  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            
243 karl  1.13.2.1 /** toMof - returns the MOF for the CIM Property Object in the parameter.
244                    The BNF for the property MOF is:
245                    <pre>
246                    propertyDeclaration     = 	[ qualifierList ] dataType propertyName
247                				[ array ] [ defaultValue ] ";"
248                   
249                    array 		    = 	"[" [positiveDecimalValue] "]"
250                    
251                    defaultValue 	    = 	"=" initializer
252                    </pre>
253                    Format with qualifiers on one line and declaration on another. Start
254                    with newline but none at the end.
255                */
256                void CIMPropertyRep::toMof(Array<Sint8>& out) const  //ATTNKS:
257                {
258                    //Output the qualifier list
259                    if (_qualifiers.getCount())
260                	out << "\n"; 
261                    _qualifiers.toMof(out);
262                
263                    // Output the Type and name on a new line
264 karl  1.13.2.1     out << "\n" << TypeToString(_value.getType()) << " " << _name;
265                
266                    // If array put the Array indicator "[]" and possible size after name.
267                    if (_value.isArray())
268                    {
269                	if (_arraySize)
270                	{
271                	    char buffer[32];
272                	    sprintf(buffer, "[%d]", _arraySize);
273                	    out << buffer;
274                	}
275                	else
276                	    out << "[]";
277                    }
278                
279                    // If the property value is not Null, add value after "="
280                    if (!_value.isNull())
281                    {
282                	out << " = "; 
283                	if (_value.isArray())
284                	{ 
285 karl  1.13.2.1 	    // Insert any property values
286                	    _value.toMof(out);
287                	}
288                	else if (_value.getType() == CIMType::REFERENCE)
289                	{
290                	    _value.toMof(out);
291                	}
292                	else
293                	{ 
294                	    _value.toMof(out);
295                	}
296                    }
297                    // Close the property MOF
298                    out << ";";
299                
300                }
301                
302 mike  1.13     Boolean CIMPropertyRep::identical(const CIMPropertyRep* x) const
303                {
304                    if (_name != x->_name)
305                	return false;
306                
307                    if (_value != x->_value)
308                	return false;
309                
310                    if (_referenceClassName != x->_referenceClassName)
311                	return false;
312                
313                    if (!_qualifiers.identical(x->_qualifiers))
314                	return false;
315                
316                    if (_classOrigin != x->_classOrigin)
317                	return false;
318                
319                    if (_propagated != x->_propagated)
320                	return false;
321                
322                    return true;
323 mike  1.13     }
324                
325                Boolean CIMPropertyRep::isKey() const
326                {
327                    Uint32 pos = _qualifiers.findReverse("key");
328                
329                    if (pos == PEG_NOT_FOUND)
330                	return false;
331                
332                    Boolean flag;
333                    _qualifiers.getQualifier(pos).getValue().get(flag);
334                
335                    return flag;
336                }
337                
338                CIMPropertyRep::CIMPropertyRep()
339                {
340                
341                }
342                
343                CIMPropertyRep::CIMPropertyRep(const CIMPropertyRep& x) :
344 mike  1.13         Sharable(),
345                    _name(x._name),
346                    _value(x._value),
347                    _arraySize(x._arraySize),
348                    _referenceClassName(x._referenceClassName),
349                    _classOrigin(x._classOrigin),
350                    _propagated(x._propagated)
351                {
352                    x._qualifiers.cloneTo(_qualifiers);
353                }
354                
355                CIMPropertyRep& CIMPropertyRep::operator=(const CIMPropertyRep& x)
356                {
357                    return *this;
358                }
359                
360                void CIMPropertyRep::setValue(const CIMValue& value)
361                {
362                    // CIMType of value is immutable:
363                
364                    if (!value.typeCompatible(_value))
365 mike  1.13     	throw IncompatibleTypes();
366                
367                    if (_arraySize && _arraySize != value.getArraySize())
368                	throw IncompatibleTypes();
369                
370                    _value = value;
371                }
372                
373                PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2