(file) Return to CIMQualifierDeclRep.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

  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            #include "Indentor.h"
 32            #include "DeclContext.h"
 33            #include "CIMName.h"
 34            #include "Exception.h"
 35            #include "XmlWriter.h"
 36            
 37            PEGASUS_NAMESPACE_BEGIN
 38 karl  1.15 PEGASUS_USING_STD;
 39 mike  1.10 ////////////////////////////////////////////////////////////////////////////////
 40            //
 41            // CIMQualifierDeclRep
 42            //
 43            ////////////////////////////////////////////////////////////////////////////////
 44            
 45            CIMQualifierDeclRep::CIMQualifierDeclRep(
 46 mike  1.11     const String& name,
 47                const CIMValue& value,
 48 mike  1.10     Uint32 scope,
 49                Uint32 flavor,
 50                Uint32 arraySize)
 51 mike  1.11     :
 52                _name(name),
 53                _value(value),
 54 mike  1.10     _scope(scope),
 55                _flavor(flavor),
 56                _arraySize(arraySize)
 57            {
 58 karl  1.15     //cout << "KSTEST Qualifier Declflavor " << flavor << endl;
 59 mike  1.10     if (!CIMName::legal(name))
 60            	throw IllegalName();
 61            
 62                if (_value.getType() == CIMType::NONE)
 63            	throw NullType();
 64 karl  1.17 
 65            	// Set the flavor defaults. Must actively set them in case input flavor
 66            	// sets some but not all the defaults.	Also Make sure no conflicts. This covers
 67            	// the fact that we have separate flags for on and off for the toelement
 68            	// and override functions. Something must be set on creation and the
 69            	// default in the .h file only covers the case where there is no input.
 70            	// This also assures that there are no conflicts. Note that it favors
 71            	// restricted and disable override
 72            	//ATTN: This should become an exception in case conflicting entities are set.
 73            	if((_flavor & CIMFlavor::RESTRICTED) == 0)
 74            		_flavor |= ( CIMFlavor::DEFAULTS);
 75            	else
 76            		_flavor &= ~( CIMFlavor::DEFAULTS);
 77            
 78            	if((_flavor & CIMFlavor::DISABLEOVERRIDE) == 0)
 79            		_flavor |= ( CIMFlavor::ENABLEOVERRIDE);
 80            	else
 81            		_flavor &= ~( CIMFlavor::ENABLEOVERRIDE);
 82            
 83 mike  1.10 }
 84            
 85            CIMQualifierDeclRep::~CIMQualifierDeclRep()
 86            {
 87            
 88            }
 89            
 90 mike  1.11 void CIMQualifierDeclRep::setName(const String& name)
 91 mike  1.10 {
 92                if (!CIMName::legal(name))
 93            	throw IllegalName();
 94            
 95 mike  1.11     _name = name;
 96 mike  1.10 }
 97            
 98            static const char* _toString(Boolean x)
 99            {
100                return x ? "true" : "false";
101            }
102            
103            void CIMQualifierDeclRep::toXml(Array<Sint8>& out) const
104            {
105                out << "<QUALIFIER.DECLARATION";
106                out << " NAME=\"" << _name << "\"";
107                out << " TYPE=\"" << TypeToString(_value.getType()) << "\"";
108            
109                if (_value.isArray())
110                {
111            	out << " ISARRAY=\"true\"";
112            
113            	if (_arraySize)
114            	{
115            	    char buffer[64];
116            	    sprintf(buffer, " ARRAYSIZE=\"%d\"", _arraySize);
117 mike  1.10 	    out << buffer;
118            	}
119                }
120            
121                FlavorToXml(out, _flavor);
122            
123                out << ">\n";
124            
125                ScopeToXml(out, _scope);
126 karl  1.14     /*KSTESTNULL - Put the XML out with no VALUE tags if Null*/
127                _value.toXml(out, false);
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                out << "Qualfier " << _name;
153            
154                // output the qualifiertype
155                out << " : " << TypeToString(_value.getType());
156            
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 mike  1.11 	    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            	_value.toMof(out);
178 karl  1.12     //}
179 mike  1.11 
180 karl  1.12     // Output Scope Information
181 mike  1.11     String scopeString;
182 karl  1.13     scopeString = ScopeToMofString(_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                flavorString = FlavorToMof(_flavor);
190                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            }
197            
198            
199 mike  1.10 void CIMQualifierDeclRep::print(PEGASUS_STD(ostream) &os) const
200            {
201                Array<Sint8> tmp;
202                toXml(tmp);
203                tmp.append('\0');
204                os << tmp.getData() << PEGASUS_STD(endl);
205            }
206 karl  1.16 
207            void CIMQualifierDeclRep::printMof(PEGASUS_STD(ostream) &os) const
208            {
209                Array<Sint8> tmp;
210                toMof(tmp);
211                tmp.append('\0');
212                os << tmp.getData() << PEGASUS_STD(endl);
213            }
214            
215 mike  1.10 
216            CIMQualifierDeclRep::CIMQualifierDeclRep()
217            {
218            
219            }
220            
221 mike  1.11 CIMQualifierDeclRep::CIMQualifierDeclRep(const CIMQualifierDeclRep& x) :
222 mike  1.10     Sharable(),
223                _name(x._name),
224                _value(x._value),
225                _scope(x._scope),
226                _flavor(x._flavor),
227                _arraySize(x._arraySize)
228            {
229            
230            }
231            
232 mike  1.11 CIMQualifierDeclRep& CIMQualifierDeclRep::operator=(const CIMQualifierDeclRep&
233            x)
234            {
235                return *this;
236 mike  1.10 }
237            
238            Boolean CIMQualifierDeclRep::identical(const CIMQualifierDeclRep* x) const
239            {
240                return
241            	this == x ||
242 mike  1.11 	CIMName::equal(_name, x->_name) &&
243            	_value == x->_value &&
244 mike  1.10 	_scope == x->_scope &&
245            	_flavor == x->_flavor &&
246            	_arraySize == x->_arraySize;
247            }
248            
249 mike  1.11 void CIMQualifierDeclRep::setValue(const CIMValue& value)
250 mike  1.10 {
251 mike  1.11     _value = value;
252 mike  1.10 
253                if (_value.getType() == CIMType::NONE)
254            	throw NullType();
255            }
256            
257            PEGASUS_NAMESPACE_END
258 mike  1.11 

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2