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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2