File: cim_xml.py

package info (click to toggle)
pywbem 0.8.0~dev650-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch
  • size: 872 kB
  • ctags: 1,115
  • sloc: python: 10,652; xml: 101; makefile: 19
file content (1344 lines) | stat: -rw-r--r-- 44,350 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
#
# (C) Copyright 2003-2006 Hewlett-Packard Development Company, L.P.
# (C) Copyright 2006-2007 Novell, Inc. 
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; version 2 of the License.
#   
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#   
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

# Author: Tim Potter <tpot@hp.com>
#         Bart Whiteley <bwhiteley@suse.de>

"""

Functions to create XML documens and elements conforming to the DMTF
standard DSP0201, Representation of CIM in XML, v2.2.

  http://www.dmtf.org/standards/wbem/DSP201.html
  http://www.dmtf.org/standards/published_documents/DSP201.pdf

Elements generated by this module should conform to version 2.2 of the
DTD:

  http://www.dmtf.org/standards/wbem/CIM_DTD_V22.dtd

There should be one class for each element described in the DTD.  The
constructors take builtin Python types, or other cim_xml classes where
child elements are required.

Every class is a subclass of the Element class and so shares the same
attributes and methods, and can be used with the built-in Python XML
handling routines.  In particular you can call the toxml() and
toprettyxml() methods to generate XML.

Note that converting using toprettyxml() inserts whitespace which may
corrupt the data in the XML (!!) so you should only do this when
displaying to humans who can ignore it, and never for computers.  XML
always passes through all non-markup whitespace.

"""

import sys, xml.dom.minidom
from xml.dom.minidom import Document, Element

def Text(data):
    """Grr.  The API for the minidom text node function has changed in
    Python 2.3.  This function allows the code to run under older
    versions of the intepreter."""
    
    if sys.version_info[0] == 2 and sys.version_info[1] >= 3:
        t = xml.dom.minidom.Text()
        t.data = data
        return t
    
    return xml.dom.minidom.Text(data)

class CIMElement(Element):
    """A base class that has a few bonus helper methods."""

    def setName(self, name):
        """Set the NAME attribute of the element."""
        self.setAttribute('NAME', name)

    def setOptionalAttribute(self, name, value):
        """Set an attribute if the value parameter is not None."""
        if value is not None:
            self.setAttribute(name, value)

    def appendOptionalChild(self, child):
        """Append a child element which can be None."""
        if child is not None:
            self.appendChild(child)

    def appendChildren(self, children):
        """Append a list or tuple of children."""
        [self.appendChild(child) for child in children]

# Root element

class CIM(CIMElement):
    """
    The CIM element is the root element of every XML Document that is
    valid with respect to this schema. 

    Each document takes one of two forms; it either contains a single
    MESSAGE element defining a CIM message (to be used in the HTTP
    mapping), or it contains a DECLARATION element used to declare a
    set of CIM objects.
 
    <!ELEMENT CIM (MESSAGE | DECLARATION)>
    <!ATTLIST CIM
        CIMVERSION CDATA #REQUIRED
        DTDVERSION CDATA #REQUIRED>
    """

    def __init__(self, data, cim_version, dtd_version):
        Element.__init__(self, 'CIM')
        self.setAttribute('CIMVERSION', cim_version)
        self.setAttribute('DTDVERSION', dtd_version)
        self.appendChild(data)

# Object declaration elements

class DECLARATION(CIMElement):
    """
    The DECLARATION element defines a set of one or more declarations
    of CIM objects.  These are partitioned into logical declaration
    subsets. 
 
    <!ELEMENT DECLARATION (DECLGROUP | DECLGROUP.WITHNAME |
                           DECLGROUP.WITHPATH)+>
    """

    def __init__(self, data):
        Element.__init__(self, 'DECLARATION')
        self.appendChildren(data)

class DECLGROUP(CIMElement):
    """
    The DECLGROUP element defines a logical set of CIM Class, Instance
    and Qualifier declarations.  It MAY optionally include a
    NAMESPACEPATH or LOCALNAMESPACEPATH element which, if present,
    defines the common namespace in which all objects within the group
    are declared.
    
    <!ELEMENT DECLGROUP ((LOCALNAMESPACEPATH | NAMESPACEPATH)?,
                         QUALIFIER.DECLARATION*, VALUE.OBJECT*)>
    """

    def __init__(self, data):
        Element.__init__(self, 'DECLGROUP')
        self.appendChildren(data)

class DECLGROUP_WITHNAME(CIMElement):
    """
    The DECLGROUP.WITHNAME element defines a logical set of CIM Class,
    Instance and Qualifier declarations.  It MAY optionally include a
    NAMESPACEPATH or LOCALNAMESPACEPATH element which, if present,
    defines the common namespace in which all objects within the group
    are declared.

    <!ELEMENT DECLGROUP.WITHNAME ((LOCALNAMESPACEPATH | NAMESPACEPATH)?,
                                   QUALIFIER.DECLARATION*, VALUE.NAMEDOBJECT*)>
    """

    def __init__(self, data):
        Element.__init__(self, 'DECLGROUP.WITHNAME')
        self.appendChildren(data)

class DECLGROUP_WITHPATH(CIMElement):
    """
    The DECLGROUP.WITHPATH element defines a logical set of CIM Class
    and Instance declarations.  Each object is declared with its own
    independent naming and location information.

    <!ELEMENT DECLGROUP.WITHPATH  (VALUE.OBJECTWITHPATH |
                                   VALUE.OBJECTWITHLOCALPATH)*>
    """

    def __init__(self, data):
        Element.__init__(self, 'DECLGROUP.WITHPATH')
        self.appendChildren(data)

