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-11-05 ebak Make SBLIM client JSR48 compliant
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 */
20
21 package org.metricshub.wbem.sblim.cimclient.internal.uri;
22
23 /*-
24 * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
25 * WBEM Java Client
26 * ჻჻჻჻჻჻
27 * Copyright 2023 - 2025 MetricsHub
28 * ჻჻჻჻჻჻
29 * Licensed under the Apache License, Version 2.0 (the "License");
30 * you may not use this file except in compliance with the License.
31 * You may obtain a copy of the License at
32 *
33 * http://www.apache.org/licenses/LICENSE-2.0
34 *
35 * Unless required by applicable law or agreed to in writing, software
36 * distributed under the License is distributed on an "AS IS" BASIS,
37 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
38 * See the License for the specific language governing permissions and
39 * limitations under the License.
40 * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
41 */
42
43 import java.util.Vector;
44
45 /**
46 * key_value_pair *("," key_value_pair)
47 */
48 public class KeyValuePairs extends Vector<Object> {
49 /**
50 * serialVersionUID
51 */
52 private static final long serialVersionUID = -7518417983119426792L;
53
54 /**
55 * Tries to parse the key-value pairs from the passed <code>pUriStr</code>.
56 *
57 * @param pTyped
58 * @param pUriStr
59 * @return instance of <code>UntypedKeyValuePairs</code> or
60 * <code>null</code> if failed.
61 * @throws IllegalArgumentException
62 */
63 public static KeyValuePairs parse(boolean pTyped, URIString pUriStr) throws IllegalArgumentException {
64 // TODO: tracing TRC.log(uriStr.toString());
65 URIString uriStr = pUriStr.deepCopy();
66 KeyValuePairs pairs = new KeyValuePairs();
67 KeyValuePair pair = null;
68 while ((pair = KeyValuePair.parse(pTyped, uriStr)) != null) {
69 pairs.add(pair);
70 if (uriStr.length() > 0) {
71 if (!uriStr.cutStarting(',')) {
72 String msg = "',' expected!\n" + uriStr.markPosition();
73 throw new IllegalArgumentException(msg);
74 }
75 }
76 if (uriStr.length() == 0) break;
77 }
78 if (pairs.size() > 0) {
79 pUriStr.set(uriStr);
80 return pairs;
81 }
82 return null;
83 }
84
85 /**
86 * @see java.util.Vector#toString()
87 */
88 @Override
89 public String toString() {
90 String sep = null;
91 StringBuffer dstBuf = new StringBuffer();
92 for (int i = 0; i < size(); i++) {
93 KeyValuePair pair = (KeyValuePair) elementAt(i);
94 if (sep != null) dstBuf.append(sep); else sep = ",";
95 dstBuf.append(pair.toString());
96 }
97 return dstBuf.toString();
98 }
99 }