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   * 3511454    2012-03-27  blaschke-oss SAX nodes not reinitialized properly
22   */
23  
24  package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node;
25  
26  /*-
27   * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
28   * WBEM Java Client
29   * ჻჻჻჻჻჻
30   * Copyright 2023 - 2025 MetricsHub
31   * ჻჻჻჻჻჻
32   * Licensed under the Apache License, Version 2.0 (the "License");
33   * you may not use this file except in compliance with the License.
34   * You may obtain a copy of the License at
35   *
36   *      http://www.apache.org/licenses/LICENSE-2.0
37   *
38   * Unless required by applicable law or agreed to in writing, software
39   * distributed under the License is distributed on an "AS IS" BASIS,
40   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
41   * See the License for the specific language governing permissions and
42   * limitations under the License.
43   * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
44   */
45  
46  import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession;
47  import org.xml.sax.Attributes;
48  import org.xml.sax.SAXException;
49  
50  /**
51   * <pre>
52   * ELEMENT MESSAGE (SIMPLEREQ | MULTIREQ | SIMPLERSP | MULTIRSP | SIMPLEEXPREQ | MULTIEXPREQ |
53   *    SIMPLEEXPRSP | MULTIEXPRSP)
54   * ATTLIST MESSAGE
55   *    ID CDATA #REQUIRED
56   *    PROTOCOLVERSION CDATA #REQUIRED
57   * </pre>
58   */
59  public class MessageNode extends Node implements NonVolatileIf {
60  	private String iID;
61  
62  	private String iProtocolVersion;
63  
64  	private AbstractMessageNode iAbstractMsgNode;
65  
66  	/**
67  	 * Ctor.
68  	 */
69  	public MessageNode() {
70  		super(MESSAGE);
71  	}
72  
73  	public void addChild(Node pChild) {
74  		this.iAbstractMsgNode = (AbstractMessageNode) pChild;
75  	}
76  
77  	/**
78  	 * @param pSession
79  	 */
80  	@Override
81  	public void init(Attributes pAttribs, SAXSession pSession) throws SAXException {
82  		this.iID = pAttribs.getValue("ID");
83  		if (this.iID == null) throw new SAXException("ID attribute is mandatory for MESSAGE node!");
84  		this.iProtocolVersion = pAttribs.getValue("PROTOCOLVERSION");
85  		if (this.iProtocolVersion == null) throw new SAXException(
86  			"PROTOCOLVERSION attribute is mandatory for MESSAGE node!"
87  		);
88  		this.iAbstractMsgNode = null;
89  	}
90  
91  	/**
92  	 * @param pData
93  	 */
94  	@Override
95  	public void parseData(String pData) {
96  		// no data
97  	}
98  
99  	private static final String[] ALLOWED_CHILDREN = {
100 		SIMPLEREQ,
101 		MULTIREQ,
102 		SIMPLERSP,
103 		MULTIRSP,
104 		SIMPLEEXPREQ,
105 		MULTIEXPREQ,
106 		SIMPLEEXPRSP,
107 		MULTIEXPRSP
108 	};
109 
110 	@Override
111 	public void testChild(String pNodeNameEnum) throws SAXException {
112 		if (this.iAbstractMsgNode != null) throw new SAXException("MESSAGE node can have only one child node!");
113 		for (int i = 0; i < ALLOWED_CHILDREN.length; i++) if (pNodeNameEnum == ALLOWED_CHILDREN[i]) return;
114 		throw new SAXException("MESSAGE node cannot have " + pNodeNameEnum + " child node!");
115 	}
116 
117 	/**
118 	 * @param pChild
119 	 */
120 	@Override
121 	public void childParsed(Node pChild) {
122 		// nothing to do
123 	}
124 
125 	@Override
126 	public void testCompletness() throws SAXException {
127 		if (this.iAbstractMsgNode == null) throw new SAXException("MESSAGE node must have a child node!");
128 	}
129 
130 	/**
131 	 * getAbstractMessageNode
132 	 *
133 	 * @return AbstractMessageNode
134 	 */
135 	public AbstractMessageNode getAbstractMessageNode() {
136 		return this.iAbstractMsgNode;
137 	}
138 }