1 mike 1.13 //%/////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001 The Open group, BMC Software, Tivoli Systems, IBM
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to
7 // deal in the Software without restriction, including without limitation the
8 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 // sell copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
13 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
14 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
15 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
16 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
18 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
19 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 //
21 //==============================================================================
22 mike 1.13 //
23 // Author: Mike Brasher (mbrasher@bmc.com)
24 //
25 // Modified By:
26 //
27 //%/////////////////////////////////////////////////////////////////////////////
28
|
29 sage 1.15 #include <Pegasus/Common/Config.h>
|
30 mike 1.13 #include <cassert>
31 #include "CIMMethod.h"
32 #include "Indentor.h"
33 #include "CIMName.h"
34 #include "CIMScope.h"
35 #include "XmlWriter.h"
36
37 PEGASUS_NAMESPACE_BEGIN
38
39 CIMMethodRep::CIMMethodRep(
40 const String& name,
41 CIMType type,
42 const String& classOrigin,
43 Boolean propagated)
44 : _name(name), _type(type),
45 _classOrigin(classOrigin), _propagated(propagated)
46 {
47 if (!CIMName::legal(name))
48 throw IllegalName();
49
50 if (classOrigin.size() && !CIMName::legal(classOrigin))
51 mike 1.13 throw IllegalName();
52
53 if (type == CIMType::NONE)
54 throw NullType();
55 }
56
57 CIMMethodRep::~CIMMethodRep()
58 {
59
60 }
61
62 void CIMMethodRep::setName(const String& name)
63 {
64 if (!CIMName::legal(name))
65 throw IllegalName();
66
67 _name = name;
68 }
69
70 void CIMMethodRep::setClassOrigin(const String& classOrigin)
71 {
72 mike 1.13 if (!CIMName::legal(classOrigin))
73 throw IllegalName();
74
75 _classOrigin = classOrigin;
76 }
77
78 void CIMMethodRep::addParameter(const CIMParameter& x)
79 {
80 if (!x)
81 throw UnitializedHandle();
82
83 if (findParameter(x.getName()) != PEG_NOT_FOUND)
84 throw AlreadyExists();
85
86 _parameters.append(x);
87 }
88
89 Uint32 CIMMethodRep::findParameter(const String& name)
90 {
91 for (Uint32 i = 0, n = _parameters.size(); i < n; i++)
92 {
93 mike 1.13 if (CIMName::equal(_parameters[i].getName(), name))
94 return i;
95 }
96
97 return PEG_NOT_FOUND;
98 }
99
100 CIMParameter CIMMethodRep::getParameter(Uint32 pos)
101 {
102 if (pos >= _parameters.size())
103 throw OutOfBounds();
104
105 return _parameters[pos];
106 }
107
108 Uint32 CIMMethodRep::getParameterCount() const
109 {
110 return _parameters.size();
111 }
112
113 void CIMMethodRep::resolve(
114 mike 1.13 DeclContext* declContext,
115 const String& nameSpace,
116 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 assert (inheritedMethod);
124
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 _parameters[i].resolve(declContext, nameSpace);
141
142 _classOrigin = inheritedMethod.getClassOrigin();
143 }
144
145 void CIMMethodRep::resolve(
146 DeclContext* declContext,
147 const String& nameSpace)
148 {
149 // Validate the qualifiers:
150
151 CIMQualifierList dummy;
152
153 _qualifiers.resolve(
154 declContext,
155 nameSpace,
156 CIMScope::METHOD,
157 mike 1.13 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 _parameters[i].resolve(declContext, nameSpace);
165 }
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 out << " TYPE=\"" << TypeToString(_type) << "\"";
179
180 if (_classOrigin.size())
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 _parameters[i].toXml(out);
192
193 out << "</METHOD>\n";
194 }
195
196 void CIMMethodRep::print(PEGASUS_STD(ostream) &os) const
197 {
198 Array<Sint8> tmp;
199 toXml(tmp);
200 tmp.append('\0');
201 os << tmp.getData() << PEGASUS_STD(endl);
202 mike 1.13 }
203
|
204 mike 1.14 /**
205 The BNF for this is;
206 methodDeclaration = [ qualifierList ] dataType methodName
207 "(" [ parameterList ] ")" ";"
208
209 parameterList = parameter *( "," parameter )
210 Format with qualifiers on one line and declaration on another. Start
211 with newline but none at the end.
212 */
213 void CIMMethodRep::toMof(Array<Sint8>& out) const //ATTNKS:
214 {
215 // Output the qualifier list starting on new line
216 if (_qualifiers.getCount())
217 out << "\n";
218
219 _qualifiers.toMof(out);
220
221 // output the type, MethodName and ParmeterList left enclosure
222 out << "\n" << TypeToString(_type) << " " << _name << "(";
223
224 // output the param list separated by commas.
225 mike 1.14
226 for (Uint32 i = 0, n = _parameters.size(); i < n; i++)
227 {
228 // If not first, output comma separator
229 if (i)
230 out << ", ";
231
232 _parameters[i].toMof(out);
233 }
234
235 // output the parameterlist and method terminator
236 out << ");";
237 }
238
239
|
240 mike 1.13 CIMMethodRep::CIMMethodRep()
241 {
242
243 }
244
245 CIMMethodRep::CIMMethodRep(const CIMMethodRep& x) :
246 Sharable(),
247 _name(x._name),
248 _type(x._type),
249 _classOrigin(x._classOrigin),
250 _propagated(x._propagated)
251 {
252 x._qualifiers.cloneTo(_qualifiers);
253
254 _parameters.reserve(x._parameters.size());
255
256 for (Uint32 i = 0, n = x._parameters.size(); i < n; i++)
257 _parameters.append(x._parameters[i].clone());
258 }
259
260 Boolean CIMMethodRep::identical(const CIMMethodRep* x) const
261 mike 1.13 {
262 if (_name != x->_name)
263 return false;
264
265 if (_type != x->_type)
266 return false;
267
268 if (!_qualifiers.identical(x->_qualifiers))
269 return false;
270
271 if (_parameters.size() != x->_parameters.size())
272 return false;
273
274 for (Uint32 i = 0, n = _parameters.size(); i < n; i++)
275 {
276 if (!_parameters[i].identical(x->_parameters[i]))
277 return false;
278 }
279
280 return true;
281 }
282 mike 1.13
283 void CIMMethodRep::setType(CIMType type)
284 {
285 _type = type;
286
287 if (type == CIMType::NONE)
288 throw NullType();
289 }
290
291 PEGASUS_NAMESPACE_END
|