version 1.36, 2006/02/22 07:03:43
|
version 1.37, 2006/11/14 18:34:58
|
|
|
// | // |
//============================================================================== | //============================================================================== |
// | // |
// Author: Mike Brasher (mbrasher@bmc.com) |
|
// |
|
// Modified By: Carol Ann Krug Graves, Hewlett-Packard Company |
|
// (carolann_graves@hp.com) |
|
// Vijay Eli, IBM (vijayeli@in.ibm.com) for bug#3352 |
|
// |
|
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
#include <Pegasus/Common/String.h> | #include <Pegasus/Common/String.h> |
|
|
{ | { |
// For each subClass: | // For each subClass: |
| |
for (InheritanceTreeNode* p = subClasses; p; p = p->sibling) { |
for (InheritanceTreeNode* p = subClasses; p; p = p->sibling) |
if (p->extension) { |
{ |
for (int j=0,m=p->extNodes->size(); j<m; j++) { |
if (p->extension) |
|
{ |
|
for (int j = 0, m = p->extNodes->size(); j < m; j++) |
|
{ |
InheritanceTreeExt *itx=(*(p->extNodes))[j]; | InheritanceTreeExt *itx=(*(p->extNodes))[j]; |
subClassNames.append(p->className); | subClassNames.append(p->className); |
if (!ns) { |
if (!ns) |
|
{ |
InheritanceTreeNode* itn=itx->node; | InheritanceTreeNode* itn=itx->node; |
itn->getSubClassNames(subClassNames, deepInheritance, ns); | itn->getSubClassNames(subClassNames, deepInheritance, ns); |
} | } |
else if (itx->tag==ns) { |
else if (itx->tag == ns) |
|
{ |
InheritanceTreeNode* itn=itx->node; | InheritanceTreeNode* itn=itx->node; |
itn->getSubClassNames(subClassNames, deepInheritance, ns); | itn->getSubClassNames(subClassNames, deepInheritance, ns); |
break; | break; |
} | } |
} | } |
} | } |
|
else |
else { |
{ |
subClassNames.append(p->className); | subClassNames.append(p->className); |
if (deepInheritance) { |
if (deepInheritance) |
|
{ |
p->getSubClassNames(subClassNames, true, ns); | p->getSubClassNames(subClassNames, true, ns); |
} | } |
} | } |
|
|
{ | { |
InheritanceTreeNode* superClassNode = 0; | InheritanceTreeNode* superClassNode = 0; |
| |
if ((superClassName.size()) && |
if (superClassName.size() && |
!parentTree._rep->table.lookup(superClassName, superClassNode)) { |
!parentTree._rep->table.lookup(superClassName, superClassNode)) |
|
{ |
superClassNode = | superClassNode = |
new InheritanceTreeNode(CIMNameUnchecked(superClassName)); | new InheritanceTreeNode(CIMNameUnchecked(superClassName)); |
parentTree._rep->table.insert(superClassName, superClassNode); | parentTree._rep->table.insert(superClassName, superClassNode); |
|
|
| |
InheritanceTreeNode* extNode = 0; | InheritanceTreeNode* extNode = 0; |
| |
if (!parentTree._rep->table.lookup(className, extNode)) { |
if (!parentTree._rep->table.lookup(className, extNode)) |
|
{ |
extNode = new InheritanceTreeNode(CIMNameUnchecked(className)); | extNode = new InheritanceTreeNode(CIMNameUnchecked(className)); |
parentTree._rep->table.insert(className, extNode); | parentTree._rep->table.insert(className, extNode); |
extNode->extension=true; | extNode->extension=true; |
|
|
| |
InheritanceTreeNode* classNode = 0; | InheritanceTreeNode* classNode = 0; |
| |
if (!_rep->table.lookup(className, classNode)) { |
if (!_rep->table.lookup(className, classNode)) |
|
{ |
classNode = new InheritanceTreeNode(className); | classNode = new InheritanceTreeNode(className); |
_rep->table.insert(className, classNode); | _rep->table.insert(className, classNode); |
} | } |
|
|
| |
InheritanceTreeNode* superClassNode = 0; | InheritanceTreeNode* superClassNode = 0; |
| |
if ((superClassName.size()) && |
if (superClassName.size() && |
!_rep->table.lookup(superClassName, superClassNode)) | !_rep->table.lookup(superClassName, superClassNode)) |
{ | { |
superClassNode = | superClassNode = |
|
|
| |
| |
#ifdef PEGASUS_REPOSITORY_ESCAPE_UTF8 | #ifdef PEGASUS_REPOSITORY_ESCAPE_UTF8 |
if (ns) insert(escapeStringDecoder(className), escapeStringDecoder(superClassName), |
if (ns) |
|
insert( |
|
escapeStringDecoder(className), |
|
escapeStringDecoder(superClassName), |
*parentTree,ns); | *parentTree,ns); |
else insert(escapeStringDecoder(className), |
else |
|
insert( |
|
escapeStringDecoder(className), |
escapeStringDecoder(superClassName)); | escapeStringDecoder(superClassName)); |
#else | #else |
if (ns) insert(className, superClassName, *parentTree,ns); |
if (ns) |
else insert(className,superClassName); |
insert(className, superClassName, *parentTree, ns); |
|
else |
|
insert(className, superClassName); |
#endif | #endif |
} | } |
} | } |
|
|
Array<CIMName>& subClassNames, | Array<CIMName>& subClassNames, |
NameSpace *ns) const | NameSpace *ns) const |
{ | { |
|
|
// -- Case 1: className is empty: get all class names (if deepInheritance) | // -- Case 1: className is empty: get all class names (if deepInheritance) |
// -- or just root class names (if not deepInheritance). | // -- or just root class names (if not deepInheritance). |
| |
if (className.isNull()) { |
if (className.isNull()) |
|
{ |
for (InheritanceTreeRep::Table::Iterator i = _rep->table.start();i;i++) { |
for (InheritanceTreeRep::Table::Iterator i = _rep->table.start();i;i++) |
|
{ |
InheritanceTreeNode *itn=i.value(); | InheritanceTreeNode *itn=i.value(); |
if (itn->extension) { |
if (itn->extension) |
if (!ns) continue; |
{ |
for (int j=0,m=itn->extNodes->size(); j<m; j++) { |
if (!ns) |
|
continue; |
|
for (int j=0,m=itn->extNodes->size(); j<m; j++) |
|
{ |
InheritanceTreeExt *itx=(*(itn->extNodes))[j]; | InheritanceTreeExt *itx=(*(itn->extNodes))[j]; |
if (itx->tag==ns) { |
if (itx->tag==ns) |
|
{ |
InheritanceTreeNode *itn=itx->node; | InheritanceTreeNode *itn=itx->node; |
if (deepInheritance) { |
if (deepInheritance) |
|
{ |
subClassNames.append(CIMNameUnchecked(i.key())); | subClassNames.append(CIMNameUnchecked(i.key())); |
itn->getSubClassNames(subClassNames, deepInheritance, ns); |
itn->getSubClassNames( |
|
subClassNames, deepInheritance, ns); |
} | } |
else if (!i.value()->superClass) | else if (!i.value()->superClass) |
subClassNames.append(CIMNameUnchecked(i.key())); | subClassNames.append(CIMNameUnchecked(i.key())); |
|
|
} | } |
} | } |
} | } |
|
else if (deepInheritance) |
else if (deepInheritance) { |
{ |
// Append all classes: | // Append all classes: |
subClassNames.append(CIMNameUnchecked(i.key())); | subClassNames.append(CIMNameUnchecked(i.key())); |
} | } |
else if (!i.value()->superClass) { |
else if (!i.value()->superClass) |
|
{ |
// Just append root classes: | // Just append root classes: |
subClassNames.append(CIMNameUnchecked(i.key())); | subClassNames.append(CIMNameUnchecked(i.key())); |
} | } |
|
|
// -- Case 2: className non-empty: get names of classes descendent from | // -- Case 2: className non-empty: get names of classes descendent from |
// -- the given class. | // -- the given class. |
| |
for (InheritanceTreeRep::Table::Iterator i = _rep->table.start(); i; i++) { |
for (InheritanceTreeRep::Table::Iterator i = _rep->table.start(); i; i++) |
if (className.equal (CIMNameUnchecked(i.key()))) { |
{ |
|
if (className.equal (CIMNameUnchecked(i.key()))) |
|
{ |
i.value()->getSubClassNames(subClassNames, deepInheritance, ns); | i.value()->getSubClassNames(subClassNames, deepInheritance, ns); |
return true; | return true; |
} | } |
|
|
// Not found! | // Not found! |
return false; | return false; |
} | } |
|
|
#if 0 | #if 0 |
Boolean InheritanceTree::isSubClass( | Boolean InheritanceTree::isSubClass( |
const CIMName& class1, | const CIMName& class1, |
|
|
return _rep->table.contains(className.getString()); | return _rep->table.contains(className.getString()); |
} | } |
| |
void InheritanceTree::remove(const CIMName& className, |
void InheritanceTree::remove( |
|
const CIMName& className, |
InheritanceTree &parentTree, | InheritanceTree &parentTree, |
NameSpace *tag) | NameSpace *tag) |
{ | { |
|
|
InheritanceTreeNode* node = 0; | InheritanceTreeNode* node = 0; |
| |
if (!_rep->table.lookup(className.getString(), node)) | if (!_rep->table.lookup(className.getString(), node)) |
throw PEGASUS_CIM_EXCEPTION |
throw PEGASUS_CIM_EXCEPTION( |
(CIM_ERR_INVALID_CLASS, className.getString()); |
CIM_ERR_INVALID_CLASS, className.getString()); |
| |
// -- Disallow if is has any subclasses: | // -- Disallow if is has any subclasses: |
| |
if (node->subClasses) | if (node->subClasses) |
throw PEGASUS_CIM_EXCEPTION |
throw PEGASUS_CIM_EXCEPTION( |
(CIM_ERR_CLASS_HAS_CHILDREN, className.getString()); |
CIM_ERR_CLASS_HAS_CHILDREN, className.getString()); |
| |
// -- Remove as child of superclass: | // -- Remove as child of superclass: |
| |
InheritanceTreeNode* superClass = node->superClass; | InheritanceTreeNode* superClass = node->superClass; |
| |
if (tag) { |
if (tag) |
|
{ |
InheritanceTreeNode* itn = 0; | InheritanceTreeNode* itn = 0; |
if (parentTree._rep->table.lookup(className.getString(),itn)) { |
if (parentTree._rep->table.lookup(className.getString(), itn)) |
if (itn->extension) { |
{ |
for (int j=0,m=itn->extNodes->size(); j<m; j++) { |
if (itn->extension) |
if ((*(itn->extNodes))[j]->tag==tag) { |
{ |
|
for (int j = 0, m = itn->extNodes->size(); j < m; j++) |
|
{ |
|
if ((*(itn->extNodes))[j]->tag == tag) |
|
{ |
itn->extNodes->remove(j); | itn->extNodes->remove(j); |
break; | break; |
} | } |
} | } |
if (itn->extNodes->size()==0) { |
if (itn->extNodes->size() == 0) |
|
{ |
delete itn->extNodes; | delete itn->extNodes; |
parentTree._rep->table.remove(className.getString()); | parentTree._rep->table.remove(className.getString()); |
} | } |
} | } |
} | } |
else { |
else |
|
{ |
Boolean result = superClass->removeSubClass(node); | Boolean result = superClass->removeSubClass(node); |
PEGASUS_ASSERT(result); | PEGASUS_ASSERT(result); |
} | } |
} | } |
|
|
else if (superClass) | else if (superClass) |
{ | { |
Boolean result = superClass->removeSubClass(node); | Boolean result = superClass->removeSubClass(node); |