version 1.39, 2002/05/14 03:27:25
|
version 1.49, 2002/07/30 16:14:53
|
|
|
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
// | // |
// Copyright (c) 2000, 2001 The Open group, BMC Software, Tivoli Systems, IBM |
// Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM, |
|
// The Open Group, Tivoli Systems |
// | // |
// 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 |
|
|
// | // |
// Modified By: Karl Schopmeyer(k.schopmeyer@attglobal.net) | // Modified By: Karl Schopmeyer(k.schopmeyer@attglobal.net) |
// Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com) | // Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com) |
|
// Carol Ann Krug Graves, Hewlett-Packard Company |
|
// (carolann_graves@hp.com) |
// | // |
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
#include "CIMClassRep.h" | #include "CIMClassRep.h" |
#include "DeclContext.h" | #include "DeclContext.h" |
|
#include "Resolver.h" |
#include "Indentor.h" | #include "Indentor.h" |
#include "CIMName.h" | #include "CIMName.h" |
#include "CIMQualifierNames.h" | #include "CIMQualifierNames.h" |
#include "CIMScope.h" | #include "CIMScope.h" |
#include "XmlWriter.h" | #include "XmlWriter.h" |
|
#include "MofWriter.h" |
#include <Pegasus/Common/Tracer.h> | #include <Pegasus/Common/Tracer.h> |
| |
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
PEGASUS_USING_STD; | PEGASUS_USING_STD; |
| |
CIMClassRep::CIMClassRep( | CIMClassRep::CIMClassRep( |
const CIMReference& reference, |
const CIMName& className, |
const String& superClassName) |
const CIMName& superClassName) |
: | : |
CIMObjectRep(reference), |
CIMObjectRep(CIMObjectPath(String(), CIMNamespaceName(), className)), |
_superClassName(superClassName) | _superClassName(superClassName) |
{ | { |
if (superClassName.size() && !CIMName::legal(superClassName)) |
|
throw IllegalName(); |
|
} | } |
| |
CIMClassRep::~CIMClassRep() | CIMClassRep::~CIMClassRep() |
{ | { |
|
|
} | } |
| |
Boolean CIMClassRep::isAssociation() const | Boolean CIMClassRep::isAssociation() const |
|
|
| |
const CIMValue& value = getQualifier(pos).getValue(); | const CIMValue& value = getQualifier(pos).getValue(); |
| |
if (value.getType() != CIMType::BOOLEAN) |
if (value.getType() != CIMTYPE_BOOLEAN) |
return false; | return false; |
| |
value.get(flag); | value.get(flag); |
|
|
Boolean flag; | Boolean flag; |
const CIMValue& value = getQualifier(pos).getValue(); | const CIMValue& value = getQualifier(pos).getValue(); |
| |
if (value.getType() != CIMType::BOOLEAN) |
if (value.getType() != CIMTYPE_BOOLEAN) |
return false; | return false; |
| |
value.get(flag); | value.get(flag); |
return flag; | return flag; |
} | } |
| |
Boolean CIMClassRep::isTrueQualifier(const String& name) const |
Boolean CIMClassRep::isTrueQualifier(const CIMName& name) const |
{ | { |
Uint32 pos = findQualifier(name); | Uint32 pos = findQualifier(name); |
| |
|
|
Boolean flag; | Boolean flag; |
const CIMValue& value = getQualifier(pos).getValue(); | const CIMValue& value = getQualifier(pos).getValue(); |
| |
if (value.getType() != CIMType::BOOLEAN) |
if (value.getType() != CIMTYPE_BOOLEAN) |
return false; | return false; |
| |
value.get(flag); | value.get(flag); |
return flag; | return flag; |
} | } |
| |
void CIMClassRep::setSuperClassName(const String& superClassName) |
void CIMClassRep::setSuperClassName(const CIMName& superClassName) |
{ | { |
if (!CIMName::legal(superClassName)) |
|
throw IllegalName(); |
|
|
|
_superClassName = superClassName; | _superClassName = superClassName; |
} | } |
| |
|
|
| |
// Reject addition of references to non-associations: | // Reject addition of references to non-associations: |
| |
if (!isAssociation() && x.getValue().getType() == CIMType::REFERENCE) |
if (!isAssociation() && x.getValue().getType() == CIMTYPE_REFERENCE) |
throw AddedReferenceToClass(_reference.getClassName()); | throw AddedReferenceToClass(_reference.getClassName()); |
| |
// Set the class origin: | // Set the class origin: |
// ATTN: put this check in other places: | // ATTN: put this check in other places: |
| |
if (x.getClassOrigin().size() == 0) |
if (x.getClassOrigin().isNull()) |
CIMProperty(x).setClassOrigin(_reference.getClassName()); | CIMProperty(x).setClassOrigin(_reference.getClassName()); |
| |
// Add the property: | // Add the property: |
|
|
_methods.append(x); | _methods.append(x); |
} | } |
| |
Uint32 CIMClassRep::findMethod(const String& name) const |
Uint32 CIMClassRep::findMethod(const CIMName& name) const |
{ | { |
for (Uint32 i = 0, n = _methods.size(); i < n; i++) | for (Uint32 i = 0, n = _methods.size(); i < n; i++) |
{ | { |
if (CIMName::equal(_methods[i].getName(), name)) |
if (name.equal(_methods[i].getName())) |
return i; | return i; |
} | } |
| |
return PEG_NOT_FOUND; | return PEG_NOT_FOUND; |
} | } |
| |
Boolean CIMClassRep::existsMethod(const String& name) const |
|
{ |
|
return(findMethod(name) == PEG_NOT_FOUND) ? false : true; |
|
} |
|
|
|
CIMMethod CIMClassRep::getMethod(Uint32 pos) | CIMMethod CIMClassRep::getMethod(Uint32 pos) |
{ | { |
if (pos >= _methods.size()) | if (pos >= _methods.size()) |
|
|
| |
void CIMClassRep::resolve( | void CIMClassRep::resolve( |
DeclContext* context, | DeclContext* context, |
const String& nameSpace) |
const CIMNamespaceName& nameSpace) |
{ | { |
PEG_METHOD_ENTER(TRC_OBJECTRESOLUTION, "CIMClassRep::resolve()"); | PEG_METHOD_ENTER(TRC_OBJECTRESOLUTION, "CIMClassRep::resolve()"); |
#if 0 | #if 0 |
|
|
_reference.getClassName() + ", superclass = " + | _reference.getClassName() + ", superclass = " + |
_superClassName); | _superClassName); |
| |
if (_superClassName.size()) |
if (!_superClassName.isNull()) |
{ | { |
//cout << "KSTEST Class Resolve with Super class " << getClassName() | //cout << "KSTEST Class Resolve with Super class " << getClassName() |
//<< " superClass " << _superClassName << endl; | //<< " superClass " << _superClassName << endl; |
|
|
| |
if (pos == PEG_NOT_FOUND) | if (pos == PEG_NOT_FOUND) |
{ | { |
property.resolve(context, nameSpace, false, true); |
Resolver::resolveProperty (property, context, |
|
nameSpace, false, true); |
} | } |
else | else |
{ | { |
CIMConstProperty superClassProperty = | CIMConstProperty superClassProperty = |
superClass.getProperty(pos); | superClass.getProperty(pos); |
property.resolve( |
Resolver::resolveProperty (property, context, |
context, nameSpace, false, superClassProperty, true); |
nameSpace, false, superClassProperty, true); |
} | } |
} | } |
| |
|
|
Uint32 pos = PEG_NOT_FOUND; | Uint32 pos = PEG_NOT_FOUND; |
CIMQualifier superClassQualifier = | CIMQualifier superClassQualifier = |
superproperty.getQualifier(i); | superproperty.getQualifier(i); |
const String name = superClassQualifier.getName(); |
const CIMName name = superClassQualifier.getName(); |
/* ATTN KS This is replacement find function. | /* ATTN KS This is replacement find function. |
if((Uint32 j = subproperty.findQualifier(q.getName()) == PEG_NOT_FOUND) | if((Uint32 j = subproperty.findQualifier(q.getName()) == PEG_NOT_FOUND) |
{ | { |
|
|
j++) | j++) |
{ | { |
CIMConstQualifier q = subproperty.getQualifier(j); | CIMConstQualifier q = subproperty.getQualifier(j); |
if (CIMName::equal(name, |
if (name.equal(q.getName())) |
q.getName())) |
|
{ | { |
pos = j; | pos = j; |
break; | break; |
|
|
| |
if (pos == PEG_NOT_FOUND) | if (pos == PEG_NOT_FOUND) |
{ | { |
method.resolve(context, nameSpace); |
Resolver::resolveMethod (method, context, |
|
nameSpace); |
} | } |
else | else |
{ | { |
CIMConstMethod superClassMethod = superClass.getMethod(pos); | CIMConstMethod superClassMethod = superClass.getMethod(pos); |
method.resolve(context, nameSpace, superClassMethod); |
Resolver::resolveMethod (method, context, |
|
nameSpace, superClassMethod); |
} | } |
} | } |
| |
|
|
//cout << "KSTEST Class Resolve, No Super class " << getClassName() << endl; | //cout << "KSTEST Class Resolve, No Super class " << getClassName() << endl; |
| |
for (Uint32 i = 0, n = _properties.size(); i < n; i++) | for (Uint32 i = 0, n = _properties.size(); i < n; i++) |
_properties[i].resolve(context, nameSpace, false, true); |
Resolver::resolveProperty (_properties[i], context, |
|
nameSpace, false, true); |
| |
//---------------------------------------------------------------------- | //---------------------------------------------------------------------- |
// Resolve each method: | // Resolve each method: |
//---------------------------------------------------------------------- | //---------------------------------------------------------------------- |
| |
for (Uint32 i = 0, n = _methods.size(); i < n; i++) | for (Uint32 i = 0, n = _methods.size(); i < n; i++) |
_methods[i].resolve(context, nameSpace); |
Resolver::resolveMethod (_methods[i], context, nameSpace); |
| |
//---------------------------------------------------------------------- | //---------------------------------------------------------------------- |
// Resolve the qualifiers: | // Resolve the qualifiers: |
|
|
out << "<CLASS "; | out << "<CLASS "; |
out << " NAME=\"" << _reference.getClassName() << "\" "; | out << " NAME=\"" << _reference.getClassName() << "\" "; |
| |
if (_superClassName.size()) |
if (!_superClassName.isNull()) |
out << " SUPERCLASS=\"" << _superClassName << "\" "; | out << " SUPERCLASS=\"" << _superClassName << "\" "; |
| |
out << ">\n"; | out << ">\n"; |
|
|
// Parameters: | // Parameters: |
| |
for (Uint32 i = 0, n = _properties.size(); i < n; i++) | for (Uint32 i = 0, n = _properties.size(); i < n; i++) |
_properties[i].toXml(out); |
XmlWriter::appendPropertyElement(out, _properties[i]); |
| |
// Methods: | // Methods: |
| |
for (Uint32 i = 0, n = _methods.size(); i < n; i++) | for (Uint32 i = 0, n = _methods.size(); i < n; i++) |
_methods[i].toXml(out); |
XmlWriter::appendMethodElement(out, _methods[i]); |
| |
// Class closing element: | // Class closing element: |
| |
|
|
// output class statement | // output class statement |
out << "class " << _reference.getClassName(); | out << "class " << _reference.getClassName(); |
| |
if (_superClassName.size()) |
if (!_superClassName.isNull()) |
out << " : " << _superClassName; | out << " : " << _superClassName; |
| |
out << "\n{"; | out << "\n{"; |
|
|
// there is an error in getclass that does not | // there is an error in getclass that does not |
// test the localOnly flag. | // test the localOnly flag. |
if (!_properties[i].getPropagated()) | if (!_properties[i].getPropagated()) |
_properties[i].toMof(out); |
MofWriter::appendPropertyElement(out, _properties[i]); |
} | } |
| |
// Format the Methods: for non-propagated methods | // Format the Methods: for non-propagated methods |
for (Uint32 i = 0, n = _methods.size(); i < n; i++) | for (Uint32 i = 0, n = _methods.size(); i < n; i++) |
{ | { |
if (!_methods[i].getPropagated()) | if (!_methods[i].getPropagated()) |
_methods[i].toMof(out); |
MofWriter::appendMethodElement(out, _methods[i]); |
} | } |
| |
// Class closing element: | // Class closing element: |
out << "\n};\n"; | out << "\n};\n"; |
} | } |
| |
void CIMClassRep::print(PEGASUS_STD(ostream) &os) const |
|
{ |
|
Array<Sint8> tmp; |
|
toXml(tmp); |
|
tmp.append('\0'); |
|
XmlWriter::indentedPrint(os, tmp.getData(), 4); |
|
} |
|
|
|
void CIMClassRep::printMof(PEGASUS_STD(ostream) &os) const |
|
{ |
|
Array<Sint8> tmp; |
|
toMof(tmp); |
|
tmp.append('\0'); |
|
os << tmp.getData() << PEGASUS_STD(endl); |
|
} |
|
|
|
| |
CIMClassRep::CIMClassRep() | CIMClassRep::CIMClassRep() |
{ | { |
|
|
} | } |
| |
CIMClassRep::CIMClassRep(const CIMClassRep& x) : | CIMClassRep::CIMClassRep(const CIMClassRep& x) : |
CIMObjectRep(x), | CIMObjectRep(x), |
_superClassName(x._superClassName) | _superClassName(x._superClassName) |
{ | { |
_methods.reserve(x._methods.size()); |
_methods.reserveCapacity(x._methods.size()); |
| |
for (Uint32 i = 0, n = x._methods.size(); i < n; i++) | for (Uint32 i = 0, n = x._methods.size(); i < n; i++) |
_methods.append(x._methods[i].clone()); | _methods.append(x._methods[i].clone()); |
|
|
return true; | return true; |
} | } |
| |
void CIMClassRep::getKeyNames(Array<String>& keyNames) const |
void CIMClassRep::getKeyNames(Array<CIMName>& keyNames) const |
{ | { |
keyNames.clear(); | keyNames.clear(); |
| |