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   * 1689085    2007-04-10  ebak         Embedded object enhancements for Pegasus
19   * 1719991    2007-05-16  ebak         FVT: regression ClassCastException in EmbObjHandler
20   * 1720707    2007-05-17  ebak         Conventional Node factory for CIM-XML SAX parser
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   * 2797550    2009-06-01  raman_arora  JSR48 compliance - add Java Generics
24   *    2605    2013-03-20  buccella     SAX parser throws wrong exception
25   *    2537    2013-10-17  blaschke-oss Add new data types for PARAMVALUE
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 org.metricshub.wbem.javax.cim.CIMArgument;
51  import org.metricshub.wbem.javax.cim.CIMDataType;
52  import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.EmbObjHandler;
53  import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession;
54  import org.xml.sax.Attributes;
55  import org.xml.sax.SAXException;
56  
57  /**
58   * ELEMENT PARAMVALUE (VALUE | VALUE.REFERENCE | VALUE.ARRAY | VALUE.REFARRAY |
59   * CLASSNAME | INSTANCENAME | CLASS | INSTANCE | VALUE.NAMEDINSTANCE)? ATTLIST
60   * PARAMVALUE %CIMName; %ParamType; #IMPLIED %EmbeddedObject; #IMPLIED - new
61   */
62  public class ParamValueNode extends AbstractParamValueNode {
63  	private String iName;
64  
65  	private EmbObjHandler iEmbObjHandler;
66  
67  	private CIMDataType iType;
68  
69  	// VALUE.xxx node
70  	private boolean iHasChild;
71  
72  	private boolean iHasTypeValue;
73  
74  	private Object iValue;
75  
76  	/**
77  	 * Ctor.
78  	 */
79  	public ParamValueNode() {
80  		super(PARAMVALUE);
81  	}
82  
83  	@Override
84  	public void init(Attributes pAttribs, SAXSession pSession) throws SAXException {
85  		this.iEmbObjHandler = EmbObjHandler.init(this.iEmbObjHandler, getNodeName(), pAttribs, pSession, null, true);
86  		this.iHasChild = false;
87  		this.iHasTypeValue = false;
88  		this.iName = getCIMName(pAttribs);
89  		this.iType = null;
90  		this.iValue = null;
91  	}
92  
93  	/**
94  	 * @param pData
95  	 */
96  	@Override
97  	public void parseData(String pData) {
98  		// no data
99  	}
100 
101 	private static final String[] ALLOWED_CHILDREN = {
102 		VALUE,
103 		VALUE_REFERENCE,
104 		VALUE_ARRAY,
105 		VALUE_REFARRAY,
106 		CLASSNAME,
107 		INSTANCENAME,
108 		CLASS,
109 		INSTANCE,
110 		VALUE_NAMEDINSTANCE
111 	};
112 
113 	@Override
114 	public void testChild(String pNodeNameEnum) throws SAXException {
115 		boolean allowed = false;
116 		for (int i = 0; i < ALLOWED_CHILDREN.length; i++) {
117 			if (ALLOWED_CHILDREN[i] == pNodeNameEnum) {
118 				allowed = true;
119 				break;
120 			}
121 		}
122 		if (!allowed) throw new SAXException(getNodeName() + " node cannot have " + pNodeNameEnum + " child node!");
123 		if (this.iHasChild) throw new SAXException(getNodeName() + " node cannot have more than one child node!");
124 		// type check
125 		CIMDataType rawType = this.iEmbObjHandler.getRawType();
126 		if (rawType != null) {
127 			if (pNodeNameEnum == VALUE_REFERENCE || pNodeNameEnum == VALUE_REFARRAY) {
128 				if (rawType.getType() != CIMDataType.REFERENCE) throw new SAXException(
129 					"PARAMVALUE node's PARAMTYPE attribute is not reference (" +
130 					rawType +
131 					"), but a " +
132 					pNodeNameEnum +
133 					" child node is found!"
134 				);
135 			}
136 		}
137 	}
138 
139 	@Override
140 	public void childParsed(Node pChild) {
141 		if (pChild instanceof AbstractValueNode) {
142 			this.iEmbObjHandler.addValueNode((AbstractValueNode) pChild);
143 		} else {
144 			this.iValue = ((ValueIf) pChild).getValue();
145 			if (pChild instanceof TypedIf) this.iType = ((TypedIf) pChild).getType(); else if (
146 				pChild instanceof ObjectPathIf
147 			) this.iType = CIMDataType.getDataType(((ObjectPathIf) pChild).getCIMObjectPath()); else if (
148 				pChild instanceof ValueIf
149 			) this.iType = CIMDataType.getDataType(((ValueIf) pChild).getValue());
150 			this.iHasTypeValue = true;
151 		}
152 		this.iHasChild = true;
153 	}
154 
155 	@Override
156 	public void testCompletness() throws SAXException {
157 		if (!this.iHasTypeValue) {
158 			// here is a type and value conversion
159 			this.iType = this.iEmbObjHandler.getType();
160 			this.iValue = this.iEmbObjHandler.getValue();
161 		}
162 	}
163 
164 	public CIMDataType getType() {
165 		return this.iType;
166 	}
167 
168 	/**
169 	 * getCIMArgument
170 	 *
171 	 * @return CIMArgument
172 	 */
173 	@Override
174 	public CIMArgument<Object> getCIMArgument() {
175 		/*
176 		 * CIMArgument(String name, CIMDataType type, Object value)
177 		 */
178 		return new CIMArgument<Object>(this.iName, this.iType, this.iValue);
179 	}
180 
181 	/**
182 	 * @see ValueIf#getValue()
183 	 */
184 	public Object getValue() {
185 		return this.iValue;
186 	}
187 }