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

  1 mike  1.9 //%/////////////////////////////////////////////////////////////////////////////
  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.9 //
 23           // Author: Mike Brasher (mbrasher@bmc.com)
 24           //
 25           // Modified By:
 26           //
 27           //%/////////////////////////////////////////////////////////////////////////////
 28           
 29 sage  1.11 #include <Pegasus/Common/Config.h>
 30 mike  1.9  #include <cstdio>
 31            #include "CIMParameter.h"
 32            #include "Indentor.h"
 33            #include "CIMName.h"
 34            #include "CIMScope.h"
 35            #include "XmlWriter.h"
 36            
 37            PEGASUS_NAMESPACE_BEGIN
 38            
 39            CIMParameterRep::CIMParameterRep(
 40                const String& name, 
 41                CIMType type,
 42                Boolean isArray,
 43                Uint32 arraySize,
 44                const String& referenceClassName) 
 45                : _name(name), _type(type), 
 46                _isArray(isArray), _arraySize(arraySize), 
 47                _referenceClassName(referenceClassName)
 48            {
 49                if (!CIMName::legal(name))
 50            	throw IllegalName();
 51 mike  1.9  
 52 kumpf 1.13     if (_type == CIMType::NONE)
 53            	throw NullType();
 54 mike  1.9  
 55                if (_arraySize && !_isArray)
 56            	throw IncompatibleTypes();
 57            
 58                if (referenceClassName.size())
 59                {
 60            	if (!CIMName::legal(referenceClassName))
 61            	    throw IllegalName();
 62            
 63            	if (_type != CIMType::REFERENCE)
 64            	{
 65            	    throw ExpectedReferenceValue();
 66            	}
 67                }
 68                else
 69                {
 70            
 71                // ATTN: revisit this later!
 72            #if 0
 73            	if (_type == CIMType::REFERENCE)
 74            	    throw MissingReferenceClassName();
 75 mike  1.9  #endif
 76                }
 77            }
 78            
 79            CIMParameterRep::~CIMParameterRep()
 80            {
 81            
 82            }
 83            
 84            void CIMParameterRep::setName(const String& name) 
 85            {
 86                if (!CIMName::legal(name))
 87            	throw IllegalName();
 88            
 89                _name = name; 
 90            }
 91            
 92            void CIMParameterRep::resolve(
 93                DeclContext* declContext,
 94                const String& nameSpace)
 95            {
 96 mike  1.9      // Validate the qualifiers of the method (according to
 97                // superClass's method with the same name). This method
 98                // will throw an exception if the validation fails.
 99            
100                CIMQualifierList dummy;
101            
102                _qualifiers.resolve(
103            	declContext,
104            	nameSpace,
105            	CIMScope::PARAMETER,
106            	false,
107            	dummy);
108            }
109            
110            void CIMParameterRep::toXml(Array<Sint8>& out) const
111            {
112                if (_isArray)
113                {
114            	out << "<PARAMETER.ARRAY";
115            
116            	out << " NAME=\"" << _name << "\" ";
117 mike  1.9  
118            	out << " TYPE=\"" << TypeToString(_type) << "\"";
119            
120            	if (_arraySize)
121            	{
122            	    char buffer[32];
123            	    sprintf(buffer, "%d", _arraySize);
124            	    out << " ARRAYSIZE=\"" << buffer << "\"";
125            	}
126            
127            	out << ">\n";
128            
129            	_qualifiers.toXml(out);
130            
131            	out << "</PARAMETER.ARRAY>\n";
132                }
133 mike  1.10     else if (_type == CIMType::REFERENCE)
134                {
135            	out << "<PARAMETER.REFERENCE";
136            	out << " NAME=\"" << _name << "\" ";
137            	out << " REFERENCECLASS=\"" << _referenceClassName << "\"";
138            	out << ">\n";
139            
140            	_qualifiers.toXml(out);
141            
142            	out << "</PARAMETER.REFERENCE>\n";
143                }
144 mike  1.9      else
145                {
146            	out << "<PARAMETER";
147            	out << " NAME=\"" << _name << "\" ";
148            	out << " TYPE=\"" << TypeToString(_type) << "\"";
149            	out << ">\n";
150            
151            	_qualifiers.toXml(out);
152            
153            	out << "</PARAMETER>\n";
154                }
155            }
156 mike  1.10 
157            /** toMof - puts the Mof representation of teh Parameter object to
158                the output parameter array
159                The BNF for this conversion is:
160                parameterList    = 	parameter *( "," parameter )
161            
162            	parameter    = 	[ qualifierList ] (dataType|objectRef) parameterName
163            				[ array ]
164            
165            	parameterName= 	IDENTIFIER
166            	
167            	array 	     = 	"[" [positiveDecimalValue] "]"
168            	
169                Format on a single line.
170                */
171            void CIMParameterRep::toMof(Array<Sint8>& out) const
172            {
173                // Output the qualifiers for the parameter
174                _qualifiers.toMof(out);
175            
176                if (_qualifiers.getCount())
177 mike  1.10 	out << " ";
178            
179                // Output the data type and name
180                out << TypeToString(_type) << " " <<  _name;
181            
182                if (_isArray)
183                {
184            	//Output the array indicator "[ [arraysize] ]"
185            	if (_arraySize)
186            	{
187            	    char buffer[32];
188            	    sprintf(buffer, "[%d]", _arraySize);
189            	    out << buffer;
190            	}
191            	else
192            	    out << "[]";
193                }
194            }
195            
196 mike  1.9  
197            void CIMParameterRep::print(PEGASUS_STD(ostream) &os) const 
198            {
199                Array<Sint8> tmp;
200                toXml(tmp);
201                tmp.append('\0');
202                os << tmp.getData() << PEGASUS_STD(endl);
203            }
204            
205            Boolean CIMParameterRep::identical(const CIMParameterRep* x) const
206            {
207                if (_name != x->_name)
208            	return false;
209            
210                if (_type != x->_type)
211            	return false;
212            
213                if (_referenceClassName != x->_referenceClassName)
214            	return false;
215            
216                if (!_qualifiers.identical(x->_qualifiers))
217 mike  1.9  	return false;
218            
219                return true;
220            }
221            
222            CIMParameterRep::CIMParameterRep()
223            {
224            
225            }
226            
227            CIMParameterRep::CIMParameterRep(const CIMParameterRep& x) :
228                Sharable(),
229                _name(x._name),
230                _type(x._type),
231                _isArray(x._isArray),
232                _arraySize(x._arraySize),
233                _referenceClassName(x._referenceClassName)
234            {
235                x._qualifiers.cloneTo(_qualifiers);
236            }
237            
238 mike  1.9  CIMParameterRep& CIMParameterRep::operator=(const CIMParameterRep& x) 
239            { 
240                return *this; 
241            }
242            
243            void CIMParameterRep::setType(CIMType type)
244            { 
245                _type = type;
246            
247                if (_referenceClassName.size() == 0 && _type == CIMType::REFERENCE)
248                {
249            	throw MissingReferenceClassName();
250                }
251            }
252            
253            PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2