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   * 1686000    2007-04-20  ebak         modifyInstance() missing from WBEMClient
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   *    2682    2013-10-02  blaschke-oss (I)MethodCallNode allows no LOCAL*PATH
25   *    2690    2013-10-11  blaschke-oss Remove RESPONSEDESTINATION support
26   */
27  
28  package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node;
29  
30  /*-
31   * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
32   * WBEM Java Client
33   * ჻჻჻჻჻჻
34   * Copyright 2023 - 2025 MetricsHub
35   * ჻჻჻჻჻჻
36   * Licensed under the Apache License, Version 2.0 (the "License");
37   * you may not use this file except in compliance with the License.
38   * You may obtain a copy of the License at
39   *
40   *      http://www.apache.org/licenses/LICENSE-2.0
41   *
42   * Unless required by applicable law or agreed to in writing, software
43   * distributed under the License is distributed on an "AS IS" BASIS,
44   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
45   * See the License for the specific language governing permissions and
46   * limitations under the License.
47   * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
48   */
49  
50  import java.util.ArrayList;
51  import org.metricshub.wbem.javax.cim.CIMArgument;
52  import org.metricshub.wbem.javax.cim.CIMObjectPath;
53  import org.metricshub.wbem.sblim.cimclient.internal.cim.CIMElementSorter;
54  import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession;
55  import org.xml.sax.Attributes;
56  import org.xml.sax.SAXException;
57  
58  /**
59   * <pre>
60   * ELEMENT IMETHODCALL (LOCALNAMESPACEPATH, IPARAMVALUE*)
61   * ATTLIST IMETHODCALL
62   *   %CIMName;
63   *
64   * ELEMENT METHODCALL ((LOCALINSTANCEPATH | LOCALCLASSPATH), PARAMVALUE*)
65   * ATTLIST METHODCALL
66   *   %CIMName;
67   * </pre>
68   */
69  public abstract class AbstractMethodCallNode extends Node implements NonVolatileIf, ObjectPathIf {
70  	private String iName;
71  
72  	protected CIMObjectPath iPath;
73  
74  	/**
75  	 * (IPARAMVALUE | PARAMVALUE)* -> ArrayList of CIMArgument
76  	 */
77  	private ArrayList<CIMArgument<?>> iArgAL;
78  
79  	/**
80  	 * Sorted array of CIMArguments
81  	 */
82  	private CIMArgument<?>[] iArgA;
83  
84  	/**
85  	 * Ctor.
86  	 *
87  	 * @param pNameEnum
88  	 */
89  	public AbstractMethodCallNode(String pNameEnum) {
90  		super(pNameEnum);
91  	}
92  
93  	/**
94  	 * @param pSession
95  	 */
96  	@Override
97  	public void init(Attributes pAttribs, SAXSession pSession) throws SAXException {
98  		this.iName = getCIMName(pAttribs);
99  		this.iPath = null;
100 		this.iArgAL = null;
101 		this.iArgA = null;
102 	}
103 
104 	/**
105 	 * @param pChild
106 	 */
107 	public void addChild(Node pChild) {
108 		// nothing to do
109 	}
110 
111 	@Override
112 	public void childParsed(Node pChild) {
113 		if (pChild instanceof AbstractPathNode) {
114 			this.iPath = ((AbstractPathNode) pChild).getCIMObjectPath();
115 		} else if (pChild instanceof AbstractParamValueNode) {
116 			if (this.iArgAL == null) this.iArgAL = new ArrayList<CIMArgument<?>>();
117 			this.iArgAL.add(((AbstractParamValueNode) pChild).getCIMArgument());
118 		}
119 	}
120 
121 	/**
122 	 * @param pData
123 	 */
124 	@Override
125 	public void parseData(String pData) {
126 		// no data
127 	}
128 
129 	protected abstract void testSpecChild(String pNodeNameEnum) throws SAXException;
130 
131 	@Override
132 	public void testChild(String pNodeNameEnum) throws SAXException {
133 		testSpecChild(pNodeNameEnum);
134 	}
135 
136 	/**
137 	 * getName
138 	 *
139 	 * @return String, name of the called method
140 	 */
141 	public String getName() {
142 		return this.iName;
143 	}
144 
145 	public CIMObjectPath getCIMObjectPath() {
146 		return this.iPath;
147 	}
148 
149 	private static final CIMArgument<?>[] EMPTY_ARG_A = new CIMArgument[0];
150 
151 	/**
152 	 * getCIMArguments
153 	 *
154 	 * @return CIMArgument[]
155 	 */
156 	public CIMArgument<?>[] getCIMArguments() {
157 		if (this.iArgA != null) return this.iArgA;
158 		this.iArgA = this.iArgAL == null ? null : (CIMArgument[]) this.iArgAL.toArray(EMPTY_ARG_A);
159 		return (CIMArgument[]) CIMElementSorter.sort(this.iArgA);
160 	}
161 
162 	/**
163 	 * getArgumentCount
164 	 *
165 	 * @return int
166 	 */
167 	public int getArgumentCount() {
168 		getCIMArguments();
169 		return this.iArgA == null ? 0 : this.iArgA.length;
170 	}
171 
172 	/**
173 	 * getArgument
174 	 *
175 	 * @param pName
176 	 * @return CIMArgument
177 	 */
178 	public CIMArgument<?> getArgument(String pName) {
179 		getCIMArguments();
180 		return (CIMArgument<?>) CIMElementSorter.find(this.iArgA, pName);
181 	}
182 
183 	/**
184 	 * getArgument
185 	 *
186 	 * @param pIdx
187 	 * @return CIMArgument
188 	 */
189 	public CIMArgument<?> getArgument(int pIdx) {
190 		getCIMArguments();
191 		return this.iArgA == null ? null : this.iArgA[pIdx];
192 	}
193 
194 	@Override
195 	public String toString() {
196 		StringBuffer buf = new StringBuffer("Name: " + getName() + "\nPath: " + getCIMObjectPath() + "\nParamValues:\n");
197 		for (int i = 0; i < getArgumentCount(); i++) {
198 			buf.append("  " + getArgument(i) + "\n");
199 		}
200 		return buf.toString();
201 	}
202 }