class QUALIFIER_DECLARATION(CIMElement):
    """
    The QUALIFIER.DECLARATION element defines a single CIM Qualifier
    declaration.

    <!ELEMENT QUALIFIER.DECLARATION (SCOPE?, (VALUE | VALUE.ARRAY)?)>
    <!ATTLIST QUALIFIER.DECLARATION
         %CIMName;               
         %CIMType;               #REQUIRED
         ISARRAY    (true|false) #IMPLIED
         %ArraySize;
         %QualifierFlavor;>
    """

    def __init__(self, name, type, value, is_array = None,
                 array_size = None, qualifier_scopes = {},
                 overridable = None, tosubclass = None, 
                 toinstance = None, translatable = None):
        Element.__init__(self, 'QUALIFIER.DECLARATION')
        self.setName(name)
        self.setAttribute('TYPE', type)
        if is_array is not None:
            self.setOptionalAttribute('ISARRAY', str(is_array).lower())
        if array_size is not None:
            self.setAttribute('ARRAYSIZE', str(array_size))
        if overridable is not None:
            self.setAttribute('OVERRIDABLE', str(overridable).lower())
        if tosubclass is not None:
            self.setAttribute('TOSUBCLASS', str(tosubclass).lower())
        if toinstance is not None:
            self.setAttribute('TOINSTANCE', str(toinstance).lower())
        if translatable is not None:
            self.setAttribute('TRANSLATABLE', str(translatable).lower())
            
        if qualifier_scopes:
            scope = SCOPE(qualifier_scopes)
            self.appendOptionalChild(scope)
        if value is not None:
            if is_array:
                xval = VALUE_ARRAY(value)
            else:
                xval = VALUE(value)
            self.appendOptionalChild(xval)

class SCOPE(CIMElement):
    """
    The SCOPE element defines the scope of a QUALIFIER.DECLARATION in
    the case that there are restrictions on the scope of the Qualifier
    declaration.

    <!ELEMENT SCOPE EMPTY>
    <!ATTLIST SCOPE 
         CLASS        (true|false)      'false'
         ASSOCIATION  (true|false)      'false'
         REFERENCE    (true|false)      'false'
         PROPERTY     (true|false)      'false'
         METHOD       (true|false)      'false'
         PARAMETER    (true|false)      'false'
         INDICATION   (true|false)      'false'>
    """
    
    def __init__(self, scopes={}):
        Element.__init__(self, 'SCOPE')
        if 'any' in scopes and scopes['any']:
            scopes = {'CLASS': True,
                      'ASSOCIATION': True,
                      'REFERENCE': True,
                      'PROPERTY': True,
                      'METHOD': True,
                      'PARAMETER': True,
                      'INDICATION': True}
        for k, v in scopes.items():
            self.setOptionalAttribute(k, str(v).lower())

# Object value elements

class VALUE(CIMElement):
    """
    The VALUE element is used to define a single (non-array and
    non-reference) CIM Property value, CIM Qualifier value, or a CIM
    Method Parameter value.

    <!ELEMENT VALUE (#PCDATA)>
    """

    def __init__(self, pcdata):
        Element.__init__(self, 'VALUE')
        if pcdata is not None:
            self.appendChild(Text(pcdata))

class VALUE_ARRAY(CIMElement):
    """
    The VALUE.ARRAY element is used to represent the value of a CIM
    Property or Qualifier that has an array type.

    <!ELEMENT VALUE.ARRAY (VALUE*)>
    """

    def __init__(self, values):
        Element.__init__(self, 'VALUE.ARRAY')
        self.appendChildren(values)

class VALUE_REFERENCE(CIMElement):
    """
    The VALUE.REFERENCE element is used to define a single CIM
    reference Property value.

    <!ELEMENT VALUE.REFERENCE (CLASSPATH | LOCALCLASSPATH | CLASSNAME |
                               INSTANCEPATH | LOCALINSTANCEPATH |
                               INSTANCENAME)>
    """

    def __init__(self, data):
        Element.__init__(self, 'VALUE.REFERENCE')
        self.appendChild(data)

class VALUE_REFARRAY(CIMElement):
    """
    The VALUE.REFARRAY element is used to represent the value of an
    array of CIM references.

    <!ELEMENT VALUE.REFARRAY (VALUE.REFERENCE*)>
    """
    
    def __init__(self, data):
        Element.__init__(self, 'VALUE.REFARRAY')
        self.appendChildren(data)

class VALUE_OBJECT(CIMElement):
    """
    The VALUE.OBJECT element is used to define a value which is
    comprised of a single CIM Class or Instance definition.
    
    <!ELEMENT VALUE.OBJECT (CLASS | INSTANCE)>
    """

    def __init__(self, data):
        Element.__init__(self, 'VALUE.OBJECT')
        self.appendChild(data)

class VALUE_NAMEDINSTANCE(CIMElement):
    """
    The VALUE.NAMEDINSTANCE element is used to define a value which
    is comprised of a single named CIM Instance definition.
    
    <!ELEMENT VALUE.NAMEDINSTANCE (INSTANCENAME, INSTANCE)>
    """

    def __init__(self, instancename, instance):
        Element.__init__(self, 'VALUE.NAMEDINSTANCE')
        self.appendChild(instancename)
        self.appendChild(instance)

class VALUE_NAMEDOBJECT(CIMElement):
    """
    The VALUE.NAMEDOBJECT element is used to define a value which
    is comprised of a single named CIM Class or Instance definition. 

    <!ELEMENT VALUE.NAMEDOBJECT (CLASS | (INSTANCENAME, INSTANCE))>
    """
    
    def __init__(self, data):
        Element.__init__(self, 'VALUE.NAMEDOBJECT')
        if type(data) == tuple or type(data) == list:
            self.appendChildren(data)
        else:
            self.appendChild(data)

