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

  1 karl  1.39 //%2006////////////////////////////////////////////////////////////////////////
  2 mike  1.9  //
  3 karl  1.33 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
  4            // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
  5            // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
  6 karl  1.29 // IBM Corp.; EMC Corporation, The Open Group.
  7 karl  1.33 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  8            // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
  9 karl  1.35 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10            // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11 karl  1.39 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 12            // EMC Corporation; Symantec Corporation; The Open Group.
 13 mike  1.9  //
 14            // Permission is hereby granted, free of charge, to any person obtaining a copy
 15 kumpf 1.19 // of this software and associated documentation files (the "Software"), to
 16            // deal in the Software without restriction, including without limitation the
 17            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 18 mike  1.9  // sell copies of the Software, and to permit persons to whom the Software is
 19            // furnished to do so, subject to the following conditions:
 20 karl  1.39 // 
 21 kumpf 1.19 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 22 mike  1.9  // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 23            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 24 kumpf 1.19 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 25            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 26            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 27 mike  1.9  // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 28            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 29            //
 30            //==============================================================================
 31            //
 32            //%/////////////////////////////////////////////////////////////////////////////
 33            
 34 sage  1.11 #include <Pegasus/Common/Config.h>
 35 mike  1.9  #include <cstdio>
 36            #include "CIMParameter.h"
 37 kumpf 1.16 #include "CIMParameterRep.h"
 38 mike  1.9  #include "CIMName.h"
 39            #include "CIMScope.h"
 40            #include "XmlWriter.h"
 41 mike  1.38 #include "StrLit.h"
 42 mike  1.9  
 43            PEGASUS_NAMESPACE_BEGIN
 44            
 45 chip  1.36 CIMParameterRep::CIMParameterRep(const CIMParameterRep& x) :
 46                Sharable(),
 47                _name(x._name),
 48                _type(x._type),
 49                _isArray(x._isArray),
 50                _arraySize(x._arraySize),
 51 marek 1.44     _referenceClassName(x._referenceClassName),
 52                _ownerCount(0)
 53 chip  1.36 {
 54                x._qualifiers.cloneTo(_qualifiers);
 55 marek 1.44     // Set the CIM name tag.
 56                _nameTag = generateCIMNameTag(_name);
 57 chip  1.36 }
 58            
 59 mike  1.9  CIMParameterRep::CIMParameterRep(
 60 chip  1.36     const CIMName& name,
 61 mike  1.9      CIMType type,
 62                Boolean isArray,
 63                Uint32 arraySize,
 64 chip  1.36     const CIMName& referenceClassName)
 65                : _name(name), _type(type),
 66                _isArray(isArray), _arraySize(arraySize),
 67 marek 1.44     _referenceClassName(referenceClassName),
 68                _ownerCount(0)
 69            {    
 70 chip  1.36     // ensure name is not null
 71 kumpf 1.41     if (name.isNull())
 72 chip  1.36     {
 73                    throw UninitializedObjectException();
 74                }
 75 marek 1.44     // Set the CIM name tag.
 76                _nameTag = generateCIMNameTag(_name);
 77 chip  1.36 
 78 kumpf 1.41     if ((_arraySize != 0) && !_isArray)
 79 chip  1.36     {
 80                    throw TypeMismatchException();
 81                }
 82 mike  1.9  
 83 kumpf 1.21     if (!referenceClassName.isNull())
 84 mike  1.9      {
 85 chip  1.36         if (_type != CIMTYPE_REFERENCE)
 86                    {
 87                        throw TypeMismatchException();
 88                    }
 89 mike  1.9      }
 90                else
 91                {
 92 chip  1.36         if (_type == CIMTYPE_REFERENCE)
 93                    {
 94                        throw TypeMismatchException();
 95                    }
 96 mike  1.9      }
 97            }
 98            
 99            CIMParameterRep::~CIMParameterRep()
