View Javadoc
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   * 2003590    2008-06-30  blaschke-oss Change licensing from CPL to EPL
21   * 2524131    2009-01-21  raman_arora  Upgrade client to JDK 1.5 (Phase 1)
22   * 2531371    2009-02-10  raman_arora  Upgrade client to JDK 1.5 (Phase 2)
23   * 2797550    2009-06-01  raman_arora  JSR48 compliance - add Java Generics
24   * 3511454    2012-03-27  blaschke-oss SAX nodes not reinitialized properly
25   * 3513353    2012-03-30  blaschke-oss TCK: CIMDataType arrays must have length >= 1
26   * 3521119    2012-04-24  blaschke-oss JSR48 1.0.0: remove CIMObjectPath 2/3/4-parm ctors
27   *    2604    2013-07-01  blaschke-oss SAXException messages should contain node name
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 org.metricshub.wbem.javax.cim.CIMDataType;
53  import org.metricshub.wbem.javax.cim.CIMObjectPath;
54  import org.metricshub.wbem.javax.cim.CIMQualifierType;
55  import org.metricshub.wbem.sblim.cimclient.internal.cim.CIMHelper;
56  import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.CIMObjectFactory;
57  import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession;
58  import org.xml.sax.Attributes;
59  import org.xml.sax.SAXException;
60  
61  /**
62   * <pre>
63   * ELEMENT QUALIFIER.DECLARATION (SCOPE?, (VALUE | VALUE.ARRAY)?)
64   * ATTLIST QUALIFIER.DECLARATION
65   * 	%CIMName;
66   * 	%CIMType;               #REQUIRED
67   * 	ISARRAY    (true|false) #IMPLIED
68   * 	%ArraySize;
69   * 	%QualifierFlavor;
70   * </pre>
71   */
72  public class QualiDeclNode extends Node implements TypedIf, ValueIf {
73  	// child nodes
74  	// SCOPE
75  	private boolean iHasScope;
76  
77  	private int iScope;
78  
79  	// VALUE
80  	private String iValueNodeName;
81  
82  	private Object iValue;
83  
84  	// attributes
85  	private String iName;
86  
87  	private CIMDataType iType;
88  
89  	private int iFlavor;
90  
91  	/**
92  	 * Ctor.
93  	 */
94  	public QualiDeclNode() {
95  		super(QUALIFIER_DECLARATION);
96  	}
97  
98  	/**
99  	 * getName
100 	 *
101 	 * @return String
102 	 */
103 	public String getName() {
104 		return this.iName;
105 	}
106 
107 	public CIMDataType getType() {
108 		return this.iType;
109 	}
110 
111 	/**
112 	 * getFlavor
113 	 *
114 	 * @return int - CIMFlavor bitset
115 	 */
116 	public int getFlavor() {
117 		return this.iFlavor;
118 	}
119 
120 	/**
121 	 * @param pSession
122 	 */
123 	@Override
124 	public void init(Attributes pAttribs, SAXSession pSession) throws SAXException {
125 		this.iHasScope = false;
126 		this.iScope = 0;
127 		this.iValueNodeName = null;
128 		this.iValue = null;
129 		this.iName = getCIMName(pAttribs);
130 		this.iType = getCIMType(pAttribs, true);
131 		this.iFlavor = getQualifierFlavor(pAttribs);
132 	}
133 
134 	/**
135 	 * @param pData
136 	 */
137 	@Override
138 	public void parseData(String pData) {
139 		// no data
140 	}
141 
142 	@Override
143 	public void testChild(String pNodeNameEnum) throws SAXException {
144 		if (pNodeNameEnum == VALUE || pNodeNameEnum == VALUE_ARRAY) {
145 			if (this.iValueNodeName != null) throw new SAXException(
146 				"Cannot add " +
147 				pNodeNameEnum +
148 				" node, this " +
149 				getNodeName() +
150 				" node has already got a " +
151 				this.iValueNodeName +
152 				" node!"
153 			);
154 		} else if (pNodeNameEnum == SCOPE) {
155 			if (this.iHasScope) throw new SAXException(
156 				"Cannot add " + pNodeNameEnum + " node, this " + getNodeName() + " node has already got one!"
157 			);
158 		} else throw new SAXException(getNodeName() + " node cannot have " + pNodeNameEnum + " child node!");
159 	}
160 
161 	/**
162 	 * Required to handle the output XML of some non-standard CIMOMs like SVC
163 	 * which adds the TYPE attribute to the sub VALUE or VALUE.ARRAY XML
164 	 * element.
165 	 *
166 	 * @param pTypedIf
167 	 * @throws SAXException
168 	 */
169 	private void setType(TypedIf pTypedIf) throws SAXException {
170 		if (this.iType != null) return;
171 		this.iType = pTypedIf.getType();
172 		if (this.iType == null) throw new SAXException(
173 			"Unknown type for Qualifier declaration in " + getNodeName() + " node!"
174 		);
175 	}
176 
177 	@Override
178 	public void childParsed(Node pChild) throws SAXException {
179 		if (pChild instanceof ScopeNode) {
180 			this.iHasScope = true;
181 			this.iScope = ((ScopeNode) pChild).getScope();
182 		} else {
183 			this.iValueNodeName = pChild.getNodeName();
184 			if (pChild instanceof ValueArrayNode) {
185 				ValueArrayNode valAChild = (ValueArrayNode) pChild;
186 				setType(valAChild);
187 				this.iValue = CIMObjectFactory.getObject(this.iType, valAChild);
188 				// making array type
189 				if (!this.iType.isArray()) this.iType = CIMHelper.UnboundedArrayDataType(this.iType.getType());
190 			} else if (pChild instanceof ValueNode) {
191 				ValueNode valChild = (ValueNode) pChild;
192 				setType(valChild);
193 				this.iValue = CIMObjectFactory.getObject(this.iType, valChild);
194 			} else {
195 				this.iValue = null;
196 			}
197 		}
198 	}
199 
200 	@Override
201 	public void testCompletness() throws SAXException {
202 		if (this.iType == null) throw new SAXException(
203 			"Unknown type for Qualifier declaration in " + getNodeName() + " node!"
204 		);
205 	}
206 
207 	/**
208 	 * getCIMQualifierType
209 	 *
210 	 * @return CIMQualifierType
211 	 */
212 	public CIMQualifierType<Object> getCIMQualifierType() {
213 		/*
214 		 * CIMQualifierType( CIMObjectPath pPath, CIMDataType pType, Object
215 		 * pValue, int pScope, int pFlavor )
216 		 */
217 		return new CIMQualifierType<Object>(
218 			new CIMObjectPath(null, null, null, null, this.iName, null),
219 			this.iType,
220 			this.iValue,
221 			this.iScope,
222 			this.iFlavor
223 		);
224 	}
225 
226 	public Object getValue() {
227 		return getCIMQualifierType();
228 	}
229 }