version 1.46, 2002/03/25 20:13:58
|
version 1.53, 2002/05/13 18:35:53
|
|
|
| |
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |
// | // |
// expectXmlDeclaration() |
// getXmlDeclaration() |
|
// |
|
// <?xml version="1.0" encoding="utf-8"?> |
// | // |
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |
| |
void XmlReader::expectXmlDeclaration( |
void XmlReader::getXmlDeclaration( |
XmlParser& parser, | XmlParser& parser, |
XmlEntry& entry) |
const char*& xmlVersion, |
|
const char*& xmlEncoding) |
{ | { |
|
XmlEntry entry; |
|
|
if (!parser.next(entry) || | if (!parser.next(entry) || |
entry.type != XmlEntry::XML_DECLARATION || | entry.type != XmlEntry::XML_DECLARATION || |
strcmp(entry.text, "xml") != 0) | strcmp(entry.text, "xml") != 0) |
|
|
throw XmlValidationError(parser.getLine(), | throw XmlValidationError(parser.getLine(), |
"Expected <?xml ... ?> style declaration"); | "Expected <?xml ... ?> style declaration"); |
} | } |
|
|
|
if (!entry.getAttributeValue("version", xmlVersion)) |
|
throw XmlValidationError( |
|
parser.getLine(), "missing xml.version attribute"); |
|
|
|
if (!entry.getAttributeValue("encoding", xmlEncoding)) |
|
{ |
|
// ATTN-RK-P3-20020403: Is there a default encoding? |
|
} |
} | } |
| |
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |
|
|
| |
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |
// | // |
// testEndTag>() |
// testEndTag() |
// | // |
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |
| |
|
|
{ | { |
// ATTN-B: accepting only UTF-8 for now! (affects string and char16): | // ATTN-B: accepting only UTF-8 for now! (affects string and char16): |
| |
// The Specification for the Representation of CIM in XML does not indicate |
|
// that a default value should be used when a VALUE element is empty. |
|
//#if 0 ATTN-RK-P3-20020321: Take this code out when null qualifiers are fixed |
|
// If strlen == 0, set to default value for type |
|
|
|
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)); |
|
} |
|
} |
|
//#endif |
|
|
|
// Create value per type | // Create value per type |
switch (type) | switch (type) |
{ | { |
|
|
if (!testStartTagOrEmptyTag(parser, entry, "VALUE.ARRAY")) | if (!testStartTagOrEmptyTag(parser, entry, "VALUE.ARRAY")) |
return false; | return false; |
| |
//ATTN: P1 KS KSTESTNULL - Need to relook at this one. |
|
if (entry.type == XmlEntry::EMPTY_TAG) |
|
return true; |
|
|
|
if (entry.type != XmlEntry::EMPTY_TAG) | if (entry.type != XmlEntry::EMPTY_TAG) |
{ | { |
// For each VALUE element: | // For each VALUE element: |
|
|
| |
if (overridable) | if (overridable) |
flavor |= CIMFlavor::OVERRIDABLE; | flavor |= CIMFlavor::OVERRIDABLE; |
|
else |
|
flavor |= CIMFlavor::DISABLEOVERRIDE; |
| |
if (toSubClass) | if (toSubClass) |
flavor |= CIMFlavor::TOSUBCLASS; | flavor |= CIMFlavor::TOSUBCLASS; |
|
else |
|
flavor |= CIMFlavor::RESTRICTED; |
| |
if (toInstance) | if (toInstance) |
flavor |= CIMFlavor::TOINSTANCE; | flavor |= CIMFlavor::TOINSTANCE; |
|
|
// | // |
// getQualifierElement() | // getQualifierElement() |
// | // |
// <!ELEMENT QUALIFIER (VALUE|VALUE.ARRAY)> |
// <!ELEMENT QUALIFIER (VALUE|VALUE.ARRAY)?> |
// <!ATTLIST QUALIFIER | // <!ATTLIST QUALIFIER |
// %CIMName; | // %CIMName; |
// %CIMType; #REQUIRED | // %CIMType; #REQUIRED |
|
|
| |
// Get VALUE or VALUE.ARRAY element: | // Get VALUE or VALUE.ARRAY element: |
| |
// ATTN: KS P1 4 March 2002 - Requires either value or array element or |
|
// generates exception. Correct for spec but means no NULL values on qualifier |
|
// values. Alternative is to set NULL value and continue |
|
|
|
CIMValue value; | CIMValue value; |
| |
if (!getValueElement(parser, type, value) && | if (!getValueElement(parser, type, value) && |
!getValueArrayElement(parser, type, value)) | !getValueArrayElement(parser, type, value)) |
{ | { |
throw XmlSemanticError(parser.getLine(), |
value.setNullValue(type, false); |
"Expected VALUE or VALUE.ARRAY element"); |
|
} | } |
| |
// Expect </QUALIFIER>: | // Expect </QUALIFIER>: |
|
|
| |
// Create property: | // Create property: |
| |
CIMValue value; |
CIMValue value = CIMValue(CIMType::REFERENCE, false, 0); |
value.set(CIMReference()); |
// value.set(CIMReference()); |
property = CIMProperty( | property = CIMProperty( |
name, value, 0, referenceClass, classOrigin, propagated); | name, value, 0, referenceClass, classOrigin, propagated); |
| |
|
|
| |
Boolean XmlReader::getErrorElement( | Boolean XmlReader::getErrorElement( |
XmlParser& parser, | XmlParser& parser, |
CIMStatusCode& code, |
CIMException& cimException, |
const char*& description, |
|
Boolean required) | Boolean required) |
{ | { |
XmlEntry entry; | XmlEntry entry; |
|
|
throw XmlValidationError( | throw XmlValidationError( |
parser.getLine(), "missing ERROR.CODE attribute"); | parser.getLine(), "missing ERROR.CODE attribute"); |
| |
code = CIMStatusCode(tmpCode); |
|
|
|
// Get ERROR.DESCRIPTION: | // Get ERROR.DESCRIPTION: |
| |
description = ""; |
String tmpDescription; |
entry.getAttributeValue("DESCRIPTION", description); |
|
|
entry.getAttributeValue("DESCRIPTION", tmpDescription); |
| |
if (!empty) | if (!empty) |
expectEndTag(parser, "ERROR"); | expectEndTag(parser, "ERROR"); |
| |
|
cimException = PEGASUS_CIM_EXCEPTION(CIMStatusCode(tmpCode), tmpDescription); |
return true; | return true; |
} | } |
| |
| |
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |
// getObjectWithPath() |
// getValueObjectElement() |
|
// |
|
// <!ELEMENT VALUE.OBJECT (CLASS|INSTANCE)> |
|
// |
|
//------------------------------------------------------------------------------ |
|
|
|
Boolean XmlReader::getValueObjectElement( |
|
XmlParser& parser, |
|
CIMObject& object) |
|
{ |
|
XmlEntry entry; |
|
|
|
if (!testStartTag(parser, entry, "VALUE.OBJECT")) |
|
return false; |
|
|
|
CIMInstance cimInstance; |
|
CIMClass cimClass; |
|
|
|
if (XmlReader::getInstanceElement(parser, cimInstance)) |
|
{ |
|
object = CIMObject(cimInstance); |
|
} |
|
else if (!XmlReader::getClassElement(parser, cimClass)) |
|
{ |
|
object = CIMObject(cimClass); |
|
} |
|
else |
|
{ |
|
throw XmlValidationError(parser.getLine(), |
|
"Expected INSTANCE or CLASS element"); |
|
} |
|
|
|
expectEndTag(parser, "VALUE.OBJECT"); |
|
|
|
return true; |
|
} |
|
|
|
//------------------------------------------------------------------------------ |
|
// getValueObjectWithPathElement() |
// | // |
// <!ELEMENT VALUE.OBJECTWITHPATH ((CLASSPATH,CLASS)|(INSTANCEPATH,INSTANCE))> | // <!ELEMENT VALUE.OBJECTWITHPATH ((CLASSPATH,CLASS)|(INSTANCEPATH,INSTANCE))> |
// | // |
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |
| |
Boolean XmlReader::getObjectWithPath( |
Boolean XmlReader::getValueObjectWithPathElement( |
XmlParser& parser, | XmlParser& parser, |
CIMObjectWithPath& objectWithPath) | CIMObjectWithPath& objectWithPath) |
{ | { |
|
|
else if (!XmlReader::getClassPathElement(parser, reference)) | else if (!XmlReader::getClassPathElement(parser, reference)) |
{ | { |
throw XmlValidationError(parser.getLine(), | throw XmlValidationError(parser.getLine(), |
"Expected INSTANCE element"); |
"Expected INSTANCEPATH or CLASSPATH element"); |
} | } |
| |
if (isInstance) | if (isInstance) |
|
|
if (!XmlReader::getInstanceElement(parser, cimInstance)) | if (!XmlReader::getInstanceElement(parser, cimInstance)) |
{ | { |
throw XmlValidationError(parser.getLine(), | throw XmlValidationError(parser.getLine(), |
"Expected INSTANCEPATH or CLASSPATH element"); |
"Expected INSTANCE element"); |
} | } |
objectWithPath.set(reference, CIMObject(cimInstance)); | objectWithPath.set(reference, CIMObject(cimInstance)); |
} | } |
|
|
} | } |
| |
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |
|
// getValueObjectWithLocalPathElement() |
|
// |
|
// <!ELEMENT VALUE.OBJECTWITHLOCALPATH |
|
// ((LOCALCLASSPATH,CLASS)|(LOCALINSTANCEPATH,INSTANCE))> |
|
// |
|
//------------------------------------------------------------------------------ |
|
|
|
Boolean XmlReader::getValueObjectWithLocalPathElement( |
|
XmlParser& parser, |
|
CIMObjectWithPath& objectWithPath) |
|
{ |
|
XmlEntry entry; |
|
|
|
if (!testStartTag(parser, entry, "VALUE.OBJECTWITHLOCALPATH")) |
|
return false; |
|
|
|
CIMReference reference; |
|
Boolean isInstance = false; |
|
|
|
if (XmlReader::getLocalInstancePathElement(parser, reference)) |
|
isInstance = true; |
|
else if (!XmlReader::getLocalClassPathElement(parser, reference)) |
|
{ |
|
throw XmlValidationError(parser.getLine(), |
|
"Expected LOCALINSTANCEPATH or LOCALCLASSPATH element"); |
|
} |
|
|
|
if (isInstance) |
|
{ |
|
CIMInstance cimInstance; |
|
|
|
if (!XmlReader::getInstanceElement(parser, cimInstance)) |
|
{ |
|
throw XmlValidationError(parser.getLine(), |
|
"Expected INSTANCE 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.OBJECTWITHLOCALPATH"); |
|
|
|
return true; |
|
} |
|
|
|
//------------------------------------------------------------------------------ |
|
// getObjectArray() |
|
// |
|
// <object> |
|
// (VALUE.OBJECT|VALUE.OBJECTWITHLOCALPATH|VALUE.OBJECTWITHPATH) |
|
// |
|
//------------------------------------------------------------------------------ |
|
|
|
void XmlReader::getObjectArray( |
|
XmlParser& parser, |
|
Array<CIMObjectWithPath>& objectArray) |
|
{ |
|
CIMObject object; |
|
CIMObjectWithPath objectWithPath; |
|
|
|
objectArray.clear(); |
|
|
|
if (getValueObjectElement(parser, object)) |
|
{ |
|
objectArray.append(CIMObjectWithPath(CIMReference(), object)); |
|
while (getValueObjectElement(parser, object)) |
|
objectArray.append(CIMObjectWithPath(CIMReference(), object)); |
|
} |
|
else if (getValueObjectWithPathElement(parser, objectWithPath)) |
|
{ |
|
objectArray.append(objectWithPath); |
|
while (getValueObjectWithPathElement(parser, objectWithPath)) |
|
objectArray.append(objectWithPath); |
|
} |
|
else if (getValueObjectWithLocalPathElement(parser, objectWithPath)) |
|
{ |
|
objectArray.append(objectWithPath); |
|
while (getValueObjectWithLocalPathElement(parser, objectWithPath)) |
|
objectArray.append(objectWithPath); |
|
} |
|
} |
|
|
|
//------------------------------------------------------------------------------ |
// | // |
// <objectName>: (CLASSNAME|INSTANCENAME) | // <objectName>: (CLASSNAME|INSTANCENAME) |
// | // |