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

  1 mike  1.1 //BEGIN_LICENSE
  2           //
  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           //END_LICENSE
 21           //BEGIN_HISTORY
 22 mike  1.1 //
 23           // Author:
 24           //
 25           // $Log: CIMMethodRep.cpp,v $
 26 mike  1.2 // Revision 1.1  2001/02/18 18:39:06  mike
 27           // new
 28           //
 29 mike  1.1 // Revision 1.2  2001/02/18 03:56:01  mike
 30 mike  1.2 // Changed more class names (e.g., ConstClassDecl -> ConstCIMClass)
 31 mike  1.1 //
 32           // Revision 1.1  2001/02/16 02:07:06  mike
 33           // Renamed many classes and headers (using new CIM prefixes).
 34           //
 35           // Revision 1.3  2001/01/23 01:25:35  mike
 36           // Reworked resolve scheme.
 37           //
 38           // Revision 1.2  2001/01/22 00:45:47  mike
 39           // more work on resolve scheme
 40           //
 41           // Revision 1.1.1.1  2001/01/14 19:52:58  mike
 42           // Pegasus import
 43           //
 44           //
 45           //END_HISTORY
 46           
 47           #include <cassert>
 48           #include "CIMMethod.h"
 49           #include "Indentor.h"
 50           #include "CIMName.h"
 51           #include "CIMScope.h"
 52 mike  1.1 #include "XmlWriter.h"
 53           
 54           PEGASUS_NAMESPACE_BEGIN
 55           
 56           CIMMethodRep::CIMMethodRep(
 57               const String& name, 
 58               CIMType type,
 59               const String& classOrigin,
 60               Boolean propagated) 
 61               : _name(name), _type(type), 
 62               _classOrigin(classOrigin), _propagated(propagated)
 63           {
 64               if (!CIMName::legal(name))
 65           	throw IllegalName();
 66           
 67               if (classOrigin.getLength() && !CIMName::legal(classOrigin))
 68           	throw IllegalName();
 69           
 70               if (type == CIMType::NONE)
 71           	throw NullType();
 72           }
 73 mike  1.1 
 74           CIMMethodRep::~CIMMethodRep()
 75           {
 76           
 77           }
 78           
 79           void CIMMethodRep::setName(const String& name) 
 80           {
 81               if (!CIMName::legal(name))
 82           	throw IllegalName();
 83           
 84               _name = name; 
 85           }
 86           
 87           void CIMMethodRep::setClassOrigin(const String& classOrigin)
 88           {
 89               if (!CIMName::legal(classOrigin))
 90           	throw IllegalName();
 91           
 92               _classOrigin = classOrigin; 
 93           }
 94 mike  1.1 
 95           void CIMMethodRep::addParameter(const CIMParameter& x)
 96           {
 97               if (!x)
 98           	throw UnitializedHandle();
 99           
100               if (findParameter(x.getName()) != Uint32(-1))
101           	throw AlreadyExists();
102           
103               _parameters.append(x);
104           }
105           
106           Uint32 CIMMethodRep::findParameter(const String& name)
107           {
108               for (Uint32 i = 0, n = _parameters.getSize(); i < n; i++)
109               {
110           	if (CIMName::equal(_parameters[i].getName(), name))
111           	    return i;
112               }
113           
114               return Uint32(-1);
115 mike  1.1 }
116           
117           CIMParameter CIMMethodRep::getParameter(Uint32 pos)
118           {
119               if (pos >= _parameters.getSize())
120           	throw OutOfBounds();
121           
122               return _parameters[pos];
123           }
124           
125           Uint32 CIMMethodRep::getParameterCount() const
126           {
127               return _parameters.getSize();
128           }
129           
130           void CIMMethodRep::resolve(
131               DeclContext* declContext, 
132               const String& nameSpace,
133               const CIMConstMethod& inheritedMethod)
134           {
135               // ATTN: Check to see if this method has same signature as
136 mike  1.1     // inherited one.
137           
138               // Check for type mismatch between return types.
139           
140               assert (inheritedMethod);
141           
142               // Validate the qualifiers of the method (according to
143               // superClass's method with the same name). This method
144               // will throw an exception if the validation fails.
145           
146               _qualifiers.resolve(
147           	declContext,
148           	nameSpace,
149           	CIMScope::METHOD,
150           	false,
151           	inheritedMethod._rep->_qualifiers);
152           
153               // Validate each of the parameters:
154           
155               for (size_t i = 0; i < _parameters.getSize(); i++)
156           	_parameters[i].resolve(declContext, nameSpace);
157 mike  1.1 
158               _classOrigin = inheritedMethod.getClassOrigin();
159           }
160           
161           void CIMMethodRep::resolve(
162               DeclContext* declContext,
163               const String& nameSpace)
164           {
165               // Validate the qualifiers:
166           
167               CIMQualifierList dummy;
168           
169               _qualifiers.resolve(
170           	declContext,
171           	nameSpace,
172           	CIMScope::METHOD,
173           	false,
174           	dummy);
175           
176               // Validate each of the parameters:
177           
178 mike  1.1     for (size_t i = 0; i < _parameters.getSize(); i++)
179           	_parameters[i].resolve(declContext, nameSpace);
180           }
181           
182           static const char* _toString(Boolean x)
183           {
184               return x ? "true" : "false";
185           }
186           
187           void CIMMethodRep::toXml(Array<Sint8>& out) const
188           {
189               out << "<METHOD";
190           
191               out << " NAME=\"" << _name << "\"";
192           
193               out << " TYPE=\"" << TypeToString(_type) << "\"";
194           
195               if (_classOrigin.getLength())
196           	out << " CLASSORIGIN=\"" << _classOrigin << "\"";
197           
198               if (_propagated != false)
199 mike  1.1 	out << " PROPAGATED=\"" << _toString(_propagated) << "\"";
200           
201               out << ">\n";
202           
203               _qualifiers.toXml(out);
204           
205               for (Uint32 i = 0, n = _parameters.getSize(); i < n; i++)
206           	_parameters[i].toXml(out);
207           
208               out << "</METHOD>\n";
209           }
210           
211           void CIMMethodRep::print() const
212           {
213               Array<Sint8> tmp;
214               toXml(tmp);
215               tmp.append('\0');
216               std::cout << tmp.getData() << std::endl;
217           }
218           
219           CIMMethodRep::CIMMethodRep()
220 mike  1.1 {
221           
222           }
223           
224           CIMMethodRep::CIMMethodRep(const CIMMethodRep& x) : 
225               Sharable(),
226               _name(x._name),
227               _type(x._type),
228               _classOrigin(x._classOrigin),
229               _propagated(x._propagated)
230           {
231               x._qualifiers.cloneTo(_qualifiers);
232           
233               _parameters.reserve(x._parameters.getSize());
234           
235               for (Uint32 i = 0, n = x._parameters.getSize(); i < n; i++)
236           	_parameters.append(x._parameters[i].clone());
237           }
238           
239           CIMMethodRep& CIMMethodRep::operator=(const CIMMethodRep& x) 
240           { 
241 mike  1.1     return *this; 
242           }
243           
244           Boolean CIMMethodRep::identical(const CIMMethodRep* x) const
245           {
246               if (_name != x->_name)
247           	return false;
248           
249               if (_type != x->_type)
250           	return false;
251           
252               if (!_qualifiers.identical(x->_qualifiers))
253           	return false;
254           
255               if (_parameters.getSize() != x->_parameters.getSize())
256           	return false;
257           
258               for (Uint32 i = 0, n = _parameters.getSize(); i < n; i++)
259               {
260           	if (!_parameters[i].identical(x->_parameters[i]))
261           	    return false;
262 mike  1.1     }
263           
264               return true;
265           }
266           
267           PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2