(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            
 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                if (!CIMName::legal(name))
 59            	throw IllegalName();
 60            
 61                if (_value.getType() == CIMType::NONE)
 62            	throw NullType();
 63            }
 64            
 65            CIMQualifierDeclRep::~CIMQualifierDeclRep()
 66            {
 67            
 68            }
 69            
 70 mike  1.11 void CIMQualifierDeclRep::setName(const String& name)
 71 mike  1.10 {
 72                if (!CIMName::legal(name))
 73            	throw IllegalName();
 74            
 75 mike  1.11     _name = name;
 76 mike  1.10 }
 77            
 78            static const char* _toString(Boolean x)
 79            {
 80                return x ? "true" : "false";
 81            }
 82            
 83            void CIMQualifierDeclRep::toXml(Array<Sint8>& out) const
 84            {
 85                out << "<QUALIFIER.DECLARATION";
 86                out << " NAME=\"" << _name << "\"";
 87                out << " TYPE=\"" << TypeToString(_value.getType()) << "\"";
 88            
 89                if (_value.isArray())
 90                {
 91            	out << " ISARRAY=\"true\"";
 92            
 93            	if (_arraySize)
 94            	{
 95            	    char buffer[64];
 96            	    sprintf(buffer, " ARRAYSIZE=\"%d\"", _arraySize);
 97 mike  1.10 	    out << buffer;
 98            	}
 99                }
100            
101                FlavorToXml(out, _flavor);
102            
103                out << ">\n";
104            
105                ScopeToXml(out, _scope);
106            
107                _value.toXml(out);
108            
109                out << "</QUALIFIER.DECLARATION>\n";
110            }
111            
112 mike  1.11 /** toMof - Generate the MOF output for the Qualifier Declaration object.
113 karl  1.12     
114 mike  1.11     The BNF for this output is:
115 karl  1.12     <pre>
116 mike  1.11     qualifierDeclaration   = 	QUALIFIER qualifierName qualifierType scope
117            				[ defaultFlavor ] ";"
118            
119                qualifierName 	   = 	IDENTIFIER
120            
121                qualifierType 	   = 	":" dataType [ array ] [ defaultValue ]
122            
123                scope 		   = 	"," SCOPE "(" metaElement *( "," metaElement )
124                ")"
125 karl  1.12     </pre>
126 mike  1.11 */
127            void CIMQualifierDeclRep::toMof(Array<Sint8>& out) const
128            {
129                out << "\n";
130            
131                // output the "Qualifier" keyword and name
132                out << "Qualfier " << _name;
133            
134                // output the qualifiertype
135                out << " : " << TypeToString(_value.getType());
136            
137                // If array put the Array indicator "[]" and possible size after name.
138                if (_value.isArray())
139                {
140            	if (_arraySize)
141            	{
142            	    char buffer[32];
143            	    sprintf(buffer, "[%d]", _arraySize);
144            	    out << buffer;
145            	}
146            	else
147 mike  1.11 	    out << "[]";
148                }
149            
150                Boolean hasValueField = false;
151 karl  1.12     // KS think through the following test
152                //if (!_value.isNull() || !(_value.getType() == CIMType::BOOLEAN) )
153                //{
154                    // KS With CIM Qualifier, this should be =
155            	out << " =";
156 mike  1.11 	hasValueField = true;
157            	_value.toMof(out);
158 karl  1.12     //}
159 mike  1.11 
160 karl  1.12     // Output Scope Information
161 mike  1.11     String scopeString;
162 karl  1.12     scopeString = ScopeToString(_scope);
163                //if (scopeString.size())
164                //{
165            	out << ", Scope(" << scopeString << ")";
166                //}
167                // Output Flavor Information
168 mike  1.11     String flavorString;
169                flavorString = FlavorToMof(_flavor);
170                if (flavorString.size())
171                {
172 karl  1.12     out << ", Flavor(" << flavorString << ")";
173 mike  1.11     }
174 karl  1.12     // End each qualifier declaration with newline
175 mike  1.11     out << ";\n";
176            }
177            
178            
179 mike  1.10 void CIMQualifierDeclRep::print(PEGASUS_STD(ostream) &os) const
180            {
181                Array<Sint8> tmp;
182                toXml(tmp);
183                tmp.append('\0');
184 mike  1.11     // ATTN:KS 7 Aug 2001 I think the endl should be removed here.
185 mike  1.10     os << tmp.getData() << PEGASUS_STD(endl);
186            }
187            
188            CIMQualifierDeclRep::CIMQualifierDeclRep()
189            {
190            
191            }
192            
193 mike  1.11 CIMQualifierDeclRep::CIMQualifierDeclRep(const CIMQualifierDeclRep& x) :
194 mike  1.10     Sharable(),
195                _name(x._name),
196                _value(x._value),
197                _scope(x._scope),
198                _flavor(x._flavor),
199                _arraySize(x._arraySize)
200            {
201            
202            }
203            
204 mike  1.11 CIMQualifierDeclRep& CIMQualifierDeclRep::operator=(const CIMQualifierDeclRep&
205            x)
206            {
207                return *this;
208 mike  1.10 }
209            
210            Boolean CIMQualifierDeclRep::identical(const CIMQualifierDeclRep* x) const
211            {
212                return
213            	this == x ||
214 mike  1.11 	CIMName::equal(_name, x->_name) &&
215            	_value == x->_value &&
216 mike  1.10 	_scope == x->_scope &&
217            	_flavor == x->_flavor &&
218            	_arraySize == x->_arraySize;
219            }
220            
221 mike  1.11 void CIMQualifierDeclRep::setValue(const CIMValue& value)
222 mike  1.10 {
223 mike  1.11     _value = value;
224 mike  1.10 
225                if (_value.getType() == CIMType::NONE)
226            	throw NullType();
227            }
228            
229            PEGASUS_NAMESPACE_END
230 mike  1.11 

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2