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   * 1848607    2007-12-11  ebak         Strict EmbeddedObject types
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   * 2763216    2009-04-14  blaschke-oss Code cleanup: visible spelling/grammar errors
24   * 2797550    2009-06-01  raman_arora  JSR48 compliance - add Java Generics
25   * 3602604    2013-01-29  blaschke-oss Clean up SAXException messages
26   *    2703    2013-11-08  blaschke-oss MethodNode should not require TYPE attribute
27   */
28  
29  package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node;
30  
31  /*-
32   * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
33   * WBEM Java Client
34   * ჻჻჻჻჻჻
35   * Copyright 2023 - 2025 MetricsHub
36   * ჻჻჻჻჻჻
37   * Licensed under the Apache License, Version 2.0 (the "License");
38   * you may not use this file except in compliance with the License.
39   * You may obtain a copy of the License at
40   *
41   *      http://www.apache.org/licenses/LICENSE-2.0
42   *
43   * Unless required by applicable law or agreed to in writing, software
44   * distributed under the License is distributed on an "AS IS" BASIS,
45   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
46   * See the License for the specific language governing permissions and
47   * limitations under the License.
48   * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
49   */
50  
51  import java.util.ArrayList;
52  import org.metricshub.wbem.javax.cim.CIMDataType;
53  import org.metricshub.wbem.javax.cim.CIMMethod;
54  import org.metricshub.wbem.javax.cim.CIMParameter;
55  import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.EmbObjHandler;
56  import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession;
57  import org.xml.sax.Attributes;
58  import org.xml.sax.SAXException;
59  
60  /**
61   * <pre>
62   *
63   * ELEMENT METHOD (QUALIFIER*, (PARAMETER | PARAMETER.REFERENCE | PARAMETER.ARRAY | PARAMETER.REFARRAY)*)
64   * ATTLIST METHOD
65   *   %CIMName;
66   *   %CIMType;              #IMPLIED
67   *   %ClassOrigin;
68   *   %Propagated;&gt;
69   * </pre>
70   */
71  public class MethodNode extends Node {
72  	private String iName;
73  
74  	private CIMDataType iType;
75  
76  	private String iClassOrigin;
77  
78  	private boolean iPropagated;
79  
80  	private QualifiedNodeHandler iQualiHandler;
81  
82  	private EmbObjHandler iEmbObjHandler;
83  
84  	private SAXSession iSession;
85  
86  	/**
87  	 * PARAMETER.XXX*, AbstractParameterNode*
88  	 */
89  	private ArrayList<CIMParameter<?>> iCIMParamAL;
90  
91  	/**
92  	 * Ctor.
93  	 */
94  	public MethodNode() {
95  		super(METHOD);
96  	}
97  
98  	@Override
99  	public void init(Attributes pAttribs, SAXSession pSession) throws SAXException {
100 		this.iSession = pSession;
101 		this.iQualiHandler = QualifiedNodeHandler.init(this.iQualiHandler);
102 		this.iEmbObjHandler =
103 			EmbObjHandler.init(this.iEmbObjHandler, getNodeName(), pAttribs, this.iSession, this.iQualiHandler, true);
104 
105 		if (this.iCIMParamAL != null) this.iCIMParamAL.clear();
106 
107 		this.iName = getCIMName(pAttribs);
108 
109 		this.iType = getCIMType(pAttribs, true);
110 		if (this.iType != null && this.iType.isArray()) throw new SAXException("METHOD node's TYPE cannot be an array!");
111 		this.iClassOrigin = getClassOrigin(pAttribs);
112 		this.iPropagated = getPropagated(pAttribs);
113 	}
114 
115 	/**
116 	 * @param pData
117 	 */
118 	@Override
119 	public void parseData(String pData) {
120 		// no data
121 	}
122 
123 	private static final String[] ALLOWED_CHILDREN = {
124 		QUALIFIER,
125 		PARAMETER,
126 		PARAMETER_REFERENCE,
127 		PARAMETER_ARRAY,
128 		PARAMETER_REFARRAY
129 	};
130 
131 	@Override
132 	public void testChild(String pNodeNameEnum) throws SAXException {
133 		for (int i = 0; i < ALLOWED_CHILDREN.length; i++) if (pNodeNameEnum.equalsIgnoreCase(ALLOWED_CHILDREN[i])) return;
134 		throw new SAXException(getNodeName() + " node cannot have " + pNodeNameEnum + " child node!");
135 	}
136 
137 	@Override
138 	public void childParsed(Node pChild) {
139 		if (this.iQualiHandler.addQualifierNode(pChild)) return;
140 		if (this.iCIMParamAL == null) this.iCIMParamAL = new ArrayList<CIMParameter<?>>();
141 		this.iCIMParamAL.add(((AbstractParameterNode) pChild).getCIMParameter());
142 	}
143 
144 	@Override
145 	public void testCompletness() throws SAXException {
146 		this.iType = this.iEmbObjHandler.getType();
147 		if (this.iType != null && this.iType.isArray()) throw new SAXException(
148 			"METHOD node's TYPE attribute cannot be an array!"
149 		);
150 	}
151 
152 	/**
153 	 * getCIMMethod
154 	 *
155 	 * @return CIMMethod
156 	 */
157 	public CIMMethod<?> getCIMMethod() {
158 		/*
159 		 * CIMMethod( String name, CIMDataType type, CIMQualifier[] qualifiers,
160 		 * CIMParameter[] parameters, boolean propagated, String originClass );
161 		 *
162 		 * EmbeddedObject qualifier mustn't be removed. Return type cannot be
163 		 * changed.
164 		 *
165 		 * The situation changed by the introduction of the strict embedded
166 		 * object type parsing.
167 		 */
168 		return new CIMMethod<Object>(
169 			this.iName,
170 			this.iType,
171 			this.iQualiHandler.getQualis(!this.iSession.strictEmbObjParsing()),
172 			this.iCIMParamAL == null ? null : (CIMParameter<?>[]) this.iCIMParamAL.toArray(EMPTY_PA),
173 			this.iPropagated,
174 			this.iClassOrigin
175 		);
176 	}
177 
178 	private static final CIMParameter<?>[] EMPTY_PA = new CIMParameter[0];
179 }