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 * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2)
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.sblim.cimclient.internal.cimxml.sax.SAXSession;
49 import org.xml.sax.Attributes;
50 import org.xml.sax.SAXException;
51
52 /**
53 * ELEMENT NAMESPACEPATH (HOST, LOCALNAMESPACEPATH)
54 */
55 public class NameSpacePathNode extends Node {
56 // HOST
57 private boolean iHasHost;
58
59 private String iHostStr;
60
61 // LOCALNAMESPACEPATH
62 private boolean iHasLocalNameSpacePath;
63
64 private String iLocalNameSpacePathStr;
65
66 /**
67 * Ctor.
68 */
69 public NameSpacePathNode() {
70 super(NAMESPACEPATH);
71 }
72
73 /**
74 * @param pAttribs
75 * @param pSession
76 */
77 @Override
78 public void init(Attributes pAttribs, SAXSession pSession) {
79 this.iHasHost = this.iHasLocalNameSpacePath = false;
80 this.iHostStr = this.iLocalNameSpacePathStr = null;
81 // no attributes
82 }
83
84 /**
85 * @param pData
86 */
87 @Override
88 public void parseData(String pData) {
89 // no data
90 }
91
92 @Override
93 public void testChild(String pNodeNameEnum) throws SAXException {
94 if (pNodeNameEnum == HOST) {
95 if (this.iHasHost) throw new SAXException(getNodeName() + " node can have only one HOST child node!");
96 } else if (pNodeNameEnum == LOCALNAMESPACEPATH) {
97 if (this.iHasLocalNameSpacePath) throw new SAXException(
98 getNodeName() + " node can have only one LOCALNAMESPACEPATH child node!"
99 );
100 } else throw new SAXException(getNodeName() + " node cannot have " + pNodeNameEnum + " child node!");
101 }
102
103 @Override
104 public void childParsed(Node pChild) {
105 if (pChild instanceof HostNode) {
106 this.iHasHost = true;
107 this.iHostStr = ((HostNode) pChild).getHostStr();
108 } else {
109 this.iHasLocalNameSpacePath = true;
110 this.iLocalNameSpacePathStr = ((LocalNameSpacePathNode) pChild).getNameSpace();
111 }
112 }
113
114 @Override
115 public void testCompletness() throws SAXException {
116 if (!this.iHasHost) throw new SAXException("HOST child node is mandatory for " + getNodeName() + " node!");
117 if (!this.iHasLocalNameSpacePath) throw new SAXException(
118 "LOCALNAMESPACEPATH child node is mandatory for " + getNodeName() + " node!"
119 );
120 }
121
122 /**
123 * getHostStr
124 *
125 * @return String which may contain the protocol, host and port
126 */
127 public String getHostStr() {
128 return this.iHostStr;
129 }
130
131 /**
132 * getLocalNameSpacePath
133 *
134 * @return String
135 */
136 public String getLocalNameSpacePath() {
137 return this.iLocalNameSpacePathStr;
138 }
139 }