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