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 package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node;
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 import org.metricshub.wbem.javax.cim.CIMArgument;
51 import org.metricshub.wbem.javax.cim.CIMDataType;
52 import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.EmbObjHandler;
53 import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession;
54 import org.xml.sax.Attributes;
55 import org.xml.sax.SAXException;
56
57
58
59
60
61
62 public class ParamValueNode extends AbstractParamValueNode {
63 private String iName;
64
65 private EmbObjHandler iEmbObjHandler;
66
67 private CIMDataType iType;
68
69
70 private boolean iHasChild;
71
72 private boolean iHasTypeValue;
73
74 private Object iValue;
75
76
77
78
79 public ParamValueNode() {
80 super(PARAMVALUE);
81 }
82
83 @Override
84 public void init(Attributes pAttribs, SAXSession pSession) throws SAXException {
85 this.iEmbObjHandler = EmbObjHandler.init(this.iEmbObjHandler, getNodeName(), pAttribs, pSession, null, true);
86 this.iHasChild = false;
87 this.iHasTypeValue = false;
88 this.iName = getCIMName(pAttribs);
89 this.iType = null;
90 this.iValue = null;
91 }
92
93
94
95
96 @Override
97 public void parseData(String pData) {
98
99 }
100
101 private static final String[] ALLOWED_CHILDREN = {
102 VALUE,
103 VALUE_REFERENCE,
104 VALUE_ARRAY,
105 VALUE_REFARRAY,
106 CLASSNAME,
107 INSTANCENAME,
108 CLASS,
109 INSTANCE,
110 VALUE_NAMEDINSTANCE
111 };
112
113 @Override
114 public void testChild(String pNodeNameEnum) throws SAXException {
115 boolean allowed = false;
116 for (int i = 0; i < ALLOWED_CHILDREN.length; i++) {
117 if (ALLOWED_CHILDREN[i] == pNodeNameEnum) {
118 allowed = true;
119 break;
120 }
121 }
122 if (!allowed) throw new SAXException(getNodeName() + " node cannot have " + pNodeNameEnum + " child node!");
123 if (this.iHasChild) throw new SAXException(getNodeName() + " node cannot have more than one child node!");
124
125 CIMDataType rawType = this.iEmbObjHandler.getRawType();
126 if (rawType != null) {
127 if (pNodeNameEnum == VALUE_REFERENCE || pNodeNameEnum == VALUE_REFARRAY) {
128 if (rawType.getType() != CIMDataType.REFERENCE) throw new SAXException(
129 "PARAMVALUE node's PARAMTYPE attribute is not reference (" +
130 rawType +
131 "), but a " +
132 pNodeNameEnum +
133 " child node is found!"
134 );
135 }
136 }
137 }
138
139 @Override
140 public void childParsed(Node pChild) {
141 if (pChild instanceof AbstractValueNode) {
142 this.iEmbObjHandler.addValueNode((AbstractValueNode) pChild);
143 } else {
144 this.iValue = ((ValueIf) pChild).getValue();
145 if (pChild instanceof TypedIf) this.iType = ((TypedIf) pChild).getType(); else if (
146 pChild instanceof ObjectPathIf
147 ) this.iType = CIMDataType.getDataType(((ObjectPathIf) pChild).getCIMObjectPath()); else if (
148 pChild instanceof ValueIf
149 ) this.iType = CIMDataType.getDataType(((ValueIf) pChild).getValue());
150 this.iHasTypeValue = true;
151 }
152 this.iHasChild = true;
153 }
154
155 @Override
156 public void testCompletness() throws SAXException {
157 if (!this.iHasTypeValue) {
158
159 this.iType = this.iEmbObjHandler.getType();
160 this.iValue = this.iEmbObjHandler.getValue();
161 }
162 }
163
164 public CIMDataType getType() {
165 return this.iType;
166 }
167
168
169
170
171
172
173 @Override
174 public CIMArgument<Object> getCIMArgument() {
175
176
177
178 return new CIMArgument<Object>(this.iName, this.iType, this.iValue);
179 }
180
181
182
183
184 public Object getValue() {
185 return this.iValue;
186 }
187 }