1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.metricshub.wbem.sblim.cimclient.internal.uri;
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 import org.metricshub.wbem.sblim.cimclient.internal.util.Util;
44
45
46
47
48 public class Test {
49 private static String cUriArray[] = {
50 "//www.acme.com/root/cimv2",
51 "//www.acme.com/root/cimv2:CIM_RegisteredProfile",
52 "https://jdd:test@acme.com:5959/cimv2:CIM_RegisteredProfile",
53 "https://jdd:test@acme.com:5959/cimv2:CIM_RegisteredProfile." + "Cool=\"Hey! It's a string\"",
54 "https://jdd:test@acme.com:5959/cimv2:CIM_RegisteredProfile.ThisShouldBeAnInt=0",
55 "https://jdd:test@acme.com:5959/cimv2:CIM_RegisteredProfile." +
56 "Cool=\"Hey! It's a string\"," +
57 "Yeah=\"Gee! \\\"It's an embedded string\\\"\"",
58 "https://jdd:test@acme.com:5959/cimv2:CIM_RegisteredProfile." +
59
60
61 "InstRef=\"CIM_RegisteredProfile.IntKey=10\"",
62 "https://jdd:test@acme.com:5959/cimv2:CIM_RegisteredProfile." +
63 "Yeah=" +
64 Util.quote("Gee! " + Util.quote("It's an embedded string")) +
65 ",Ref=" +
66 Util.quote(
67 "root/cimv2:CIM_RegisteredProfile." + "Yeah=" + Util.quote("Gee! " + Util.quote("It's an embedded string"))
68 ),
69 "https://jdd:test@64.202.189.170:5959/cimv2:CIM_RegisteredProfile." +
70 "Yeah=" +
71 Util.quote("Gee! " + Util.quote("It's an embedded string")) +
72 ",Ref=" +
73 Util.quote(
74 "CIM_RegisteredProfile." + "Yeah=" + Util.quote("Gee! " + Util.quote("It's an embedded string"))
75 ),
76 "https://64.202.189.170:5959/cimv2:CIM_RegisteredProfile." +
77 "Yeah=" +
78 Util.quote("Gee! " + Util.quote("It's an embedded string")) +
79 ",Ref=" +
80 Util.quote(
81 "CIM_RegisteredProfile." + "Yeah=" + Util.quote("Gee! " + Util.quote("It's an embedded string"))
82 ),
83 "https://64.202.189.170:5959/cimv2:CIM_RegisteredProfile." +
84 "Yeah=" +
85 Util.quote("Gee! " + Util.quote("It's an embedded string")) +
86 ",Ref=" +
87 Util.quote("CIM_RegisteredProfile." + "Yeah=" + Util.quote("Gee! " + Util.quote("It's an embedded string"))) +
88 ",CharKey0='a'" +
89 ",CharKey1='\\x32'" +
90 ",boolKeyT=True" +
91 ",boolKeyF=False" +
92 ",binValP=01011010b" +
93 ",binValN=-01011010b" +
94 ",octValP=0644" +
95 ",octValN=-0644" +
96 ",decValP=1848" +
97 ",decValN=-1848" +
98 ",hexValP=0x55aa" +
99 ",hexValN=-0x55aa" +
100 ",realValP=+23.566e-23" +
101 ",realValN=-23.566e+23" +
102 ",dtAbs=" +
103 Util.quote("20061027112135.600123+001") +
104 ",dtInv=" +
105 Util.quote("00000042123625.600123:000"),
106
107
108
109 "https://64.202.189.170:5959/cimv2/(instance)CIM_RegisteredProfile." +
110 "Yeah=(string)" +
111 Util.quote("Gee! " + Util.quote("It's an embedded string")) +
112 ",uInt32=(uint32)100000" +
113 ",Real32=(real32)3.14" +
114 ",dtAbs=(datetime)" +
115 Util.quote("20061027112135.600123+001") +
116 ",dtInv=(datetime)" +
117 Util.quote("00000042123625.600123:000") +
118 ",Bool=(boolean)true" +
119 ",Char=(char16)'x'" +
120 ",Ref=(reference)" +
121 Util.quote(
122 "/(instance)CIM_RegisteredProfile." +
123 "Yeah=(string)" +
124 Util.quote("Gee! " + Util.quote("It's an embedded string")) +
125 ",ClassRef=(reference)" +
126 Util.quote("/(instance)CIM_Gyurcsany.Key=(uint8)10")
127 ) +
128 ",RefWithNS=(reference)" +
129 Util.quote("root/cimv2/(instance)CIM_Orban.Key=(uint8)42")
130 };
131
132
133
134
135
136
137 public static void main(String args[]) {
138 for (int i = 0; i < cUriArray.length; i++) {
139 System.out.println("\nparsing:\n" + cUriArray[i]);
140 URI uri = URI.parse(cUriArray[i]);
141 if (uri == null) {
142 System.out.println("parsing failed!");
143 continue;
144 }
145 System.out.println("class:\n" + uri.getClass().getName());
146 System.out.println("refactored string:\n" + uri.toString());
147
148 System.out.println("namespace name : " + uri.getNamespaceName());
149 System.out.println("namespace type : " + uri.getNamespaceType());
150 System.out.println("user info : " + uri.getUserInfo());
151 System.out.println("host name : " + uri.getHost());
152 System.out.println("port : " + uri.getPort());
153 System.out.println("class name : " + uri.getClassName());
154 KeyValuePairs pairs = uri.getKeyValuePairs();
155 if (pairs == null) continue;
156 for (int j = 0; j < pairs.size(); j++) {
157 KeyValuePair pair = (KeyValuePair) pairs.elementAt(j);
158 Value value = pair.getValue();
159 System.out.println(
160 "key : " +
161 pair.getKey() +
162 "\n " +
163 getTypeStr(value) +
164 " : " +
165 pair.getValue().toString() +
166 " " +
167 getIntProps(value)
168 );
169 }
170 }
171 }
172
173 private static String getTypeStr(Value pVal) {
174 if (pVal instanceof ReferenceValue) return "refValue"; else if (
175 pVal instanceof StringValue
176 ) return "strValue"; else if (pVal instanceof CharValue) return "chrValue"; else if (
177 pVal instanceof BooleanValue
178 ) return "boolValue"; else if (pVal instanceof DateTimeValue) return "dateTimeVal"; else if (
179 pVal instanceof IntegerValue
180 ) return "intValue"; else if (pVal instanceof RealValue) return "realValue";
181 return pVal.getClass().getName();
182 }
183
184 private static String getIntProps(Value pVal) {
185 if (!(pVal instanceof IntegerValue)) return "";
186 IntegerValue intVal = (IntegerValue) pVal;
187 return "sigend=" + intVal.isSigned() + ", bitWidth=" + intVal.getBitWidth();
188 }
189 }