100            {
101            }
102            
103 chip  1.36 void CIMParameterRep::setName(const CIMName& name)
104 mike  1.9  {
105 chip  1.36     // ensure name is not null
106 kumpf 1.41     if (name.isNull())
107 chip  1.36     {
108                    throw UninitializedObjectException();
109                }
110 marek 1.44     if (_ownerCount != 0 && _name != name)
111                {
112                    MessageLoaderParms parms(
113                        "Common.CIMParameterRep.CONTAINED_PARAMETER_NAMECHANGEDEXCEPTION",
114                        "Attempted to change the name of a parameter"
115                            " already in a container.");
116                    throw Exception(parms);
117                }
118                _name = name;    
119                // Set the CIM name tag.
120                _nameTag = generateCIMNameTag(_name);
121 mike  1.9  }
122            
123 kumpf 1.26 void CIMParameterRep::removeQualifier(Uint32 index)
124 kumpf 1.23 {
125 kumpf 1.26     if (index >= _qualifiers.getCount())
126 kumpf 1.24         throw IndexOutOfBoundsException();
127 kumpf 1.23 
128 kumpf 1.26     _qualifiers.removeQualifier (index);
129 kumpf 1.23 }
130            
131 mike  1.9  void CIMParameterRep::resolve(
132                DeclContext* declContext,
133 kumpf 1.21     const CIMNamespaceName& nameSpace)
134 mike  1.9  {
135                // Validate the qualifiers of the method (according to
136                // superClass's method with the same name). This method
137                // will throw an exception if the validation fails.
138            
139                CIMQualifierList dummy;
140            
141                _qualifiers.resolve(
142 kumpf 1.40         declContext,
143                    nameSpace,
144                    CIMScope::PARAMETER,
145                    false,
146                    dummy,
147                    true);
148 mike  1.9  }
149            
150 mike  1.37 void CIMParameterRep::toXml(Buffer& out) const
151 mike  1.9  {
152                if (_isArray)
153                {
154 kumpf 1.30         if (_type == CIMTYPE_REFERENCE)
155                    {
156 mike  1.38             out << STRLIT("<PARAMETER.REFARRAY NAME=\"") << _name;
157 kumpf 1.40             out.append('"');
158 kumpf 1.30 
159                        if (!_referenceClassName.isNull())
160                        {
161 mike  1.38                 out << STRLIT(" REFERENCECLASS=\"");
162 kumpf 1.40                 out << _referenceClassName.getString();
163                            out.append('"');
164 kumpf 1.30             }
165            
166 kumpf 1.40             if (_arraySize)
167 h.sterling 1.32             {
168                                 char buffer[32];
169 mike       1.38                 int n = sprintf(buffer, "%d", _arraySize);
170                                 out << STRLIT(" ARRAYSIZE=\"");
171 kumpf      1.40                 out.append(buffer, n);
172                                 out.append('"');
173 h.sterling 1.32             }
174                 
175 mike       1.38             out << STRLIT(">\n");
176 kumpf      1.30 
177                             _qualifiers.toXml(out);
178                 
179 mike       1.38             out << STRLIT("</PARAMETER.REFARRAY>\n");
180 kumpf      1.30         }
181                         else
182                         {
183 mike       1.38             out << STRLIT("<PARAMETER.ARRAY");
184                             out << STRLIT(" NAME=\"") << _name;
185 kumpf      1.40             out << STRLIT("\" ");
186 mike       1.38             out << STRLIT(" TYPE=\"") << cimTypeToString(_type);
187 kumpf      1.40             out.append('"');
188 kumpf      1.30 
189                             if (_arraySize)
190                             {
191                                 char buffer[32];
192                                 sprintf(buffer, "%d", _arraySize);
193 mike       1.38                 out << STRLIT(" ARRAYSIZE=\"") << buffer;
194 kumpf      1.40                 out.append('"');
195 kumpf      1.30             }
196 mike       1.9  
197 mike       1.38             out << STRLIT(">\n");
198 mike       1.9  
199 kumpf      1.30             _qualifiers.toXml(out);
200 mike       1.9  
201 mike       1.38             out << STRLIT("</PARAMETER.ARRAY>\n");
202 kumpf      1.30         }
203 mike       1.9      }
204 kumpf      1.20     else if (_type == CIMTYPE_REFERENCE)
205 mike       1.10     {
206 kumpf      1.40         out << STRLIT("<PARAMETER.REFERENCE");
207                         out << STRLIT(" NAME=\"") << _name;
208                         out.append('"');
209 mike       1.38 
210 kumpf      1.30         if (!_referenceClassName.isNull())
211                         {
212 kumpf      1.40             out << STRLIT(" REFERENCECLASS=\"");
213                             out << _referenceClassName.getString();
214                             out.append('"');
215 kumpf      1.30         }
216 kumpf      1.40         out << STRLIT(">\n");
217 mike       1.10 
218 kumpf      1.40         _qualifiers.toXml(out);
219 mike       1.10 
220 kumpf      1.40         out << STRLIT("</PARAMETER.REFERENCE>\n");
221 mike       1.10     }
222 mike       1.9      else
223                     {
224 kumpf      1.40         out << STRLIT("<PARAMETER");
225                         out << STRLIT(" NAME=\"") << _name;
226                         out << STRLIT("\" ");
227                         out << STRLIT(" TYPE=\"") << cimTypeToString(_type);
228                         out << STRLIT("\">\n");
229 mike       1.9  
230 kumpf      1.40         _qualifiers.toXml(out);
231 mike       1.9  
232 kumpf      1.40         out << STRLIT("</PARAMETER>\n");
233 mike       1.9      }
234                 }
235 mike       1.10 
236                 /** toMof - puts the Mof representation of teh Parameter object to
237                     the output parameter array
238                     The BNF for this conversion is:
239 kumpf      1.40     parameterList    =  parameter *( "," parameter )
240 mike       1.10 
241 kumpf      1.40         parameter    =  [ qualifierList ] (dataType|objectRef) parameterName
242                                         [ array ]
243 mike       1.10 
244 kumpf      1.40         parameterName=  IDENTIFIER
245 chip       1.36 
246 kumpf      1.40         array        =  "[" [positiveDecimalValue] "]"
247 chip       1.36 
248 mike       1.10     Format on a single line.
249 kumpf      1.40 */
250 mike       1.37 void CIMParameterRep::toMof(Buffer& out) const
251 mike       1.10 {
252                     // Output the qualifiers for the parameter
253                     _qualifiers.toMof(out);
254                 
255                     if (_qualifiers.getCount())
256 kumpf      1.40         out.append(' ');
257 mike       1.10 
258                     // Output the data type and name
259 mike       1.38     out << cimTypeToString(_type);
260                     out.append(' ');
261                     out <<  _name;
262 mike       1.10 
263                     if (_isArray)
264                     {
265 kumpf      1.40         //Output the array indicator "[ [arraysize] ]"
266                         if (_arraySize)
267                         {
268                             char buffer[32];
269                             int n = sprintf(buffer, "[%d]", _arraySize);
270                             out.append(buffer, n);
271                         }
272                         else
273                             out << STRLIT("[]");
274 mike       1.10     }
275                 }
276                 
277 mike       1.9  
278                 Boolean CIMParameterRep::identical(const CIMParameterRep* x) const
279                 {
280 kumpf      1.42     // If the pointers are the same, the objects must be identical
281                     if (this == x)
282                     {
283                         return true;
284                     }
285                 
286 kumpf      1.28     if (!_name.equal (x->_name))
287 kumpf      1.40         return false;
288 mike       1.9  
289                     if (_type != x->_type)
290 kumpf      1.40         return false;
291 mike       1.9  
292 kumpf      1.28     if (!_referenceClassName.equal (x->_referenceClassName))
293 kumpf      1.40         return false;
294 mike       1.9  
295                     if (!_qualifiers.identical(x->_qualifiers))
296 kumpf      1.40         return false;
297 mike       1.9  
298                     return true;
299                 }
300                 
301                 PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2