1 mike 1.5 //%/////////////////////////////////////////////////////////////////////////////
|
2 mike 1.1 //
3 // Copyright (c) 2000 The Open Group, BMC Software, Tivoli Systems, IBM
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a
6 // copy of this software and associated documentation files (the "Software"),
7 // to deal in the Software without restriction, including without limitation
8 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 // and/or sell copies of the Software, and to permit persons to whom the
10 // Software is furnished to do so, subject to the following conditions:
11 //
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
15 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18 // DEALINGS IN THE SOFTWARE.
19 //
|
20 mike 1.5 //==============================================================================
|
21 mike 1.1 //
|
22 mike 1.5 // Author: Mike Brasher (mbrasher@bmc.com)
|
23 mike 1.1 //
|
24 mike 1.5 // Modified By:
|
25 bob 1.3 //
|
26 mike 1.5 //%/////////////////////////////////////////////////////////////////////////////
|
27 mike 1.1
28 #include <cassert>
29 #include "CIMMethod.h"
30 #include "Indentor.h"
31 #include "CIMName.h"
32 #include "CIMScope.h"
33 #include "XmlWriter.h"
34
35 PEGASUS_NAMESPACE_BEGIN
36
37 CIMMethodRep::CIMMethodRep(
38 const String& name,
39 CIMType type,
40 const String& classOrigin,
41 Boolean propagated)
42 : _name(name), _type(type),
43 _classOrigin(classOrigin), _propagated(propagated)
44 {
45 if (!CIMName::legal(name))
46 throw IllegalName();
47
|
48 mike 1.6 if (classOrigin.size() && !CIMName::legal(classOrigin))
|
49 mike 1.1 throw IllegalName();
50
51 if (type == CIMType::NONE)
52 throw NullType();
53 }
54
55 CIMMethodRep::~CIMMethodRep()
56 {
57
58 }
59
60 void CIMMethodRep::setName(const String& name)
61 {
62 if (!CIMName::legal(name))
63 throw IllegalName();
64
65 _name = name;
66 }
67
68 void CIMMethodRep::setClassOrigin(const String& classOrigin)
69 {
70 mike 1.1 if (!CIMName::legal(classOrigin))
71 throw IllegalName();
72
73 _classOrigin = classOrigin;
74 }
75
76 void CIMMethodRep::addParameter(const CIMParameter& x)
77 {
78 if (!x)
79 throw UnitializedHandle();
80
81 if (findParameter(x.getName()) != Uint32(-1))
82 throw AlreadyExists();
83
84 _parameters.append(x);
85 }
86
87 Uint32 CIMMethodRep::findParameter(const String& name)
88 {
|
89 mike 1.6 for (Uint32 i = 0, n = _parameters.size(); i < n; i++)
|
90 mike 1.1 {
91 if (CIMName::equal(_parameters[i].getName(), name))
92 return i;
93 }
94
95 return Uint32(-1);
96 }
97
98 CIMParameter CIMMethodRep::getParameter(Uint32 pos)
99 {
|
100 mike 1.6 if (pos >= _parameters.size())
|
101 mike 1.1 throw OutOfBounds();
102
103 return _parameters[pos];
104 }
105
106 Uint32 CIMMethodRep::getParameterCount() const
107 {
|
108 mike 1.6 return _parameters.size();
|
109 mike 1.1 }
110
111 void CIMMethodRep::resolve(
112 DeclContext* declContext,
113 const String& nameSpace,
114 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 assert (inheritedMethod);
122
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 mike 1.1 CIMScope::METHOD,
131 false,
132 inheritedMethod._rep->_qualifiers);
133
134 // Validate each of the parameters:
135
|
136 mike 1.6 for (size_t i = 0; i < _parameters.size(); i++)
|
137 mike 1.1 _parameters[i].resolve(declContext, nameSpace);
138
139 _classOrigin = inheritedMethod.getClassOrigin();
140 }
141
142 void CIMMethodRep::resolve(
143 DeclContext* declContext,
144 const String& nameSpace)
145 {
146 // Validate the qualifiers:
147
148 CIMQualifierList dummy;
149
150 _qualifiers.resolve(
151 declContext,
152 nameSpace,
153 CIMScope::METHOD,
154 false,
155 dummy);
156
157 // Validate each of the parameters:
158 mike 1.1
|
159 mike 1.6 for (size_t i = 0; i < _parameters.size(); i++)
|
160 mike 1.1 _parameters[i].resolve(declContext, nameSpace);
161 }
162
163 static const char* _toString(Boolean x)
164 {
165 return x ? "true" : "false";
166 }
167
168 void CIMMethodRep::toXml(Array<Sint8>& out) const
169 {
170 out << "<METHOD";
171
172 out << " NAME=\"" << _name << "\"";
173
174 out << " TYPE=\"" << TypeToString(_type) << "\"";
175
|
176 mike 1.6 if (_classOrigin.size())
|
177 mike 1.1 out << " CLASSORIGIN=\"" << _classOrigin << "\"";
178
179 if (_propagated != false)
180 out << " PROPAGATED=\"" << _toString(_propagated) << "\"";
181
182 out << ">\n";
183
184 _qualifiers.toXml(out);
185
|
186 mike 1.6 for (Uint32 i = 0, n = _parameters.size(); i < n; i++)
|
187 mike 1.1 _parameters[i].toXml(out);
188
189 out << "</METHOD>\n";
190 }
191
|
192 bob 1.3 void CIMMethodRep::print(std::ostream &os) const
|
193 mike 1.1 {
194 Array<Sint8> tmp;
195 toXml(tmp);
196 tmp.append('\0');
|
197 bob 1.3 os << tmp.getData() << std::endl;
|
198 mike 1.1 }
199
200 CIMMethodRep::CIMMethodRep()
201 {
202
203 }
204
205 CIMMethodRep::CIMMethodRep(const CIMMethodRep& x) :
206 Sharable(),
207 _name(x._name),
208 _type(x._type),
209 _classOrigin(x._classOrigin),
210 _propagated(x._propagated)
211 {
212 x._qualifiers.cloneTo(_qualifiers);
213
|
214 mike 1.6 _parameters.reserve(x._parameters.size());
|
215 mike 1.1
|
216 mike 1.6 for (Uint32 i = 0, n = x._parameters.size(); i < n; i++)
|
217 mike 1.1 _parameters.append(x._parameters[i].clone());
218 }
219
220 CIMMethodRep& CIMMethodRep::operator=(const CIMMethodRep& x)
221 {
222 return *this;
223 }
224
225 Boolean CIMMethodRep::identical(const CIMMethodRep* x) const
226 {
227 if (_name != x->_name)
228 return false;
229
230 if (_type != x->_type)
231 return false;
232
233 if (!_qualifiers.identical(x->_qualifiers))
234 return false;
235
|
236 mike 1.6 if (_parameters.size() != x->_parameters.size())
|
237 mike 1.1 return false;
238
|
239 mike 1.6 for (Uint32 i = 0, n = _parameters.size(); i < n; i++)
|
240 mike 1.1 {
241 if (!_parameters[i].identical(x->_parameters[i]))
242 return false;
243 }
244
245 return true;
246 }
247
|
248 mike 1.7 void CIMMethodRep::setType(CIMType type)
249 {
250 _type = type;
251
252 if (type == CIMType::NONE)
253 throw NullType();
254 }
255
|
256 mike 1.1 PEGASUS_NAMESPACE_END
|