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 package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node;
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 import java.util.ArrayList;
52 import org.metricshub.wbem.javax.cim.CIMArgument;
53 import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession;
54 import org.metricshub.wbem.sblim.cimclient.internal.wbem.CIMError;
55 import org.xml.sax.Attributes;
56 import org.xml.sax.SAXException;
57
58
59
60
61
62
63
64
65 public class MethodResponseNode extends Node implements ErrorIf, RetValPipeIf, NonVolatileIf {
66 private String iName;
67
68 private CIMError iError;
69
70 private Object iRetVal;
71
72 private ArrayList<CIMArgument<Object>> iCIMArgAL;
73
74 private boolean iHasError;
75
76 private boolean iHasRetVal;
77
78
79
80
81 public MethodResponseNode() {
82 super(METHODRESPONSE);
83 }
84
85
86
87
88 public void addChild(Node pChild) {
89
90 }
91
92
93
94
95 @Override
96 public void init(Attributes pAttribs, SAXSession pSession) throws SAXException {
97 this.iName = getCIMName(pAttribs);
98 this.iError = null;
99 this.iRetVal = null;
100 if (this.iCIMArgAL != null) this.iCIMArgAL.clear();
101 this.iHasError = false;
102 this.iHasRetVal = false;
103 }
104
105
106
107
108 @Override
109 public void parseData(String pData) {
110
111 }
112
113 @Override
114 public void testChild(String pNodeNameEnum) throws SAXException {
115 if (pNodeNameEnum == ERROR) {
116 String ownedNodeName;
117 if (this.iHasRetVal) ownedNodeName = RETURNVALUE; else if (this.iHasError) ownedNodeName = ERROR; else if (
118 this.iCIMArgAL != null && this.iCIMArgAL.size() > 0
119 ) ownedNodeName = PARAMVALUE; else ownedNodeName = null;
120 if (ownedNodeName != null) throw new SAXException(
121 pNodeNameEnum +
122 " child node is invalid for " +
123 getNodeName() +
124 " node, since it already has a " +
125 ownedNodeName +
126 " child node!"
127 );
128 } else if (pNodeNameEnum == RETURNVALUE) {
129 String ownedNodeName;
130 if (this.iHasRetVal) ownedNodeName = RETURNVALUE; else if (this.iHasError) ownedNodeName =
131 ERROR; else ownedNodeName = null;
132 if (ownedNodeName != null) throw new SAXException(
133 pNodeNameEnum +
134 " child node is invalid for " +
135 getNodeName() +
136 " node, since it already has a " +
137 ownedNodeName +
138 " child node!"
139 );
140 } else if (pNodeNameEnum == PARAMVALUE) {
141 if (this.iHasError) throw new SAXException(
142 pNodeNameEnum +
143 " child node is invalid for " +
144 getNodeName() +
145 " node, since it already has an ERROR child node!"
146 );
147 } else throw new SAXException(getNodeName() + " node cannot have " + pNodeNameEnum + " child node!");
148 }
149
150 @Override
151 public void childParsed(Node pChild) {
152 if (pChild instanceof ErrorNode) {
153 this.iHasError = true;
154 this.iError = ((ErrorNode) pChild).getCIMError();
155 } else if (pChild instanceof ReturnValueNode) {
156 this.iHasRetVal = true;
157 this.iRetVal = ((ReturnValueNode) pChild).getValue();
158 } else if (pChild instanceof ParamValueNode) {
159 if (this.iCIMArgAL == null) this.iCIMArgAL = new ArrayList<CIMArgument<Object>>();
160 this.iCIMArgAL.add(((ParamValueNode) pChild).getCIMArgument());
161 }
162 }
163
164 @Override
165 public void testCompletness() {
166
167 }
168
169 public CIMError getCIMError() {
170 return this.iError;
171 }
172
173 private static final CIMArgument<?>[] EMPTY_ARG_A = new CIMArgument[0];
174
175
176
177
178
179
180
181 public CIMArgument<?>[] getCIMArguments() {
182 if (this.iCIMArgAL == null || this.iCIMArgAL.size() == 0) return null;
183 return this.iCIMArgAL.toArray(EMPTY_ARG_A);
184 }
185
186 public int getReturnValueCount() {
187 return this.iRetVal == null ? 0 : 1;
188 }
189
190 public Object readReturnValue() {
191 Object val = this.iRetVal;
192 this.iRetVal = null;
193 return val;
194 }
195
196
197
198
199
200
201 public String getName() {
202 return this.iName;
203 }
204 }