1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.metricshub.wbem.sblim.cimclient.internal.wbem;
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 import java.io.IOException;
43 import java.io.InputStreamReader;
44 import java.util.List;
45 import javax.xml.parsers.ParserConfigurationException;
46 import org.metricshub.wbem.javax.cim.CIMArgument;
47 import org.metricshub.wbem.javax.cim.CIMObjectPath;
48 import org.metricshub.wbem.javax.wbem.CloseableIterator;
49 import org.metricshub.wbem.javax.wbem.WBEMException;
50 import org.metricshub.wbem.javax.wbem.client.EnumerateResponse;
51 import org.xml.sax.SAXException;
52
53
54
55
56
57
58
59
60 public class EnumerateResponseDOM<T> {
61 private EnumerateResponse<T> enumResponse;
62
63
64
65
66
67
68
69
70
71
72
73 @SuppressWarnings("unchecked")
74 public EnumerateResponseDOM(InputStreamReader pStream, CIMObjectPath pPath)
75 throws IOException, SAXException, ParserConfigurationException, WBEMException {
76 String enumContext = null;
77
78 Boolean endOfSequence = null;
79
80 CloseableIterator<?> iter = new CloseableIteratorDOM(pStream, pPath);
81
82
83 try {
84 iter.hasNext();
85 } catch (RuntimeException e) {
86 iter.close();
87 if (e.getCause() != null && e.getCause() instanceof WBEMException) {
88 throw (WBEMException) e.getCause();
89 }
90 throw e;
91 }
92
93
94 List<Object> pOutArgA = ((CloseableIteratorDOM) iter).getParamValues();
95
96
97 if (pOutArgA == null) {
98 throw new IllegalArgumentException("Output auguments not found during CIM-XML DOM parser");
99 }
100
101 for (int i = 0; i < pOutArgA.size(); i++) {
102 CIMArgument<?> cimArg = (CIMArgument<?>) pOutArgA.get(i);
103
104 if (cimArg.getName().equals("EnumerationContext")) enumContext = (String) cimArg.getValue(); else if (
105 cimArg.getName().equals("EndOfSequence")
106 ) endOfSequence = (Boolean) cimArg.getValue(); else throw new IllegalArgumentException(
107 "Invalid argument : only EnumerationContext and EndOfSequence are allowed"
108 );
109 }
110
111 if (endOfSequence == null) {
112 throw new IllegalArgumentException("Invalid argument : EndOfSequence can never be null");
113 }
114
115
116 if ((endOfSequence.booleanValue() == false) && (enumContext == null)) {
117 throw new IllegalArgumentException(
118 "Invalid argument : EnumerationContext cannot be null if there is more data available"
119 );
120 }
121
122 this.enumResponse =
123 new EnumerateResponse<T>(enumContext, (CloseableIterator<T>) iter, endOfSequence.booleanValue());
124 }
125
126
127
128
129
130
131 public EnumerateResponse<T> getEnumResponse() {
132 return this.enumResponse;
133 }
134 }