View Javadoc
1   /*
2     (C) Copyright IBM Corp. 2006, 2012
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   * 1742873    2007-06-25  ebak         IPv6 ready cim-client
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   * 3511454    2012-03-27  blaschke-oss SAX nodes not reinitialized properly
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.CIMObjectPath;
49  import org.metricshub.wbem.javax.cim.CIMProperty;
50  import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession;
51  import org.metricshub.wbem.sblim.cimclient.internal.util.XMLHostStr;
52  import org.xml.sax.Attributes;
53  import org.xml.sax.SAXException;
54  
55  /**
56   * ELEMENT INSTANCEPATH (NAMESPACEPATH, INSTANCENAME)
57   */
58  public class InstancePathNode extends AbstractObjectPathNode {
59  	// INSTANCEPATH
60  	private boolean iHasInstancePath;
61  
62  	private String iLocalNameSpacePathStr;
63  
64  	private XMLHostStr iHostStr;
65  
66  	// INSTANCENAME
67  	private boolean iHasInstanceName;
68  
69  	private String iClassNameStr;
70  
71  	private CIMProperty<?>[] iKeys;
72  
73  	/**
74  	 * Ctor.
75  	 */
76  	public InstancePathNode() {
77  		super(INSTANCEPATH);
78  	}
79  
80  	/**
81  	 * @param pAttribs
82  	 * @param pSession
83  	 */
84  	@Override
85  	public void init(Attributes pAttribs, SAXSession pSession) {
86  		this.iHasInstanceName = this.iHasInstancePath = false;
87  		this.iLocalNameSpacePathStr = this.iClassNameStr = null;
88  		this.iHostStr = new XMLHostStr();
89  		this.iKeys = null;
90  	}
91  
92  	@Override
93  	public void testChild(String pNodeNameEnum) throws SAXException {
94  		if (pNodeNameEnum == NAMESPACEPATH) {
95  			if (this.iHasInstancePath) throw new SAXException(
96  				"INSTANCEPATH node can have only one NAMESPACEPATH child node!"
97  			);
98  		} else if (pNodeNameEnum == INSTANCENAME) {
99  			if (this.iHasInstanceName) throw new SAXException("INSTANCEPATH node can have only one INSTANCENAME child node!");
100 		} else throw new SAXException("INSTANCEPATH node cannot have " + pNodeNameEnum + " child node!");
101 	}
102 
103 	/**
104 	 * @param pData
105 	 */
106 	@Override
107 	public void parseData(String pData) {
108 		// no data
109 	}
110 
111 	@Override
112 	public void childParsed(Node pChild) {
113 		if (pChild instanceof NameSpacePathNode) {
114 			NameSpacePathNode nsPathNode = (NameSpacePathNode) pChild;
115 			this.iHostStr.set(nsPathNode.getHostStr());
116 			this.iLocalNameSpacePathStr = nsPathNode.getLocalNameSpacePath();
117 			this.iHasInstancePath = true;
118 		} else {
119 			InstanceNameNode instNameNode = (InstanceNameNode) pChild;
120 			this.iClassNameStr = instNameNode.getClassName();
121 			this.iKeys = instNameNode.getKeys();
122 			this.iHasInstanceName = true;
123 		}
124 	}
125 
126 	@Override
127 	public void testCompletness() throws SAXException {
128 		if (!this.iHasInstancePath) throw new SAXException("INSTANCEPATH node must have a NAMESPACEPATH child node!");
129 		if (!this.iHasInstanceName) throw new SAXException("INSTANCEPATH node must have an INSTANCENAME child node!");
130 	}
131 
132 	public CIMObjectPath getCIMObjectPath() {
133 		/*
134 		 * CIMObjectPath( String scheme, String host, String port, String
135 		 * namespace, String objectName, CIMProperty[] keys )
136 		 */
137 		return new CIMObjectPath(
138 			this.iHostStr.getProtocol(),
139 			this.iHostStr.getHost(),
140 			this.iHostStr.getPort(),
141 			this.iLocalNameSpacePathStr,
142 			this.iClassNameStr,
143 			this.iKeys
144 		);
145 	}
146 }