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 * Change History
14 * Flag Date Prog Description
15 * -------------------------------------------------------------------------------
16 * 1565892 2006-10-06 ebak Make SBLIM client JSR48 compliant
17 * 1660756 2007-02-22 ebak Embedded object support
18 * 1737141 2007-06-18 ebak Sync up with JSR48 evolution
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 * 2750520 2009-04-10 blaschke-oss Code cleanup from empty statement et al
22 * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics
23 * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0
24 * 2944842 2010-02-08 blaschke-oss Missing thrown ArrayIndexOutOfBoundsException
25 * 3001333 2010-05-19 blaschke-oss CIMMethod class ignores propagated parameter
26 * 3400209 2011-08-31 blaschke-oss Highlighted Static Analysis (PMD) issues
27 * 3565581 2012-09-07 blaschke-oss TCK: remove unnecessary overriding methods
28 */
29
30 package org.metricshub.wbem.javax.cim;
31
32 /*-
33 * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
34 * WBEM Java Client
35 * ჻჻჻჻჻჻
36 * Copyright 2023 - 2025 MetricsHub
37 * ჻჻჻჻჻჻
38 * Licensed under the Apache License, Version 2.0 (the "License");
39 * you may not use this file except in compliance with the License.
40 * You may obtain a copy of the License at
41 *
42 * http://www.apache.org/licenses/LICENSE-2.0
43 *
44 * Unless required by applicable law or agreed to in writing, software
45 * distributed under the License is distributed on an "AS IS" BASIS,
46 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
47 * See the License for the specific language governing permissions and
48 * limitations under the License.
49 * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
50 */
51
52 import java.util.Arrays;
53 import org.metricshub.wbem.sblim.cimclient.internal.cim.CIMElementSorter;
54 import org.metricshub.wbem.sblim.cimclient.internal.cim.CIMQualifiedElementInterfaceImpl;
55 import org.metricshub.wbem.sblim.cimclient.internal.util.MOF;
56
57 //Sync'd against JSR48 1.0.0 javadoc (build 1.5.0_10) on Wed Jan 20 02:20:59 EST 2010
58 /**
59 * This class represents a CIM Method as defined by the Distributed Management
60 * Task Force (<a href=http://www.dmtf.org>DMTF</a>) CIM Infrastructure
61 * Specification (<a
62 * href=http://www.dmtf.org/standards/published_documents/DSP0004V2.3_final.pdf
63 * >DSP004</a>).
64 *
65 * @param <E>
66 * Type parameter.
67 */
68 public class CIMMethod<E> extends CIMTypedElement implements CIMQualifiedElementInterface {
69 private static final long serialVersionUID = -3920536802046705977L;
70
71 private CIMQualifiedElementInterfaceImpl iQualiImpl;
72
73 private CIMParameter<?>[] iParams;
74
75 private boolean iPropagated;
76
77 private String iOriginClass;
78
79 /**
80 * Constructs a <code>CIMMethod</code> object with the specified
81 * information.
82 *
83 * @param pName
84 * The name of the method.
85 * @param pType
86 * The data type of the method.
87 * @param pQualis
88 * The method qualifiers.
89 * @param pParams
90 * The array of parameters for this method.
91 * @param pPropagated
92 * Is this method propagated from the superclass.
93 * @param pOriginClass
94 * The class this method was defined or overridden in.
95 */
96 public CIMMethod(
97 String pName,
98 CIMDataType pType,
99 CIMQualifier<?>[] pQualis,
100 CIMParameter<?>[] pParams,
101 boolean pPropagated,
102 String pOriginClass
103 ) {
104 super(pName, pType);
105 this.iQualiImpl = new CIMQualifiedElementInterfaceImpl(pQualis, false, true);
106 this.iParams = (CIMParameter[]) CIMElementSorter.sort(pParams);
107 this.iPropagated = pPropagated;
108 this.iOriginClass = pOriginClass;
109 }
110
111 /**
112 * Compares this object against the specified object. The result is
113 * <code>true</code> if and only if the argument is not <code>null</code>
114 * and is a <code>CIMMethod</code> object that represents the same value as
115 * this object.
116 *
117 * @param pObj
118 * The object to compare.
119 * @return <code>true</code> if the objects are the same; <code>false</code>
120 * otherwise.
121 */
122 @Override
123 public boolean equals(Object pObj) {
124 if (!(pObj instanceof CIMMethod)) return false;
125 if (!super.equals(pObj)) return false;
126 CIMMethod<?> that = (CIMMethod<?>) pObj;
127 if (!this.iQualiImpl.equals(that.iQualiImpl)) return false;
128 if (this.iPropagated != that.iPropagated) return false;
129 return Arrays.equals(getParameters(), that.getParameters());
130 }
131
132 /**
133 * Returns a <code>CIMMethod</code> filtered as specified.
134 *
135 * @param pIncludeQualifiers
136 * If <code>true</code> all qualifiers are returned; otherwise no
137 * qualifiers.
138 * @param pIncludeClassOrigin
139 * If <code>true</code> the class origin is included; otherwise
140 * no class origin is present.
141 * @return A filtered <code>CIMMethod</code>.
142 */
143 public CIMMethod<E> filter(boolean pIncludeQualifiers, boolean pIncludeClassOrigin) {
144 return filter(pIncludeQualifiers, pIncludeClassOrigin, false);
145 }
146
147 /**
148 * Returns a <code>CIMMethod</code> filtered as specified.
149 *
150 * @param pIncludeQualifiers
151 * If <code>true</code> all qualifiers are returned; otherwise no
152 * qualifiers.
153 * @param pIncludeClassOrigin
154 * If <code>true</code> the class origin is included; otherwise
155 * no class origin is present
156 * @param pLocalOnly
157 * If <code>true</code> only the qualifiers defined on this class
158 * are included; otherwise all qualifiers are included.
159 *
160 * @return A filtered <code>CIMMethod</code>.
161 */
162 public CIMMethod<E> filter(boolean pIncludeQualifiers, boolean pIncludeClassOrigin, boolean pLocalOnly) {
163 return new CIMMethod<E>(
164 getName(),
165 getDataType(),
166 pIncludeQualifiers ? this.iQualiImpl.getQualifiers(pLocalOnly) : null,
167 this.iParams,
168 this.iPropagated,
169 pIncludeClassOrigin ? this.iOriginClass : null
170 );
171 }
172
173 /**
174 * Returns the class name in which this method was defined or overridden.
175 *
176 * @return Name of class where this property was defined.
177 */
178 public String getOriginClass() {
179 return this.iOriginClass;
180 }
181
182 /**
183 * Get the parameter that matches the specified name.
184 *
185 * @param pName
186 * The name of the <code>CIMParameter</code> to retrieve.
187 * @return <code>CIMParameter</code> matching the name specified; otherwise
188 * <code>null</code>.
189 */
190 public CIMParameter<?> getParameter(String pName) {
191 return (CIMParameter<?>) CIMElementSorter.find(this.iParams, pName);
192 }
193
194 /**
195 * Returns an array of the parameters for this method.
196 *
197 * @return The parameters for this method.
198 */
199 public CIMParameter<?>[] getParameters() {
200 return this.iParams == null ? new CIMParameter[0] : this.iParams;
201 }
202
203 /**
204 * Get a qualifier by index.
205 *
206 * @param pIndex
207 * The index of the qualifier.
208 * @return The Qualifier at index <code>pIndex</code>.
209 * @throws ArrayIndexOutOfBoundsException
210 */
211 public CIMQualifier<?> getQualifier(int pIndex) throws ArrayIndexOutOfBoundsException {
212 return this.iQualiImpl.getQualifier(pIndex);
213 }
214
215 /**
216 * Gets a qualifier by name.
217 *
218 * @param pName
219 * The name of the qualifier to get.
220 * @return <code>null</code> if the qualifier does not exist, otherwise
221 * returns the reference to the qualifier.
222 */
223 public CIMQualifier<?> getQualifier(String pName) {
224 return this.iQualiImpl.getQualifier(pName);
225 }
226
227 /**
228 * Get the number of qualifiers defined for this CIM Method.
229 *
230 * @return The number of qualifiers.
231 */
232 public int getQualifierCount() {
233 return this.iQualiImpl.getQualifierCount();
234 }
235
236 /**
237 * Returns the list of qualifiers for this class.
238 *
239 * @return Qualifiers for this class.
240 */
241 public CIMQualifier<?>[] getQualifiers() {
242 return this.iQualiImpl.getQualifiers();
243 }
244
245 /**
246 * Gets a qualifier value by name.
247 *
248 * @param pName
249 * The name of the qualifier to get.
250 * @return <code>null</code> if the qualifier does not exist or value is
251 * <code>null</code>, otherwise returns the reference to the
252 * qualifier.
253 */
254 public Object getQualifierValue(String pName) {
255 return this.iQualiImpl.getQualifierValue(pName);
256 }
257
258 /**
259 * Checks whether the specified qualifier is one of the qualifiers in this
260 * CIM method.
261 *
262 * @param pName
263 * The name of the qualifier.
264 * @return <code>true</code> if the qualifier exists in this CIM method,
265 * otherwise <code>false</code>.
266 */
267 public boolean hasQualifier(String pName) {
268 return this.iQualiImpl.hasQualifier(pName);
269 }
270
271 /**
272 * Checks whether the specified qualifier is one of the qualifiers defined
273 * for this method with the specified value. This method will return
274 * <code>false</code> if the qualifier is not applied or if the value does
275 * not match.
276 *
277 * @param pName
278 * The name of the qualifier.
279 * @param pValue
280 * The value to be tested.
281 * @return <code>true</code> if the qualifier exists and has this value,
282 * otherwise false.
283 */
284 public boolean hasQualifierValue(String pName, Object pValue) {
285 return this.iQualiImpl.hasQualifierValue(pName, pValue);
286 }
287
288 /**
289 * Determines if this method is Propagated.
290 *
291 * @return <code>true</code> if this method is propagated.
292 */
293 public boolean isPropagated() {
294 return this.iPropagated;
295 }
296
297 /**
298 * Returns a <code>String</code> representation of the
299 * <code>CIMMethod</code>. This method is intended to be used only for
300 * debugging purposes, and the format of the returned string may vary
301 * between implementations. The returned string may be empty but may not be
302 * <code>null</code>.
303 *
304 * @return The string representation of this method.
305 */
306 @Override
307 public String toString() {
308 return MOF.methodDeclaration(this, MOF.EMPTY);
309 }
310 }