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