1 /*
2 (C) Copyright IBM Corp. 2006, 2013
3
4 THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE
5 ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE
6 CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT.
7
8 You can obtain a current copy of the Eclipse Public License from
9 http://www.opensource.org/licenses/eclipse-1.0.php
10
11 @author : Endre Bak, ebak@de.ibm.com
12 *
13 * Flag Date Prog Description
14 * -------------------------------------------------------------------------------
15 * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant
16 * 1663270 2007-02-19 ebak Minor performance problems
17 * 1660756 2007-02-22 ebak Embedded object support
18 * 1712656 2007-05-04 ebak Correct type identification for SVC CIMOM
19 * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser
20 * 1735693 2007-06-12 ebak Empty VALUE.ARRAY elements are parsed as nulls
21 * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL
22 * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1)
23 * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2)
24 * 3513353 2012-03-30 blaschke-oss TCK: CIMDataType arrays must have length >= 1
25 * 2715 2013-11-26 blaschke-oss Add VALUE.NULL support
26 */
27
28 package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node;
29
30 /*-
31 * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
32 * WBEM Java Client
33 * ჻჻჻჻჻჻
34 * Copyright 2023 - 2025 MetricsHub
35 * ჻჻჻჻჻჻
36 * Licensed under the Apache License, Version 2.0 (the "License");
37 * you may not use this file except in compliance with the License.
38 * You may obtain a copy of the License at
39 *
40 * http://www.apache.org/licenses/LICENSE-2.0
41 *
42 * Unless required by applicable law or agreed to in writing, software
43 * distributed under the License is distributed on an "AS IS" BASIS,
44 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
45 * See the License for the specific language governing permissions and
46 * limitations under the License.
47 * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
48 */
49
50 import java.util.ArrayList;
51 import org.metricshub.wbem.javax.cim.CIMDataType;
52 import org.metricshub.wbem.sblim.cimclient.GenericExts;
53 import org.metricshub.wbem.sblim.cimclient.internal.cim.CIMHelper;
54 import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession;
55 import org.xml.sax.Attributes;
56 import org.xml.sax.SAXException;
57
58 /**
59 * ELEMENT VALUE.ARRAY (VALUE|VALUE.NULL)*<br>
60 * For non-standard CIMOMs the TYPE and PARAMTYPE attributes are handled.
61 */
62 public class ValueArrayNode extends AbstractArrayValueNode {
63 // VALUE *
64 private ArrayList<Object> iValueAL;
65
66 private CIMDataType iType;
67
68 /**
69 * Ctor.
70 */
71 public ValueArrayNode() {
72 super(VALUE_ARRAY);
73 }
74
75 /**
76 * @param pSession
77 */
78 @Override
79 public void init(Attributes pAttribs, SAXSession pSession) throws SAXException {
80 this.iValueAL = GenericExts.initClearArrayList(this.iValueAL);
81 /*
82 * For supporting non-standard CIMOMs TYPE and PARAMTYPE attributes are
83 * handled
84 */
85 CIMDataType scalarType = getCIMType(pAttribs, true);
86 if (scalarType == null) scalarType = getParamType(pAttribs);
87 // make array type
88 this.iType = scalarType == null ? null : CIMHelper.UnboundedArrayDataType(scalarType.getType());
89 }
90
91 /**
92 * @param pData
93 */
94 @Override
95 public void parseData(String pData) {
96 // no data
97 }
98
99 @Override
100 public void testChild(String pNodeNameEnum) throws SAXException {
101 if (pNodeNameEnum != VALUE && pNodeNameEnum != VALUE_NULL) throw new SAXException(
102 "Only VALUE and VALUE.NULL nodes can be added to VALUE.ARRAY nodes but " + pNodeNameEnum + " found!"
103 );
104 }
105
106 @Override
107 public void childParsed(Node pChild) {
108 if (this.iValueAL == null) this.iValueAL = new ArrayList<Object>();
109 if (pChild instanceof ValueNode) this.iValueAL.add(((ValueNode) pChild).getValue()); else if (
110 pChild instanceof ValueNullNode
111 ) this.iValueAL.add(null);
112 }
113
114 @Override
115 public void testCompletness() {
116 // Nothing to test, since it is OK if it doesn't have child node.
117 }
118
119 /**
120 * @see ArrayIf#elementAt(int)
121 * @return String value of VALUE child node
122 */
123 public Object elementAt(int pIdx) {
124 return this.iValueAL.get(pIdx);
125 }
126
127 public int size() {
128 return this.iValueAL == null ? 0 : this.iValueAL.size();
129 }
130
131 /**
132 * @see TypedIf#getType()
133 * @return usually null, because the type is unknown, but can return
134 * non-null in case of non-standard CIMOM.
135 */
136 public CIMDataType getType() {
137 return this.iType;
138 }
139
140 private static final String[] EMPTY_SA = new String[0];
141
142 /**
143 * @see ValueIf#getValue() If
144 * the getType() returns non-null value, the container Node have to
145 * convert the String into the corresponding Java object.
146 * @return String[]
147 */
148 public Object getValue() {
149 return this.iValueAL == null ? EMPTY_SA : this.iValueAL.toArray(EMPTY_SA);
150 }
151 }