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