class VALUE_OBJECTWITHLOCALPATH(CIMElement):
    """
    The VALUE.OBJECTWITHLOCALPATH element is used to define a value
    which is comprised of a single CIM Object (Class or Instance)
    definition with additional information that defines the local path
    to that Object.    

    <!ELEMENT VALUE.OBJECTWITHLOCALPATH ((LOCALCLASSPATH, CLASS) |
                                         (LOCALINSTANCEPATH, INSTANCE))>
    """

    def __init__(self, data1, data2):
        Element.__init__(self, 'VALUE.OBJECTWITHLOCALPATH')
        self.appendChild(data1)
        self.appendChild(data2)

class VALUE_OBJECTWITHPATH(CIMElement):
    """
    The VALUE.OBJECTWITHPATH element is used to define a value
    which is comprised of a single CIM Object (Class or Instance)
    definition with additional information that defines the absolute
    path to that Object.

    <!ELEMENT VALUE.OBJECTWITHPATH ((CLASSPATH, CLASS) |
                                    (INSTANCEPATH, INSTANCE))>
    """
    
    def __init__(self, data1, data2):
        Element.__init__(self, 'VALUE.OBJECTWITHPATH')
        self.appendChild(data1)
        self.appendChild(data2)

class VALUE_NULL(CIMElement):
    """
    The VALUE.NULL element is used to represent a TABLECELL that has
    no assigned value.
    
    <!ELEMENT VALUE.NULL EMPTY>
    """

    def __init__(self):
        Element.__init__(self, 'VALUE.NULL')

# Object naming and location elements

class NAMESPACEPATH(CIMElement):
    """
    The NAMESPACEPATH element is used to define a Namespace Path. It
    consists of a HOST element and a LOCALNAMESPACE element.

    <!ELEMENT NAMESPACEPATH (HOST, LOCALNAMESPACEPATH)> 
    """

    def __init__(self, host, localnamespacepath):
        Element.__init__(self, 'NAMESPACEPATH')
        self.appendChild(host)
        self.appendChild(localnamespacepath)

class LOCALNAMESPACEPATH(CIMElement):
    """
    The LOCALNAMESPACEPATH element is used to define a local Namespace
    path (one without a Host component). It consists of one or more
    NAMESPACE elements (one for each namespace in the path). 
 
    <!ELEMENT LOCALNAMESPACEPATH (NAMESPACE+)> 
    """
    
    def __init__(self, namespaces):
        Element.__init__(self, 'LOCALNAMESPACEPATH')
        self.appendChildren(namespaces)

class HOST(CIMElement):
    """
    The HOST element is used to define a single Host. The element
    content MUST specify a legal value for a hostname in accordance
    with the CIM specification.
 
    <!ELEMENT HOST (#PCDATA)> 
    """
    
    def __init__(self, pcdata):
        Element.__init__(self, 'HOST')
        self.appendChild(Text(pcdata))

class NAMESPACE(CIMElement):
    """
    The NAMESPACE element is used to define a single Namespace
    component of a Namespace path.
 
    <!ELEMENT NAMESPACE EMPTY> 
    <!ATTLIST NAMESPACE
        %CIMName;>
    """
    
    def __init__(self, name):
        Element.__init__(self, 'NAMESPACE')
        self.setName(name)
        
class CLASSPATH(CIMElement):
    """
    The CLASSPATH element defines the absolute path to a CIM Class. It
    is formed from a namespace path and Class name. 
 
    <!ELEMENT CLASSPATH (NAMESPACEPATH, CLASSNAME)>
    """
    
    def __init__(self, namespacepath, classname):
        Element.__init__(self, 'CLASSPATH')
        self.appendChild(namespacepath)
        self.appendChild(classname)


class LOCALCLASSPATH(CIMElement):
    """
    The LOCALCLASSPATH element defines the a local path to a CIM
    Class. It is formed from a local namespace path and Class name. 
 
    <!ELEMENT LOCALCLASSPATH (LOCALNAMESPACEPATH, CLASSNAME)>
    """
    
    def __init__(self, localnamespacepath, classname):
        Element.__init__(self, 'LOCALCLASSPATH')
        self.appendChild(localnamespacepath)
        self.appendChild(classname)

class CLASSNAME(CIMElement):
    """
    The CLASSNAME element defines the qualifying name of a CIM Class.
 
    <!ELEMENT CLASSNAME EMPTY>
    <!ATTLIST CLASSNAME
        %CIMName;>
    """
    
    def __init__(self, classname):
        Element.__init__(self, 'CLASSNAME')
        self.setName(classname)

class INSTANCEPATH(CIMElement):
    """
    The INSTANCEPATH element defines the absolute path to a CIM
    Instance. It is comprised of a Namespace path and an Instance Name
    (model path). 
 
    <!ELEMENT INSTANCEPATH (NAMESPACEPATH, INSTANCENAME)>
    """
    
    def __init__(self, namespacepath, instancename):
        Element.__init__(self, 'INSTANCEPATH')
        self.appendChild(namespacepath)
        self.appendChild(instancename)

class LOCALINSTANCEPATH(CIMElement):
    """
    The LOCALINSTANCEPATH element defines the local path to a CIM
    Instance. It is comprised of a local Namespace path and an
    Instance Name (model path). 
 
    <!ELEMENT LOCALINSTANCEPATH (LOCALNAMESPACEPATH, INSTANCENAME)>
    """
    
    def __init__(self, localpath, instancename):
        Element.__init__(self, 'LOCALINSTANCEPATH')
        self.appendChild(localpath)
        self.appendChild(instancename)

class INSTANCENAME(CIMElement):
    """
    The INSTANCENAME element defines the location of a CIM Instance
    within a Namespace (it is referred to in the CIM Specification
    as a Model Path). It is comprised of a class name and a key
    binding information. 

    If the Class has a single key property, then a single KEYVALUE or
    VALUE.REFERENCE subelement may be used to describe the
    (necessarily) unique key value without a key name. Alternatively a
    single KEYBINDING subelement may be used instead. 

    If the Class has more than one key property, then a KEYBINDING
    subelement MUST appear for each key. 

    If there are no key-bindings specified, the instance is assumed to
    be a singleton instance of a keyless Class. 
 
    <!ELEMENT INSTANCENAME (KEYBINDING* | KEYVALUE? | VALUE.REFERENCE?)>
    <!ATTLIST INSTANCENAME
        %ClassName;>
    """
    
    def __init__(self, classname, data):
        Element.__init__(self, 'INSTANCENAME')
        self.setAttribute('CLASSNAME', classname)
        if data is not None:
            if type(data) == list:
                self.appendChildren(data)
            else:
                self.appendChild(data)

