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 * 1679534 2007-03-13 ebak wrong ValueObjectNode.testChild()
19 * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser
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 * 3602604 2013-01-29 blaschke-oss Clean up SAXException messages
24 * 2604 2013-07-01 blaschke-oss SAXException messages should contain node name
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.CIMClass;
50 import org.metricshub.wbem.javax.cim.CIMDataType;
51 import org.metricshub.wbem.javax.cim.CIMNamedElementInterface;
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 * ELEMENT VALUE.OBJECT (CLASS | INSTANCE)
58 */
59 public class ValueObjectNode extends AbstractScalarValueNode {
60 private CIMNamedElementInterface iCIMObject;
61
62 /**
63 * Ctor.
64 */
65 public ValueObjectNode() {
66 super(VALUE_OBJECT);
67 }
68
69 /**
70 * @param pAttribs
71 * @param pSession
72 */
73 @Override
74 public void init(Attributes pAttribs, SAXSession pSession) {
75 this.iCIMObject = null;
76 // no attributes
77 }
78
79 /**
80 * @param pData
81 */
82 @Override
83 public void parseData(String pData) {
84 // no data
85 }
86
87 @Override
88 public void testChild(String pNodeNameEnum) throws SAXException {
89 if (this.iCIMObject != null) throw new SAXException(
90 "This " + getNodeName() + " node can have only one child but an additional " + pNodeNameEnum + " node found!"
91 );
92 if (pNodeNameEnum != CLASS && pNodeNameEnum != INSTANCE) throw new SAXException(
93 getNodeName() + " node child node can be CLASS or INSTANCE but a " + pNodeNameEnum + " node was found!"
94 );
95 }
96
97 @Override
98 public void childParsed(Node pChild) {
99 AbstractObjectNode objNode = (AbstractObjectNode) pChild;
100 if (objNode instanceof ClassNode) this.iCIMObject = ((ClassNode) objNode).getCIMClass(); else this.iCIMObject =
101 ((InstanceNode) objNode).getCIMInstance();
102 }
103
104 @Override
105 public void testCompletness() throws SAXException {
106 if (this.iCIMObject == null) throw new SAXException("VALUE.OBJECT node must have a CLASS or INSTANCE child node!");
107 }
108
109 /**
110 * @seeValueIf#getValue()
111 * @return CIMClass or CIMInstance
112 */
113 public Object getValue() {
114 return this.iCIMObject;
115 }
116
117 public CIMDataType getType() {
118 if (this.iCIMObject instanceof CIMClass) return CIMDataType.CLASS_T;
119 return CIMDataType.OBJECT_T;
120 }
121 }