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