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   * 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   * 3511454    2012-03-27  blaschke-oss SAX nodes not reinitialized properly
22   *    2604    2013-07-01  blaschke-oss SAXException messages should contain node name
23   *    2708    2013-11-12  blaschke-oss CIMNode quietly ignores DECLARATION child
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   * <pre>
54   * ELEMENT CIM (MESSAGE | DECLARATION)
55   * ATTLIST CIM
56   * 	CIMVERSION CDATA #REQUIRED
57   * DTDVERSION CDATA #REQUIRED
58   * </pre>
59   */
60  public class CIMNode extends Node implements NonVolatileIf {
61  
62  	/**
63  	 * Ctor.
64  	 */
65  	public CIMNode() {
66  		super(CIM);
67  	}
68  
69  	private Node iContent;
70  
71  	private String iCimVersion, iDtdVersion;
72  
73  	public void addChild(Node pChild) {
74  		this.iContent = pChild;
75  	}
76  
77  	/**
78  	 * @param pSession
79  	 */
80  	@Override
81  	public void init(Attributes pAttribs, SAXSession pSession) throws SAXException {
82  		this.iCimVersion = pAttribs.getValue("CIMVERSION");
83  		if (this.iCimVersion == null) {
84  			throw new SAXException("CIMVERSION attribute is mandatory for " + getNodeName() + " node!");
85  		}
86  		this.iDtdVersion = pAttribs.getValue("DTDVERSION");
87  		if (this.iDtdVersion == null) {
88  			throw new SAXException("DTDVERSION attribute is mandatory for " + getNodeName() + " node!");
89  		}
90  		this.iContent = null;
91  	}
92  
93  	/**
94  	 * @param pData
95  	 */
96  	@Override
97  	public void parseData(String pData) {
98  		return;
99  	}
100 
101 	@Override
102 	public void testChild(String pNodeNameEnum) throws SAXException {
103 		if (this.iContent != null) {
104 			String msg = "CIM node also has a " + this.iContent.getNodeName() + " child node!";
105 			throw new SAXException(msg);
106 		}
107 		if (pNodeNameEnum == MESSAGE) return;
108 		String msg = (pNodeNameEnum == DECLARATION)
109 			? "DECLARATION child node not supported by CIM node!"
110 			: pNodeNameEnum + " cannot be a child node of CIM node!";
111 		throw new SAXException(msg);
112 	}
113 
114 	@Override
115 	public void testCompletness() throws SAXException {
116 		if (this.iContent == null) throw new SAXException("CIM node must have a MESSAGE or a DECLARATION child!");
117 	}
118 
119 	/**
120 	 * @param pChild
121 	 */
122 	@Override
123 	public void childParsed(Node pChild) {
124 		// nothing to do here
125 	}
126 
127 	/**
128 	 * getCimVersion
129 	 *
130 	 * @return String
131 	 */
132 	public String getCimVersion() {
133 		return this.iCimVersion;
134 	}
135 
136 	/**
137 	 * getDtdVersion
138 	 *
139 	 * @return String
140 	 */
141 	public String getDtdVersion() {
142 		return this.iDtdVersion;
143 	}
144 
145 	/**
146 	 * getMessageNode
147 	 *
148 	 * @return MessageNode or null
149 	 */
150 	public MessageNode getMessageNode() {
151 		return (this.iContent instanceof MessageNode) ? (MessageNode) this.iContent : null;
152 	}
153 	// not implemented yet
154 	// public DeclarationNode getDeclarationNode() {}
155 
156 }