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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2