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   * 1689085    2007-04-10  ebak         Embedded object enhancements for Pegasus
19   * 1714878    2007-05-08  ebak         Empty string property values are parsed as nulls
20   * 1720707    2007-05-17  ebak         Conventional Node factory for CIM-XML SAX parser
21   * 2003590    2008-06-30  blaschke-oss Change licensing from CPL to EPL
22   * 2524131    2009-01-21  raman_arora  Upgrade client to JDK 1.5 (Phase 1)
23   * 2797550    2009-06-01  raman_arora  JSR48 compliance - add Java Generics
24   *    2701    2013-11-07  blaschke-oss PROPERTY.ARRAY does not require TYPE attribute
25   */
26  
27  package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node;
28  
29  /*-
30   * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
31   * WBEM Java Client
32   * ჻჻჻჻჻჻
33   * Copyright 2023 - 2025 MetricsHub
34   * ჻჻჻჻჻჻
35   * Licensed under the Apache License, Version 2.0 (the "License");
36   * you may not use this file except in compliance with the License.
37   * You may obtain a copy of the License at
38   *
39   *      http://www.apache.org/licenses/LICENSE-2.0
40   *
41   * Unless required by applicable law or agreed to in writing, software
42   * distributed under the License is distributed on an "AS IS" BASIS,
43   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
44   * See the License for the specific language governing permissions and
45   * limitations under the License.
46   * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
47   */
48  
49  import org.metricshub.wbem.javax.cim.CIMDataType;
50  import org.metricshub.wbem.javax.cim.CIMQualifier;
51  import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.EmbObjHandler;
52  import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession;
53  import org.xml.sax.Attributes;
54  import org.xml.sax.SAXException;
55  
56  /**
57   * <pre>
58   * ELEMENT PROPERTY.ARRAY (QUALIFIER*, VALUE.ARRAY?)
59   * ATTLIST PROPERTY.ARRAY
60   *   %CIMName;
61   *   %CIMType;              #REQUIRED
62   *   %ArraySize;
63   *   %ClassOrigin;
64   *   %Propagated;
65   *   %EmbeddedObject;    	#IMPLIED - new
66   *   xml:lang   NMTOKEN     #IMPLIED
67   * </pre>
68   */
69  public class PropertyArrayNode extends AbstractPropertyNode {
70  	// VALUE.ARRAY
71  	// required for super.testChild()
72  	private boolean iHasValueArray;
73  
74  	private boolean iHasTypeAttribute;
75  
76  	private CIMDataType iType;
77  
78  	private Object iValue;
79  
80  	private EmbObjHandler iEmbObjHandler;
81  
82  	/**
83  	 * Ctor.
84  	 */
85  	public PropertyArrayNode() {
86  		super(PROPERTY_ARRAY);
87  	}
88  
89  	@Override
90  	protected void specificInit(Attributes pAttribs, SAXSession pSession) throws SAXException {
91  		this.iHasTypeAttribute = (getCIMType(pAttribs, true) != null);
92  		this.iEmbObjHandler =
93  			EmbObjHandler.init(this.iEmbObjHandler, getNodeName(), pAttribs, pSession, this.iQualiHandler, true);
94  		this.iHasValueArray = false;
95  	}
96  
97  	@Override
98  	protected void childValueNodeParsed(Node pChild) throws SAXException {
99  		if (!this.iHasTypeAttribute && ((ValueArrayNode) pChild).getType() == null) throw new SAXException(
100 			"PROPERTY.ARRAY element missing TYPE attribute!"
101 		);
102 		this.iEmbObjHandler.addValueNode((ValueArrayNode) pChild);
103 		this.iHasValueArray = true;
104 	}
105 
106 	@Override
107 	public void testCompletness() throws SAXException {
108 		/*
109 		 * Value and type conversion are placed here. It can throw Exception.
110 		 */
111 		this.iType = this.iEmbObjHandler.getArrayType();
112 		this.iValue = this.iEmbObjHandler.getValue();
113 	}
114 
115 	public CIMDataType getType() {
116 		return this.iType;
117 	}
118 
119 	@Override
120 	protected String getChildValueNodeNameEnum() {
121 		return VALUE_ARRAY;
122 	}
123 
124 	public Object getValue() {
125 		// if iHasValueArray is false iObjA is null, since nulled in init()
126 		return this.iValue;
127 	}
128 
129 	@Override
130 	protected boolean hasValueNode() {
131 		return this.iHasValueArray;
132 	}
133 
134 	@Override
135 	protected CIMQualifier<?>[] getQualis() {
136 		return this.iQualiHandler.getQualis(this.iType == CIMDataType.STRING_ARRAY_T);
137 	}
138 }