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 package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node;
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48 import java.util.ArrayList;
49 import org.metricshub.wbem.javax.cim.CIMObjectPath;
50 import org.metricshub.wbem.javax.cim.CIMProperty;
51 import org.metricshub.wbem.sblim.cimclient.internal.cimxml.LocalPathBuilder;
52 import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession;
53 import org.xml.sax.Attributes;
54 import org.xml.sax.SAXException;
55
56
57
58
59
60
61
62
63
64 public class InstanceNameNode extends AbstractPathNode {
65 private String iClassName;
66
67 private ArrayList<CIMProperty<?>> iCIMPropAL;
68
69 private CIMObjectPath iLocalPath;
70
71 private String iNodeName;
72
73
74
75
76 public InstanceNameNode() {
77 super(INSTANCENAME);
78 }
79
80 @Override
81 public void init(Attributes pAttribs, SAXSession pSession) throws SAXException {
82 this.iLocalPath = pSession.getDefLocalPath();
83 if (this.iCIMPropAL != null) this.iCIMPropAL.clear();
84 this.iClassName = getClassName(pAttribs);
85 this.iNodeName = null;
86 }
87
88
89
90
91 @Override
92 public void parseData(String pData) {
93
94 }
95
96 private static final String[] ALLOWED_CHILDREN = { KEYBINDING, KEYVALUE, VALUE_REFERENCE };
97
98 @Override
99 public void testChild(String pNodeNameEnum) throws SAXException {
100 for (int i = 0; i < ALLOWED_CHILDREN.length; i++) if (ALLOWED_CHILDREN[i] == pNodeNameEnum) {
101 if (this.iNodeName != null && this.iNodeName != pNodeNameEnum) throw new SAXException(
102 getNodeName() + " node cannot have " + pNodeNameEnum + " child node, it already has a " + this.iNodeName + "!"
103 );
104 if (pNodeNameEnum != KEYBINDING) {
105 if (this.iNodeName != null) throw new SAXException(
106 getNodeName() + " node can have only one " + pNodeNameEnum + " child node!"
107 );
108 }
109 this.iNodeName = pNodeNameEnum;
110 return;
111 }
112 throw new SAXException(getNodeName() + " node cannot have " + pNodeNameEnum + " child node!");
113 }
114
115 @Override
116 public void childParsed(Node pChild) {
117 if (this.iCIMPropAL == null) this.iCIMPropAL = new ArrayList<CIMProperty<?>>();
118 if (pChild instanceof KeyBindingNode) this.iCIMPropAL.add(
119 ((KeyBindingNode) pChild).getCIMProperty()
120 ); else this.iCIMPropAL.add(
121 new CIMProperty<Object>(
122 "",
123 ((AbstractScalarValueNode) pChild).getType(),
124 ((AbstractScalarValueNode) pChild).getValue(),
125 true,
126 false,
127 null
128 )
129 );
130 }
131
132 @Override
133 public void testCompletness() {
134
135 }
136
137
138
139
140
141
142 public String getClassName() {
143 return this.iClassName;
144 }
145
146 private static final CIMProperty<?>[] EMPTY_PA = new CIMProperty[0];
147
148
149
150
151
152
153 public CIMProperty<?>[] getKeys() {
154 if (this.iCIMPropAL == null || this.iCIMPropAL.size() == 0) return null;
155 return this.iCIMPropAL.toArray(EMPTY_PA);
156 }
157
158 public CIMObjectPath getCIMObjectPath() {
159
160
161
162
163 return LocalPathBuilder.build(this.iLocalPath, this.iClassName, null, getKeys());
164 }
165 }