class OBJECTPATH(CIMElement):
    """
    The OBJECTPATH element is used to define a full path to a single
    CIM Object (Class or Instance). 
 
    <!ELEMENT OBJECTPATH (INSTANCEPATH | CLASSPATH)>
    """
    
    def __init__(self, data):
        Element.__init__(self, 'OBJECTPATH')
        self.appendChild(data)

class KEYBINDING(CIMElement):
    """
    The KEYBINDING element defines a single key property value binding.
 
    <!ELEMENT KEYBINDING (KEYVALUE | VALUE.REFERENCE)>
    <!ATTLIST KEYBINDING
        %CIMName;>
    """
    
    def __init__(self, name, data):
        Element.__init__(self, 'KEYBINDING')
        self.setName(name)
        self.appendChild(data)

class KEYVALUE(CIMElement):
    """
    The KEYVALUE element defines a single property key value when the
    key property is a non-reference type. 
 
    <!ELEMENT KEYVALUE (#PCDATA)>
    <!ATTLIST KEYVALUE
        VALUETYPE    (string|boolean|numeric)  'string'
        %CIMType;    #IMPLIED>
    """

    def __init__(self, data, value_type = None, cim_type = None):

        Element.__init__(self, 'KEYVALUE')

        if value_type is None:
            self.setAttribute('VALUETYPE', 'string')
        else:
            self.setAttribute('VALUETYPE', value_type)

        self.setOptionalAttribute('TYPE', cim_type)

        if data != None:
            self.appendChild(Text(data))

# Object definition elements
    
class CLASS(CIMElement):
    """
    The CLASS element defines a single CIM Class.
 
    <!ELEMENT CLASS (QUALIFIER*, (PROPERTY | PROPERTY.ARRAY |
                     PROPERTY.REFERENCE)*, METHOD*)>
    <!ATTLIST CLASS 
        %CIMName;
        %SuperClass;>
    """

    def __init__(self, classname, properties = [], methods = [],
                 qualifiers = [], superclass = None):
        Element.__init__(self, 'CLASS')
        self.setName(classname)
        self.setOptionalAttribute('SUPERCLASS', superclass)
        self.appendChildren(qualifiers + properties + methods)

class INSTANCE(CIMElement):
    """
    The INSTANCE element defines a single CIM Instance of a CIM Class.
 
    <!ELEMENT INSTANCE (QUALIFIER*, (PROPERTY | PROPERTY.ARRAY |
                                     PROPERTY.REFERENCE)*)>
    <!ATTLIST INSTANCE
         %ClassName;
         xml:lang   NMTOKEN  #IMPLIED>
    """
    def __init__(self, classname, properties = [], qualifiers = [],
                 xml_lang = None):
        Element.__init__(self, 'INSTANCE')
        self.setAttribute('CLASSNAME', classname)
        self.setOptionalAttribute('xml:lang', xml_lang)
        self.appendChildren(qualifiers + properties)

class QUALIFIER(CIMElement):
    """
    The QUALIFIER element defines a single CIM Qualifier. If the
    Qualifier has a non-array type, it contains a single VALUE element
    representing the value of the Qualifier. If the Qualifier has an
    array type, it contains a single VALUE.ARRAY element to represent
    the value.

    If the Qualifier has no assigned value then the VALUE element MUST
    be absent. 
 
    <!ELEMENT QUALIFIER ((VALUE | VALUE.ARRAY)?)>
    <!ATTLIST QUALIFIER 
        %CIMName;
        %CIMType;               #REQUIRED 
        %Propagated;
        %QualifierFlavor;
        xml:lang  NMTOKEN  #IMPLIED>
    """
    
    def __init__(self, name, type, value = None, propagated = None,
                 overridable = None, tosubclass = None, toinstance = None,
                 translatable = None, xml_lang = None):

        Element.__init__(self, 'QUALIFIER')

        self.setName(name)
        self.setAttribute('TYPE', type)
        
        if propagated is not None:
            self.setAttribute('PROPAGATED', str(propagated).lower())

        if overridable is not None:
            self.setAttribute('OVERRIDABLE', str(overridable).lower())
        if tosubclass is not None:
            self.setAttribute('TOSUBCLASS', str(tosubclass).lower())
        if toinstance is not None:
            self.setAttribute('TOINSTANCE', str(toinstance).lower())
        if translatable is not None:
            self.setAttribute('TRANSLATABLE', str(translatable).lower())

        self.setOptionalAttribute('xml:lang', xml_lang)

        self.appendOptionalChild(value)

class PROPERTY(CIMElement):
    """
    The PROPERTY element defines a single (non-array) CIM Property
    that is not a reference. It contains a single VALUE element
    representing the value of the Property. 

    If the Property has no assigned value then the VALUE element MUST be
    absent.

    CIM Reference Properties are described using the
    PROPERTY.REFERENCE element.
 
    <!ELEMENT PROPERTY (QUALIFIER*, VALUE?)>
    <!ATTLIST PROPERTY 
        %CIMName;
        %ClassOrigin;
        %Propagated;
        %CIMType;           #REQUIRED 
        xml:lang   NMTOKEN  #IMPLIED>
    """

    def __init__(self, name, type, value = None, class_origin = None,
                 propagated = None, qualifiers = [], xml_lang = None,
                 embedded_object = None):

        Element.__init__(self, 'PROPERTY')

        self.setName(name)
        self.setAttribute('TYPE', type)
        
        self.setOptionalAttribute('CLASSORIGIN', class_origin)

        if propagated is not None:
            self.setAttribute('PROPAGATED', str(propagated).lower())

        self.setOptionalAttribute('xml:lang', xml_lang)
        self.setOptionalAttribute('EmbeddedObject', embedded_object)

        self.appendChildren(qualifiers)
        self.appendOptionalChild(value)

