1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.metricshub.wbem.sblim.cimclient.internal.uri;
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 import java.util.regex.Pattern;
43
44
45
46
47 public class KeyValuePair {
48 private static final Pattern KEYNAMEPAT = Pattern.compile("^([A-Za-z][0-9A-Za-z_]*).*");
49
50
51
52
53
54
55
56
57
58
59 public static KeyValuePair parse(boolean pTyped, URIString pUriStr) throws IllegalArgumentException {
60
61 URIString uriStr = pUriStr.deepCopy();
62 if (!uriStr.matchAndCut(KEYNAMEPAT, 1)) {
63 String msg = "keyName expected!\n" + uriStr.markPosition();
64 throw new IllegalArgumentException(msg);
65 }
66 String key = uriStr.group(1);
67 if (!uriStr.cutStarting('=')) {
68 String msg = "'=' expected!\n" + uriStr.markPosition();
69 throw new IllegalArgumentException(msg);
70 }
71 Value value = Value.parse(pTyped, uriStr);
72 if (value == null) {
73 String msg = "value expected!\n" + uriStr.markPosition();
74 throw new IllegalArgumentException(msg);
75 }
76 pUriStr.set(uriStr);
77 return new KeyValuePair(key, value, pTyped);
78 }
79
80 private String iKey;
81
82 private Value iValue;
83
84 private boolean iTyped;
85
86 private KeyValuePair(String pKey, Value pValue, boolean pTyped) {
87 this.iKey = pKey;
88 this.iValue = pValue;
89 this.iTyped = pTyped;
90 }
91
92
93
94
95 @Override
96 public String toString() {
97 StringBuffer buf = new StringBuffer(this.iKey + '=');
98 if (this.iTyped) buf.append('(' + this.iValue.getTypeInfo() + ')');
99 buf.append(
100 (this.iValue instanceof QuotedValue) ? ((QuotedValue) this.iValue).toQuotedString() : this.iValue.toString()
101 );
102 return buf.toString();
103 }
104
105
106
107
108
109
110 public String getKey() {
111 return this.iKey;
112 }
113
114
115
116
117
118
119 public Value getValue() {
120 return this.iValue;
121 }
122 }