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