version 1.2, 2002/05/16 03:07:02
|
version 1.10, 2002/08/19 17:43:23
|
|
|
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
// | // |
// 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 |
|
|
// Author: Mike Brasher (mbrasher@bmc.com) | // Author: Mike Brasher (mbrasher@bmc.com) |
// | // |
// Modified By: Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com) | // Modified By: Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com) |
|
// Carol Ann Krug Graves, Hewlett-Packard Company |
|
// (carolann_graves@hp.com) |
// | // |
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
|
|
} | } |
| |
KeyBindingRep( | KeyBindingRep( |
const String& name, |
const CIMName& name, |
const String& value, | const String& value, |
KeyBinding::Type type) | KeyBinding::Type type) |
: _name(name), _value(value), _type(type) | : _name(name), _value(value), _type(type) |
|
|
return *this; | return *this; |
} | } |
| |
String _name; |
CIMName _name; |
String _value; | String _value; |
KeyBinding::Type _type; | KeyBinding::Type _type; |
}; | }; |
|
|
_rep = new KeyBindingRep(*x._rep); | _rep = new KeyBindingRep(*x._rep); |
} | } |
| |
KeyBinding::KeyBinding(const String& name, const String& value, Type type) |
KeyBinding::KeyBinding(const CIMName& name, const String& value, Type type) |
{ | { |
_rep = new KeyBindingRep(name, value, type); | _rep = new KeyBindingRep(name, value, type); |
} | } |
|
|
return *this; | return *this; |
} | } |
| |
const String& KeyBinding::getName() const |
const CIMName& KeyBinding::getName() const |
{ | { |
return _rep->_name; | return _rep->_name; |
} | } |
| |
void KeyBinding::setName(const String& name) |
void KeyBinding::setName(const CIMName& name) |
{ | { |
_rep->_name = name; | _rep->_name = name; |
} | } |
|
|
_rep->_type = type; | _rep->_type = type; |
} | } |
| |
const char* KeyBinding::typeToString(KeyBinding::Type type) |
|
{ |
|
switch (type) |
|
{ |
|
case KeyBinding::BOOLEAN: |
|
return "boolean"; |
|
|
|
case KeyBinding::STRING: |
|
return "string"; |
|
|
|
case KeyBinding::NUMERIC: |
|
return "numeric"; |
|
|
|
case KeyBinding::REFERENCE: |
|
default: |
|
PEGASUS_ASSERT(false); |
|
} |
|
|
|
return "unknown"; |
|
} |
|
|
|
Boolean operator==(const KeyBinding& x, const KeyBinding& y) | Boolean operator==(const KeyBinding& x, const KeyBinding& y) |
{ | { |
return | return |
CIMName::equal(x.getName(), y.getName()) && |
x.getName().equal(y.getName()) && |
String::equal(x.getValue(), y.getValue()) && | String::equal(x.getValue(), y.getValue()) && |
x.getType() == y.getType(); | x.getType() == y.getType(); |
} | } |
|
|
| |
CIMObjectPathRep( | CIMObjectPathRep( |
const String& host, | const String& host, |
const String& nameSpace, |
const CIMNamespaceName& nameSpace, |
const String& className, |
const CIMName& className, |
const Array<KeyBinding>& keyBindings) | const Array<KeyBinding>& keyBindings) |
: _host(host), _nameSpace(nameSpace), | : _host(host), _nameSpace(nameSpace), |
_className(className), _keyBindings(keyBindings) | _className(className), _keyBindings(keyBindings) |
|
|
// | // |
String _host; | String _host; |
| |
String _nameSpace; |
CIMNamespaceName _nameSpace; |
String _className; |
CIMName _className; |
Array<KeyBinding> _keyBindings; | Array<KeyBinding> _keyBindings; |
}; | }; |
| |
|
|
_rep = new CIMObjectPathRep(*tmpRef._rep); | _rep = new CIMObjectPathRep(*tmpRef._rep); |
} | } |
| |
CIMObjectPath::CIMObjectPath(const char* objectName) |
|
{ |
|
// Test the objectName out to see if we get an exception |
|
CIMObjectPath tmpRef; |
|
tmpRef.set(objectName); |
|
|
|
_rep = new CIMObjectPathRep(*tmpRef._rep); |
|
} |
|
|
|
CIMObjectPath::CIMObjectPath( | CIMObjectPath::CIMObjectPath( |
const String& host, | const String& host, |
const String& nameSpace, |
const CIMNamespaceName& nameSpace, |
const String& className, |
const CIMName& className, |
const Array<KeyBinding>& keyBindings) | const Array<KeyBinding>& keyBindings) |
{ | { |
// Test the objectName out to see if we get an exception | // Test the objectName out to see if we get an exception |
|
|
| |
void CIMObjectPath::set( | void CIMObjectPath::set( |
const String& host, | const String& host, |
const String& nameSpace, |
const CIMNamespaceName& nameSpace, |
const String& className, |
const CIMName& className, |
const Array<KeyBinding>& keyBindings) throw(IllformedObjectName, IllegalName) |
const Array<KeyBinding>& keyBindings) |
{ | { |
setHost(host); | setHost(host); |
setNameSpace(nameSpace); | setNameSpace(nameSpace); |
|
|
Boolean CIMObjectPath::_parseHostElement( | Boolean CIMObjectPath::_parseHostElement( |
const String& objectName, | const String& objectName, |
char*& p, | char*& p, |
String& host) throw(IllformedObjectName) |
String& host) |
{ | { |
// See if there is a host name (true if it begins with "//"): | // See if there is a host name (true if it begins with "//"): |
// Host is of the from <hostname>-<port> and begins with "//" | // Host is of the from <hostname>-<port> and begins with "//" |
|
|
char* q = p; | char* q = p; |
| |
if (!isalpha(*q)) | if (!isalpha(*q)) |
throw IllformedObjectName(objectName); |
throw MalformedObjectNameException(objectName); |
| |
q++; | q++; |
| |
|
|
// Check for a port number: | // Check for a port number: |
| |
if (!isdigit(*q)) | if (!isdigit(*q)) |
throw IllformedObjectName(objectName); |
throw MalformedObjectNameException(objectName); |
| |
while (isdigit(*q)) | while (isdigit(*q)) |
q++; | q++; |
|
|
if (*q != '/') | if (*q != '/') |
{ | { |
host.clear(); | host.clear(); |
throw IllformedObjectName(objectName); |
throw MalformedObjectNameException(objectName); |
} | } |
| |
p = ++q; | p = ++q; |
|
|
Boolean CIMObjectPath::_parseNamespaceElement( | Boolean CIMObjectPath::_parseNamespaceElement( |
const String& objectName, | const String& objectName, |
char*& p, | char*& p, |
String& nameSpace) |
CIMNamespaceName& nameSpace) |
{ | { |
// If we don't find a valid namespace name followed by a ':', we | // If we don't find a valid namespace name followed by a ':', we |
// assume we're not looking at a namespace name. | // assume we're not looking at a namespace name. |
| |
|
char* colon = strchr(p, ':'); |
|
if (!colon) |
|
{ |
|
return false; |
|
} |
|
|
//---------------------------------------------------------------------- | //---------------------------------------------------------------------- |
// Validate the namespace path. Namespaces must match the following | // Validate the namespace path. Namespaces must match the following |
// regular expression: "[A-Za-z_]+(/[A-Za-z_]+)*" | // regular expression: "[A-Za-z_]+(/[A-Za-z_]+)*" |
//---------------------------------------------------------------------- | //---------------------------------------------------------------------- |
| |
char* q = p; |
String namespaceName = String(p, colon - p); |
|
if (!CIMNamespaceName::legal(namespaceName)) |
for (;;) |
|
{ |
|
// Pass the next token: |
|
|
|
if (!*q || (!isalpha(*q) && *q != '_')) |
|
return false; |
|
|
|
q++; |
|
|
|
while (isalnum(*q) || *q == '_') |
|
q++; |
|
|
|
if (!*q) |
|
return false; |
|
|
|
if (*q == ':') |
|
break; |
|
|
|
if (*q == '/') |
|
{ | { |
q++; |
throw MalformedObjectNameException(objectName); |
continue; |
|
} | } |
|
nameSpace = namespaceName; |
| |
return false; |
p = colon+1; |
} |
|
|
|
nameSpace.assign(p, q - p); |
|
p = ++q; |
|
return true; | return true; |
} | } |
| |
|
|
void CIMObjectPath::_parseKeyBindingPairs( | void CIMObjectPath::_parseKeyBindingPairs( |
const String& objectName, | const String& objectName, |
char*& p, | char*& p, |
Array<KeyBinding>& keyBindings) throw(IllformedObjectName) |
Array<KeyBinding>& keyBindings) |
{ | { |
// Get the key-value pairs: | // Get the key-value pairs: |
| |
|
|
{ | { |
// Get key part: | // Get key part: |
| |
char* key = strtok(p, "="); |
char* equalsign = strchr(p, '='); |
|
if (!equalsign) |
if (!key) |
|
{ | { |
throw IllformedObjectName(objectName); |
throw MalformedObjectNameException(objectName); |
} | } |
| |
String keyString(key); |
*equalsign = 0; |
|
CIMName keyString(p); |
| |
if (!CIMName::legal(keyString)) | if (!CIMName::legal(keyString)) |
throw IllformedObjectName(objectName); |
throw MalformedObjectNameException(objectName); |
| |
// Get the value part: | // Get the value part: |
| |
String valueString; | String valueString; |
p = p + strlen(key) + 1; |
p = equalsign + 1; |
KeyBinding::Type type; | KeyBinding::Type type; |
| |
if (*p == 'R') | if (*p == 'R') |
|
|
type = KeyBinding::REFERENCE; | type = KeyBinding::REFERENCE; |
| |
if (*p++ != '"') | if (*p++ != '"') |
throw IllformedObjectName(objectName); |
throw MalformedObjectNameException(objectName); |
| |
while (*p && *p != '"') | while (*p && *p != '"') |
{ | { |
|
|
} | } |
| |
if (*p++ != '"') | if (*p++ != '"') |
throw IllformedObjectName(objectName); |
throw MalformedObjectNameException(objectName); |
} | } |
else if (*p == '"') | else if (*p == '"') |
{ | { |
|
|
} | } |
| |
if (*p++ != '"') | if (*p++ != '"') |
throw IllformedObjectName(objectName); |
throw MalformedObjectNameException(objectName); |
} | } |
else if (toupper(*p) == 'T' || toupper(*p) == 'F') | else if (toupper(*p) == 'T' || toupper(*p) == 'F') |
{ | { |
|
|
| |
if (!(((strncmp(p, "TRUE", n) == 0) && n == 4) || | if (!(((strncmp(p, "TRUE", n) == 0) && n == 4) || |
((strncmp(p, "FALSE", n) == 0) && n == 5))) | ((strncmp(p, "FALSE", n) == 0) && n == 5))) |
throw IllformedObjectName(objectName); |
throw MalformedObjectNameException(objectName); |
| |
valueString.assign(p, n); | valueString.assign(p, n); |
| |
|
|
Sint64 x; | Sint64 x; |
| |
if (!XmlReader::stringToSignedInteger(p, x)) | if (!XmlReader::stringToSignedInteger(p, x)) |
throw IllformedObjectName(objectName); |
throw MalformedObjectNameException(objectName); |
| |
valueString.assign(p, n); | valueString.assign(p, n); |
| |
|
|
{ | { |
if (*p++ != ',') | if (*p++ != ',') |
{ | { |
throw IllformedObjectName(objectName); |
throw MalformedObjectNameException(objectName); |
} | } |
} | } |
} | } |
|
|
_BubbleSort(keyBindings); | _BubbleSort(keyBindings); |
} | } |
| |
void CIMObjectPath::set(const String& objectName) throw(IllformedObjectName) |
void CIMObjectPath::set(const String& objectName) |
{ | { |
clear(); | clear(); |
| |
|
|
| |
// Convert to a C String first: | // Convert to a C String first: |
| |
char* p = objectName.allocateCString(1); |
char* p = objectName.allocateCString(); |
ArrayDestroyer<char> destroyer(p); | ArrayDestroyer<char> destroyer(p); |
Boolean gotHost; | Boolean gotHost; |
Boolean gotNamespace; | Boolean gotNamespace; |
| |
// null terminate the C String |
|
// ATTN-RK-P3-20020301: Is the +1 correct? |
|
p[objectName.size() + 1]= '\0'; |
|
|
|
gotHost = _parseHostElement(objectName, p, _rep->_host); | gotHost = _parseHostElement(objectName, p, _rep->_host); |
gotNamespace = _parseNamespaceElement(objectName, p, _rep->_nameSpace); | gotNamespace = _parseNamespaceElement(objectName, p, _rep->_nameSpace); |
| |
if (gotHost && !gotNamespace) | if (gotHost && !gotNamespace) |
{ | { |
throw IllformedObjectName(objectName); |
throw MalformedObjectNameException(objectName); |
} | } |
| |
// Extract the class name: | // Extract the class name: |
|
|
{ | { |
if (!CIMName::legal(p)) | if (!CIMName::legal(p)) |
{ | { |
throw IllformedObjectName(objectName); |
throw MalformedObjectNameException(objectName); |
} | } |
| |
// ATTN: remove this later: a reference should only be able to hold | // ATTN: remove this later: a reference should only be able to hold |
// an instance name. | // an instance name. |
| |
_rep->_className.assign(p); |
_rep->_className = p; |
return; | return; |
} | } |
| |
_rep->_className.assign(p, dot - p); |
String className = String(p, dot - p); |
|
if (!CIMName::legal(className)) |
|
{ |
|
throw MalformedObjectNameException(objectName); |
|
} |
|
_rep->_className = className; |
| |
// Advance past dot: | // Advance past dot: |
| |
|
|
return *this; | return *this; |
} | } |
| |
CIMObjectPath& CIMObjectPath::operator=(const char* objectName) |
|
{ |
|
set(objectName); |
|
return *this; |
|
} |
|
|
|
const String& CIMObjectPath::getHost() const | const String& CIMObjectPath::getHost() const |
{ | { |
return _rep->_host; | return _rep->_host; |
|
|
_rep->_host = host; | _rep->_host = host; |
} | } |
| |
const String& CIMObjectPath::getNameSpace() const |
const CIMNamespaceName& CIMObjectPath::getNameSpace() const |
{ | { |
return _rep->_nameSpace; | return _rep->_nameSpace; |
} | } |
| |
void CIMObjectPath::setNameSpace(const String& nameSpace) throw(IllegalName) |
void CIMObjectPath::setNameSpace(const CIMNamespaceName& nameSpace) |
{ |
|
String temp; |
|
|
|
// check each namespace segment (delimted by '/') for correctness |
|
|
|
for(Uint32 i = 0; i < nameSpace.size(); i += temp.size() + 1) |
|
{ |
|
// isolate the segment beginning at i and ending at the first |
|
// ocurrance of '/' after i or eos |
|
|
|
temp = nameSpace.subString(i, nameSpace.subString(i).find('/')); |
|
|
|
// check segment for correctness |
|
|
|
if(!CIMName::legal(temp)) |
|
{ | { |
throw IllegalName() ; |
|
} |
|
} |
|
|
|
_rep->_nameSpace = nameSpace; | _rep->_nameSpace = nameSpace; |
} | } |
| |
const String& CIMObjectPath::getClassName() const |
const CIMName& CIMObjectPath::getClassName() const |
{ | { |
return _rep->_className; | return _rep->_className; |
} | } |
| |
const Boolean CIMObjectPath::equalClassName(const String& classname) const |
void CIMObjectPath::setClassName(const CIMName& className) |
{ |
|
return (String::equalNoCase(classname, CIMObjectPath::getClassName())); |
|
} |
|
|
|
void CIMObjectPath::setClassName(const String& className) throw(IllegalName) |
|
{ | { |
if (!CIMName::legal(className)) |
|
throw IllegalName(); |
|
|
|
_rep->_className = className; | _rep->_className = className; |
} | } |
| |
|
|
| |
// Get the namespace (if we have a host name, we must write namespace): | // Get the namespace (if we have a host name, we must write namespace): |
| |
if (_rep->_nameSpace.size() || _rep->_host.size()) |
if (!_rep->_nameSpace.isNull() || _rep->_host.size()) |
{ | { |
objectName += _rep->_nameSpace; | objectName += _rep->_nameSpace; |
objectName += ":"; | objectName += ":"; |
|
|
| |
objectName.append(getClassName()); | objectName.append(getClassName()); |
| |
if (isInstanceName()) |
// |
|
// ATTN-CAKG-P2-20020726: The following condition does not correctly |
|
// distinguish instanceNames from classNames in every case |
|
// The instanceName of a singleton instance of a keyless class has no |
|
// key bindings |
|
// |
|
if (_rep->_keyBindings.size () != 0) |
{ | { |
objectName.append('.'); | objectName.append('.'); |
| |
|
|
| |
// ATTN-RK-P2-20020510: Need to make hostname and namespace lower case? | // ATTN-RK-P2-20020510: Need to make hostname and namespace lower case? |
| |
ref._rep->_className.toLower(); |
String classNameLower = ref._rep->_className; |
|
classNameLower.toLower(); |
|
ref._rep->_className = classNameLower; |
| |
for (Uint32 i = 0, n = ref._rep->_keyBindings.size(); i < n; i++) | for (Uint32 i = 0, n = ref._rep->_keyBindings.size(); i < n; i++) |
{ | { |
ref._rep->_keyBindings[i]._rep->_name.toLower(); |
String keyBindingNameLower = ref._rep->_keyBindings[i]._rep->_name; |
|
keyBindingNameLower.toLower(); |
|
ref._rep->_keyBindings[i]._rep->_name = keyBindingNameLower; |
} | } |
| |
return ref.toString(includeHost); | return ref.toString(includeHost); |
} | } |
| |
CIMObjectPath CIMObjectPath::clone() const |
|
{ |
|
return CIMObjectPath(*this); |
|
} |
|
|
|
Boolean CIMObjectPath::identical(const CIMObjectPath& x) const | Boolean CIMObjectPath::identical(const CIMObjectPath& x) const |
{ | { |
return | return |
String::equal(_rep->_host, x._rep->_host) && | String::equal(_rep->_host, x._rep->_host) && |
CIMName::equal(_rep->_nameSpace, x._rep->_nameSpace) && |
_rep->_nameSpace.equal(x._rep->_nameSpace) && |
CIMName::equal(_rep->_className, x._rep->_className) && |
_rep->_className.equal(x._rep->_className) && |
_rep->_keyBindings == x._rep->_keyBindings; | _rep->_keyBindings == x._rep->_keyBindings; |
} | } |
| |
|
|
return HashFunc<String>::hash(toStringCanonical()); | return HashFunc<String>::hash(toStringCanonical()); |
} | } |
| |
Boolean CIMObjectPath::isInstanceName() const |
|
{ |
|
return _rep->_keyBindings.size() != 0; |
|
} |
|
|
|
KeyBindingArray CIMObjectPath::getKeyBindingArray() |
|
{ |
|
return KeyBindingArray(); |
|
} |
|
|
|
|
|
Boolean operator==(const CIMObjectPath& x, const CIMObjectPath& y) | Boolean operator==(const CIMObjectPath& x, const CIMObjectPath& y) |
{ | { |
return x.identical(y); | return x.identical(y); |