version 1.4, 2001/02/26 04:33:28
|
version 1.20, 2001/07/03 18:25:45
|
|
|
//BEGIN_LICENSE |
|
// | // |
// 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 ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN |
|
// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED |
|
// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT |
|
// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
|
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
|
// 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. |
// | // |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
//============================================================================== |
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
|
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
// LIABILITY, WHETHER IN AN 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. |
|
// | // |
//END_LICENSE |
// Author: Mike Brasher (mbrasher@bmc.com) |
//BEGIN_HISTORY |
|
// | // |
// Author: |
// Modified By: |
// | // |
// $Log$ |
//%///////////////////////////////////////////////////////////////////////////// |
// Revision 1.4 2001/02/26 04:33:28 mike |
|
// Fixed many places where cim names were be compared with operator==(String,String). |
|
// Changed all of these to use CIMName::equal() |
|
// |
|
// Revision 1.3 2001/02/19 01:47:16 mike |
|
// Renamed names of the form CIMConst to ConstCIM. |
|
// |
|
// Revision 1.2 2001/02/16 02:06:07 mike |
|
// Renamed many classes and headers. |
|
// |
|
// Revision 1.1.1.1 2001/01/14 19:53:32 mike |
|
// Pegasus import |
|
// |
|
// |
|
//END_HISTORY |
|
| |
#include <cassert> | #include <cassert> |
#include <cctype> | #include <cctype> |
|
|
#include "CIMQualifierDecl.h" | #include "CIMQualifierDecl.h" |
#include "CIMClass.h" | #include "CIMClass.h" |
#include "CIMInstance.h" | #include "CIMInstance.h" |
|
#include "CIMObject.h" |
| |
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
| |
|
|
strcmp(entry.text, tagName) != 0) | strcmp(entry.text, tagName) != 0) |
{ | { |
char message[MESSAGE_SIZE]; | char message[MESSAGE_SIZE]; |
sprintf(message, "Expected close of %s element", tagName); |
sprintf(message, "Expected close of %s element, got %s instead", |
|
tagName,entry.text); |
throw XmlValidationError(parser.getLine(), message); | throw XmlValidationError(parser.getLine(), message); |
} | } |
} | } |
|
|
throw XmlValidationError(lineNumber, buffer); | throw XmlValidationError(lineNumber, buffer); |
} | } |
| |
if (acceptNull && name.getLength() == 0) |
if (acceptNull && name.size() == 0) |
return name; | return name; |
| |
if (!CIMName::legal(name)) | if (!CIMName::legal(name)) |
|
|
{ | { |
// ATTN-B: accepting only UTF-8 for now! (affects string and char16): | // ATTN-B: accepting only UTF-8 for now! (affects string and char16): |
| |
|
if (strlen(valueString)==0) |
|
{ |
|
switch (type) |
|
{ |
|
case CIMType::BOOLEAN: return CIMValue(false); |
|
case CIMType::STRING: return CIMValue(valueString); |
|
case CIMType::CHAR16: return CIMValue(Char16('\0')); |
|
case CIMType::UINT8: return CIMValue(Uint8(0)); |
|
case CIMType::UINT16: return CIMValue(Uint16(0)); |
|
case CIMType::UINT32: return CIMValue(Uint32(0)); |
|
case CIMType::UINT64: return CIMValue(Uint64(0)); |
|
case CIMType::SINT8: return CIMValue(Sint8(0)); |
|
case CIMType::SINT16: return CIMValue(Sint16(0)); |
|
case CIMType::SINT32: return CIMValue(Sint32(0)); |
|
case CIMType::SINT64: return CIMValue(Sint64(0)); |
|
case CIMType::REAL32: return CIMValue(Real32(0)); |
|
case CIMType::REAL64: return CIMValue(Real64(0)); |
|
} |
|
} |
|
|
switch (type) | switch (type) |
{ | { |
case CIMType::BOOLEAN: | case CIMType::BOOLEAN: |
{ | { |
if (strcmp(valueString, "TRUE") == 0) |
if (CompareNoCase(valueString, "TRUE") == 0) |
return CIMValue(true); | return CIMValue(true); |
else if (strcmp(valueString, "FALSE") == 0) |
else if (CompareNoCase(valueString, "FALSE") == 0) |
return CIMValue(false); | return CIMValue(false); |
else | else |
throw XmlSemanticError( | throw XmlSemanticError( |
|
|
// Get VALUE start tag: | // Get VALUE start tag: |
| |
XmlEntry entry; | XmlEntry entry; |
|
|
if (!testStartTagOrEmptyTag(parser, entry, "VALUE")) | if (!testStartTagOrEmptyTag(parser, entry, "VALUE")) |
return false; | return false; |
| |
Boolean empty = entry.type == XmlEntry::EMPTY_TAG; | Boolean empty = entry.type == XmlEntry::EMPTY_TAG; |
| |
// Get VALUE content: |
|
|
|
const char* valueString = ""; | const char* valueString = ""; |
| |
if (!empty) | if (!empty) |
|
|
} | } |
| |
value = stringToValue(parser.getLine(), valueString,type); | value = stringToValue(parser.getLine(), valueString,type); |
|
|
return true; | return true; |
} | } |
| |
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |
// | // |
|
// getStringValueElement() |
|
// |
|
// <!ELEMENT VALUE (#PCDATA)> |
|
// |
|
//------------------------------------------------------------------------------ |
|
|
|
Boolean XmlReader::getStringValueElement( |
|
XmlParser& parser, |
|
String& str, |
|
Boolean required) |
|
{ |
|
XmlEntry entry; |
|
|
|
if (!testStartTagOrEmptyTag(parser, entry, "VALUE")) |
|
{ |
|
if (required) |
|
throw XmlValidationError(parser.getLine(),"Expected VALUE element"); |
|
return false; |
|
} |
|
|
|
Boolean empty = entry.type == XmlEntry::EMPTY_TAG; |
|
|
|
const char* valueString = ""; |
|
|
|
if (!empty) |
|
{ |
|
if (testContentOrCData(parser, entry)) |
|
valueString = entry.text; |
|
|
|
expectEndTag(parser, "VALUE"); |
|
} |
|
|
|
str = valueString; |
|
return true; |
|
} |
|
|
|
//---------------------------------------------------------------------------- |
|
// |
|
// getPropertyValue |
|
// Use: Decode property value from getPropertyResponse |
|
// Expect (ERROR|IRETURNVALUE).!ELEMENT VALUE (#PCDATA)> |
|
// |
|
// PropertyValue: |
|
// <!ELEMENT VALUE> |
|
// |
|
// <!ELEMENT VALUE.ARRAY (VALUE*)> |
|
// |
|
// <!ELEMENT VALUE.REFERENCE (CLASSPATH|LOCALCLASSPATH|CLASSNAME| |
|
// INSTANCEPATH|LOCALINSTANCEPATH|INSTANCENAME)> |
|
// |
|
//---------------------------------------------------------------------------- |
|
Boolean XmlReader::getPropertyValue( |
|
XmlParser& parser, |
|
CIMValue& cimValue) |
|
{ |
|
//Test for Element value type |
|
CIMType type = CIMType::STRING; |
|
|
|
if (XmlReader::getValueElement(parser, type, cimValue)) |
|
{ |
|
//cout << "DEBUG xmlReader::getPropertyValue " << __LINE__ |
|
// << " CimValue = " << cimValue.toString << endl; |
|
return true; |
|
} |
|
|
|
//Test for Element.array value |
|
if(XmlReader::getValueArrayElement(parser, type, cimValue)) |
|
return true; |
|
|
|
// Test for Value.reference type |
|
// ATTN:This returns a different type (CIMReference) |
|
// ATTN: Possibly change to simply return result after |
|
// we figure out the type differences. |
|
|
|
CIMReference reference; |
|
if(XmlReader::getValueReferenceElement(parser, reference)) |
|
return true; |
|
|
|
return false; |
|
} |
|
|
|
//------------------------------------------------------------------------------ |
|
// |
// stringArrayToValue() | // stringArrayToValue() |
// | // |
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |
|
|
{ | { |
Array<T> array; | Array<T> array; |
| |
for (Uint32 i = 0, n = stringArray.getSize(); i < n; i++) |
for (Uint32 i = 0, n = stringArray.size(); i < n; i++) |
{ | { |
CIMValue value = XmlReader::stringToValue( | CIMValue value = XmlReader::stringToValue( |
lineNumber, stringArray[i], type); | lineNumber, stringArray[i], type); |
|
|
| |
while (getNameSpaceElement(parser, nameSpaceComponent)) | while (getNameSpaceElement(parser, nameSpaceComponent)) |
{ | { |
if (nameSpace.getLength()) |
if (nameSpace.size()) |
nameSpace += '/'; | nameSpace += '/'; |
| |
nameSpace += nameSpaceComponent; | nameSpace += nameSpaceComponent; |
} | } |
| |
if (!nameSpace.getLength()) |
if (!nameSpace.size()) |
{ | { |
throw XmlValidationError(parser.getLine(), | throw XmlValidationError(parser.getLine(), |
"Expected one or more NAMESPACE elements within " | "Expected one or more NAMESPACE elements within " |
|
|
// | // |
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |
| |
KeyBinding::CIMType XmlReader::getValueTypeAttribute( |
KeyBinding::Type XmlReader::getValueTypeAttribute( |
Uint32 lineNumber, | Uint32 lineNumber, |
const XmlEntry& entry, | const XmlEntry& entry, |
const char* elementName) | const char* elementName) |
|
|
| |
Boolean XmlReader::getKeyValueElement( | Boolean XmlReader::getKeyValueElement( |
XmlParser& parser, | XmlParser& parser, |
KeyBinding::CIMType& type, |
KeyBinding::Type& type, |
String& value) | String& value) |
{ | { |
XmlEntry entry; | XmlEntry entry; |
|
|
XmlParser& parser, | XmlParser& parser, |
String& name, | String& name, |
String& value, | String& value, |
KeyBinding::CIMType& type) |
KeyBinding::Type& type) |
{ | { |
XmlEntry entry; | XmlEntry entry; |
| |
|
|
// %ClassName;> | // %ClassName;> |
// | // |
// ATTN-B: VALUE.REFERENCE sub-element not accepted yet. | // ATTN-B: VALUE.REFERENCE sub-element not accepted yet. |
// ATTN-B: KEYVALUE sub-element nothandled yet. |
|
// | // |
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |
| |
|
|
if (!empty) | if (!empty) |
{ | { |
String name; | String name; |
KeyBinding::CIMType type; |
KeyBinding::Type type; |
String value; | String value; |
| |
while (getKeyBindingElement(parser, name, value, type)) | while (getKeyBindingElement(parser, name, value, type)) |
|
|
return true; | return true; |
} | } |
| |
|
Boolean XmlReader::getInstanceNameElement( |
|
XmlParser& parser, |
|
CIMReference& instanceName) |
|
{ |
|
String className; |
|
Array<KeyBinding> keyBindings; |
|
|
|
if (!XmlReader::getInstanceNameElement(parser, className, keyBindings)) |
|
return false; |
|
|
|
instanceName.set(String(), String(), className, keyBindings); |
|
return true; |
|
} |
|
|
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |
// | // |
// getInstancePathElement() | // getInstancePathElement() |
|
|
| |
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |
// | // |
|
// getObject() |
|
// |
|
//------------------------------------------------------------------------------ |
|
|
|
void XmlReader::getObject(XmlParser& parser, CIMClass& x) |
|
{ |
|
if (!getClassElement(parser, x)) |
|
{ |
|
throw XmlValidationError(parser.getLine(), |
|
"expected CLASS element"); |
|
} |
|
} |
|
|
|
//------------------------------------------------------------------------------ |
|
// |
|
// getObject() |
|
// |
|
//------------------------------------------------------------------------------ |
|
|
|
void XmlReader::getObject(XmlParser& parser, CIMInstance& x) |
|
{ |
|
if (!getInstanceElement(parser, x)) |
|
{ |
|
throw XmlValidationError(parser.getLine(), |
|
"expected INSTANCE element"); |
|
} |
|
} |
|
|
|
//------------------------------------------------------------------------------ |
|
// |
|
// getObject() |
|
// |
|
//------------------------------------------------------------------------------ |
|
|
|
void XmlReader::getObject(XmlParser& parser, CIMQualifierDecl& x) |
|
{ |
|
if (!getQualifierDeclElement(parser, x)) |
|
{ |
|
throw XmlValidationError(parser.getLine(), |
|
"expected QUALIFIER.DECLARATION element"); |
|
} |
|
} |
|
|
|
//------------------------------------------------------------------------------ |
|
// |
// getMessageStartTag() | // getMessageStartTag() |
// | // |
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |
| |
Boolean XmlReader::getMessageStartTag( | Boolean XmlReader::getMessageStartTag( |
XmlParser& parser, | XmlParser& parser, |
Uint32& id, |
String& id, |
const char*& protocolVersion) | const char*& protocolVersion) |
{ | { |
XmlEntry entry; | XmlEntry entry; |
|
|
| |
if (!entry.getAttributeValue("PROTOCOLVERSION", protocolVersion)) | if (!entry.getAttributeValue("PROTOCOLVERSION", protocolVersion)) |
throw XmlValidationError(parser.getLine(), | throw XmlValidationError(parser.getLine(), |
"Bad or missing MESSAGE.ID attribute"); |
"Bad or missing MESSAGE.PROTOCOLVERSION attribute"); |
| |
return true; | return true; |
} | } |
|
|
| |
Boolean XmlReader::getErrorElement( | Boolean XmlReader::getErrorElement( |
XmlParser& parser, | XmlParser& parser, |
CimException::Code& code, |
CIMException::Code& code, |
const char*& description, | const char*& description, |
Boolean required) | Boolean required) |
{ | { |
|
|
throw XmlValidationError( | throw XmlValidationError( |
parser.getLine(), "missing ERROR.CODE attribute"); | parser.getLine(), "missing ERROR.CODE attribute"); |
| |
code = CimException::Code(tmpCode); |
code = CIMException::Code(tmpCode); |
| |
// Get ERROR.DESCRIPTION: | // Get ERROR.DESCRIPTION: |
| |
|
|
return true; | return true; |
} | } |
| |
|
|
|
//------------------------------------------------------------------------------ |
|
// getObjectWithPath() |
|
// |
|
// <!ELEMENT VALUE.OBJECTWITHPATH ((CLASSPATH,CLASS)|(INSTANCEPATH,INSTANCE))> |
|
// |
|
//------------------------------------------------------------------------------ |
|
|
|
Boolean XmlReader::getObjectWithPath( |
|
XmlParser& parser, |
|
CIMObjectWithPath& objectWithPath) |
|
{ |
|
XmlEntry entry; |
|
|
|
if (!testStartTag(parser, entry, "VALUE.OBJECTWITHPATH")) |
|
return false; |
|
|
|
CIMReference reference; |
|
Boolean isInstance = false; |
|
|
|
if (XmlReader::getInstancePathElement(parser, reference)) |
|
isInstance = true; |
|
else if (!XmlReader::getClassPathElement(parser, reference)) |
|
{ |
|
throw XmlValidationError(parser.getLine(), |
|
"Expected INSTANCE element"); |
|
} |
|
|
|
if (isInstance) |
|
{ |
|
CIMInstance cimInstance; |
|
|
|
if (!XmlReader::getInstanceElement(parser, cimInstance)) |
|
{ |
|
throw XmlValidationError(parser.getLine(), |
|
"Expected INSTANCEPATH or CLASSPATH element"); |
|
} |
|
objectWithPath.set(reference, CIMObject(cimInstance)); |
|
} |
|
else |
|
{ |
|
CIMClass cimClass; |
|
|
|
if (!XmlReader::getClassElement(parser, cimClass)) |
|
{ |
|
throw XmlValidationError(parser.getLine(), |
|
"Expected CLASS element"); |
|
} |
|
objectWithPath.set(reference, CIMObject(cimClass)); |
|
} |
|
|
|
expectEndTag(parser, "VALUE.OBJECTWITHPATH"); |
|
|
|
return true; |
|
} |
|
|
|
//------------------------------------------------------------------------------ |
|
// |
|
// <objectName>: (CLASSNAME|INSTANCENAME) |
|
// |
|
//------------------------------------------------------------------------------ |
|
|
|
Boolean XmlReader::getObjectNameElement( |
|
XmlParser& parser, |
|
CIMReference& objectName) |
|
{ |
|
String className; |
|
CIMReference instanceName; |
|
|
|
if (getClassNameElement(parser, className, false)) |
|
{ |
|
objectName.set(String(), String(), className); |
|
return true; |
|
} |
|
else if (getInstanceNameElement(parser, objectName)) |
|
return true; |
|
else |
|
{ |
|
throw XmlValidationError(parser.getLine(), |
|
"expected CLASSNAME or INSTANCENAME element"); |
|
} |
|
|
|
return false; |
|
} |
|
|
|
//------------------------------------------------------------------------------ |
|
// |
|
// <!ELEMENT OBJECTPATH (INSTANCEPATH|CLASSPATH)> |
|
// |
|
//------------------------------------------------------------------------------ |
|
|
|
Boolean XmlReader::getObjectPathElement( |
|
XmlParser& parser, |
|
CIMReference& objectPath) |
|
{ |
|
if (getClassPathElement(parser, objectPath)) |
|
return true; |
|
else if (getInstancePathElement(parser, objectPath)) |
|
return true; |
|
else |
|
{ |
|
throw XmlValidationError(parser.getLine(), |
|
"expected INSTANCEPATH or CLASSPATH element"); |
|
} |
|
|
|
return false; |
|
} |
|
|
PEGASUS_NAMESPACE_END | PEGASUS_NAMESPACE_END |