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