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.CIMClass;
51 import org.metricshub.wbem.javax.cim.CIMClassProperty;
52 import org.metricshub.wbem.javax.cim.CIMMethod;
53 import org.metricshub.wbem.javax.cim.CIMObjectPath;
54 import org.metricshub.wbem.sblim.cimclient.GenericExts;
55 import org.metricshub.wbem.sblim.cimclient.internal.cimxml.LocalPathBuilder;
56 import org.metricshub.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
66
67
68 public class ClassNode extends AbstractObjectNode {
69 private String iName;
70
71 private String iSuperClass;
72
73 private QualifiedNodeHandler iQualiHandler;
74
75 private ArrayList<CIMClassProperty<?>> iCIMClassPropAL;
76
77 private boolean iKeyed;
78
79 private ArrayList<CIMMethod<?>> iCIMMethodAL;
80
81
82
83
84 public ClassNode() {
85 super(CLASS);
86 }
87
88 @Override
89 public void init(Attributes pAttribs, SAXSession pSession) throws SAXException {
90 this.iLocalPath = pSession.getDefLocalPath();
91 this.iQualiHandler = QualifiedNodeHandler.init(this.iQualiHandler);
92 this.iCIMClassPropAL = GenericExts.initClearArrayList(this.iCIMClassPropAL);
93 this.iKeyed = false;
94 this.iCIMMethodAL = GenericExts.initClearArrayList(this.iCIMMethodAL);
95 this.iName = getCIMName(pAttribs);
96 this.iSuperClass = pAttribs.getValue("SUPERCLASS");
97 }
98
99
100
101
102 @Override
103 public void parseData(String pData) {
104
105 }
106
107 private static final String[] ALLOWED_CHILDREN = { QUALIFIER, PROPERTY, PROPERTY_ARRAY, PROPERTY_REFERENCE, METHOD };
108
109 @Override
110 public void testChild(String pNodeNameEnum) throws SAXException {
111 for (int i = 0; i < ALLOWED_CHILDREN.length; i++) if (ALLOWED_CHILDREN[i] == pNodeNameEnum) return;
112 throw new SAXException(getNodeName() + " node cannot have " + pNodeNameEnum + " child node!");
113 }
114
115 @Override
116 public void childParsed(Node pChild) {
117 if (this.iQualiHandler.addQualifierNode(pChild)) return;
118 if (pChild instanceof AbstractPropertyNode) {
119 if (this.iCIMClassPropAL == null) this.iCIMClassPropAL = new ArrayList<CIMClassProperty<?>>();
120 CIMClassProperty<Object> prop = ((AbstractPropertyNode) pChild).getCIMClassProperty();
121 if (prop.isKey()) this.iKeyed = true;
122 this.iCIMClassPropAL.add(prop);
123 } else {
124 if (this.iCIMMethodAL == null) this.iCIMMethodAL = new ArrayList<CIMMethod<?>>();
125 this.iCIMMethodAL.add(((MethodNode) pChild).getCIMMethod());
126 }
127 }
128
129 @Override
130 public void testCompletness() {
131
132 }
133
134
135
136
137
138
139 public CIMClass getCIMClass() {
140
141
142
143
144
145
146 return new CIMClass(
147 LocalPathBuilder.build(this.iLocalPath, this.iName, null),
148 this.iSuperClass,
149 this.iQualiHandler.getQualis(),
150 this.iCIMClassPropAL.toArray(EMPTY_PA),
151 this.iCIMMethodAL.toArray(EMPTY_MA),
152 this.iQualiHandler.isAssociation(),
153 this.iKeyed
154 );
155 }
156
157 private static final CIMMethod<?>[] EMPTY_MA = new CIMMethod[0];
158
159 private static final CIMClassProperty<?>[] EMPTY_PA = new CIMClassProperty[0];
160
161
162
163
164
165
166
167 public CIMClass getCIMClass(CIMObjectPath pObjPath) {
168 return new CIMClass(
169 pObjPath,
170 this.iSuperClass,
171 this.iQualiHandler.getQualis(),
172 this.iCIMClassPropAL.toArray(EMPTY_PA),
173 this.iCIMMethodAL.toArray(EMPTY_MA),
174 this.iQualiHandler.isAssociation(),
175 this.iKeyed
176 );
177 }
178
179
180
181
182
183 public Object getValue() {
184 return getCIMClass();
185 }
186 }