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   * 2003590    2008-06-30  blaschke-oss Change licensing from CPL to EPL
20   * 2524131    2009-01-21  raman_arora  Upgrade client to JDK 1.5 (Phase 1)
21   * 2531371    2009-02-10  raman_arora  Upgrade client to JDK 1.5 (Phase 2)
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.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 LOCALINSTANCEPATH (LOCALNAMESPACEPATH, INSTANCENAME)
57   */
58  public class LocalInstancePathNode extends AbstractObjectPathNode {
59  	// LOCALNAMESPACEPATH
60  	private boolean iHasLocalNameSpacePath;
61  
62  	private String iNameSpaceStr;
63  
64  	// INSTANCENAME
65  	private boolean iHasInstanceName;
66  
67  	private String iClassNameStr;
68  
69  	private CIMProperty<?>[] iKeys;
70  
71  	// base localpath
72  	private CIMObjectPath iLocalPath;
73  
74  	/**
75  	 * Ctor.
76  	 */
77  	public LocalInstancePathNode() {
78  		super(LOCALINSTANCEPATH);
79  	}
80  
81  	/**
82  	 * @param pAttribs
83  	 */
84  	@Override
85  	public void init(Attributes pAttribs, SAXSession pSession) {
86  		this.iLocalPath = pSession.getDefLocalPath();
87  		this.iHasLocalNameSpacePath = this.iHasInstanceName = false;
88  		this.iNameSpaceStr = this.iClassNameStr = null;
89  		this.iKeys = null;
90  		// no attributes
91  	}
92  
93  	/**
94  	 * @param pData
95  	 */
96  	@Override
97  	public void parseData(String pData) {
98  		// no data
99  	}
100 
101 	@Override
102 	public void testChild(String pNodeNameEnum) throws SAXException {
103 		if (pNodeNameEnum == LOCALNAMESPACEPATH) {
104 			if (this.iHasLocalNameSpacePath) throw new SAXException(
105 				getNodeName() + " node can have only one LOCALNAMESPACEPATH child node!"
106 			);
107 		} else if (pNodeNameEnum == INSTANCENAME) {
108 			if (this.iHasInstanceName) throw new SAXException(
109 				getNodeName() + " node can have only one INSTANCENAME child node!"
110 			);
111 		} else throw new SAXException(getNodeName() + " node cannot have " + pNodeNameEnum + " child node!");
112 	}
113 
114 	@Override
115 	public void childParsed(Node pChild) {
116 		if (pChild instanceof LocalNameSpacePathNode) {
117 			this.iHasLocalNameSpacePath = true;
118 			this.iNameSpaceStr = ((LocalNameSpacePathNode) pChild).getNameSpace();
119 		} else {
120 			this.iHasInstanceName = true;
121 			InstanceNameNode instNameNode = (InstanceNameNode) pChild;
122 			this.iClassNameStr = instNameNode.getClassName();
123 			this.iKeys = instNameNode.getKeys();
124 		}
125 	}
126 
127 	@Override
128 	public void testCompletness() throws SAXException {
129 		if (!this.iHasLocalNameSpacePath) throw new SAXException(
130 			getNodeName() + " node must have a LOCALNAMESPACEPATH child node!"
131 		);
132 		if (!this.iHasInstanceName) throw new SAXException(getNodeName() + " node must have a INSTANCENAME child node!");
133 	}
134 
135 	public CIMObjectPath getCIMObjectPath() {
136 		// CIMObjectPath(String objectName, String namespace, CIMProperty[]
137 		// keys)
138 		return LocalPathBuilder.build(this.iLocalPath, this.iClassNameStr, this.iNameSpaceStr, this.iKeys);
139 	}
140 }