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

  1 mike  1.1 //BEGIN_LICENSE
  2           //
  3           // Copyright (c) 2000 The Open Group, BMC Software, Tivoli Systems, IBM
  4           //
  5           // Permission is hereby granted, free of charge, to any person obtaining a
  6           // copy of this software and associated documentation files (the "Software"),
  7           // to deal in the Software without restriction, including without limitation
  8           // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9           // and/or sell copies of the Software, and to permit persons to whom the
 10           // Software is furnished to do so, subject to the following conditions:
 11           //
 12           // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 13           // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 14           // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 15           // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 16           // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 17           // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 18           // DEALINGS IN THE SOFTWARE.
 19           //
 20           //END_LICENSE
 21           //BEGIN_HISTORY
 22 mike  1.1 //
 23           // Author:
 24           //
 25           // $Log: CIMQualifierList.cpp,v $
 26 bob   1.4 // Revision 1.3  2001/02/20 05:16:57  mike
 27           // Implemented CIMInstance::getInstanceName()
 28           //
 29 mike  1.3 // Revision 1.2  2001/02/19 01:47:16  mike
 30 mike  1.5 // Renamed names of the form CIMConst to CIMConst.
 31 mike  1.3 //
 32 mike  1.2 // Revision 1.1  2001/02/18 18:39:06  mike
 33           // new
 34           //
 35 mike  1.1 // Revision 1.3  2001/02/18 03:56:01  mike
 36 mike  1.5 // Changed more class names (e.g., ConstClassDecl -> CIMConstClass)
 37 mike  1.1 //
 38           // Revision 1.2  2001/02/17 00:41:28  bob
 39           // #ifdefed around the check of scope to avoid bogus exceptions
 40           //
 41           // Revision 1.1  2001/02/16 02:07:06  mike
 42           // Renamed many classes and headers (using new CIM prefixes).
 43           //
 44           // Revision 1.5  2001/02/13 02:06:40  mike
 45           // Added renameFile() method.
 46           //
 47           // Revision 1.4  2001/01/28 04:11:03  mike
 48           // fixed qualifier resolution
 49           //
 50           // Revision 1.3  2001/01/23 01:25:35  mike
 51           // Reworked resolve scheme.
 52           //
 53           // Revision 1.2  2001/01/22 00:45:47  mike
 54           // more work on resolve scheme
 55           //
 56           // Revision 1.1.1.1  2001/01/14 19:53:09  mike
 57           // Pegasus import
 58 mike  1.1 //
 59           //
 60           //END_HISTORY
 61           
 62           #include "CIMQualifierList.h"
 63           #include "DeclContext.h"
 64           #include "CIMQualifierDecl.h"
 65           #include "CIMName.h"
 66           #include "Indentor.h"
 67           #include "XmlWriter.h"
 68           
 69           PEGASUS_NAMESPACE_BEGIN
 70           
 71           CIMQualifierList& CIMQualifierList::add(const CIMQualifier& qualifier)
 72           {
 73               if (!qualifier)
 74           	throw UnitializedHandle();
 75           
 76               if (find(qualifier.getName()) != Uint32(-1))
 77           	throw AlreadyExists();
 78           
 79 mike  1.1     _qualifiers.append(qualifier);
 80           
 81               return *this;
 82           }
 83           
 84           Uint32 CIMQualifierList::find(const String& name) const
 85           {
 86               for (Uint32 i = 0, n = _qualifiers.getSize(); i < n; i++)
 87               {
 88           	if (CIMName::equal(_qualifiers[i].getName(), name))
 89           	    return i;
 90 mike  1.3     }
 91               
 92               return Uint32(-1);
 93           }
 94           
 95           Uint32 CIMQualifierList::findReverse(const String& name) const
 96           {
 97               for (Uint32 i = _qualifiers.getSize(); i; --i)
 98               {
 99           	if (CIMName::equal(_qualifiers[i - 1].getName(), name))
100           	    return i - 1;
101 mike  1.1     }
102               
103               return Uint32(-1);
104           }
105           
106           void CIMQualifierList::resolve(
107               DeclContext* declContext,
108               const String& nameSpace,
109               Uint32 scope,
110               Boolean isInstancePart,
111               CIMQualifierList& inheritedQualifiers)
112           {
113               // For each qualifier in the qualifiers array, the following 
114               // is checked:
115               //
116               //     1. Whether it is declared (can be obtained from the declContext).
117               //
118               //     2. Whether it has the same type as the declaration.
119               //
120               //	   3. Whether the the qualifier is valid for the given scope.
121               //
122 mike  1.1     //	   4. Whether the qualifier can be overriden (the flavor is
123               //	      ENABLEOVERRIDE on the corresponding reference qualifier).
124               //
125               //	   5. Whether the qualifier should be propagated to the subclass.
126               //
127               // If the qualifier should be overriden, then it is injected into the 
128               // qualifiers array (from the inheritedQualifiers array).
129           
130               for (Uint32 i = 0, n = _qualifiers.getSize(); i < n; i++)
131               {
132           	CIMQualifier q = _qualifiers[i];
133           
134           	//----------------------------------------------------------------------
135           	// 1. Check to see if it's declared.
136           	//----------------------------------------------------------------------
137           
138           	CIMConstQualifierDecl qd = declContext->lookupQualifierDecl(
139           	    nameSpace, q.getName());
140           
141           	if (!qd)
142           	    throw UndeclaredQualifier(q.getName());
143 mike  1.1 
144           	//----------------------------------------------------------------------
145           	// 2. Check the type:
146           	//----------------------------------------------------------------------
147           
148           	if (!(q.getType() == qd.getType() && q.isArray() == qd.isArray()))
149           	    throw BadQualifierType(q.getName());
150           
151           	//----------------------------------------------------------------------
152           	// 3. Check the scope:
153           	//----------------------------------------------------------------------
154           #if 0
155                   // ATTN:  These lines throw a bogus exception if the qualifier has
156                   // a valid scope (such as Scope::ASSOCIATION) which is not Scope::CLASS
157                   // grb 1/16/01
158           	if (!(qd.getScope() & scope))
159           	    throw BadQualifierScope(qd.getName(), ScopeToString(scope));
160           #endif
161           	//----------------------------------------------------------------------
162           	// See if this qualifier is contained in the inheritedQualifiers. If
163           	// so then we must handle the OVERRIDABLE flavor.
164 mike  1.1 	//----------------------------------------------------------------------
165           
166           	// ATTN: there seems to be a problem with the CIM schema that marks the
167           	// abstract qualifier as non-overridable but then they override it.
168           	// For now it is just disabled. This problem exists in both XML and
169           	// CIM schema.
170           
171           #if 0
172           	Uint32 pos = inheritedQualifiers.find(q.getName());
173           
174           	if (pos != Uint32(-1))
175           	{
176           	    CIMConstQualifier iq = inheritedQualifiers.getQualifier(pos);
177           
178           	    if (!(iq.getFlavor() & CIMFlavor::OVERRIDABLE))
179           		throw BadQualifierOverride(q.getName());
180           	}
181           #endif
182               }
183           
184               //--------------------------------------------------------------------------
185 mike  1.1     // Propagate qualifiers to subclass or to instance that do not have 
186               // already have those qualifiers:
187               //--------------------------------------------------------------------------
188           
189               for (Uint32 i = 0, n = inheritedQualifiers.getCount(); i < n; i++)
190               {
191           	CIMQualifier iq = inheritedQualifiers.getQualifier(i);
192           
193           	if (isInstancePart)
194           	{
195           	    if (!(iq.getFlavor() & CIMFlavor::TOINSTANCE))
196           		continue;
197           	}
198           	else
199           	{
200           	    if (!(iq.getFlavor() & CIMFlavor::TOSUBCLASS))
201           		continue;
202           	}
203           
204           	// If the qualifiers list does not already contain this qualifier,
205           	// then propagate it (and set the propagated flag to true).
206 mike  1.1 
207           	if (find(iq.getName()) != Uint32(-1))
208           	    continue;
209           
210           	CIMQualifier q = iq.clone();
211           	q.setPropagated(true);
212           	_qualifiers.prepend(q);
213               }
214           }
215           
216           void CIMQualifierList::toXml(Array<Sint8>& out) const
217           {
218               for (Uint32 i = 0, n = _qualifiers.getSize(); i < n; i++)
219           	_qualifiers[i].toXml(out);
220           }
221           
222 bob   1.4 void CIMQualifierList::print(std::ostream &os) const
223 mike  1.1 {
224               Array<Sint8> tmp;
225               toXml(tmp);
226               tmp.append('\0');
227 bob   1.4     os << tmp.getData() << std::endl;
228 mike  1.1 }
229           
230           Boolean CIMQualifierList::identical(const CIMQualifierList& x) const
231           {
232               Uint32 count = getCount();
233           
234               if (count != x.getCount())
235           	return false;
236           
237               for (Uint32 i = 0; i < count; i++)
238           	return _qualifiers[i].identical(x._qualifiers[i]);
239           
240               return true;
241           }
242           
243           void CIMQualifierList::cloneTo(CIMQualifierList& x) const
244           {
245               x._qualifiers.clear();
246               x._qualifiers.reserve(_qualifiers.getSize());
247           
248               for (Uint32 i = 0, n = _qualifiers.getSize(); i < n; i++)
249 mike  1.1 	x._qualifiers.append(_qualifiers[i].clone());
250           }
251           
252           PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2