1 mike 1.9 //%/////////////////////////////////////////////////////////////////////////////
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.9 //
23 // Author: Mike Brasher (mbrasher@bmc.com)
24 //
25 // Modified By:
26 //
27 //%/////////////////////////////////////////////////////////////////////////////
28
|
29 sage 1.11 #include <Pegasus/Common/Config.h>
|
30 mike 1.9 #include <cstdio>
31 #include "CIMParameter.h"
32 #include "Indentor.h"
33 #include "CIMName.h"
34 #include "CIMScope.h"
35 #include "XmlWriter.h"
36
37 PEGASUS_NAMESPACE_BEGIN
38
39 CIMParameterRep::CIMParameterRep(
40 const String& name,
41 CIMType type,
42 Boolean isArray,
43 Uint32 arraySize,
44 const String& referenceClassName)
45 : _name(name), _type(type),
46 _isArray(isArray), _arraySize(arraySize),
47 _referenceClassName(referenceClassName)
48 {
49 if (!CIMName::legal(name))
50 throw IllegalName();
51 mike 1.9
|
52 kumpf 1.13 if (_type == CIMType::NONE)
53 throw NullType();
|
54 mike 1.9
55 if (_arraySize && !_isArray)
56 throw IncompatibleTypes();
57
58 if (referenceClassName.size())
59 {
60 if (!CIMName::legal(referenceClassName))
61 throw IllegalName();
62
63 if (_type != CIMType::REFERENCE)
64 {
65 throw ExpectedReferenceValue();
66 }
67 }
68 else
69 {
70
71 // ATTN: revisit this later!
72 #if 0
73 if (_type == CIMType::REFERENCE)
74 throw MissingReferenceClassName();
75 mike 1.9 #endif
76 }
77 }
78
79 CIMParameterRep::~CIMParameterRep()
80 {
81
82 }
83
84 void CIMParameterRep::setName(const String& name)
85 {
86 if (!CIMName::legal(name))
87 throw IllegalName();
88
89 _name = name;
90 }
91
92 void CIMParameterRep::resolve(
93 DeclContext* declContext,
94 const String& nameSpace)
95 {
96 mike 1.9 // Validate the qualifiers of the method (according to
97 // superClass's method with the same name). This method
98 // will throw an exception if the validation fails.
99
100 CIMQualifierList dummy;
101
102 _qualifiers.resolve(
103 declContext,
104 nameSpace,
105 CIMScope::PARAMETER,
106 false,
|
107 mike 1.14 dummy,
108 true);
|
109 mike 1.9 }
110
111 void CIMParameterRep::toXml(Array<Sint8>& out) const
112 {
113 if (_isArray)
114 {
115 out << "<PARAMETER.ARRAY";
116
117 out << " NAME=\"" << _name << "\" ";
118
119 out << " TYPE=\"" << TypeToString(_type) << "\"";
120
121 if (_arraySize)
122 {
123 char buffer[32];
124 sprintf(buffer, "%d", _arraySize);
125 out << " ARRAYSIZE=\"" << buffer << "\"";
126 }
127
128 out << ">\n";
129
130 mike 1.9 _qualifiers.toXml(out);
131
132 out << "</PARAMETER.ARRAY>\n";
133 }
|
134 mike 1.10 else if (_type == CIMType::REFERENCE)
135 {
136 out << "<PARAMETER.REFERENCE";
137 out << " NAME=\"" << _name << "\" ";
138 out << " REFERENCECLASS=\"" << _referenceClassName << "\"";
139 out << ">\n";
140
141 _qualifiers.toXml(out);
142
143 out << "</PARAMETER.REFERENCE>\n";
144 }
|
145 mike 1.9 else
146 {
147 out << "<PARAMETER";
148 out << " NAME=\"" << _name << "\" ";
149 out << " TYPE=\"" << TypeToString(_type) << "\"";
150 out << ">\n";
151
152 _qualifiers.toXml(out);
153
154 out << "</PARAMETER>\n";
155 }
156 }
|
157 mike 1.10
158 /** toMof - puts the Mof representation of teh Parameter object to
159 the output parameter array
160 The BNF for this conversion is:
161 parameterList = parameter *( "," parameter )
162
163 parameter = [ qualifierList ] (dataType|objectRef) parameterName
164 [ array ]
165
166 parameterName= IDENTIFIER
167
168 array = "[" [positiveDecimalValue] "]"
169
170 Format on a single line.
171 */
172 void CIMParameterRep::toMof(Array<Sint8>& out) const
173 {
174 // Output the qualifiers for the parameter
175 _qualifiers.toMof(out);
176
177 if (_qualifiers.getCount())
178 mike 1.10 out << " ";
179
180 // Output the data type and name
181 out << TypeToString(_type) << " " << _name;
182
183 if (_isArray)
184 {
185 //Output the array indicator "[ [arraysize] ]"
186 if (_arraySize)
187 {
188 char buffer[32];
189 sprintf(buffer, "[%d]", _arraySize);
190 out << buffer;
191 }
192 else
193 out << "[]";
194 }
195 }
196
|
197 mike 1.9
198 void CIMParameterRep::print(PEGASUS_STD(ostream) &os) const
199 {
200 Array<Sint8> tmp;
201 toXml(tmp);
202 tmp.append('\0');
203 os << tmp.getData() << PEGASUS_STD(endl);
204 }
205
206 Boolean CIMParameterRep::identical(const CIMParameterRep* x) const
207 {
208 if (_name != x->_name)
209 return false;
210
211 if (_type != x->_type)
212 return false;
213
214 if (_referenceClassName != x->_referenceClassName)
215 return false;
216
217 if (!_qualifiers.identical(x->_qualifiers))
218 mike 1.9 return false;
219
220 return true;
221 }
222
223 CIMParameterRep::CIMParameterRep()
224 {
225
226 }
227
228 CIMParameterRep::CIMParameterRep(const CIMParameterRep& x) :
229 Sharable(),
230 _name(x._name),
231 _type(x._type),
232 _isArray(x._isArray),
233 _arraySize(x._arraySize),
234 _referenceClassName(x._referenceClassName)
235 {
236 x._qualifiers.cloneTo(_qualifiers);
237 }
238
239 mike 1.9 CIMParameterRep& CIMParameterRep::operator=(const CIMParameterRep& x)
240 {
241 return *this;
242 }
243
244 void CIMParameterRep::setType(CIMType type)
245 {
246 _type = type;
247
248 if (_referenceClassName.size() == 0 && _type == CIMType::REFERENCE)
249 {
250 throw MissingReferenceClassName();
251 }
252 }
253
254 PEGASUS_NAMESPACE_END
|