90 mike 1.23 }
91
92 //------------------------------------------------------------------------------
93 //
94 // expectStartTag()
95 //
96 //------------------------------------------------------------------------------
97
98 void XmlReader::expectStartTag(
99 XmlParser& parser,
100 XmlEntry& entry,
101 const char* tagName)
102 {
103 if (!parser.next(entry) ||
104 entry.type != XmlEntry::START_TAG ||
105 strcmp(entry.text, tagName) != 0)
106 {
107 char message[MESSAGE_SIZE];
108 sprintf(message, "Expected open of %s element", tagName);
109 throw XmlValidationError(parser.getLine(), message);
110 }
111 mike 1.23 }
112
113 //------------------------------------------------------------------------------
114 //
115 // expectEndTag()
116 //
117 //------------------------------------------------------------------------------
118
119 void XmlReader::expectEndTag(XmlParser& parser, const char* tagName)
120 {
121 XmlEntry entry;
122
123 if (!parser.next(entry) ||
124 entry.type != XmlEntry::END_TAG ||
125 strcmp(entry.text, tagName) != 0)
126 {
127 char message[MESSAGE_SIZE];
128 sprintf(message, "Expected close of %s element, got %s instead",
129 tagName,entry.text);
130 throw XmlValidationError(parser.getLine(), message);
131 }
132 mike 1.23 }
133
134 //------------------------------------------------------------------------------
135 //
136 // expectStartTagOrEmptyTag()
137 //
138 //------------------------------------------------------------------------------
139
140 void XmlReader::expectStartTagOrEmptyTag(
141 XmlParser& parser,
142 XmlEntry& entry,
143 const char* tagName)
144 {
145 if (!parser.next(entry) ||
146 (entry.type != XmlEntry::START_TAG &&
147 entry.type != XmlEntry::EMPTY_TAG) ||
148 strcmp(entry.text, tagName) != 0)
149 {
150 char message[MESSAGE_SIZE];
151 sprintf(message,
152 "Expected either open or open/close %s element", tagName);
153 mike 1.23 throw XmlValidationError(parser.getLine(), message);
154 }
155 }
156
157 //------------------------------------------------------------------------------
158 //
159 // expectContentOrCData()
160 //
161 //------------------------------------------------------------------------------
162
163 Boolean XmlReader::expectContentOrCData(
164 XmlParser& parser,
165 XmlEntry& entry)
166 {
167 if (!parser.next(entry) ||
168 (entry.type != XmlEntry::CONTENT &&
169 entry.type != XmlEntry::CDATA))
170 {
171 throw XmlValidationError(parser.getLine(),
172 "Expected content of CDATA");
173 }
174 mike 1.23
175 return true;
176 }
177
178 //------------------------------------------------------------------------------
179 //
180 // testStartTag()
181 //
182 //------------------------------------------------------------------------------
183
184 Boolean XmlReader::testStartTag(
185 XmlParser& parser,
186 XmlEntry& entry,
187 const char* tagName)
188 {
189 if (!parser.next(entry) ||
190 entry.type != XmlEntry::START_TAG ||
191 strcmp(entry.text, tagName) != 0)
192 {
193 parser.putBack(entry);
194 return false;
195 mike 1.23 }
196
197 return true;
198 }
199
200 //------------------------------------------------------------------------------
201 //
202 // testEndTag>()
203 //
204 //------------------------------------------------------------------------------
205
206 Boolean XmlReader::testEndTag(XmlParser& parser, const char* tagName)
207 {
208 XmlEntry entry;
209
210 if (!parser.next(entry) ||
211 entry.type != XmlEntry::END_TAG ||
212 strcmp(entry.text, tagName) != 0)
213 {
214 parser.putBack(entry);
215 return false;
216 mike 1.23 }
217
218 return true;
219 }
220
221 //------------------------------------------------------------------------------
222 //
223 // testStartTagOrEmptyTag()
224 //
225 //------------------------------------------------------------------------------
226
227 Boolean XmlReader::testStartTagOrEmptyTag(
228 XmlParser& parser,
229 XmlEntry& entry,
230 const char* tagName)
231 {
232 if (!parser.next(entry) ||
233 (entry.type != XmlEntry::START_TAG &&
234 entry.type != XmlEntry::EMPTY_TAG) ||
235 strcmp(entry.text, tagName) != 0)
236 {
237 mike 1.23 parser.putBack(entry);
238 return false;
239 }
240
241 return true;
242 }
243
244 //------------------------------------------------------------------------------
245 //
246 // testContentOrCData()
247 //
248 //------------------------------------------------------------------------------
249
250 Boolean XmlReader::testContentOrCData(
251 XmlParser& parser,
252 XmlEntry& entry)
253 {
254 if (!parser.next(entry) ||
255 (entry.type != XmlEntry::CONTENT &&
256 entry.type != XmlEntry::CDATA))
257 {
258 mike 1.23 parser.putBack(entry);
259 return false;
260 }
261
262 return true;
263 }
264
265 //------------------------------------------------------------------------------
266 //
267 // testCimStartTag()
268 //
269 // <!ELEMENT CIM (MESSAGE|DECLARATION)>
270 // <!ATTRLIST CIM
271 // CIMVERSION CDATA #REQUIRED
272 // DTDVERSION CDATA #REQUIRED>
273 //
274 //------------------------------------------------------------------------------
275
276 void XmlReader::testCimStartTag(XmlParser& parser)
277 {
278 XmlEntry entry;
279 mike 1.23 XmlReader::expectStartTag(parser, entry, "CIM");
280
281 const char* cimVersion;
282
283 if (!entry.getAttributeValue("CIMVERSION", cimVersion))
284 throw XmlValidationError(
285 parser.getLine(), "missing CIM.CIMVERSION attribute");
286
287 if (strcmp(cimVersion, "2.0") != 0)
288 throw XmlValidationError(parser.getLine(),
289 "CIM.CIMVERSION attribute must be \"2.0\"");
290
291 const char* dtdVersion;
292
293 if (!entry.getAttributeValue("DTDVERSION", dtdVersion))
294 throw XmlValidationError(
295 parser.getLine(), "missing CIM.DTDVERSION attribute");
296
297 if (strcmp(dtdVersion, "2.0") != 0)
298 throw XmlValidationError(parser.getLine(),
299 "CIM.DTDVERSION attribute must be \"2.0\"");
300 mike 1.23 }
301
302 //------------------------------------------------------------------------------
303 //
304 // getIsArrayAttribute()
305 //
306 //------------------------------------------------------------------------------
307
308 Boolean XmlReader::getIsArrayAttribute(
309 Uint32 lineNumber,
310 const XmlEntry& entry,
311 const char* tagName,
312 Boolean& value)
313 {
314 const char* tmp;
315
316 if (!entry.getAttributeValue("ISARRAY", tmp))
317 return false;
318
319 if (strcmp(tmp, "true") == 0)
320 {
321 mike 1.23 value = true;
322 return true;
323 }
324 else if (strcmp(tmp, "false") == 0)
325 {
326 value = false;
327 return true;
328 }
329
330 char buffer[62];
331 sprintf(buffer, "Bad %s.%s attribute value", "ISARRAY", tagName);
332 throw XmlSemanticError(lineNumber, buffer);
333 return false;
334 }
335
336 //------------------------------------------------------------------------------
337 //
338 // getCimNameAttribute()
339 //
340 // <!ENTITY % CIMName "NAME CDATA #REQUIRED">
341 //
342 mike 1.23 //------------------------------------------------------------------------------
343
344 String XmlReader::getCimNameAttribute(
345 Uint32 lineNumber,
346 const XmlEntry& entry,
347 const char* elementName,
348 Boolean acceptNull)
349 {
350 String name;
351
352 if (!entry.getAttributeValue("NAME", name))
353 {
354 char buffer[MESSAGE_SIZE];
355 sprintf(buffer, "missing %s.NAME attribute", elementName);
356 throw XmlValidationError(lineNumber, buffer);
357 }
358
359 if (acceptNull && name.size() == 0)
360 return name;
361
362 if (!CIMName::legal(name))
363 mike 1.23 {
364 char buffer[MESSAGE_SIZE];
365 sprintf(buffer, "Illegal value for %s.NAME attribute", elementName);
366 throw XmlSemanticError(lineNumber, buffer);
367 }
368
369 return name;
370 }
371
372 //------------------------------------------------------------------------------
373 //
374 // getClassNameAttribute()
375 //
376 // <!ENTITY % CIMName "CLASSNAME CDATA #REQUIRED">
377 //
378 //------------------------------------------------------------------------------
379
380 String XmlReader::getClassNameAttribute(
381 Uint32 lineNumber,
382 const XmlEntry& entry,
383 const char* elementName)
384 mike 1.23 {
385 String name;
386
387 if (!entry.getAttributeValue("CLASSNAME", name))
388 {
389 char buffer[MESSAGE_SIZE];
390 sprintf(buffer, "missing %s.CLASSNAME attribute", elementName);
391 throw XmlValidationError(lineNumber, buffer);
392 }
393
394 if (!CIMName::legal(name))
395 {
396 char buffer[MESSAGE_SIZE];
397 sprintf(buffer,
398 "Illegal value for %s.CLASSNAME attribute", elementName);
399 throw XmlSemanticError(lineNumber, buffer);
400 }
401
402 return name;
403 }
404
405 mike 1.23 //------------------------------------------------------------------------------
406 //
407 // getClassOriginAttribute()
408 //
409 // <!ENTITY % ClassOrigin "CLASSORIGIN CDATA #IMPLIED">
410 //
411 //------------------------------------------------------------------------------
412
413 String XmlReader::getClassOriginAttribute(
414 Uint32 lineNumber,
415 const XmlEntry& entry,
416 const char* tagName)
417 {
418 String name;
419
420 if (!entry.getAttributeValue("CLASSORIGIN", name))
421 return String();
422
423 if (!CIMName::legal(name))
424 {
425 char buffer[MESSAGE_SIZE];
426 mike 1.23 sprintf(buffer,
427 "Illegal value for %s.CLASSORIGIN attribute", tagName);
428 throw XmlSemanticError(lineNumber, buffer);
429 }
430
431 return name;
432 }
433
434 //------------------------------------------------------------------------------
435 //
436 // getReferenceClassAttribute()
437 //
438 // <!ENTITY % ReferenceClass "REFERENCECLASS CDATA #IMPLIED">
439 //
440 //------------------------------------------------------------------------------
441
442 String XmlReader::getReferenceClassAttribute(
443 Uint32 lineNumber,
444 const XmlEntry& entry,
445 const char* elementName)
446 {
447 mike 1.23 String name;
448
449 if (!entry.getAttributeValue("REFERENCECLASS", name))
450 return String();
451
452 if (!CIMName::legal(name))
453 {
454 char buffer[MESSAGE_SIZE];
455 sprintf(buffer,
456 "Illegal value for %s.REFERENCECLASS attribute", elementName);
457 throw XmlSemanticError(lineNumber, buffer);
458 }
459
460 return name;
461 }
462
463 //------------------------------------------------------------------------------
464 //
465 // getSuperClassAttribute()
466 //
467 // <!ENTITY % SuperClass "SUPERCLASS CDATA #IMPLIED">
468 mike 1.23 //
469 //------------------------------------------------------------------------------
470
471 String XmlReader::getSuperClassAttribute(
472 Uint32 lineNumber,
473 const XmlEntry& entry,
474 const char* tagName)
475 {
476 String superClass;
477
478 if (!entry.getAttributeValue("SUPERCLASS", superClass))
479 return String();
480
481 if (!CIMName::legal(superClass))
482 {
483 char buffer[MESSAGE_SIZE];
484 sprintf(
485 buffer, "Illegal value for %s.SUPERCLASS attribute", tagName);
486 throw XmlSemanticError(lineNumber, buffer);
487 }
488
489 mike 1.23 return superClass;
490 }
491
492 //------------------------------------------------------------------------------
493 //
494 // getCimTypeAttribute()
495 //
496 // <!ENTITY % CIMType "TYPE (boolean|string|char16|uint8|sint8|uint16
497 // |sint16|uint32|sint32|uint64|sint64|datetime|real32|real64)">
498 //
499 //------------------------------------------------------------------------------
500
501 CIMType XmlReader::getCimTypeAttribute(
502 Uint32 lineNumber,
503 const XmlEntry& entry,
504 const char* tagName)
505 {
506 const char* typeName;
507
508 if (!entry.getAttributeValue("TYPE", typeName))
509 {
510 mike 1.23 char message[MESSAGE_SIZE];
511 sprintf(message, "missing %s.TYPE attribute", tagName);
512 throw XmlValidationError(lineNumber, message);
513 }
514
515 CIMType type = CIMType::NONE;
516
517 if (strcmp(typeName, "boolean") == 0)
518 type = CIMType::BOOLEAN;
519 else if (strcmp(typeName, "string") == 0)
520 type = CIMType::STRING;
521 else if (strcmp(typeName, "char16") == 0)
522 type = CIMType::CHAR16;
523 else if (strcmp(typeName, "uint8") == 0)
524 type = CIMType::UINT8;
525 else if (strcmp(typeName, "sint8") == 0)
526 type = CIMType::SINT8;
527 else if (strcmp(typeName, "uint16") == 0)
528 type = CIMType::UINT16;
529 else if (strcmp(typeName, "sint16") == 0)
530 type = CIMType::SINT16;
531 mike 1.23 else if (strcmp(typeName, "uint32") == 0)
532 type = CIMType::UINT32;
533 else if (strcmp(typeName, "sint32") == 0)
534 type = CIMType::SINT32;
535 else if (strcmp(typeName, "uint64") == 0)
536 type = CIMType::UINT64;
537 else if (strcmp(typeName, "sint64") == 0)
538 type = CIMType::SINT64;
539 else if (strcmp(typeName, "datetime") == 0)
540 type = CIMType::DATETIME;
541 else if (strcmp(typeName, "real32") == 0)
542 type = CIMType::REAL32;
543 else if (strcmp(typeName, "real64") == 0)
544 type = CIMType::REAL64;
545 else if (strcmp(typeName, "reference") == 0)
546 type = CIMType::REFERENCE;
547
548 // ATTN: "reference" is not legal according to the DTD; however, it is
549 // used by the XML version of the CIM schema.
550
551 if (type == CIMType::NONE)
552 mike 1.23 {
553 char message[MESSAGE_SIZE];
554 sprintf(message, "Illegal value for %s.TYPE attribute", tagName);
555 throw XmlSemanticError(lineNumber, message);
556 }
557
558 return type;
559 }
560
561 //------------------------------------------------------------------------------
562 //
563 // getCimBooleanAttribute()
564 //
565 //------------------------------------------------------------------------------
566
567 Boolean XmlReader::getCimBooleanAttribute(
568 Uint32 lineNumber,
569 const XmlEntry& entry,
570 const char* tagName,
571 const char* attributeName,
572 Boolean defaultValue,
573 mike 1.23 Boolean required)
574 {
575 const char* tmp;
576
577 if (!entry.getAttributeValue(attributeName, tmp))
578 {
579 if (!required)
580 return defaultValue;
581
582 char buffer[62];
583 sprintf(buffer, "missing required %s.%s attribute",
584 attributeName, tagName);
585
586 throw XmlValidationError(lineNumber, buffer);
587 }
588
589 if (strcmp(tmp, "true") == 0)
590 return true;
591 else if (strcmp(tmp, "false") == 0)
592 return false;
593
594 mike 1.23 char buffer[62];
595 sprintf(buffer, "Bad %s.%s attribute value", attributeName, tagName);
596 throw XmlSemanticError(lineNumber, buffer);
597 return false;
598 }
599
600 //------------------------------------------------------------------------------
601 //
602 // SringToReal()
603 //
604 // [ "+" | "-" ] *decimalDigit "." 1*decimalDigit
605 // [ ( "e" | "E" ) [ "+" | "-" ] 1*decimalDigit ]
606 //
607 //------------------------------------------------------------------------------
608
609 Boolean XmlReader::stringToReal(const char* stringValue, Real64& x)
610 {
611 const char* p = stringValue;
612
613 if (!*p)
614 return false;
615 mike 1.23
616 // Skip optional sign:
617
618 if (*p == '+' || *p == '-')
619 p++;
620
621 // Skip optional first set of digits:
622
623 while (isdigit(*p))
624 p++;
625
626 // Test required dot:
627
628 if (*p++ != '.')
629 return false;
630
631 // One or more digits required:
632
633 if (!isdigit(*p++))
634 return false;
635
636 mike 1.23 while (isdigit(*p))
637 p++;
638
639 // If there is an exponent now:
640
641 if (*p)
642 {
643 // Test exponent:
644
645 if (*p != 'e' && *p != 'E')
646 return false;
647
648 p++;
649
650 // Skip optional sign:
651
652 if (*p == '+' || *p == '-')
653 p++;
654
655 // One or more digits required:
656
657 mike 1.23 if (!isdigit(*p++))
658 return false;
659
660 while (isdigit(*p))
661 p++;
662 }
663
664 if (*p)
665 return false;
666
667 char* end;
668 x = strtod(stringValue, &end);
669 return true;
670 }
671
672 //------------------------------------------------------------------------------
673 //
674 // stringToSignedInteger
675 //
676 // [ "+" | "-" ] ( positiveDecimalDigit *decimalDigit | "0" )
677 //
678 mike 1.23 // ATTN-B: handle conversion from hexadecimal.
679 //------------------------------------------------------------------------------
680
681 Boolean XmlReader::stringToSignedInteger(
682 const char* stringValue,
683 Sint64& x)
684 {
685 x = 0;
686 const char* p = stringValue;
687
688 if (!*p)
689 return false;
690
691 // Skip optional sign:
692
693 Boolean negative = *p == '-';
694
695 if (negative || *p == '+')
696 p++;
697
698 // If the next thing is a zero, then it must be the last:
699 mike 1.23
700 if (*p == '0')
701 return p[1] == '\0';
702
703 // Expect a positive decimal digit:
704
705 const char* first = p;
706
707 if (!isdigit(*p) || *p == '0')
708 return false;
709
710 p++;
711
712 // Expect zero or more digits:
713
714 while (isdigit(*p))
715 p++;
716
717 if (*p)
718 return false;
719
720 mike 1.23 const char* last = p;
721
722 while (first != last)
723 x = 10 * x + (*first++ - '0');
724
725 if (negative)
726 x = -x;
727
728 return true;
729 }
730
731 //------------------------------------------------------------------------------
732 //
733 // stringToUnsignedInteger
734 //
735 // [ "+" | "-" ] ( positiveDecimalDigit *decimalDigit | "0" )
736 //
737 // ATTN-B: handle conversion from hexadecimal.
738 //------------------------------------------------------------------------------
739
740 Boolean XmlReader::stringToUnsignedInteger(
741 mike 1.23 const char* stringValue,
742 Uint64& x)
743 {
744 x = 0;
745 const char* p = stringValue;
746
747 if (!*p)
748 return false;
749
750 // Skip optional sign:
751
752 if (*p == '-')
753 return false;
754
755 if (*p == '+')
756 p++;
757
758 // If the next thing is a zero, then it must be the last:
759
760 if (*p == '0')
761 return p[1] == '\0';
762 mike 1.23
763 // Expect a positive decimal digit:
764
765 const char* first = p;
766
767 if (!isdigit(*p) || *p == '0')
768 return false;
769
770 p++;
771
772 // Expect zero or more digits:
773
774 while (isdigit(*p))
775 p++;
776
777 if (*p)
778 return false;
779
780 const char* last = p;
781
782 while (first != last)
783 mike 1.23 x = 10 * x + (*first++ - '0');
784
785 return true;
786 }
787
788 //------------------------------------------------------------------------------
789 //
790 // stringToValue()
791 //
792 // ATTN-C: note that integers are truncated without warning. What should be
793 // done in this case? In C they are truncated without warning by design.
794 //
795 //------------------------------------------------------------------------------
796
797 CIMValue XmlReader::stringToValue(
798 Uint32 lineNumber,
799 const char* valueString,
800 CIMType type)
801 {
802 // ATTN-B: accepting only UTF-8 for now! (affects string and char16):
803
804 mike 1.23 if (strlen(valueString)==0)
805 {
806 switch (type)
807 {
808 case CIMType::BOOLEAN: return CIMValue(false);
809 case CIMType::STRING: return CIMValue(valueString);
810 case CIMType::CHAR16: return CIMValue(Char16('\0'));
811 case CIMType::UINT8: return CIMValue(Uint8(0));
812 case CIMType::UINT16: return CIMValue(Uint16(0));
813 case CIMType::UINT32: return CIMValue(Uint32(0));
814 case CIMType::UINT64: return CIMValue(Uint64(0));
815 case CIMType::SINT8: return CIMValue(Sint8(0));
816 case CIMType::SINT16: return CIMValue(Sint16(0));
817 case CIMType::SINT32: return CIMValue(Sint32(0));
818 case CIMType::SINT64: return CIMValue(Sint64(0));
819 case CIMType::REAL32: return CIMValue(Real32(0));
820 case CIMType::REAL64: return CIMValue(Real64(0));
821 }
822 }
823
824 switch (type)
825 mike 1.23 {
826 case CIMType::BOOLEAN:
827 {
828 if (CompareNoCase(valueString, "TRUE") == 0)
829 return CIMValue(true);
830 else if (CompareNoCase(valueString, "FALSE") == 0)
831 return CIMValue(false);
832 else
833 throw XmlSemanticError(
834 lineNumber, "Bad boolean value");
835 }
836
837 case CIMType::STRING:
838 {
839 return CIMValue(valueString);
840 }
841
842 case CIMType::CHAR16:
843 {
844 if (strlen(valueString) != 1)
845 throw XmlSemanticError(lineNumber, "Bad char16 value");
846 mike 1.23
847 return CIMValue(Char16(valueString[0]));
848 }
849
850 case CIMType::UINT8:
851 case CIMType::UINT16:
852 case CIMType::UINT32:
853 case CIMType::UINT64:
854 {
855 Uint64 x;
856
857 if (!stringToUnsignedInteger(valueString, x))
858 {
859 throw XmlSemanticError(
860 lineNumber, "Bad unsigned integer value");
861 }
862
863 switch (type)
864 {
865 case CIMType::UINT8: return CIMValue(Uint8(x));
866 case CIMType::UINT16: return CIMValue(Uint16(x));
867 mike 1.23 case CIMType::UINT32: return CIMValue(Uint32(x));
868 case CIMType::UINT64: return CIMValue(Uint64(x));
869 default: break;
870 }
871 }
872
873 case CIMType::SINT8:
874 case CIMType::SINT16:
875 case CIMType::SINT32:
876 case CIMType::SINT64:
877 {
878 Sint64 x;
879
880 if (!stringToSignedInteger(valueString, x))
881 {
882 throw XmlSemanticError(
883 lineNumber, "Bad signed integer value");
884 }
885
886 switch (type)
887 {
888 mike 1.23 case CIMType::SINT8: return CIMValue(Sint8(x));
889 case CIMType::SINT16: return CIMValue(Sint16(x));
890 case CIMType::SINT32: return CIMValue(Sint32(x));
891 case CIMType::SINT64: return CIMValue(Sint64(x));
892 default: break;
893 }
894 }
895
896 case CIMType::DATETIME:
897 {
898 CIMDateTime tmp;
899
900 try
901 {
902 tmp.set(valueString);
903 }
904 catch (BadDateTimeFormat&)
905 {
906 throw XmlSemanticError(lineNumber, "Bad datetime value");
907 }
908
909 mike 1.23 return CIMValue(tmp);
910 }
911
912 case CIMType::REAL32:
913 {
914 Real64 x;
915
916 if (!stringToReal(valueString, x))
917 throw XmlSemanticError(lineNumber, "Bad real value");
918
919 return CIMValue(Real32(x));
920 }
921
922 case CIMType::REAL64:
923 {
924 Real64 x;
925
926 if (!stringToReal(valueString, x))
927 throw XmlSemanticError(lineNumber, "Bad real value");
928
929 return CIMValue(x);
930 mike 1.23 }
931
932 default:
933 break;
934 }
935
936 throw XmlSemanticError(lineNumber, "malformed XML");
937 return false;
938 }
939
940 //------------------------------------------------------------------------------
941 //
942 // getValueElement()
943 //
944 // <!ELEMENT VALUE (#PCDATA)>
945 //
946 //------------------------------------------------------------------------------
947
948 Boolean XmlReader::getValueElement(
949 XmlParser& parser,
950 CIMType type,
951 mike 1.23 CIMValue& value)
952 {
953 // Get VALUE start tag:
954
955 XmlEntry entry;
956 if (!testStartTagOrEmptyTag(parser, entry, "VALUE"))
957 return false;
958
959 Boolean empty = entry.type == XmlEntry::EMPTY_TAG;
960
961 const char* valueString = "";
962
963 if (!empty)
964 {
965 if (testContentOrCData(parser, entry))
966 valueString = entry.text;
967
968 expectEndTag(parser, "VALUE");
969 }
970
971 value = stringToValue(parser.getLine(), valueString,type);
972 mike 1.23
973 return true;
974 }
975
976 //------------------------------------------------------------------------------
977 //
978 // getStringValueElement()
979 //
980 // <!ELEMENT VALUE (#PCDATA)>
981 //
982 //------------------------------------------------------------------------------
983
984 Boolean XmlReader::getStringValueElement(
985 XmlParser& parser,
986 String& str,
987 Boolean required)
988 {
989 XmlEntry entry;
990
991 if (!testStartTagOrEmptyTag(parser, entry, "VALUE"))
992 {
993 mike 1.23 if (required)
994 throw XmlValidationError(parser.getLine(),"Expected VALUE element");
995 return false;
996 }
997
998 Boolean empty = entry.type == XmlEntry::EMPTY_TAG;
999
1000 const char* valueString = "";
1001
1002 if (!empty)
1003 {
1004 if (testContentOrCData(parser, entry))
1005 valueString = entry.text;
1006
1007 expectEndTag(parser, "VALUE");
1008 }
1009
1010 str = valueString;
1011 return true;
1012 }
1013
1014 mike 1.23 //----------------------------------------------------------------------------
1015 //
1016 // getPropertyValue
1017 // Use: Decode property value from getPropertyResponse
1018 // Expect (ERROR|IRETURNVALUE).!ELEMENT VALUE (#PCDATA)>
1019 //
1020 // PropertyValue:
1021 // <!ELEMENT VALUE>
1022 //
1023 // <!ELEMENT VALUE.ARRAY (VALUE*)>
1024 //
1025 // <!ELEMENT VALUE.REFERENCE (CLASSPATH|LOCALCLASSPATH|CLASSNAME|
1026 // INSTANCEPATH|LOCALINSTANCEPATH|INSTANCENAME)>
1027 //
1028 //----------------------------------------------------------------------------
1029 Boolean XmlReader::getPropertyValue(
1030 XmlParser& parser,
1031 CIMValue& cimValue)
1032 {
1033 //Test for Element value type
1034 CIMType type = CIMType::STRING;
1035 mike 1.23
1036 if (XmlReader::getValueElement(parser, type, cimValue))
1037 {
1038 //cout << "DEBUG xmlReader::getPropertyValue " << __LINE__
1039 // << " CimValue = " << cimValue.toString << endl;
1040 return true;
1041 }
1042
1043 //Test for Element.array value
1044 if(XmlReader::getValueArrayElement(parser, type, cimValue))
1045 return true;
1046
1047 // Test for Value.reference type
1048 // ATTN:This returns a different type (CIMReference)
1049 // ATTN: Possibly change to simply return result after
1050 // we figure out the type differences.
1051
1052 CIMReference reference;
1053 if(XmlReader::getValueReferenceElement(parser, reference))
1054 return true;
1055
1056 mike 1.23 return false;
1057 }
1058
1059 //------------------------------------------------------------------------------
1060 //
1061 // stringArrayToValue()
1062 //
1063 //------------------------------------------------------------------------------
1064
1065 template<class T>
1066 CIMValue StringArrayToValueAux(
1067 Uint32 lineNumber,
1068 const Array<const char*>& stringArray,
1069 CIMType type,
1070 T*)
1071 {
1072 Array<T> array;
1073
1074 for (Uint32 i = 0, n = stringArray.size(); i < n; i++)
1075 {
1076 CIMValue value = XmlReader::stringToValue(
1077 mike 1.23 lineNumber, stringArray[i], type);
1078
1079 T x;
1080 value.get(x);
1081 array.append(x);
1082 }
1083
1084 return CIMValue(array);
1085 }
1086
1087 CIMValue XmlReader::stringArrayToValue(
1088 Uint32 lineNumber,
1089 const Array<const char*>& array,
1090 CIMType type)
1091 {
1092 switch (type)
1093 {
1094 case CIMType::BOOLEAN:
1095 return StringArrayToValueAux(lineNumber, array, type, (Boolean*)0);
1096
1097 case CIMType::STRING:
1098 mike 1.23 return StringArrayToValueAux(lineNumber, array, type, (String*)0);
1099
1100 case CIMType::CHAR16:
1101 return StringArrayToValueAux(lineNumber, array, type, (Char16*)0);
1102
1103 case CIMType::UINT8:
1104 return StringArrayToValueAux(lineNumber, array, type, (Uint8*)0);
1105
1106 case CIMType::UINT16:
1107 return StringArrayToValueAux(lineNumber, array, type, (Uint16*)0);
1108
1109 case CIMType::UINT32:
1110 return StringArrayToValueAux(lineNumber, array, type, (Uint32*)0);
1111
1112 case CIMType::UINT64:
1113 return StringArrayToValueAux(lineNumber, array, type, (Uint64*)0);
1114
1115 case CIMType::SINT8:
1116 return StringArrayToValueAux(lineNumber, array, type, (Sint8*)0);
1117
1118 case CIMType::SINT16:
1119 mike 1.23 return StringArrayToValueAux(lineNumber, array, type, (Sint16*)0);
1120
1121 case CIMType::SINT32:
1122 return StringArrayToValueAux(lineNumber, array, type, (Sint32*)0);
1123
1124 case CIMType::SINT64:
1125 return StringArrayToValueAux(lineNumber, array, type, (Sint64*)0);
1126
1127 case CIMType::DATETIME:
1128 return StringArrayToValueAux(lineNumber, array, type, (CIMDateTime*)0);
1129
1130 case CIMType::REAL32:
1131 return StringArrayToValueAux(lineNumber, array, type, (Real32*)0);
1132
1133 case CIMType::REAL64:
1134 return StringArrayToValueAux(lineNumber, array, type, (Real64*)0);
1135
1136 default:
1137 break;
1138 }
1139
1140 mike 1.23 // Unreachable:
1141 return CIMValue();
1142 }
1143
1144 //------------------------------------------------------------------------------
1145 //
1146 // getValueArrayElement()
1147 //
1148 // <!ELEMENT VALUE.ARRAY (VALUE*)>
1149 //
1150 //------------------------------------------------------------------------------
1151
1152 Boolean XmlReader::getValueArrayElement(
1153 XmlParser& parser,
1154 CIMType type,
1155 CIMValue& value)
1156 {
1157 value.clear();
1158
1159 // Get VALUE.ARRAY open tag:
1160
1161 mike 1.23 XmlEntry entry;
1162
1163 if (!testStartTagOrEmptyTag(parser, entry, "VALUE.ARRAY"))
1164 return false;
1165
1166 if (entry.type == XmlEntry::EMPTY_TAG)
1167 return true;
1168
1169 // For each VALUE element:
1170
1171 Array<const char*> stringArray;
1172
1173 while (testStartTagOrEmptyTag(parser, entry, "VALUE"))
1174 {
1175 if (entry.type == XmlEntry::EMPTY_TAG)
1176 {
1177 stringArray.append("");
1178 continue;
1179 }
1180
1181 if (testContentOrCData(parser, entry))
1182 mike 1.23 stringArray.append(entry.text);
1183 else
1184 stringArray.append("");
1185
1186 expectEndTag(parser, "VALUE");
1187 }
1188
1189 expectEndTag(parser, "VALUE.ARRAY");
1190
1191 value = stringArrayToValue(parser.getLine(), stringArray, type);
1192 return true;
1193 }
1194
1195 //------------------------------------------------------------------------------
1196 //
1197 // getFlavor()
1198 //
1199 // <!ENTITY % QualifierFlavor
1200 // "OVERRIDABLE (true|false) 'true'
1201 // TOSUBCLASS (true|false) 'true'
1202 // TOINSTANCE (true|false) 'false'
1203 mike 1.23 // TRANSLATABLE (true|false) 'false'">
1204 //
1205 //------------------------------------------------------------------------------
1206
1207 Uint32 XmlReader::getFlavor(
1208 XmlEntry& entry,
1209 Uint32 lineNumber,
1210 const char* tagName)
1211 {
1212 // Get QUALIFIER.OVERRIDABLE
1213
1214 Boolean overridable = getCimBooleanAttribute(
1215 lineNumber, entry, tagName, "OVERRIDABLE", true, false);
1216
1217 // Get QUALIFIER.TOSUBCLASS
1218
1219 Boolean toSubClass = getCimBooleanAttribute(
1220 lineNumber, entry, tagName, "TOSUBCLASS", true, false);
1221
1222 // Get QUALIFIER.TOINSTANCE
1223
1224 mike 1.23 Boolean toInstance = getCimBooleanAttribute(
1225 lineNumber, entry, tagName, "TOINSTANCE", false, false);
1226
1227 // Get QUALIFIER.TRANSLATABLE
1228
1229 Boolean translatable = getCimBooleanAttribute(
1230 lineNumber, entry, tagName, "TRANSLATABLE", false, false);
1231
1232 Uint32 flavor = 0;
1233
1234 if (overridable)
1235 flavor |= CIMFlavor::OVERRIDABLE;
1236
1237 if (toSubClass)
1238 flavor |= CIMFlavor::TOSUBCLASS;
1239
1240 if (toInstance)
1241 flavor |= CIMFlavor::TOINSTANCE;
1242
1243 if (translatable)
1244 flavor |= CIMFlavor::TRANSLATABLE;
1245 mike 1.23
1246 return flavor;
1247 }
1248
1249 //------------------------------------------------------------------------------
1250 //
1251 // getOptionalScope()
1252 //
1253 // DTD:
1254 // <!ELEMENT SCOPE EMPTY>
1255 // <!ATTLIST SCOPE
1256 // CLASS (true|false) 'false'
1257 // ASSOCIATION (true|false) 'false'
1258 // REFERENCE (true|false) 'false'
1259 // PROPERTY (true|false) 'false'
1260 // METHOD (true|false) 'false'
1261 // PARAMETER (true|false) 'false'
1262 // INDICATION (true|false) 'false'>
1263 //
1264 //------------------------------------------------------------------------------
1265
1266 mike 1.23 Uint32 XmlReader::getOptionalScope(XmlParser& parser)
1267 {
1268 XmlEntry entry;
1269
1270 if (!parser.next(entry))
1271 return false;
1272
1273 Boolean isEmptyTag = entry.type == XmlEntry::EMPTY_TAG;
1274
1275 if ((!isEmptyTag &&
1276 entry.type != XmlEntry::START_TAG) ||
1277 strcmp(entry.text, "SCOPE") != 0)
1278 {
1279 parser.putBack(entry);
1280 return 0;
1281 }
1282
1283 Uint32 line = parser.getLine();
1284 Uint32 scope = 0;
1285
1286 if (getCimBooleanAttribute(line, entry, "SCOPE", "CLASS", false, false))
1287 mike 1.23 scope |= CIMScope::CLASS;
1288
1289 if (getCimBooleanAttribute(
1290 line, entry, "SCOPE", "ASSOCIATION", false, false))
1291 scope |= CIMScope::ASSOCIATION;
1292
1293 if (getCimBooleanAttribute(
1294 line, entry, "SCOPE", "REFERENCE", false, false))
1295 scope |= CIMScope::REFERENCE;
1296
1297 if (getCimBooleanAttribute(line, entry, "SCOPE", "PROPERTY", false, false))
1298 scope |= CIMScope::PROPERTY;
1299
1300 if (getCimBooleanAttribute(line, entry, "SCOPE", "METHOD", false, false))
1301 scope |= CIMScope::METHOD;
1302
1303 if (getCimBooleanAttribute(line, entry, "SCOPE", "PARAMETER", false, false))
1304 scope |= CIMScope::PARAMETER;
1305
1306 if (getCimBooleanAttribute(line, entry, "SCOPE", "INDICATION",false, false))
1307 scope |= CIMScope::INDICATION;
1308 mike 1.23
1309 if (!isEmptyTag)
1310 expectEndTag(parser, "SCOPE");
1311
1312 return scope;
1313 }
1314
1315 //------------------------------------------------------------------------------
1316 //
1317 // getQualifierElement()
1318 //
1319 // <!ELEMENT QUALIFIER (VALUE|VALUE.ARRAY)>
1320 // <!ATTLIST QUALIFIER
1321 // %CIMName;
1322 // %CIMType; #REQUIRED
1323 // %Propagated;
1324 // %QualifierFlavor;>
1325 //
1326 //------------------------------------------------------------------------------
1327
1328 Boolean XmlReader::getQualifierElement(
1329 mike 1.23 XmlParser& parser,
1330 CIMQualifier& qualifier)
1331 {
1332 // Get QUALIFIER element:
1333
1334 XmlEntry entry;
1335 if (!testStartTag(parser, entry, "QUALIFIER"))
1336 return false;
1337
1338 // Get QUALIFIER.NAME attribute:
1339
1340 String name = getCimNameAttribute(parser.getLine(), entry, "QUALIFIER");
1341
1342 // Get QUALIFIER.TYPE attribute:
1343
1344 CIMType type = getCimTypeAttribute(parser.getLine(), entry, "QUALIFIER");
1345
1346 // Get QUALIFIER.PROPAGATED
1347
1348 Boolean propagated = getCimBooleanAttribute(
1349 parser.getLine(), entry, "QUALIFIER", "PROPAGATED", false, false);
1350 mike 1.23
1351 // Get flavor oriented attributes:
1352
1353 Uint32 flavor = getFlavor(entry, parser.getLine(), "QUALIFIER");
1354
1355 // Get VALUE or VALUE.ARRAY element:
1356
1357 CIMValue value;
1358
1359 if (!getValueElement(parser, type, value) &&
1360 !getValueArrayElement(parser, type, value))
1361 {
1362 throw XmlSemanticError(parser.getLine(),
1363 "Expected VALUE or VALUE.ARRAY element");
1364 }
1365
1366 // Expect </QUALIFIER>:
1367
1368 expectEndTag(parser, "QUALIFIER");
1369
1370 // Build qualifier:
1371 mike 1.23
1372 qualifier = CIMQualifier(name, value, flavor, propagated);
1373 return true;
1374 }
1375
1376 //------------------------------------------------------------------------------
1377 //
1378 // getQualifierElements()
1379 //
1380 //------------------------------------------------------------------------------
1381
1382 template<class CONTAINER>
1383 void getQualifierElements(XmlParser& parser, CONTAINER& container)
1384 {
1385 CIMQualifier qualifier;
1386
1387 while (XmlReader::getQualifierElement(parser, qualifier))
1388 {
1389 try
1390 {
1391 container.addQualifier(qualifier);
1392 mike 1.23 }
1393 catch (AlreadyExists&)
1394 {
1395 throw XmlSemanticError(parser.getLine(), "duplicate qualifier");
1396 }
1397 }
1398 }
1399
1400 //------------------------------------------------------------------------------
1401 //
1402 // getPropertyElement()
1403 //
1404 // <!ELEMENT PROPERTY (QUALIFIER*,VALUE?)>
1405 // <!ATTLIST PROPERTY
1406 // %CIMName;
1407 // %ClassOrigin;
1408 // %Propagated;
1409 // %CIMType; #REQUIRED>
1410 //
1411 //------------------------------------------------------------------------------
1412
1413 mike 1.23 Boolean XmlReader::getPropertyElement(XmlParser& parser, CIMProperty& property)
1414 {
1415 XmlEntry entry;
1416
1417 if (!testStartTagOrEmptyTag(parser, entry, "PROPERTY"))
1418 return false;
1419
1420 Boolean empty = entry.type == XmlEntry::EMPTY_TAG;
1421
1422 // Get PROPERTY.NAME attribute:
1423
1424 String name = getCimNameAttribute(parser.getLine(), entry, "PROPERTY");
1425
1426 // Get PROPERTY.CLASSORIGIN attribute:
1427
1428 String classOrigin =
1429 getClassOriginAttribute(parser.getLine(), entry, "PROPERTY");
1430
1431 // Get PROPERTY.PROPAGATED
1432
1433 Boolean propagated = getCimBooleanAttribute(
1434 mike 1.23 parser.getLine(), entry, "PROPERTY", "PROPAGATED", false, false);
1435
1436 // Get PROPERTY.TYPE attribute:
1437
1438 CIMType type = getCimTypeAttribute(parser.getLine(), entry, "PROPERTY");
1439
1440 // Create property:
1441
1442 CIMValue value;
1443 value.setNullValue(type, false);
1444 property = CIMProperty(
1445 name, value, 0, String(), classOrigin, propagated);
1446
1447 if (!empty)
1448 {
1449 // Get qualifiers:
1450
1451 getQualifierElements(parser, property);
1452
1453 // Get value:
1454
1455 mike 1.23 if (getValueElement(parser, type, value))
1456 property.setValue(value);
1457
1458 expectEndTag(parser, "PROPERTY");
1459 }
1460
1461 return true;
1462 }
1463
1464 //------------------------------------------------------------------------------
1465 //
1466 // getArraySizeAttribute()
1467 //
1468 // Returns true if able to get array-size. Note that array size will
1469 // always be a positive integer.
1470 //
1471 // <!ENTITY % ArraySize "ARRAYSIZE CDATA #IMPLIED">
1472 //
1473 //------------------------------------------------------------------------------
1474
1475 Boolean XmlReader::getArraySizeAttribute(
1476 mike 1.23 Uint32 lineNumber,
1477 const XmlEntry& entry,
1478 const char* tagName,
1479 Uint32& value)
1480 {
1481 const char* tmp;
1482
1483 if (!entry.getAttributeValue("ARRAYSIZE", tmp))
1484 return false;
1485
1486 Uint64 arraySize;
1487
1488 if (!stringToUnsignedInteger(tmp, arraySize) || arraySize == 0)
1489 {
1490 char message[128];
1491 sprintf(message, "Illegal value for %s.%s", tagName, "ARRAYSIZE");
1492 throw XmlSemanticError(lineNumber, message);
1493 }
1494
1495 value = Uint32(arraySize);
1496 return true;
1497 mike 1.23 }
1498
1499 //------------------------------------------------------------------------------
1500 //
1501 // getPropertyArrayElement()
1502 //
1503 // <!ELEMENT PROPERTY.ARRAY (QUALIFIER*,VALUE.ARRAY?)>
1504 // <!ATTLIST PROPERTY.ARRAY
1505 // %CIMName;
1506 // %CIMType; #REQUIRED
1507 // %ArraySize;
1508 // %ClassOrigin;
1509 // %Propagated;>
1510 //
1511 //------------------------------------------------------------------------------
1512
1513 Boolean XmlReader::getPropertyArrayElement(
1514 XmlParser& parser,
1515 CIMProperty& property)
1516 {
1517 // Get PROPERTY element:
1518 mike 1.23
1519 XmlEntry entry;
1520
1521 if (!testStartTagOrEmptyTag(parser, entry, "PROPERTY.ARRAY"))
1522 return false;
1523
1524 Boolean empty = entry.type == XmlEntry::EMPTY_TAG;
1525
1526 // Get PROPERTY.NAME attribute:
1527
1528 String name =
1529 getCimNameAttribute(parser.getLine(), entry, "PROPERTY.ARRAY");
1530
1531 // Get PROPERTY.TYPE attribute:
1532
1533 CIMType type = getCimTypeAttribute(parser.getLine(), entry, "PROPERTY.ARRAY");
1534
1535 // Get PROPERTY.ARRAYSIZE attribute:
1536
1537 Uint32 arraySize = 0;
1538 getArraySizeAttribute(parser.getLine(), entry, "PROPERTY.ARRAY", arraySize);
1539 mike 1.23
1540 // Get PROPERTY.CLASSORIGIN attribute:
1541
1542 String classOrigin
1543 = getClassOriginAttribute(parser.getLine(), entry, "PROPERTY.ARRAY");
1544
1545 // Get PROPERTY.ARRAY.PROPAGATED
1546
1547 Boolean propagated = getCimBooleanAttribute(
1548 parser.getLine(), entry, "PROPERTY.ARRAY", "PROPAGATED", false, false);
1549
1550 // Create property:
1551
1552 CIMValue nullValue;
1553 nullValue.setNullValue(type, true, arraySize);
1554 property = CIMProperty(
1555 name, nullValue, arraySize, String(), classOrigin, propagated);
1556
1557 if (!empty)
1558 {
1559 // Get qualifiers:
1560 mike 1.23
1561 getQualifierElements(parser, property);
1562
1563 // Get value:
1564
1565 CIMValue value;
1566
1567 if (getValueArrayElement(parser, type, value))
1568 {
1569 if (arraySize && arraySize != value.getArraySize())
1570 {
1571 throw XmlSemanticError(parser.getLine(),
1572 "ARRAYSIZE attribute and value-array size are different");
1573 }
1574
1575 property.setValue(value);
1576 }
1577
1578 expectEndTag(parser, "PROPERTY.ARRAY");
1579 }
1580
1581 mike 1.23 return true;
1582 }
1583
1584 //------------------------------------------------------------------------------
1585 //
1586 // getHostElement()
1587 //
1588 // <!ELEMENT HOST (#PCDATA)>
1589 //
1590 //------------------------------------------------------------------------------
1591
1592 Boolean XmlReader::getHostElement(
1593 XmlParser& parser,
1594 String& host)
1595 {
1596 XmlEntry entry;
1597
1598 if (!testStartTag(parser, entry, "HOST"))
1599 return false;
1600
1601 if (!parser.next(entry) || entry.type != XmlEntry::CONTENT)
1602 mike 1.23 {
1603 throw XmlValidationError(parser.getLine(),
1604 "expected content of HOST element");
1605 }
1606
1607 host = entry.text;
1608
1609 expectEndTag(parser, "HOST");
1610 return true;
1611 }
1612
1613 //------------------------------------------------------------------------------
1614 //
1615 // getNameSpaceElement()
1616 //
1617 // <!ELEMENT NAMESPACE EMPTY>
1618 // <!ATTLIST NAMESPACE %CIMName;>
1619 //
1620 //------------------------------------------------------------------------------
1621
1622 Boolean XmlReader::getNameSpaceElement(
1623 mike 1.23 XmlParser& parser,
1624 String& nameSpaceComponent)
1625 {
1626 XmlEntry entry;
1627
1628 if (!testStartTagOrEmptyTag(parser, entry, "NAMESPACE"))
1629 return false;
1630
1631 Boolean empty = entry.type == XmlEntry::EMPTY_TAG;
1632
1633 nameSpaceComponent = getCimNameAttribute(
1634 parser.getLine(), entry, "NAMESPACE");
1635
1636 if (!empty)
1637 expectEndTag(parser, "NAMESPACE");
1638
1639 return true;
1640 }
1641
1642 //------------------------------------------------------------------------------
1643 //
1644 mike 1.23 // getLocalNameSpacePathElement()
1645 //
1646 // <!ELEMENT LOCALNAMESPACEPATH (NAMESPACE+)>
1647 //
1648 //------------------------------------------------------------------------------
1649
1650 Boolean XmlReader::getLocalNameSpacePathElement(
1651 XmlParser& parser,
1652 String& nameSpace)
1653 {
1654 XmlEntry entry;
1655
1656 if (!testStartTag(parser, entry, "LOCALNAMESPACEPATH"))
1657 return false;
1658
1659 String nameSpaceComponent;
1660
1661 while (getNameSpaceElement(parser, nameSpaceComponent))
1662 {
1663 if (nameSpace.size())
1664 nameSpace += '/';
1665 mike 1.23
1666 nameSpace += nameSpaceComponent;
1667 }
1668
1669 if (!nameSpace.size())
1670 {
1671 throw XmlValidationError(parser.getLine(),
1672 "Expected one or more NAMESPACE elements within "
1673 "LOCALNAMESPACEPATH element");
1674 }
1675
1676 expectEndTag(parser, "LOCALNAMESPACEPATH");
1677 return true;
1678 }
1679
1680 //------------------------------------------------------------------------------
1681 //
1682 // getNameSpacePathElement()
1683 //
1684 // <!ELEMENT NAMESPACEPATH (HOST,LOCALNAMESPACEPATH)>
1685 //
1686 mike 1.23 //------------------------------------------------------------------------------
1687
1688 Boolean XmlReader::getNameSpacePathElement(
1689 XmlParser& parser,
1690 String& host,
1691 String& nameSpace)
1692 {
1693 host.clear();
1694 nameSpace.clear();
1695
1696 XmlEntry entry;
1697
1698 if (!testStartTag(parser, entry, "NAMESPACEPATH"))
1699 return false;
1700
1701 if (!getHostElement(parser, host))
1702 throw XmlValidationError(parser.getLine(), "expected HOST element");
1703
1704 if (!getLocalNameSpacePathElement(parser, nameSpace))
1705 {
1706 throw XmlValidationError(parser.getLine(),
1707 mike 1.23 "expected LOCALNAMESPACEPATH element");
1708 }
1709
1710 expectEndTag(parser, "NAMESPACEPATH");
1711
1712 return true;
1713 }
1714
1715 //------------------------------------------------------------------------------
1716 //
1717 // getClassNameElement()
1718 //
1719 // <!ELEMENT CLASSNAME EMPTY>
1720 // <!ATTLIST CLASSNAME %CIMName;>
1721 //
1722 //------------------------------------------------------------------------------
1723
1724 Boolean XmlReader::getClassNameElement(
1725 XmlParser& parser,
1726 String& className,
1727 Boolean required)
1728 mike 1.23 {
1729 XmlEntry entry;
1730
1731 if (!testStartTagOrEmptyTag(parser, entry, "CLASSNAME"))
1732 {
1733 if (required)
1734 {
1735 throw XmlValidationError(parser.getLine(),
1736 "expected CLASSNAME element");
1737 }
1738 else
1739 return false;
1740 }
1741
1742 Boolean empty = entry.type == XmlEntry::EMPTY_TAG;
1743
1744 className = getCimNameAttribute(
1745 parser.getLine(), entry, "CLASSNAME", true);
1746
1747 if (!empty)
1748 expectEndTag(parser, "CLASSNAME");
1749 mike 1.23
1750 return true;
1751 }
1752
1753 //------------------------------------------------------------------------------
1754 //
1755 // getValueTypeAttribute()
1756 //
1757 // VALUETYPE (string|boolean|numeric) 'string'
1758 //
1759 //------------------------------------------------------------------------------
1760
1761 KeyBinding::Type XmlReader::getValueTypeAttribute(
1762 Uint32 lineNumber,
1763 const XmlEntry& entry,
1764 const char* elementName)
1765 {
1766 String tmp;
1767
1768 if (!entry.getAttributeValue("VALUETYPE", tmp))
1769 return KeyBinding::STRING;
1770 mike 1.23
1771 if (String::equal(tmp, "string"))
1772 return KeyBinding::STRING;
1773 else if (String::equal(tmp, "boolean"))
1774 return KeyBinding::BOOLEAN;
1775 else if (String::equal(tmp, "numeric"))
1776 return KeyBinding::NUMERIC;
1777
1778 char buffer[MESSAGE_SIZE];
1779
1780 sprintf(buffer,
1781 "Illegal value for %s.VALUETYPE attribute; "
1782 "CIMValue must be one of \"string\", \"boolean\", or \"numeric\"",
1783 elementName);
1784
1785 throw XmlSemanticError(lineNumber, buffer);
1786 return KeyBinding::BOOLEAN;
1787 }
1788
1789 //------------------------------------------------------------------------------
1790 //
1791 mike 1.23 // getKeyValueElement()
1792 //
1793 // <!ELEMENT KEYVALUE (#PCDATA)>
1794 // <!ATTLIST KEYVALUE
1795 // VALUETYPE (string|boolean|numeric) 'string'>
1796 //
1797 //------------------------------------------------------------------------------
1798
1799 Boolean XmlReader::getKeyValueElement(
1800 XmlParser& parser,
1801 KeyBinding::Type& type,
1802 String& value)
1803 {
1804 XmlEntry entry;
1805
1806 if (!testStartTagOrEmptyTag(parser, entry, "KEYVALUE"))
1807 return false;
1808
1809 Boolean empty = entry.type == XmlEntry::EMPTY_TAG;
1810
1811 type = getValueTypeAttribute(parser.getLine(), entry, "KEYVALUE");
1812 mike 1.23
1813 value.clear();
1814
1815 if (!empty)
1816 {
1817 if (!parser.next(entry))
1818 throw XmlException(XmlException::UNCLOSED_TAGS, parser.getLine());
1819
1820 if (entry.type == XmlEntry::CONTENT)
1821 value = entry.text;
1822 else
1823 parser.putBack(entry);
1824
1825 expectEndTag(parser, "KEYVALUE");
1826 }
1827
1828 return true;
1829 }
1830
1831 //------------------------------------------------------------------------------
1832 //
1833 mike 1.23 // getKeyBindingElement()
1834 //
1835 // <!ELEMENT KEYBINDING (KEYVALUE|VALUE.REFERENCE)>
1836 // <!ATTLIST KEYBINDING
1837 // %CIMName;>
1838 //
1839 //------------------------------------------------------------------------------
1840
1841 Boolean XmlReader::getKeyBindingElement(
1842 XmlParser& parser,
1843 String& name,
1844 String& value,
1845 KeyBinding::Type& type)
1846 {
1847 XmlEntry entry;
1848
1849 if (!testStartTag(parser, entry, "KEYBINDING"))
1850 return false;
1851
1852 name = getCimNameAttribute(parser.getLine(), entry, "KEYBINDING");
1853
1854 mike 1.23 if (!getKeyValueElement(parser, type, value))
|
1867 mike 1.23
1868 expectEndTag(parser, "KEYBINDING");
1869 return true;
1870 }
1871
1872 //------------------------------------------------------------------------------
1873 //
1874 // getInstanceNameElement()
1875 //
1876 // <!ELEMENT INSTANCENAME (KEYBINDING*|KEYVALUE?|VALUE.REFERENCE?)>
1877 // <!ATTLIST INSTANCENAME
1878 // %ClassName;>
1879 //
1880 // ATTN-B: VALUE.REFERENCE sub-element not accepted yet.
1881 //
1882 //------------------------------------------------------------------------------
1883
1884 Boolean XmlReader::getInstanceNameElement(
1885 XmlParser& parser,
1886 String& className,
1887 Array<KeyBinding>& keyBindings)
1888 mike 1.23 {
1889 className.clear();
1890 keyBindings.clear();
1891
1892 XmlEntry entry;
1893
1894 if (!testStartTagOrEmptyTag(parser, entry, "INSTANCENAME"))
1895 return false;
1896
1897 Boolean empty = entry.type == XmlEntry::EMPTY_TAG;
1898
1899 className = getClassNameAttribute(parser.getLine(), entry, "INSTANCENAME");
1900
1901 if (!empty)
1902 {
1903 String name;
1904 KeyBinding::Type type;
1905 String value;
1906
1907 while (getKeyBindingElement(parser, name, value, type))
1908 keyBindings.append(KeyBinding(name, value, type));
1909 mike 1.23
1910 if (!empty)
1911 expectEndTag(parser, "INSTANCENAME");
1912 }
1913
1914 return true;
1915 }
1916
1917 Boolean XmlReader::getInstanceNameElement(
1918 XmlParser& parser,
1919 CIMReference& instanceName)
1920 {
1921 String className;
1922 Array<KeyBinding> keyBindings;
1923
1924 if (!XmlReader::getInstanceNameElement(parser, className, keyBindings))
1925 return false;
1926
1927 instanceName.set(String(), String(), className, keyBindings);
1928 return true;
1929 }
1930 mike 1.23
1931 //------------------------------------------------------------------------------
1932 //
1933 // getInstancePathElement()
1934 //
1935 // <!ELEMENT INSTANCEPATH (NAMESPACEPATH,INSTANCENAME)>
1936 //
1937 //------------------------------------------------------------------------------
1938
1939 Boolean XmlReader::getInstancePathElement(
1940 XmlParser& parser,
1941 CIMReference& reference)
1942 {
1943 XmlEntry entry;
1944
1945 if (!testStartTag(parser, entry, "INSTANCEPATH"))
1946 return false;
1947
1948 String host;
1949 String nameSpace;
1950
1951 mike 1.23 if (!getNameSpacePathElement(parser, host, nameSpace))
1952 {
1953 throw XmlValidationError(parser.getLine(),
1954 "expected NAMESPACEPATH element");
1955 }
1956
1957 String className;
1958 Array<KeyBinding> keyBindings;
1959
1960 if (!getInstanceNameElement(parser, className, keyBindings))
1961 {
1962 throw XmlValidationError(parser.getLine(),
1963 "expected INSTANCENAME element");
1964 }
1965
1966 reference.set(host, nameSpace, className, keyBindings);
1967
1968 expectEndTag(parser, "INSTANCEPATH");
1969 return true;
1970 }
1971
1972 mike 1.23 //------------------------------------------------------------------------------
1973 //
1974 // getLocalInstancePathElement()
1975 //
1976 // <!ELEMENT LOCALINSTANCEPATH (NAMESPACEPATH,INSTANCENAME)>
1977 //
1978 //------------------------------------------------------------------------------
1979
1980 Boolean XmlReader::getLocalInstancePathElement(
1981 XmlParser& parser,
1982 CIMReference& reference)
1983 {
1984 XmlEntry entry;
1985
1986 if (!testStartTag(parser, entry, "LOCALINSTANCEPATH"))
1987 return false;
1988
1989 String nameSpace;
1990
1991 if (!getLocalNameSpacePathElement(parser, nameSpace))
1992 {
1993 mike 1.23 throw XmlValidationError(parser.getLine(),
1994 "expected LOCALNAMESPACEPATH element");
1995 }
1996
1997 String className;
1998 Array<KeyBinding> keyBindings;
1999
2000 if (!getInstanceNameElement(parser, className, keyBindings))
2001 {
2002 throw XmlValidationError(parser.getLine(),
2003 "expected INSTANCENAME element");
2004 }
2005
2006 reference.set(String(), nameSpace, className, keyBindings);
2007
2008 expectEndTag(parser, "LOCALINSTANCEPATH");
2009 return true;
2010 }
2011
2012 //------------------------------------------------------------------------------
2013 //
2014 mike 1.23 // getClassPathElement()
2015 //
2016 // <!ELEMENT CLASSPATH (NAMESPACEPATH,CLASSNAME)>
2017 //
2018 //------------------------------------------------------------------------------
2019
2020 Boolean XmlReader::getClassPathElement(
2021 XmlParser& parser,
2022 CIMReference& reference)
2023 {
2024 XmlEntry entry;
2025
2026 if (!testStartTag(parser, entry, "CLASSPATH"))
2027 return false;
2028
2029 String host;
2030 String nameSpace;
2031
2032 if (!getNameSpacePathElement(parser, host, nameSpace))
2033 {
2034 throw XmlValidationError(parser.getLine(),
2035 mike 1.23 "expected NAMESPACEPATH element");
2036 }
2037
2038 String className;
2039
2040 if (!getClassNameElement(parser, className))
2041 {
2042 throw XmlValidationError(parser.getLine(),
2043 "expected CLASSNAME element");
2044 }
2045
2046 reference.set(host, nameSpace, className);
2047
2048 expectEndTag(parser, "CLASSPATH");
2049 return true;
2050 }
2051
2052 //------------------------------------------------------------------------------
2053 //
2054 // getLocalClassPathElement()
2055 //
2056 mike 1.23 // <!ELEMENT LOCALCLASSPATH (LOCALNAMESPACEPATH,CLASSNAME)>
2057 //
2058 //------------------------------------------------------------------------------
2059
2060 Boolean XmlReader::getLocalClassPathElement(
2061 XmlParser& parser,
2062 CIMReference& reference)
2063 {
2064 XmlEntry entry;
2065
2066 if (!testStartTag(parser, entry, "LOCALCLASSPATH"))
2067 return false;
2068
2069 String nameSpace;
2070
2071 if (!getLocalNameSpacePathElement(parser, nameSpace))
2072 {
2073 throw XmlValidationError(parser.getLine(),
2074 "expected LOCALNAMESPACEPATH element");
2075 }
2076
2077 mike 1.23 String className;
2078
2079 if (!getClassNameElement(parser, className))
2080 {
2081 throw XmlValidationError(parser.getLine(),
2082 "expected CLASSNAME element");
2083 }
2084
2085 reference.set(String(), nameSpace, className);
2086
2087 expectEndTag(parser, "LOCALCLASSPATH");
2088
2089 return true;
2090 }
2091
2092 //------------------------------------------------------------------------------
2093 //
2094 // getValueReferenceElement()
2095 //
2096 // <!ELEMENT VALUE.REFERENCE (CLASSPATH|LOCALCLASSPATH|CLASSNAME|
2097 // INSTANCEPATH|LOCALINSTANCEPATH|INSTANCENAME)>
2098 mike 1.23 //
2099 //
2100 //------------------------------------------------------------------------------
2101
2102 Boolean XmlReader::getValueReferenceElement(
2103 XmlParser& parser,
2104 CIMReference& reference)
2105 {
2106 XmlEntry entry;
2107
2108 if (!testStartTag(parser, entry, "VALUE.REFERENCE"))
2109 return false;
2110
2111 if (!parser.next(entry))
2112 throw XmlException(XmlException::UNCLOSED_TAGS, parser.getLine());
2113
2114 if (entry.type != XmlEntry::START_TAG &&
2115 entry.type != XmlEntry::EMPTY_TAG)
2116 {
2117 throw XmlValidationError(parser.getLine(),
2118 "Expected one of the following start tags: "
2119 mike 1.23 "CLASSPATH, LOCALCLASSPATH, CLASSNAME, INSTANCEPATH, "
2120 "LOCALINSTANCEPATH, INSTANCENAME");
2121 }
2122
2123 if (strcmp(entry.text, "CLASSPATH") == 0)
2124 {
2125 parser.putBack(entry);
2126 getClassPathElement(parser, reference);
2127 }
2128 else if (strcmp(entry.text, "LOCALCLASSPATH") == 0)
2129 {
2130 parser.putBack(entry);
2131 getLocalClassPathElement(parser, reference);
2132 }
2133 else if (strcmp(entry.text, "CLASSNAME") == 0)
2134 {
2135 parser.putBack(entry);
2136 String className;
2137 getClassNameElement(parser, className);
2138 reference.set(String(), String(), className);
2139 }
2140 mike 1.23 else if (strcmp(entry.text, "INSTANCEPATH") == 0)
2141 {
2142 parser.putBack(entry);
2143 getInstancePathElement(parser, reference);
2144 }
2145 else if (strcmp(entry.text, "LOCALINSTANCEPATH") == 0)
2146 {
2147 parser.putBack(entry);
2148 getLocalInstancePathElement(parser, reference);
2149 }
2150 else if (strcmp(entry.text, "INSTANCENAME") == 0)
2151 {
2152 parser.putBack(entry);
2153 String className;
2154 Array<KeyBinding> keyBindings;
2155 getInstanceNameElement(parser, className, keyBindings);
2156 reference.set(String(), String(), className, keyBindings);
2157 }
2158
2159 expectEndTag(parser, "VALUE.REFERENCE");
2160 return true;
2161 mike 1.23 }
2162
2163 //------------------------------------------------------------------------------
2164 //
2165 // getPropertyReferenceElement()
2166 //
2167 // <!ELEMENT PROPERTY.REFERENCE (QUALIFIER*,(VALUE.REFERENCE)?)>
2168 // <!ATTLIST PROPERTY.REFERENCE
2169 // %CIMName;
2170 // %ReferenceClass;
2171 // %ClassOrigin;
2172 // %Propagated;>
2173 //
2174 //------------------------------------------------------------------------------
2175
2176 Boolean XmlReader::getPropertyReferenceElement(
2177 XmlParser& parser,
2178 CIMProperty& property)
2179 {
2180 XmlEntry entry;
2181
2182 mike 1.23 if (!testStartTagOrEmptyTag(parser, entry, "PROPERTY.REFERENCE"))
2183 return false;
2184
2185 Boolean empty = entry.type == XmlEntry::EMPTY_TAG;
2186
2187 // Get PROPERTY.NAME attribute:
2188
2189 String name = getCimNameAttribute(
2190 parser.getLine(), entry, "PROPERTY.REFERENCE");
2191
2192 // Get PROPERTY.REFERENCECLASS attribute:
2193
2194 String referenceClass = getReferenceClassAttribute(
2195 parser.getLine(), entry, "PROPERTY.REFERENCE");
2196
2197 // Get PROPERTY.CLASSORIGIN attribute:
2198
2199 String classOrigin =
2200 getClassOriginAttribute(parser.getLine(), entry, "PROPERTY.REFERENCE");
2201
2202 // Get PROPERTY.PROPAGATED
2203 mike 1.23
2204 Boolean propagated = getCimBooleanAttribute(parser.getLine(), entry,
2205 "PROPERTY.REFERENCE", "PROPAGATED", false, false);
2206
2207 // Create property:
2208
2209 CIMValue value;
2210 value.set(CIMReference());
2211 property = CIMProperty(
2212 name, value, 0, referenceClass, classOrigin, propagated);
2213
2214 if (!empty)
2215 {
2216 getQualifierElements(parser, property);
2217
2218 CIMReference reference;
2219
2220 if (getValueReferenceElement(parser, reference))
2221 property.setValue(reference);
2222
2223 expectEndTag(parser, "PROPERTY.REFERENCE");
2224 mike 1.23 }
2225
2226 return true;
2227 }
2228
2229 //------------------------------------------------------------------------------
2230 //
2231 // GetPropertyElements()
2232 //
2233 //------------------------------------------------------------------------------
2234
2235 template<class CONTAINER>
2236 void GetPropertyElements(XmlParser& parser, CONTAINER& container)
2237 {
2238 CIMProperty property;
2239
2240 while (XmlReader::getPropertyElement(parser, property) ||
2241 XmlReader::getPropertyArrayElement(parser, property) ||
2242 XmlReader::getPropertyReferenceElement(parser, property))
2243 {
2244 try
2245 mike 1.23 {
2246 container.addProperty(property);
2247 }
2248 catch (AlreadyExists&)
2249 {
2250 throw XmlSemanticError(parser.getLine(), "duplicate property");
2251 }
2252 }
2253 }
2254
2255 //------------------------------------------------------------------------------
2256 //
2257 // getParameterElement()
2258 //
2259 // <!ELEMENT PARAMETER (QUALIFIER*)>
2260 // <!ATTLIST PARAMETER
2261 // %CIMName;
2262 // %CIMType; #REQUIRED>
2263 //
2264 //------------------------------------------------------------------------------
2265
2266 mike 1.23 Boolean XmlReader::getParameterElement(
2267 XmlParser& parser,
2268 CIMParameter& parameter)
2269 {
2270 XmlEntry entry;
2271
2272 if (!testStartTagOrEmptyTag(parser, entry, "PARAMETER"))
2273 return false;
2274
2275 Boolean empty = entry.type == XmlEntry::EMPTY_TAG;
2276
2277 // Get PARAMETER.NAME attribute:
2278
2279 String name = getCimNameAttribute(parser.getLine(), entry, "PARAMETER");
2280
2281 // Get PARAMETER.TYPE attribute:
2282
2283 CIMType type = getCimTypeAttribute(parser.getLine(), entry, "PARAMETER");
2284
2285 // Create parameter:
2286
2287 mike 1.23 parameter = CIMParameter(name, type);
2288
2289 if (!empty)
2290 {
2291 getQualifierElements(parser, parameter);
2292
2293 expectEndTag(parser, "PARAMETER");
2294 }
2295
2296 return true;
2297 }
2298
2299 //------------------------------------------------------------------------------
2300 //
2301 // getParameterArrayElement()
2302 //
2303 // <!ELEMENT PARAMETER.ARRAY (QUALIFIER*)>
2304 // <!ATTLIST PARAMETER.ARRAY
2305 // %CIMName;
2306 // %CIMType; #REQUIRED
2307 // %ArraySize;>
2308 mike 1.23 //
2309 //------------------------------------------------------------------------------
2310
2311 Boolean XmlReader::getParameterArrayElement(
2312 XmlParser& parser,
2313 CIMParameter& parameter)
2314 {
2315 XmlEntry entry;
2316
2317 if (!testStartTagOrEmptyTag(parser, entry, "PARAMETER.ARRAY"))
2318 return false;
2319
2320 Boolean empty = entry.type == XmlEntry::EMPTY_TAG;
2321
2322 // Get PARAMETER.ARRAY.NAME attribute:
2323
2324 String name = getCimNameAttribute(
2325 parser.getLine(), entry, "PARAMETER.ARRAY");
2326
2327 // Get PARAMETER.ARRAY.TYPE attribute:
2328
2329 mike 1.23 CIMType type = getCimTypeAttribute(parser.getLine(), entry, "PARAMETER.ARRAY");
2330
2331 // Get PARAMETER.ARRAYSIZE attribute:
2332
2333 Uint32 arraySize = 0;
2334 getArraySizeAttribute(parser.getLine(), entry, "PARAMETER.ARRAY",arraySize);
2335
2336 // Create parameter:
2337
2338 parameter = CIMParameter(name, type, true, arraySize);
2339
2340 if (!empty)
2341 {
2342 getQualifierElements(parser, parameter);
2343
2344 expectEndTag(parser, "PARAMETER.ARRAY");
2345 }
2346
2347 return true;
2348 }
2349
2350 mike 1.23 //------------------------------------------------------------------------------
2351 //
2352 // getParameterReferenceElement()
2353 //
2354 // <!ELEMENT PARAMETER.REFERENCE (QUALIFIER*)>
2355 // <!ATTLIST PARAMETER.REFERENCE
2356 // %CIMName;
2357 // %ReferenceClass;>
2358 //
2359 //------------------------------------------------------------------------------
2360
2361 Boolean XmlReader::getParameterReferenceElement(
2362 XmlParser& parser,
2363 CIMParameter& parameter)
2364 {
2365 XmlEntry entry;
2366
2367 if (!testStartTagOrEmptyTag(parser, entry, "PARAMETER.REFERENCE"))
2368 return false;
2369
2370 Boolean empty = entry.type == XmlEntry::EMPTY_TAG;
2371 mike 1.23
2372 // Get PARAMETER.NAME attribute:
2373
2374 String name = getCimNameAttribute(
2375 parser.getLine(), entry, "PARAMETER.REFERENCE");
2376
2377 // Get PARAMETER.REFERENCECLASS attribute:
2378
2379 String referenceClass = getReferenceClassAttribute(
2380 parser.getLine(), entry, "PARAMETER.REFERENCE");
2381
2382 // Create parameter:
2383
2384 parameter = CIMParameter(name, CIMType::REFERENCE, false, 0, referenceClass);
2385
2386 if (!empty)
2387 {
2388 getQualifierElements(parser, parameter);
2389 expectEndTag(parser, "PARAMETER.REFERENCE");
2390 }
2391
2392 mike 1.23 return true;
2393 }
2394
2395 //------------------------------------------------------------------------------
2396 //
2397 // GetParameterElements()
2398 //
2399 //------------------------------------------------------------------------------
2400
2401 template<class CONTAINER>
2402 void GetParameterElements(XmlParser& parser, CONTAINER& container)
2403 {
2404 CIMParameter parameter;
2405
2406 while (XmlReader::getParameterElement(parser, parameter) ||
2407 XmlReader::getParameterArrayElement(parser, parameter) ||
2408 XmlReader::getParameterReferenceElement(parser, parameter))
2409 {
2410 try
2411 {
2412 container.addParameter(parameter);
2413 mike 1.23 }
2414 catch (AlreadyExists&)
2415 {
2416 throw XmlSemanticError(parser.getLine(), "duplicate parameter");
2417 }
2418 }
2419 }
2420
2421 //------------------------------------------------------------------------------
2422 //
2423 // getQualifierDeclElement()
2424 //
2425 // <!ELEMENT QUALIFIER.DECLARATION (SCOPE?,(VALUE|VALUE.ARRAY)?)>
2426 // <!ATTLIST QUALIFIER.DECLARATION
2427 // %CIMName;
2428 // %CIMType; #REQUIRED
2429 // ISARRAY (true|false) #IMPLIED
2430 // %ArraySize;
2431 // %QualifierFlavor;>
2432 //
2433 //------------------------------------------------------------------------------
2434 mike 1.23
2435 Boolean XmlReader::getQualifierDeclElement(
2436 XmlParser& parser,
2437 CIMQualifierDecl& qualifierDecl)
2438 {
2439 XmlEntry entry;
2440
2441 if (!testStartTagOrEmptyTag(parser, entry, "QUALIFIER.DECLARATION"))
2442 return false;
2443
2444 Boolean empty = entry.type == XmlEntry::EMPTY_TAG;
2445
2446 // Get NAME attribute:
2447
2448 String name = getCimNameAttribute(
2449 parser.getLine(), entry, "QUALIFIER.DECLARATION");
2450
2451 // Get TYPE attribute:
2452
2453 CIMType type = getCimTypeAttribute(
2454 parser.getLine(), entry, "QUALIFIER.DECLARATION");
2455 mike 1.23
2456 // Get ISARRAY attribute:
2457
2458 Boolean isArray = false;
2459 getIsArrayAttribute(
2460 parser.getLine(), entry, "QUALIFIER.DECLARATION", isArray);
2461
2462 // Get ARRAYSIZE attribute:
2463
2464 Uint32 arraySize = 0;
2465 Boolean gotArraySize = getArraySizeAttribute(parser.getLine(),
2466 entry, "QUALIFIER.DECLARATION", arraySize);
2467
2468 // Get flavor oriented attributes:
2469
2470 Uint32 flavor = getFlavor(entry,parser.getLine(), "QUALIFIER.DECLARATION");
2471
2472 // No need to look for interior elements if empty tag:
2473
2474 Uint32 scope = CIMScope::NONE;
2475 CIMValue value;
2476 mike 1.23
2477 if (!empty)
2478 {
2479 // Get the option SCOPE element:
2480
2481 scope = getOptionalScope(parser);
2482
2483 // Get VALUE or VALUE.ARRAY element:
2484
2485 if (getValueArrayElement(parser, type, value))
2486 {
2487 if (!isArray)
2488 {
2489 throw XmlSemanticError(parser.getLine(),
2490 "VALUE.ARRAY element encountered without "
2491 "ISARRAY attribute");
2492 }
2493
2494 if (arraySize && arraySize != value.getArraySize())
2495 {
2496 throw XmlSemanticError(parser.getLine(),
2497 mike 1.23 "VALUE.ARRAY size is not the same as "
2498 "ARRAYSIZE attribute");
2499 }
2500 }
2501 else if (getValueElement(parser, type, value))
2502 {
2503 if (isArray)
2504 {
2505 throw XmlSemanticError(parser.getLine(),
2506 "ISARRAY attribute used but VALUE element encountered");
2507 }
2508 }
2509
2510 // Now get the closing tag:
2511
2512 expectEndTag(parser, "QUALIFIER.DECLARATION");
2513 }
2514
2515 if (value.getType() == CIMType::NONE)
2516 {
2517 if (isArray)
2518 mike 1.23 value.setNullValue(type, true, arraySize);
2519 else
2520 value.setNullValue(type, false);
2521 }
2522
2523 CIMQualifierDecl tmp(name, value, scope, flavor, arraySize);
2524 qualifierDecl = CIMQualifierDecl(name, value, scope, flavor, arraySize);
2525 return true;
2526 }
2527
2528 //------------------------------------------------------------------------------
2529 // getMethodElement()
2530 //
2531 // <!ELEMENT METHOD (QUALIFIER*,(PARAMETER|PARAMETER.REFERENCE|
2532 // PARAMETER.ARRAY|PARAMETER.REFARRAY)*)>
2533 // <!ATTLIST METHOD
2534 // %CIMName;
2535 // %CIMType; #IMPLIED
2536 // %ClassOrigin;
2537 // %Propagated;>
2538 //
2539 mike 1.23 //------------------------------------------------------------------------------
2540
2541 Boolean XmlReader::getMethodElement(XmlParser& parser, CIMMethod& method)
2542 {
2543 XmlEntry entry;
2544
2545 if (!testStartTagOrEmptyTag(parser, entry, "METHOD"))
2546 return false;
2547
2548 Boolean empty = entry.type == XmlEntry::EMPTY_TAG;
2549
2550 String name = getCimNameAttribute(parser.getLine(), entry, "PROPERTY");
2551
2552 CIMType type = getCimTypeAttribute(parser.getLine(), entry, "PROPERTY");
2553
2554 String classOrigin =
2555 getClassOriginAttribute(parser.getLine(), entry, "PROPERTY");
2556
2557 Boolean propagated = getCimBooleanAttribute(
2558 parser.getLine(), entry, "PROPERTY", "PROPAGATED", false, false);
2559
2560 mike 1.23 method = CIMMethod(name, type, classOrigin, propagated);
2561
2562 if (!empty)
2563 {
2564 getQualifierElements(parser, method);
2565
2566 GetParameterElements(parser, method);
2567
2568 expectEndTag(parser, "METHOD");
2569 }
2570
2571 return true;
2572 }
2573
2574 //------------------------------------------------------------------------------
2575 // getClassElement()
2576 //
2577 // <!ELEMENT CLASS (QUALIFIER*,
2578 // (PROPERTY|PROPERTY.ARRAY|PROPERTY.REFERENCE)*,METHOD*)>
2579 // <!ATTLIST CLASS %CIMName; %SuperClass;>
2580 //
2581 mike 1.23 //------------------------------------------------------------------------------
2582
2583 Boolean XmlReader::getClassElement(XmlParser& parser, CIMClass& cimClass)
2584 {
2585 XmlEntry entry;
2586
2587 if (!testStartTag(parser, entry, "CLASS"))
2588 return false;
2589
2590 String name = getCimNameAttribute(parser.getLine(), entry, "CLASS");
2591
2592 String superClass = getSuperClassAttribute(parser.getLine(), entry,"CLASS");
2593
2594 cimClass = CIMClass(name, superClass);
2595
2596 // Get QUALIFIER elements:
2597
2598 getQualifierElements(parser, cimClass);
2599
2600 // Get PROPERTY elements:
2601
2602 mike 1.23 GetPropertyElements(parser, cimClass);
2603
2604 // Get METHOD elements:
2605
2606 CIMMethod method;
2607
2608 while (getMethodElement(parser, method))
2609 cimClass.addMethod(method);
2610
2611 // Get CLASS end tag:
2612
2613 expectEndTag(parser, "CLASS");
2614
2615 return true;
2616 }
2617
2618 //------------------------------------------------------------------------------
2619 // getInstanceElement()
2620 //
2621 // <!ELEMENT INSTANCE (QUALIFIER*,
2622 // (PROPERTY|PROPERTY.ARRAY|PROPERTY.REFERENCE)*) >
2623 mike 1.23 // <!ATTLIST INSTANCE
2624 // %ClassName;>
2625 //
2626 //------------------------------------------------------------------------------
2627
2628 Boolean XmlReader::getInstanceElement(
2629 XmlParser& parser,
2630 CIMInstance& cimInstance)
2631 {
2632 XmlEntry entry;
2633
2634 if (!testStartTag(parser, entry, "INSTANCE"))
2635 return false;
2636
2637 String className = getClassNameAttribute(
2638 parser.getLine(), entry, "INSTANCE");
2639
2640 cimInstance = CIMInstance(className);
2641
2642 // Get QUALIFIER elements:
2643
2644 mike 1.23 getQualifierElements(parser, cimInstance);
2645
2646 // Get PROPERTY elements:
2647
2648 GetPropertyElements(parser, cimInstance);
2649
2650 // Get INSTANCE end tag:
2651
2652 expectEndTag(parser, "INSTANCE");
2653
2654 return true;
2655 }
2656
2657 //------------------------------------------------------------------------------
2658 //
2659 // getObject()
2660 //
2661 //------------------------------------------------------------------------------
2662
2663 void XmlReader::getObject(XmlParser& parser, CIMClass& x)
2664 {
2665 mike 1.23 if (!getClassElement(parser, x))
2666 {
2667 throw XmlValidationError(parser.getLine(),
2668 "expected CLASS element");
2669 }
2670 }
2671
2672 //------------------------------------------------------------------------------
2673 //
2674 // getObject()
2675 //
2676 //------------------------------------------------------------------------------
2677
2678 void XmlReader::getObject(XmlParser& parser, CIMInstance& x)
2679 {
2680 if (!getInstanceElement(parser, x))
2681 {
2682 throw XmlValidationError(parser.getLine(),
2683 "expected INSTANCE element");
2684 }
2685 }
2686 mike 1.23
2687 //------------------------------------------------------------------------------
2688 //
2689 // getObject()
2690 //
2691 //------------------------------------------------------------------------------
2692
2693 void XmlReader::getObject(XmlParser& parser, CIMQualifierDecl& x)
2694 {
2695 if (!getQualifierDeclElement(parser, x))
2696 {
2697 throw XmlValidationError(parser.getLine(),
2698 "expected QUALIFIER.DECLARATION element");
2699 }
2700 }
2701
2702 //------------------------------------------------------------------------------
2703 //
2704 // getMessageStartTag()
2705 //
2706 //------------------------------------------------------------------------------
2707 mike 1.23
2708 Boolean XmlReader::getMessageStartTag(
2709 XmlParser& parser,
2710 String& id,
2711 const char*& protocolVersion)
2712 {
2713 XmlEntry entry;
2714
2715 if (!testStartTag(parser, entry, "MESSAGE"))
2716 return false;
2717
2718 // Get MESSAGE.ID:
2719
2720 if (!entry.getAttributeValue("ID", id))
2721 throw XmlValidationError(parser.getLine(),
2722 "Bad or missing MESSAGE.ID attribute");
2723
2724 // Get MESSAGE.PROTOCOLVERSION:
2725
2726 if (!entry.getAttributeValue("PROTOCOLVERSION", protocolVersion))
2727 throw XmlValidationError(parser.getLine(),
2728 mike 1.23 "Bad or missing MESSAGE.PROTOCOLVERSION attribute");
2729
2730 return true;
2731 }
2732
2733 //------------------------------------------------------------------------------
2734 //
2735 // getIMethodCallStartTag()
2736 //
2737 //------------------------------------------------------------------------------
2738
2739 Boolean XmlReader::getIMethodCallStartTag(
2740 XmlParser& parser,
2741 const char*& name)
2742 {
2743 XmlEntry entry;
2744
2745 if (!testStartTag(parser, entry, "IMETHODCALL"))
2746 return false;
2747
2748 // Get IMETHODCALL.NAME attribute:
2749 mike 1.23
2750 if (!entry.getAttributeValue("NAME", name))
2751 throw XmlValidationError(parser.getLine(),
2752 "Missing IMETHODCALL.NAME attribute");
2753
2754 return true;
2755 }
2756
2757 //------------------------------------------------------------------------------
2758 //
2759 // getIMethodResponseStartTag()
2760 //
2761 //------------------------------------------------------------------------------
2762
2763 Boolean XmlReader::getIMethodResponseStartTag(
2764 XmlParser& parser,
2765 const char*& name)
2766 {
2767 XmlEntry entry;
2768
2769 if (!testStartTag(parser, entry, "IMETHODRESPONSE"))
2770 mike 1.23 return false;
2771
2772 // Get IMETHODRESPONSE.NAME attribute:
2773
2774 if (!entry.getAttributeValue("NAME", name))
2775 throw XmlValidationError(parser.getLine(),
2776 "Missing IMETHODRESPONSE.NAME attribute");
2777
2778 return true;
2779 }
2780
2781 //------------------------------------------------------------------------------
2782 //
2783 // getIParamValueTag()
2784 //
2785 //------------------------------------------------------------------------------
2786
2787 Boolean XmlReader::getIParamValueTag(
2788 XmlParser& parser,
2789 const char*& name)
2790 {
2791 mike 1.23 XmlEntry entry;
2792
2793 if (!testStartTag(parser, entry, "IPARAMVALUE"))
2794 return false;
2795
2796 // Get IPARAMVALUE.NAME attribute:
2797
2798 if (!entry.getAttributeValue("NAME", name))
2799 throw XmlValidationError(parser.getLine(),
2800 "Missing IPARAMVALUE.NAME attribute");
2801
2802 return true;
2803 }
2804
2805 //------------------------------------------------------------------------------
2806 //
2807 // getBooleanValueElement()
2808 //
2809 // Get an elements like: "<VALUE>FALSE</VALUE>"
2810 //
2811 //------------------------------------------------------------------------------
2812 mike 1.23
2813 Boolean XmlReader::getBooleanValueElement(
2814 XmlParser& parser,
2815 Boolean& result,
2816 Boolean required)
2817 {
2818 XmlEntry entry;
2819
2820 if (!testStartTag(parser, entry, "VALUE"))
2821 {
2822 if (required)
2823 {
2824 throw XmlValidationError(parser.getLine(),
2825 "Expected VALUE element");
2826 }
2827 return false;
2828 }
2829
2830 expectContentOrCData(parser, entry);
2831
2832 if (strcmp(entry.text, "TRUE") == 0)
2833 mike 1.23 result = true;
2834 else if (strcmp(entry.text, "FALSE") == 0)
2835 result = false;
2836 else
2837 throw XmlSemanticError(parser.getLine(),
2838 "Bad value for VALUE element: must be \"TRUE\" or \"FALSE\"");
2839
2840 expectEndTag(parser, "VALUE");
2841
2842 return true;
2843 }
2844
2845 //------------------------------------------------------------------------------
2846 //
2847 // getErrorElement()
2848 //
2849 // <!ELEMENT ERROR EMPTY>
2850 // <!ATTLIST ERROR
2851 // CODE CDATA #REQUIRED
2852 // DESCRIPTION CDATA #IMPLIED>
2853 //
2854 mike 1.23 //------------------------------------------------------------------------------
2855
2856 Boolean XmlReader::getErrorElement(
2857 XmlParser& parser,
2858 CIMStatusCode& code,
2859 const char*& description,
2860 Boolean required)
2861 {
2862 XmlEntry entry;
2863
2864 if (!testStartTagOrEmptyTag(parser, entry, "ERROR"))
2865 {
2866 if (required)
2867 throw XmlValidationError(parser.getLine(),"Expected ERROR element");
2868 return false;
2869 }
2870
2871 Boolean empty = entry.type == XmlEntry::EMPTY_TAG;
2872
2873 // Get ERROR.CODE
2874
2875 mike 1.23 Uint32 tmpCode;
2876
2877 if (!entry.getAttributeValue("CODE", tmpCode))
2878 throw XmlValidationError(
2879 parser.getLine(), "missing ERROR.CODE attribute");
2880
2881 code = CIMStatusCode(tmpCode);
2882
2883 // Get ERROR.DESCRIPTION:
2884
2885 description = "";
2886 entry.getAttributeValue("DESCRIPTION", description);
2887
2888 if (!empty)
2889 expectEndTag(parser, "ERROR");
2890
2891 return true;
2892 }
2893
2894
2895 //------------------------------------------------------------------------------
2896 mike 1.23 // getObjectWithPath()
2897 //
2898 // <!ELEMENT VALUE.OBJECTWITHPATH ((CLASSPATH,CLASS)|(INSTANCEPATH,INSTANCE))>
2899 //
2900 //------------------------------------------------------------------------------
2901
2902 Boolean XmlReader::getObjectWithPath(
2903 XmlParser& parser,
2904 CIMObjectWithPath& objectWithPath)
2905 {
2906 XmlEntry entry;
2907
2908 if (!testStartTag(parser, entry, "VALUE.OBJECTWITHPATH"))
2909 return false;
2910
2911 CIMReference reference;
2912 Boolean isInstance = false;
2913
2914 if (XmlReader::getInstancePathElement(parser, reference))
2915 isInstance = true;
2916 else if (!XmlReader::getClassPathElement(parser, reference))
2917 mike 1.23 {
2918 throw XmlValidationError(parser.getLine(),
2919 "Expected INSTANCE element");
2920 }
2921
2922 if (isInstance)
2923 {
2924 CIMInstance cimInstance;
2925
2926 if (!XmlReader::getInstanceElement(parser, cimInstance))
2927 {
2928 throw XmlValidationError(parser.getLine(),
2929 "Expected INSTANCEPATH or CLASSPATH element");
2930 }
2931 objectWithPath.set(reference, CIMObject(cimInstance));
2932 }
2933 else
2934 {
2935 CIMClass cimClass;
2936
2937 if (!XmlReader::getClassElement(parser, cimClass))
2938 mike 1.23 {
2939 throw XmlValidationError(parser.getLine(),
2940 "Expected CLASS element");
2941 }
2942 objectWithPath.set(reference, CIMObject(cimClass));
2943 }
2944
2945 expectEndTag(parser, "VALUE.OBJECTWITHPATH");
2946
2947 return true;
2948 }
2949
2950 //------------------------------------------------------------------------------
2951 //
2952 // <objectName>: (CLASSNAME|INSTANCENAME)
2953 //
2954 //------------------------------------------------------------------------------
2955
2956 Boolean XmlReader::getObjectNameElement(
2957 XmlParser& parser,
2958 CIMReference& objectName)
2959 mike 1.23 {
2960 String className;
2961 CIMReference instanceName;
2962
2963 if (getClassNameElement(parser, className, false))
2964 {
2965 objectName.set(String(), String(), className);
2966 return true;
2967 }
2968 else if (getInstanceNameElement(parser, objectName))
2969 return true;
2970 else
2971 {
2972 throw XmlValidationError(parser.getLine(),
2973 "expected CLASSNAME or INSTANCENAME element");
2974 }
2975
2976 return false;
2977 }
2978
2979 //------------------------------------------------------------------------------
2980 mike 1.23 //
2981 // <!ELEMENT OBJECTPATH (INSTANCEPATH|CLASSPATH)>
2982 //
2983 //------------------------------------------------------------------------------
2984
2985 Boolean XmlReader::getObjectPathElement(
2986 XmlParser& parser,
2987 CIMReference& objectPath)
2988 {
2989 XmlEntry entry;
2990
2991 if (!testStartTag(parser, entry, "OBJECTPATH"))
2992 return false;
2993
2994 if (getClassPathElement(parser, objectPath))
2995 {
2996 expectEndTag(parser, "OBJECTPATH");
2997 return true;
2998 }
2999 else if (getInstancePathElement(parser, objectPath))
3000 {
3001 mike 1.23 expectEndTag(parser, "OBJECTPATH");
3002 return true;
3003 }
3004 else
3005 {
3006 throw XmlValidationError(parser.getLine(),
3007 "expected INSTANCEPATH or CLASSPATH element");
3008 }
3009
|