class PROPERTY_ARRAY(CIMElement):
    """
    The PROPERTY.ARRAY element defines a single CIM Property with an
    array type. It contains a single VALUE.ARRAY element  representing
    the value of the Property. 

    If the Property has no assigned value then the VALUE.ARRAY element
    MUST be absent. 

    There is no element to model a Property that contains an array of
    references as this is not a valid Property type according to CIM. 
 
    <!ELEMENT PROPERTY.ARRAY (QUALIFIER*, VALUE.ARRAY?)>
    <!ATTLIST PROPERTY.ARRAY 
       %CIMName;
       %CIMType;           #REQUIRED 
       %ArraySize;
       %ClassOrigin;
       %Propagated;
       xml:lang   NMTOKEN  #IMPLIED>
    """
    
    def __init__(self, name, type, value_array = None, array_size = None,
                 class_origin = None, propagated = None, qualifiers = [],
                 xml_lang = None, embedded_object = None):

        Element.__init__(self, 'PROPERTY.ARRAY')

        self.setName(name)
        self.setAttribute('TYPE', type)

        if array_size is not None:
            self.setAttribute('ARRAYSIZE', str(array_size))
        self.setOptionalAttribute('CLASSORIGIN', class_origin)
        self.setOptionalAttribute('EmbeddedObject', embedded_object)

        if propagated is not None:
            self.setAttribute('PROPAGATED', str(propagated).lower())
            
        self.setOptionalAttribute('xml:lang', xml_lang)

        self.appendChildren(qualifiers)
        self.appendOptionalChild(value_array)

class PROPERTY_REFERENCE(CIMElement):
    """
    The PROPERTY.REFERENCE element models a single CIM Property with
    reference semantics. In future the features of XML Linking may
    be used to identify linking elements within the XML Document; as
    XML Linking is currently only at Working Draft status no explicit
    dependencies have been made at this point. 
 
    <!ELEMENT PROPERTY.REFERENCE (QUALIFIER*, VALUE.REFERENCE?)>
    <!ATTLIST PROPERTY.REFERENCE
        %CIMName;
        %ReferenceClass;
        %ClassOrigin;
        %Propagated;>
    """
    
    def __init__(self, name, value_reference = None, reference_class = None,
                 class_origin = None, propagated = None, qualifiers = []):

        Element.__init__(self, 'PROPERTY.REFERENCE')

        self.setName(name)

        self.setOptionalAttribute('REFERENCECLASS', reference_class)
        self.setOptionalAttribute('CLASSORIGIN', class_origin)

        if propagated is not None:
            self.setAttribute('PROPAGATED', str(propagated).lower());
            
        self.appendChildren(qualifiers)
        self.appendOptionalChild(value_reference)

class METHOD(CIMElement):
    """
    The METHOD element defines a single CIM Method. It may have
    Qualifiers, and zero or more parameters. 

    The order of the PARAMETER, PARAMETER.REFERENCE, PARAMETER.ARRAY
    and PARAMETER.REFARRAY subelements is not significant. 
 
    <!ELEMENT METHOD (QUALIFIER*, (PARAMETER | PARAMETER.REFERENCE |
                                   PARAMETER.ARRAY | PARAMETER.REFARRAY)*)>
    <!ATTLIST METHOD 
        %CIMName;
        %CIMType;          #IMPLIED 
        %ClassOrigin;
        %Propagated;>
    """
    
    def __init__(self, name, parameters = [], return_type = None,
                 class_origin = None, propagated = None, qualifiers = []):

        Element.__init__(self, 'METHOD')

        self.setName(name)

        self.setOptionalAttribute('TYPE', return_type)
        self.setOptionalAttribute('CLASSORIGIN', class_origin)

        if propagated is not None:
            self.setAttribute('PROPAGATED', str(propagated).lower())
            
        self.appendChildren(qualifiers + parameters)

class PARAMETER(CIMElement):
    """
    The PARAMETER element defines a single (non-array, non-reference)
    Parameter to a CIM Method. The parameter MAY have zero or more
    Qualifiers. 
 
    <!ELEMENT PARAMETER (QUALIFIER*)>
    <!ATTLIST PARAMETER 
        %CIMName;
        %CIMType;      #REQUIRED>
    """
    
    def __init__(self, name, type, qualifiers = []):
        Element.__init__(self, 'PARAMETER')
        self.setName(name)
        self.setAttribute('TYPE', type)
        self.appendChildren(qualifiers)

class PARAMETER_REFERENCE(CIMElement):
    """
    The PARAMETER.REFERENCE element defines a single reference
    Parameter to a CIM Method. The parameter MAY have zero or more
    Qualifiers.
 
    <!ELEMENT PARAMETER.REFERENCE (QUALIFIER*)>
    <!ATTLIST PARAMETER.REFERENCE
        %CIMName;
        %ReferenceClass;>
    """
    
    def __init__(self, name, reference_class = None, qualifiers = []):
        Element.__init__(self, 'PARAMETER.REFERENCE')
        self.setName(name)
        self.setOptionalAttribute('REFERENCECLASS', reference_class)
        self.appendChildren(qualifiers)

