View Javadoc
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.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node;
27  
28  /*-
29   * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
30   * WBEM Java Client
31   * ჻჻჻჻჻჻
32   * Copyright (C) 2023 Sentry Software
33   * ჻჻჻჻჻჻
34   * This program is free software: you can redistribute it and/or modify
35   * it under the terms of the GNU Lesser General Public License as
36   * published by the Free Software Foundation, either version 3 of the
37   * License, or (at your option) any later version.
38   *
39   * This program is distributed in the hope that it will be useful,
40   * but WITHOUT ANY WARRANTY; without even the implied warranty of
41   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
42   * GNU General Lesser Public License for more details.
43   *
44   * You should have received a copy of the GNU General Lesser Public
45   * License along with this program.  If not, see
46   * <http://www.gnu.org/licenses/lgpl-3.0.html>.
47   * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
48   */
49  
50  import org.sentrysoftware.wbem.javax.cim.CIMClassProperty;
51  import org.sentrysoftware.wbem.javax.cim.CIMProperty;
52  import org.sentrysoftware.wbem.javax.cim.CIMQualifier;
53  
54  import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession;
55  import org.xml.sax.Attributes;
56  import org.xml.sax.SAXException;
57  
58  /**
59   * AbstractPropertyNode is superclass of PropertyArrayNode, PropertyNode and
60   * PropertyReferenceNode classes.
61   */
62  public abstract class AbstractPropertyNode extends Node implements TypedIf, ValueIf {
63  
64  	// common attributes
65  	private String iName;
66  
67  	private String iClassOrigin;
68  
69  	private boolean iPropagated;
70  
71  	protected QualifiedNodeHandler iQualiHandler;
72  
73  	/**
74  	 * Ctor.
75  	 * 
76  	 * @param pNameEnum
77  	 */
78  	public AbstractPropertyNode(String pNameEnum) {
79  		super(pNameEnum);
80  	}
81  
82  	/**
83  	 * hasValue
84  	 * 
85  	 * @return true if it has a value child node
86  	 */
87  	protected abstract boolean hasValueNode();
88  
89  	protected abstract void childValueNodeParsed(Node pChild) throws SAXException;
90  
91  	protected abstract void specificInit(Attributes pAttribs, SAXSession pSession)
92  			throws SAXException;
93  
94  	protected abstract String getChildValueNodeNameEnum();
95  
96  	@Override
97  	public void init(Attributes pAttribs, SAXSession pSession) throws SAXException {
98  		this.iQualiHandler = QualifiedNodeHandler.init(this.iQualiHandler);
99  		this.iName = getCIMName(pAttribs);
100 		this.iClassOrigin = getClassOrigin(pAttribs);
101 		this.iPropagated = getPropagated(pAttribs);
102 		specificInit(pAttribs, pSession);
103 	}
104 
105 	@Override
106 	public void testChild(String pNodeNameEnum) throws SAXException {
107 		String valueNodeNameEnum = getChildValueNodeNameEnum();
108 		if (pNodeNameEnum == valueNodeNameEnum) {
109 			if (hasValueNode()) throw new SAXException(getNodeName() + " node can have only one "
110 					+ valueNodeNameEnum + " child node!");
111 		} else if (pNodeNameEnum != QUALIFIER) throw new SAXException(getNodeName()
112 				+ " node cannot have " + pNodeNameEnum + " child node!");
113 	}
114 
115 	/**
116 	 * @param pData
117 	 */
118 	@Override
119 	public void parseData(String pData) {
120 	// no data
121 	}
122 
123 	@Override
124 	public void childParsed(Node pChild) throws SAXException {
125 		if (!this.iQualiHandler.addQualifierNode(pChild)) {
126 			childValueNodeParsed(pChild);
127 		}
128 	}
129 
130 	protected CIMQualifier<?>[] getQualis() {
131 		// not dealing with embedded object qualifier is faster
132 		return this.iQualiHandler.getQualis(true);
133 	}
134 
135 	/**
136 	 * getCIMProperty
137 	 * 
138 	 * @return CIMProperty
139 	 */
140 	public CIMProperty<Object> getCIMProperty() {
141 		/*
142 		 * CIMProperty( String name, CIMDataType type, Object value, boolean
143 		 * key, boolean propagated, String originClass )
144 		 */
145 		return new CIMProperty<Object>(this.iName, getType(), getValue(), this.iQualiHandler
146 				.isKeyed(), this.iPropagated, this.iClassOrigin);
147 	}
148 
149 	/**
150 	 * getCIMClassProperty
151 	 * 
152 	 * @return CIMClassProperty
153 	 */
154 	public CIMClassProperty<Object> getCIMClassProperty() {
155 		/*
156 		 * CIMClassProperty( String pName, CIMDataType pType, Object pValue,
157 		 * CIMQualifier[] pQualifiers, boolean pKey, boolean propagated, String
158 		 * originClass) );
159 		 */
160 		return new CIMClassProperty<Object>(this.iName, getType(), getValue(), getQualis(),
161 				this.iQualiHandler.isKeyed(), this.iPropagated, this.iClassOrigin);
162 	}
163 
164 }