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   * 1720707    2007-05-17  ebak         Conventional Node factory for CIM-XML SAX parser
19   * 2003590    2008-06-30  blaschke-oss Change licensing from CPL to EPL
20   * 2524131    2009-01-21  raman_arora  Upgrade client to JDK 1.5 (Phase 1)
21   * 2797550    2009-06-01  raman_arora  JSR48 compliance - add Java Generics
22   * 3602604    2013-01-29  blaschke-oss Clean up SAXException messages
23   */
24  
25  package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node;
26  
27  /*-
28   * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
29   * WBEM Java Client
30   * ჻჻჻჻჻჻
31   * Copyright 2023 - 2025 MetricsHub
32   * ჻჻჻჻჻჻
33   * Licensed under the Apache License, Version 2.0 (the "License");
34   * you may not use this file except in compliance with the License.
35   * You may obtain a copy of the License at
36   *
37   *      http://www.apache.org/licenses/LICENSE-2.0
38   *
39   * Unless required by applicable law or agreed to in writing, software
40   * distributed under the License is distributed on an "AS IS" BASIS,
41   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
42   * See the License for the specific language governing permissions and
43   * limitations under the License.
44   * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
45   */
46  
47  import org.metricshub.wbem.javax.cim.CIMDataType;
48  import org.metricshub.wbem.javax.cim.CIMProperty;
49  import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession;
50  import org.xml.sax.Attributes;
51  import org.xml.sax.SAXException;
52  
53  /**
54   * ELEMENT KEYBINDING (KEYVALUE | VALUE.REFERENCE) ATTLIST KEYBINDING %CIMName;
55   */
56  public class KeyBindingNode extends Node {
57  	private String iName;
58  
59  	// child element
60  	private boolean iHasChild;
61  
62  	private CIMDataType iType;
63  
64  	private Object iValue;
65  
66  	/**
67  	 * Ctor.
68  	 */
69  	public KeyBindingNode() {
70  		super(KEYBINDING);
71  	}
72  
73  	/**
74  	 * @param pSession
75  	 */
76  	@Override
77  	public void init(Attributes pAttribs, SAXSession pSession) throws SAXException {
78  		this.iHasChild = false;
79  		this.iValue = null;
80  		this.iName = getCIMName(pAttribs);
81  	}
82  
83  	/**
84  	 * @param pData
85  	 */
86  	@Override
87  	public void parseData(String pData) {
88  		// no data
89  	}
90  
91  	@Override
92  	public void testChild(String pNodeNameEnum) throws SAXException {
93  		if (this.iHasChild) throw new SAXException("KEYBINDING node can only have one child node!");
94  		if (pNodeNameEnum != KEYVALUE && pNodeNameEnum != VALUE_REFERENCE) throw new SAXException(
95  			"KEYBINDING node's child node can be KEYVALUE or VALUE_REFERENCE but not " + pNodeNameEnum
96  		);
97  	}
98  
99  	@Override
100 	public void childParsed(Node pChild) {
101 		AbstractScalarValueNode abstScalarValNode = (AbstractScalarValueNode) pChild;
102 		this.iType = abstScalarValNode.getType();
103 		this.iValue = abstScalarValNode.getValue();
104 		this.iHasChild = true;
105 	}
106 
107 	@Override
108 	public void testCompletness() throws SAXException {
109 		if (!this.iHasChild) throw new SAXException("KEYBINDING node must have a KEYVALUE or VALUE_REFERENCE child node!");
110 	}
111 
112 	/**
113 	 * getCIMProperty
114 	 *
115 	 * @return CIMProperty
116 	 */
117 	public CIMProperty<Object> getCIMProperty() {
118 		// CIMProperty(
119 		// String name, CIMDataType type, Object value, boolean key, boolean
120 		// propagated, String originClass
121 		// )
122 		return new CIMProperty<Object>(this.iName, this.iType, this.iValue, true, false, null);
123 	}
124 }