View Javadoc
1   /*
2     (C) Copyright IBM Corp. 2009, 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 : Ramandeep S Arora, IBM,  arorar@us.ibm.com
12   * 
13   * Flag       Date        Prog         Description
14   * -------------------------------------------------------------------------------
15   * 2845211    2009-08-27  raman_arora  Pull Enumeration Feature (SAX Parser)
16   * 3598613    2013-01-11  blaschke-oss different data type in cim instance and cim object path
17   */
18  
19  package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node;
20  
21  /*-
22   * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
23   * WBEM Java Client
24   * ჻჻჻჻჻჻
25   * Copyright 2023 - 2025 MetricsHub
26   * ჻჻჻჻჻჻
27   * Licensed under the Apache License, Version 2.0 (the "License");
28   * you may not use this file except in compliance with the License.
29   * You may obtain a copy of the License at
30   *
31   *      http://www.apache.org/licenses/LICENSE-2.0
32   *
33   * Unless required by applicable law or agreed to in writing, software
34   * distributed under the License is distributed on an "AS IS" BASIS,
35   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
36   * See the License for the specific language governing permissions and
37   * limitations under the License.
38   * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
39   */
40  
41  import org.metricshub.wbem.javax.cim.CIMDataType;
42  import org.metricshub.wbem.javax.cim.CIMInstance;
43  import org.metricshub.wbem.javax.cim.CIMObjectPath;
44  import org.metricshub.wbem.sblim.cimclient.internal.cim.CIMHelper;
45  import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession;
46  import org.metricshub.wbem.sblim.cimclient.internal.util.WBEMConfiguration;
47  import org.xml.sax.Attributes;
48  import org.xml.sax.SAXException;
49  
50  /**
51   * <pre>
52   * ELEMENT VALUE.INSTANCEWITHPATH (INSTANCEPATH, INSTANCE)
53   *
54   * ELEMENT INSTANCEPATH (NAMESPACEPATH,INSTANCENAME)
55   *
56   * ELEMENT INSTANCE (QUALIFIER*, (PROPERTY | PROPERTY.ARRAY | PROPERTY.REFERENCE)*)
57   * ATTLIST INSTANCE
58   *   %ClassName;
59   *   xml:lang   NMTOKEN      #IMPLIED
60   * </pre>
61   */
62  public class ValueInstanceWithPathNode extends AbstractScalarValueNode {
63  	// INSTANCEPATH
64  	private CIMObjectPath iCIMInstPath;
65  
66  	// INSTANCE
67  	private CIMInstance iCIMInstance;
68  
69  	/**
70  	 * Ctor.
71  	 */
72  	public ValueInstanceWithPathNode() {
73  		super(VALUE_INSTANCEWITHPATH);
74  	}
75  
76  	/**
77  	 * @param pAttribs
78  	 * @param pSession
79  	 */
80  	@Override
81  	public void init(Attributes pAttribs, SAXSession pSession) {
82  		// no attribute
83  		this.iCIMInstPath = null;
84  		this.iCIMInstance = null;
85  	}
86  
87  	/**
88  	 * @param pData
89  	 */
90  	@Override
91  	public void parseData(String pData) {
92  		// no data
93  	}
94  
95  	@Override
96  	public void testChild(String pNodeNameEnum) throws SAXException {
97  		if (pNodeNameEnum == INSTANCEPATH) {
98  			if (this.iCIMInstPath != null) throw new SAXException(
99  				"VALUE.INSTANCEWITHPATH node can have only one INSTANCEPATH node, but another one was found!"
100 			);
101 		} else if (pNodeNameEnum == INSTANCE) {
102 			if (this.iCIMInstance != null) throw new SAXException(
103 				"VALUE.INSTANCEWITHPATH node can have only one INSTANCE node, but another one was found!"
104 			);
105 		} else {
106 			throw new SAXException("VALUE.INSTANCEWITHPATH node cannot have " + pNodeNameEnum + " child node!");
107 		}
108 	}
109 
110 	@Override
111 	public void childParsed(Node pChild) {
112 		if (pChild instanceof InstancePathNode) {
113 			this.iCIMInstPath = ((InstancePathNode) pChild).getCIMObjectPath();
114 		} else {
115 			this.iCIMInstance = ((InstanceNode) pChild).getCIMInstance();
116 		}
117 	}
118 
119 	@Override
120 	public void testCompletness() throws SAXException {
121 		if (this.iCIMInstPath == null) throw new SAXException(
122 			"VALUE.INSTANCEWITHPATH node must have an INSTANCEPATH child node!"
123 		);
124 		if (this.iCIMInstance == null) throw new SAXException(
125 			"VALUE.INSTANCEWITHPATH node must have an INSTANCE child node!"
126 		);
127 	}
128 
129 	/**
130 	 * @see ValueIf#getValue()
131 	 * @return CIMInstance
132 	 */
133 	public Object getValue() {
134 		/*
135 		 * INSTANCENAME contains the key properties only, INSTANCE contains
136 		 * non-key properties too.
137 		 */
138 		if (
139 			WBEMConfiguration.getGlobalConfiguration().synchronizeNumericKeyDataTypes()
140 		) return CIMHelper.CIMInstanceWithSynchonizedNumericKeyDataTypes(
141 			this.iCIMInstPath,
142 			this.iCIMInstance.getProperties()
143 		);
144 		return new CIMInstance(this.iCIMInstPath, this.iCIMInstance.getProperties());
145 	}
146 
147 	public CIMDataType getType() {
148 		return CIMDataType.OBJECT_T;
149 	}
150 }