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