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