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.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node;
29  
30  /*-
31   * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
32   * WBEM Java Client
33   * ჻჻჻჻჻჻
34   * Copyright (C) 2023 Sentry Software
35   * ჻჻჻჻჻჻
36   * This program is free software: you can redistribute it and/or modify
37   * it under the terms of the GNU Lesser General Public License as
38   * published by the Free Software Foundation, either version 3 of the
39   * License, or (at your option) any later version.
40   *
41   * This program is distributed in the hope that it will be useful,
42   * but WITHOUT ANY WARRANTY; without even the implied warranty of
43   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
44   * GNU General Lesser Public License for more details.
45   *
46   * You should have received a copy of the GNU General Lesser Public
47   * License along with this program.  If not, see
48   * <http://www.gnu.org/licenses/lgpl-3.0.html>.
49   * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
50   */
51  
52  import org.sentrysoftware.wbem.javax.cim.CIMArgument;
53  import org.sentrysoftware.wbem.javax.cim.CIMDataType;
54  
55  import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.EmbObjHandler;
56  import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession;
57  import org.xml.sax.Attributes;
58  import org.xml.sax.SAXException;
59  
60  /**
61   * ELEMENT PARAMVALUE (VALUE | VALUE.REFERENCE | VALUE.ARRAY | VALUE.REFARRAY |
62   * CLASSNAME | INSTANCENAME | CLASS | INSTANCE | VALUE.NAMEDINSTANCE)? ATTLIST
63   * PARAMVALUE %CIMName; %ParamType; #IMPLIED %EmbeddedObject; #IMPLIED - new
64   */
65  public class ParamValueNode extends AbstractParamValueNode {
66  
67  	private String iName;
68  
69  	private EmbObjHandler iEmbObjHandler;
70  
71  	private CIMDataType iType;
72  
73  	// VALUE.xxx node
74  	private boolean iHasChild;
75  
76  	private boolean iHasTypeValue;
77  
78  	private Object iValue;
79  
80  	/**
81  	 * Ctor.
82  	 */
83  	public ParamValueNode() {
84  		super(PARAMVALUE);
85  	}
86  
87  	@Override
88  	public void init(Attributes pAttribs, SAXSession pSession) throws SAXException {
89  		this.iEmbObjHandler = EmbObjHandler.init(this.iEmbObjHandler, getNodeName(), pAttribs,
90  				pSession, null, true);
91  		this.iHasChild = false;
92  		this.iHasTypeValue = false;
93  		this.iName = getCIMName(pAttribs);
94  		this.iType = null;
95  		this.iValue = null;
96  	}
97  
98  	/**
99  	 * @param pData
100 	 */
101 	@Override
102 	public void parseData(String pData) {
103 	// no data
104 	}
105 
106 	private static final String[] ALLOWED_CHILDREN = { VALUE, VALUE_REFERENCE, VALUE_ARRAY,
107 			VALUE_REFARRAY, CLASSNAME, INSTANCENAME, CLASS, INSTANCE, VALUE_NAMEDINSTANCE };
108 
109 	@Override
110 	public void testChild(String pNodeNameEnum) throws SAXException {
111 		boolean allowed = false;
112 		for (int i = 0; i < ALLOWED_CHILDREN.length; i++) {
113 			if (ALLOWED_CHILDREN[i] == pNodeNameEnum) {
114 				allowed = true;
115 				break;
116 			}
117 		}
118 		if (!allowed) throw new SAXException(getNodeName() + " node cannot have " + pNodeNameEnum
119 				+ " child node!");
120 		if (this.iHasChild) throw new SAXException(getNodeName()
121 				+ " node cannot have more than one child node!");
122 		// type check
123 		CIMDataType rawType = this.iEmbObjHandler.getRawType();
124 		if (rawType != null) {
125 			if (pNodeNameEnum == VALUE_REFERENCE || pNodeNameEnum == VALUE_REFARRAY) {
126 				if (rawType.getType() != CIMDataType.REFERENCE) throw new SAXException(
127 						"PARAMVALUE node's PARAMTYPE attribute is not reference (" + rawType
128 								+ "), but a " + pNodeNameEnum + " child node is found!");
129 			}
130 		}
131 	}
132 
133 	@Override
134 	public void childParsed(Node pChild) {
135 		if (pChild instanceof AbstractValueNode) {
136 			this.iEmbObjHandler.addValueNode((AbstractValueNode) pChild);
137 		} else {
138 			this.iValue = ((ValueIf) pChild).getValue();
139 			if (pChild instanceof TypedIf) this.iType = ((TypedIf) pChild).getType();
140 			else if (pChild instanceof ObjectPathIf) this.iType = CIMDataType
141 					.getDataType(((ObjectPathIf) pChild).getCIMObjectPath());
142 			else if (pChild instanceof ValueIf) this.iType = CIMDataType
143 					.getDataType(((ValueIf) pChild).getValue());
144 			this.iHasTypeValue = true;
145 		}
146 		this.iHasChild = true;
147 	}
148 
149 	@Override
150 	public void testCompletness() throws SAXException {
151 		if (!this.iHasTypeValue) {
152 			// here is a type and value conversion
153 			this.iType = this.iEmbObjHandler.getType();
154 			this.iValue = this.iEmbObjHandler.getValue();
155 		}
156 	}
157 
158 	public CIMDataType getType() {
159 		return this.iType;
160 	}
161 
162 	/**
163 	 * getCIMArgument
164 	 * 
165 	 * @return CIMArgument
166 	 */
167 	@Override
168 	public CIMArgument<Object> getCIMArgument() {
169 		/*
170 		 * CIMArgument(String name, CIMDataType type, Object value)
171 		 */
172 		return new CIMArgument<Object>(this.iName, this.iType, this.iValue);
173 	}
174 
175 	/**
176 	 * @see ValueIf#getValue()
177 	 */
178 	public Object getValue() {
179 		return this.iValue;
180 	}
181 
182 }