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