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