version 1.11, 2001/06/16 23:09:59
|
version 1.56, 2008/03/05 21:31:44
|
|
|
//%///////////////////////////////////////////////////////////////////////////// |
//%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 <cassert> |
#include <Pegasus/Common/Config.h> |
#include "CIMMethod.h" | #include "CIMMethod.h" |
#include "Indentor.h" |
#include "CIMMethodRep.h" |
|
#include "Resolver.h" |
#include "CIMName.h" | #include "CIMName.h" |
#include "CIMScope.h" | #include "CIMScope.h" |
#include "XmlWriter.h" |
#include <Pegasus/Common/MessageLoader.h> |
|
#include "StrLit.h" |
| |
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
| |
|
CIMMethodRep::CIMMethodRep(const CIMMethodRep& x) : |
|
Sharable(), |
|
_name(x._name), |
|
_type(x._type), |
|
_classOrigin(x._classOrigin), |
|
_propagated(x._propagated), |
|
_ownerCount(0) |
|
{ |
|
x._qualifiers.cloneTo(_qualifiers); |
|
// Set the CIM name tag. |
|
_nameTag = generateCIMNameTag(_name); |
|
|
|
_parameters.reserveCapacity(x._parameters.size()); |
|
|
|
for (Uint32 i = 0, n = x._parameters.size(); i < n; i++) |
|
{ |
|
_parameters.append(x._parameters[i].clone()); |
|
} |
|
} |
|
|
CIMMethodRep::CIMMethodRep( | CIMMethodRep::CIMMethodRep( |
const String& name, |
const CIMName& name, |
CIMType type, | CIMType type, |
const String& classOrigin, |
const CIMName& classOrigin, |
Boolean propagated) | Boolean propagated) |
: _name(name), _type(type), | : _name(name), _type(type), |
_classOrigin(classOrigin), _propagated(propagated) |
_classOrigin(classOrigin), |
|
_propagated(propagated), |
|
_ownerCount(0) |
{ | { |
if (!CIMName::legal(name)) |
// ensure name is not null |
throw IllegalName(); |
if (name.isNull()) |
|
{ |
if (classOrigin.size() && !CIMName::legal(classOrigin)) |
throw UninitializedObjectException(); |
throw IllegalName(); |
} |
|
// Set the CIM name tag. |
if (type == CIMType::NONE) |
_nameTag = generateCIMNameTag(_name); |
throw NullType(); |
|
} | } |
| |
CIMMethodRep::~CIMMethodRep() | CIMMethodRep::~CIMMethodRep() |
{ | { |
|
|
} | } |
| |
void CIMMethodRep::setName(const String& name) |
void CIMMethodRep::setName(const CIMName& name) |
{ | { |
if (!CIMName::legal(name)) |
// ensure name is not null |
throw IllegalName(); |
if (name.isNull()) |
|
{ |
|
throw UninitializedObjectException(); |
|
} |
|
if (_ownerCount != 0 && _name != name) |
|
{ |
|
MessageLoaderParms parms( |
|
"Common.CIMMethodRep.CONTAINED_METHOD_NAMECHANGEDEXCEPTION", |
|
"Attempted to change the name of a method" |
|
" already in a container."); |
|
throw Exception(parms); |
|
} |
_name = name; | _name = name; |
|
// Set the CIM name tag. |
|
_nameTag = generateCIMNameTag(_name); |
} | } |
| |
void CIMMethodRep::setClassOrigin(const String& classOrigin) |
void CIMMethodRep::setClassOrigin(const CIMName& classOrigin) |
{ | { |
if (!CIMName::legal(classOrigin)) |
|
throw IllegalName(); |
|
|
|
_classOrigin = classOrigin; | _classOrigin = classOrigin; |
} | } |
| |
void CIMMethodRep::addParameter(const CIMParameter& x) | void CIMMethodRep::addParameter(const CIMParameter& x) |
{ | { |
if (!x) |
if (x.isUninitialized()) |
throw UnitializedHandle(); |
throw UninitializedObjectException(); |
| |
if (findParameter(x.getName()) != PEG_NOT_FOUND) | if (findParameter(x.getName()) != PEG_NOT_FOUND) |
throw AlreadyExists(); |
{ |
|
MessageLoaderParms parms("Common.CIMMethodRep.PARAMETER", |
|
"parameter \"$0\"", |
|
x.getName().getString()); |
|
throw AlreadyExistsException(parms); |
|
} |
| |
_parameters.append(x); | _parameters.append(x); |
} | } |
| |
Uint32 CIMMethodRep::findParameter(const String& name) |
Uint32 CIMMethodRep::findParameter(const CIMName& name) const |
{ |
|
for (Uint32 i = 0, n = _parameters.size(); i < n; i++) |
|
{ | { |
if (CIMName::equal(_parameters[i].getName(), name)) |
return _parameters.find(name, generateCIMNameTag(name)); |
return i; |
|
} | } |
| |
return PEG_NOT_FOUND; |
CIMParameter CIMMethodRep::getParameter(Uint32 index) |
|
{ |
|
if (index >= _parameters.size()) |
|
throw IndexOutOfBoundsException(); |
|
|
|
return _parameters[index]; |
} | } |
| |
CIMParameter CIMMethodRep::getParameter(Uint32 pos) |
void CIMMethodRep::removeParameter(Uint32 index) |
{ | { |
if (pos >= _parameters.size()) |
if (index >= _parameters.size()) |
throw OutOfBounds(); |
throw IndexOutOfBoundsException(); |
| |
return _parameters[pos]; |
_parameters.remove (index); |
} | } |
| |
Uint32 CIMMethodRep::getParameterCount() const | Uint32 CIMMethodRep::getParameterCount() const |
|
|
| |
void CIMMethodRep::resolve( | void CIMMethodRep::resolve( |
DeclContext* declContext, | DeclContext* declContext, |
const String& nameSpace, |
const CIMNamespaceName& nameSpace, |
const CIMConstMethod& inheritedMethod) | const CIMConstMethod& inheritedMethod) |
{ | { |
// ATTN: Check to see if this method has same signature as | // ATTN: Check to see if this method has same signature as |
|
|
| |
// Check for type mismatch between return types. | // Check for type mismatch between return types. |
| |
assert (inheritedMethod); |
PEGASUS_ASSERT(!inheritedMethod.isUninitialized()); |
| |
// Validate the qualifiers of the method (according to | // Validate the qualifiers of the method (according to |
// superClass's method with the same name). This method | // superClass's method with the same name). This method |
|
|
nameSpace, | nameSpace, |
CIMScope::METHOD, | CIMScope::METHOD, |
false, | false, |
inheritedMethod._rep->_qualifiers); |
inheritedMethod._rep->_qualifiers, |
|
true); |
| |
// Validate each of the parameters: | // Validate each of the parameters: |
| |
for (size_t i = 0; i < _parameters.size(); i++) |
for (Uint32 i = 0; i < _parameters.size(); i++) |
_parameters[i].resolve(declContext, nameSpace); |
Resolver::resolveParameter (_parameters[i], declContext, nameSpace); |
| |
_classOrigin = inheritedMethod.getClassOrigin(); | _classOrigin = inheritedMethod.getClassOrigin(); |
} | } |
| |
void CIMMethodRep::resolve( | void CIMMethodRep::resolve( |
DeclContext* declContext, | DeclContext* declContext, |
const String& nameSpace) |
const CIMNamespaceName& nameSpace) |
{ | { |
// Validate the qualifiers: | // Validate the qualifiers: |
| |
|
|
nameSpace, | nameSpace, |
CIMScope::METHOD, | CIMScope::METHOD, |
false, | false, |
dummy); |
dummy, |
|
true); |
| |
// Validate each of the parameters: | // Validate each of the parameters: |
| |
for (size_t i = 0; i < _parameters.size(); i++) |
for (Uint32 i = 0; i < _parameters.size(); i++) |
_parameters[i].resolve(declContext, nameSpace); |
Resolver::resolveParameter (_parameters[i], declContext, nameSpace); |
} |
|
|
|
static const char* _toString(Boolean x) |
|
{ |
|
return x ? "true" : "false"; |
|
} | } |
| |
void CIMMethodRep::toXml(Array<Sint8>& out) const |
Boolean CIMMethodRep::identical(const CIMMethodRep* x) const |
{ |
|
out << "<METHOD"; |
|
|
|
out << " NAME=\"" << _name << "\""; |
|
|
|
out << " TYPE=\"" << TypeToString(_type) << "\""; |
|
|
|
if (_classOrigin.size()) |
|
out << " CLASSORIGIN=\"" << _classOrigin << "\""; |
|
|
|
if (_propagated != false) |
|
out << " PROPAGATED=\"" << _toString(_propagated) << "\""; |
|
|
|
out << ">\n"; |
|
|
|
_qualifiers.toXml(out); |
|
|
|
for (Uint32 i = 0, n = _parameters.size(); i < n; i++) |
|
_parameters[i].toXml(out); |
|
|
|
out << "</METHOD>\n"; |
|
} |
|
|
|
void CIMMethodRep::print(PEGASUS_STD(ostream) &os) const |
|
{ |
|
Array<Sint8> tmp; |
|
toXml(tmp); |
|
tmp.append('\0'); |
|
os << tmp.getData() << PEGASUS_STD(endl); |
|
} |
|
|
|
CIMMethodRep::CIMMethodRep() |
|
{ |
|
|
|
} |
|
|
|
CIMMethodRep::CIMMethodRep(const CIMMethodRep& x) : |
|
Sharable(), |
|
_name(x._name), |
|
_type(x._type), |
|
_classOrigin(x._classOrigin), |
|
_propagated(x._propagated) |
|
{ | { |
x._qualifiers.cloneTo(_qualifiers); |
// If the pointers are the same, the objects must be identical |
|
if (this == x) |
_parameters.reserve(x._parameters.size()); |
|
|
|
for (Uint32 i = 0, n = x._parameters.size(); i < n; i++) |
|
_parameters.append(x._parameters[i].clone()); |
|
} |
|
|
|
CIMMethodRep& CIMMethodRep::operator=(const CIMMethodRep& x) |
|
{ | { |
return *this; |
return true; |
} | } |
| |
Boolean CIMMethodRep::identical(const CIMMethodRep* x) const |
if (!_name.equal (x->_name)) |
{ |
|
if (_name != x->_name) |
|
return false; | return false; |
| |
if (_type != x->_type) | if (_type != x->_type) |
|
|
void CIMMethodRep::setType(CIMType type) | void CIMMethodRep::setType(CIMType type) |
{ | { |
_type = type; | _type = type; |
|
|
if (type == CIMType::NONE) |
|
throw NullType(); |
|
} | } |
| |
PEGASUS_NAMESPACE_END | PEGASUS_NAMESPACE_END |