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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2