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   * 1720707    2007-05-17  ebak         Conventional Node factory for CIM-XML SAX parser
16   * 2003590    2008-06-30  blaschke-oss Change licensing from CPL to EPL
17   * 2524131    2009-01-21  raman_arora  Upgrade client to JDK 1.5 (Phase 1)
18   * 2531371    2009-02-10  raman_arora  Upgrade client to JDK 1.5 (Phase 2)
19   * 2845211    2009-08-27  raman_arora  Pull Enumeration Feature (SAX Parser)
20   * 3498482    2012-03-09  blaschke-oss Red Hat: Possible XML Hash DoS in sblim
21   * 3535383    2012-08-01  blaschke-oss HashDoS fix 3498482
22   *    2672    2013-09-26  blaschke-oss Remove SIMPLEREQACK support
23   *    2690    2013-10-11  blaschke-oss Remove RESPONSEDESTINATION support
24   *    2538    2013-11-28  blaschke-oss CR14: Support new CORRELATOR element
25   */
26  
27  package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax;
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 java.util.HashMap;
50  import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node.*;
51  
52  /**
53   * Class NodeFactory is responsible for Node instance construction.
54   *
55   */
56  public class NodeFactory implements NodeConstIf {
57  
58  	/**
59  	 * getNodeInstance
60  	 *
61  	 * @param pNodeName
62  	 *            Should be an XML element name constant which is defined in
63  	 *            NodeConstIf
64  	 * @return the Node subclass which implements the parsing of pNodeName named
65  	 *         XML Element.
66  	 */
67  	public static Node getNodeInstance(String pNodeName) {
68  		createParserMap();
69  		return cParserMap.get(pNodeName).create();
70  	}
71  
72  	/**
73  	 * getEnum
74  	 *
75  	 * @param pNodeName
76  	 * @return The corresponding String constant for an XML element name. It
77  	 *         must be used, because the Node subclasses use reference based
78  	 *         equals comparisons (==).
79  	 */
80  	public static String getEnum(String pNodeName) {
81  		return NODENAME_HASH.get(pNodeName);
82  	}
83  
84  	private static HashMap<String, FactoryEntry> cParserMap;
85  
86  	private interface FactoryEntry {
87  		/**
88  		 * create
89  		 *
90  		 * @return Node
91  		 */
92  		public Node create();
93  	}
94  
95  	private static synchronized void createParserMap() {
96  		if (cParserMap != null) return;
97  		cParserMap = new HashMap<String, FactoryEntry>();
98  		cParserMap.put(
99  			CIM,
100 			new FactoryEntry() {
101 
102 				public Node create() {
103 					return new CIMNode();
104 				}
105 			}
106 		);
107 		// DECLARATION - not implemented
108 		// DECLGROUP - not implemented
109 		// DECLGROUP.WITHNAME - not implemented
110 		// DECLGROUP.WITHPATH - not implemented
111 		cParserMap.put(
112 			QUALIFIER_DECLARATION,
113 			new FactoryEntry() {
114 
115 				public Node create() {
116 					return new QualiDeclNode();
117 				}
118 			}
119 		);
120 		cParserMap.put(
121 			SCOPE,
122 			new FactoryEntry() {
123 
124 				public Node create() {
125 					return new ScopeNode();
126 				}
127 			}
128 		);
129 		cParserMap.put(
130 			VALUE,
131 			new FactoryEntry() {
132 
133 				public Node create() {
134 					return new ValueNode();
135 				}
136 			}
137 		);
138 		cParserMap.put(
139 			VALUE_ARRAY,
140 			new FactoryEntry() {
141 
142 				public Node create() {
143 					return new ValueArrayNode();
144 				}
145 			}
146 		);
147 		cParserMap.put(
148 			VALUE_REFERENCE,
149 			new FactoryEntry() {
150 
151 				public Node create() {
152 					return new ValueReferenceNode();
153 				}
154 			}
155 		);
156 		cParserMap.put(
157 			VALUE_REFARRAY,
158 			new FactoryEntry() {
159 
160 				public Node create() {
161 					return new ValueRefArrayNode();
162 				}
163 			}
164 		);
165 		cParserMap.put(
166 			VALUE_OBJECT,
167 			new FactoryEntry() {
168 
169 				public Node create() {
170 					return new ValueObjectNode();
171 				}
172 			}
173 		);
174 		cParserMap.put(
175 			VALUE_NAMEDINSTANCE,
176 			new FactoryEntry() {
177 
178 				public Node create() {
179 					return new ValueNamedInstanceNode();
180 				}
181 			}
182 		);
183 		cParserMap.put(
184 			VALUE_OBJECTWITHLOCALPATH,
185 			new FactoryEntry() {
186 
187 				public Node create() {
188 					return new ValueObjectWithLocalPathNode();
189 				}
190 			}
191 		);
192 		cParserMap.put(
193 			VALUE_OBJECTWITHPATH,
194 			new FactoryEntry() {
195 
196 				public Node create() {
197 					return new ValueObjectWithPathNode();
198 				}
199 			}
200 		);
201 		cParserMap.put(
202 			VALUE_NULL,
203 			new FactoryEntry() {
204 
205 				public Node create() {
206 					return new ValueNullNode();
207 				}
208 			}
209 		);
210 		cParserMap.put(
211 			VALUE_INSTANCEWITHPATH,
212 			new FactoryEntry() {
213 
214 				public Node create() {
215 					return new ValueInstanceWithPathNode();
216 				}
217 			}
218 		);
219 		cParserMap.put(
220 			NAMESPACEPATH,
221 			new FactoryEntry() {
222 
223 				public Node create() {
224 					return new NameSpacePathNode();
225 				}
226 			}
227 		);
228 		cParserMap.put(
229 			LOCALNAMESPACEPATH,
230 			new FactoryEntry() {
231 
232 				public Node create() {
233 					return new LocalNameSpacePathNode();
234 				}
235 			}
236 		);
237 		cParserMap.put(
238 			HOST,
239 			new FactoryEntry() {
240 
241 				public Node create() {
242 					return new HostNode();
243 				}
244 			}
245 		);
246 		cParserMap.put(
247 			NAMESPACE,
248 			new FactoryEntry() {
249 
250 				public Node create() {
251 					return new NameSpaceNode();
252 				}
253 			}
254 		);
255 		cParserMap.put(
256 			CLASSPATH,
257 			new FactoryEntry() {
258 
259 				public Node create() {
260 					return new ClassPathNode();
261 				}
262 			}
263 		);
264 		cParserMap.put(
265 			LOCALCLASSPATH,
266 			new FactoryEntry() {
267 
268 				public Node create() {
269 					return new LocalClassPathNode();
270 				}
271 			}
272 		);
273 		cParserMap.put(
274 			CLASSNAME,
275 			new FactoryEntry() {
276 
277 				public Node create() {
278 					return new ClassNameNode();
279 				}
280 			}
281 		);
282 		cParserMap.put(
283 			INSTANCEPATH,
284 			new FactoryEntry() {
285 
286 				public Node create() {
287 					return new InstancePathNode();
288 				}
289 			}
290 		);
291 		cParserMap.put(
292 			LOCALINSTANCEPATH,
293 			new FactoryEntry() {
294 
295 				public Node create() {
296 					return new LocalInstancePathNode();
297 				}
298 			}
299 		);
300 		cParserMap.put(
301 			INSTANCENAME,
302 			new FactoryEntry() {
303 
304 				public Node create() {
305 					return new InstanceNameNode();
306 				}
307 			}
308 		);
309 		cParserMap.put(
310 			OBJECTPATH,
311 			new FactoryEntry() {
312 
313 				public Node create() {
314 					return new ObjectPathNode();
315 				}
316 			}
317 		);
318 		cParserMap.put(
319 			KEYBINDING,
320 			new FactoryEntry() {
321 
322 				public Node create() {
323 					return new KeyBindingNode();
324 				}
325 			}
326 		);
327 		cParserMap.put(
328 			KEYVALUE,
329 			new FactoryEntry() {
330 
331 				public Node create() {
332 					return new KeyValueNode();
333 				}
334 			}
335 		);
336 		cParserMap.put(
337 			CLASS,
338 			new FactoryEntry() {
339 
340 				public Node create() {
341 					return new ClassNode();
342 				}
343 			}
344 		);
345 		cParserMap.put(
346 			INSTANCE,
347 			new FactoryEntry() {
348 
349 				public Node create() {
350 					return new InstanceNode();
351 				}
352 			}
353 		);
354 		cParserMap.put(
355 			QUALIFIER,
356 			new FactoryEntry() {
357 
358 				public Node create() {
359 					return new QualifierNode();
360 				}
361 			}
362 		);
363 		cParserMap.put(
364 			PROPERTY,
365 			new FactoryEntry() {
366 
367 				public Node create() {
368 					return new PropertyNode();
369 				}
370 			}
371 		);
372 		cParserMap.put(
373 			PROPERTY_ARRAY,
374 			new FactoryEntry() {
375 
376 				public Node create() {
377 					return new PropertyArrayNode();
378 				}
379 			}
380 		);
381 		cParserMap.put(
382 			PROPERTY_REFERENCE,
383 			new FactoryEntry() {
384 
385 				public Node create() {
386 					return new PropertyReferenceNode();
387 				}
388 			}
389 		);
390 		cParserMap.put(
391 			METHOD,
392 			new FactoryEntry() {
393 
394 				public Node create() {
395 					return new MethodNode();
396 				}
397 			}
398 		);
399 		cParserMap.put(
400 			PARAMETER,
401 			new FactoryEntry() {
402 
403 				public Node create() {
404 					return new ParameterNode();
405 				}
406 			}
407 		);
408 		cParserMap.put(
409 			PARAMETER_REFERENCE,
410 			new FactoryEntry() {
411 
412 				public Node create() {
413 					return new ParameterReferenceNode();
414 				}
415 			}
416 		);
417 		cParserMap.put(
418 			PARAMETER_ARRAY,
419 			new FactoryEntry() {
420 
421 				public Node create() {
422 					return new ParameterArrayNode();
423 				}
424 			}
425 		);
426 		cParserMap.put(
427 			PARAMETER_REFARRAY,
428 			new FactoryEntry() {
429 
430 				public Node create() {
431 					return new ParameterRefArrayNode();
432 				}
433 			}
434 		);
435 		cParserMap.put(
436 			MESSAGE,
437 			new FactoryEntry() {
438 
439 				public Node create() {
440 					return new MessageNode();
441 				}
442 			}
443 		);
444 		cParserMap.put(
445 			MULTIREQ,
446 			new FactoryEntry() {
447 
448 				public Node create() {
449 					return new MultiReqNode();
450 				}
451 			}
452 		);
453 		cParserMap.put(
454 			MULTIEXPREQ,
455 			new FactoryEntry() {
456 
457 				public Node create() {
458 					return new MultiExpReqNode();
459 				}
460 			}
461 		);
462 		cParserMap.put(
463 			SIMPLEREQ,
464 			new FactoryEntry() {
465 
466 				public Node create() {
467 					return new SimpleReqNode();
468 				}
469 			}
470 		);
471 		cParserMap.put(
472 			SIMPLEEXPREQ,
473 			new FactoryEntry() {
474 
475 				public Node create() {
476 					return new SimpleExpReqNode();
477 				}
478 			}
479 		);
480 		cParserMap.put(
481 			IMETHODCALL,
482 			new FactoryEntry() {
483 
484 				public Node create() {
485 					return new IMethodCallNode();
486 				}
487 			}
488 		);
489 		cParserMap.put(
490 			METHODCALL,
491 			new FactoryEntry() {
492 
493 				public Node create() {
494 					return new MethodCallNode();
495 				}
496 			}
497 		);
498 		cParserMap.put(
499 			EXPMETHODCALL,
500 			new FactoryEntry() {
501 
502 				public Node create() {
503 					return new ExpMethodCallNode();
504 				}
505 			}
506 		);
507 		cParserMap.put(
508 			PARAMVALUE,
509 			new FactoryEntry() {
510 
511 				public Node create() {
512 					return new ParamValueNode();
513 				}
514 			}
515 		);
516 		cParserMap.put(
517 			IPARAMVALUE,
518 			new FactoryEntry() {
519 
520 				public Node create() {
521 					return new IParamValueNode();
522 				}
523 			}
524 		);
525 		cParserMap.put(
526 			EXPPARAMVALUE,
527 			new FactoryEntry() {
528 
529 				public Node create() {
530 					return new ExpParamValueNode();
531 				}
532 			}
533 		);
534 		cParserMap.put(
535 			MULTIRSP,
536 			new FactoryEntry() {
537 
538 				public Node create() {
539 					return new MultiRspNode();
540 				}
541 			}
542 		);
543 		cParserMap.put(
544 			MULTIEXPRSP,
545 			new FactoryEntry() {
546 
547 				public Node create() {
548 					return new MultiExpRspNode();
549 				}
550 			}
551 		);
552 		cParserMap.put(
553 			SIMPLERSP,
554 			new FactoryEntry() {
555 
556 				public Node create() {
557 					return new SimpleRspNode();
558 				}
559 			}
560 		);
561 		cParserMap.put(
562 			SIMPLEEXPRSP,
563 			new FactoryEntry() {
564 
565 				public Node create() {
566 					return new SimpleExpRspNode();
567 				}
568 			}
569 		);
570 		cParserMap.put(
571 			METHODRESPONSE,
572 			new FactoryEntry() {
573 
574 				public Node create() {
575 					return new MethodResponseNode();
576 				}
577 			}
578 		);
579 		cParserMap.put(
580 			EXPMETHODRESPONSE,
581 			new FactoryEntry() {
582 
583 				public Node create() {
584 					return new ExpMethodResponseNode();
585 				}
586 			}
587 		);
588 		cParserMap.put(
589 			IMETHODRESPONSE,
590 			new FactoryEntry() {
591 
592 				public Node create() {
593 					return new IMethodResponseNode();
594 				}
595 			}
596 		);
597 		cParserMap.put(
598 			ERROR,
599 			new FactoryEntry() {
600 
601 				public Node create() {
602 					return new ErrorNode();
603 				}
604 			}
605 		);
606 		cParserMap.put(
607 			RETURNVALUE,
608 			new FactoryEntry() {
609 
610 				public Node create() {
611 					return new ReturnValueNode();
612 				}
613 			}
614 		);
615 		cParserMap.put(
616 			IRETURNVALUE,
617 			new FactoryEntry() {
618 
619 				public Node create() {
620 					return new IReturnValueNode();
621 				}
622 			}
623 		);
624 		cParserMap.put(
625 			CORRELATOR,
626 			new FactoryEntry() {
627 
628 				public Node create() {
629 					return new CorrelatorNode();
630 				}
631 			}
632 		);
633 	}
634 
635 	private static final HashMap<String, String> NODENAME_HASH = new HashMap<String, String>();
636 
637 	private static void initNodeNameHash(String[] pEnumA) {
638 		for (int i = 0; i < pEnumA.length; i++) NODENAME_HASH.put(pEnumA[i], pEnumA[i]);
639 	}
640 
641 	static {
642 		initNodeNameHash(
643 			new String[] {
644 				CIM,
645 				DECLARATION,
646 				DECLGROUP,
647 				DECLGROUP_WITHNAME,
648 				DECLGROUP_WITHPATH,
649 				QUALIFIER_DECLARATION,
650 				SCOPE,
651 				VALUE,
652 				VALUE_ARRAY,
653 				VALUE_REFERENCE,
654 				VALUE_REFARRAY,
655 				VALUE_OBJECT,
656 				VALUE_NAMEDINSTANCE,
657 				VALUE_NAMEDOBJECT,
658 				VALUE_OBJECTWITHLOCALPATH,
659 				VALUE_OBJECTWITHPATH,
660 				VALUE_NULL,
661 				VALUE_INSTANCEWITHPATH,
662 				NAMESPACEPATH,
663 				LOCALNAMESPACEPATH,
664 				HOST,
665 				NAMESPACE,
666 				CLASSPATH,
667 				LOCALCLASSPATH,
668 				CLASSNAME,
669 				INSTANCEPATH,
670 				LOCALINSTANCEPATH,
671 				INSTANCENAME,
672 				OBJECTPATH,
673 				KEYBINDING,
674 				KEYVALUE,
675 				CLASS,
676 				INSTANCE,
677 				QUALIFIER,
678 				PROPERTY,
679 				PROPERTY_ARRAY,
680 				PROPERTY_REFERENCE,
681 				METHOD,
682 				PARAMETER,
683 				PARAMETER_REFERENCE,
684 				PARAMETER_ARRAY,
685 				PARAMETER_REFARRAY,
686 				/*
687 				 * TABLE stuff is missing yet
688 				 */
689 				MESSAGE,
690 				MULTIREQ,
691 				MULTIEXPREQ,
692 				SIMPLEREQ,
693 				SIMPLEEXPREQ,
694 				IMETHODCALL,
695 				METHODCALL,
696 				EXPMETHODCALL,
697 				PARAMVALUE,
698 				IPARAMVALUE,
699 				EXPPARAMVALUE,
700 				MULTIRSP,
701 				MULTIEXPRSP,
702 				SIMPLERSP,
703 				SIMPLEEXPRSP,
704 				METHODRESPONSE,
705 				EXPMETHODRESPONSE,
706 				IMETHODRESPONSE,
707 				ERROR,
708 				RETURNVALUE,
709 				IRETURNVALUE,
710 				CORRELATOR
711 			}
712 		);
713 	}
714 }