(file) Return to MethodRep.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$
 26           //
 27           //END_HISTORY
 28           
 29           #include <cassert>
 30           #include "Method.h"
 31           #include "Indentor.h"
 32           #include "Name.h"
 33           #include "Scope.h"
 34           #include "XmlWriter.h"
 35           
 36           PEGASUS_NAMESPACE_BEGIN
 37           
 38           MethodRep::MethodRep(
 39               const String& name, 
 40               Type type,
 41               const String& classOrigin,
 42               Boolean propagated) 
 43 mike  1.1     : _name(name), _type(type), 
 44               _classOrigin(classOrigin), _propagated(propagated)
 45           {
 46               if (!Name::legal(name))
 47           	throw IllegalName();
 48           
 49               if (classOrigin.getLength() && !Name::legal(classOrigin))
 50           	throw IllegalName();
 51           
 52               if (type == Type::NONE)
 53           	throw NullType();
 54           }
 55           
 56           MethodRep::~MethodRep()
 57           {
 58           
 59           }
 60           
 61           void MethodRep::setName(const String& name) 
 62           {
 63               if (!Name::legal(name))
 64 mike  1.1 	throw IllegalName();
 65           
 66               _name = name; 
 67           }
 68           
 69           void MethodRep::setClassOrigin(const String& classOrigin)
 70           {
 71               if (!Name::legal(classOrigin))
 72           	throw IllegalName();
 73           
 74               _classOrigin = classOrigin; 
 75           }
 76           
 77           void MethodRep::addParameter(const Parameter& x)
 78           {
 79               if (!x)
 80           	throw UnitializedHandle();
 81           
 82               if (findParameter(x.getName()) != Uint32(-1))
 83           	throw AlreadyExists();
 84           
 85 mike  1.1     _parameters.append(x);
 86           }
 87           
 88           Uint32 MethodRep::findParameter(const String& name)
 89           {
 90               for (Uint32 i = 0, n = _parameters.getSize(); i < n; i++)
 91               {
 92           	if (Name::equal(_parameters[i].getName(), name))
 93           	    return i;
 94               }
 95           
 96               return Uint32(-1);
 97           }
 98           
 99           Parameter MethodRep::getParameter(Uint32 pos)
100           {
101               if (pos >= _parameters.getSize())
102           	throw OutOfBounds();
103           
104               return _parameters[pos];
105           }
106 mike  1.1 
107           Uint32 MethodRep::getParameterCount() const
108           {
109               return _parameters.getSize();
110           }
111           
112           void MethodRep::resolve(
113               DeclContext* declContext, 
114               const String& nameSpace,
115               const ConstMethod& inheritedMethod)
116           {
117               assert(Name::equal(getName(), inheritedMethod.getName()));
118           
119               if (getType() != inheritedMethod.getType())
120               {
121           	String tmp = inheritedMethod.getName();
122           	tmp.append("; attempt to change type");
123           	throw InvalidMethodOverride(tmp);
124               }
125           
126               // Validate the qualifiers of the method (according to
127 mike  1.1     // superClass's method with the same name). This method
128               // will throw an exception if the validation fails.
129           
130               _qualifiers.resolve(
131           	declContext,
132           	nameSpace,
133           	Scope::METHOD,
134           	false,
135           	inheritedMethod._rep->_qualifiers);
136           
137               // Validate each of the parameters:
138           
139               for (size_t i = 0; i < _parameters.getSize(); i++)
140           	_parameters[i].resolve(declContext, nameSpace);
141           }
142           
143           void MethodRep::resolve(
144               DeclContext* declContext,
145               const String& nameSpace)
146           {
147               // Validate the qualifiers:
148 mike  1.1 
149               QualifierList dummy;
150           
151               _qualifiers.resolve(
152           	declContext,
153           	nameSpace,
154           	Scope::METHOD,
155           	false,
156           	dummy);
157           
158               // Validate each of the parameters:
159           
160               for (size_t i = 0; i < _parameters.getSize(); i++)
161           	_parameters[i].resolve(declContext, nameSpace);
162           }
163           
164           static const char* _toString(Boolean x)
165           {
166               return x ? "true" : "false";
167           }
168           
169 mike  1.1 void MethodRep::toXml(Array<Sint8>& out) const
170           {
171               out << "<METHOD";
172           
173               out << " NAME=\"" << _name << "\"";
174           
175               out << " TYPE=\"" << TypeToString(_type) << "\"";
176           
177               if (_classOrigin.getLength())
178           	out << " CLASSORIGIN=\"" << _classOrigin << "\"";
179           
180               if (_propagated != false)
181           	out << " PROPAGATED=\"" << _toString(_propagated) << "\"";
182           
183               out << ">\n";
184           
185               _qualifiers.toXml(out);
186           
187               for (Uint32 i = 0, n = _parameters.getSize(); i < n; i++)
188           	_parameters[i].toXml(out);
189           
190 mike  1.1     out << "</METHOD>\n";
191           }
192           
193           void MethodRep::print() const
194           {
195               Array<Sint8> tmp;
196               toXml(tmp);
197               tmp.append('\0');
198               std::cout << tmp.getData() << std::endl;
199           }
200           
201           MethodRep::MethodRep()
202           {
203           
204           }
205           
206           MethodRep::MethodRep(const MethodRep& x) : 
207               Sharable(),
208               _name(x._name),
209               _type(x._type),
210               _classOrigin(x._classOrigin),
211 mike  1.1     _propagated(x._propagated)
212           {
213               x._qualifiers.cloneTo(_qualifiers);
214           
215               _parameters.reserve(x._parameters.getSize());
216           
217               for (Uint32 i = 0, n = x._parameters.getSize(); i < n; i++)
218           	_parameters.append(x._parameters[i].clone());
219           }
220           
221           MethodRep& MethodRep::operator=(const MethodRep& x) 
222           { 
223               return *this; 
224           }
225           
226           Boolean MethodRep::identical(const MethodRep* x) const
227           {
228               if (_name != x->_name)
229           	return false;
230           
231               if (_type != x->_type)
232 mike  1.1 	return false;
233           
234               if (!_qualifiers.identical(x->_qualifiers))
235           	return false;
236           
237               if (_parameters.getSize() != x->_parameters.getSize())
238           	return false;
239           
240               for (Uint32 i = 0, n = _parameters.getSize(); i < n; i++)
241               {
242           	if (!_parameters[i].identical(x->_parameters[i]))
243           	    return false;
244               }
245           
246               return true;
247           }
248           
249           PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2