class PARAMETER_ARRAY(CIMElement):
    """
    The PARAMETER.ARRAY element defines a single Parameter to a CIM
    Method that has an array type. The parameter MAY have zero or more
    Qualifiers.
 
    <!ELEMENT PARAMETER.ARRAY (QUALIFIER*)>
    <!ATTLIST PARAMETER.ARRAY
        %CIMName;
        %CIMType;           #REQUIRED
        %ArraySize;>
    """
    
    def __init__(self, name, type, array_size = None, qualifiers = []):
        Element.__init__(self, 'PARAMETER.ARRAY')
        self.setName(name)
        self.setAttribute('TYPE', type)
        if array_size is not None:
            self.setAttribute('ARRAYSIZE', str(array_size))
        self.appendChildren(qualifiers)

class PARAMETER_REFARRAY(CIMElement):
    """
    The PARAMETER.REFARRAY element defines a single Parameter to a CIM
    Method that has an array of references type. The parameter MAY
    have zero or more Qualifiers. 
 
    <!ELEMENT PARAMETER.REFARRAY (QUALIFIER*)>
    <!ATTLIST PARAMETER.REFARRAY
        %CIMName;
        %ReferenceClass;
        %ArraySize;>
    """
    
    def __init__(self, name, reference_class = None, array_size = None,
                 qualifiers = []):
        Element.__init__(self, 'PARAMETER.REFARRAY')
        self.setName(name)
        self.setOptionalAttribute('REFERENCECLASS', reference_class)
        if array_size is not None:
            self.setAttribute('ARRAYSIZE', str(array_size))
        self.appendChildren(qualifiers)

class TABLECELL_DECLARATION(CIMElement):
    """
    The TABLECELL.DECLARATION element describes a TABLECELL that is
    not a reference or an array of references.

    
    <!ELEMENT TABLECELL.DECLARATION EMPTY>
    <!ATTLIST TABLECELL.DECLARATION
        %CIMName;
        %CIMType;                    #REQUIRED
        ISARRAY         (true|false) "false"
        %ARRAYSIZE;
        CELLPOS          CDATA       #REQUIRED
        SORTPOS          CDATA       #IMPLIED
        SORTDIR        (ASC|DESC)    #IMPLIED>
    """

class TABLECELL_REFERENCE(CIMElement):
    """

    The TABLECELL.REFERENCE element defines a TABLECELL that contains
    reference or reference array values.

    <!ELEMENT TABLECELL.REFERENCE EMPTY>
    <!ATTLIST TABLECELL.REFERENCE
        %CIMName;
        %ReferenceClass;             #REQUIRED
        ISARRAY        (true|false)  "false"
        %ARRAYSIZE;
        CELLPOS         CDATA        #REQUIRED
        SORTPOS          CDATA       #IMPLIED
        SORTDIR         (ASC|DESC)   #IMPLIED>
     """

class TABLEROW_DECLARATION(CIMElement):
    """

    The TABLEROW.DECLARATION element contains a definition for each
    TABLECELL in the TABLEROW.

    <!ELEMENT TABLEROW.DECLARATION (TABLECELL.DECLARATION
                                    | TABLECELL.REFERENCE)*>
    """
    
class TABLE(CIMElement):
    """
    The TABLE element defines the result of a CIM Query.  A TABLE
    element consists of a TABLEROW.DECLARATION followed by 0 or more
    rows.

    <!ELEMENT TABLE(TABLEROW.DECLARATION,(TABLEROW)*)>
    """

class TABLEROW(CIMElement):
    """

    The TABLEROW element defines the values for a single row of a
    table.  A value for each cell of the row MUST be specified.  If a
    value has no assigned value, the VALUE.NULL element MUST be used.

    <!ELEMENT TABLEROW (VALUE | VALUE.ARRAY | VALUE.REFERENCE |
                        VALUE.REFARRAY | VALUE.NULL)*>
    """

# Message elements

class MESSAGE(CIMElement):
    """
    The MESSAGE element models a single CIM message.  This element is
    used as the basis for CIM Operation Messages and CIM Export
    Messages.

    <!ELEMENT MESSAGE (SIMPLEREQ | MULTIREQ | SIMPLERSP | MULTIRSP |
                       SIMPLEEXPREQ | MULTIEXPREQ | SIMPLEEXPRSP |
                       MULTIEXPRSP)>
    <!ATTLIST MESSAGE
	ID CDATA #REQUIRED
	PROTOCOLVERSION CDATA #REQUIRED>
    """
    
    def __init__(self, data, message_id, protocol_version):
        Element.__init__(self, 'MESSAGE')
        self.setAttribute('ID', message_id)
        self.setAttribute('PROTOCOLVERSION', protocol_version)
        self.appendChild(data)

class MULTIREQ(CIMElement):
    """
    The MULTIREQ element defines a Multiple CIM Operation request.  It
    contains two or more subelements defining the SIMPLEREQ elements
    that make up this multiple request.

    <!ELEMENT MULTIREQ (SIMPLEREQ, SIMPLEREQ+)>
    """
    
    def __init__(self, data):
        Element.__init__(self, 'MULTIREQ')
        self.appendChildren(data)

class MULTIEXPREQ(CIMElement):
    """
    The MULTIEXPREQ element defines a Multiple CIM Export request.  It
    contains two or more subelements defining the SIMPLEEXPREQ
    elements that make up this multiple request. 
    
    <!ELEMENT MULTIEXPREQ (SIMPLEEXPREQ, SIMPLEEXPREQ+)>
    """
    
    def __init__(self, data):
        Element.__init__(self, 'MULTIEXPREQ')
        self.appendChildren(data)

class SIMPLEREQ(CIMElement):
    """
    The SIMPLEREQ element defines a Simple CIM Operation request.  It
    contains either a METHODCALL (extrinsic method) element or an
    IMETHODCALL (intrinsic method) element. 
 
    <!ELEMENT SIMPLEREQ (IMETHODCALL | METHODCALL)>
    """
    
    def __init__(self, data):
        Element.__init__(self, 'SIMPLEREQ')
        self.appendChild(data)

