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

  1 karl  1.39 //%2003////////////////////////////////////////////////////////////////////////
  2 mike  1.13 //
  3 karl  1.39 // Copyright (c) 2000, 2001, 2002  BMC Software, Hewlett-Packard Development
  4            // Company, L. P., IBM Corp., The Open Group, Tivoli Systems.
  5            // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.;
  6            // IBM Corp.; EMC Corporation, The Open Group.
  7 mike  1.13 //
  8            // Permission is hereby granted, free of charge, to any person obtaining a copy
  9 kumpf 1.24 // of this software and associated documentation files (the "Software"), to
 10            // deal in the Software without restriction, including without limitation the
 11            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 12 mike  1.13 // sell copies of the Software, and to permit persons to whom the Software is
 13            // furnished to do so, subject to the following conditions:
 14            // 
 15 kumpf 1.24 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 16 mike  1.13 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 17            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 18 kumpf 1.24 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 19            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 20            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 21 mike  1.13 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 22            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 23            //
 24            //==============================================================================
 25            //
 26            // Author: Mike Brasher (mbrasher@bmc.com)
 27            //
 28 kumpf 1.27 // Modified By: Carol Ann Krug Graves, Hewlett-Packard Company
 29            //                (carolann_graves@hp.com)
 30 mike  1.13 //
 31            //%/////////////////////////////////////////////////////////////////////////////
 32            
 33 sage  1.15 #include <Pegasus/Common/Config.h>
 34 mike  1.13 #include "CIMMethod.h"
 35 kumpf 1.18 #include "CIMMethodRep.h"
 36 kumpf 1.27 #include "Resolver.h"
 37 mike  1.13 #include "Indentor.h"
 38            #include "CIMName.h"
 39            #include "CIMScope.h"
 40            #include "XmlWriter.h"
 41 kumpf 1.23 #include "MofWriter.h"
 42 humberto 1.38 #include <Pegasus/Common/MessageLoader.h> //l10n
 43 mike     1.13 
 44               PEGASUS_NAMESPACE_BEGIN
 45               
 46               CIMMethodRep::CIMMethodRep(
 47 kumpf    1.29     const CIMName& name,
 48 mike     1.13     CIMType type,
 49 kumpf    1.29     const CIMName& classOrigin,
 50 mike     1.13     Boolean propagated)
 51                   : _name(name), _type(type),
 52                   _classOrigin(classOrigin), _propagated(propagated)
 53               {
 54               }
 55               
 56               CIMMethodRep::~CIMMethodRep()
 57               {
 58               
 59               }
 60               
 61 kumpf    1.29 void CIMMethodRep::setName(const CIMName& name)
 62 mike     1.13 {
 63                   _name = name;
 64               }
 65               
 66 kumpf    1.29 void CIMMethodRep::setClassOrigin(const CIMName& classOrigin)
 67 mike     1.13 {
 68                   _classOrigin = classOrigin;
 69               }
 70               
 71               void CIMMethodRep::addParameter(const CIMParameter& x)
 72               {
 73 kumpf    1.31     if (x.isUninitialized())
 74 kumpf    1.34 	throw UninitializedObjectException();
 75 mike     1.13 
 76 humberto 1.38     if (findParameter(x.getName()) != PEG_NOT_FOUND){
 77                   	//l10n
 78               		//throw AlreadyExistsException
 79                           //("parameter \"" + x.getName().getString () + "\"");
 80                       MessageLoaderParms parms("Common.CIMMethodRep.PARAMETER",
 81                       						 "parameter \"$0\"",
 82                       						 x.getName().getString());
 83                       throw AlreadyExistsException(parms);
 84                   }
 85 mike     1.13 
 86                   _parameters.append(x);
 87               }
 88               
 89 kumpf    1.29 Uint32 CIMMethodRep::findParameter(const CIMName& name) const
 90 mike     1.13 {
 91                   for (Uint32 i = 0, n = _parameters.size(); i < n; i++)
 92                   {
 93 kumpf    1.29 	if (name.equal(_parameters[i].getName()))
 94 mike     1.13 	    return i;
 95                   }
 96               
 97                   return PEG_NOT_FOUND;
 98               }
 99               
