version 1.7, 2001/04/29 18:57:33
|
version 1.20, 2001/12/22 02:15:15
|
|
|
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
// | // |
// Copyright (c) 2000 The Open Group, BMC Software, Tivoli Systems, IBM |
// Copyright (c) 2000, 2001 The Open group, BMC Software, Tivoli Systems, IBM |
// | // |
// Permission is hereby granted, free of charge, to any person obtaining a |
// Permission is hereby granted, free of charge, to any person obtaining a copy |
// copy of this software and associated documentation files (the "Software"), |
// of this software and associated documentation files (the "Software"), to |
// to deal in the Software without restriction, including without limitation |
// deal in the Software without restriction, including without limitation the |
// the rights to use, copy, modify, merge, publish, distribute, sublicense, |
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
// and/or sell copies of the Software, and to permit persons to whom the |
// sell copies of the Software, and to permit persons to whom the Software is |
// Software is furnished to do so, subject to the following conditions: |
// furnished to do so, subject to the following conditions: |
// | // |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
// THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN |
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED |
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT |
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
// DEALINGS IN THE SOFTWARE. |
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
// | // |
//============================================================================== | //============================================================================== |
// | // |
|
|
CIMClassRep::CIMClassRep( | CIMClassRep::CIMClassRep( |
const String& className, | const String& className, |
const String& superClassName) | const String& superClassName) |
: _className(className), _superClassName(superClassName), _resolved(false) |
: |
|
CIMObjectRep(className), |
|
_superClassName(superClassName) |
{ | { |
if (!CIMName::legal(className)) |
|
throw IllegalName(); |
|
|
|
if (superClassName.size() && !CIMName::legal(superClassName)) | if (superClassName.size() && !CIMName::legal(superClassName)) |
throw IllegalName(); | throw IllegalName(); |
} | } |
|
|
{ | { |
Uint32 pos = findQualifier(CIMQualifierNames::ASSOCIATION); | Uint32 pos = findQualifier(CIMQualifierNames::ASSOCIATION); |
| |
if (pos == Uint32(-1)) |
if (pos == PEG_NOT_FOUND) |
return false; | return false; |
| |
Boolean flag; | Boolean flag; |
|
|
{ | { |
Uint32 pos = findQualifier(CIMQualifierNames::ABSTRACT); | Uint32 pos = findQualifier(CIMQualifierNames::ABSTRACT); |
| |
if (pos == Uint32(-1)) |
if (pos == PEG_NOT_FOUND) |
return false; | return false; |
| |
Boolean flag; | Boolean flag; |
|
|
| |
// Reject addition of duplicate property name: | // Reject addition of duplicate property name: |
| |
if (findProperty(x.getName()) != Uint32(-1)) |
if (findProperty(x.getName()) != PEG_NOT_FOUND) |
throw AlreadyExists(); | throw AlreadyExists(); |
| |
// Reject addition of references to non-associations: | // Reject addition of references to non-associations: |
|
|
_properties.append(x); | _properties.append(x); |
} | } |
| |
void CIMClassRep::removeProperty(Uint32 pos) |
|
{ |
|
if (pos >= _properties.size()) |
|
throw OutOfBounds(); |
|
} |
|
|
|
Uint32 CIMClassRep::findProperty(const String& name) |
|
{ |
|
for (Uint32 i = 0, n = _properties.size(); i < n; i++) |
|
{ |
|
if (CIMName::equal(_properties[i].getName(), name)) |
|
return i; |
|
} |
|
|
|
return Uint32(-1); |
|
} |
|
|
|
CIMProperty CIMClassRep::getProperty(Uint32 pos) |
|
{ |
|
if (pos >= _properties.size()) |
|
throw OutOfBounds(); |
|
|
|
return _properties[pos]; |
|
} |
|
|
|
Uint32 CIMClassRep::getPropertyCount() const |
|
{ |
|
return _properties.size(); |
|
} |
|
|
|
void CIMClassRep::addMethod(const CIMMethod& x) | void CIMClassRep::addMethod(const CIMMethod& x) |
{ | { |
if (!x) | if (!x) |
|
|
| |
// Reject duplicate method names: | // Reject duplicate method names: |
| |
if (findMethod(x.getName()) != Uint32(-1)) |
if (findMethod(x.getName()) != PEG_NOT_FOUND) |
throw AlreadyExists(); | throw AlreadyExists(); |
| |
// Add the method: | // Add the method: |
|
|
return i; | return i; |
} | } |
| |
return Uint32(-1); |
return PEG_NOT_FOUND; |
|
} |
|
|
|
Boolean CIMClassRep::existsMethod(const String& name) |
|
{ |
|
return(findMethod(name) == PEG_NOT_FOUND) ? false : true; |
} | } |
| |
CIMMethod CIMClassRep::getMethod(Uint32 pos) | CIMMethod CIMClassRep::getMethod(Uint32 pos) |
|
|
return _methods.size(); | return _methods.size(); |
} | } |
| |
|
void CIMClassRep::removeMethod(Uint32 pos) |
|
{ |
|
if (pos >= _methods.size()) |
|
throw OutOfBounds(); |
|
|
|
_methods.remove(pos); |
|
} |
|
|
void CIMClassRep::resolve( | void CIMClassRep::resolve( |
DeclContext* context, | DeclContext* context, |
const String& nameSpace) | const String& nameSpace) |
|
|
= context->lookupClass(nameSpace, _superClassName); | = context->lookupClass(nameSpace, _superClassName); |
| |
if (!superClass) | if (!superClass) |
throw NoSuchSuperClass(_superClassName); |
throw PEGASUS_CIM_EXCEPTION(CIM_ERR_INVALID_SUPERCLASS,_superClassName); |
| |
#if 0 | #if 0 |
if (!superClass._rep->_resolved) | if (!superClass._rep->_resolved) |
|
|
CIMProperty& property = _properties[i]; | CIMProperty& property = _properties[i]; |
Uint32 pos = superClass.findProperty(property.getName()); | Uint32 pos = superClass.findProperty(property.getName()); |
| |
if (pos == Uint32(-1)) |
if (pos == PEG_NOT_FOUND) |
{ | { |
property.resolve(context, nameSpace, false); | property.resolve(context, nameSpace, false); |
} | } |
else | else |
{ | { |
CIMConstProperty superClassProperty = superClass.getProperty(pos); |
CIMConstProperty superClassProperty = |
|
superClass.getProperty(pos); |
property.resolve(context, nameSpace, false, superClassProperty); | property.resolve(context, nameSpace, false, superClassProperty); |
} | } |
} | } |
|
|
// insert it (setting the propagated flag). Otherwise, change | // insert it (setting the propagated flag). Otherwise, change |
// the class-origin and propagated flag accordingly. | // the class-origin and propagated flag accordingly. |
| |
Uint32 pos = Uint32(-1); |
Uint32 pos = PEG_NOT_FOUND; |
| |
for (Uint32 j = m, n = _properties.size(); j < n; j++) | for (Uint32 j = m, n = _properties.size(); j < n; j++) |
{ | { |
|
|
// clone and insert it. Otherwise, the properties class | // clone and insert it. Otherwise, the properties class |
// origin was set above. | // origin was set above. |
| |
if (pos == Uint32(-1)) |
if (pos == PEG_NOT_FOUND) |
{ | { |
CIMProperty property = superClassProperty.clone(); | CIMProperty property = superClassProperty.clone(); |
property.setPropagated(true); | property.setPropagated(true); |
|
|
CIMMethod& method = _methods[i]; | CIMMethod& method = _methods[i]; |
Uint32 pos = superClass.findMethod(method.getName()); | Uint32 pos = superClass.findMethod(method.getName()); |
| |
if (pos == Uint32(-1)) |
if (pos == PEG_NOT_FOUND) |
{ | { |
method.resolve(context, nameSpace); | method.resolve(context, nameSpace); |
} | } |
|
|
// insert it (setting the propagated flag). Otherwise, change | // insert it (setting the propagated flag). Otherwise, change |
// the class-origin and propagated flag accordingly. | // the class-origin and propagated flag accordingly. |
| |
Uint32 pos = Uint32(-1); |
Uint32 pos = PEG_NOT_FOUND; |
| |
for (Uint32 j = m, n = _methods.size(); j < n; j++) | for (Uint32 j = m, n = _methods.size(); j < n; j++) |
{ | { |
|
|
// clone and insert it. Otherwise, the method's class origin | // clone and insert it. Otherwise, the method's class origin |
// has already been set above. | // has already been set above. |
| |
if (pos == Uint32(-1)) |
if (pos == PEG_NOT_FOUND) |
{ | { |
CIMMethod method = superClassMethod.clone(); | CIMMethod method = superClassMethod.clone(); |
method.setPropagated(true); | method.setPropagated(true); |
|
|
| |
out << "</CLASS>\n"; | out << "</CLASS>\n"; |
} | } |
|
/** toMof prepares an 8-bit string with the MOF for the class. |
|
The BNF for this is: |
|
<pre> |
|
classDeclaration = [ qualifierList ] |
|
CLASS className [ alias ] [ superClass ] |
|
"{" *classFeature "}" ";" |
|
|
|
superClass = :" className |
|
|
|
classFeature = propertyDeclaration | methodDeclaration |
| |
void CIMClassRep::print(std::ostream &os) const |
*/ |
|
|
|
void CIMClassRep::toMof(Array<Sint8>& out) const |
|
{ |
|
// Get and format the class qualifiers |
|
out << "\n// Class " << _className; |
|
if (_qualifiers.getCount()) |
|
out << "\n"; |
|
_qualifiers.toMof(out); |
|
|
|
// Separate qualifiers from Class Name |
|
out << "\n"; |
|
|
|
// output class statement |
|
out << "class " << _className; |
|
|
|
if (_superClassName.size()) |
|
out << " : " << _superClassName; |
|
|
|
out << "\n{"; |
|
|
|
// format the Properties: |
|
for (Uint32 i = 0, n = _properties.size(); i < n; i++) |
|
{ |
|
// Generate MOF if this property not propogated |
|
// Note that the test is required only because |
|
// there is an error in getclass that does not |
|
// test the localOnly flag. |
|
if (!_properties[i].getPropagated()) |
|
_properties[i].toMof(out); |
|
} |
|
|
|
// Format the Methods: for non-propagated methods |
|
for (Uint32 i = 0, n = _methods.size(); i < n; i++) |
|
{ |
|
if (!_methods[i].getPropagated()) |
|
_methods[i].toMof(out); |
|
} |
|
|
|
// Class closing element: |
|
out << "\n};\n"; |
|
} |
|
|
|
void CIMClassRep::print(PEGASUS_STD(ostream) &os) const |
{ | { |
Array<Sint8> tmp; | Array<Sint8> tmp; |
toXml(tmp); | toXml(tmp); |
|
|
// cout << tmp.getData() << endl; | // cout << tmp.getData() << endl; |
} | } |
| |
|
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) : |
Sharable(), |
CIMObjectRep(x), |
_className(x._className), |
_superClassName(x._superClassName) |
_superClassName(x._superClassName), |
|
_resolved(x._resolved) |
|
{ | { |
x._qualifiers.cloneTo(_qualifiers); |
|
|
|
_properties.reserve(x._properties.size()); |
|
|
|
for (Uint32 i = 0, n = x._properties.size(); i < n; i++) |
|
_properties.append(x._properties[i].clone()); |
|
|
|
_methods.reserve(x._methods.size()); | _methods.reserve(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()); |
} | } |
| |
CIMClassRep& CIMClassRep::operator=(const CIMClassRep& x) |
|
{ |
|
return *this; |
|
} |
|
|
|
Boolean CIMClassRep::identical(const CIMClassRep* x) const | Boolean CIMClassRep::identical(const CIMClassRep* x) const |
{ | { |
if (_className != x->_className) |
if (!CIMObjectRep::identical(x)) |
return false; | return false; |
| |
if (_superClassName != x->_superClassName) | if (_superClassName != x->_superClassName) |
return false; | return false; |
| |
if (!_qualifiers.identical(x->_qualifiers)) |
// |
return false; |
// Check methods: |
|
// |
// Compare properties: |
|
|
|
{ |
|
const Array<CIMProperty>& tmp1 = _properties; |
|
const Array<CIMProperty>& tmp2 = x->_properties; |
|
|
|
if (tmp1.size() != tmp2.size()) |
|
return false; |
|
|
|
for (Uint32 i = 0, n = tmp1.size(); i < n; i++) |
|
{ |
|
if (!tmp1[i].identical(tmp2[i])) |
|
return false; |
|
} |
|
} |
|
|
|
// Compare methods: |
|
| |
{ | { |
const Array<CIMMethod>& tmp1 = _methods; | const Array<CIMMethod>& tmp1 = _methods; |
|
|
} | } |
} | } |
| |
|
Boolean CIMClassRep::hasKeys() const |
|
{ |
|
for (Uint32 i = 0, n = getPropertyCount(); i < n; i++) |
|
{ |
|
CIMConstProperty property = getProperty(i); |
|
|
|
if (getProperty(i).isKey()) |
|
return true; |
|
} |
|
|
|
return false; |
|
} |
|
|
PEGASUS_NAMESPACE_END | PEGASUS_NAMESPACE_END |
|
|