version 1.23, 2002/03/22 00:48:58
|
version 1.64, 2008/02/29 18:55:06
|
|
|
//%///////////////////////////////////////////////////////////////////////////// |
//%2006//////////////////////////////////////////////////////////////////////// |
// | // |
// Copyright (c) 2000, 2001 The Open group, BMC Software, Tivoli Systems, IBM |
// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development |
|
// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems. |
|
// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.; |
|
// IBM Corp.; EMC Corporation, The Open Group. |
|
// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.; |
|
// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group. |
|
// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.; |
|
// EMC Corporation; VERITAS Software Corporation; The Open Group. |
|
// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.; |
|
// EMC Corporation; Symantec Corporation; The Open Group. |
// | // |
// Permission is hereby granted, free of charge, to any person obtaining a copy | // Permission is hereby granted, free of charge, to any person obtaining a copy |
// of this software and associated documentation files (the "Software"), to | // of this software and associated documentation files (the "Software"), to |
|
|
// | // |
//============================================================================== | //============================================================================== |
// | // |
// Author: Mike Brasher (mbrasher@bmc.com) |
|
// |
|
// Modified By: |
|
// |
|
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
#include "CIMQualifierList.h" | #include "CIMQualifierList.h" |
#include "DeclContext.h" | #include "DeclContext.h" |
|
#include "Resolver.h" |
#include "CIMQualifierDecl.h" | #include "CIMQualifierDecl.h" |
#include "CIMName.h" | #include "CIMName.h" |
#include "Indentor.h" |
|
#include "XmlWriter.h" | #include "XmlWriter.h" |
|
#include "MofWriter.h" |
|
#include <Pegasus/Common/Tracer.h> |
|
#include <Pegasus/Common/MessageLoader.h> |
|
#include "StrLit.h" |
|
#include "ArrayIterator.h" |
|
#include "CIMQualifierRep.h" |
| |
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
PEGASUS_USING_STD; | PEGASUS_USING_STD; |
| |
CIMQualifierList::CIMQualifierList() |
static CIMName _KEY("Key"); |
|
|
|
CIMQualifierList::CIMQualifierList() : |
|
_keyIndex(PEGASUS_ORDEREDSET_INDEX_UNKNOWN) |
{ | { |
| |
} | } |
|
|
| |
CIMQualifierList& CIMQualifierList::add(const CIMQualifier& qualifier) | CIMQualifierList& CIMQualifierList::add(const CIMQualifier& qualifier) |
{ | { |
if (!qualifier) |
if (qualifier.isUninitialized()) |
throw UnitializedHandle(); |
throw UninitializedObjectException(); |
| |
if (find(qualifier.getName()) != PEG_NOT_FOUND) | if (find(qualifier.getName()) != PEG_NOT_FOUND) |
throw AlreadyExists(); |
{ |
|
MessageLoaderParms parms("Common.CIMQualifierList.QUALIFIER", |
|
"qualifier \"$0\"", |
|
qualifier.getName().getString()); |
|
throw AlreadyExistsException(parms); |
|
} |
| |
_qualifiers.append(qualifier); | _qualifiers.append(qualifier); |
| |
|
// Update key index: |
|
if (_keyIndex == PEGASUS_ORDEREDSET_INDEX_UNKNOWN && |
|
qualifier._rep->_name == _KEY) |
|
_keyIndex = _qualifiers.size()-1; |
|
|
return *this; | return *this; |
} | } |
//ATTN: Why do we not do the outofbounds check here. KS 18 May 2k |
|
CIMQualifier& CIMQualifierList::getQualifier(Uint32 pos) |
CIMQualifier& CIMQualifierList::getQualifier(Uint32 index) |
{ | { |
return _qualifiers[pos]; |
return _qualifiers[index]; |
} | } |
| |
//ATTN: added ks 18 may 2001. Should we have outofbounds? |
void CIMQualifierList::removeQualifier(Uint32 index) |
void CIMQualifierList::removeQualifier(Uint32 pos) |
|
{ | { |
_qualifiers.remove(pos); |
_qualifiers.remove(index); |
|
_keyIndex = PEGASUS_ORDEREDSET_INDEX_UNKNOWN; |
} | } |
| |
Uint32 CIMQualifierList::find(const String& name) const |
void CIMQualifierList::clear() |
{ |
|
for (Uint32 i = 0, n = _qualifiers.size(); i < n; i++) |
|
{ | { |
if (CIMName::equal(_qualifiers[i].getName(), name)) |
_qualifiers.clear(); |
return i; |
|
} | } |
| |
return PEG_NOT_FOUND; |
Uint32 CIMQualifierList::find(const CIMName& name) const |
|
{ |
|
return _qualifiers.find(name, generateCIMNameTag(name)); |
} | } |
| |
Uint32 CIMQualifierList::findReverse(const String& name) const |
Boolean CIMQualifierList::isTrue(const CIMName& name) const |
{ |
|
for (Uint32 i = _qualifiers.size(); i; --i) |
|
{ | { |
if (CIMName::equal(_qualifiers[i - 1].getName(), name)) |
Uint32 index = find(name); |
return i - 1; |
|
} |
if (index == PEG_NOT_FOUND) |
|
return false; |
|
|
|
Boolean flag; |
|
const CIMValue& value = getQualifier(index).getValue(); |
|
|
|
if (value.getType() != CIMTYPE_BOOLEAN) |
|
return false; |
| |
return PEG_NOT_FOUND; |
value.get(flag); |
|
return flag; |
} | } |
| |
void CIMQualifierList::resolve( | void CIMQualifierList::resolve( |
DeclContext* declContext, | DeclContext* declContext, |
const String& nameSpace, |
const CIMNamespaceName & nameSpace, |
Uint32 scope, |
CIMScope scope, // Scope of the entity being resolved. |
Boolean isInstancePart, | Boolean isInstancePart, |
CIMQualifierList& inheritedQualifiers, | CIMQualifierList& inheritedQualifiers, |
Boolean propagateQualifiers) |
Boolean propagateQualifiers) // Apparently not used ks 24 mar 2002 |
{ | { |
|
_keyIndex = PEGASUS_ORDEREDSET_INDEX_UNKNOWN; |
|
|
|
PEG_METHOD_ENTER(TRC_OBJECTRESOLUTION, "CIMQualifierList::resolve()"); |
// For each qualifier in the qualifiers array, the following | // For each qualifier in the qualifiers array, the following |
// is checked: | // is checked: |
// | // |
|
|
// | // |
// 2. Whether it has the same type as the declaration. | // 2. Whether it has the same type as the declaration. |
// | // |
// 3. Whether the the qualifier is valid for the given scope. |
// 3. Whether the qualifier is valid for the given scope. |
// | // |
// 4. Whether the qualifier can be overriden (the flavor is | // 4. Whether the qualifier can be overriden (the flavor is |
// ENABLEOVERRIDE on the corresponding reference qualifier). | // ENABLEOVERRIDE on the corresponding reference qualifier). |
|
|
for (Uint32 i = 0, n = _qualifiers.size(); i < n; i++) | for (Uint32 i = 0, n = _qualifiers.size(); i < n; i++) |
{ | { |
CIMQualifier q = _qualifiers[i]; | CIMQualifier q = _qualifiers[i]; |
//cout << "KSTEST Qualifier resolve for Name = " << q.getName() << endl; |
|
//---------------------------------------------------------------------- | //---------------------------------------------------------------------- |
// 1. Check to see if it's declared. | // 1. Check to see if it's declared. |
//---------------------------------------------------------------------- | //---------------------------------------------------------------------- |
|
// set this back to CIMConstQualifierDecl |
CIMConstQualifierDecl qd = declContext->lookupQualifierDecl( |
CIMQualifierDecl qd = declContext->lookupQualifierDecl( |
nameSpace, q.getName()); | nameSpace, q.getName()); |
| |
if (!qd) |
if (qd.isUninitialized()) |
throw UndeclaredQualifier(q.getName()); |
{ |
|
PEG_METHOD_EXIT(); |
|
throw UndeclaredQualifier(q.getName().getString ()); |
|
} |
| |
//---------------------------------------------------------------------- | //---------------------------------------------------------------------- |
// 2. Check the type: |
// 2. Check the type and isArray. Must be the same: |
//---------------------------------------------------------------------- | //---------------------------------------------------------------------- |
| |
if (!(q.getType() == qd.getType() && q.isArray() == qd.isArray())) | if (!(q.getType() == qd.getType() && q.isArray() == qd.isArray())) |
throw BadQualifierType(q.getName()); |
{ |
|
PEG_METHOD_EXIT(); |
|
throw BadQualifierType(q.getName().getString ()); |
|
} |
| |
|
#ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT |
//---------------------------------------------------------------------- | //---------------------------------------------------------------------- |
// 3. Check the scope: |
// 3. If the qualifier is the EmbeddedInstance qualifier, then check |
|
// that the class specified by the qualifier exists in the namespace. |
|
//---------------------------------------------------------------------- |
|
if (q.getName().equal(CIMName("EmbeddedInstance"))) |
|
{ |
|
String className; |
|
q.getValue().get(className); |
|
CIMClass classDef = declContext->lookupClass(nameSpace, |
|
CIMName(className)); |
|
if (classDef.isUninitialized()) |
|
{ |
|
String embeddedInstType("EmbeddedInstance(\""); |
|
embeddedInstType = embeddedInstType + className + "\")"; |
|
PEG_METHOD_EXIT(); |
|
throw BadQualifierType(embeddedInstType); |
|
} |
|
} |
|
#endif // PEGASUS_EMBEDDED_INSTANCE_SUPPORT |
|
|
|
//---------------------------------------------------------------------- |
|
// 4. Check the scope: Must be legal for this qualifier |
//---------------------------------------------------------------------- | //---------------------------------------------------------------------- |
#if 0 |
|
// ATTN: These lines throw a bogus exception if the qualifier has | // ATTN: These lines throw a bogus exception if the qualifier has |
// a valid scope (such as Scope::ASSOCIATION) which is not Scope::CLASS | // a valid scope (such as Scope::ASSOCIATION) which is not Scope::CLASS |
// ks Mar 2002 |
// ks Mar 2002. Reinstalled 23 March 2002 to test. |
if (!(qd.getScope() & scope)) |
|
throw BadQualifierScope(qd.getName(), ScopeToString(scope)); |
if (!(qd.getScope().hasScope (scope))) |
#endif |
{ |
|
PEG_METHOD_EXIT(); |
|
throw BadQualifierScope |
|
(qd.getName().getString (), scope.toString ()); |
|
} |
|
|
//---------------------------------------------------------------------- | //---------------------------------------------------------------------- |
// See if this qualifier is contained in the inheritedQualifiers. If |
// Resolve the qualifierflavor. Since Flavors are a combination of |
// so then we must handle the OVERRIDABLE flavor. |
// inheritance and input characteristics, resolve the inherited |
|
// characteristics against those provided with the creation. If |
|
// there is a superclass the flavor is resolved against that |
|
// superclass. If not, it is resolved against the declaration. If |
|
// the flavor is disableoverride and tosubclass the resolved |
|
// qualifier value must be identical to the original |
//---------------------------------------------------------------------- | //---------------------------------------------------------------------- |
|
// Test for Qualifier found in SuperClass. If found and qualifier |
|
// is not overridable. |
|
// Abstract (not Overridable and restricted) can be found in subclasses |
|
// Can have nonabstracts below abstracts. That is function of |
|
// nottosubclass Association (notOverridable and tosubclass) can be |
|
// found in subclasses but cannot be changed. No non-associatons below |
|
// associations. In other words once a class becomes an association, |
|
// no subclass can override that definition apparently |
|
// Throw exception if DisableOverride and tosubclass and different |
|
// value. Gets the source from superclass if qualifier exists or from |
|
// declaraction. |
|
// If we do not throw the exception, resolve the flavor from the |
|
// inheritance point and resolve against current input. |
|
// Diableoverride is defined in the CIM Spec to mean that the value |
|
// cannot change. |
|
// The other characteristics including the flavor can change |
|
// apparently. Thus, we need only confirm that the value is the same |
|
// (2.2 pp 33). Strange since we would think that override implies |
|
// that you cannot override any of the characteristics (value, type, |
|
// flavor, etc.) This also leaves the question of NULL or no values. |
|
// The implication is that we must move the value from the superclass |
|
// or declaration. |
|
|
|
Uint32 index = inheritedQualifiers.find(q.getName()); |
|
|
|
if (index == PEG_NOT_FOUND) |
|
{ // Qualifier does not exist in superclass |
|
/* If from declaration, we can override the default value. |
|
However, we need some way to get the value if we have a Null. |
|
if (!qd.getFlavor().hasFlavor(CIMFlavor::OVERRIDABLE) && |
|
qd.getFlavor().hasFlavor(CIMFlavor::TOSUBCLASS)) |
|
{ |
|
//throw BadQualifierOverride(q.getName()); |
|
} |
|
*/ |
|
// Do not allow change from disable override to enable override. |
|
if ((!qd.getFlavor ().hasFlavor(CIMFlavor::OVERRIDABLE)) |
|
&& (q.getFlavor ().hasFlavor(CIMFlavor::OVERRIDABLE))) |
|
{ |
|
PEG_METHOD_EXIT(); |
|
throw BadQualifierOverride(q.getName().getString ()); |
|
} |
| |
// ATTN: there seems to be a problem with the CIM schema that marks the |
Resolver::resolveQualifierFlavor( |
// abstract qualifier as non-overridable but then they override it. |
q, CIMFlavor (qd.getFlavor ()), false); |
// For now it is just disabled. This problem exists in both XML and |
} |
// CIM schema. |
else // qualifier exists in superclass |
//cout << "KSTEST QUal resolve Propagate 1 " << q.getName() << endl; |
{ ////// Make Const again |
#if 0 |
CIMQualifier iq = inheritedQualifiers.getQualifier(index); |
Uint32 pos = inheritedQualifiers.find(q.getName()); |
// don't allow change override to notoverride. |
|
if (!(iq.getFlavor ().hasFlavor(CIMFlavor::OVERRIDABLE)) |
if (pos != PEG_NOT_FOUND) |
&& q.getFlavor ().hasFlavor (CIMFlavor::OVERRIDABLE)) |
{ | { |
CIMConstQualifier iq = inheritedQualifiers.getQualifier(pos);{ |
PEG_METHOD_EXIT(); |
|
throw BadQualifierOverride(q.getName().getString ()); |
|
} |
| |
if (!(iq.getFlavor() & CIMFlavor::OVERRIDABLE)) |
if (!(iq.getFlavor ().hasFlavor(CIMFlavor::OVERRIDABLE)) |
throw BadQualifierOverride(q.getName()); |
&& iq.getFlavor ().hasFlavor(CIMFlavor::TOSUBCLASS)) |
|
{ |
|
// test if values the same. |
|
CIMValue qv = q.getValue(); |
|
CIMValue iqv = iq.getValue(); |
|
if (!(qv == iqv)) |
|
{ |
|
PEG_METHOD_EXIT(); |
|
throw BadQualifierOverride(q.getName().getString()); |
} | } |
} | } |
#endif |
|
|
Resolver::resolveQualifierFlavor( |
|
q, CIMFlavor(iq.getFlavor()), true); |
} | } |
|
} // end of this objects qualifier loop |
| |
//-------------------------------------------------------------------------- | //-------------------------------------------------------------------------- |
// Propagate qualifiers to subclass or to instance that do not have | // Propagate qualifiers to subclass or to instance that do not have |
// already have those qualifiers: | // already have those qualifiers: |
//-------------------------------------------------------------------------- | //-------------------------------------------------------------------------- |
|
|
for (Uint32 i = 0, n = inheritedQualifiers.getCount(); i < n; i++) | for (Uint32 i = 0, n = inheritedQualifiers.getCount(); i < n; i++) |
{ | { |
CIMQualifier iq = inheritedQualifiers.getQualifier(i); | CIMQualifier iq = inheritedQualifiers.getQualifier(i); |
//cout << "KSTEST inherited propagate loop 2 " << iq.getName() |
|
//<< " flavor " << iq.getFlavor << " count " << i << endl; |
|
|
|
// ATTN-DE-P1-This next test is incorrect. It is a temporary, hard-coded |
|
// HACK to avoid propagating the "Abstract" Qualifier to subclasses |
|
//if (CIMName::equal(iq.getName(), "Abstract")) |
|
// continue; |
|
| |
if (isInstancePart) | if (isInstancePart) |
{ | { |
if (!(iq.getFlavor() && CIMFlavor::TOINSTANCE)) |
if (!(iq.getFlavor ().hasFlavor |
|
(CIMFlavor::TOINSTANCE))) |
continue; | continue; |
} | } |
else | else |
{ | { |
if (!(iq.getFlavor() && CIMFlavor::TOSUBCLASS)){ |
if (!(iq.getFlavor ().hasFlavor |
|
(CIMFlavor::TOSUBCLASS))) |
continue; | continue; |
} | } |
} |
|
| |
// If the qualifiers list does not already contain this qualifier, | // If the qualifiers list does not already contain this qualifier, |
// then propagate it (and set the propagated flag to true). |
// then propagate it (and set the propagated flag to true). Else we |
|
// keep current value. Note we have already eliminated any possibity |
|
// that a nonoverridable qualifier can be in the list. |
|
// Note that there is no exists() function ATTN:KS 25 Mar 2002 |
if (find(iq.getName()) != PEG_NOT_FOUND) | if (find(iq.getName()) != PEG_NOT_FOUND) |
continue; | continue; |
| |
/* |
|
cout << "KSTEST resolve Propagate " << iq.getName() << " true= " << true |
|
<< " flavor= " << iq.getFlavor() |
|
<< " TOSUBCLASS " << (iq.getFlavor() && CIMFlavor::TOSUBCLASS) << endl; |
|
*/ |
|
|
|
if (propagateQualifiers) |
|
{ |
|
CIMQualifier q = iq.clone(); | CIMQualifier q = iq.clone(); |
q.setPropagated(true); | q.setPropagated(true); |
_qualifiers.prepend(q); |
_qualifiers.insert(0, q); |
} |
|
} | } |
|
PEG_METHOD_EXIT(); |
} | } |
| |
void CIMQualifierList::toXml(Array<Sint8>& out) const |
void CIMQualifierList::toXml(Buffer& out) const |
{ | { |
for (Uint32 i = 0, n = _qualifiers.size(); i < n; i++) | for (Uint32 i = 0, n = _qualifiers.size(); i < n; i++) |
_qualifiers[i].toXml(out); |
XmlWriter::appendQualifierElement(out, _qualifiers[i]); |
} | } |
| |
/** toMof - Generates MOF output for a list of CIM Qualifiers. | /** toMof - Generates MOF output for a list of CIM Qualifiers. |
|
|
</pre> | </pre> |
Produces qualifiers as a string on without nl. | Produces qualifiers as a string on without nl. |
*/ | */ |
void CIMQualifierList::toMof(Array<Sint8>& out) const |
void CIMQualifierList::toMof(Buffer& out) const |
{ | { |
// if no qualifiers, return | // if no qualifiers, return |
if (_qualifiers.size() == 0) | if (_qualifiers.size() == 0) |
return; | return; |
| |
// Qualifier leading bracket. | // Qualifier leading bracket. |
out <<"["; |
out.append('['); |
| |
// Loop to list qualifiers | // Loop to list qualifiers |
for (Uint32 i = 0, n = _qualifiers.size(); i < n; i++) | for (Uint32 i = 0, n = _qualifiers.size(); i < n; i++) |
{ | { |
// if second or greater, add comma separator | // if second or greater, add comma separator |
if (i > 0) | if (i > 0) |
out << ", \n"; |
out << STRLIT(", \n"); |
_qualifiers[i].toMof(out); |
MofWriter::appendQualifierElement(out, _qualifiers[i]); |
} | } |
| |
// Terminating bracket | // Terminating bracket |
out << "]"; |
out.append(']'); |
} | } |
| |
| |
void CIMQualifierList::print(PEGASUS_STD(ostream) &os) const | void CIMQualifierList::print(PEGASUS_STD(ostream) &os) const |
{ | { |
Array<Sint8> tmp; |
Buffer tmp; |
toXml(tmp); | toXml(tmp); |
tmp.append('\0'); |
|
os << tmp.getData() << PEGASUS_STD(endl); | os << tmp.getData() << PEGASUS_STD(endl); |
} | } |
| |
|
|
| |
void CIMQualifierList::cloneTo(CIMQualifierList& x) const | void CIMQualifierList::cloneTo(CIMQualifierList& x) const |
{ | { |
|
x._keyIndex = PEGASUS_ORDEREDSET_INDEX_UNKNOWN; |
x._qualifiers.clear(); | x._qualifiers.clear(); |
x._qualifiers.reserve(_qualifiers.size()); |
x._qualifiers.reserveCapacity(_qualifiers.size()); |
| |
for (Uint32 i = 0, n = _qualifiers.size(); i < n; i++) | for (Uint32 i = 0, n = _qualifiers.size(); i < n; i++) |
x._qualifiers.append(_qualifiers[i].clone()); | x._qualifiers.append(_qualifiers[i].clone()); |
|
x._keyIndex = _keyIndex; |
|
} |
|
|
|
Boolean CIMQualifierList::isKey() const |
|
{ |
|
static Uint32 _KEY_TAG = generateCIMNameTag(_KEY); |
|
|
|
// Resolve key index if unresolved. |
|
|
|
if (_keyIndex == PEGASUS_ORDEREDSET_INDEX_UNKNOWN) |
|
{ |
|
Uint32 pos = _qualifiers.find(_KEY, _KEY_TAG); |
|
((CIMQualifierList*)this)->_keyIndex = int(pos); |
|
} |
|
|
|
// If no key qualifier in list, then return false (default key value). |
|
|
|
if (_keyIndex == PEGASUS_ORDEREDSET_INDEX_NOTFOUND) |
|
return false; |
|
|
|
// Obtain value of key qualifier. |
|
|
|
const CIMValue& value = _qualifiers[_keyIndex]._rep->_value; |
|
if (!value.isNull() && |
|
value.getType() == CIMTYPE_BOOLEAN) |
|
{ |
|
Boolean boolVal; |
|
value.get(boolVal); |
|
return boolVal; |
|
} |
|
|
|
return false; |
} | } |
| |
PEGASUS_NAMESPACE_END | PEGASUS_NAMESPACE_END |