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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2