View Javadoc
1   /*
2     (C) Copyright IBM Corp. 2006, 2011
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   * 3194680    2011-02-28  blaschke-oss Error in numeric keys
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 org.metricshub.wbem.sblim.cimclient.internal.util.Util;
44  
45  /**
46   * Class Test is responsible for testing the WBEM-URI String parsing.
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  		// "SelfRef=\"https://jdd:test@acme.com:5959/cimv2:CIM_RegisteredProfile\"",
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( // "https://jdd:test@acme.com:5959/cimv2:CIM_RegisteredProfile."
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( // "https://jdd:test@acme.com:5959/cimv2:CIM_RegisteredProfile."
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( // "https://jdd:test@acme.com:5959/cimv2:CIM_RegisteredProfile."
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 		 * Typed URI strings
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 	 * main
134 	 *
135 	 * @param args
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 }