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

  1 mike  1.13 //%/////////////////////////////////////////////////////////////////////////////
  2            //
  3 kumpf 1.24 // 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.24 // 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.24 // 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.24 // 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.27 // Modified By: Carol Ann Krug Graves, Hewlett-Packard Company
 27            //                (carolann_graves@hp.com)
 28 mike  1.13 //
 29            //%/////////////////////////////////////////////////////////////////////////////
 30            
 31 sage  1.15 #include <Pegasus/Common/Config.h>
 32 mike  1.13 #include "CIMMethod.h"
 33 kumpf 1.18 #include "CIMMethodRep.h"
 34 kumpf 1.27 #include "Resolver.h"
 35 mike  1.13 #include "Indentor.h"
 36            #include "CIMName.h"
 37            #include "CIMScope.h"
 38            #include "XmlWriter.h"
 39 kumpf 1.23 #include "MofWriter.h"
 40 mike  1.13 
 41            PEGASUS_NAMESPACE_BEGIN
 42            
 43            CIMMethodRep::CIMMethodRep(
 44                const String& name,
 45                CIMType type,
 46                const String& classOrigin,
 47                Boolean propagated)
 48                : _name(name), _type(type),
 49                _classOrigin(classOrigin), _propagated(propagated)
 50            {
 51                if (!CIMName::legal(name))
 52            	throw IllegalName();
 53            
 54                if (classOrigin.size() && !CIMName::legal(classOrigin))
 55            	throw IllegalName();
 56            
 57 kumpf 1.28     if (type == CIMTYPE_NONE)
 58 mike  1.13 	throw NullType();
 59            }
 60            
 61            CIMMethodRep::~CIMMethodRep()
 62            {
 63            
 64            }
 65            
 66            void CIMMethodRep::setName(const String& name)
 67            {
 68                if (!CIMName::legal(name))
 69            	throw IllegalName();
 70            
 71                _name = name;
 72            }
 73            
 74            void CIMMethodRep::setClassOrigin(const String& classOrigin)
 75            {
 76                if (!CIMName::legal(classOrigin))
 77            	throw IllegalName();
 78            
 79 mike  1.13     _classOrigin = classOrigin;
 80            }
 81            
 82            void CIMMethodRep::addParameter(const CIMParameter& x)
 83            {
 84 kumpf 1.20     if (x.isNull())
 85 kumpf 1.19 	throw UninitializedHandle();
 86 mike  1.13 
 87                if (findParameter(x.getName()) != PEG_NOT_FOUND)
 88            	throw AlreadyExists();
 89            
 90                _parameters.append(x);
 91            }
 92            
 93 kumpf 1.18 Uint32 CIMMethodRep::findParameter(const String& name) const
 94 mike  1.13 {
 95                for (Uint32 i = 0, n = _parameters.size(); i < n; i++)
 96                {
 97            	if (CIMName::equal(_parameters[i].getName(), name))
 98            	    return i;
 99                }
100            
101                return PEG_NOT_FOUND;
102            }
103            
104            CIMParameter CIMMethodRep::getParameter(Uint32 pos)
105            {
106                if (pos >= _parameters.size())
107            	throw OutOfBounds();
108            
109                return _parameters[pos];
110            }
111            
112            Uint32 CIMMethodRep::getParameterCount() const
113            {
114                return _parameters.size();
115 mike  1.13 }
116            
117            void CIMMethodRep::resolve(
118                DeclContext* declContext,
119                const String& nameSpace,
120                const CIMConstMethod& inheritedMethod)
121            {
122                // ATTN: Check to see if this method has same signature as
123                // inherited one.
124            
125                // Check for type mismatch between return types.
126            
127 kumpf 1.25     PEGASUS_ASSERT(!inheritedMethod.isNull());
128 mike  1.13 
129                // Validate the qualifiers of the method (according to
130                // superClass's method with the same name). This method
131                // will throw an exception if the validation fails.
132            
133                _qualifiers.resolve(
134            	declContext,
135            	nameSpace,
136            	CIMScope::METHOD,
137            	false,
138 mike  1.16 	inheritedMethod._rep->_qualifiers,
139            	true);
140 mike  1.13 
141                // Validate each of the parameters:
142            
143                for (size_t i = 0; i < _parameters.size(); i++)
144 kumpf 1.27 	Resolver::resolveParameter (_parameters[i], declContext, nameSpace);
145 mike  1.13 
146                _classOrigin = inheritedMethod.getClassOrigin();
147            }
148            
149            void CIMMethodRep::resolve(
150                DeclContext* declContext,
151                const String& nameSpace)
152            {
153                // Validate the qualifiers:
154            
155                CIMQualifierList dummy;
156            
157                _qualifiers.resolve(
158            	declContext,
159            	nameSpace,
160            	CIMScope::METHOD,
161            	false,
162 mike  1.16 	dummy,
163            	true);
164 mike  1.13 
165                // Validate each of the parameters:
166            
167                for (size_t i = 0; i < _parameters.size(); i++)
168 kumpf 1.27 	Resolver::resolveParameter (_parameters[i], declContext, nameSpace);
169 mike  1.13 }
170            
171            static const char* _toString(Boolean x)
172            {
173                return x ? "true" : "false";
174            }
175            
176            void CIMMethodRep::toXml(Array<Sint8>& out) const
177            {
178                out << "<METHOD";
179            
180                out << " NAME=\"" << _name << "\"";
181            
182 kumpf 1.28     out << " TYPE=\"" << cimTypeToString (_type) << "\"";
183 mike  1.13 
184                if (_classOrigin.size())
185            	out << " CLASSORIGIN=\"" << _classOrigin << "\"";
186            
187                if (_propagated != false)
188            	out << " PROPAGATED=\"" << _toString(_propagated) << "\"";
189            
190                out << ">\n";
191            
192                _qualifiers.toXml(out);
193            
194                for (Uint32 i = 0, n = _parameters.size(); i < n; i++)
195 kumpf 1.22 	XmlWriter::appendParameterElement(out, _parameters[i]);
196 mike  1.13 
197                out << "</METHOD>\n";
198            }
199            
200 mike  1.14 /**
201                The BNF for this is;
202                methodDeclaration 	=  [ qualifierList ] dataType methodName
203            			   "(" [ parameterList ] ")" ";"
204            
205                parameterList 	=  parameter *( "," parameter )
206                Format with qualifiers on one line and declaration on another. Start
207                with newline but none at the end.
208            */
209            void CIMMethodRep::toMof(Array<Sint8>& out) const   //ATTNKS:
210            {
211                // Output the qualifier list starting on new line
212                if (_qualifiers.getCount())
213            	out << "\n";
214            
215                _qualifiers.toMof(out);
216            
217                // output the type,	MethodName and ParmeterList left enclosure
218 kumpf 1.28     out << "\n" << cimTypeToString (_type) << " " << _name << "(";
219 mike  1.14 
220                // output the param list separated by commas.
221                
222                for (Uint32 i = 0, n = _parameters.size(); i < n; i++)
223                {
224            	// If not first, output comma separator
225            	if (i)
226            	    out << ", ";
227            
228 kumpf 1.23 	MofWriter::appendParameterElement(out, _parameters[i]);
229 mike  1.14     }
230            
231                // output the parameterlist and method terminator
232                out << ");";
233            }
234            
235            
236 mike  1.13 CIMMethodRep::CIMMethodRep()
237            {
238            
239            }
240            
241            CIMMethodRep::CIMMethodRep(const CIMMethodRep& x) :
242                Sharable(),
243                _name(x._name),
244                _type(x._type),
245                _classOrigin(x._classOrigin),
246                _propagated(x._propagated)
247            {
248                x._qualifiers.cloneTo(_qualifiers);
249            
250 kumpf 1.26     _parameters.reserveCapacity(x._parameters.size());
251 mike  1.13 
252                for (Uint32 i = 0, n = x._parameters.size(); i < n; i++)
253            	_parameters.append(x._parameters[i].clone());
254            }
255            
256            Boolean CIMMethodRep::identical(const CIMMethodRep* x) const
257            {
258                if (_name != x->_name)
259            	return false;
260            
261                if (_type != x->_type)
262            	return false;
263            
264                if (!_qualifiers.identical(x->_qualifiers))
265            	return false;
266            
267                if (_parameters.size() != x->_parameters.size())
268            	return false;
269            
270                for (Uint32 i = 0, n = _parameters.size(); i < n; i++)
271                {
272 mike  1.13 	if (!_parameters[i].identical(x->_parameters[i]))
273            	    return false;
274                }
275            
276                return true;
277            }
278            
279            void CIMMethodRep::setType(CIMType type)
280            {
281                _type = type;
282            
283 kumpf 1.28     if (type == CIMTYPE_NONE)
284 mike  1.13 	throw NullType();
285            }
286            
287            PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2