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.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node;
27  
28  /*-
29   * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
30   * WBEM Java Client
31   * ჻჻჻჻჻჻
32   * Copyright (C) 2023 Sentry Software
33   * ჻჻჻჻჻჻
34   * This program is free software: you can redistribute it and/or modify
35   * it under the terms of the GNU Lesser General Public License as
36   * published by the Free Software Foundation, either version 3 of the
37   * License, or (at your option) any later version.
38   *
39   * This program is distributed in the hope that it will be useful,
40   * but WITHOUT ANY WARRANTY; without even the implied warranty of
41   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
42   * GNU General Lesser Public License for more details.
43   *
44   * You should have received a copy of the GNU General Lesser Public
45   * License along with this program.  If not, see
46   * <http://www.gnu.org/licenses/lgpl-3.0.html>.
47   * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
48   */
49  
50  import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession;
51  import org.xml.sax.Attributes;
52  import org.xml.sax.SAXException;
53  
54  /**
55   * <pre>
56   * ELEMENT CIM (MESSAGE | DECLARATION)
57   * ATTLIST CIM
58   * 	CIMVERSION CDATA #REQUIRED
59   * DTDVERSION CDATA #REQUIRED
60   * </pre>
61   */
62  public class CIMNode extends Node implements NonVolatileIf {
63  
64  	/**
65  	 * Ctor.
66  	 */
67  	public CIMNode() {
68  		super(CIM);
69  	}
70  
71  	private Node iContent;
72  
73  	private String iCimVersion, iDtdVersion;
74  
75  	public void addChild(Node pChild) {
76  		this.iContent = pChild;
77  	}
78  
79  	/**
80  	 * @param pSession
81  	 */
82  	@Override
83  	public void init(Attributes pAttribs, SAXSession pSession) throws SAXException {
84  		this.iCimVersion = pAttribs.getValue("CIMVERSION");
85  		if (this.iCimVersion == null) { throw new SAXException(
86  				"CIMVERSION attribute is mandatory for " + getNodeName() + " node!"); }
87  		this.iDtdVersion = pAttribs.getValue("DTDVERSION");
88  		if (this.iDtdVersion == null) { throw new SAXException(
89  				"DTDVERSION attribute is mandatory for " + getNodeName() + " node!"); }
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) ? "DECLARATION child node not supported by CIM node!"
109 				: pNodeNameEnum + " cannot be a child node of CIM node!";
110 		throw new SAXException(msg);
111 	}
112 
113 	@Override
114 	public void testCompletness() throws SAXException {
115 		if (this.iContent == null) throw new SAXException(
116 				"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 
154 	// not implemented yet
155 	// public DeclarationNode getDeclarationNode() {}
156 
157 }