1 /*
2 (C) Copyright IBM Corp. 2006, 2012
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 * 1783288 2007-09-10 ebak CIMClass.isAssociation() not working for retrieved classes.
19 * 1820763 2007-10-29 ebak Supporting the EmbeddedInstance qualifier
20 * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL
21 * 2013628 2008-07-30 rgummada SAXException when listing classes
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 * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics
25 * 2823494 2009-08-03 rgummada Change Boolean constructor to static
26 * 2957387 2010-03-03 blaschke-oss EmbededObject XML attribute must not be all uppercases
27 * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly
28 */
29
30 package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node;
31
32 /*-
33 * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
34 * WBEM Java Client
35 * ჻჻჻჻჻჻
36 * Copyright 2023 - 2025 MetricsHub
37 * ჻჻჻჻჻჻
38 * Licensed under the Apache License, Version 2.0 (the "License");
39 * you may not use this file except in compliance with the License.
40 * You may obtain a copy of the License at
41 *
42 * http://www.apache.org/licenses/LICENSE-2.0
43 *
44 * Unless required by applicable law or agreed to in writing, software
45 * distributed under the License is distributed on an "AS IS" BASIS,
46 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
47 * See the License for the specific language governing permissions and
48 * limitations under the License.
49 * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
50 */
51
52 import java.util.ArrayList;
53 import org.metricshub.wbem.javax.cim.CIMDataType;
54 import org.metricshub.wbem.javax.cim.CIMQualifier;
55 import org.metricshub.wbem.sblim.cimclient.GenericExts;
56 import org.metricshub.wbem.sblim.cimclient.internal.cim.CIMQualifiedElementInterfaceImpl;
57
58 /**
59 * Class QualifiedNodeHandler helps parsing XML elements with QUALIFIER child
60 * elements.
61 */
62 public class QualifiedNodeHandler {
63 private static final Boolean TRUE = Boolean.TRUE;
64
65 private ArrayList<CIMQualifier<?>> iQualiAL;
66
67 private CIMQualifiedElementInterfaceImpl iQualiImpl;
68
69 private boolean iHasEmbObjQuali, iHasEmbInstQuali;
70
71 private boolean iHasKeyQuali, iHasAssocQuali;
72
73 /**
74 * init
75 *
76 * @param pQNH
77 * - if it's null it returns with a new instance otherwise it
78 * inits and returns pQNH
79 * @return a QualifiedNodeHandler instance
80 */
81 public static QualifiedNodeHandler init(QualifiedNodeHandler pQNH) {
82 if (pQNH == null) pQNH = new QualifiedNodeHandler();
83 pQNH.init();
84 return pQNH;
85 }
86
87 /**
88 * init - for reusing an existing QualifiedNodeHandler instance
89 */
90 public void init() {
91 this.iQualiAL = GenericExts.initClearArrayList(this.iQualiAL);
92 this.iHasEmbObjQuali = this.iHasEmbInstQuali = this.iHasKeyQuali = this.iHasAssocQuali = false;
93 this.iQualiImpl = null;
94 }
95
96 /**
97 * addQualifierNode
98 *
99 * @param pNode
100 * @return false if pNode is not instance of QualifierNode
101 */
102 public boolean addQualifierNode(Node pNode) {
103 if (!(pNode instanceof QualifierNode)) return false;
104 if (this.iQualiAL == null) this.iQualiAL = new ArrayList<CIMQualifier<?>>();
105 CIMQualifier<Object> quali = ((QualifierNode) pNode).getQualifier();
106 if (quali != null) {
107 // check for null,
108 // because it can be null if child node is not populated
109 if (CIMDataType.BOOLEAN_T.equals(quali.getDataType()) && TRUE.equals(quali.getValue())) {
110 if ("EmbeddedObject".equalsIgnoreCase(quali.getName())) {
111 this.iHasEmbObjQuali = true;
112 } else if ("KEY".equalsIgnoreCase(quali.getName())) {
113 this.iHasKeyQuali = true;
114 } else if ("ASSOCIATION".equalsIgnoreCase(quali.getName())) {
115 this.iHasAssocQuali = true;
116 }
117 } else if (
118 CIMDataType.STRING_T.equals(quali.getDataType()) && "EMBEDDEDINSTANCE".equalsIgnoreCase(quali.getName())
119 ) {
120 this.iHasEmbInstQuali = true;
121 }
122 this.iQualiAL.add(quali);
123 }
124 return true;
125 }
126
127 /**
128 * getQualis
129 *
130 * @return CIMQualifier[]
131 */
132 public CIMQualifier<?>[] getQualis() {
133 return getQualis(false);
134 }
135
136 /**
137 * getQualis
138 *
139 * @param pIncludeEmbObj
140 * @return CIMQualifier[]
141 */
142 public CIMQualifier<?>[] getQualis(boolean pIncludeEmbObj) {
143 makeQualiImpl(pIncludeEmbObj);
144 return this.iQualiImpl.getQualifiers();
145 }
146
147 /**
148 * isKeyed
149 *
150 * @return boolean
151 */
152 public boolean isKeyed() {
153 return this.iHasKeyQuali;
154 }
155
156 /**
157 * isAssociation
158 *
159 * @return boolean
160 */
161 public boolean isAssociation() {
162 return this.iHasAssocQuali;
163 }
164
165 /**
166 * isEmbeddedObject
167 *
168 * @return boolean
169 */
170 public boolean isEmbeddedObject() {
171 return this.iHasEmbObjQuali;
172 }
173
174 /**
175 * isEmbeddedInstance
176 *
177 * @return boolean
178 */
179 public boolean isEmbeddedInstance() {
180 return this.iHasEmbInstQuali;
181 }
182
183 private static final CIMQualifier<?>[] EMPTY_QA = new CIMQualifier[0];
184
185 private void makeQualiImpl(boolean pIncludeEmbObj) {
186 if (this.iQualiImpl != null) return;
187 if (this.iQualiAL == null) {
188 this.iQualiImpl = new CIMQualifiedElementInterfaceImpl(null);
189 return;
190 }
191 this.iQualiImpl =
192 new CIMQualifiedElementInterfaceImpl(this.iQualiAL.toArray(EMPTY_QA), this.iHasKeyQuali, pIncludeEmbObj);
193 this.iQualiAL = null;
194 }
195 }