class SIMPLEEXPREQ(CIMElement):
    """
    The SIMPLEEXPREQ element defines a Simple CIM Export request.  It
    contains an EXPMETHODCALL (export method). 
    
    <!ELEMENT SIMPLEEXPREQ (EXPMETHODCALL)>
    """
    
    def __init__(self, data):
        Element.__init__(self, 'SIMPLEEXPREQ')
        self.appendChild(data)

class IMETHODCALL(CIMElement):
    """
    The IMETHODCALL element defines a single intrinsic method
    invocation.  It specifies the target local namespace, followed by
    zero or more IPARAMVALUE subelements as the parameter values to be
    passed to the method. If the RESPONSEDESTINATION element is
    specified, the intrinsic method call MUST be interpreted as an
    asynchronous method call. 
    
    <!ELEMENT IMETHODCALL (LOCALNAMESPACEPATH, IPARAMVALUE*,
                           RESPONSEDESTINATION?)>
    <!ATTLIST IMETHODCALL
	%CIMName;>
    """
    
    def __init__(self, name, localnamespacepath, iparamvalues = [],
        responsedestination = None):
        Element.__init__(self, 'IMETHODCALL')
        self.setName(name)
        self.appendChild(localnamespacepath)        
        self.appendChildren(iparamvalues)
        self.appendOptionalChild(responsedestination)

class METHODCALL(CIMElement):
    """
    The METHODCALL element defines a single method invocation on a
    Class or Instance.  It specifies the local path of the target
    Class or Instance, followed by zero or more PARAMVALUE subelements
    as the parameter values to be passed to the method. If the
    RESPONSEDESTINATION element is specified, the method call MUST be
    interpreted as an asynchronous method call. 

    <!ELEMENT METHODCALL ((LOCALINSTANCEPATH | LOCALCLASSPATH), PARAMVALUE*,
                          RESPONSEDESTINATION?)>
    <!ATTLIST METHODCALL
	%CIMName;>
    """
    
    def __init__(self, name, localpath, paramvalues = [],
                 responsedestination = None):
        Element.__init__(self, 'METHODCALL')
        self.setName(name)
        self.appendChild(localpath)
        self.appendChildren(paramvalues)
        self.appendOptionalChild(responsedestination)

class EXPMETHODCALL(CIMElement):
    """
    The EXPMETHODCALL element defines a single export method
    invocation.  It specifies zero or more  <EXPPARAMVALUE>
    subelements as the parameter values to be passed to the method. 
    
    <!ELEMENT EXPMETHODCALL (EXPPARAMVALUE*)>
    <!ATTLIST EXPMETHODCALL
	%CIMName;>
    """
    
    def __init__(self, name, params = []):
        Element.__init__(self, 'EXPMETHODCALL')
        self.setName(name)
        self.appendChildren(params)

class PARAMVALUE(CIMElement):
    """
    The PARAMVALUE element defines a single extrinsic method named
    parameter value. If no subelement is present this indicates that
    no value has been supplied for this parameter.
    
    <!ELEMENT PARAMVALUE (VALUE | VALUE.REFERENCE | VALUE.ARRAY |
                          VALUE.REFARRAY)?>
    <!ATTLIST PARAMVALUE
	%CIMName;
        %ParamType;    #IMPLIED>        
    """
    
    def __init__(self, name, data = None, paramtype = None, 
                 embedded_object = None):
        Element.__init__(self, 'PARAMVALUE')
        self.setName(name)
        self.setOptionalAttribute('PARAMTYPE', paramtype)
        self.setOptionalAttribute('EmbeddedObject', embedded_object)
        self.appendOptionalChild(data)

class IPARAMVALUE(CIMElement):
    """
    The IPARAMVALUE element defines a single intrinsic method named
    parameter value. If no subelement is present this indicates that
    no value has been supplied for this parameter. 

    <!ELEMENT IPARAMVALUE (VALUE | VALUE.ARRAY | VALUE.REFERENCE |
                           INSTANCENAME | CLASSNAME | QUALIFIER.DECLARATION |
                           CLASS | INSTANCE | VALUE.NAMEDINSTANCE)?>
    <!ATTLIST IPARAMVALUE
	%CIMName;>
    """
    
    def __init__(self, name, data = None):
        Element.__init__(self, 'IPARAMVALUE')
        self.setName(name)
        self.appendOptionalChild(data)

class EXPPARAMVALUE(CIMElement):
    """
    The EXPPARAMVALUE element defines a single export method named
    parameter value.  If no subelement is present this indicates that
    no value has been supplied for this parameter. 
    
    <!ELEMENT EXPPARAMVALUE (INSTANCE? | VALUE? | METHODRESPONSE? |
                             IMETHODRESPONSE?)>
    <!ATTLIST EXPPARAMVALUE
	%CIMName;
        %ParamType;  #IMPLIED>
    """
    
    def __init__(self, name, data = None, param_type = None):
        Element.__init__(self, 'EXPPARAMVALUE')
        self.setName(name)
        self.setOptionalAttribute('PARAMTYPE', param_type)
        self.appendOptionalChild(data)

class MULTIRSP(CIMElement):
    """
    The MULTIRSP element defines a Multiple CIM Operation response.
    It contains two or more subelements defining the SIMPLERSP
    elements that make up this multiple response. 
    
    <!ELEMENT MULTIRSP (SIMPLERSP, SIMPLERSP+)>
    """
    
    def __init__(self, data):
        Element.__init__(self, 'MULTIRSP')
        self.appendChildren(data)

class MULTIEXPRSP(CIMElement):
    """
    The MULTIEXPRSP element defines a Multiple CIM Export response.
    It contains two or more subelements defining the SIMPLEEXPRSP
    elements that make up this multiple response.
    
    <!ELEMENT MULTIEXPRSP (SIMPLEEXPRSP, SIMPLEEXPRSP+)>
    """

    def __init__(self, data):
        Element.__init__(self, 'MULTIEXPRSP')
        self.appendChildren(data)

