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   * 3521119    2012-04-24  blaschke-oss JSR48 1.0.0: remove CIMObjectPath 2/3/4-parm ctors
24   *    2711    2013-11-13  blaschke-oss LOCALNAMESPACEPATH allows 0 NAMESPACE children
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.sax.SAXSession;
51  import org.metricshub.wbem.sblim.cimclient.internal.util.WBEMConfiguration;
52  import org.xml.sax.Attributes;
53  import org.xml.sax.SAXException;
54  
55  /**
56   * ELEMENT LOCALNAMESPACEPATH (NAMESPACE+)
57   */
58  public class LocalNameSpacePathNode extends AbstractPathNode {
59  	private StringBuffer iNameSpaceStrBuf;
60  
61  	private String iNameSpaceStr;
62  
63  	private CIMObjectPath iNameSpacePath;
64  
65  	private CIMObjectPath iLocalPath;
66  
67  	/**
68  	 * Ctor.
69  	 */
70  	public LocalNameSpacePathNode() {
71  		super(LOCALNAMESPACEPATH);
72  	}
73  
74  	/**
75  	 * @param pAttribs
76  	 */
77  	@Override
78  	public void init(Attributes pAttribs, SAXSession pSession) {
79  		this.iLocalPath = pSession.getDefLocalPath();
80  		this.iNameSpaceStrBuf = null;
81  		this.iNameSpaceStr = null;
82  		this.iNameSpacePath = null;
83  		// no attributes
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 != NAMESPACE) throw new SAXException(
97  			getNodeName() + " node can have NAMESPACE child node only! " + pNodeNameEnum + " child node is invalid!"
98  		);
99  	}
100 
101 	@Override
102 	public void childParsed(Node pChild) {
103 		String nsStr = ((NameSpaceNode) pChild).getNameSpace();
104 		if (this.iNameSpaceStrBuf == null) {
105 			this.iNameSpaceStrBuf = new StringBuffer(nsStr);
106 		} else {
107 			this.iNameSpaceStrBuf.append('/' + nsStr);
108 		}
109 	}
110 
111 	@Override
112 	public void testCompletness() throws SAXException {
113 		if (this.iNameSpaceStrBuf == null) {
114 			if (
115 				WBEMConfiguration.getGlobalConfiguration().allowEmptyLocalNameSpacePath() &&
116 				this.iLocalPath != null &&
117 				this.iLocalPath.getNamespace() != null
118 			) return;
119 			throw new SAXException(getNodeName() + " node must have at least one NAMESPACE child node!");
120 		}
121 	}
122 
123 	/**
124 	 * getNameSpace
125 	 *
126 	 * @return String
127 	 */
128 	public String getNameSpace() {
129 		if (this.iNameSpaceStr != null) return this.iNameSpaceStr;
130 		return (
131 			this.iNameSpaceStr =
132 				(this.iNameSpaceStrBuf == null ? this.iLocalPath.getNamespace() : this.iNameSpaceStrBuf.toString())
133 		);
134 	}
135 
136 	public CIMObjectPath getCIMObjectPath() {
137 		if (this.iNameSpacePath != null) return this.iNameSpacePath;
138 		return this.iNameSpacePath = new CIMObjectPath(null, null, null, getNameSpace(), null, null);
139 	}
140 }