100 kumpf    1.36 CIMParameter CIMMethodRep::getParameter(Uint32 index)
101 mike     1.13 {
102 kumpf    1.36     if (index >= _parameters.size())
103 kumpf    1.34 	throw IndexOutOfBoundsException();
104 mike     1.13 
105 kumpf    1.36     return _parameters[index];
106 mike     1.13 }
107               
108 kumpf    1.36 void CIMMethodRep::removeParameter(Uint32 index)
109 kumpf    1.32 {
110 kumpf    1.36     if (index >= _parameters.size())
111 kumpf    1.34 	throw IndexOutOfBoundsException();
112 kumpf    1.32 
113 kumpf    1.36     _parameters.remove (index);
114 kumpf    1.32 }
115               
116 mike     1.13 Uint32 CIMMethodRep::getParameterCount() const
117               {
118                   return _parameters.size();
119               }
120               
121               void CIMMethodRep::resolve(
122                   DeclContext* declContext,
123 kumpf    1.29     const CIMNamespaceName& nameSpace,
124 mike     1.13     const CIMConstMethod& inheritedMethod)
125               {
126                   // ATTN: Check to see if this method has same signature as
127                   // inherited one.
128               
129                   // Check for type mismatch between return types.
130               
131 kumpf    1.31     PEGASUS_ASSERT(!inheritedMethod.isUninitialized());
132 mike     1.13 
133                   // Validate the qualifiers of the method (according to
134                   // superClass's method with the same name). This method
135                   // will throw an exception if the validation fails.
136               
137                   _qualifiers.resolve(
138               	declContext,
139               	nameSpace,
140               	CIMScope::METHOD,
141               	false,
142 mike     1.16 	inheritedMethod._rep->_qualifiers,
143               	true);
144 mike     1.13 
145                   // Validate each of the parameters:
146               
147                   for (size_t i = 0; i < _parameters.size(); i++)
148 kumpf    1.27 	Resolver::resolveParameter (_parameters[i], declContext, nameSpace);
149 mike     1.13 
150                   _classOrigin = inheritedMethod.getClassOrigin();
151               }
152               
153               void CIMMethodRep::resolve(
154                   DeclContext* declContext,
155 kumpf    1.29     const CIMNamespaceName& nameSpace)
156 mike     1.13 {
157                   // Validate the qualifiers:
158               
159                   CIMQualifierList dummy;
160               
161                   _qualifiers.resolve(
162               	declContext,
163               	nameSpace,
164               	CIMScope::METHOD,
165               	false,
166 mike     1.16 	dummy,
167               	true);
168 mike     1.13 
169                   // Validate each of the parameters:
170               
171                   for (size_t i = 0; i < _parameters.size(); i++)
172 kumpf    1.27 	Resolver::resolveParameter (_parameters[i], declContext, nameSpace);
173 mike     1.13 }
174               
175               static const char* _toString(Boolean x)
176               {
177                   return x ? "true" : "false";
178               }
179               
180               void CIMMethodRep::toXml(Array<Sint8>& out) const
181               {
182                   out << "<METHOD";
183               
184                   out << " NAME=\"" << _name << "\"";
185               
186 kumpf    1.28     out << " TYPE=\"" << cimTypeToString (_type) << "\"";
187 mike     1.13 
188 kumpf    1.29     if (!_classOrigin.isNull())
189 mike     1.13 	out << " CLASSORIGIN=\"" << _classOrigin << "\"";
190               
191                   if (_propagated != false)
192               	out << " PROPAGATED=\"" << _toString(_propagated) << "\"";
193               
194                   out << ">\n";
195               
196                   _qualifiers.toXml(out);
197               
198                   for (Uint32 i = 0, n = _parameters.size(); i < n; i++)
199 kumpf    1.22 	XmlWriter::appendParameterElement(out, _parameters[i]);
200 mike     1.13 
201                   out << "</METHOD>\n";
202               }
203               
204 mike     1.14 /**
205                   The BNF for this is;
206                   methodDeclaration 	=  [ qualifierList ] dataType methodName
207               			   "(" [ parameterList ] ")" ";"
208               
209                   parameterList 	=  parameter *( "," parameter )
210                   Format with qualifiers on one line and declaration on another. Start
211                   with newline but none at the end.
212               */
213               void CIMMethodRep::toMof(Array<Sint8>& out) const   //ATTNKS:
214               {
215                   // Output the qualifier list starting on new line
216                   if (_qualifiers.getCount())
217               	out << "\n";
218               
219                   _qualifiers.toMof(out);
220               
221                   // output the type,	MethodName and ParmeterList left enclosure
222 kumpf    1.28     out << "\n" << cimTypeToString (_type) << " " << _name << "(";
223 mike     1.14 
224                   // output the param list separated by commas.
225                   
226                   for (Uint32 i = 0, n = _parameters.size(); i < n; i++)
227                   {
228               	// If not first, output comma separator
229               	if (i)
230               	    out << ", ";
231               
232 kumpf    1.23 	MofWriter::appendParameterElement(out, _parameters[i]);
233 mike     1.14     }
234               
235                   // output the parameterlist and method terminator
236                   out << ");";
237               }
238               
239               
240 mike     1.13 CIMMethodRep::CIMMethodRep()
241               {
242               
243               }
244               
245               CIMMethodRep::CIMMethodRep(const CIMMethodRep& x) :
246                   Sharable(),
247                   _name(x._name),
248                   _type(x._type),
249                   _classOrigin(x._classOrigin),
250                   _propagated(x._propagated)
251               {
252                   x._qualifiers.cloneTo(_qualifiers);
253               
254 kumpf    1.26     _parameters.reserveCapacity(x._parameters.size());
255 mike     1.13 
256                   for (Uint32 i = 0, n = x._parameters.size(); i < n; i++)
257               	_parameters.append(x._parameters[i].clone());
258               }
259               
260               Boolean CIMMethodRep::identical(const CIMMethodRep* x) const
261               {
262 kumpf    1.37     if (!_name.equal (x->_name))
263 mike     1.13 	return false;
264               
265                   if (_type != x->_type)
266               	return false;
267               
268                   if (!_qualifiers.identical(x->_qualifiers))
269               	return false;
270               
271                   if (_parameters.size() != x->_parameters.size())
272               	return false;
273               
274                   for (Uint32 i = 0, n = _parameters.size(); i < n; i++)
275                   {
276               	if (!_parameters[i].identical(x->_parameters[i]))
277               	    return false;
278                   }
279               
280                   return true;
281               }
282               
283               void CIMMethodRep::setType(CIMType type)
284 mike     1.13 {
285                   _type = type;
286               }
287               
288               PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2