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 #include <cassert>
30 #include "CIMMethod.h"
31 #include "Indentor.h"
32 #include "CIMName.h"
33 #include "CIMScope.h"
34 #include "XmlWriter.h"
35
36 PEGASUS_NAMESPACE_BEGIN
37
38 CIMMethodRep::CIMMethodRep(
39 const String& name,
40 CIMType type,
41 const String& classOrigin,
42 Boolean propagated)
43 mike 1.13 : _name(name), _type(type),
44 _classOrigin(classOrigin), _propagated(propagated)
45 {
46 if (!CIMName::legal(name))
47 throw IllegalName();
48
49 if (classOrigin.size() && !CIMName::legal(classOrigin))
50 throw IllegalName();
51
52 if (type == CIMType::NONE)
53 throw NullType();
54 }
55
56 CIMMethodRep::~CIMMethodRep()
57 {
58
59 }
60
61 void CIMMethodRep::setName(const String& name)
62 {
63 if (!CIMName::legal(name))
64 mike 1.13 throw IllegalName();
65
66 _name = name;
67 }
68
69 void CIMMethodRep::setClassOrigin(const String& classOrigin)
70 {
71 if (!CIMName::legal(classOrigin))
72 throw IllegalName();
73
74 _classOrigin = classOrigin;
75 }
76
77 void CIMMethodRep::addParameter(const CIMParameter& x)
78 {
79 if (!x)
80 throw UnitializedHandle();
81
82 if (findParameter(x.getName()) != PEG_NOT_FOUND)
83 throw AlreadyExists();
84
85 mike 1.13 _parameters.append(x);
86 }
87
88 Uint32 CIMMethodRep::findParameter(const String& name)
89 {
90 for (Uint32 i = 0, n = _parameters.size(); i < n; i++)
91 {
92 if (CIMName::equal(_parameters[i].getName(), name))
93 return i;
94 }
95
96 return PEG_NOT_FOUND;
97 }
98
99 CIMParameter CIMMethodRep::getParameter(Uint32 pos)
100 {
101 if (pos >= _parameters.size())
102 throw OutOfBounds();
103
104 return _parameters[pos];
105 }
106 mike 1.13
107 Uint32 CIMMethodRep::getParameterCount() const
108 {
109 return _parameters.size();
110 }
111
112 void CIMMethodRep::resolve(
113 DeclContext* declContext,
114 const String& nameSpace,
115 const CIMConstMethod& inheritedMethod)
116 {
117 // ATTN: Check to see if this method has same signature as
118 // inherited one.
119
120 // Check for type mismatch between return types.
121
122 assert (inheritedMethod);
123
124 // Validate the qualifiers of the method (according to
125 // superClass's method with the same name). This method
126 // will throw an exception if the validation fails.
127 mike 1.13
128 _qualifiers.resolve(
129 declContext,
130 nameSpace,
131 CIMScope::METHOD,
132 false,
133 inheritedMethod._rep->_qualifiers);
134
135 // Validate each of the parameters:
136
137 for (size_t i = 0; i < _parameters.size(); i++)
138 _parameters[i].resolve(declContext, nameSpace);
139
140 _classOrigin = inheritedMethod.getClassOrigin();
141 }
142
143 void CIMMethodRep::resolve(
144 DeclContext* declContext,
145 const String& nameSpace)
146 {
147 // Validate the qualifiers:
148 mike 1.13
149 CIMQualifierList dummy;
150
151 _qualifiers.resolve(
152 declContext,
153 nameSpace,
154 CIMScope::METHOD,
155 false,
156 dummy);
157
158 // Validate each of the parameters:
159
160 for (size_t i = 0; i < _parameters.size(); i++)
161 _parameters[i].resolve(declContext, nameSpace);
162 }
163
164 static const char* _toString(Boolean x)
165 {
166 return x ? "true" : "false";
167 }
168
169 mike 1.13 void CIMMethodRep::toXml(Array<Sint8>& out) const
170 {
171 out << "<METHOD";
172
173 out << " NAME=\"" << _name << "\"";
174
175 out << " TYPE=\"" << TypeToString(_type) << "\"";
176
177 if (_classOrigin.size())
178 out << " CLASSORIGIN=\"" << _classOrigin << "\"";
179
180 if (_propagated != false)
181 out << " PROPAGATED=\"" << _toString(_propagated) << "\"";
182
183 out << ">\n";
184
185 _qualifiers.toXml(out);
186
187 for (Uint32 i = 0, n = _parameters.size(); i < n; i++)
188 _parameters[i].toXml(out);
189
190 mike 1.13 out << "</METHOD>\n";
191 }
192
193 void CIMMethodRep::print(PEGASUS_STD(ostream) &os) const
194 {
195 Array<Sint8> tmp;
196 toXml(tmp);
197 tmp.append('\0');
198 os << tmp.getData() << PEGASUS_STD(endl);
199 }
200
|
236 mike 1.13 CIMMethodRep::CIMMethodRep()
237 {
238
239 }
240
241 CIMMethodRep::CIMMethodRep(const CIMMethodRep& x) :
242 Sharable(),
243 _name(x._name),
244 _type(x._type),
245 _classOrigin(x._classOrigin),
246 _propagated(x._propagated)
247 {
248 x._qualifiers.cloneTo(_qualifiers);
249
250 _parameters.reserve(x._parameters.size());
251
252 for (Uint32 i = 0, n = x._parameters.size(); i < n; i++)
253 _parameters.append(x._parameters[i].clone());
254 }
255
256 CIMMethodRep& CIMMethodRep::operator=(const CIMMethodRep& x)
257 mike 1.13 {
258 return *this;
259 }
260
261 Boolean CIMMethodRep::identical(const CIMMethodRep* x) const
262 {
263 if (_name != x->_name)
264 return false;
265
266 if (_type != x->_type)
267 return false;
268
269 if (!_qualifiers.identical(x->_qualifiers))
270 return false;
271
272 if (_parameters.size() != x->_parameters.size())
273 return false;
274
275 for (Uint32 i = 0, n = _parameters.size(); i < n; i++)
276 {
277 if (!_parameters[i].identical(x->_parameters[i]))
278 mike 1.13 return false;
279 }
280
281 return true;
282 }
283
284 void CIMMethodRep::setType(CIMType type)
285 {
286 _type = type;
287
288 if (type == CIMType::NONE)
289 throw NullType();
290 }
291
292 PEGASUS_NAMESPACE_END
|