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   * 1686000    2007-04-20  ebak         modifyInstance() missing from WBEMClient
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   * 2797550    2009-06-01  raman_arora  JSR48 compliance - add Java Generics
23   *    2680    2013-10-02  blaschke-oss IPARAMVALUE parsing broken on DOM/SAX
24   */
25  
26  package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node;
27  
28  /*-
29   * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
30   * WBEM Java Client
31   * ჻჻჻჻჻჻
32   * Copyright 2023 - 2025 MetricsHub
33   * ჻჻჻჻჻჻
34   * Licensed under the Apache License, Version 2.0 (the "License");
35   * you may not use this file except in compliance with the License.
36   * You may obtain a copy of the License at
37   *
38   *      http://www.apache.org/licenses/LICENSE-2.0
39   *
40   * Unless required by applicable law or agreed to in writing, software
41   * distributed under the License is distributed on an "AS IS" BASIS,
42   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
43   * See the License for the specific language governing permissions and
44   * limitations under the License.
45   * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
46   */
47  
48  import org.metricshub.wbem.javax.cim.CIMArgument;
49  import org.metricshub.wbem.javax.cim.CIMDataType;
50  import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession;
51  import org.xml.sax.Attributes;
52  import org.xml.sax.SAXException;
53  
54  /**
55   * FIXME: Why hasn't it got TYPE attribute? For VALUE and VALUE.ARRAY it would
56   * be necessary.
57   *
58   * <pre>
59   *
60   * ELEMENT IPARAMVALUE (VALUE | VALUE.ARRAY | VALUE.REFERENCE | INSTANCENAME | CLASSNAME |
61   *   QUALIFIER.DECLARATION | CLASS | INSTANCE | VALUE.NAMEDINSTANCE)?
62   * ATTLIST IPARAMVALUE
63   *   %CIMName;
64   * </pre>
65   */
66  public class IParamValueNode extends AbstractParamValueNode {
67  	private String iName;
68  
69  	/**
70  	 * child element
71  	 */
72  	private Object iValue;
73  
74  	private boolean iIsArray;
75  
76  	private CIMDataType iType;
77  
78  	/**
79  	 * Ctor.
80  	 */
81  	public IParamValueNode() {
82  		super(IPARAMVALUE);
83  	}
84  
85  	/**
86  	 * @param pSession
87  	 */
88  	@Override
89  	public void init(Attributes pAttribs, SAXSession pSession) throws SAXException {
90  		this.iValue = null;
91  		this.iType = null;
92  		this.iName = getCIMName(pAttribs);
93  	}
94  
95  	/**
96  	 * @param pData
97  	 */
98  	@Override
99  	public void parseData(String pData) {
100 		// no data
101 	}
102 
103 	private static final String[] ALLOWED_CHILDREN = {
104 		VALUE,
105 		VALUE_ARRAY,
106 		VALUE_REFERENCE,
107 		INSTANCENAME,
108 		CLASSNAME,
109 		QUALIFIER_DECLARATION,
110 		CLASS,
111 		INSTANCE,
112 		VALUE_NAMEDINSTANCE
113 	};
114 
115 	@Override
116 	public void testChild(String pNodeNameEnum) throws SAXException {
117 		boolean allowed = false;
118 		for (int i = 0; i < ALLOWED_CHILDREN.length; i++) {
119 			if (ALLOWED_CHILDREN[i] == pNodeNameEnum) {
120 				allowed = true;
121 				break;
122 			}
123 		}
124 		if (!allowed) throw new SAXException(getNodeName() + " node cannot have " + pNodeNameEnum + " child node!");
125 		/*
126 		 * this kind of check is not so strict (ValueNode.getValue() can return
127 		 * null)
128 		 */
129 		if (this.iValue != null) throw new SAXException(getNodeName() + " node cannot have more than one child node!");
130 	}
131 
132 	@Override
133 	public void childParsed(Node pChild) {
134 		this.iValue = ((ValueIf) pChild).getValue();
135 		this.iIsArray = pChild instanceof ArrayIf;
136 		if (pChild instanceof TypedIf) this.iType = ((TypedIf) pChild).getType(); else if (
137 			pChild instanceof ObjectPathIf
138 		) this.iType = CIMDataType.getDataType(((ObjectPathIf) pChild).getCIMObjectPath()); else if (
139 			pChild instanceof ValueIf
140 		) this.iType = CIMDataType.getDataType(((ValueIf) pChild).getValue());
141 	}
142 
143 	@Override
144 	public void testCompletness() {
145 		// child node is optional
146 	}
147 
148 	@Override
149 	public CIMArgument<Object> getCIMArgument() {
150 		return new CIMArgument<Object>(this.iName, getType(), this.iValue);
151 	}
152 
153 	/**
154 	 * getName
155 	 *
156 	 * @return String
157 	 */
158 	public String getName() {
159 		return this.iName;
160 	}
161 
162 	public CIMDataType getType() {
163 		return this.iType == null ? (this.iIsArray ? CIMDataType.STRING_ARRAY_T : CIMDataType.STRING_T) : this.iType;
164 	}
165 
166 	public Object getValue() {
167 		return this.iValue;
168 	}
169 }