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   * 2531371    2009-02-10  raman_arora  Upgrade client to JDK 1.5 (Phase 2)
22   * 2763216    2009-04-14  blaschke-oss Code cleanup: visible spelling/grammar errors
23   * 3598613    2013-01-11  blaschke-oss different data type in cim instance and cim object path
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.CIMDataType;
49  import org.metricshub.wbem.javax.cim.CIMInstance;
50  import org.metricshub.wbem.javax.cim.CIMObjectPath;
51  import org.metricshub.wbem.sblim.cimclient.internal.cim.CIMHelper;
52  import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession;
53  import org.metricshub.wbem.sblim.cimclient.internal.util.WBEMConfiguration;
54  import org.xml.sax.Attributes;
55  import org.xml.sax.SAXException;
56  
57  /**
58   * <pre>
59   * ELEMENT VALUE.NAMEDINSTANCE (INSTANCENAME, INSTANCE)
60   *
61   * ELEMENT INSTANCENAME (KEYBINDING* | KEYVALUE? | VALUE.REFERENCE?)
62   * ATTLIST INSTANCENAME
63   *   %ClassName;
64   *
65   * ELEMENT INSTANCE (QUALIFIER*, (PROPERTY | PROPERTY.ARRAY | PROPERTY.REFERENCE)*)
66   * ATTLIST INSTANCE
67   *   %ClassName;
68   *   xml:lang   NMTOKEN      #IMPLIED
69   * FIXME: Why INSTANCE has qualifiers? CIMInstance doesn't have!
70   * FIXME: InstanceName and instance provides redundant information. Why?
71   * </pre>
72   */
73  public class ValueNamedInstanceNode extends AbstractScalarValueNode {
74  	// INSTANCENAME
75  	private CIMObjectPath iCIMInstPath;
76  
77  	// INSTANCE
78  	private CIMInstance iCIMInstance;
79  
80  	/**
81  	 * Ctor.
82  	 */
83  	public ValueNamedInstanceNode() {
84  		super(VALUE_NAMEDINSTANCE);
85  	}
86  
87  	/**
88  	 * @param pAttribs
89  	 * @param pSession
90  	 */
91  	@Override
92  	public void init(Attributes pAttribs, SAXSession pSession) {
93  		this.iCIMInstPath = null;
94  		this.iCIMInstance = null;
95  		// no attribute
96  	}
97  
98  	/**
99  	 * @param pData
100 	 */
101 	@Override
102 	public void parseData(String pData) {
103 		// no data
104 	}
105 
106 	@Override
107 	public void testChild(String pNodeNameEnum) throws SAXException {
108 		if (pNodeNameEnum == INSTANCENAME) {
109 			if (this.iCIMInstPath != null) throw new SAXException(
110 				"VALUE.NAMEDINSTANCE node can have only one INSTANCENAME node, but another one was found!"
111 			);
112 		} else if (pNodeNameEnum == INSTANCE) {
113 			if (this.iCIMInstance != null) throw new SAXException(
114 				"VALUE.NAMEDINSTANCE node can have only one INSTANCE node, but another one was found!"
115 			);
116 		} else {
117 			throw new SAXException("VALUE.NAMEDINSTANCE node cannot have " + pNodeNameEnum + " child node!");
118 		}
119 	}
120 
121 	@Override
122 	public void childParsed(Node pChild) {
123 		if (pChild instanceof InstanceNameNode) {
124 			this.iCIMInstPath = ((InstanceNameNode) pChild).getCIMObjectPath();
125 		} else {
126 			this.iCIMInstance = ((InstanceNode) pChild).getCIMInstance();
127 		}
128 	}
129 
130 	@Override
131 	public void testCompletness() throws SAXException {
132 		if (this.iCIMInstPath == null) throw new SAXException(
133 			"VALUE.NAMEDINSTANCE node must have an INSTANCENAME child node!"
134 		);
135 		if (this.iCIMInstance == null) throw new SAXException("VALUE.NAMEDINSTANCE node must have an INSTANCE child node!");
136 	}
137 
138 	/**
139 	 * @see ValueIf#getValue()
140 	 * @return CIMInstance
141 	 */
142 	public Object getValue() {
143 		// CIMObjectPath op=iInstanceNameNode.getCIMObjectPath();
144 		/*
145 		 * INSTANCENAME contains the key properties only, INSTANCE contains the
146 		 * non-key properties too.
147 		 */
148 		if (
149 			WBEMConfiguration.getGlobalConfiguration().synchronizeNumericKeyDataTypes()
150 		) return CIMHelper.CIMInstanceWithSynchonizedNumericKeyDataTypes(
151 			this.iCIMInstPath,
152 			this.iCIMInstance.getProperties()
153 		);
154 		return new CIMInstance(this.iCIMInstPath, this.iCIMInstance.getProperties());
155 	}
156 
157 	public CIMDataType getType() {
158 		return CIMDataType.OBJECT_T;
159 	}
160 }