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   * 1686000    2007-04-20  ebak         modifyInstance() missing from WBEMClient
19   * 1720707    2007-05-17  ebak         Conventional Node factory for CIM-XML SAX parser
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   * 2531371    2009-02-10  raman_arora  Upgrade client to JDK 1.5 (Phase 2)
23   * 2974884    2010-04-20  blaschke-oss Exception when attaching 2 CDRoms with invoke method
24   * 3602604    2013-01-29  blaschke-oss Clean up SAXException messages
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.CIMObjectPath;
50  import org.metricshub.wbem.sblim.cimclient.internal.cimxml.LocalPathBuilder;
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 LOCALCLASSPATH (LOCALNAMESPACEPATH, CLASSNAME)
57   */
58  public class LocalClassPathNode extends AbstractObjectPathNode {
59  	// LOCALNAMESPACEPATH
60  	private boolean iHasLocalNameSpacePath, iHasClassName;
61  
62  	private String iNameSpaceStr;
63  
64  	// CLASSNAME
65  	private String iClassNameStr;
66  
67  	// ---
68  	private CIMObjectPath iLocalPath;
69  
70  	/**
71  	 * Ctor.
72  	 */
73  	public LocalClassPathNode() {
74  		super(LOCALCLASSPATH);
75  	}
76  
77  	/**
78  	 * @param pAttribs
79  	 */
80  	@Override
81  	public void init(Attributes pAttribs, SAXSession pSession) {
82  		this.iLocalPath = pSession.getDefLocalPath();
83  		this.iHasLocalNameSpacePath = this.iHasClassName = false;
84  		this.iNameSpaceStr = this.iClassNameStr = null;
85  		// no attributes
86  	}
87  
88  	/**
89  	 * @param pData
90  	 */
91  	@Override
92  	public void parseData(String pData) {
93  		// no data
94  	}
95  
96  	@Override
97  	public void testChild(String pNodeNameEnum) throws SAXException {
98  		if (pNodeNameEnum == LOCALNAMESPACEPATH) {
99  			if (this.iHasLocalNameSpacePath) throw new SAXException(
100 				"LOCALCLASSPATH node already has a LOCALNAMESPACEPATH child node!"
101 			);
102 		} else if (pNodeNameEnum == CLASSNAME) {
103 			if (this.iHasClassName) throw new SAXException("LOCALCLASSPATH node already has a CLASSNAME child node!");
104 		} else throw new SAXException(
105 			"LOCALCLASSPATH node cannot have " +
106 			pNodeNameEnum +
107 			" child node!" +
108 			" It can have LOCALNAMESPACEPATH and CLASSNAME child nodes only!"
109 		);
110 	}
111 
112 	@Override
113 	public void childParsed(Node pChild) {
114 		if (pChild instanceof LocalNameSpacePathNode) {
115 			this.iNameSpaceStr = ((LocalNameSpacePathNode) pChild).getNameSpace();
116 			this.iHasLocalNameSpacePath = true;
117 		} else {
118 			this.iClassNameStr = ((ClassNameNode) pChild).getClassName();
119 			this.iHasClassName = true;
120 		}
121 	}
122 
123 	@Override
124 	public void testCompletness() throws SAXException {
125 		if (!this.iHasLocalNameSpacePath) throw new SAXException(
126 			"LOCALNAMESPACE child node is mandatory for LOCALCLASSPATH node!"
127 		);
128 		if (!this.iHasClassName) throw new SAXException("CLASSNAME child node is mandatory for LOCALCLASSPATH node!");
129 	}
130 
131 	public CIMObjectPath getCIMObjectPath() {
132 		return LocalPathBuilder.build(this.iLocalPath, this.iClassNameStr, this.iNameSpaceStr);
133 	}
134 }