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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2