class SIMPLERSP(CIMElement):
    """
    The SIMPLERSP element defines a Simple CIM Operation response.  It
    contains either a METHODRESPONSE (for extrinsic methods),
    IMETHODRESPONSE (for intrinsic methods) or a SIMPLEREQACK
    subelement.  
    
    <!ELEMENT SIMPLERSP (METHODRESPONSE | IMETHODRESPONSE | SIMPLEREQACK)>
    """
    
    def __init__(self, data):
        Element.__init__(self, 'SIMPLERSP')
        self.appendChild(data)

class SIMPLEEXPRSP(CIMElement):
    """
    The SIMPLEEXPRSP element defines a Simple CIM Export response.  It
    contains either a EXPMETHODRESPONSE (for export methods)
    subelement. 
    
    <!ELEMENT SIMPLEEXPRSP (EXPMETHODRESPONSE)>
    """
    
    def __init__(self, data):
        Element.__init__(self, 'SIMPLEEXPRSP')
        self.appendChild(data)

class METHODRESPONSE(CIMElement):
    """
    The METHODRESPONSE defines the response to a single CIM extrinsic
    method invocation.  It contains either an ERROR subelement (to
    report a fundamental error which prevented the method from
    executing), or a combination of an optional return value and zero
    or more out parameter values.  
    
    <!ELEMENT METHODRESPONSE (ERROR | (RETURNVALUE?, PARAMVALUE*))>
    <!ATTLIST METHODRESPONSE
	%CIMName;>
    """
    
    def __init__(self, name, data = None):
        Element.__init__(self, 'METHODRESPONSE')
        self.setName(name)
        if data is not None:
            if type(data) == tuple or type(data) == list:
                self.appendChildren(data)
            else:
                self.appendChild(data)
            
class EXPMETHODRESPONSE(CIMElement):
    """
    The EXPMETHODRESPONSE defines the response to a single export
    method invocation.  It contains either an ERROR subelement (to
    report a fundamental error which prevented the method from
    executing), or an optional return value. 
    
    <!ELEMENT EXPMETHODRESPONSE (ERROR | IRETURNVALUE?)>
    <!ATTLIST EXPMETHODRESPONSE
	%CIMName;>
    """
    
    def __init__(self, name, data = None):
        Element.__init__(self, 'EXPMETHODRESPONSE')
        self.setName(name)
        self.appendOptionalChild(data)

class IMETHODRESPONSE(CIMElement):
    """
    The IMETHODRESPONSE defines the response to a single intrinsic CIM
    method invocation.  It contains either an ERROR subelement (to
    report a fundamental error which prevented the method from
    executing), or an optional return value.  
    
    <!ELEMENT IMETHODRESPONSE (ERROR | IRETURNVALUE?)>
    <!ATTLIST IMETHODRESPONSE
	%CIMName;>
    """
    
    def __init__(self, name, data = None):
        Element.__init__(self, 'IMETHODRESPONSE')
        self.setName(name)
        self.appendOptionalChild(data)

class ERROR(CIMElement):
    """
    The ERROR element is used to define a fundamental error which
    prevented a method from executing normally. It consists of a
    status code, an optional description and zero or more instances
    containing detailed information about the error. 
    
    <!ELEMENT ERROR (INSTANCE*)>
    <!ATTLIST ERROR
	CODE CDATA #REQUIRED
	DESCRIPTION CDATA #IMPLIED>
    """
    
    def __init__(self, code, description = None, instances = []):
        Element.__init__(self, 'ERROR')
        self.setAttribute('CODE', code)
        self.setOptionalAttribute('DESCRIPTION', description)
        self.appendChildren(instances)

class RETURNVALUE(CIMElement):
    """
    The RETURNVALUE element specifies the value returned from an
    extrinsic method call. 
    
    <!ELEMENT RETURNVALUE (VALUE | VALUE.REFERENCE)>
    <!ATTLIST RETURNVALUE
        %ParamType;     #IMPLIED>                           
    """
    
    def __init__(self, data, param_type = None):
        Element.__init__(self, 'RETURNVALUE')
        self.setOptionalAttribute('PARAMTYPE', param_type)
        self.appendChild(data)

class IRETURNVALUE(CIMElement):
    """
    The IRETURNVALUE element specifies the value returned from an
    intrinsic method call. 
    
    <!ELEMENT IRETURNVALUE (CLASSNAME* | INSTANCENAME* | VALUE* |
                            VALUE.OBJECTWITHPATH* |
                            VALUE.OBJECTWITHLOCALPATH* | VALUE.OBJECT* |
                            OBJECTPATH* | QUALIFIER.DECLARATION* |
                            VALUE.ARRAY? | VALUE.REFERENCE? | CLASS* |
                            INSTANCE* | VALUE.NAMEDINSTANCE*)>
    """
    
    def __init__(self, data):
        Element.__init__(self, 'IRETURNVALUE')
        self.appendOptionalChild(data)

class RESPONSEDESTINATION(CIMElement):
    """
    The RESPONSEDESTINATION element contains an instance that
    describes the desired destination for the response.

    <!ELEMENT RESPONSEDESTINATON (INSTANCE)>
    """

    def __init__(self, data):
        Element.__init__(self, 'RESPONSEDESTINATON')
        self.appendChild(data);

class SIMPLEREQACK(CIMElement):
    """
    The SIMPLEREQACK defines the acknowledgement response to a Simple
    CIM Operation asynchronous request. The ERROR subelement is used
    to report a fundamental error which prevented the asynchronous
    request from being initiated.

    <!ELEMENT SIMPLEREQACK (ERROR?)>
    <!ATTLIST SIMPLEREQACK 
        INSTANCEID CDATA     #REQUIRED>
    """

    def __init__(self, instanceid, data):
        Element.__init__(self, 'SIMPLEREQACK')
        self.setOptionalAttribute('INSTANCEID', instanceid)
        self.appendOptionalChild(data)