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   * 1737141    2007-06-18  ebak         Sync up with JSR48 evolution
21   * 2003590    2008-06-30  blaschke-oss Change licensing from CPL to EPL
22   * 2013628    2008-07-30  rgummada     SAXException when listing classes
23   * 2204488 	  2008-10-28  raman_arora  Fix code to remove compiler warnings
24   * 2524131    2009-01-21  raman_arora  Upgrade client to JDK 1.5 (Phase 1)
25   * 2531371    2009-02-10  raman_arora  Upgrade client to JDK 1.5 (Phase 2)
26   * 2797550    2009-06-01  raman_arora  JSR48 compliance - add Java Generics
27   * 3513353    2012-03-30  blaschke-oss TCK: CIMDataType arrays must have length >= 1
28   *    2604    2013-07-01  blaschke-oss SAXException messages should contain node name
29   */
30  
31  package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node;
32  
33  /*-
34   * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
35   * WBEM Java Client
36   * ჻჻჻჻჻჻
37   * Copyright 2023 - 2025 MetricsHub
38   * ჻჻჻჻჻჻
39   * Licensed under the Apache License, Version 2.0 (the "License");
40   * you may not use this file except in compliance with the License.
41   * You may obtain a copy of the License at
42   *
43   *      http://www.apache.org/licenses/LICENSE-2.0
44   *
45   * Unless required by applicable law or agreed to in writing, software
46   * distributed under the License is distributed on an "AS IS" BASIS,
47   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
48   * See the License for the specific language governing permissions and
49   * limitations under the License.
50   * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
51   */
52  
53  import org.metricshub.wbem.javax.cim.CIMDataType;
54  import org.metricshub.wbem.javax.cim.CIMQualifier;
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 ((VALUE | VALUE.ARRAY)?)
64   * ATTLIST QUALIFIER
65   *  %CIMName;
66   *  %CIMType;              #REQUIRED
67   *  %Propagated;
68   *  %QualifierFlavor;
69   *  xml:lang   NMTOKEN     #IMPLIED
70   * </pre>
71   */
72  public class QualifierNode extends Node {
73  	private String iName;
74  
75  	private CIMDataType iType;
76  
77  	private boolean iPropagated;
78  
79  	private int iFlavor;
80  
81  	// (VALUE | VALUE.ARRAY)
82  	// it can be built when child is available
83  	private CIMQualifier<Object> iQuali;
84  
85  	/**
86  	 * Ctor.
87  	 */
88  	public QualifierNode() {
89  		super(QUALIFIER);
90  	}
91  
92  	/**
93  	 * @param pSession
94  	 */
95  	@Override
96  	public void init(Attributes pAttribs, SAXSession pSession) throws SAXException {
97  		this.iQuali = null;
98  		this.iName = getCIMName(pAttribs);
99  		/*
100 		 * non-standard CIMOM can supply the type info in the sub Node
101 		 */
102 		this.iType = getCIMType(pAttribs, true);
103 
104 		this.iPropagated = getPropagated(pAttribs);
105 		this.iFlavor = getQualifierFlavor(pAttribs);
106 	}
107 
108 	/**
109 	 * @param pData
110 	 */
111 	@Override
112 	public void parseData(String pData) {
113 		// no data
114 	}
115 
116 	@Override
117 	public void testChild(String pNodeNameEnum) throws SAXException {
118 		if (this.iQuali != null) throw new SAXException(
119 			getNodeName() + " node can have only one VALUE or VALUE.ARRAY child node!"
120 		);
121 		if (pNodeNameEnum != VALUE && pNodeNameEnum != VALUE_ARRAY) throw new SAXException(
122 			pNodeNameEnum + " child node is not valid for " + getNodeName() + " node!"
123 		);
124 	}
125 
126 	@Override
127 	public void childParsed(Node pChild) throws SAXException {
128 		AbstractValueNode absValNode = (AbstractValueNode) pChild;
129 		Object value;
130 		CIMDataType type;
131 		if (absValNode instanceof ValueArrayNode) {
132 			ValueArrayNode valANode = (ValueArrayNode) absValNode;
133 			setType(valANode);
134 			// create array value
135 			value = CIMObjectFactory.getObject(this.iType, valANode);
136 			// constructs array type
137 			type = this.iType.isArray() ? this.iType : CIMHelper.UnboundedArrayDataType(this.iType.getType());
138 		} else if (absValNode instanceof ValueNode) {
139 			ValueNode valNode = (ValueNode) absValNode;
140 			setType(valNode);
141 			String valueStr = (String) valNode.getValue();
142 			type = this.iType;
143 			value = CIMObjectFactory.getObject(type, valueStr);
144 		} else {
145 			type = CIMDataType.STRING_T;
146 			value = null;
147 		}
148 		this.iQuali = new CIMQualifier<Object>(this.iName, type, value, this.iFlavor, this.iPropagated);
149 	}
150 
151 	@Override
152 	public void testCompletness() {
153 		// child node is optional, hence commented to support
154 		// servers that do not implement default value to qualifier node
155 		/*
156 		 * if (iQuali == null) throw new SAXException(getNodeName() + " must have a
157 		 * VALUE or VALUE.ARRAY child node!");
158 		 */
159 	}
160 
161 	/**
162 	 * getQualifier
163 	 *
164 	 * @return CIMQualifier
165 	 */
166 	public CIMQualifier<Object> getQualifier() {
167 		return this.iQuali;
168 	}
169 
170 	/**
171 	 * Required to handle the output XML of some non-standard CIMOMs like SVC
172 	 * which adds the TYPE attribute to the sub VALUE or VALUE.ARRAY XML
173 	 * element.
174 	 *
175 	 * @param pTypedIf
176 	 * @throws SAXException
177 	 */
178 	private void setType(TypedIf pTypedIf) throws SAXException {
179 		if (this.iType != null) return;
180 		this.iType = pTypedIf.getType();
181 		if (this.iType == null) throw new SAXException(
182 			"Unknown type for Qualifier declaration in " + getNodeName() + " node!"
183 		);
184 	}
185 }