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
30
31
32
33 package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node;
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55 import org.metricshub.wbem.javax.cim.CIMDataType;
56 import org.metricshub.wbem.javax.cim.CIMFlavor;
57 import org.metricshub.wbem.sblim.cimclient.internal.cim.CIMHelper;
58 import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.CIMObjectFactory;
59 import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.NodeConstIf;
60 import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession;
61 import org.metricshub.wbem.sblim.cimclient.internal.util.MOF;
62 import org.xml.sax.Attributes;
63 import org.xml.sax.SAXException;
64
65
66
67
68
69 public abstract class Node implements NodeConstIf {
70 private String iNameEnum;
71
72 private boolean iCompleted;
73
74
75
76
77
78
79
80
81
82 public Node(String pNameEnum) {
83 this.iNameEnum = pNameEnum;
84 }
85
86
87
88
89
90
91
92 public String getNodeName() {
93 return this.iNameEnum;
94 }
95
96
97
98
99
100
101
102
103
104
105
106
107 public abstract void init(Attributes pAttribs, SAXSession pSession) throws SAXException;
108
109
110
111
112
113
114
115
116
117 public abstract void parseData(String pData) throws SAXException;
118
119
120
121
122
123
124
125
126
127
128
129
130
131 public abstract void testChild(String pNodeNameEnum) throws SAXException;
132
133
134
135
136
137
138
139
140
141 public abstract void testCompletness() throws SAXException;
142
143
144
145
146
147
148
149
150
151
152 public abstract void childParsed(Node pChild) throws SAXException;
153
154
155
156
157
158
159 public boolean isCompleted() {
160 return this.iCompleted;
161 }
162
163
164
165
166
167 public void setCompleted() {
168 this.iCompleted = true;
169 }
170
171
172
173
174
175 public void clearCompleted() {
176 this.iCompleted = false;
177 }
178
179
180
181
182
183
184
185
186 public static String getCIMName(Attributes pAttribs) throws SAXException {
187 String name = pAttribs.getValue("NAME");
188 if (name == null) throw new SAXException("NAME attribute not found!");
189 return name;
190 }
191
192
193
194
195
196
197
198
199 public static String getClassName(Attributes pAttribs) throws SAXException {
200 String name = pAttribs.getValue("CLASSNAME");
201 if (name == null) throw new SAXException("CLASSNAME attribute not found!");
202 return name;
203 }
204
205
206
207
208
209
210
211 public static String getReferenceClass(Attributes pAttribs) {
212 return pAttribs.getValue("REFERENCECLASS");
213 }
214
215
216
217
218
219
220
221 public static String getClassOrigin(Attributes pAttribs) {
222 return pAttribs.getValue("CLASSORIGIN");
223 }
224
225
226
227
228
229
230
231 public static boolean getPropagated(Attributes pAttribs) {
232 String str = pAttribs.getValue("PROPAGATED");
233 return MOF.TRUE.equalsIgnoreCase(str);
234 }
235
236
237
238
239
240
241
242
243 public static int getArraySize(Attributes pAttribs) throws SAXException {
244 String arraySizeStr = pAttribs.getValue("ARRAYSIZE");
245
246 int size = 0;
247 try {
248 size = arraySizeStr == null || arraySizeStr.length() == 0 ? 0 : Integer.parseInt(arraySizeStr);
249 } catch (NumberFormatException e) {
250 throw new SAXException(arraySizeStr + " is not a valid ARRAYSIZE attribute!");
251 }
252 if (size < 0) throw new SAXException("ARRAYSIZE cannot be " + size + "!");
253 return size;
254 }
255
256
257
258
259
260
261
262
263
264
265
266 public static CIMDataType getCIMType(Attributes pAttribs, boolean pOptional) throws SAXException {
267 String typeStr = pAttribs.getValue("TYPE");
268 if (typeStr == null) {
269 if (pOptional) return null;
270 throw new SAXException("TYPE attribute not found!");
271 }
272 CIMDataType type = CIMObjectFactory.getType(typeStr);
273 if (type == null) throw new SAXException(typeStr + " is not a valid TYPE attribute!");
274 if (type.getType() == CIMDataType.REFERENCE) throw new SAXException("TYPE attribute cannot be \"reference\"!");
275
276
277 boolean isArray = hasTrueAttribute(pAttribs, "ISARRAY");
278 String arraySizeStr = pAttribs.getValue("ARRAYSIZE");
279 int arraySize;
280 try {
281 arraySize =
282 (arraySizeStr == null || arraySizeStr.length() == 0 ? (isArray ? 0 : -1) : Integer.parseInt(arraySizeStr));
283 } catch (NumberFormatException e) {
284 throw new SAXException(arraySizeStr + " is not a valid ARRAYSIZE attribute!");
285 }
286 if (isArray || arraySize >= 0) {
287 if (arraySize > 0) return new CIMDataType(type.getType(), arraySize);
288 return CIMHelper.UnboundedArrayDataType(type.getType());
289 }
290 return type;
291 }
292
293
294
295
296
297
298
299
300 public static CIMDataType getCIMType(Attributes pAttribs) throws SAXException {
301 return getCIMType(pAttribs, false);
302 }
303
304
305
306
307
308
309
310
311
312
313 public static CIMDataType getParamType(Attributes pAttribs) throws SAXException {
314 String typeStr = pAttribs.getValue("PARAMTYPE");
315 return CIMObjectFactory.getType(typeStr);
316 }
317
318
319
320
321
322
323
324
325
326
327
328
329
330 public int getQualifierFlavor(Attributes pAttribs) {
331 int flavors = 0;
332 if (!getBoolAttribute(pAttribs, "OVERRIDABLE", true)) flavors |= CIMFlavor.DISABLEOVERRIDE;
333 if (!getBoolAttribute(pAttribs, "TOSUBCLASS", true)) flavors |= CIMFlavor.RESTRICTED;
334 if (getBoolAttribute(pAttribs, "TRANSLATABLE", false)) flavors |= CIMFlavor.TRANSLATE;
335 return flavors;
336 }
337
338
339
340
341
342
343
344
345 public static boolean hasTrueAttribute(Attributes pAttribs, String pName) {
346 return MOF.TRUE.equalsIgnoreCase(pAttribs.getValue(pName));
347 }
348
349
350
351
352
353
354
355
356
357 public static boolean getBoolAttribute(Attributes pAttribs, String pName, boolean pDefVal) {
358 String val = pAttribs.getValue(pName);
359 if (MOF.TRUE.equalsIgnoreCase(val)) return true;
360 if (MOF.FALSE.equalsIgnoreCase(val)) return false;
361 return pDefVal;
362 }
363
364
365
366
367
368
369
370
371 public void duplicatedNode(String pParsedNodeName, String pNewNodeName) throws SAXException {
372 throw new SAXException(
373 getNodeName() +
374 " has a " +
375 pParsedNodeName +
376 " child node which disallows an additional " +
377 pNewNodeName +
378 " child node!"
379 );
380 }
381
382
383
384
385
386
387
388
389 public void illegalChildNodePair(String pNodeName0, String pNodeName1) throws SAXException {
390 throw new SAXException(
391 pNodeName0 + ", " + pNodeName1 + " child node pair is illegal for " + getNodeName() + " node!"
392 );
393 }
394 }