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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2