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