1 /*
2 (C) Copyright IBM Corp. 2006, 2009
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 null
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 * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics
24 */
25
26 package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node;
27
28 /*-
29 * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
30 * WBEM Java Client
31 * ჻჻჻჻჻჻
32 * Copyright 2023 - 2025 MetricsHub
33 * ჻჻჻჻჻჻
34 * Licensed under the Apache License, Version 2.0 (the "License");
35 * you may not use this file except in compliance with the License.
36 * You may obtain a copy of the License at
37 *
38 * http://www.apache.org/licenses/LICENSE-2.0
39 *
40 * Unless required by applicable law or agreed to in writing, software
41 * distributed under the License is distributed on an "AS IS" BASIS,
42 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
43 * See the License for the specific language governing permissions and
44 * limitations under the License.
45 * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
46 */
47
48 import org.metricshub.wbem.javax.cim.CIMClassProperty;
49 import org.metricshub.wbem.javax.cim.CIMProperty;
50 import org.metricshub.wbem.javax.cim.CIMQualifier;
51 import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession;
52 import org.xml.sax.Attributes;
53 import org.xml.sax.SAXException;
54
55 /**
56 * AbstractPropertyNode is superclass of PropertyArrayNode, PropertyNode and
57 * PropertyReferenceNode classes.
58 */
59 public abstract class AbstractPropertyNode extends Node implements TypedIf, ValueIf {
60 // common attributes
61 private String iName;
62
63 private String iClassOrigin;
64
65 private boolean iPropagated;
66
67 protected QualifiedNodeHandler iQualiHandler;
68
69 /**
70 * Ctor.
71 *
72 * @param pNameEnum
73 */
74 public AbstractPropertyNode(String pNameEnum) {
75 super(pNameEnum);
76 }
77
78 /**
79 * hasValue
80 *
81 * @return true if it has a value child node
82 */
83 protected abstract boolean hasValueNode();
84
85 protected abstract void childValueNodeParsed(Node pChild) throws SAXException;
86
87 protected abstract void specificInit(Attributes pAttribs, SAXSession pSession) throws SAXException;
88
89 protected abstract String getChildValueNodeNameEnum();
90
91 @Override
92 public void init(Attributes pAttribs, SAXSession pSession) throws SAXException {
93 this.iQualiHandler = QualifiedNodeHandler.init(this.iQualiHandler);
94 this.iName = getCIMName(pAttribs);
95 this.iClassOrigin = getClassOrigin(pAttribs);
96 this.iPropagated = getPropagated(pAttribs);
97 specificInit(pAttribs, pSession);
98 }
99
100 @Override
101 public void testChild(String pNodeNameEnum) throws SAXException {
102 String valueNodeNameEnum = getChildValueNodeNameEnum();
103 if (pNodeNameEnum == valueNodeNameEnum) {
104 if (hasValueNode()) throw new SAXException(
105 getNodeName() + " node can have only one " + valueNodeNameEnum + " child node!"
106 );
107 } else if (pNodeNameEnum != QUALIFIER) throw new SAXException(
108 getNodeName() + " node cannot have " + pNodeNameEnum + " child node!"
109 );
110 }
111
112 /**
113 * @param pData
114 */
115 @Override
116 public void parseData(String pData) {
117 // no data
118 }
119
120 @Override
121 public void childParsed(Node pChild) throws SAXException {
122 if (!this.iQualiHandler.addQualifierNode(pChild)) {
123 childValueNodeParsed(pChild);
124 }
125 }
126
127 protected CIMQualifier<?>[] getQualis() {
128 // not dealing with embedded object qualifier is faster
129 return this.iQualiHandler.getQualis(true);
130 }
131
132 /**
133 * getCIMProperty
134 *
135 * @return CIMProperty
136 */
137 public CIMProperty<Object> getCIMProperty() {
138 /*
139 * CIMProperty( String name, CIMDataType type, Object value, boolean
140 * key, boolean propagated, String originClass )
141 */
142 return new CIMProperty<Object>(
143 this.iName,
144 getType(),
145 getValue(),
146 this.iQualiHandler.isKeyed(),
147 this.iPropagated,
148 this.iClassOrigin
149 );
150 }
151
152 /**
153 * getCIMClassProperty
154 *
155 * @return CIMClassProperty
156 */
157 public CIMClassProperty<Object> getCIMClassProperty() {
158 /*
159 * CIMClassProperty( String pName, CIMDataType pType, Object pValue,
160 * CIMQualifier[] pQualifiers, boolean pKey, boolean propagated, String
161 * originClass) );
162 */
163 return new CIMClassProperty<Object>(
164 this.iName,
165 getType(),
166 getValue(),
167 getQualis(),
168 this.iQualiHandler.isKeyed(),
169 this.iPropagated,
170 this.iClassOrigin
171 );
172 }
173 }