1 mike 1.10 //%/////////////////////////////////////////////////////////////////////////////
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 mike 1.11 // 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 mike 1.10 // 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 mike 1.11 //
12 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
13 mike 1.10 // 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 mike 1.11 // 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 mike 1.10 // 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 //
23 // Author: Mike Brasher (mbrasher@bmc.com)
24 //
25 // Modified By:
26 //
27 //%/////////////////////////////////////////////////////////////////////////////
28
29 #include <cstdio>
30 #include "CIMQualifierDecl.h"
|
31 kumpf 1.19 #include "CIMQualifierDeclRep.h"
|
32 mike 1.10 #include "Indentor.h"
33 #include "CIMName.h"
34 #include "Exception.h"
35 #include "XmlWriter.h"
|
36 kumpf 1.25 #include "MofWriter.h"
|
37 mike 1.10
38 PEGASUS_NAMESPACE_BEGIN
|
39 karl 1.15 PEGASUS_USING_STD;
|
40 mike 1.10 ////////////////////////////////////////////////////////////////////////////////
41 //
42 // CIMQualifierDeclRep
43 //
44 ////////////////////////////////////////////////////////////////////////////////
45
46 CIMQualifierDeclRep::CIMQualifierDeclRep(
|
47 mike 1.11 const String& name,
48 const CIMValue& value,
|
49 mike 1.10 Uint32 scope,
50 Uint32 flavor,
51 Uint32 arraySize)
|
52 mike 1.11 :
53 _name(name),
54 _value(value),
|
55 mike 1.10 _scope(scope),
56 _flavor(flavor),
57 _arraySize(arraySize)
58 {
|
59 karl 1.15 //cout << "KSTEST Qualifier Declflavor " << flavor << endl;
|
60 mike 1.10 if (!CIMName::legal(name))
61 throw IllegalName();
62
63 if (_value.getType() == CIMType::NONE)
64 throw NullType();
|
65 karl 1.17
66 // Set the flavor defaults. Must actively set them in case input flavor
67 // sets some but not all the defaults. Also Make sure no conflicts. This covers
68 // the fact that we have separate flags for on and off for the toelement
69 // and override functions. Something must be set on creation and the
70 // default in the .h file only covers the case where there is no input.
71 // This also assures that there are no conflicts. Note that it favors
72 // restricted and disable override
73 //ATTN: This should become an exception in case conflicting entities are set.
74 if((_flavor & CIMFlavor::RESTRICTED) == 0)
75 _flavor |= ( CIMFlavor::DEFAULTS);
76 else
77 _flavor &= ~( CIMFlavor::DEFAULTS);
78
79 if((_flavor & CIMFlavor::DISABLEOVERRIDE) == 0)
80 _flavor |= ( CIMFlavor::ENABLEOVERRIDE);
81 else
82 _flavor &= ~( CIMFlavor::ENABLEOVERRIDE);
83
|
84 mike 1.10 }
85
86 CIMQualifierDeclRep::~CIMQualifierDeclRep()
87 {
88
89 }
90
|
91 mike 1.11 void CIMQualifierDeclRep::setName(const String& name)
|
92 mike 1.10 {
93 if (!CIMName::legal(name))
94 throw IllegalName();
95
|
96 mike 1.11 _name = name;
|
97 mike 1.10 }
98
99 static const char* _toString(Boolean x)
100 {
101 return x ? "true" : "false";
102 }
103
104 void CIMQualifierDeclRep::toXml(Array<Sint8>& out) const
105 {
106 out << "<QUALIFIER.DECLARATION";
107 out << " NAME=\"" << _name << "\"";
|
108 kumpf 1.22 out << " TYPE=\"" << _value.getType().toString() << "\"";
|
109 mike 1.10
110 if (_value.isArray())
111 {
112 out << " ISARRAY=\"true\"";
113
114 if (_arraySize)
115 {
116 char buffer[64];
117 sprintf(buffer, " ARRAYSIZE=\"%d\"", _arraySize);
118 out << buffer;
119 }
120 }
121
|
122 kumpf 1.26 XmlWriter::appendQualifierFlavorEntity(out, _flavor);
|
123 mike 1.10
124 out << ">\n";
125
|
126 kumpf 1.27 XmlWriter::appendScopeElement(out, _scope);
|
127 kumpf 1.23 XmlWriter::appendValueElement(out, _value);
|
128 mike 1.10
129 out << "</QUALIFIER.DECLARATION>\n";
130 }
131
|
132 mike 1.11 /** toMof - Generate the MOF output for the Qualifier Declaration object.
|
133 karl 1.12
|
134 mike 1.11 The BNF for this output is:
|
135 karl 1.12 <pre>
|
136 mike 1.11 qualifierDeclaration = QUALIFIER qualifierName qualifierType scope
137 [ defaultFlavor ] ";"
138
139 qualifierName = IDENTIFIER
140
141 qualifierType = ":" dataType [ array ] [ defaultValue ]
142
143 scope = "," SCOPE "(" metaElement *( "," metaElement )
144 ")"
|
145 karl 1.12 </pre>
|
146 mike 1.11 */
147 void CIMQualifierDeclRep::toMof(Array<Sint8>& out) const
148 {
149 out << "\n";
150
151 // output the "Qualifier" keyword and name
|
152 kumpf 1.25 out << "Qualifier " << _name;
|
153 mike 1.11
154 // output the qualifiertype
|
155 kumpf 1.22 out << " : " << _value.getType().toString();
|
156 mike 1.11
157 // If array put the Array indicator "[]" and possible size after name.
158 if (_value.isArray())
159 {
160 if (_arraySize)
161 {
162 char buffer[32];
163 sprintf(buffer, "[%d]", _arraySize);
164 out << buffer;
165 }
166 else
167 out << "[]";
168 }
169
170 Boolean hasValueField = false;
|
171 karl 1.12 // KS think through the following test
172 //if (!_value.isNull() || !(_value.getType() == CIMType::BOOLEAN) )
173 //{
174 // KS With CIM Qualifier, this should be =
|
175 karl 1.13 out << " = ";
|
176 mike 1.11 hasValueField = true;
|
177 kumpf 1.25 MofWriter::appendValueElement(out, _value);
|
178 karl 1.12 //}
|
179 mike 1.11
|
180 karl 1.12 // Output Scope Information
|
181 mike 1.11 String scopeString;
|
182 kumpf 1.27 scopeString = MofWriter::getQualifierScope(_scope);
|
183 karl 1.12 //if (scopeString.size())
184 //{
185 out << ", Scope(" << scopeString << ")";
186 //}
187 // Output Flavor Information
|
188 mike 1.11 String flavorString;
|
189 kumpf 1.26 flavorString = MofWriter::getQualifierFlavor(_flavor);
|
190 mike 1.11 if (flavorString.size())
191 {
|
192 karl 1.12 out << ", Flavor(" << flavorString << ")";
|
193 mike 1.11 }
|
194 karl 1.12 // End each qualifier declaration with newline
|
195 mike 1.11 out << ";\n";
|
196 karl 1.16 }
197
|
198 mike 1.10
199 CIMQualifierDeclRep::CIMQualifierDeclRep()
200 {
201
202 }
203
|
204 mike 1.11 CIMQualifierDeclRep::CIMQualifierDeclRep(const CIMQualifierDeclRep& x) :
|
205 mike 1.10 Sharable(),
206 _name(x._name),
207 _value(x._value),
208 _scope(x._scope),
209 _flavor(x._flavor),
210 _arraySize(x._arraySize)
211 {
212
213 }
214
215 Boolean CIMQualifierDeclRep::identical(const CIMQualifierDeclRep* x) const
216 {
217 return
218 this == x ||
|
219 mike 1.11 CIMName::equal(_name, x->_name) &&
220 _value == x->_value &&
|
221 mike 1.10 _scope == x->_scope &&
222 _flavor == x->_flavor &&
223 _arraySize == x->_arraySize;
224 }
225
|
226 mike 1.11 void CIMQualifierDeclRep::setValue(const CIMValue& value)
|
227 mike 1.10 {
|
228 mike 1.11 _value = value;
|
229 mike 1.10
230 if (_value.getType() == CIMType::NONE)
231 throw NullType();
232 }
233
234 PEGASUS_NAMESPACE_END
|
235 mike 1.11
|