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   * 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   * 3511454    2012-03-27  blaschke-oss SAX nodes not reinitialized properly
23   * 3602604    2013-01-29  blaschke-oss Clean up SAXException messages
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.sblim.cimclient.internal.cimxml.sax.SAXSession;
50  import org.metricshub.wbem.sblim.cimclient.internal.util.XMLHostStr;
51  import org.xml.sax.Attributes;
52  import org.xml.sax.SAXException;
53  
54  /**
55   * ELEMENT CLASSPATH (NAMESPACEPATH, CLASSNAME)
56   */
57  public class ClassPathNode extends AbstractObjectPathNode {
58  	// child nodes:
59  	private boolean iHasNameSpacePath, iHasClassName;
60  
61  	private String iLocalNameSpacePathStr;
62  
63  	private XMLHostStr iHostStr;
64  
65  	private String iClassNameStr;
66  
67  	/**
68  	 * Ctor.
69  	 */
70  	public ClassPathNode() {
71  		super(CLASSPATH);
72  	}
73  
74  	/**
75  	 * @param pAttribs
76  	 * @param pSession
77  	 */
78  	@Override
79  	public void init(Attributes pAttribs, SAXSession pSession) {
80  		// reset
81  		this.iHasNameSpacePath = this.iHasClassName = false;
82  		this.iLocalNameSpacePathStr = this.iClassNameStr = null;
83  		this.iHostStr = new XMLHostStr();
84  	}
85  
86  	/**
87  	 * @param pData
88  	 */
89  	@Override
90  	public void parseData(String pData) {
91  		// no data
92  	}
93  
94  	@Override
95  	public void testChild(String pNodeNameEnum) throws SAXException {
96  		if (pNodeNameEnum == NAMESPACEPATH) {
97  			if (this.iHasNameSpacePath) throw new SAXException("CLASSPATH node already has a NAMESPACEPATH child node!");
98  		} else if (pNodeNameEnum == CLASSNAME) {
99  			if (this.iHasClassName) throw new SAXException("CLASSPATH node already has a CLASSNAME child node!");
100 		} else throw new SAXException(
101 			"CLASSPATH node cannot have " +
102 			pNodeNameEnum +
103 			" child node!" +
104 			" It can have NAMESPACEPATH and CLASSNAME child nodes only!"
105 		);
106 	}
107 
108 	@Override
109 	public void childParsed(Node pChild) {
110 		if (pChild instanceof NameSpacePathNode) {
111 			NameSpacePathNode nsPathNode = (NameSpacePathNode) pChild;
112 			this.iLocalNameSpacePathStr = nsPathNode.getLocalNameSpacePath();
113 			this.iHostStr.set(nsPathNode.getHostStr());
114 			this.iHasNameSpacePath = true;
115 		} else {
116 			this.iClassNameStr = ((ClassNameNode) pChild).getClassName();
117 			this.iHasClassName = true;
118 		}
119 	}
120 
121 	@Override
122 	public void testCompletness() throws SAXException {
123 		if (!this.iHasNameSpacePath) throw new SAXException("NAMESPACEPATH child node is mandatory for CLASSPATH node!");
124 		if (!this.iHasClassName) throw new SAXException("CLASSNAME child node is mandatory for CLASSPATH node!");
125 	}
126 
127 	public CIMObjectPath getCIMObjectPath() {
128 		/*
129 		 * CIMObjectPath( String scheme, String host, String port, String
130 		 * namespace, String objectName, CIMProperty[] keys )
131 		 */
132 		return new CIMObjectPath(
133 			this.iHostStr.getProtocol(),
134 			this.iHostStr.getHost(),
135 			this.iHostStr.getPort(),
136 			this.iLocalNameSpacePathStr,
137 			this.iClassNameStr,
138 			null
139 		);
140 	}
141 }