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   * 3511454    2012-03-27  blaschke-oss SAX nodes not reinitialized properly
23   * 3466280    2012-04-23  blaschke-oss get instance failure for CIM_IndicationSubscription
24   *    2604    2013-07-01  blaschke-oss SAXException messages should contain node name
25   */
26  
27  package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node;
28  
29  /*-
30   * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
31   * WBEM Java Client
32   * ჻჻჻჻჻჻
33   * Copyright 2023 - 2025 MetricsHub
34   * ჻჻჻჻჻჻
35   * Licensed under the Apache License, Version 2.0 (the "License");
36   * you may not use this file except in compliance with the License.
37   * You may obtain a copy of the License at
38   *
39   *      http://www.apache.org/licenses/LICENSE-2.0
40   *
41   * Unless required by applicable law or agreed to in writing, software
42   * distributed under the License is distributed on an "AS IS" BASIS,
43   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
44   * See the License for the specific language governing permissions and
45   * limitations under the License.
46   * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
47   */
48  
49  import org.metricshub.wbem.javax.cim.CIMDataType;
50  import org.metricshub.wbem.javax.cim.CIMObjectPath;
51  import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession;
52  import org.xml.sax.Attributes;
53  import org.xml.sax.SAXException;
54  
55  /**
56   * ELEMENT VALUE.REFERENCE (CLASSPATH | LOCALCLASSPATH | CLASSNAME |
57   * INSTANCEPATH | LOCALINSTANCEPATH | INSTANCENAME)
58   */
59  public class ValueReferenceNode extends AbstractScalarValueNode implements ObjectPathIf {
60  	private CIMObjectPath iCIMObjPath;
61  
62  	private String iChildNodeName = null;
63  
64  	/**
65  	 * Ctor.
66  	 */
67  	public ValueReferenceNode() {
68  		super(VALUE_REFERENCE);
69  	}
70  
71  	@Override
72  	public void childParsed(Node pChild) {
73  		this.iCIMObjPath = ((AbstractPathNode) pChild).getCIMObjectPath();
74  		if (
75  			(CLASSNAME.equalsIgnoreCase(this.iChildNodeName) || INSTANCENAME.equalsIgnoreCase(this.iChildNodeName)) &&
76  			this.iCIMObjPath.getNamespace() != null
77  		) {
78  			// LocalPathBuilder includes default namespace in CLASSNAME and
79  			// INSTANCENAME elements, needs to be stripped
80  			this.iCIMObjPath =
81  				new CIMObjectPath(
82  					this.iCIMObjPath.getScheme(),
83  					this.iCIMObjPath.getHost(),
84  					this.iCIMObjPath.getPort(),
85  					null,
86  					this.iCIMObjPath.getObjectName(),
87  					this.iCIMObjPath.getKeys(),
88  					this.iCIMObjPath.getXmlSchemaName()
89  				);
90  		}
91  	}
92  
93  	/**
94  	 * @param pAttribs
95  	 * @param pSession
96  	 */
97  	@Override
98  	public void init(Attributes pAttribs, SAXSession pSession) {
99  		this.iCIMObjPath = null;
100 		this.iChildNodeName = null;
101 		// no attributes
102 	}
103 
104 	/**
105 	 * @param pData
106 	 */
107 	@Override
108 	public void parseData(String pData) {
109 		// there is no data
110 	}
111 
112 	private static final String[] ALLOWED_CHILDREN = {
113 		CLASSPATH,
114 		LOCALCLASSPATH,
115 		CLASSNAME,
116 		INSTANCEPATH,
117 		LOCALINSTANCEPATH,
118 		INSTANCENAME
119 	};
120 
121 	@Override
122 	public void testChild(String pNodeNameEnum) throws SAXException {
123 		if (this.iCIMObjPath != null) throw new SAXException(
124 			"Child node " + pNodeNameEnum + " is illegal, since VALUE.REFERENCE already has a child!"
125 		);
126 		for (int i = 0; i < ALLOWED_CHILDREN.length; i++) if (ALLOWED_CHILDREN[i] == pNodeNameEnum) {
127 			this.iChildNodeName = pNodeNameEnum;
128 			return;
129 		}
130 		throw new SAXException(
131 			"Invalid child node in " +
132 			getNodeName() +
133 			" node: " +
134 			pNodeNameEnum +
135 			"! Valid nodes are CLASSPATH, LOCALCLASSPATH, CLASSNAME, " +
136 			"INSTANCEPATH, LOCALINSTANCEPATH, INSTANCENAME"
137 		);
138 	}
139 
140 	@Override
141 	public void testCompletness() throws SAXException {
142 		if (this.iCIMObjPath == null) throw new SAXException("VALUE.REFERENCE node must have a child node!");
143 	}
144 
145 	/**
146 	 * @see ValueIf#getValue()
147 	 * @return CIMObjectPath
148 	 */
149 	public Object getValue() {
150 		return this.iCIMObjPath;
151 	}
152 
153 	public CIMDataType getType() {
154 		return this.iCIMObjPath == null ? null : new CIMDataType(this.iCIMObjPath.getObjectName());
155 	}
156 
157 	public CIMObjectPath getCIMObjectPath() {
158 		return this.iCIMObjPath;
159 	}
160 }